@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.
- package/dist/{chunk-VURUAGMM.js → chunk-LZJOEDGQ.js} +603 -154
- package/dist/engine-discovery-scan-Da4Dkzsi.d.cts +818 -0
- package/dist/engine-discovery-scan-Da4Dkzsi.d.ts +818 -0
- package/dist/execution/engine/engine-discovery-scan.cjs +325 -154
- package/dist/execution/engine/engine-discovery-scan.d.cts +1 -2
- package/dist/execution/engine/engine-discovery-scan.d.ts +1 -2
- package/dist/execution/engine/engine-discovery-scan.js +1 -1
- package/dist/execution/relay-env.js +5 -4
- package/dist/index.cjs +9799 -7954
- package/dist/index.d.cts +1896 -1360
- package/dist/index.d.ts +1896 -1360
- package/dist/index.js +8952 -7513
- package/dist.bundle/index.cjs +7897 -6054
- package/package.json +5 -5
- package/src/__tests__/manifest-store.test.ts +16 -15
- package/src/__tests__/record-store-last-line.test.ts +12 -0
- package/src/__tests__/robustness-medium-batch1.test.ts +10 -14
- package/src/__tests__/robustness-medium-batch2.test.ts +7 -2
- package/src/core/logger.ts +1 -1
- package/src/execution/__tests__/alive-store.test.ts +117 -1
- package/src/execution/__tests__/batch-finalized.test.ts +206 -0
- package/src/execution/__tests__/chat-engine-routing.test.ts +117 -1
- package/src/execution/__tests__/{cold-resurrect.test.ts → cold-lookup.test.ts} +133 -33
- package/src/execution/__tests__/collect-coordinator-service.test.ts +7 -5
- package/src/execution/__tests__/conversation-continuation.test.ts +1452 -0
- package/src/execution/__tests__/delivery-methods.test.ts +90 -176
- package/src/execution/__tests__/dialog-queue.test.ts +70 -3
- package/src/execution/__tests__/dispose-manifest-recovery.test.ts +475 -0
- package/src/execution/__tests__/execute-and-await-worktree.test.ts +3 -3
- package/src/execution/__tests__/execute-nesting.test.ts +8 -5
- package/src/execution/__tests__/execution-record.test.ts +8 -148
- package/src/execution/__tests__/finalize-record.test.ts +295 -129
- package/src/execution/__tests__/get-record-for-action-restart.test.ts +21 -29
- package/src/execution/__tests__/helpers/fake-engine-port.ts +13 -68
- package/src/execution/__tests__/helpers/legacy-sidecar.ts +33 -0
- package/src/execution/__tests__/helpers/subagent-service-mocks.ts +9 -5
- package/src/execution/__tests__/idle-gc.test.ts +60 -0
- package/src/execution/__tests__/inflight-production-wiring.test.ts +223 -0
- package/src/execution/__tests__/lifecycle-manager.test.ts +3 -254
- package/src/execution/__tests__/manifest-store-tmp-recovery.test.ts +43 -22
- package/src/execution/__tests__/model-config-service.test.ts +111 -0
- package/src/execution/__tests__/nested-visibility-env-propagation.test.ts +10 -6
- package/src/execution/__tests__/nested-visibility.test.ts +13 -1
- package/src/execution/__tests__/notify-ledger.test.ts +42 -1
- package/src/execution/__tests__/rebuild-indexes.test.ts +329 -0
- package/src/execution/__tests__/record-binding.test.ts +613 -0
- package/src/execution/__tests__/record-origin.test.ts +318 -0
- package/src/execution/__tests__/record-store-intent-api.test.ts +600 -0
- package/src/execution/__tests__/record-store-orphan-revive.test.ts +71 -3
- package/src/execution/__tests__/record-store.test.ts +72 -54
- package/src/execution/__tests__/recursive-visibility-baseline.test.ts +8 -5
- package/src/execution/__tests__/round-supervisor-workflow-origin.test.ts +205 -0
- package/src/execution/__tests__/run-orchestration-write-lease.test.ts +293 -0
- package/src/execution/__tests__/run-orchestration.test.ts +199 -0
- package/src/execution/__tests__/session-file-gc.test.ts +35 -4
- package/src/execution/__tests__/session-reconstructor.test.ts +78 -0
- package/src/execution/__tests__/state-marker.test.ts +288 -0
- package/src/execution/__tests__/stream-sink-retirement.test.ts +8 -5
- package/src/execution/__tests__/subagent-actions-core.test.ts +67 -16
- package/src/execution/__tests__/subagent-service-multiproc-guard.test.ts +0 -1
- package/src/execution/__tests__/subagent-service-notify-gate.test.ts +27 -11
- package/src/execution/__tests__/subagent-service-parent-guard.test.ts +17 -11
- package/src/execution/__tests__/subagent-service-recovery-bounds.test.ts +130 -53
- package/src/execution/__tests__/subagent-service.test.ts +17 -215
- package/src/execution/__tests__/subprocess-agent-runner-no-progress-killall.test.ts +138 -0
- package/src/execution/__tests__/subprocess-agent-runner.test.ts +105 -660
- package/src/execution/__tests__/sync-collect-recovery.test.ts +23 -16
- package/src/execution/__tests__/terminal-write-latency.test.ts +79 -0
- package/src/execution/__tests__/workflow-agent-dispatch.test.ts +782 -0
- package/src/execution/alive-store.ts +37 -28
- package/src/execution/{cold-resurrect.ts → cold-lookup.ts} +48 -45
- package/src/execution/config.ts +1 -1
- package/src/execution/conversation-continuation.ts +541 -0
- package/src/execution/dialog-queue.ts +60 -12
- package/src/execution/engine/__tests__/common/capability-gate.test.ts +1 -1
- package/src/execution/engine/__tests__/common/journal-wiring.test.ts +16 -1
- package/src/execution/engine/__tests__/conformance/__fixtures__/engine-protocol/fake-engine-protocol.mjs +17 -51
- package/src/execution/engine/__tests__/conformance/__fixtures__/engine-protocol/smoke-run.fixture.json +0 -5
- package/src/execution/engine/__tests__/conformance/engine-conformance.live.test.ts +1 -1
- package/src/execution/engine/__tests__/conformance/protocol-blackbox.test.ts +5 -9
- package/src/execution/engine/__tests__/conformance/registry-fork-filter.test.ts +55 -53
- package/src/execution/engine/__tests__/engine-discovery-scan.test.ts +0 -3
- package/src/execution/engine/__tests__/engine-discovery.test.ts +0 -3
- package/src/execution/engine/__tests__/inflight-snapshot.test.ts +180 -0
- package/src/execution/engine/__tests__/model-prompt.test.ts +0 -3
- package/src/execution/engine/__tests__/registry.test.ts +0 -1
- package/src/execution/engine/__tests__/routing.test.ts +0 -1
- package/src/execution/engine/__tests__/run-failure-worktree-cleanup.test.ts +0 -3
- package/src/execution/engine/client/__tests__/__fixtures__/fake-engine.mjs +0 -3
- package/src/execution/engine/client/__tests__/engine-client-reap.test.ts +212 -0
- package/src/execution/engine/client/__tests__/mirror.test.ts +73 -1
- package/src/execution/engine/client/__tests__/protocol-closure.test.ts +2 -9
- package/src/execution/engine/client/__tests__/remote-engine.test.ts +46 -12
- package/src/execution/engine/client/engine-client.ts +111 -26
- package/src/execution/engine/client/mirror.ts +9 -0
- package/src/execution/engine/client/remote-engine.ts +52 -34
- package/src/execution/engine/client/reverse-router.ts +6 -27
- package/src/execution/engine/common/__tests__/run-signals.test.ts +79 -0
- package/src/execution/engine/common/capability-gate.ts +27 -0
- package/src/execution/engine/common/data-dir.ts +3 -2
- package/src/execution/engine/common/errors.ts +1 -1
- package/src/execution/engine/common/journal-wiring.ts +18 -9
- package/src/execution/engine/common/run-signals.ts +83 -0
- package/src/execution/engine/d8-compat.ts +1 -1
- package/src/execution/engine/host/__tests__/host-bridge.test.ts +3 -18
- package/src/execution/engine/host/host-bridge.ts +26 -41
- package/src/execution/engine/host/pi-host-binding.ts +5 -5
- package/src/execution/engine/host/spawned-children.ts +1 -1
- package/src/execution/engine/inflight-snapshot.ts +92 -0
- package/src/execution/engine/port.ts +52 -54
- package/src/execution/engine/types.ts +11 -14
- package/src/execution/execution-record.ts +15 -47
- package/src/execution/finalize-record.ts +94 -197
- package/src/execution/idle-gc.ts +9 -3
- package/src/execution/lifecycle-manager.ts +25 -361
- package/src/execution/lifecycle-predicates.ts +22 -19
- package/src/execution/manifest-store.ts +40 -42
- package/src/execution/model-config-service.ts +1 -1
- package/src/execution/notifier.ts +39 -1
- package/src/execution/notify-host.ts +13 -4
- package/src/execution/path-encoding.ts +6 -0
- package/src/execution/record-entry.ts +20 -2
- package/src/execution/record-store.ts +925 -160
- package/src/execution/relay-env.ts +8 -3
- package/src/execution/round-supervisor/domain.ts +17 -5
- package/src/execution/round-supervisor/service-binding.test.ts +89 -53
- package/src/execution/round-supervisor/service-binding.ts +71 -21
- package/src/execution/round-supervisor/supervisor.ts +23 -9
- package/src/execution/service/record-access.ts +547 -0
- package/src/execution/service/record-lifecycle.ts +542 -0
- package/src/execution/service/run-orchestration.ts +1647 -0
- package/src/execution/service/service-bootstrap.ts +111 -0
- package/src/execution/service/service-constants.ts +27 -0
- package/src/execution/service/session-baselines.ts +401 -0
- package/src/execution/service/sync-collect-domain.ts +442 -0
- package/src/execution/service/workflow-dispatch.ts +567 -0
- package/src/execution/session-file-gc.ts +11 -8
- package/src/execution/session-reconstructor.ts +44 -1
- package/src/execution/sessions-index.ts +20 -3
- package/src/execution/settled-watchdog.ts +86 -43
- package/src/execution/state-marker.ts +516 -0
- package/src/execution/stream-sink.ts +1 -1
- package/src/execution/subagent-actions-core.ts +53 -31
- package/src/execution/subagent-service.ts +643 -2955
- package/src/execution/subprocess-agent-runner.ts +46 -323
- package/src/execution/types.ts +60 -43
- package/src/execution/ui-request-handler-factory.ts +5 -0
- package/src/execution/worktree-manager.ts +1 -1
- package/src/execution/worktree-registry.ts +12 -8
- package/src/index.ts +16 -5
- package/src/orchestration/__tests__/agent-call-catch-fallback.test.ts +2 -3
- package/src/orchestration/__tests__/agent-call-stream.test.ts +24 -49
- package/src/orchestration/__tests__/error-recovery-terminal-hardening.test.ts +4 -4
- package/src/orchestration/__tests__/file-run-store.test.ts +5 -7
- package/src/orchestration/__tests__/lifecycle-abort-broadcast-signal.test.ts +2 -3
- package/src/orchestration/__tests__/run-snapshot.test.ts +27 -43
- package/src/orchestration/__tests__/worker-message-pump-workflow-dispatch.test.ts +274 -0
- package/src/orchestration/execute-agent-call.ts +1 -1
- package/src/orchestration/file-run-store.ts +1 -1
- package/src/orchestration/models/ports.ts +20 -13
- package/src/orchestration/models/types.ts +11 -13
- package/src/orchestration/run-snapshot.ts +18 -22
- package/src/orchestration/worker-message-pump.ts +33 -57
- package/src/shared/atomic-write.ts +10 -8
- package/dist/chunk-T2SYBW3I.js +0 -24
- package/dist/engine-discovery-scan-ocpM8FmI.d.cts +0 -1608
- package/dist/engine-discovery-scan-ocpM8FmI.d.ts +0 -1608
- package/src/execution/__tests__/chat-round-first-round-watchdog.test.ts +0 -255
- package/src/execution/__tests__/finalized-marker.test.ts +0 -104
- package/src/execution/__tests__/lifecycle-manager-lock.test.ts +0 -211
- package/src/execution/__tests__/subprocess-agent-runner-routing.test.ts +0 -488
- package/src/execution/__tests__/subprocess-agent-runner-timeout.test.ts +0 -75
- package/src/execution/__tests__/tombstone-store.test.ts +0 -73
- package/src/execution/engine/__tests__/conformance/chat-round-protocol.test.ts +0 -230
- package/src/execution/finalized-marker.ts +0 -70
- 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
|
|
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
|
|
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
|
-
*
|
|
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
|
-
*
|
|
533
|
-
*
|
|
534
|
-
*
|
|
535
|
-
|
|
536
|
-
*
|
|
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,后续走
|
|
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
|
-
// 与
|
|
585
|
+
// 与 conversation-continuation 的 D4 revive 格(跨重启冷升级写点②)分工协同:
|
|
574
586
|
// 本入口服务进程内 one-shot,跨重启路径恒被 getRecordForAction 磁盘重建绕过
|
|
575
|
-
|
|
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
|
|
582
|
-
//
|
|
583
|
-
//
|
|
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
|
|
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
|
|
714
|
+
// 守卫 3:异进程活跃(.alive 侧车指向另一进程的活 pid)。
|
|
697
715
|
// 双写防护:fork 虽 copy-on-write(历史 jsonl 只读),但源仍在异进程运行时接续容易
|
|
698
|
-
//
|
|
699
|
-
//
|
|
700
|
-
|
|
701
|
-
//
|
|
702
|
-
|
|
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
|
|