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,448 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Executor (default) — Agentic Loop Act 层的单一真实 executor(WP-188 重构)
|
|
3
|
-
*
|
|
4
|
-
* @module executor-default
|
|
5
|
-
*
|
|
6
|
-
* 职责:spawn Claude Code CLI(`claude -p --output-format json --allowedTools ...`)逐轮写代码,
|
|
7
|
-
* 从 stdout JSON 提取 text,再从 text 里的 `json:machine-readable` fenced block 解析 CheckResult。
|
|
8
|
-
*
|
|
9
|
-
* 为什么取代 executor-claude / executor-glm(去 provider 死标签):
|
|
10
|
-
* 原 executor-claude(真实 Anthropic)与 executor-glm(智谱)是两个模块,差异仅在:
|
|
11
|
-
* - glm 追加 --model、注入智谱 env、内置 5h 额度感知。
|
|
12
|
-
* 新模型下端点+认证+model 全部由 --settings 文件(或环境变量)携带,executor 不再注入环境变量;
|
|
13
|
-
* 智谱额度感知改为**按探测到的模型自动启用**(provider-resolver 判定 features.quotaAware)。
|
|
14
|
-
* 故合并为单一 default executor,内部按 features 门控额度逻辑,零 provider 分支。
|
|
15
|
-
*
|
|
16
|
-
* 行为决策(由 loop.js 调 provider-resolver 后透传):
|
|
17
|
-
* - features.quotaAware=true(探测到 glm 模型且有 quotaConfig):
|
|
18
|
-
* 启用 5h 滚动窗口额度记账 + 高峰系数(3x/2x)+ 只读余额视图(observability)。
|
|
19
|
-
* WP-198① 后续(用户「去 glm 限速」):降速门控已移除——不再因接近软阈值返回 quota_exhausted,
|
|
20
|
-
* loop 永远 spawn;仅保留记账/视图供观测(无功能影响)。
|
|
21
|
-
* - 否则(mimo/deepseek/unknown):纯透传 spawn claude,无额度约束。
|
|
22
|
-
* - settingsPath 非空:追加 `--settings <path>`(透传 claude 原生 flag);此时 model 由 settings
|
|
23
|
-
* 文件决定,不追加 --model。settingsPath 为空但探测到 model:追加 `--model <model>`(环境变量场景)。
|
|
24
|
-
*
|
|
25
|
-
* SECURITY:
|
|
26
|
-
* - S1:prompt 走 stdin,不进 argv(对齐 executor-claude internals)。
|
|
27
|
-
* - 不再注入 ANTHROPIC_BASE_URL/AUTH_TOKEN 环境变量(端点+认证由 settings 文件携带,
|
|
28
|
-
* executor 注入会与 settings 冲突且有泄漏风险)。智谱旧路径 buildAnthropicEnv 已删除。
|
|
29
|
-
*
|
|
30
|
-
* CheckResult 契约(与 executor-claude / executor-local 一致,见 executor-claude.js 头注)。
|
|
31
|
-
*
|
|
32
|
-
* 可测性(遵循 codebase DI-over-mocking):
|
|
33
|
-
* - createExecutor({ spawnFn, nowFn, gitStatusFn }) 注入实现,测试传 fake spawn,不真调 claude。
|
|
34
|
-
* - 额度逻辑(isPeakHour/quotaCostFactor/createQuotaTracker)从 executor-glm 搬迁,零漂移。
|
|
35
|
-
*/
|
|
36
|
-
|
|
37
|
-
'use strict';
|
|
38
|
-
|
|
39
|
-
var { spawn } = require('child_process');
|
|
40
|
-
|
|
41
|
-
// 复用 executor-claude 的内部工具(prompt 模板 / checklist 解析 / 进展检测 / WP 文档读取 / buildClaudeArgs)
|
|
42
|
-
// —— provider 解耦验证锚点:default 与原 claude 共享同一套 prompt+解析,差异仅在调用目标与可选额度门控。
|
|
43
|
-
var claudeInternals = require('./executor-claude');
|
|
44
|
-
var buildPrompt = claudeInternals._buildPrompt;
|
|
45
|
-
var buildClaudeArgs = claudeInternals._buildClaudeArgs;
|
|
46
|
-
var extractTextFromClaudeStdout = claudeInternals._extractTextFromClaudeStdout;
|
|
47
|
-
var extractMetaFromClaudeStdout = claudeInternals._extractMetaFromClaudeStdout;
|
|
48
|
-
var parseCheckResult = claudeInternals._parseCheckResult;
|
|
49
|
-
var normalizeCheckResult = claudeInternals._normalizeCheckResult;
|
|
50
|
-
var buildFailedChecklist = claudeInternals._buildFailedChecklist;
|
|
51
|
-
// WP-191-2-impl:进展检测复用 claude 的工作树脏度判定 + applyProgressDetection(零漂移)
|
|
52
|
-
var readWorktreeDirty = claudeInternals._readWorktreeDirty;
|
|
53
|
-
var applyProgressDetection = claudeInternals._applyProgressDetection;
|
|
54
|
-
|
|
55
|
-
// ---------------------------------------------------------------------------
|
|
56
|
-
// 默认配置
|
|
57
|
-
// ---------------------------------------------------------------------------
|
|
58
|
-
|
|
59
|
-
var DEFAULTS = {
|
|
60
|
-
binary: 'claude', // Claude Code CLI 可执行名
|
|
61
|
-
timeoutMs: 15 * 60 * 1000, // 单次执行超时 15min(对齐 executor-claude/local)
|
|
62
|
-
rateLimitPerHour: 100, // 单实例每小时调用上限(对齐 executor-claude internals)
|
|
63
|
-
allowedTools: [
|
|
64
|
-
// 白名单:允许 Claude 读写代码与跑测试,禁止改动 .claude/ 内部状态(防自篡改)
|
|
65
|
-
'Read', 'Write', 'Edit', 'Glob', 'Grep', 'Bash',
|
|
66
|
-
],
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
// ---------------------------------------------------------------------------
|
|
70
|
-
// 额度感知(从 executor-glm 搬迁,零漂移;仅 features.quotaAware=true 时启用)
|
|
71
|
-
// docs/wp/WP-188-research.md §3.3:智谱 GLM Coding Plan 双重限额 + 高峰系数
|
|
72
|
-
// ---------------------------------------------------------------------------
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* 判断当前时刻是否落在智谱高峰时段(peakStartHour-peakEndHour,UTC+8 小时数)。
|
|
76
|
-
* 与宿主时区无关。
|
|
77
|
-
* @param {number} peakStartUtc8Hour
|
|
78
|
-
* @param {number} peakEndUtc8Hour
|
|
79
|
-
* @param {Function} [nowFn] 注入时间函数(测试用),返回 Date
|
|
80
|
-
* @returns {boolean}
|
|
81
|
-
*/
|
|
82
|
-
function isPeakHour(peakStartUtc8Hour, peakEndUtc8Hour, nowFn) {
|
|
83
|
-
var now = (nowFn || function () { return new Date(); })();
|
|
84
|
-
var beijingHour = (now.getUTCHours() + 8) % 24;
|
|
85
|
-
return beijingHour >= peakStartUtc8Hour && beijingHour < peakEndUtc8Hour;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* 计算一次调用消耗的额度系数。
|
|
90
|
-
* costModelRegex 命中(如 glm-5.x)→ 高峰 peakCostFactor / 非高峰 offpeakCostFactor;
|
|
91
|
-
* 不命中(如 glm-4.6)→ 1x(不受高峰系数影响)。
|
|
92
|
-
* @param {string} model 模型名
|
|
93
|
-
* @param {object} quotaConfig { peakStartHour, peakEndHour, peakCostFactor, offpeakCostFactor, costModelRegex }
|
|
94
|
-
* @param {Function} [nowFn]
|
|
95
|
-
* @returns {number}
|
|
96
|
-
*/
|
|
97
|
-
function quotaCostFactor(model, quotaConfig, nowFn) {
|
|
98
|
-
if (!quotaConfig) return 1;
|
|
99
|
-
var costRe = null;
|
|
100
|
-
// 'i' 标志:对齐原 executor-glm 的 /^glm[-_]?5(?!\d)/i,让 GLM-5.2 / GLM5Turbo 等大写变体
|
|
101
|
-
// 同样命中高峰系数(零漂移搬迁承诺)。
|
|
102
|
-
try { costRe = new RegExp(quotaConfig.costModelRegex, 'i'); } catch (_e) { return 1; }
|
|
103
|
-
if (!costRe.test(model || '')) return 1;
|
|
104
|
-
var peak = isPeakHour(quotaConfig.peakStartHour, quotaConfig.peakEndHour, nowFn);
|
|
105
|
-
return peak ? quotaConfig.peakCostFactor : quotaConfig.offpeakCostFactor;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* 创建滚动窗口额度计数器(从 executor-glm 搬迁,零漂移)。
|
|
110
|
-
* 记录每次调用的 { ts, cost },提供 usedInWindow / usedInWeek / windowRatio 查询。
|
|
111
|
-
* 进程内存状态(单 loop 一个 executor 实例),不持久化、不跨 loop 共享(跨 loop 归 coordinator)。
|
|
112
|
-
*
|
|
113
|
-
* @param {object} quotaConfig { windowPrompts, weeklyPrompts }
|
|
114
|
-
* @param {Function} [nowFn]
|
|
115
|
-
* @returns {{ record:Function, windowUsed:Function, weekUsed:Function, windowRatio:Function }}
|
|
116
|
-
*/
|
|
117
|
-
function createQuotaTracker(quotaConfig, nowFn) {
|
|
118
|
-
var WINDOW_MS = 5 * 60 * 60 * 1000; // 5h
|
|
119
|
-
var WEEK_MS = 7 * 24 * 60 * 60 * 1000; // 7d
|
|
120
|
-
var entries = []; // { ts:number, cost:number }
|
|
121
|
-
var windowPrompts = (quotaConfig && quotaConfig.windowPrompts) || 0;
|
|
122
|
-
var weeklyPrompts = (quotaConfig && quotaConfig.weeklyPrompts) || 0;
|
|
123
|
-
|
|
124
|
-
var getNow = function () { return (nowFn || function () { return new Date(); })().getTime(); };
|
|
125
|
-
|
|
126
|
-
function prune() {
|
|
127
|
-
var now = getNow();
|
|
128
|
-
entries = entries.filter(function (e) { return now - e.ts < WEEK_MS; });
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
return {
|
|
132
|
-
record: function (cost) {
|
|
133
|
-
prune();
|
|
134
|
-
entries.push({ ts: getNow(), cost: cost });
|
|
135
|
-
},
|
|
136
|
-
windowUsed: function () {
|
|
137
|
-
var now = getNow();
|
|
138
|
-
var sum = 0;
|
|
139
|
-
for (var i = 0; i < entries.length; i++) {
|
|
140
|
-
if (now - entries[i].ts < WINDOW_MS) sum += entries[i].cost;
|
|
141
|
-
}
|
|
142
|
-
return sum;
|
|
143
|
-
},
|
|
144
|
-
weekUsed: function () {
|
|
145
|
-
var now = getNow();
|
|
146
|
-
var sum = 0;
|
|
147
|
-
for (var i = 0; i < entries.length; i++) {
|
|
148
|
-
if (now - entries[i].ts < WEEK_MS) sum += entries[i].cost;
|
|
149
|
-
}
|
|
150
|
-
return sum;
|
|
151
|
-
},
|
|
152
|
-
windowRatio: function () {
|
|
153
|
-
var w = windowPrompts > 0 ? this.windowUsed() / windowPrompts : 0;
|
|
154
|
-
var k = weeklyPrompts > 0 ? this.weekUsed() / weeklyPrompts : 0;
|
|
155
|
-
return Math.max(w, k);
|
|
156
|
-
},
|
|
157
|
-
};
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
// ---------------------------------------------------------------------------
|
|
161
|
-
// args 构造
|
|
162
|
-
// ---------------------------------------------------------------------------
|
|
163
|
-
|
|
164
|
-
/**
|
|
165
|
-
* 构造 claude CLI 参数。
|
|
166
|
-
* - settingsPath 非空:追加 `--settings <path>`(透传 claude 原生 flag),model 由 settings 文件决定。
|
|
167
|
-
* - settingsPath 为空但 model 非空:追加 `--model <model>`(环境变量场景需要显式指定)。
|
|
168
|
-
* - 两者都无:仅 claude 骨架 flags(走 claude 账号默认模型)。
|
|
169
|
-
*
|
|
170
|
-
* SECURITY (S1):prompt 走 stdin,不进 args(见 executor-claude.buildClaudeArgs)。
|
|
171
|
-
*
|
|
172
|
-
* @param {string[]} allowedTools
|
|
173
|
-
* @param {string} [settingsPath]
|
|
174
|
-
* @param {string} [model] settingsPath 为空时生效
|
|
175
|
-
* @returns {string[]}
|
|
176
|
-
*/
|
|
177
|
-
function buildDefaultArgs(allowedTools, settingsPath, model) {
|
|
178
|
-
var args = buildClaudeArgs(allowedTools, settingsPath);
|
|
179
|
-
// settings 接管时 model 由文件决定;仅无 settings 才显式 --model(环境变量场景)
|
|
180
|
-
if (!settingsPath && model) {
|
|
181
|
-
args.push('--model', model);
|
|
182
|
-
}
|
|
183
|
-
return args;
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
/**
|
|
187
|
-
* 把 executor 打点 trace 附到 CheckResult 上(WP-196-1-impl,纯观测)。
|
|
188
|
-
* 下划线前缀字段 `_executorTrace` 表示内部观测,reflection-evaluator 不消费;
|
|
189
|
-
* driver 读取后聚合到 round record。全程 try/catch 降级——trace 缺失不影响 checkResult。
|
|
190
|
-
* @param {object} checkResult
|
|
191
|
-
* @param {object} trace { spawnMs, exitCode, timedOut, rateLimited, tokenUsage, endpointMs }
|
|
192
|
-
* @returns {object} 原 checkResult(附 _executorTrace)
|
|
193
|
-
*/
|
|
194
|
-
function _withTrace(checkResult, trace) {
|
|
195
|
-
try {
|
|
196
|
-
if (checkResult && typeof checkResult === 'object') {
|
|
197
|
-
checkResult._executorTrace = trace || null;
|
|
198
|
-
}
|
|
199
|
-
} catch (_e) { /* 降级:观测失败绝不阻断 */ }
|
|
200
|
-
return checkResult;
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
// ---------------------------------------------------------------------------
|
|
204
|
-
// 公开 API
|
|
205
|
-
// ---------------------------------------------------------------------------
|
|
206
|
-
|
|
207
|
-
/**
|
|
208
|
-
* 创建一个 default executor 实例。
|
|
209
|
-
*
|
|
210
|
-
* @param {object} [opts]
|
|
211
|
-
* @param {Function} [opts.spawnFn] 注入 spawn(测试用);默认 child_process.spawn
|
|
212
|
-
* @param {string} [opts.binary] claude 可执行名
|
|
213
|
-
* @param {number} [opts.timeoutMs] 单次超时(ms)
|
|
214
|
-
* @param {number} [opts.rateLimitPerHour] 调用上限/h
|
|
215
|
-
* @param {string[]} [opts.allowedTools] 工具白名单
|
|
216
|
-
* @param {string} [opts.projectRoot] 项目根覆盖(默认自动探测)
|
|
217
|
-
* @param {string} [opts.settingsPath] claude settings 文件路径(透传 --settings)
|
|
218
|
-
* @param {string} [opts.model] 生效模型名(settingsPath 为空时追加 --model;也供额度系数判定)
|
|
219
|
-
* @param {string} [opts.provider] 探测到的 provider key(诊断/日志用,'glm'/'mimo'/'unknown')
|
|
220
|
-
* @param {object} [opts.quotaConfig] 智谱额度配置(provider-resolver 产出;非空即启用额度感知)
|
|
221
|
-
* @param {Function} [opts.gitStatusFn] 进展检测 git status 注入(测试用)
|
|
222
|
-
* @param {Function} [opts.nowFn] 注入时间函数(测试用,额度窗口与高峰系数)
|
|
223
|
-
* @returns {{ name:string, run:Function, config:object }}
|
|
224
|
-
*/
|
|
225
|
-
function createExecutor(opts) {
|
|
226
|
-
opts = opts || {};
|
|
227
|
-
var config = {
|
|
228
|
-
binary: opts.binary || DEFAULTS.binary,
|
|
229
|
-
timeoutMs: typeof opts.timeoutMs === 'number' ? opts.timeoutMs : DEFAULTS.timeoutMs,
|
|
230
|
-
rateLimitPerHour: typeof opts.rateLimitPerHour === 'number'
|
|
231
|
-
? opts.rateLimitPerHour : DEFAULTS.rateLimitPerHour,
|
|
232
|
-
allowedTools: (opts.allowedTools && opts.allowedTools.length)
|
|
233
|
-
? opts.allowedTools.slice() : DEFAULTS.allowedTools.slice(),
|
|
234
|
-
projectRoot: opts.projectRoot || claudeInternals._resolveProjectRoot(),
|
|
235
|
-
settingsPath: opts.settingsPath || null,
|
|
236
|
-
model: opts.model || null,
|
|
237
|
-
provider: opts.provider || 'unknown',
|
|
238
|
-
quotaConfig: opts.quotaConfig || null,
|
|
239
|
-
// 上下文窗口预算 tokens(Phase B-2 分档;null=未知不注入 prompt)
|
|
240
|
-
contextWindow: typeof opts.contextWindow === 'number' && opts.contextWindow > 0
|
|
241
|
-
? opts.contextWindow : null,
|
|
242
|
-
};
|
|
243
|
-
var quotaAware = !!(config.quotaConfig && config.quotaConfig.windowPrompts > 0);
|
|
244
|
-
var spawnFn = opts.spawnFn || spawn;
|
|
245
|
-
var gitStatusFn = typeof opts.gitStatusFn === 'function' ? opts.gitStatusFn : null;
|
|
246
|
-
var nowFn = opts.nowFn;
|
|
247
|
-
|
|
248
|
-
// 额度计数器:仅 quotaAware 时实例化(mimo/deepseek/unknown 不创建,省内存)
|
|
249
|
-
var quota = quotaAware
|
|
250
|
-
? createQuotaTracker(config.quotaConfig, nowFn)
|
|
251
|
-
: null;
|
|
252
|
-
|
|
253
|
-
// 限流状态(对齐 executor-claude internals)
|
|
254
|
-
var callTimestamps = [];
|
|
255
|
-
var HOUR_MS = 60 * 60 * 1000;
|
|
256
|
-
|
|
257
|
-
/**
|
|
258
|
-
* 执行 pendingAction:spawn claude → 收集 stdout → 解析 checklist block。
|
|
259
|
-
*
|
|
260
|
-
* 额度感知流程(仅 quotaAware;对齐原 executor-glm 硬约束 #2"降速返回"):
|
|
261
|
-
* 1. 调用前查 quotaRatio,超过软阈值 → 返回 quota_exhausted(不 spawn),让 driver 发散检测兜底
|
|
262
|
-
* 2. 调用后按高峰系数计入额度窗口
|
|
263
|
-
*
|
|
264
|
-
* @param {object} pendingAction
|
|
265
|
-
* @returns {Promise<object>} CheckResult
|
|
266
|
-
*/
|
|
267
|
-
async function run(pendingAction) {
|
|
268
|
-
pendingAction = pendingAction || {};
|
|
269
|
-
var wpId = pendingAction.wpId || 'unknown';
|
|
270
|
-
|
|
271
|
-
// concurrent-dispatch Step 2(per-WP worktree 隔离):
|
|
272
|
-
// per-call projectRoot override(对齐 executor-claude internals)。批内 N 个并发 run 各走独立
|
|
273
|
-
// worktree,readWorktreeDirty per-WP 准确、互不串扰(修复 v0.4.0 noProgress 批级串扰)。
|
|
274
|
-
// 不传 → 走 config.projectRoot(零回归 = v0.4.0)。
|
|
275
|
-
var runCwd = (typeof pendingAction.projectRoot === 'string' && pendingAction.projectRoot)
|
|
276
|
-
? pendingAction.projectRoot : config.projectRoot;
|
|
277
|
-
// noProgressForceZero(--no-progress-detect escape hatch,文档 §5.5)。
|
|
278
|
-
var forceZeroProgress = pendingAction.noProgressForceZero === true;
|
|
279
|
-
|
|
280
|
-
// WP-196-1-impl / token-usage:executor.run 打点(仅观测,不引入 provider 分支)。
|
|
281
|
-
// 采集 {spawnMs, exitCode, timedOut, rateLimited, tokenUsage, endpointMs} 附在 checkResult._executorTrace;
|
|
282
|
-
// 全程容错,缺失字段降级为 null。tokenUsage/endpointMs 在 close 回调由 extractMetaFromClaudeStdout 填充。
|
|
283
|
-
var trace = { spawnMs: null, exitCode: null, timedOut: false, rateLimited: false, tokenUsage: null, endpointMs: null };
|
|
284
|
-
var spawnStartMs = Date.now();
|
|
285
|
-
|
|
286
|
-
// 限流(对齐 executor-claude internals,所有 provider 共用)
|
|
287
|
-
var now = Date.now();
|
|
288
|
-
callTimestamps = callTimestamps.filter(function (ts) { return now - ts < HOUR_MS; });
|
|
289
|
-
if (callTimestamps.length >= config.rateLimitPerHour) {
|
|
290
|
-
trace.rateLimited = true;
|
|
291
|
-
trace.spawnMs = Date.now() - spawnStartMs;
|
|
292
|
-
return _withTrace(buildFailedChecklist(wpId, 'rate_limited'), trace);
|
|
293
|
-
}
|
|
294
|
-
callTimestamps.push(now);
|
|
295
|
-
|
|
296
|
-
// WP-198① 后续(用户「去 glm 限速」第二层):额度降速门控已移除——不再因 5h 窗口接近
|
|
297
|
-
// 上限返回 quota_exhausted。quota 记账(spawn 后 quota.record)+ 只读视图(quota.windowRatio)
|
|
298
|
-
// 保留供 observability;softThreshold 字段保留但不再触发停止。loop 永远 spawn(仅受上方
|
|
299
|
-
// rateLimitPerHour 通用限流约束,对齐 executor-claude internals、所有 provider 共用)。
|
|
300
|
-
|
|
301
|
-
// 进展检测基线(WP-191-2-impl,复用 executor-claude 的工作树脏度判定)
|
|
302
|
-
// forceZeroProgress → 跳过采样(置 null),applyProgressDetection 走降级 noProgress=false
|
|
303
|
-
var dirtyBefore = forceZeroProgress ? null : readWorktreeDirty(runCwd, gitStatusFn);
|
|
304
|
-
|
|
305
|
-
// 构造 prompt(复用 executor-claude)+ args
|
|
306
|
-
// bug-003 fix:readWpDoc 读项目级 WP 文档(docs/wp/,主工作树),用 config.projectRoot
|
|
307
|
-
// 而非 runCwd。并发批 worktree 模式下 runCwd=worktree(git worktree add 建,不含
|
|
308
|
-
// gitignored 的 docs/wp/),用 runCwd 会读空 → executor 拿不到 WP 任务。spawn cwd
|
|
309
|
-
// 仍用 runCwd(worktree 隔离执行),文档读取用 config.projectRoot(主工作树)——两者正交。
|
|
310
|
-
// 无 override 时 runCwd===config.projectRoot,零回归。
|
|
311
|
-
var prompt = buildPrompt(pendingAction, config.projectRoot, config.contextWindow);
|
|
312
|
-
var args = buildDefaultArgs(config.allowedTools, config.settingsPath, config.model);
|
|
313
|
-
|
|
314
|
-
// spawn + 超时控制
|
|
315
|
-
var stdoutBuf = '';
|
|
316
|
-
var stderrBuf = '';
|
|
317
|
-
var timedOut = false;
|
|
318
|
-
// 额度计入闸门(仅 quotaAware;对齐原 executor-glm WP-191-4-impl 项 3):
|
|
319
|
-
// spawn 立即失败 / error / close 且 code==null(未真运行)不计额度;
|
|
320
|
-
// 仅 close 且 code!=null(真正启动并退出)或 timedOut 才计。
|
|
321
|
-
var quotaRecorded = false;
|
|
322
|
-
var child;
|
|
323
|
-
try {
|
|
324
|
-
child = spawnFn(config.binary, args, {
|
|
325
|
-
cwd: runCwd,
|
|
326
|
-
encoding: 'utf8',
|
|
327
|
-
stdio: ['pipe', 'pipe', 'pipe'],
|
|
328
|
-
// WP-D1 dogfood 发现(同 executor-claude):Windows claude.cmd 需 shell 解析
|
|
329
|
-
shell: process.platform === 'win32',
|
|
330
|
-
});
|
|
331
|
-
} catch (e) {
|
|
332
|
-
trace.spawnMs = Date.now() - spawnStartMs;
|
|
333
|
-
return _withTrace(buildFailedChecklist(wpId, 'spawn_failed: ' + ((e && e.code) || (e && e.message) || String(e))), trace);
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
// prompt 走 stdin(S1,对齐 executor-claude internals)
|
|
337
|
-
if (child.stdin) {
|
|
338
|
-
child.stdin.on('error', function (_e) {});
|
|
339
|
-
try {
|
|
340
|
-
child.stdin.write(prompt);
|
|
341
|
-
child.stdin.end();
|
|
342
|
-
} catch (_writeErr) {
|
|
343
|
-
// 同步写失败:忽略,由 close/error 裁决
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
return new Promise(function (resolve) {
|
|
348
|
-
var timer = setTimeout(function () {
|
|
349
|
-
timedOut = true;
|
|
350
|
-
try { child.kill('SIGTERM'); } catch (_e) {}
|
|
351
|
-
setTimeout(function () {
|
|
352
|
-
try { child.kill('SIGKILL'); } catch (_e2) {}
|
|
353
|
-
}, 2000);
|
|
354
|
-
}, config.timeoutMs);
|
|
355
|
-
|
|
356
|
-
if (child.stdout) {
|
|
357
|
-
child.stdout.on('data', function (chunk) {
|
|
358
|
-
if (chunk) stdoutBuf += chunk.toString();
|
|
359
|
-
});
|
|
360
|
-
}
|
|
361
|
-
if (child.stderr) {
|
|
362
|
-
child.stderr.on('data', function (chunk) {
|
|
363
|
-
if (chunk) stderrBuf += chunk.toString();
|
|
364
|
-
});
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
child.on('error', function (err) {
|
|
368
|
-
clearTimeout(timer);
|
|
369
|
-
// spawn_error 路径不计额度(本地未真打到端点)。标记 quotaRecorded 防重复计。
|
|
370
|
-
quotaRecorded = true;
|
|
371
|
-
trace.spawnMs = Date.now() - spawnStartMs;
|
|
372
|
-
trace.exitCode = null;
|
|
373
|
-
resolve(_withTrace(buildFailedChecklist(wpId, 'spawn_error: ' + (err && err.message ? err.message : String(err))), trace));
|
|
374
|
-
});
|
|
375
|
-
|
|
376
|
-
child.on('close', function (code) {
|
|
377
|
-
clearTimeout(timer);
|
|
378
|
-
|
|
379
|
-
// 额度计入(仅 quotaAware):仅当子进程真正运行过(code!=null 或 timedOut)才计。
|
|
380
|
-
if (quotaAware && !quotaRecorded && (code != null || timedOut)) {
|
|
381
|
-
var cost = quotaCostFactor(config.model, config.quotaConfig, nowFn);
|
|
382
|
-
quota.record(cost);
|
|
383
|
-
quotaRecorded = true;
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
trace.spawnMs = Date.now() - spawnStartMs;
|
|
387
|
-
trace.exitCode = (typeof code === 'number') ? code : null;
|
|
388
|
-
trace.timedOut = timedOut === true;
|
|
389
|
-
|
|
390
|
-
if (timedOut) {
|
|
391
|
-
resolve(_withTrace(buildFailedChecklist(wpId, 'timeout'), trace));
|
|
392
|
-
return;
|
|
393
|
-
}
|
|
394
|
-
// 提取 text → 解析 checklist block(复用 executor-claude 解析)
|
|
395
|
-
var text = extractTextFromClaudeStdout(stdoutBuf);
|
|
396
|
-
// token-usage:提取端点元数据(复用 executor-claude 的 extractMeta),失败降级 null
|
|
397
|
-
try {
|
|
398
|
-
var meta = extractMetaFromClaudeStdout(stdoutBuf);
|
|
399
|
-
trace.tokenUsage = meta.usage;
|
|
400
|
-
// 仅当提取到至少一个端点时序时才设 endpointMs,否则保持 null(语义:无端点数据)
|
|
401
|
-
if (meta.ttftMs !== null || meta.durationMs !== null) {
|
|
402
|
-
trace.endpointMs = { ttft: meta.ttftMs, duration: meta.durationMs };
|
|
403
|
-
}
|
|
404
|
-
} catch (_me) { /* 元数据提取降级:保持 null */ }
|
|
405
|
-
// Phase D 收尾链(executor-claude 共享):schema 校验 → normalize → 客观交叉验证
|
|
406
|
-
var raw = parseCheckResult(text);
|
|
407
|
-
var chk = claudeInternals._finalizeCheckResult(raw, wpId, { cwd: runCwd });
|
|
408
|
-
|
|
409
|
-
// 进展检测(WP-191-2-impl,复用 executor-claude.applyProgressDetection)
|
|
410
|
-
// forceZeroProgress → 置 null 走降级(与 dirtyBefore 对称)
|
|
411
|
-
var dirtyAfter = forceZeroProgress ? null : readWorktreeDirty(runCwd, gitStatusFn);
|
|
412
|
-
applyProgressDetection(chk, dirtyBefore, dirtyAfter);
|
|
413
|
-
// 非 0 退出码且无解析结果 → 失败
|
|
414
|
-
if (code !== 0 && !raw) {
|
|
415
|
-
resolve(_withTrace(buildFailedChecklist(wpId, 'claude_exit_' + code + ': ' + stderrBuf.slice(0, 200)), trace));
|
|
416
|
-
return;
|
|
417
|
-
}
|
|
418
|
-
resolve(_withTrace(chk, trace));
|
|
419
|
-
});
|
|
420
|
-
});
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
return {
|
|
424
|
-
name: 'default',
|
|
425
|
-
run: run,
|
|
426
|
-
config: config,
|
|
427
|
-
// quota 只读视图(供 coordinator 查询;quotaAware=false 时各方法返回 0)
|
|
428
|
-
quota: quotaAware ? {
|
|
429
|
-
windowUsed: quota.windowUsed,
|
|
430
|
-
weekUsed: quota.weekUsed,
|
|
431
|
-
windowRatio: quota.windowRatio,
|
|
432
|
-
} : {
|
|
433
|
-
windowUsed: function () { return 0; },
|
|
434
|
-
weekUsed: function () { return 0; },
|
|
435
|
-
windowRatio: function () { return 0; },
|
|
436
|
-
},
|
|
437
|
-
};
|
|
438
|
-
}
|
|
439
|
-
|
|
440
|
-
module.exports = {
|
|
441
|
-
createExecutor: createExecutor,
|
|
442
|
-
// 暴露内部工具便于单元测试(额度逻辑从 executor-glm 搬迁,签名对齐)
|
|
443
|
-
_buildDefaultArgs: buildDefaultArgs,
|
|
444
|
-
_isPeakHour: isPeakHour,
|
|
445
|
-
_quotaCostFactor: quotaCostFactor,
|
|
446
|
-
_createQuotaTracker: createQuotaTracker,
|
|
447
|
-
_DEFAULTS: DEFAULTS,
|
|
448
|
-
};
|
|
@@ -1,178 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Executor (local) — Agentic Loop Act 层 provider 执行单元的本地 mock 实现(WP-185-impl)
|
|
3
|
-
*
|
|
4
|
-
* @module executor-local
|
|
5
|
-
*
|
|
6
|
-
* 职责:实现 driver 期望的 `run(pendingAction) -> CheckResult` 契约的「固定通过」mock,
|
|
7
|
-
* 供 driver 单测与 `--executor=local` 冒烟使用。不调任何真实模型/子进程,零副作用
|
|
8
|
-
* (除了可选地触摸 PROGRESS.md 由 driver 负责,本模块不写文件)。
|
|
9
|
-
*
|
|
10
|
-
* 设计约束(docs/plan/agentic-loop-node-driver.md 硬约束 #3):
|
|
11
|
-
* - provider 解耦点是 `executor.run()`:driver 不直接 spawn claude,
|
|
12
|
-
* Claude/GLM/local 都是 run() 的不同实现。
|
|
13
|
-
* - 本模块与 executor-claude.js(WP-185)实现同一份接口契约,可互换。
|
|
14
|
-
*
|
|
15
|
-
* CheckResult 契约(与 reflection-evaluator / loop-snapshot 消费口径一致,
|
|
16
|
-
* 见 reflection-evaluator.js proximityFromChecklist / failingDriversFromChecklist):
|
|
17
|
-
* {
|
|
18
|
-
* wpId: string,
|
|
19
|
-
* passed: boolean,
|
|
20
|
-
* summary: { total:number, passed:number, failed:number },
|
|
21
|
-
* categories: [], // 本 mock 不细分类别
|
|
22
|
-
* failedItems: [], // 空数组表示无失败项
|
|
23
|
-
* }
|
|
24
|
-
*
|
|
25
|
-
* 限流与超时(WP-185-impl,对齐 Ralph 模式):
|
|
26
|
-
* - 单实例默认 100/h 调用上限,超限返回 passed:false + failedItems:[{reason:'rate_limited'}]
|
|
27
|
-
* - run() 默认无超时(mock 即时返回),opts.timeoutMs 仅作记录
|
|
28
|
-
* 这两项语义与 executor-claude 一致,便于 driver 不感知 provider 差异。
|
|
29
|
-
*/
|
|
30
|
-
|
|
31
|
-
'use strict';
|
|
32
|
-
|
|
33
|
-
// ---------------------------------------------------------------------------
|
|
34
|
-
// 默认配置
|
|
35
|
-
// ---------------------------------------------------------------------------
|
|
36
|
-
|
|
37
|
-
var DEFAULTS = {
|
|
38
|
-
rateLimitPerHour: 100, // 单实例每小时调用上限
|
|
39
|
-
timeoutMs: 15 * 60 * 1000, // 15min(mock 不真等,仅记录)
|
|
40
|
-
// model 占位(WP-191-1-impl-d,provider 零分支统一通道):
|
|
41
|
-
// mock 不调真实模型,config.model 仅供 driver 写 sidecar 时统一取值
|
|
42
|
-
// (executor.config.model),与 claude/glm 共用同一通道,无 provider 分支。
|
|
43
|
-
// coordinator 额度池对 local 无限额(Infinity),此 model 值不参与计量。
|
|
44
|
-
model: 'local-mock',
|
|
45
|
-
// mock 是否模拟失败(测试用):true 时按 failRate 随机返回 passed:false
|
|
46
|
-
simulateFailure: false,
|
|
47
|
-
failRate: 0.0,
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
// ---------------------------------------------------------------------------
|
|
51
|
-
// 工具函数
|
|
52
|
-
// ---------------------------------------------------------------------------
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* ISO 时间戳。
|
|
56
|
-
* @returns {string}
|
|
57
|
-
*/
|
|
58
|
-
function nowIso() {
|
|
59
|
-
return new Date().toISOString();
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* 生成「固定通过」的 CheckResult(mock 默认行为)。
|
|
64
|
-
* summary 固定 3/3 全过(与 WP-184 验证脚本口径一致,便于 proximity 单调递增回归)。
|
|
65
|
-
* @param {string} wpId
|
|
66
|
-
* @returns {object} CheckResult
|
|
67
|
-
*/
|
|
68
|
-
function buildPassedChecklist(wpId) {
|
|
69
|
-
return {
|
|
70
|
-
wpId: wpId,
|
|
71
|
-
passed: true,
|
|
72
|
-
summary: { total: 3, passed: 3, failed: 0 },
|
|
73
|
-
categories: [],
|
|
74
|
-
failedItems: [],
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* 生成「失败」CheckResult(mock simulateFailure 或 限流场景)。
|
|
80
|
-
* @param {string} wpId
|
|
81
|
-
* @param {string} reason 失败原因
|
|
82
|
-
* @returns {object} CheckResult
|
|
83
|
-
*/
|
|
84
|
-
function buildFailedChecklist(wpId, reason) {
|
|
85
|
-
return {
|
|
86
|
-
wpId: wpId,
|
|
87
|
-
passed: false,
|
|
88
|
-
summary: { total: 3, passed: 0, failed: 3 },
|
|
89
|
-
categories: [],
|
|
90
|
-
failedItems: [
|
|
91
|
-
{ id: 'mock-1', category: 'check', text: 'mock check', reason: reason },
|
|
92
|
-
],
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
// ---------------------------------------------------------------------------
|
|
97
|
-
// 公开 API
|
|
98
|
-
// ---------------------------------------------------------------------------
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* 创建一个 local executor 实例。
|
|
102
|
-
*
|
|
103
|
-
* @param {object} [opts]
|
|
104
|
-
* @param {number} [opts.rateLimitPerHour] 调用上限/h
|
|
105
|
-
* @param {number} [opts.timeoutMs] 单次超时(ms)
|
|
106
|
-
* @param {boolean} [opts.simulateFailure] 是否模拟随机失败
|
|
107
|
-
* @param {number} [opts.failRate] 失败概率 [0,1]
|
|
108
|
-
* @returns {{ run: Function, name: string }}
|
|
109
|
-
*/
|
|
110
|
-
function createExecutor(opts) {
|
|
111
|
-
opts = opts || {};
|
|
112
|
-
var config = {
|
|
113
|
-
rateLimitPerHour: typeof opts.rateLimitPerHour === 'number'
|
|
114
|
-
? opts.rateLimitPerHour : DEFAULTS.rateLimitPerHour,
|
|
115
|
-
timeoutMs: typeof opts.timeoutMs === 'number' ? opts.timeoutMs : DEFAULTS.timeoutMs,
|
|
116
|
-
model: opts.model || DEFAULTS.model,
|
|
117
|
-
simulateFailure: opts.simulateFailure === true,
|
|
118
|
-
failRate: typeof opts.failRate === 'number' ? opts.failRate : DEFAULTS.failRate,
|
|
119
|
-
};
|
|
120
|
-
|
|
121
|
-
// 限流状态:滑动窗口记录调用时间戳
|
|
122
|
-
var callTimestamps = [];
|
|
123
|
-
var HOUR_MS = 60 * 60 * 1000;
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* 执行 pendingAction,返回固定通过的 CheckResult(mock)。
|
|
127
|
-
*
|
|
128
|
-
* 签名契约(driver 与 executor-claude 共享):
|
|
129
|
-
* run(pendingAction: {wpId, mode, strategy, failingDrivers?, ...}) -> Promise<CheckResult>
|
|
130
|
-
*
|
|
131
|
-
* @param {object} pendingAction loop-actuator 产出的 dispatcher 待执行指令
|
|
132
|
-
* @returns {Promise<object>} CheckResult
|
|
133
|
-
*/
|
|
134
|
-
async function run(pendingAction) {
|
|
135
|
-
pendingAction = pendingAction || {};
|
|
136
|
-
var wpId = pendingAction.wpId || 'unknown';
|
|
137
|
-
|
|
138
|
-
// 限流:清理 1h 外的旧记录,检查窗口内调用数
|
|
139
|
-
var now = Date.now();
|
|
140
|
-
callTimestamps = callTimestamps.filter(function (ts) {
|
|
141
|
-
return now - ts < HOUR_MS;
|
|
142
|
-
});
|
|
143
|
-
if (callTimestamps.length >= config.rateLimitPerHour) {
|
|
144
|
-
return buildFailedChecklist(wpId, 'rate_limited');
|
|
145
|
-
}
|
|
146
|
-
callTimestamps.push(now);
|
|
147
|
-
|
|
148
|
-
// 模拟失败(测试路径)
|
|
149
|
-
if (config.simulateFailure && Math.random() < config.failRate) {
|
|
150
|
-
return buildFailedChecklist(wpId, 'mock_simulated_failure');
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
// mock 主路径:固定返回 passed。真实 executor(claude)会在此 spawn 子进程写代码。
|
|
154
|
-
return buildPassedChecklist(wpId);
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
return {
|
|
158
|
-
name: 'local',
|
|
159
|
-
run: run,
|
|
160
|
-
config: config,
|
|
161
|
-
// quota 视图(mock 不计量):与 executor-default 的 quotaAware=false 视图同构,
|
|
162
|
-
// 统一 { name, run, config, quota } 契约——让消费者无分支读 executor.quota.*,
|
|
163
|
-
// 各方法恒返回 0(local 是 mock,无真实额度概念)。
|
|
164
|
-
quota: {
|
|
165
|
-
windowUsed: function () { return 0; },
|
|
166
|
-
weekUsed: function () { return 0; },
|
|
167
|
-
windowRatio: function () { return 0; },
|
|
168
|
-
},
|
|
169
|
-
};
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
module.exports = {
|
|
173
|
-
createExecutor: createExecutor,
|
|
174
|
-
// 暴露内部工具便于单元测试
|
|
175
|
-
_buildPassedChecklist: buildPassedChecklist,
|
|
176
|
-
_buildFailedChecklist: buildFailedChecklist,
|
|
177
|
-
_DEFAULTS: DEFAULTS,
|
|
178
|
-
};
|