doukui 0.5.0 → 0.6.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/bin/commands/loop.js
CHANGED
|
@@ -61,7 +61,7 @@ var selfRescueLadder = require('../../plugins/runtime/self-rescue-ladder');
|
|
|
61
61
|
var loopReport = require('../../plugins/runtime/loop-report');
|
|
62
62
|
// concurrent-dispatch Step 1(next-dev-plan Batch 2):readyWave 批并发调度。
|
|
63
63
|
// driver 主循环单 WP dispatch → readyWave 批并发(Promise.allsettled 语义)+ 串行回填。
|
|
64
|
-
// WP-198①:默认 maxConcurrency=
|
|
64
|
+
// WP-198①:默认 maxConcurrency=3(并发开箱即用,去默认限速);N=1 串行可经 --concurrency=1
|
|
65
65
|
// 或 harness-config loop.concurrency:1 显式回退。单 executor 实例限流段同步原子,并发安全。
|
|
66
66
|
var dispatchBatchLib = require('../../plugins/runtime/loop-dispatch-batch');
|
|
67
67
|
// concurrent-dispatch Step 2(per-WP git worktree 隔离):为批内每 WP 建独立 worktree,
|
|
@@ -926,7 +926,7 @@ module.exports = {
|
|
|
926
926
|
var loopError = null;
|
|
927
927
|
|
|
928
928
|
// concurrent-dispatch Step 1(next-dev-plan Batch 2):并发批调度参数 + 状态。
|
|
929
|
-
// maxConcurrency 优先级(WP-198①):--concurrency flag > harness-config loop.concurrency >
|
|
929
|
+
// maxConcurrency 优先级(WP-198①):--concurrency flag > harness-config loop.concurrency > 3(默认并发;
|
|
930
930
|
// N=1 串行可经 flag/config 显式回退)。completedSet:已完成 WP(init 从 PROGRESS.md 恢复,支持 --loop-id
|
|
931
931
|
// 续跑;每轮 passed 更新)。loopGoal:Step 0 挂了 dependencyGraph 的 goal,算 pendingWps。
|
|
932
932
|
var configLoopConcurrency = null;
|
|
@@ -936,10 +936,10 @@ module.exports = {
|
|
|
936
936
|
if (_cfgAll2 && _cfgAll2.loop && typeof _cfgAll2.loop.concurrency === 'number') {
|
|
937
937
|
configLoopConcurrency = _cfgAll2.loop.concurrency;
|
|
938
938
|
}
|
|
939
|
-
} catch (_cfgErr2) { /* 降级:用 flag 或默认
|
|
940
|
-
//
|
|
941
|
-
// flag(--concurrency) > config
|
|
942
|
-
var maxConcurrency =
|
|
939
|
+
} catch (_cfgErr2) { /* 降级:用 flag 或默认 3 */ }
|
|
940
|
+
// 滑动窗口补位(Step 3):默认并发 2→3(v0.6.0;配合 runWaveWithRefill 飞行数恒满,
|
|
941
|
+
// GLM 端点压力可控 + worktree 开销可控)。flag(--concurrency) > config > 3(默认)。N=1 显式串行回退。
|
|
942
|
+
var maxConcurrency = 3;
|
|
943
943
|
if (typeof args.concurrency === 'number' && !isNaN(args.concurrency) && args.concurrency > 0) {
|
|
944
944
|
maxConcurrency = Math.floor(args.concurrency);
|
|
945
945
|
} else if (typeof configLoopConcurrency === 'number' && configLoopConcurrency > 0) {
|
|
@@ -1220,8 +1220,12 @@ module.exports = {
|
|
|
1220
1220
|
pending.noProgressForceZero = true;
|
|
1221
1221
|
}
|
|
1222
1222
|
|
|
1223
|
-
// concurrent-dispatch Step
|
|
1224
|
-
//
|
|
1223
|
+
// concurrent-dispatch Step 3(滑动窗口补位):算 pendingWps(依赖序中未完成),
|
|
1224
|
+
// 由 runWaveWithRefill 调度——单 WP settle → 立即回填 + 补位下一个 ready WP,
|
|
1225
|
+
// 飞行数恒满 maxConcurrency。相对旧「整批 Promise.all → 回填 → 下一轮」:
|
|
1226
|
+
// ① 消除批边界 straggler 空转(快 WP 完成后槽位立即补位,不等最慢 WP);
|
|
1227
|
+
// ② 依赖同轮解锁(依赖本轮刚完成 WP 的后继同轮即可起飞,旧须等下一轮 think)。
|
|
1228
|
+
// maxConcurrency=1 → 窗口退化为单飞串行 = v0.3.15 行为(回退安全)。
|
|
1225
1229
|
var _goalWps = (loopGoal && loopGoal.wpIds) ? loopGoal.wpIds.slice() : [];
|
|
1226
1230
|
var _depOrder = (loopGoal && loopGoal.dependencyGraph && loopGoal.dependencyGraph.order && loopGoal.dependencyGraph.order.length)
|
|
1227
1231
|
? loopGoal.dependencyGraph.order : null;
|
|
@@ -1233,69 +1237,61 @@ module.exports = {
|
|
|
1233
1237
|
pendingWps.push(_wid);
|
|
1234
1238
|
}
|
|
1235
1239
|
}
|
|
1236
|
-
var wave = dispatchBatchLib.readyWaveFor({
|
|
1237
|
-
dependencyGraph: (loopGoal && loopGoal.dependencyGraph) || null,
|
|
1238
|
-
pendingWps: pendingWps,
|
|
1239
|
-
completedSet: completedSet,
|
|
1240
|
-
goalWps: _goalWps,
|
|
1241
|
-
maxConcurrency: maxConcurrency,
|
|
1242
|
-
});
|
|
1243
|
-
// engine _think 已选 pending.wpId(readyWave[0]),防御性确保它在 wave 内
|
|
1244
|
-
if (wave.indexOf(pending.wpId) === -1) wave.unshift(pending.wpId);
|
|
1245
|
-
if (wave.length > maxConcurrency) wave = wave.slice(0, maxConcurrency);
|
|
1246
|
-
|
|
1247
|
-
if (wave.length === 1) {
|
|
1248
|
-
log(ctx.colorize('▶ dispatch ' + wave[0], 'cyan') +
|
|
1249
|
-
' (mode=' + pending.mode + ', iter=' + result.iteration + ')');
|
|
1250
|
-
} else {
|
|
1251
|
-
log(ctx.colorize('▶ dispatch batch [' + wave.join(', ') + ']', 'cyan') +
|
|
1252
|
-
' (concurrency=' + wave.length + ', iter=' + result.iteration + ')');
|
|
1253
|
-
}
|
|
1254
|
-
// WP-191-1-impl-a:dispatch 前刷新心跳。executor.run 是单轮最长耗时点
|
|
1255
|
-
// (claude/glm 单轮可超 staleMs),刷新确保 coordinator 在此期间不误判 disconnected。
|
|
1256
|
-
if (workspace.isolated) touchExecutorSidecar(wsRoot);
|
|
1257
1240
|
|
|
1258
1241
|
// concurrent-dispatch Step 2(per-WP git worktree 隔离):
|
|
1259
|
-
// 仅 N>1 +
|
|
1260
|
-
// executor.run 经
|
|
1242
|
+
// 仅 N>1 + 非 local executor 启用:为每个 dispatch 的 WP 建独立 git worktree,
|
|
1243
|
+
// executor.run 经 prepareWp 注入 pendingAction.projectRoot=wtPath,
|
|
1261
1244
|
// readWorktreeDirty per-WP 准确、互不串扰(修复 v0.4.0 noProgress 批级串扰)。
|
|
1262
1245
|
// N=1 / local executor / 非 git 仓库 → 跳过(零回归 = v0.4.0)。
|
|
1263
1246
|
// WP-198①:不再要求 --loop-id(worktree 与 state isolated 解耦;无 --loop-id 时 worktree 落 projectRoot/.doukui/)。
|
|
1264
1247
|
// wtMap:{wpId: wtPath};degraded 的 WP 不写入(executor 走 config.projectRoot)。
|
|
1265
|
-
// wtBranches:{wpId: branch}
|
|
1248
|
+
// wtBranches:{wpId: branch},settle 时 cherry-pick + 清理用。
|
|
1266
1249
|
var wtMap = {};
|
|
1267
1250
|
var wtBranches = {};
|
|
1268
1251
|
// WP-198①:worktree 隔离与 state isolated 解耦——N>1 + default executor 即开(防串扰),
|
|
1269
1252
|
// 不再要求 --loop-id。state 隔离(.doukui-state/{loopId}/)仍由 --loop-id 决定。
|
|
1270
1253
|
var enableWorktree = (maxConcurrency > 1 && args.executor !== 'local');
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1254
|
+
|
|
1255
|
+
// per-WP dispatch 前准备(滑动窗口 onBeforeDispatch 钩子,同步):
|
|
1256
|
+
// 刷心跳 + 打点 + 建 worktree + 查上轮 SDK session id。
|
|
1257
|
+
var prepareWp = function (wpId) {
|
|
1258
|
+
// WP-191-1-impl-a:dispatch 前刷新心跳。executor.run 是单轮最长耗时点
|
|
1259
|
+
// (claude/glm 单轮可超 staleMs),刷新确保 coordinator 在此期间不误判 disconnected。
|
|
1260
|
+
if (workspace.isolated) touchExecutorSidecar(wsRoot);
|
|
1261
|
+
log(ctx.colorize('▶ dispatch ' + wpId, 'cyan') +
|
|
1262
|
+
' (mode=' + pending.mode + ', iter=' + result.iteration + ')');
|
|
1263
|
+
if (enableWorktree) {
|
|
1274
1264
|
try {
|
|
1275
1265
|
var wt = worktreeMod.createWorktreeForWp({
|
|
1276
1266
|
repoRoot: projectRoot,
|
|
1277
1267
|
loopId: loopId,
|
|
1278
|
-
wpId:
|
|
1268
|
+
wpId: wpId,
|
|
1279
1269
|
worktreesDir: path.join(wsRoot, '.doukui'),
|
|
1280
1270
|
});
|
|
1281
1271
|
if (!wt.degraded && wt.wtPath) {
|
|
1282
|
-
wtMap[
|
|
1283
|
-
wtBranches[
|
|
1272
|
+
wtMap[wpId] = wt.wtPath;
|
|
1273
|
+
wtBranches[wpId] = wt.branch;
|
|
1274
|
+
log(ctx.colorize(' · ' + wpId + ' per-WP worktree 隔离: ' + wt.wtPath, 'cyan'));
|
|
1284
1275
|
} else {
|
|
1285
|
-
log(ctx.colorize(' · ' +
|
|
1276
|
+
log(ctx.colorize(' · ' + wpId + ' worktree 降级 (' + (wt.reason || 'unknown') +
|
|
1286
1277
|
'),退回共享工作树', 'yellow'));
|
|
1287
1278
|
}
|
|
1288
1279
|
} catch (e) {
|
|
1289
1280
|
// 容错:worktree 基建失败绝不阻断 loop(承袭 WP-191/196 降级纪律)
|
|
1290
|
-
log(ctx.colorize(' · ' +
|
|
1281
|
+
log(ctx.colorize(' · ' + wpId + ' worktree 创建异常: ' +
|
|
1291
1282
|
((e && e.message) ? e.message : String(e)) + ',退回共享工作树', 'yellow'));
|
|
1292
1283
|
}
|
|
1293
1284
|
}
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1285
|
+
// WP-D7:per-WP 上轮 SDK session id(retry 续轮;executor-sdk 消费,其他 executor 忽略)。
|
|
1286
|
+
// 条件:sdk executor + 开关开 + 该 WP 无 worktree(session 记录的 cwd 是已清理的
|
|
1287
|
+
// wt 路径,resume 后文件引用失效,保守禁用)+ retry 模式。
|
|
1288
|
+
var _resumeId = null;
|
|
1289
|
+
if (executor.name === 'sdk' && sdkResumeOnRetry && !wtMap[wpId] &&
|
|
1290
|
+
pending.mode === 'retry' && sdkSessionIds[wpId]) {
|
|
1291
|
+
_resumeId = sdkSessionIds[wpId];
|
|
1297
1292
|
}
|
|
1298
|
-
|
|
1293
|
+
return { projectRoot: wtMap[wpId] || null, resumeSessionId: _resumeId };
|
|
1294
|
+
};
|
|
1299
1295
|
|
|
1300
1296
|
// WP-D3:dispatch 前评估跨 provider 切换——当前 provider 窗口占用 ≥ 阈值
|
|
1301
1297
|
// 且 profile 声明了 fallback_settings → 用备用 settings 重建 default executor。
|
|
@@ -1330,25 +1326,11 @@ module.exports = {
|
|
|
1330
1326
|
}
|
|
1331
1327
|
}
|
|
1332
1328
|
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
pendingActionTemplate: pending,
|
|
1336
|
-
wpIds: wave,
|
|
1337
|
-
wpProjectRoots: Object.keys(wtMap).length > 0 ? wtMap : null,
|
|
1338
|
-
// WP-D7:retry 场景把上轮 SDK session id 注入 per-WP(SessionStore 续轮)。
|
|
1339
|
-
// 条件:sdk executor + 开关开 + 非 worktree(session 记录的 cwd 是已清理的
|
|
1340
|
-
// wt 路径,resume 后文件引用失效,保守禁用)。
|
|
1341
|
-
wpResumeSessionIds: (executor.name === 'sdk' && sdkResumeOnRetry &&
|
|
1342
|
-
Object.keys(wtMap).length === 0 && pending.mode === 'retry')
|
|
1343
|
-
? sdkSessionIds : null,
|
|
1344
|
-
});
|
|
1345
|
-
|
|
1346
|
-
// 串行回填(driver 单线程 for 循环,天然串行,无并发写)。
|
|
1329
|
+
// 单 WP settle 同步回填(滑动窗口 onSettled 钩子):worktree merge/清理 +
|
|
1330
|
+
// 进度回填 + trace。Node 单线程,settle 钩子天然串行,无并发写。
|
|
1347
1331
|
// 硬约束 #5:snapshot 从 PROGRESS.md 读 completed;passed 即 appendProgressLine。
|
|
1348
1332
|
// 隔离时 PROGRESS.md 落在 wsRoot,snapshot 的 parseProgressMarkdown 基于 cwd 探测同目录。
|
|
1349
|
-
|
|
1350
|
-
for (var ri = 0; ri < results.length; ri++) {
|
|
1351
|
-
var r = results[ri];
|
|
1333
|
+
var settleWp = function (r) {
|
|
1352
1334
|
var cr = (r.status === 'fulfilled') ? r.checkResult : null;
|
|
1353
1335
|
|
|
1354
1336
|
// Step 2 worktree 收尾:commit WP 改动 → merge 回主分支 → remove。
|
|
@@ -1424,6 +1406,8 @@ module.exports = {
|
|
|
1424
1406
|
branch: wtBranches[r.wpId],
|
|
1425
1407
|
});
|
|
1426
1408
|
} catch (_e) { /* best-effort,残留 .doukui/ 已 gitignored */ }
|
|
1409
|
+
delete wtMap[r.wpId];
|
|
1410
|
+
delete wtBranches[r.wpId];
|
|
1427
1411
|
}
|
|
1428
1412
|
}
|
|
1429
1413
|
|
|
@@ -1453,9 +1437,23 @@ module.exports = {
|
|
|
1453
1437
|
}
|
|
1454
1438
|
// WP-196-1-impl:每 WP 一条 round record(engine 阶段 + executor trace)
|
|
1455
1439
|
emitRoundTrace(ctx, log, loopId, result, cr, r.wpId);
|
|
1456
|
-
}
|
|
1440
|
+
};
|
|
1441
|
+
|
|
1442
|
+
var results = await dispatchBatchLib.runWaveWithRefill({
|
|
1443
|
+
executor: executor,
|
|
1444
|
+
pendingActionTemplate: pending,
|
|
1445
|
+
pendingWps: pendingWps,
|
|
1446
|
+
dependencyGraph: (loopGoal && loopGoal.dependencyGraph) || null,
|
|
1447
|
+
completedSet: completedSet,
|
|
1448
|
+
goalWps: _goalWps,
|
|
1449
|
+
maxConcurrency: maxConcurrency,
|
|
1450
|
+
// engine _think 已选 pending.wpId,防御性确保它在首波(对齐旧 unshift 语义)
|
|
1451
|
+
mustIncludeWpId: pending.wpId,
|
|
1452
|
+
onBeforeDispatch: prepareWp,
|
|
1453
|
+
onSettled: settleWp,
|
|
1454
|
+
});
|
|
1457
1455
|
|
|
1458
|
-
// 回填聚合 lastChecklist
|
|
1456
|
+
// 回填聚合 lastChecklist(本轮 N 个 CheckResult 合并,供 reflection-evaluator 评分 proximity)
|
|
1459
1457
|
var aggregated = dispatchBatchLib.aggregateCheckResults(results);
|
|
1460
1458
|
driverStore.invalidate();
|
|
1461
1459
|
await driverStore.set('loop.' + loopId + '.lastChecklist', aggregated);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "doukui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Doukui (斗魁) - multi-provider AI agent orchestration harness for Claude Code: goal-driven agentic loop, dependency-graph dispatch, per-WP worktree isolation, for GLM/DeepSeek/MiMo and Claude",
|
|
5
5
|
"bin": {
|
|
6
6
|
"doukui": "bin/doukui.js"
|
|
@@ -238,9 +238,113 @@ function aggregateCheckResults(results) {
|
|
|
238
238
|
};
|
|
239
239
|
}
|
|
240
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
|
+
|
|
241
344
|
module.exports = {
|
|
242
345
|
readyWaveFor: readyWaveFor,
|
|
243
346
|
dispatchBatch: dispatchBatch,
|
|
347
|
+
runWaveWithRefill: runWaveWithRefill,
|
|
244
348
|
aggregateCheckResults: aggregateCheckResults,
|
|
245
349
|
// 暴露内部函数便于单元测试(一模块一测试 CI 70% 阈值)
|
|
246
350
|
_isDepsReady: isDepsReady,
|
|
@@ -286,19 +286,20 @@ loop:
|
|
|
286
286
|
# default = SDK 全量注入(v0.3.0 行为,安全默认)。
|
|
287
287
|
# system_prompt_mode: lean
|
|
288
288
|
|
|
289
|
-
# concurrent-dispatch Step
|
|
290
|
-
#
|
|
291
|
-
#
|
|
292
|
-
#
|
|
289
|
+
# concurrent-dispatch Step 3(滑动窗口补位,v0.6.0):单 WP 完成 → 立即回填 + 补位
|
|
290
|
+
# 下一个 ready WP,飞行数恒满 concurrency;依赖「本轮刚完成 WP」的后继同轮即起飞。
|
|
291
|
+
# 默认并发 3(WP-198① 去默认限速,所有 provider 一视同仁;v0.6.0 起 2→3)。
|
|
292
|
+
# 优先级:--concurrency flag > 此值 > 3(默认)。N=1 显式串行回退。
|
|
293
|
+
# N>1 时飞行中额度检查-消耗间隙放大,由 executor softThreshold(0.9) + coordinator
|
|
293
294
|
# hardThreshold(0.95) 兜底;若需限速可设 concurrency:1 或 --concurrency=1。
|
|
294
295
|
#
|
|
295
296
|
# concurrent-dispatch Step 2(per-WP git worktree 隔离,v0.4.1):N>1 + default executor
|
|
296
|
-
#
|
|
297
|
+
# 时,每个 dispatch 的 WP 建独立 git worktree(.doukui/wt-{loopId}-{wpId}),executor 在各自 cwd 跑,
|
|
297
298
|
# readWorktreeDirty per-WP 准确、互不串扰(修复 v0.4.0 noProgress 批级串扰)。
|
|
298
|
-
#
|
|
299
|
+
# settle 时逐个 cherry-pick 回主分支(策略 A),冲突不阻断(engine retry/resplit 兜底)。
|
|
299
300
|
# WP-198①:worktree 与 state isolated 解耦——N>1 即开,无需 --loop-id(无 --loop-id 时
|
|
300
301
|
# worktree 落 projectRoot/.doukui/,.gitignore 已覆盖)。N=1 / local / 非 git → 跳过。
|
|
301
|
-
# concurrency: 1 # 默认注释掉 → 走 loop.js fallback=
|
|
302
|
+
# concurrency: 1 # 默认注释掉 → 走 loop.js fallback=3(默认并发);取消注释可显式覆盖(如 1 限速)
|
|
302
303
|
# no_progress_detect(concurrent-dispatch Step 2 escape hatch,文档 §5.5):N>1 时强制
|
|
303
304
|
# noProgress 归零不累计发散(牺牲 per-WP 进展归因精度换稳定性)。worktree 降级时的兜底。
|
|
304
305
|
# --no-progress-detect flag 优先于此值;默认 false(启用 worktree 隔离时无需开)。
|