@sagmans/dsh-tui 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (200) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +270 -68
  3. package/lib/agent/present.js +1 -1
  4. package/lib/agent/present.js.map +1 -1
  5. package/lib/agent/prompt-history.d.ts.map +1 -1
  6. package/lib/agent/prompt-history.js +5 -3
  7. package/lib/agent/prompt-history.js.map +1 -1
  8. package/lib/agent/status.d.ts +1 -1
  9. package/lib/cards.d.ts +83 -13
  10. package/lib/cards.d.ts.map +1 -1
  11. package/lib/cards.js +96 -28
  12. package/lib/cards.js.map +1 -1
  13. package/lib/export.d.ts +3 -3
  14. package/lib/export.d.ts.map +1 -1
  15. package/lib/export.js +23 -13
  16. package/lib/export.js.map +1 -1
  17. package/lib/fold-cursor.d.ts +12 -5
  18. package/lib/fold-cursor.d.ts.map +1 -1
  19. package/lib/fold-cursor.js +16 -5
  20. package/lib/fold-cursor.js.map +1 -1
  21. package/lib/gates.d.ts.map +1 -1
  22. package/lib/gates.js +42 -9
  23. package/lib/gates.js.map +1 -1
  24. package/lib/index.d.ts.map +1 -1
  25. package/lib/index.js +459 -72
  26. package/lib/index.js.map +1 -1
  27. package/lib/injection.d.ts +9 -0
  28. package/lib/injection.d.ts.map +1 -0
  29. package/lib/injection.js +128 -0
  30. package/lib/injection.js.map +1 -0
  31. package/lib/input/actions.d.ts +19 -2
  32. package/lib/input/actions.d.ts.map +1 -1
  33. package/lib/input/actions.js +57 -11
  34. package/lib/input/actions.js.map +1 -1
  35. package/lib/input/cancel.d.ts +55 -0
  36. package/lib/input/cancel.d.ts.map +1 -0
  37. package/lib/input/cancel.js +47 -0
  38. package/lib/input/cancel.js.map +1 -0
  39. package/lib/input/completion.d.ts +5 -2
  40. package/lib/input/completion.d.ts.map +1 -1
  41. package/lib/input/completion.js +79 -4
  42. package/lib/input/completion.js.map +1 -1
  43. package/lib/input/file-search.d.ts +105 -0
  44. package/lib/input/file-search.d.ts.map +1 -0
  45. package/lib/input/file-search.js +665 -0
  46. package/lib/input/file-search.js.map +1 -0
  47. package/lib/input/fuzzy.d.ts +42 -0
  48. package/lib/input/fuzzy.d.ts.map +1 -0
  49. package/lib/input/fuzzy.js +289 -0
  50. package/lib/input/fuzzy.js.map +1 -0
  51. package/lib/input/keymap.d.ts +3 -1
  52. package/lib/input/keymap.d.ts.map +1 -1
  53. package/lib/input/keymap.js +14 -3
  54. package/lib/input/keymap.js.map +1 -1
  55. package/lib/input/match.d.ts +12 -4
  56. package/lib/input/match.d.ts.map +1 -1
  57. package/lib/input/match.js +50 -51
  58. package/lib/input/match.js.map +1 -1
  59. package/lib/input/submission.d.ts +10 -0
  60. package/lib/input/submission.d.ts.map +1 -1
  61. package/lib/input/submission.js +7 -6
  62. package/lib/input/submission.js.map +1 -1
  63. package/lib/keys-command.d.ts +19 -3
  64. package/lib/keys-command.d.ts.map +1 -1
  65. package/lib/keys-command.js +34 -31
  66. package/lib/keys-command.js.map +1 -1
  67. package/lib/settings-notice.d.ts +5 -0
  68. package/lib/settings-notice.d.ts.map +1 -1
  69. package/lib/settings-notice.js +9 -7
  70. package/lib/settings-notice.js.map +1 -1
  71. package/lib/stash/paths.d.ts +8 -8
  72. package/lib/stash/paths.d.ts.map +1 -1
  73. package/lib/stash/paths.js +19 -18
  74. package/lib/stash/paths.js.map +1 -1
  75. package/lib/stash/schema.d.ts +11 -12
  76. package/lib/stash/schema.d.ts.map +1 -1
  77. package/lib/stash/schema.js +10 -29
  78. package/lib/stash/schema.js.map +1 -1
  79. package/lib/stash/store.js +10 -10
  80. package/lib/stash/store.js.map +1 -1
  81. package/lib/stash.d.ts +37 -6
  82. package/lib/stash.d.ts.map +1 -1
  83. package/lib/stash.js +93 -36
  84. package/lib/stash.js.map +1 -1
  85. package/lib/terminal/external-editor.d.ts +93 -0
  86. package/lib/terminal/external-editor.d.ts.map +1 -0
  87. package/lib/terminal/external-editor.js +263 -0
  88. package/lib/terminal/external-editor.js.map +1 -0
  89. package/lib/terminal/host-writes.d.ts +39 -0
  90. package/lib/terminal/host-writes.d.ts.map +1 -0
  91. package/lib/terminal/host-writes.js +136 -0
  92. package/lib/terminal/host-writes.js.map +1 -0
  93. package/lib/terminal/signals.d.ts +25 -0
  94. package/lib/terminal/signals.d.ts.map +1 -0
  95. package/lib/terminal/signals.js +39 -0
  96. package/lib/terminal/signals.js.map +1 -0
  97. package/lib/terminal/warning-screen.d.ts +19 -1
  98. package/lib/terminal/warning-screen.d.ts.map +1 -1
  99. package/lib/terminal/warning-screen.js +37 -1
  100. package/lib/terminal/warning-screen.js.map +1 -1
  101. package/lib/terminal-text.d.ts +72 -0
  102. package/lib/terminal-text.d.ts.map +1 -0
  103. package/lib/terminal-text.js +603 -0
  104. package/lib/terminal-text.js.map +1 -0
  105. package/lib/text.d.ts +45 -6
  106. package/lib/text.d.ts.map +1 -1
  107. package/lib/text.js +106 -46
  108. package/lib/text.js.map +1 -1
  109. package/lib/theme-command.d.ts +7 -4
  110. package/lib/theme-command.d.ts.map +1 -1
  111. package/lib/theme-command.js +32 -12
  112. package/lib/theme-command.js.map +1 -1
  113. package/lib/theme-files.d.ts +110 -0
  114. package/lib/theme-files.d.ts.map +1 -0
  115. package/lib/theme-files.js +352 -0
  116. package/lib/theme-files.js.map +1 -0
  117. package/lib/theme-schema.d.ts +121 -0
  118. package/lib/theme-schema.d.ts.map +1 -0
  119. package/lib/theme-schema.js +87 -0
  120. package/lib/theme-schema.js.map +1 -0
  121. package/lib/theme-settings.d.ts +43 -10
  122. package/lib/theme-settings.d.ts.map +1 -1
  123. package/lib/theme-settings.js +103 -43
  124. package/lib/theme-settings.js.map +1 -1
  125. package/lib/theme-tokens.d.ts +39 -7
  126. package/lib/theme-tokens.d.ts.map +1 -1
  127. package/lib/theme-tokens.js +96 -13
  128. package/lib/theme-tokens.js.map +1 -1
  129. package/lib/theme.d.ts +24 -2
  130. package/lib/theme.d.ts.map +1 -1
  131. package/lib/theme.js +49 -6
  132. package/lib/theme.js.map +1 -1
  133. package/lib/tool-display.d.ts +57 -0
  134. package/lib/tool-display.d.ts.map +1 -0
  135. package/lib/tool-display.js +51 -0
  136. package/lib/tool-display.js.map +1 -0
  137. package/lib/transcript.d.ts +28 -0
  138. package/lib/transcript.d.ts.map +1 -1
  139. package/lib/transcript.js +126 -37
  140. package/lib/transcript.js.map +1 -1
  141. package/lib/ui/diff.d.ts +49 -0
  142. package/lib/ui/diff.d.ts.map +1 -0
  143. package/lib/ui/diff.js +208 -0
  144. package/lib/ui/diff.js.map +1 -0
  145. package/lib/ui/dock.d.ts.map +1 -1
  146. package/lib/ui/dock.js +9 -6
  147. package/lib/ui/dock.js.map +1 -1
  148. package/lib/ui/editor.d.ts.map +1 -1
  149. package/lib/ui/editor.js +4 -2
  150. package/lib/ui/editor.js.map +1 -1
  151. package/lib/ui/frame.d.ts +16 -5
  152. package/lib/ui/frame.d.ts.map +1 -1
  153. package/lib/ui/frame.js +32 -13
  154. package/lib/ui/frame.js.map +1 -1
  155. package/lib/ui/keymap-picker.d.ts +16 -0
  156. package/lib/ui/keymap-picker.d.ts.map +1 -0
  157. package/lib/ui/keymap-picker.js +41 -0
  158. package/lib/ui/keymap-picker.js.map +1 -0
  159. package/lib/ui/layout.d.ts +33 -0
  160. package/lib/ui/layout.d.ts.map +1 -0
  161. package/lib/ui/layout.js +33 -0
  162. package/lib/ui/layout.js.map +1 -0
  163. package/lib/ui/markdown.d.ts +25 -3
  164. package/lib/ui/markdown.d.ts.map +1 -1
  165. package/lib/ui/markdown.js +12 -8
  166. package/lib/ui/markdown.js.map +1 -1
  167. package/lib/ui/picker-card.d.ts +42 -0
  168. package/lib/ui/picker-card.d.ts.map +1 -0
  169. package/lib/ui/picker-card.js +148 -0
  170. package/lib/ui/picker-card.js.map +1 -0
  171. package/lib/ui/picker.d.ts +40 -2
  172. package/lib/ui/picker.d.ts.map +1 -1
  173. package/lib/ui/picker.js +50 -6
  174. package/lib/ui/picker.js.map +1 -1
  175. package/lib/ui/prompt.d.ts +10 -2
  176. package/lib/ui/prompt.d.ts.map +1 -1
  177. package/lib/ui/prompt.js +21 -2
  178. package/lib/ui/prompt.js.map +1 -1
  179. package/lib/ui/rows.d.ts +8 -6
  180. package/lib/ui/rows.d.ts.map +1 -1
  181. package/lib/ui/rows.js +10 -18
  182. package/lib/ui/rows.js.map +1 -1
  183. package/lib/ui/stash-picker.d.ts +2 -2
  184. package/lib/ui/stash-picker.d.ts.map +1 -1
  185. package/lib/ui/stash-picker.js +4 -4
  186. package/lib/ui/stash-picker.js.map +1 -1
  187. package/lib/ui/status.d.ts.map +1 -1
  188. package/lib/ui/status.js +18 -16
  189. package/lib/ui/status.js.map +1 -1
  190. package/lib/ui/theme-picker.d.ts +18 -0
  191. package/lib/ui/theme-picker.d.ts.map +1 -0
  192. package/lib/ui/theme-picker.js +68 -0
  193. package/lib/ui/theme-picker.js.map +1 -0
  194. package/lib/ui/view.d.ts +146 -22
  195. package/lib/ui/view.d.ts.map +1 -1
  196. package/lib/ui/view.js +461 -154
  197. package/lib/ui/view.js.map +1 -1
  198. package/package.json +3 -1
  199. package/themes/deepseek-blue.yaml +183 -0
  200. package/themes/violet-orbit.yaml +178 -0
