doukui 0.6.0 → 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/README.en.md +85 -18
- package/README.md +32 -72
- package/bin/commands/help.js +2 -25
- package/bin/commands/plan-lint.js +105 -0
- package/bin/commands/verify.js +263 -0
- package/bin/doukui.js +3 -3
- package/package.json +2 -3
- package/plugins/core/hook-session-start/index.js +1 -1
- package/plugins/core/hook-skill-gate/index.js +64 -15
- package/plugins/core/hook-skill-gate/plugin.json +1 -1
- package/plugins/core/skill-agent-dispatcher/cleanup-reference.md +7 -28
- package/plugins/core/skill-agent-dispatcher/monitoring-reference.md +89 -0
- package/plugins/core/skill-agent-dispatcher/plugin.json +1 -1
- package/plugins/core/skill-agent-dispatcher/recovery-reference.md +132 -0
- package/plugins/core/skill-agent-dispatcher/roles-reference.md +9 -22
- package/plugins/core/skill-agent-dispatcher/skill.md +124 -796
- package/plugins/core/skill-agentic-loop/mirror-rules.md +95 -24
- package/plugins/core/skill-agentic-loop/plugin.json +2 -7
- package/plugins/core/skill-agentic-loop/skill.md +125 -354
- package/plugins/core/skill-batch-task-creator/plugin.json +1 -1
- package/plugins/core/skill-checklist/skill.md +15 -141
- package/plugins/core/skill-completion-report/plugin.json +1 -1
- package/plugins/core/skill-completion-report/skill.md +7 -1
- package/plugins/core/skill-doukui-plan/plugin.json +1 -1
- package/plugins/core/skill-doukui-plan/skill.md +24 -21
- package/plugins/core/skill-experience-logger/plugin.json +1 -1
- package/plugins/core/skill-human-checkpoint/skill.md +1 -0
- package/plugins/core/skill-split-work-package/plugin.json +1 -1
- package/plugins/core/skill-task-creator/plugin.json +1 -1
- package/plugins/core/skill-task-creator/skill.md +1 -139
- package/plugins/core/skill-workflow-orchestrator/plugin.json +1 -1
- package/plugins/plugin-registry.json +0 -48
- package/plugins/runtime/harness-build.js +5 -5
- package/plugins/runtime/plan-reader.js +54 -21
- package/plugins/runtime/resolve-plugin-path.js +2 -2
- package/templates/harness-config.yaml +0 -100
- package/bin/commands/loop-server.js +0 -357
- package/bin/commands/loop.js +0 -1508
- package/plugins/contracts/capabilities.js +0 -268
- package/plugins/contracts/checkresult-schema.json +0 -75
- package/plugins/core/provider-loop-engine/index.js +0 -1411
- package/plugins/core/provider-loop-engine/plugin.json +0 -15
- package/plugins/core/provider-memory-store/index.js +0 -510
- package/plugins/core/provider-memory-store/plugin.json +0 -9
- package/plugins/core/provider-state-store/index.js +0 -244
- package/plugins/core/provider-state-store/plugin.json +0 -9
- package/plugins/core/provider-watchdog/assets/daemon-config.template.json +0 -32
- package/plugins/core/provider-watchdog/assets/lib/watchdog-multi-window.js +0 -676
- package/plugins/core/provider-watchdog/assets/watchdog.js +0 -754
- package/plugins/core/provider-watchdog/index.js +0 -151
- package/plugins/core/provider-watchdog/plugin.json +0 -13
- package/plugins/core/skill-agent-dispatcher/daemon-helpers-reference.md +0 -249
- package/plugins/core/skill-watchdog-manager/plugin.json +0 -10
- package/plugins/core/skill-watchdog-manager/skill.md +0 -143
- package/plugins/core/validator-doc-sync/index.js +0 -248
- package/plugins/core/validator-doc-sync/plugin.json +0 -12
- package/plugins/core/validator-work-package/index.js +0 -300
- package/plugins/core/validator-work-package/plugin.json +0 -12
- package/plugins/runtime/audit-logger.js +0 -311
- package/plugins/runtime/build-cli.js +0 -89
- package/plugins/runtime/checkresult-validator.js +0 -131
- package/plugins/runtime/context-window.js +0 -81
- package/plugins/runtime/event-bus.js +0 -207
- package/plugins/runtime/executor-claude.js +0 -604
- package/plugins/runtime/executor-default.js +0 -448
- package/plugins/runtime/executor-local.js +0 -178
- package/plugins/runtime/executor-sdk.js +0 -415
- package/plugins/runtime/hook-dispatcher.js +0 -315
- package/plugins/runtime/loop-actuator.js +0 -292
- package/plugins/runtime/loop-coordinator.js +0 -347
- package/plugins/runtime/loop-defaults.js +0 -29
- package/plugins/runtime/loop-dispatch-batch.js +0 -351
- package/plugins/runtime/loop-executor.js +0 -120
- package/plugins/runtime/loop-report.js +0 -395
- package/plugins/runtime/loop-server-core.js +0 -750
- package/plugins/runtime/loop-snapshot.js +0 -581
- package/plugins/runtime/loop-trace.js +0 -242
- package/plugins/runtime/loop-worktree.js +0 -404
- package/plugins/runtime/multi-window-coordinator.js +0 -560
- package/plugins/runtime/objective-verifier.js +0 -136
- package/plugins/runtime/plan-lint.js +0 -106
- package/plugins/runtime/plugin-loader.js +0 -798
- package/plugins/runtime/plugin-trust.js +0 -182
- package/plugins/runtime/provider-failover.js +0 -114
- package/plugins/runtime/provider-resolver.js +0 -342
- package/plugins/runtime/reflection-evaluator.js +0 -545
- package/plugins/runtime/sandbox-context.js +0 -235
- package/plugins/runtime/sandbox-manager.js +0 -609
- package/plugins/runtime/sandbox-worker.js +0 -215
- package/plugins/runtime/self-rescue-ladder.js +0 -51
- package/plugins/runtime/text-tokenize.js +0 -25
- package/plugins/runtime/validator-pipeline.js +0 -475
|
@@ -1,351 +0,0 @@
|
|
|
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
|
-
/**
|
|
242
|
-
* 滑动窗口补位调度:把「整批 Promise.all → 回填 → 下一轮」升级为
|
|
243
|
-
* 「单 WP settle → 立即回填 → 立即补位下一个 ready WP」。
|
|
244
|
-
*
|
|
245
|
-
* 相对 dispatchBatch 的两点提速:
|
|
246
|
-
* 1. 消除批边界 straggler 空转:批内快 WP 完成后槽位立即补位,不等最慢 WP;
|
|
247
|
-
* 2. 依赖同轮解锁:onSettled 更新 completedSet(同步),补位重算 readyWave 时
|
|
248
|
-
* 依赖「本轮刚完成 WP」的后继 WP 同轮即可起飞(现状须等下一轮 think)。
|
|
249
|
-
*
|
|
250
|
-
* 调度纪律(与 dispatchBatch / driver 现状语义对齐):
|
|
251
|
-
* - 失败(rejected / 未 passed)的 WP 不回 pending 池——本轮不重试,下轮 engine think 裁决;
|
|
252
|
-
* - 首波 mustIncludeWpId 强塞(engine 已选 WP 依赖未就绪也在首波,对齐 driver unshift 语义);
|
|
253
|
-
* - onSettled / onBeforeDispatch 为同步钩子(Node 单线程天然串行,回填无并发写)。
|
|
254
|
-
*
|
|
255
|
-
* @param {object} opts
|
|
256
|
-
* @param {object} opts.executor executor 实例(窗口存续期内固定;provider failover 留在 round 边界)
|
|
257
|
-
* @param {object} opts.pendingActionTemplate actuator 产出的 pendingAction 模板
|
|
258
|
-
* @param {string[]} opts.pendingWps 未完成 WP(建议按拓扑序;函数内部克隆不改原数组)
|
|
259
|
-
* @param {object} [opts.dependencyGraph] {nodes,...}(plan-reader 产出)
|
|
260
|
-
* @param {string[]} [opts.completedSet] 已完成 WP id(onSettled 内更新此引用,补位重算可见)
|
|
261
|
-
* @param {string[]|null} [opts.goalWps] goal 范围(越界保护)
|
|
262
|
-
* @param {number} [opts.maxConcurrency=1]
|
|
263
|
-
* @param {string} [opts.mustIncludeWpId] 首波必须包含的 wpId(engine 已选)
|
|
264
|
-
* @param {Function} [opts.onBeforeDispatch] (wpId) → {projectRoot?, resumeSessionId?}|null(dispatch 前钩子:建 worktree/刷心跳)
|
|
265
|
-
* @param {Function} [opts.onSettled] (settledResult) → void(同步回填钩子:merge/appendProgressLine/completedSet 更新)
|
|
266
|
-
* @returns {Promise<Array<{wpId:string,status:'fulfilled'|'rejected',checkResult?:object,reason?:*}>>}
|
|
267
|
-
* 全部 settled 结果(按完成顺序),供 aggregateCheckResults 聚合
|
|
268
|
-
*/
|
|
269
|
-
async function runWaveWithRefill(opts) {
|
|
270
|
-
opts = opts || {};
|
|
271
|
-
var executor = opts.executor;
|
|
272
|
-
var template = opts.pendingActionTemplate || {};
|
|
273
|
-
var dependencyGraph = opts.dependencyGraph || null;
|
|
274
|
-
var goalWps = Array.isArray(opts.goalWps) ? opts.goalWps : null;
|
|
275
|
-
var max = (typeof opts.maxConcurrency === 'number' && opts.maxConcurrency > 0)
|
|
276
|
-
? Math.floor(opts.maxConcurrency) : 1;
|
|
277
|
-
var onBeforeDispatch = (typeof opts.onBeforeDispatch === 'function') ? opts.onBeforeDispatch : null;
|
|
278
|
-
var onSettled = (typeof opts.onSettled === 'function') ? opts.onSettled : null;
|
|
279
|
-
if (!executor || typeof executor.run !== 'function') return [];
|
|
280
|
-
|
|
281
|
-
var pending = (Array.isArray(opts.pendingWps) ? opts.pendingWps : []).slice();
|
|
282
|
-
var completedSet = Array.isArray(opts.completedSet) ? opts.completedSet : [];
|
|
283
|
-
var settledResults = [];
|
|
284
|
-
var flying = {}; // wpId → settle promise(promise resolve 前 refill 已同步跑完)
|
|
285
|
-
var firstWave = true;
|
|
286
|
-
|
|
287
|
-
function launch(wpId) {
|
|
288
|
-
var pi = pending.indexOf(wpId);
|
|
289
|
-
if (pi !== -1) pending.splice(pi, 1);
|
|
290
|
-
// 克隆 pendingAction 仅换 wpId + onBeforeDispatch 注入(对齐 dispatchBatch 克隆语义)
|
|
291
|
-
var pa = {};
|
|
292
|
-
for (var k in template) {
|
|
293
|
-
if (Object.prototype.hasOwnProperty.call(template, k)) pa[k] = template[k];
|
|
294
|
-
}
|
|
295
|
-
pa.wpId = wpId;
|
|
296
|
-
if (onBeforeDispatch) {
|
|
297
|
-
var pre = onBeforeDispatch(wpId) || {};
|
|
298
|
-
if (pre.projectRoot) pa.projectRoot = pre.projectRoot;
|
|
299
|
-
if (pre.resumeSessionId) pa.resumeSessionId = pre.resumeSessionId;
|
|
300
|
-
}
|
|
301
|
-
flying[wpId] = Promise.resolve(executor.run(pa)).then(
|
|
302
|
-
function (checkResult) {
|
|
303
|
-
return { wpId: wpId, status: 'fulfilled', checkResult: checkResult };
|
|
304
|
-
},
|
|
305
|
-
function (err) {
|
|
306
|
-
// 单失败不阻断窗口:rejected 也 settle
|
|
307
|
-
return { wpId: wpId, status: 'rejected', reason: err };
|
|
308
|
-
}
|
|
309
|
-
).then(function (settled) {
|
|
310
|
-
delete flying[wpId];
|
|
311
|
-
settledResults.push(settled);
|
|
312
|
-
if (onSettled) onSettled(settled); // 同步回填(completedSet 更新于此,补位可见)
|
|
313
|
-
refill();
|
|
314
|
-
return settled;
|
|
315
|
-
});
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
function refill() {
|
|
319
|
-
var slots = max - Object.keys(flying).length;
|
|
320
|
-
if (slots <= 0) return;
|
|
321
|
-
var wave = readyWaveFor({
|
|
322
|
-
dependencyGraph: dependencyGraph, pendingWps: pending,
|
|
323
|
-
completedSet: completedSet, goalWps: goalWps, maxConcurrency: slots,
|
|
324
|
-
});
|
|
325
|
-
// 首波防御:engine 已选 wpId 必须在首波(对齐 driver 旧 unshift + slice 语义)
|
|
326
|
-
if (firstWave && opts.mustIncludeWpId && wave.indexOf(opts.mustIncludeWpId) === -1 &&
|
|
327
|
-
pending.indexOf(opts.mustIncludeWpId) !== -1) {
|
|
328
|
-
wave.unshift(opts.mustIncludeWpId);
|
|
329
|
-
if (wave.length > slots) wave = wave.slice(0, slots);
|
|
330
|
-
}
|
|
331
|
-
firstWave = false;
|
|
332
|
-
for (var i = 0; i < wave.length; i++) launch(wave[i]);
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
refill();
|
|
336
|
-
return (function waitAll() {
|
|
337
|
-
var keys = Object.keys(flying);
|
|
338
|
-
if (keys.length === 0) return Promise.resolve(settledResults.slice());
|
|
339
|
-
// settle promise resolve 时 refill 已同步执行完,waitAll 重读 flying 不会漏新补位的 WP
|
|
340
|
-
return Promise.all(keys.map(function (k) { return flying[k]; })).then(waitAll);
|
|
341
|
-
})();
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
module.exports = {
|
|
345
|
-
readyWaveFor: readyWaveFor,
|
|
346
|
-
dispatchBatch: dispatchBatch,
|
|
347
|
-
runWaveWithRefill: runWaveWithRefill,
|
|
348
|
-
aggregateCheckResults: aggregateCheckResults,
|
|
349
|
-
// 暴露内部函数便于单元测试(一模块一测试 CI 70% 阈值)
|
|
350
|
-
_isDepsReady: isDepsReady,
|
|
351
|
-
};
|
|
@@ -1,120 +0,0 @@
|
|
|
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
|
-
};
|