doukui 0.4.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,
|
|
@@ -83,7 +83,7 @@ var DEFAULT_PLAN_REL = path.join('.claude', 'plan.md');
|
|
|
83
83
|
* @param {string[]} argv
|
|
84
84
|
* @returns {{planPath:string|null, executor:string, loopId:string|null,
|
|
85
85
|
* maxIters:number|null, stateDir:string|null, dryRun:boolean, force:boolean,
|
|
86
|
-
* settingsPath:string|null, error?:string}}
|
|
86
|
+
* settingsPath:string|null, roundTimeoutMs:number|null, error?:string}}
|
|
87
87
|
*/
|
|
88
88
|
function parseArgs(argv) {
|
|
89
89
|
argv = argv || [];
|
|
@@ -100,6 +100,10 @@ function parseArgs(argv) {
|
|
|
100
100
|
settingsPath: null,
|
|
101
101
|
concurrency: null,
|
|
102
102
|
noProgressDetect: false,
|
|
103
|
+
// executor 单轮超时(毫秒):null = 未传 → executor DEFAULTS(15min,零回归)。
|
|
104
|
+
// 动机:大体量 WP(21 checklist 项)健康机器上单轮也跑不完 15min 硬超时
|
|
105
|
+
// (nest loop-20261109 实证,见 claude-code-plan/executor-round-timeout.md)。
|
|
106
|
+
roundTimeoutMs: null,
|
|
103
107
|
};
|
|
104
108
|
for (var i = 0; i < argv.length; i++) {
|
|
105
109
|
var a = argv[i];
|
|
@@ -127,6 +131,10 @@ function parseArgs(argv) {
|
|
|
127
131
|
// concurrent-dispatch Step 2(文档 §5.5 escape hatch):批模式(N>1)强制 noProgress 归零
|
|
128
132
|
// 不累计发散。牺牲 per-WP 进展归因精度换稳定性(worktree 隔离降级时的兜底)。
|
|
129
133
|
out.noProgressDetect = true;
|
|
134
|
+
} else if (a.indexOf('--round-timeout-ms=') === 0) {
|
|
135
|
+
// executor 单轮超时(毫秒),driver 构造 executor 时透传 timeoutMs。
|
|
136
|
+
// 仅 driver 路径生效;默认不传 = executor DEFAULTS(15min)。
|
|
137
|
+
out.roundTimeoutMs = parseInt(a.slice('--round-timeout-ms='.length), 10);
|
|
130
138
|
} else if (a.indexOf('-') !== 0) {
|
|
131
139
|
// 第一个非 flag 参数是 plan 路径
|
|
132
140
|
if (!out.planPath) out.planPath = a;
|
|
@@ -142,6 +150,14 @@ function parseArgs(argv) {
|
|
|
142
150
|
out.maxIters = null;
|
|
143
151
|
}
|
|
144
152
|
}
|
|
153
|
+
// executor-round-timeout:--round-timeout-ms 必须 >0(NaN/0/负数均拒绝,
|
|
154
|
+
// 不静默回退——超时被静默吞掉会把大体量 WP 重新掐死在 15min)。
|
|
155
|
+
if (out.roundTimeoutMs !== null) {
|
|
156
|
+
if (isNaN(out.roundTimeoutMs) || out.roundTimeoutMs <= 0) {
|
|
157
|
+
out.error = 'Invalid --round-timeout-ms: 必须是 >0 的整数毫秒(收到 ' + out.roundTimeoutMs + ')。';
|
|
158
|
+
out.roundTimeoutMs = null;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
145
161
|
// S4:校验 loopId 字符集,防止 path.join 拼出逃逸路径
|
|
146
162
|
if (out.loopId) {
|
|
147
163
|
var v = safePath.validateSafeName(out.loopId);
|
|
@@ -574,7 +590,7 @@ module.exports = {
|
|
|
574
590
|
|
|
575
591
|
if (!fs.existsSync(planPath)) {
|
|
576
592
|
log(ctx.colorize('Error: plan file not found: ' + planPath, 'red'));
|
|
577
|
-
log('Usage: doukui loop <plan.md> [--executor=sdk|default|local] [--max-iters=N] [--loop-id=X] [--settings=<path>]');
|
|
593
|
+
log('Usage: doukui loop <plan.md> [--executor=sdk|default|local] [--max-iters=N] [--loop-id=X] [--settings=<path>] [--round-timeout-ms=N]');
|
|
578
594
|
ctx.exit(2);
|
|
579
595
|
return;
|
|
580
596
|
}
|
|
@@ -635,14 +651,14 @@ module.exports = {
|
|
|
635
651
|
if (_settingsRel.startsWith('..') || path.isAbsolute(_settingsRel)) {
|
|
636
652
|
log(ctx.colorize('Error: --settings relative path must be within project root: ' +
|
|
637
653
|
args.settingsPath + ' (resolved: ' + settingsResolved + ')', 'red'));
|
|
638
|
-
log('Usage: doukui loop <plan.md> [--executor=sdk|default|local] [--settings=<path>]');
|
|
654
|
+
log('Usage: doukui loop <plan.md> [--executor=sdk|default|local] [--settings=<path>] [--round-timeout-ms=N]');
|
|
639
655
|
ctx.exit(2);
|
|
640
656
|
return;
|
|
641
657
|
}
|
|
642
658
|
}
|
|
643
659
|
if (!fs.existsSync(settingsResolved)) {
|
|
644
660
|
log(ctx.colorize('Error: settings file not found: ' + settingsResolved, 'red'));
|
|
645
|
-
log('Usage: doukui loop <plan.md> [--executor=sdk|default|local] [--settings=<path>]');
|
|
661
|
+
log('Usage: doukui loop <plan.md> [--executor=sdk|default|local] [--settings=<path>] [--round-timeout-ms=N]');
|
|
646
662
|
ctx.exit(2);
|
|
647
663
|
return;
|
|
648
664
|
}
|
|
@@ -674,6 +690,9 @@ module.exports = {
|
|
|
674
690
|
log(ctx.colorize('=== Agentic Loop Node Driver ===', 'cyan'));
|
|
675
691
|
log('plan: ' + planPath);
|
|
676
692
|
log('executor: ' + args.executor);
|
|
693
|
+
if (args.roundTimeoutMs) {
|
|
694
|
+
log('round-timeout-ms: ' + args.roundTimeoutMs + '(executor 单轮超时,缺省 15min)');
|
|
695
|
+
}
|
|
677
696
|
if (settingsResolved) {
|
|
678
697
|
log('settings: ' + settingsResolved);
|
|
679
698
|
}
|
|
@@ -778,6 +797,9 @@ module.exports = {
|
|
|
778
797
|
contextWindow: resolvedProvider ? contextWindowResolved.tokens : null,
|
|
779
798
|
// v0.3.1 T2:系统提示模式(sdk executor 消费;default executor 忽略)
|
|
780
799
|
systemPromptMode: selfRescueCfg.systemPromptMode,
|
|
800
|
+
// executor-round-timeout:--round-timeout-ms 透传(null = 未传,
|
|
801
|
+
// executor 内 typeof 检查回退 DEFAULTS 15min,零回归)
|
|
802
|
+
timeoutMs: args.roundTimeoutMs,
|
|
781
803
|
};
|
|
782
804
|
try {
|
|
783
805
|
executor = loopExecutor.createExecutor(args.executor, executorOpts);
|
|
@@ -904,7 +926,7 @@ module.exports = {
|
|
|
904
926
|
var loopError = null;
|
|
905
927
|
|
|
906
928
|
// concurrent-dispatch Step 1(next-dev-plan Batch 2):并发批调度参数 + 状态。
|
|
907
|
-
// maxConcurrency 优先级(WP-198①):--concurrency flag > harness-config loop.concurrency >
|
|
929
|
+
// maxConcurrency 优先级(WP-198①):--concurrency flag > harness-config loop.concurrency > 3(默认并发;
|
|
908
930
|
// N=1 串行可经 flag/config 显式回退)。completedSet:已完成 WP(init 从 PROGRESS.md 恢复,支持 --loop-id
|
|
909
931
|
// 续跑;每轮 passed 更新)。loopGoal:Step 0 挂了 dependencyGraph 的 goal,算 pendingWps。
|
|
910
932
|
var configLoopConcurrency = null;
|
|
@@ -914,10 +936,10 @@ module.exports = {
|
|
|
914
936
|
if (_cfgAll2 && _cfgAll2.loop && typeof _cfgAll2.loop.concurrency === 'number') {
|
|
915
937
|
configLoopConcurrency = _cfgAll2.loop.concurrency;
|
|
916
938
|
}
|
|
917
|
-
} catch (_cfgErr2) { /* 降级:用 flag 或默认
|
|
918
|
-
//
|
|
919
|
-
// flag(--concurrency) > config
|
|
920
|
-
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;
|
|
921
943
|
if (typeof args.concurrency === 'number' && !isNaN(args.concurrency) && args.concurrency > 0) {
|
|
922
944
|
maxConcurrency = Math.floor(args.concurrency);
|
|
923
945
|
} else if (typeof configLoopConcurrency === 'number' && configLoopConcurrency > 0) {
|
|
@@ -1105,6 +1127,8 @@ module.exports = {
|
|
|
1105
1127
|
provider: (resolvedProvider ? resolvedProvider.provider : 'unknown') + '-rescued',
|
|
1106
1128
|
quotaConfig: null,
|
|
1107
1129
|
contextWindow: resolvedProvider ? contextWindowResolved.tokens : null,
|
|
1130
|
+
// 换模型自救不重置超时配置(--round-timeout-ms 继续生效)
|
|
1131
|
+
timeoutMs: args.roundTimeoutMs,
|
|
1108
1132
|
});
|
|
1109
1133
|
_rescueOk = true;
|
|
1110
1134
|
}
|
|
@@ -1196,8 +1220,12 @@ module.exports = {
|
|
|
1196
1220
|
pending.noProgressForceZero = true;
|
|
1197
1221
|
}
|
|
1198
1222
|
|
|
1199
|
-
// concurrent-dispatch Step
|
|
1200
|
-
//
|
|
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 行为(回退安全)。
|
|
1201
1229
|
var _goalWps = (loopGoal && loopGoal.wpIds) ? loopGoal.wpIds.slice() : [];
|
|
1202
1230
|
var _depOrder = (loopGoal && loopGoal.dependencyGraph && loopGoal.dependencyGraph.order && loopGoal.dependencyGraph.order.length)
|
|
1203
1231
|
? loopGoal.dependencyGraph.order : null;
|
|
@@ -1209,69 +1237,61 @@ module.exports = {
|
|
|
1209
1237
|
pendingWps.push(_wid);
|
|
1210
1238
|
}
|
|
1211
1239
|
}
|
|
1212
|
-
var wave = dispatchBatchLib.readyWaveFor({
|
|
1213
|
-
dependencyGraph: (loopGoal && loopGoal.dependencyGraph) || null,
|
|
1214
|
-
pendingWps: pendingWps,
|
|
1215
|
-
completedSet: completedSet,
|
|
1216
|
-
goalWps: _goalWps,
|
|
1217
|
-
maxConcurrency: maxConcurrency,
|
|
1218
|
-
});
|
|
1219
|
-
// engine _think 已选 pending.wpId(readyWave[0]),防御性确保它在 wave 内
|
|
1220
|
-
if (wave.indexOf(pending.wpId) === -1) wave.unshift(pending.wpId);
|
|
1221
|
-
if (wave.length > maxConcurrency) wave = wave.slice(0, maxConcurrency);
|
|
1222
|
-
|
|
1223
|
-
if (wave.length === 1) {
|
|
1224
|
-
log(ctx.colorize('▶ dispatch ' + wave[0], 'cyan') +
|
|
1225
|
-
' (mode=' + pending.mode + ', iter=' + result.iteration + ')');
|
|
1226
|
-
} else {
|
|
1227
|
-
log(ctx.colorize('▶ dispatch batch [' + wave.join(', ') + ']', 'cyan') +
|
|
1228
|
-
' (concurrency=' + wave.length + ', iter=' + result.iteration + ')');
|
|
1229
|
-
}
|
|
1230
|
-
// WP-191-1-impl-a:dispatch 前刷新心跳。executor.run 是单轮最长耗时点
|
|
1231
|
-
// (claude/glm 单轮可超 staleMs),刷新确保 coordinator 在此期间不误判 disconnected。
|
|
1232
|
-
if (workspace.isolated) touchExecutorSidecar(wsRoot);
|
|
1233
1240
|
|
|
1234
1241
|
// concurrent-dispatch Step 2(per-WP git worktree 隔离):
|
|
1235
|
-
// 仅 N>1 +
|
|
1236
|
-
// executor.run 经
|
|
1242
|
+
// 仅 N>1 + 非 local executor 启用:为每个 dispatch 的 WP 建独立 git worktree,
|
|
1243
|
+
// executor.run 经 prepareWp 注入 pendingAction.projectRoot=wtPath,
|
|
1237
1244
|
// readWorktreeDirty per-WP 准确、互不串扰(修复 v0.4.0 noProgress 批级串扰)。
|
|
1238
1245
|
// N=1 / local executor / 非 git 仓库 → 跳过(零回归 = v0.4.0)。
|
|
1239
1246
|
// WP-198①:不再要求 --loop-id(worktree 与 state isolated 解耦;无 --loop-id 时 worktree 落 projectRoot/.doukui/)。
|
|
1240
1247
|
// wtMap:{wpId: wtPath};degraded 的 WP 不写入(executor 走 config.projectRoot)。
|
|
1241
|
-
// wtBranches:{wpId: branch}
|
|
1248
|
+
// wtBranches:{wpId: branch},settle 时 cherry-pick + 清理用。
|
|
1242
1249
|
var wtMap = {};
|
|
1243
1250
|
var wtBranches = {};
|
|
1244
1251
|
// WP-198①:worktree 隔离与 state isolated 解耦——N>1 + default executor 即开(防串扰),
|
|
1245
1252
|
// 不再要求 --loop-id。state 隔离(.doukui-state/{loopId}/)仍由 --loop-id 决定。
|
|
1246
1253
|
var enableWorktree = (maxConcurrency > 1 && args.executor !== 'local');
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
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) {
|
|
1250
1264
|
try {
|
|
1251
1265
|
var wt = worktreeMod.createWorktreeForWp({
|
|
1252
1266
|
repoRoot: projectRoot,
|
|
1253
1267
|
loopId: loopId,
|
|
1254
|
-
wpId:
|
|
1268
|
+
wpId: wpId,
|
|
1255
1269
|
worktreesDir: path.join(wsRoot, '.doukui'),
|
|
1256
1270
|
});
|
|
1257
1271
|
if (!wt.degraded && wt.wtPath) {
|
|
1258
|
-
wtMap[
|
|
1259
|
-
wtBranches[
|
|
1272
|
+
wtMap[wpId] = wt.wtPath;
|
|
1273
|
+
wtBranches[wpId] = wt.branch;
|
|
1274
|
+
log(ctx.colorize(' · ' + wpId + ' per-WP worktree 隔离: ' + wt.wtPath, 'cyan'));
|
|
1260
1275
|
} else {
|
|
1261
|
-
log(ctx.colorize(' · ' +
|
|
1276
|
+
log(ctx.colorize(' · ' + wpId + ' worktree 降级 (' + (wt.reason || 'unknown') +
|
|
1262
1277
|
'),退回共享工作树', 'yellow'));
|
|
1263
1278
|
}
|
|
1264
1279
|
} catch (e) {
|
|
1265
1280
|
// 容错:worktree 基建失败绝不阻断 loop(承袭 WP-191/196 降级纪律)
|
|
1266
|
-
log(ctx.colorize(' · ' +
|
|
1281
|
+
log(ctx.colorize(' · ' + wpId + ' worktree 创建异常: ' +
|
|
1267
1282
|
((e && e.message) ? e.message : String(e)) + ',退回共享工作树', 'yellow'));
|
|
1268
1283
|
}
|
|
1269
1284
|
}
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
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];
|
|
1273
1292
|
}
|
|
1274
|
-
|
|
1293
|
+
return { projectRoot: wtMap[wpId] || null, resumeSessionId: _resumeId };
|
|
1294
|
+
};
|
|
1275
1295
|
|
|
1276
1296
|
// WP-D3:dispatch 前评估跨 provider 切换——当前 provider 窗口占用 ≥ 阈值
|
|
1277
1297
|
// 且 profile 声明了 fallback_settings → 用备用 settings 重建 default executor。
|
|
@@ -1306,25 +1326,11 @@ module.exports = {
|
|
|
1306
1326
|
}
|
|
1307
1327
|
}
|
|
1308
1328
|
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
pendingActionTemplate: pending,
|
|
1312
|
-
wpIds: wave,
|
|
1313
|
-
wpProjectRoots: Object.keys(wtMap).length > 0 ? wtMap : null,
|
|
1314
|
-
// WP-D7:retry 场景把上轮 SDK session id 注入 per-WP(SessionStore 续轮)。
|
|
1315
|
-
// 条件:sdk executor + 开关开 + 非 worktree(session 记录的 cwd 是已清理的
|
|
1316
|
-
// wt 路径,resume 后文件引用失效,保守禁用)。
|
|
1317
|
-
wpResumeSessionIds: (executor.name === 'sdk' && sdkResumeOnRetry &&
|
|
1318
|
-
Object.keys(wtMap).length === 0 && pending.mode === 'retry')
|
|
1319
|
-
? sdkSessionIds : null,
|
|
1320
|
-
});
|
|
1321
|
-
|
|
1322
|
-
// 串行回填(driver 单线程 for 循环,天然串行,无并发写)。
|
|
1329
|
+
// 单 WP settle 同步回填(滑动窗口 onSettled 钩子):worktree merge/清理 +
|
|
1330
|
+
// 进度回填 + trace。Node 单线程,settle 钩子天然串行,无并发写。
|
|
1323
1331
|
// 硬约束 #5:snapshot 从 PROGRESS.md 读 completed;passed 即 appendProgressLine。
|
|
1324
1332
|
// 隔离时 PROGRESS.md 落在 wsRoot,snapshot 的 parseProgressMarkdown 基于 cwd 探测同目录。
|
|
1325
|
-
|
|
1326
|
-
for (var ri = 0; ri < results.length; ri++) {
|
|
1327
|
-
var r = results[ri];
|
|
1333
|
+
var settleWp = function (r) {
|
|
1328
1334
|
var cr = (r.status === 'fulfilled') ? r.checkResult : null;
|
|
1329
1335
|
|
|
1330
1336
|
// Step 2 worktree 收尾:commit WP 改动 → merge 回主分支 → remove。
|
|
@@ -1400,6 +1406,8 @@ module.exports = {
|
|
|
1400
1406
|
branch: wtBranches[r.wpId],
|
|
1401
1407
|
});
|
|
1402
1408
|
} catch (_e) { /* best-effort,残留 .doukui/ 已 gitignored */ }
|
|
1409
|
+
delete wtMap[r.wpId];
|
|
1410
|
+
delete wtBranches[r.wpId];
|
|
1403
1411
|
}
|
|
1404
1412
|
}
|
|
1405
1413
|
|
|
@@ -1429,9 +1437,23 @@ module.exports = {
|
|
|
1429
1437
|
}
|
|
1430
1438
|
// WP-196-1-impl:每 WP 一条 round record(engine 阶段 + executor trace)
|
|
1431
1439
|
emitRoundTrace(ctx, log, loopId, result, cr, r.wpId);
|
|
1432
|
-
}
|
|
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
|
+
});
|
|
1433
1455
|
|
|
1434
|
-
// 回填聚合 lastChecklist
|
|
1456
|
+
// 回填聚合 lastChecklist(本轮 N 个 CheckResult 合并,供 reflection-evaluator 评分 proximity)
|
|
1435
1457
|
var aggregated = dispatchBatchLib.aggregateCheckResults(results);
|
|
1436
1458
|
driverStore.invalidate();
|
|
1437
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"
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
#
|
|
1
|
+
# 镜像路径规则(engine 行为镜像 · 会话内默认路径)
|
|
2
2
|
|
|
3
|
-
> **何时读本文件(v0.4.
|
|
4
|
-
>
|
|
5
|
-
>
|
|
3
|
+
> **何时读本文件(v0.4.1 起默认)**:skill Step 2.5 的**默认执行路径**——在当前会话内按本文件
|
|
4
|
+
> 规则框自轮询跑 loop。driver 子进程(`doukui loop`)改为显式 opt-in(用户明确要求「起 driver /
|
|
5
|
+
> 后台跑」时;其 CLI 探测失败仍输出 provider settings 修复指引,不静默换路径)。翻转依据:driver
|
|
6
|
+
> executor 单轮默认 15min 硬超时对大体量 WP 是结构性缺陷,会话内路径无此问题。
|
|
6
7
|
>
|
|
7
8
|
> **镜像一致性**:本文件规则文本是 `provider-loop-engine/index.js`(判定逻辑)+
|
|
8
9
|
> `plugins/runtime/loop-defaults.js`(阈值默认)的行为镜像,由
|
|
@@ -19,7 +19,7 @@ description: "Use when user says \"自主循环\", \"agentic loop\", \"目标驱
|
|
|
19
19
|
> - **唯一真相源** = `plugins/core/provider-loop-engine/index.js`(判定逻辑)+ `plugins/runtime/loop-defaults.js`(阈值默认值,单源化)。
|
|
20
20
|
> - 修改判定规则或默认阈值:**先改 engine / loop-defaults,再同步本 skill 的镜像段落**(含 `skill-agentic-loop/plugin.json` 的 config 静态镜像)。
|
|
21
21
|
> - 镜像一致性由 `test/runtime/test-agentic-loop-skill-mirror.js` CI 锁定(skill 文本中的默认阈值数字必须与 loop-defaults.js 相等);引用 engine 时一律用**符号名**(如 engine `_think`),禁止硬编码行号(行号随代码漂移)。
|
|
22
|
-
> - 代码驱动路径(`doukui loop`)由 JS engine
|
|
22
|
+
> - 代码驱动路径(`doukui loop`)由 JS engine 直接决策;**会话内路径**(无 driver,Step 2.5 起为默认)按镜像规则自轮询。
|
|
23
23
|
|
|
24
24
|
---
|
|
25
25
|
|
|
@@ -224,27 +224,33 @@ loop 是半自主的,**入口必须经 P1 人确认**。调用 `skill-human-ch
|
|
|
224
224
|
|
|
225
225
|
> design 把状态放在 `state-store` key `loop.{loopId}`(engine 测试用)。运行时由 Claude 通过 PROGRESS.md 维护等效信息(progress-tracker),防上下文压缩。
|
|
226
226
|
|
|
227
|
-
### Step 2.5:
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
227
|
+
### Step 2.5: 路径选择(会话内镜像 loop 默认;driver 子进程显式 opt-in)🔴
|
|
228
|
+
|
|
229
|
+
**默认路径:会话内镜像自轮询(本会话直接跑)**——Read 本 skill 目录的 `mirror-rules.md`,按其规则框
|
|
230
|
+
在当前会话内自轮询(Observe→Think→Act→Reflect→Decide,Act 委托 `skill-agent-dispatcher` 多 agent)。
|
|
231
|
+
|
|
232
|
+
> **默认翻转依据(v0.4.1,现场实证 nest 项目 loop-20261109)**:driver 路径的 executor 单轮默认
|
|
233
|
+
> 15min 硬超时对大体量 WP 是结构性缺陷——健康机器上 21 checklist 项的单轮也跑不完;内存紧张机器上
|
|
234
|
+
> SDK 子进程 15min 零字节产出被掐死,full_restart 每轮从干净 main 重来。会话内路径由本会话 Claude
|
|
235
|
+
> 驱动 dispatcher 多 agent 执行,**无单轮硬超时掐死问题**。镜像判定一致性由
|
|
236
|
+
> `test-agentic-loop-skill-mirror.js` CI 锁定。
|
|
237
|
+
|
|
238
|
+
**仅当用户明确要求「起 driver / 后台挂机跑 / `doukui loop`」时**,才走 driver 子进程路径:
|
|
239
|
+
|
|
240
|
+
1. 先探测 `doukui --version`(或 `node <doukui包根>/bin/doukui.js --version`);探测失败几乎总是
|
|
241
|
+
**provider settings 未配置**(doukui skill 与 CLI 同包分发),向用户输出修复指引,不静默换路径:
|
|
242
|
+
「driver 需要 provider settings 才能启动。请把 provider 配置 JSON 路径经 `--settings=<路径>` 传入
|
|
243
|
+
(如 `~/.claude/settings-glm.json`),或让 Claude 侧确认配置后重试。」
|
|
244
|
+
2. 用 Bash 后台启动:`doukui loop <plan 路径> --executor=sdk --loop-id=<本 loopId> [--settings=<provider 配置>] [--round-timeout-ms=<N>] &`
|
|
245
|
+
—— 决策由 **JS engine 真跑**(Observe→Think→Reflect→Decide 全在 driver 进程内),本会话只做监控,
|
|
246
|
+
**不复现任何判定规则**。大体量 WP 记得调大单轮超时(`--round-timeout-ms`,缺省 15min)。
|
|
247
|
+
3. 监控协议(每 30~60s 轮询一次,用 Bash `tail`):
|
|
248
|
+
- `.doukui/loop-{loopId}/trace.jsonl` 尾部 1 行 = 最新轮次的五段计时 + verdict + token
|
|
249
|
+
- `PROGRESS.md` = WP 完成标记
|
|
250
|
+
- 终态:driver 退出(`wait` 或检查进程)后读 stdout 尾部的「Agentic Loop 终止报告」呈现给用户;含 `♻ WP-S1 自救` 行则说明自救链已自动介入
|
|
251
|
+
4. 会话在 loop 运行期间**只读不写**仓库文件(driver 子进程持有执行权,并行写会冲突)
|
|
252
|
+
|
|
253
|
+
> **镜像路径核心速查**(默认路径,详情在 mirror-rules.md):
|
|
248
254
|
> - **Think 优先级**:失败项重试(retry)> 待执行调度(dispatch)> 被阻塞 noop;`failed` 由 `lastChecklist.failedItems` 聚合 wpId 得到
|
|
249
255
|
> - **Reflect**:`proximity = 1 - (failed/total)`;连续 `divergence_threshold` 轮不增 → diverged
|
|
250
256
|
> - **Decide 优先级**:熔断 > 发散 > 达成 > 上限 > 继续(末轮达标判 achieved 不判 timeout)
|
|
@@ -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 隔离时无需开)。
|