@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
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
// src/execution/engine/engines/zcode/appserver-probe.ts
|
|
2
|
+
//
|
|
3
|
+
// [R5 D8] app-server 协议冒烟探针。设计权威源:docs/design/zcode-engine-appserver-
|
|
4
|
+
// resident.md §3.3 D8①(独立连接 create 探针会话 → close → shutdown、校验应答形状
|
|
5
|
+
// 与 sessionId 提取、预算 10s、不触发模型请求不产生费用)+ D2 降级链第①步(探针
|
|
6
|
+
// 失败 → 本任务起直接走 spawn)。
|
|
7
|
+
//
|
|
8
|
+
// 关键约束:
|
|
9
|
+
// - 独立短命连接(AppServerConnection 全新实例,不与常驻主连接共享进程/状态);
|
|
10
|
+
// 探针结束 shutdown 杀链收割,绝不留孤儿进程;
|
|
11
|
+
// - 必须用**已引导的常驻 HOME**(D7 教训:先 bootstrap 再 probe,否则 app-server
|
|
12
|
+
// 启动即因 config 缺失报 -32603,探针永远误降级 spawn)——homeDir 由调用方
|
|
13
|
+
// (zcode-engine 的 probe 门控)经 ensureAppServerHome 保证;
|
|
14
|
+
// - create 帧键集与 SessionChannel.createSession 逐字同源(A.2 ① strict——对面
|
|
15
|
+
// zod 拒未知键),但不带 model、绝不发 session/send(无模型请求、无费用);
|
|
16
|
+
// - 预算整体 race 兜底:请求级超时之外,进程假死/spawn 挂起由外层 deadline 收割。
|
|
17
|
+
//
|
|
18
|
+
// 结论消费方:zcode-engine 的 probe 门控(结论与 CLI mtime 绑定缓存——zcode 升级
|
|
19
|
+
// mtime 变化后首个任务前重探,D2③)。
|
|
20
|
+
|
|
21
|
+
import { getLogger } from "../../../../core/logger.ts";
|
|
22
|
+
|
|
23
|
+
import { AppServerConnection, buildAppServerEnv } from "./connection.ts";
|
|
24
|
+
import { extractCreatedSessionId, stableWorkspaceKey } from "./session-channel.ts";
|
|
25
|
+
import {
|
|
26
|
+
ZCODE_APPSERVER_PROBE_BUDGET_MS,
|
|
27
|
+
ZCODE_APPSERVER_PROBE_CONN_ENV,
|
|
28
|
+
ZCODE_KILL_GRACE_MS,
|
|
29
|
+
} from "./constants.ts";
|
|
30
|
+
|
|
31
|
+
const logger = getLogger("subagents");
|
|
32
|
+
|
|
33
|
+
/** 应答形状异常时的摘要截断长度(够定位形态、不刷屏)。 */
|
|
34
|
+
const CREATE_REPLY_LOG_CHARS = 300;
|
|
35
|
+
|
|
36
|
+
/** 冒烟探针参数(依赖全量注入:cliPath/homeDir/env 来自引擎,测试可换 tmp 路径)。 */
|
|
37
|
+
export interface AppServerSmokeProbeOptions {
|
|
38
|
+
/** zcode CLI 路径(node 脚本)。 */
|
|
39
|
+
cliPath: string;
|
|
40
|
+
/** 已引导的常驻 HOME(D7:探针连接的 --cwd 与 $HOME)。 */
|
|
41
|
+
homeDir: string;
|
|
42
|
+
/** env 基底(引擎 deps.processEnv;探针 env 在其上叠 HOME/嵌套标记/探针连接标记)。 */
|
|
43
|
+
baseEnv: NodeJS.ProcessEnv;
|
|
44
|
+
/** stderr tee 落盘路径(append;与常驻连接分文件——探针故障独立取证)。 */
|
|
45
|
+
stderrLogPath: string;
|
|
46
|
+
/** 总预算(缺省 ZCODE_APPSERVER_PROBE_BUDGET_MS;测试注入短预算验证超时路径)。 */
|
|
47
|
+
budgetMs?: number;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** 冒烟探针结论(ok=false 时 detail 携带失败素材——降级 reason 的数据源)。 */
|
|
51
|
+
export interface AppServerSmokeProbeResult {
|
|
52
|
+
ok: boolean;
|
|
53
|
+
detail: string;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** 错误出声用 message 提取(非 Error 值不抛二次异常)。 */
|
|
57
|
+
function errMessage(err: unknown): string {
|
|
58
|
+
return err instanceof Error ? err.message : String(err);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* 跑一次协议冒烟:独立连接上 create 探针会话(校验 sessionId 可提取)→ close →
|
|
63
|
+
* shutdown。任何一步失败/超预算 → ok=false(调用方降级 spawn,不抛——探针失败是
|
|
64
|
+
* 结论不是异常)。
|
|
65
|
+
*/
|
|
66
|
+
export async function runAppServerSmokeProbe(opts: AppServerSmokeProbeOptions): Promise<AppServerSmokeProbeResult> {
|
|
67
|
+
const budgetMs = opts.budgetMs ?? ZCODE_APPSERVER_PROBE_BUDGET_MS;
|
|
68
|
+
const conn = new AppServerConnection({
|
|
69
|
+
cliPath: opts.cliPath,
|
|
70
|
+
cwd: opts.homeDir,
|
|
71
|
+
env: {
|
|
72
|
+
...buildAppServerEnv(opts.homeDir, opts.baseEnv),
|
|
73
|
+
// 探针连接标记(fake/诊断侧区分探针进程与常驻进程的判据;对真 CLI 透明)
|
|
74
|
+
[ZCODE_APPSERVER_PROBE_CONN_ENV]: "1",
|
|
75
|
+
},
|
|
76
|
+
stderrLogPath: opts.stderrLogPath,
|
|
77
|
+
requestTimeoutMs: budgetMs,
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
// 探针工作面:create(形状校验)→ close。绝不 send(无模型请求)。
|
|
81
|
+
const work = (async (): Promise<string> => {
|
|
82
|
+
const created = await conn.request("session/create", {
|
|
83
|
+
workspace: {
|
|
84
|
+
workspacePath: opts.homeDir,
|
|
85
|
+
workspaceKey: stableWorkspaceKey(opts.homeDir),
|
|
86
|
+
},
|
|
87
|
+
mode: "yolo",
|
|
88
|
+
persistence: "immediate",
|
|
89
|
+
});
|
|
90
|
+
const sessionId = extractCreatedSessionId(created);
|
|
91
|
+
if (sessionId === undefined) {
|
|
92
|
+
throw new Error(
|
|
93
|
+
`session/create 应答无可提取 sessionId: ${JSON.stringify(created).slice(0, CREATE_REPLY_LOG_CHARS)}`,
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
await conn.request("session/close", { sessionId });
|
|
97
|
+
return sessionId;
|
|
98
|
+
})();
|
|
99
|
+
|
|
100
|
+
// 预算 race:进程假死/spawn 挂起时请求级超时不够(帧可能永不到达)——外层
|
|
101
|
+
// deadline 兜底,超时即判探针失败(错误规格表末行:probe 预算耗尽 → 降级 spawn)
|
|
102
|
+
let timedOut = false;
|
|
103
|
+
const deadline = new Promise<void>((resolve) => {
|
|
104
|
+
const t = setTimeout(() => {
|
|
105
|
+
timedOut = true;
|
|
106
|
+
resolve();
|
|
107
|
+
}, budgetMs);
|
|
108
|
+
if (typeof t.unref === "function") t.unref();
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
let failure: unknown;
|
|
112
|
+
const sessionId = await Promise.race([
|
|
113
|
+
work.catch((err: unknown) => {
|
|
114
|
+
failure = err;
|
|
115
|
+
return undefined;
|
|
116
|
+
}),
|
|
117
|
+
deadline.then(() => undefined),
|
|
118
|
+
]);
|
|
119
|
+
|
|
120
|
+
// 无论成败都收割探针进程(短命语义:shutdown 是杀链全序,幂等;失败只 debug——
|
|
121
|
+
// 探针结论已定,收割失败留给宿主 dispose 兜底)
|
|
122
|
+
await conn.shutdown({ graceMs: ZCODE_KILL_GRACE_MS }).catch((err: unknown) => {
|
|
123
|
+
logger.debug(`[zcode-probe] 探针连接 shutdown 失败(best-effort): ${errMessage(err)}`);
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
if (failure !== undefined) {
|
|
127
|
+
return { ok: false, detail: `探针会话失败: ${errMessage(failure)}` };
|
|
128
|
+
}
|
|
129
|
+
if (sessionId === undefined) {
|
|
130
|
+
return {
|
|
131
|
+
ok: false,
|
|
132
|
+
detail: timedOut
|
|
133
|
+
? `探针 ${budgetMs}ms 预算耗尽(create/close 未完成——协议无响应或进程假死)`
|
|
134
|
+
: "探针未产出会话 id(未知形态)",
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
return {
|
|
138
|
+
ok: true,
|
|
139
|
+
detail: `协议冒烟通过(create→close→shutdown,探针会话 ${sessionId},未发模型请求)`,
|
|
140
|
+
};
|
|
141
|
+
}
|