knotra 0.32.0

knotra: multi-project VCS dashboard and bulk-operation tool.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
//! All `Message` variants for the knotra GUI.

use knotra_vcs::{
    ContextList, ContextSwitchResult, ContextTarget, FreezeResult, FreezeValidation, ProjectId,
    WorkspaceStatus,
    model::operation::{OperationId, OperationLog, SmartPullPlan, SmartPullProgress},
    model::workspace::WorkspaceId,
};

use crate::state::sync::RetryPreparationId;
use crate::state::{OperationLeaseId, Screen};

#[derive(Debug, Clone)]
pub enum Message {
    Navigate(Screen),
    Workspace(WorkspaceMessage),
    Project(ProjectMessage),
    Sync(SyncMessage),
    Context(ContextMessage),
    Freezer(FreezerMessage),
    History(HistoryMessage),
    Settings(SettingsMessage),
    Background(BackgroundMessage),
    Filter(FilterMessage),
    /// Open an external tool (editor or merge tool).
    Launch(LaunchMessage),
    TagPush(TagPushMessage),
    ConflictOps(ConflictOpsMessage),
    Changelog(ChangelogMessage),
    Shortcut(ShortcutMessage),
    Selection(SelectionMessage),
    Activity(ActivityMessage),
    Palette(PaletteMessage),
    Dashboard(DashboardMessage),
    KeyEvent(KeyboardMessage),
    DetailPanel(DetailPanelMessage),
    /// Periodic tick from the FS-watch subscription.
    FsWatchTick,
    /// Request to write text to the system clipboard.
    CopyToClipboard(String),
    /// Toggle "Show details / Hide details" in modal result screens (RFC-0021 Phase 2).
    ToggleOpDetails,
    Tick,
    /// RFC-035 R8/Handoff 029: the window resized. Recomputes
    /// `state.width_mode` — iced's own documented subscription shape
    /// (`iced-0.14.0/src/lib.rs:358`), not a knotra-invented mechanism.
    WindowResized(iced::Size),
}

// --- Workspace ---
#[derive(Debug, Clone)]
pub enum WorkspaceMessage {
    RefreshRequested,
    WorkspaceSwitched(WorkspaceId),
    /// Open/close the shell's workspace-switcher dropdown (RFC-034 R12).
    SwitcherToggled,
    // Project management
    AddProjectDialogOpened,
    AddProjectNameChanged(String),
    AddProjectPathChanged(String),
    /// Advance from Step 1 (folder) to Step 2 (name) in the guided flow.
    AddProjectNextStep,
    AddProjectConfirmed,
    AddProjectCancelled,
    /// "Back" on Step 2 (name): return to Step 1 (folder), keeping it.
    AddProjectBack,
    /// User clicked the folder browse button.
    BrowsePathRequested,
    /// Native folder dialog returned (None = cancelled).
    BrowsePathSelected(Option<String>),
    RemoveProjectRequested(ProjectId),
    RemoveProjectConfirmed(ProjectId),
    RemoveProjectCancelled,
    /// Undo the most recent project removal (RFC-0021 Phase 5).
    UndoRemoval,
    /// Dismiss the undo snackbar without undoing.
    DismissUndoSnackbar,
    // Multi-workspace management
    CreateWorkspaceDialogOpened,
    CreateWorkspaceNameChanged(String),
    CreateWorkspaceConfirmed,
    CreateWorkspaceCancelled,
    RenameWorkspaceDialogOpened,
    RenameWorkspaceNameChanged(String),
    RenameWorkspaceConfirmed,
    RenameWorkspaceCancelled,
    DeleteWorkspaceRequested,
    DeleteWorkspaceConfirmed,
    DeleteWorkspaceCancelled,
}

// --- Project ---
#[derive(Debug, Clone)]
pub enum ProjectMessage {
    StatusRefreshRequested(ProjectId),
    FetchRequested(ProjectId),
}

// --- Sync ---
#[derive(Debug, Clone)]
pub enum SyncMessage {
    DispositionChanged(ProjectId, knotra_vcs::SmartPullDisposition),
    BulkFetchRequested,
    BulkFetchAllRequested,
    SmartPullPlanRequested,
    SmartPullConfirmed(SmartPullPlan),
    BulkPullRequested,
    ExecuteRequested,
    ModalClosed,
    Cancelled,
}

// --- Context ---
#[derive(Debug, Clone)]
pub enum ContextMessage {
    OpenRequested(Option<ProjectId>),
    SearchChanged(String),
    SwitchTargetChosen(ProjectId, ContextTarget, String),
    SwitchConfirmed,
    SwitchCancelled,
    BulkOpenRequested,
    BulkModalClosed,
}

// --- Freezer ---
#[derive(Debug, Clone)]
pub enum FreezerMessage {
    /// User navigated to the Freezer screen.
    OpenRequested,
    /// User typed in the freeze-point name field.
    NameChanged(String),
    /// User typed in the optional tag annotation message field.
    TagMessageChanged(String),
    BulkOpenRequested,
    BulkModalClosed,
    /// User requested pre-execution validation.
    ValidateRequested,
    /// User confirmed execution after seeing the validation results.
    ExecuteConfirmed,
}

