doukui 0.3.1 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/bin/commands/loop.js +82 -15
- package/package.json +1 -1
- package/plugins/core/hook-skill-gate/index.js +18 -17
- package/plugins/core/skill-agent-dispatcher/skill.md +93 -388
- package/plugins/core/skill-agentic-loop/mirror-rules.md +100 -0
- package/plugins/core/skill-agentic-loop/plugin.json +1 -1
- package/plugins/core/skill-agentic-loop/skill.md +38 -164
- package/plugins/core/skill-batch-task-creator/skill.md +14 -65
- package/plugins/core/skill-split-work-package/skill.md +14 -65
- package/plugins/core/skill-task-creator/context-budget-reference.md +67 -0
- package/plugins/core/skill-task-creator/skill.md +14 -63
- package/plugins/runtime/executor-claude.js +11 -235
- package/plugins/runtime/executor-default.js +7 -7
- package/plugins/runtime/loop-report.js +68 -0
- package/plugins/runtime/plan-lint.js +7 -1
- package/plugins/runtime/self-rescue-ladder.js +14 -1
- package/templates/harness-config.yaml +29 -4
package/README.md
CHANGED
|
@@ -33,7 +33,7 @@ doukui loop docs/plan/my-plan.md --executor=sdk \
|
|
|
33
33
|
--settings=~/.claude/settings-glm-5.2[1m]max.json
|
|
34
34
|
|
|
35
35
|
# spawn CLI 载体(不装 SDK 时的回退,行为一致)
|
|
36
|
-
doukui loop docs/plan/my-plan.md --executor=
|
|
36
|
+
doukui loop docs/plan/my-plan.md --executor=sdk
|
|
37
37
|
|
|
38
38
|
# 并发批:默认 N=2,批内 WP 并行 spawn + per-WP worktree 隔离
|
|
39
39
|
doukui loop my-plan.md --executor=sdk --concurrency=2
|
package/bin/commands/loop.js
CHANGED
|
@@ -57,6 +57,8 @@ var providerFailover = require('../../plugins/runtime/provider-failover');
|
|
|
57
57
|
// v0.3.1 T4:plan 质量前置闸(空 checklist 拒启 / verify 命令拼错前置暴露)
|
|
58
58
|
var planLint = require('../../plugins/runtime/plan-lint');
|
|
59
59
|
var selfRescueLadder = require('../../plugins/runtime/self-rescue-ladder');
|
|
60
|
+
// v0.4.0 A1:降级交付报告(自救梯穷尽 + 有部分成果时,替代纯失败退出)
|
|
61
|
+
var loopReport = require('../../plugins/runtime/loop-report');
|
|
60
62
|
// concurrent-dispatch Step 1(next-dev-plan Batch 2):readyWave 批并发调度。
|
|
61
63
|
// driver 主循环单 WP dispatch → readyWave 批并发(Promise.allsettled 语义)+ 串行回填。
|
|
62
64
|
// WP-198①:默认 maxConcurrency=2(并发开箱即用,去默认限速);N=1 串行可经 --concurrency=1
|
|
@@ -81,13 +83,15 @@ var DEFAULT_PLAN_REL = path.join('.claude', 'plan.md');
|
|
|
81
83
|
* @param {string[]} argv
|
|
82
84
|
* @returns {{planPath:string|null, executor:string, loopId:string|null,
|
|
83
85
|
* maxIters:number|null, stateDir:string|null, dryRun:boolean, force:boolean,
|
|
84
|
-
* settingsPath:string|null, error?:string}}
|
|
86
|
+
* settingsPath:string|null, roundTimeoutMs:number|null, error?:string}}
|
|
85
87
|
*/
|
|
86
88
|
function parseArgs(argv) {
|
|
87
89
|
argv = argv || [];
|
|
88
90
|
var out = {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
+
// v0.4.0 T1:默认 executor local(mock) → sdk(SDK 载体 + SessionStore 续轮,
|
|
92
|
+
// retry 轮只付增量 token);SDK 未装(optionalDependency)时创建处自动降级
|
|
93
|
+
// default(spawn CLI)。显式 --executor=local 保留 mock 语义(测试用)。
|
|
94
|
+
executor: 'sdk',
|
|
91
95
|
loopId: null,
|
|
92
96
|
maxIters: null,
|
|
93
97
|
stateDir: null,
|
|
@@ -96,6 +100,10 @@ function parseArgs(argv) {
|
|
|
96
100
|
settingsPath: null,
|
|
97
101
|
concurrency: null,
|
|
98
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,
|
|
99
107
|
};
|
|
100
108
|
for (var i = 0; i < argv.length; i++) {
|
|
101
109
|
var a = argv[i];
|
|
@@ -123,6 +131,10 @@ function parseArgs(argv) {
|
|
|
123
131
|
// concurrent-dispatch Step 2(文档 §5.5 escape hatch):批模式(N>1)强制 noProgress 归零
|
|
124
132
|
// 不累计发散。牺牲 per-WP 进展归因精度换稳定性(worktree 隔离降级时的兜底)。
|
|
125
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);
|
|
126
138
|
} else if (a.indexOf('-') !== 0) {
|
|
127
139
|
// 第一个非 flag 参数是 plan 路径
|
|
128
140
|
if (!out.planPath) out.planPath = a;
|
|
@@ -138,6 +150,14 @@ function parseArgs(argv) {
|
|
|
138
150
|
out.maxIters = null;
|
|
139
151
|
}
|
|
140
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
|
+
}
|
|
141
161
|
// S4:校验 loopId 字符集,防止 path.join 拼出逃逸路径
|
|
142
162
|
if (out.loopId) {
|
|
143
163
|
var v = safePath.validateSafeName(out.loopId);
|
|
@@ -570,7 +590,7 @@ module.exports = {
|
|
|
570
590
|
|
|
571
591
|
if (!fs.existsSync(planPath)) {
|
|
572
592
|
log(ctx.colorize('Error: plan file not found: ' + planPath, 'red'));
|
|
573
|
-
log('Usage: doukui loop <plan.md> [--executor=
|
|
593
|
+
log('Usage: doukui loop <plan.md> [--executor=sdk|default|local] [--max-iters=N] [--loop-id=X] [--settings=<path>] [--round-timeout-ms=N]');
|
|
574
594
|
ctx.exit(2);
|
|
575
595
|
return;
|
|
576
596
|
}
|
|
@@ -631,14 +651,14 @@ module.exports = {
|
|
|
631
651
|
if (_settingsRel.startsWith('..') || path.isAbsolute(_settingsRel)) {
|
|
632
652
|
log(ctx.colorize('Error: --settings relative path must be within project root: ' +
|
|
633
653
|
args.settingsPath + ' (resolved: ' + settingsResolved + ')', 'red'));
|
|
634
|
-
log('Usage: doukui loop <plan.md> [--executor=
|
|
654
|
+
log('Usage: doukui loop <plan.md> [--executor=sdk|default|local] [--settings=<path>] [--round-timeout-ms=N]');
|
|
635
655
|
ctx.exit(2);
|
|
636
656
|
return;
|
|
637
657
|
}
|
|
638
658
|
}
|
|
639
659
|
if (!fs.existsSync(settingsResolved)) {
|
|
640
660
|
log(ctx.colorize('Error: settings file not found: ' + settingsResolved, 'red'));
|
|
641
|
-
log('Usage: doukui loop <plan.md> [--executor=
|
|
661
|
+
log('Usage: doukui loop <plan.md> [--executor=sdk|default|local] [--settings=<path>] [--round-timeout-ms=N]');
|
|
642
662
|
ctx.exit(2);
|
|
643
663
|
return;
|
|
644
664
|
}
|
|
@@ -670,6 +690,9 @@ module.exports = {
|
|
|
670
690
|
log(ctx.colorize('=== Agentic Loop Node Driver ===', 'cyan'));
|
|
671
691
|
log('plan: ' + planPath);
|
|
672
692
|
log('executor: ' + args.executor);
|
|
693
|
+
if (args.roundTimeoutMs) {
|
|
694
|
+
log('round-timeout-ms: ' + args.roundTimeoutMs + '(executor 单轮超时,缺省 15min)');
|
|
695
|
+
}
|
|
673
696
|
if (settingsResolved) {
|
|
674
697
|
log('settings: ' + settingsResolved);
|
|
675
698
|
}
|
|
@@ -734,7 +757,7 @@ module.exports = {
|
|
|
734
757
|
// var 提升导致创建点读到 undefined 抛 TypeError)
|
|
735
758
|
var selfRescueCfg = {
|
|
736
759
|
enabled: true,
|
|
737
|
-
maxSwitches:
|
|
760
|
+
maxSwitches: 3, // v0.4.0 A1:三级梯子(provider → model → retry_resplit),每级一次
|
|
738
761
|
modelFallback: null,
|
|
739
762
|
extraIterations: 3,
|
|
740
763
|
extraWallMs: 30 * 60 * 1000,
|
|
@@ -761,11 +784,11 @@ module.exports = {
|
|
|
761
784
|
}
|
|
762
785
|
} catch (_cfgErr4) { /* 用默认 */ }
|
|
763
786
|
try {
|
|
764
|
-
// local executor 只需 projectRoot(mock);default 额外接收 resolver 产物
|
|
787
|
+
// local executor 只需 projectRoot(mock);default/sdk 额外接收 resolver 产物
|
|
765
788
|
if (args.executor === 'local') {
|
|
766
789
|
executor = loopExecutor.createExecutor('local', { projectRoot: projectRoot });
|
|
767
790
|
} else {
|
|
768
|
-
|
|
791
|
+
var executorOpts = {
|
|
769
792
|
projectRoot: projectRoot,
|
|
770
793
|
settingsPath: settingsResolved,
|
|
771
794
|
model: resolvedProvider ? resolvedProvider.model : null,
|
|
@@ -774,7 +797,22 @@ module.exports = {
|
|
|
774
797
|
contextWindow: resolvedProvider ? contextWindowResolved.tokens : null,
|
|
775
798
|
// v0.3.1 T2:系统提示模式(sdk executor 消费;default executor 忽略)
|
|
776
799
|
systemPromptMode: selfRescueCfg.systemPromptMode,
|
|
777
|
-
|
|
800
|
+
// executor-round-timeout:--round-timeout-ms 透传(null = 未传,
|
|
801
|
+
// executor 内 typeof 检查回退 DEFAULTS 15min,零回归)
|
|
802
|
+
timeoutMs: args.roundTimeoutMs,
|
|
803
|
+
};
|
|
804
|
+
try {
|
|
805
|
+
executor = loopExecutor.createExecutor(args.executor, executorOpts);
|
|
806
|
+
} catch (sdkErr) {
|
|
807
|
+
// v0.4.0 T1:SDK 未装(optionalDependency)→ 自动降级 default(spawn CLI)。
|
|
808
|
+
// 仅 SDK_UNAVAILABLE 降级;用户显式 --executor=sdk 装失败也降级并 warn
|
|
809
|
+
// (默认 executor=sdk 的主场景就是「没装 SDK 也照跑」)。其他错误照旧 exit 2。
|
|
810
|
+
if (sdkErr && sdkErr.code !== 'SDK_UNAVAILABLE') throw sdkErr;
|
|
811
|
+
log(ctx.colorize('⚠ executor "' + args.executor + '" 不可用(' +
|
|
812
|
+
(sdkErr && sdkErr.message ? sdkErr.message : String(sdkErr)) +
|
|
813
|
+
'),自动降级 default(spawn claude CLI;无 SessionStore 续轮)', 'yellow'));
|
|
814
|
+
executor = loopExecutor.createExecutor('default', executorOpts);
|
|
815
|
+
}
|
|
778
816
|
// WP-D3:fallback 配置预解析(profile.fallback_settings → 文件预检)
|
|
779
817
|
failoverCfg = providerFailover.resolveFallbackConfig({
|
|
780
818
|
profile: resolvedProvider ? resolvedProvider.profile : null,
|
|
@@ -811,7 +849,7 @@ module.exports = {
|
|
|
811
849
|
try {
|
|
812
850
|
await driverStore.set('harness.planRisk', planRiskLow ? 'low' : 'high');
|
|
813
851
|
if (planRiskLow) {
|
|
814
|
-
log(ctx.colorize('ℹ plan 声明风险分级 low(WP-S3
|
|
852
|
+
log(ctx.colorize('ℹ plan 声明风险分级 low(WP-S3);会话内 gated skill 自动豁免强制人审', 'gray'));
|
|
815
853
|
}
|
|
816
854
|
} catch (_prErr) { /* 风险标记失败不影响 loop */ }
|
|
817
855
|
if (typeof emitConcurrencyWarn === 'function') emitConcurrencyWarn(workspace, args.loopId);
|
|
@@ -1062,7 +1100,8 @@ module.exports = {
|
|
|
1062
1100
|
}
|
|
1063
1101
|
|
|
1064
1102
|
// 终态出口:engine verdict 非 continue 即停——WP-S1 自救链:diverged/timeout
|
|
1065
|
-
//
|
|
1103
|
+
// 先穷尽自救梯子(①换 provider → ②换模型 → ③retry_resplit 纯重置续跑),
|
|
1104
|
+
// 每级一次;穷尽后降级交付(A1)——已完成 WP 照常交付 + 未完成项交接,才升级人。
|
|
1066
1105
|
if (result.verdict !== 'continue') {
|
|
1067
1106
|
var _rescueAction = (result.verdict === 'diverged' || result.verdict === 'timeout')
|
|
1068
1107
|
? planSelfRescue(result.verdict) : null;
|
|
@@ -1075,6 +1114,11 @@ module.exports = {
|
|
|
1075
1114
|
fallbackSettings: failoverCfg.fallbackSettings,
|
|
1076
1115
|
});
|
|
1077
1116
|
_rescueOk = true;
|
|
1117
|
+
} else if (_rescueAction.type === 'retry_resplit') {
|
|
1118
|
+
// v0.4.0 A1 三级:纯重置续跑——不换 executor(零配置可用),
|
|
1119
|
+
// 重置发散计数 + 追加预算;下轮 engine Think 基于 lastChecklist
|
|
1120
|
+
// 自选 retry(带 failingDrivers)或 resplit 策略,决策权在 engine。
|
|
1121
|
+
_rescueOk = true;
|
|
1078
1122
|
} else if (_rescueAction.type === 'switch_model') {
|
|
1079
1123
|
executor = loopExecutor.createExecutor(args.executor, {
|
|
1080
1124
|
projectRoot: projectRoot,
|
|
@@ -1083,6 +1127,8 @@ module.exports = {
|
|
|
1083
1127
|
provider: (resolvedProvider ? resolvedProvider.provider : 'unknown') + '-rescued',
|
|
1084
1128
|
quotaConfig: null,
|
|
1085
1129
|
contextWindow: resolvedProvider ? contextWindowResolved.tokens : null,
|
|
1130
|
+
// 换模型自救不重置超时配置(--round-timeout-ms 继续生效)
|
|
1131
|
+
timeoutMs: args.roundTimeoutMs,
|
|
1086
1132
|
});
|
|
1087
1133
|
_rescueOk = true;
|
|
1088
1134
|
}
|
|
@@ -1092,9 +1138,12 @@ module.exports = {
|
|
|
1092
1138
|
}
|
|
1093
1139
|
if (_rescueOk) {
|
|
1094
1140
|
usedRescues.push(_rescueAction.type);
|
|
1095
|
-
// v0.3.1
|
|
1096
|
-
//
|
|
1097
|
-
|
|
1141
|
+
// v0.3.1 深审修复:换 provider/model 的自救重建 executor 后必须清空 session
|
|
1142
|
+
// 映射——旧 provider/model 的 sessionId 注入新 executor 的 resume 是未定义行为。
|
|
1143
|
+
// v0.4.0 A1:retry_resplit 不换 executor,session 保留(续轮上下文仍有效,省 token)。
|
|
1144
|
+
if (_rescueAction.type !== 'retry_resplit') {
|
|
1145
|
+
sdkSessionIds = {};
|
|
1146
|
+
}
|
|
1098
1147
|
try {
|
|
1099
1148
|
if (result.verdict === 'diverged') {
|
|
1100
1149
|
await api.prepareSelfRescue(loopId, {
|
|
@@ -1126,6 +1175,24 @@ module.exports = {
|
|
|
1126
1175
|
log(ctx.colorize('ℹ WP-S1 自救链已尝试 ' + usedRescues.length + ' 级 [' +
|
|
1127
1176
|
usedRescues.join(' → ') + '],穷尽后终止。未完成 WP 建议 resplit 或人审', 'yellow'));
|
|
1128
1177
|
}
|
|
1178
|
+
// v0.4.0 A1 降级交付:diverged/timeout 穷尽自救后,若已有部分成果,输出降级交付
|
|
1179
|
+
// 报告(已完成 WP 交付清单 + 未完成交接明细)替代纯失败退出——北极星 1「终态
|
|
1180
|
+
// 不是停下等人」。报告走 stdout,会话内监控协议(skill Step 2.5)读 driver
|
|
1181
|
+
// stdout 尾部即可呈现给人。goal 为空或零成果时不输出(保持原纯终态报告)。
|
|
1182
|
+
if ((result.verdict === 'diverged' || result.verdict === 'timeout') &&
|
|
1183
|
+
completedSet.length > 0 && loopGoal && Array.isArray(loopGoal.wpIds)) {
|
|
1184
|
+
try {
|
|
1185
|
+
var _ddState = await driverStore.get('loop.' + loopId);
|
|
1186
|
+
var _dd = loopReport.generateDegradedDeliveryReport(_ddState || {}, {
|
|
1187
|
+
loopId: loopId,
|
|
1188
|
+
verdict: result.verdict,
|
|
1189
|
+
completedWps: completedSet.slice(),
|
|
1190
|
+
goalWps: loopGoal.wpIds.slice(),
|
|
1191
|
+
});
|
|
1192
|
+
log(ctx.colorize('', 'cyan'));
|
|
1193
|
+
log(_dd.markdown);
|
|
1194
|
+
} catch (_ddErr) { /* 报告生成失败不阻断退出 */ }
|
|
1195
|
+
}
|
|
1129
1196
|
// v0.3.1 T5:token 汇总(命中率 = cacheRead / (cacheRead + input))
|
|
1130
1197
|
if (tokenTotals.rounds > 0) {
|
|
1131
1198
|
var _tot = tokenTotals.cacheRead + tokenTotals.input;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "doukui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.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"
|
|
@@ -336,23 +336,24 @@ class SkillGateHook extends HookPlugin {
|
|
|
336
336
|
return { allowed: true, handled: false };
|
|
337
337
|
}
|
|
338
338
|
|
|
339
|
-
// WP-S3
|
|
340
|
-
//
|
|
341
|
-
//
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
339
|
+
// WP-S3 风险分级人审豁免(v0.3.2 起默认自动):当前 plan 声明 风险分级 low
|
|
340
|
+
// (driver/skill 解析后写 harness.planRisk=low)→ 跳过 waiting 强制暂停。
|
|
341
|
+
// 北极星 1:人审按风险分级——代码改动必审,纯文档/测试补充类不强制。
|
|
342
|
+
// 旧版需 DOUKUI_LOW_RISK_GATE=1 显式授权(双条件),v0.3.2 起该 env 退役:
|
|
343
|
+
// plan 声明 low 即豁免;未声明风险的 plan 照常完整人审。
|
|
344
|
+
// 状态读取失败 → 不豁免,走正常门控(fail-closed)。
|
|
345
|
+
try {
|
|
346
|
+
var planRisk = this._store ? await this._store.get('harness.planRisk') : undefined;
|
|
347
|
+
if (planRisk === 'low') {
|
|
348
|
+
return {
|
|
349
|
+
allowed: true,
|
|
350
|
+
handled: true,
|
|
351
|
+
newState: (await this._getState()) || 'idle',
|
|
352
|
+
stateChanges: [],
|
|
353
|
+
skipReason: 'low_risk_plan',
|
|
354
|
+
};
|
|
355
|
+
}
|
|
356
|
+
} catch (_e) { /* 状态读取失败 → 不豁免,走正常门控 */ }
|
|
356
357
|
|
|
357
358
|
// Set state to "waiting" to pause for human confirmation
|
|
358
359
|
var waitingState = 'waiting';
|