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
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
//! The single-line text-input overlay — "type a string, press Enter". A integration
//! of the fuzzy [`Picker`](crate::picker) for the cases where there's no list to
//! filter, just free text (the commit message, …). `App` owns an `Option<Prompt>`
//! and maps the accepted text back to an action by [`PromptKind`].
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum PromptKind {
/// Accept ⇒ `App::add_workspace_runtime(input)`. Input is a path
/// (tilde-expanded); the workspace name defaults to the basename.
AddWorkspace,
/// Accept ⇒ `git commit -m <input>`.
GitCommit,
/// Accept ⇒ `git commit --amend -m <input>` (rewrite HEAD's message in
/// place). Opened by `git.ai_recompose` after the AI returns a new message.
GitCommitAmend,
/// Accept ⇒ `claude -p <input>`, answer in a `Pane::Ai`.
AiAsk,
/// Accept ⇒ `git checkout -b <input>`.
NewBranch,
/// Accept ⇒ `textDocument/rename` with the typed name (LSP).
LspRename,
/// Accept ⇒ launch Chrome on the typed URL in a `Pane::Browser` (CDP).
BrowserUrl,
/// `:ai.link_claude_token` — user pastes their Claude Code OAuth
/// token. Accept writes it to `~/.config/mnml/ai_token` (chmod
/// 600) via `App::accept_link_claude_token`.
LinkClaudeToken,
/// Accept ⇒ `Page.navigate` the active browser pane to the typed URL.
BrowserNavigate,
/// Accept ⇒ `Runtime.evaluate` the typed JS in the active browser pane.
BrowserEval,
/// Accept ⇒ `Network.setCookie` with the new value. Name, domain,
/// and path come from `App.pending_cookie_edit` (set when the chord
/// fires). Replaces the existing cookie.
BrowserCookieEdit,
/// Accept ⇒ `Network.setCookie` with a `name=value` payload (parsed
/// from the input). Domain comes from the active browser pane's
/// URL host; path is `/`. Adds a new cookie if no match exists.
BrowserCookieAdd,
/// Accept ⇒ Web Storage eval that sets the value for the
/// `(is_local, key)` stash on `App.pending_storage_edit`.
BrowserStorageEdit,
/// Accept ⇒ Web Storage eval that adds a `local|key=value` entry
/// (parsed from the input — the leading `local|` or `session|`
/// picks the storage).
BrowserStorageAdd,
/// Accept ⇒ find the typed string in the active editor (case-insensitive
/// ASCII), highlight matches, jump to the nearest one.
Find,
/// Accept ⇒ replace every match of the active find with the typed text.
/// Requires a non-empty find state already on the active buffer.
Replace,
/// Accept ⇒ grep the workspace (ripgrep; falls back to `git grep`), open
/// the results in a `Pane::Grep`.
Grep,
/// Accept ⇒ replace every hit in the active `Pane::Grep` (across every
/// file it matched) with the typed text. ASCII case-insensitive, like the
/// in-buffer find/replace.
GrepReplace,
/// Accept ⇒ jump the active editor's cursor to the typed 1-based line
/// number. (`Ctrl+G` — standard-mode equivalent of vim's `:N`.)
GotoLine,
/// Accept ⇒ write `<typed-var>=<pending_lookup_picked_id>` to
/// the current env file (`<workspace>/.rqst/env/<active>.env`)
/// and toast the result. The picked id was stashed into
/// `App::pending_lookup_picked_id` by the
/// `PickerKind::LookupItem` accept handler. Phase 7 of the
/// rqst→mnml port-back.
LookupVarName,
/// Accept ⇒ upsert `<pending_env_edit_key>=<typed>` into the
/// active env file. Stashed via `App::pending_env_edit_key`
/// when the EnvVars picker accepted an existing key. Phase 3
/// polish.
EnvEditValue,
/// Accept ⇒ split typed input on `=` → `<key>=<value>` and
/// upsert into the active env file. Empty / malformed input
/// toasts an error. Triggered by the `+add` row in the
/// `EnvVars` picker. Phase 3 polish.
EnvAddKey,
/// Accept ⇒ split typed input on `=`, append to the active
/// Request pane's URL as a query parameter. `?` if URL has no
/// query string yet; `&` if it does.
HttpParamAdd,
/// Accept ⇒ save active Request pane's Authorization header
/// as `.mnml/auth/<typed-name>.txt`. The preset can later be
/// applied via `:auth.apply_preset`.
AuthSavePreset,
/// Accept ⇒ ask Claude the typed question with the active
/// Request pane's request + response as context. Spawned by
/// clicking the AI section in the Request pane.
AiAskAboutRequest,
/// Accept ⇒ save the active Request pane's Done response body
/// to the typed file path (workspace-relative or absolute).
HttpSaveResponse,
/// Accept ⇒ save the active Request pane's current fields to
/// the typed .http path, set as source_path, and write.
HttpSaveRequestAs,
/// Accept ⇒ create a new empty `.env` file at
/// `.mnml/env/<typed>.env` and set it as the active env.
HttpNewEnv,
/// Accept ⇒ create a new `.chain.json` file at
/// `.mnml/chains/<typed>.chain.json` with a starter template
/// and open it in an editor pane.
HttpNewChain,
/// Accept ⇒ create a new collection folder at
/// `.mnml/collections/<typed>/` with a starter `.http` file
/// and open that file in an editor pane.
HttpNewCollection,
/// Accept ⇒ replace the active Request pane's Authorization
/// header with `Bearer <typed-token>`.
HttpAuthBearer,
/// Accept ⇒ replace Authorization with `Basic <base64(typed)>`.
/// Typed value is `user:pass`.
HttpAuthBasic,
/// Accept ⇒ replace `X-Api-Key` header value with typed.
HttpAuthApiKey,
/// Accept ⇒ connect to the typed wss:// URL via tungstenite.
WsConnect,
/// Accept ⇒ send the typed message on the active WebSocket.
WsSendMessage,
/// Accept ⇒ send the typed natural-language description to
/// Claude (one-shot), wait for the curl reply, then open a new
/// Request pane populated with the parsed request. Useful for
/// "get me the top 5 users from prod" → fully-formed POST.
HttpAiBuild,
/// Accept ⇒ SIGTERM the PID stashed in `App.pending_kill_pid`.
/// design-critic round-3 #4 2026-07-11: was a typed-confirm
/// (input == "kill") but the button-dialog migration converted
/// every remaining destructive prompt to a 2-button
/// `[Kill] [Cancel]` dialog. The typed-word gating is gone.
ClaudeKillConfirm,
/// Accept ⇒ grep every transcript under ~/.claude/projects/
/// for the typed substring (case-insensitive). Results land in
/// a `[session-search]` scratch buffer.
ClaudeSessionSearch,
/// Accept ⇒ force-delete the branch stashed in
/// `App.pending_branch_delete`. design-critic round-3 #4
/// 2026-07-11: was a typed-word confirm; now a 2-button
/// `[Delete] [Cancel]` dialog like every other destructive
/// action.
GitDeleteBranchConfirm,
/// Accept ⇒ pass the typed natural-language description to
/// Claude one-shot; the reply (a branch name) gets seeded
/// into a `BranchName` prompt for the user to accept/edit.
AiBranchNameDescription,
/// Accept ⇒ run `git checkout -b <input>` on the active repo.
/// Pre-seeded with the AI's suggestion when the
/// `AiBranchNameDescription` flow completes.
BranchName,
/// Accept ⇒ move the source path stashed in
/// `App.pending_file_move` into the typed destination
/// directory. Typed value is a workspace-relative or absolute
/// dir; missing intermediates are created; existing target
/// blocks the move. 2026-07-07.
FileMoveTo,
/// Accept (any non-empty) ⇒ `git worktree add <pending_path> <input>`.
/// `App.pending_worktree_path` is set by `:git.worktree_add`
/// before the prompt opens. Input is the branch name to check
/// out in the new worktree.
WorktreeBranchName,
/// Accept ⇒ `git worktree remove <pending_path>`. Confirm prompt
/// for the GitWorktreeRemove picker. design-critic round-3 #4
/// 2026-07-11: was typed-word gated; now a 2-button dialog.
WorktreeRemoveConfirm,
/// Accept ⇒ spawn `brew install <pkg>` in a Pty pane. Used by
/// `run_external_tool` when the binary isn't on PATH. The pending
/// package name lives on `App::pending_tool_install`.
/// design-critic round-3 #4 2026-07-11: was `input starts with 'y'`
/// gated; now a 2-button dialog.
ToolInstallConfirm,
/// Accept ⇒ `npm run <input>` in a pty pane. Used by
/// `:npm.run_script` so polyglot projects with non-`dev`
/// scripts (next dev, vite, start:dev, etc.) can run them
/// without a hardcoded chord.
NpmRunScript,
/// Accept ⇒ `go run <input>` in a pty pane. Used by
/// `:go.run_path` so projects with a `cmd/<app>/main.go`
/// layout can pick the right package without `:go.run` being
/// hardcoded to `.`.
GoRunPath,
/// Accept ⇒ `git merge <pending_merge_source>`. Confirm prompt for
/// the GitMergeInto picker. design-critic round-3 #4 2026-07-11:
/// was typed-word gated; now a 2-button dialog.
GitMergeConfirm,
/// Accept ⇒ `git rebase <pending_rebase_onto>`. Confirm prompt for
/// the GitRebaseOnto picker. design-critic round-3 #4 2026-07-11:
/// was typed-word gated; now a 2-button dialog.
GitRebaseConfirm,
/// Accept ⇒ patch the typed SVG path into the user's Nerd Font at
/// the next free PUA codepoint, then yank the assigned glyph as a
/// literal char to the clipboard so the user can paste it into
/// the integration edit panel's Glyph field directly (NOT as
/// `\u{XXXX}` — TOML doesn't parse Rust's escape syntax).
/// Surfaced from the palette command
/// `integrations.patch_nerd_font_svg`.
PatchNerdFontSvg,
/// Accept ⇒ write `launcher = "<input>"` to
/// `<workspace>/.mnml/integrations/<id>.toml` where `<id>` is
/// held in `App.pending_integration_launcher_id`. Empty input
/// clears the launcher override (deletes the key or the file).
/// `pty_pane::claude_code` / `codex` read this at spawn time
/// so a per-workspace wrapper (e.g. `./bin/claude-multi.sh`)
/// runs in place of the plain binary. Ships with v0.2.0.
IntegrationLauncher,
/// Accept ⇒ create an empty file at `<parent>/<input>`, then open it.
NewFile,
/// Accept ⇒ `mkdir -p <parent>/<input>`. No buffer opened.
NewFolder,
/// Accept ⇒ rename the held path to `<dir>/<input>` (same parent).
Rename,
/// Accept ⇒ delete the held path. design-critic round-3 #4
/// 2026-07-11: was a typed-filename confirm; now a 2-button
/// `[Delete] [Cancel]` dialog per the button-dialog migration.
DeleteConfirm,
/// Accept ⇒ `git stash drop <held ref>`. Ref + a short label held
/// in `App.pending_stash_drop`. design-critic round-3 #4
/// 2026-07-11: was a typed-word confirm (drop is reflog-recoverable
/// only until `git gc`, so the harder gate had a rationale). The
/// button-dialog migration converted it to a 2-button dialog like
/// every other destructive prompt — the extra friction is gone,
/// documented here so future readers don't rebuild the old shape
/// by accident.
GitStashDrop,
/// Accept ⇒ run `git tag -d <name>`. Tag name held in
/// `App.pending_tag_delete`. design-critic round-3 #4 2026-07-11:
/// was typed-word gated; now a 2-button dialog.
GitTagDelete,
/// Workspaces editor — apply the typed value to
/// `config.workspaces[App::workspaces_edit_target_name].name`
/// then persist.
WorkspaceRename,
/// Workspaces editor — apply path edit (tilde-expanded; must
/// exist on disk).
WorkspacePathEdit,
/// Workspaces editor — apply group label edit (empty = ungrouped).
WorkspaceGroupEdit,
/// Accept ⇒ reverse-apply the hunk against the working tree
/// (`crate::git::diff::discard_hunk`). Hunk identity is held in
/// `App.pending_discard_hunk = Some((pane_id, hunk_index))`.
/// design-critic round-3 #4 2026-07-11: was a typed-word
/// "discard" confirm — arguably the safest gate since a discarded
/// hunk is NOT reflog-recoverable. The button-dialog migration
/// dropped that extra friction; the outcome remains destructive.
DiffDiscardHunk,
/// Accept ⇒ `git restore -- <held rel>`. Opened by GitStatus's
/// right-click menu's "Discard changes" entry; path held in
/// `App.pending_discard_file`. design-critic round-3 #4 2026-07-11:
/// was a typed-basename confirm; now a 2-button dialog.
GitDiscardFile,
/// Accept ⇒ `workspace/symbol` with the typed query; the reply lands as
/// `LspEvent::WorkspaceSymbols` and opens a `Locations` picker.
LspWorkspaceSymbol,
/// Accept ⇒ `git stash push -u -m <input>` (or no `-m` if empty) — the
/// optional message form of `git.stash`. Esc ⇒ cancel without stashing.
GitStashMessage,
/// Accept ⇒ add the typed expression to `App.dap_watches`. If a
/// session is stopped at a breakpoint, immediately fires `evaluate`
/// against the top frame so the watch row's value populates.
DapAddWatch,
/// Accept ⇒ toggle a conditional breakpoint at the cursor line in
/// the active editor. Empty input ⇒ plain breakpoint (no condition);
/// non-empty ⇒ the adapter only stops when the expression is truthy.
DapBreakpointCondition,
/// Accept ⇒ set a hit-count condition on the breakpoint at the
/// cursor's line. Empty input ⇒ clear the hit count. Non-empty ⇒
/// the adapter interprets it (e.g. `">= 5"` stops after 5+ hits,
/// `"% 10"` every 10th hit). Independent of `DapBreakpointCondition`
/// — a line can have both.
DapBreakpointHitCount,
/// Accept ⇒ fire `setVariable` against the parent_ref + name stashed
/// on `App.pending_set_variable`. The adapter's reply lands as
/// `DapEvent::SetVariableDone` and the variables panel updates in
/// place. Failure (immutable / invalid value) routes through the
/// generic `DapEvent::Failed` toast path. Seeded with the current
/// value so the user can edit in place.
DapSetVariable,
/// Accept ⇒ `git tag -a <input> -m <input>` against either the selected
/// `Pane::GitGraph` commit (when one is focused) or HEAD. Empty input
/// cancels. The same input is used as both tag name AND annotation
/// message — for finer control the user can drop to a pty.
GitTag,
/// Accept ⇒ set the GitGraph pane's date-range filter from the typed
/// spec. Empty ⇒ clear. Accepts `--since=<s>`, `--until=<u>`, or
/// `<s>..<u>` shorthand; any git-recognized date works
/// (`1 week ago`, `2026-01-01`, …).
GitGraphDateFilter,
/// Accept ⇒ set `LogFilter.author` to the typed pattern. Empty ⇒ clear.
GitGraphAuthorFilter,
/// Accept ⇒ set `LogFilter.grep` to the typed pattern. Empty ⇒ clear.
GitGraphGrepFilter,
/// Accept ⇒ apply the pending tree move staged on
/// `App.pending_tree_move`. Used by the tree drag-and-drop flow as
/// the confirmation step.
TreeMoveConfirm,
/// Accept ⇒ exit mnml. Opened by `request_quit` so a fat-fingered
/// `Ctrl+Q` doesn't kill the session unexpectedly. Esc cancels via
/// the standard prompt machinery.
QuitConfirm,
/// Accept ⇒ pipe the pending filter range (staged on
/// `App::pending_filter_range`) through the typed shell command.
/// Vim `!{motion}` / `!!`. nvchad-round-9 SEV-2 2026-07-11.
FilterLinesShellCmd,
/// Accept ⇒ context-aware Claude Code dispatch (`App::dispatch_ai_chat`).
/// The wrapper formulates file + selection context and either seeds a
/// fresh interactive Claude pane or types into an already-open one.
/// Empty input + no selection ⇒ just open/focus a plain Claude pane.
AiChat,
/// Accept ⇒ set the active pty pane's `display_name` to the typed
/// text (`:rename` / `term.rename`). Empty input clears the name
/// back to the profile default.
PtySessionName,
/// Accept ⇒ rename the dock widget referenced by
/// `App::dock_rename_target`. Empty input falls back to the
/// default `Note N` style name (regenerated from id).
DockWidgetRename,
/// Accept ⇒ approve the AI agent's pending `write_file`; Esc ⇒ deny.
/// The answer is relayed to the blocked agent worker through its
/// confirm channel (`App::resolve_tool_confirm`).
AiToolConfirm,
/// Accept ⇒ spawn `<input>` as a Mount pane. Used by the
/// `mount.open` palette command for developer / testing flows
/// while integrations get ported to the Bridge tier-4 protocol.
MountBinary,
/// Accept ⇒ fire an ECS cloud run for the typed ticket
/// (validated against `[jira] ticket_prefix`). Default flow
/// = triage, env = prod. Used by the `cloud_agents.new_run`
/// palette command; requires `[cloud_agents]` to be
/// configured.
CloudRunTicket,
/// Accept ⇒ install the marketplace entry whose index is stashed
/// in `App::pending_marketplace_install_idx` — routes to
/// `App::install_marketplace_entry`. vscode-mouse r4 SEV-2 +
/// user report (2026-08-06): left-click on a marketplace row
/// used to install immediately with zero confirmation, which
/// was jarring given every other add/remove action gates on a
/// button dialog. Now that click opens this confirm first.
MarketplaceInstallConfirm,
/// Accept ⇒ actually run `remove_integration_by_id` on the
/// integration id stashed in `App::pending_integration_remove_id`.
/// Two-button confirm dialog — user reported bumping the
/// wrong context-menu entry on 2026-07-09 and losing an
/// integration.
IntegrationRemoveConfirm,
/// Accept ⇒ `App::perform_reset_to_defaults()`. Two-button
/// dialog: `Reset` renames `~/.config/mnml/` to a timestamped
/// backup + relaunches with a fresh config dir; `Cancel` drops.
/// Per-workspace `<ws>/.mnml/*` (env / chains / collections /
/// session) is deliberately untouched — that's real user work +
/// API tokens. A "Config + workspace" third button is designed
/// but not shipped; see task #851 for that v2 sketch.
/// A `.last-reset-from` marker in the fresh config dir carries
/// the backup path so the launch-time toast can point the user
/// at their restore command.
ResetToDefaultsConfirm,
/// #867 — first-ever launch prompt: portable-mode-vs-normal
/// data-layout choice. Rendered as a button dialog `[ Portable ]
/// [ Normal ]`. Primary defaults to Portable when
/// `data_root::portable_state()` reports `AwaitingConsent`
/// (folder was found next to the binary — user probably wants
/// portable), Normal otherwise.
PortableChoicePrompt,
/// Task #944 rename UX (2026-08-16) — inline pencil next to a
/// Claude account's section header in the Claude Usage pane.
/// Seeded with the current name; accept edits the
/// `[[ai.claude.accounts]]` block in place (comments preserved)
/// via `App::rename_claude_account`. The old name is stashed on
/// `App::pending_claude_account_rename` at open time.
ClaudeAccountRename,
}
#[derive(Debug)]
pub struct Prompt {
pub kind: PromptKind,
pub title: String,
pub input: String,
/// Caret position, a byte index into `input` (always on a char boundary).
pub cursor: usize,
/// Live-filtered directory suggestions — populated for path-typed
/// prompts (`AddWorkspace`). Each entry is a full path that
/// `Tab`/`Enter` can autocomplete or accept.
pub suggestions: Vec<std::path::PathBuf>,
/// `Some(i)` ⇒ the i-th suggestion is focused (↑/↓ navigation);
/// `None` ⇒ no row focused (Enter accepts the typed input).
pub selected_suggestion: Option<usize>,
/// vscode-user-keyboard SEV-2 2026-07-11: for `PromptKind::Find`
/// opened via Ctrl+H — set to `true` so Enter's accept-find path
/// also opens the Replace prompt automatically. VS Code parity:
/// `Ctrl+H` is one chord for the whole flow instead of two.
/// For every other invocation (`Ctrl+F`), stays `false` and Enter
/// just runs the search.
pub chain_to_replace: bool,
/// R7 vscode-mouse F5 2026-08-09: browser-style "seeded content
/// is selected — first typed char replaces everything". Chrome's
/// URL bar has this: click into it, everything highlights, and
/// typing a new URL overwrites the current one instead of
/// appending. We don't render a real selection (single-line
/// prompt, no selection state), but we emulate the behavior by
/// clearing the input on the FIRST `insert_char`/`insert_str`
/// after open. Any explicit caret motion (arrows / Home / End),
/// deletion (Backspace / Delete / Ctrl-U / Ctrl-K), OR the user
/// hitting `Tab` clears the flag first, so keeping the seed
/// stays one keystroke away. Set by
/// [`Self::seeded_select_all`].
pub select_all_on_first_type: bool,
}
impl Prompt {
pub fn new(kind: PromptKind, title: impl Into<String>) -> Self {
let mut p = Prompt {
kind,
title: title.into(),
input: String::new(),
cursor: 0,
suggestions: Vec::new(),
selected_suggestion: None,
chain_to_replace: false,
select_all_on_first_type: false,
};
p.refresh_suggestions();
p
}
/// Like [`Self::new`] but with the input field pre-filled (caret at the end) —
/// e.g. an AI-suggested commit message you can then edit before confirming.
pub fn seeded(kind: PromptKind, title: impl Into<String>, input: impl Into<String>) -> Self {
let input = input.into();
let cursor = input.len();
let mut p = Prompt {
kind,
title: title.into(),
input,
cursor,
suggestions: Vec::new(),
selected_suggestion: None,
chain_to_replace: false,
select_all_on_first_type: false,
};
p.refresh_suggestions();
p
}
/// Like [`Self::seeded`] but marks the seed as "selected" — the
/// first typed character (or paste) clears the input first, so
/// the user can overwrite the seed without hand-erasing it.
/// R7 vscode-mouse F5 2026-08-09 — Chrome's URL-bar behavior for
/// the browser navigate prompt (`g` in a browser pane).
pub fn seeded_select_all(
kind: PromptKind,
title: impl Into<String>,
input: impl Into<String>,
) -> Self {
let mut p = Self::seeded(kind, title, input);
p.select_all_on_first_type = true;
p
}
/// Does this prompt type want a directory listing alongside the
/// text input? Today `AddWorkspace` and `FileMoveTo`; extend as
/// needed.
pub fn is_path_kind(&self) -> bool {
matches!(self.kind, PromptKind::AddWorkspace | PromptKind::FileMoveTo)
}
/// Clear the select-all-on-first-type flag AND (if it was set)
/// wipe the seed to empty so the next `insert_char`/`insert_str`
/// starts fresh. Called from `insert_char`/`insert_str` before
/// the actual insert; also called from any user gesture that
/// says "keep the seed, I'm editing it" (arrow / Home / End /
/// Backspace / Delete / Tab). No-op if the flag is already off.
fn consume_select_all(&mut self) {
if self.select_all_on_first_type {
self.select_all_on_first_type = false;
self.input.clear();
self.cursor = 0;
}
}
/// Just clear the flag without touching the input — for gestures
/// that mean "I want to edit the seed as-is" (arrows, Home, End,
/// Backspace, Tab).
fn cancel_select_all(&mut self) {
self.select_all_on_first_type = false;
}
pub fn insert_char(&mut self, c: char) {
self.consume_select_all();
self.input.insert(self.cursor, c);
self.cursor += c.len_utf8();
self.refresh_suggestions();
}
/// Insert a string at the caret — used by the bracketed-paste
/// handler (Cmd+V on macOS, Ctrl+V in linux terminals). Newlines
/// are collapsed to spaces since the prompt is a single-line
/// widget; embedded NUL is stripped so a pasted binary blob can't
/// break the buffer.
pub fn insert_str(&mut self, s: &str) {
self.consume_select_all();
let cleaned: String = s
.chars()
.filter(|c| *c != '\0')
.map(|c| if c == '\n' || c == '\r' { ' ' } else { c })
.collect();
self.input.insert_str(self.cursor, &cleaned);
self.cursor += cleaned.len();
self.refresh_suggestions();
}
pub fn backspace(&mut self) {
// Backspace = "I want to edit this seed, one char at a time".
// Cancel the select-all flag (keep the seed) instead of
// wiping the whole input.
self.cancel_select_all();
if self.cursor == 0 {
return;
}
let prev = self.input[..self.cursor]
.char_indices()
.next_back()
.map(|(i, _)| i)
.unwrap_or(0);
self.input.replace_range(prev..self.cursor, "");
self.cursor = prev;
self.refresh_suggestions();
}
/// Delete — remove the char AT the caret (forward-delete).
/// Complements `backspace` (which deletes BEFORE the caret).
pub fn delete_forward(&mut self) {
self.cancel_select_all();
if self.cursor >= self.input.len() {
return;
}
let next = self.input[self.cursor..]
.char_indices()
.nth(1)
.map(|(i, _)| self.cursor + i)
.unwrap_or(self.input.len());
self.input.replace_range(self.cursor..next, "");
self.refresh_suggestions();
}
/// Delete the word (and trailing run of spaces) before the caret — Ctrl+W.
pub fn delete_word(&mut self) {
self.cancel_select_all();
let head = &self.input[..self.cursor];
let trimmed = head.trim_end_matches(' ');
let cut = trimmed
.char_indices()
.rev()
.find(|&(_, c)| c == ' ')
.map(|(i, _)| i + 1)
.unwrap_or(0);
self.input.replace_range(cut..self.cursor, "");
self.cursor = cut;
self.refresh_suggestions();
}
/// ↓ — focus the next suggestion (wraps to top).
pub fn suggestion_next(&mut self) {
if self.suggestions.is_empty() {
return;
}
let n = self.suggestions.len();
self.selected_suggestion = Some(match self.selected_suggestion {
None => 0,
Some(i) => (i + 1) % n,
});
}
/// ↑ — focus the previous suggestion (wraps to bottom). Going up
/// from the topmost row drops focus back to the input.
pub fn suggestion_prev(&mut self) {
if self.suggestions.is_empty() {
return;
}
let n = self.suggestions.len();
self.selected_suggestion = Some(match self.selected_suggestion {
None => n - 1,
Some(0) => return self.selected_suggestion = None,
Some(i) => i - 1,
});
}
/// Tab — autocomplete the input from the focused suggestion, or
/// from the first suggestion when none is focused. The caret
/// jumps to the end so further typing extends the path.
pub fn autocomplete(&mut self) {
let idx = self.selected_suggestion.unwrap_or(0);
let Some(path) = self.suggestions.get(idx) else {
return;
};
let s = path.to_string_lossy().to_string();
self.input = s;
self.cursor = self.input.len();
// Refresh again — picking a directory should now show its
// subdirectories.
self.refresh_suggestions();
// Clear the focus indicator after autocompleting; the user's
// next ↑↓ re-engages the list.
self.selected_suggestion = None;
}
/// Replace the input with the focused suggestion (no refresh). Used
/// by Enter on a focused row to commit the picked path.
pub fn take_selected_input(&mut self) -> Option<String> {
let idx = self.selected_suggestion?;
self.suggestions
.get(idx)
.map(|p| p.to_string_lossy().to_string())
}
/// Recompute `suggestions` based on the current `input`. No-op for
/// non-path prompts. Errors (directory unreadable, etc.) silently
/// produce an empty list.
pub fn refresh_suggestions(&mut self) {
if !self.is_path_kind() {
self.suggestions.clear();
self.selected_suggestion = None;
return;
}
const MAX_SUGGESTIONS: usize = 12;
let (parent, filter) = split_path_for_browse(&self.input);
let mut out: Vec<std::path::PathBuf> = Vec::new();
if let Ok(read) = std::fs::read_dir(&parent) {
for entry in read.flatten() {
let Ok(ft) = entry.file_type() else {
continue;
};
if !ft.is_dir() {
continue;
}
let name = entry.file_name();
let name_str = name.to_string_lossy();
// Skip dotfiles unless the filter explicitly asks for
// them (typed `.` as the prefix).
if name_str.starts_with('.') && !filter.starts_with('.') {
continue;
}
if !name_str.to_lowercase().starts_with(&filter.to_lowercase()) {
continue;
}
out.push(entry.path());
}
}
out.sort_by(|a, b| {
a.file_name()
.map(|s| s.to_string_lossy().to_lowercase())
.cmp(&b.file_name().map(|s| s.to_string_lossy().to_lowercase()))
});
out.truncate(MAX_SUGGESTIONS);
self.suggestions = out;
// Keep focus if it's still a valid index, otherwise drop it.
if let Some(i) = self.selected_suggestion
&& i >= self.suggestions.len()
{
self.selected_suggestion = None;
}
}
pub fn move_left(&mut self) {
// Motion keys mean "I want to place my caret within the
// seed" — cancel the select-all-on-first-type flag, but
// keep the seed contents.
self.cancel_select_all();
if self.cursor == 0 {
return;
}
self.cursor = self.input[..self.cursor]
.char_indices()
.next_back()
.map(|(i, _)| i)
.unwrap_or(0);
}
pub fn move_right(&mut self) {
self.cancel_select_all();
if self.cursor >= self.input.len() {
return;
}
let step = self.input[self.cursor..]
.chars()
.next()
.map(char::len_utf8)
.unwrap_or(0);
self.cursor += step;
}
pub fn move_home(&mut self) {
self.cancel_select_all();
self.cursor = 0;
}
pub fn move_end(&mut self) {
self.cancel_select_all();
self.cursor = self.input.len();
}
/// 2026-08-08 — kill from caret to end of line (Ctrl+K /
/// readline convention). Complements `delete_word`/Ctrl+U
/// (kill to start) that already lived on `Prompt`.
pub fn kill_to_end(&mut self) {
self.cancel_select_all();
self.input.truncate(self.cursor);
self.refresh_suggestions();
}
/// 2026-08-08 — Alt+← / Ctrl+← — move caret one word left.
/// Word boundaries: whitespace-run + a non-whitespace run
/// (matches `delete_word`).
pub fn move_word_left(&mut self) {
self.cancel_select_all();
if self.cursor == 0 {
return;
}
let head = &self.input[..self.cursor];
let trimmed = head.trim_end_matches(char::is_whitespace);
let cut = trimmed
.char_indices()
.rev()
.find(|&(_, c)| c.is_whitespace())
.map(|(i, c)| i + c.len_utf8())
.unwrap_or(0);
self.cursor = cut;
}
/// 2026-08-08 — Alt+→ / Ctrl+→ — move caret one word right.
pub fn move_word_right(&mut self) {
self.cancel_select_all();
if self.cursor >= self.input.len() {
return;
}
let tail = &self.input[self.cursor..];
// Skip leading whitespace.
let mut off = 0;
for (i, c) in tail.char_indices() {
if c.is_whitespace() {
off = i + c.len_utf8();
} else {
break;
}
}
// Then skip the word run.
let rest = &tail[off..];
for (i, c) in rest.char_indices() {
if c.is_whitespace() {
self.cursor += off + i;
return;
}
}
self.cursor = self.input.len();
}
/// Caret column for rendering (chars before the cursor).
pub fn caret_col(&self) -> usize {
self.input[..self.cursor].chars().count()
}
}
/// Resolve the user's typed path into `(parent_dir, filename_prefix)`
/// for live directory browsing. Tilde expansion happens here.
///
/// Examples (assuming `$HOME = /Users/chris`):
/// `""` ⇒ ($HOME, "" )
/// `"~"` ⇒ ($HOME, "" )
/// `"~/Pro"` ⇒ ($HOME, "Pro" )
/// `"~/Projects"` ⇒ ($HOME, "Projects")
/// `"~/Projects/"` ⇒ ($HOME/Projects, "" )
/// `"/Users/chris/Pr"` ⇒ ("/Users/chris", "Pr" )
/// `"foo"` ⇒ (PWD, "foo" )
fn split_path_for_browse(input: &str) -> (std::path::PathBuf, String) {
let home = std::env::var_os("HOME")
.or_else(|| std::env::var_os("USERPROFILE"))
.map(std::path::PathBuf::from);
// Empty / "~" — browse $HOME.
if input.is_empty() || input == "~" {
return (
home.unwrap_or_else(|| std::env::current_dir().unwrap_or_default()),
String::new(),
);
}
// Tilde expansion: "~/X" → "$HOME/X". Anything else stays literal.
let expanded: std::path::PathBuf = if let Some(rest) = input.strip_prefix("~/") {
match &home {
Some(h) => h.join(rest),
None => std::path::PathBuf::from(input),
}
} else {
std::path::PathBuf::from(input)
};
// Trailing slash ⇒ treat the whole path as parent, empty filter.
if input.ends_with('/') {
return (expanded, String::new());
}
// Split into parent dir + last segment (the filter).
let parent = expanded
.parent()
.map(std::path::PathBuf::from)
.unwrap_or_else(|| std::path::PathBuf::from("."));
let filter = expanded
.file_name()
.map(|s| s.to_string_lossy().to_string())
.unwrap_or_default();
// If the typed path is relative (no leading `/` or `~/`), resolve
// against PWD so suggestions make sense.
let parent = if parent.is_relative() {
std::env::current_dir().unwrap_or_default().join(parent)
} else {
parent
};
(parent, filter)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn edits_and_caret() {
let mut p = Prompt::new(PromptKind::GitCommit, "Commit");
for c in "fix the bug".chars() {
p.insert_char(c);
}
assert_eq!(p.input, "fix the bug");
assert_eq!(p.caret_col(), 11);
p.delete_word();
assert_eq!(p.input, "fix the ");
p.backspace();
assert_eq!(p.input, "fix the");
p.move_home();
p.move_right();
p.insert_char('!');
assert_eq!(p.input, "f!ix the");
}
#[test]
fn utf8_safe() {
let mut p = Prompt::new(PromptKind::GitCommit, "x");
for c in "héllo→".chars() {
p.insert_char(c);
}
p.backspace();
assert_eq!(p.input, "héllo");
p.move_left();
p.backspace();
assert_eq!(p.input, "hélo");
}
#[test]
fn seeded_select_all_first_type_replaces() {
// R7 vscode-mouse F5: browser navigate prompt seeded with
// current URL. First typed char must replace the seed
// (Chrome URL-bar behavior).
let mut p = Prompt::seeded_select_all(
PromptKind::BrowserNavigate,
"Navigate to",
"https://old.example.com/page",
);
assert!(p.select_all_on_first_type);
p.insert_char('a');
assert_eq!(p.input, "a");
assert!(!p.select_all_on_first_type);
// Subsequent typing appends normally.
for c in "bc".chars() {
p.insert_char(c);
}
assert_eq!(p.input, "abc");
}
#[test]
fn seeded_select_all_paste_replaces() {
// First paste also counts as first-type and replaces.
let mut p = Prompt::seeded_select_all(
PromptKind::BrowserNavigate,
"Navigate to",
"https://old.example.com",
);
p.insert_str("https://new.example.com/x");
assert_eq!(p.input, "https://new.example.com/x");
}
#[test]
fn seeded_select_all_arrow_keeps_seed() {
// Any caret motion means "I'm editing this, not
// overwriting" — cancel the flag but keep the seed.
let seed = "https://old.example.com";
let mut p = Prompt::seeded_select_all(PromptKind::BrowserNavigate, "Navigate to", seed);
p.move_left();
assert!(!p.select_all_on_first_type);
assert_eq!(p.input, seed);
p.insert_char('!');
// Character inserted at (len-1), before the trailing 'm'.
assert_eq!(p.input, format!("{}!m", &seed[..seed.len() - 1]));
}
#[test]
fn seeded_select_all_backspace_keeps_seed_edits() {
// Backspace also means "I'm editing" — remove one char, keep
// the rest.
let seed = "https://old.example.com";
let mut p = Prompt::seeded_select_all(PromptKind::BrowserNavigate, "Navigate to", seed);
p.backspace();
assert!(!p.select_all_on_first_type);
assert_eq!(p.input, &seed[..seed.len() - 1]);
}
#[test]
fn is_path_kind_only_addworkspace() {
assert!(Prompt::new(PromptKind::AddWorkspace, "").is_path_kind());
assert!(!Prompt::new(PromptKind::GitCommit, "").is_path_kind());
assert!(!Prompt::new(PromptKind::Find, "").is_path_kind());
}
#[test]
fn non_path_kinds_have_no_suggestions() {
let mut p = Prompt::new(PromptKind::GitCommit, "");
p.insert_char('f');
p.insert_char('o');
p.insert_char('o');
assert!(p.suggestions.is_empty());
}
#[test]
fn kill_to_end_trims_from_caret() {
let mut p = Prompt::new(PromptKind::GitCommit, "");
for c in "hello world".chars() {
p.insert_char(c);
}
p.cursor = 5;
p.kill_to_end();
assert_eq!(p.input, "hello");
assert_eq!(p.cursor, 5);
}
#[test]
fn move_word_left_walks_over_whitespace_then_word() {
let mut p = Prompt::new(PromptKind::GitCommit, "");
for c in "one two three".chars() {
p.insert_char(c);
}
// Cursor at end.
assert_eq!(p.cursor, 13);
p.move_word_left();
assert_eq!(p.cursor, 8); // start of "three"
p.move_word_left();
assert_eq!(p.cursor, 4); // start of "two"
p.move_word_left();
assert_eq!(p.cursor, 0);
p.move_word_left();
assert_eq!(p.cursor, 0);
}
#[test]
fn move_word_right_walks_to_next_word_end() {
let mut p = Prompt::new(PromptKind::GitCommit, "");
for c in "one two three".chars() {
p.insert_char(c);
}
p.cursor = 0;
p.move_word_right();
assert_eq!(p.cursor, 3); // end of "one"
p.move_word_right();
assert_eq!(p.cursor, 7); // end of "two"
p.move_word_right();
assert_eq!(p.cursor, 13);
}
#[test]
fn insert_str_at_caret_moves_cursor_and_scrubs_newlines() {
let mut p = Prompt::new(PromptKind::GitCommit, "");
p.insert_str("./bin/multi.sh");
assert_eq!(p.input, "./bin/multi.sh");
assert_eq!(p.cursor, 14);
// A pasted multi-line blob collapses newlines to spaces.
let mut p2 = Prompt::new(PromptKind::GitCommit, "");
p2.insert_str("one\ntwo\rthree");
assert_eq!(p2.input, "one two three");
assert_eq!(p2.cursor, 13);
// Insert at the middle preserves surrounding text.
let mut p3 = Prompt::new(PromptKind::GitCommit, "");
p3.insert_char('a');
p3.insert_char('c');
p3.cursor = 1;
p3.insert_str("XYZ");
assert_eq!(p3.input, "aXYZc");
assert_eq!(p3.cursor, 4);
}
#[test]
fn split_path_empty_is_home_no_filter() {
let (parent, filter) = split_path_for_browse("");
// Either $HOME or PWD — at least non-empty.
assert!(parent.exists() || parent.to_string_lossy().is_empty().not());
assert_eq!(filter, "");
}
#[test]
fn split_path_trailing_slash_treats_whole_as_parent() {
let (parent, filter) = split_path_for_browse("/tmp/");
assert_eq!(parent, std::path::PathBuf::from("/tmp"));
assert_eq!(filter, "");
}
// Hardcodes a Unix-shape path (`/tmp/myProj`) — on Windows
// `PathBuf::from("/tmp/myProj").parent()` is `/`, not `/tmp`,
// because the path is absolute-with-implicit-root there.
// Function itself is cross-platform; only the assertion is
// Unix-specific. See tests below for the Windows variant.
#[cfg(unix)]
#[test]
fn split_path_extracts_prefix() {
let (parent, filter) = split_path_for_browse("/tmp/myProj");
assert_eq!(parent, std::path::PathBuf::from("/tmp"));
assert_eq!(filter, "myProj");
}
#[cfg(windows)]
#[test]
fn split_path_extracts_prefix_windows() {
let (parent, filter) = split_path_for_browse(r"C:\tmp\myProj");
assert_eq!(parent, std::path::PathBuf::from(r"C:\tmp"));
assert_eq!(filter, "myProj");
}
// Uses `$HOME` — on Windows the function falls back to
// `$USERPROFILE`. Split into per-platform tests so each sets
// the right env var and asserts against a valid platform path.
#[cfg(unix)]
#[test]
fn split_path_tilde_expansion() {
// Serialize env mutation across test modules; EnvGuard
// restores HOME on scope exit (panic-safe).
let _lk = crate::test_env_lock()
.lock()
.unwrap_or_else(|e| e.into_inner());
let _home = crate::EnvGuard::set("HOME", "/Users/x");
let (parent, filter) = split_path_for_browse("~/Proj");
assert_eq!(parent, std::path::PathBuf::from("/Users/x"));
assert_eq!(filter, "Proj");
}
#[cfg(windows)]
#[test]
fn split_path_tilde_expansion_windows() {
// Windows: function falls back to USERPROFILE when HOME isn't set.
// EnvGuard restores both env vars on scope exit, panic-safe.
let _lk = crate::test_env_lock()
.lock()
.unwrap_or_else(|e| e.into_inner());
let _up = crate::EnvGuard::set("USERPROFILE", r"C:\Users\x");
let _home = crate::EnvGuard::remove("HOME");
let (parent, filter) = split_path_for_browse("~/Proj");
assert_eq!(parent, std::path::PathBuf::from(r"C:\Users\x"));
assert_eq!(filter, "Proj");
}
// Helper for `is_empty().not()` in the test above.
trait NotExt {
fn not(self) -> bool;
}
impl NotExt for bool {
fn not(self) -> bool {
!self
}
}
}