// --- History ---
#[derive(Debug, Clone)]
pub enum HistoryMessage {
    SearchChanged(String),
    EntryToggled(OperationId),
}

// --- Settings ---
#[derive(Debug, Clone)]
pub enum SettingsMessage {
    LocaleChanged(knotra_ui::i18n::Locale),
    ThemeChanged(bool),
    // RFC-038 Stage 2 §1b: these four carry the raw typed text, not a
    // pre-parsed number — the view previously coerced unparseable input to
    // a magic default (0/1/10/2) at the message boundary, which destroyed
    // the user's input before validation could ever see it. Parsing (and
    // deciding what counts as valid) now happens in the handler.
    RefreshIntervalChanged(String),
    MaxConcurrentChanged(String),
    ExternalEditorChanged(String),
    ExternalMergeToolChanged(String),
    MaxLogEntriesChanged(String),
    FsWatchEnabledChanged(bool),
    FsDebounceSecs(String),
    SaveRequested,
}

// --- Background ---
#[derive(Debug, Clone)]
pub enum BackgroundMessage {
    WorkspaceStatusRefreshed(WorkspaceStatus),
    SingleFetchCompleted {
        lease_id: OperationLeaseId,
        log: OperationLog,
    },
    SmartPullProjectCompleted {
        lease_id: OperationLeaseId,
        progress: SmartPullProgress,
    },
    ActivityFetchRetryProjectCompleted {
        lease_id: OperationLeaseId,
        operation_id: OperationId,
        result: knotra_vcs::model::operation::ProjectOperationResult,
    },
    SmartPullRetryStatusReady {
        request_id: RetryPreparationId,
        workspace_id: WorkspaceId,
        lease_id: OperationLeaseId,
        statuses: Vec<knotra_vcs::ProjectStatus>,
    },
    SmartPullPlanReady(SmartPullPlan),
    ContextListLoaded(ContextList),
    /// Conflict file list loaded.
    ConflictFilesLoaded(knotra_vcs::ProjectConflictDetail),
    /// Conflict mutation completed, with refreshed conflict state.
    ConflictOperationCompleted {
        lease_id: OperationLeaseId,
        result: knotra_vcs::model::operation::ProjectOperationResult,
        detail: knotra_vcs::ProjectConflictDetail,
    },
    /// Changelog draft generated.
    ChangelogDraftReady {
        request_id: u64,
        draft: knotra_vcs::ChangelogDraft,
    },
    /// Topology graph scanned.
    TopologyScanned(knotra_vcs::DependencyGraph),
    /// Tag push completed for all offered projects.
    TagPushCompleted {
        lease_id: OperationLeaseId,
        success_count: usize,
        fail_count: usize,
    },
    /// Validation phase completed.
    FreezeValidationDone {
        lease_id: OperationLeaseId,
        validation: FreezeValidation,
    },
    /// Execution phase completed.
    FreezeExecutionDone {
        lease_id: OperationLeaseId,
        result: FreezeResult,
    },
    ContextSwitchDone {
        lease_id: OperationLeaseId,
        result: ContextSwitchResult,
    },
    /// Recent-commits list loaded for the detail panel (RFC-039 D4).
    RecentCommitsLoaded(knotra_vcs::RecentCommits),
}

// --- Filter ---
#[derive(Debug, Clone)]
pub enum FilterMessage {
    SearchChanged(String),
    StatusFilterToggled(StatusFilter),
    AllFiltersCleared,
}

#[derive(Debug, Clone, PartialEq, Eq)]
pub enum StatusFilter {
    AllSet,
    Behind,
    Ahead,
    Dirty,
    Conflict,
    NeedsHelp,
}
impl StatusFilter {
    pub fn label_key(&self) -> &'static str {
        match self {
            StatusFilter::AllSet => "filter.all_set",
            StatusFilter::Behind => "filter.behind",
            StatusFilter::Ahead => "filter.ahead",
            StatusFilter::Dirty => "filter.dirty",
            StatusFilter::Conflict => "filter.conflict",
            StatusFilter::NeedsHelp => "filter.needs_help",
        }
    }
}

#[derive(Debug, Clone)]
pub enum DashboardMessage {
    GroupingChanged(crate::config::DashboardGrouping),
    SortChanged(crate::config::DashboardSort),
    TierToggled(crate::state::dashboard::DashboardTier),
    /// RFC-035 R8/Handoff 028 Ruling 6.1: compact toolbar's chip overflow (`⋯`).
    ToolbarOverflowToggled,
    /// RFC-035 R8/Handoff 028 Ruling 6.1: compact toolbar's selector disclosure (`▾`).
    ToolbarSelectorsToggled,
}

