@chatcode/chatcode-cli 3.0.5-rc.5 → 3.0.5-rc.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/lib/{command-errors-DGyKMxEq.js → command-errors-CnbcOM1a.js} +12 -12
  2. package/lib/{command-trees-Bh2WKUZ3.js → command-trees-CU7BxVJo.js} +2 -2
  3. package/lib/{component-identity-B7wyM-aN.js → component-identity-kZK1_hFy.js} +3 -3
  4. package/lib/{extension-events-JX8c4mnR.js → extension-events-hLxwPvpg.js} +20 -20
  5. package/lib/{host-access-ClndygbX.js → host-access-kT-u85k_.js} +1 -1
  6. package/lib/{keymap-nfqAZoFE.js → keymap-DS1M8sDo.js} +2 -2
  7. package/lib/{plugin-C9yd07Wb.js → plugin-d65VulBk.js} +583 -532
  8. package/lib/{scenes-C5_xUR61.js → scenes-DG6T8t-A.js} +3 -3
  9. package/lib/{settings-sections-CRhTUEBm.js → settings-sections-2SuE0biI.js} +3 -3
  10. package/lib/{statusBarSettings-ChS8Z4Jf.js → statusBarSettings-B2MEAwnI.js} +3 -3
  11. package/lib/{themes-bFi516uK.js → themes-DUO7kGW-.js} +12 -12
  12. package/lib/tui-compat-command-trees.js +1 -1
  13. package/lib/tui-compat-extensions.js +3 -3
  14. package/lib/tui-compat-plugin-host.js +5 -5
  15. package/lib/tui-compat-scenes.js +1 -1
  16. package/lib/tui-compat-settings-sections.js +1 -1
  17. package/lib/tui-compat-working-activity.js +1 -1
  18. package/lib/tui-compat-workspaces.js +1 -1
  19. package/lib/tui-compat.js +5 -5
  20. package/lib/{workspaces-ous4jIwo.js → workspaces-CLOkL_yE.js} +2 -2
  21. package/package.json +24 -24
  22. package/runtime/manifest.json +2 -2
  23. package/runtime/node_modules/@deepseek-ai/dsh-agent/lib/types/runtime-types.d.ts +16 -0
  24. package/runtime/node_modules/@deepseek-ai/dsh-agent-loop/lib/index.js +4 -0
  25. package/runtime/node_modules/@deepseek-ai/dsh-agent-preset-registry/lib/typert.host.js +1 -1
  26. package/runtime/node_modules/@deepseek-ai/dsh-api-session-controller/lib/typert.host.js +2 -2
  27. package/runtime/node_modules/@deepseek-ai/dsh-api-terminal-controller/lib/typert.host.js +1 -1
  28. package/runtime/node_modules/@deepseek-ai/dsh-atomic-write/lib/index.js +38 -38
  29. package/runtime/node_modules/@deepseek-ai/dsh-atomic-write/lib/types/index.d.ts +2 -2
  30. package/runtime/node_modules/@deepseek-ai/dsh-atomic-write/lib/types/linux-lock.d.ts +1 -1
  31. package/runtime/node_modules/@deepseek-ai/dsh-atomic-write/lib/types/windows-lock.d.ts +1 -1
  32. package/runtime/node_modules/@deepseek-ai/dsh-client-file-upload/lib/typert.host.js +1 -1
  33. package/runtime/node_modules/@deepseek-ai/dsh-client-ui-settings-account/lib/client.js +2 -2
  34. package/runtime/node_modules/@deepseek-ai/dsh-client-ui-settings-general/lib/client.js +1 -1
  35. package/runtime/node_modules/@deepseek-ai/dsh-client-ui-sidebar/lib/client.js +1 -1
  36. package/runtime/node_modules/@deepseek-ai/dsh-commands/lib/typert.host.js +1 -1
  37. package/runtime/node_modules/@deepseek-ai/dsh-cordis-host-runner/lib/typert.host.js +2 -2
  38. package/runtime/node_modules/@deepseek-ai/dsh-goal/lib/typert.host.js +1 -1
  39. package/runtime/node_modules/@deepseek-ai/dsh-llm-deepseek/lib/index.js +77 -10
  40. package/runtime/node_modules/@deepseek-ai/dsh-llm-deepseek/lib/types/error-diagnostic.d.ts +15 -0
  41. package/runtime/node_modules/@deepseek-ai/dsh-llm-deepseek/lib/types/protocol-adapter.d.ts +1 -1
  42. package/runtime/node_modules/@deepseek-ai/dsh-llm-deepseek/lib/types/transport.d.ts +1 -1
  43. package/runtime/node_modules/@deepseek-ai/dsh-scope/lib/invariant.js +1 -0
  44. package/runtime/node_modules/@deepseek-ai/dsh-session-reference/lib/typert.host.js +1 -1
  45. package/runtime/node_modules/@deepseek-ai/dsh-subagent/lib/index.js +51 -9
  46. package/runtime/node_modules/@deepseek-ai/dsh-subagent/lib/typert.host.js +1 -1
  47. package/runtime/node_modules/@deepseek-ai/dsh-subagent/lib/types/archive-admission.d.ts +13 -0
  48. package/runtime/node_modules/@deepseek-ai/dsh-subagent/lib/types/archive-admission.js +20 -6
  49. package/runtime/node_modules/@deepseek-ai/dsh-subagent/lib/types/continuation-activation.d.ts +4 -0
  50. package/runtime/node_modules/@deepseek-ai/dsh-subagent/lib/types/continuation-activation.js +42 -3
  51. package/runtime/node_modules/@deepseek-ai/dsh-subagent/lib/types/control.d.ts +1 -1
  52. package/runtime/node_modules/@deepseek-ai/dsh-tool-cordis/lib/types/api-catalog.js +12 -0
  53. package/runtime/node_modules/@deepseek-ai/dsh-web-frontend/dist/chatcode-apple-touch-icon.png +0 -0
  54. package/runtime/node_modules/@deepseek-ai/dsh-web-frontend/dist/chatcode-icon-32.png +0 -0
  55. package/runtime/node_modules/@deepseek-ai/dsh-web-frontend/dist/chatcode-mask-icon.svg +1 -1
  56. package/runtime/node_modules/@deepseek-ai/dsh-web-frontend/dist/favicon-dark.svg +1 -1
  57. package/runtime/node_modules/@deepseek-ai/dsh-web-frontend/dist/favicon.ico +0 -0
  58. package/runtime/node_modules/@deepseek-ai/dsh-web-frontend/dist/favicon.svg +1 -1
  59. package/runtime/node_modules/@deepseek-ai/dsh-web-frontend/dist/index.html +5 -5
  60. package/runtime/node_modules/@deepseek-ai/dsh-web-frontend/dist/logo.png +0 -0
  61. package/runtime/node_modules/@deepseek-ai/dsh-web-frontend/dist/preview.html +5 -5
