@agi-fans/dsh-tui 0.18.0 → 0.20.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.
- package/lib/CHANGELOG.md +115 -1
- package/lib/chrome/box.d.ts +2 -0
- package/lib/chrome/box.js +6 -12
- package/lib/chrome/box.js.map +1 -1
- package/lib/chrome/code-highlight.d.ts +26 -18
- package/lib/chrome/code-highlight.js +114 -39
- package/lib/chrome/code-highlight.js.map +1 -1
- package/lib/chrome/diff-render.d.ts +1 -2
- package/lib/chrome/diff-render.js +41 -90
- package/lib/chrome/diff-render.js.map +1 -1
- package/lib/chrome/main-screen-renderer.d.ts +52 -30
- package/lib/chrome/main-screen-renderer.js +1730 -79
- package/lib/chrome/main-screen-renderer.js.map +1 -1
- package/lib/chrome/markdown.js +144 -101
- package/lib/chrome/markdown.js.map +1 -1
- package/lib/chrome/math.d.ts +4 -0
- package/lib/chrome/math.js +340 -0
- package/lib/chrome/math.js.map +1 -0
- package/lib/chrome/md-style.d.ts +3 -0
- package/lib/chrome/md-style.js.map +1 -1
- package/lib/chrome/mermaid.d.ts +6 -0
- package/lib/chrome/mermaid.js +56 -0
- package/lib/chrome/mermaid.js.map +1 -0
- package/lib/chrome/renderer.d.ts +78 -0
- package/lib/chrome/renderer.js.map +1 -1
- package/lib/chrome/status-config.d.ts +5 -0
- package/lib/chrome/status-config.js +3 -0
- package/lib/chrome/status-config.js.map +1 -1
- package/lib/chrome/status-line.d.ts +0 -21
- package/lib/chrome/status-line.js +8 -65
- package/lib/chrome/status-line.js.map +1 -1
- package/lib/chrome/terminal-images.d.ts +31 -0
- package/lib/chrome/terminal-images.js +34 -0
- package/lib/chrome/terminal-images.js.map +1 -0
- package/lib/chrome/theme.d.ts +23 -6
- package/lib/chrome/theme.js +217 -109
- package/lib/chrome/theme.js.map +1 -1
- package/lib/chrome/tool-args.d.ts +24 -1
- package/lib/chrome/tool-args.js +40 -1
- package/lib/chrome/tool-args.js.map +1 -1
- package/lib/chrome/tool-renderers.d.ts +11 -0
- package/lib/chrome/tool-renderers.js +55 -5
- package/lib/chrome/tool-renderers.js.map +1 -1
- package/lib/chrome/welcome-tips.js +2 -2
- package/lib/chrome/welcome-tips.js.map +1 -1
- package/lib/chrome/width.d.ts +7 -3
- package/lib/chrome/width.js +78 -14
- package/lib/chrome/width.js.map +1 -1
- package/lib/commands/diff.js +49 -3
- package/lib/commands/diff.js.map +1 -1
- package/lib/commands/export.js +28 -5
- package/lib/commands/export.js.map +1 -1
- package/lib/commands/files.d.ts +8 -0
- package/lib/commands/files.js +137 -0
- package/lib/commands/files.js.map +1 -0
- package/lib/commands/plugins.d.ts +8 -0
- package/lib/commands/plugins.js +158 -0
- package/lib/commands/plugins.js.map +1 -0
- package/lib/commands/session-configuration.d.ts +4 -0
- package/lib/commands/session-configuration.js +39 -8
- package/lib/commands/session-configuration.js.map +1 -1
- package/lib/commands/session.js +47 -15
- package/lib/commands/session.js.map +1 -1
- package/lib/commands/steer.js +2 -2
- package/lib/commands/steer.js.map +1 -1
- package/lib/commands/terminal.d.ts +7 -0
- package/lib/commands/terminal.js +99 -0
- package/lib/commands/terminal.js.map +1 -0
- package/lib/definition.d.ts +180 -14
- package/lib/definition.js.map +1 -1
- package/lib/input/clipboard.d.ts +12 -7
- package/lib/input/clipboard.js +79 -20
- package/lib/input/clipboard.js.map +1 -1
- package/lib/input/composer-files.d.ts +26 -0
- package/lib/input/composer-files.js +50 -0
- package/lib/input/composer-files.js.map +1 -0
- package/lib/input/editor-discovery.d.ts +21 -0
- package/lib/input/editor-discovery.js +99 -0
- package/lib/input/editor-discovery.js.map +1 -0
- package/lib/input/editor.d.ts +26 -1
- package/lib/input/editor.js +126 -12
- package/lib/input/editor.js.map +1 -1
- package/lib/input/external-editor.d.ts +5 -2
- package/lib/input/external-editor.js +14 -12
- package/lib/input/external-editor.js.map +1 -1
- package/lib/input/fuzzy-search.d.ts +9 -0
- package/lib/input/fuzzy-search.js +113 -0
- package/lib/input/fuzzy-search.js.map +1 -0
- package/lib/input/keybindings-config.d.ts +1 -1
- package/lib/input/keybindings-config.js +7 -1
- package/lib/input/keybindings-config.js.map +1 -1
- package/lib/input/keys.d.ts +17 -0
- package/lib/input/keys.js +21 -5
- package/lib/input/keys.js.map +1 -1
- package/lib/input/mouse-policy.d.ts +3 -0
- package/lib/input/mouse-policy.js +14 -0
- package/lib/input/mouse-policy.js.map +1 -0
- package/lib/input/paste-burst.d.ts +16 -0
- package/lib/input/paste-burst.js +61 -0
- package/lib/input/paste-burst.js.map +1 -0
- package/lib/input/text-selection.d.ts +20 -0
- package/lib/input/text-selection.js +195 -0
- package/lib/input/text-selection.js.map +1 -0
- package/lib/runtime/composer-images.d.ts +1 -0
- package/lib/runtime/composer-images.js +11 -3
- package/lib/runtime/composer-images.js.map +1 -1
- package/lib/runtime/file-open.d.ts +2 -0
- package/lib/runtime/file-open.js +12 -0
- package/lib/runtime/file-open.js.map +1 -0
- package/lib/runtime/file-review.d.ts +24 -0
- package/lib/runtime/file-review.js +188 -0
- package/lib/runtime/file-review.js.map +1 -0
- package/lib/runtime/herdr-agent.d.ts +7 -15
- package/lib/runtime/herdr-agent.js +151 -79
- package/lib/runtime/herdr-agent.js.map +1 -1
- package/lib/runtime/hook-settings.d.ts +17 -0
- package/lib/runtime/hook-settings.js +57 -0
- package/lib/runtime/hook-settings.js.map +1 -0
- package/lib/runtime/human-interaction.js +1 -1
- package/lib/runtime/human-interaction.js.map +1 -1
- package/lib/runtime/image-preview.d.ts +8 -0
- package/lib/runtime/image-preview.js +119 -0
- package/lib/runtime/image-preview.js.map +1 -0
- package/lib/runtime/plain-tui.d.ts +2 -0
- package/lib/runtime/plain-tui.js +2 -2
- package/lib/runtime/plain-tui.js.map +1 -1
- package/lib/runtime/plugin-settings.d.ts +17 -0
- package/lib/runtime/plugin-settings.js +154 -0
- package/lib/runtime/plugin-settings.js.map +1 -0
- package/lib/runtime/provider-local.d.ts +58 -7
- package/lib/runtime/provider-local.js +1394 -137
- package/lib/runtime/provider-local.js.map +1 -1
- package/lib/runtime/runner.js +3 -3
- package/lib/runtime/runner.js.map +1 -1
- package/lib/runtime/session-archive.d.ts +5 -0
- package/lib/runtime/session-archive.js +114 -0
- package/lib/runtime/session-archive.js.map +1 -0
- package/lib/runtime/subagent-model-selection.d.ts +5 -0
- package/lib/runtime/subagent-model-selection.js +15 -0
- package/lib/runtime/subagent-model-selection.js.map +1 -0
- package/lib/runtime/terminal-notifications.d.ts +8 -0
- package/lib/runtime/terminal-notifications.js +16 -0
- package/lib/runtime/terminal-notifications.js.map +1 -1
- package/lib/runtime/terminal-reader.d.ts +11 -0
- package/lib/runtime/terminal-reader.js +87 -0
- package/lib/runtime/terminal-reader.js.map +1 -0
- package/lib/runtime/tool-presentation.js +43 -30
- package/lib/runtime/tool-presentation.js.map +1 -1
- package/lib/session/composer-drafts.d.ts +20 -0
- package/lib/session/composer-drafts.js +103 -0
- package/lib/session/composer-drafts.js.map +1 -0
- package/lib/session/conversation-turns.d.ts +16 -0
- package/lib/session/conversation-turns.js +33 -0
- package/lib/session/conversation-turns.js.map +1 -0
- package/lib/session/feature-toggles.d.ts +79 -0
- package/lib/session/feature-toggles.js +139 -0
- package/lib/session/feature-toggles.js.map +1 -0
- package/lib/session/fold-policy.d.ts +4 -0
- package/lib/session/fold-policy.js +4 -0
- package/lib/session/fold-policy.js.map +1 -0
- package/lib/session/interaction-adapter.d.ts +2 -2
- package/lib/session/interaction-adapter.js +156 -25
- package/lib/session/interaction-adapter.js.map +1 -1
- package/lib/session/job-notice.d.ts +4 -0
- package/lib/session/job-notice.js +44 -3
- package/lib/session/job-notice.js.map +1 -1
- package/lib/session/message-queue.d.ts +22 -0
- package/lib/session/message-queue.js +157 -0
- package/lib/session/message-queue.js.map +1 -0
- package/lib/session/project-file-search.js +3 -21
- package/lib/session/project-file-search.js.map +1 -1
- package/lib/session/session-controller.d.ts +11 -18
- package/lib/session/session-controller.js +246 -100
- package/lib/session/session-controller.js.map +1 -1
- package/lib/session/session-library.d.ts +11 -3
- package/lib/session/session-library.js +48 -8
- package/lib/session/session-library.js.map +1 -1
- package/lib/session/session-tree.d.ts +26 -0
- package/lib/session/session-tree.js +112 -0
- package/lib/session/session-tree.js.map +1 -0
- package/lib/session/steering.d.ts +3 -0
- package/lib/session/steering.js +9 -0
- package/lib/session/steering.js.map +1 -0
- package/lib/session/tui-settings.d.ts +23 -1
- package/lib/session/tui-settings.js +15 -2
- package/lib/session/tui-settings.js.map +1 -1
- package/lib/session/workflow-projection.d.ts +9 -0
- package/lib/session/workflow-projection.js +44 -0
- package/lib/session/workflow-projection.js.map +1 -0
- package/lib/views/agent-hub.js +9 -4
- package/lib/views/agent-hub.js.map +1 -1
- package/lib/views/autocomplete.js +5 -25
- package/lib/views/autocomplete.js.map +1 -1
- package/lib/views/document-reader.d.ts +34 -0
- package/lib/views/document-reader.js +145 -0
- package/lib/views/document-reader.js.map +1 -0
- package/lib/views/event-views.d.ts +26 -2
- package/lib/views/event-views.js +196 -42
- package/lib/views/event-views.js.map +1 -1
- package/lib/views/hotkeys.d.ts +2 -0
- package/lib/views/hotkeys.js +20 -8
- package/lib/views/hotkeys.js.map +1 -1
- package/lib/views/prompt-selector.d.ts +33 -3
- package/lib/views/prompt-selector.js +287 -43
- package/lib/views/prompt-selector.js.map +1 -1
- package/lib/views/prompt-tree.d.ts +11 -0
- package/lib/views/prompt-tree.js +74 -0
- package/lib/views/prompt-tree.js.map +1 -0
- package/lib/views/session-files.d.ts +7 -0
- package/lib/views/session-files.js +62 -0
- package/lib/views/session-files.js.map +1 -0
- package/lib/views/settings-list.d.ts +32 -4
- package/lib/views/settings-list.js +148 -37
- package/lib/views/settings-list.js.map +1 -1
- package/lib/views/transcript-render.d.ts +117 -18
- package/lib/views/transcript-render.js +1084 -126
- package/lib/views/transcript-render.js.map +1 -1
- package/lib/views/transcript-types.d.ts +80 -2
- package/lib/views/transcript-types.js +11 -0
- package/lib/views/transcript-types.js.map +1 -1
- package/lib/views/workspace-changes.d.ts +27 -0
- package/lib/views/workspace-changes.js +128 -0
- package/lib/views/workspace-changes.js.map +1 -0
- package/package.json +77 -41
- package/lib/chrome/style.d.ts +0 -22
- package/lib/chrome/style.js +0 -23
- package/lib/chrome/style.js.map +0 -1
|
@@ -10,43 +10,58 @@
|
|
|
10
10
|
* printing of settled blocks.
|
|
11
11
|
* @module @agi-fans/dsh-tui
|
|
12
12
|
*/
|
|
13
|
-
import { TerminalNotificationController, terminalNotificationSequence, terminalProgressSequence, } from "./terminal-notifications.js";
|
|
13
|
+
import { TerminalNotificationController, TerminalNotificationQueue, terminalNotificationSequence, terminalProgressSequence, } from "./terminal-notifications.js";
|
|
14
14
|
import { HerdrAgentReporter } from "./herdr-agent.js";
|
|
15
|
+
import { imageProtocol } from "../chrome/terminal-images.js";
|
|
16
|
+
import { previewImages } from "./image-preview.js";
|
|
17
|
+
import { rmSync } from 'node:fs';
|
|
15
18
|
import { ComposerImages } from "./composer-images.js";
|
|
19
|
+
import { ComposerDraftStore } from "../session/composer-drafts.js";
|
|
20
|
+
import { mergeJobSettlement } from "../session/job-notice.js";
|
|
16
21
|
import { PlainTui } from "./plain-tui.js";
|
|
22
|
+
import { documentDestination, documentLayout, documentLineRow, documentMatches, documentModel, documentPosition, documentStart } from "../views/document-reader.js";
|
|
17
23
|
import { homedir } from 'node:os';
|
|
18
24
|
import { join, sep } from 'node:path';
|
|
19
25
|
import { StringDecoder } from 'node:string_decoder';
|
|
26
|
+
import { ComposerFiles } from "../input/composer-files.js";
|
|
27
|
+
import { defaultFeatureStates, featurePatchPath, featureStatesFromPatch, renderFeatureBlock, replaceFeatureBlock, } from "../session/feature-toggles.js";
|
|
28
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
29
|
+
import { dirname } from 'node:path';
|
|
20
30
|
import { TUI_SERVICE, } from "../definition.js";
|
|
21
31
|
import { applySlashCompletion, formatHelpText, parseSlashInput, resolveSlashCommand, slashSuggestions, BUILTIN_SLASH_COMMANDS, } from "../views/autocomplete.js";
|
|
22
32
|
import { applyPathCompletion, defaultPathSource, editorLineAt, findPathToken, parsePathPrefix, pathSuggestions, searchPathSuggestions, } from "../views/path-complete.js";
|
|
23
33
|
import { activeAtToken } from '@deepseek-ai/dsh-file-reference/grammar';
|
|
24
34
|
import { nextSelectableAutocompleteIndex, searchAtSuggestions, } from "../views/at-complete.js";
|
|
35
|
+
import { readTmuxMouseEnabled } from "../input/mouse-policy.js";
|
|
36
|
+
import { TextSelection } from "../input/text-selection.js";
|
|
25
37
|
import { copyToClipboard, readFromClipboard } from "../input/clipboard.js";
|
|
26
38
|
import { applyCopySelectorEvent, createCopySelector, } from "../views/copy-selector.js";
|
|
27
39
|
import { buildCopyTargets, extractCopyTarget, parseCopyKind } from "../views/copy-targets.js";
|
|
28
40
|
import { applyHistorySearchEvent, createHistorySearch, } from "../views/history-search.js";
|
|
29
41
|
import { InputEditor, lineEnd, lineStart } from "../input/editor.js";
|
|
30
42
|
import { applySettingsEvent, createSettings, } from "../views/settings-list.js";
|
|
43
|
+
import { editPluginSettings, pluginSettingsEntries } from "./plugin-settings.js";
|
|
31
44
|
import { appendTrajectoryEvent, applyTrajectoryEvent, createTrajectory, trajectoryDetailMetrics, trajectoryListMetrics, } from "../views/trajectory.js";
|
|
32
45
|
import { applyAgentHubEvent, createAgentHub, updateAgentHub, } from "../views/agent-hub.js";
|
|
33
|
-
import { applyEvent, applyStreamChunk, blockSearchText, initialTranscript, replayEvents, renderView, TRANSCRIPT_FAST_SCROLL, } from "../views/event-views.js";
|
|
46
|
+
import { applyEvent, applyStreamChunk, blockSearchText, initialTranscript, replayEvents, renderView, turnGroups, transcriptSeam, TRANSCRIPT_FAST_SCROLL, withWorkspaceSummary, } from "../views/event-views.js";
|
|
34
47
|
import { applyTranscriptSearchEvent, createTranscriptSearch, searchBlockIndexes, } from "../views/transcript-search.js";
|
|
35
48
|
import { nextRevealStep, revealStreamingAssistant, streamingAssistantKey, streamingAssistantUnits, } from "../views/streaming-reveal.js";
|
|
36
49
|
import { flushPending, parseKeys } from "../input/keys.js";
|
|
37
50
|
import { MainScreenRenderer } from "../chrome/main-screen-renderer.js";
|
|
38
|
-
import { colorDisabledByEnv, detectTrueColor } from "../chrome/theme.js";
|
|
51
|
+
import { colorDisabledByEnv, createTheme, detectTrueColor } from "../chrome/theme.js";
|
|
39
52
|
import { renderTool } from "../chrome/tool-renderers.js";
|
|
40
53
|
import { TUI_SETTINGS_ENTRY, TUI_SETTINGS_FIELDS } from "../session/tui-settings.js";
|
|
41
54
|
import { defaultStatusBarConfig, resolveStatusBarConfig } from "../chrome/status-config.js";
|
|
42
55
|
import { HistoryStore } from "../session/history-store.js";
|
|
56
|
+
import { PasteBurst } from "../input/paste-burst.js";
|
|
43
57
|
import { loadKeybindings } from "../input/keybindings-config.js";
|
|
44
|
-
import {
|
|
58
|
+
import { discoverEditors } from "../input/editor-discovery.js";
|
|
59
|
+
import { editExternally, editFileExternally } from "../input/external-editor.js";
|
|
45
60
|
import z from '@deepseek-ai/schemastery';
|
|
46
|
-
import { movePromptSelection, filteredPromptOptions, selectedPromptAnswer, selectedFilteredPromptAnswer, togglePromptSelection, } from "../views/prompt-selector.js";
|
|
61
|
+
import { movePromptSelection, movePromptTree, searchPromptSelection, filteredPromptOptions, refreshPromptOptions, promptTreePageSize, selectedPromptAnswer, selectedFilteredPromptAnswer, togglePromptSelection, } from "../views/prompt-selector.js";
|
|
47
62
|
import { refreshProjectContext, resolveProjectContext } from "../session/project-context.js";
|
|
48
63
|
import { pickWelcomeTips } from "../chrome/welcome-tips.js";
|
|
49
|
-
import { formatEssentialHotkeysText, formatHotkeysText, hotkeyCount } from "../views/hotkeys.js";
|
|
64
|
+
import { formatEssentialHotkeysText, formatHotkeysText, hotkeyCount, keysForAction } from "../views/hotkeys.js";
|
|
50
65
|
import { imagePathCandidates, stripComposerImageMarkers, readImageFile, readImageFromClipboard, readMacClipboardFiles, } from "../input/image-paste.js";
|
|
51
66
|
import { APP_NAME, APP_VERSION } from "../session/package-metadata.js";
|
|
52
67
|
const DOUBLE_CTRL_C_MS = 500;
|
|
@@ -99,6 +114,7 @@ export const Config = z.object({
|
|
|
99
114
|
model: z.string(),
|
|
100
115
|
historyPath: z.string(),
|
|
101
116
|
keybindingsPath: z.string(),
|
|
117
|
+
dshHome: z.string(),
|
|
102
118
|
...TUI_SETTINGS_FIELDS,
|
|
103
119
|
});
|
|
104
120
|
/**
|
|
@@ -122,8 +138,50 @@ function resolveColors(preference, isTty) {
|
|
|
122
138
|
return preference;
|
|
123
139
|
return isTty && !colorDisabledByEnv();
|
|
124
140
|
}
|
|
141
|
+
/**
|
|
142
|
+
* The first body row whose shape changed between two frames: the earliest
|
|
143
|
+
* surface that opened, closed, or changed how it is open. Rows above it are
|
|
144
|
+
* the same in both frames, which is what lets the renderer keep history that
|
|
145
|
+
* is still true and repair only what moved.
|
|
146
|
+
*/
|
|
147
|
+
function firstReshapedRow(before, after) {
|
|
148
|
+
const keys = (marks) => new Set(marks.map(mark => mark.key));
|
|
149
|
+
const was = keys(before);
|
|
150
|
+
const now = keys(after);
|
|
151
|
+
let row = Number.POSITIVE_INFINITY;
|
|
152
|
+
for (const mark of before)
|
|
153
|
+
if (!now.has(mark.key))
|
|
154
|
+
row = Math.min(row, mark.row);
|
|
155
|
+
for (const mark of after)
|
|
156
|
+
if (!was.has(mark.key))
|
|
157
|
+
row = Math.min(row, mark.row);
|
|
158
|
+
return Number.isFinite(row) ? row : 0;
|
|
159
|
+
}
|
|
125
160
|
export class LocalTui {
|
|
161
|
+
get interactive() { return this.#tty; }
|
|
162
|
+
openFileInEditor(path) {
|
|
163
|
+
if (!this.#tty)
|
|
164
|
+
throw new Error('Opening an editor requires an interactive terminal.');
|
|
165
|
+
try {
|
|
166
|
+
this.#setMouseTracking(false);
|
|
167
|
+
this.#term.output.write('\x1b[?1004l');
|
|
168
|
+
this.#term.input.setRawMode?.(false);
|
|
169
|
+
editFileExternally(path, this.#externalEditor);
|
|
170
|
+
}
|
|
171
|
+
finally {
|
|
172
|
+
if (!this.#disposed) {
|
|
173
|
+
this.#term.input.setRawMode?.(true);
|
|
174
|
+
this.#term.output.write('\x1b[?1004h');
|
|
175
|
+
this.#renderer.reset();
|
|
176
|
+
this.#render();
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
126
180
|
#deferInitialRender = false;
|
|
181
|
+
#imageProtocol;
|
|
182
|
+
#imageCellSize = { width: 9, height: 18 };
|
|
183
|
+
#imagePreviewAbort;
|
|
184
|
+
#imageTemporary = new Set();
|
|
127
185
|
#terminalProfile;
|
|
128
186
|
#resizeDebounceMs;
|
|
129
187
|
#resizeTimer = null;
|
|
@@ -138,13 +196,34 @@ export class LocalTui {
|
|
|
138
196
|
#renderer;
|
|
139
197
|
#state = initialTranscript();
|
|
140
198
|
#editor = new InputEditor();
|
|
199
|
+
#files = new ComposerFiles({ text: () => this.#editor.text,
|
|
200
|
+
append: marker => { this.#editor.setCursor(this.#editor.text.length); this.#editor.handle({ type: 'text', value: (this.#editor.text === '' ? '' : ' ') + marker }); } });
|
|
201
|
+
stageFileAttachment(file) {
|
|
202
|
+
this.#files.add(file);
|
|
203
|
+
this.#refreshAutocomplete();
|
|
204
|
+
if (this.#tty)
|
|
205
|
+
this.#render();
|
|
206
|
+
}
|
|
141
207
|
#history = [];
|
|
142
208
|
#historyIndex = 0;
|
|
209
|
+
#literalInput = false;
|
|
143
210
|
#draft = '';
|
|
211
|
+
#historyDraft;
|
|
212
|
+
#draftStore;
|
|
213
|
+
#draftScope;
|
|
214
|
+
#draftFingerprint = '';
|
|
215
|
+
#draftDirty = false;
|
|
216
|
+
#draftTimer;
|
|
217
|
+
#unsavedDrafts = new Map();
|
|
218
|
+
#draftError = false;
|
|
144
219
|
#ac = null;
|
|
145
220
|
#search = null;
|
|
146
221
|
#transcriptSearch = null;
|
|
147
222
|
#settings = null;
|
|
223
|
+
/** Optional-feature state read from the Profile patch this process booted with. */
|
|
224
|
+
#features;
|
|
225
|
+
/** Profile patch the Features section writes; absent hides that section. */
|
|
226
|
+
#featurePatch;
|
|
148
227
|
#copySelector = null;
|
|
149
228
|
#trajectory = null;
|
|
150
229
|
#agentHub = null;
|
|
@@ -160,6 +239,11 @@ export class LocalTui {
|
|
|
160
239
|
#inspectEscapeFenceUntil = 0;
|
|
161
240
|
#interrupts = new Set();
|
|
162
241
|
#queueEdits = new Set();
|
|
242
|
+
#queueHandler;
|
|
243
|
+
#queueHotkeyAbort;
|
|
244
|
+
#queuedInputIds = new WeakMap();
|
|
245
|
+
#queuedInputSerial = 0;
|
|
246
|
+
#steerHandler;
|
|
163
247
|
#rewinds = new Set();
|
|
164
248
|
#inspects = new Set();
|
|
165
249
|
#inspectCloses = new Set();
|
|
@@ -170,6 +254,9 @@ export class LocalTui {
|
|
|
170
254
|
#autocompleteTimer = null;
|
|
171
255
|
#autocompleteAbort = null;
|
|
172
256
|
#autocompleteRequestId = 0;
|
|
257
|
+
#pasteBurst = new PasteBurst();
|
|
258
|
+
#pasteBurstTimer;
|
|
259
|
+
#pasteProtection = true;
|
|
173
260
|
#paste = false;
|
|
174
261
|
#pasteBuf = '';
|
|
175
262
|
#pasteInFlight = 0;
|
|
@@ -180,6 +267,7 @@ export class LocalTui {
|
|
|
180
267
|
});
|
|
181
268
|
#plain;
|
|
182
269
|
#offData = null;
|
|
270
|
+
#offResume;
|
|
183
271
|
#offResize = null;
|
|
184
272
|
#pwd;
|
|
185
273
|
#branch;
|
|
@@ -191,16 +279,26 @@ export class LocalTui {
|
|
|
191
279
|
#scrollStart = 0;
|
|
192
280
|
#maxStart = 0;
|
|
193
281
|
#scrollBudget = 0;
|
|
282
|
+
#blockStarts = [];
|
|
283
|
+
/** Last frame's {@link TranscriptScroll.foldShape}, to notice a fold change. */
|
|
284
|
+
#foldShape;
|
|
285
|
+
/** Last frame's open surfaces, to find where a fold change starts. */
|
|
286
|
+
#foldMarks;
|
|
194
287
|
#follow = true;
|
|
195
288
|
#focusBlock;
|
|
196
|
-
#
|
|
289
|
+
#focusBlockEdge;
|
|
197
290
|
#motion = 'full';
|
|
291
|
+
#externalEditor = 'auto';
|
|
198
292
|
#terminalProgress = false;
|
|
199
293
|
#terminalProgressActive = false;
|
|
200
294
|
#terminalProgressTick = null;
|
|
201
295
|
#checkUpdates = true;
|
|
202
296
|
#startupChangelog = 'summary';
|
|
203
297
|
#notifications = new TerminalNotificationController();
|
|
298
|
+
#notificationQueue = new TerminalNotificationQueue();
|
|
299
|
+
#notificationTimer;
|
|
300
|
+
#terminalFocused;
|
|
301
|
+
#notificationFocus = 'unfocused';
|
|
204
302
|
/**
|
|
205
303
|
* Herdr lifecycle authority for this pane. The plugin entry injects the
|
|
206
304
|
* environment-aware reporter; a directly constructed instance is inert so
|
|
@@ -211,10 +309,37 @@ export class LocalTui {
|
|
|
211
309
|
#notificationThreshold = '30s';
|
|
212
310
|
#statusBar = defaultStatusBarConfig();
|
|
213
311
|
#toolsExpanded = false;
|
|
214
|
-
|
|
312
|
+
/**
|
|
313
|
+
* The reader opened something with Ctrl+O or Alt+O and is reading it.
|
|
314
|
+
*
|
|
315
|
+
* Openings are shown in a browsing frame, never in the flow that follows the
|
|
316
|
+
* tail: every opening starts an inspection, and returning to the tail ends it
|
|
317
|
+
* and closes them all. The flow's rows cross into the terminal's history, which can only be
|
|
318
|
+
* appended to: opening a run in place pushed rows that closing it could not
|
|
319
|
+
* take back, so the screen either went blank where they had been or painted
|
|
320
|
+
* rows history already held, and the transcript read twice. A browsing frame
|
|
321
|
+
* repaints the screen and nothing above it, so reading an opened run leaves
|
|
322
|
+
* the flow — and the history — exactly as it was.
|
|
323
|
+
*/
|
|
324
|
+
#inspecting = false;
|
|
325
|
+
#mouseTracking = false;
|
|
326
|
+
#selection = new TextSelection();
|
|
327
|
+
#copyOnSelect = true;
|
|
328
|
+
#mathMode = 'auto';
|
|
329
|
+
#mermaidMode = 'auto';
|
|
330
|
+
#mouseInteraction = 'auto';
|
|
331
|
+
#tmuxMouseEnabled;
|
|
332
|
+
#jumpPress;
|
|
333
|
+
#jumpToLatest;
|
|
334
|
+
#openedGroups = new Set();
|
|
335
|
+
/** Turn scopes whose tools stay detailed as new calls arrive during inspection. */
|
|
336
|
+
#detailedTurns = new Set();
|
|
215
337
|
#tools = [];
|
|
216
338
|
#runtimeCommands = [];
|
|
217
339
|
#prompt = null;
|
|
340
|
+
#pluginSettings;
|
|
341
|
+
#pluginSettingsAbort;
|
|
342
|
+
#pluginSettingsTask;
|
|
218
343
|
/**
|
|
219
344
|
* The overlay surface displaced by an in-flight prompt: while a human
|
|
220
345
|
* prompt owns the keyboard, its screen must not compete with a stale
|
|
@@ -241,6 +366,7 @@ export class LocalTui {
|
|
|
241
366
|
*/
|
|
242
367
|
#trueColor = false;
|
|
243
368
|
#copy;
|
|
369
|
+
#copyTask = Promise.resolve();
|
|
244
370
|
#readClipboard;
|
|
245
371
|
#readClipboardImage;
|
|
246
372
|
#readClipboardFiles;
|
|
@@ -281,6 +407,17 @@ export class LocalTui {
|
|
|
281
407
|
this.#historyStore = paths.historyPath === undefined ? undefined : new HistoryStore(paths.historyPath);
|
|
282
408
|
this.#history = this.#historyStore?.load() ?? [];
|
|
283
409
|
this.#keybindings = loadKeybindings(paths.keybindingsPath);
|
|
410
|
+
this.#featurePatch = paths.featurePatch;
|
|
411
|
+
if (paths.featurePatch !== undefined) {
|
|
412
|
+
try {
|
|
413
|
+
this.#features = featureStatesFromPatch(readFileSync(paths.featurePatch, 'utf8'));
|
|
414
|
+
}
|
|
415
|
+
catch {
|
|
416
|
+
// A patch that cannot be read still leaves the shipped defaults; the
|
|
417
|
+
// write path below reports the failure when the user toggles.
|
|
418
|
+
this.#features = defaultFeatureStates();
|
|
419
|
+
}
|
|
420
|
+
}
|
|
284
421
|
const fallback = defaultPathSource();
|
|
285
422
|
this.#cwd = paths.cwd ?? fallback.cwd;
|
|
286
423
|
this.#readImagePath = paths.readImagePath ?? (path => readImageFile(path, this.#cwd));
|
|
@@ -295,14 +432,18 @@ export class LocalTui {
|
|
|
295
432
|
this.#welcomeTips = pickWelcomeTips();
|
|
296
433
|
this.#deferInitialRender = paths.deferInitialRender === true;
|
|
297
434
|
this.#terminalProfile = paths.terminalProfile ?? detectTerminalProfile();
|
|
435
|
+
this.#imageProtocol = this.#terminalProfile !== 'direct' || paths.imageProtocol === 'none' ? undefined : paths.imageProtocol ?? imageProtocol(process.env);
|
|
298
436
|
this.#resizeDebounceMs = Math.max(0, paths.resizeDebounceMs ?? 120);
|
|
299
437
|
this.#streamRenderMs = Math.max(0, paths.streamRenderMs ?? 8);
|
|
300
438
|
this.#herdr = paths.herdrReporter ?? new HerdrAgentReporter({ env: {} });
|
|
301
439
|
this.#syncTrueColor();
|
|
302
440
|
this.#tty = term.input.isTTY === true;
|
|
441
|
+
this.#draftStore = this.#tty && paths.draftsPath !== undefined ? new ComposerDraftStore(paths.draftsPath) : undefined;
|
|
303
442
|
this.#plain = new PlainTui({
|
|
304
443
|
term,
|
|
305
444
|
blocks: () => this.#state.blocks,
|
|
445
|
+
mathMode: () => this.#mathMode,
|
|
446
|
+
mermaidMode: () => this.#mermaidMode,
|
|
306
447
|
promptRequest: () => this.#prompt?.request,
|
|
307
448
|
finishPrompt: answer => { this.#finishPrompt(answer); },
|
|
308
449
|
});
|
|
@@ -312,7 +453,6 @@ export class LocalTui {
|
|
|
312
453
|
width: this.#term.width(),
|
|
313
454
|
height: this.#term.height(),
|
|
314
455
|
synchronized: this.#tty,
|
|
315
|
-
clearScrollback: this.#terminalProfile === 'direct',
|
|
316
456
|
alternateScreenOverlays: paths.alternateScreenOverlays === true,
|
|
317
457
|
});
|
|
318
458
|
if (this.#tty) {
|
|
@@ -324,6 +464,8 @@ export class LocalTui {
|
|
|
324
464
|
this.#offResize = term.onResize?.(() => {
|
|
325
465
|
// A terminal resize changes the committed/live seam; re-anchor the
|
|
326
466
|
// live window so it stays anchored at the bottom.
|
|
467
|
+
this.#selection.clear();
|
|
468
|
+
this.#jumpPress = undefined;
|
|
327
469
|
const repaint = () => {
|
|
328
470
|
this.#resizeTimer = null;
|
|
329
471
|
this.#renderer.resize(this.#term.width(), this.#term.height());
|
|
@@ -338,7 +480,19 @@ export class LocalTui {
|
|
|
338
480
|
repaint();
|
|
339
481
|
}
|
|
340
482
|
}) ?? null;
|
|
341
|
-
|
|
483
|
+
if (process.platform !== 'win32') {
|
|
484
|
+
const resume = () => {
|
|
485
|
+
if (this.#disposed)
|
|
486
|
+
return;
|
|
487
|
+
this.#terminalFocused = undefined;
|
|
488
|
+
this.#term.output.write('\x1b[?1004h');
|
|
489
|
+
this.#renderer.reset();
|
|
490
|
+
this.#render();
|
|
491
|
+
};
|
|
492
|
+
process.on('SIGCONT', resume);
|
|
493
|
+
this.#offResume = () => { process.off('SIGCONT', resume); };
|
|
494
|
+
}
|
|
495
|
+
term.output.write('\x1b[?2004h\x1b[?1004h');
|
|
342
496
|
}
|
|
343
497
|
this.#render();
|
|
344
498
|
this.#herdr.start();
|
|
@@ -352,8 +506,15 @@ export class LocalTui {
|
|
|
352
506
|
if (this.#tty)
|
|
353
507
|
this.#render();
|
|
354
508
|
}
|
|
355
|
-
event(event, presentation) {
|
|
356
|
-
|
|
509
|
+
event(event, presentation, workspace) {
|
|
510
|
+
// Paint any coalesced results and remaining streamed text before the turn's
|
|
511
|
+
// end changes the live work into its folded summary.
|
|
512
|
+
if (event.type === 'turn/end' && this.#tty && this.#state.status !== 'idle'
|
|
513
|
+
&& turnGroups(this.#state).some(group => group.live)) {
|
|
514
|
+
this.#syncStreamingReveal(undefined);
|
|
515
|
+
this.#render();
|
|
516
|
+
}
|
|
517
|
+
this.#state = applyEvent(this.#state, event, presentation, workspace);
|
|
357
518
|
this.#emitNotification(this.#notifications.event({
|
|
358
519
|
type: event.type,
|
|
359
520
|
time: event.time,
|
|
@@ -380,6 +541,16 @@ export class LocalTui {
|
|
|
380
541
|
this.#plain.print();
|
|
381
542
|
}
|
|
382
543
|
}
|
|
544
|
+
setWorkspaceSummary(turn, summary) {
|
|
545
|
+
const next = withWorkspaceSummary(this.#state, turn, summary);
|
|
546
|
+
if (next === this.#state)
|
|
547
|
+
return;
|
|
548
|
+
this.#state = next;
|
|
549
|
+
if (this.#tty)
|
|
550
|
+
this.#render();
|
|
551
|
+
else
|
|
552
|
+
this.#plain.print();
|
|
553
|
+
}
|
|
383
554
|
/**
|
|
384
555
|
* Fold one live `agent/assistant-stream` chunk into the transcript and
|
|
385
556
|
* schedule the streaming reveal. Durable settlement follows on the session
|
|
@@ -401,11 +572,12 @@ export class LocalTui {
|
|
|
401
572
|
}
|
|
402
573
|
}
|
|
403
574
|
}
|
|
404
|
-
setStatus(status) {
|
|
405
|
-
//
|
|
406
|
-
|
|
407
|
-
if (this.#inspected === undefined)
|
|
575
|
+
setStatus(status, options = {}) {
|
|
576
|
+
// Parent lifecycle remains authoritative while the child owns the visible view.
|
|
577
|
+
if (options.root === true || this.#inspected === undefined)
|
|
408
578
|
this.#herdr.setRunning(status === 'running');
|
|
579
|
+
if (options.root === true && this.#inspected !== undefined)
|
|
580
|
+
return;
|
|
409
581
|
if (this.#state.status === 'compacting')
|
|
410
582
|
return;
|
|
411
583
|
this.#state = { ...this.#state, status };
|
|
@@ -468,6 +640,7 @@ export class LocalTui {
|
|
|
468
640
|
&& this.#inspected?.phase === inspected?.phase && this.#inspected?.mode === inspected?.mode
|
|
469
641
|
&& this.#inspected?.writable === inspected?.writable)
|
|
470
642
|
return;
|
|
643
|
+
this.#switchDraft(inspected?.id ?? this.#sessionId);
|
|
471
644
|
this.#inspected = inspected === undefined ? undefined : { ...inspected };
|
|
472
645
|
if (inspected !== undefined) {
|
|
473
646
|
this.#inspectEscapeFenceUntil = 0;
|
|
@@ -544,50 +717,136 @@ export class LocalTui {
|
|
|
544
717
|
.join(' · ');
|
|
545
718
|
}
|
|
546
719
|
notice(text, options = {}) {
|
|
720
|
+
const merged = options.job === undefined ? undefined : mergeJobSettlement(this.#state, options.job);
|
|
721
|
+
if (merged !== undefined && this.#tty) {
|
|
722
|
+
const origin = merged.blocks.find((block, index) => block !== this.#state.blocks[index]);
|
|
723
|
+
this.#state = merged;
|
|
724
|
+
// A previous turn may already be in native history. Keep its new outcome
|
|
725
|
+
// visible at the tail as well as updating the live transcript's tool.
|
|
726
|
+
if (origin?.kind === 'tool' && (origin.turn === undefined || origin.turn === this.#state.turn)) {
|
|
727
|
+
if (options.focus === true)
|
|
728
|
+
this.#followTail();
|
|
729
|
+
this.#render();
|
|
730
|
+
return;
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
const running = options.process === true && this.#state.status !== 'idle' && this.#state.turn > 0;
|
|
547
734
|
const block = {
|
|
548
735
|
kind: 'notice',
|
|
549
736
|
level: options.level ?? 'info',
|
|
550
737
|
text,
|
|
551
738
|
...(options.framed === true ? { framed: true } : {}),
|
|
739
|
+
...(running
|
|
740
|
+
? { process: { turn: this.#state.turn, ...(options.processSource === undefined ? {} : { source: options.processSource }) } }
|
|
741
|
+
: {}),
|
|
552
742
|
};
|
|
553
743
|
this.#state = { ...this.#state, blocks: [...this.#state.blocks, block] };
|
|
744
|
+
if (options.focus === true)
|
|
745
|
+
this.#followTail();
|
|
554
746
|
if (this.#tty)
|
|
555
747
|
this.#render();
|
|
556
748
|
else
|
|
557
749
|
this.#plain.print();
|
|
558
750
|
}
|
|
559
|
-
commandOutput(command, text) {
|
|
751
|
+
commandOutput(command, text, options = {}) {
|
|
560
752
|
this.#state = { ...this.#state, blocks: [...this.#state.blocks, { kind: 'commandOutput', command, text }] };
|
|
753
|
+
if (options.focus === true)
|
|
754
|
+
this.#followTail();
|
|
561
755
|
if (this.#tty)
|
|
562
756
|
this.#render();
|
|
563
757
|
else
|
|
564
758
|
this.#plain.print();
|
|
565
759
|
}
|
|
566
760
|
prompt(request) {
|
|
567
|
-
if (this.#prompt !== null)
|
|
568
|
-
return Promise.reject(new Error('omdsh-tui: prompt already in flight'));
|
|
569
761
|
if (this.#disposed || request.signal?.aborted === true)
|
|
570
762
|
return Promise.resolve(null);
|
|
571
|
-
|
|
763
|
+
if (this.#prompt !== null) {
|
|
764
|
+
const superseded = this.#prompt.request.onSuperseded;
|
|
765
|
+
if (superseded === undefined || request.notify === false)
|
|
766
|
+
return Promise.reject(new Error('omdsh-tui: prompt already in flight'));
|
|
767
|
+
const input = this.#editor.expandedText;
|
|
768
|
+
this.#finishPrompt(null);
|
|
769
|
+
try {
|
|
770
|
+
superseded(input);
|
|
771
|
+
}
|
|
772
|
+
catch (error) {
|
|
773
|
+
this.notice(error instanceof Error ? error.message : String(error), { level: 'error' });
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
this.#flushPasteBurst(true);
|
|
777
|
+
this.#pasteBurst.clear();
|
|
778
|
+
if (request.notify !== false)
|
|
779
|
+
this.#emitNotification(this.#notifications.humanPrompt());
|
|
572
780
|
this.#herdr.prompt(request.title);
|
|
573
|
-
this.#
|
|
781
|
+
if (this.#tty && request.documentImage !== undefined && this.#imageProtocol !== undefined)
|
|
782
|
+
this.#term.output.write('\x1b[16t');
|
|
783
|
+
const savedInput = this.#editor.snapshot();
|
|
784
|
+
this.#editor.setText(request.options?.length || request.allowCustom === false ? '' : request.initialInput ?? '');
|
|
574
785
|
this.#ac = null;
|
|
575
786
|
const displaced = this.#displaceSurface();
|
|
576
787
|
return new Promise((resolve) => {
|
|
577
|
-
const selected = Math.max(0, request.
|
|
578
|
-
const pending = { request, selected, checked: new Set(), resolve
|
|
788
|
+
const selected = Math.max(0, filteredPromptOptions(request, '').findIndex(option => (option.value ?? option.label) === request.initialValue) ?? 0);
|
|
789
|
+
const pending = { request, selected, checked: new Set(), resolve, savedInput,
|
|
790
|
+
...(request.documentPosition === undefined ? {} : { documentAnchor: request.documentPosition, documentQuery: request.documentPosition.query,
|
|
791
|
+
documentWordWrap: request.documentPosition.wordWrap, documentColumn: request.documentPosition.column }),
|
|
792
|
+
...(request.documentTail === true && request.documentPosition?.following !== false ? { documentScroll: Number.POSITIVE_INFINITY } : {}) };
|
|
579
793
|
if (request.signal !== undefined) {
|
|
580
|
-
const onAbort = () => {
|
|
794
|
+
const onAbort = () => {
|
|
795
|
+
this.#finishPrompt(null);
|
|
796
|
+
if (this.#tty && !this.#disposed)
|
|
797
|
+
this.#render();
|
|
798
|
+
};
|
|
581
799
|
request.signal.addEventListener('abort', onAbort, { once: true });
|
|
582
800
|
pending.offAbort = () => { request.signal?.removeEventListener('abort', onAbort); };
|
|
583
801
|
}
|
|
584
802
|
this.#prompt = pending;
|
|
585
803
|
this.#promptDisplaced = displaced;
|
|
804
|
+
if (this.#tty && request.wait !== undefined && request.refreshDocument === undefined && request.refreshDocumentSource === undefined && request.refreshOptions === undefined) {
|
|
805
|
+
const tick = setInterval(() => { if (!this.#disposed)
|
|
806
|
+
this.#render(); }, 1_000);
|
|
807
|
+
pending.offTick = () => { clearInterval(tick); };
|
|
808
|
+
}
|
|
809
|
+
if (this.#tty && (request.refreshDocument !== undefined || request.refreshDocumentSource !== undefined || request.refreshOptions !== undefined)) {
|
|
810
|
+
const tick = setInterval(() => {
|
|
811
|
+
if (this.#disposed || this.#prompt === null)
|
|
812
|
+
return;
|
|
813
|
+
try {
|
|
814
|
+
const detail = request.refreshDocument?.();
|
|
815
|
+
const source = request.refreshDocumentSource?.(this.#prompt.documentScroll === Number.POSITIVE_INFINITY);
|
|
816
|
+
const options = request.refreshOptions?.();
|
|
817
|
+
let changed = false;
|
|
818
|
+
if (source !== undefined && source !== this.#prompt.request.documentSource) {
|
|
819
|
+
const shift = (this.#prompt.request.documentSource?.firstLine ?? 1) - (source.firstLine ?? 1);
|
|
820
|
+
const anchor = this.#prompt.documentAnchor;
|
|
821
|
+
this.#prompt = { ...this.#prompt, request: { ...this.#prompt.request, documentSource: source },
|
|
822
|
+
...(anchor === undefined ? {} : { documentAnchor: { ...anchor, row: Math.max(0, anchor.row + shift) } }) };
|
|
823
|
+
changed = true;
|
|
824
|
+
}
|
|
825
|
+
if (options !== undefined && options !== this.#prompt.request.options) {
|
|
826
|
+
this.#prompt = refreshPromptOptions(this.#prompt, options, this.#editor.text);
|
|
827
|
+
changed = true;
|
|
828
|
+
}
|
|
829
|
+
if (detail !== undefined && detail !== this.#prompt.request.detail) {
|
|
830
|
+
this.#prompt = { ...this.#prompt, request: { ...this.#prompt.request, detail } };
|
|
831
|
+
changed = true;
|
|
832
|
+
}
|
|
833
|
+
if (changed)
|
|
834
|
+
this.#render();
|
|
835
|
+
}
|
|
836
|
+
catch (error) {
|
|
837
|
+
this.#finishPrompt(null);
|
|
838
|
+
this.notice(error instanceof Error ? error.message : String(error), { level: 'error' });
|
|
839
|
+
}
|
|
840
|
+
}, 250);
|
|
841
|
+
pending.offTick = () => { clearInterval(tick); };
|
|
842
|
+
}
|
|
586
843
|
if (this.#tty) {
|
|
587
844
|
this.#render();
|
|
588
845
|
}
|
|
589
846
|
else {
|
|
590
847
|
const lines = [request.question];
|
|
848
|
+
if (request.documentSource !== undefined)
|
|
849
|
+
lines.push('', request.documentSource.text);
|
|
591
850
|
if (request.detail !== undefined && request.detail !== '')
|
|
592
851
|
lines.push('', request.detail);
|
|
593
852
|
if (request.options !== undefined && request.options.length > 0) {
|
|
@@ -598,24 +857,31 @@ export class LocalTui {
|
|
|
598
857
|
? 'Choose labels/numbers separated by commas, or type a custom answer.'
|
|
599
858
|
: 'Choose a label/number, or type a custom answer.');
|
|
600
859
|
}
|
|
860
|
+
if (request.skippable === true)
|
|
861
|
+
lines.push('', 'A blank line skips this question.');
|
|
601
862
|
this.notice(`${request.title}\n${lines.join('\n')}`);
|
|
602
863
|
}
|
|
603
864
|
});
|
|
604
865
|
}
|
|
605
|
-
replaceSession(events, presentations, status = 'idle') {
|
|
866
|
+
replaceSession(events, presentations, status = 'idle', reason = 'open') {
|
|
606
867
|
this.#trajectory = null;
|
|
607
868
|
const state = replayEvents(events, presentations);
|
|
608
|
-
|
|
869
|
+
// Notices and tool catalogs do not turn a blank session into a document
|
|
870
|
+
// that /new needs to separate. Refreshes are the same document.
|
|
871
|
+
const boundary = reason === 'open' || (reason === 'new' && this.#state.blocks.some(block => block.kind !== 'notice' && block.kind !== 'toolCatalog'));
|
|
872
|
+
const blocks = boundary ? [transcriptSeam('session-opened'), ...state.blocks] : state.blocks;
|
|
873
|
+
this.#state = { ...state, status, compactCommandId: undefined, blocks };
|
|
609
874
|
this.#plain.resetPrinted();
|
|
610
875
|
this.#followTail();
|
|
611
876
|
this.#deferInitialRender = false;
|
|
612
|
-
this.#renderer.startEpoch({ replay: status === 'idle' ? 'full' : 'pinned' });
|
|
877
|
+
this.#renderer.startEpoch({ replay: reason === 'refresh' ? 'viewport' : status === 'idle' ? 'full' : 'pinned' });
|
|
613
878
|
if (this.#tty)
|
|
614
879
|
this.#render();
|
|
615
880
|
else
|
|
616
881
|
this.#plain.print();
|
|
617
882
|
}
|
|
618
883
|
setSession(info) {
|
|
884
|
+
this.#switchDraft(this.#inspected?.id ?? info.id);
|
|
619
885
|
this.#sessionId = info.id;
|
|
620
886
|
this.#herdr.setSession(info.id);
|
|
621
887
|
const title = info.title?.trim();
|
|
@@ -671,12 +937,18 @@ export class LocalTui {
|
|
|
671
937
|
theme: this.#themeName,
|
|
672
938
|
colors: this.#colors,
|
|
673
939
|
motion: this.#motion,
|
|
940
|
+
mathMode: this.#mathMode,
|
|
941
|
+
mermaidMode: this.#mermaidMode,
|
|
942
|
+
editor: this.#externalEditor,
|
|
674
943
|
terminalProgress: this.#terminalProgress,
|
|
675
|
-
|
|
944
|
+
copyOnSelect: this.#copyOnSelect,
|
|
945
|
+
mouseInteraction: this.#mouseInteraction,
|
|
946
|
+
pasteProtection: this.#pasteProtection,
|
|
676
947
|
checkUpdates: this.#checkUpdates,
|
|
677
948
|
startupChangelog: this.#startupChangelog,
|
|
678
949
|
notifications: this.#notificationPolicy,
|
|
679
950
|
notificationThreshold: this.#notificationThreshold,
|
|
951
|
+
notificationFocus: this.#notificationFocus,
|
|
680
952
|
statusBar: {
|
|
681
953
|
...this.#statusBar,
|
|
682
954
|
groups: [...this.#statusBar.groups],
|
|
@@ -692,6 +964,23 @@ export class LocalTui {
|
|
|
692
964
|
setPrefsPersist(persist) {
|
|
693
965
|
this.#persistPrefs = persist;
|
|
694
966
|
}
|
|
967
|
+
/** Bind the native Plugins section; unbinding cancels and drains its active form. */
|
|
968
|
+
bindPluginSettings(binding) {
|
|
969
|
+
if (this.#pluginSettings !== undefined)
|
|
970
|
+
throw new Error('omdsh-tui: Plugin settings are already bound');
|
|
971
|
+
this.#pluginSettings = binding;
|
|
972
|
+
return async () => {
|
|
973
|
+
if (this.#pluginSettings !== binding)
|
|
974
|
+
return;
|
|
975
|
+
this.#pluginSettings = undefined;
|
|
976
|
+
this.#pluginSettingsAbort?.abort();
|
|
977
|
+
await this.#pluginSettingsTask;
|
|
978
|
+
if (this.#settings !== null)
|
|
979
|
+
this.#settings = createSettings(this.prefs(), undefined, this.#agentBehavior, this.#features, undefined, discoverEditors(this.#externalEditor));
|
|
980
|
+
if (this.#tty && !this.#disposed)
|
|
981
|
+
this.#render();
|
|
982
|
+
};
|
|
983
|
+
}
|
|
695
984
|
bindAgentBehaviorSettings(binding) {
|
|
696
985
|
if (this.#updateAgentBehavior !== undefined) {
|
|
697
986
|
throw new Error('omdsh-tui: Agent behavior settings are already bound');
|
|
@@ -710,7 +999,7 @@ export class LocalTui {
|
|
|
710
999
|
this.#agentBehavior = undefined;
|
|
711
1000
|
this.#agentBehaviorPending = false;
|
|
712
1001
|
if (this.#settings !== null)
|
|
713
|
-
this.#settings = createSettings(this.prefs());
|
|
1002
|
+
this.#settings = createSettings(this.prefs(), undefined, this.#agentBehavior, this.#features, this.#pluginSettings?.entries(), discoverEditors(this.#externalEditor));
|
|
714
1003
|
if (this.#tty && !this.#disposed)
|
|
715
1004
|
this.#render();
|
|
716
1005
|
};
|
|
@@ -755,7 +1044,10 @@ export class LocalTui {
|
|
|
755
1044
|
return (await this.readInput())?.text ?? null;
|
|
756
1045
|
}
|
|
757
1046
|
restoreInput(submission) {
|
|
1047
|
+
this.#literalInput ||= submission.literal === true;
|
|
758
1048
|
this.#images.restore(submission);
|
|
1049
|
+
for (const file of submission.files ?? [])
|
|
1050
|
+
this.#files.add(file);
|
|
759
1051
|
this.#refreshAutocomplete();
|
|
760
1052
|
if (this.#tty)
|
|
761
1053
|
this.#render();
|
|
@@ -778,13 +1070,18 @@ export class LocalTui {
|
|
|
778
1070
|
this.#replaceInput(submission);
|
|
779
1071
|
}
|
|
780
1072
|
#currentSubmission() {
|
|
1073
|
+
const files = this.#files.copies();
|
|
781
1074
|
return {
|
|
782
|
-
text: this.#editor.
|
|
1075
|
+
text: this.#files.text(this.#editor.expandedText),
|
|
1076
|
+
...(this.#literalInput || this.#editor.startsWithPaste ? { literal: true } : {}),
|
|
783
1077
|
images: this.#images.copies(),
|
|
1078
|
+
...(files.length === 0 ? {} : { files }),
|
|
784
1079
|
};
|
|
785
1080
|
}
|
|
786
1081
|
#replaceInput(submission) {
|
|
1082
|
+
this.#literalInput = submission.literal === true;
|
|
787
1083
|
this.#images.replace(submission);
|
|
1084
|
+
this.#files.restore(submission.files);
|
|
788
1085
|
this.#historyIndex = 0;
|
|
789
1086
|
this.#refreshAutocomplete();
|
|
790
1087
|
if (this.#tty)
|
|
@@ -794,6 +1091,53 @@ export class LocalTui {
|
|
|
794
1091
|
this.#interrupts.add(listener);
|
|
795
1092
|
return () => { this.#interrupts.delete(listener); };
|
|
796
1093
|
}
|
|
1094
|
+
pendingInputs = {
|
|
1095
|
+
list: () => {
|
|
1096
|
+
if (this.#disposed)
|
|
1097
|
+
return [];
|
|
1098
|
+
if (this.#queueEditNewer !== null || this.#queueEditPending)
|
|
1099
|
+
throw new Error('Finish editing the queued follow-up with Enter before opening Queue.');
|
|
1100
|
+
return this.#queuedSubmissions.map(submission => {
|
|
1101
|
+
let id = this.#queuedInputIds.get(submission);
|
|
1102
|
+
if (id === undefined) {
|
|
1103
|
+
id = `local-${++this.#queuedInputSerial}`;
|
|
1104
|
+
this.#queuedInputIds.set(submission, id);
|
|
1105
|
+
}
|
|
1106
|
+
return { id, submission };
|
|
1107
|
+
});
|
|
1108
|
+
},
|
|
1109
|
+
update: (id, change) => {
|
|
1110
|
+
if (this.#disposed)
|
|
1111
|
+
return false;
|
|
1112
|
+
const index = this.#queuedSubmissions.findIndex(item => this.#queuedInputIds.get(item) === id);
|
|
1113
|
+
if (index < 0)
|
|
1114
|
+
return false;
|
|
1115
|
+
if (change.kind === 'remove')
|
|
1116
|
+
this.#queuedSubmissions.splice(index, 1);
|
|
1117
|
+
else if (change.kind === 'replace') {
|
|
1118
|
+
this.#queuedInputIds.set(change.submission, id);
|
|
1119
|
+
this.#queuedSubmissions[index] = change.submission;
|
|
1120
|
+
}
|
|
1121
|
+
else {
|
|
1122
|
+
const destination = index + change.direction;
|
|
1123
|
+
if (destination < 0 || destination >= this.#queuedSubmissions.length)
|
|
1124
|
+
return false;
|
|
1125
|
+
const other = this.#queuedSubmissions[destination];
|
|
1126
|
+
this.#queuedSubmissions[destination] = this.#queuedSubmissions[index];
|
|
1127
|
+
this.#queuedSubmissions[index] = other;
|
|
1128
|
+
}
|
|
1129
|
+
if (this.#tty && !this.#disposed)
|
|
1130
|
+
this.#render();
|
|
1131
|
+
return true;
|
|
1132
|
+
},
|
|
1133
|
+
};
|
|
1134
|
+
setQueueHandler(handler) {
|
|
1135
|
+
this.#queueHandler = handler;
|
|
1136
|
+
return () => { if (this.#queueHandler === handler) {
|
|
1137
|
+
this.#queueHotkeyAbort?.abort();
|
|
1138
|
+
this.#queueHandler = undefined;
|
|
1139
|
+
} };
|
|
1140
|
+
}
|
|
797
1141
|
onQueueEdit(listener) {
|
|
798
1142
|
this.#queueEdits.add(listener);
|
|
799
1143
|
return () => { this.#queueEdits.delete(listener); };
|
|
@@ -814,10 +1158,35 @@ export class LocalTui {
|
|
|
814
1158
|
this.#inspectSubmits.add(listener);
|
|
815
1159
|
return () => { this.#inspectSubmits.delete(listener); };
|
|
816
1160
|
}
|
|
1161
|
+
setSteerHandler(handler) {
|
|
1162
|
+
this.#steerHandler = handler;
|
|
1163
|
+
return () => { if (this.#steerHandler === handler)
|
|
1164
|
+
this.#steerHandler = undefined; };
|
|
1165
|
+
}
|
|
817
1166
|
dispose() {
|
|
818
1167
|
if (this.#disposed)
|
|
819
|
-
return;
|
|
1168
|
+
return this.#herdr.release();
|
|
1169
|
+
this.#flushPasteBurst(true);
|
|
1170
|
+
this.#flushDraft();
|
|
820
1171
|
this.#disposed = true;
|
|
1172
|
+
this.#steerHandler = undefined;
|
|
1173
|
+
this.#imagePreviewAbort?.abort();
|
|
1174
|
+
for (const directory of this.#imageTemporary) {
|
|
1175
|
+
try {
|
|
1176
|
+
rmSync(directory, { recursive: true, force: true });
|
|
1177
|
+
}
|
|
1178
|
+
catch { /* OS may still hold the opened file. */ }
|
|
1179
|
+
}
|
|
1180
|
+
this.#imageTemporary.clear();
|
|
1181
|
+
this.#queueHotkeyAbort?.abort();
|
|
1182
|
+
this.#queueHandler = undefined;
|
|
1183
|
+
if (this.#notificationTimer !== undefined)
|
|
1184
|
+
clearTimeout(this.#notificationTimer);
|
|
1185
|
+
this.#notificationQueue.clear();
|
|
1186
|
+
if (this.#pasteBurstTimer !== undefined)
|
|
1187
|
+
clearTimeout(this.#pasteBurstTimer);
|
|
1188
|
+
this.#pasteBurst.clear();
|
|
1189
|
+
this.#pluginSettingsAbort?.abort();
|
|
821
1190
|
if (this.#resizeTimer !== null) {
|
|
822
1191
|
clearTimeout(this.#resizeTimer);
|
|
823
1192
|
this.#resizeTimer = null;
|
|
@@ -839,6 +1208,8 @@ export class LocalTui {
|
|
|
839
1208
|
if (this.#tty) {
|
|
840
1209
|
this.#offData?.();
|
|
841
1210
|
this.#offResize?.();
|
|
1211
|
+
this.#offResume?.();
|
|
1212
|
+
this.#setMouseTracking(false);
|
|
842
1213
|
this.#term.input.setRawMode?.(false);
|
|
843
1214
|
// Leave the cursor on a fresh line below the last frame so the shell
|
|
844
1215
|
// prompt does not overwrite the transcript. Disable bracketed paste
|
|
@@ -849,7 +1220,7 @@ export class LocalTui {
|
|
|
849
1220
|
this.#term.output.write('\x1b]2;\x07');
|
|
850
1221
|
this.#writtenWindowTitle = undefined;
|
|
851
1222
|
}
|
|
852
|
-
this.#term.output.write('\x1b[?2004l\x1b[?25h\r\n');
|
|
1223
|
+
this.#term.output.write('\x1b[?2004l\x1b[?1004l\x1b[?25h\r\n');
|
|
853
1224
|
if (this.#resumeHintRequested && this.#sessionId !== undefined) {
|
|
854
1225
|
this.#term.output.write(`\r\nResume this session with ${APP_NAME} --resume ${this.#sessionId}\r\n`);
|
|
855
1226
|
}
|
|
@@ -869,7 +1240,7 @@ export class LocalTui {
|
|
|
869
1240
|
this.#offAgentBehaviorWatch = undefined;
|
|
870
1241
|
this.#settlePending(null);
|
|
871
1242
|
this.#finishPrompt(null);
|
|
872
|
-
this.#herdr.release();
|
|
1243
|
+
return this.#herdr.release();
|
|
873
1244
|
}
|
|
874
1245
|
/** Settle one pending read, detaching its abort listener. */
|
|
875
1246
|
#settlePending(submission) {
|
|
@@ -990,7 +1361,105 @@ export class LocalTui {
|
|
|
990
1361
|
this.#loopTick = null;
|
|
991
1362
|
}
|
|
992
1363
|
}
|
|
1364
|
+
#captureDraft() {
|
|
1365
|
+
if (this.#historyIndex > 0 && this.#historyDraft !== undefined)
|
|
1366
|
+
return this.#historyDraft;
|
|
1367
|
+
const editor = this.#prompt?.savedInput ?? this.#editor.snapshot();
|
|
1368
|
+
return { editor, images: this.#images.copies(), files: this.#files.snapshot(editor.text), literal: this.#literalInput };
|
|
1369
|
+
}
|
|
1370
|
+
#restoreDraft(draft) {
|
|
1371
|
+
this.#images.replace({ text: draft.editor.text, images: draft.images });
|
|
1372
|
+
this.#editor.restore(draft.editor);
|
|
1373
|
+
this.#files.restoreSnapshot(draft.files);
|
|
1374
|
+
this.#literalInput = draft.literal;
|
|
1375
|
+
}
|
|
1376
|
+
#draftKey() {
|
|
1377
|
+
return [this.#editor.revision, this.#editor.cursor, this.#images.revision, this.#files.revision, this.#literalInput].join(':');
|
|
1378
|
+
}
|
|
1379
|
+
#watchDraft() {
|
|
1380
|
+
if (this.#disposed || this.#draftStore === undefined || this.#draftScope === undefined || this.#prompt !== null || this.#historyIndex > 0)
|
|
1381
|
+
return;
|
|
1382
|
+
const key = this.#draftKey();
|
|
1383
|
+
if (key === this.#draftFingerprint)
|
|
1384
|
+
return;
|
|
1385
|
+
this.#draftFingerprint = key;
|
|
1386
|
+
this.#draftDirty = true;
|
|
1387
|
+
if (this.#draftTimer !== undefined)
|
|
1388
|
+
clearTimeout(this.#draftTimer);
|
|
1389
|
+
this.#draftTimer = setTimeout(() => { this.#draftTimer = undefined; this.#flushDraft(); }, 500);
|
|
1390
|
+
this.#draftTimer.unref?.();
|
|
1391
|
+
}
|
|
1392
|
+
#flushDraft() {
|
|
1393
|
+
this.#watchDraft();
|
|
1394
|
+
if (this.#draftTimer !== undefined)
|
|
1395
|
+
clearTimeout(this.#draftTimer);
|
|
1396
|
+
this.#draftTimer = undefined;
|
|
1397
|
+
const id = this.#draftScope;
|
|
1398
|
+
if (id === undefined || this.#draftStore === undefined || !this.#draftDirty && !this.#unsavedDrafts.has(id))
|
|
1399
|
+
return;
|
|
1400
|
+
const draft = this.#captureDraft();
|
|
1401
|
+
this.#draftDirty = false;
|
|
1402
|
+
try {
|
|
1403
|
+
this.#draftStore.save(id, draft);
|
|
1404
|
+
this.#unsavedDrafts.delete(id);
|
|
1405
|
+
this.#draftError = false;
|
|
1406
|
+
}
|
|
1407
|
+
catch (error) {
|
|
1408
|
+
this.#unsavedDrafts.set(id, draft);
|
|
1409
|
+
this.#reportDraftError('save', error);
|
|
1410
|
+
}
|
|
1411
|
+
}
|
|
1412
|
+
#reportDraftError(action, error) {
|
|
1413
|
+
if (this.#draftError)
|
|
1414
|
+
return;
|
|
1415
|
+
this.#draftError = true;
|
|
1416
|
+
this.notice(`Could not ${action} composer draft: ${error instanceof Error ? error.message : String(error)}`, { level: 'error' });
|
|
1417
|
+
}
|
|
1418
|
+
#clearDraft() {
|
|
1419
|
+
this.#historyDraft = undefined;
|
|
1420
|
+
if (this.#draftStore === undefined || this.#draftScope === undefined)
|
|
1421
|
+
return;
|
|
1422
|
+
// A sent or explicitly discarded input must not return after a quick exit.
|
|
1423
|
+
this.#draftFingerprint = this.#draftKey();
|
|
1424
|
+
this.#draftDirty = true;
|
|
1425
|
+
this.#flushDraft();
|
|
1426
|
+
}
|
|
1427
|
+
#switchDraft(id) {
|
|
1428
|
+
if (this.#draftStore === undefined || id === this.#draftScope)
|
|
1429
|
+
return;
|
|
1430
|
+
this.#flushPasteBurst(true);
|
|
1431
|
+
this.#finishPrompt(null);
|
|
1432
|
+
this.#flushDraft();
|
|
1433
|
+
const initialInput = this.#draftScope === undefined && this.#editor.text !== '' ? this.#captureDraft() : undefined;
|
|
1434
|
+
this.#draftScope = id;
|
|
1435
|
+
this.#historyIndex = 0;
|
|
1436
|
+
this.#historyDraft = undefined;
|
|
1437
|
+
this.#draft = '';
|
|
1438
|
+
this.#draftDirty = false;
|
|
1439
|
+
this.#draftError = false;
|
|
1440
|
+
this.#search = null;
|
|
1441
|
+
this.#ac = null;
|
|
1442
|
+
this.#restoreDraft({ editor: { text: '', cursor: 0, pastes: [] }, images: [], files: { entries: [], next: 0 }, literal: false });
|
|
1443
|
+
let restoreError;
|
|
1444
|
+
if (id !== undefined) {
|
|
1445
|
+
try {
|
|
1446
|
+
const draft = this.#unsavedDrafts.get(id) ?? this.#draftStore.load(id);
|
|
1447
|
+
if (draft !== undefined)
|
|
1448
|
+
this.#restoreDraft(draft);
|
|
1449
|
+
}
|
|
1450
|
+
catch (error) {
|
|
1451
|
+
restoreError = error;
|
|
1452
|
+
}
|
|
1453
|
+
}
|
|
1454
|
+
if (initialInput !== undefined)
|
|
1455
|
+
this.#restoreDraft(initialInput);
|
|
1456
|
+
this.#draftFingerprint = initialInput === undefined ? this.#draftKey() : '';
|
|
1457
|
+
this.#refreshAutocomplete();
|
|
1458
|
+
if (restoreError !== undefined)
|
|
1459
|
+
this.#reportDraftError('restore', restoreError);
|
|
1460
|
+
}
|
|
993
1461
|
#render() {
|
|
1462
|
+
this.#watchDraft();
|
|
994
1463
|
if (this.#streamRenderTimer !== null) {
|
|
995
1464
|
clearTimeout(this.#streamRenderTimer);
|
|
996
1465
|
this.#streamRenderTimer = null;
|
|
@@ -1004,6 +1473,10 @@ export class LocalTui {
|
|
|
1004
1473
|
const frame = this.#tty
|
|
1005
1474
|
? renderView(renderState, {
|
|
1006
1475
|
width,
|
|
1476
|
+
...(this.#imageProtocol === undefined ? {} : { imageProtocol: this.#imageProtocol }),
|
|
1477
|
+
imageCellSize: this.#imageCellSize,
|
|
1478
|
+
mathMode: this.#mathMode,
|
|
1479
|
+
mermaidMode: this.#mermaidMode,
|
|
1007
1480
|
height: this.#term.height(),
|
|
1008
1481
|
model: this.#model,
|
|
1009
1482
|
...(this.#reasoningEffort === undefined ? {} : { reasoningEffort: this.#reasoningEffort }),
|
|
@@ -1024,7 +1497,7 @@ export class LocalTui {
|
|
|
1024
1497
|
trueColor: this.#trueColor,
|
|
1025
1498
|
themeName: this.#themeName,
|
|
1026
1499
|
scrollStart: this.#follow ? Number.POSITIVE_INFINITY : this.#scrollStart,
|
|
1027
|
-
...(this.#focusBlock === undefined ? {} : { focusBlock: this.#focusBlock }),
|
|
1500
|
+
...(this.#focusBlock === undefined ? {} : { focusBlock: this.#focusBlock, focusBlockEdge: this.#focusBlockEdge ?? 'start' }),
|
|
1028
1501
|
...(this.#transcriptSearch === null ? {} : {
|
|
1029
1502
|
transcriptSearch: {
|
|
1030
1503
|
query: this.#transcriptSearch.query,
|
|
@@ -1034,7 +1507,11 @@ export class LocalTui {
|
|
|
1034
1507
|
},
|
|
1035
1508
|
}),
|
|
1036
1509
|
toolsExpanded: this.#toolsExpanded,
|
|
1037
|
-
expandedTools: this.#
|
|
1510
|
+
expandedTools: this.#detailedToolIds(),
|
|
1511
|
+
toolDetailsKey: keysForAction(this.#keybindings, 'toggle-tool-details'),
|
|
1512
|
+
turnDetailsKey: keysForAction(this.#keybindings, 'toggle-tools'),
|
|
1513
|
+
...(this.#steerHandler === undefined ? {} : { steerKey: keysForAction(this.#keybindings, 'steer-turn') }),
|
|
1514
|
+
openedGroups: this.#openedGroups,
|
|
1038
1515
|
commands: this.#commands(),
|
|
1039
1516
|
recentSessions: this.#recentSessions,
|
|
1040
1517
|
welcomeTips: this.#welcomeTips,
|
|
@@ -1058,9 +1535,27 @@ export class LocalTui {
|
|
|
1058
1535
|
})
|
|
1059
1536
|
: { lines: [] };
|
|
1060
1537
|
this.#focusBlock = undefined;
|
|
1538
|
+
this.#focusBlockEdge = undefined;
|
|
1061
1539
|
this.#promptDocument = frame.promptDocument;
|
|
1540
|
+
if (this.#prompt !== null && this.#prompt.documentScroll !== Number.POSITIVE_INFINITY && frame.promptDocument?.position !== undefined) {
|
|
1541
|
+
this.#prompt = { ...this.#prompt, documentAnchor: frame.promptDocument.position };
|
|
1542
|
+
}
|
|
1062
1543
|
this.#syncScroll(frame.transcript);
|
|
1063
|
-
this.#
|
|
1544
|
+
this.#jumpToLatest = frame.jumpToLatest;
|
|
1545
|
+
this.#setMouseTracking(frame.transcript !== undefined && frame.transientSurface !== 'overlay'
|
|
1546
|
+
&& (this.#inspecting || this.#maxStart > 0));
|
|
1547
|
+
// A run opening or folding reshapes rows above the screen in place; the
|
|
1548
|
+
// renderer's frozen boundary is a row index and has to be told, or a fold
|
|
1549
|
+
// blanks the screen and a large one replays the transcript into history.
|
|
1550
|
+
const scroll = frame.transcript;
|
|
1551
|
+
if (scroll?.foldShape !== undefined && scroll.foldMarks !== undefined) {
|
|
1552
|
+
if (this.#foldMarks !== undefined && scroll.foldShape !== this.#foldShape) {
|
|
1553
|
+
this.#renderer.reflow((scroll.bodyRow ?? 0) + firstReshapedRow(this.#foldMarks, scroll.foldMarks));
|
|
1554
|
+
}
|
|
1555
|
+
this.#foldShape = scroll.foldShape;
|
|
1556
|
+
this.#foldMarks = scroll.foldMarks;
|
|
1557
|
+
}
|
|
1558
|
+
this.#renderer.render(frame, rows => this.#selection.paint(rows));
|
|
1064
1559
|
}
|
|
1065
1560
|
#scheduleStreamRender() {
|
|
1066
1561
|
if (this.#streamRenderTimer !== null)
|
|
@@ -1073,16 +1568,17 @@ export class LocalTui {
|
|
|
1073
1568
|
}
|
|
1074
1569
|
#syncScroll(scroll) {
|
|
1075
1570
|
if (scroll === undefined) {
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
this.#scrollBudget = 0;
|
|
1079
|
-
this.#follow = true;
|
|
1571
|
+
// Full-screen surfaces temporarily cover the transcript. They carry no
|
|
1572
|
+
// scroll projection and must not replace the reader's return position.
|
|
1080
1573
|
return;
|
|
1081
1574
|
}
|
|
1082
1575
|
this.#scrollStart = scroll.start;
|
|
1083
1576
|
this.#maxStart = scroll.maxStart;
|
|
1084
1577
|
this.#scrollBudget = scroll.budget;
|
|
1085
|
-
|
|
1578
|
+
this.#blockStarts = scroll.blockStarts?.map(row => row + (scroll.bodyRow ?? 0)) ?? [];
|
|
1579
|
+
// An inspection stays a browsing frame even when everything fits: resuming
|
|
1580
|
+
// the follow would drop the openings the reader just asked for.
|
|
1581
|
+
if (!this.#inspecting && (this.#follow || this.#scrollStart >= this.#maxStart)) {
|
|
1086
1582
|
this.#follow = true;
|
|
1087
1583
|
this.#scrollStart = this.#maxStart;
|
|
1088
1584
|
}
|
|
@@ -1091,8 +1587,22 @@ export class LocalTui {
|
|
|
1091
1587
|
return Math.max(1, this.#scrollBudget > 2 ? this.#scrollBudget - 2 : 1);
|
|
1092
1588
|
}
|
|
1093
1589
|
#scrollBy(delta) {
|
|
1590
|
+
if (this.#follow && delta > 0)
|
|
1591
|
+
return;
|
|
1094
1592
|
if (delta === 0 && this.#maxStart === 0)
|
|
1095
1593
|
return;
|
|
1594
|
+
if (!this.#inspecting && delta > 0 && this.#scrollStart + delta >= this.#maxStart) {
|
|
1595
|
+
this.#followTail();
|
|
1596
|
+
this.#render();
|
|
1597
|
+
return;
|
|
1598
|
+
}
|
|
1599
|
+
// Scrolling past the end of an inspection is how a reader goes back to
|
|
1600
|
+
// the live tail, the same as scrolling to the end of history does.
|
|
1601
|
+
if (this.#inspecting && delta > 0 && this.#scrollStart >= this.#maxStart) {
|
|
1602
|
+
this.#followTail();
|
|
1603
|
+
this.#render();
|
|
1604
|
+
return;
|
|
1605
|
+
}
|
|
1096
1606
|
this.#follow = false;
|
|
1097
1607
|
this.#scrollStart += delta;
|
|
1098
1608
|
if (this.#scrollStart <= 0)
|
|
@@ -1102,6 +1612,53 @@ export class LocalTui {
|
|
|
1102
1612
|
#followTail() {
|
|
1103
1613
|
this.#follow = true;
|
|
1104
1614
|
this.#scrollStart = this.#maxStart;
|
|
1615
|
+
this.#endInspection();
|
|
1616
|
+
}
|
|
1617
|
+
/** Close every opening the reader made; they belong to one inspection. */
|
|
1618
|
+
#endInspection() {
|
|
1619
|
+
if (!this.#inspecting)
|
|
1620
|
+
return;
|
|
1621
|
+
this.#inspecting = false;
|
|
1622
|
+
this.#toolsExpanded = false;
|
|
1623
|
+
this.#openedGroups.clear();
|
|
1624
|
+
this.#detailedTurns.clear();
|
|
1625
|
+
}
|
|
1626
|
+
/** Capture transcript navigation; overlays and disposal restore terminal ownership. */
|
|
1627
|
+
#setMouseTracking(enabled) {
|
|
1628
|
+
enabled = enabled && this.#mouseInteraction !== 'native'
|
|
1629
|
+
&& (this.#mouseInteraction === 'tui' || this.#tmuxMouseEnabled !== false);
|
|
1630
|
+
if (!enabled) {
|
|
1631
|
+
this.#selection.clear();
|
|
1632
|
+
this.#jumpPress = undefined;
|
|
1633
|
+
}
|
|
1634
|
+
if (!this.#tty || enabled === this.#mouseTracking)
|
|
1635
|
+
return;
|
|
1636
|
+
this.#mouseTracking = enabled;
|
|
1637
|
+
this.#term.output.write(enabled ? '\x1b[?1000h\x1b[?1002h\x1b[?1006h' : '\x1b[?1006l\x1b[?1002l\x1b[?1000l');
|
|
1638
|
+
}
|
|
1639
|
+
/**
|
|
1640
|
+
* After a Ctrl+O toggle: read what is open in a browsing frame at `target`,
|
|
1641
|
+
* or go back to the live tail once nothing is open any more.
|
|
1642
|
+
*/
|
|
1643
|
+
#inspect(target) {
|
|
1644
|
+
const open = this.#toolsExpanded || this.#openedGroups.size > 0;
|
|
1645
|
+
if (!open) {
|
|
1646
|
+
this.#inspecting = false;
|
|
1647
|
+
this.#followTail();
|
|
1648
|
+
return;
|
|
1649
|
+
}
|
|
1650
|
+
if (this.#inspecting)
|
|
1651
|
+
return;
|
|
1652
|
+
this.#inspecting = true;
|
|
1653
|
+
this.#follow = false;
|
|
1654
|
+
// Opening from the tail with nothing in particular under the viewport
|
|
1655
|
+
// keeps the reader at the end of the transcript, now in a browsing frame.
|
|
1656
|
+
if (target === undefined)
|
|
1657
|
+
this.#scrollStart = Number.MAX_SAFE_INTEGER;
|
|
1658
|
+
else {
|
|
1659
|
+
this.#focusBlock = target;
|
|
1660
|
+
this.#focusBlockEdge = 'end';
|
|
1661
|
+
}
|
|
1105
1662
|
}
|
|
1106
1663
|
#utf8 = new StringDecoder('utf8');
|
|
1107
1664
|
#onData(chunk) {
|
|
@@ -1114,20 +1671,77 @@ export class LocalTui {
|
|
|
1114
1671
|
clearTimeout(this.#escapeTimer);
|
|
1115
1672
|
this.#escapeTimer = null;
|
|
1116
1673
|
}
|
|
1117
|
-
|
|
1118
|
-
this.#dispatch(event);
|
|
1674
|
+
this.#routeInputBatch(events);
|
|
1119
1675
|
if (rest === '\x1b') {
|
|
1120
1676
|
this.#escapeTimer = setTimeout(() => {
|
|
1121
1677
|
this.#pendingKeys = '';
|
|
1122
1678
|
this.#escapeTimer = null;
|
|
1123
1679
|
for (const event of flushPending(rest))
|
|
1124
|
-
this.#
|
|
1680
|
+
this.#routeInput(event);
|
|
1125
1681
|
}, 80);
|
|
1126
1682
|
}
|
|
1127
1683
|
else if (rest.length > 32) {
|
|
1128
1684
|
this.#pendingKeys = '';
|
|
1129
1685
|
}
|
|
1130
1686
|
}
|
|
1687
|
+
#routeInputBatch(events) {
|
|
1688
|
+
if (this.#pasteProtection && this.#state.status !== 'compacting' && !this.#paste && this.#pasteInFlight === 0
|
|
1689
|
+
&& this.#prompt === null && this.#settings === null && this.#copySelector === null
|
|
1690
|
+
&& this.#search === null && this.#trajectory === null && this.#agentHub === null && this.#transcriptSearch === null
|
|
1691
|
+
&& events.every(event => event.type === 'text' || (event.type === 'key' && ['enter', 'ctrl+j', 'tab'].includes(event.id)))) {
|
|
1692
|
+
if (this.#pasteBurstTimer !== undefined)
|
|
1693
|
+
clearTimeout(this.#pasteBurstTimer);
|
|
1694
|
+
for (const event of this.#pasteBurst.pushBatch(events, Date.now()))
|
|
1695
|
+
this.#deliverPasteEmission(event);
|
|
1696
|
+
this.#armPasteBurst();
|
|
1697
|
+
}
|
|
1698
|
+
else
|
|
1699
|
+
for (const event of events)
|
|
1700
|
+
this.#routeInput(event);
|
|
1701
|
+
}
|
|
1702
|
+
#armPasteBurst() {
|
|
1703
|
+
this.#pasteBurstTimer = undefined;
|
|
1704
|
+
if (this.#pasteBurst.pending) {
|
|
1705
|
+
this.#pasteBurstTimer = setTimeout(() => { this.#pasteBurstTimer = undefined; this.#flushPasteBurst(true); }, this.#pasteBurst.delay);
|
|
1706
|
+
}
|
|
1707
|
+
}
|
|
1708
|
+
#routeInput(event) {
|
|
1709
|
+
if (event.type === 'focus' || event.type === 'cell-size') {
|
|
1710
|
+
this.#dispatch(event);
|
|
1711
|
+
return;
|
|
1712
|
+
}
|
|
1713
|
+
const composer = this.#state.status !== 'compacting' && this.#prompt === null && this.#settings === null && this.#copySelector === null
|
|
1714
|
+
&& this.#search === null && this.#trajectory === null && this.#agentHub === null && this.#transcriptSearch === null;
|
|
1715
|
+
if (this.#paste || this.#pasteInFlight > 0 || !this.#pasteProtection || !composer
|
|
1716
|
+
|| event.type === 'paste-start' || event.type === 'paste-end') {
|
|
1717
|
+
this.#flushPasteBurst(true);
|
|
1718
|
+
this.#pasteBurst.clear();
|
|
1719
|
+
this.#dispatch(event);
|
|
1720
|
+
return;
|
|
1721
|
+
}
|
|
1722
|
+
if (this.#pasteBurstTimer !== undefined)
|
|
1723
|
+
clearTimeout(this.#pasteBurstTimer);
|
|
1724
|
+
this.#pasteBurstTimer = undefined;
|
|
1725
|
+
for (const emission of this.#pasteBurst.push(event, Date.now()))
|
|
1726
|
+
this.#deliverPasteEmission(emission);
|
|
1727
|
+
this.#armPasteBurst();
|
|
1728
|
+
}
|
|
1729
|
+
#deliverPasteEmission(event) {
|
|
1730
|
+
if (event.type === 'paste') {
|
|
1731
|
+
this.#editor.paste(event.value.replaceAll('\r\n', '\n').replaceAll('\r', '\n'));
|
|
1732
|
+
this.#refreshAutocomplete();
|
|
1733
|
+
this.#render();
|
|
1734
|
+
}
|
|
1735
|
+
else
|
|
1736
|
+
this.#dispatch(event);
|
|
1737
|
+
}
|
|
1738
|
+
#flushPasteBurst(force = false) {
|
|
1739
|
+
if (this.#pasteBurstTimer !== undefined)
|
|
1740
|
+
clearTimeout(this.#pasteBurstTimer);
|
|
1741
|
+
this.#pasteBurstTimer = undefined;
|
|
1742
|
+
for (const event of this.#pasteBurst.flush(Date.now(), force))
|
|
1743
|
+
this.#deliverPasteEmission(event);
|
|
1744
|
+
}
|
|
1131
1745
|
#startAsyncPaste(operation) {
|
|
1132
1746
|
this.#pasteInFlight += 1;
|
|
1133
1747
|
void operation.catch((error) => {
|
|
@@ -1148,6 +1762,16 @@ export class LocalTui {
|
|
|
1148
1762
|
}
|
|
1149
1763
|
async #acceptPastedText(text) {
|
|
1150
1764
|
if (this.#prompt !== null) {
|
|
1765
|
+
const prompt = this.#prompt;
|
|
1766
|
+
if (prompt.request.documentSource !== undefined && prompt.documentInput !== undefined) {
|
|
1767
|
+
this.#handleDocumentReader({ type: 'text', value: text }, prompt);
|
|
1768
|
+
return;
|
|
1769
|
+
}
|
|
1770
|
+
if (prompt.request.wait !== undefined && prompt.waitHeld !== true) {
|
|
1771
|
+
prompt.request.wait.hold();
|
|
1772
|
+
prompt.offTick?.();
|
|
1773
|
+
this.#prompt = { ...prompt, waitHeld: true };
|
|
1774
|
+
}
|
|
1151
1775
|
this.#editor.handle({ type: 'text', value: text });
|
|
1152
1776
|
this.#render();
|
|
1153
1777
|
return;
|
|
@@ -1186,7 +1810,7 @@ export class LocalTui {
|
|
|
1186
1810
|
return;
|
|
1187
1811
|
}
|
|
1188
1812
|
}
|
|
1189
|
-
this.#editor.
|
|
1813
|
+
this.#editor.paste(text);
|
|
1190
1814
|
this.#refreshAutocomplete();
|
|
1191
1815
|
this.#render();
|
|
1192
1816
|
}
|
|
@@ -1226,8 +1850,120 @@ export class LocalTui {
|
|
|
1226
1850
|
if (text !== '')
|
|
1227
1851
|
await this.#acceptPastedText(text);
|
|
1228
1852
|
}
|
|
1853
|
+
/** Resolve one bounded tmux probe without overwriting an explicit preference. */
|
|
1854
|
+
setTmuxMouseEnabled(enabled) {
|
|
1855
|
+
if (this.#disposed)
|
|
1856
|
+
return;
|
|
1857
|
+
this.#tmuxMouseEnabled = enabled;
|
|
1858
|
+
if (this.#tty)
|
|
1859
|
+
this.#render();
|
|
1860
|
+
}
|
|
1861
|
+
#handleMouse(event) {
|
|
1862
|
+
if (!this.#mouseTracking || this.#paste || this.#pasteInFlight > 0)
|
|
1863
|
+
return;
|
|
1864
|
+
const inside = (target) => event.row === target.row && event.column >= target.column && event.column < target.column + target.width;
|
|
1865
|
+
if (event.button === 'right') {
|
|
1866
|
+
if (event.action === 'press')
|
|
1867
|
+
void this.#copySelection();
|
|
1868
|
+
return;
|
|
1869
|
+
}
|
|
1870
|
+
if (event.action === 'press') {
|
|
1871
|
+
const target = this.#jumpToLatest;
|
|
1872
|
+
this.#jumpPress = target !== undefined && inside(target) ? target : undefined;
|
|
1873
|
+
if (this.#jumpPress !== undefined)
|
|
1874
|
+
this.#selection.clear();
|
|
1875
|
+
else
|
|
1876
|
+
this.#selection.begin(this.#renderer.viewport(), event, Date.now(), event.shift);
|
|
1877
|
+
}
|
|
1878
|
+
else if (this.#jumpPress !== undefined) {
|
|
1879
|
+
const target = this.#jumpPress;
|
|
1880
|
+
// A drag that starts on the floating button must not activate it on release.
|
|
1881
|
+
if (event.action === 'drag')
|
|
1882
|
+
this.#jumpPress = undefined;
|
|
1883
|
+
else {
|
|
1884
|
+
this.#jumpPress = undefined;
|
|
1885
|
+
if (inside(target))
|
|
1886
|
+
this.#followTail();
|
|
1887
|
+
}
|
|
1888
|
+
}
|
|
1889
|
+
else if (event.action === 'drag')
|
|
1890
|
+
this.#selection.move(event);
|
|
1891
|
+
else {
|
|
1892
|
+
const text = this.#selection.release(event);
|
|
1893
|
+
if (text !== undefined && this.#copyOnSelect)
|
|
1894
|
+
void this.#copySelection();
|
|
1895
|
+
}
|
|
1896
|
+
this.#render();
|
|
1897
|
+
}
|
|
1898
|
+
/** Keep older clipboard operations from finishing after a newer user copy. */
|
|
1899
|
+
#deliverCopy(text) {
|
|
1900
|
+
const task = this.#copyTask.then(() => {
|
|
1901
|
+
if (this.#disposed)
|
|
1902
|
+
throw new Error('terminal closed');
|
|
1903
|
+
return this.#copy(text);
|
|
1904
|
+
});
|
|
1905
|
+
this.#copyTask = task.catch(() => { });
|
|
1906
|
+
return task;
|
|
1907
|
+
}
|
|
1908
|
+
async #copySelection() {
|
|
1909
|
+
if (!this.#selection.valid(this.#renderer.viewport())) {
|
|
1910
|
+
this.#selection.clear();
|
|
1911
|
+
return;
|
|
1912
|
+
}
|
|
1913
|
+
const text = this.#selection.text();
|
|
1914
|
+
if (text === undefined)
|
|
1915
|
+
return;
|
|
1916
|
+
try {
|
|
1917
|
+
await this.#deliverCopy(text);
|
|
1918
|
+
}
|
|
1919
|
+
catch {
|
|
1920
|
+
if (!this.#disposed)
|
|
1921
|
+
this.notice('Could not copy selection to the clipboard.', { level: 'error' });
|
|
1922
|
+
}
|
|
1923
|
+
}
|
|
1229
1924
|
#dispatch(event) {
|
|
1925
|
+
if (event.type === 'cell-size') {
|
|
1926
|
+
this.#imageCellSize = { width: event.width, height: event.height };
|
|
1927
|
+
if (this.#prompt?.request.documentImage !== undefined)
|
|
1928
|
+
this.#render();
|
|
1929
|
+
return;
|
|
1930
|
+
}
|
|
1931
|
+
if (event.type === 'focus') {
|
|
1932
|
+
this.#terminalFocused = event.focused;
|
|
1933
|
+
if (event.focused && this.#notificationFocus === 'unfocused')
|
|
1934
|
+
this.#notificationQueue.clear();
|
|
1935
|
+
return;
|
|
1936
|
+
}
|
|
1937
|
+
if (event.type === 'mouse') {
|
|
1938
|
+
this.#handleMouse(event);
|
|
1939
|
+
return;
|
|
1940
|
+
}
|
|
1941
|
+
this.#jumpPress = undefined;
|
|
1942
|
+
if (this.#selection.active) {
|
|
1943
|
+
if (event.type === 'key' && (['super+c', 'enter'].includes(event.id) || this.#boundAction(event.id) === 'copy-prompt')) {
|
|
1944
|
+
void this.#copySelection();
|
|
1945
|
+
return;
|
|
1946
|
+
}
|
|
1947
|
+
this.#selection.clear();
|
|
1948
|
+
this.#render();
|
|
1949
|
+
if (event.type === 'key' && event.id === 'escape') {
|
|
1950
|
+
this.#lastEscapeTime = 0;
|
|
1951
|
+
return;
|
|
1952
|
+
}
|
|
1953
|
+
}
|
|
1954
|
+
if (event.type === 'wheel') {
|
|
1955
|
+
this.#jumpPress = undefined;
|
|
1956
|
+
if (this.#mouseTracking && !this.#paste && this.#pasteInFlight === 0) {
|
|
1957
|
+
this.#scrollBy(event.direction === 'up' ? -3 : 3);
|
|
1958
|
+
}
|
|
1959
|
+
return;
|
|
1960
|
+
}
|
|
1230
1961
|
if (this.#state.status === 'compacting') {
|
|
1962
|
+
if (event.type === 'key' && event.id === 'end' && this.#jumpToLatest !== undefined) {
|
|
1963
|
+
this.#followTail();
|
|
1964
|
+
this.#render();
|
|
1965
|
+
return;
|
|
1966
|
+
}
|
|
1231
1967
|
if (event.type === 'key' && event.id === 'pageUp') {
|
|
1232
1968
|
this.#scrollBy(-this.#pageSize());
|
|
1233
1969
|
return;
|
|
@@ -1257,8 +1993,12 @@ export class LocalTui {
|
|
|
1257
1993
|
}
|
|
1258
1994
|
if (event.type === 'text')
|
|
1259
1995
|
this.#pasteBuf += event.value;
|
|
1260
|
-
else if (event.type === 'key' &&
|
|
1996
|
+
else if (event.type === 'key' && event.id === 'enter')
|
|
1997
|
+
this.#pasteBuf += '\r';
|
|
1998
|
+
else if (event.type === 'key' && event.id === 'ctrl+j')
|
|
1261
1999
|
this.#pasteBuf += '\n';
|
|
2000
|
+
else if (event.type === 'key' && event.id === 'tab')
|
|
2001
|
+
this.#pasteBuf += '\t';
|
|
1262
2002
|
return;
|
|
1263
2003
|
}
|
|
1264
2004
|
if (event.type === 'paste-start') {
|
|
@@ -1307,6 +2047,12 @@ export class LocalTui {
|
|
|
1307
2047
|
this.#applyTranscriptSearch(event);
|
|
1308
2048
|
return;
|
|
1309
2049
|
}
|
|
2050
|
+
if (event.type === 'key' && event.id === 'end' && this.#jumpToLatest !== undefined
|
|
2051
|
+
&& this.#settings === null && this.#copySelector === null && this.#search === null) {
|
|
2052
|
+
this.#followTail();
|
|
2053
|
+
this.#render();
|
|
2054
|
+
return;
|
|
2055
|
+
}
|
|
1310
2056
|
if (event.type === 'key') {
|
|
1311
2057
|
const action = this.#boundAction(event.id);
|
|
1312
2058
|
if (action !== undefined && this.#runAction(action))
|
|
@@ -1350,9 +2096,12 @@ export class LocalTui {
|
|
|
1350
2096
|
listener();
|
|
1351
2097
|
}
|
|
1352
2098
|
else {
|
|
2099
|
+
this.#literalInput = false;
|
|
1353
2100
|
this.#editor.clear();
|
|
1354
2101
|
this.#images.clear();
|
|
2102
|
+
this.#files.clear();
|
|
1355
2103
|
this.#historyIndex = 0;
|
|
2104
|
+
this.#clearDraft();
|
|
1356
2105
|
this.#ac = null;
|
|
1357
2106
|
this.#render();
|
|
1358
2107
|
}
|
|
@@ -1382,6 +2131,10 @@ export class LocalTui {
|
|
|
1382
2131
|
if (this.#inspected.writable === true && (this.#editor.text !== '' || this.#images.count > 0)) {
|
|
1383
2132
|
this.#editor.clear();
|
|
1384
2133
|
this.#images.clear();
|
|
2134
|
+
this.#files.clear();
|
|
2135
|
+
this.#historyIndex = 0;
|
|
2136
|
+
this.#literalInput = false;
|
|
2137
|
+
this.#clearDraft();
|
|
1385
2138
|
this.#ac = null;
|
|
1386
2139
|
this.#render();
|
|
1387
2140
|
return;
|
|
@@ -1415,16 +2168,44 @@ export class LocalTui {
|
|
|
1415
2168
|
this.#applyCommand(this.#editor.handle(event));
|
|
1416
2169
|
}
|
|
1417
2170
|
#handlePrompt(event) {
|
|
1418
|
-
|
|
2171
|
+
let prompt = this.#prompt;
|
|
1419
2172
|
if (prompt === null)
|
|
1420
2173
|
return false;
|
|
1421
|
-
if (
|
|
2174
|
+
if (event.type === 'key' && event.id === 'ctrl+c' && prompt.request.interrupt !== undefined) {
|
|
2175
|
+
this.#lastSigintTime = Date.now();
|
|
2176
|
+
prompt.request.interrupt();
|
|
2177
|
+
this.#finishPrompt(null);
|
|
2178
|
+
if (this.#state.status !== 'idle')
|
|
2179
|
+
for (const listener of this.#interrupts)
|
|
2180
|
+
listener();
|
|
2181
|
+
this.#render();
|
|
2182
|
+
return true;
|
|
2183
|
+
}
|
|
2184
|
+
if (event.type === 'key' && event.id === 'ctrl+s' && prompt.request.skippable === true) {
|
|
2185
|
+
this.#editor.setText('');
|
|
2186
|
+
this.#finishPrompt('');
|
|
2187
|
+
this.#render();
|
|
2188
|
+
return true;
|
|
2189
|
+
}
|
|
2190
|
+
const takeTime = event.type === 'key' && event.id === 'ctrl+t';
|
|
2191
|
+
const editing = event.type === 'text' || (event.type === 'key'
|
|
2192
|
+
&& ['backspace', 'delete', 'up', 'down', 'tab', 'shift+tab'].includes(event.id));
|
|
2193
|
+
if (prompt.request.wait !== undefined && prompt.waitHeld !== true && (takeTime || editing)) {
|
|
2194
|
+
prompt.request.wait.hold();
|
|
2195
|
+
prompt.offTick?.();
|
|
2196
|
+
prompt = { ...prompt, waitHeld: true };
|
|
2197
|
+
this.#prompt = prompt;
|
|
2198
|
+
this.#render();
|
|
2199
|
+
}
|
|
2200
|
+
if (takeTime && prompt.request.wait !== undefined)
|
|
2201
|
+
return true;
|
|
2202
|
+
if (prompt.request.presentation === 'plan-review' || prompt.request.presentation === 'document')
|
|
1422
2203
|
return this.#handlePlanReview(event, prompt);
|
|
1423
2204
|
if (event.type === 'text' && this.#editor.text === '') {
|
|
1424
2205
|
const action = prompt.request.actions?.find(item => item.key === event.value);
|
|
1425
|
-
const selected = filteredPromptOptions(prompt.request, '')[prompt.selected];
|
|
1426
|
-
if (action !== undefined && selected !== undefined) {
|
|
1427
|
-
this.#finishPrompt(action.valuePrefix + (selected.value ?? selected.label));
|
|
2206
|
+
const selected = filteredPromptOptions(prompt.request, '', prompt.collapsed)[prompt.selected];
|
|
2207
|
+
if (action !== undefined && (action.scope === 'list' || selected !== undefined)) {
|
|
2208
|
+
this.#finishPrompt(action.valuePrefix + (action.scope === 'list' ? '' : selected.value ?? selected.label));
|
|
1428
2209
|
this.#render();
|
|
1429
2210
|
return true;
|
|
1430
2211
|
}
|
|
@@ -1437,7 +2218,7 @@ export class LocalTui {
|
|
|
1437
2218
|
if (event.type === 'text' && prompt.request.filterable === true) {
|
|
1438
2219
|
const command = this.#editor.handle(event);
|
|
1439
2220
|
if (command.kind === 'changed') {
|
|
1440
|
-
this.#prompt =
|
|
2221
|
+
this.#prompt = searchPromptSelection(prompt, this.#editor.text);
|
|
1441
2222
|
this.#render();
|
|
1442
2223
|
}
|
|
1443
2224
|
return true;
|
|
@@ -1446,14 +2227,43 @@ export class LocalTui {
|
|
|
1446
2227
|
return true;
|
|
1447
2228
|
if (event.type !== 'key')
|
|
1448
2229
|
return false;
|
|
1449
|
-
const filtered = filteredPromptOptions(prompt.request, this.#editor.text);
|
|
2230
|
+
const filtered = filteredPromptOptions(prompt.request, this.#editor.text, prompt.collapsed);
|
|
1450
2231
|
const count = filtered.length;
|
|
2232
|
+
if (prompt.request.presentation === 'fullscreen-tree' || prompt.request.presentation === 'fullscreen-list') {
|
|
2233
|
+
const action = prompt.request.actions?.find(item => item.key.toLowerCase() === event.id);
|
|
2234
|
+
const selected = filtered[prompt.selected];
|
|
2235
|
+
if (action !== undefined) {
|
|
2236
|
+
if (action.scope === 'list' || selected !== undefined) {
|
|
2237
|
+
this.#finishPrompt(action.valuePrefix + (action.scope === 'list' ? '' : selected.value ?? selected.label));
|
|
2238
|
+
this.#render();
|
|
2239
|
+
}
|
|
2240
|
+
return true;
|
|
2241
|
+
}
|
|
2242
|
+
}
|
|
1451
2243
|
if (event.id === 'escape' || event.id === 'ctrl+c') {
|
|
2244
|
+
if (event.id === 'escape' && prompt.request.presentation === 'fullscreen-tree' && this.#editor.text !== '') {
|
|
2245
|
+
const selected = filtered[prompt.selected]?.value;
|
|
2246
|
+
this.#editor.setText('');
|
|
2247
|
+
this.#prompt = { ...prompt, collapsed: new Set(), selected: Math.max(0, filteredPromptOptions(prompt.request, '').findIndex(option => option.value === selected)), previewScroll: 0 };
|
|
2248
|
+
this.#render();
|
|
2249
|
+
return true;
|
|
2250
|
+
}
|
|
1452
2251
|
this.#editor.setText('');
|
|
1453
2252
|
this.#finishPrompt(null);
|
|
1454
2253
|
this.#render();
|
|
1455
2254
|
return true;
|
|
1456
2255
|
}
|
|
2256
|
+
if (prompt.request.presentation === 'fullscreen-tree' && (event.id === 'left' || event.id === 'right')) {
|
|
2257
|
+
this.#prompt = movePromptTree(prompt, event.id, this.#editor.text);
|
|
2258
|
+
this.#render();
|
|
2259
|
+
return true;
|
|
2260
|
+
}
|
|
2261
|
+
if (prompt.request.presentation === 'fullscreen-tree' && (event.id === 'ctrl+up' || event.id === 'ctrl+down')) {
|
|
2262
|
+
const start = this.#promptDocument?.start ?? prompt.previewScroll ?? 0;
|
|
2263
|
+
this.#prompt = { ...prompt, previewScroll: Math.max(0, Math.min(start + (event.id === 'ctrl+up' ? -1 : 1), this.#promptDocument?.maxStart ?? 0)) };
|
|
2264
|
+
this.#render();
|
|
2265
|
+
return true;
|
|
2266
|
+
}
|
|
1457
2267
|
if (count === 0) {
|
|
1458
2268
|
if (prompt.request.filterable !== true)
|
|
1459
2269
|
return false;
|
|
@@ -1461,20 +2271,22 @@ export class LocalTui {
|
|
|
1461
2271
|
return true;
|
|
1462
2272
|
const command = this.#editor.handle(event);
|
|
1463
2273
|
if (command.kind === 'changed') {
|
|
1464
|
-
this.#prompt =
|
|
2274
|
+
this.#prompt = searchPromptSelection(prompt, this.#editor.text);
|
|
1465
2275
|
this.#render();
|
|
1466
2276
|
}
|
|
1467
2277
|
return true;
|
|
1468
2278
|
}
|
|
1469
2279
|
let next;
|
|
2280
|
+
const page = prompt.request.presentation === 'fullscreen-tree'
|
|
2281
|
+
? promptTreePageSize(prompt.request, this.#term.width(), this.#term.height()) : 10;
|
|
1470
2282
|
if (event.id === 'up' || event.id === 'shift+tab')
|
|
1471
2283
|
next = prompt.selected - 1;
|
|
1472
2284
|
else if (event.id === 'down' || event.id === 'tab')
|
|
1473
2285
|
next = prompt.selected + 1;
|
|
1474
2286
|
else if (event.id === 'pageUp')
|
|
1475
|
-
next = prompt.selected -
|
|
2287
|
+
next = prompt.request.presentation === 'fullscreen-tree' ? Math.max(0, prompt.selected - page) : prompt.selected - page;
|
|
1476
2288
|
else if (event.id === 'pageDown')
|
|
1477
|
-
next = prompt.selected +
|
|
2289
|
+
next = prompt.request.presentation === 'fullscreen-tree' ? Math.min(count - 1, prompt.selected + page) : prompt.selected + page;
|
|
1478
2290
|
else if (event.id === 'home')
|
|
1479
2291
|
next = 0;
|
|
1480
2292
|
else if (event.id === 'end')
|
|
@@ -1493,15 +2305,16 @@ export class LocalTui {
|
|
|
1493
2305
|
return true;
|
|
1494
2306
|
}
|
|
1495
2307
|
if (event.id === 'enter' && prompt.request.filterable === true) {
|
|
1496
|
-
|
|
2308
|
+
const answer = selectedFilteredPromptAnswer(prompt, this.#editor.text);
|
|
1497
2309
|
this.#editor.setText('');
|
|
2310
|
+
this.#finishPrompt(answer);
|
|
1498
2311
|
this.#render();
|
|
1499
2312
|
return true;
|
|
1500
2313
|
}
|
|
1501
2314
|
if (prompt.request.filterable === true) {
|
|
1502
2315
|
const command = this.#editor.handle(event);
|
|
1503
2316
|
if (command.kind === 'changed') {
|
|
1504
|
-
this.#prompt =
|
|
2317
|
+
this.#prompt = searchPromptSelection(prompt, this.#editor.text);
|
|
1505
2318
|
this.#render();
|
|
1506
2319
|
}
|
|
1507
2320
|
return true;
|
|
@@ -1509,6 +2322,17 @@ export class LocalTui {
|
|
|
1509
2322
|
return false;
|
|
1510
2323
|
}
|
|
1511
2324
|
#handlePlanReview(event, prompt) {
|
|
2325
|
+
const document = prompt.request.presentation === 'document';
|
|
2326
|
+
if (document && prompt.request.documentSource !== undefined && this.#handleDocumentReader(event, prompt))
|
|
2327
|
+
return true;
|
|
2328
|
+
if (document && event.type === 'text') {
|
|
2329
|
+
const action = prompt.request.actions?.find(item => item.key.toLowerCase() === event.value.toLowerCase());
|
|
2330
|
+
if (action !== undefined) {
|
|
2331
|
+
this.#finishPrompt(action.valuePrefix);
|
|
2332
|
+
this.#render();
|
|
2333
|
+
}
|
|
2334
|
+
return true;
|
|
2335
|
+
}
|
|
1512
2336
|
if (prompt.feedback === true) {
|
|
1513
2337
|
if (event.type === 'key' && event.id === 'ctrl+c') {
|
|
1514
2338
|
this.#editor.setText('');
|
|
@@ -1557,11 +2381,13 @@ export class LocalTui {
|
|
|
1557
2381
|
else if (event.id === 'home')
|
|
1558
2382
|
documentScroll = 0;
|
|
1559
2383
|
else if (event.id === 'end')
|
|
1560
|
-
documentScroll = scroll?.maxStart ?? prompt.documentScroll ?? 0;
|
|
2384
|
+
documentScroll = prompt.request.documentTail === true ? Number.POSITIVE_INFINITY : scroll?.maxStart ?? prompt.documentScroll ?? 0;
|
|
1561
2385
|
if (documentScroll !== undefined) {
|
|
1562
2386
|
this.#prompt = {
|
|
1563
2387
|
...prompt,
|
|
1564
|
-
|
|
2388
|
+
documentAnchor: undefined,
|
|
2389
|
+
documentTarget: undefined,
|
|
2390
|
+
documentScroll: documentScroll === Number.POSITIVE_INFINITY ? documentScroll : Math.max(0, Math.min(documentScroll, scroll?.maxStart ?? Number.POSITIVE_INFINITY)),
|
|
1565
2391
|
};
|
|
1566
2392
|
this.#render();
|
|
1567
2393
|
return true;
|
|
@@ -1582,7 +2408,7 @@ export class LocalTui {
|
|
|
1582
2408
|
return true;
|
|
1583
2409
|
const approve = prompt.request.approveValue ?? prompt.request.options?.[0]?.value
|
|
1584
2410
|
?? prompt.request.options?.[0]?.label;
|
|
1585
|
-
if (answer === approve) {
|
|
2411
|
+
if (document || answer === approve) {
|
|
1586
2412
|
this.#finishPrompt(answer);
|
|
1587
2413
|
}
|
|
1588
2414
|
else {
|
|
@@ -1594,6 +2420,85 @@ export class LocalTui {
|
|
|
1594
2420
|
}
|
|
1595
2421
|
return true;
|
|
1596
2422
|
}
|
|
2423
|
+
#handleDocumentReader(event, prompt) {
|
|
2424
|
+
const source = prompt.request.documentSource;
|
|
2425
|
+
const layout = documentLayout(source, createTheme(this.#colors, this.#trueColor, this.#themeName), Math.max(1, this.#term.width() - 6), {
|
|
2426
|
+
wordWrap: prompt.documentWordWrap ?? true, column: prompt.documentColumn ?? 0,
|
|
2427
|
+
});
|
|
2428
|
+
const start = this.#promptDocument?.start ?? 0;
|
|
2429
|
+
const current = prompt.documentTarget ?? layout.sourceRows[start] ?? 0;
|
|
2430
|
+
const origin = prompt.documentOrigin === undefined ? start : documentStart(layout, prompt.documentOrigin);
|
|
2431
|
+
const jump = (row) => {
|
|
2432
|
+
this.#prompt = { ...prompt, documentAnchor: undefined, documentTarget: row, documentScroll: row === undefined ? start : layout.starts[row] ?? start };
|
|
2433
|
+
};
|
|
2434
|
+
if (prompt.documentInput !== undefined) {
|
|
2435
|
+
if (event.type === 'key' && (event.id === 'escape' || event.id === 'ctrl+c')) {
|
|
2436
|
+
this.#editor.setText('');
|
|
2437
|
+
this.#prompt = { ...prompt, documentInput: undefined, documentQuery: prompt.documentOriginalQuery ?? '',
|
|
2438
|
+
documentAnchor: undefined, documentTarget: undefined, documentScroll: origin, documentError: undefined };
|
|
2439
|
+
}
|
|
2440
|
+
else if (event.type === 'key' && (event.id === 'enter' || event.id === 'ctrl+j')) {
|
|
2441
|
+
const text = this.#editor.text;
|
|
2442
|
+
const row = prompt.documentInput === 'line' && /^[1-9]\d*$/u.test(text.trim()) ? documentLineRow(source, Number(text)) : undefined;
|
|
2443
|
+
if (prompt.documentInput === 'line' && row === undefined) {
|
|
2444
|
+
this.#prompt = { ...prompt, documentError: source.diff ? 'Enter a new-file line shown in this diff.' : source.firstLine === undefined ? 'Enter a line number in this file.' : 'Enter a retained line number in this snapshot.' };
|
|
2445
|
+
}
|
|
2446
|
+
else {
|
|
2447
|
+
if (row !== undefined)
|
|
2448
|
+
jump(row);
|
|
2449
|
+
this.#prompt = { ...(this.#prompt ?? prompt), documentInput: undefined, documentError: undefined };
|
|
2450
|
+
this.#editor.setText('');
|
|
2451
|
+
}
|
|
2452
|
+
}
|
|
2453
|
+
else {
|
|
2454
|
+
const command = this.#editor.handle(event);
|
|
2455
|
+
if (command.kind === 'changed') {
|
|
2456
|
+
this.#prompt = { ...prompt, documentError: undefined };
|
|
2457
|
+
if (prompt.documentInput === 'search') {
|
|
2458
|
+
const query = this.#editor.text.replace(/\r?\n/gu, ' ');
|
|
2459
|
+
const matches = documentMatches(source, query);
|
|
2460
|
+
const row = matches.find(row => row >= (layout.sourceRows[origin] ?? 0)) ?? matches[0];
|
|
2461
|
+
this.#prompt = { ...prompt, documentError: undefined, documentQuery: query, documentAnchor: undefined,
|
|
2462
|
+
documentTarget: row,
|
|
2463
|
+
documentScroll: row === undefined ? origin : layout.starts[row] ?? start };
|
|
2464
|
+
}
|
|
2465
|
+
}
|
|
2466
|
+
}
|
|
2467
|
+
this.#render();
|
|
2468
|
+
return true;
|
|
2469
|
+
}
|
|
2470
|
+
const toggleWrap = event.type === 'text' && event.value.toLowerCase() === 'w';
|
|
2471
|
+
const pan = event.type === 'key' && (event.id === 'alt+left' || event.id === 'alt+right');
|
|
2472
|
+
if (toggleWrap || pan) {
|
|
2473
|
+
const wordWrap = toggleWrap ? !layout.wordWrap : false;
|
|
2474
|
+
const column = pan ? Math.max(0, Math.min(layout.maxColumn, layout.column + (event.id === 'alt+right' ? 8 : -8))) : layout.column;
|
|
2475
|
+
this.#prompt = { ...prompt, documentWordWrap: wordWrap, documentColumn: column,
|
|
2476
|
+
documentAnchor: { ...documentPosition(layout, start, prompt.documentQuery ?? ''), wrap: 0, wordWrap, column } };
|
|
2477
|
+
this.#render();
|
|
2478
|
+
return true;
|
|
2479
|
+
}
|
|
2480
|
+
const search = event.type === 'key' && event.id === 'ctrl+f' || event.type === 'text' && event.value === '/';
|
|
2481
|
+
const line = event.type === 'key' && event.id === 'ctrl+g' || event.type === 'text' && event.value.toLowerCase() === 'g';
|
|
2482
|
+
if (search || line) {
|
|
2483
|
+
this.#editor.setText(search ? prompt.documentQuery ?? '' : '');
|
|
2484
|
+
this.#prompt = { ...prompt, documentInput: search ? 'search' : 'line', documentOrigin: documentPosition(layout, start, prompt.documentQuery ?? ''), documentError: undefined,
|
|
2485
|
+
documentScroll: start,
|
|
2486
|
+
documentOriginalQuery: prompt.documentQuery ?? '',
|
|
2487
|
+
documentAnchor: { row: current, wrap: start - (layout.starts[current] ?? 0), query: prompt.documentQuery ?? '' } };
|
|
2488
|
+
this.#render();
|
|
2489
|
+
return true;
|
|
2490
|
+
}
|
|
2491
|
+
if (event.type === 'key' && (event.id === 'ctrl+n' || event.id === 'ctrl+p')) {
|
|
2492
|
+
jump(documentDestination(documentMatches(source, prompt.documentQuery ?? ''), current, event.id === 'ctrl+n' ? 1 : -1));
|
|
2493
|
+
}
|
|
2494
|
+
else if (source.diff === true && event.type === 'text' && (event.value === '[' || event.value === ']')) {
|
|
2495
|
+
jump(documentDestination(documentModel(source).hunks, current, event.value === ']' ? 1 : -1));
|
|
2496
|
+
}
|
|
2497
|
+
else
|
|
2498
|
+
return false;
|
|
2499
|
+
this.#render();
|
|
2500
|
+
return true;
|
|
2501
|
+
}
|
|
1597
2502
|
#openInspect(id) {
|
|
1598
2503
|
for (const listener of this.#inspects)
|
|
1599
2504
|
listener(id);
|
|
@@ -1642,7 +2547,7 @@ export class LocalTui {
|
|
|
1642
2547
|
#pickSubagent() {
|
|
1643
2548
|
this.#subagentLauncherFocused = false;
|
|
1644
2549
|
const agents = this.#subagents?.agents ?? [];
|
|
1645
|
-
if (agents.length === 0) {
|
|
2550
|
+
if (agents.length === 0 && !this.#subagents?.workflows?.length) {
|
|
1646
2551
|
this.notice('No subagents are available in this session.');
|
|
1647
2552
|
return;
|
|
1648
2553
|
}
|
|
@@ -1652,26 +2557,34 @@ export class LocalTui {
|
|
|
1652
2557
|
this.#search = null;
|
|
1653
2558
|
this.#trajectory = null;
|
|
1654
2559
|
this.#ac = null;
|
|
1655
|
-
this.#agentHub = createAgentHub({ agents });
|
|
2560
|
+
this.#agentHub = createAgentHub(this.#subagents ?? { agents });
|
|
1656
2561
|
this.#render();
|
|
1657
2562
|
}
|
|
1658
2563
|
#applyPrefs(prefs, options) {
|
|
1659
2564
|
const previousMotion = this.#motion;
|
|
1660
|
-
const expandChanged = prefs.expandTools !== this.#expandTools;
|
|
1661
2565
|
this.#themeName = prefs.theme;
|
|
1662
2566
|
this.#colors = prefs.colors;
|
|
1663
2567
|
this.#syncTrueColor();
|
|
1664
2568
|
this.#motion = prefs.motion ?? 'full';
|
|
2569
|
+
this.#flushPasteBurst(true);
|
|
2570
|
+
this.#pasteProtection = prefs.pasteProtection !== false;
|
|
2571
|
+
this.#externalEditor = prefs.editor ?? 'auto';
|
|
1665
2572
|
this.#terminalProgress = prefs.terminalProgress ?? false;
|
|
1666
|
-
this.#
|
|
2573
|
+
this.#copyOnSelect = prefs.copyOnSelect ?? true;
|
|
2574
|
+
this.#mathMode = prefs.mathMode ?? 'auto';
|
|
2575
|
+
this.#mermaidMode = prefs.mermaidMode ?? 'auto';
|
|
2576
|
+
this.#mouseInteraction = prefs.mouseInteraction ?? 'auto';
|
|
1667
2577
|
this.#checkUpdates = prefs.checkUpdates ?? true;
|
|
1668
2578
|
this.#startupChangelog = prefs.startupChangelog ?? 'summary';
|
|
1669
2579
|
this.#notificationPolicy = prefs.notifications ?? 'off';
|
|
1670
2580
|
this.#notificationThreshold = prefs.notificationThreshold ?? '30s';
|
|
2581
|
+
this.#notificationFocus = prefs.notificationFocus ?? 'unfocused';
|
|
2582
|
+
if (this.#notificationPolicy === 'off')
|
|
2583
|
+
this.#notificationQueue.clear();
|
|
1671
2584
|
this.#configureNotifications();
|
|
1672
2585
|
this.#statusBar = resolveStatusBarConfig(prefs.statusBar, prefs.statusPreset);
|
|
1673
|
-
if (options.forceToolsSync
|
|
1674
|
-
this.#toolsExpanded =
|
|
2586
|
+
if (options.forceToolsSync)
|
|
2587
|
+
this.#toolsExpanded = false;
|
|
1675
2588
|
if (previousMotion !== this.#motion) {
|
|
1676
2589
|
this.#stopRevealTick();
|
|
1677
2590
|
this.#reveal = undefined;
|
|
@@ -1708,16 +2621,61 @@ export class LocalTui {
|
|
|
1708
2621
|
this.#render();
|
|
1709
2622
|
}
|
|
1710
2623
|
}
|
|
2624
|
+
/**
|
|
2625
|
+
* Write the Features section's state into the Profile patch.
|
|
2626
|
+
*
|
|
2627
|
+
* `disabled` is a Loader option rather than plugin config, so the settings
|
|
2628
|
+
* service cannot express it; the Profile patch is the documented surface
|
|
2629
|
+
* that can, and the Harness reads it while composing the tree. Only the
|
|
2630
|
+
* managed block is rewritten, so hand-authored rows and comments survive.
|
|
2631
|
+
* A failure is reported and the overlay keeps the value it shows.
|
|
2632
|
+
*/
|
|
2633
|
+
#writeFeaturePatch() {
|
|
2634
|
+
const path = this.#featurePatch;
|
|
2635
|
+
const features = this.#features;
|
|
2636
|
+
if (path === undefined || features === undefined)
|
|
2637
|
+
return;
|
|
2638
|
+
try {
|
|
2639
|
+
let current = '';
|
|
2640
|
+
try {
|
|
2641
|
+
current = readFileSync(path, 'utf8');
|
|
2642
|
+
}
|
|
2643
|
+
catch {
|
|
2644
|
+
current = '';
|
|
2645
|
+
}
|
|
2646
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
2647
|
+
writeFileSync(path, replaceFeatureBlock(current, renderFeatureBlock(features)), 'utf8');
|
|
2648
|
+
}
|
|
2649
|
+
catch (error) {
|
|
2650
|
+
this.notice(`Feature toggles were not saved: ${error instanceof Error ? error.message : String(error)}`);
|
|
2651
|
+
this.#render();
|
|
2652
|
+
}
|
|
2653
|
+
}
|
|
1711
2654
|
#applySettings(event) {
|
|
1712
2655
|
if (this.#settings === null)
|
|
1713
2656
|
return;
|
|
2657
|
+
if (this.#pluginSettingsTask !== undefined)
|
|
2658
|
+
return;
|
|
1714
2659
|
const command = applySettingsEvent(this.#settings, event);
|
|
2660
|
+
if (command.kind === 'open-plugin') {
|
|
2661
|
+
this.#openPluginSettings(command.id);
|
|
2662
|
+
return;
|
|
2663
|
+
}
|
|
1715
2664
|
if (command.kind === 'update') {
|
|
1716
2665
|
this.#settings = command.state;
|
|
1717
2666
|
this.#render();
|
|
1718
2667
|
return;
|
|
1719
2668
|
}
|
|
1720
2669
|
if (command.kind === 'apply') {
|
|
2670
|
+
if (command.domain === 'features') {
|
|
2671
|
+
if (command.state.features === undefined)
|
|
2672
|
+
return;
|
|
2673
|
+
this.#settings = command.state;
|
|
2674
|
+
this.#features = command.state.features;
|
|
2675
|
+
this.#render();
|
|
2676
|
+
this.#writeFeaturePatch();
|
|
2677
|
+
return;
|
|
2678
|
+
}
|
|
1721
2679
|
if (command.domain === 'agent') {
|
|
1722
2680
|
if (this.#agentBehaviorPending || command.state.agent === undefined)
|
|
1723
2681
|
return;
|
|
@@ -1737,6 +2695,26 @@ export class LocalTui {
|
|
|
1737
2695
|
this.#render();
|
|
1738
2696
|
}
|
|
1739
2697
|
}
|
|
2698
|
+
#openPluginSettings(id) {
|
|
2699
|
+
const binding = this.#pluginSettings;
|
|
2700
|
+
if (binding === undefined)
|
|
2701
|
+
return;
|
|
2702
|
+
const closing = new AbortController();
|
|
2703
|
+
this.#pluginSettingsAbort = closing;
|
|
2704
|
+
this.#pluginSettingsTask = Promise.resolve().then(() => binding.edit(id, closing.signal)).catch((error) => {
|
|
2705
|
+
if (!closing.signal.aborted && !this.#disposed)
|
|
2706
|
+
this.notice(error instanceof Error ? error.message : String(error), { level: 'error' });
|
|
2707
|
+
}).finally(() => {
|
|
2708
|
+
this.#pluginSettingsAbort = undefined;
|
|
2709
|
+
this.#pluginSettingsTask = undefined;
|
|
2710
|
+
if (this.#settings !== null)
|
|
2711
|
+
this.#settings = { ...this.#settings, prefs: this.prefs(),
|
|
2712
|
+
...(this.#agentBehavior === undefined ? {} : { agent: this.#agentBehavior }),
|
|
2713
|
+
...(this.#features === undefined ? {} : { features: this.#features }), plugins: this.#pluginSettings?.entries() ?? [] };
|
|
2714
|
+
if (this.#tty && !this.#disposed)
|
|
2715
|
+
this.#render();
|
|
2716
|
+
});
|
|
2717
|
+
}
|
|
1740
2718
|
#applyCopySelector(event) {
|
|
1741
2719
|
if (this.#copySelector === null)
|
|
1742
2720
|
return;
|
|
@@ -1758,10 +2736,14 @@ export class LocalTui {
|
|
|
1758
2736
|
}
|
|
1759
2737
|
async #copyPicked(text, label) {
|
|
1760
2738
|
try {
|
|
1761
|
-
await this.#
|
|
1762
|
-
this.#
|
|
2739
|
+
const delivery = await this.#deliverCopy(text);
|
|
2740
|
+
if (this.#disposed)
|
|
2741
|
+
return;
|
|
2742
|
+
this.#notice(delivery === 'requested' ? 'Sent ' + label + ' to the terminal clipboard' : 'Copied ' + label);
|
|
1763
2743
|
}
|
|
1764
2744
|
catch {
|
|
2745
|
+
if (this.#disposed)
|
|
2746
|
+
return;
|
|
1765
2747
|
this.#notice('Copy failed');
|
|
1766
2748
|
}
|
|
1767
2749
|
this.#render();
|
|
@@ -1820,7 +2802,7 @@ export class LocalTui {
|
|
|
1820
2802
|
}
|
|
1821
2803
|
if (event.id === 'enter') {
|
|
1822
2804
|
this.#applySelectedCompletion();
|
|
1823
|
-
this.#submit(this.#editor.
|
|
2805
|
+
this.#submit(this.#editor.expandedText);
|
|
1824
2806
|
return true;
|
|
1825
2807
|
}
|
|
1826
2808
|
return false;
|
|
@@ -1935,7 +2917,7 @@ export class LocalTui {
|
|
|
1935
2917
|
const next = item.kind === 'path' || item.kind === 'session'
|
|
1936
2918
|
? applyPathCompletion(this.#editor.text, this.#editor.cursor, item)
|
|
1937
2919
|
: applySlashCompletion(this.#editor.text, this.#editor.cursor, item);
|
|
1938
|
-
this.#editor.
|
|
2920
|
+
this.#editor.replaceText(next.text, next.cursor);
|
|
1939
2921
|
this.#refreshAutocomplete();
|
|
1940
2922
|
}
|
|
1941
2923
|
#applyCommand(command) {
|
|
@@ -1974,11 +2956,14 @@ export class LocalTui {
|
|
|
1974
2956
|
return;
|
|
1975
2957
|
}
|
|
1976
2958
|
if (command.kind === 'clear') {
|
|
2959
|
+
this.#literalInput = false;
|
|
1977
2960
|
this.#editor.clear();
|
|
1978
2961
|
this.#images.clear();
|
|
2962
|
+
this.#files.clear();
|
|
1979
2963
|
this.#queueEditNewer = null;
|
|
1980
2964
|
this.#queueEditPending = false;
|
|
1981
2965
|
this.#historyIndex = 0;
|
|
2966
|
+
this.#clearDraft();
|
|
1982
2967
|
this.#ac = null;
|
|
1983
2968
|
this.#search = null;
|
|
1984
2969
|
this.#render();
|
|
@@ -1990,6 +2975,12 @@ export class LocalTui {
|
|
|
1990
2975
|
}
|
|
1991
2976
|
if (command.kind === 'suspend') {
|
|
1992
2977
|
if (process.platform !== 'win32') {
|
|
2978
|
+
if (this.#inspecting) {
|
|
2979
|
+
this.#followTail();
|
|
2980
|
+
this.#render();
|
|
2981
|
+
}
|
|
2982
|
+
this.#setMouseTracking(false);
|
|
2983
|
+
this.#term.output.write('\x1b[?1004l');
|
|
1993
2984
|
try {
|
|
1994
2985
|
process.kill(process.pid, 'SIGTSTP');
|
|
1995
2986
|
}
|
|
@@ -2007,8 +2998,10 @@ export class LocalTui {
|
|
|
2007
2998
|
return;
|
|
2008
2999
|
if (this.#history.length === 0 || this.#historyIndex >= this.#history.length)
|
|
2009
3000
|
return;
|
|
2010
|
-
if (this.#historyIndex === 0)
|
|
2011
|
-
this.#draft = this.#editor.
|
|
3001
|
+
if (this.#historyIndex === 0) {
|
|
3002
|
+
this.#draft = this.#editor.expandedText;
|
|
3003
|
+
this.#historyDraft = this.#captureDraft();
|
|
3004
|
+
}
|
|
2012
3005
|
this.#historyIndex += 1;
|
|
2013
3006
|
this.#editor.setText(this.#history[this.#history.length - this.#historyIndex] ?? '');
|
|
2014
3007
|
this.#refreshAutocomplete();
|
|
@@ -2055,7 +3048,12 @@ export class LocalTui {
|
|
|
2055
3048
|
if (this.#historyIndex === 0)
|
|
2056
3049
|
return;
|
|
2057
3050
|
this.#historyIndex -= 1;
|
|
2058
|
-
|
|
3051
|
+
if (this.#historyIndex === 0 && this.#historyDraft !== undefined) {
|
|
3052
|
+
this.#restoreDraft(this.#historyDraft);
|
|
3053
|
+
this.#draftFingerprint = this.#draftKey();
|
|
3054
|
+
}
|
|
3055
|
+
else
|
|
3056
|
+
this.#editor.setText(this.#historyIndex === 0 ? this.#draft : (this.#history[this.#history.length - this.#historyIndex] ?? ''));
|
|
2059
3057
|
this.#refreshAutocomplete();
|
|
2060
3058
|
this.#render();
|
|
2061
3059
|
}
|
|
@@ -2074,12 +3072,16 @@ export class LocalTui {
|
|
|
2074
3072
|
#submit(text) {
|
|
2075
3073
|
if (this.#prompt !== null) {
|
|
2076
3074
|
this.#editor.setText('');
|
|
2077
|
-
this.#
|
|
3075
|
+
const answer = this.#prompt.request.preserveWhitespace === true ? text : text.trim();
|
|
3076
|
+
this.#finishPrompt(answer.trim() === '' ? null : answer);
|
|
2078
3077
|
this.#render();
|
|
2079
3078
|
return;
|
|
2080
3079
|
}
|
|
2081
3080
|
const images = this.#images.copies();
|
|
2082
|
-
const
|
|
3081
|
+
const files = this.#files.copies();
|
|
3082
|
+
const submittedText = this.#files.text(images.length > 0 ? text.trim() : text);
|
|
3083
|
+
const literal = text === this.#editor.expandedText && (this.#literalInput || this.#editor.startsWithPaste);
|
|
3084
|
+
const submission = { text: submittedText, images, ...(files.length === 0 ? {} : { files }), ...(literal ? { literal: true } : {}) };
|
|
2083
3085
|
const queueEditNewer = this.#queueEditNewer;
|
|
2084
3086
|
const historyText = stripComposerImageMarkers(submittedText, images)
|
|
2085
3087
|
.replace(/[ \t]{2,}/gu, ' ')
|
|
@@ -2090,38 +3092,41 @@ export class LocalTui {
|
|
|
2090
3092
|
}
|
|
2091
3093
|
this.#historyIndex = 0;
|
|
2092
3094
|
this.#draft = '';
|
|
3095
|
+
this.#literalInput = false;
|
|
2093
3096
|
this.#queueEditNewer = null;
|
|
2094
3097
|
this.#queueEditPending = false;
|
|
2095
3098
|
this.#editor.setText('');
|
|
2096
3099
|
this.#images.clear();
|
|
3100
|
+
this.#files.clear();
|
|
3101
|
+
this.#clearDraft();
|
|
2097
3102
|
this.#ac = null;
|
|
2098
3103
|
this.#search = null;
|
|
2099
3104
|
this.#settings = null;
|
|
2100
3105
|
this.#copySelector = null;
|
|
2101
3106
|
this.#trajectory = null;
|
|
2102
3107
|
this.#agentHub = null;
|
|
2103
|
-
this.#followTail();
|
|
2104
3108
|
// Image placeholders are TUI-owned. Mixed image+slash drafts stay a
|
|
2105
3109
|
// submission so restore can keep the original markers; the runner strips
|
|
2106
3110
|
// them only to detect and execute Harness commands.
|
|
2107
|
-
const slash = images.length === 0 ? parseSlashInput(submittedText) : null;
|
|
3111
|
+
const slash = !literal && images.length === 0 && files.length === 0 ? parseSlashInput(submittedText) : null;
|
|
2108
3112
|
if (slash !== null) {
|
|
2109
3113
|
if (queueEditNewer !== null)
|
|
2110
3114
|
this.#queuedSubmissions.push(...queueEditNewer);
|
|
2111
3115
|
this.#runSlash(slash.name, slash.args);
|
|
2112
3116
|
return;
|
|
2113
3117
|
}
|
|
3118
|
+
this.#followTail();
|
|
2114
3119
|
const pending = this.#pending;
|
|
2115
3120
|
if (pending !== null) {
|
|
2116
3121
|
pending.offAbort?.();
|
|
2117
3122
|
this.#pending = null;
|
|
2118
|
-
pending.resolve(
|
|
3123
|
+
pending.resolve(submission);
|
|
2119
3124
|
if (queueEditNewer !== null)
|
|
2120
3125
|
this.#queuedSubmissions.push(...queueEditNewer);
|
|
2121
3126
|
}
|
|
2122
|
-
else if (submittedText !== '' || images.length > 0 || queueEditNewer !== null) {
|
|
2123
|
-
if (submittedText !== '' || images.length > 0) {
|
|
2124
|
-
this.#queuedSubmissions.push(
|
|
3127
|
+
else if (submittedText !== '' || images.length > 0 || files.length > 0 || queueEditNewer !== null) {
|
|
3128
|
+
if (submittedText !== '' || images.length > 0 || files.length > 0) {
|
|
3129
|
+
this.#queuedSubmissions.push(submission);
|
|
2125
3130
|
}
|
|
2126
3131
|
if (queueEditNewer !== null)
|
|
2127
3132
|
this.#queuedSubmissions.push(...queueEditNewer);
|
|
@@ -2129,8 +3134,10 @@ export class LocalTui {
|
|
|
2129
3134
|
this.#render();
|
|
2130
3135
|
}
|
|
2131
3136
|
#submitInspect(text) {
|
|
3137
|
+
const literal = text === this.#editor.expandedText && (this.#literalInput || this.#editor.startsWithPaste);
|
|
2132
3138
|
const images = this.#images.copies();
|
|
2133
|
-
const
|
|
3139
|
+
const files = this.#files.copies();
|
|
3140
|
+
const submittedText = this.#files.text(images.length > 0 ? text.trim() : text);
|
|
2134
3141
|
const historyText = stripComposerImageMarkers(submittedText, images)
|
|
2135
3142
|
.replace(/[ \t]{2,}/gu, ' ')
|
|
2136
3143
|
.trim();
|
|
@@ -2140,22 +3147,25 @@ export class LocalTui {
|
|
|
2140
3147
|
}
|
|
2141
3148
|
this.#historyIndex = 0;
|
|
2142
3149
|
this.#draft = '';
|
|
3150
|
+
this.#literalInput = false;
|
|
2143
3151
|
this.#editor.setText('');
|
|
2144
3152
|
this.#images.clear();
|
|
3153
|
+
this.#files.clear();
|
|
3154
|
+
this.#clearDraft();
|
|
2145
3155
|
this.#ac = null;
|
|
2146
3156
|
this.#search = null;
|
|
2147
|
-
|
|
2148
|
-
const slash = images.length === 0 ? parseSlashInput(submittedText) : null;
|
|
3157
|
+
const slash = !literal && images.length === 0 && files.length === 0 ? parseSlashInput(submittedText) : null;
|
|
2149
3158
|
if (slash !== null) {
|
|
2150
3159
|
this.#runSlash(slash.name, slash.args);
|
|
2151
3160
|
return;
|
|
2152
3161
|
}
|
|
2153
|
-
|
|
3162
|
+
this.#followTail();
|
|
3163
|
+
if (submittedText === '' && images.length === 0 && files.length === 0) {
|
|
2154
3164
|
this.#render();
|
|
2155
3165
|
return;
|
|
2156
3166
|
}
|
|
2157
3167
|
for (const listener of this.#inspectSubmits)
|
|
2158
|
-
listener({ text: submittedText, images });
|
|
3168
|
+
listener({ text: submittedText, images, ...(files.length === 0 ? {} : { files }) });
|
|
2159
3169
|
this.#render();
|
|
2160
3170
|
}
|
|
2161
3171
|
#runSlash(name, args = '') {
|
|
@@ -2165,25 +3175,13 @@ export class LocalTui {
|
|
|
2165
3175
|
}
|
|
2166
3176
|
const command = resolveSlashCommand(name, this.#commands());
|
|
2167
3177
|
if (command === undefined) {
|
|
2168
|
-
this.#notice('unknown command: /' + name);
|
|
2169
|
-
this.#render();
|
|
2170
|
-
return;
|
|
2171
|
-
}
|
|
2172
|
-
if (command.name === 'quit') {
|
|
2173
|
-
this.#render();
|
|
2174
|
-
this.#quit();
|
|
2175
|
-
return;
|
|
2176
|
-
}
|
|
2177
|
-
if (command.name === 'clear') {
|
|
2178
|
-
// Presentation-only reset: the agent may still own an active turn with
|
|
2179
|
-
// live status, todos, and queued inbox state. Clearing those would make
|
|
2180
|
-
// the next Ctrl-C (or follow-up) behave as if the session had finished.
|
|
2181
|
-
this.#state = { ...this.#state, blocks: [] };
|
|
2182
3178
|
this.#followTail();
|
|
2183
|
-
this.#
|
|
3179
|
+
this.#notice('unknown command: /' + name);
|
|
2184
3180
|
this.#render();
|
|
2185
3181
|
return;
|
|
2186
3182
|
}
|
|
3183
|
+
// Reading controls cover the current view; submitting a command that
|
|
3184
|
+
// opens one must preserve the same return position as a keyboard action.
|
|
2187
3185
|
if (command.name === 'settings') {
|
|
2188
3186
|
this.#runSettings(args);
|
|
2189
3187
|
return;
|
|
@@ -2192,11 +3190,8 @@ export class LocalTui {
|
|
|
2192
3190
|
void this.#runCopy(args);
|
|
2193
3191
|
return;
|
|
2194
3192
|
}
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
this.#render();
|
|
2198
|
-
return;
|
|
2199
|
-
}
|
|
3193
|
+
// A plugin decides whether its command opens a reading surface or changes
|
|
3194
|
+
// the document. Forwarding alone must not discard the return position.
|
|
2200
3195
|
if (!BUILTIN_SLASH_COMMANDS.some((entry) => entry.name === command.name)) {
|
|
2201
3196
|
if (this.#inspected !== undefined) {
|
|
2202
3197
|
this.#notice('Return to the parent session to run /' + command.name + '.');
|
|
@@ -2216,6 +3211,27 @@ export class LocalTui {
|
|
|
2216
3211
|
this.#render();
|
|
2217
3212
|
return;
|
|
2218
3213
|
}
|
|
3214
|
+
this.#followTail();
|
|
3215
|
+
if (command.name === 'quit') {
|
|
3216
|
+
this.#render();
|
|
3217
|
+
this.#quit();
|
|
3218
|
+
return;
|
|
3219
|
+
}
|
|
3220
|
+
if (command.name === 'clear') {
|
|
3221
|
+
// Presentation-only reset: the agent may still own an active turn with
|
|
3222
|
+
// live status, todos, and queued inbox state. Clearing those would make
|
|
3223
|
+
// the next Ctrl-C (or follow-up) behave as if the session had finished.
|
|
3224
|
+
this.#state = { ...this.#state, blocks: [transcriptSeam('cleared')] };
|
|
3225
|
+
this.#followTail();
|
|
3226
|
+
this.#renderer.startEpoch();
|
|
3227
|
+
this.#render();
|
|
3228
|
+
return;
|
|
3229
|
+
}
|
|
3230
|
+
if (command.name === 'tools') {
|
|
3231
|
+
this.#toolCatalog();
|
|
3232
|
+
this.#render();
|
|
3233
|
+
return;
|
|
3234
|
+
}
|
|
2219
3235
|
if (args !== '' && args !== 'full') {
|
|
2220
3236
|
this.#notice('Usage: /help [full]');
|
|
2221
3237
|
this.#render();
|
|
@@ -2262,8 +3278,19 @@ export class LocalTui {
|
|
|
2262
3278
|
this.#prompt = null;
|
|
2263
3279
|
this.#herdr.promptResolved();
|
|
2264
3280
|
pending.offAbort?.();
|
|
3281
|
+
pending.offTick?.();
|
|
3282
|
+
this.#editor.restore(pending.savedInput);
|
|
3283
|
+
this.#draftFingerprint = this.#draftKey();
|
|
2265
3284
|
pending.resolve(answer);
|
|
2266
3285
|
this.#restoreDisplacedSurface();
|
|
3286
|
+
if (this.#promptDocument?.position !== undefined) {
|
|
3287
|
+
try {
|
|
3288
|
+
pending.request.onDocumentPosition?.(this.#promptDocument.position);
|
|
3289
|
+
}
|
|
3290
|
+
catch (error) {
|
|
3291
|
+
this.notice(error instanceof Error ? error.message : String(error), { level: 'error' });
|
|
3292
|
+
}
|
|
3293
|
+
}
|
|
2267
3294
|
}
|
|
2268
3295
|
/** Save and close the visible overlay so a prompt owns both input and screen. */
|
|
2269
3296
|
#displaceSurface() {
|
|
@@ -2337,7 +3364,7 @@ export class LocalTui {
|
|
|
2337
3364
|
}
|
|
2338
3365
|
this.#search = null;
|
|
2339
3366
|
this.#ac = null;
|
|
2340
|
-
this.#settings = createSettings(this.prefs(), undefined, this.#agentBehavior);
|
|
3367
|
+
this.#settings = createSettings(this.prefs(), undefined, this.#agentBehavior, this.#features, this.#pluginSettings?.entries(), discoverEditors(this.#externalEditor));
|
|
2341
3368
|
this.#render();
|
|
2342
3369
|
}
|
|
2343
3370
|
#notice(text) {
|
|
@@ -2354,11 +3381,22 @@ export class LocalTui {
|
|
|
2354
3381
|
});
|
|
2355
3382
|
}
|
|
2356
3383
|
#emitNotification(notification) {
|
|
2357
|
-
if (notification === undefined || !this.#tty)
|
|
3384
|
+
if (notification === undefined || !this.#tty || this.#disposed)
|
|
2358
3385
|
return;
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
|
|
3386
|
+
if (this.#notificationFocus === 'unfocused' && this.#terminalFocused === true)
|
|
3387
|
+
return;
|
|
3388
|
+
this.#notificationQueue.offer(notification);
|
|
3389
|
+
if (this.#notificationTimer !== undefined)
|
|
3390
|
+
return;
|
|
3391
|
+
this.#notificationTimer = setTimeout(() => {
|
|
3392
|
+
this.#notificationTimer = undefined;
|
|
3393
|
+
const pending = this.#notificationQueue.take(this.#notificationFocus, this.#terminalFocused);
|
|
3394
|
+
if (pending === undefined || this.#disposed || this.#notificationPolicy === 'off')
|
|
3395
|
+
return;
|
|
3396
|
+
const sequence = terminalNotificationSequence(pending);
|
|
3397
|
+
if (sequence !== '')
|
|
3398
|
+
this.#term.output.write(sequence);
|
|
3399
|
+
}, 25);
|
|
2362
3400
|
}
|
|
2363
3401
|
#toolCatalog() {
|
|
2364
3402
|
this.#state = {
|
|
@@ -2379,6 +3417,91 @@ export class LocalTui {
|
|
|
2379
3417
|
#runAction(action) {
|
|
2380
3418
|
if (this.#prompt !== null || this.#settings !== null || this.#copySelector !== null)
|
|
2381
3419
|
return false;
|
|
3420
|
+
if (action === 'preview-images') {
|
|
3421
|
+
if (this.#search !== null || this.#inspected !== undefined)
|
|
3422
|
+
return false;
|
|
3423
|
+
if (this.#images.count === 0)
|
|
3424
|
+
this.notice('Paste an image before opening its preview.');
|
|
3425
|
+
else if (this.#imagePreviewAbort === undefined) {
|
|
3426
|
+
const abort = new AbortController();
|
|
3427
|
+
const revision = this.#images.revision;
|
|
3428
|
+
const session = this.#sessionId;
|
|
3429
|
+
this.#imagePreviewAbort = abort;
|
|
3430
|
+
void previewImages(this, this.#images.copies(), abort.signal, undefined, directory => {
|
|
3431
|
+
if (this.#disposed)
|
|
3432
|
+
rmSync(directory, { recursive: true, force: true });
|
|
3433
|
+
else
|
|
3434
|
+
this.#imageTemporary.add(directory);
|
|
3435
|
+
}, () => !this.#disposed && session === this.#sessionId && revision === this.#images.revision && this.#prompt === null && this.#settings === null)
|
|
3436
|
+
.catch((error) => { if (!abort.signal.aborted && !this.#disposed)
|
|
3437
|
+
this.notice(error instanceof Error ? error.message : String(error), { level: 'error' }); })
|
|
3438
|
+
.finally(() => { if (this.#imagePreviewAbort === abort)
|
|
3439
|
+
this.#imagePreviewAbort = undefined; });
|
|
3440
|
+
}
|
|
3441
|
+
return true;
|
|
3442
|
+
}
|
|
3443
|
+
if (action === 'expand-paste') {
|
|
3444
|
+
if (this.#search !== null)
|
|
3445
|
+
return false;
|
|
3446
|
+
this.#literalInput ||= this.#editor.startsWithPaste;
|
|
3447
|
+
this.#editor.expandPaste();
|
|
3448
|
+
this.#refreshAutocomplete();
|
|
3449
|
+
this.#render();
|
|
3450
|
+
return true;
|
|
3451
|
+
}
|
|
3452
|
+
if (action === 'manage-queue') {
|
|
3453
|
+
if (this.#inspected !== undefined)
|
|
3454
|
+
this.notice('Return to the parent session to manage queued messages.');
|
|
3455
|
+
else if (this.#queueHandler === undefined)
|
|
3456
|
+
this.notice('Queue management is unavailable in this profile.');
|
|
3457
|
+
else if (this.#queueHotkeyAbort === undefined) {
|
|
3458
|
+
const abort = new AbortController();
|
|
3459
|
+
this.#queueHotkeyAbort = abort;
|
|
3460
|
+
void this.#queueHandler(abort.signal).catch((error) => {
|
|
3461
|
+
if (!abort.signal.aborted && !this.#disposed)
|
|
3462
|
+
this.notice(error instanceof Error ? error.message : String(error), { level: 'error' });
|
|
3463
|
+
}).finally(() => { if (this.#queueHotkeyAbort === abort)
|
|
3464
|
+
this.#queueHotkeyAbort = undefined; });
|
|
3465
|
+
}
|
|
3466
|
+
return true;
|
|
3467
|
+
}
|
|
3468
|
+
if (action === 'steer-turn') {
|
|
3469
|
+
if (this.#search !== null)
|
|
3470
|
+
return false;
|
|
3471
|
+
if (this.#inspected !== undefined || this.#state.status !== 'running') {
|
|
3472
|
+
this.notice('Steering needs an active parent turn. Use Enter to send the next message.');
|
|
3473
|
+
}
|
|
3474
|
+
else if (this.#images.count > 0 || this.#files.copies().length > 0) {
|
|
3475
|
+
this.notice('Use Enter to queue attachments; steering accepts text only.');
|
|
3476
|
+
}
|
|
3477
|
+
else if (this.#queueEditNewer !== null || this.#queueEditPending) {
|
|
3478
|
+
this.notice('Finish editing the queued follow-up with Enter before steering.');
|
|
3479
|
+
}
|
|
3480
|
+
else if (this.#editor.expandedText.trim() !== '') {
|
|
3481
|
+
try {
|
|
3482
|
+
if (this.#steerHandler === undefined)
|
|
3483
|
+
throw new Error('Steering is unavailable in this profile.');
|
|
3484
|
+
this.#steerHandler(this.#editor.expandedText);
|
|
3485
|
+
this.#editor.setText('');
|
|
3486
|
+
this.#literalInput = false;
|
|
3487
|
+
this.#historyIndex = 0;
|
|
3488
|
+
this.#clearDraft();
|
|
3489
|
+
this.#ac = null;
|
|
3490
|
+
this.#render();
|
|
3491
|
+
}
|
|
3492
|
+
catch (error) {
|
|
3493
|
+
this.notice(error instanceof Error ? error.message : String(error), { level: 'error' });
|
|
3494
|
+
}
|
|
3495
|
+
}
|
|
3496
|
+
return true;
|
|
3497
|
+
}
|
|
3498
|
+
if (action === 'review-changes') {
|
|
3499
|
+
const anchor = this.#viewportBlock() ?? this.#state.blocks.length - 1;
|
|
3500
|
+
const nextUser = this.#state.blocks.findIndex((block, index) => index > anchor && block.kind === 'user');
|
|
3501
|
+
const workspace = this.#state.blocks.slice(0, nextUser < 0 ? undefined : nextUser).findLast(block => block.kind === 'workspace');
|
|
3502
|
+
this.#runSlash('diff', workspace?.kind === 'workspace' ? `turn ${workspace.turn}` : '');
|
|
3503
|
+
return true;
|
|
3504
|
+
}
|
|
2382
3505
|
if (action === 'scroll-page-up') {
|
|
2383
3506
|
if (this.#search !== null)
|
|
2384
3507
|
return false;
|
|
@@ -2406,7 +3529,13 @@ export class LocalTui {
|
|
|
2406
3529
|
if (action === 'toggle-tools') {
|
|
2407
3530
|
if (this.#search !== null)
|
|
2408
3531
|
return false;
|
|
2409
|
-
this.#
|
|
3532
|
+
this.#toggleFoldTarget();
|
|
3533
|
+
return true;
|
|
3534
|
+
}
|
|
3535
|
+
if (action === 'toggle-tool-details') {
|
|
3536
|
+
if (this.#search !== null)
|
|
3537
|
+
return false;
|
|
3538
|
+
this.#toggleToolDetails();
|
|
2410
3539
|
return true;
|
|
2411
3540
|
}
|
|
2412
3541
|
if (action === 'search-history') {
|
|
@@ -2450,11 +3579,11 @@ export class LocalTui {
|
|
|
2450
3579
|
return true;
|
|
2451
3580
|
}
|
|
2452
3581
|
if (action === 'copy-prompt') {
|
|
2453
|
-
void this.#copyPicked(this.#editor.
|
|
3582
|
+
void this.#copyPicked(this.#editor.expandedText, 'current prompt');
|
|
2454
3583
|
return true;
|
|
2455
3584
|
}
|
|
2456
3585
|
if (action === 'copy-line') {
|
|
2457
|
-
const text = this.#editor.
|
|
3586
|
+
const text = this.#editor.textRange(lineStart(this.#editor.text, this.#editor.cursor), lineEnd(this.#editor.text, this.#editor.cursor));
|
|
2458
3587
|
void this.#copyPicked(text, 'current line');
|
|
2459
3588
|
return true;
|
|
2460
3589
|
}
|
|
@@ -2463,8 +3592,11 @@ export class LocalTui {
|
|
|
2463
3592
|
return true;
|
|
2464
3593
|
}
|
|
2465
3594
|
try {
|
|
3595
|
+
this.#setMouseTracking(false);
|
|
3596
|
+
this.#term.output.write('\x1b[?1004l');
|
|
2466
3597
|
this.#term.input.setRawMode?.(false);
|
|
2467
|
-
|
|
3598
|
+
this.#literalInput ||= this.#editor.startsWithPaste;
|
|
3599
|
+
const text = editExternally(this.#editor.expandedText, this.#externalEditor);
|
|
2468
3600
|
this.#editor.setText(text);
|
|
2469
3601
|
this.#images.reconcile();
|
|
2470
3602
|
}
|
|
@@ -2472,33 +3604,140 @@ export class LocalTui {
|
|
|
2472
3604
|
this.notice(error instanceof Error ? error.message : String(error), { level: 'error' });
|
|
2473
3605
|
}
|
|
2474
3606
|
finally {
|
|
2475
|
-
this.#
|
|
2476
|
-
|
|
2477
|
-
|
|
2478
|
-
|
|
3607
|
+
if (!this.#disposed) {
|
|
3608
|
+
this.#term.input.setRawMode?.(true);
|
|
3609
|
+
this.#term.output.write('\x1b[?1004h');
|
|
3610
|
+
this.#renderer.reset();
|
|
3611
|
+
this.#refreshAutocomplete();
|
|
3612
|
+
this.#render();
|
|
3613
|
+
}
|
|
2479
3614
|
}
|
|
2480
3615
|
return true;
|
|
2481
3616
|
}
|
|
2482
|
-
/**
|
|
2483
|
-
|
|
2484
|
-
|
|
2485
|
-
|
|
2486
|
-
|
|
2487
|
-
|
|
2488
|
-
|
|
2489
|
-
|
|
3617
|
+
/**
|
|
3618
|
+
* Block index the reader is looking at: the first one that starts at or below
|
|
3619
|
+
* the top of the transcript window. A collapsed row has to stay reachable
|
|
3620
|
+
* after the reader scrolls away from the tail, so the toggle aims here rather
|
|
3621
|
+
* than at the newest call.
|
|
3622
|
+
*/
|
|
3623
|
+
#viewportBlock() {
|
|
3624
|
+
const starts = this.#blockStarts;
|
|
3625
|
+
if (starts.length === 0)
|
|
3626
|
+
return undefined;
|
|
3627
|
+
const at = this.#follow ? Number.POSITIVE_INFINITY : this.#scrollStart;
|
|
3628
|
+
let index = starts.findIndex(row => row >= at);
|
|
3629
|
+
if (index < 0)
|
|
3630
|
+
index = starts.length - 1;
|
|
3631
|
+
return index;
|
|
3632
|
+
}
|
|
3633
|
+
/** Restore the completed turn under the viewport, or close its inspection. */
|
|
3634
|
+
#toggleFoldTarget() {
|
|
3635
|
+
// Flush coalesced events so hit testing uses the blocks that are on screen.
|
|
3636
|
+
if (this.#streamRenderTimer !== null)
|
|
3637
|
+
this.#render();
|
|
3638
|
+
// Inside an inspection the key is the way back out: it closes what was
|
|
3639
|
+
// opened and returns to the live tail, wherever the reader has scrolled.
|
|
3640
|
+
if (this.#inspecting) {
|
|
3641
|
+
this.#followTail();
|
|
3642
|
+
this.#render();
|
|
3643
|
+
return;
|
|
2490
3644
|
}
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
|
|
2494
|
-
|
|
2495
|
-
|
|
3645
|
+
const anchor = this.#viewportBlock();
|
|
3646
|
+
const groups = turnGroups(this.#state).filter(item => !item.live);
|
|
3647
|
+
// The answer, changed-file record, and following notices still address
|
|
3648
|
+
// their turn when the reader is following the tail.
|
|
3649
|
+
const reach = (group) => {
|
|
3650
|
+
let at = group.until;
|
|
3651
|
+
const blocks = this.#state.blocks;
|
|
3652
|
+
while (at < blocks.length) {
|
|
3653
|
+
const block = blocks[at];
|
|
3654
|
+
if (block?.kind === 'workspace' || (block?.kind === 'notice' && block.boundary !== true)) {
|
|
3655
|
+
at += 1;
|
|
3656
|
+
continue;
|
|
3657
|
+
}
|
|
3658
|
+
break;
|
|
3659
|
+
}
|
|
3660
|
+
return at - 1;
|
|
3661
|
+
};
|
|
3662
|
+
const group = anchor === undefined
|
|
3663
|
+
? undefined
|
|
3664
|
+
: groups.findLast(item => {
|
|
3665
|
+
const first = this.#state.blocks[item.start - 1]?.kind === 'user' ? item.start - 1 : item.start;
|
|
3666
|
+
return anchor >= first && anchor <= reach(item);
|
|
3667
|
+
});
|
|
3668
|
+
if (group !== undefined) {
|
|
3669
|
+
this.#toggleSet(this.#openedGroups, group.key);
|
|
3670
|
+
this.#inspect((group.answer ?? group.until) - 1);
|
|
3671
|
+
this.#render();
|
|
3672
|
+
return;
|
|
2496
3673
|
}
|
|
2497
|
-
|
|
3674
|
+
if (anchor !== undefined && this.#state.blocks[anchor]?.kind === 'toolCatalog') {
|
|
2498
3675
|
this.#toolsExpanded = !this.#toolsExpanded;
|
|
3676
|
+
this.#inspect(anchor);
|
|
3677
|
+
this.#render();
|
|
2499
3678
|
}
|
|
3679
|
+
// A live turn already has the process presentation; Alt+O owns tool details.
|
|
3680
|
+
}
|
|
3681
|
+
#detailScope(group) {
|
|
3682
|
+
return group.turn === undefined ? group.key : `turn:${group.turn}`;
|
|
3683
|
+
}
|
|
3684
|
+
#detailedToolIds() {
|
|
3685
|
+
const calls = new Set();
|
|
3686
|
+
if (this.#detailedTurns.size === 0)
|
|
3687
|
+
return calls;
|
|
3688
|
+
for (const group of turnGroups(this.#state)) {
|
|
3689
|
+
if (!this.#detailedTurns.has(this.#detailScope(group)))
|
|
3690
|
+
continue;
|
|
3691
|
+
for (let at = group.start; at < group.until; at++) {
|
|
3692
|
+
const block = this.#state.blocks[at];
|
|
3693
|
+
if (block?.kind === 'tool')
|
|
3694
|
+
calls.add(block.callId);
|
|
3695
|
+
}
|
|
3696
|
+
}
|
|
3697
|
+
return calls;
|
|
3698
|
+
}
|
|
3699
|
+
#toggleToolDetails() {
|
|
3700
|
+
if (this.#streamRenderTimer !== null)
|
|
3701
|
+
this.#render();
|
|
3702
|
+
// A long tool can fill the viewport. Target the block containing its top,
|
|
3703
|
+
// rather than the next block starting below it (possibly another turn).
|
|
3704
|
+
const anchor = this.#follow ? this.#state.blocks.length - 1
|
|
3705
|
+
: Math.max(0, this.#blockStarts.findLastIndex(row => row <= this.#scrollStart));
|
|
3706
|
+
const groups = turnGroups(this.#state);
|
|
3707
|
+
const group = groups.findLast(item => {
|
|
3708
|
+
const first = this.#state.blocks[item.start - 1]?.kind === 'user' ? item.start - 1 : item.start;
|
|
3709
|
+
let end = item.until;
|
|
3710
|
+
while (end < this.#state.blocks.length) {
|
|
3711
|
+
const block = this.#state.blocks[end];
|
|
3712
|
+
if (block?.kind !== 'workspace' && !(block?.kind === 'notice' && block.boundary !== true))
|
|
3713
|
+
break;
|
|
3714
|
+
end++;
|
|
3715
|
+
}
|
|
3716
|
+
return anchor >= first && anchor < end;
|
|
3717
|
+
});
|
|
3718
|
+
if (group === undefined)
|
|
3719
|
+
return;
|
|
3720
|
+
const scope = this.#detailScope(group);
|
|
3721
|
+
const members = groups.filter(item => this.#detailScope(item) === scope);
|
|
3722
|
+
if (members.every(member => member.calls === 0))
|
|
3723
|
+
return;
|
|
3724
|
+
this.#toggleSet(this.#detailedTurns, scope);
|
|
3725
|
+
for (const member of members)
|
|
3726
|
+
this.#openedGroups.add(member.key);
|
|
3727
|
+
const tools = members.flatMap(member => this.#state.blocks.slice(member.start, member.until)
|
|
3728
|
+
.flatMap((block, offset) => block.kind === 'tool' ? [member.start + offset] : []));
|
|
3729
|
+
const target = tools.includes(anchor) ? anchor : tools[0];
|
|
3730
|
+
this.#inspect(target);
|
|
3731
|
+
this.#focusBlock = target;
|
|
3732
|
+
this.#focusBlockEdge = 'start';
|
|
2500
3733
|
this.#render();
|
|
2501
3734
|
}
|
|
3735
|
+
#toggleSet(set, key) {
|
|
3736
|
+
if (set.has(key))
|
|
3737
|
+
set.delete(key);
|
|
3738
|
+
else
|
|
3739
|
+
set.add(key);
|
|
3740
|
+
}
|
|
2502
3741
|
/** Fold one event into the active transcript search. */
|
|
2503
3742
|
#applyTranscriptSearch(event) {
|
|
2504
3743
|
const state = this.#transcriptSearch;
|
|
@@ -2538,12 +3777,17 @@ export function apply(ctx, config) {
|
|
|
2538
3777
|
deferInitialRender: true,
|
|
2539
3778
|
terminalProfile,
|
|
2540
3779
|
alternateScreenOverlays: terminalProfile === 'direct',
|
|
2541
|
-
herdrReporter: new HerdrAgentReporter(),
|
|
3780
|
+
herdrReporter: new HerdrAgentReporter({ interactive: term.input.isTTY === true && term.output.isTTY === true }),
|
|
2542
3781
|
historyPath: config.historyPath ?? join(dshHome, 'omdsh', 'history.jsonl'),
|
|
3782
|
+
draftsPath: join(config.dshHome ?? dshHome, 'omdsh', 'drafts'),
|
|
2543
3783
|
keybindingsPath: config.keybindingsPath ?? join(dshHome, 'omdsh', 'keybindings.json'),
|
|
3784
|
+
...(() => {
|
|
3785
|
+
const path = featurePatchPath(config.dshHome ?? dshHome);
|
|
3786
|
+
return existsSync(path) ? { featurePatch: path } : {};
|
|
3787
|
+
})(),
|
|
2544
3788
|
});
|
|
2545
3789
|
ctx.provide(TUI_SERVICE, tui);
|
|
2546
|
-
ctx.effect(() => () =>
|
|
3790
|
+
ctx.effect(() => () => tui.dispose());
|
|
2547
3791
|
// Preferences are this entry's own volatile config: the initial read applies
|
|
2548
3792
|
// them without persisting, a committed form edit dispatches a volatile update
|
|
2549
3793
|
// to this fiber only, and an in-app `/settings` change writes back through the
|
|
@@ -2553,12 +3797,18 @@ export function apply(ctx, config) {
|
|
|
2553
3797
|
theme: config.theme.get(),
|
|
2554
3798
|
colors: resolveColors(config.colors.get(), term.output.isTTY === true),
|
|
2555
3799
|
motion: config.motion.get(),
|
|
3800
|
+
mathMode: config.mathMode.get(),
|
|
3801
|
+
mermaidMode: config.mermaidMode.get(),
|
|
3802
|
+
editor: config.editor.get(),
|
|
2556
3803
|
terminalProgress: config.terminalProgress.get(),
|
|
2557
|
-
|
|
3804
|
+
copyOnSelect: config.copyOnSelect.get(),
|
|
3805
|
+
mouseInteraction: config.mouseInteraction.get(),
|
|
3806
|
+
pasteProtection: config.pasteProtection.get(),
|
|
2558
3807
|
checkUpdates: config.checkUpdates.get(),
|
|
2559
3808
|
startupChangelog: config.startupChangelog.get(),
|
|
2560
3809
|
notifications: config.notifications.get(),
|
|
2561
3810
|
notificationThreshold: config.notificationThreshold.get(),
|
|
3811
|
+
notificationFocus: config.notificationFocus.get(),
|
|
2562
3812
|
};
|
|
2563
3813
|
const statusBar = config.statusBar.get();
|
|
2564
3814
|
// The reference holds a frozen snapshot; the provider keeps a mutable copy.
|
|
@@ -2570,6 +3820,7 @@ export function apply(ctx, config) {
|
|
|
2570
3820
|
return prefs;
|
|
2571
3821
|
};
|
|
2572
3822
|
tui.applyStoredPrefs(storedPrefs());
|
|
3823
|
+
void readTmuxMouseEnabled().then(enabled => tui.setTmuxMouseEnabled(enabled));
|
|
2573
3824
|
ctx.on('loader/volatile-update', () => { tui.applyStoredPrefs(storedPrefs()); });
|
|
2574
3825
|
// Persistence needs the settings service; without one the provider still runs
|
|
2575
3826
|
// and an in-app change stays session-local, as it did before.
|
|
@@ -2580,5 +3831,11 @@ export function apply(ctx, config) {
|
|
|
2580
3831
|
.catch((error) => { settingsCtx.logger.warn(error); });
|
|
2581
3832
|
});
|
|
2582
3833
|
});
|
|
3834
|
+
ctx.inject(['settings', 'credentials'], (settingsCtx) => {
|
|
3835
|
+
settingsCtx.effect(() => tui.bindPluginSettings({
|
|
3836
|
+
entries: () => pluginSettingsEntries(settingsCtx),
|
|
3837
|
+
edit: (id, signal) => editPluginSettings(settingsCtx, id, signal),
|
|
3838
|
+
}));
|
|
3839
|
+
});
|
|
2583
3840
|
}
|
|
2584
3841
|
//# sourceMappingURL=provider-local.js.map
|