doukui 0.0.0-stage → 0.3.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/LICENSE +21 -0
- package/README.en.md +42 -0
- package/README.md +147 -2
- package/bin/commands/build.js +178 -0
- package/bin/commands/config.js +88 -0
- package/bin/commands/help.js +83 -0
- package/bin/commands/init.js +194 -0
- package/bin/commands/install.js +202 -0
- package/bin/commands/interactive.js +352 -0
- package/bin/commands/list.js +108 -0
- package/bin/commands/loop-server.js +357 -0
- package/bin/commands/loop.js +1398 -0
- package/bin/commands/migrate.js +120 -0
- package/bin/commands/setup-global.js +81 -0
- package/bin/commands/status.js +140 -0
- package/bin/commands/team-cleanup.js +190 -0
- package/bin/commands/validate-config.js +35 -0
- package/bin/commands/validate.js +21 -0
- package/bin/commands/version.js +22 -0
- package/bin/context.js +143 -0
- package/bin/doukui.js +216 -0
- package/package.json +47 -4
- package/plugins/contracts/capabilities.js +268 -0
- package/plugins/contracts/checkresult-schema.json +75 -0
- package/plugins/contracts/config-schema.json +179 -0
- package/plugins/contracts/plugin-interface.js +262 -0
- package/plugins/contracts/plugin-schema.json +104 -0
- package/plugins/core/hook-session-start/index.js +281 -0
- package/plugins/core/hook-session-start/plugin.json +7 -0
- package/plugins/core/hook-skill-gate/index.js +661 -0
- package/plugins/core/hook-skill-gate/plugin.json +12 -0
- package/plugins/core/provider-loop-engine/index.js +1397 -0
- package/plugins/core/provider-loop-engine/plugin.json +15 -0
- package/plugins/core/provider-memory-store/index.js +510 -0
- package/plugins/core/provider-memory-store/plugin.json +9 -0
- package/plugins/core/provider-role-registry/index.js +376 -0
- package/plugins/core/provider-role-registry/plugin.json +9 -0
- package/plugins/core/provider-state-store/index.js +244 -0
- package/plugins/core/provider-state-store/plugin.json +9 -0
- package/plugins/core/provider-watchdog/assets/daemon-config.template.json +32 -0
- package/plugins/core/provider-watchdog/assets/lib/watchdog-multi-window.js +676 -0
- package/plugins/core/provider-watchdog/assets/watchdog.js +754 -0
- package/plugins/core/provider-watchdog/index.js +151 -0
- package/plugins/core/provider-watchdog/plugin.json +13 -0
- package/plugins/core/skill-agent-dispatcher/cleanup-reference.md +214 -0
- package/plugins/core/skill-agent-dispatcher/daemon-helpers-reference.md +249 -0
- package/plugins/core/skill-agent-dispatcher/plugin.json +13 -0
- package/plugins/core/skill-agent-dispatcher/roles-reference.md +253 -0
- package/plugins/core/skill-agent-dispatcher/skill.md +1291 -0
- package/plugins/core/skill-agentic-loop/plugin.json +20 -0
- package/plugins/core/skill-agentic-loop/skill.md +572 -0
- package/plugins/core/skill-batch-task-creator/plugin.json +15 -0
- package/plugins/core/skill-batch-task-creator/skill.md +620 -0
- package/plugins/core/skill-checklist/plugin.json +10 -0
- package/plugins/core/skill-checklist/skill.md +171 -0
- package/plugins/core/skill-completion-report/plugin.json +10 -0
- package/plugins/core/skill-completion-report/skill.md +331 -0
- package/plugins/core/skill-doukui-plan/plugin.json +15 -0
- package/plugins/core/skill-doukui-plan/skill.md +233 -0
- package/plugins/core/skill-doukui-sync/plugin.json +10 -0
- package/plugins/core/skill-doukui-sync/skill.md +76 -0
- package/plugins/core/skill-experience-logger/plugin.json +10 -0
- package/plugins/core/skill-experience-logger/skill.md +235 -0
- package/plugins/core/skill-human-checkpoint/plugin.json +10 -0
- package/plugins/core/skill-human-checkpoint/skill.md +194 -0
- package/plugins/core/skill-progress-tracker/plugin.json +10 -0
- package/plugins/core/skill-progress-tracker/skill.md +228 -0
- package/plugins/core/skill-role-manager/plugin.json +10 -0
- package/plugins/core/skill-role-manager/skill.md +252 -0
- package/plugins/core/skill-split-work-package/plugin.json +15 -0
- package/plugins/core/skill-split-work-package/skill.md +441 -0
- package/plugins/core/skill-task-archive/plugin.json +10 -0
- package/plugins/core/skill-task-archive/skill.md +116 -0
- package/plugins/core/skill-task-creator/plugin.json +15 -0
- package/plugins/core/skill-task-creator/skill.md +886 -0
- package/plugins/core/skill-team-cleanup/plugin.json +10 -0
- package/plugins/core/skill-team-cleanup/skill.md +266 -0
- package/plugins/core/skill-watchdog-manager/plugin.json +10 -0
- package/plugins/core/skill-watchdog-manager/skill.md +143 -0
- package/plugins/core/skill-workflow-orchestrator/plugin.json +13 -0
- package/plugins/core/skill-workflow-orchestrator/skill.md +273 -0
- package/plugins/core/validator-doc-sync/index.js +248 -0
- package/plugins/core/validator-doc-sync/plugin.json +12 -0
- package/plugins/core/validator-work-package/index.js +300 -0
- package/plugins/core/validator-work-package/plugin.json +12 -0
- package/plugins/plugin-registry.json +186 -0
- package/plugins/runtime/agent-def-generator.js +150 -0
- package/plugins/runtime/audit-logger.js +311 -0
- package/plugins/runtime/build-cli.js +89 -0
- package/plugins/runtime/checkresult-validator.js +131 -0
- package/plugins/runtime/claude-md-injector.js +159 -0
- package/plugins/runtime/cleanup-utils.js +293 -0
- package/plugins/runtime/config-manager.js +317 -0
- package/plugins/runtime/config-validator.js +320 -0
- package/plugins/runtime/context-window.js +81 -0
- package/plugins/runtime/event-bus.js +207 -0
- package/plugins/runtime/executor-claude.js +828 -0
- package/plugins/runtime/executor-default.js +448 -0
- package/plugins/runtime/executor-local.js +178 -0
- package/plugins/runtime/executor-sdk.js +390 -0
- package/plugins/runtime/harness-build.js +1037 -0
- package/plugins/runtime/hook-dispatcher.js +315 -0
- package/plugins/runtime/logger.js +192 -0
- package/plugins/runtime/loop-actuator.js +292 -0
- package/plugins/runtime/loop-coordinator.js +347 -0
- package/plugins/runtime/loop-defaults.js +29 -0
- package/plugins/runtime/loop-dispatch-batch.js +247 -0
- package/plugins/runtime/loop-executor.js +120 -0
- package/plugins/runtime/loop-report.js +327 -0
- package/plugins/runtime/loop-server-core.js +750 -0
- package/plugins/runtime/loop-snapshot.js +581 -0
- package/plugins/runtime/loop-trace.js +242 -0
- package/plugins/runtime/loop-worktree.js +404 -0
- package/plugins/runtime/manifest-resolver.js +457 -0
- package/plugins/runtime/multi-window-coordinator.js +560 -0
- package/plugins/runtime/objective-verifier.js +136 -0
- package/plugins/runtime/plan-reader.js +763 -0
- package/plugins/runtime/plugin-loader.js +798 -0
- package/plugins/runtime/plugin-trust.js +182 -0
- package/plugins/runtime/plugin-validator.js +491 -0
- package/plugins/runtime/provider-failover.js +114 -0
- package/plugins/runtime/provider-resolver.js +342 -0
- package/plugins/runtime/reflection-evaluator.js +540 -0
- package/plugins/runtime/resolve-plugin-path.js +297 -0
- package/plugins/runtime/safe-path.js +119 -0
- package/plugins/runtime/sandbox-context.js +235 -0
- package/plugins/runtime/sandbox-manager.js +609 -0
- package/plugins/runtime/sandbox-worker.js +215 -0
- package/plugins/runtime/settings-merger.js +172 -0
- package/plugins/runtime/state-store.js +527 -0
- package/plugins/runtime/team-cleanup.js +497 -0
- package/plugins/runtime/text-tokenize.js +25 -0
- package/plugins/runtime/validator-pipeline.js +475 -0
- package/plugins/runtime/yaml-parser.js +692 -0
- package/templates/harness-config.yaml +388 -0
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Loop Dispatch Batch — 并发批调度(concurrent-dispatch Step 1 / next-dev-plan Batch 2)
|
|
3
|
+
*
|
|
4
|
+
* @module loop-dispatch-batch
|
|
5
|
+
*
|
|
6
|
+
* 把 driver 主循环的「单 WP 串行 dispatch」升级为「readyWave 批并发 dispatch」:
|
|
7
|
+
* - readyWaveFor:从 pending 中选出依赖全完成(readyWave)的子集,限 maxConcurrency
|
|
8
|
+
* - dispatchBatch:Promise.all 并发 executor.run(每 spawn 克隆 pendingAction 仅换 wpId),
|
|
9
|
+
* 单失败不阻断同批(task 内部 catch 成 settled)
|
|
10
|
+
* - aggregateCheckResults:批内 N 个 CheckResult 合并为单 CheckResult(reflect 评分用)
|
|
11
|
+
*
|
|
12
|
+
* 并发安全前提(决策 1:单实例 + 容忍放大):
|
|
13
|
+
* driver 复用单 executor 实例,executor.run 的限流段(callTimestamps filter/length/push)
|
|
14
|
+
* + quota 前置检查都在第一个 await(new Promise)前同步执行 → Node 单线程下原子串行,
|
|
15
|
+
* 限流天然并发安全(批内 N 个 push 串行,rateLimitPerHour 对批总 spawn 计数,无需 race-free)。
|
|
16
|
+
* quota 额度(5h 窗口)检查-消耗间隙:批内 N 个 spawn 都基于批前额度通过检查,N 个 close
|
|
17
|
+
* 回调后才计入 → 批内 N 倍消耗可能超 softThreshold,由 executor softThreshold(0.9) 下批降速
|
|
18
|
+
* + coordinator hardThreshold(0.95) 熔断兜底,资源浪费有界。默认 maxConcurrency=1 零放大。
|
|
19
|
+
*
|
|
20
|
+
* 不变量(Step 1 守住):
|
|
21
|
+
* - engine index.js / loop-actuator.js / plan-reader.js git diff 为空(WP-191)
|
|
22
|
+
* - maxConcurrency=1 时行为与 v0.3.15 串行完全一致(回退安全)
|
|
23
|
+
*
|
|
24
|
+
* 已知限制(仅 N>1 触发,N=1 完全无影响):
|
|
25
|
+
* - ~~工作树脏度信号串扰~~(Step 2 已解决):v0.4.0 的 readWorktreeDirty 共用
|
|
26
|
+
* config.projectRoot 致批内 N 个 spawn 串扰。Step 2(concurrent-dispatch Step 2 /
|
|
27
|
+
* per-WP git worktree 隔离)已落地——driver 为批内每 WP 建独立 git worktree,经
|
|
28
|
+
* dispatchBatch 的 wpProjectRoots 透传给 executor.run 的 pendingAction.projectRoot,
|
|
29
|
+
* 脏度检测 per-WP 准确。非 git 仓库 / local executor / 无 --loop-id / 降级路径仍走
|
|
30
|
+
* 旧行为(批级串扰),另由 coordinator hardThreshold(0.95) + max_iterations 双兜底兜住。
|
|
31
|
+
* --no-progress-detect flag 作为 escape hatch(强制批模式 noProgress 归零不累计)。
|
|
32
|
+
* - quota 额度放大:见上方「并发安全前提」(容忍 + softThreshold/hardThreshold 兜底)。
|
|
33
|
+
* - trace 观测冗余:批内 N 条 round record 共享同一轮 engine phaseTimings(每条自带
|
|
34
|
+
* dispatchedWp 可区分;按 iteration 聚合统计时注意同轮多条)。
|
|
35
|
+
*
|
|
36
|
+
* 设计依据:docs/reports/2026-07-01_next-dev-plan.md §3.7(gitignored,运行时产物)
|
|
37
|
+
*/
|
|
38
|
+
|
|
39
|
+
'use strict';
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* 判断 wpId 的依赖是否全部落在 completedSet 内(readyWave 判定)。
|
|
43
|
+
* 与 engine _think 的 isDepsReady 同口径(Step 0 readyWave 逻辑的批量化)。
|
|
44
|
+
* @param {string} wid
|
|
45
|
+
* @param {object|null} depNodes dependencyGraph.nodes({wpId:{dependencies:[...]}})
|
|
46
|
+
* @param {string[]} completedSet 已完成 WP id
|
|
47
|
+
* @returns {boolean}
|
|
48
|
+
*/
|
|
49
|
+
function isDepsReady(wid, depNodes, completedSet) {
|
|
50
|
+
if (!depNodes) return true; // 无拓扑信息 → 视为 ready(降级 = v0.3.15)
|
|
51
|
+
var node = depNodes[wid];
|
|
52
|
+
if (!node) return true; // 节点缺失,视为无依赖
|
|
53
|
+
var deps = node.dependencies || [];
|
|
54
|
+
for (var d = 0; d < deps.length; d++) {
|
|
55
|
+
if (completedSet.indexOf(deps[d]) === -1) return false; // 依赖未完成
|
|
56
|
+
}
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* 从 pendingWps 中选出 readyWave:依赖全完成 + 在 goal 范围内,限 maxConcurrency 个。
|
|
62
|
+
*
|
|
63
|
+
* readyWave 语义:拓扑入度 0(依赖全 completed)的 pending WP,可安全并发 dispatch
|
|
64
|
+
* (无依赖关系,互不干扰)。maxConcurrency 限制批大小(默认 1 = 串行 = v0.3.15)。
|
|
65
|
+
*
|
|
66
|
+
* @param {object} opts
|
|
67
|
+
* @param {object} [opts.dependencyGraph] {nodes,edges,order,hasCycle,cycle}(plan-reader 产出)
|
|
68
|
+
* @param {string[]} opts.pendingWps 未完成 WP(goalWps 减 completed,建议按拓扑序排)
|
|
69
|
+
* @param {string[]} opts.completedSet 已完成 WP id
|
|
70
|
+
* @param {string[]|null} [opts.goalWps] goal 范围(越界保护;null/缺省不限制)
|
|
71
|
+
* @param {number} [opts.maxConcurrency=1] 最大并发数
|
|
72
|
+
* @returns {string[]} readyWave wpId[](≤ maxConcurrency)
|
|
73
|
+
*/
|
|
74
|
+
function readyWaveFor(opts) {
|
|
75
|
+
opts = opts || {};
|
|
76
|
+
var depNodes = (opts.dependencyGraph && opts.dependencyGraph.nodes)
|
|
77
|
+
? opts.dependencyGraph.nodes : null;
|
|
78
|
+
var pending = Array.isArray(opts.pendingWps) ? opts.pendingWps : [];
|
|
79
|
+
var completedSet = Array.isArray(opts.completedSet) ? opts.completedSet : [];
|
|
80
|
+
var goalWps = Array.isArray(opts.goalWps) ? opts.goalWps : null;
|
|
81
|
+
var max = (typeof opts.maxConcurrency === 'number' && opts.maxConcurrency > 0)
|
|
82
|
+
? Math.floor(opts.maxConcurrency) : 1;
|
|
83
|
+
var out = [];
|
|
84
|
+
for (var i = 0; i < pending.length && out.length < max; i++) {
|
|
85
|
+
var wid = pending[i];
|
|
86
|
+
if (goalWps && goalWps.indexOf(wid) === -1) continue; // 越界保护
|
|
87
|
+
if (!isDepsReady(wid, depNodes, completedSet)) continue; // 依赖未就绪
|
|
88
|
+
out.push(wid);
|
|
89
|
+
}
|
|
90
|
+
return out;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* 并发 dispatch 一个 readyWave:每个 wpId 克隆 pendingActionTemplate(仅换 wpId),
|
|
95
|
+
* executor.run 并发,Promise.all 收集(每个 task 内部 catch 成 settled,单失败不阻断同批)。
|
|
96
|
+
*
|
|
97
|
+
* concurrent-dispatch Step 2(per-WP worktree 隔离):
|
|
98
|
+
* opts.wpProjectRoots({wpId: wtPath})注入每 WP 的 per-call projectRoot override,
|
|
99
|
+
* 使 executor.run 在各自 worktree cwd 跑 → readWorktreeDirty per-WP 准确、互不串扰。
|
|
100
|
+
* 缺省/某 WP 无映射 → 不注入(executor 走 config.projectRoot = v0.4.0 串扰行为,回退安全)。
|
|
101
|
+
*
|
|
102
|
+
* @param {object} opts
|
|
103
|
+
* @param {object} opts.executor executor 实例(单实例,run 限流段同步原子故并发安全)
|
|
104
|
+
* @param {object} opts.pendingActionTemplate actuator 产出的 pendingAction 模板(mode/strategy/...)
|
|
105
|
+
* @param {string[]} opts.wpIds readyWave(≤ maxConcurrency)
|
|
106
|
+
* @param {object} [opts.wpProjectRoots] per-WP worktree 路径映射({wpId: wtPath});Step 2 隔离用
|
|
107
|
+
* @param {object} [opts.wpResumeSessionIds] per-WP 上轮 SDK session id 映射(WP-D7):
|
|
108
|
+
* retry 场景注入 pa.resumeSessionId 供 executor-sdk SessionStore 续轮;仅 sdk executor 消费
|
|
109
|
+
* @returns {Promise<Array<{wpId:string,status:'fulfilled'|'rejected',checkResult?:object,reason?:*}>>}
|
|
110
|
+
*/
|
|
111
|
+
async function dispatchBatch(opts) {
|
|
112
|
+
opts = opts || {};
|
|
113
|
+
var executor = opts.executor;
|
|
114
|
+
var template = opts.pendingActionTemplate || {};
|
|
115
|
+
var wpIds = Array.isArray(opts.wpIds) ? opts.wpIds : [];
|
|
116
|
+
var wpProjectRoots = (opts.wpProjectRoots && typeof opts.wpProjectRoots === 'object')
|
|
117
|
+
? opts.wpProjectRoots : null;
|
|
118
|
+
var wpResumeSessionIds = (opts.wpResumeSessionIds && typeof opts.wpResumeSessionIds === 'object')
|
|
119
|
+
? opts.wpResumeSessionIds : null;
|
|
120
|
+
if (!executor || typeof executor.run !== 'function' || wpIds.length === 0) {
|
|
121
|
+
return [];
|
|
122
|
+
}
|
|
123
|
+
var tasks = wpIds.map(function (wpId) {
|
|
124
|
+
// 克隆 pendingAction 仅换 wpId(保留 mode/strategy/context/failingDrivers/createdAt/loopId)
|
|
125
|
+
var pa = {};
|
|
126
|
+
for (var k in template) {
|
|
127
|
+
if (Object.prototype.hasOwnProperty.call(template, k)) pa[k] = template[k];
|
|
128
|
+
}
|
|
129
|
+
pa.wpId = wpId;
|
|
130
|
+
// Step 2:per-WP worktree projectRoot override(wpProjectRoots[wpId] 为 null/undefined 时不注入)
|
|
131
|
+
if (wpProjectRoots && wpProjectRoots[wpId]) {
|
|
132
|
+
pa.projectRoot = wpProjectRoots[wpId];
|
|
133
|
+
}
|
|
134
|
+
// WP-D7:per-WP 上轮 SDK session id(retry 续轮;executor-sdk 消费,其他 executor 忽略)
|
|
135
|
+
if (wpResumeSessionIds && wpResumeSessionIds[wpId]) {
|
|
136
|
+
pa.resumeSessionId = wpResumeSessionIds[wpId];
|
|
137
|
+
}
|
|
138
|
+
return executor.run(pa).then(
|
|
139
|
+
function (checkResult) {
|
|
140
|
+
return { wpId: wpId, status: 'fulfilled', checkResult: checkResult };
|
|
141
|
+
},
|
|
142
|
+
function (err) {
|
|
143
|
+
// 单失败不阻断同批:rejected 也 resolve 成 settled 条目
|
|
144
|
+
return { wpId: wpId, status: 'rejected', reason: err };
|
|
145
|
+
}
|
|
146
|
+
);
|
|
147
|
+
});
|
|
148
|
+
// 每个 task 都 resolve(不 reject),Promise.all 等价 allSettled
|
|
149
|
+
return Promise.all(tasks);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* 把批内 N 个 CheckResult 合并为单 CheckResult,供 reflection-evaluator 评分 proximity。
|
|
154
|
+
*
|
|
155
|
+
* 合并语义:
|
|
156
|
+
* - passed = 全部 fulfilled 且 checkResult.passed(任一失败/拒绝 → passed=false)
|
|
157
|
+
* - failedItems = 全部 fulfilled 的 failedItems 并集 + rejected/no-result 占位项(带 wpId 供 evaluator 归一化)
|
|
158
|
+
* - summary = {total:Σ, passed:Σ, failed:Σ}
|
|
159
|
+
* - wpId = 首个 wpId(reflect 单 WP 评分粒度兼容);_batchWpIds 保留全集供追溯
|
|
160
|
+
*
|
|
161
|
+
* 设计:driver 层回填策略(lastChecklist 聚合),不改 reflection-evaluator API、不触 design §5.3
|
|
162
|
+
* (计划 §3.8 的「~5 行内联」扩展为可测的独立函数)。
|
|
163
|
+
*
|
|
164
|
+
* @param {Array<{wpId:string,status:string,checkResult?:object}>} results dispatchBatch 返回值
|
|
165
|
+
* @returns {object} 合并 CheckResult(含 wpId/passed/failedItems/summary/_batchWpIds)
|
|
166
|
+
*/
|
|
167
|
+
function aggregateCheckResults(results) {
|
|
168
|
+
results = Array.isArray(results) ? results : [];
|
|
169
|
+
var allPassed = true;
|
|
170
|
+
var anyObserved = false;
|
|
171
|
+
var failedItems = [];
|
|
172
|
+
var wpIds = [];
|
|
173
|
+
var total = 0;
|
|
174
|
+
var passedCount = 0;
|
|
175
|
+
var failedCount = 0;
|
|
176
|
+
for (var i = 0; i < results.length; i++) {
|
|
177
|
+
var r = results[i];
|
|
178
|
+
if (!r) continue;
|
|
179
|
+
var cr = r.checkResult;
|
|
180
|
+
if (r.status !== 'fulfilled' || !cr) {
|
|
181
|
+
// rejected 或无 checkResult → 计为失败项(带 wpId 供 reflection-evaluator 归一化)
|
|
182
|
+
allPassed = false;
|
|
183
|
+
if (r.wpId) {
|
|
184
|
+
wpIds.push(r.wpId);
|
|
185
|
+
total += 1;
|
|
186
|
+
failedCount += 1;
|
|
187
|
+
failedItems.push({
|
|
188
|
+
wpId: r.wpId,
|
|
189
|
+
category: 'executor',
|
|
190
|
+
id: 'dispatch_' + (r.status === 'rejected' ? 'rejected' : 'no_result'),
|
|
191
|
+
reason: r.status === 'rejected' ? String(r.reason) : 'no checkResult',
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
continue;
|
|
195
|
+
}
|
|
196
|
+
anyObserved = true;
|
|
197
|
+
if (r.wpId) wpIds.push(r.wpId);
|
|
198
|
+
if (!cr.passed) allPassed = false;
|
|
199
|
+
if (cr.failedItems && cr.failedItems.length) {
|
|
200
|
+
for (var f = 0; f < cr.failedItems.length; f++) {
|
|
201
|
+
var fi = cr.failedItems[f];
|
|
202
|
+
// 补条目级 wpId:executor 产出的 failedItems 不带 fi.wpId(executor-local/claude/default
|
|
203
|
+
// 的 buildFailedChecklist 仅 id/category/reason)。批内聚合若不补,reflection-evaluator
|
|
204
|
+
// 的 failingWpsFromChecklist 会因 fi.wpId 缺失回退到聚合顶层 wpId(=wpIds[0]),把批内
|
|
205
|
+
// 某 WP 的失败错归因到首个 WP(可能已 passed)→ engine retry/resplit 指向错误 WP。
|
|
206
|
+
// 补 r.wpId 让 fi.wpId 优先归因到真正失败的 WP(review major 修复)。
|
|
207
|
+
if (fi && typeof fi === 'object' && !fi.wpId && r.wpId) {
|
|
208
|
+
var _fi = {};
|
|
209
|
+
for (var kk in fi) {
|
|
210
|
+
if (Object.prototype.hasOwnProperty.call(fi, kk)) _fi[kk] = fi[kk];
|
|
211
|
+
}
|
|
212
|
+
_fi.wpId = r.wpId;
|
|
213
|
+
fi = _fi;
|
|
214
|
+
}
|
|
215
|
+
failedItems.push(fi);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
if (cr.summary && typeof cr.summary === 'object') {
|
|
219
|
+
total += cr.summary.total || 0;
|
|
220
|
+
passedCount += cr.summary.passed || 0;
|
|
221
|
+
failedCount += cr.summary.failed || 0;
|
|
222
|
+
} else {
|
|
223
|
+
// 无 summary:按单条计
|
|
224
|
+
total += 1;
|
|
225
|
+
if (cr.passed) passedCount += 1; else failedCount += 1;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
// 空批兜底(不该发生,防御):passed=false 防止 engine 误判达成
|
|
229
|
+
if (!anyObserved && wpIds.length === 0) {
|
|
230
|
+
return { wpId: 'batch', passed: false, failedItems: [], summary: { total: 0, passed: 0, failed: 0 } };
|
|
231
|
+
}
|
|
232
|
+
return {
|
|
233
|
+
wpId: wpIds[0] || 'batch',
|
|
234
|
+
passed: allPassed,
|
|
235
|
+
failedItems: failedItems,
|
|
236
|
+
summary: { total: total, passed: passedCount, failed: failedCount },
|
|
237
|
+
_batchWpIds: wpIds,
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
module.exports = {
|
|
242
|
+
readyWaveFor: readyWaveFor,
|
|
243
|
+
dispatchBatch: dispatchBatch,
|
|
244
|
+
aggregateCheckResults: aggregateCheckResults,
|
|
245
|
+
// 暴露内部函数便于单元测试(一模块一测试 CI 70% 阈值)
|
|
246
|
+
_isDepsReady: isDepsReady,
|
|
247
|
+
};
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Loop Executor Factory — provider 路由层(WP-185-impl / WP-188 重构)
|
|
3
|
+
*
|
|
4
|
+
* @module loop-executor
|
|
5
|
+
*
|
|
6
|
+
* 职责:按 `opts.provider`(或 `opts.name`)分发到具体 executor 实现,统一
|
|
7
|
+
* `createExecutor(opts)` 工厂入口。driver 与具体 executor 实现解耦——driver 只认
|
|
8
|
+
* `createExecutor('local'|'default', opts)`,不直接 require 具体 executor 模块。
|
|
9
|
+
*
|
|
10
|
+
* 设计约束(docs/plan/agentic-loop-node-driver.md 硬约束 #3 / 成功标准 #4):
|
|
11
|
+
* - provider 解耦点是 `executor.run()`;新增 executor 时,driver 与 engine 零改动——
|
|
12
|
+
* 只需在此注册一行 + 新建 executor 模块。
|
|
13
|
+
* - 所有 executor 实现同一份接口契约:{ name, run(pendingAction)->Promise<CheckResult>, config }
|
|
14
|
+
*
|
|
15
|
+
* 注册表(REGISTRY):executor 名 → 模块 require 函数(惰性 require,避免未用 executor
|
|
16
|
+
* 的依赖在 driver 启动时被加载,如 executor-default 在 --executor=local 场景无需 spawn)。
|
|
17
|
+
*
|
|
18
|
+
* 别名:`claude` → `default`(向后兼容 v0.3.4~0.3.8 的 `--executor=claude`;重构后真实
|
|
19
|
+
* Anthropic 与智谱/mimo 等都走 default,按探测到的模型自动门控额度,故 claude 不再是
|
|
20
|
+
* 独立模块)。listProviders 不列别名(仅暴露真实 executor 名),避免给用户制造"有 claude
|
|
21
|
+
* 和 default 两个"的歧义;但 createExecutor('claude') 静默重定向。
|
|
22
|
+
*
|
|
23
|
+
* BREAKING(v0.3.10):删除 `glm` executor。`--executor=glm` 现抛 unknown provider。
|
|
24
|
+
* 智谱 GLM 现走 `--executor=default --settings=<glm-profile.json>`,由 provider-resolver
|
|
25
|
+
* 探测到 glm 模型后自动启用 5h 额度感知。详见 CHANGELOG 与 README。
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
'use strict';
|
|
29
|
+
|
|
30
|
+
// ---------------------------------------------------------------------------
|
|
31
|
+
// executor 注册表(别名在 createExecutor 内解析,不进 REGISTRY)
|
|
32
|
+
// ---------------------------------------------------------------------------
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* executor 名 → 惰性 require 工厂。
|
|
36
|
+
* 新增 executor:在此加一行 `'foo': function(){ return require('./executor-foo'); }`。
|
|
37
|
+
*/
|
|
38
|
+
var REGISTRY = {
|
|
39
|
+
local: function () { return require('./executor-local'); },
|
|
40
|
+
// WP-188 重构:单一真实 executor,spawn claude CLI,按 provider-resolver 探测结果门控额度。
|
|
41
|
+
default: function () { return require('./executor-default'); },
|
|
42
|
+
// Phase C-2:Claude Agent SDK 载体(流式消息 + AbortController 超时 + SessionStore 续轮)。
|
|
43
|
+
// SDK 为 optionalDependency——未安装时 createExecutor('sdk') 抛 SDK_UNAVAILABLE,
|
|
44
|
+
// driver/用户回退 --executor=default。
|
|
45
|
+
sdk: function () { return require('./executor-sdk'); },
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
// 别名表:alias → 真实 executor 名。listProviders 不列别名(避免歧义)。
|
|
49
|
+
var ALIASES = {
|
|
50
|
+
claude: 'default', // 向后兼容 v0.3.4~0.3.8 的 --executor=claude
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
// ---------------------------------------------------------------------------
|
|
54
|
+
// 公开 API
|
|
55
|
+
// ---------------------------------------------------------------------------
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* 列出已注册的 executor 名(供 driver 在「未知 executor」时打印可用列表)。
|
|
59
|
+
* 不列别名(别名是兼容垫片,不应作为推荐用法暴露)。
|
|
60
|
+
* @returns {string[]}
|
|
61
|
+
*/
|
|
62
|
+
function listProviders() {
|
|
63
|
+
return Object.keys(REGISTRY);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* 创建 executor 实例(路由 + 别名解析)。
|
|
68
|
+
*
|
|
69
|
+
* @param {string} [provider='local'] executor 名(local / default ...);别名 claude→default
|
|
70
|
+
* @param {object} [opts] 透传给具体 executor.createExecutor 的选项
|
|
71
|
+
* @returns {{ name:string, run:Function, config:object }}
|
|
72
|
+
* @throws {Error} provider 未注册时抛错(driver 捕获后打印可用列表)
|
|
73
|
+
*/
|
|
74
|
+
function createExecutor(provider, opts) {
|
|
75
|
+
// 兼容 createExecutor(opts) 单参调用(此时 opts.provider 指定 provider)
|
|
76
|
+
if (provider && typeof provider === 'object') {
|
|
77
|
+
opts = provider;
|
|
78
|
+
provider = opts.provider || 'local';
|
|
79
|
+
}
|
|
80
|
+
provider = provider || 'local';
|
|
81
|
+
|
|
82
|
+
// 别名解析(claude → default);别名不在 REGISTRY,避免 listProviders 暴露歧义
|
|
83
|
+
if (!REGISTRY[provider] && ALIASES[provider]) {
|
|
84
|
+
provider = ALIASES[provider];
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
var factory = REGISTRY[provider];
|
|
88
|
+
if (!factory) {
|
|
89
|
+
var err = new Error('unknown executor provider: ' + provider +
|
|
90
|
+
' (available: ' + listProviders().join(', ') + ')');
|
|
91
|
+
err.code = 'UNKNOWN_EXECUTOR';
|
|
92
|
+
err.provider = provider;
|
|
93
|
+
err.available = listProviders();
|
|
94
|
+
throw err;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
var mod;
|
|
98
|
+
try {
|
|
99
|
+
mod = factory();
|
|
100
|
+
} catch (e) {
|
|
101
|
+
var loadErr = new Error('executor module load failed (' + provider + '): ' +
|
|
102
|
+
(e && e.message ? e.message : String(e)));
|
|
103
|
+
loadErr.code = 'EXECUTOR_LOAD_FAILED';
|
|
104
|
+
loadErr.provider = provider;
|
|
105
|
+
throw loadErr;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (!mod || typeof mod.createExecutor !== 'function') {
|
|
109
|
+
throw new Error('executor module "' + provider + '" missing createExecutor export');
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return mod.createExecutor(opts);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
module.exports = {
|
|
116
|
+
createExecutor: createExecutor,
|
|
117
|
+
listProviders: listProviders,
|
|
118
|
+
_REGISTRY: REGISTRY,
|
|
119
|
+
_ALIASES: ALIASES,
|
|
120
|
+
};
|