zcode-app-cli 3.15.3-36 → 3.15.3-37
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/docs/CONFIGURATION.md +14 -3
- package/docs/CONFIGURATION.zh-CN.md +11 -3
- package/docs/HOST_INTEGRATION.md +160 -0
- package/package.json +10 -7
- package/vendor/cli-config.cjs +52 -0
- package/vendor/extraction.json +6 -1
- package/vendor/node_modules/@zcode/tui/dist/index.js +108 -24
- package/vendor/node_modules/@zcode/tui/package.json +1 -1
- package/vendor/zcode.cjs +2 -2
|
@@ -5,7 +5,7 @@ import { constants as constants$1, homedir } from "node:os";
|
|
|
5
5
|
import { access, link, mkdir, open, readFile, rename, rm, stat, writeFile } from "node:fs/promises";
|
|
6
6
|
import { basename, dirname, extname, isAbsolute, join, posix, resolve, sep, win32 } from "node:path";
|
|
7
7
|
import { randomUUID } from "node:crypto";
|
|
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";
|
|
8
|
+
import { Box, CombinedAutocompleteProvider, Container, Editor, Image, Input, Markdown, ProcessTerminal, ScrollView, SelectList, Spacer, Text, TuiAltScreen, TuiMainScreen, VStack, decodeKittyPrintable, getKeybindings, isKeyRelease, isViewportTUI, matchesKey, renderFakeCursor, truncateToWidth, visibleWidth, wrapTextWithAnsi } from "@earendil-works/pi-tui";
|
|
9
9
|
import { AltScreenSearchComponent } from "@earendil-works/pi-tui/dist/alt-screen-search.js";
|
|
10
10
|
import { StringDecoder } from "node:string_decoder";
|
|
11
11
|
import { isDeepStrictEqual } from "node:util";
|
|
@@ -153881,13 +153881,12 @@ function removeLastGrapheme(value) {
|
|
|
153881
153881
|
return segments.join("");
|
|
153882
153882
|
}
|
|
153883
153883
|
/**
|
|
153884
|
-
* Drop
|
|
153885
|
-
*
|
|
153886
|
-
*
|
|
153887
|
-
* Input placeholders may add SGR (e.g. dim) inside the caret; retain it.
|
|
153884
|
+
* Drop pi-tui's fake-cursor APC markers before the renderer turns them into
|
|
153885
|
+
* reverse video. Retain the hardware cursor marker, text and placeholder styles.
|
|
153886
|
+
* Also accept the SGR caret form used by custom/legacy input components.
|
|
153888
153887
|
*/
|
|
153889
153888
|
function stripCaretHighlight(text) {
|
|
153890
|
-
return text.replace(/\x1b\[7m((?:\x1b\[(?!(?:0|27)m)[0-9;:]*m|[^\x1b])*)\x1b\[(?:0|27)m/gu, "$1");
|
|
153889
|
+
return text.replace(/\x1b_pi:\/?fc\x07/gu, "").replace(/\x1b\[7m((?:\x1b\[(?!(?:0|27)m)[0-9;:]*m|[^\x1b])*)\x1b\[(?:0|27)m/gu, "$1");
|
|
153891
153890
|
}
|
|
153892
153891
|
const maxHighlightCharacters = 1e5;
|
|
153893
153892
|
const plainLanguages = /* @__PURE__ */ new Set([
|
|
@@ -157115,6 +157114,7 @@ function toolScope(event) {
|
|
|
157115
157114
|
var BackgroundTaskEventStore = class {
|
|
157116
157115
|
activities = /* @__PURE__ */ new Map();
|
|
157117
157116
|
handoffTurns = /* @__PURE__ */ new Map();
|
|
157117
|
+
handoffTexts = /* @__PURE__ */ new Map();
|
|
157118
157118
|
pendingBackgroundTasks = /* @__PURE__ */ new Set();
|
|
157119
157119
|
pendingSubagentMessages = /* @__PURE__ */ new Set();
|
|
157120
157120
|
scopedTurnIds = /* @__PURE__ */ new Set();
|
|
@@ -157133,6 +157133,7 @@ var BackgroundTaskEventStore = class {
|
|
|
157133
157133
|
const notices = [];
|
|
157134
157134
|
let changed = false;
|
|
157135
157135
|
let handoffSettled = false;
|
|
157136
|
+
let settledTurnId;
|
|
157136
157137
|
const taskId = taskIdFor(event);
|
|
157137
157138
|
if (event.type === "background_task_completed" && taskId) {
|
|
157138
157139
|
this.pendingBackgroundTasks.add(taskId);
|
|
@@ -157193,6 +157194,7 @@ var BackgroundTaskEventStore = class {
|
|
|
157193
157194
|
if (handoff && (completed || failed)) {
|
|
157194
157195
|
this.handoffTurns.delete(event.turnId);
|
|
157195
157196
|
handoffSettled = true;
|
|
157197
|
+
settledTurnId = event.turnId;
|
|
157196
157198
|
if (failed) {
|
|
157197
157199
|
const detail = event.message ?? "The task finished, but ZCode could not process its result.";
|
|
157198
157200
|
for (const id of handoff.taskIds) this.record(id, "error", detail, event.turnId);
|
|
@@ -157208,9 +157210,20 @@ var BackgroundTaskEventStore = class {
|
|
|
157208
157210
|
return {
|
|
157209
157211
|
changed,
|
|
157210
157212
|
handoffSettled,
|
|
157211
|
-
notices
|
|
157213
|
+
notices,
|
|
157214
|
+
settledTurnId
|
|
157212
157215
|
};
|
|
157213
157216
|
}
|
|
157217
|
+
/**
|
|
157218
|
+
* The response text a background handoff turn produced for the conversation.
|
|
157219
|
+
* Handoff turns are task-scoped away from the main transcript while they
|
|
157220
|
+
* run, so the transcript render needs the accumulated text when they settle.
|
|
157221
|
+
*/
|
|
157222
|
+
takeHandoffText(turnId) {
|
|
157223
|
+
const text = this.handoffTexts.get(turnId);
|
|
157224
|
+
this.handoffTexts.delete(turnId);
|
|
157225
|
+
return text;
|
|
157226
|
+
}
|
|
157214
157227
|
entries(taskId) {
|
|
157215
157228
|
return this.activities.get(taskId) ?? [];
|
|
157216
157229
|
}
|
|
@@ -157220,6 +157233,7 @@ var BackgroundTaskEventStore = class {
|
|
|
157220
157233
|
settleActiveHandoffs() {
|
|
157221
157234
|
const count = this.handoffTurns.size;
|
|
157222
157235
|
this.handoffTurns.clear();
|
|
157236
|
+
this.handoffTexts.clear();
|
|
157223
157237
|
return count;
|
|
157224
157238
|
}
|
|
157225
157239
|
isTaskScoped(event) {
|
|
@@ -157237,6 +157251,12 @@ var BackgroundTaskEventStore = class {
|
|
|
157237
157251
|
this.record(taskId, failed ? "error" : "system", message);
|
|
157238
157252
|
}
|
|
157239
157253
|
appendHandoffDelta(taskId, turnId, delta) {
|
|
157254
|
+
const accumulated = bounded((this.handoffTexts.get(turnId) ?? "") + delta);
|
|
157255
|
+
this.handoffTexts.set(turnId, accumulated);
|
|
157256
|
+
if (this.handoffTexts.size > 32) {
|
|
157257
|
+
const oldest = this.handoffTexts.keys().next().value;
|
|
157258
|
+
if (oldest !== void 0 && oldest !== turnId) this.handoffTexts.delete(oldest);
|
|
157259
|
+
}
|
|
157240
157260
|
const entries = this.activities.get(taskId) ?? [];
|
|
157241
157261
|
const id = `handoff:${turnId}`;
|
|
157242
157262
|
const existing = entries.find((entry) => entry.id === id);
|
|
@@ -157332,6 +157352,24 @@ var BackgroundTaskEventStore = class {
|
|
|
157332
157352
|
}
|
|
157333
157353
|
};
|
|
157334
157354
|
//#endregion
|
|
157355
|
+
//#region packages/zcode-tui/src/background-task-notifications.ts
|
|
157356
|
+
const deliveredTaskIdPattern = /<task-id>([^<]{1,200})<\/task-id>/gu;
|
|
157357
|
+
/** Task ids whose terminal notification already exists in the conversation. */
|
|
157358
|
+
function deliveredBackgroundTaskIds(messages) {
|
|
157359
|
+
const delivered = /* @__PURE__ */ new Set();
|
|
157360
|
+
for (const message of messages) {
|
|
157361
|
+
if (message.role !== "user") continue;
|
|
157362
|
+
for (const part of message.parts ?? []) {
|
|
157363
|
+
if (typeof part.text !== "string") continue;
|
|
157364
|
+
for (const match of part.text.matchAll(deliveredTaskIdPattern)) {
|
|
157365
|
+
const taskId = match[1]?.trim();
|
|
157366
|
+
if (taskId) delivered.add(taskId);
|
|
157367
|
+
}
|
|
157368
|
+
}
|
|
157369
|
+
}
|
|
157370
|
+
return delivered;
|
|
157371
|
+
}
|
|
157372
|
+
//#endregion
|
|
157335
157373
|
//#region packages/zcode-tui/src/background-task-output.ts
|
|
157336
157374
|
const defaultMaximumBytes = 64 * 1024;
|
|
157337
157375
|
function readBackgroundTaskOutput(path, maximumBytes = defaultMaximumBytes) {
|
|
@@ -157957,7 +157995,8 @@ var PromptInput = class extends Input {
|
|
|
157957
157995
|
const lines = super.render(width);
|
|
157958
157996
|
if (!value && this.placeholderText && lines[0]) {
|
|
157959
157997
|
const placeholder = this.theme.muted(this.placeholderText);
|
|
157960
|
-
|
|
157998
|
+
const cursor = renderFakeCursor(" ");
|
|
157999
|
+
return [truncateToWidth(lines[0].replace(cursor, `${cursor}${placeholder}`), width, "", true)];
|
|
157961
158000
|
}
|
|
157962
158001
|
return lines;
|
|
157963
158002
|
}
|
|
@@ -157987,7 +158026,7 @@ var PromptEditor = class extends Editor {
|
|
|
157987
158026
|
renderEditor(width) {
|
|
157988
158027
|
const lines = super.render(width);
|
|
157989
158028
|
if (this.getText() || !this.placeholder) return lines;
|
|
157990
|
-
const cursor = "
|
|
158029
|
+
const cursor = renderFakeCursor(" ");
|
|
157991
158030
|
const cursorLine = lines.findIndex((line) => line.includes(cursor));
|
|
157992
158031
|
if (cursorLine >= 0) lines[cursorLine] = truncateToWidth(lines[cursorLine].replace(cursor, `${cursor}${this.promptTheme.muted(this.placeholder)}`), width, "", true);
|
|
157993
158032
|
return lines;
|
|
@@ -158031,6 +158070,20 @@ function promptText(ui, host, theme, options) {
|
|
|
158031
158070
|
function colorSchemeFromRgb(color) {
|
|
158032
158071
|
return (.2126 * color.r + .7152 * color.g + .0722 * color.b) / 255 > .5 ? "light" : "dark";
|
|
158033
158072
|
}
|
|
158073
|
+
/** Query pi-tui's combined palette, retaining the terminal scheme-report fallback. */
|
|
158074
|
+
async function queryTerminalColorScheme(ui, timeoutMs) {
|
|
158075
|
+
let reportedScheme;
|
|
158076
|
+
const unsubscribe = ui.onTerminalColorSchemeChange((scheme) => {
|
|
158077
|
+
reportedScheme = scheme;
|
|
158078
|
+
});
|
|
158079
|
+
try {
|
|
158080
|
+
ui.terminal.write("\x1B[?996n");
|
|
158081
|
+
const colors = await ui.queryTerminalColors({ timeoutMs });
|
|
158082
|
+
return colors.background ? colorSchemeFromRgb(colors.background) : reportedScheme;
|
|
158083
|
+
} finally {
|
|
158084
|
+
unsubscribe();
|
|
158085
|
+
}
|
|
158086
|
+
}
|
|
158034
158087
|
/**
|
|
158035
158088
|
* Best-effort synchronous fallback for terminals that expose COLORFGBG.
|
|
158036
158089
|
* The last ANSI color is the background; values outside the conventional
|
|
@@ -166397,7 +166450,7 @@ const exitUsageQueryTimeoutMs = 250;
|
|
|
166397
166450
|
const fullscreenWelcomeTransitionMs = 180;
|
|
166398
166451
|
const terminalFocusIn = "\x1B[I";
|
|
166399
166452
|
const updateAvailableBlockId = "update_available";
|
|
166400
|
-
const
|
|
166453
|
+
const modelStatusBlockIdPrefix = "model_status";
|
|
166401
166454
|
const questionBackValue = "__back__";
|
|
166402
166455
|
const questionOtherValue = "__other__";
|
|
166403
166456
|
const questionDoneValue = "__done__";
|
|
@@ -166560,9 +166613,8 @@ function suppressTuiAiSdkWarnings() {
|
|
|
166560
166613
|
}
|
|
166561
166614
|
suppressTuiAiSdkWarnings();
|
|
166562
166615
|
/**
|
|
166563
|
-
*
|
|
166564
|
-
*
|
|
166565
|
-
* so it needs the same priority as a modal overlay while it has focus.
|
|
166616
|
+
* Give the composer priority for page navigation and modified Home/End keys
|
|
166617
|
+
* while editing. Bare Home/End are already editor keys in pi-tui 1.x.
|
|
166566
166618
|
*/
|
|
166567
166619
|
var ZCodeAltScreen = class extends TuiAltScreen {
|
|
166568
166620
|
viewportInputDeferral;
|
|
@@ -166672,7 +166724,7 @@ var ZCodeTui = class {
|
|
|
166672
166724
|
activeTurnId;
|
|
166673
166725
|
turnEpoch = 0;
|
|
166674
166726
|
activeTurnEpoch;
|
|
166675
|
-
|
|
166727
|
+
modelStatusBlockId;
|
|
166676
166728
|
pendingSteerInterrupt;
|
|
166677
166729
|
recentSteerCommit;
|
|
166678
166730
|
currentThinking;
|
|
@@ -166708,6 +166760,8 @@ var ZCodeTui = class {
|
|
|
166708
166760
|
unsubscribeSession;
|
|
166709
166761
|
backgroundTaskEvents = new BackgroundTaskEventStore();
|
|
166710
166762
|
restoredNoticeSeen = /* @__PURE__ */ new Set();
|
|
166763
|
+
notifiedBackgroundTaskIds = /* @__PURE__ */ new Set();
|
|
166764
|
+
transcriptNotificationsReady = false;
|
|
166711
166765
|
turnWork = new TurnWorkTracker();
|
|
166712
166766
|
backgroundCoordinatorMessageIds = /* @__PURE__ */ new Set();
|
|
166713
166767
|
workflowPanel;
|
|
@@ -166946,8 +167000,7 @@ var ZCodeTui = class {
|
|
|
166946
167000
|
async resolveTerminalColorScheme() {
|
|
166947
167001
|
if (!this.colorsEnabled || this.themePreference !== "auto") return;
|
|
166948
167002
|
try {
|
|
166949
|
-
const
|
|
166950
|
-
const colorScheme = background ? colorSchemeFromRgb(background) : reportedScheme;
|
|
167003
|
+
const colorScheme = await queryTerminalColorScheme(this.ui, terminalThemeQueryTimeoutMs);
|
|
166951
167004
|
if (colorScheme) this.theme.setColorScheme(colorScheme);
|
|
166952
167005
|
} catch {}
|
|
166953
167006
|
}
|
|
@@ -168216,7 +168269,7 @@ var ZCodeTui = class {
|
|
|
168216
168269
|
title: event.type === "streamRecovery.updated" ? "Recovering model stream" : "Retrying model request",
|
|
168217
168270
|
summary: [retry, delay].filter(Boolean).join(" · "),
|
|
168218
168271
|
detail: event.message
|
|
168219
|
-
}, this.
|
|
168272
|
+
}, this.modelStatusBlockId);
|
|
168220
168273
|
} else if (event.type === "model_request_failed") {
|
|
168221
168274
|
if (!isModelCancellationEvent(event)) {
|
|
168222
168275
|
this.updateActivity(event.retryable === true ? "model request failed · waiting to retry…" : "model request failed…", false);
|
|
@@ -168224,7 +168277,7 @@ var ZCodeTui = class {
|
|
|
168224
168277
|
tone: "error",
|
|
168225
168278
|
title: "Model request failed",
|
|
168226
168279
|
detail: event.message
|
|
168227
|
-
});
|
|
168280
|
+
}, this.modelStatusBlockId);
|
|
168228
168281
|
}
|
|
168229
168282
|
} else if (event.type === "model_stream_stalled") {
|
|
168230
168283
|
this.updateActivity("model stream stalled · waiting to retry…", false);
|
|
@@ -168234,9 +168287,11 @@ var ZCodeTui = class {
|
|
|
168234
168287
|
title: "Model stream stalled",
|
|
168235
168288
|
summary: idle,
|
|
168236
168289
|
detail: event.message
|
|
168237
|
-
});
|
|
168238
|
-
} else if (event.type === "model_request_completed")
|
|
168239
|
-
|
|
168290
|
+
}, this.modelStatusBlockId);
|
|
168291
|
+
} else if (event.type === "model_request_completed") {
|
|
168292
|
+
this.updateActivity("processing model response…", false);
|
|
168293
|
+
this.clearModelStatus();
|
|
168294
|
+
} else if (event.type === "compact_boundary" || event.type === "session_compacted") this.addSystemEvent({
|
|
168240
168295
|
tone: "muted",
|
|
168241
168296
|
title: "Conversation compacted",
|
|
168242
168297
|
summary: "Earlier context remains in transcript history"
|
|
@@ -168418,9 +168473,23 @@ var ZCodeTui = class {
|
|
|
168418
168473
|
});
|
|
168419
168474
|
this.notifications.notify(notice.notification, notice.detail ?? `${notice.title} · ${notice.summary}`);
|
|
168420
168475
|
}
|
|
168421
|
-
if (update.handoffSettled)
|
|
168476
|
+
if (update.handoffSettled) {
|
|
168477
|
+
this.renderSettledHandoffResponse(update.settledTurnId);
|
|
168478
|
+
this.drainInputAfterBackgroundHandoff();
|
|
168479
|
+
}
|
|
168422
168480
|
if (update.changed || update.notices.length > 0) this.requestStreamRender();
|
|
168423
168481
|
}
|
|
168482
|
+
/**
|
|
168483
|
+
* Turns that a background task handed off to are task-scoped out of the
|
|
168484
|
+
* main transcript while they run, so without this the response to a
|
|
168485
|
+
* completed task is only reachable from /tasks and the assistant appears to
|
|
168486
|
+
* stay silent after "Background task completed".
|
|
168487
|
+
*/
|
|
168488
|
+
renderSettledHandoffResponse(turnId) {
|
|
168489
|
+
if (!turnId) return;
|
|
168490
|
+
const text = this.backgroundTaskEvents.takeHandoffText(turnId);
|
|
168491
|
+
if (text && text.trim()) this.addAssistantMessage(text);
|
|
168492
|
+
}
|
|
168424
168493
|
drainInputAfterBackgroundHandoff() {
|
|
168425
168494
|
if (this.backgroundDrainScheduled) return;
|
|
168426
168495
|
this.backgroundDrainScheduled = true;
|
|
@@ -168604,7 +168673,7 @@ var ZCodeTui = class {
|
|
|
168604
168673
|
beginTurn(prompt) {
|
|
168605
168674
|
this.completeThinking();
|
|
168606
168675
|
this.presentationRegistry.beginTurn();
|
|
168607
|
-
this.
|
|
168676
|
+
this.modelStatusBlockId = `${modelStatusBlockIdPrefix}_${this.turnEpoch}`;
|
|
168608
168677
|
this.currentThinking = void 0;
|
|
168609
168678
|
this.currentThinkingPartId = void 0;
|
|
168610
168679
|
this.currentToolGroup = void 0;
|
|
@@ -168728,6 +168797,14 @@ var ZCodeTui = class {
|
|
|
168728
168797
|
});
|
|
168729
168798
|
this.ui.requestRender();
|
|
168730
168799
|
}
|
|
168800
|
+
/**
|
|
168801
|
+
* The model status row reports the current attempt (stalled, failed, retrying).
|
|
168802
|
+
* A completed request proves the connection is back, so the row must not outlive it.
|
|
168803
|
+
*/
|
|
168804
|
+
clearModelStatus() {
|
|
168805
|
+
if (!this.modelStatusBlockId || !this.transcript.removeBlock(this.modelStatusBlockId)) return;
|
|
168806
|
+
this.ui.requestRender();
|
|
168807
|
+
}
|
|
168731
168808
|
addUpdateAvailable(currentVersion, latestVersion) {
|
|
168732
168809
|
this.transcript.addBlock(new UpdateAvailableView(this.theme, currentVersion, latestVersion), {
|
|
168733
168810
|
id: updateAvailableBlockId,
|
|
@@ -169061,6 +169138,8 @@ var ZCodeTui = class {
|
|
|
169061
169138
|
this.currentToolGroupBlockId = void 0;
|
|
169062
169139
|
this.currentToolGroupMessageId = void 0;
|
|
169063
169140
|
this.assistantStream.breakSegment();
|
|
169141
|
+
for (const taskId of deliveredBackgroundTaskIds(messages)) this.notifiedBackgroundTaskIds.add(taskId);
|
|
169142
|
+
this.transcriptNotificationsReady = true;
|
|
169064
169143
|
if (lastAssistantModel) this.model = lastAssistantModel;
|
|
169065
169144
|
}
|
|
169066
169145
|
restorePart(part, role, fallbackMessageId) {
|
|
@@ -171027,7 +171106,9 @@ var ZCodeTui = class {
|
|
|
171027
171106
|
} catch (error) {
|
|
171028
171107
|
const message = error instanceof Error ? error.message : String(error);
|
|
171029
171108
|
this.addNotice(`Unable to restore session transcript: ${message}`, "warning");
|
|
171109
|
+
this.transcriptNotificationsReady = true;
|
|
171030
171110
|
}
|
|
171111
|
+
else this.transcriptNotificationsReady = true;
|
|
171031
171112
|
await this.restoreSessionModel();
|
|
171032
171113
|
}
|
|
171033
171114
|
async restoreSessionModel() {
|
|
@@ -171223,7 +171304,10 @@ var ZCodeTui = class {
|
|
|
171223
171304
|
* model-facing task_status attachment alone does not reach the user.
|
|
171224
171305
|
*/
|
|
171225
171306
|
noticeRestoredBackgroundTasks(projection) {
|
|
171226
|
-
|
|
171307
|
+
if (!this.transcriptNotificationsReady) return;
|
|
171308
|
+
const jobs = projection.restoredBackgroundTasks ?? [];
|
|
171309
|
+
for (const job of jobs) {
|
|
171310
|
+
if (this.notifiedBackgroundTaskIds.has(job.taskId)) continue;
|
|
171227
171311
|
const seenKey = `${projection.sessionId ?? ""}/${job.taskId}`;
|
|
171228
171312
|
if (this.restoredNoticeSeen.has(seenKey)) continue;
|
|
171229
171313
|
this.restoredNoticeSeen.add(seenKey);
|