// --- Conflict resolution ---
#[derive(Debug, Clone)]
pub enum ConflictOpsMessage {
    OpenRequested(Option<ProjectId>),
    ProjectSelected(ProjectId),
    MarkResolvedRequested {
        project_id: ProjectId,
        file_path: String,
    },
    AbortMergeRequested(ProjectId),
    /// RFC-067: "Stop this fix attempt" — enters `ConfirmStop`, runs nothing.
    StopRequested(ProjectId),
    /// RFC-067: "Keep fixing", Escape, or the scrim from `ConfirmStop` — returns to
    /// `Browsing`, runs nothing.
    StopCancelled,
    /// RFC-0021 Phase 3: open a conflicted file in the configured external editor.
    OpenInEditorRequested(String),
    /// Handoff 058: open a conflicted file in the configured merge tool.
    OpenInMergeToolRequested(String),
    /// RFC-0013: close the resolve panel.
    PanelClosed,
}

// --- Changelog ---
#[derive(Debug, Clone)]
pub enum ChangelogMessage {
    BulkOpenRequested,
    SinceRefChanged(String),
    ProjectToggled(ProjectId, bool),
    GenerateRequested,
    CopyRequested,
    CollectRequested,
    ModalClosed,
}

// --- Tag push (post-freeze) ---
#[derive(Debug, Clone)]
pub enum TagPushMessage {
    /// User accepted the push.
    PushConfirmed,
    /// User declined.
    PushDeclined,
}

// --- External tool launch ---
#[derive(Debug, Clone)]
pub enum LaunchMessage {
    /// Open a file path in the configured external editor.
    OpenInEditor(String),
    /// Open a file path in the configured merge tool.
    OpenInMergeTool(String),
}

// --- Shortcuts ---
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ShortcutMessage {
    Refresh,
    OpenContextOps,
    OpenFreezer,
    /// `Ctrl`/`Cmd`+`/` — unconditional, unchanged from before RFC-036.
    FocusSearch,
    Close,
    /// RFC-036 R1: Tab.
    FocusNext,
    /// RFC-036 R1: Shift-Tab.
    FocusPrevious,
    /// RFC-036 R3/R3a: Enter or Space, gated on text-input focus.
    ActivateFocused,
    /// RFC-036 R4: bare `/`, gated on text-input focus so a literal `/`
    /// typed into a field is never intercepted.
    FocusSearchBare,
    /// RFC-035 R22, `j` only as of RFC-066 D5 (`↓` is now
    /// [`ShortcutMessage::ArrowDown`]) — card arrow-navigation, coarser
    /// than Tab (moves between dashboard rows only, skipping their
    /// internal controls). Gated on text-input focus in `handle_shortcut`,
    /// consistent with `FocusSearchBare`/`ActivateFocused` even though
    /// iced 0.14's `text_input` does not itself consume `j`/`k` — the gate
    /// is for the user's typing, not to resolve a widget-level key
    /// conflict (Handoff 032 §3/§4). D5: does nothing while a window is
    /// open — already true today, since `advance_card_focus` already
    /// no-ops whenever `top_layer` is `Some`.
    CardFocusNext,
    /// `k` only. See [`ShortcutMessage::CardFocusNext`].
    CardFocusPrevious,
    /// RFC-066 D5: `↓`. Card arrow-navigation on the dashboard (same as
    /// `CardFocusNext` there, unchanged); inside a window, the same as
    /// Tab — advances that window's own order. Split from `CardFocusNext`
    /// because the two must now differ while a window is open, where they
    /// used to be identical.
    ArrowDown,
    /// RFC-066 D5: `↑`. See [`ShortcutMessage::ArrowDown`].
    ArrowUp,
    /// RFC-066 D4: a mouse button pressed anywhere — clears the focus
    /// outline (`AppState::focus_visible`). Never moves focus itself.
    MousePressed,
}

// ---------------------------------------------------------------------------
// RFC-0009 — Selection messages
// ---------------------------------------------------------------------------
#[derive(Debug, Clone)]
pub enum SelectionMessage {
    Toggled(ProjectId),
    SelectAll,
    Clear,
    /// Enter selection mode (show checkboxes).
    ModeEntered,
    /// Exit selection mode and clear selection.
    ModeExited,
}

// ---------------------------------------------------------------------------
// RFC-0011 — Activity strip messages
// ---------------------------------------------------------------------------
#[derive(Debug, Clone)]
pub enum ActivityMessage {
    RetryRequested { source_operation_id: OperationId },
    DetailsRequested { operation_id: OperationId },
}

// ---------------------------------------------------------------------------
// RFC-0012 — Command palette messages
// ---------------------------------------------------------------------------
#[derive(Debug, Clone)]
pub enum PaletteMessage {
    Opened,
    Closed,
    QueryChanged(String),
    EntryClicked(usize),
}

// ---------------------------------------------------------------------------
// RFC-0016 — Keyboard messages
// ---------------------------------------------------------------------------
#[derive(Debug, Clone)]
pub enum KeyboardMessage {
    CheatSheetToggled,
}

// ---------------------------------------------------------------------------
// RFC-0014 — Detail panel messages
// ---------------------------------------------------------------------------
#[derive(Debug, Clone)]
pub enum DetailPanelMessage {
    Opened(ProjectId),
    Closed,
}