zcode-app-cli 3.9.2-16 → 3.10.2-18
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/bin/zcode.js +7 -7
- package/config.example.json +5 -6
- package/package.json +3 -3
- package/vendor/extraction.json +9 -4
- package/vendor/node_modules/@zcode/tui/dist/index.js +1296 -316
- package/vendor/node_modules/@zcode/tui/package.json +1 -1
- package/vendor/packages/browser-use-plugin/.zcode-plugin/plugin.json +1 -1
- package/vendor/packages/browser-use-plugin/dist/mcp/server.js +660 -220
- package/vendor/packages/browser-use-plugin/docs/api.json +2 -2
- package/vendor/packages/browser-use-plugin/docs/overview.md +1 -1
- package/vendor/packages/browser-use-plugin/docs/playwright.md +4 -6
- package/vendor/packages/browser-use-plugin/docs/safety.md +1 -1
- package/vendor/packages/browser-use-plugin/docs/workflow.md +1 -1
- package/vendor/packages/browser-use-plugin/package.json +1 -1
- package/vendor/packages/browser-use-plugin/scripts/browser-client.mjs +2 -2
- package/vendor/packages/browser-use-plugin/skills/control-browser/SKILL.md +2 -2
- package/vendor/packages/document-skills-plugin/.zcode-plugin/plugin.json +2 -2
- package/vendor/packages/document-skills-plugin/agents/judge.md +51 -0
- package/vendor/packages/document-skills-plugin/package.json +4 -4
- package/vendor/packages/document-skills-plugin/skills/pptx/SKILL.md +6 -3
- package/vendor/packages/zcode-cua-plugin/.zcode-plugin/plugin.json +2 -2
- package/vendor/packages/zcode-cua-plugin/dist/mcp/server.js +2 -2
- package/vendor/packages/zcode-cua-plugin/node_modules/koffi/build/koffi/linux_x64/koffi.node +0 -0
- package/vendor/packages/zcode-cua-plugin/node_modules/koffi/index.d.ts +288 -0
- package/vendor/packages/zcode-cua-plugin/node_modules/koffi/index.js +634 -0
- package/vendor/packages/zcode-cua-plugin/node_modules/koffi/package.json +38 -0
- package/vendor/packages/zcode-cua-plugin/package.json +1 -1
- package/vendor/packages/zcode-cua-plugin/scripts/build-mcp.mjs +3 -1
- package/vendor/packages/zcode-cua-plugin/scripts/bump-zcode-cua-producer.mjs +4 -4
- package/vendor/packages/zcode-cua-plugin/scripts/check-cua-baseline.mjs +2 -2
- package/vendor/packages/zcode-cua-plugin/scripts/check-version-coherence.mjs +4 -4
- package/vendor/packages/zcode-cua-plugin/scripts/sync-cache.mjs +9 -2
- package/vendor/packages/zcode-cua-plugin/scripts/sync-skill-from-zcode-cua.mjs +7 -7
- package/vendor/packages/zcode-cua-plugin/skills/{zcode-computer-use → computer-use}/SKILL.md +1 -1
- package/vendor/zcode.cjs +773 -771
- package/zcode-runtime.lock.json +3 -3
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { createRequire } from "node:module";
|
|
2
2
|
import { spawn } from "node:child_process";
|
|
3
3
|
import { accessSync, appendFileSync, closeSync, constants, fstatSync, openSync, readSync } from "node:fs";
|
|
4
|
+
import { constants as constants$1, homedir } from "node:os";
|
|
4
5
|
import { basename, dirname, extname, isAbsolute, join, posix, resolve, sep, win32 } from "node:path";
|
|
5
6
|
import { randomUUID } from "node:crypto";
|
|
6
7
|
import { copyFile, link, mkdir, open, readFile, rename, rm, stat, writeFile } from "node:fs/promises";
|
|
7
|
-
import {
|
|
8
|
-
import { Box, CombinedAutocompleteProvider, Container, Editor, Image, Input, Markdown, ProcessTerminal, SelectList, Spacer, TUI, Text, decodeKittyPrintable, getKeybindings, isKeyRelease, matchesKey, truncateToWidth, visibleWidth, wrapTextWithAnsi } from "@earendil-works/pi-tui";
|
|
8
|
+
import { Box, CombinedAutocompleteProvider, Container, Editor, Image, Input, Markdown, ProcessTerminal, ScrollView, SelectList, Spacer, Text, TuiAltScreen, TuiMainScreen, VStack, decodeKittyPrintable, getKeybindings, isKeyRelease, isViewportTUI, matchesKey, truncateToWidth, visibleWidth, wrapTextWithAnsi } from "@earendil-works/pi-tui";
|
|
9
9
|
import { isDeepStrictEqual } from "node:util";
|
|
10
10
|
var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod), cb = null), mod.exports);
|
|
11
11
|
var __require = /* #__PURE__ */ (() => createRequire(import.meta.url))();
|
|
@@ -24,17 +24,15 @@ var config_example_default = {
|
|
|
24
24
|
"glm-5.3": { "name": "GLM-5.3" },
|
|
25
25
|
"glm-5.3-flash": {
|
|
26
26
|
"name": "GLM-5.3-Flash",
|
|
27
|
-
"
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
"limit": { "context": 1e6 },
|
|
27
|
+
"limit": {
|
|
28
|
+
"context": 1e6,
|
|
29
|
+
"output": 128e3
|
|
30
|
+
},
|
|
32
31
|
"modalities": {
|
|
33
32
|
"input": [
|
|
34
33
|
"text",
|
|
35
34
|
"image",
|
|
36
|
-
"video"
|
|
37
|
-
"pdf"
|
|
35
|
+
"video"
|
|
38
36
|
],
|
|
39
37
|
"output": ["text"]
|
|
40
38
|
}
|
|
@@ -100,6 +98,8 @@ var config_example_default = {
|
|
|
100
98
|
ui: {
|
|
101
99
|
"locale": "auto",
|
|
102
100
|
"theme": "auto",
|
|
101
|
+
"tuiMode": "regular",
|
|
102
|
+
"copyOnSelect": true,
|
|
103
103
|
"notifications": {
|
|
104
104
|
"method": "auto",
|
|
105
105
|
"condition": "unfocused"
|
|
@@ -156989,6 +156989,75 @@ var AssistantStream = class {
|
|
|
156989
156989
|
}
|
|
156990
156990
|
};
|
|
156991
156991
|
//#endregion
|
|
156992
|
+
//#region packages/zcode-tui/src/tool-renderers/registry.ts
|
|
156993
|
+
function normalizeToolName(name) {
|
|
156994
|
+
return name.toLowerCase().replace(/[^a-z0-9]/gu, "");
|
|
156995
|
+
}
|
|
156996
|
+
const canonicalAliases = /* @__PURE__ */ new Map([
|
|
156997
|
+
["read", "Read"],
|
|
156998
|
+
["fileread", "Read"],
|
|
156999
|
+
["write", "Write"],
|
|
157000
|
+
["filewrite", "Write"],
|
|
157001
|
+
["edit", "Edit"],
|
|
157002
|
+
["fileedit", "Edit"],
|
|
157003
|
+
["applypatch", "ApplyPatch"],
|
|
157004
|
+
["patch", "ApplyPatch"],
|
|
157005
|
+
["bash", "Bash"],
|
|
157006
|
+
["shell", "Bash"],
|
|
157007
|
+
["exec", "Bash"],
|
|
157008
|
+
["glob", "Glob"],
|
|
157009
|
+
["find", "Glob"],
|
|
157010
|
+
["grep", "Grep"],
|
|
157011
|
+
["searchtext", "Grep"],
|
|
157012
|
+
["webfetch", "WebFetch"],
|
|
157013
|
+
["fetch", "WebFetch"],
|
|
157014
|
+
["websearch", "WebSearch"],
|
|
157015
|
+
["todoread", "TodoRead"],
|
|
157016
|
+
["todowrite", "TodoWrite"],
|
|
157017
|
+
["goalread", "GoalRead"],
|
|
157018
|
+
["readsessioncontext", "ReadSessionContext"],
|
|
157019
|
+
["askuserquestion", "AskUserQuestion"],
|
|
157020
|
+
["sendmessage", "SendMessage"],
|
|
157021
|
+
["taskstop", "TaskStop"],
|
|
157022
|
+
["killshell", "TaskStop"],
|
|
157023
|
+
["killbash", "TaskStop"],
|
|
157024
|
+
["taskoutput", "TaskOutput"],
|
|
157025
|
+
["agent", "Agent"],
|
|
157026
|
+
["subagent", "Agent"],
|
|
157027
|
+
["task", "Task"],
|
|
157028
|
+
["skill", "Skill"],
|
|
157029
|
+
["enterplanmode", "EnterPlanMode"],
|
|
157030
|
+
["exitplanmode", "ExitPlanMode"],
|
|
157031
|
+
["exitplanmodev2", "ExitPlanMode"]
|
|
157032
|
+
]);
|
|
157033
|
+
function isMcpToolName(name) {
|
|
157034
|
+
return /^(?:mcp__|mcp[:./])/iu.test(name.trim());
|
|
157035
|
+
}
|
|
157036
|
+
function canonicalToolName(name) {
|
|
157037
|
+
return canonicalAliases.get(normalizeToolName(name)) ?? (isMcpToolName(name) ? "MCP" : void 0);
|
|
157038
|
+
}
|
|
157039
|
+
function isKnownTool(name) {
|
|
157040
|
+
return canonicalToolName(name) !== void 0;
|
|
157041
|
+
}
|
|
157042
|
+
function isAgentDispatchTool(name) {
|
|
157043
|
+
if (!name) return false;
|
|
157044
|
+
const canonical = canonicalToolName(name);
|
|
157045
|
+
return canonical === "Agent" || canonical === "Task";
|
|
157046
|
+
}
|
|
157047
|
+
function isGroupedInformationTool(name) {
|
|
157048
|
+
const canonical = canonicalToolName(name);
|
|
157049
|
+
return canonical === "Read" || canonical === "Glob" || canonical === "Grep";
|
|
157050
|
+
}
|
|
157051
|
+
function toolGroupKind(name) {
|
|
157052
|
+
const canonical = canonicalToolName(name);
|
|
157053
|
+
if (canonical === "Read") return "read";
|
|
157054
|
+
if (canonical === "Glob" || canonical === "Grep") return "search";
|
|
157055
|
+
}
|
|
157056
|
+
function displayNameForMcp(name) {
|
|
157057
|
+
const parts = name.trim().replace(/^mcp(?:__|[:./])/iu, "").split(/__|[:./]/u).filter(Boolean);
|
|
157058
|
+
return parts.length > 0 ? `MCP · ${parts.join("/")}` : "MCP";
|
|
157059
|
+
}
|
|
157060
|
+
//#endregion
|
|
156992
157061
|
//#region packages/zcode-tui/src/background-task-events.ts
|
|
156993
157062
|
const maximumEntriesPerTask = 32;
|
|
156994
157063
|
const maximumCharactersPerTask = 64e3;
|
|
@@ -157002,7 +157071,7 @@ function taskIdFor(event) {
|
|
|
157002
157071
|
return event.taskId ?? event.agentId;
|
|
157003
157072
|
}
|
|
157004
157073
|
function terminalTaskStatus(status) {
|
|
157005
|
-
return status === "completed" || status === "failed" || status === "timed_out" || status === "cancelled" || status === "spawn_error" || status === "lost" || status === "stopped";
|
|
157074
|
+
return status === "completed" || status === "failed" || status === "timed_out" || status === "cancelled" || status === "killed" || status === "spawn_error" || status === "lost" || status === "stopped";
|
|
157006
157075
|
}
|
|
157007
157076
|
function taskFailure(status) {
|
|
157008
157077
|
return status === "failed" || status === "timed_out" || status === "spawn_error" || status === "lost";
|
|
@@ -157010,22 +157079,18 @@ function taskFailure(status) {
|
|
|
157010
157079
|
function bounded(value) {
|
|
157011
157080
|
return value.length <= maximumEntryCharacters ? value : value.slice(0, maximumEntryCharacters) + "\n[truncated]";
|
|
157012
157081
|
}
|
|
157013
|
-
function
|
|
157014
|
-
const normalized = name?.trim().toLowerCase();
|
|
157015
|
-
return normalized === "agent" || normalized === "subagent";
|
|
157016
|
-
}
|
|
157017
|
-
function record$1(value) {
|
|
157082
|
+
function record$3(value) {
|
|
157018
157083
|
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
|
|
157019
157084
|
}
|
|
157020
157085
|
function explicitlyBackgroundAgentInput(value) {
|
|
157021
|
-
return record$
|
|
157086
|
+
return record$3(value)?.run_in_background === true;
|
|
157022
157087
|
}
|
|
157023
157088
|
function asyncAgentResult(value) {
|
|
157024
|
-
const root = record$
|
|
157089
|
+
const root = record$3(value);
|
|
157025
157090
|
return [
|
|
157026
157091
|
root,
|
|
157027
|
-
record$
|
|
157028
|
-
record$
|
|
157092
|
+
record$3(root?.output),
|
|
157093
|
+
record$3(root?.result)
|
|
157029
157094
|
].some((candidate) => candidate?.isAsync === true || candidate?.status === "async_launched" || candidate?.status === "backgrounded" || typeof candidate?.backgroundTaskId === "string");
|
|
157030
157095
|
}
|
|
157031
157096
|
function toolScope(event) {
|
|
@@ -157152,7 +157217,7 @@ var BackgroundTaskEventStore = class {
|
|
|
157152
157217
|
isBackgroundToolScoped(event) {
|
|
157153
157218
|
const scope = toolScope(event);
|
|
157154
157219
|
const part = event.part?.type === "tool" ? event.part : void 0;
|
|
157155
|
-
return Boolean(
|
|
157220
|
+
return Boolean(isAgentDispatchTool(scope.name) && (explicitlyBackgroundAgentInput(event.input ?? part?.input) || asyncAgentResult(event.result ?? part?.output))) || Boolean(scope.id && this.scopedTool(scope.id)) || Boolean(scope.parentId && this.scopedTool(scope.parentId));
|
|
157156
157221
|
}
|
|
157157
157222
|
recordUserMessage(taskId, message) {
|
|
157158
157223
|
this.record(taskId, "user", message);
|
|
@@ -157214,10 +157279,10 @@ var BackgroundTaskEventStore = class {
|
|
|
157214
157279
|
const scope = toolScope(event);
|
|
157215
157280
|
if (scope.id && scope.parentId) this.rememberToolParent(scope.id, scope.parentId);
|
|
157216
157281
|
const part = event.part?.type === "tool" ? event.part : void 0;
|
|
157217
|
-
const backgroundLifecycleParent = (event.type === "background_task_started" || event.type === "background_task_updated") && (event.taskKind === "local_agent" || event.toolName
|
|
157282
|
+
const backgroundLifecycleParent = (event.type === "background_task_started" || event.type === "background_task_updated") && (event.taskKind === "local_agent" || isAgentDispatchTool(event.toolName)) ? event.progress?.parentToolCallId : void 0;
|
|
157218
157283
|
if (backgroundLifecycleParent) this.rememberScopedToolCall(backgroundLifecycleParent);
|
|
157219
157284
|
if (!scope.id) return;
|
|
157220
|
-
if (
|
|
157285
|
+
if (isAgentDispatchTool(scope.name) && (explicitlyBackgroundAgentInput(event.input ?? part?.input) || asyncAgentResult(event.result ?? part?.output)) || Boolean(scope.parentId && this.scopedTool(scope.parentId))) this.rememberScopedToolCall(scope.id);
|
|
157221
157286
|
}
|
|
157222
157287
|
scopedTool(toolCallId) {
|
|
157223
157288
|
let current = toolCallId;
|
|
@@ -157451,6 +157516,109 @@ function isWindowedComponent(component) {
|
|
|
157451
157516
|
}
|
|
157452
157517
|
//#endregion
|
|
157453
157518
|
//#region packages/zcode-tui/src/choice-dialog.ts
|
|
157519
|
+
const fullscreenDialogContentMaxWidth = 100;
|
|
157520
|
+
/** Leading numeric parameter of a Kitty CSI-u sequence: the base key code. */
|
|
157521
|
+
const kittyCsiUBaseCodepointPattern = /^\x1b\[(\d+)(?=[:;u])/u;
|
|
157522
|
+
const controlCharacterPattern$1 = /[\u0000-\u001f\u007f-\u009f]/u;
|
|
157523
|
+
/**
|
|
157524
|
+
* Codepoint ranges inside the Unicode private use area that terminals reserve
|
|
157525
|
+
* for keys rather than glyphs:
|
|
157526
|
+
*
|
|
157527
|
+
* - Kitty's keyboard protocol encodes functional keys (F1-F35, PrintScreen,
|
|
157528
|
+
* CapsLock, media keys, IME process keys, modifiers, …) in 57344-57454.
|
|
157529
|
+
* - macOS/AppKit reports its own function keys as 0xF700-0xF8FF (NSUpArrow
|
|
157530
|
+
* FunctionKey … NSModeSwitchFunctionKey), which some terminals pass through
|
|
157531
|
+
* raw.
|
|
157532
|
+
*
|
|
157533
|
+
* Everything else in the private use area is a real glyph — Nerd Font icons
|
|
157534
|
+
* live just above Kitty's block (Powerline starts at 0xE0A0, Seti at 0xE5FA,
|
|
157535
|
+
* Font Awesome at 0xF000) — so it must stay typeable and pasteable.
|
|
157536
|
+
*/
|
|
157537
|
+
const functionalKeyRanges = [{
|
|
157538
|
+
start: 57344,
|
|
157539
|
+
end: 57454
|
|
157540
|
+
}, {
|
|
157541
|
+
start: 63232,
|
|
157542
|
+
end: 63743
|
|
157543
|
+
}];
|
|
157544
|
+
function isFunctionalKeyCharacter(character) {
|
|
157545
|
+
const codepoint = character.codePointAt(0);
|
|
157546
|
+
if (codepoint === void 0) return false;
|
|
157547
|
+
return functionalKeyRanges.some(({ start, end }) => codepoint >= start && codepoint <= end);
|
|
157548
|
+
}
|
|
157549
|
+
function containsFunctionalKeyCharacter(value) {
|
|
157550
|
+
return [...value].some(isFunctionalKeyCharacter);
|
|
157551
|
+
}
|
|
157552
|
+
/**
|
|
157553
|
+
* True when a Kitty CSI-u sequence describes a functional key with no text
|
|
157554
|
+
* equivalent.
|
|
157555
|
+
*
|
|
157556
|
+
* Rather than duplicating pi-tui's functional-key mapping table (which would
|
|
157557
|
+
* silently drift as that table grows), this asks pi-tui to decode the *base*
|
|
157558
|
+
* key code on its own. Numpad keys and friends normalize to real text; anything
|
|
157559
|
+
* that still decodes to a reserved key codepoint has no text equivalent. Testing
|
|
157560
|
+
* the base code also ignores the shifted/alternate fields, which must never
|
|
157561
|
+
* turn a functional key into text.
|
|
157562
|
+
*/
|
|
157563
|
+
function isTextlessFunctionalKey(data) {
|
|
157564
|
+
const match = kittyCsiUBaseCodepointPattern.exec(data);
|
|
157565
|
+
if (!match) return false;
|
|
157566
|
+
const decodedBase = decodeKittyPrintable(`\x1b[${match[1]}u`);
|
|
157567
|
+
return decodedBase === void 0 || containsFunctionalKeyCharacter(decodedBase);
|
|
157568
|
+
}
|
|
157569
|
+
/**
|
|
157570
|
+
* Resolve the text a key press should append to the filter, or undefined when
|
|
157571
|
+
* the input is not text and should fall through to list navigation.
|
|
157572
|
+
*/
|
|
157573
|
+
function decodeFilterText(data) {
|
|
157574
|
+
if (data.length === 0) return void 0;
|
|
157575
|
+
if (isKeyRelease(data)) return void 0;
|
|
157576
|
+
if (isTextlessFunctionalKey(data)) return void 0;
|
|
157577
|
+
const printable = decodeKittyPrintable(data);
|
|
157578
|
+
if (printable !== void 0) return containsFunctionalKeyCharacter(printable) ? void 0 : printable;
|
|
157579
|
+
if (controlCharacterPattern$1.test(data) || containsFunctionalKeyCharacter(data)) return void 0;
|
|
157580
|
+
return data;
|
|
157581
|
+
}
|
|
157582
|
+
var FullscreenDialogSurface = class {
|
|
157583
|
+
dialog;
|
|
157584
|
+
theme;
|
|
157585
|
+
focused = false;
|
|
157586
|
+
constructor(dialog, theme) {
|
|
157587
|
+
this.dialog = dialog;
|
|
157588
|
+
this.theme = theme;
|
|
157589
|
+
}
|
|
157590
|
+
render(width) {
|
|
157591
|
+
const safeWidth = Math.max(1, width);
|
|
157592
|
+
if ("focused" in this.dialog) this.dialog.focused = this.focused;
|
|
157593
|
+
const inset = safeWidth >= 12 ? 2 : 0;
|
|
157594
|
+
const contentWidth = Math.max(1, Math.min(fullscreenDialogContentMaxWidth, safeWidth - inset * 2));
|
|
157595
|
+
const prefix = " ".repeat(inset);
|
|
157596
|
+
const rule = this.theme.muted("─".repeat(safeWidth));
|
|
157597
|
+
return [
|
|
157598
|
+
rule,
|
|
157599
|
+
...this.dialog.render(contentWidth).map((line) => truncateToWidth(`${prefix}${line}`, safeWidth, "", true)),
|
|
157600
|
+
rule
|
|
157601
|
+
];
|
|
157602
|
+
}
|
|
157603
|
+
handleInput(data) {
|
|
157604
|
+
this.dialog.handleInput?.(data);
|
|
157605
|
+
}
|
|
157606
|
+
invalidate() {
|
|
157607
|
+
this.dialog.invalidate();
|
|
157608
|
+
}
|
|
157609
|
+
};
|
|
157610
|
+
function showFullscreenDialog(ui, theme, dialog) {
|
|
157611
|
+
if (ui.mode !== "fullscreen" || typeof ui.showOverlay !== "function") return void 0;
|
|
157612
|
+
const surface = new FullscreenDialogSurface(dialog, theme);
|
|
157613
|
+
return {
|
|
157614
|
+
focus: surface,
|
|
157615
|
+
handle: ui.showOverlay(surface, {
|
|
157616
|
+
anchor: "bottom-left",
|
|
157617
|
+
maxHeight: "100%",
|
|
157618
|
+
width: "100%"
|
|
157619
|
+
})
|
|
157620
|
+
};
|
|
157621
|
+
}
|
|
157454
157622
|
var ChoiceItemDetails = class {
|
|
157455
157623
|
item;
|
|
157456
157624
|
theme;
|
|
@@ -157586,9 +157754,9 @@ var ChoiceDialog = class {
|
|
|
157586
157754
|
this.updateFilter(removeLastGrapheme(this.filter));
|
|
157587
157755
|
return;
|
|
157588
157756
|
}
|
|
157589
|
-
const
|
|
157590
|
-
if (
|
|
157591
|
-
this.updateFilter(this.filter +
|
|
157757
|
+
const text = decodeFilterText(data);
|
|
157758
|
+
if (text !== void 0) {
|
|
157759
|
+
this.updateFilter(this.filter + text);
|
|
157592
157760
|
return;
|
|
157593
157761
|
}
|
|
157594
157762
|
this.list.handleInput(data);
|
|
@@ -157669,11 +157837,13 @@ function choose(ui, host, theme, options) {
|
|
|
157669
157837
|
};
|
|
157670
157838
|
dialog.setSelectionPreview(previewFor(list.getSelectedItem()));
|
|
157671
157839
|
let settled = false;
|
|
157840
|
+
let overlayHandle;
|
|
157672
157841
|
const finish = (item) => {
|
|
157673
157842
|
if (settled) return;
|
|
157674
157843
|
settled = true;
|
|
157675
157844
|
options.signal?.removeEventListener("abort", onAbort);
|
|
157676
|
-
|
|
157845
|
+
if (overlayHandle) overlayHandle.hide();
|
|
157846
|
+
else host.removeChild(dialog);
|
|
157677
157847
|
ui.requestRender();
|
|
157678
157848
|
resolve(item);
|
|
157679
157849
|
};
|
|
@@ -157681,8 +157851,10 @@ function choose(ui, host, theme, options) {
|
|
|
157681
157851
|
list.onSelect = (item) => finish(choicesByValue.get(item.value) ?? null);
|
|
157682
157852
|
list.onSelectionChange = (item) => dialog.setSelectionPreview(previewFor(item));
|
|
157683
157853
|
list.onCancel = () => finish(null);
|
|
157684
|
-
|
|
157685
|
-
|
|
157854
|
+
const fullscreenDialog = showFullscreenDialog(ui, theme, dialog);
|
|
157855
|
+
if (fullscreenDialog) overlayHandle = fullscreenDialog.handle;
|
|
157856
|
+
else host.addChild(dialog);
|
|
157857
|
+
ui.setFocus(fullscreenDialog?.focus ?? dialog);
|
|
157686
157858
|
ui.requestRender();
|
|
157687
157859
|
options.signal?.addEventListener("abort", onAbort, { once: true });
|
|
157688
157860
|
if (options.signal?.aborted) finish(null);
|
|
@@ -157694,6 +157866,7 @@ var TextPromptDialog = class {
|
|
|
157694
157866
|
input;
|
|
157695
157867
|
theme;
|
|
157696
157868
|
help;
|
|
157869
|
+
focused = false;
|
|
157697
157870
|
constructor(title, prompt, input, theme, help) {
|
|
157698
157871
|
this.title = title;
|
|
157699
157872
|
this.prompt = prompt;
|
|
@@ -157703,6 +157876,7 @@ var TextPromptDialog = class {
|
|
|
157703
157876
|
}
|
|
157704
157877
|
render(width) {
|
|
157705
157878
|
const safeWidth = Math.max(1, width);
|
|
157879
|
+
if ("focused" in this.input) this.input.focused = this.focused;
|
|
157706
157880
|
return [
|
|
157707
157881
|
...wrapTerminalText(this.theme.bold(this.title), safeWidth),
|
|
157708
157882
|
...wrapTerminalText(this.theme.muted(this.prompt), safeWidth),
|
|
@@ -157712,6 +157886,9 @@ var TextPromptDialog = class {
|
|
|
157712
157886
|
...wrapTerminalText(this.theme.muted(this.help), safeWidth)
|
|
157713
157887
|
];
|
|
157714
157888
|
}
|
|
157889
|
+
handleInput(data) {
|
|
157890
|
+
this.input.handleInput?.(data);
|
|
157891
|
+
}
|
|
157715
157892
|
invalidate() {
|
|
157716
157893
|
this.input.invalidate();
|
|
157717
157894
|
}
|
|
@@ -157777,19 +157954,23 @@ function promptText(ui, host, theme, options) {
|
|
|
157777
157954
|
else input.setValue(options.initialValue);
|
|
157778
157955
|
const dialog = new TextPromptDialog(sanitizeTerminalText(options.title, { preserveSgr: false }), sanitizeTerminalText(options.prompt, { preserveSgr: false }), input, theme, sanitizeTerminalText(options.help ?? "Enter confirm · Esc cancel", { preserveSgr: false }));
|
|
157779
157956
|
let settled = false;
|
|
157957
|
+
let overlayHandle;
|
|
157780
157958
|
const finish = (value) => {
|
|
157781
157959
|
if (settled) return;
|
|
157782
157960
|
settled = true;
|
|
157783
157961
|
options.signal?.removeEventListener("abort", onAbort);
|
|
157784
|
-
|
|
157962
|
+
if (overlayHandle) overlayHandle.hide();
|
|
157963
|
+
else host.removeChild(dialog);
|
|
157785
157964
|
ui.requestRender();
|
|
157786
157965
|
resolve(value);
|
|
157787
157966
|
};
|
|
157788
157967
|
const onAbort = () => finish(null);
|
|
157789
157968
|
input.onSubmit = (value) => finish(value);
|
|
157790
157969
|
input.onEscape = () => finish(null);
|
|
157791
|
-
|
|
157792
|
-
|
|
157970
|
+
const fullscreenDialog = showFullscreenDialog(ui, theme, dialog);
|
|
157971
|
+
if (fullscreenDialog) overlayHandle = fullscreenDialog.handle;
|
|
157972
|
+
else host.addChild(dialog);
|
|
157973
|
+
ui.setFocus(fullscreenDialog?.focus ?? dialog);
|
|
157793
157974
|
ui.requestRender();
|
|
157794
157975
|
options.signal?.addEventListener("abort", onAbort, { once: true });
|
|
157795
157976
|
if (options.signal?.aborted) finish(null);
|
|
@@ -157952,6 +158133,29 @@ function normalizeEvent(value) {
|
|
|
157952
158133
|
function isModelCancellationEvent(event) {
|
|
157953
158134
|
return event.type === "model_request_failed" && (event.reason?.toLowerCase() === "cancelled" || event.errorCode?.toLowerCase() === "model_request_cancelled" || event.exceptionType?.toLowerCase() === "aborterror");
|
|
157954
158135
|
}
|
|
158136
|
+
const toolCancellationValues = /* @__PURE__ */ new Set([
|
|
158137
|
+
"aborterror",
|
|
158138
|
+
"cancelled",
|
|
158139
|
+
"canceled",
|
|
158140
|
+
"tool_cancelled",
|
|
158141
|
+
"tool_canceled"
|
|
158142
|
+
]);
|
|
158143
|
+
function isToolCancellation(value) {
|
|
158144
|
+
if (value instanceof Error) return toolCancellationValues.has(value.name.toLowerCase()) || /\b(?:tool|command|process|bash)\b.{0,40}\b(?:cancelled|canceled)\b/iu.test(value.message);
|
|
158145
|
+
if (typeof value === "string") {
|
|
158146
|
+
const normalized = value.trim().toLowerCase();
|
|
158147
|
+
return toolCancellationValues.has(normalized) || /\b(?:tool|command|process|bash)\b.{0,40}\b(?:cancelled|canceled)\b/iu.test(value);
|
|
158148
|
+
}
|
|
158149
|
+
if (!isRecord(value)) return false;
|
|
158150
|
+
if ([
|
|
158151
|
+
value.type,
|
|
158152
|
+
value.code,
|
|
158153
|
+
value.name,
|
|
158154
|
+
value.status,
|
|
158155
|
+
value.reason
|
|
158156
|
+
].some((marker) => typeof marker === "string" && toolCancellationValues.has(marker.trim().toLowerCase()))) return true;
|
|
158157
|
+
return value.error !== value && isToolCancellation(value.error);
|
|
158158
|
+
}
|
|
157955
158159
|
function responseText(value) {
|
|
157956
158160
|
if (!isRecord(value)) return void 0;
|
|
157957
158161
|
return asString(value.response) ?? asString(value.message) ?? asString(value.text);
|
|
@@ -160526,69 +160730,6 @@ function planText$1(input) {
|
|
|
160526
160730
|
}
|
|
160527
160731
|
}
|
|
160528
160732
|
//#endregion
|
|
160529
|
-
//#region packages/zcode-tui/src/tool-renderers/registry.ts
|
|
160530
|
-
function normalizeToolName(name) {
|
|
160531
|
-
return name.toLowerCase().replace(/[^a-z0-9]/gu, "");
|
|
160532
|
-
}
|
|
160533
|
-
const canonicalAliases = /* @__PURE__ */ new Map([
|
|
160534
|
-
["read", "Read"],
|
|
160535
|
-
["fileread", "Read"],
|
|
160536
|
-
["write", "Write"],
|
|
160537
|
-
["filewrite", "Write"],
|
|
160538
|
-
["edit", "Edit"],
|
|
160539
|
-
["fileedit", "Edit"],
|
|
160540
|
-
["applypatch", "ApplyPatch"],
|
|
160541
|
-
["patch", "ApplyPatch"],
|
|
160542
|
-
["bash", "Bash"],
|
|
160543
|
-
["shell", "Bash"],
|
|
160544
|
-
["exec", "Bash"],
|
|
160545
|
-
["glob", "Glob"],
|
|
160546
|
-
["find", "Glob"],
|
|
160547
|
-
["grep", "Grep"],
|
|
160548
|
-
["searchtext", "Grep"],
|
|
160549
|
-
["webfetch", "WebFetch"],
|
|
160550
|
-
["fetch", "WebFetch"],
|
|
160551
|
-
["websearch", "WebSearch"],
|
|
160552
|
-
["todoread", "TodoRead"],
|
|
160553
|
-
["todowrite", "TodoWrite"],
|
|
160554
|
-
["goalread", "GoalRead"],
|
|
160555
|
-
["readsessioncontext", "ReadSessionContext"],
|
|
160556
|
-
["askuserquestion", "AskUserQuestion"],
|
|
160557
|
-
["sendmessage", "SendMessage"],
|
|
160558
|
-
["taskstop", "TaskStop"],
|
|
160559
|
-
["killshell", "TaskStop"],
|
|
160560
|
-
["killbash", "TaskStop"],
|
|
160561
|
-
["agent", "Agent"],
|
|
160562
|
-
["subagent", "Agent"],
|
|
160563
|
-
["task", "Task"],
|
|
160564
|
-
["skill", "Skill"],
|
|
160565
|
-
["enterplanmode", "EnterPlanMode"],
|
|
160566
|
-
["exitplanmode", "ExitPlanMode"],
|
|
160567
|
-
["exitplanmodev2", "ExitPlanMode"]
|
|
160568
|
-
]);
|
|
160569
|
-
function isMcpToolName(name) {
|
|
160570
|
-
return /^(?:mcp__|mcp[:./])/iu.test(name.trim());
|
|
160571
|
-
}
|
|
160572
|
-
function canonicalToolName(name) {
|
|
160573
|
-
return canonicalAliases.get(normalizeToolName(name)) ?? (isMcpToolName(name) ? "MCP" : void 0);
|
|
160574
|
-
}
|
|
160575
|
-
function isKnownTool(name) {
|
|
160576
|
-
return canonicalToolName(name) !== void 0;
|
|
160577
|
-
}
|
|
160578
|
-
function isGroupedInformationTool(name) {
|
|
160579
|
-
const canonical = canonicalToolName(name);
|
|
160580
|
-
return canonical === "Read" || canonical === "Glob" || canonical === "Grep";
|
|
160581
|
-
}
|
|
160582
|
-
function toolGroupKind(name) {
|
|
160583
|
-
const canonical = canonicalToolName(name);
|
|
160584
|
-
if (canonical === "Read") return "read";
|
|
160585
|
-
if (canonical === "Glob" || canonical === "Grep") return "search";
|
|
160586
|
-
}
|
|
160587
|
-
function displayNameForMcp(name) {
|
|
160588
|
-
const parts = name.trim().replace(/^mcp(?:__|[:./])/iu, "").split(/__|[:./]/u).filter(Boolean);
|
|
160589
|
-
return parts.length > 0 ? `MCP · ${parts.join("/")}` : "MCP";
|
|
160590
|
-
}
|
|
160591
|
-
//#endregion
|
|
160592
160733
|
//#region packages/zcode-tui/src/tool-renderers/helpers.ts
|
|
160593
160734
|
function recordString(record, keys) {
|
|
160594
160735
|
if (!record) return void 0;
|
|
@@ -160733,6 +160874,10 @@ function toolSummary(name, input) {
|
|
|
160733
160874
|
]);
|
|
160734
160875
|
return task ? `task ${task}` : void 0;
|
|
160735
160876
|
}
|
|
160877
|
+
case "TaskOutput": {
|
|
160878
|
+
const task = recordString(record, ["task_id", "taskId"]);
|
|
160879
|
+
return task ? `task ${task}` : void 0;
|
|
160880
|
+
}
|
|
160736
160881
|
case "Agent":
|
|
160737
160882
|
case "Task": return recordString(record, [
|
|
160738
160883
|
"description",
|
|
@@ -160925,6 +161070,137 @@ function taskStopRender(options) {
|
|
|
160925
161070
|
consumesResult: Boolean(record)
|
|
160926
161071
|
};
|
|
160927
161072
|
}
|
|
161073
|
+
const taskOutputDisplayLimit = 2e3;
|
|
161074
|
+
const retrievalStatusLabels = {
|
|
161075
|
+
success: "retrieved",
|
|
161076
|
+
not_ready: "not ready yet",
|
|
161077
|
+
timeout: "timed out waiting"
|
|
161078
|
+
};
|
|
161079
|
+
function taskOutputDisplayFromTask(record) {
|
|
161080
|
+
const task = isRecord(record.task) ? record.task : void 0;
|
|
161081
|
+
const retrievalStatus = recordString(record, ["retrieval_status", "retrievalStatus"]);
|
|
161082
|
+
if (!task && !retrievalStatus) return void 0;
|
|
161083
|
+
return {
|
|
161084
|
+
retrievalStatus,
|
|
161085
|
+
taskStatus: recordString(task, ["status"]),
|
|
161086
|
+
source: "fallback"
|
|
161087
|
+
};
|
|
161088
|
+
}
|
|
161089
|
+
function taskOutputDisplayFromString(value) {
|
|
161090
|
+
const trimmed = value.trim();
|
|
161091
|
+
if (trimmed.startsWith("{")) try {
|
|
161092
|
+
const parsed = JSON.parse(trimmed);
|
|
161093
|
+
const fromJson = isRecord(parsed) ? taskOutputDisplayFromTask(parsed) : void 0;
|
|
161094
|
+
if (fromJson) return fromJson;
|
|
161095
|
+
} catch {}
|
|
161096
|
+
if (value.includes("<retrieval_status>")) {
|
|
161097
|
+
const status = /<retrieval_status>([^<]+)<\/retrieval_status>/u.exec(value)?.[1];
|
|
161098
|
+
const taskStatus = /<status>([^<]+)<\/status>/u.exec(value)?.[1];
|
|
161099
|
+
if (status || taskStatus) return {
|
|
161100
|
+
retrievalStatus: status ? sanitizeTerminalText(status.trim(), { preserveSgr: false }) : void 0,
|
|
161101
|
+
taskStatus: taskStatus ? sanitizeTerminalText(taskStatus.trim(), { preserveSgr: false }) : void 0,
|
|
161102
|
+
source: "fallback"
|
|
161103
|
+
};
|
|
161104
|
+
}
|
|
161105
|
+
}
|
|
161106
|
+
function compactTaskOutput(value) {
|
|
161107
|
+
const raw = directText(value)?.trimEnd();
|
|
161108
|
+
if (!raw) return { truncated: false };
|
|
161109
|
+
const output = truncateGraphemes(raw, taskOutputDisplayLimit, "");
|
|
161110
|
+
return {
|
|
161111
|
+
output,
|
|
161112
|
+
truncated: output !== raw
|
|
161113
|
+
};
|
|
161114
|
+
}
|
|
161115
|
+
function taskOutputFailureMessage(result, depth = 0) {
|
|
161116
|
+
if (depth > 3) return void 0;
|
|
161117
|
+
if (typeof result === "string") {
|
|
161118
|
+
const trimmed = result.trim();
|
|
161119
|
+
if (!trimmed.startsWith("{")) return void 0;
|
|
161120
|
+
try {
|
|
161121
|
+
return taskOutputFailureMessage(JSON.parse(trimmed), depth + 1);
|
|
161122
|
+
} catch {
|
|
161123
|
+
return;
|
|
161124
|
+
}
|
|
161125
|
+
}
|
|
161126
|
+
if (!isRecord(result)) return void 0;
|
|
161127
|
+
if (result.success === false || result.result === false) {
|
|
161128
|
+
const message = recordString(result, ["message", "error"]);
|
|
161129
|
+
if (message) return oneLine$2(message, 240);
|
|
161130
|
+
}
|
|
161131
|
+
for (const candidate of [
|
|
161132
|
+
result.output,
|
|
161133
|
+
result.content,
|
|
161134
|
+
result.result
|
|
161135
|
+
]) {
|
|
161136
|
+
if (candidate === result || typeof candidate === "boolean") continue;
|
|
161137
|
+
const nested = taskOutputFailureMessage(candidate, depth + 1);
|
|
161138
|
+
if (nested) return nested;
|
|
161139
|
+
}
|
|
161140
|
+
}
|
|
161141
|
+
/**
|
|
161142
|
+
* Prefer the runtime's compact `display` metadata; fall back to the raw
|
|
161143
|
+
* `{retrieval_status, task}` result or the persisted model-content string.
|
|
161144
|
+
* Restored parts arrive as `{output, display}` and live results as
|
|
161145
|
+
* `{success, content, display}` — in both the raw field can embed a full
|
|
161146
|
+
* subagent transcript, so it must never be rendered directly. When a restored
|
|
161147
|
+
* part carries no display metadata at all, `upsertProtocolPart` passes the
|
|
161148
|
+
* persisted `state.output` string through as the whole result.
|
|
161149
|
+
*/
|
|
161150
|
+
function taskOutputDisplay(result) {
|
|
161151
|
+
if (typeof result === "string") return taskOutputDisplayFromString(result);
|
|
161152
|
+
const record = isRecord(result) ? result : void 0;
|
|
161153
|
+
if (!record) return void 0;
|
|
161154
|
+
const display = isRecord(record.display) ? record.display : isRecord(record.resultDisplay) ? record.resultDisplay : void 0;
|
|
161155
|
+
if (display && (recordString(display, ["kind"]) === "task_output" || recordString(display, ["retrievalStatus", "retrieval_status"]))) {
|
|
161156
|
+
const compact = compactTaskOutput(display.output);
|
|
161157
|
+
return {
|
|
161158
|
+
retrievalStatus: recordString(display, ["retrievalStatus", "retrieval_status"]),
|
|
161159
|
+
taskStatus: recordString(display, [
|
|
161160
|
+
"taskStatus",
|
|
161161
|
+
"task_status",
|
|
161162
|
+
"status"
|
|
161163
|
+
]),
|
|
161164
|
+
output: compact.output,
|
|
161165
|
+
truncated: booleanField(display, ["truncated"]) === true || compact.truncated,
|
|
161166
|
+
source: "display"
|
|
161167
|
+
};
|
|
161168
|
+
}
|
|
161169
|
+
const nested = taskOutputDisplayFromTask(record);
|
|
161170
|
+
if (nested) return nested;
|
|
161171
|
+
for (const candidate of [record.output, record.content]) {
|
|
161172
|
+
if (typeof candidate !== "string") continue;
|
|
161173
|
+
const fallback = taskOutputDisplayFromString(candidate);
|
|
161174
|
+
if (fallback) return fallback;
|
|
161175
|
+
}
|
|
161176
|
+
}
|
|
161177
|
+
function taskOutputRender(options) {
|
|
161178
|
+
const taskId = recordString(isRecord(options.input) ? options.input : void 0, [
|
|
161179
|
+
"task_id",
|
|
161180
|
+
"taskId",
|
|
161181
|
+
"taskID"
|
|
161182
|
+
]);
|
|
161183
|
+
const display = taskOutputDisplay(options.result);
|
|
161184
|
+
const body = [];
|
|
161185
|
+
const status = display ? compactStatusLine([
|
|
161186
|
+
display.retrievalStatus ? retrievalStatusLabels[display.retrievalStatus] ?? display.retrievalStatus.replaceAll("_", " ") : void 0,
|
|
161187
|
+
display.taskStatus && display.taskStatus !== display.retrievalStatus ? display.taskStatus.replaceAll("_", " ") : void 0,
|
|
161188
|
+
display.truncated ? "output truncated" : void 0
|
|
161189
|
+
], options.theme) : void 0;
|
|
161190
|
+
if (status) body.push(status);
|
|
161191
|
+
if (display?.source === "display" && display.output?.trim()) body.push(display.output.trimEnd());
|
|
161192
|
+
else if (display?.retrievalStatus === "not_ready" || display?.retrievalStatus === "timeout") body.push(options.theme.muted("No output yet — check again with TaskOutput or /tasks."));
|
|
161193
|
+
else {
|
|
161194
|
+
const failureMessage = taskOutputFailureMessage(options.result);
|
|
161195
|
+
body.push(failureMessage ?? options.theme.muted("Task output is available in /tasks."));
|
|
161196
|
+
}
|
|
161197
|
+
return {
|
|
161198
|
+
displayName: "TaskOutput",
|
|
161199
|
+
summary: taskId ? `task ${taskId}` : toolSummary(options.name, options.input),
|
|
161200
|
+
body: body.join("\n") || void 0,
|
|
161201
|
+
consumesResult: true
|
|
161202
|
+
};
|
|
161203
|
+
}
|
|
160928
161204
|
//#endregion
|
|
160929
161205
|
//#region packages/zcode-tui/src/tool-renderers/workflow.ts
|
|
160930
161206
|
function todoItems(value) {
|
|
@@ -161225,6 +161501,7 @@ const rendererRegistry = {
|
|
|
161225
161501
|
AskUserQuestion: questionRender,
|
|
161226
161502
|
SendMessage: sendMessageRender,
|
|
161227
161503
|
TaskStop: taskStopRender,
|
|
161504
|
+
TaskOutput: taskOutputRender,
|
|
161228
161505
|
Agent: agentRender,
|
|
161229
161506
|
Task: agentRender,
|
|
161230
161507
|
Skill: skillRender,
|
|
@@ -161727,11 +162004,11 @@ function findExecutable(name, env = process.env, platform = process.platform) {
|
|
|
161727
162004
|
}
|
|
161728
162005
|
return null;
|
|
161729
162006
|
}
|
|
161730
|
-
function record(value) {
|
|
162007
|
+
function record$2(value) {
|
|
161731
162008
|
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
|
|
161732
162009
|
}
|
|
161733
162010
|
function configuredNotifications(config) {
|
|
161734
|
-
return record(record(record(config)?.ui)?.notifications);
|
|
162011
|
+
return record$2(record$2(record$2(config)?.ui)?.notifications);
|
|
161735
162012
|
}
|
|
161736
162013
|
function notificationSettings(env = process.env, config) {
|
|
161737
162014
|
const configured = configuredNotifications(config);
|
|
@@ -161750,7 +162027,7 @@ async function readStoredNotificationSettings(env = process.env) {
|
|
|
161750
162027
|
}
|
|
161751
162028
|
async function writeNotificationSettings(settings, env = process.env) {
|
|
161752
162029
|
return await updateUserConfig((config) => {
|
|
161753
|
-
const ui = record(config.ui) ?? {};
|
|
162030
|
+
const ui = record$2(config.ui) ?? {};
|
|
161754
162031
|
ui.notifications = { ...settings };
|
|
161755
162032
|
config.ui = ui;
|
|
161756
162033
|
}, env);
|
|
@@ -161968,6 +162245,52 @@ var TurnNotifier = class {
|
|
|
161968
162245
|
}
|
|
161969
162246
|
};
|
|
161970
162247
|
//#endregion
|
|
162248
|
+
//#region packages/zcode-tui/src/tui-mode.ts
|
|
162249
|
+
function record$1(value) {
|
|
162250
|
+
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
|
|
162251
|
+
}
|
|
162252
|
+
function configuredTuiMode(config) {
|
|
162253
|
+
const value = record$1(record$1(config)?.ui)?.tuiMode;
|
|
162254
|
+
return typeof value === "string" ? value : void 0;
|
|
162255
|
+
}
|
|
162256
|
+
function tuiMode(value) {
|
|
162257
|
+
if (typeof value !== "string") return void 0;
|
|
162258
|
+
const normalized = value.trim().toLowerCase();
|
|
162259
|
+
return normalized === "regular" || normalized === "fullscreen" ? normalized : void 0;
|
|
162260
|
+
}
|
|
162261
|
+
function resolveTuiMode(env = process.env, config) {
|
|
162262
|
+
return tuiMode(env.ZCODE_TUI_MODE) ?? tuiMode(configuredTuiMode(config)) ?? "regular";
|
|
162263
|
+
}
|
|
162264
|
+
async function readTuiMode(env = process.env) {
|
|
162265
|
+
return resolveTuiMode(env, await readUserConfig(env));
|
|
162266
|
+
}
|
|
162267
|
+
async function writeTuiMode(mode, env = process.env) {
|
|
162268
|
+
return await updateUserConfig((config) => {
|
|
162269
|
+
const ui = record$1(config.ui) ?? {};
|
|
162270
|
+
ui.tuiMode = mode;
|
|
162271
|
+
config.ui = ui;
|
|
162272
|
+
}, env);
|
|
162273
|
+
}
|
|
162274
|
+
//#endregion
|
|
162275
|
+
//#region packages/zcode-tui/src/copy-on-select.ts
|
|
162276
|
+
function record(value) {
|
|
162277
|
+
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
|
|
162278
|
+
}
|
|
162279
|
+
function configuredCopyOnSelect(config) {
|
|
162280
|
+
const value = record(record(config)?.ui)?.copyOnSelect;
|
|
162281
|
+
return typeof value === "boolean" ? value : void 0;
|
|
162282
|
+
}
|
|
162283
|
+
async function readCopyOnSelect(env = process.env) {
|
|
162284
|
+
return configuredCopyOnSelect(await readUserConfig(env)) ?? true;
|
|
162285
|
+
}
|
|
162286
|
+
async function writeCopyOnSelect(enabled, env = process.env) {
|
|
162287
|
+
return await updateUserConfig((config) => {
|
|
162288
|
+
const ui = record(config.ui) ?? {};
|
|
162289
|
+
ui.copyOnSelect = enabled;
|
|
162290
|
+
config.ui = ui;
|
|
162291
|
+
}, env);
|
|
162292
|
+
}
|
|
162293
|
+
//#endregion
|
|
161971
162294
|
//#region packages/zcode-tui/src/selectors.ts
|
|
161972
162295
|
function pickerRequest(input, commands) {
|
|
161973
162296
|
const match = /^\/([^\s]+)(?:\s+(.*))?$/u.exec(input.trim());
|
|
@@ -162582,6 +162905,8 @@ const backgroundStatuses = /* @__PURE__ */ new Set([
|
|
|
162582
162905
|
"failed",
|
|
162583
162906
|
"timed_out",
|
|
162584
162907
|
"cancelled",
|
|
162908
|
+
"killed",
|
|
162909
|
+
"stopped",
|
|
162585
162910
|
"spawn_error",
|
|
162586
162911
|
"lost"
|
|
162587
162912
|
]);
|
|
@@ -162790,12 +163115,18 @@ function normalizeRuntimeProjection(value) {
|
|
|
162790
163115
|
}),
|
|
162791
163116
|
backgroundJobs: records(rawBackgroundJobs).flatMap((item) => {
|
|
162792
163117
|
const taskId = stringField(item, "taskId", "taskID", "id");
|
|
162793
|
-
const
|
|
162794
|
-
|
|
162795
|
-
|
|
163118
|
+
const details = taskId ? taskDetails.get(taskId) : void 0;
|
|
163119
|
+
const definedDetails = details ? Object.fromEntries(Object.entries(details).filter(([, field]) => field !== void 0)) : void 0;
|
|
163120
|
+
const job = backgroundJobFrom(definedDetails ? {
|
|
163121
|
+
...item,
|
|
163122
|
+
...definedDetails
|
|
162796
163123
|
} : item);
|
|
162797
163124
|
return job ? [job] : [];
|
|
162798
163125
|
}),
|
|
163126
|
+
restoredBackgroundTasks: records(projection.restoredBackgroundTasks ?? value.restoredBackgroundTasks).flatMap((item) => {
|
|
163127
|
+
const job = backgroundJobFrom(item);
|
|
163128
|
+
return job ? [job] : [];
|
|
163129
|
+
}),
|
|
162799
163130
|
contextUsage: contextUsageFrom(runtime?.contextUsage ?? value.contextUsage, projection),
|
|
162800
163131
|
lastError: lastErrorType && lastErrorMessage ? {
|
|
162801
163132
|
type: lastErrorType,
|
|
@@ -163279,7 +163610,10 @@ var ThinkingView = class extends Box {
|
|
|
163279
163610
|
}
|
|
163280
163611
|
append(delta) {
|
|
163281
163612
|
if (!delta) return;
|
|
163282
|
-
|
|
163613
|
+
const sanitized = sanitizeTerminalText(delta, { preserveSgr: false });
|
|
163614
|
+
if (!sanitized) return;
|
|
163615
|
+
this.completed = false;
|
|
163616
|
+
this.text += sanitized;
|
|
163283
163617
|
this.dirty = true;
|
|
163284
163618
|
}
|
|
163285
163619
|
setText(text) {
|
|
@@ -163985,7 +164319,16 @@ function resultContent(value, expanded) {
|
|
|
163985
164319
|
function errorText(value) {
|
|
163986
164320
|
if (value instanceof Error) return sanitizeTerminalText(value.message, { preserveSgr: false });
|
|
163987
164321
|
const direct = asString(value);
|
|
163988
|
-
|
|
164322
|
+
if (direct) return sanitizeTerminalText(direct, { preserveSgr: false });
|
|
164323
|
+
if (!isRecord(value)) return stringify(value);
|
|
164324
|
+
const message = asString(value.message) ?? asString(value.detail) ?? asString(value.description);
|
|
164325
|
+
if (message) return sanitizeTerminalText(message, { preserveSgr: false });
|
|
164326
|
+
if (value.error !== value) {
|
|
164327
|
+
const nested = errorText(value.error);
|
|
164328
|
+
if (nested) return nested;
|
|
164329
|
+
}
|
|
164330
|
+
const code = asString(value.code) ?? asString(value.type) ?? asString(value.name);
|
|
164331
|
+
return code ? sanitizeTerminalText(code, { preserveSgr: false }) : void 0;
|
|
163989
164332
|
}
|
|
163990
164333
|
function statePresentation(state, theme) {
|
|
163991
164334
|
const normalized = state.toLowerCase();
|
|
@@ -164030,7 +164373,7 @@ function statePresentation(state, theme) {
|
|
|
164030
164373
|
}
|
|
164031
164374
|
function stateBackground(state, theme) {
|
|
164032
164375
|
const normalized = state.toLowerCase();
|
|
164033
|
-
if (normalized === "failed" || normalized === "error"
|
|
164376
|
+
if (normalized === "failed" || normalized === "error") return theme.toolErrorBackground;
|
|
164034
164377
|
return normalized === "waiting_permission" ? theme.toolPendingBackground : void 0;
|
|
164035
164378
|
}
|
|
164036
164379
|
function stylePreview(value, theme, expanded) {
|
|
@@ -164064,6 +164407,11 @@ function toolText(options, theme, input = parsedInput(options), expanded = false
|
|
|
164064
164407
|
summary && theme.muted(oneLine$2(summary)),
|
|
164065
164408
|
presentation.suffix && theme.muted(`· ${presentation.suffix}`)
|
|
164066
164409
|
].filter(Boolean).join(" ");
|
|
164410
|
+
if (options.state.toLowerCase() === "cancelled") return {
|
|
164411
|
+
header,
|
|
164412
|
+
images: [],
|
|
164413
|
+
truncated: false
|
|
164414
|
+
};
|
|
164067
164415
|
const sections = [];
|
|
164068
164416
|
let truncated = false;
|
|
164069
164417
|
const mutation = mutationInput(options.name, input);
|
|
@@ -164660,6 +165008,7 @@ const terminalStatuses = /* @__PURE__ */ new Set([
|
|
|
164660
165008
|
"failed",
|
|
164661
165009
|
"timed_out",
|
|
164662
165010
|
"cancelled",
|
|
165011
|
+
"killed",
|
|
164663
165012
|
"spawn_error",
|
|
164664
165013
|
"lost",
|
|
164665
165014
|
"stopped"
|
|
@@ -164706,6 +165055,14 @@ var TurnWorkTracker = class {
|
|
|
164706
165055
|
this.awaitingProjection = awaitProjection;
|
|
164707
165056
|
return this.isActive();
|
|
164708
165057
|
}
|
|
165058
|
+
cancel() {
|
|
165059
|
+
this.foregroundActive = false;
|
|
165060
|
+
this.awaitingProjection = false;
|
|
165061
|
+
this.projectionToolActive = false;
|
|
165062
|
+
this.projectionTurnActive = false;
|
|
165063
|
+
this.turnId = void 0;
|
|
165064
|
+
this.taskIds.clear();
|
|
165065
|
+
}
|
|
164709
165066
|
reconcile(projection) {
|
|
164710
165067
|
const jobs = projection.backgroundJobs;
|
|
164711
165068
|
for (const job of jobs) {
|
|
@@ -164746,18 +165103,20 @@ var UpdateAvailableView = class extends Box {
|
|
|
164746
165103
|
}
|
|
164747
165104
|
};
|
|
164748
165105
|
//#endregion
|
|
164749
|
-
//#region packages/zcode-tui/src/
|
|
164750
|
-
|
|
164751
|
-
|
|
164752
|
-
|
|
164753
|
-
|
|
164754
|
-
"
|
|
164755
|
-
|
|
164756
|
-
|
|
164757
|
-
const
|
|
164758
|
-
const
|
|
164759
|
-
|
|
164760
|
-
|
|
165106
|
+
//#region packages/zcode-tui/src/fullscreen-header.ts
|
|
165107
|
+
function clean(value) {
|
|
165108
|
+
return (value ? sanitizeTerminalText(value, { preserveSgr: false }).replace(/\s+/gu, " ").trim() : "") || void 0;
|
|
165109
|
+
}
|
|
165110
|
+
function normalizePath(value) {
|
|
165111
|
+
return value.replaceAll("\\", "/");
|
|
165112
|
+
}
|
|
165113
|
+
function displayWorkspacePath(workspace, homeDirectory = homedir()) {
|
|
165114
|
+
const path = normalizePath(clean(workspace) ?? "");
|
|
165115
|
+
const home = normalizePath(clean(homeDirectory) ?? "").replace(/\/+$/u, "");
|
|
165116
|
+
if (!path || !home) return path;
|
|
165117
|
+
if (path === home) return "~";
|
|
165118
|
+
if (path.startsWith(`${home}/`)) return `~${path.slice(home.length)}`;
|
|
165119
|
+
return path;
|
|
164761
165120
|
}
|
|
164762
165121
|
function truncateFromStart(value, width) {
|
|
164763
165122
|
if (width <= 0) return "";
|
|
@@ -164770,84 +165129,116 @@ function truncateFromStart(value, width) {
|
|
|
164770
165129
|
}
|
|
164771
165130
|
return `…${suffix.join("")}`;
|
|
164772
165131
|
}
|
|
164773
|
-
function
|
|
164774
|
-
const
|
|
164775
|
-
return
|
|
164776
|
-
|
|
164777
|
-
|
|
164778
|
-
const
|
|
164779
|
-
return
|
|
164780
|
-
}
|
|
164781
|
-
|
|
165132
|
+
function locationText(workspace, branch, width, homeDirectory) {
|
|
165133
|
+
const path = displayWorkspacePath(workspace, homeDirectory);
|
|
165134
|
+
if (!branch) return truncateFromStart(path, width);
|
|
165135
|
+
const separator = " · ";
|
|
165136
|
+
const branchText = truncateToWidth(branch, Math.min(visibleWidth(branch), Math.max(8, Math.floor(width * .36))), "…");
|
|
165137
|
+
const pathWidth = width - visibleWidth(separator) - visibleWidth(branchText);
|
|
165138
|
+
if (pathWidth <= 0) return truncateToWidth(branchText, width, "…");
|
|
165139
|
+
return `${truncateFromStart(path, pathWidth)}${separator}${branchText}`;
|
|
165140
|
+
}
|
|
165141
|
+
function fit(value, width) {
|
|
165142
|
+
return truncateToWidth(value, Math.max(0, width), "…");
|
|
165143
|
+
}
|
|
165144
|
+
function horizontalRail(content, width, theme) {
|
|
165145
|
+
const safeWidth = Math.max(1, width);
|
|
165146
|
+
if (safeWidth < 5) return fit(content, safeWidth);
|
|
165147
|
+
const left = "── ";
|
|
165148
|
+
const body = fit(content, Math.max(1, safeWidth - visibleWidth(left) - 2));
|
|
165149
|
+
const fill = "─".repeat(Math.max(1, safeWidth - visibleWidth(left) - visibleWidth(body) - 1));
|
|
165150
|
+
return fit(`${theme.muted(left)}${body}${theme.muted(` ${fill}`)}`, safeWidth);
|
|
165151
|
+
}
|
|
165152
|
+
function frameRule(edge, title, width, theme) {
|
|
165153
|
+
const [left, right] = edge === "top" ? ["╭─ ", "╮"] : ["╰─ ", "╯"];
|
|
165154
|
+
const fixedWidth = visibleWidth(left) + visibleWidth(right) + 2;
|
|
165155
|
+
if (width < fixedWidth) return fit(theme.muted("─".repeat(Math.max(1, width))), width);
|
|
165156
|
+
const body = fit(title, Math.max(1, width - fixedWidth));
|
|
165157
|
+
const fill = "─".repeat(Math.max(1, width - visibleWidth(left) - visibleWidth(body) - visibleWidth(right) - 1));
|
|
165158
|
+
return fit(`${theme.muted(left)}${body}${theme.muted(` ${fill}${right}`)}`, width);
|
|
165159
|
+
}
|
|
165160
|
+
function frameContent(content, width, theme) {
|
|
165161
|
+
if (width < 4) return fit(content, width);
|
|
165162
|
+
const innerWidth = width - 4;
|
|
165163
|
+
const body = fit(content, innerWidth);
|
|
165164
|
+
const padding = " ".repeat(Math.max(0, innerWidth - visibleWidth(body)));
|
|
165165
|
+
return `${theme.muted("│ ")}${body}${padding}${theme.muted(" │")}`;
|
|
165166
|
+
}
|
|
165167
|
+
var FullscreenHeader = class {
|
|
164782
165168
|
theme;
|
|
165169
|
+
phase = "welcome";
|
|
164783
165170
|
branch;
|
|
164784
165171
|
distributionVersion;
|
|
164785
165172
|
runtimeVersion;
|
|
164786
165173
|
workspace;
|
|
165174
|
+
homeDirectory;
|
|
164787
165175
|
constructor(theme, options) {
|
|
164788
165176
|
this.theme = theme;
|
|
164789
|
-
this.branch =
|
|
164790
|
-
this.distributionVersion =
|
|
164791
|
-
this.runtimeVersion =
|
|
164792
|
-
this.workspace =
|
|
165177
|
+
this.branch = clean(options.branch);
|
|
165178
|
+
this.distributionVersion = clean(options.distributionVersion);
|
|
165179
|
+
this.runtimeVersion = clean(options.runtimeVersion) ?? "unknown";
|
|
165180
|
+
this.workspace = clean(options.workspace) ?? "";
|
|
165181
|
+
this.homeDirectory = options.homeDirectory ?? homedir();
|
|
165182
|
+
}
|
|
165183
|
+
setPhase(phase) {
|
|
165184
|
+
this.phase = phase;
|
|
165185
|
+
}
|
|
165186
|
+
getPhase() {
|
|
165187
|
+
return this.phase;
|
|
165188
|
+
}
|
|
165189
|
+
location(width) {
|
|
165190
|
+
return locationText(this.workspace, this.branch, Math.max(0, width), this.homeDirectory);
|
|
165191
|
+
}
|
|
165192
|
+
identity(width, includeVersion = true) {
|
|
165193
|
+
const brand = this.theme.bold(this.theme.accent("◆ ZCODE"));
|
|
165194
|
+
if (!includeVersion) return fit(brand, Math.max(0, width));
|
|
165195
|
+
const version = this.distributionVersion ?? this.runtimeVersion;
|
|
165196
|
+
return fit(`${brand} ${this.theme.muted(`v${version}`)}`, Math.max(0, width));
|
|
164793
165197
|
}
|
|
164794
165198
|
render(width) {
|
|
164795
|
-
|
|
164796
|
-
|
|
165199
|
+
const safeWidth = Math.max(1, width);
|
|
165200
|
+
if (this.phase === "welcome") return [horizontalRail(this.identity(safeWidth, true), safeWidth, this.theme)];
|
|
165201
|
+
if (this.phase === "transition") return [horizontalRail(this.identity(safeWidth, false), safeWidth, this.theme)];
|
|
165202
|
+
const identity = this.identity(safeWidth, false);
|
|
165203
|
+
const separator = " ";
|
|
165204
|
+
const location = this.location(Math.max(0, safeWidth - visibleWidth(identity) - visibleWidth(separator) - 6));
|
|
165205
|
+
return [horizontalRail(`${identity}${separator}${this.theme.muted(location)}`, safeWidth, this.theme)];
|
|
164797
165206
|
}
|
|
164798
165207
|
invalidate() {}
|
|
164799
|
-
renderWide(width) {
|
|
164800
|
-
const contentWidth = Math.max(1, width - 1);
|
|
164801
|
-
const gap = " ";
|
|
164802
|
-
const informationWidth = Math.max(1, contentWidth - 10 - 3);
|
|
164803
|
-
const panelWidth = Math.min(informationWidth, maxInformationWidth);
|
|
164804
|
-
const panelContentWidth = Math.max(1, panelWidth - 2);
|
|
164805
|
-
const primaryVersion = this.distributionVersion ?? this.runtimeVersion;
|
|
164806
|
-
const identity = `${this.theme.bold(this.theme.accent("ZCODE"))} ${this.theme.muted(`v${primaryVersion}`)}`;
|
|
164807
|
-
const fullVersionLine = this.distributionVersion ? `${identity}${this.theme.muted(` · runtime v${this.runtimeVersion}`)}` : identity;
|
|
164808
|
-
const compactVersionLine = this.distributionVersion ? `${identity}${this.theme.muted(` · rt v${this.runtimeVersion}`)}` : identity;
|
|
164809
|
-
const versionLine = visibleWidth(fullVersionLine) <= panelContentWidth ? fullVersionLine : compactVersionLine;
|
|
164810
|
-
const locationLine = this.locationLine(panelContentWidth);
|
|
164811
|
-
const information = [
|
|
164812
|
-
this.theme.muted(boxRule("┌", panelWidth)),
|
|
164813
|
-
`${this.theme.muted("│")} ${padTerminalText(versionLine, panelContentWidth)}`,
|
|
164814
|
-
`${this.theme.muted("│")} ${this.theme.muted(padTerminalText(locationLine, panelContentWidth))}`,
|
|
164815
|
-
this.theme.muted(boxRule("└", panelWidth))
|
|
164816
|
-
];
|
|
164817
|
-
return BRAND_MARK.map((line, index) => ` ${this.theme.accent(line)}${gap}${information[index] ?? ""}`);
|
|
164818
|
-
}
|
|
164819
|
-
locationLine(width) {
|
|
164820
|
-
if (!this.branch) return truncateFromStart(this.workspace, width);
|
|
164821
|
-
const separator = " · ";
|
|
164822
|
-
const branchWidth = Math.max(8, Math.min(visibleWidth(`branch ${this.branch}`), Math.floor(width * .45)));
|
|
164823
|
-
const branch = truncateToWidth(`branch ${this.branch}`, branchWidth, "…");
|
|
164824
|
-
const workspaceWidth = width - visibleWidth(separator) - visibleWidth(branch);
|
|
164825
|
-
if (workspaceWidth < 4) return truncateToWidth(branch, width, "…");
|
|
164826
|
-
return `${truncateFromStart(this.workspace, workspaceWidth)}${separator}${branch}`;
|
|
164827
|
-
}
|
|
164828
|
-
renderCompact(width) {
|
|
164829
|
-
const contentWidth = Math.max(0, width - 1);
|
|
164830
|
-
const primaryVersion = this.distributionVersion ?? this.runtimeVersion;
|
|
164831
|
-
const identity = `${this.theme.bold(this.theme.accent("ZCODE"))} ${this.theme.muted(`v${primaryVersion}`)}`;
|
|
164832
|
-
const location = [this.workspace, this.branch ? `branch ${this.branch}` : void 0].filter((value) => Boolean(value)).join(" · ");
|
|
164833
|
-
return [` ${truncateToWidth(identity, contentWidth)}`, ` ${this.theme.muted(truncateFromStart(location, contentWidth))}`];
|
|
164834
|
-
}
|
|
164835
165208
|
};
|
|
164836
|
-
/**
|
|
164837
|
-
var
|
|
164838
|
-
|
|
164839
|
-
|
|
164840
|
-
|
|
164841
|
-
|
|
164842
|
-
|
|
165209
|
+
/** One-time startup content that belongs to the transcript, not the chrome. */
|
|
165210
|
+
var SessionWelcome = class {
|
|
165211
|
+
theme;
|
|
165212
|
+
location;
|
|
165213
|
+
identity;
|
|
165214
|
+
loginRequired;
|
|
165215
|
+
includeIdentity;
|
|
165216
|
+
transitioning = false;
|
|
165217
|
+
constructor(theme, location, identity, options = {}) {
|
|
165218
|
+
this.theme = theme;
|
|
165219
|
+
this.location = location;
|
|
165220
|
+
this.identity = identity;
|
|
165221
|
+
this.loginRequired = options.loginRequired === true;
|
|
165222
|
+
this.includeIdentity = options.includeIdentity !== false;
|
|
165223
|
+
}
|
|
165224
|
+
setLoginRequired(required) {
|
|
165225
|
+
this.loginRequired = required;
|
|
165226
|
+
}
|
|
165227
|
+
setIncludeIdentity(include) {
|
|
165228
|
+
this.includeIdentity = include;
|
|
165229
|
+
}
|
|
165230
|
+
setTransitioning(transitioning) {
|
|
165231
|
+
this.transitioning = transitioning;
|
|
164843
165232
|
}
|
|
164844
165233
|
render(width) {
|
|
164845
|
-
|
|
164846
|
-
const
|
|
164847
|
-
|
|
164848
|
-
const
|
|
164849
|
-
|
|
164850
|
-
|
|
165234
|
+
const safeWidth = Math.max(1, width);
|
|
165235
|
+
const frameWidth = Math.max(1, Math.min(safeWidth, 76));
|
|
165236
|
+
const innerWidth = Math.max(1, frameWidth - 4);
|
|
165237
|
+
const content = [frameRule("top", this.includeIdentity ? this.identity(Math.max(1, frameWidth - 8)) : this.theme.bold("Workspace"), frameWidth, this.theme), frameContent(this.theme.muted(this.location(innerWidth)), frameWidth, this.theme)];
|
|
165238
|
+
if (this.loginRequired) content.push(frameContent(this.theme.warning("Model access is not configured · Run /login."), frameWidth, this.theme));
|
|
165239
|
+
content.push(frameContent(this.theme.bold("Ask a task about this workspace"), frameWidth, this.theme), frameRule("bottom", this.theme.muted("/help commands · /status details"), frameWidth, this.theme));
|
|
165240
|
+
const lines = content.map((line) => truncateToWidth(line, safeWidth, "…"));
|
|
165241
|
+
return this.transitioning ? lines.map((line) => this.theme.muted(sanitizeTerminalText(line, { preserveSgr: false }))) : lines;
|
|
164851
165242
|
}
|
|
164852
165243
|
invalidate() {}
|
|
164853
165244
|
};
|
|
@@ -165270,6 +165661,7 @@ const runtimeCommandSummaries = /* @__PURE__ */ new Map([
|
|
|
165270
165661
|
]);
|
|
165271
165662
|
const terminalThemeQueryTimeoutMs = 100;
|
|
165272
165663
|
const exitUsageQueryTimeoutMs = 250;
|
|
165664
|
+
const fullscreenWelcomeTransitionMs = 180;
|
|
165273
165665
|
const updateAvailableBlockId = "update_available";
|
|
165274
165666
|
const modelRetryBlockIdPrefix = "model_retry_status";
|
|
165275
165667
|
const questionBackValue = "__back__";
|
|
@@ -165281,6 +165673,7 @@ const backgroundTaskAttentionStatuses = /* @__PURE__ */ new Set([
|
|
|
165281
165673
|
"spawn_error",
|
|
165282
165674
|
"lost"
|
|
165283
165675
|
]);
|
|
165676
|
+
const defaultBackgroundResumeMessage = "Continue the assigned task from the last completed step. Re-check the current workspace state and finish the remaining work.";
|
|
165284
165677
|
function backgroundTaskKindLabel(job) {
|
|
165285
165678
|
switch (job.taskKind) {
|
|
165286
165679
|
case "local_agent": return job.agentType ? `Agent (${job.agentType})` : "Agent";
|
|
@@ -165297,13 +165690,33 @@ function backgroundTaskSortRank(job) {
|
|
|
165297
165690
|
}
|
|
165298
165691
|
function backgroundAgentPart(part) {
|
|
165299
165692
|
if (part.type !== "tool") return false;
|
|
165300
|
-
|
|
165301
|
-
if (name !== "agent" && name !== "subagent") return false;
|
|
165693
|
+
if (!isAgentDispatchTool(part.toolName)) return false;
|
|
165302
165694
|
const input = isRecord(part.input) ? part.input : void 0;
|
|
165303
165695
|
const output = isRecord(part.output) ? part.output : void 0;
|
|
165304
165696
|
const nestedOutput = isRecord(output?.output) ? output.output : void 0;
|
|
165305
165697
|
return input?.run_in_background === true || output?.isAsync === true || output?.status === "async_launched" || output?.status === "backgrounded" || typeof output?.backgroundTaskId === "string" || nestedOutput?.isAsync === true || nestedOutput?.status === "async_launched" || nestedOutput?.status === "backgrounded" || typeof nestedOutput?.backgroundTaskId === "string";
|
|
165306
165698
|
}
|
|
165699
|
+
/**
|
|
165700
|
+
* Conversation-facing notice for a task-center action (resume / restart /
|
|
165701
|
+
* guidance). Side-channel task actions are invisible to the model otherwise —
|
|
165702
|
+
* surfacing them through the main conversation lets the coordinator wait on
|
|
165703
|
+
* the task with TaskOutput(block=true) instead of finalizing without it.
|
|
165704
|
+
*/
|
|
165705
|
+
function taskCoordinatorNotice(job, restart, message) {
|
|
165706
|
+
const label = job.description ? `${job.taskId} (${job.description})` : job.taskId;
|
|
165707
|
+
return [
|
|
165708
|
+
restart ? `Background task ${label} was restarted from the task center with the instruction:` : isActiveBackgroundJob(job) ? `Guidance was sent to background task ${label}:` : `Background task ${label} was resumed from the task center with the instruction:`,
|
|
165709
|
+
`"${message}"`,
|
|
165710
|
+
"If your current work depends on this task, call TaskOutput with block=true to wait for its result before giving your final answer; otherwise continue and its completion notification will arrive automatically."
|
|
165711
|
+
].join("\n");
|
|
165712
|
+
}
|
|
165713
|
+
function backgroundCancellationFailure(value) {
|
|
165714
|
+
if (isRecord(value) && value.cancelled === true) return void 0;
|
|
165715
|
+
if (!isRecord(value)) return "cancellation was not confirmed";
|
|
165716
|
+
const reason = asString(value.reason)?.replaceAll("_", " ");
|
|
165717
|
+
const status = asString(value.status)?.replaceAll("_", " ");
|
|
165718
|
+
return [reason, status ? `status ${status}` : void 0].filter(Boolean).join(" · ") || "cancellation was not confirmed";
|
|
165719
|
+
}
|
|
165307
165720
|
function backgroundToolPartIds(parts) {
|
|
165308
165721
|
const hidden = /* @__PURE__ */ new Set();
|
|
165309
165722
|
for (const part of parts) {
|
|
@@ -165386,6 +165799,63 @@ var ConditionalContainer = class extends Container {
|
|
|
165386
165799
|
return this.visible() ? super.render(width) : [];
|
|
165387
165800
|
}
|
|
165388
165801
|
};
|
|
165802
|
+
/**
|
|
165803
|
+
* AI SDK emits its warning banner through console.info when no handler is
|
|
165804
|
+
* installed. In the interactive TUI that stdout write is terminal content,
|
|
165805
|
+
* so suppress only the default banner while preserving a runtime-provided
|
|
165806
|
+
* structured warning handler.
|
|
165807
|
+
*/
|
|
165808
|
+
function suppressTuiAiSdkWarnings() {
|
|
165809
|
+
const global = globalThis;
|
|
165810
|
+
if (typeof global.AI_SDK_LOG_WARNINGS === "function") return;
|
|
165811
|
+
try {
|
|
165812
|
+
global.AI_SDK_LOG_WARNINGS = false;
|
|
165813
|
+
} catch {}
|
|
165814
|
+
}
|
|
165815
|
+
suppressTuiAiSdkWarnings();
|
|
165816
|
+
/**
|
|
165817
|
+
* The upstream alternate-screen renderer intentionally reserves Home/End and
|
|
165818
|
+
* PageUp/PageDown for viewport navigation. ZCode's composer is a real editor,
|
|
165819
|
+
* so it needs the same priority as a modal overlay while it has focus.
|
|
165820
|
+
*/
|
|
165821
|
+
var ZCodeAltScreen = class extends TuiAltScreen {
|
|
165822
|
+
viewportInputDeferral;
|
|
165823
|
+
currentInput;
|
|
165824
|
+
setViewportInputDeferral(deferral) {
|
|
165825
|
+
this.viewportInputDeferral = deferral;
|
|
165826
|
+
}
|
|
165827
|
+
setCurrentInput(data) {
|
|
165828
|
+
this.currentInput = data;
|
|
165829
|
+
}
|
|
165830
|
+
isOverlayFocused() {
|
|
165831
|
+
if (super.isOverlayFocused()) return true;
|
|
165832
|
+
return this.viewportInputDeferral?.(this.currentInput ?? "") === true;
|
|
165833
|
+
}
|
|
165834
|
+
};
|
|
165835
|
+
/** Feed focus reports to the notifier before the TUI's own input listeners. */
|
|
165836
|
+
var NotifyingProcessTerminal = class extends ProcessTerminal {
|
|
165837
|
+
beforeInput;
|
|
165838
|
+
afterInput;
|
|
165839
|
+
constructor(beforeInput, afterInput) {
|
|
165840
|
+
super();
|
|
165841
|
+
this.beforeInput = beforeInput;
|
|
165842
|
+
this.afterInput = afterInput;
|
|
165843
|
+
}
|
|
165844
|
+
start(onInput, onResize) {
|
|
165845
|
+
super.start((data) => {
|
|
165846
|
+
this.beforeInput(data);
|
|
165847
|
+
try {
|
|
165848
|
+
onInput(data);
|
|
165849
|
+
} finally {
|
|
165850
|
+
this.afterInput?.();
|
|
165851
|
+
}
|
|
165852
|
+
}, onResize);
|
|
165853
|
+
}
|
|
165854
|
+
};
|
|
165855
|
+
function signalExitCode(signal) {
|
|
165856
|
+
const number = constants$1.signals[signal];
|
|
165857
|
+
return typeof number === "number" ? 128 + number : 1;
|
|
165858
|
+
}
|
|
165389
165859
|
var ZCodeTui = class {
|
|
165390
165860
|
options;
|
|
165391
165861
|
animateTurnTimer;
|
|
@@ -165397,6 +165867,14 @@ var ZCodeTui = class {
|
|
|
165397
165867
|
transcript;
|
|
165398
165868
|
choiceHost = new Container();
|
|
165399
165869
|
composerHost = new ConditionalContainer(() => this.choiceDepth === 0);
|
|
165870
|
+
headerHost = new Container();
|
|
165871
|
+
transcriptHost = new Container();
|
|
165872
|
+
sessionWelcomeHost = new ConditionalContainer(() => this.tuiMode === "fullscreen" && this.fullscreenWelcomeVisible);
|
|
165873
|
+
editorHost = new Container();
|
|
165874
|
+
fullscreenHeader;
|
|
165875
|
+
sessionWelcome;
|
|
165876
|
+
fullscreenTranscript;
|
|
165877
|
+
fullscreenLayout;
|
|
165400
165878
|
runtimeActivity;
|
|
165401
165879
|
status;
|
|
165402
165880
|
turnStatus;
|
|
@@ -165439,8 +165917,11 @@ var ZCodeTui = class {
|
|
|
165439
165917
|
currentToolGroupBlockId;
|
|
165440
165918
|
currentToolGroupMessageId;
|
|
165441
165919
|
pendingAttachments = [];
|
|
165920
|
+
editorHistory = [];
|
|
165442
165921
|
mode;
|
|
165443
165922
|
model;
|
|
165923
|
+
tuiMode;
|
|
165924
|
+
copyOnSelect = true;
|
|
165444
165925
|
thoughtLevel;
|
|
165445
165926
|
modelOptions;
|
|
165446
165927
|
effortOptions;
|
|
@@ -165449,6 +165930,7 @@ var ZCodeTui = class {
|
|
|
165449
165930
|
unsubscribeWorkflow;
|
|
165450
165931
|
unsubscribeSession;
|
|
165451
165932
|
backgroundTaskEvents = new BackgroundTaskEventStore();
|
|
165933
|
+
restoredNoticeSeen = /* @__PURE__ */ new Set();
|
|
165452
165934
|
turnWork = new TurnWorkTracker();
|
|
165453
165935
|
backgroundCoordinatorMessageIds = /* @__PURE__ */ new Set();
|
|
165454
165936
|
workflowPanel;
|
|
@@ -165456,6 +165938,9 @@ var ZCodeTui = class {
|
|
|
165456
165938
|
workflowRefreshInFlight = false;
|
|
165457
165939
|
choiceDepth = 0;
|
|
165458
165940
|
settingSwitchInFlight = false;
|
|
165941
|
+
fullscreenWelcomeVisible = true;
|
|
165942
|
+
fullscreenWelcomeTransitionTimer;
|
|
165943
|
+
sessionHasContent = false;
|
|
165459
165944
|
rewindEscapePending = false;
|
|
165460
165945
|
rewindEscapeTimer;
|
|
165461
165946
|
rewindFlowActive = false;
|
|
@@ -165487,8 +165972,6 @@ var ZCodeTui = class {
|
|
|
165487
165972
|
backgroundHandoffInterruptInFlight = false;
|
|
165488
165973
|
updateCheckAbortController;
|
|
165489
165974
|
loginRequired;
|
|
165490
|
-
loginWarning = new Text("", 1, 0);
|
|
165491
|
-
loginHelp = new Text("", 1, 0);
|
|
165492
165975
|
constructor(options) {
|
|
165493
165976
|
this.options = options;
|
|
165494
165977
|
this.animateTurnTimer = turnTimerAnimationEnabled();
|
|
@@ -165497,6 +165980,18 @@ var ZCodeTui = class {
|
|
|
165497
165980
|
this.distributionVersion = sanitizeTerminalText(process.env.ZCODE_APP_CLI_VERSION?.trim() ?? "", { preserveSgr: false }) || void 0;
|
|
165498
165981
|
this.theme = createTheme(this.colorsEnabled, initialColorScheme(this.themePreference));
|
|
165499
165982
|
this.transcript = new Transcript(this.theme.searchMatch);
|
|
165983
|
+
const workspace = options.workspaceDirectory ?? process.cwd();
|
|
165984
|
+
const runtimeVersion = sanitizeTerminalText(options.version ?? "unknown", { preserveSgr: false });
|
|
165985
|
+
this.fullscreenHeader = new FullscreenHeader(this.theme, {
|
|
165986
|
+
branch: options.workspaceGitBranch,
|
|
165987
|
+
distributionVersion: this.distributionVersion,
|
|
165988
|
+
runtimeVersion,
|
|
165989
|
+
workspace
|
|
165990
|
+
});
|
|
165991
|
+
this.sessionWelcome = new SessionWelcome(this.theme, (width) => this.fullscreenHeader.location(width), (width) => this.fullscreenHeader.identity(width), {
|
|
165992
|
+
loginRequired: options.loginRequired === true,
|
|
165993
|
+
includeIdentity: true
|
|
165994
|
+
});
|
|
165500
165995
|
this.mode = normalizedMode(options.initialMode);
|
|
165501
165996
|
this.model = modelLabel$1(options.initialModel);
|
|
165502
165997
|
this.thoughtLevel = options.initialThoughtLevel;
|
|
@@ -165504,7 +165999,8 @@ var ZCodeTui = class {
|
|
|
165504
165999
|
this.effortOptions = [...options.effortOptions ?? []];
|
|
165505
166000
|
this.loginRequired = options.loginRequired === true;
|
|
165506
166001
|
this.skillCatalog = new SkillCatalog(options.listSkills);
|
|
165507
|
-
this.
|
|
166002
|
+
this.tuiMode = resolveTuiMode(process.env, { ui: { tuiMode: options.initialTuiMode } });
|
|
166003
|
+
this.ui = this.createTui(this.tuiMode);
|
|
165508
166004
|
this.notifications = new TurnNotifier({ writeTerminal: (data) => this.ui.terminal.write(data) });
|
|
165509
166005
|
this.status = new StatusLine();
|
|
165510
166006
|
this.turnStatus = new FooterBar();
|
|
@@ -165534,11 +166030,8 @@ var ZCodeTui = class {
|
|
|
165534
166030
|
onRender: () => this.ui.requestRender()
|
|
165535
166031
|
});
|
|
165536
166032
|
this.runtimeActivity = new RuntimeActivityView(this.theme);
|
|
165537
|
-
this.editor =
|
|
165538
|
-
|
|
165539
|
-
autocompleteMaxVisible: 7
|
|
165540
|
-
});
|
|
165541
|
-
this.assistantStream = new AssistantStream(this.theme, (component, blockOptions) => this.transcript.addBlock(component, blockOptions));
|
|
166033
|
+
this.editor = this.createEditor(this.ui);
|
|
166034
|
+
this.assistantStream = new AssistantStream(this.theme, (component, blockOptions) => this.addTranscriptBlock(component, blockOptions));
|
|
165542
166035
|
this.done = new Promise((resolve) => {
|
|
165543
166036
|
this.resolveDone = resolve;
|
|
165544
166037
|
});
|
|
@@ -165551,34 +166044,79 @@ var ZCodeTui = class {
|
|
|
165551
166044
|
} catch (error) {
|
|
165552
166045
|
notificationConfigError = error instanceof Error ? error.message : String(error);
|
|
165553
166046
|
}
|
|
166047
|
+
try {
|
|
166048
|
+
this.setCopyOnSelect(await readCopyOnSelect());
|
|
166049
|
+
} catch {}
|
|
166050
|
+
try {
|
|
166051
|
+
const configEnv = { ...process.env };
|
|
166052
|
+
delete configEnv.ZCODE_TUI_MODE;
|
|
166053
|
+
const fromConfig = await readTuiMode(configEnv);
|
|
166054
|
+
const effective = resolveTuiMode(process.env, { ui: { tuiMode: this.options.initialTuiMode ?? fromConfig } });
|
|
166055
|
+
if (effective !== this.tuiMode) {
|
|
166056
|
+
this.ui = this.createTui(effective);
|
|
166057
|
+
this.tuiMode = effective;
|
|
166058
|
+
this.editor = this.createEditor(this.ui);
|
|
166059
|
+
}
|
|
166060
|
+
} catch {}
|
|
165554
166061
|
const updateCheck = this.distributionVersion ? await readStartupUpdate({ currentVersion: this.distributionVersion }).catch(() => void 0) : void 0;
|
|
165555
|
-
this.
|
|
165556
|
-
|
|
165557
|
-
this.
|
|
165558
|
-
|
|
165559
|
-
|
|
165560
|
-
if (
|
|
165561
|
-
|
|
165562
|
-
|
|
165563
|
-
|
|
165564
|
-
|
|
165565
|
-
|
|
165566
|
-
|
|
165567
|
-
|
|
165568
|
-
|
|
165569
|
-
|
|
165570
|
-
|
|
165571
|
-
|
|
165572
|
-
|
|
165573
|
-
|
|
165574
|
-
|
|
165575
|
-
this.
|
|
165576
|
-
|
|
165577
|
-
|
|
165578
|
-
this.
|
|
165579
|
-
this.
|
|
165580
|
-
|
|
165581
|
-
|
|
166062
|
+
const onSigint = () => this.handleSignal("SIGINT");
|
|
166063
|
+
const onSigterm = () => this.handleSignal("SIGTERM");
|
|
166064
|
+
const onSighup = () => this.handleSignal("SIGHUP");
|
|
166065
|
+
process.once("SIGINT", onSigint);
|
|
166066
|
+
process.once("SIGTERM", onSigterm);
|
|
166067
|
+
if (process.platform !== "win32") process.once("SIGHUP", onSighup);
|
|
166068
|
+
let startAttempted = false;
|
|
166069
|
+
try {
|
|
166070
|
+
if (this.stopped) {
|
|
166071
|
+
await this.done;
|
|
166072
|
+
return;
|
|
166073
|
+
}
|
|
166074
|
+
startAttempted = true;
|
|
166075
|
+
this.ui.start();
|
|
166076
|
+
if (this.stopped) {
|
|
166077
|
+
await this.done;
|
|
166078
|
+
return;
|
|
166079
|
+
}
|
|
166080
|
+
await this.resolveTerminalColorScheme();
|
|
166081
|
+
this.buildLayout();
|
|
166082
|
+
if (notificationConfigError) this.addNotice(`Unable to load notification settings: ${notificationConfigError}`, "warning");
|
|
166083
|
+
await this.restoreInitialTranscript();
|
|
166084
|
+
if (this.transcript.blockCount > 0) this.enterSessionRail(true);
|
|
166085
|
+
if (updateCheck?.availableVersion && this.distributionVersion) this.addUpdateAvailable(this.distributionVersion, updateCheck.availableVersion);
|
|
166086
|
+
this.bindInput();
|
|
166087
|
+
this.notifications.start();
|
|
166088
|
+
this.focusEditor();
|
|
166089
|
+
this.updateMetadata();
|
|
166090
|
+
this.updateTurnStatus();
|
|
166091
|
+
this.ui.requestRender(true);
|
|
166092
|
+
this.startUpdateRefresh(updateCheck);
|
|
166093
|
+
if (!this.loginRequired) this.refreshGoal();
|
|
166094
|
+
if (!this.loginRequired) this.refreshSessionUsage();
|
|
166095
|
+
if (await readSetupPending().catch(() => false)) if (await readConfiguredModelAccess().catch(() => null)) await clearSetupPending().catch(() => {});
|
|
166096
|
+
else this.runFirstRunSetup();
|
|
166097
|
+
this.scheduleRuntimePoll(0);
|
|
166098
|
+
this.loadHistory();
|
|
166099
|
+
if (this.options.subscribeSessionEvents) this.unsubscribeSession = this.options.subscribeSessionEvents((event) => {
|
|
166100
|
+
this.onSessionEvent(event);
|
|
166101
|
+
}) ?? void 0;
|
|
166102
|
+
if (this.options.subscribeWorkflowEvents) this.unsubscribeWorkflow = this.options.subscribeWorkflowEvents((event) => {
|
|
166103
|
+
this.debugEvent("workflow", event);
|
|
166104
|
+
this.refreshWorkflowFromEvent();
|
|
166105
|
+
}) ?? void 0;
|
|
166106
|
+
await this.done;
|
|
166107
|
+
} finally {
|
|
166108
|
+
process.off("SIGINT", onSigint);
|
|
166109
|
+
process.off("SIGTERM", onSigterm);
|
|
166110
|
+
if (process.platform !== "win32") process.off("SIGHUP", onSighup);
|
|
166111
|
+
if (startAttempted && !this.stopped) {
|
|
166112
|
+
this.stop();
|
|
166113
|
+
await this.done;
|
|
166114
|
+
}
|
|
166115
|
+
}
|
|
166116
|
+
}
|
|
166117
|
+
handleSignal(signal) {
|
|
166118
|
+
process.exitCode = signalExitCode(signal);
|
|
166119
|
+
if (!this.stopped) this.stop();
|
|
165582
166120
|
}
|
|
165583
166121
|
async resolveTerminalColorScheme() {
|
|
165584
166122
|
if (!this.colorsEnabled || this.themePreference !== "auto") return;
|
|
@@ -165588,43 +166126,260 @@ var ZCodeTui = class {
|
|
|
165588
166126
|
if (colorScheme) this.theme.setColorScheme(colorScheme);
|
|
165589
166127
|
} catch {}
|
|
165590
166128
|
}
|
|
166129
|
+
/** The live fullscreen alt screen, when the active TUI is the fullscreen one. */
|
|
166130
|
+
get fullscreenAltScreen() {
|
|
166131
|
+
return this.ui instanceof ZCodeAltScreen ? this.ui : void 0;
|
|
166132
|
+
}
|
|
166133
|
+
setCopyOnSelect(enabled) {
|
|
166134
|
+
this.copyOnSelect = enabled;
|
|
166135
|
+
this.fullscreenAltScreen?.setCopyOnSelect(enabled);
|
|
166136
|
+
}
|
|
166137
|
+
createTui(mode) {
|
|
166138
|
+
let fullscreenTui;
|
|
166139
|
+
const terminal = new NotifyingProcessTerminal((data) => {
|
|
166140
|
+
fullscreenTui?.setCurrentInput(data);
|
|
166141
|
+
this.notifications?.handleInput(data);
|
|
166142
|
+
}, () => fullscreenTui?.setCurrentInput(void 0));
|
|
166143
|
+
if (mode !== "fullscreen") return new TuiMainScreen(terminal, true);
|
|
166144
|
+
const tui = new ZCodeAltScreen(terminal, true, void 0, {
|
|
166145
|
+
copySelection: async (text) => {
|
|
166146
|
+
const writeClipboardText = this.options.writeClipboardText;
|
|
166147
|
+
if (!writeClipboardText) return false;
|
|
166148
|
+
try {
|
|
166149
|
+
await writeClipboardText(text);
|
|
166150
|
+
return true;
|
|
166151
|
+
} catch {
|
|
166152
|
+
return false;
|
|
166153
|
+
}
|
|
166154
|
+
},
|
|
166155
|
+
copyOnSelect: this.copyOnSelect,
|
|
166156
|
+
mouse: true,
|
|
166157
|
+
wheelScrollLines: 3
|
|
166158
|
+
});
|
|
166159
|
+
fullscreenTui = tui;
|
|
166160
|
+
tui.setViewportInputDeferral((data) => {
|
|
166161
|
+
const focused = tui.getFocusedComponent();
|
|
166162
|
+
if (focused === this.attachmentBar) return matchesKey(data, "home") || matchesKey(data, "end");
|
|
166163
|
+
if (focused !== this.editor) return false;
|
|
166164
|
+
if (matchesKey(data, "home") || matchesKey(data, "end") || matchesKey(data, "ctrl+home") || matchesKey(data, "ctrl+end")) return true;
|
|
166165
|
+
return matchesKey(data, "pageUp") || matchesKey(data, "pageDown") || matchesKey(data, "ctrl+pageUp") || matchesKey(data, "ctrl+pageDown");
|
|
166166
|
+
});
|
|
166167
|
+
return tui;
|
|
166168
|
+
}
|
|
165591
166169
|
buildLayout() {
|
|
165592
|
-
const
|
|
165593
|
-
|
|
165594
|
-
this.
|
|
165595
|
-
|
|
165596
|
-
|
|
165597
|
-
runtimeVersion,
|
|
165598
|
-
workspace
|
|
165599
|
-
}));
|
|
165600
|
-
this.ui.addChild(new Divider("─", this.theme.muted));
|
|
165601
|
-
this.ui.addChild(this.loginWarning);
|
|
165602
|
-
this.ui.addChild(this.loginHelp);
|
|
166170
|
+
const fullscreen = isViewportTUI(this.ui);
|
|
166171
|
+
this.fullscreenHeader.setPhase(fullscreen && this.fullscreenWelcomeVisible ? "welcome" : "rail");
|
|
166172
|
+
this.sessionWelcome.setLoginRequired(this.loginRequired);
|
|
166173
|
+
this.sessionWelcome.setIncludeIdentity(!fullscreen);
|
|
166174
|
+
this.headerHost.clear();
|
|
165603
166175
|
this.updateLoginWarning();
|
|
165604
|
-
|
|
165605
|
-
|
|
165606
|
-
|
|
165607
|
-
this.
|
|
166176
|
+
if (!fullscreen) {
|
|
166177
|
+
if (!this.sessionHasContent) this.mountRegularSessionWelcome();
|
|
166178
|
+
}
|
|
166179
|
+
this.transcriptHost.clear();
|
|
166180
|
+
this.sessionWelcomeHost.clear();
|
|
166181
|
+
if (fullscreen) this.sessionWelcome.setIncludeIdentity(false);
|
|
166182
|
+
this.sessionWelcomeHost.addChild(this.sessionWelcome);
|
|
166183
|
+
if (fullscreen) this.transcriptHost.addChild(this.sessionWelcomeHost);
|
|
166184
|
+
this.transcriptHost.addChild(this.transcript);
|
|
166185
|
+
this.transcriptHost.addChild(this.runtimeActivity);
|
|
166186
|
+
this.transcriptHost.addChild(this.choiceHost);
|
|
166187
|
+
this.editorHost.clear();
|
|
166188
|
+
this.editorHost.addChild(this.editor);
|
|
166189
|
+
this.composerHost.clear();
|
|
165608
166190
|
this.composerHost.addChild(this.turnStatus);
|
|
165609
166191
|
this.composerHost.addChild(this.queuedInputView);
|
|
165610
166192
|
this.composerHost.addChild(this.attachmentBar);
|
|
165611
|
-
this.composerHost.addChild(this.
|
|
166193
|
+
this.composerHost.addChild(this.editorHost);
|
|
165612
166194
|
this.composerHost.addChild(this.status);
|
|
166195
|
+
this.mountLayout();
|
|
166196
|
+
}
|
|
166197
|
+
enterSessionRail(immediate = false) {
|
|
166198
|
+
this.sessionHasContent = true;
|
|
166199
|
+
if (this.tuiMode !== "fullscreen") return;
|
|
166200
|
+
const phase = this.fullscreenHeader.getPhase();
|
|
166201
|
+
if (phase === "rail") {
|
|
166202
|
+
this.fullscreenWelcomeVisible = false;
|
|
166203
|
+
this.sessionWelcome.setTransitioning(false);
|
|
166204
|
+
return;
|
|
166205
|
+
}
|
|
166206
|
+
if (phase === "transition" && !immediate) return;
|
|
166207
|
+
if (this.fullscreenWelcomeTransitionTimer) {
|
|
166208
|
+
clearTimeout(this.fullscreenWelcomeTransitionTimer);
|
|
166209
|
+
this.fullscreenWelcomeTransitionTimer = void 0;
|
|
166210
|
+
}
|
|
166211
|
+
if (immediate || !this.animateTurnTimer) {
|
|
166212
|
+
this.fullscreenWelcomeVisible = false;
|
|
166213
|
+
this.sessionWelcome.setTransitioning(false);
|
|
166214
|
+
this.fullscreenHeader.setPhase("rail");
|
|
166215
|
+
this.ui.requestRender(true);
|
|
166216
|
+
return;
|
|
166217
|
+
}
|
|
166218
|
+
this.sessionWelcome.setTransitioning(true);
|
|
166219
|
+
this.fullscreenHeader.setPhase("transition");
|
|
166220
|
+
this.ui.requestRender();
|
|
166221
|
+
this.fullscreenWelcomeTransitionTimer = setTimeout(() => {
|
|
166222
|
+
this.fullscreenWelcomeTransitionTimer = void 0;
|
|
166223
|
+
if (this.stopped || this.tuiMode !== "fullscreen") return;
|
|
166224
|
+
this.fullscreenWelcomeVisible = false;
|
|
166225
|
+
this.sessionWelcome.setTransitioning(false);
|
|
166226
|
+
this.fullscreenHeader.setPhase("rail");
|
|
166227
|
+
this.ui.requestRender();
|
|
166228
|
+
}, fullscreenWelcomeTransitionMs);
|
|
166229
|
+
this.fullscreenWelcomeTransitionTimer.unref?.();
|
|
166230
|
+
}
|
|
166231
|
+
resetSessionPresentation() {
|
|
166232
|
+
if (this.fullscreenWelcomeTransitionTimer) {
|
|
166233
|
+
clearTimeout(this.fullscreenWelcomeTransitionTimer);
|
|
166234
|
+
this.fullscreenWelcomeTransitionTimer = void 0;
|
|
166235
|
+
}
|
|
166236
|
+
this.sessionHasContent = false;
|
|
166237
|
+
this.fullscreenWelcomeVisible = true;
|
|
166238
|
+
this.fullscreenHeader.setPhase("welcome");
|
|
166239
|
+
this.sessionWelcome.setTransitioning(false);
|
|
166240
|
+
if (this.tuiMode === "regular") this.mountRegularSessionWelcome();
|
|
166241
|
+
this.ui.requestRender();
|
|
166242
|
+
}
|
|
166243
|
+
mountRegularSessionWelcome() {
|
|
166244
|
+
this.headerHost.clear();
|
|
166245
|
+
this.sessionWelcome.setIncludeIdentity(true);
|
|
166246
|
+
this.headerHost.addChild(this.sessionWelcome);
|
|
166247
|
+
this.headerHost.addChild(new Spacer(1));
|
|
166248
|
+
}
|
|
166249
|
+
addTranscriptBlock(component, options = {}) {
|
|
166250
|
+
this.enterSessionRail();
|
|
166251
|
+
return this.transcript.addBlock(component, options);
|
|
166252
|
+
}
|
|
166253
|
+
mountLayout() {
|
|
166254
|
+
if (isViewportTUI(this.ui)) {
|
|
166255
|
+
this.fullscreenTranscript ??= new ScrollView(this.transcriptHost, {
|
|
166256
|
+
follow: "end",
|
|
166257
|
+
primary: true,
|
|
166258
|
+
overscroll: "chain",
|
|
166259
|
+
scrollbar: "always"
|
|
166260
|
+
});
|
|
166261
|
+
this.fullscreenLayout ??= new VStack([
|
|
166262
|
+
{
|
|
166263
|
+
component: this.fullscreenHeader,
|
|
166264
|
+
basis: 1,
|
|
166265
|
+
shrink: 0,
|
|
166266
|
+
minSize: 1
|
|
166267
|
+
},
|
|
166268
|
+
{
|
|
166269
|
+
component: this.fullscreenTranscript,
|
|
166270
|
+
basis: 0,
|
|
166271
|
+
grow: 1,
|
|
166272
|
+
minSize: 1
|
|
166273
|
+
},
|
|
166274
|
+
{
|
|
166275
|
+
component: this.composerHost,
|
|
166276
|
+
basis: "auto",
|
|
166277
|
+
shrink: 1,
|
|
166278
|
+
minSize: 1
|
|
166279
|
+
}
|
|
166280
|
+
]);
|
|
166281
|
+
this.ui.setLayoutRoot(this.fullscreenLayout);
|
|
166282
|
+
return;
|
|
166283
|
+
}
|
|
166284
|
+
this.ui.clear();
|
|
166285
|
+
this.ui.addChild(this.headerHost);
|
|
166286
|
+
this.ui.addChild(this.transcriptHost);
|
|
165613
166287
|
this.ui.addChild(this.composerHost);
|
|
166288
|
+
}
|
|
166289
|
+
createEditor(tui) {
|
|
166290
|
+
const editor = new Editor(tui, this.theme.editor, {
|
|
166291
|
+
paddingX: 1,
|
|
166292
|
+
autocompleteMaxVisible: 7
|
|
166293
|
+
});
|
|
166294
|
+
for (const input of [...this.editorHistory].reverse()) editor.addToHistory(input);
|
|
165614
166295
|
const commands = this.autocompleteCommands();
|
|
165615
166296
|
const workspaceDirectory = this.options.workspaceDirectory ?? process.cwd();
|
|
165616
|
-
|
|
165617
|
-
|
|
166297
|
+
editor.setAutocompleteProvider(new WorkspaceAutocompleteProvider(commands, workspaceDirectory, this.options.listWorkspacePathSuggestions, this.skillCatalog, this.options.listPluginReferences ?? createRuntimePluginReferenceLister(workspaceDirectory)));
|
|
166298
|
+
editor.onSubmit = (text) => void this.submit(text);
|
|
166299
|
+
return editor;
|
|
166300
|
+
}
|
|
166301
|
+
focusEditor() {
|
|
166302
|
+
this.ui.setFocus(this.editor);
|
|
166303
|
+
}
|
|
166304
|
+
rememberEditorHistory(input) {
|
|
166305
|
+
const trimmed = input.trim();
|
|
166306
|
+
if (!trimmed || this.editorHistory[0] === trimmed) return;
|
|
166307
|
+
this.editorHistory.unshift(trimmed);
|
|
166308
|
+
if (this.editorHistory.length > 100) this.editorHistory.pop();
|
|
166309
|
+
}
|
|
166310
|
+
async switchTuiMode(next) {
|
|
166311
|
+
if (this.settingSwitchInFlight) return;
|
|
166312
|
+
if (next === this.tuiMode) return;
|
|
166313
|
+
if (this.activeSubmissions > 0 || this.turnAbortController) {
|
|
166314
|
+
this.addNotice("Wait for the active turn before switching display mode.", "warning");
|
|
166315
|
+
return;
|
|
166316
|
+
}
|
|
166317
|
+
this.settingSwitchInFlight = true;
|
|
166318
|
+
const savedDraft = this.editor.getText();
|
|
166319
|
+
const hadSessionContent = this.sessionHasContent || this.transcript.blockCount > 0;
|
|
166320
|
+
const previousUi = this.ui;
|
|
166321
|
+
const previousMode = this.tuiMode;
|
|
166322
|
+
let previousStopped = false;
|
|
166323
|
+
try {
|
|
166324
|
+
this.notifications.stop();
|
|
166325
|
+
previousStopped = true;
|
|
166326
|
+
this.ui.stop({ preserveScreen: true });
|
|
166327
|
+
this.ui = this.createTui(next);
|
|
166328
|
+
this.tuiMode = next;
|
|
166329
|
+
this.sessionHasContent = hadSessionContent;
|
|
166330
|
+
this.fullscreenWelcomeVisible = !hadSessionContent;
|
|
166331
|
+
this.fullscreenHeader.setPhase(hadSessionContent ? "rail" : "welcome");
|
|
166332
|
+
this.editor = this.createEditor(this.ui);
|
|
166333
|
+
this.fullscreenTranscript = void 0;
|
|
166334
|
+
this.fullscreenLayout = void 0;
|
|
166335
|
+
this.buildLayout();
|
|
166336
|
+
this.ui.start();
|
|
166337
|
+
this.bindInput();
|
|
166338
|
+
this.focusEditor();
|
|
166339
|
+
if (savedDraft) this.editor.setText(savedDraft);
|
|
166340
|
+
this.ui.requestRender(true);
|
|
166341
|
+
this.notifications.start();
|
|
166342
|
+
try {
|
|
166343
|
+
await writeTuiMode(next);
|
|
166344
|
+
} catch (error) {
|
|
166345
|
+
this.addNotice(error instanceof Error ? error.message : String(error), "error");
|
|
166346
|
+
}
|
|
166347
|
+
} catch (error) {
|
|
166348
|
+
if (this.ui !== previousUi || previousStopped) {
|
|
166349
|
+
if (this.ui !== previousUi) try {
|
|
166350
|
+
this.ui.stop({ preserveScreen: true });
|
|
166351
|
+
} catch {}
|
|
166352
|
+
this.ui = previousUi;
|
|
166353
|
+
this.tuiMode = previousMode;
|
|
166354
|
+
this.sessionHasContent = hadSessionContent;
|
|
166355
|
+
this.fullscreenWelcomeVisible = previousMode === "fullscreen" ? !hadSessionContent : true;
|
|
166356
|
+
this.fullscreenHeader.setPhase(hadSessionContent ? "rail" : "welcome");
|
|
166357
|
+
this.fullscreenTranscript = void 0;
|
|
166358
|
+
this.fullscreenLayout = void 0;
|
|
166359
|
+
this.editor = this.createEditor(this.ui);
|
|
166360
|
+
if (savedDraft) this.editor.setText(savedDraft);
|
|
166361
|
+
this.buildLayout();
|
|
166362
|
+
try {
|
|
166363
|
+
this.ui.start();
|
|
166364
|
+
this.bindInput();
|
|
166365
|
+
this.focusEditor();
|
|
166366
|
+
this.notifications.start();
|
|
166367
|
+
this.ui.requestRender(true);
|
|
166368
|
+
} catch {}
|
|
166369
|
+
}
|
|
166370
|
+
this.addNotice(`Display mode switch failed: ${error instanceof Error ? error.message : String(error)}`, "error");
|
|
166371
|
+
} finally {
|
|
166372
|
+
this.settingSwitchInFlight = false;
|
|
166373
|
+
}
|
|
165618
166374
|
}
|
|
165619
166375
|
updateLoginWarning() {
|
|
165620
|
-
|
|
165621
|
-
this.loginWarning.setText(this.loginRequired ? this.theme.warning("Model access is not configured.") : "");
|
|
165622
|
-
this.loginHelp.setText(this.loginRequired ? this.theme.warning(`Run /login, or configure a custom provider in ${configPath}.`) : "");
|
|
166376
|
+
this.sessionWelcome.setLoginRequired(this.loginRequired);
|
|
165623
166377
|
}
|
|
165624
166378
|
setLoginRequired(required) {
|
|
165625
166379
|
const changed = this.loginRequired !== required;
|
|
165626
166380
|
this.loginRequired = required;
|
|
165627
166381
|
this.updateLoginWarning();
|
|
166382
|
+
this.ui.requestRender();
|
|
165628
166383
|
if (changed && !required) {
|
|
165629
166384
|
this.refreshGoal();
|
|
165630
166385
|
this.refreshSessionUsage();
|
|
@@ -165690,10 +166445,12 @@ var ZCodeTui = class {
|
|
|
165690
166445
|
} catch (error) {
|
|
165691
166446
|
failure = error instanceof Error ? error.message : String(error);
|
|
165692
166447
|
} finally {
|
|
165693
|
-
this.
|
|
165694
|
-
|
|
165695
|
-
|
|
165696
|
-
|
|
166448
|
+
if (!this.stopped) {
|
|
166449
|
+
this.ui.start();
|
|
166450
|
+
this.notifications.start();
|
|
166451
|
+
this.focusEditor();
|
|
166452
|
+
this.ui.requestRender(true);
|
|
166453
|
+
}
|
|
165697
166454
|
}
|
|
165698
166455
|
const access = code === 0 ? await readConfiguredModelAccess() : null;
|
|
165699
166456
|
if (access) {
|
|
@@ -165728,7 +166485,7 @@ var ZCodeTui = class {
|
|
|
165728
166485
|
},
|
|
165729
166486
|
{
|
|
165730
166487
|
name: "copy",
|
|
165731
|
-
description: "Copy the latest assistant response"
|
|
166488
|
+
description: "Copy the active fullscreen selection or latest assistant response"
|
|
165732
166489
|
},
|
|
165733
166490
|
{
|
|
165734
166491
|
name: "paste-image",
|
|
@@ -165796,6 +166553,13 @@ var ZCodeTui = class {
|
|
|
165796
166553
|
this.clearRewindEscape();
|
|
165797
166554
|
this.recentSteerCommit = void 0;
|
|
165798
166555
|
}
|
|
166556
|
+
const focusedComponent = this.ui.getFocusedComponent?.();
|
|
166557
|
+
if (this.tuiMode === "fullscreen" && this.fullscreenTranscript && focusedComponent === this.editor && !this.editor.getText() && (matchesKey(data, "pageUp") || matchesKey(data, "pageDown"))) {
|
|
166558
|
+
if (matchesKey(data, "pageUp")) this.fullscreenTranscript.scrollBy(-Math.max(1, this.fullscreenTranscript.viewportHeight - 4));
|
|
166559
|
+
else this.fullscreenTranscript.scrollBy(Math.max(1, this.fullscreenTranscript.viewportHeight - 4));
|
|
166560
|
+
this.ui.requestRender();
|
|
166561
|
+
return { consume: true };
|
|
166562
|
+
}
|
|
165799
166563
|
if (matchesKey(data, "up") && this.canEnterAttachmentSelection()) {
|
|
165800
166564
|
this.enterAttachmentSelection();
|
|
165801
166565
|
return { consume: true };
|
|
@@ -165885,6 +166649,14 @@ var ZCodeTui = class {
|
|
|
165885
166649
|
this.clearRewindEscape();
|
|
165886
166650
|
return { consume: true };
|
|
165887
166651
|
}
|
|
166652
|
+
if (this.transcript.searchStatus() || this.transcript.cursorStatus()) {
|
|
166653
|
+
this.clearRewindEscape();
|
|
166654
|
+
this.transcript.clearSearch();
|
|
166655
|
+
this.transcript.clearCursor();
|
|
166656
|
+
this.updateMetadata();
|
|
166657
|
+
this.ui.requestRender(true);
|
|
166658
|
+
return { consume: true };
|
|
166659
|
+
}
|
|
165888
166660
|
if (this.turnAbortController) {
|
|
165889
166661
|
this.clearRewindEscape();
|
|
165890
166662
|
const pendingSteer = this.inputQueue.hasPendingSteers();
|
|
@@ -165896,14 +166668,6 @@ var ZCodeTui = class {
|
|
|
165896
166668
|
else this.requestForegroundTurnInterrupt();
|
|
165897
166669
|
return { consume: true };
|
|
165898
166670
|
}
|
|
165899
|
-
if (this.transcript.searchStatus() || this.transcript.cursorStatus()) {
|
|
165900
|
-
this.clearRewindEscape();
|
|
165901
|
-
this.transcript.clearSearch();
|
|
165902
|
-
this.transcript.clearCursor();
|
|
165903
|
-
this.updateMetadata();
|
|
165904
|
-
this.ui.requestRender(true);
|
|
165905
|
-
return { consume: true };
|
|
165906
|
-
}
|
|
165907
166671
|
if (!this.editor.getText() && this.activeSubmissions === 0) {
|
|
165908
166672
|
this.handleRewindEscape();
|
|
165909
166673
|
return { consume: true };
|
|
@@ -165913,9 +166677,12 @@ var ZCodeTui = class {
|
|
|
165913
166677
|
}
|
|
165914
166678
|
async submit(rawInput, queuedSubmission) {
|
|
165915
166679
|
const input = (queuedSubmission?.input ?? rawInput).trim();
|
|
165916
|
-
if (!input || this.stopped) return;
|
|
166680
|
+
if (!input || this.stopped) return false;
|
|
165917
166681
|
const submission = queuedSubmission ?? protectSubmission(input);
|
|
165918
|
-
if (submission.recordHistory)
|
|
166682
|
+
if (submission.recordHistory) {
|
|
166683
|
+
this.rememberEditorHistory(input);
|
|
166684
|
+
this.editor.addToHistory(input);
|
|
166685
|
+
}
|
|
165919
166686
|
if (input === "/exit" || input === "/quit") {
|
|
165920
166687
|
this.stop();
|
|
165921
166688
|
return;
|
|
@@ -165935,7 +166702,7 @@ var ZCodeTui = class {
|
|
|
165935
166702
|
return;
|
|
165936
166703
|
}
|
|
165937
166704
|
if (input === "/copy") {
|
|
165938
|
-
await this.
|
|
166705
|
+
await this.copySelectionOrLastResponse();
|
|
165939
166706
|
return;
|
|
165940
166707
|
}
|
|
165941
166708
|
if (input === "/paste-image") {
|
|
@@ -166023,7 +166790,7 @@ var ZCodeTui = class {
|
|
|
166023
166790
|
...submission,
|
|
166024
166791
|
recordHistory: false
|
|
166025
166792
|
});
|
|
166026
|
-
return;
|
|
166793
|
+
return true;
|
|
166027
166794
|
}
|
|
166028
166795
|
if (!steering && this.backgroundTaskEvents.hasActiveHandoffs()) {
|
|
166029
166796
|
this.inputQueue.queueFollowUp({
|
|
@@ -166031,7 +166798,7 @@ var ZCodeTui = class {
|
|
|
166031
166798
|
recordHistory: false
|
|
166032
166799
|
});
|
|
166033
166800
|
this.interruptBackgroundHandoffForInput();
|
|
166034
|
-
return;
|
|
166801
|
+
return true;
|
|
166035
166802
|
}
|
|
166036
166803
|
if (!steering && !input.startsWith("/") && !this.sessionTitleEmitted) {
|
|
166037
166804
|
const sessionTitle = sessionTitleFromFirstMessage(submission.displayInput);
|
|
@@ -166047,7 +166814,7 @@ var ZCodeTui = class {
|
|
|
166047
166814
|
...submission,
|
|
166048
166815
|
recordHistory: false
|
|
166049
166816
|
});
|
|
166050
|
-
return;
|
|
166817
|
+
return true;
|
|
166051
166818
|
}
|
|
166052
166819
|
const attachments = !steering && !input.startsWith("/") ? [...this.pendingAttachments] : [];
|
|
166053
166820
|
if (steering && !this.options.sendInput) {
|
|
@@ -166055,7 +166822,7 @@ var ZCodeTui = class {
|
|
|
166055
166822
|
...submission,
|
|
166056
166823
|
recordHistory: false
|
|
166057
166824
|
});
|
|
166058
|
-
return;
|
|
166825
|
+
return true;
|
|
166059
166826
|
}
|
|
166060
166827
|
if (attachments.length > 0) this.clearPendingAttachments(false);
|
|
166061
166828
|
const abortController = new AbortController();
|
|
@@ -166064,6 +166831,7 @@ var ZCodeTui = class {
|
|
|
166064
166831
|
const callOptions = {
|
|
166065
166832
|
abortSignal: abortController.signal,
|
|
166066
166833
|
delivery: steering ? "steer_active_turn" : "start_turn",
|
|
166834
|
+
queueDelivery: steering ? "guide" : void 0,
|
|
166067
166835
|
expectedTurnId: steering ? this.activeTurnId : void 0,
|
|
166068
166836
|
inputId,
|
|
166069
166837
|
pendingInputReservationId: queuedSubmission?.pendingInputReservationId,
|
|
@@ -166095,7 +166863,7 @@ var ZCodeTui = class {
|
|
|
166095
166863
|
this.activeSubmissions += 1;
|
|
166096
166864
|
} else this.steerAbortControllers.add(abortController);
|
|
166097
166865
|
if (!steering || submission.status) this.updateActivity(submission.status ?? "working…");
|
|
166098
|
-
const notificationEligible = !steering && !input.startsWith("/");
|
|
166866
|
+
const notificationEligible = !steering && !input.startsWith("/") && queuedSubmission?.suppressCompletionNotification !== true;
|
|
166099
166867
|
if (notificationEligible) this.pendingTurnNotification = "completed";
|
|
166100
166868
|
let accepted = false;
|
|
166101
166869
|
let unfinishedToolState = "interrupted";
|
|
@@ -166108,9 +166876,9 @@ var ZCodeTui = class {
|
|
|
166108
166876
|
} else {
|
|
166109
166877
|
const preparedInput = promptInput(runtimeInput, attachments);
|
|
166110
166878
|
const outcome = queuedSubmission?.pendingInputIds?.length && this.options.promoteQueuedInput ? await this.options.promoteQueuedInput(preparedInput, queuedSubmission.pendingInputIds, callOptions) : await this.options.sendInput(preparedInput, callOptions);
|
|
166111
|
-
if (steering && this.activeTurnEpoch !== turnEpoch) return;
|
|
166879
|
+
if (steering && this.activeTurnEpoch !== turnEpoch) return false;
|
|
166112
166880
|
const disposition = await this.handleSendOutcome(outcome);
|
|
166113
|
-
if (steering && this.activeTurnEpoch !== turnEpoch) return;
|
|
166881
|
+
if (steering && this.activeTurnEpoch !== turnEpoch) return false;
|
|
166114
166882
|
if (steering && disposition.targetTurnId) this.activeTurnId = disposition.targetTurnId;
|
|
166115
166883
|
if (pendingSteer && disposition.pendingInputId) this.inputQueue.associateSteer(pendingSteer.inputId, disposition.pendingInputId, disposition.targetTurnId);
|
|
166116
166884
|
accepted = disposition.accepted;
|
|
@@ -166169,6 +166937,7 @@ var ZCodeTui = class {
|
|
|
166169
166937
|
this.refreshSessionUsage();
|
|
166170
166938
|
}
|
|
166171
166939
|
if (nextCommand) await this.submit(nextCommand.input, nextCommand);
|
|
166940
|
+
return accepted;
|
|
166172
166941
|
}
|
|
166173
166942
|
finishPrimaryTurnSubmission(turnEpoch, abortController, unfinishedToolState) {
|
|
166174
166943
|
this.activeSubmissions = Math.max(0, this.activeSubmissions - 1);
|
|
@@ -166224,9 +166993,9 @@ var ZCodeTui = class {
|
|
|
166224
166993
|
pendingInputIds: this.inputQueue.admittedPendingInputIds(),
|
|
166225
166994
|
reason: "TUI interrupted the active model step to submit steer instructions.",
|
|
166226
166995
|
reservationId: request.reservationId
|
|
166227
|
-
}).then((
|
|
166996
|
+
}).then(() => {
|
|
166228
166997
|
if (!this.isPendingSteerInterrupt(turnEpoch, abortController)) return;
|
|
166229
|
-
|
|
166998
|
+
abortController.abort();
|
|
166230
166999
|
}).catch(() => {
|
|
166231
167000
|
if (this.isPendingSteerInterrupt(turnEpoch, abortController)) abortController.abort();
|
|
166232
167001
|
});
|
|
@@ -166238,18 +167007,64 @@ var ZCodeTui = class {
|
|
|
166238
167007
|
this.pendingSteerInterrupt = void 0;
|
|
166239
167008
|
this.foregroundTurnInterrupt = abortController;
|
|
166240
167009
|
this.updateActivity("cancelling…");
|
|
167010
|
+
this.cancelActiveBackgroundAgentTasks();
|
|
166241
167011
|
const interruptTurn = this.options.interruptTurn;
|
|
166242
167012
|
if (!interruptTurn) {
|
|
166243
167013
|
abortController.abort();
|
|
166244
167014
|
return;
|
|
166245
167015
|
}
|
|
166246
|
-
interruptTurn({ reason: "TUI interrupted the active foreground turn." }).then((
|
|
167016
|
+
interruptTurn({ reason: "TUI interrupted the active foreground turn." }).then(() => {
|
|
166247
167017
|
if (this.turnAbortController !== abortController || abortController.signal.aborted) return;
|
|
166248
|
-
|
|
167018
|
+
abortController.abort();
|
|
166249
167019
|
}).catch(() => {
|
|
166250
167020
|
if (this.turnAbortController === abortController && !abortController.signal.aborted) abortController.abort();
|
|
166251
167021
|
});
|
|
166252
167022
|
}
|
|
167023
|
+
/**
|
|
167024
|
+
* Backgrounded agents owned by the interrupted turn are detached from its
|
|
167025
|
+
* abort signal, so cancel those explicitly. Older agents and non-agent tasks
|
|
167026
|
+
* remain independent and continue running.
|
|
167027
|
+
*/
|
|
167028
|
+
cancelActiveBackgroundAgentTasks() {
|
|
167029
|
+
const cancelBackgroundTask = this.options.cancelBackgroundTask;
|
|
167030
|
+
if (!cancelBackgroundTask) return;
|
|
167031
|
+
const jobs = this.runtimeProjection?.backgroundJobs ?? [];
|
|
167032
|
+
const active = jobs.filter((job) => isActiveBackgroundJob(job) && job.taskKind === "local_agent" && job.cancellable !== false && (this.turnWork.ownsTask(job.taskId) || Boolean(this.activeTurnId && job.turnId === this.activeTurnId)));
|
|
167033
|
+
const activeIds = new Set(active.map((job) => job.taskId));
|
|
167034
|
+
const surviving = jobs.filter((job) => isActiveBackgroundJob(job) && !activeIds.has(job.taskId));
|
|
167035
|
+
if (active.length === 0 && surviving.length === 0) return;
|
|
167036
|
+
(async () => {
|
|
167037
|
+
const stopped = [];
|
|
167038
|
+
const failed = [];
|
|
167039
|
+
for (const job of active) try {
|
|
167040
|
+
const failure = backgroundCancellationFailure(await cancelBackgroundTask(job.taskId));
|
|
167041
|
+
if (failure) {
|
|
167042
|
+
failed.push({
|
|
167043
|
+
detail: failure,
|
|
167044
|
+
taskId: job.taskId
|
|
167045
|
+
});
|
|
167046
|
+
this.backgroundTaskEvents.recordSystemMessage(job.taskId, `Task was not cancelled: ${failure}.`, true);
|
|
167047
|
+
continue;
|
|
167048
|
+
}
|
|
167049
|
+
stopped.push(job.taskId);
|
|
167050
|
+
this.backgroundTaskEvents.recordSystemMessage(job.taskId, "Task cancelled by Esc interrupt.");
|
|
167051
|
+
} catch (error) {
|
|
167052
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
167053
|
+
failed.push({
|
|
167054
|
+
detail,
|
|
167055
|
+
taskId: job.taskId
|
|
167056
|
+
});
|
|
167057
|
+
this.backgroundTaskEvents.recordSystemMessage(job.taskId, detail, true);
|
|
167058
|
+
}
|
|
167059
|
+
if (stopped.length > 0) this.addNotice(`Esc also stopped background task${stopped.length > 1 ? "s" : ""}: ${stopped.join(", ")}.`, "muted");
|
|
167060
|
+
for (const failure of failed) this.addNotice(`Esc could not stop background task ${failure.taskId}: ${failure.detail}.`, "warning");
|
|
167061
|
+
if (surviving.length > 0) {
|
|
167062
|
+
const ids = surviving.map((job) => job.taskId).join(", ");
|
|
167063
|
+
this.addNotice(`Background task${surviving.length > 1 ? "s" : ""} ${ids} keep${surviving.length > 1 ? "" : "s"} running — /tasks stop <task-id> to stop.`, "muted");
|
|
167064
|
+
}
|
|
167065
|
+
if (active.length > 0) await this.refreshRuntimeState();
|
|
167066
|
+
})();
|
|
167067
|
+
}
|
|
166253
167068
|
isPendingSteerInterrupt(turnEpoch, abortController) {
|
|
166254
167069
|
const pending = this.pendingSteerInterrupt;
|
|
166255
167070
|
return pending?.turnEpoch === turnEpoch && pending.abortController === abortController;
|
|
@@ -166293,6 +167108,7 @@ var ZCodeTui = class {
|
|
|
166293
167108
|
emitSessionTerminalTitle(this.options.stdout ?? process.stdout, "");
|
|
166294
167109
|
this.sessionMetrics = {};
|
|
166295
167110
|
this.restoreTranscript(restoredMessages(result.restoredMessages));
|
|
167111
|
+
if (this.transcript.blockCount > 0) this.enterSessionRail(true);
|
|
166296
167112
|
}
|
|
166297
167113
|
const response = responseText(result);
|
|
166298
167114
|
if (renderResponse && response) {
|
|
@@ -166360,25 +167176,18 @@ var ZCodeTui = class {
|
|
|
166360
167176
|
this.completeThinking();
|
|
166361
167177
|
this.assistantStream.breakSegment();
|
|
166362
167178
|
}
|
|
166363
|
-
if (event.kind === "text_start")
|
|
167179
|
+
if (event.kind === "text_start") this.currentToolGroup = void 0;
|
|
167180
|
+
else if (event.kind === "text_delta" && event.delta) {
|
|
166364
167181
|
this.currentToolGroup = void 0;
|
|
166365
|
-
this.
|
|
166366
|
-
|
|
166367
|
-
} else if (event.kind === "text_delta" && event.delta) {
|
|
166368
|
-
this.currentToolGroup = void 0;
|
|
166369
|
-
this.completeThinking();
|
|
166370
|
-
this.recordAssistantText(this.assistantStream.append(event.delta, event.partId, event.messageId));
|
|
166371
|
-
} else if (event.kind === "text_end") this.assistantStream.breakSegment();
|
|
166372
|
-
else if (event.kind === "reasoning_start") {
|
|
167182
|
+
this.recordAssistantText(this.assistantStream.append(event.delta, void 0, event.messageId));
|
|
167183
|
+
} else if (event.kind === "text_end") {} else if (event.kind === "reasoning_start") {
|
|
166373
167184
|
this.currentToolGroup = void 0;
|
|
166374
|
-
this.assistantStream.breakSegment();
|
|
166375
167185
|
this.updateActivity("thinking…", false);
|
|
166376
167186
|
} else if (event.kind === "reasoning_delta") {
|
|
166377
167187
|
this.currentToolGroup = void 0;
|
|
166378
|
-
this.assistantStream.breakSegment();
|
|
166379
167188
|
this.updateActivity("thinking…", false);
|
|
166380
|
-
if (event.delta && (this.currentThinking || event.delta.trim())) this.appendThinking(event.delta,
|
|
166381
|
-
} else if (event.kind === "reasoning_end") this.
|
|
167189
|
+
if (event.delta && (this.currentThinking || event.delta.trim())) this.appendThinking(event.delta, void 0, event.messageId);
|
|
167190
|
+
} else if (event.kind === "reasoning_end") this.settleThinking();
|
|
166382
167191
|
else if (event.kind === "tool_input_start") {
|
|
166383
167192
|
const tool = this.ensureToolView(event.toolCallId, event.toolName, event.partId, event.messageId);
|
|
166384
167193
|
tool.input = void 0;
|
|
@@ -166405,10 +167214,11 @@ var ZCodeTui = class {
|
|
|
166405
167214
|
this.updateToolView(tool, "running", event.result, void 0, event.progress);
|
|
166406
167215
|
} else if (event.kind === "result") {
|
|
166407
167216
|
const tool = this.ensureToolView(event.toolCallId, event.toolName, event.partId, event.messageId);
|
|
166408
|
-
|
|
167217
|
+
const cancelled = isToolCancellation(event.result);
|
|
167218
|
+
this.updateToolView(tool, cancelled ? "cancelled" : toolSucceeded(event.result) ? "complete" : "failed", event.result, void 0, event.progress);
|
|
166409
167219
|
} else if (event.kind === "error" && (event.toolCallId || event.toolName)) {
|
|
166410
167220
|
const tool = this.ensureToolView(event.toolCallId, event.toolName, event.partId, event.messageId);
|
|
166411
|
-
this.updateToolView(tool, "failed", event.result, event.error, event.progress);
|
|
167221
|
+
this.updateToolView(tool, isToolCancellation(event.error ?? event.result) ? "cancelled" : "failed", event.result, event.error, event.progress);
|
|
166412
167222
|
} else if (event.kind === "closed" && (event.toolCallId || event.toolName)) {
|
|
166413
167223
|
const tool = this.ensureToolView(event.toolCallId, event.toolName, event.partId, event.messageId);
|
|
166414
167224
|
if (!tool.view.isTerminal()) this.updateToolView(tool, "complete", event.result, event.error, event.progress);
|
|
@@ -166633,7 +167443,7 @@ var ZCodeTui = class {
|
|
|
166633
167443
|
display: part.resultDisplay
|
|
166634
167444
|
} : part.output;
|
|
166635
167445
|
if (part.output !== void 0 || part.resultDisplay !== void 0) tool.outputText = void 0;
|
|
166636
|
-
this.updateToolView(tool, restoredToolState(part.status), result, part.error, {
|
|
167446
|
+
this.updateToolView(tool, isToolCancellation(part.error ?? result) ? "cancelled" : restoredToolState(part.status), result, part.error, {
|
|
166637
167447
|
parentToolCallId: part.parentToolCallId,
|
|
166638
167448
|
childToolCallId: part.childToolCallId,
|
|
166639
167449
|
agentId: part.agentId,
|
|
@@ -166744,6 +167554,7 @@ var ZCodeTui = class {
|
|
|
166744
167554
|
}
|
|
166745
167555
|
clearTranscriptProjection() {
|
|
166746
167556
|
this.transcript.clear();
|
|
167557
|
+
this.resetSessionPresentation();
|
|
166747
167558
|
this.assistantStream.clear();
|
|
166748
167559
|
this.currentThinking = void 0;
|
|
166749
167560
|
this.currentThinkingPartId = void 0;
|
|
@@ -166755,6 +167566,7 @@ var ZCodeTui = class {
|
|
|
166755
167566
|
this.currentToolGroupMessageId = void 0;
|
|
166756
167567
|
}
|
|
166757
167568
|
appendThinking(delta, partId, messageId) {
|
|
167569
|
+
if (delta.trim()) this.enterSessionRail();
|
|
166758
167570
|
if (partId) {
|
|
166759
167571
|
let view = this.thinkingParts.get(partId);
|
|
166760
167572
|
if (!view) {
|
|
@@ -166780,10 +167592,15 @@ var ZCodeTui = class {
|
|
|
166780
167592
|
}
|
|
166781
167593
|
this.currentThinking.append(delta);
|
|
166782
167594
|
}
|
|
166783
|
-
|
|
167595
|
+
settleThinking(partId) {
|
|
166784
167596
|
const thinking = partId ? this.thinkingParts.get(partId) : this.currentThinking;
|
|
166785
|
-
if (!thinking) return;
|
|
167597
|
+
if (!thinking) return void 0;
|
|
166786
167598
|
thinking.complete();
|
|
167599
|
+
return thinking;
|
|
167600
|
+
}
|
|
167601
|
+
completeThinking(partId) {
|
|
167602
|
+
const thinking = this.settleThinking(partId);
|
|
167603
|
+
if (!thinking) return;
|
|
166787
167604
|
if (this.currentThinking === thinking) {
|
|
166788
167605
|
this.currentThinking = void 0;
|
|
166789
167606
|
this.currentThinkingPartId = void 0;
|
|
@@ -166791,6 +167608,7 @@ var ZCodeTui = class {
|
|
|
166791
167608
|
}
|
|
166792
167609
|
addUserMessage(text, attachmentCount = 0, messageId) {
|
|
166793
167610
|
const safeText = sanitizeTerminalText(text, { preserveSgr: false });
|
|
167611
|
+
this.enterSessionRail();
|
|
166794
167612
|
const suffix = attachmentCount > 0 ? ` [${attachmentCount} image${attachmentCount === 1 ? "" : "s"}]` : "";
|
|
166795
167613
|
this.currentToolGroup = void 0;
|
|
166796
167614
|
this.transcript.addBlock(new Text(`${this.theme.accent("›")} ${safeText}${this.theme.muted(suffix)}`, 1, 0), {
|
|
@@ -166801,6 +167619,7 @@ var ZCodeTui = class {
|
|
|
166801
167619
|
this.ui.requestRender();
|
|
166802
167620
|
}
|
|
166803
167621
|
addAssistantMessage(text, partId, messageId) {
|
|
167622
|
+
this.enterSessionRail();
|
|
166804
167623
|
this.currentToolGroup = void 0;
|
|
166805
167624
|
this.transcript.addBlock(new RichMarkdown(text, 1, this.theme), {
|
|
166806
167625
|
id: partId,
|
|
@@ -166859,6 +167678,7 @@ var ZCodeTui = class {
|
|
|
166859
167678
|
});
|
|
166860
167679
|
}
|
|
166861
167680
|
ensureToolView(toolCallId, toolName, partId, messageId) {
|
|
167681
|
+
this.enterSessionRail();
|
|
166862
167682
|
const anonymous = !toolCallId ? Array.from(this.toolViews.values()).findLast((tool) => tool.name === (toolName ?? "tool") && !tool.view.isTerminal()) : void 0;
|
|
166863
167683
|
if (anonymous) {
|
|
166864
167684
|
if (partId) {
|
|
@@ -167215,7 +168035,7 @@ var ZCodeTui = class {
|
|
|
167215
168035
|
const submission = this.inputQueue.editLatestFollowUp();
|
|
167216
168036
|
if (!submission) return;
|
|
167217
168037
|
this.editor.setText(submission.input);
|
|
167218
|
-
this.
|
|
168038
|
+
this.focusEditor();
|
|
167219
168039
|
}
|
|
167220
168040
|
async attachClipboardImage() {
|
|
167221
168041
|
if (!this.options.readClipboardImage) {
|
|
@@ -167260,7 +168080,7 @@ var ZCodeTui = class {
|
|
|
167260
168080
|
}
|
|
167261
168081
|
leaveAttachmentSelection() {
|
|
167262
168082
|
this.attachmentBar.deactivate();
|
|
167263
|
-
this.
|
|
168083
|
+
this.focusEditor();
|
|
167264
168084
|
this.ui.requestRender();
|
|
167265
168085
|
}
|
|
167266
168086
|
removePendingAttachment(index) {
|
|
@@ -167276,7 +168096,7 @@ var ZCodeTui = class {
|
|
|
167276
168096
|
syncAttachmentBar() {
|
|
167277
168097
|
const wasActive = this.attachmentBar.isActive();
|
|
167278
168098
|
this.attachmentBar.setAttachments(this.pendingAttachments);
|
|
167279
|
-
if (wasActive && !this.attachmentBar.isActive()) this.
|
|
168099
|
+
if (wasActive && !this.attachmentBar.isActive()) this.focusEditor();
|
|
167280
168100
|
this.ui.requestRender();
|
|
167281
168101
|
}
|
|
167282
168102
|
async requestPermission(requestValue, context) {
|
|
@@ -167840,6 +168660,7 @@ var ZCodeTui = class {
|
|
|
167840
168660
|
const backend = notificationDeliveryLabel(effective.method, diagnostics.backend);
|
|
167841
168661
|
const methodOverride = Boolean(process.env.ZCODE_TUI_NOTIFICATION_METHOD?.trim());
|
|
167842
168662
|
const conditionOverride = Boolean(process.env.ZCODE_TUI_NOTIFICATION_CONDITION?.trim());
|
|
168663
|
+
const tuiModeOverride = process.env.ZCODE_TUI_MODE?.trim().toLowerCase();
|
|
167843
168664
|
const savedConfig = await readUserConfig().then((config) => isRecord(config.model) ? config.model : void 0).catch(() => void 0);
|
|
167844
168665
|
const savedModelLabel = typeof savedConfig?.main === "string" && savedConfig.main.trim() ? savedConfig.main : void 0;
|
|
167845
168666
|
const setting = await this.showChoice({
|
|
@@ -167861,6 +168682,16 @@ var ZCodeTui = class {
|
|
|
167861
168682
|
value: "notification-condition",
|
|
167862
168683
|
label: "When to notify",
|
|
167863
168684
|
description: conditionOverride ? `Current: ${effective.condition} · Saved: ${stored.condition} (environment override)` : `Current: ${stored.condition}`
|
|
168685
|
+
},
|
|
168686
|
+
{
|
|
168687
|
+
value: "tui-mode",
|
|
168688
|
+
label: "Display mode",
|
|
168689
|
+
description: tuiModeOverride === "fullscreen" || tuiModeOverride === "regular" ? `Current: ${this.tuiMode === "fullscreen" ? "Fullscreen" : "Regular"} (environment override)` : `Current: ${this.tuiMode === "fullscreen" ? "Fullscreen" : "Regular"}`
|
|
168690
|
+
},
|
|
168691
|
+
{
|
|
168692
|
+
value: "copy-on-select",
|
|
168693
|
+
label: "Fullscreen copy on select",
|
|
168694
|
+
description: `Current: ${this.copyOnSelect ? "Enabled" : "Disabled"}`
|
|
167864
168695
|
}
|
|
167865
168696
|
],
|
|
167866
168697
|
selectedIndex: selectedSettingIndex
|
|
@@ -167872,6 +168703,73 @@ var ZCodeTui = class {
|
|
|
167872
168703
|
feedback = "Changes save immediately · Esc closes settings";
|
|
167873
168704
|
continue;
|
|
167874
168705
|
}
|
|
168706
|
+
if (setting.value === "tui-mode") {
|
|
168707
|
+
selectedSettingIndex = 3;
|
|
168708
|
+
const selected = await this.showChoice({
|
|
168709
|
+
title: "Display mode",
|
|
168710
|
+
prompt: "Switch between regular and fullscreen TUI.",
|
|
168711
|
+
help: "Up/Down choose · Enter apply · Esc back",
|
|
168712
|
+
items: [{
|
|
168713
|
+
value: "regular",
|
|
168714
|
+
label: "Regular",
|
|
168715
|
+
description: "Scrollback-style output (default)"
|
|
168716
|
+
}, {
|
|
168717
|
+
value: "fullscreen",
|
|
168718
|
+
label: "Fullscreen",
|
|
168719
|
+
description: "Alternate screen with scrollable transcript and scrollbars"
|
|
168720
|
+
}],
|
|
168721
|
+
selectedIndex: this.tuiMode === "fullscreen" ? 1 : 0
|
|
168722
|
+
});
|
|
168723
|
+
if (!selected) {
|
|
168724
|
+
feedback = "No changes · Esc closes settings";
|
|
168725
|
+
continue;
|
|
168726
|
+
}
|
|
168727
|
+
const next = selected.value;
|
|
168728
|
+
if (next === this.tuiMode) {
|
|
168729
|
+
feedback = "Display mode unchanged";
|
|
168730
|
+
continue;
|
|
168731
|
+
}
|
|
168732
|
+
await this.switchTuiMode(next);
|
|
168733
|
+
feedback = this.tuiMode === next ? `Display mode: ${next} · applied` : "Could not switch display mode";
|
|
168734
|
+
selectedSettingIndex = 3;
|
|
168735
|
+
continue;
|
|
168736
|
+
}
|
|
168737
|
+
if (setting.value === "copy-on-select") {
|
|
168738
|
+
selectedSettingIndex = 4;
|
|
168739
|
+
const selected = await this.showChoice({
|
|
168740
|
+
title: "Fullscreen copy on select",
|
|
168741
|
+
prompt: "Only applies to fullscreen mode. Releasing a mouse selection copies it to the clipboard.",
|
|
168742
|
+
help: "Up/Down choose · Enter save · Esc back",
|
|
168743
|
+
items: [{
|
|
168744
|
+
value: "enabled",
|
|
168745
|
+
label: "Enabled",
|
|
168746
|
+
description: "Release copies the selection (default)"
|
|
168747
|
+
}, {
|
|
168748
|
+
value: "disabled",
|
|
168749
|
+
label: "Disabled",
|
|
168750
|
+
description: "Selection only highlights; copy manually via /copy or the terminal"
|
|
168751
|
+
}],
|
|
168752
|
+
selectedIndex: this.copyOnSelect ? 0 : 1
|
|
168753
|
+
});
|
|
168754
|
+
if (!selected) {
|
|
168755
|
+
feedback = "No changes · Esc closes settings";
|
|
168756
|
+
continue;
|
|
168757
|
+
}
|
|
168758
|
+
const next = selected.value === "enabled";
|
|
168759
|
+
if (next === this.copyOnSelect) {
|
|
168760
|
+
feedback = "Copy on select unchanged";
|
|
168761
|
+
continue;
|
|
168762
|
+
}
|
|
168763
|
+
try {
|
|
168764
|
+
await writeCopyOnSelect(next);
|
|
168765
|
+
this.setCopyOnSelect(next);
|
|
168766
|
+
feedback = `Copy on select ${next ? "enabled" : "disabled"} · saved`;
|
|
168767
|
+
} catch (error) {
|
|
168768
|
+
this.addNotice(error instanceof Error ? error.message : String(error), "error");
|
|
168769
|
+
feedback = "Could not save the setting · select it to retry";
|
|
168770
|
+
}
|
|
168771
|
+
continue;
|
|
168772
|
+
}
|
|
167875
168773
|
selectedSettingIndex = setting.value === "notification-condition" ? 2 : setting.value === "notification-method" ? 1 : 0;
|
|
167876
168774
|
let next = stored;
|
|
167877
168775
|
let changedLabel;
|
|
@@ -168175,6 +169073,7 @@ var ZCodeTui = class {
|
|
|
168175
169073
|
this.lastAssistantText = "";
|
|
168176
169074
|
this.turnAssistantText = "";
|
|
168177
169075
|
this.restoreTranscript(restored);
|
|
169076
|
+
if (this.transcript.blockCount > 0) this.enterSessionRail(true);
|
|
168178
169077
|
this.editor.setText(target.text);
|
|
168179
169078
|
}
|
|
168180
169079
|
const label = scope === "both" ? "Conversation and workspace rewound. The selected input was restored to the editor." : scope === "conversation" ? "Conversation rewound. The selected input was restored to the editor." : "Workspace files rewound. Conversation history was kept.";
|
|
@@ -168591,10 +169490,18 @@ var ZCodeTui = class {
|
|
|
168591
169490
|
const canMessage = job.taskKind === "local_agent" && Boolean(this.options.sendBackgroundTaskMessage);
|
|
168592
169491
|
const canStop = active && job.cancellable !== false && Boolean(this.options.cancelBackgroundTask);
|
|
168593
169492
|
const items = [
|
|
168594
|
-
...canMessage ? [{
|
|
169493
|
+
...canMessage ? active ? [{
|
|
168595
169494
|
value: "message",
|
|
168596
|
-
label:
|
|
168597
|
-
description:
|
|
169495
|
+
label: "Message agent",
|
|
169496
|
+
description: "Send guidance to this task"
|
|
169497
|
+
}] : [{
|
|
169498
|
+
value: "resume",
|
|
169499
|
+
label: "Resume agent",
|
|
169500
|
+
description: "Continue from the saved child session"
|
|
169501
|
+
}, {
|
|
169502
|
+
value: "resume-with-instructions",
|
|
169503
|
+
label: "Resume with instructions",
|
|
169504
|
+
description: "Continue the saved child session with custom guidance"
|
|
168598
169505
|
}] : [],
|
|
168599
169506
|
...canMessage && active ? [{
|
|
168600
169507
|
value: "restart",
|
|
@@ -168646,11 +169553,16 @@ var ZCodeTui = class {
|
|
|
168646
169553
|
await this.stopBackgroundTask(job.taskId);
|
|
168647
169554
|
continue;
|
|
168648
169555
|
}
|
|
168649
|
-
if (action.value === "
|
|
169556
|
+
if (action.value === "resume" && !active) {
|
|
169557
|
+
await this.messageBackgroundTask(job, defaultBackgroundResumeMessage);
|
|
169558
|
+
continue;
|
|
169559
|
+
}
|
|
169560
|
+
if (action.value === "message" || action.value === "resume-with-instructions" || action.value === "restart") {
|
|
168650
169561
|
const restart = action.value === "restart";
|
|
169562
|
+
const customResume = action.value === "resume-with-instructions";
|
|
168651
169563
|
const message = await this.showTextPrompt({
|
|
168652
|
-
title: restart ? "Restart background agent" :
|
|
168653
|
-
prompt: restart ? `Describe what ${job.agentId ?? job.taskId} should continue or repair after restart.` :
|
|
169564
|
+
title: restart ? "Restart background agent" : customResume ? "Resume background agent with instructions" : "Message background agent",
|
|
169565
|
+
prompt: restart ? `Describe what ${job.agentId ?? job.taskId} should continue or repair after restart.` : customResume ? `Describe what ${job.agentId ?? job.taskId} should continue or repair.` : `Send guidance to ${job.agentId ?? job.taskId}.`
|
|
168654
169566
|
});
|
|
168655
169567
|
if (message?.trim()) await this.messageBackgroundTask(job, message.trim(), restart);
|
|
168656
169568
|
continue;
|
|
@@ -168756,7 +169668,7 @@ var ZCodeTui = class {
|
|
|
168756
169668
|
this.addNotice(`No background task found with ID ${taskId}.`, "warning");
|
|
168757
169669
|
return;
|
|
168758
169670
|
}
|
|
168759
|
-
const message = suppliedMessage || (resume ?
|
|
169671
|
+
const message = suppliedMessage || (resume ? defaultBackgroundResumeMessage : "");
|
|
168760
169672
|
if (!message) {
|
|
168761
169673
|
this.addNotice(`Usage: /tasks message ${taskId} <message>`, "muted");
|
|
168762
169674
|
return;
|
|
@@ -168787,6 +169699,7 @@ var ZCodeTui = class {
|
|
|
168787
169699
|
if (status === "failed") throw new Error(asString(record?.error) ?? detail);
|
|
168788
169700
|
this.backgroundTaskEvents.recordSystemMessage(job.taskId, detail);
|
|
168789
169701
|
this.addNotice(detail, "muted");
|
|
169702
|
+
await this.notifyTaskCoordinator(job, restart, message);
|
|
168790
169703
|
await this.refreshRuntimeState();
|
|
168791
169704
|
} catch (error) {
|
|
168792
169705
|
const detail = error instanceof Error ? error.message : String(error);
|
|
@@ -168796,6 +169709,23 @@ var ZCodeTui = class {
|
|
|
168796
169709
|
this.updateActivity(void 0);
|
|
168797
169710
|
}
|
|
168798
169711
|
}
|
|
169712
|
+
async notifyTaskCoordinator(job, restart, message) {
|
|
169713
|
+
const coordinatorNotice = taskCoordinatorNotice(job, restart, message);
|
|
169714
|
+
let failure;
|
|
169715
|
+
try {
|
|
169716
|
+
if (await this.submit(coordinatorNotice, {
|
|
169717
|
+
...protectSubmission(coordinatorNotice),
|
|
169718
|
+
recordHistory: false,
|
|
169719
|
+
suppressCompletionNotification: true
|
|
169720
|
+
}) === true) return;
|
|
169721
|
+
failure = "the coordinator notice was not accepted";
|
|
169722
|
+
} catch (error) {
|
|
169723
|
+
failure = error instanceof Error ? error.message : String(error);
|
|
169724
|
+
}
|
|
169725
|
+
const detail = `Task action succeeded, but ${failure}.`;
|
|
169726
|
+
this.backgroundTaskEvents.recordSystemMessage(job.taskId, detail, true);
|
|
169727
|
+
this.addNotice(detail, "warning");
|
|
169728
|
+
}
|
|
168799
169729
|
async stopBackgroundTask(taskId) {
|
|
168800
169730
|
if (!taskId) {
|
|
168801
169731
|
this.addNotice("Usage: /tasks stop <task-id>", "muted");
|
|
@@ -168837,7 +169767,7 @@ var ZCodeTui = class {
|
|
|
168837
169767
|
return await choose(this.ui, this.choiceHost, this.theme, options);
|
|
168838
169768
|
} finally {
|
|
168839
169769
|
this.choiceDepth = Math.max(0, this.choiceDepth - 1);
|
|
168840
|
-
this.
|
|
169770
|
+
this.focusEditor();
|
|
168841
169771
|
this.ui.requestRender();
|
|
168842
169772
|
}
|
|
168843
169773
|
}
|
|
@@ -168847,11 +169777,16 @@ var ZCodeTui = class {
|
|
|
168847
169777
|
return await promptText(this.ui, this.choiceHost, this.theme, options);
|
|
168848
169778
|
} finally {
|
|
168849
169779
|
this.choiceDepth = Math.max(0, this.choiceDepth - 1);
|
|
168850
|
-
this.
|
|
169780
|
+
this.focusEditor();
|
|
168851
169781
|
this.ui.requestRender();
|
|
168852
169782
|
}
|
|
168853
169783
|
}
|
|
168854
|
-
async
|
|
169784
|
+
async copySelectionOrLastResponse() {
|
|
169785
|
+
const fullscreen = this.fullscreenAltScreen;
|
|
169786
|
+
if (fullscreen?.hasActiveSelection()) {
|
|
169787
|
+
await fullscreen.copyActiveSelectionToClipboard();
|
|
169788
|
+
return;
|
|
169789
|
+
}
|
|
168855
169790
|
const text = this.transcript.selectedText() ?? this.lastAssistantText;
|
|
168856
169791
|
if (!text) {
|
|
168857
169792
|
this.addNotice("There is no assistant response to copy.", "muted");
|
|
@@ -168878,7 +169813,10 @@ var ZCodeTui = class {
|
|
|
168878
169813
|
} catch {
|
|
168879
169814
|
break;
|
|
168880
169815
|
}
|
|
168881
|
-
for (const input of history.reverse())
|
|
169816
|
+
for (const input of history.reverse()) {
|
|
169817
|
+
this.rememberEditorHistory(input);
|
|
169818
|
+
this.editor.addToHistory(input);
|
|
169819
|
+
}
|
|
168882
169820
|
}
|
|
168883
169821
|
async restoreInitialTranscript() {
|
|
168884
169822
|
if (!this.options.loadSessionTranscript) return;
|
|
@@ -169020,6 +169958,7 @@ var ZCodeTui = class {
|
|
|
169020
169958
|
applyRuntimeProjection(projection) {
|
|
169021
169959
|
if (!projection) return;
|
|
169022
169960
|
this.runtimeProjection = projection;
|
|
169961
|
+
this.noticeRestoredBackgroundTasks(projection);
|
|
169023
169962
|
this.reconcileTurnTiming(projection);
|
|
169024
169963
|
if (projection.sessionId) this.sessionId = projection.sessionId;
|
|
169025
169964
|
this.sessionMetrics = mergeProjectionMetrics(this.sessionMetrics, {
|
|
@@ -169030,6 +169969,35 @@ var ZCodeTui = class {
|
|
|
169030
169969
|
}, Boolean(this.options.readSessionUsage));
|
|
169031
169970
|
this.updateRuntimeActivity(false);
|
|
169032
169971
|
}
|
|
169972
|
+
/**
|
|
169973
|
+
* Surface tasks the persisted background-agent restore bridge re-registered.
|
|
169974
|
+
* Tasks that completed or failed while ZCode was closed never produce a
|
|
169975
|
+
* completion notification, so without this notice they are silent — the
|
|
169976
|
+
* model-facing task_status attachment alone does not reach the user.
|
|
169977
|
+
*/
|
|
169978
|
+
noticeRestoredBackgroundTasks(projection) {
|
|
169979
|
+
for (const job of projection.restoredBackgroundTasks ?? []) {
|
|
169980
|
+
const seenKey = `${projection.sessionId ?? ""}/${job.taskId}`;
|
|
169981
|
+
if (this.restoredNoticeSeen.has(seenKey)) continue;
|
|
169982
|
+
this.restoredNoticeSeen.add(seenKey);
|
|
169983
|
+
const label = job.description ? `${job.taskId} (${job.description})` : job.taskId;
|
|
169984
|
+
if (job.status === "completed") this.addSystemEvent({
|
|
169985
|
+
tone: "muted",
|
|
169986
|
+
title: "Background task completed while ZCode was closed",
|
|
169987
|
+
detail: `${label} finished before this session was resumed. Collect its result with TaskOutput or open /tasks.`
|
|
169988
|
+
});
|
|
169989
|
+
else if (job.status === "failed") this.addSystemEvent({
|
|
169990
|
+
tone: "error",
|
|
169991
|
+
title: "Background task failed while ZCode was closed",
|
|
169992
|
+
detail: `${label} failed before this session was resumed. Resume it from /tasks to continue.`
|
|
169993
|
+
});
|
|
169994
|
+
else this.addSystemEvent({
|
|
169995
|
+
tone: "warning",
|
|
169996
|
+
title: "Background task restored from this session",
|
|
169997
|
+
detail: `${label} was interrupted before ZCode closed. Resume it from /tasks when needed.`
|
|
169998
|
+
});
|
|
169999
|
+
}
|
|
170000
|
+
}
|
|
169033
170001
|
updateRuntimeActivity(requestRender = true) {
|
|
169034
170002
|
this.runtimeActivity.update({
|
|
169035
170003
|
projection: this.runtimeProjection,
|
|
@@ -169145,7 +170113,10 @@ var ZCodeTui = class {
|
|
|
169145
170113
|
this.finalizeUnresolvedTools(unfinishedToolState);
|
|
169146
170114
|
this.turnDiffs.finishTurn();
|
|
169147
170115
|
this.currentToolGroup = void 0;
|
|
169148
|
-
if (
|
|
170116
|
+
if (unfinishedToolState === "cancelled") {
|
|
170117
|
+
this.turnWork.cancel();
|
|
170118
|
+
this.settleTurnTiming();
|
|
170119
|
+
} else if (!this.turnWork.finishForeground(Boolean(this.options.readRuntimeProjection))) this.settleTurnTiming();
|
|
169149
170120
|
this.activity = void 0;
|
|
169150
170121
|
this.refreshSessionTerminalTitle();
|
|
169151
170122
|
this.updateTurnStatus();
|
|
@@ -169191,36 +170162,45 @@ var ZCodeTui = class {
|
|
|
169191
170162
|
this.updateCheckAbortController?.abort();
|
|
169192
170163
|
if (this.turnTimer) clearInterval(this.turnTimer);
|
|
169193
170164
|
if (this.rewindEscapeTimer) clearTimeout(this.rewindEscapeTimer);
|
|
170165
|
+
if (this.fullscreenWelcomeTransitionTimer) clearTimeout(this.fullscreenWelcomeTransitionTimer);
|
|
169194
170166
|
if (this.runtimeRefreshTimer) clearTimeout(this.runtimeRefreshTimer);
|
|
169195
170167
|
if (this.runtimePollTimer) clearTimeout(this.runtimePollTimer);
|
|
169196
170168
|
this.unsubscribeSession?.();
|
|
169197
170169
|
this.unsubscribeWorkflow?.();
|
|
169198
170170
|
const elapsedMilliseconds = this.turnStartedAt === void 0 ? this.turnElapsedMilliseconds : Math.max(0, performance.now() - this.turnStartedAt);
|
|
169199
|
-
|
|
169200
|
-
|
|
170171
|
+
try {
|
|
170172
|
+
this.notifications.stop();
|
|
170173
|
+
} catch {}
|
|
170174
|
+
try {
|
|
170175
|
+
this.ui.stop();
|
|
170176
|
+
} catch {}
|
|
169201
170177
|
this.finishStop(elapsedMilliseconds);
|
|
169202
170178
|
}
|
|
169203
170179
|
async finishStop(elapsedMilliseconds) {
|
|
169204
|
-
|
|
169205
|
-
|
|
169206
|
-
|
|
169207
|
-
|
|
169208
|
-
|
|
169209
|
-
|
|
169210
|
-
|
|
169211
|
-
|
|
169212
|
-
|
|
169213
|
-
|
|
169214
|
-
|
|
169215
|
-
|
|
169216
|
-
|
|
169217
|
-
(
|
|
169218
|
-
|
|
169219
|
-
|
|
170180
|
+
try {
|
|
170181
|
+
await this.refreshExitUsage();
|
|
170182
|
+
const summary = buildExitSummary({
|
|
170183
|
+
elapsedMilliseconds,
|
|
170184
|
+
metrics: this.sessionMetrics,
|
|
170185
|
+
sessionId: this.sessionId ?? this.runtimeProjection?.sessionId,
|
|
170186
|
+
width: this.ui.terminal.columns
|
|
170187
|
+
});
|
|
170188
|
+
const lines = [
|
|
170189
|
+
summary.divider && this.theme.muted(summary.divider),
|
|
170190
|
+
summary.tokenUsage,
|
|
170191
|
+
summary.resumeCommand ? `To continue this session, run ${this.theme.accent(summary.resumeCommand)}` : void 0
|
|
170192
|
+
].filter((line) => Boolean(line));
|
|
170193
|
+
if (lines.length > 0) try {
|
|
170194
|
+
(this.options.stdout ?? process.stdout).write(`${lines.join("\n")}\n`);
|
|
170195
|
+
} catch {}
|
|
170196
|
+
} catch {} finally {
|
|
170197
|
+
this.resolveDone();
|
|
170198
|
+
}
|
|
169220
170199
|
}
|
|
169221
170200
|
};
|
|
169222
170201
|
async function runTui(options) {
|
|
170202
|
+
suppressTuiAiSdkWarnings();
|
|
169223
170203
|
await new ZCodeTui(options).run();
|
|
169224
170204
|
}
|
|
169225
170205
|
//#endregion
|
|
169226
|
-
export { loginFailureDiagnostic, runTui, shouldSuspendForLoginCommand, shouldUseNoBrowserForLogin, suspendedZaiLoginCommand };
|
|
170206
|
+
export { loginFailureDiagnostic, runTui, shouldSuspendForLoginCommand, shouldUseNoBrowserForLogin, suppressTuiAiSdkWarnings, suspendedZaiLoginCommand };
|