@@ -4125,7 +4125,7 @@ window.__ModuleLoader__.load({
4125
4125
  for (const listener of listeners) listener();
4126
4126
  };
4127
4127
  /** @returns the client identity for one account call, read at call time so it carries the language and zone in effect then. */
4128
- const client = () => accountClientMetadata(ctx.locale.getSnapshot().active, "3.0.5-rc.5");
4128
+ const client = () => accountClientMetadata(ctx.locale.getSnapshot().active, "3.0.5-rc.7");
4129
4129
  const notices = createBonusNoticeController({
4130
4130
  ackRetryDelayMs: config.bonusAckRetryDelayMs,
4131
4131
  ackRetryMaxDelayMs: config.bonusAckRetryMaxDelayMs,
@@ -4256,7 +4256,7 @@ window.__ModuleLoader__.load({
4256
4256
  refreshAccount,
4257
4257
  contactUs() {
4258
4258
  const url = contactUrl(config, {
4259
- version: "3.0.5-rc.5",
4259
+ version: "3.0.5-rc.7",
4260
4260
  locale: ctx.locale.getSnapshot().active === "zh" ? "zh-CN" : "en",
4261
4261
  width: window.screen.width,
4262
4262
  height: window.screen.height,
@@ -657,7 +657,7 @@ window.__ModuleLoader__.load({
657
657
  function CurrentVersionRow({ t }) {
658
658
  return (0, react_jsx_runtime.jsx)("div", {
659
659
  className: CurrentVersionRow_module_css_default.row,
660
- children: t("general.currentVersion", { version: "3.0.5-rc.5" })
660
+ children: t("general.currentVersion", { version: "3.0.5-rc.7" })
661
661
  });
662
662
  }
663
663
  //#endregion
@@ -167,7 +167,7 @@ window.__ModuleLoader__.load({
167
167
  const SCROLLBAR_LINGER_MS = 2e3;
168
168
  /** Format complete-build metadata for the local brand badge. */
169
169
  function localBuildVersion() {
170
- return `3.0.5-rc.5-e398502-dirty`;
170
+ return `3.0.5-rc.7-3bb55ac-dirty`;
171
171
  }
172
172
  /** Each panel row subscribes only to its own selection state. */
173
173
  function PanelRow({ id, label, wide, usePanelInfo, selectPanel, renderSlot }) {
@@ -246,7 +246,7 @@ export const TYPERT = {
246
246
  },
247
247
  {
248
248
  "name": "CancelOptions",
249
- "declaration": "export interface CancelOptions {\n keepInbox?: boolean | undefined;\n}"
249
+ "declaration": "export interface CancelOptions {\n keepChildren?: boolean | undefined;\n keepInbox?: boolean | undefined;\n}"
250
250
  },
251
251
  {
252
252
  "name": "CommandDefinition",
@@ -930,7 +930,7 @@ export const TYPERT = {
930
930
  },
931
931
  {
932
932
  "name": "CancelOptions",
933
- "declaration": "export interface CancelOptions {\n keepInbox?: boolean | undefined;\n}"
933
+ "declaration": "export interface CancelOptions {\n keepChildren?: boolean | undefined;\n keepInbox?: boolean | undefined;\n}"
934
934
  },
935
935
  {
936
936
  "name": "CommandId",
@@ -1673,7 +1673,7 @@ export const TYPERT = {
1673
1673
  },
1674
1674
  {
1675
1675
  "name": "CancelOptions",
1676
- "declaration": "export interface CancelOptions {\n keepInbox?: boolean | undefined;\n}"
1676
+ "declaration": "export interface CancelOptions {\n keepChildren?: boolean | undefined;\n keepInbox?: boolean | undefined;\n}"
1677
1677
  },
1678
1678
  {
1679
1679
  "name": "CommandId",
@@ -579,7 +579,7 @@ export const TYPERT = {
579
579
  },
580
580
  {
581
581
  "name": "CancelOptions",
582
- "declaration": "export interface CancelOptions {\n keepInbox?: boolean | undefined;\n}"
582
+ "declaration": "export interface CancelOptions {\n keepChildren?: boolean | undefined;\n keepInbox?: boolean | undefined;\n}"
583
583
  },
584
584
  {
585
585
  "name": "CommandId",
@@ -1,6 +1,6 @@
1
1
  import z from "@deepseek-ai/schemastery";
2
2
  import { isVolatile } from "@deepseek-ai/cosmokit";
3
- import { EMPTY_RESPONSE_CODE, IMAGE_OFFLOAD_REQUIRED_CODE, LlmAdapter, LlmError, ProviderRequestId, ReasoningEffortId, RetryPolicySchema, ToolCallId, attributionHeaders, contentHasImage, isContextWindowExceededError, isQuotaExceededError, offloadedImageText, projectOffloadedImages, requestImageHandleText, requiredImageOffload, resolveImageAttachmentAccess, resolveRetryPolicy, textOnlyImageText } from "@deepseek-ai/dsh-llm";
3
+ import { EMPTY_RESPONSE_CODE, IMAGE_OFFLOAD_REQUIRED_CODE, LlmAdapter, LlmError, ProviderRequestId, ReasoningEffortId, RetryPolicySchema, ToolCallId, attributionHeaders, contentHasImage, errorChain, isContextWindowExceededError, isQuotaExceededError, offloadedImageText, projectOffloadedImages, requestImageHandleText, requiredImageOffload, resolveImageAttachmentAccess, resolveRetryPolicy, textOnlyImageText } from "@deepseek-ai/dsh-llm";
4
4
  import { MAX_TIMER_DELAY_MS, deadline, idleWatchdog, timeoutOf } from "@deepseek-ai/dsh-timeout";
5
5
  import { ImageVariantId, longEdgeDimensions, requestImageDimensions } from "@deepseek-ai/dsh-attachment";
6
6
  import { createHash } from "node:crypto";
@@ -1483,8 +1483,57 @@ async function prepareFileIds(messages, versions, files) {
1483
1483
  return ids;
1484
1484
  }
1485
1485
  //#endregion
1486
+ //#region lib/types/error-diagnostic.js
1487
+ /** Bounded provider diagnostics with request credentials and endpoint addresses removed. */
1488
+ /**
1489
+ * Remove credentials, URLs, terminal controls, and oversized response text.
1490
+ * @param value - provider message or diagnostic cause.
1491
+ * @param secrets - credential and endpoint values captured for this request.
1492
+ * @returns a single-line diagnostic capped after redaction.
1493
+ */
1494
+ function redactProviderDiagnostic(value, secrets = []) {
1495
+ let text = value.replace(/\u001b\][^\u0007]*(?:\u0007|\u001b\\)/gu, "").replace(/\u001b\[[0-?]*[ -/]*[@-~]/gu, "");
1496
+ const variants = secrets.filter((value) => value.length > 0).flatMap((value) => [
1497
+ value,
1498
+ encodeURIComponent(value),
1499
+ JSON.stringify(value).slice(1, -1)
1500
+ ]).sort((a, b) => b.length - a.length);
1501
+ for (const secret of variants) if (secret.length >= 8) text = text.split(secret).join("[REDACTED]");
1502
+ else {
1503
+ const literal = secret.replace(/[.*+?^${}()|[\]\\]/gu, "\\$&");
1504
+ text = text.replace(new RegExp(`(?<![\\p{L}\\p{N}_-])${literal}(?![\\p{L}\\p{N}_-])`, "gu"), "[REDACTED]");
1505
+ }
1506
+ text = text.replace(/\bhttps?:\/\/[^\s<>"'`\\]+/giu, "[REDACTED]").replace(/\b(Bearer|Basic)\s+[a-z0-9._~+\/-]+=*/giu, "$1 [REDACTED]").replace(/((?:["']?(?:[\w-]*api[ _-]?key|authorization|[\w-]*token|password|secret|base[ _-]?url)["']?)\s*[:=]\s*)(?:(?:Bearer|Basic)\s+)?(?:\[REDACTED\]|"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|[^\s,;}\]]+)/giu, "$1[REDACTED]").replace(/\bsk-[a-z0-9_-]+/giu, "[REDACTED]").replace(/[\x00-\x1f\x7f-\x9f]/gu, " ").replace(/\s+/gu, " ").trim();
1507
+ return text.length <= 4096 ? text : `${text.slice(0, 4095)}…`;
1508
+ }
1509
+ /**
1510
+ * Extract human-readable fields without dumping arbitrary JSON response data.
1511
+ * @param raw - decoded provider error, or a non-JSON response body.
1512
+ * @returns the first nonempty message, detail, msg, or error string.
1513
+ */
1514
+ function providerDiagnosticMessage(raw) {
1515
+ const read = (value, depth) => {
1516
+ if (typeof value === "string") return value.trim();
1517
+ if (depth === 0 || typeof value !== "object" || value === null) return "";
1518
+ for (const key of [
1519
+ "error",
1520
+ "message",
1521
+ "detail",
1522
+ "msg"
1523
+ ]) {
1524
+ if (!(key in value)) continue;
1525
+ const text = read(value[key], depth - 1);
1526
+ if (text !== "") return text;
1527
+ }
1528
+ return "";
1529
+ };
1530
+ const message = read(raw, 3);
1531
+ if (!/<(?:!doctype\s+html|html|head|body|title)\b|<\/[a-z][^>]*>/iu.test(message)) return message;
1532
+ return message.replace(/<(script|style)\b[^>]*>[\s\S]*?<\/\1\s*>/giu, "").replace(/<[^>]*>/gu, " ").replace(/&nbsp;/giu, " ");
1533
+ }
1534
+ //#endregion
1486
1535
  //#region lib/types/transport.js
1487
- /** Normalize HTTP and in-band Messages errors into provider-neutral failures. */
1536
+ /** Normalize HTTP and in-band provider errors; the request owner redacts captured secrets. */
1488
1537
  /** Read only provider error fields used by bounded Files recovery.
1489
1538
  * @param raw - decoded HTTP error response.
1490
1539
  * @returns code, type, and message text, without unrelated response fields.
@@ -1509,7 +1558,7 @@ function providerErrorDetail(raw) {
1509
1558
  function providerError(raw, status, headers, protocol = "Messages") {
1510
1559
  const envelope = typeof raw === "object" && raw !== null ? raw : {};
1511
1560
  const error = typeof envelope.error === "object" && envelope.error !== null ? envelope.error : {};
1512
- const message = typeof error.message === "string" ? error.message : `DeepSeek ${protocol} request failed (${status ?? "stream error"})`;
1561
+ const message = providerDiagnosticMessage(raw).trim() || `DeepSeek ${protocol} request failed (${status ?? "stream error"})`;
1513
1562
  const type = typeof error.type === "string" ? error.type : "";
1514
1563
  const detail = `${type} ${typeof error.code === "string" ? error.code : ""} ${message}`;
1515
1564
  let code;
@@ -1683,6 +1732,11 @@ var DeepSeekProtocolAdapter = class extends LlmAdapter {
1683
1732
  signal.throwIfAborted();
1684
1733
  const { messages, versions } = await prepareImages(options.messages, connection, options.model, this.dependencies.resolveAttachments?.(), this.imageAccess, signal);
1685
1734
  const auth = await this.dependencies.resolveAuth(connection);
1735
+ const secrets = [
1736
+ connection.baseURL,
1737
+ new URL(connection.baseURL).host,
1738
+ ...Object.values(auth.headers).flatMap((value) => [value, value.replace(/^(?:Bearer|Basic)\s+/iu, "")])
1739
+ ];
1686
1740
  try {
1687
1741
  const files = new RequestFiles(this.files, {
1688
1742
  baseURL: connection.baseURL,
@@ -1739,16 +1793,16 @@ var DeepSeekProtocolAdapter = class extends LlmAdapter {
1739
1793
  });
1740
1794
  if (!response.ok) {
1741
1795
  const text = await response.text();
1742
- let raw;
1796
+ let raw = text;
1743
1797
  try {
1744
1798
  raw = JSON.parse(text);
1745
1799
  } catch (_nonJsonGatewayError) {}
1746
1800
  const detail = providerErrorDetail(raw);
1747
1801
  if (await files.retry(detail)) continue;
1748
1802
  const failure = providerError(raw, response.status, response.headers, this.protocol.name);
1749
- throw new LlmError(files.errorMessage(response.status, failure.message, detail), failure.code, {
1803
+ throw new LlmError(redactProviderDiagnostic(files.errorMessage(response.status, failure.message, detail), secrets), failure.code, {
1750
1804
  ...failure.failure,
1751
- cause: new Error(text)
1805
+ cause: new Error(redactProviderDiagnostic(text, secrets))
1752
1806
  });
1753
1807
  }
1754
1808
  await extensions.accept();
@@ -1757,16 +1811,28 @@ var DeepSeekProtocolAdapter = class extends LlmAdapter {
1757
1811
  return;
1758
1812
  }
1759
1813
  } catch (error) {
1814
+ let safeError = error;
1815
+ if (error instanceof Error) {
1816
+ const message = redactProviderDiagnostic(error.message, secrets);
1817
+ const cause = error.cause === void 0 ? void 0 : redactProviderDiagnostic(errorChain(error.cause), secrets);
1818
+ if (message !== error.message || cause !== void 0 && cause !== errorChain(error.cause)) {
1819
+ const options = cause === void 0 ? {} : { cause: new Error(cause) };
1820
+ safeError = error instanceof LlmError ? new LlmError(message, error.code, {
1821
+ ...error.failure,
1822
+ ...options
1823
+ }) : new Error(message, options);
1824
+ }
1825
+ }
1760
1826
  if (auth.onRequestError !== void 0) {
1761
1827
  let mapped;
1762
1828
  try {
1763
- mapped = await auth.onRequestError(error);
1829
+ mapped = await auth.onRequestError(safeError);
1764
1830
  } catch (_credentialUpdateFailed) {
1765
- throw error;
1831
+ throw safeError;
1766
1832
  }
1767
1833
  throw mapped;
1768
1834
  }
1769
- throw error;
1835
+ throw safeError;
1770
1836
  }
1771
1837
  }
1772
1838
  };
@@ -2590,8 +2656,9 @@ async function* translate(payloads) {
2590
2656
  try {
2591
2657
  chunk = JSON.parse(payload);
2592
2658
  } catch (_invalidProviderJson) {
2593
- throw new LlmError(`malformed SSE payload: ${payload.slice(0, 120)}`, "MALFORMED_RESPONSE");
2659
+ throw new LlmError("malformed SSE payload", "MALFORMED_RESPONSE");
2594
2660
  }
2661
+ if ("error" in chunk) throw providerError(chunk, void 0, void 0, "Chat Completions");
2595
2662
  for (const choice of chunk.choices ?? []) {
2596
2663
  const delta = choice.delta;
2597
2664
  const reasoning = delta?.reasoning_content;
@@ -0,0 +1,15 @@
1
+ /** Bounded provider diagnostics with request credentials and endpoint addresses removed. */
2
+ /**
3
+ * Remove credentials, URLs, terminal controls, and oversized response text.
4
+ * @param value - provider message or diagnostic cause.
5
+ * @param secrets - credential and endpoint values captured for this request.
6
+ * @returns a single-line diagnostic capped after redaction.
7
+ */
8
+ export declare function redactProviderDiagnostic(value: string, secrets?: readonly string[]): string;
9
+ /**
10
+ * Extract human-readable fields without dumping arbitrary JSON response data.
11
+ * @param raw - decoded provider error, or a non-JSON response body.
12
+ * @returns the first nonempty message, detail, msg, or error string.
13
+ */
14
+ export declare function providerDiagnosticMessage(raw: unknown): string;
15
+ //# sourceMappingURL=error-diagnostic.d.ts.map
@@ -19,7 +19,7 @@ export declare class DeepSeekProtocolAdapter<C extends Connection = Connection>
19
19
  name: string;
20
20
  };
21
21
  providerRetryPolicy(_provider: string): import("@deepseek-ai/dsh-llm").ResolvedRetryPolicy;
22
- listModels(provider: string): Promise<never[] | import("@deepseek-ai/dsh-llm").LlmModelInfo[]>;
22
+ listModels(provider: string): Promise<import("@deepseek-ai/dsh-llm").LlmModelInfo[] | never[]>;
23
23
  resolveModel(provider: string, model: string, _signal?: AbortSignal): Promise<{
24
24
  context?: import("@deepseek-ai/dsh-llm").LlmModelContext;
25
25
  defaultMaxTokens?: number;
@@ -1,4 +1,4 @@
1
- /** Normalize HTTP and in-band Messages errors into provider-neutral failures. */
1
+ /** Normalize HTTP and in-band provider errors; the request owner redacts captured secrets. */
2
2
  import { LlmError } from '@deepseek-ai/dsh-llm';
3
3
  /** Read only provider error fields used by bounded Files recovery.
4
4
  * @param raw - decoded HTTP error response.
@@ -8,6 +8,7 @@ import { carrierKeyOf, isScopeCarrier } from "@deepseek-ai/dsh-scope";
8
8
  */
9
9
  const scopedSubjectResolvers = Object.freeze({
10
10
  "agent/assistant-stream": (args) => args[0]["agent"],
11
+ "agent/cancelled": (args) => args[0]["agent"],
11
12
  "agent/created": (args) => args[0]["agent"],
12
13
  "agent/disposed": (args) => args[0]["agent"],
13
14
  "agent/error": (args) => args[0]["agent"],
@@ -164,7 +164,7 @@ export const TYPERT = {
164
164
  },
165
165
  {
166
166
  "name": "CancelOptions",
167
- "declaration": "export interface CancelOptions {\n keepInbox?: boolean | undefined;\n}"
167
+ "declaration": "export interface CancelOptions {\n keepChildren?: boolean | undefined;\n keepInbox?: boolean | undefined;\n}"
168
168
  },
169
169
  {
170
170
  "name": "CommandId",
@@ -733,6 +733,15 @@ var ActivationPool = class {
733
733
  };
734
734
  }
735
735
  };
736
+ /** Retain task ancestry through handle release, stopping at independent fork conversations. */
737
+ function taskAncestry(lineage) {
738
+ const task = [];
739
+ for (const agent of lineage) {
740
+ task.push(agent);
741
+ if (agent.session.header.origin !== "subagent") break;
742
+ }
743
+ return new WeakSet(task);
744
+ }
736
745
  /** Serialize each durable child's delivery, release, and disposal. */
737
746
  var ChildLock = class {
738
747
  tails = /* @__PURE__ */ new Map();
@@ -793,6 +802,16 @@ var ContinuableActivationRegistry = class {
793
802
  yield scope.dispose;
794
803
  yield () => this.drain();
795
804
  }.bind(this), "subagents.continuations()");
805
+ ctx.on("agent/cancelled", ({ agent, cause, options }) => {
806
+ if (cause.kind !== "user" || options.keepChildren || ctx.agents.get(agent.id) !== agent) return;
807
+ const descendants = [...this.resident.values()].filter((activation) => activation.handle.agent !== agent && activation.taskAncestry.has(agent));
808
+ for (const activation of descendants) activation.parentStopped = true;
809
+ for (const materialization of this.materializations) if (materialization.taskAncestry.has(agent)) materialization.cancellation.abort(/* @__PURE__ */ new Error("parent task stopped"));
810
+ for (const pending of [...agent.inbox.nextStep, ...agent.inbox.nextTurn]) if (pending.source.kind === "subagent-settled" || pending.source.kind === "agent-message") agent.inbox.remove(pending.id);
811
+ for (const activation of descendants) this.dispose(activation).catch((error) => {
812
+ ctx.logger.warn(`subagent "${activation.childId}" cancellation teardown failed: ${errorChain(error)}`);
813
+ });
814
+ });
796
815
  }
797
816
  /**
798
817
  * Return the live Activation for a durable child id, if resident.
@@ -852,7 +871,10 @@ var ContinuableActivationRegistry = class {
852
871
  if (activation.handle.agent.session.header.parentSession !== authority.parentSessionId) throw new SubagentError(`subagent "${targetSessionId}" belongs to another parent session`, "UNAUTHORIZED");
853
872
  } else if (!activation.ancestry.has(authority.agent)) throw new SubagentError(`subagent "${targetSessionId}" is not a live descendant of agent "${authority.agent.id}"`, "UNAUTHORIZED");
854
873
  if (activation.inbox.closing !== void 0) return;
855
- activation.handle.agent.cancel(authority.kind === "user" ? { kind: "user" } : { kind: "parent" }, { keepInbox: true });
874
+ activation.handle.agent.cancel(authority.kind === "user" ? { kind: "user" } : { kind: "parent" }, {
875
+ keepInbox: true,
876
+ keepChildren: true
877
+ });
856
878
  }
857
879
  /**
858
880
  * Send through a receiving parent's Activation inbox when it has one.
@@ -969,12 +991,19 @@ var ContinuableActivationRegistry = class {
969
991
  const pool = this.resident.get(inputs.parent.id)?.pool ?? this.rootPool(inputs.parent);
970
992
  const releaseSlot = pool.reserve(this.maxActiveSubagents());
971
993
  const settled = Promise.withResolvers();
994
+ const cancellation = new AbortController();
972
995
  const materialization = {
973
996
  lineage,
974
- settled: settled.promise
997
+ taskAncestry: taskAncestry(lineage),
998
+ settled: settled.promise,
999
+ cancellation
975
1000
  };
976
1001
  this.materializations.add(materialization);
977
- return this.materializeTracked(inputs, lineage, pool, releaseSlot).catch((error) => {
1002
+ const signal = AbortSignal.any([inputs.signal, cancellation.signal]);
1003
+ return this.materializeTracked({
1004
+ ...inputs,
1005
+ signal
1006
+ }, lineage, pool, releaseSlot).catch((error) => {
978
1007
  releaseSlot();
979
1008
  throw error;
980
1009
  }).finally(() => {
@@ -1098,9 +1127,11 @@ var ContinuableActivationRegistry = class {
1098
1127
  handle,
1099
1128
  inbox: new SubagentInbox(handle.agent),
1100
1129
  ancestry: new WeakSet([handle.agent, ...parentLineage]),
1130
+ taskAncestry: taskAncestry([handle.agent, ...parentLineage]),
1101
1131
  ownedChildren: /* @__PURE__ */ new Set(),
1102
1132
  observer,
1103
1133
  announced: false,
1134
+ parentStopped: false,
1104
1135
  poke: Promise.withResolvers()
1105
1136
  };
1106
1137
  this.resident.set(childId, activation);
@@ -1252,7 +1283,7 @@ var ContinuableActivationRegistry = class {
1252
1283
  }
1253
1284
  /** Tell the durable direct parent how this Activation ended. */
1254
1285
  notifySettlement(activation, terminal) {
1255
- if (!activation.announced) return;
1286
+ if (!activation.announced || activation.parentStopped) return;
1256
1287
  try {
1257
1288
  const parent = this.ctx.agents.get(activation.parentSession);
1258
1289
  if (parent === void 0) return;
@@ -2241,8 +2272,16 @@ var __disposeResources = (function(SuppressedError) {
2241
2272
  * @param ctx - context carrying the Agent registry; the Session query service is optional and only supplies labels.
2242
2273
  */
2243
2274
  function installSubagentArchiveAdmission(ctx) {
2275
+ ctx.on("agent/cancelled", ({ agent, cause, options }) => {
2276
+ if (cause.kind !== "user" || options.keepChildren || ctx.agents.get(agent.id) !== agent) return;
2277
+ for (const child of subagentDescendants(ctx, agent.id)) try {
2278
+ child.cancel({ kind: "parent" });
2279
+ } catch (error) {
2280
+ ctx.logger.warn(`subagent: cancelling "${child.id}" for a stopped parent failed: ${String(error)}`);
2281
+ }
2282
+ });
2244
2283
  ctx.on("workspace/session-activity", async ({ sessionId }, next) => {
2245
- const running = runningDescendants(ctx, sessionId);
2284
+ const running = subagentDescendants(ctx, sessionId).filter((child) => child.status === "running");
2246
2285
  const rest = await next();
2247
2286
  if (running.length === 0) return rest;
2248
2287
  return [{
@@ -2251,7 +2290,7 @@ function installSubagentArchiveAdmission(ctx) {
2251
2290
  }, ...rest];
2252
2291
  });
2253
2292
  ctx.on("workspace/session-stop", ({ sessionId }) => {
2254
- for (const child of runningDescendants(ctx, sessionId)) try {
2293
+ for (const child of subagentDescendants(ctx, sessionId).filter((child) => child.status === "running")) try {
2255
2294
  child.cancel({ kind: "parent" });
2256
2295
  } catch (error) {
2257
2296
  ctx.logger.warn(`subagent: cancelling "${child.id}" for an archived Session failed: ${String(error)}`);
@@ -2259,13 +2298,16 @@ function installSubagentArchiveAdmission(ctx) {
2259
2298
  });
2260
2299
  }
2261
2300
  /**
2262
- * Live subagent descendants inside a turn, by durable lineage: a child whose
2301
+ * Live subagent descendants by durable lineage: a child whose
2263
2302
  * header names its parent and carries the subagent origin this package
2264
2303
  * records, at any depth. A fork shares the lineage field without the origin
2265
2304
  * and is an independent conversation, so it never holds its source. Lineage
2266
2305
  * is read as data, so a damaged header chain that loops is visited once.
2306
+ * @param ctx - live Agent registry.
2307
+ * @param rootId - Session whose subagent descendants are selected.
2308
+ * @returns live descendants, including idle Agents with parked inbox work.
2267
2309
  */
2268
- function runningDescendants(ctx, rootId) {
2310
+ function subagentDescendants(ctx, rootId) {
2269
2311
  const childrenOf = /* @__PURE__ */ new Map();
2270
2312
  for (const agent of ctx.agents.list()) {
2271
2313
  const { parentSession, origin } = agent.session.header;
@@ -2282,7 +2324,7 @@ function runningDescendants(ctx, rootId) {
2282
2324
  if (visited.has(parentId)) continue;
2283
2325
  visited.add(parentId);
2284
2326
  for (const child of childrenOf.get(parentId) ?? []) {
2285
- if (child.status === "running") running.push(child);
2327
+ running.push(child);
2286
2328
  pending.push(child.id);
2287
2329
  }
2288
2330
  }
@@ -288,7 +288,7 @@ export const TYPERT = {
288
288
  },
289
289
  {
290
290
  "name": "CancelOptions",
291
- "declaration": "export interface CancelOptions {\n keepInbox?: boolean | undefined;\n}"
291
+ "declaration": "export interface CancelOptions {\n keepChildren?: boolean | undefined;\n keepInbox?: boolean | undefined;\n}"
292
292
  },
293
293
  {
294
294
  "name": "CommandId",
@@ -6,6 +6,8 @@
6
6
  * @module @deepseek-ai/dsh-subagent
7
7
  */
8
8
  import type { Context } from '@deepseek-ai/cordis';
9
+ import type { Agent } from '@deepseek-ai/dsh-agent';
10
+ import type { SessionId } from '@deepseek-ai/dsh-session';
9
11
  /**
10
12
  * Answer `workspace/session-activity` with the running subagent descendants of
11
13
  * the asked Session, and `workspace/session-stop` by cancelling each of them
@@ -13,4 +15,15 @@ import type { Context } from '@deepseek-ai/cordis';
13
15
  * @param ctx - context carrying the Agent registry; the Session query service is optional and only supplies labels.
14
16
  */
15
17
  export declare function installSubagentArchiveAdmission(ctx: Context): void;
18
+ /**
19
+ * Live subagent descendants by durable lineage: a child whose
20
+ * header names its parent and carries the subagent origin this package
21
+ * records, at any depth. A fork shares the lineage field without the origin
22
+ * and is an independent conversation, so it never holds its source. Lineage
23
+ * is read as data, so a damaged header chain that loops is visited once.
24
+ * @param ctx - live Agent registry.
25
+ * @param rootId - Session whose subagent descendants are selected.
26
+ * @returns live descendants, including idle Agents with parked inbox work.
27
+ */
28
+ export declare function subagentDescendants(ctx: Context, rootId: SessionId): Agent[];
16
29
  //# sourceMappingURL=archive-admission.d.ts.map
@@ -65,8 +65,20 @@ import { foldSubagentDescriptor } from "./descriptor.js";
65
65
  * @param ctx - context carrying the Agent registry; the Session query service is optional and only supplies labels.
66
66
  */
67
67
  export function installSubagentArchiveAdmission(ctx) {
68
+ ctx.on('agent/cancelled', ({ agent, cause, options }) => {
69
+ if (cause.kind !== 'user' || options.keepChildren || ctx.agents.get(agent.id) !== agent)
70
+ return;
71
+ for (const child of subagentDescendants(ctx, agent.id)) {
72
+ try {
73
+ child.cancel({ kind: 'parent' });
74
+ }
75
+ catch (error) {
76
+ ctx.logger.warn(`subagent: cancelling "${child.id}" for a stopped parent failed: ${String(error)}`);
77
+ }
78
+ }
79
+ });
68
80
  ctx.on('workspace/session-activity', async ({ sessionId }, next) => {
69
- const running = runningDescendants(ctx, sessionId);
81
+ const running = subagentDescendants(ctx, sessionId).filter(child => child.status === 'running');
70
82
  const rest = await next();
71
83
  if (running.length === 0)
72
84
  return rest;
@@ -74,7 +86,7 @@ export function installSubagentArchiveAdmission(ctx) {
74
86
  return [own, ...rest];
75
87
  });
76
88
  ctx.on('workspace/session-stop', ({ sessionId }) => {
77
- for (const child of runningDescendants(ctx, sessionId)) {
89
+ for (const child of subagentDescendants(ctx, sessionId).filter(child => child.status === 'running')) {
78
90
  try {
79
91
  child.cancel({ kind: 'parent' });
80
92
  }
@@ -86,13 +98,16 @@ export function installSubagentArchiveAdmission(ctx) {
86
98
  });
87
99
  }
88
100
  /**
89
- * Live subagent descendants inside a turn, by durable lineage: a child whose
101
+ * Live subagent descendants by durable lineage: a child whose
90
102
  * header names its parent and carries the subagent origin this package
91
103
  * records, at any depth. A fork shares the lineage field without the origin
92
104
  * and is an independent conversation, so it never holds its source. Lineage
93
105
  * is read as data, so a damaged header chain that loops is visited once.
106
+ * @param ctx - live Agent registry.
107
+ * @param rootId - Session whose subagent descendants are selected.
108
+ * @returns live descendants, including idle Agents with parked inbox work.
94
109
  */
95
- function runningDescendants(ctx, rootId) {
110
+ export function subagentDescendants(ctx, rootId) {
96
111
  const childrenOf = new Map();
97
112
  for (const agent of ctx.agents.list()) {
98
113
  const { parentSession, origin } = agent.session.header;
@@ -111,8 +126,7 @@ function runningDescendants(ctx, rootId) {
111
126
  continue;
112
127
  visited.add(parentId);
113
128
  for (const child of childrenOf.get(parentId) ?? []) {
114
- if (child.status === 'running')
115
- running.push(child);
129
+ running.push(child);
116
130
  pending.push(child.id);
117
131
  }
118
132
  }
@@ -55,6 +55,8 @@ export interface Activation {
55
55
  * ancestor leaving the registry without retaining that ancestor's runtime.
56
56
  */
57
57
  readonly ancestry: WeakSet<Agent>;
58
+ /** Exact cancellation ancestors up to the first ordinary conversation, excluding fork sources. */
59
+ readonly taskAncestry: WeakSet<Agent>;
58
60
  /**
59
61
  * Session ids of the child Activations this one owns. Because one Session has
60
62
  * at most one live Activation, the id identifies the live child without
@@ -69,6 +71,8 @@ export interface Activation {
69
71
  * not exist, so its teardown owes the parent no settlement account.
70
72
  */
71
73
  announced: boolean;
74
+ /** Ancestor user cancellation suppresses this epoch's late settlement wakeup. */
75
+ parentStopped: boolean;
72
76
  /** Renewed whenever a settlement watcher must re-check residency state. */
73
77
  poke: PromiseWithResolvers<void>;
74
78
  }
@@ -27,6 +27,16 @@ class ActivationPool {
27
27
  return () => { this.slots.delete(slot); };
28
28
  }
29
29
  }
30
+ /** Retain task ancestry through handle release, stopping at independent fork conversations. */
31
+ function taskAncestry(lineage) {
32
+ const task = [];
33
+ for (const agent of lineage) {
34
+ task.push(agent);
35
+ if (agent.session.header.origin !== 'subagent')
36
+ break;
37
+ }
38
+ return new WeakSet(task);
39
+ }
30
40
  /** Serialize each durable child's delivery, release, and disposal. */
31
41
  export class ChildLock {
32
42
  tails = new Map();
@@ -97,6 +107,29 @@ export class ContinuableActivationRegistry {
97
107
  yield scope.dispose;
98
108
  yield () => this.drain();
99
109
  }.bind(this), 'subagents.continuations()');
110
+ ctx.on('agent/cancelled', ({ agent, cause, options }) => {
111
+ if (cause.kind !== 'user' || options.keepChildren || ctx.agents.get(agent.id) !== agent)
112
+ return;
113
+ const descendants = [...this.resident.values()].filter(activation => activation.handle.agent !== agent && activation.taskAncestry.has(agent));
114
+ // Suppress every descendant before cancelling any: child completion may be reentrant.
115
+ for (const activation of descendants)
116
+ activation.parentStopped = true;
117
+ for (const materialization of this.materializations) {
118
+ if (materialization.taskAncestry.has(agent)) {
119
+ materialization.cancellation.abort(new Error('parent task stopped'));
120
+ }
121
+ }
122
+ for (const pending of [...agent.inbox.nextStep, ...agent.inbox.nextTurn]) {
123
+ if (pending.source.kind === 'subagent-settled' || pending.source.kind === 'agent-message') {
124
+ agent.inbox.remove(pending.id);
125
+ }
126
+ }
127
+ for (const activation of descendants) {
128
+ void this.dispose(activation).catch((error) => {
129
+ ctx.logger.warn(`subagent "${activation.childId}" cancellation teardown failed: ${errorChain(error)}`);
130
+ });
131
+ }
132
+ });
100
133
  }
101
134
  /**
102
135
  * Return the live Activation for a durable child id, if resident.
@@ -177,7 +210,7 @@ export class ContinuableActivationRegistry {
177
210
  // a second cancel would be a redundant signal on a closing handle.
178
211
  if (activation.inbox.closing !== undefined)
179
212
  return;
180
- activation.handle.agent.cancel(authority.kind === 'user' ? { kind: 'user' } : { kind: 'parent' }, { keepInbox: true });
213
+ activation.handle.agent.cancel(authority.kind === 'user' ? { kind: 'user' } : { kind: 'parent' }, { keepInbox: true, keepChildren: true });
181
214
  }
182
215
  /**
183
216
  * Send through a receiving parent's Activation inbox when it has one.
@@ -328,12 +361,16 @@ export class ContinuableActivationRegistry {
328
361
  const pool = this.resident.get(inputs.parent.id)?.pool ?? this.rootPool(inputs.parent);
329
362
  const releaseSlot = pool.reserve(this.maxActiveSubagents());
330
363
  const settled = Promise.withResolvers();
364
+ const cancellation = new AbortController();
331
365
  const materialization = {
332
366
  lineage,
367
+ taskAncestry: taskAncestry(lineage),
333
368
  settled: settled.promise,
369
+ cancellation,
334
370
  };
335
371
  this.materializations.add(materialization);
336
- return this.materializeTracked(inputs, lineage, pool, releaseSlot).catch((error) => {
372
+ const signal = AbortSignal.any([inputs.signal, cancellation.signal]);
373
+ return this.materializeTracked({ ...inputs, signal }, lineage, pool, releaseSlot).catch((error) => {
337
374
  releaseSlot();
338
375
  throw error;
339
376
  }).finally(() => {
@@ -474,9 +511,11 @@ export class ContinuableActivationRegistry {
474
511
  handle,
475
512
  inbox: new SubagentInbox(handle.agent),
476
513
  ancestry: new WeakSet([handle.agent, ...parentLineage]),
514
+ taskAncestry: taskAncestry([handle.agent, ...parentLineage]),
477
515
  ownedChildren: new Set(),
478
516
  observer,
479
517
  announced: false,
518
+ parentStopped: false,
480
519
  poke: Promise.withResolvers(),
481
520
  };
482
521
  this.resident.set(childId, activation);
@@ -667,7 +706,7 @@ export class ContinuableActivationRegistry {
667
706
  }
668
707
  /** Tell the durable direct parent how this Activation ended. */
669
708
  notifySettlement(activation, terminal) {
670
- if (!activation.announced)
709
+ if (!activation.announced || activation.parentStopped)
671
710
  return;
672
711
  try {
673
712
  const parent = this.ctx.agents.get(activation.parentSession);
@@ -12,8 +12,8 @@ declare const CONTROL_ID_SCHEMAS: {
12
12
  childSessionId: z.ZodString;
13
13
  mode: z.ZodLiteral<"continuable">;
14
14
  delivery: z.ZodEnum<{
15
- steer: "steer";
16
15
  queue: "queue";
16
+ steer: "steer";
17
17
  }>;
18
18
  }, z.core.$strip>;
19
19
  readonly 'subagent.interrupt': z.ZodObject<{