@zhushanwen/subagent-core 0.7.1 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (176) hide show
  1. package/dist/{chunk-VURUAGMM.js → chunk-LZJOEDGQ.js} +603 -154
  2. package/dist/engine-discovery-scan-Da4Dkzsi.d.cts +818 -0
  3. package/dist/engine-discovery-scan-Da4Dkzsi.d.ts +818 -0
  4. package/dist/execution/engine/engine-discovery-scan.cjs +325 -154
  5. package/dist/execution/engine/engine-discovery-scan.d.cts +1 -2
  6. package/dist/execution/engine/engine-discovery-scan.d.ts +1 -2
  7. package/dist/execution/engine/engine-discovery-scan.js +1 -1
  8. package/dist/execution/relay-env.js +5 -4
  9. package/dist/index.cjs +9799 -7954
  10. package/dist/index.d.cts +1896 -1360
  11. package/dist/index.d.ts +1896 -1360
  12. package/dist/index.js +8952 -7513
  13. package/dist.bundle/index.cjs +7897 -6054
  14. package/package.json +5 -5
  15. package/src/__tests__/manifest-store.test.ts +16 -15
  16. package/src/__tests__/record-store-last-line.test.ts +12 -0
  17. package/src/__tests__/robustness-medium-batch1.test.ts +10 -14
  18. package/src/__tests__/robustness-medium-batch2.test.ts +7 -2
  19. package/src/core/logger.ts +1 -1
  20. package/src/execution/__tests__/alive-store.test.ts +117 -1
  21. package/src/execution/__tests__/batch-finalized.test.ts +206 -0
  22. package/src/execution/__tests__/chat-engine-routing.test.ts +117 -1
  23. package/src/execution/__tests__/{cold-resurrect.test.ts → cold-lookup.test.ts} +133 -33
  24. package/src/execution/__tests__/collect-coordinator-service.test.ts +7 -5
  25. package/src/execution/__tests__/conversation-continuation.test.ts +1452 -0
  26. package/src/execution/__tests__/delivery-methods.test.ts +90 -176
  27. package/src/execution/__tests__/dialog-queue.test.ts +70 -3
  28. package/src/execution/__tests__/dispose-manifest-recovery.test.ts +475 -0
  29. package/src/execution/__tests__/execute-and-await-worktree.test.ts +3 -3
  30. package/src/execution/__tests__/execute-nesting.test.ts +8 -5
  31. package/src/execution/__tests__/execution-record.test.ts +8 -148
  32. package/src/execution/__tests__/finalize-record.test.ts +295 -129
  33. package/src/execution/__tests__/get-record-for-action-restart.test.ts +21 -29
  34. package/src/execution/__tests__/helpers/fake-engine-port.ts +13 -68
  35. package/src/execution/__tests__/helpers/legacy-sidecar.ts +33 -0
  36. package/src/execution/__tests__/helpers/subagent-service-mocks.ts +9 -5
  37. package/src/execution/__tests__/idle-gc.test.ts +60 -0
  38. package/src/execution/__tests__/inflight-production-wiring.test.ts +223 -0
  39. package/src/execution/__tests__/lifecycle-manager.test.ts +3 -254
  40. package/src/execution/__tests__/manifest-store-tmp-recovery.test.ts +43 -22
  41. package/src/execution/__tests__/model-config-service.test.ts +111 -0
  42. package/src/execution/__tests__/nested-visibility-env-propagation.test.ts +10 -6
  43. package/src/execution/__tests__/nested-visibility.test.ts +13 -1
  44. package/src/execution/__tests__/notify-ledger.test.ts +42 -1
  45. package/src/execution/__tests__/rebuild-indexes.test.ts +329 -0
  46. package/src/execution/__tests__/record-binding.test.ts +613 -0
  47. package/src/execution/__tests__/record-origin.test.ts +318 -0
  48. package/src/execution/__tests__/record-store-intent-api.test.ts +600 -0
  49. package/src/execution/__tests__/record-store-orphan-revive.test.ts +71 -3
  50. package/src/execution/__tests__/record-store.test.ts +72 -54
  51. package/src/execution/__tests__/recursive-visibility-baseline.test.ts +8 -5
  52. package/src/execution/__tests__/round-supervisor-workflow-origin.test.ts +205 -0
  53. package/src/execution/__tests__/run-orchestration-write-lease.test.ts +293 -0
  54. package/src/execution/__tests__/run-orchestration.test.ts +199 -0
  55. package/src/execution/__tests__/session-file-gc.test.ts +35 -4
  56. package/src/execution/__tests__/session-reconstructor.test.ts +78 -0
  57. package/src/execution/__tests__/state-marker.test.ts +288 -0
  58. package/src/execution/__tests__/stream-sink-retirement.test.ts +8 -5
  59. package/src/execution/__tests__/subagent-actions-core.test.ts +67 -16
  60. package/src/execution/__tests__/subagent-service-multiproc-guard.test.ts +0 -1
  61. package/src/execution/__tests__/subagent-service-notify-gate.test.ts +27 -11
  62. package/src/execution/__tests__/subagent-service-parent-guard.test.ts +17 -11
  63. package/src/execution/__tests__/subagent-service-recovery-bounds.test.ts +130 -53
  64. package/src/execution/__tests__/subagent-service.test.ts +17 -215
  65. package/src/execution/__tests__/subprocess-agent-runner-no-progress-killall.test.ts +138 -0
  66. package/src/execution/__tests__/subprocess-agent-runner.test.ts +105 -660
  67. package/src/execution/__tests__/sync-collect-recovery.test.ts +23 -16
  68. package/src/execution/__tests__/terminal-write-latency.test.ts +79 -0
  69. package/src/execution/__tests__/workflow-agent-dispatch.test.ts +782 -0
  70. package/src/execution/alive-store.ts +37 -28
  71. package/src/execution/{cold-resurrect.ts → cold-lookup.ts} +48 -45
  72. package/src/execution/config.ts +1 -1
  73. package/src/execution/conversation-continuation.ts +541 -0
  74. package/src/execution/dialog-queue.ts +60 -12
  75. package/src/execution/engine/__tests__/common/capability-gate.test.ts +1 -1
  76. package/src/execution/engine/__tests__/common/journal-wiring.test.ts +16 -1
  77. package/src/execution/engine/__tests__/conformance/__fixtures__/engine-protocol/fake-engine-protocol.mjs +17 -51
  78. package/src/execution/engine/__tests__/conformance/__fixtures__/engine-protocol/smoke-run.fixture.json +0 -5
  79. package/src/execution/engine/__tests__/conformance/engine-conformance.live.test.ts +1 -1
  80. package/src/execution/engine/__tests__/conformance/protocol-blackbox.test.ts +5 -9
  81. package/src/execution/engine/__tests__/conformance/registry-fork-filter.test.ts +55 -53
  82. package/src/execution/engine/__tests__/engine-discovery-scan.test.ts +0 -3
  83. package/src/execution/engine/__tests__/engine-discovery.test.ts +0 -3
  84. package/src/execution/engine/__tests__/inflight-snapshot.test.ts +180 -0
  85. package/src/execution/engine/__tests__/model-prompt.test.ts +0 -3
  86. package/src/execution/engine/__tests__/registry.test.ts +0 -1
  87. package/src/execution/engine/__tests__/routing.test.ts +0 -1
  88. package/src/execution/engine/__tests__/run-failure-worktree-cleanup.test.ts +0 -3
  89. package/src/execution/engine/client/__tests__/__fixtures__/fake-engine.mjs +0 -3
  90. package/src/execution/engine/client/__tests__/engine-client-reap.test.ts +212 -0
  91. package/src/execution/engine/client/__tests__/mirror.test.ts +73 -1
  92. package/src/execution/engine/client/__tests__/protocol-closure.test.ts +2 -9
  93. package/src/execution/engine/client/__tests__/remote-engine.test.ts +46 -12
  94. package/src/execution/engine/client/engine-client.ts +111 -26
  95. package/src/execution/engine/client/mirror.ts +9 -0
  96. package/src/execution/engine/client/remote-engine.ts +52 -34
  97. package/src/execution/engine/client/reverse-router.ts +6 -27
  98. package/src/execution/engine/common/__tests__/run-signals.test.ts +79 -0
  99. package/src/execution/engine/common/capability-gate.ts +27 -0
  100. package/src/execution/engine/common/data-dir.ts +3 -2
  101. package/src/execution/engine/common/errors.ts +1 -1
  102. package/src/execution/engine/common/journal-wiring.ts +18 -9
  103. package/src/execution/engine/common/run-signals.ts +83 -0
  104. package/src/execution/engine/d8-compat.ts +1 -1
  105. package/src/execution/engine/host/__tests__/host-bridge.test.ts +3 -18
  106. package/src/execution/engine/host/host-bridge.ts +26 -41
  107. package/src/execution/engine/host/pi-host-binding.ts +5 -5
  108. package/src/execution/engine/host/spawned-children.ts +1 -1
  109. package/src/execution/engine/inflight-snapshot.ts +92 -0
  110. package/src/execution/engine/port.ts +52 -54
  111. package/src/execution/engine/types.ts +11 -14
  112. package/src/execution/execution-record.ts +15 -47
  113. package/src/execution/finalize-record.ts +94 -197
  114. package/src/execution/idle-gc.ts +9 -3
  115. package/src/execution/lifecycle-manager.ts +25 -361
  116. package/src/execution/lifecycle-predicates.ts +22 -19
  117. package/src/execution/manifest-store.ts +40 -42
  118. package/src/execution/model-config-service.ts +1 -1
  119. package/src/execution/notifier.ts +39 -1
  120. package/src/execution/notify-host.ts +13 -4
  121. package/src/execution/path-encoding.ts +6 -0
  122. package/src/execution/record-entry.ts +20 -2
  123. package/src/execution/record-store.ts +925 -160
  124. package/src/execution/relay-env.ts +8 -3
  125. package/src/execution/round-supervisor/domain.ts +17 -5
  126. package/src/execution/round-supervisor/service-binding.test.ts +89 -53
  127. package/src/execution/round-supervisor/service-binding.ts +71 -21
  128. package/src/execution/round-supervisor/supervisor.ts +23 -9
  129. package/src/execution/service/record-access.ts +547 -0
  130. package/src/execution/service/record-lifecycle.ts +542 -0
  131. package/src/execution/service/run-orchestration.ts +1647 -0
  132. package/src/execution/service/service-bootstrap.ts +111 -0
  133. package/src/execution/service/service-constants.ts +27 -0
  134. package/src/execution/service/session-baselines.ts +401 -0
  135. package/src/execution/service/sync-collect-domain.ts +442 -0
  136. package/src/execution/service/workflow-dispatch.ts +567 -0
  137. package/src/execution/session-file-gc.ts +11 -8
  138. package/src/execution/session-reconstructor.ts +44 -1
  139. package/src/execution/sessions-index.ts +20 -3
  140. package/src/execution/settled-watchdog.ts +86 -43
  141. package/src/execution/state-marker.ts +516 -0
  142. package/src/execution/stream-sink.ts +1 -1
  143. package/src/execution/subagent-actions-core.ts +53 -31
  144. package/src/execution/subagent-service.ts +643 -2955
  145. package/src/execution/subprocess-agent-runner.ts +46 -323
  146. package/src/execution/types.ts +60 -43
  147. package/src/execution/ui-request-handler-factory.ts +5 -0
  148. package/src/execution/worktree-manager.ts +1 -1
  149. package/src/execution/worktree-registry.ts +12 -8
  150. package/src/index.ts +16 -5
  151. package/src/orchestration/__tests__/agent-call-catch-fallback.test.ts +2 -3
  152. package/src/orchestration/__tests__/agent-call-stream.test.ts +24 -49
  153. package/src/orchestration/__tests__/error-recovery-terminal-hardening.test.ts +4 -4
  154. package/src/orchestration/__tests__/file-run-store.test.ts +5 -7
  155. package/src/orchestration/__tests__/lifecycle-abort-broadcast-signal.test.ts +2 -3
  156. package/src/orchestration/__tests__/run-snapshot.test.ts +27 -43
  157. package/src/orchestration/__tests__/worker-message-pump-workflow-dispatch.test.ts +274 -0
  158. package/src/orchestration/execute-agent-call.ts +1 -1
  159. package/src/orchestration/file-run-store.ts +1 -1
  160. package/src/orchestration/models/ports.ts +20 -13
  161. package/src/orchestration/models/types.ts +11 -13
  162. package/src/orchestration/run-snapshot.ts +18 -22
  163. package/src/orchestration/worker-message-pump.ts +33 -57
  164. package/src/shared/atomic-write.ts +10 -8
  165. package/dist/chunk-T2SYBW3I.js +0 -24
  166. package/dist/engine-discovery-scan-ocpM8FmI.d.cts +0 -1608
  167. package/dist/engine-discovery-scan-ocpM8FmI.d.ts +0 -1608
  168. package/src/execution/__tests__/chat-round-first-round-watchdog.test.ts +0 -255
  169. package/src/execution/__tests__/finalized-marker.test.ts +0 -104
  170. package/src/execution/__tests__/lifecycle-manager-lock.test.ts +0 -211
  171. package/src/execution/__tests__/subprocess-agent-runner-routing.test.ts +0 -488
  172. package/src/execution/__tests__/subprocess-agent-runner-timeout.test.ts +0 -75
  173. package/src/execution/__tests__/tombstone-store.test.ts +0 -73
  174. package/src/execution/engine/__tests__/conformance/chat-round-protocol.test.ts +0 -230
  175. package/src/execution/finalized-marker.ts +0 -70
  176. package/src/execution/tombstone-store.ts +0 -72