package/lib/stash.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"stash.js","sourceRoot":"","sources":["../src/stash.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,EAAE;AACF,iFAAiF;AACjF,4EAA4E;AAC5E,2EAA2E;AAC3E,+EAA+E;AAC/E,2CAA2C;AAE3C,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAA;AACzD,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAA;AACrD,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAmB,MAAM,kBAAkB,CAAA;AAEnF,OAAO,EACL,cAAc,EACd,2BAA2B,GAG5B,MAAM,kBAAkB,CAAA;AAEzB,MAAM,sBA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ClE,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,KAAK,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAA;YAChF,MAAM,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,cAAc,EAAE,CAAA;YAC9C,IAAI,UAAU,KAAK,SAAS,EAAE,CAAC;gBAC7B,MAAM,UAAU,GAAG,UAAU,CAAC,UAAU,CAAC,CAAC,CAAC,iCAAiC,CAAC,CAAC,CAAC,EAAE,CAAA;gBACjF,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,wBAAwB,IAAI,UAAU,CAAC,IAAI,GAAG,UAAU,EAAE,CAAC,CAAA;YACjF,CAAC;QACH,CAAC;QACD,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAA;IACpB,CAAC;CACF"}
@@ -0,0 +1,93 @@
1
+ /**
2
+ * Where a reader's editor is configured, most specific first.
3
+ *
4
+ * VISUAL is the full-screen editor and EDITOR the line one, which is the
5
+ * distinction a surface that gives up the whole screen cares about; a reader
6
+ * who set only one of them still gets it.
7
+ */
8
+ export declare const EDITOR_ENV_KEYS: readonly ["VISUAL", "EDITOR"];
9
+ /** A draft larger than this is left where it is rather than handed to the bar. */
10
+ export declare const MAX_DRAFT_BYTES = 1048576;
11
+ /**
12
+ * One configured command line as argv, or undefined when it names nothing.
13
+ *
14
+ * A reader writes an editor the way a shell would take it — `code --wait`,
15
+ * `emacsclient -t` — so the line is split the way a shell would split it:
16
+ * quotes group, and nothing else is special. No shell ever sees the result,
17
+ * because an environment value is data and a shell would execute a typo. An
18
+ * unterminated quote takes the rest of the line rather than refusing the whole
19
+ * binding: a missing quote should not leave the reader with no editor at all.
20
+ */
21
+ export declare function parseEditorCommand(value: string): readonly string[] | undefined;
22
+ /** The editor this environment configures, or undefined when none is usable. */
23
+ export declare function resolveEditorCommand(env?: NodeJS.ProcessEnv): readonly string[] | undefined;
24
+ /**
25
+ * What this module needs from the surface while a child owns the terminal.
26
+ *
27
+ * `suspend` and `resume` are the whole reason the handoff is safe — the
28
+ * alternate screen has to leave before the child starts and be asked for again
29
+ * after it ends — and only the surface owns that object. `notice` is how a
30
+ * refusal or a failure reaches the reader, who is looking at the transcript.
31
+ */
32
+ export interface EditorTerminalHost {
33
+ suspend(): void;
34
+ resume(): void;
35
+ notice(message: string): void;
36
+ }
37
+ /** The slice of a spawned child this module waits on. */
38
+ export interface EditorChild {
39
+ on(event: 'error', listener: (error: Error) => void): void;
40
+ on(event: 'exit', listener: (code: number | null, signal: string | null) => void): void;
41
+ }
42
+ export interface EditorSpawnOptions {
43
+ readonly stdio: 'inherit';
44
+ readonly cwd: string;
45
+ readonly env: NodeJS.ProcessEnv;
46
+ }
47
+ /** The one process call this module makes, so a spec can drive it without a terminal. */
48
+ export type EditorSpawn = (file: string, args: readonly string[], options: EditorSpawnOptions) => EditorChild;
49
+ /** How the handoff runs; every part a spec would otherwise have to fake is overridable. */
50
+ export interface ExternalEditorOptions {
51
+ readonly env?: NodeJS.ProcessEnv | undefined;
52
+ /** Where the scratch directory is made; tests keep theirs out of the real tmpdir. */
53
+ readonly tempRoot?: string | undefined;
54
+ readonly spawn?: EditorSpawn | undefined;
55
+ }
56
+ /**
57
+ * The reader's editor, opened over one draft.
58
+ *
59
+ * Every failure is reported through the host and answered with `undefined`
60
+ * ("keep what the bar had") rather than thrown, because the caller is a key
61
+ * press with nowhere to put an error.
62
+ */
63
+ export declare class ExternalEditor {
64
+ private readonly host;
65
+ private readonly env;
66
+ private readonly tempRoot;
67
+ private readonly spawn;
68
+ /** Whether a child holds the terminal; a second handoff would stop it twice. */
69
+ private running;
70
+ constructor(host: EditorTerminalHost, options?: ExternalEditorOptions);
71
+ /** Edit `text` in the reader's editor, and return what was saved, or undefined to keep the bar. */
72
+ edit(text: string): Promise<string | undefined>;
73
+ /**
74
+ * What the editor saved, read through one handle.
75
+ *
76
+ * The file is opened without following a link and read through that same
77
+ * handle, so a replacement between a check and a read cannot slip past it, a
78
+ * fifo left in the draft's place cannot block the surface, and the read stops
79
+ * one byte past the cap so a file that grows while it is read cannot exhaust
80
+ * memory.
81
+ */
82
+ private readDraft;
83
+ /**
84
+ * Run the editor over one file, and report only whether it could be started.
85
+ *
86
+ * A non-zero exit is not a failure: an editor that refused to save its buffer
87
+ * already told the reader why, and whatever it did save is what they meant to
88
+ * keep. A child that never started emits `error` and no `exit`, so either one
89
+ * settling the wait is the answer.
90
+ */
91
+ private run;
92
+ }
93
+ //# sourceMappingURL=external-editor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"external-editor.d.ts","sourceRoot":"","sources":["../../src/terminal/external-editor.ts"],"names":[],"mappings":"AAmBA;;;;;;GAMG;AACH,eAAO,MAAM,eAAe,+BAAgC,CAAA;AAS5D,kFAAkF;AAClF,eAAO,MAAM,eAAe,UAAY,CAAA;AAuBxC;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,GAAG,SAAS,CA2B/E;AAED,gFAAgF;AAChF,wBAAgB,oBAAoB,CAAC,GAAG,GAAE,MAAM,CAAC,UAAwB,GAAG,SAAS,MAAM,EAAE,GAAG,SAAS,CAQxG;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,kBAAkB;IACjC,OAAO,IAAI,IAAI,CAAA;IACf,MAAM,IAAI,IAAI,CAAA;IACd,MAAM,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAA;CAC9B;AAED,yDAAyD;AACzD,MAAM,WAAW,WAAW;IAC1B,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,GAAG,IAAI,CAAA;IAC1D,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,EAAE,MAAM,E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needs the terminal itself. The surface gives the screen up, waits for the
5
+ // child, and takes it back, the same handoff a shell performs for a commit
6
+ // message. Only the terminal side is delegated — the caller owns the alternate
7
+ // screen, so this module runs and is tested without one.
8
+ //
9
+ // Two invariants keep that handoff safe, and both live with the code that would
10
+ // break them: the child is always awaited before anything restores the terminal,
11
+ // and nothing in this surface writes to the tty while the child owns it.
12
+ import { spawn } from 'node:child_process';
13
+ import { constants } from 'node:fs';
14
+ import { chmod, mkdtemp, open, rm, writeFile } from 'node:fs/promises';
15
+ import { tmpdir } from 'node:os';
16
+ import { join } from 'node:path';
17
+ import { stripControlCharacters } from "../text.js";
18
+ /**
19
+ * Where a reader's editor is configured, most specific first.
20
+ *
21
+ * VISUAL is the full-screen editor and EDITOR the line one, which is the
22
+ * distinction a surface that gives up the whole screen cares about; a reader
23
+ * who set only one of them still gets it.
24
+ */
25
+ export const EDITOR_ENV_KEYS = ['VISUAL', 'EDITOR'];
26
+ /** The buffer's name, so the editor's filetype, syntax, and wrap settings see prose. */
27
+ const DRAFT_FILE_NAME = 'draft.md';
28
+ /** A directory the reader's draft is written into must not be readable by others. */
29
+ const DRAFT_DIR_MODE = 0o700;
30
+ const DRAFT_FILE_MODE = 0o600;
31
+ const DRAFT_DIR_PREFIX = 'dsh-tui-draft-';
32
+ /** A draft larger than this is left where it is rather than handed to the bar. */
33
+ export const MAX_DRAFT_BYTES = 1_048_576;
34
+ /** The same budget as a word, so the notice reads as a size and cannot drift from it. */
35
+ const MAX_DRAFT_LABEL = `${Math.round(MAX_DRAFT_BYTES / 1024 / 1024)} MiB`;
36
+ const NO_EDITOR_MESSAGE = 'no editor configured: set $VISUAL or $EDITOR to open the draft in one';
37
+ const launchFailureMessage = (command, error) => `could not start ${command}: ${error.message}`;
38
+ const useFailureMessage = (error) => `could not use the edited draft: ${error instanceof Error ? error.message : 'unknown error'}`;
39
+ const tooLargeMessage = (file) => `the edited draft is larger than ${MAX_DRAFT_LABEL}; it was left at ${file}`;
40
+ const NOT_A_FILE_MESSAGE = 'the edited draft is no longer a plain file; nothing was taken back';
41
+ const retainedMessage = (directory) => `could not remove the scratch directory; the draft is still at ${directory}`;
42
+ const resumeFailureMessage = (error) => `the screen did not come back cleanly: ${error instanceof Error ? error.message : 'unknown error'}`;
43
+ /** The quote a command line is currently inside, if any. */
44
+ const QUOTES = new Set(["'", '"']);
45
+ /** Whitespace that separates one argument from the next. */
46
+ const SEPARATORS = new Set([' ', '\t', '\n', '\r']);
47
+ /**
48
+ * One configured command line as argv, or undefined when it names nothing.
49
+ *
50
+ * A reader writes an editor the way a shell would take it — `code --wait`,
51
+ * `emacsclient -t` — so the line is split the way a shell would split it:
52
+ * quotes group, and nothing else is special. No shell ever sees the result,
53
+ * because an environment value is data and a shell would execute a typo. An
54
+ * unterminated quote takes the rest of the line rather than refusing the whole
55
+ * binding: a missing quote should not leave the reader with no editor at all.
56
+ */
57
+ export function parseEditorCommand(value) {
58
+ const argv = [];
59
+ let token = '';
60
+ let started = false;
61
+ let quote;
62
+ for (const character of value) {
63
+ if (quote !== undefined) {
64
+ if (character === quote)
65
+ quote = undefined;
66
+ else
67
+ token += character;
68
+ continue;
69
+ }
70
+ if (QUOTES.has(character)) {
71
+ quote = character;
72
+ started = true;
73
+ continue;
74
+ }
75
+ if (SEPARATORS.has(character)) {
76
+ if (started && token !== '')
77
+ argv.push(token);
78
+ token = '';
79
+ started = false;
80
+ continue;
81
+ }
82
+ token += character;
83
+ started = true;
84
+ }
85
+ if (started && token !== '')
86
+ argv.push(token);
87
+ return argv.length === 0 ? undefined : argv;
88
+ }
89
+ /** The editor this environment configures, or undefined when none is usable. */
90
+ export function resolveEditorCommand(env = process.env) {
91
+ for (const name of EDITOR_ENV_KEYS) {
92
+ const configured = env[name];
93
+ if (configured === undefined)
94
+ continue;
95
+ const argv = parseEditorCommand(configured);
96
+ if (argv !== undefined)
97
+ return argv;
98
+ }
99
+ return undefined;
100
+ }
101
+ /**
102
+ * The real spawn, wrapped rather than passed.
103
+ *
104
+ * `child_process.spawn` carries overloads that do not narrow to a single
105
+ * callable signature, and a wrapper keeps the injectable seam honest about
106
+ * which call this module actually makes.
107
+ */
108
+ const SPAWN = (file, args, options) => spawn(file, [...args], options);
109
+ /**
110
+ * The reader's editor, opened over one draft.
111
+ *
112
+ * Every failure is reported through the host and answered with `undefined`
113
+ * ("keep what the bar had") rather than thrown, because the caller is a key
114
+ * press with nowhere to put an error.
115
+ */
116
+ export class ExternalEditor {
117
+ host;
118
+ env;
119
+ tempRoot;
120
+ spawn;
121
+ /** Whether a child holds the terminal; a second handoff would stop it twice. */
122
+ running = false;
123
+ constructor(host, options = {}) {
124
+ this.host = host;
125
+ this.env = options.env ?? process.env;
126
+ this.tempRoot = options.tempRoot ?? tmpdir();
127
+ this.spawn = options.spawn ?? SPAWN;
128
+ }
129
+ /** Edit `text` in the reader's editor, and return what was saved, or undefined to keep the bar. */
130
+ async edit(text) {
131
+ if (this.running)
132
+ return undefined;
133
+ const argv = resolveEditorCommand(this.env);
134
+ const command = argv?.[0];
135
+ if (argv === undefined || command === undefined) {
136
+ this.host.notice(NO_EDITOR_MESSAGE);
137
+ return undefined;
138
+ }
139
+ this.running = true;
140
+ let directory;
141
+ // A draft too large for the bar is left on disk rather than deleted with the
142
+ // scratch directory: a refusal must not also be a way to lose the work.
143
+ let keepDirectory = false;
144
+ // The screen goes before the first await, so no key can be read between the
145
+ // chord that asked for this and the child that owns the terminal. A stop that
146
+ // failed leaves the screen ours, so the flag behind it has to come back down:
147
+ // left up, this surface would suppress every later title and defer every exit.
148
+ try {
149
+ this.host.suspend();
150
+ }
151
+ catch (error) {
152
+ this.running = false;
153
+ this.host.notice(useFailureMessage(error));
154
+ return undefined;
155
+ }
156
+ try {
157
+ directory = await mkdtemp(join(this.tempRoot, DRAFT_DIR_PREFIX));
158
+ // mkdtemp makes the directory owner-only on POSIX; setting it here makes
159
+ // the guarantee this module's rather than the platform's.
160
+ await chmod(directory, DRAFT_DIR_MODE);
161
+ const file = join(directory, DRAFT_FILE_NAME);
162
+ await writeFile(file, text, { encoding: 'utf8', mode: DRAFT_FILE_MODE, flag: 'wx' });
163
+ const failure = await this.run(command, argv.slice(1), file);
164
+ if (failure !== undefined) {
165
+ this.host.notice(launchFailureMessage(command, failure));
166
+ return undefined;
167
+ }
168
+ const draft = await this.readDraft(file);
169
+ if (draft.kind === 'too-large') {
170
+ keepDirectory = true;
171
+ this.host.notice(tooLargeMessage(file));
172
+ return undefined;
173
+ }
174
+ if (draft.kind === 'not-a-file') {
175
+ this.host.notice(NOT_A_FILE_MESSAGE);
176
+ return undefined;
177
+ }
178
+ return draft.text;
179
+ }
180
+ catch (error) {
181
+ this.host.notice(useFailureMessage(error));
182
+ return undefined;
183
+ }
184
+ finally {
185
+ const scratch = directory;
186
+ if (scratch !== undefined && !keepDirectory) {
187
+ // Best effort, but not silent: a directory the reader believes was swept
188
+ // still holds what they typed, and only they can decide what to do with it.
189
+ await rm(scratch, { recursive: true, force: true }).catch(() => {
190
+ this.host.notice(retainedMessage(scratch));
191
+ });
192
+ }
193
+ // Cleared before the screen comes back, so a `resume` that throws cannot
194
+ // leave a surface that refuses every later handoff.
195
+ this.running = false;
196
+ // A resume that failed must not reject this promise: the caller is a key
197
+ // press with nobody to catch it, and the exit it deferred still has to run.
198
+ try {
199
+ this.host.resume();
200
+ }
201
+ catch (error) {
202
+ this.host.notice(resumeFailureMessage(error));
203
+ }
204
+ }
205
+ }
206
+ /**
207
+ * What the editor saved, read through one handle.
208
+ *
209
+ * The file is opened without following a link and read through that same
210
+ * handle, so a replacement between a check and a read cannot slip past it, a
211
+ * fifo left in the draft's place cannot block the surface, and the read stops
212
+ * one byte past the cap so a file that grows while it is read cannot exhaust
213
+ * memory.
214
+ */
215
+ async readDraft(file) {
216
+ const handle = await open(file, constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK);
217
+ try {
218
+ if (!(await handle.stat()).isFile())
219
+ return { kind: 'not-a-file' };
220
+ const buffer = Buffer.allocUnsafe(MAX_DRAFT_BYTES + 1);
221
+ let filled = 0;
222
+ while (filled < buffer.length) {
223
+ const { bytesRead } = await handle.read(buffer, filled, buffer.length - filled, filled);
224
+ if (bytesRead === 0)
225
+ break;
226
+ filled += bytesRead;
227
+ }
228
+ if (filled > MAX_DRAFT_BYTES)
229
+ return { kind: 'too-large' };
230
+ return { kind: 'text', text: stripControlCharacters(buffer.subarray(0, filled).toString('utf8')) };
231
+ }
232
+ finally {
233
+ await handle.close().catch(() => undefined);
234
+ }
235
+ }
236
+ /**
237
+ * Run the editor over one file, and report only whether it could be started.
238
+ *
239
+ * A non-zero exit is not a failure: an editor that refused to save its buffer
240
+ * already told the reader why, and whatever it did save is what they meant to
241
+ * keep. A child that never started emits `error` and no `exit`, so either one
242
+ * settling the wait is the answer.
243
+ */
244
+ run(command, args, file) {
245
+ return new Promise(resolve => {
246
+ const child = this.spawn(command, [...args, file], {
247
+ stdio: 'inherit',
248
+ cwd: process.cwd(),
249
+ env: this.env,
250
+ });
251
+ let settled = false;
252
+ const settle = (error) => {
253
+ if (settled)
254
+ return;
255
+ settled = true;
256
+ resolve(error);
257
+ };
258
+ child.on('error', error => settle(error));
259
+ child.on('exit', () => settle(undefined));
260
+ });
261
+ }
262
+ }
263
+ //# sourceMappingURL=external-editor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"external-editor.js","sourceRoot":"","sources":["../../src/terminal/external-editor.ts"],"names":[],"mappings":"AAAA,oDAAoD;AACpD,EAAE;AACF,4EAA4E;AAC5E,4EAA4E;AAC5E,2EAA2E;AAC3E,+EAA+E;AAC/E,yDAAyD;AACzD,EAAE;AACF,gFAAgF;AAChF,iFAAiF;AACjF,yEAAyE;AAEzE,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAA;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AACnC,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,kBAAk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AAC,CAAC,EAAE,MAAM,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,EAAE,CAAA;QACpG,CAAC;gBAAS,CAAC;YACT,MAAM,MAAM,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAA;QAC7C,CAAC;IACH,CAAC;IAED;;;;;;;OAOG;IACK,GAAG,CAAC,OAAe,EAAE,IAAuB,EAAE,IAAY;QAChE,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE;YAC3B,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,GAAG,IAAI,EAAE,IAAI,CAAC,EAAE;gBACjD,KAAK,EAAE,SAAS;gBAChB,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE;gBAClB,GAAG,EAAE,IAAI,CAAC,GAAG;aACd,CAAC,CAAA;YACF,IAAI,OAAO,GAAG,KAAK,CAAA;YACnB,MAAM,MAAM,GAAG,CAAC,KAAwB,EAAQ,EAAE;gBAChD,IAAI,OAAO;oBAAE,OAAM;gBACnB,OAAO,GAAG,IAAI,CAAA;gBACd,OAAO,CAAC,KAAK,CAAC,CAAA;YAChB,CAAC,CAAA;YACD,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,KAAK,CAAC,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAA;YACzC,KAAK,CAAC,EAAE,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAA;QAC3C,CAAC,CAAC,CAAA;IACJ,CAAC;CACF"}
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Keep the host's own writing off a screen the surface owns.
3
+ *
4
+ * The alternate screen is painted from a buffer the surface keeps, so text that
5
+ * arrives between frames is drawn over a frame the surface then believes is
6
+ * already on screen: the damage is skipped as unchanged and stays until
7
+ * something forces a full repaint. Warnings are deferred separately; this is the
8
+ * channel a library, a stray `console.log`, or an unhandled rejection report
9
+ * writes to directly. Text is held until the screen is given back, then written
10
+ * in the order it arrived, so a reader still gets the diagnostics — after the
11
+ * frame they would otherwise have ruined.
12
+ *
13
+ * The surface's own drawing goes through the terminal object, which is wrapped
14
+ * here: a write made inside that call passes through, and everything else waits.
15
+ */
16
+ /** One stream a host may write to without asking the surface. */
17
+ export interface HostWritable {
18
+ write(...args: unknown[]): unknown;
19
+ }
20
+ /** How much host text one stream may hold before the oldest is dropped. */
21
+ export declare const HOST_WRITE_LIMIT: number;
22
+ /** What a reader is told when the held text had to be trimmed. */
23
+ export declare const HOST_WRITE_DROPPED = "\u2026 host output dropped";
24
+ /** The streams a host reaches for when it writes without the surface's help. */
25
+ export declare const HOST_WRITE_TARGETS: readonly HostWritable[];
26
+ export interface HostWriteGuard {
27
+ /** Stop holding: later writes pass, and everything held is written out. */
28
+ release(): void;
29
+ }
30
+ export interface HostWriteOptions {
31
+ /** The channel the surface draws through; a write inside it must pass through. */
32
+ terminal: HostWritable;
33
+ /** The streams the host writes to directly. */
34
+ targets: readonly HostWritable[];
35
+ /** Per-stream hold budget; the oldest text is dropped past it. */
36
+ limit?: number;
37
+ }
38
+ export declare function holdHostWrites(options: HostWriteOptions): HostWriteGuard;
39
+ //# sourceMappingURL=host-writes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"host-writes.d.ts","sourceRoot":"","sources":["../../src/terminal/host-writes.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;GAcG;AAEH,iEAAiE;AACjE,MAAM,WAAW,YAAY;IAC3B,KAAK,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,OAAO,CAAA;CACnC;AAED,2EAA2E;AAC3E,eAAO,MAAM,gBAAgB,QAAY,CAAA;AAEzC,kEAAkE;AAClE,eAAO,MAAM,kBAAkB,+BAA0B,CAAA;AAEzD,gFAAgF;AAChF,eAAO,MAAM,kBAAkB,EAAE,SAAS,YAAY,EAAqC,CAAA;AAE3F,MAAM,WAAW,cAAc;IAC7B,2EAA2E;IAC3E,OAAO,IAAI,IAAI,CAAA;CAChB;AAED,MAAM,WAAW,gBAAgB;IAC/B,kFAAkF;IAClF,QAAQ,EAAE,YAAY,CAAA;IACtB,+CAA+C;IAC/C,OAAO,EAAE,SAAS,YAAY,EAAE,CAAA;IAChC,kEAAkE;IAClE,KAAK,CAAC,EAAE,MAAM,CAAA;CACf;AA4GD,wBAAgB,cAAc,CAAC,OAAO,EAAE,gBAAgB,GAAG,cAAc,CAyBxE"}
@@ -0,0 +1,136 @@
1
+ import { Buffer } from 'node:buffer';
2
+ /** How much host text one stream may hold before the oldest is dropped. */
3
+ export const HOST_WRITE_LIMIT = 64 * 1024;
4
+ /** What a reader is told when the held text had to be trimmed. */
5
+ export const HOST_WRITE_DROPPED = '… host output dropped';
6
+ /** The streams a host reaches for when it writes without the surface's help. */
7
+ export const HOST_WRITE_TARGETS = [process.stdout, process.stderr];
8
+ /**
9
+ * Replace a stream's write with one that holds text until release.
10
+ *
11
+ * The original is restored exactly as it was found — an own property stays an own
12
+ * property, an inherited one disappears again — so a host that patched the
13
+ * stream before this ran keeps its own seam.
14
+ */
15
+ function holdStream(target, held, isSurfaceWrite, limit) {
16
+ const own = Object.getOwnPropertyDescriptor(target, 'write');
17
+ const original = target.write;
18
+ target.write = function (...args) {
19
+ if (isSurfaceWrite())
20
+ return Reflect.apply(original, this, args);
21
+ const [chunk, encoding, callback] = args;
22
+ const text = typeof chunk === 'string'
23
+ ? chunk
24
+ : chunk instanceof Uint8Array
25
+ ? Buffer.from(chunk).toString('utf8')
26
+ : String(chunk);
27
+ held.chunks.push(text);
28
+ held.length += text.length;
29
+ while (held.length > limit && held.chunks.length > 1) {
30
+ held.length -= held.chunks.shift()?.length ?? 0;
31
+ held.dropped += 1;
32
+ }
33
+ if (typeof encoding === 'function')
34
+ encoding();
35
+ else if (typeof callback === 'function')
36
+ callback();
37
+ return true;
38
+ };
39
+ return {
40
+ original: (...args) => Reflect.apply(original, target, args),
41
+ restore: () => {
42
+ if (own === undefined)
43
+ delete target.write;
44
+ else
45
+ Object.defineProperty(target, 'write', own);
46
+ },
47
+ };
48
+ }
49
+ /**
50
+ * Mark every call on the terminal object as the surface's own, whatever method it is.
51
+ *
52
+ * A real terminal writes part of its protocol straight to the stream: the
53
+ * keyboard-protocol query, the bracketed-paste toggle, and the cursor moves all
54
+ * bypass the terminal's own `write`, so watching only `write` defers them to
55
+ * release — after the screen is gone, where the shell answers a query the
56
+ * surface no longer reads. A method that can suspend is left unmarked, because
57
+ * the mark would outlive its synchronous call and let host output through while
58
+ * it waits.
59
+ */
60
+ function markTerminalCalls(terminal, call) {
61
+ const keys = new Set();
62
+ for (let holder = terminal; holder !== null && holder !== Object.prototype; holder = Object.getPrototypeOf(holder)) {
63
+ for (const key of Reflect.ownKeys(holder)) {
64
+ if (key === 'constructor')
65
+ continue;
66
+ const descriptor = Object.getOwnPropertyDescriptor(holder, key);
67
+ if (descriptor !== undefined && typeof descriptor.value === 'function')
68
+ keys.add(key);
69
+ }
70
+ }
71
+ const own = new Map();
72
+ for (const key of keys) {
73
+ const method = terminal[key];
74
+ if (typeof method !== 'function' || Object.getPrototypeOf(method)?.constructor?.name !== 'Function')
75
+ continue;
76
+ const before = Object.getOwnPropertyDescriptor(terminal, key);
77
+ if (before !== undefined && !before.configurable && !before.writable)
78
+ continue;
79
+ own.set(key, before);
80
+ const wrapped = function (...args) {
81
+ call.depth += 1;
82
+ try {
83
+ return Reflect.apply(method, this, args);
84
+ }
85
+ finally {
86
+ call.depth -= 1;
87
+ }
88
+ };
89
+ Object.defineProperty(terminal, key, {
90
+ configurable: before?.configurable ?? true,
91
+ enumerable: before?.enumerable ?? false,
92
+ writable: before?.writable ?? true,
93
+ value: wrapped,
94
+ });
95
+ }
96
+ return () => {
97
+ for (const [key, before] of own) {
98
+ if (before === undefined)
99
+ delete terminal[key];
100
+ else
101
+ Object.defineProperty(terminal, key, before);
102
+ }
103
+ own.clear();
104
+ };
105
+ }
106
+ export function holdHostWrites(options) {
107
+ const limit = options.limit ?? HOST_WRITE_LIMIT;
108
+ const held = new Map();
109
+ for (const target of options.targets)
110
+ held.set(target, { chunks: [], length: 0, dropped: 0 });
111
+ const surface = { depth: 0 };
112
+ const restoreTerminal = markTerminalCalls(options.terminal, surface);
113
+ const streams = options.targets.map(target => holdStream(target, held.get(target), () => surface.depth > 0, limit));
114
+ let active = true;
115
+ return {
116
+ release() {
117
+ if (!active)
118
+ return;
119
+ active = false;
120
+ restoreTerminal();
121
+ for (const stream of streams)
122
+ stream.restore();
123
+ for (const [index, target] of options.targets.entries()) {
124
+ const writes = held.get(target);
125
+ if (writes === undefined || (writes.chunks.length === 0 && writes.dropped === 0))
126
+ continue;
127
+ const notice = writes.dropped === 0 ? '' : `${HOST_WRITE_DROPPED} (${writes.dropped} writes)\n`;
128
+ streams[index]?.original(notice + writes.chunks.join(''));
129
+ writes.chunks.length = 0;
130
+ writes.length = 0;
131
+ writes.dropped = 0;
132
+ }
133
+ },
134
+ };
135
+ }
136
+ //# sourceMappingURL=host-writes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"host-writes.js","sourceRoot":"","sources":["../../src/terminal/host-writes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAuBpC,2EAA2E;AAC3E,MAAM,CAAC,MAAM,gBAAgB,GAAG,EAAE,GAAG,IAAI,CAAA;AAEzC,kEAAkE;AAClE,MAAM,CAAC,MAAM,kBAAkB,GAAG,uBAAuB,CAAA;AAEzD,gFAAgF;AAChF,MAAM,CAAC,MAAM,kBAAkB,GAA4B,CAAC,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,CAAA;AA6B3F;;;;;;GAMG;AACH,SAAS,UAAU,CAAC,MAAoB,EAAE,IAAgB,EAAE,cAA6B,EAAE,KAAa;IACtG,MAAM,GAAG,GAAG,MAAM,CAAC,wBAAwB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC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,MAAM,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAA;gBACxB,MAAM,CAAC,MAAM,GAAG,CAAC,CAAA;gBACjB,MAAM,CAAC,OAAO,GAAG,CAAC,CAAA;YACpB,CAAC;QACH,CAAC;KACF,CAAA;AACH,CAAC"}
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Restore the terminal when the process is asked to end from outside.
3
+ *
4
+ * The surface owns the alternate screen and nothing else puts it back: a SIGTERM
5
+ * from a supervisor, a SIGHUP when a window closes, or a SIGQUIT all end a
6
+ * process by default, leaving the reader on a screen no shell prompt is drawn
7
+ * in. These handlers run the same shutdown a quit key runs, then leave with the
8
+ * status a shell reports for the signal.
9
+ */
10
+ /** Signals whose default action ends the process without unwinding the surface. */
11
+ export declare const TERMINATING_SIGNALS: readonly ["SIGINT", "SIGTERM", "SIGHUP", "SIGQUIT"];
12
+ export type TerminatingSignal = (typeof TERMINATING_SIGNALS)[number];
13
+ /**
14
+ * Run a shutdown once for the first terminating signal, then leave.
15
+ *
16
+ * The listener removes itself before the shutdown runs, so a slow shutdown
17
+ * cannot be re-entered by a second signal; the status is the one a shell expects
18
+ * for the signal, so whatever was supervising the process sees an interrupted
19
+ * run rather than a clean one.
20
+ */
21
+ export declare function installSignalRestore(options: {
22
+ shutdown(code: number, signal: TerminatingSignal): void;
23
+ signals?: readonly TerminatingSignal[];
24
+ }): () => void;
25
+ //# sourceMappingURL=signals.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signals.d.ts","sourceRoot":"","sources":["../../src/terminal/signals.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,mFAAmF;AACnF,eAAO,MAAM,mBAAmB,qDAAsD,CAAA;AAEtF,MAAM,MAAM,iBAAiB,GAAG,CAAC,OAAO,mBAAmB,CAAC,CAAC,MAAM,CAAC,CAAA;AAKpE;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE;IAC5C,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,iBAAiB,GAAG,IAAI,CAAA;IACvD,OAAO,CAAC,EAAE,SAAS,iBAAiB,EAAE,CAAA;CACvC,GAAG,MAAM,IAAI,CAeb"}