zcode-app-cli 3.11.2-24 → 3.11.2-25

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/README.md CHANGED
@@ -33,9 +33,22 @@ ZCode desktop app is installed it can import the desktop provider settings
33
33
  (credentials stay behind a fresh sign-in, like a browser profile import).
34
34
  Reopen it anytime with `/setup`; press Esc to skip.
35
35
 
36
+ ## Host integration
37
+
38
+ `zcode-app-cli` is designed to run as a normal child process of a terminal host
39
+ or agent orchestrator. Hosts such as Herdr and Orca can launch the same
40
+ published `zcode` command without depending on private runtime files. The
41
+ launcher uses the host terminal without inserting a second PTY, forwards
42
+ cancellation signals, preserves the runtime exit status, and exposes a small
43
+ set of environment overrides.
44
+
45
+ See [Host integration](./docs/HOST_INTEGRATION.md) for the versioned contract,
46
+ Node.js example, terminal/PTY requirements, and compatibility rules.
47
+
36
48
  ## Table of contents
37
49
 
38
50
  - [Quick start](#quick-start)
51
+ - [Host integration](#host-integration)
39
52
  - [Install and update](#install-and-update)
40
53
  - [Architecture](#architecture)
41
54
  - [Features](#features)
package/bin/zcode.js CHANGED
@@ -690,10 +690,41 @@ var AppServerRequestError = class extends Error {
690
690
  this.name = "AppServerRequestError";
691
691
  }
692
692
  };
693
- function cancellationError() {
694
- const error = /* @__PURE__ */ new Error("App-server request cancelled.");
695
- error.name = "AbortError";
696
- return error;
693
+ var AppServerProcessError = class extends Error {
694
+ exitCode;
695
+ constructor(message, exitCode) {
696
+ super(message);
697
+ this.exitCode = exitCode;
698
+ this.name = "AppServerProcessError";
699
+ }
700
+ };
701
+ var AppServerCancellationError = class extends Error {
702
+ exitCode;
703
+ constructor(exitCode) {
704
+ super("App-server request cancelled.");
705
+ this.exitCode = exitCode;
706
+ this.name = "AbortError";
707
+ }
708
+ };
709
+ function signalExitCode$1(signal) {
710
+ if (!signal) return 1;
711
+ const number = constants.signals[signal];
712
+ return typeof number === "number" ? 128 + number : 1;
713
+ }
714
+ function abortSignalName$1(signal) {
715
+ const reason = signal?.reason;
716
+ return reason === "SIGINT" || reason === "SIGTERM" || reason === "SIGHUP" ? reason : void 0;
717
+ }
718
+ function cancellationError(signal) {
719
+ const signalName = abortSignalName$1(signal);
720
+ if (signalName) return new AppServerCancellationError(signalExitCode$1(signalName));
721
+ return new AppServerCancellationError(130);
722
+ }
723
+ function terminationSignal(signal) {
724
+ return abortSignalName$1(signal) ?? "SIGTERM";
725
+ }
726
+ function processError(message, code) {
727
+ return new AppServerProcessError(message, code);
697
728
  }
698
729
  async function readBounded(stream, onOverflow) {
699
730
  if (!stream) return "";
@@ -723,7 +754,7 @@ function responseEnvelope(stdout) {
723
754
  }
724
755
  }
725
756
  async function requestAppServer(request) {
726
- if (request.signal?.aborted) throw cancellationError();
757
+ if (request.signal?.aborted) throw cancellationError(request.signal);
727
758
  const child = spawn(request.transport.command, request.transport.args, {
728
759
  cwd: request.transport.cwd,
729
760
  env: request.transport.env,
@@ -748,7 +779,7 @@ async function requestAppServer(request) {
748
779
  launchError = error;
749
780
  finish(1);
750
781
  });
751
- child.once("close", (code) => finish(code ?? 1));
782
+ child.once("close", (code, signal) => finish(code ?? signalExitCode$1(signal)));
752
783
  });
753
784
  const terminateForOverflow = () => {
754
785
  overflow = true;
@@ -756,7 +787,7 @@ async function requestAppServer(request) {
756
787
  };
757
788
  const onAbort = () => {
758
789
  if (child.exitCode !== null || child.signalCode !== null) return;
759
- child.kill("SIGTERM");
790
+ child.kill(terminationSignal(request.signal));
760
791
  forceTerminationTimer = setTimeout(() => {
761
792
  if (child.exitCode === null && child.signalCode === null) child.kill("SIGKILL");
762
793
  }, forceTerminationDelayMilliseconds);
@@ -776,12 +807,12 @@ async function requestAppServer(request) {
776
807
  readBounded(child.stdout, terminateForOverflow),
777
808
  readBounded(child.stderr, terminateForOverflow)
778
809
  ]);
779
- if (request.signal?.aborted) throw cancellationError();
810
+ if (request.signal?.aborted) throw cancellationError(request.signal);
780
811
  if (overflow) throw new Error(`App-server output exceeded ${maximumOutputBytes} bytes.`);
781
812
  if (launchError) throw launchError;
782
813
  const envelope = responseEnvelope(stdout);
783
814
  if (envelope?.error) throw new AppServerRequestError(envelope.error.message?.trim() || "App-server request failed.", envelope.error.code, envelope.error.data);
784
- if (code !== 0) throw new Error(stderr.trim() || `App-server exited with status ${code}.`);
815
+ if (code !== 0) throw processError(stderr.trim() || `App-server exited with status ${code}.`, code);
785
816
  if (!envelope || !("result" in envelope)) throw new Error(stderr.trim() || "App-server did not return a response envelope.");
786
817
  return envelope.result;
787
818
  } finally {
@@ -1284,6 +1315,7 @@ async function runPluginCommand(args, options) {
1284
1315
  throw new Error(pluginUsage);
1285
1316
  } catch (error) {
1286
1317
  stderr.write(`Error: ${printableError(error)}\n`);
1318
+ if (error instanceof AppServerCancellationError || error instanceof AppServerProcessError) return error.exitCode;
1287
1319
  return error instanceof Error && error.name === "AbortError" ? 130 : 1;
1288
1320
  }
1289
1321
  }
@@ -1593,6 +1625,13 @@ function signalExitCode(signal) {
1593
1625
  const number = constants.signals[signal];
1594
1626
  return typeof number === "number" ? 128 + number : 1;
1595
1627
  }
1628
+ function abortSignalName(signal) {
1629
+ const reason = signal.reason;
1630
+ return reason === "SIGINT" || reason === "SIGTERM" || reason === "SIGHUP" ? reason : void 0;
1631
+ }
1632
+ function abortSignalExitCode(signal) {
1633
+ return signalExitCode(abortSignalName(signal) ?? "SIGINT");
1634
+ }
1596
1635
  async function waitForChild(child, onError = (error) => console.error("Error: " + error.message)) {
1597
1636
  return await new Promise((resolveExit) => {
1598
1637
  let settled = false;
@@ -1681,7 +1720,7 @@ async function runRuntime(node, args, extraEnv = {}) {
1681
1720
  }
1682
1721
  }
1683
1722
  async function completeOfficialZaiLogin(node, payload, runtimeArgs, abortSignal) {
1684
- if (abortSignal.aborted) return 130;
1723
+ if (abortSignal.aborted) return abortSignalExitCode(abortSignal);
1685
1724
  const child = spawn(node, [runtimePath, ...runtimeArgs], {
1686
1725
  cwd: process.cwd(),
1687
1726
  env: runtimeEnvironment({ ZCODE_CLI_OAUTH_CALLBACK_STDIN: "1" }),
@@ -1691,7 +1730,7 @@ async function completeOfficialZaiLogin(node, payload, runtimeArgs, abortSignal)
1691
1730
  "inherit"
1692
1731
  ]
1693
1732
  });
1694
- const onAbort = () => child.kill("SIGINT");
1733
+ const onAbort = () => child.kill(abortSignalName(abortSignal) ?? "SIGINT");
1695
1734
  abortSignal.addEventListener("abort", onAbort, { once: true });
1696
1735
  try {
1697
1736
  child.stdin?.end(JSON.stringify(payload));
@@ -1727,9 +1766,13 @@ async function main(args) {
1727
1766
  }
1728
1767
  const node = resolveNodeExecutable();
1729
1768
  const pluginAbortController = new AbortController();
1730
- const cancelPluginCommand = () => pluginAbortController.abort();
1731
- process.once("SIGINT", cancelPluginCommand);
1732
- process.once("SIGTERM", cancelPluginCommand);
1769
+ const cancelPluginCommand = (signal) => () => pluginAbortController.abort(signal);
1770
+ const onPluginSigint = cancelPluginCommand("SIGINT");
1771
+ const onPluginSigterm = cancelPluginCommand("SIGTERM");
1772
+ const onPluginSighup = cancelPluginCommand("SIGHUP");
1773
+ process.once("SIGINT", onPluginSigint);
1774
+ process.once("SIGTERM", onPluginSigterm);
1775
+ if (process.platform !== "win32") process.once("SIGHUP", onPluginSighup);
1733
1776
  let pluginCommand;
1734
1777
  try {
1735
1778
  pluginCommand = await runPluginCommand(args, {
@@ -1747,8 +1790,9 @@ async function main(args) {
1747
1790
  signal: pluginAbortController.signal
1748
1791
  });
1749
1792
  } finally {
1750
- process.off("SIGINT", cancelPluginCommand);
1751
- process.off("SIGTERM", cancelPluginCommand);
1793
+ process.off("SIGINT", onPluginSigint);
1794
+ process.off("SIGTERM", onPluginSigterm);
1795
+ if (process.platform !== "win32") process.off("SIGHUP", onPluginSighup);
1752
1796
  }
1753
1797
  if (pluginCommand !== void 0) return pluginCommand;
1754
1798
  const login = normalizeLoginArgs(args);
@@ -1762,9 +1806,13 @@ async function main(args) {
1762
1806
  }
1763
1807
  if (zaiOAuth) {
1764
1808
  const abortController = new AbortController();
1765
- const cancel = () => abortController.abort(/* @__PURE__ */ new Error("Login cancelled."));
1766
- process.once("SIGINT", cancel);
1767
- process.once("SIGTERM", cancel);
1809
+ const cancel = (signal) => () => abortController.abort(signal);
1810
+ const onSigint = cancel("SIGINT");
1811
+ const onSigterm = cancel("SIGTERM");
1812
+ const onSighup = cancel("SIGHUP");
1813
+ process.once("SIGINT", onSigint);
1814
+ process.once("SIGTERM", onSigterm);
1815
+ if (process.platform !== "win32") process.once("SIGHUP", onSighup);
1768
1816
  try {
1769
1817
  const code = await runZaiOAuthLogin({
1770
1818
  abortSignal: abortController.signal,
@@ -1776,10 +1824,11 @@ async function main(args) {
1776
1824
  return code;
1777
1825
  } catch (error) {
1778
1826
  console.error(`Error: ${error instanceof Error ? error.message : String(error)}`);
1779
- return abortController.signal.aborted ? 130 : 1;
1827
+ return abortController.signal.aborted ? abortSignalExitCode(abortController.signal) : 1;
1780
1828
  } finally {
1781
- process.off("SIGINT", cancel);
1782
- process.off("SIGTERM", cancel);
1829
+ process.off("SIGINT", onSigint);
1830
+ process.off("SIGTERM", onSigterm);
1831
+ if (process.platform !== "win32") process.off("SIGHUP", onSighup);
1783
1832
  }
1784
1833
  }
1785
1834
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zcode-app-cli",
3
- "version": "3.11.2-24",
3
+ "version": "3.11.2-25",
4
4
  "description": "Unofficial terminal client for the ZCode agent runtime",
5
5
  "keywords": [
6
6
  "agent",
@@ -52,11 +52,15 @@
52
52
  "check:oauth-callback": "bun scripts/smoke-oauth-callback.ts",
53
53
  "check:tui": "bun scripts/smoke-tui.ts && bun scripts/smoke-tui-features.ts && bun scripts/smoke-tui-clear.ts && bun scripts/smoke-tui-session-title.ts && bun scripts/smoke-tui-pressure.ts && bun scripts/smoke-tui-widths.ts && bun scripts/smoke-tui-fullscreen.ts && bun scripts/smoke-tui-fullscreen-switch.ts && bun scripts/smoke-tui-fullscreen-layout.ts",
54
54
  "check:tui-scenarios": "bun run test:tui",
55
- "test": "bun run test:fast",
56
- "test:all": "bun run test:fast && bun run test:tui && bun run test:runtime",
57
- "test:fast": "bun test test/*.test.ts",
55
+ "test": "bun run test:unit",
56
+ "test:all": "bun run test:unit && bun run test:tui && bun run test:runtime",
57
+ "test:unit": "bun test test/*.test.ts",
58
+ "test:fast": "bun run test:unit",
58
59
  "test:runtime": "bun test test/runtime/*.test.ts",
59
- "test:tui": "bun test test/tui/*.test.ts",
60
+ "test:tui": "bun run test:tui:component && bun run test:tui:e2e",
61
+ "test:tui:component": "bun test test/tui/scenario-http.test.ts test/tui/scenario-runtime.test.ts test/tui/scenario-shell.test.ts test/tui/scenario-workspace.test.ts test/tui/terminal-screen.test.ts",
62
+ "test:tui:e2e": "bun test test/tui/allowlisted-shell.test.ts test/tui/http-mock.test.ts test/tui/model-resume.test.ts test/tui/permission-request-queue.test.ts test/tui/run-scenario.test.ts test/tui/terminal-session.test.ts test/tui/write-and-diff.test.ts",
63
+ "test:tui:host": "bun test test/tui/scenario-mountx.test.ts",
60
64
  "test:tui:manual": "bun scripts/tui-scenario.ts --manual",
61
65
  "test:tui-scenario": "bun scripts/tui-scenario.ts",
62
66
  "typecheck": "tsc --noEmit",
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "appVersion": "3.11.2",
3
3
  "cliVersion": "0.16.5",
4
- "extractedAt": "2026-09-11T20:51:11.565Z",
4
+ "extractedAt": "2026-09-15T01:28:23.429Z",
5
5
  "sha512": "4UAMZSP9ZWBrnb8wGaP39rb5dB5ikPx4aYPXKXGea1Vmd6L6vGma3rXwRxKbhBxgsCIE9jv6tmrdSL60RrzGcA==",
6
6
  "source": "https://cdn-zcode.z.ai/zcode/electron/releases/3.11.2/linux-x64/ZCode-3.11.2-linux-x64.deb",
7
7
  "runtimeCapabilities": {
@@ -158875,6 +158875,10 @@ function restoredMessages(value) {
158875
158875
  const rawRole = asString(item.role) ?? (info && asString(info.role));
158876
158876
  const role = rawRole === "user" ? "user" : rawRole === "assistant" || rawRole === "agent" ? "assistant" : "system";
158877
158877
  const direct = asString(item.text) ?? asString(item.content);
158878
+ const model = modelReference(item.model) ?? modelReference({
158879
+ providerId: item.providerId ?? item.providerID ?? (info && (info.providerId ?? info.providerID)),
158880
+ modelId: item.modelId ?? item.modelID ?? (info && (info.modelId ?? info.modelID))
158881
+ });
158878
158882
  const structured = Array.isArray(item.parts) ? item.parts.map(normalizeRestoredPart).filter((part) => Boolean(part)) : [];
158879
158883
  const hasTextPart = structured.some((part) => part.type === "text");
158880
158884
  const parts = direct && !hasTextPart ? [{
@@ -158883,6 +158887,7 @@ function restoredMessages(value) {
158883
158887
  }, ...structured] : structured;
158884
158888
  if (parts.length > 0) messages.push({
158885
158889
  messageId: asString(item.messageId) ?? asString(item.messageID) ?? (info && (asString(info.messageId) ?? asString(info.id))),
158890
+ ...model ? { model } : {},
158886
158891
  role,
158887
158892
  parts
158888
158893
  });
@@ -162141,10 +162146,41 @@ var AppServerRequestError = class extends Error {
162141
162146
  this.name = "AppServerRequestError";
162142
162147
  }
162143
162148
  };
162144
- function cancellationError() {
162145
- const error = /* @__PURE__ */ new Error("App-server request cancelled.");
162146
- error.name = "AbortError";
162147
- return error;
162149
+ var AppServerProcessError = class extends Error {
162150
+ exitCode;
162151
+ constructor(message, exitCode) {
162152
+ super(message);
162153
+ this.exitCode = exitCode;
162154
+ this.name = "AppServerProcessError";
162155
+ }
162156
+ };
162157
+ var AppServerCancellationError = class extends Error {
162158
+ exitCode;
162159
+ constructor(exitCode) {
162160
+ super("App-server request cancelled.");
162161
+ this.exitCode = exitCode;
162162
+ this.name = "AbortError";
162163
+ }
162164
+ };
162165
+ function signalExitCode$1(signal) {
162166
+ if (!signal) return 1;
162167
+ const number = constants$1.signals[signal];
162168
+ return typeof number === "number" ? 128 + number : 1;
162169
+ }
162170
+ function abortSignalName(signal) {
162171
+ const reason = signal?.reason;
162172
+ return reason === "SIGINT" || reason === "SIGTERM" || reason === "SIGHUP" ? reason : void 0;
162173
+ }
162174
+ function cancellationError(signal) {
162175
+ const signalName = abortSignalName(signal);
162176
+ if (signalName) return new AppServerCancellationError(signalExitCode$1(signalName));
162177
+ return new AppServerCancellationError(130);
162178
+ }
162179
+ function terminationSignal(signal) {
162180
+ return abortSignalName(signal) ?? "SIGTERM";
162181
+ }
162182
+ function processError(message, code) {
162183
+ return new AppServerProcessError(message, code);
162148
162184
  }
162149
162185
  async function readBounded(stream, onOverflow) {
162150
162186
  if (!stream) return "";
@@ -162174,7 +162210,7 @@ function responseEnvelope(stdout) {
162174
162210
  }
162175
162211
  }
162176
162212
  async function requestAppServer(request) {
162177
- if (request.signal?.aborted) throw cancellationError();
162213
+ if (request.signal?.aborted) throw cancellationError(request.signal);
162178
162214
  const child = spawn(request.transport.command, request.transport.args, {
162179
162215
  cwd: request.transport.cwd,
162180
162216
  env: request.transport.env,
@@ -162199,7 +162235,7 @@ async function requestAppServer(request) {
162199
162235
  launchError = error;
162200
162236
  finish(1);
162201
162237
  });
162202
- child.once("close", (code) => finish(code ?? 1));
162238
+ child.once("close", (code, signal) => finish(code ?? signalExitCode$1(signal)));
162203
162239
  });
162204
162240
  const terminateForOverflow = () => {
162205
162241
  overflow = true;
@@ -162207,7 +162243,7 @@ async function requestAppServer(request) {
162207
162243
  };
162208
162244
  const onAbort = () => {
162209
162245
  if (child.exitCode !== null || child.signalCode !== null) return;
162210
- child.kill("SIGTERM");
162246
+ child.kill(terminationSignal(request.signal));
162211
162247
  forceTerminationTimer = setTimeout(() => {
162212
162248
  if (child.exitCode === null && child.signalCode === null) child.kill("SIGKILL");
162213
162249
  }, forceTerminationDelayMilliseconds);
@@ -162227,12 +162263,12 @@ async function requestAppServer(request) {
162227
162263
  readBounded(child.stdout, terminateForOverflow),
162228
162264
  readBounded(child.stderr, terminateForOverflow)
162229
162265
  ]);
162230
- if (request.signal?.aborted) throw cancellationError();
162266
+ if (request.signal?.aborted) throw cancellationError(request.signal);
162231
162267
  if (overflow) throw new Error(`App-server output exceeded ${maximumOutputBytes} bytes.`);
162232
162268
  if (launchError) throw launchError;
162233
162269
  const envelope = responseEnvelope(stdout);
162234
162270
  if (envelope?.error) throw new AppServerRequestError(envelope.error.message?.trim() || "App-server request failed.", envelope.error.code, envelope.error.data);
162235
- if (code !== 0) throw new Error(stderr.trim() || `App-server exited with status ${code}.`);
162271
+ if (code !== 0) throw processError(stderr.trim() || `App-server exited with status ${code}.`, code);
162236
162272
  if (!envelope || !("result" in envelope)) throw new Error(stderr.trim() || "App-server did not return a response envelope.");
162237
162273
  return envelope.result;
162238
162274
  } finally {
@@ -167884,7 +167920,7 @@ var ZCodeTui = class {
167884
167920
  this.recordAssistantText(this.assistantStream.reconcile(response));
167885
167921
  }
167886
167922
  if (appliesToSetting(settingTarget, "mode") && typeof result.mode === "string") this.mode = normalizedMode(result.mode, this.mode);
167887
- if (appliesToSetting(settingTarget, "model") && result.model !== void 0) this.model = modelLabel$1(result.model);
167923
+ if (appliesToSetting(settingTarget, "model") && result.model !== void 0 && result.resetSessionProjection !== true) this.model = modelLabel$1(result.model);
167888
167924
  if (typeof result.loginRequired === "boolean") {
167889
167925
  this.setLoginRequired(result.loginRequired);
167890
167926
  if (!result.loginRequired && result.model === void 0 && appliesToSetting(settingTarget, "model")) {
@@ -167903,6 +167939,14 @@ var ZCodeTui = class {
167903
167939
  this.ui.requestRender();
167904
167940
  if (isRecord(result.workflowPanel)) await this.showWorkflowPanel(result.workflowPanel);
167905
167941
  if (isRecord(result.selection)) await this.showSelection(result.selection);
167942
+ if (result.resetSessionProjection === true) {
167943
+ try {
167944
+ const persistedModel = await this.options.readSessionModel?.();
167945
+ if (typeof persistedModel === "string" && persistedModel.trim()) this.model = persistedModel.trim();
167946
+ } catch {}
167947
+ this.updateMetadata();
167948
+ this.ui.requestRender();
167949
+ }
167906
167950
  }
167907
167951
  onEvent(value, turnEpoch) {
167908
167952
  this.debugEvent("session", value);
@@ -168718,6 +168762,7 @@ var ZCodeTui = class {
168718
168762
  }
168719
168763
  restoreTranscript(messages) {
168720
168764
  let firstUserMessageText;
168765
+ let lastAssistantModel;
168721
168766
  for (const message of messages) {
168722
168767
  this.currentToolGroup = void 0;
168723
168768
  this.currentToolGroupBlockId = void 0;
@@ -168731,6 +168776,7 @@ var ZCodeTui = class {
168731
168776
  }
168732
168777
  continue;
168733
168778
  }
168779
+ if (message.role === "assistant" && message.model) lastAssistantModel = message.model;
168734
168780
  const hiddenToolIds = message.role === "assistant" ? backgroundToolPartIds(message.parts) : /* @__PURE__ */ new Set();
168735
168781
  const coordinatesBackgroundAgents = message.parts.some(backgroundAgentPart);
168736
168782
  for (const part of message.parts) {
@@ -168754,6 +168800,7 @@ var ZCodeTui = class {
168754
168800
  this.currentToolGroupBlockId = void 0;
168755
168801
  this.currentToolGroupMessageId = void 0;
168756
168802
  this.assistantStream.breakSegment();
168803
+ if (lastAssistantModel) this.model = lastAssistantModel;
168757
168804
  }
168758
168805
  restorePart(part, role, fallbackMessageId) {
168759
168806
  const messageId = part.messageId ?? fallbackMessageId;
@@ -170591,13 +170638,16 @@ var ZCodeTui = class {
170591
170638
  }
170592
170639
  }
170593
170640
  async restoreInitialTranscript() {
170594
- if (!this.options.loadSessionTranscript) return;
170595
- try {
170641
+ if (this.options.loadSessionTranscript) try {
170596
170642
  this.restoreTranscript(restoredMessages(await this.options.loadSessionTranscript()));
170597
170643
  } catch (error) {
170598
170644
  const message = error instanceof Error ? error.message : String(error);
170599
170645
  this.addNotice(`Unable to restore session transcript: ${message}`, "warning");
170600
170646
  }
170647
+ try {
170648
+ const persistedModel = await this.options.readSessionModel?.();
170649
+ if (typeof persistedModel === "string" && persistedModel.trim()) this.model = persistedModel.trim();
170650
+ } catch {}
170601
170651
  }
170602
170652
  updateMetadata() {
170603
170653
  const fields = [{