@@ -14,6 +14,7 @@
14
14
  // 平台中立性:全部错误文案 / 提示文案面向 LLM(行动语言),无宿主专属词汇,
15
15
  // 文案内聚本模块(文案即行为,⛔4 逐字锚定)。
16
16
 
17
+ import { findForeignLiveInstance } from "./alive-store.ts";
17
18
  import { computeElapsedSeconds, projectOutcome } from "./execution-record.ts";
18
19
  import { isResumable } from "./lifecycle-predicates.ts";
19
20
  import { SLUG_MAX_LENGTH } from "../orchestration/models/types.ts";
@@ -35,6 +36,10 @@ import type {
35
36
  } from "./types.ts";
36
37
  import { ResurrectDeniedError } from "./types.ts";
37
38
  import { COLLECT_SCAN_LIMIT } from "./collect-coordinator.ts";
39
+ // [H1 U2 / D5 双写点①] SP-5 升级 gate 的错误构造(文案/错误码/恢复指引单一权威,
40
+ // 与 Continuation D4 revive 格写点②共用)+ 默认引擎 id(engine 留痕缺省判据)。
41
+ import { engineConversationUpgradeUnsupportedError } from "./engine/common/capability-gate.ts";
42
+ import { DEFAULT_ENGINE_ID } from "./engine/registry.ts";
38
43
 
