@zhushanwen/subagent-core 0.2.0 → 0.4.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/README.md +45 -2
- package/agents/analyst.md +60 -0
- package/agents/coder.md +69 -0
- package/agents/debugger.md +66 -0
- package/agents/doc-reviewer.md +49 -0
- package/agents/explorer.md +63 -0
- package/agents/general-purpose.md +32 -0
- package/agents/orchestrator.md +61 -0
- package/agents/planner.md +53 -0
- package/agents/researcher.md +67 -0
- package/agents/reviewer.md +73 -0
- package/dist/chunk-4KN4TTG7.js +240 -0
- package/dist/chunk-APZY4IME.js +27 -0
- package/dist/chunk-X7SZ5HLQ.js +66 -0
- package/dist/execution/engine/engines/zcode/constants.cjs +65 -0
- package/dist/execution/engine/engines/zcode/constants.d.cts +93 -1
- package/dist/execution/engine/engines/zcode/constants.d.ts +93 -1
- package/dist/execution/engine/engines/zcode/constants.js +43 -1
- package/dist/execution/engine/engines/zcode/reader.d.cts +1 -1
- package/dist/execution/engine/engines/zcode/reader.d.ts +1 -1
- package/dist/execution/engine/engines/zcode/reader.js +4 -234
- package/dist/execution/engine/paths.js +7 -19
- package/dist/index.cjs +14709 -100
- package/dist/index.d.cts +4053 -200
- package/dist/index.d.ts +4053 -200
- package/dist/index.js +14358 -102
- package/dist/{types-BxyAidGf.d.cts → types-DpUO16pj.d.cts} +464 -1
- package/dist/{types-BxyAidGf.d.ts → types-DpUO16pj.d.ts} +464 -1
- package/package.json +6 -3
- package/src/__tests__/review-fix-loop-script.test.ts +90 -2
- package/src/__tests__/review-fix-loop-utils.test.ts +21 -0
- package/src/__tests__/smoke.test.ts +9 -2
- package/src/execution/__tests__/agent-profile.test.ts +232 -0
- package/src/execution/__tests__/agents-assembly.test.ts +219 -0
- package/src/execution/__tests__/chat-engine-routing.test.ts +71 -0
- package/src/execution/__tests__/chatmode-first-round-closure-spawn.test.ts +1 -0
- package/src/execution/__tests__/create-concurrency-pool.test.ts +194 -0
- package/src/execution/__tests__/delivery-methods.test.ts +2 -0
- package/src/execution/__tests__/descendant-sweep.test.ts +269 -0
- package/src/execution/__tests__/dialog-queue.test.ts +199 -1
- package/src/execution/__tests__/epipe-fallback.test.ts +2 -0
- package/src/execution/__tests__/execution-runtime-face.test.ts +272 -0
- package/src/execution/__tests__/finalize-record.test.ts +106 -0
- package/src/execution/__tests__/gc-timer.test.ts +2 -0
- package/src/execution/__tests__/get-record-for-action-restart.test.ts +2 -0
- package/src/execution/__tests__/get-state-handshake.test.ts +127 -0
- package/src/execution/__tests__/keep-alive-no-progress.test.ts +378 -0
- package/src/execution/__tests__/kill-all-escalation.test.ts +196 -0
- package/src/execution/__tests__/lifecycle-manager-idle-timer-identity.test.ts +117 -0
- package/src/execution/__tests__/lifecycle-manager.test.ts +39 -0
- package/src/execution/__tests__/manifest-store-tmp-recovery.test.ts +99 -0
- package/src/execution/__tests__/max-turns-to-watchdog-ms.test.ts +113 -0
- package/src/execution/__tests__/notify-ledger.test.ts +294 -0
- package/src/execution/__tests__/record-store-orphan-revive.test.ts +159 -0
- package/src/execution/__tests__/record-store.test.ts +83 -0
- package/src/execution/__tests__/run-and-finalize-chatmode.test.ts +4 -0
- package/src/execution/__tests__/run-spawn-chatmode-settled.test.ts +1 -0
- package/src/execution/__tests__/run-spawn-edges.test.ts +407 -17
- package/src/execution/__tests__/run-spawn-integration.test.ts +1 -1
- package/src/execution/__tests__/run-spawn-stdout-callback-throw.test.ts +12 -4
- package/src/execution/__tests__/service-kill-escalation.test.ts +89 -0
- package/src/execution/__tests__/session-pending.test.ts +228 -0
- package/src/execution/__tests__/session-runner-branch-cache-lru.test.ts +110 -0
- package/src/execution/__tests__/session-runner-close-prune.test.ts +181 -0
- package/src/execution/__tests__/session-runner-epipe.test.ts +1 -0
- package/src/execution/__tests__/session-runner-heartbeat-idle-fallback.test.ts +226 -0
- package/src/execution/__tests__/settled-watchdog.test.ts +289 -0
- package/src/execution/__tests__/spawned-children.test.ts +153 -10
- package/src/execution/__tests__/subagent-actions-core.test.ts +997 -0
- package/src/execution/__tests__/subagent-service-message-close.test.ts +71 -10
- package/src/execution/__tests__/subagent-service-multiproc-guard.test.ts +174 -0
- package/src/execution/__tests__/subagent-service-notify-gate.test.ts +266 -0
- package/src/execution/__tests__/subagent-service-parent-guard.test.ts +3 -0
- package/src/execution/__tests__/subagent-service-recovery-bounds.test.ts +316 -0
- package/src/execution/__tests__/timeout-integration.test.ts +7 -7
- package/src/execution/__tests__/ui-request-handler-factory.test.ts +95 -1
- package/src/execution/__tests__/ui-request-queue.test.ts +25 -0
- package/src/execution/__tests__/worktree-git-ops.test.ts +571 -0
- package/src/execution/__tests__/worktree-reconcile-aging.test.ts +204 -0
- package/src/execution/agent-registry.ts +225 -1
- package/src/execution/agents-assembly.ts +88 -0
- package/src/execution/concurrency-pool.ts +71 -9
- package/src/execution/dialog-queue.ts +101 -3
- package/src/execution/engine/__tests__/conformance/contract.abort.test.ts +49 -2
- package/src/execution/engine/__tests__/conformance/contract.agent-events.test.ts +87 -1
- package/src/execution/engine/__tests__/conformance/engine-conformance.live.test.ts +26 -0
- package/src/execution/engine/__tests__/conformance/golden-replay.zcode.test.ts +83 -1
- package/src/execution/engine/__tests__/conformance/zcode-appserver-harness.ts +131 -0
- package/src/execution/engine/__tests__/registry.test.ts +90 -1
- package/src/execution/engine/engine-discovery.ts +12 -16
- package/src/execution/engine/engines/pi/task-spec-mapper.ts +3 -3
- package/src/execution/engine/engines/zcode/__tests__/__fixtures__/fake-appserver.mjs +274 -0
- package/src/execution/engine/engines/zcode/__tests__/__fixtures__/zcode-golden-appserver.json +36 -0
- package/src/execution/engine/engines/zcode/__tests__/connection.test.ts +472 -0
- package/src/execution/engine/engines/zcode/__tests__/preparer-appserver.test.ts +387 -0
- package/src/execution/engine/engines/zcode/__tests__/session-channel.test.ts +780 -0
- package/src/execution/engine/engines/zcode/__tests__/zcode-engine-appserver.test.ts +815 -0
- package/src/execution/engine/engines/zcode/__tests__/zcode-engine-degrade.test.ts +462 -0
- package/src/execution/engine/engines/zcode/__tests__/zcode-engine.live.test.ts +119 -1
- package/src/execution/engine/engines/zcode/__tests__/zcode-engine.test.ts +136 -6
- package/src/execution/engine/engines/zcode/appserver-home.ts +442 -0
- package/src/execution/engine/engines/zcode/appserver-probe.ts +141 -0
- package/src/execution/engine/engines/zcode/connection.ts +585 -0
- package/src/execution/engine/engines/zcode/constants.ts +129 -0
- package/src/execution/engine/engines/zcode/golden-sample.ts +54 -8
- package/src/execution/engine/engines/zcode/preparer.ts +25 -22
- package/src/execution/engine/engines/zcode/session-channel.ts +656 -0
- package/src/execution/engine/engines/zcode/zcode-engine.ts +909 -41
- package/src/execution/engine/host-task-spec.ts +3 -3
- package/src/execution/engine/port.ts +41 -1
- package/src/execution/engine/registry.ts +53 -0
- package/src/execution/finalize-record.ts +63 -5
- package/src/execution/get-state-handshake.ts +85 -10
- package/src/execution/lifecycle-manager.ts +27 -3
- package/src/execution/manifest-store.ts +53 -62
- package/src/execution/notifier.ts +10 -10
- package/src/execution/notify-ledger.ts +117 -16
- package/src/execution/record-entry.ts +8 -2
- package/src/execution/record-store.ts +29 -15
- package/src/execution/session-pending.ts +213 -62
- package/src/execution/session-runner.ts +974 -128
- package/src/execution/sessions-index.ts +10 -55
- package/src/execution/settled-watchdog.ts +99 -0
- package/src/execution/subagent-actions-core.ts +686 -0
- package/src/execution/subagent-service.ts +396 -49
- package/src/execution/ui-request-handler-factory.ts +27 -4
- package/src/execution/worktree-git-ops.ts +397 -0
- package/src/execution/worktree-manager.ts +72 -10
- package/src/execution/worktree-registry.ts +6 -12
- package/src/index.ts +413 -6
- package/src/orchestration/__tests__/__fixtures__/worker-template.snapshot.txt +42 -3
- package/src/orchestration/__tests__/agent-call-catch-fallback.test.ts +2 -4
- package/src/orchestration/__tests__/args-meta.test.ts +358 -0
- package/src/orchestration/__tests__/error-recovery-handlers.test.ts +1 -8
- package/src/orchestration/__tests__/error-recovery-rebuild-failure.test.ts +312 -0
- package/src/orchestration/__tests__/error-recovery-terminal-hardening.test.ts +382 -0
- package/src/orchestration/__tests__/file-run-store-prune.test.ts +168 -0
- package/src/orchestration/__tests__/file-run-store-throttle.test.ts +168 -0
- package/src/orchestration/__tests__/file-run-store.test.ts +389 -0
- package/src/orchestration/__tests__/helpers/flush-microtasks.ts +13 -0
- package/src/orchestration/__tests__/launcher-nested-workflow.test.ts +34 -0
- package/src/orchestration/__tests__/lifecycle-abort-broadcast-signal.test.ts +357 -0
- package/src/orchestration/__tests__/lifecycle-recover-crashed.test.ts +289 -0
- package/src/orchestration/__tests__/lifecycle.test.ts +77 -0
- package/src/orchestration/__tests__/run-snapshot.test.ts +353 -0
- package/src/orchestration/__tests__/script-generate.test.ts +314 -0
- package/src/orchestration/__tests__/worker-pending-timeout-abort.test.ts +275 -0
- package/src/orchestration/__tests__/worker-script-builder-runtime.test.ts +78 -1
- package/src/orchestration/__tests__/workflow-files.test.ts +186 -0
- package/src/orchestration/__tests__/workflow-run-summary.test.ts +119 -0
- package/src/orchestration/__tests__/workflow-script-registry-impl.test.ts +124 -0
- package/src/orchestration/agent-opts-resolver.ts +7 -7
- package/src/orchestration/args-meta.ts +198 -0
- package/src/orchestration/error-recovery.ts +416 -146
- package/src/orchestration/execute-agent-call.ts +9 -9
- package/src/orchestration/file-run-store.ts +327 -0
- package/src/orchestration/launcher.ts +35 -26
- package/src/orchestration/lifecycle.ts +355 -79
- package/src/orchestration/models/agent-call.ts +7 -7
- package/src/orchestration/models/budget.ts +5 -5
- package/src/orchestration/models/run-runtime.ts +13 -13
- package/src/orchestration/models/trace.ts +8 -8
- package/src/orchestration/models/workflow-run.ts +27 -27
- package/src/orchestration/models/workflow-script.ts +4 -4
- package/src/orchestration/run-snapshot.ts +266 -0
- package/src/orchestration/script-generate.ts +154 -0
- package/src/orchestration/script-lint.ts +33 -33
- package/src/orchestration/worker-handle.ts +10 -10
- package/src/orchestration/worker-host.ts +10 -10
- package/src/orchestration/worker-script-builder.ts +401 -346
- package/src/orchestration/workflow-files.ts +37 -11
- package/src/orchestration/workflow-run-summary.ts +69 -0
- package/src/orchestration/workflow-script-registry-impl.ts +31 -9
- package/src/shared/__tests__/agent-ref.test.ts +209 -2
- package/src/shared/__tests__/atomic-write.test.ts +267 -0
- package/src/shared/__tests__/bounded-serialize.test.ts +236 -0
- package/src/shared/__tests__/injection-render.test.ts +518 -0
- package/src/shared/__tests__/resource-discovery-host-roots.test.ts +474 -0
- package/src/shared/__tests__/resource-discovery.test.ts +3 -2
- package/src/shared/agent-ref.ts +143 -2
- package/src/shared/atomic-write.ts +320 -0
- package/src/shared/bounded-serialize.ts +154 -0
- package/src/shared/injection-render.ts +279 -0
- package/src/shared/meta-parser.ts +41 -1
- package/src/shared/resource-discovery.ts +104 -37
- package/src/shared/resource-meta.ts +14 -0
- package/src/shared/xml-injection.ts +9 -9
- package/workflows/README.md +9 -9
- package/workflows/chain.js +4 -2
- package/workflows/map-reduce.js +5 -3
- package/workflows/parallel.js +5 -3
- package/workflows/review-fix-loop-utils.cjs +14 -3
- package/workflows/review-fix-loop.js +18 -7
- package/workflows/scatter-gather.js +4 -2
- package/dist/chunk-3VOERJPJ.js +0 -22
package/src/index.ts
CHANGED
|
@@ -5,14 +5,19 @@
|
|
|
5
5
|
* (./engines/zcode/reader、./engines/zcode/constants、./engine/paths、./relay-env)
|
|
6
6
|
* + ./workflows/* 资产子入口。exports 面即 semver 契约(D5):收窄不放宽——
|
|
7
7
|
* 新增导出走 minor,本文件刻意不使用 `export *`,逐名列出以使 diff 可审。
|
|
8
|
-
* 内部实现细节(
|
|
9
|
-
*
|
|
8
|
+
* 内部实现细节(error-recovery / execute-agent-call / worker-script-builder 等
|
|
9
|
+
* engine 编排件)不经 barrel 导出;host-surface 扩面(zsw 回接 U0,2026-08-30)
|
|
10
|
+
* 后 port 的 Infra 实现与宿主组装件已列入公共面,仓内壳侧深路径消费
|
|
11
|
+
* (`./*` -> src 通配)不受本文件约束。
|
|
10
12
|
*
|
|
11
13
|
* 设计权威源:docs/design/subagent-core-package-extraction.md §3.3 D5;
|
|
12
14
|
* 宿主接入示例见包 README(§3.4 core_host_not_configured 恢复指引的落点)。
|
|
13
15
|
*/
|
|
14
16
|
|
|
15
|
-
|
|
17
|
+
// 0.4.0 = 首个公开发布的收敛收口面(0.3.0 为 2026-08-30 裁决的跳号占位,永不单独
|
|
18
|
+
// 发布;+ minor changeset 收口面落本号);与 package.json version 的一致性由
|
|
19
|
+
// src/__tests__/smoke.test.ts 动态守护,改版本须两处同步。
|
|
20
|
+
export const CORE_PACKAGE_VERSION = "0.4.0";
|
|
16
21
|
|
|
17
22
|
// ── 宿主端口接线面(core/)────────────────────────────────────
|
|
18
23
|
// HostServices:dataRoot / log / discoveryRoots 端口 + configureCore 注入;
|
|
@@ -77,11 +82,413 @@ export {
|
|
|
77
82
|
type EngineRoutingSource,
|
|
78
83
|
} from "./execution/engine/routing.ts";
|
|
79
84
|
|
|
85
|
+
// ── 资源发现面(shared/resource-discovery,W2③)──────────────
|
|
86
|
+
// discoverResources:agent .md / workflow .js 的多源统一发现(ADR-031)——多源扫描
|
|
87
|
+
// + stem last-writer-wins 合并 + realpath 去重。宿主(zsw 回接)经 ScanConfig.hostRoots
|
|
88
|
+
// 注入发现根(source 标签即 ResourceSource 槽位键,含 project-host 项目级槽);
|
|
89
|
+
// 深路径消费在 npm/vendored 发布形态不可达(exports 无深路径通配),故出 barrel。
|
|
90
|
+
export { discoverResources } from "./shared/resource-discovery.ts";
|
|
91
|
+
export type {
|
|
92
|
+
DiscoveredResource,
|
|
93
|
+
ResourceKind,
|
|
94
|
+
ResourceSource,
|
|
95
|
+
ScanConfig,
|
|
96
|
+
} from "./shared/resource-discovery.ts";
|
|
97
|
+
// 发现链辅助(C5b):discoverResources 之外被发现消费方逐文件消费的三个原语——
|
|
98
|
+
// findWorkspaceRoot(project 源根定位)、getCachedParsed/getCachedFileContent
|
|
99
|
+
// (mtime 缓存读取)。发现链消费方(pi-sw injector 等宿主接线)逐条解析
|
|
100
|
+
// DiscoveredResource 的 frontmatter/meta 需要它们,深路径在 npm/vendored 发布
|
|
101
|
+
// 形态不可达,故随发现面出 barrel。
|
|
102
|
+
export {
|
|
103
|
+
findWorkspaceRoot,
|
|
104
|
+
getCachedFileContent,
|
|
105
|
+
getCachedParsed,
|
|
106
|
+
} from "./shared/resource-discovery.ts";
|
|
107
|
+
// parseResourceMeta:.md frontmatter / workflow @pi-meta 的统一 meta 解析
|
|
108
|
+
// (fail-safe null)——发现链消费方从 DiscoveredResource 提取 name/description
|
|
109
|
+
// 的解析入口,与上面发现链辅助同属一个消费面,深路径同样不可达。
|
|
110
|
+
export { parseResourceMeta } from "./shared/meta-parser.ts";
|
|
111
|
+
|
|
112
|
+
// ── 注入渲染面(shared/injection-render + shared/xml-injection,W3)──
|
|
113
|
+
// 三段 XML(<available_subagents>/<available_workflows>/<available_provider_models>)
|
|
114
|
+
// 的 format 纯函数 + Entry 接口从 pi-sw 插件层下沉(D-3):ModelEntry 并集口径
|
|
115
|
+
// (除 id/name 外全字段 optional,红线 5 守卫不抛不渲垃圾)、分段条目预算
|
|
116
|
+
// (码点序排 + 截尾 + 宿主注入兜底指引;models 段无预算永不截,红线 7)、
|
|
117
|
+
// guide 文案宿主注入(core 不内嵌平台文案)。summarizeDescription 随
|
|
118
|
+
// WorkflowEntry 链导出(zsw 侧同口径消费)。escapeXml/renderXmlSection 渲染
|
|
119
|
+
// 原语随面出 barrel——深路径消费在 npm/vendored 发布形态不可达。
|
|
120
|
+
export {
|
|
121
|
+
formatAgentList,
|
|
122
|
+
formatModelList,
|
|
123
|
+
formatWorkflowList,
|
|
124
|
+
sortByCodepoint,
|
|
125
|
+
summarizeDescription,
|
|
126
|
+
} from "./shared/injection-render.ts";
|
|
127
|
+
export type {
|
|
128
|
+
AgentEntry,
|
|
129
|
+
ListFormatOptions,
|
|
130
|
+
ModelEntry,
|
|
131
|
+
ModelListFormatOptions,
|
|
132
|
+
ModelReasoningInfo,
|
|
133
|
+
WorkflowEntry,
|
|
134
|
+
} from "./shared/injection-render.ts";
|
|
135
|
+
export { escapeXml, renderXmlSection } from "./shared/xml-injection.ts";
|
|
136
|
+
|
|
80
137
|
// ── workflow 编排入口(orchestration)────────────────────────
|
|
81
138
|
// runWorkflow / abortRun:run 生命周期 free functions(D-12)——orchestration 的
|
|
82
|
-
//
|
|
83
|
-
//
|
|
84
|
-
//
|
|
139
|
+
// 最小宿主入口。以下 host-surface 扩面(zsw 回接 U0)出 Barrel:宿主壳组装
|
|
140
|
+
// LifecycleDeps 需要亲手构造三个 port 实现与消费细粒度编排函数,深路径消费
|
|
141
|
+
// 在 npm 形态不可达(发布面无 `./*` 通配)——宿主触点证据即 zsw 回接设计 D2。
|
|
85
142
|
export { abortRun, runWorkflow } from "./orchestration/lifecycle.ts";
|
|
86
143
|
export type { RunSpec } from "./orchestration/models/run-spec.ts";
|
|
87
144
|
export type { LifecycleDeps } from "./orchestration/models/ports.ts";
|
|
145
|
+
|
|
146
|
+
// lifecycle 细粒度编排:session 切换/关闭批量终止、done run 内存淘汰(窗口常量
|
|
147
|
+
// MAX_RETAINED_DONE_RUNS)、run 级墙钟预算计时器(宿主 rebuildRuntime 重排用)。
|
|
148
|
+
export {
|
|
149
|
+
evictDoneRunsBeyondCap,
|
|
150
|
+
MAX_RETAINED_DONE_RUNS,
|
|
151
|
+
scheduleTimeBudget,
|
|
152
|
+
terminateRunningRuns,
|
|
153
|
+
} from "./orchestration/lifecycle.ts";
|
|
154
|
+
|
|
155
|
+
// launcher 层:runAndWait(阻塞至 done)与 executeNestedWorkflow(嵌套 workflow(),
|
|
156
|
+
// 宿主 onWorkflowCall 注入的实现体)——宿主 tool/action 面的直接消费入口。
|
|
157
|
+
export { executeNestedWorkflow, runAndWait } from "./orchestration/launcher.ts";
|
|
158
|
+
export type { LauncherDeps, WorkflowRunResult } from "./orchestration/launcher.ts";
|
|
159
|
+
|
|
160
|
+
// WorkerHost port 的 Infra 实现(worker_threads 启动 worker 脚本)——宿主组装
|
|
161
|
+
// LifecycleDeps.workerHost 的默认实现;WorkerHandlers 是 start 的回调 bag 类型。
|
|
162
|
+
export { WorkerHostImpl } from "./orchestration/worker-host.ts";
|
|
163
|
+
|
|
164
|
+
// 脚本注册表 Infra 实现(config-loader 之上的 WorkflowScript 实体工厂)——
|
|
165
|
+
// launcher 层 registry 依赖的默认实现。
|
|
166
|
+
export { WorkflowScriptRegistryImpl } from "./orchestration/workflow-script-registry-impl.ts";
|
|
167
|
+
|
|
168
|
+
// lintScript:workflow 脚本静态检查(执行前 fail-fast,宿主 list/validate 面消费)。
|
|
169
|
+
export { lintScript } from "./orchestration/script-lint.ts";
|
|
170
|
+
export type { LintFinding, LintResult } from "./orchestration/script-lint.ts";
|
|
171
|
+
|
|
172
|
+
// ── workflow 创作闭环面(orchestration/script-generate + workflow-files,W4)──
|
|
173
|
+
// generateWorkflowScript:generate 校验管线(五道闸 + @pi-meta round-trip + tmp
|
|
174
|
+
// 写盘)从 pi-sw 插件层下沉(D-6)——纯函数返回结构化结果(不 throw,pi 的
|
|
175
|
+
// isError 契约转换由宿主负责),报错文案逐字对齐 pi 现版(CA2 前提)。
|
|
176
|
+
// saveWorkflow/deleteWorkflow 首次出 barrel:宿主(zsw)generate→save→delete
|
|
177
|
+
// 创作闭环的完整入口;目录经 WorkflowDirOptions 注入(缺省 pi 布局
|
|
178
|
+
// DEFAULT_WORKFLOW_TMP_DIR / DEFAULT_WORKFLOW_SAVED_DIR,向后兼容——pi 现深路径
|
|
179
|
+
// 调用形态行为不变,改接在 C5)。
|
|
180
|
+
export { generateWorkflowScript } from "./orchestration/script-generate.ts";
|
|
181
|
+
export type {
|
|
182
|
+
GenerateWorkflowScriptOptions,
|
|
183
|
+
GenerateWorkflowScriptResult,
|
|
184
|
+
} from "./orchestration/script-generate.ts";
|
|
185
|
+
export { deleteWorkflow, saveWorkflow } from "./orchestration/workflow-files.ts";
|
|
186
|
+
export type { WorkflowDirOptions } from "./orchestration/workflow-files.ts";
|
|
187
|
+
// 缺省目录常量随面导出:宿主显式注入 pi 缺省布局时引用常量,避免字面硬编码回流。
|
|
188
|
+
export {
|
|
189
|
+
DEFAULT_WORKFLOW_SAVED_DIR,
|
|
190
|
+
DEFAULT_WORKFLOW_TMP_DIR,
|
|
191
|
+
} from "./orchestration/workflow-files.ts";
|
|
192
|
+
|
|
193
|
+
// workflow 发现/加载(ADR-031 统一资源发现):宿主 list 面与 registry 构造消费;
|
|
194
|
+
// invalidateCache 供宿主在写脚本后主动失效 mtime 缓存。
|
|
195
|
+
export {
|
|
196
|
+
discoverWorkflows,
|
|
197
|
+
getWorkflow,
|
|
198
|
+
getWorkflowByPath,
|
|
199
|
+
invalidateCache,
|
|
200
|
+
loadWorkflows,
|
|
201
|
+
} from "./orchestration/config-loader.ts";
|
|
202
|
+
export type {
|
|
203
|
+
CachedWorkflowMeta,
|
|
204
|
+
WorkflowMeta,
|
|
205
|
+
WorkflowScanConfig,
|
|
206
|
+
WorkflowSource,
|
|
207
|
+
} from "./orchestration/config-loader.ts";
|
|
208
|
+
|
|
209
|
+
// FileRunStore:RunStore port 的宿主无关文件实现(D2 设计件)——落盘
|
|
210
|
+
// <dataRoot>/workflow-state/<runId>.jsonl,zsw 等无 pi session 设施的宿主装配
|
|
211
|
+
// LifecycleDeps.store 用;pi 壳继续用 session 锚定的 JsonlRunStore。
|
|
212
|
+
export { FileRunStore } from "./orchestration/file-run-store.ts";
|
|
213
|
+
|
|
214
|
+
// RunStore / AgentRunner / WorkerHost port 契约类型:宿主自写 Infra 实现
|
|
215
|
+
// (如 zsw 的 RunnerPort 桥接)需要契约面;WorkerHandlers 已随 WorkerHost 注释。
|
|
216
|
+
export type {
|
|
217
|
+
AgentRunner,
|
|
218
|
+
RunStore,
|
|
219
|
+
WorkerHandlers,
|
|
220
|
+
WorkerHost,
|
|
221
|
+
} from "./orchestration/models/ports.ts";
|
|
222
|
+
|
|
223
|
+
// ── zcode 引擎注册面(execution/engine)──────────────────────
|
|
224
|
+
// registerZcodeEngine:把 'zcode' 引擎登记进 registry(组合根职责,幂等);
|
|
225
|
+
// createZcodeEngine:DI 工厂(测试/宿主注入 deps)。ZcodeEngineDeps 经
|
|
226
|
+
// registration.ts 的 re-export 导出(避免与 zcode-engine.ts 双源)。
|
|
227
|
+
export {
|
|
228
|
+
createZcodeEngine,
|
|
229
|
+
registerZcodeEngine,
|
|
230
|
+
} from "./execution/engine/engines/zcode/registration.ts";
|
|
231
|
+
export type { ZcodeEngineDeps } from "./execution/engine/engines/zcode/registration.ts";
|
|
232
|
+
|
|
233
|
+
// killAllSpawnedChildren:session 关闭时批量回收 agent 子进程(宿主 shutdown
|
|
234
|
+
// 钩子消费;子进程注册表在 session-runner 模块内)。
|
|
235
|
+
export { killAllSpawnedChildren } from "./execution/session-runner.ts";
|
|
236
|
+
|
|
237
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
238
|
+
// sink 下沉收口扩面(docs/design/subagent-core-sink-design.md,2026-08-31)
|
|
239
|
+
//
|
|
240
|
+
// D2 裁决:本分隔线以下全部为纯新增导出——上方既有导出符号与路径零变更
|
|
241
|
+
//(pi 24 处深路径 import 与 zsw vendor sha256 manifest 双不受波及)。
|
|
242
|
+
// 按域分组逐名列出(不使用 `export *`,沿用本文件既有纪律使 diff 可审)。
|
|
243
|
+
//
|
|
244
|
+
// semver 分档:运行时面一组标注 @experimental(一个 minor 周期内允许签名
|
|
245
|
+
// 微调,D6);其余各组为常规 semver 稳定面。
|
|
246
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
247
|
+
|
|
248
|
+
// ── agent-ref 面(契约原语,U1)────────────────────────────────
|
|
249
|
+
// agent 引用规范化(normalizeRef 含 `..` 段拒绝——G4 声明的唯一行为收紧,
|
|
250
|
+
// ⛔2 样本集验证)+ 引用扩展名常量 + 显示名投影 + 报错文案工厂 +
|
|
251
|
+
// slug 长度上限 + 进程活性探针(watchdog/孤儿判定共用)。
|
|
252
|
+
export {
|
|
253
|
+
AGENT_REF_EXT,
|
|
254
|
+
displayAgentName,
|
|
255
|
+
invalidAgentRefMessage,
|
|
256
|
+
normalizeRef,
|
|
257
|
+
type InvalidAgentRefMessageOptions,
|
|
258
|
+
WORKFLOW_REF_EXT,
|
|
259
|
+
} from "./shared/agent-ref.ts";
|
|
260
|
+
export { SLUG_MAX_LENGTH } from "./execution/execute-options-mapper.ts";
|
|
261
|
+
export { isProcessAlive } from "./execution/alive-store.ts";
|
|
262
|
+
|
|
263
|
+
// ── workflow 契约面(U1)──────────────────────────────────────
|
|
264
|
+
// workflow 引用规范化(名/路径二分 + 保留字裁决,knownNames 宿主注入——
|
|
265
|
+
// 内置 workflow 名不 core 硬编码)+ WorkflowScript 实体与按路径加载工厂
|
|
266
|
+
//(第三宿主零复刻脚本加载,G3/S5)。
|
|
267
|
+
export {
|
|
268
|
+
normalizeWorkflowRef,
|
|
269
|
+
WORKFLOW_REF_RESERVED_NAMES,
|
|
270
|
+
type NormalizeWorkflowRefOptions,
|
|
271
|
+
type NormalizedWorkflowRef,
|
|
272
|
+
type WorkflowRefInvalidReason,
|
|
273
|
+
} from "./shared/agent-ref.ts";
|
|
274
|
+
export {
|
|
275
|
+
loadWorkflowScriptByPath,
|
|
276
|
+
WorkflowScript,
|
|
277
|
+
} from "./orchestration/workflow-script-registry-impl.ts";
|
|
278
|
+
|
|
279
|
+
// ── 执行预算原语(U3/U4 / D7)─────────────────────────────────
|
|
280
|
+
// maxTurns→watchdog 毫秒换算(floor 语义文档化——两宿主预算一致性 S2 的函数级
|
|
281
|
+
// 锚点)+ 并发池工厂(queuePolicy 缺省 priority 保 pi 行为,zsw 消费 strict-fifo
|
|
282
|
+
// ——策略差异显式化而非双实现)。
|
|
283
|
+
export { maxTurnsToWatchdogMs } from "./execution/session-runner.ts";
|
|
284
|
+
export {
|
|
285
|
+
createConcurrencyPool,
|
|
286
|
+
type ConcurrencyPool,
|
|
287
|
+
type CreateConcurrencyPoolOptions,
|
|
288
|
+
type QueuePolicy,
|
|
289
|
+
} from "./execution/concurrency-pool.ts";
|
|
290
|
+
|
|
291
|
+
// ── 模型引用切分原语(U1 契约面批件)─────────────────────────
|
|
292
|
+
// provider/model 引用切分与缺省值(两宿主 maxTurns/model 换算同源);
|
|
293
|
+
// 实现体内聚 zcode preparer/constants 不挪文件,barrel re-export(§5.3)。
|
|
294
|
+
export {
|
|
295
|
+
DEFAULT_PROVIDER_ID,
|
|
296
|
+
hasApiKey,
|
|
297
|
+
splitZcodeModelRef,
|
|
298
|
+
} from "./execution/engine/engines/zcode/preparer.ts";
|
|
299
|
+
export { ZCODE_FALLBACK_DEFAULT_MODEL } from "./execution/engine/engines/zcode/constants.ts";
|
|
300
|
+
|
|
301
|
+
// ── worktree git 内核(U5 / D5)───────────────────────────────
|
|
302
|
+
// git 语义纯函数单源:保真读(gitRun)、SafeId 校验、dirty 谓词、
|
|
303
|
+
// collectWorktreePatch(统一 add+diff 基线机制,返回结构即 patchIncomplete
|
|
304
|
+
// 留痕载体)、三步容错清理、listWorktreePorcelain(原始输出供宿主 realpath
|
|
305
|
+
// 对账)。锚点缺失/损坏与 add 失败两条降级路径 warn + 留痕(⛔3)。
|
|
306
|
+
//
|
|
307
|
+
// GitRunError 同名双类裁决(u-core-exec-export 交接):worktree-manager.ts 与
|
|
308
|
+
// worktree-git-ops.ts 各有一个 GitRunError(文案同但类独立)——barrel 只导出
|
|
309
|
+
// 本组 worktree-git-ops 版(git 语义新单源);worktree-manager 版不进 barrel,
|
|
310
|
+
// 将来 manager 收缩到 git-ops 内核时随之消除。
|
|
311
|
+
export {
|
|
312
|
+
assertSafeId,
|
|
313
|
+
cleanupWorktree,
|
|
314
|
+
collectWorktreePatch,
|
|
315
|
+
GitRunError,
|
|
316
|
+
gitRun,
|
|
317
|
+
isSafeId,
|
|
318
|
+
isTreeDirty,
|
|
319
|
+
listWorktreePorcelain,
|
|
320
|
+
SAFE_ID_RE,
|
|
321
|
+
type CleanupWorktreeOptions,
|
|
322
|
+
type CollectWorktreePatchOptions,
|
|
323
|
+
type ListWorktreePorcelainOptions,
|
|
324
|
+
type PatchBaselineAnchor,
|
|
325
|
+
type WorktreePatchResult,
|
|
326
|
+
} from "./execution/worktree-git-ops.ts";
|
|
327
|
+
|
|
328
|
+
// ── 运行时面(@experimental,U10 / D6)────────────────────────
|
|
329
|
+
// SubagentService 构造依赖参数注入(modelService 等,无全局查找)+
|
|
330
|
+
// record 状态查询面(RecordStore 按状态枚举/按 id;lookupRecordAnyState
|
|
331
|
+
// 全态查询)+ record 落盘 entry 契约 + agent-registry 执行消费面
|
|
332
|
+
//(loadByPath 直接加载)+ 动作层领域内核(六 handler 的校验/守卫链/
|
|
333
|
+
// 归属判定/终态映射,产出领域对象,宿主 adapter 负责包装渲染)+
|
|
334
|
+
// 错误类型族(instanceof 分流用)。
|
|
335
|
+
//
|
|
336
|
+
// @experimental:本组全部导出在一个 minor 周期内允许签名微调,稳定后转
|
|
337
|
+
// 常规 semver 承诺(D6 语义,各源文件符号注释同款声明)。
|
|
338
|
+
//
|
|
339
|
+
// SubagentServiceSessionInit 刻意不出 barrel:pi session_start 注入专属
|
|
340
|
+
//(引用未导出的 PiLike 签面),第三宿主不经该流程。
|
|
341
|
+
//
|
|
342
|
+
// ModelConfigService:SubagentServiceInit.modelService 的构造依赖(MF-4:jsdoc
|
|
343
|
+
// 示例 `new ModelConfigService({cwd, agentDir})` 的类此前不在导出面——第三宿主
|
|
344
|
+
// 按文档用法不可构造)。getModelConfigService 同为 SubagentService 类 jsdoc
|
|
345
|
+
// session_start 示例的引用符号,随之可达;setModelConfigService 是 pi 壳
|
|
346
|
+
// session_start 专属的进程单例写入点,第三宿主参数注入构造不需要,刻意不出 barrel。
|
|
347
|
+
export {
|
|
348
|
+
getModelConfigService,
|
|
349
|
+
ModelConfigService,
|
|
350
|
+
type ModelConfigServiceInit,
|
|
351
|
+
} from "./execution/model-config-service.ts";
|
|
352
|
+
export {
|
|
353
|
+
createSubagentService,
|
|
354
|
+
SubagentService,
|
|
355
|
+
type SubagentServiceInit,
|
|
356
|
+
} from "./execution/subagent-service.ts";
|
|
357
|
+
export {
|
|
358
|
+
RecordStore,
|
|
359
|
+
type ChangeListener,
|
|
360
|
+
type RecordStorePi,
|
|
361
|
+
type StatusFilter,
|
|
362
|
+
} from "./execution/record-store.ts";
|
|
363
|
+
export {
|
|
364
|
+
SUBAGENT_RECORD_CUSTOM_TYPE,
|
|
365
|
+
toSubagentRecordEntry,
|
|
366
|
+
type SubagentRecordEntryData,
|
|
367
|
+
} from "./execution/record-entry.ts";
|
|
368
|
+
export { AgentRegistry } from "./execution/agent-registry.ts";
|
|
369
|
+
// 错误类型族(error-recovery.ts 计划路径实测不存在,实测散布于下列源文件):
|
|
370
|
+
// resurrect/fork-depth/dirty-worktree 为动作层守卫抛出点(types.ts),
|
|
371
|
+
// GitRunError 见 worktree 内核组裁决。
|
|
372
|
+
export {
|
|
373
|
+
DirtyWorktreeError,
|
|
374
|
+
ForkDepthExceededError,
|
|
375
|
+
ResurrectDeniedError,
|
|
376
|
+
} from "./execution/types.ts";
|
|
377
|
+
export {
|
|
378
|
+
BG_MESSAGE,
|
|
379
|
+
cancelHandler,
|
|
380
|
+
closeHandler,
|
|
381
|
+
DEFAULT_LIST_LIMIT,
|
|
382
|
+
endedMessageGuard,
|
|
383
|
+
FORK_FROM_DEFAULT_PROMPT,
|
|
384
|
+
forkFromHandler,
|
|
385
|
+
listHandler,
|
|
386
|
+
mapExternalState,
|
|
387
|
+
MAX_LIST_LIMIT,
|
|
388
|
+
messageHandler,
|
|
389
|
+
NOTIFY_CONTRACT,
|
|
390
|
+
recordToListItem,
|
|
391
|
+
startHandler,
|
|
392
|
+
wrapForkFromPrompt,
|
|
393
|
+
type CancelHandlerInput,
|
|
394
|
+
type CancelHandlerResult,
|
|
395
|
+
type CloseHandlerInput,
|
|
396
|
+
type CloseHandlerResult,
|
|
397
|
+
type ForkFromHandlerInput,
|
|
398
|
+
type ForkFromHandlerResult,
|
|
399
|
+
type ListHandlerInput,
|
|
400
|
+
type ListHandlerResult,
|
|
401
|
+
type MessageHandlerInput,
|
|
402
|
+
type MessageHandlerResult,
|
|
403
|
+
type StartHandlerInput,
|
|
404
|
+
type StartHandlerResult,
|
|
405
|
+
} from "./execution/subagent-actions-core.ts";
|
|
406
|
+
// 运行时面类型闭包(先例同 ModelInfo/SubagentStream:签名直接引用的具名类型
|
|
407
|
+
// 显式导出,免宿主深路径兜圈;二阶成员类型不强制——结构化类型下实例可用)。
|
|
408
|
+
export type {
|
|
409
|
+
BgResponse,
|
|
410
|
+
CancelResponse,
|
|
411
|
+
CloseResponse,
|
|
412
|
+
ExecutionRecord,
|
|
413
|
+
ExecutionStatus,
|
|
414
|
+
ExternalState,
|
|
415
|
+
ForkFromResponse,
|
|
416
|
+
ListResponse,
|
|
417
|
+
MessageResponse,
|
|
418
|
+
SubagentListItem,
|
|
419
|
+
SubagentRecord,
|
|
420
|
+
} from "./execution/types.ts";
|
|
421
|
+
|
|
422
|
+
// ── 快照 codec(U8 / D4)──────────────────────────────────────
|
|
423
|
+
// WorkflowRun ↔ 落盘快照的单一投影:版本常量沿用 pi "wf-run-v2"(存量逐字节
|
|
424
|
+
// 可读)、live 字段 strip、更高版本跳过(宿主侧 warn 可见性自决)。
|
|
425
|
+
export {
|
|
426
|
+
fromRunSnapshot,
|
|
427
|
+
SNAPSHOT_VERSION,
|
|
428
|
+
toRunSnapshot,
|
|
429
|
+
type RunSnapshot,
|
|
430
|
+
} from "./orchestration/run-snapshot.ts";
|
|
431
|
+
|
|
432
|
+
// ── 原语(U6a)────────────────────────────────────────────────
|
|
433
|
+
// atomic-write:tmp+rename 原子写单一实现(统一 tmp 命名 `.tmp.<pid>.<seq>-<rand>`、
|
|
434
|
+
// 失败清理、崩溃残留扫描/清理入口)——core 内部全部写点已收敛于此(U6b);
|
|
435
|
+
// sync/async 两档耐久语义见模块头。bounded-serialize:预算内 JSON 序列化
|
|
436
|
+
//(自 pi-sw helpers 平移,输出逐字节一致)。
|
|
437
|
+
export {
|
|
438
|
+
atomicTmpPathFor,
|
|
439
|
+
cleanupStaleTmpFiles,
|
|
440
|
+
listStaleTmpFiles,
|
|
441
|
+
parseAtomicTmpPath,
|
|
442
|
+
writeAtomicFile,
|
|
443
|
+
writeAtomicFileSync,
|
|
444
|
+
type AtomicTmpRef,
|
|
445
|
+
type AtomicWriteFileOptions,
|
|
446
|
+
type AtomicWriteOptions,
|
|
447
|
+
type CleanupStaleTmpOptions,
|
|
448
|
+
type CleanupStaleTmpResult,
|
|
449
|
+
} from "./shared/atomic-write.ts";
|
|
450
|
+
export { boundedPrettySerialize } from "./shared/bounded-serialize.ts";
|
|
451
|
+
|
|
452
|
+
// ── 组装层(U2 装配 + U7 生命周期 / D8)───────────────────────
|
|
453
|
+
// discoverAgents:发现→宽容解析→去重→码点序(workflow 侧 discoverWorkflows
|
|
454
|
+
// 对称面,第三宿主「列 agents」入口);recoverCrashedRuns:崩溃恢复四步装配
|
|
455
|
+
//(宿主事件经 hooks 外置);runSummary/isScriptRunning:以 core WorkflowRun
|
|
456
|
+
// 为准的投影(runSummary 双投影分叉收口);WorkflowRun 聚合根随闭包出 barrel。
|
|
457
|
+
export { discoverAgents } from "./execution/agents-assembly.ts";
|
|
458
|
+
export {
|
|
459
|
+
recoverCrashedRuns,
|
|
460
|
+
type RecoverCrashedRunsHooks,
|
|
461
|
+
type RecoverCrashedRunsResult,
|
|
462
|
+
} from "./orchestration/lifecycle.ts";
|
|
463
|
+
export {
|
|
464
|
+
isScriptRunning,
|
|
465
|
+
runSummary,
|
|
466
|
+
type WorkflowRunSummary,
|
|
467
|
+
} from "./orchestration/workflow-run-summary.ts";
|
|
468
|
+
export {
|
|
469
|
+
WorkflowRun,
|
|
470
|
+
type WorkflowRunMeta,
|
|
471
|
+
} from "./orchestration/models/workflow-run.ts";
|
|
472
|
+
export type { DoneReason, RunStatus } from "./orchestration/models/types.ts";
|
|
473
|
+
|
|
474
|
+
// ── schema 助手(U9 / D9)─────────────────────────────────────
|
|
475
|
+
// workflow 资产 @pi-meta parameters 的 schema→已知键集、平铺参数检测与
|
|
476
|
+
// 归一化(pi tool-workflow 消费面下沉;宿主白名单退役入口)。
|
|
477
|
+
export {
|
|
478
|
+
argKeysFromMeta,
|
|
479
|
+
findFlattenedArgKeys,
|
|
480
|
+
normalizeArgsByMeta,
|
|
481
|
+
type ArgKeySet,
|
|
482
|
+
type ArgMetaOptions,
|
|
483
|
+
type ArgMetaWarning,
|
|
484
|
+
type NormalizedArgs,
|
|
485
|
+
} from "./orchestration/args-meta.ts";
|
|
486
|
+
|
|
487
|
+
// ── 解析面(U2 / D3)──────────────────────────────────────────
|
|
488
|
+
// parseAgentProfile:宽容解析(无 frontmatter 不拒、name 缺省 stem、返回
|
|
489
|
+
// body 与执行字段全量)——执行消费面单点;与严格注入投影(parseResourceMeta)
|
|
490
|
+
// 双轨分离的执行侧统一入口。
|
|
491
|
+
export {
|
|
492
|
+
parseAgentProfile,
|
|
493
|
+
type AgentProfile,
|
|
494
|
+
} from "./execution/agent-registry.ts";
|
|
@@ -88,6 +88,8 @@ function _safePost(msg, context) {
|
|
|
88
88
|
const pending = _pendingCalls.get(msg.callId);
|
|
89
89
|
if (pending) {
|
|
90
90
|
_pendingCalls.delete(msg.callId);
|
|
91
|
+
// [OR-3] 结果已到,清除 per-call 超时 timer(有 timer 才清,防御旧 pending 无该字段)
|
|
92
|
+
if (pending.timer) { clearTimeout(pending.timer); }
|
|
91
93
|
if (typeof msg.result !== "undefined") {
|
|
92
94
|
_callCache.set(msg.callId, msg.result);
|
|
93
95
|
}
|
|
@@ -124,11 +126,16 @@ function _safePost(msg, context) {
|
|
|
124
126
|
const pending = _pendingCalls.get(msg.callId);
|
|
125
127
|
if (pending) {
|
|
126
128
|
_pendingCalls.delete(msg.callId);
|
|
129
|
+
// [OR-3] 结果已到,清除 per-call 超时 timer(workflow() 当前不挂 timer,防御性对称清理)
|
|
130
|
+
if (pending.timer) { clearTimeout(pending.timer); }
|
|
127
131
|
pending.resolve(msg.result);
|
|
128
132
|
}
|
|
129
133
|
} else if (msg.type === "abort") {
|
|
134
|
+
// [OR-3] 主线程 abortRun/terminateRunningRuns 的优雅解阻广播:全部 pending
|
|
135
|
+
// reject(脚本 catch WorkflowAbortedError 可感知取消)+ 清理 timer + 清 Map。
|
|
136
|
+
// 后续迟到结果命中空 Map(no-op),不产主线程 unhandledRejection。
|
|
130
137
|
const err = new WorkflowAbortedError(msg.reason);
|
|
131
|
-
_pendingCalls.forEach((p) => { p.reject(err); });
|
|
138
|
+
_pendingCalls.forEach((p) => { if (p.timer) { clearTimeout(p.timer); } p.reject(err); });
|
|
132
139
|
_pendingCalls.clear();
|
|
133
140
|
} else if (msg.type === "budget-update" && msg.budget) {
|
|
134
141
|
_budgetData._spentTokens = msg.budget.usedTokens ?? _budgetData._spentTokens;
|
|
@@ -141,7 +148,11 @@ function _safePost(msg, context) {
|
|
|
141
148
|
function phase(name) { _currentPhase = String(name); }
|
|
142
149
|
|
|
143
150
|
function log(msg) {
|
|
144
|
-
|
|
151
|
+
var _logText = String(msg);
|
|
152
|
+
// [B-3] 单通路:只发独立 {type:"log"} 消息,主线程 handleWorkerLog 即时消费
|
|
153
|
+
//(push 进 errorLogs)。不再同时记入 _workerLogs——旧双通路让同一日志随
|
|
154
|
+
// return/error 的 workerLogs 再带回一份,errorLogs 占两格、TUI 双份。
|
|
155
|
+
try { parentPort.postMessage({ type: "log", phase: _currentPhase, message: _logText }); } catch(e) { /* swallow */ }
|
|
145
156
|
}
|
|
146
157
|
|
|
147
158
|
async function agent(firstArg, secondArg) {
|
|
@@ -158,6 +169,9 @@ function _safePost(msg, context) {
|
|
|
158
169
|
// step 级 turn 上限(turn limiter;显式 0/负 = 显式不限,压过 spawn watchdog env 兑底,SP-6)
|
|
159
170
|
// ?? 语义保真:仅 null/undefined 归 undefined(走 env 兑底),显式 0 保留(U5 参数 > env)
|
|
160
171
|
maxTurns: (secondArg && typeof secondArg === "object" ? secondArg.maxTurns : undefined) ?? undefined,
|
|
172
|
+
// [OR-3] per-call timeoutMs 透传(string 分支此前丢弃该字段——对象分支已有;
|
|
173
|
+
// worker pending 消息层超时依赖它流到 agent-call 消息)
|
|
174
|
+
timeoutMs: (secondArg && typeof secondArg === "object" ? secondArg.timeoutMs : undefined),
|
|
161
175
|
// P4 D9③:step 级 engine 显式指定(仅限必须某引擎独有能力的场景)
|
|
162
176
|
engine: (secondArg && typeof secondArg === "object" && secondArg.engine) || undefined,
|
|
163
177
|
};
|
|
@@ -233,7 +247,32 @@ function _safePost(msg, context) {
|
|
|
233
247
|
return Promise.reject(new Error("postMessage failed for agent-call (callId=" + callId + "): see workerLogs"));
|
|
234
248
|
}
|
|
235
249
|
return new Promise((resolve, reject) => {
|
|
236
|
-
|
|
250
|
+
const _pending = { resolve: resolve, reject: reject, returnMeta: opts.returnMeta === true, timer: undefined };
|
|
251
|
+
// [OR-3] per-call timeoutMs:消息层自己的超时——主线程对 agent-call 永不回话
|
|
252
|
+
//(畸形消息丢弃 / postMessage 双重失败 / runner 不 settle)时 pending 不再永挂
|
|
253
|
+
//(旧实现零超时 → agent() 永挂 → worker 不退出 → run 永久 running)。
|
|
254
|
+
// 超时以错误 resolve(对齐 agent-result 失败容错策略:不 reject、不把单点超时
|
|
255
|
+
// 放大成脚本 error → rebuild),并记入 _workerLogs 留诊断。仅显式 timeoutMs > 0
|
|
256
|
+
// 启用(缺省不限,与 runner 侧 per-call timeout 语义一致)。timer unref:脚本
|
|
257
|
+
// 已 return 时残留 timer 不延迟 worker 自然退出。
|
|
258
|
+
if (typeof opts.timeoutMs === "number" && opts.timeoutMs > 0) {
|
|
259
|
+
_pending.timer = setTimeout(() => {
|
|
260
|
+
if (!_pendingCalls.delete(callId)) { return; }
|
|
261
|
+
const _timeoutMsg = "agent call timed out after " + opts.timeoutMs + "ms (callId=" + callId + ") — no agent-result received from main thread";
|
|
262
|
+
_pushWorkerLog("warn", ["[workflow] " + _timeoutMsg]);
|
|
263
|
+
if (opts.returnMeta === true) {
|
|
264
|
+
_pending.resolve({ value: "", error: _timeoutMsg });
|
|
265
|
+
} else {
|
|
266
|
+
// [B-5] 非 returnMeta 超时 resolve 单值错误消息字符串(对齐 agent-result
|
|
267
|
+
// 失败路径 resolve 单值 _value = parsedOutput ?? content 的形态)——
|
|
268
|
+
// 旧实现 resolve {content:"", error} 对象,字符串消费型脚本(r.trim() 类)
|
|
269
|
+
// 在超时路径 TypeError。
|
|
270
|
+
_pending.resolve(_timeoutMsg);
|
|
271
|
+
}
|
|
272
|
+
}, opts.timeoutMs);
|
|
273
|
+
if (_pending.timer && typeof _pending.timer.unref === "function") { _pending.timer.unref(); }
|
|
274
|
+
}
|
|
275
|
+
_pendingCalls.set(callId, _pending);
|
|
237
276
|
});
|
|
238
277
|
}
|
|
239
278
|
|
|
@@ -17,6 +17,7 @@ import type { LifecycleDeps, WorkerHandlers } from "../models/ports.ts";
|
|
|
17
17
|
import { Trace } from "../models/trace.ts";
|
|
18
18
|
import type { WorkflowRun } from "../models/workflow-run.ts";
|
|
19
19
|
import type { AgentResult } from "../models/types.ts";
|
|
20
|
+
import { flushMicrotasks } from "./helpers/flush-microtasks.ts";
|
|
20
21
|
|
|
21
22
|
// ── helpers ──────────────────────────────────────────────────
|
|
22
23
|
|
|
@@ -189,10 +190,7 @@ describe("U7b: AbortError 不回发 agent-result", () => {
|
|
|
189
190
|
// 先 flush 微任务队列(多次确保 withSlot promise 已 settle),
|
|
190
191
|
// 再断言断言期内无 agent-result。vi.waitFor 用反向断言会一满足就 return,
|
|
191
192
|
// 故采用:跑若干 microtask tick 后静态断言。
|
|
192
|
-
|
|
193
|
-
// eslint-disable-next-line no-await-in-loop -- 排空微任务队列的固定 tick 循环(vi.waitFor 反向断言会一满足即返回,不适用),非逐项等待
|
|
194
|
-
await Promise.resolve();
|
|
195
|
-
}
|
|
193
|
+
await flushMicrotasks(5);
|
|
196
194
|
const posted = findAgentResultPost(postMessage, 3);
|
|
197
195
|
expect(posted).toBeUndefined();
|
|
198
196
|
} finally {
|