39
44
  // ============================================================
40
45
  // 常量
@@ -133,6 +138,12 @@ export type StartHandlerResult = {
133
138
 
134
139
  export interface ListHandlerInput {
135
140
  includeFinished?: boolean;
141
+ /**
142
+ * [H2 W1,设计 subagent-workflow-record-unification §3.3 D1①] 同时列出 workflow
143
+ * 脚本 agent() 派发的 record(origin="workflow")。缺省 false——list 默认只展示
144
+ * 手动 tool 派发的 subagent;排查 workflow 子代理时显式传 true。
145
+ */
146
+ includeWorkflow?: boolean;
136
147
  limit?: number;
137
148
  }
138
149
 
@@ -230,7 +241,7 @@ export function endedMessageGuard(service: SubagentService, id: string, original
230
241
  return new Error(
231
242
  `subagent ${id} was deliberately closed by user (closedReason: ${snap.closedReason}) — ` +
232
243
  `it cannot be messaged or resumed; nothing can reattach to it. ` +
233
- `Recovery: start a new subagent (action:'start'); use action:'list' with includeFinished:true to review its final output.`,
244
+ `Recovery: start a new subagent (action:'start'); use action:'list' with includeFinished:true to review its final output (add includeWorkflow:true to also see workflow-dispatched subagents).`,
234
245
  );
235
246
  }
236
247
  return new Error(
@@ -280,8 +291,7 @@ function assertNever(value: never): string {
280
291
  * 内部 ExecutionStatus → 对外 state 映射(设计决策 10 细则 3)。
281
292
  * 两态收敛后的真实映射只有两条:
282
293
  * running → active / closed → ended(closed 统一终态,含 cancelled)
283
- * ExternalState 仍声明 waiting/error 四态联合(对外契约不变),但当前状态机不产生
284
- * 这两个值——它们是历史多态映射(idle→waiting / failed+crashed→error)的遗留声明。
294
+ * ExternalState 即两态联合(历史 waiting/error 死值成员已随 L2 清扫删除)。
285
295
  * 未来内部加态必须扩展此处,漏加会在 default 分支编译报错(而非静默返回 undefined
286
296
  * 让 state 字段以无主值进入 listResponse JSON)。
287
297
  */
@@ -297,7 +307,7 @@ export function mapExternalState(status: ExecutionStatus): ExternalState {
297
307
  }
298
308
  }
299
309
 
300
- /** SubagentRecord → SubagentListItem(state 四态主字段 + status 调试字段,duration 实时计算)。
310
+ /** SubagentRecord → SubagentListItem(state 两态主字段 + status 调试字段,duration 实时计算)。
301
311
  * parent 从 record.parentRecordId 派生(配合直接父守卫),resumable 从 isResumable 派生
302
312
  * (「可续聊」对外表达);outcome 一等终态语义(projectOutcome 唯一出口),closedReason
303
313
  * 退出对外 JSON(保留为 record 内部诊断字段),对外成败判读收口到 outcome。
@@ -318,6 +328,8 @@ export function recordToListItem(r: SubagentRecord): SubagentListItem {
318
328
  parent: r.parentRecordId,
319
329
  resumable: isResumable(r),
320
330
  outcome: projectOutcome(r),
331
+ origin: r.origin,
332
+ parentRunId: r.parentRunId,
321
333
  };
322
334
  }
323
335
 
@@ -440,15 +452,17 @@ function countPendingSyncRecords(service: SubagentService): number {
440
452
 
441
453
  /**
442
454
  * list 数据源(诚实声明):
443
- * collectRecords(limit, statusFilter) 合并内存(running) + 磁盘(重建)。磁盘源天然
444
- * session 可见——/new /resume /fork 后前 session 的终态 record 仍在 sessions
445
- * 目录里(直到 GC)。内存源仅当前 session 的 running record。
455
+ * collectRecords(limit, statusFilter, includeWorkflow) 合并内存(running) + 磁盘(重建)
456
+ * 磁盘源天然跨 session 可见——/new /resume /fork 后前 session 的终态 record 仍在
457
+ * sessions 目录里(直到 GC)。内存源仅当前 session 的 running record。
458
+ * [H2 W1] origin==="workflow" 的 record 默认过滤(D1①),includeWorkflow:true 放行。
446
459
  */
447
460
  export function listHandler(
448
461
  service: SubagentService,
449
462
  input: ListHandlerInput | undefined,
450
463
  ): ListHandlerResult {
451
464
  const includeFinished = input?.includeFinished === true;
465
+ const includeWorkflow = input?.includeWorkflow === true;
452
466
  // limit 夹紧:下限 1,上限 MAX_LIST_LIMIT
453
467
  const rawLimit = input?.limit ?? DEFAULT_LIST_LIMIT;
454
468
  const limit = Math.max(1, Math.min(rawLimit, MAX_LIST_LIMIT));
@@ -456,7 +470,7 @@ export function listHandler(
456
470
  // collectRecords 是 service 核心能力:statusFilter 决定 running-only 还是全部。
457
471
  // 防截断(先多取再过滤)已下沉到 store 层——这里直接传 limit + filter。
458
472
  const filter = includeFinished ? "all" : "running";
459
- const all = service.queries.collectRecords(limit, filter);
473
+ const all = service.queries.collectRecords(limit, filter, includeWorkflow);
460
474
  // collectRecords 磁盘源是 light(无 totalTokens/model 等):SubagentListItem 对
461
475
  // LLM 消费方暴露 totalTokens/model,逐项 getFullRecord 补全(per-file 缓存,仅首次
462
476
  // 全量解析;显式 tool 调用非渲染热路径,成本可接受)。
@@ -494,7 +508,7 @@ export async function cancelHandler(
494
508
  `cancel only works for subagents spawned by the current process.`,
495
509
  );
496
510
  }
497
- throw new Error(`No subagent record with id "${id}". It may have finished — use action:'list' with includeFinished:true to verify.`);
511
+ throw new Error(`No subagent record with id "${id}". It may have finished — use action:'list' with includeFinished:true to verify (add includeWorkflow:true to also see workflow-dispatched subagents).`);
498
512
  }
499
513
  // step 2: controller 检查(controller 为 undefined 表示 record 已终态或未启动)
500
514
  if (rec.mode !== "background") {
@@ -529,12 +543,11 @@ export async function cancelHandler(
529
543
  /**
530
544
  * message action handler:向对话模式 subagent 续聊/插入消息。
531
545
  *
532
- * 状态 × interrupt 自动映射(agent 只表达意图):
533
- * runningdeliverChatMessage 热路径(进程活:prompt + streamingBehavior,interrupt=true
534
- * 抢占 / false 排队)
535
- * 进程死 → deliverChatMessage 冷路径(resumeRound 重开 session + prompt,interrupt 自动
536
- * 退化,agent 无感)
537
- * 终态 → throw ended(正常路径不命中——终态 record 已 archive,getRecordForAction 先 throw not found)
546
+ * [H1 U6] 状态分流面收敛:running Continuation 派发新轮(新 run + resume 锚点);
547
+ * 在途轮存在 D2 打断(abort + 入队);终态 → throw ended(正常路径不命中——终态
548
+ * record archive,getRecordForAction 先 throw not found)。interrupt 输入字段保留
549
+ *([A4] 工具 schema 兼容面——extensions subagent-tool-schema 仍声明该字段)但不参与
550
+ * 分派(D2 统一打断语义)。
538
551
  *
539
552
  * 归属守卫:getRecordForAction 内部校验 rootSessionId。
540
553
  *
@@ -551,7 +564,6 @@ export async function messageHandler(
551
564
  "messageParam.text is required for action:'message' (must not be whitespace-only). " +
552
565
  'Correct: {"action":"message","messageParam":{"subagentId":"sa-...","text":"your follow-up"}}',
553
566
  );
554
- const interrupt = input?.interrupt === true;
555
567
 
556
568
  // 归属守卫:getRecordForAction 内部校验 rootSessionId。
557
569
  // 拒绝时经 endedMessageGuard 分流:找不到 → 原错误;user-close/cancelled
@@ -565,24 +577,30 @@ export async function messageHandler(
565
577
  }
566
578
 
567
579
  // one-shot upgrade:非 chatMode 的 active record(running/idle)收到 message 时
568
- // 自动升级为 chatMode,后续走 deliverChatMessage 统一投递路径(热路径或冷路径 resume)。
580
+ // 自动升级为 chatMode,后续走 Continuation 统一续聊路径(新 run + resume 锚点)。
569
581
  // closed/cancelled 终态 record 不可 upgrade(getRecordForAction 已抛 not found)。
570
582
  // chatMode 是 ExecutionRecord 的 readonly 字段,用 Mutable<T> 显式断言绕过 readonly 约束(upgrade 语义)。
571
583
  // Object.assign 隐式绕过 readonly 不可追踪,改为单字段显式赋值。
572
584
  // 进程内 upgrade 入口——one-shot 首条 message 触发 upgrade 置位 chatMode=true。
573
- // 与 subagent-service.ts getRecordForAction 磁盘重建(跨重启恢复入口)分工:
585
+ // 与 conversation-continuation D4 revive 格(跨重启冷升级写点②)分工协同:
574
586
  // 本入口服务进程内 one-shot,跨重启路径恒被 getRecordForAction 磁盘重建绕过
575
- //(该处无条件 chatMode=true)。改动这两处必须协同。
587
+ //(该处经 Continuation revive 格 gate 化)。改动这两处必须协同。
588
+ // [H1 U2 / D5 双写点①] 升级前置 gate:conversation 位检查——unsupported 引擎
589
+ //(zcode)的 one-shot 收到 message 不升级(升级后续聊行为悬空),硬拒 + fork/重派
590
+ // 指引(engineConversationUpgradeUnsupportedError 文案单源)。
576
591
  if (!record.chatMode && record.status === "running") {
592
+ if (!service.canUpgradeToConversation(record)) {
593
+ throw engineConversationUpgradeUnsupportedError(record.engine ?? DEFAULT_ENGINE_ID);
594
+ }
577
595
  type Mutable<T> = { -readonly [K in keyof T]: T[K] };
578
596
  (record as Mutable<ExecutionRecord>).chatMode = true;
579
597
  }
580
598
 
581
- // chatMode 统一投递:按进程死活分流(热路径 prompt+streamingBehavior / 冷路径 resume),
582
- // 不按 record.status(进程长驻,idle 态进程仍活,续聊走热路径 prompt 而非重开 session)。
583
- // upgrade record.chatMode 已为 true,统一进此分支。
599
+ // chatMode 统一投递:Continuation 编排(§3.4——D4 状态迁移表 / D2 打断语义)。
600
+ // [H1 U6] 旧「进程死活分流热/冷路径」消亡(每轮 = run + resume 锚点),
601
+ // interrupt 参数随 D2 打断统一语义退役(在途轮存在即打断入队,不区分抢占/排队)。
584
602
  if (record.chatMode) {
585
- await service.chatActions.deliverChatMessage(record, text, interrupt);
603
+ await service.chatActions.deliverChatMessage(record, text);
586
604
  } else {
587
605
  // 终态(closed/cancelled):防御性兜底(终态 record 已 archive,正常走 not found)
588
606
  throw new Error(
@@ -689,17 +707,21 @@ function assertAndLookupForkFromSource(service: SubagentService, id: string): Su
689
707
  if (!source) {
690
708
  throw new Error(
691
709
  `No subagent record with id "${id}". It may never have existed or been garbage-collected — ` +
692
- `use action:'list' with includeFinished:true to verify the id.`,
710
+ `use action:'list' with includeFinished:true to verify the id (add includeWorkflow:true to also see workflow-dispatched subagents).`,
693
711
  );
694
712
  }
695
713
 
696
- // 守卫 3:异进程活跃(externalInstance = 另一进程的活 pid marker)。
714
+ // 守卫 3:异进程活跃(.alive 侧车指向另一进程的活 pid)。
697
715
  // 双写防护:fork 虽 copy-on-write(历史 jsonl 只读),但源仍在异进程运行时接续容易
698
- // 读到半截历史,等它结束再接更安全。判据只认 externalInstance(真实活 pid 探针
699
- // 命中),不拦 status==='running' 的快照——后者含跨重启回退重建的 running 记录
700
- //(无活 pid,历史已完整落盘),它们正是 endedMessageGuard 指引 fork-from 的目标;
701
- // 拦了会让 agent 在「建议 fork-from」与「fork-from 拒绝 running」两条错误间死循环。
702
- if (source.externalInstance !== undefined) {
716
+ // 读到半截历史,等它结束再接更安全。判据 = findForeignLiveInstance 直接探针(同
717
+ // cold-lookup 双守卫判据;[U4b / D3b (a′)] 原读 rec.externalInstance 重建缓存换现查
718
+ // 探针——语义等价(externalInstance 非空 探针非空)且比重建时点缓存更新鲜;
719
+ // externalInstance 字段链已随 U4a 删除),不拦 status==='running' 的快照——后者含跨重启
720
+ // 回退重建的 running 记录(无活 pid,历史已完整落盘),它们正是 endedMessageGuard
721
+ // 指引 fork-from 的目标;拦了会让 agent 在「建议 fork-from」与「fork-from 拒绝
722
+ // running」两条错误间死循环。sessionFile 缺失(entry-born 孤儿)时无从探活,
723
+ // 天然无 foreign 声明,落守卫 6 处置。
724
+ if (source.sessionFile !== undefined && findForeignLiveInstance(source.sessionFile) !== undefined) {
703
725
  throw new Error(
704
726
  `subagent ${id} is still running in another process (alive pid marker present). ` +
705
727
  `Recovery: wait until it finishes, or operate it in its own session; then retry fork-from.`,
@@ -713,7 +735,7 @@ function assertAndLookupForkFromSource(service: SubagentService, id: string): Su
713
735
  throw new Error(
714
736
  `subagent ${id} was deliberately closed by user (closedReason: ${source.closedReason}) — ` +
715
737
  `deliberately-closed records cannot be resumed or branched from; nothing can reattach to them. ` +
716
- `Recovery: start a fresh subagent (action:'start'); use action:'list' with includeFinished:true to review its final output.`,
738
+ `Recovery: start a fresh subagent (action:'start'); use action:'list' with includeFinished:true to review its final output (add includeWorkflow:true to also see workflow-dispatched subagents).`,
717
739
  );
718
740
  }
719
741