doukui 0.8.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 +8 -8
- package/bin/commands/help.js +2 -0
- package/bin/commands/plan-lint.js +105 -0
- package/bin/commands/verify.js +263 -0
- package/bin/doukui.js +2 -0
- package/package.json +1 -1
- 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 +5 -177
- package/plugins/core/skill-agent-dispatcher/plugin.json +1 -1
- package/plugins/core/skill-agent-dispatcher/recovery-reference.md +99 -58
- package/plugins/core/skill-agent-dispatcher/roles-reference.md +9 -22
- package/plugins/core/skill-agent-dispatcher/skill.md +112 -524
- package/plugins/core/skill-agentic-loop/mirror-rules.md +15 -3
- package/plugins/core/skill-agentic-loop/plugin.json +1 -1
- package/plugins/core/skill-agentic-loop/skill.md +123 -324
- 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-doukui-plan/plugin.json +1 -1
- package/plugins/core/skill-doukui-plan/skill.md +22 -22
- 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 -36
- package/plugins/runtime/harness-build.js +5 -5
- package/plugins/runtime/plan-reader.js +21 -3
- package/plugins/runtime/resolve-plugin-path.js +2 -2
- package/plugins/contracts/capabilities.js +0 -268
- 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/event-bus.js +0 -207
- package/plugins/runtime/hook-dispatcher.js +0 -315
- package/plugins/runtime/plugin-loader.js +0 -798
- package/plugins/runtime/plugin-trust.js +0 -182
- 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/text-tokenize.js +0 -24
- package/plugins/runtime/validator-pipeline.js +0 -475
|
@@ -176,7 +176,6 @@ class SkillGateHook extends HookPlugin {
|
|
|
176
176
|
this.name = 'hook-skill-gate';
|
|
177
177
|
this.version = '1.0.0';
|
|
178
178
|
this.description = '统一技能门控 Hook';
|
|
179
|
-
this.dependencies = { providers: ['provider:state-store'] };
|
|
180
179
|
this.trigger = {
|
|
181
180
|
event: 'PreToolUse',
|
|
182
181
|
tools: ['Edit', 'Write'],
|
|
@@ -466,21 +465,23 @@ class SkillGateHook extends HookPlugin {
|
|
|
466
465
|
*
|
|
467
466
|
* @returns {boolean} true if this execution should be skipped
|
|
468
467
|
*/
|
|
469
|
-
_shouldSkipForDoubleTrigger() {
|
|
468
|
+
_shouldSkipForDoubleTrigger(context) {
|
|
469
|
+
// 防抖目标:global + project 双重注册对**同一事件**的毫秒级重复执行。
|
|
470
|
+
// 只按「同 event + 同 tool」且 1 秒内判重——旧版「任意 hook 5 秒」会吞掉
|
|
471
|
+
// 合法的相邻调用(如 PreToolUse(Edit) 后紧随的 PostToolUse(Skill))。
|
|
472
|
+
var key = ((context && context.event) || '') + ':' + ((context && context.tool) || '');
|
|
470
473
|
var markerPath = path.join(this._projectRoot, '.claude', '.hook-execution-marker');
|
|
471
474
|
|
|
472
|
-
// If another hook process is marked as active, skip
|
|
475
|
+
// If another hook process is marked as active for the same key, skip
|
|
473
476
|
if (fs.existsSync(markerPath)) {
|
|
474
477
|
try {
|
|
475
478
|
var marker = fs.readFileSync(markerPath, 'utf-8');
|
|
476
479
|
var markerData = JSON.parse(marker);
|
|
477
480
|
|
|
478
|
-
|
|
479
|
-
var now = Date.now();
|
|
480
|
-
if (markerData.timestamp && (now - markerData.timestamp) < 5000) {
|
|
481
|
+
if (markerData.key === key && markerData.timestamp && (Date.now() - markerData.timestamp) < 1000) {
|
|
481
482
|
return true;
|
|
482
483
|
}
|
|
483
|
-
// Stale marker — clean it up
|
|
484
|
+
// Stale / different-key marker — clean it up
|
|
484
485
|
try { fs.unlinkSync(markerPath); } catch (e) { /* ignore */ }
|
|
485
486
|
} catch (e) {
|
|
486
487
|
// Invalid marker, clean up
|
|
@@ -490,9 +491,10 @@ class SkillGateHook extends HookPlugin {
|
|
|
490
491
|
|
|
491
492
|
// Mark this hook as active
|
|
492
493
|
try {
|
|
494
|
+
fs.mkdirSync(path.dirname(markerPath), { recursive: true });
|
|
493
495
|
fs.writeFileSync(
|
|
494
496
|
markerPath,
|
|
495
|
-
JSON.stringify({ timestamp: Date.now(), pid: process.pid }),
|
|
497
|
+
JSON.stringify({ timestamp: Date.now(), pid: process.pid, key: key }),
|
|
496
498
|
'utf-8'
|
|
497
499
|
);
|
|
498
500
|
} catch (e) {
|
|
@@ -583,6 +585,28 @@ function sanitizeObject(obj) {
|
|
|
583
585
|
return result;
|
|
584
586
|
}
|
|
585
587
|
|
|
588
|
+
/**
|
|
589
|
+
* Normalize a hook stdin payload across harness schemas.
|
|
590
|
+
*
|
|
591
|
+
* Claude Code passes `{ hook_event_name, tool_name, tool_input: {...} }` on
|
|
592
|
+
* stdin; the legacy/programmatic shape is `{ event, tool, skill }`. The gate
|
|
593
|
+
* previously read only the legacy keys, so in real sessions it never saw the
|
|
594
|
+
* tool/skill and the whole gate was inert. Unknown shapes fail open (empty
|
|
595
|
+
* strings) rather than crash.
|
|
596
|
+
* @param {object} raw - sanitized stdin payload
|
|
597
|
+
* @returns {{event: string, tool: string, skill: string, toolInput: object}}
|
|
598
|
+
*/
|
|
599
|
+
function normalizeHookContext(raw) {
|
|
600
|
+
raw = raw || {};
|
|
601
|
+
var toolInput = raw.tool_input || {};
|
|
602
|
+
return {
|
|
603
|
+
event: raw.hook_event_name || raw.event || '',
|
|
604
|
+
tool: raw.tool_name || raw.tool || '',
|
|
605
|
+
skill: toolInput.skill || toolInput.skillName || raw.skill || raw.skillName || '',
|
|
606
|
+
toolInput: toolInput,
|
|
607
|
+
};
|
|
608
|
+
}
|
|
609
|
+
|
|
586
610
|
/**
|
|
587
611
|
* Main CLI function.
|
|
588
612
|
*/
|
|
@@ -591,21 +615,40 @@ function main() {
|
|
|
591
615
|
|
|
592
616
|
if (args.length === 0) {
|
|
593
617
|
console.error(
|
|
594
|
-
'Usage: node index.js --pre-tool | --post-skill\n' +
|
|
618
|
+
'Usage: node index.js --pre-tool | --post-skill | --reset\n' +
|
|
595
619
|
' --pre-tool Run PreToolUse check (reads context from stdin)\n' +
|
|
596
|
-
' --post-skill Run PostToolUse handler (reads context from stdin)'
|
|
620
|
+
' --post-skill Run PostToolUse handler (reads context from stdin)\n' +
|
|
621
|
+
' --reset Reset harness.state to idle (run after human-checkpoint approval)'
|
|
597
622
|
);
|
|
598
623
|
process.exit(1);
|
|
599
624
|
}
|
|
600
625
|
|
|
601
626
|
var mode = args[0];
|
|
602
|
-
if (mode !== '--pre-tool' && mode !== '--post-skill') {
|
|
627
|
+
if (mode !== '--pre-tool' && mode !== '--post-skill' && mode !== '--reset') {
|
|
603
628
|
console.error('Unknown mode: ' + mode);
|
|
604
|
-
console.error('Valid modes: --pre-tool, --post-skill');
|
|
629
|
+
console.error('Valid modes: --pre-tool, --post-skill, --reset');
|
|
605
630
|
process.exit(1);
|
|
606
631
|
}
|
|
607
632
|
|
|
608
|
-
|
|
633
|
+
if (mode === '--reset') {
|
|
634
|
+
var resetHook = new SkillGateHook();
|
|
635
|
+
resetHook
|
|
636
|
+
.onActivate(null)
|
|
637
|
+
.then(function () {
|
|
638
|
+
return resetHook._setState('idle');
|
|
639
|
+
})
|
|
640
|
+
.then(function () {
|
|
641
|
+
process.stdout.write(JSON.stringify({ ok: true, state: 'idle' }) + '\n');
|
|
642
|
+
process.exit(0);
|
|
643
|
+
})
|
|
644
|
+
.catch(function (error) {
|
|
645
|
+
console.error('Hook execution failed: ' + error.message);
|
|
646
|
+
process.exit(1);
|
|
647
|
+
});
|
|
648
|
+
return;
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
readStdin(function (err, payload) {
|
|
609
652
|
if (err) {
|
|
610
653
|
console.error('Failed to read stdin: ' + err.message);
|
|
611
654
|
process.exit(1);
|
|
@@ -617,8 +660,13 @@ function main() {
|
|
|
617
660
|
hook
|
|
618
661
|
.onActivate(null)
|
|
619
662
|
.then(function () {
|
|
620
|
-
|
|
621
|
-
|
|
663
|
+
var context = normalizeHookContext(payload);
|
|
664
|
+
|
|
665
|
+
// Check for double-triggering prevention (same event + tool, 1s window).
|
|
666
|
+
// Only for state-changing --post-skill: --pre-tool is a pure read-only
|
|
667
|
+
// check and must NEVER be deduped (parallel Edit calls fire within 1s;
|
|
668
|
+
// skipping them would fail the waiting-block open).
|
|
669
|
+
if (mode === '--post-skill' && hook._shouldSkipForDoubleTrigger(context)) {
|
|
622
670
|
// Skip execution to prevent double-triggering
|
|
623
671
|
process.stdout.write(JSON.stringify({ allowed: true, skipped: true, reason: 'Double-trigger prevention' }) + '\n');
|
|
624
672
|
process.exit(0);
|
|
@@ -660,3 +708,4 @@ if (require.main === module) {
|
|
|
660
708
|
}
|
|
661
709
|
|
|
662
710
|
module.exports = SkillGateHook;
|
|
711
|
+
module.exports.normalizeHookContext = normalizeHookContext;
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"version": "1.0.0",
|
|
4
4
|
"type": "hook",
|
|
5
5
|
"description": "统一技能门控 Hook - 合并 check-state + post-skill + skill-gate 三合一,动态查询 gated skills",
|
|
6
|
-
"dependencies": [
|
|
6
|
+
"dependencies": [],
|
|
7
7
|
"provides": ["hook:skill-gate"],
|
|
8
8
|
"config": {
|
|
9
9
|
"gatedSkills": [],
|
|
@@ -6,11 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
## ⚠️ 权限要求
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
- 验证目录是否存在 (`test -d`)
|
|
11
|
-
- 调用 `team-cleanup` CLI 执行文件系统级删除(**CLI 直接走 fs.rmSync,不调用 TeamDelete**——该工具已从 harness 移除)
|
|
12
|
-
|
|
13
|
-
> **Step 7f 的文件系统删除由 `node bin/doukui.js team-cleanup <team> --force` 执行**——该 CLI 是 Node 进程,**绕过 harness Bash 权限系统**,无需在 settings.json 添加 `Bash(rm -rf ...)` 权限条目。只需 `Bash(node bin/doukui.js team-cleanup ...)` 一条。
|
|
9
|
+
Step 7 清理需要 Bash 权限执行 `test -d` 验证与 `node bin/doukui.js team-cleanup <team> --force`(该 CLI 是 Node 进程,内部走 fs.rmSync 文件系统级删除,不调用 TeamDelete——工具已移除;**无需**在 settings.json 添加 `Bash(rm -rf ...)` 条目,只需 `Bash(node bin/doukui.js team-cleanup ...)` 一条)。
|
|
14
10
|
|
|
15
11
|
> ⚠️ **implicit session team 模式下的清理范围**: 当前 session 的 implicit team 随 session 自动清理,**本流程主要针对历史残留的显式/UUID 团队目录**(如旧的 `cybershop-wp101`、UUID 命名团队)。若 `team_name` 是当前 session 的批次标签(非真实 harness 团队目录),目录可能不存在,Step 7a 条件 2 会返回 `NOT_FOUND` 并正常跳过。
|
|
16
12
|
|
|
@@ -69,17 +65,10 @@ Teamee 逻辑销毁必须完成 + 残留目录清理必须验证结果!
|
|
|
69
65
|
```
|
|
70
66
|
# 无协议帧;in-process Teamee 随 session 自然终止
|
|
71
67
|
teamee_map.clear()
|
|
72
|
-
#
|
|
73
|
-
# 输出: "映射表已清空(残留 Teamee 随 session 终止)"
|
|
68
|
+
# 输出: "映射表已清空(残留 Teamee 随 session 终止)" ← 直接文本输出,禁止用 SendMessage
|
|
74
69
|
```
|
|
75
70
|
|
|
76
|
-
>
|
|
77
|
-
|
|
78
|
-
---
|
|
79
|
-
|
|
80
|
-
### Step 7c: (已删除) 无需等待 shutdown 响应
|
|
81
|
-
|
|
82
|
-
逻辑销毁(Step 7b `teamee_map.clear()`)无协议帧,无需等待响应,直接进入残留目录清理(Step 7d)。
|
|
71
|
+
> 映射表不一致的孤儿成员会在后续 team-cleanup CLI 的目录级清理中被一并删除。
|
|
83
72
|
|
|
84
73
|
---
|
|
85
74
|
|
|
@@ -198,17 +187,7 @@ Owner: godot-script-expert-t2
|
|
|
198
187
|
|
|
199
188
|
## Cleanup Guarantee (清理保障)
|
|
200
189
|
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
│ ✅ 正常完成 → Step 6.5 即时逻辑销毁 → Step 7 历史残留 CLI │
|
|
206
|
-
│ ✅ 部分失败 → Step 6.5 即时逻辑销毁 → Step 7 历史残留 CLI │
|
|
207
|
-
│ ✅ 超时 → Step 6.5 超时逻辑销毁 → Step 7 强制 CLI │
|
|
208
|
-
│ ✅ 异常中断 → 捕获中断 → Step 7 强制逻辑销毁残留 + CLI │
|
|
209
|
-
│ │
|
|
210
|
-
│ ❌ 无任何情况可以跳过 Teamee 逻辑销毁! │
|
|
211
|
-
│ (当前 session implicit team 随 session 自动清理; │
|
|
212
|
-
│ team-cleanup CLI 仅清理历史残留显式/UUID 团队目录) │
|
|
213
|
-
└─────────────────────────────────────────────────────────────┘
|
|
214
|
-
```
|
|
190
|
+
- ✅ 正常完成 / 部分失败 → Step 6.5 即时逻辑销毁 → Step 7 历史残留 CLI
|
|
191
|
+
- ✅ 超时 → Step 6.5 超时逻辑销毁 → Step 7 强制 CLI
|
|
192
|
+
- ✅ 异常中断 → 捕获中断 → Step 7 强制逻辑销毁残留 + CLI
|
|
193
|
+
- ❌ **无任何情况可以跳过 Teamee 逻辑销毁**(当前 session implicit team 随 session 自动清理;team-cleanup CLI 仅清理历史残留显式/UUID 团队目录)
|
|
@@ -1,179 +1,6 @@
|
|
|
1
1
|
# Dispatcher Monitoring Reference(监控循环运行时细则)
|
|
2
2
|
|
|
3
|
-
> 本文件是 skill-agent-dispatcher
|
|
4
|
-
> 规则本体与触发条件仍在 SKILL.md 主干;以下章节仅在遇到对应运行时场景时按 📖指针 Read,无需预载。
|
|
5
|
-
> 来源章节:SKILL.md Step 6.5 监控循环(Phase 0.1 / Phase D.1 / Phase D.3)与后置辅助函数、拆分工作包执行支持、共享上下文机制。
|
|
6
|
-
|
|
7
|
-
## Phase 0.1 多窗口阶段信号检查
|
|
8
|
-
|
|
9
|
-
位于监控循环 Phase 0 之后、Phase A 之前(缩进为循环体内原样保留):
|
|
10
|
-
|
|
11
|
-
```
|
|
12
|
-
# ---- Phase 0.1: 多窗口阶段信号检查 ----
|
|
13
|
-
# 读取 multi-window-session.json,检查当前窗口的阶段是否就绪
|
|
14
|
-
if is_multi_window:
|
|
15
|
-
session_file = ".claude-daemon/multi-window-session.json"
|
|
16
|
-
try:
|
|
17
|
-
session_data = json_loads(Read(file_path=session_file))
|
|
18
|
-
except Exception:
|
|
19
|
-
session_data = None
|
|
20
|
-
|
|
21
|
-
if session_data:
|
|
22
|
-
my_stage = None
|
|
23
|
-
for s in session_data.get("stages", []):
|
|
24
|
-
if window_id in s.get("windows", []):
|
|
25
|
-
my_stage = s
|
|
26
|
-
break
|
|
27
|
-
|
|
28
|
-
if my_stage:
|
|
29
|
-
if my_stage.get("status") == "pending":
|
|
30
|
-
# 当前阶段未就绪,跳过本轮 Teamee 创建
|
|
31
|
-
# 输出: "⏸ 窗口 {window_id} 阶段 {my_stage['stage_id']} 尚未就绪,等待阶段信号"
|
|
32
|
-
pass # 跳过后续 Phase C 创建逻辑(通过标志控制)
|
|
33
|
-
elif my_stage.get("status") == "completed":
|
|
34
|
-
# 当前阶段已完成,检查是否有下一阶段
|
|
35
|
-
next_stage = None
|
|
36
|
-
for s in session_data.get("stages", []):
|
|
37
|
-
if s.get("stage_id") == my_stage.get("stage_id") + 1:
|
|
38
|
-
next_stage = s
|
|
39
|
-
break
|
|
40
|
-
if next_stage and next_stage.get("status") == "active":
|
|
41
|
-
# 切换到下一阶段的任务
|
|
42
|
-
assigned_wps = next_stage.get("work_packages", assigned_wps)
|
|
43
|
-
current_stage = next_stage.get("stage_id", current_stage)
|
|
44
|
-
# 输出: "🔄 窗口 {window_id} 切换到阶段 {next_stage['stage_id']}: {next_stage.get('name', '')}"
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
## Phase D.1 守护进程指令处理(DISP-003)
|
|
48
|
-
|
|
49
|
-
位于监控循环 Phase C.5 写回之后、Phase D 退出判定之前(缩进原样保留):
|
|
50
|
-
|
|
51
|
-
```
|
|
52
|
-
# ---- Phase D.1: 读取守护进程指令 (DISP-003) ----
|
|
53
|
-
# 在判断退出条件前,读取守护进程下发的指令
|
|
54
|
-
daemon_actions_path = ".claude-daemon/daemon-actions.json"
|
|
55
|
-
if file_exists(daemon_actions_path):
|
|
56
|
-
actions_data = Read(file_path=daemon_actions_path)
|
|
57
|
-
try:
|
|
58
|
-
actions = json_loads(actions_data).get("actions", [])
|
|
59
|
-
except Exception as e:
|
|
60
|
-
# 输出: "⚠️ 守护进程指令文件解析失败,跳过本轮指令: {e}"
|
|
61
|
-
actions = []
|
|
62
|
-
|
|
63
|
-
for action in actions:
|
|
64
|
-
# 检查指令是否已被处理
|
|
65
|
-
if action.get("id") in processed_action_ids:
|
|
66
|
-
continue
|
|
67
|
-
|
|
68
|
-
target_task_id = action.get("target_task")
|
|
69
|
-
action_type = action.get("action")
|
|
70
|
-
strategy = action.get("strategy", "full_restart")
|
|
71
|
-
reason = action.get("reason", "")
|
|
72
|
-
# 读取 Agentic Loop 下发的失败项明细(refine 通道,WP-176-6):
|
|
73
|
-
# 来源 skill-agentic-loop Step 4.2 的 dispatchTarget.failingDrivers,
|
|
74
|
-
# 每项 {wpId, category, item, reason};仅 retry/resplit 有值,dispatch 首次执行为空。
|
|
75
|
-
failing_drivers = action.get("failing_drivers", [])
|
|
76
|
-
|
|
77
|
-
if action_type == "restart":
|
|
78
|
-
# 重启指令: 逻辑销毁旧 Teamee → 创建新 Teamee
|
|
79
|
-
if target_task_id in teamee_map:
|
|
80
|
-
old_teamee = teamee_map[target_task_id]
|
|
81
|
-
|
|
82
|
-
# D1a. 逻辑销毁旧 Teamee(无协议帧)
|
|
83
|
-
markTeameeDestroyed(teamee_map, target_task_id)
|
|
84
|
-
|
|
85
|
-
# D1b. 根据策略创建新 Teamee
|
|
86
|
-
# 🔴 两种策略都注入 failing_drivers(refine 通道,WP-176-6):
|
|
87
|
-
# 让承接重做的 Teamee 知道"重点修哪些失败项",而非盲目原样重做。
|
|
88
|
-
assignment = wp_assignments[target_task_id]
|
|
89
|
-
new_teamee_name = f"{assignment.role_id}-t{target_task_id}-retry"
|
|
90
|
-
|
|
91
|
-
if strategy == "checkpoint_resume":
|
|
92
|
-
# 复杂任务: 注入已完成文件上下文 + 失败项重点修复段
|
|
93
|
-
context = action.get("context", {})
|
|
94
|
-
prompt = build_resume_prompt(
|
|
95
|
-
teamee_name=new_teamee_name,
|
|
96
|
-
task_id=target_task_id,
|
|
97
|
-
role_prompt=assignment.role_prompt,
|
|
98
|
-
completed_files=context.get("completed_files", []),
|
|
99
|
-
remaining=context.get("remaining", []),
|
|
100
|
-
failing_drivers=failing_drivers
|
|
101
|
-
)
|
|
102
|
-
else: # full_restart
|
|
103
|
-
# 简单任务: 从头执行(仍注入失败项重点修复段,区分 retry 与首次 dispatch)
|
|
104
|
-
prompt = build_refine_prompt(
|
|
105
|
-
teamee_name=new_teamee_name,
|
|
106
|
-
task_id=target_task_id,
|
|
107
|
-
role_prompt=assignment.role_prompt,
|
|
108
|
-
memories=assignment.memories,
|
|
109
|
-
wp_doc_path=assignment.wp_doc_path,
|
|
110
|
-
failing_drivers=failing_drivers
|
|
111
|
-
)
|
|
112
|
-
|
|
113
|
-
# D1c. 创建新 Teamee(自动加入 implicit session team,无需 team_name 参数)
|
|
114
|
-
Agent(
|
|
115
|
-
name=new_teamee_name,
|
|
116
|
-
subagent_type=resolve_subagent_type(assignment.role_id), # 双分支路由(见 Step 6 规则)
|
|
117
|
-
prompt=prompt
|
|
118
|
-
)
|
|
119
|
-
teamee_map[target_task_id] = new_teamee_name
|
|
120
|
-
|
|
121
|
-
# D1d. 更新重试计数
|
|
122
|
-
update_task_file(target_task_id, increment_retry=True)
|
|
123
|
-
|
|
124
|
-
# 标记指令已处理
|
|
125
|
-
processed_action_ids.append(action.get("id"))
|
|
126
|
-
|
|
127
|
-
elif action_type == "abort":
|
|
128
|
-
# 中止单个任务
|
|
129
|
-
if target_task_id in teamee_map:
|
|
130
|
-
teamee_name = teamee_map[target_task_id]
|
|
131
|
-
# 逻辑销毁(无协议帧)
|
|
132
|
-
markTeameeDestroyed(teamee_map, target_task_id)
|
|
133
|
-
update_task_file(target_task_id, status="failed")
|
|
134
|
-
processed_action_ids.append(action.get("id"))
|
|
135
|
-
|
|
136
|
-
elif action_type == "pause":
|
|
137
|
-
# 暂停创建新 Teamee(已有 Teamee 继续运行)
|
|
138
|
-
global_pause_flag = True
|
|
139
|
-
processed_action_ids.append(action.get("id"))
|
|
140
|
-
|
|
141
|
-
elif action_type == "abort_all":
|
|
142
|
-
# 全局中止: 逻辑销毁所有 Teamee,终止监控循环(无协议帧)
|
|
143
|
-
for task_id in list(teamee_map.keys()):
|
|
144
|
-
markTeameeDestroyed(teamee_map, task_id)
|
|
145
|
-
teamee_map.clear()
|
|
146
|
-
# 输出: "收到 abort_all 指令,终止监控循环"
|
|
147
|
-
processed_action_ids.append(action.get("id"))
|
|
148
|
-
break # 跳出监控循环
|
|
149
|
-
|
|
150
|
-
# D1e. 回写已处理的 iteration
|
|
151
|
-
if actions:
|
|
152
|
-
Write(file_path=daemon_actions_path, content=json_dumps({
|
|
153
|
-
"actions": [a for a in actions if a.get("id") not in processed_action_ids],
|
|
154
|
-
"last_processed_iteration": loop_iteration
|
|
155
|
-
}))
|
|
156
|
-
```
|
|
157
|
-
|
|
158
|
-
## Phase D.3 批次自动加载
|
|
159
|
-
|
|
160
|
-
位于监控循环每轮末尾、sleep(loop_interval) 之前(缩进原样保留):
|
|
161
|
-
|
|
162
|
-
```
|
|
163
|
-
# Phase D3: 批次自动加载 — 当前批次全部完成后从 pending_batches 加载下一批
|
|
164
|
-
if current_batch and len(teamee_map) == 0:
|
|
165
|
-
batch_completed = all(
|
|
166
|
-
find_by_id(tasks, tid).status == "completed" for tid in current_batch
|
|
167
|
-
if find_by_id(tasks, tid)
|
|
168
|
-
)
|
|
169
|
-
if batch_completed and pending_batches:
|
|
170
|
-
next_batch_size = min(max_batch_size, len(pending_batches))
|
|
171
|
-
current_batch = pending_batches[:next_batch_size]
|
|
172
|
-
pending_batches = pending_batches[next_batch_size:]
|
|
173
|
-
# 输出: "当前批次完成,自动加载下一批: {len(current_batch)} 个任务, 剩余 {len(pending_batches)} 个"
|
|
174
|
-
# 写回状态文件保存批次进度
|
|
175
|
-
write_state("monitoring")
|
|
176
|
-
```
|
|
3
|
+
> 本文件是 skill-agent-dispatcher 的按需参考(渐进式加载约定)。规则本体与触发条件仍在 SKILL.md 主干(Step 6 / Step 6.5 监控循环 Phase C、拆分工作包执行支持、共享上下文机制);以下章节仅在遇到对应运行时场景时按 📖指针 Read,无需预载。
|
|
177
4
|
|
|
178
5
|
## 辅助函数(is_unblocked / 并发控制)
|
|
179
6
|
|
|
@@ -215,6 +42,8 @@ def is_time_in_range(current, start, end):
|
|
|
215
42
|
return current >= start or current < end
|
|
216
43
|
```
|
|
217
44
|
|
|
45
|
+
配置来源:`agent_dispatcher.concurrency`(plugin.json / harness-config.yaml,字段 `default_max` + `schedules[{name, time_range:{start,end}, max_concurrent}]`)。Phase C 每轮用 `get_max_concurrent(config, now())` 取当前时段上限,活跃 Teamee 数(`len(teamee_map)`)达上限即跳过创建、任务保持 pending。
|
|
46
|
+
|
|
218
47
|
## 拆分工作包执行支持
|
|
219
48
|
|
|
220
49
|
当工作包有子工作包时,agent-dispatcher 会自动识别并按依赖调度。
|
|
@@ -252,10 +81,9 @@ def is_time_in_range(current, start, end):
|
|
|
252
81
|
|
|
253
82
|
### 主动共享 (通过 SendMessage)
|
|
254
83
|
|
|
255
|
-
>
|
|
84
|
+
> Teamee 一经 spawn **自动加入 implicit session team**——SendMessage 与共享 Task List 的协作能力由 implicit session team 提供。
|
|
256
85
|
|
|
257
86
|
| 消息类型 | 格式 | 用途 |
|
|
258
87
|
|----------|------|------|
|
|
259
|
-
| `shutdown_request` | (deprecated) |
|
|
260
|
-
| `shutdown_response` | (deprecated) | 同上;Teamee 状态同步改为 TaskUpdate(completed) → Lead 检测 → markTeameeDestroyed → 批末 team-cleanup CLI |
|
|
88
|
+
| `shutdown_request` / `shutdown_response` | (deprecated) | 不再使用;harness 拦截含 protocol frame 的 SendMessage message。Teamee 状态同步改为 TaskUpdate(completed) → Lead 检测 → markTeameeDestroyed |
|
|
261
89
|
| 纯文本状态 | string + summary | Teamee 间/向 Lead 的进度沟通(唯一允许的 SendMessage 用途) |
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"type": "skill",
|
|
5
5
|
"description": "Use when user says \"批量执行\", \"并行执行\", \"调度子代理\", or needs to execute multiple work packages using Agent subagents. Analyzes dependencies and dispatches tasks in parallel or sequential order.",
|
|
6
6
|
"triggers": ["批量执行", "并行执行", "调度子代理", "agent-dispatcher", "batch execute", "parallel execute", "dispatch agents"],
|
|
7
|
-
"dependencies": ["provider:role-registry"
|
|
7
|
+
"dependencies": ["provider:role-registry"],
|
|
8
8
|
"provides": ["skill:agent-dispatcher"],
|
|
9
9
|
"metadata": {
|
|
10
10
|
"gatedByCode": true
|
|
@@ -1,91 +1,132 @@
|
|
|
1
1
|
# Dispatcher Recovery Reference(异常处置与恢复细则)
|
|
2
2
|
|
|
3
|
-
> 本文件是 skill-agent-dispatcher
|
|
4
|
-
>
|
|
5
|
-
> 来源章节:SKILL.md Step 6.5 Phase D2-idle-heal 自愈流程、上下文恢复协议。
|
|
3
|
+
> 本文件是 skill-agent-dispatcher 的按需参考(渐进式加载约定)。规则本体仍在 SKILL.md(Phase D2-idle 注释块 + idle 自愈关键不变量 + Step 8 重派发 + 文末 HARD-GATE);以下仅在自愈 / 重派发 / 恢复场景触发时按 📖指针 Read。
|
|
4
|
+
> 状态载体统一为 Lead 循环内变量 `idle_state = {task_id: {started_at, idle_nudge_sent, retry_count}}`(与 `teamee_map` 同侧),事件记入 PROGRESS.md 该轮 history。
|
|
6
5
|
|
|
7
6
|
## Phase D2-idle-heal 自愈流程
|
|
8
7
|
|
|
9
|
-
|
|
8
|
+
触发条件(SKILL.md Phase D2-idle 检测段):task_stalled 且 `(now() - idle_state[task_id].started_at) >= idle_threshold`。命中后展开(`st` 即 `idle_state[task_id]`):
|
|
10
9
|
|
|
11
10
|
```
|
|
12
11
|
# 输出: "⚠️ idle 检测: Teamee {teamee_name} (task {task_id}) 停滞,进入自愈流程"
|
|
13
|
-
# ----
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
message=f"检测到任务 {task_id} 长时间未推进。请立即开始执行 WP 文档中的任务,完成后用 SendMessage 向 team-lead 发送完成报告。"
|
|
20
|
-
)
|
|
21
|
-
update_task_file(task_id, set_idle_nudge=True)
|
|
12
|
+
# ---- Step 1: 首轮仅催促一次(去重位),给满一个 idle_threshold 窗口,本轮不重 spawn ----
|
|
13
|
+
if not st["idle_nudge_sent"]:
|
|
14
|
+
SendMessage(to=teamee_name, summary="idle 检测催促,请立即执行任务",
|
|
15
|
+
message=f"检测到任务 {task_id} 长时间未推进。请立即开始执行 WP 文档中的任务,完成后用 SendMessage 向 team-lead 发送完成报告。")
|
|
16
|
+
st["idle_nudge_sent"] = True
|
|
17
|
+
record_progress("nudge", task_id) # 事件写入 PROGRESS.md
|
|
22
18
|
continue # 下一轮若仍 idle 且已催促,才进 Step 2-4
|
|
23
19
|
# 输出: "idle 自愈: task {task_id} 已催促过仍无推进,进 Step 2-4 重 spawn"
|
|
24
|
-
# Step 2: 验证 spawn 参数(定位根因,避免原样重 spawn 仍 idle
|
|
20
|
+
# ---- Step 2: 验证 spawn 参数(定位根因,避免原样重 spawn 仍 idle)----
|
|
25
21
|
assignment = wp_assignments[task_id]
|
|
26
22
|
spawn_params_ok = (
|
|
27
|
-
assignment.
|
|
28
|
-
and assignment.team_name == team_name
|
|
23
|
+
resolve_subagent_type(assignment.role_id) in (assignment.role_id, "general-purpose") # 双分支放行
|
|
29
24
|
and task_id in assignment.prompt
|
|
30
25
|
and assignment.wp_doc_path in assignment.prompt
|
|
31
26
|
and "SendMessage" in assignment.prompt # prompt 须要求完成报告用 SendMessage
|
|
32
27
|
)
|
|
33
28
|
if not spawn_params_ok:
|
|
34
|
-
# 输出: "spawn 参数异常 (subagent_type
|
|
29
|
+
# 输出: "spawn 参数异常 (subagent_type/prompt 完整性),将在重 spawn 时修正"
|
|
35
30
|
pass
|
|
36
|
-
# Step 3: 仍不执行 → 逻辑销毁旧 Teamee
|
|
31
|
+
# ---- Step 3: 仍不执行 → 逻辑销毁旧 Teamee(无协议帧)----
|
|
37
32
|
markTeameeDestroyed(teamee_map, task_id)
|
|
38
|
-
# Step 4:
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
max_retries = task_file.get("max_retries", 3)
|
|
42
|
-
if retry_count < max_retries:
|
|
43
|
-
# 重新 spawn 专用 Teamee(递增 retry_count),复用 restart 守护进程指令段的重 spawn 逻辑
|
|
33
|
+
# ---- Step 4: retry_count < max_retries → 重新 spawn ----
|
|
34
|
+
max_retries = 3
|
|
35
|
+
if st["retry_count"] < max_retries:
|
|
44
36
|
new_teamee_name = f"{assignment.role_id}-t{task_id}-idle-retry"
|
|
45
|
-
prompt = build_refine_prompt(
|
|
46
|
-
teamee_name=new_teamee_name,
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
memories=assignment.memories,
|
|
50
|
-
wp_doc_path=assignment.wp_doc_path,
|
|
51
|
-
failing_drivers=[] # idle 重 spawn 非失败项修复,failing_drivers 为空
|
|
52
|
-
)
|
|
53
|
-
Agent( # 自动加入 implicit session team,无需 team_name 参数
|
|
54
|
-
name=new_teamee_name,
|
|
55
|
-
subagent_type=resolve_subagent_type(assignment.role_id), # 双分支路由(见 Step 6 规则)
|
|
56
|
-
prompt=prompt
|
|
57
|
-
)
|
|
37
|
+
prompt = build_refine_prompt( # idle 重 spawn 非失败项修复,failing_drivers 为空
|
|
38
|
+
teamee_name=new_teamee_name, task_id=task_id, role_prompt=assignment.role_prompt,
|
|
39
|
+
memories=assignment.memories, wp_doc_path=assignment.wp_doc_path, failing_drivers=[])
|
|
40
|
+
Agent(name=new_teamee_name, subagent_type=resolve_subagent_type(assignment.role_id), prompt=prompt) # 双分支路由(见 Step 6 规则)
|
|
58
41
|
teamee_map[task_id] = new_teamee_name
|
|
59
|
-
#
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
reset_started_at=True, # F4
|
|
64
|
-
set_idle_nudge=False # F3
|
|
65
|
-
)
|
|
66
|
-
# 输出: "idle 自愈: task {task_id} 重新 spawn 为 {new_teamee_name} (retry {retry_count+1}/{max_retries}),已刷新 started_at + 重置催促去重位"
|
|
42
|
+
# 三合一赋值(缺任一复活死亡螺旋):递增 retry + 刷新 started_at + 重置催促去重位
|
|
43
|
+
st["retry_count"] += 1; st["started_at"] = now(); st["idle_nudge_sent"] = False
|
|
44
|
+
record_progress("idle-respawn", task_id, st["retry_count"])
|
|
45
|
+
# 输出: "idle 自愈: task {task_id} 重新 spawn 为 {new_teamee_name} (retry {st['retry_count']}/{max_retries})"
|
|
67
46
|
else:
|
|
68
|
-
# Step 5: 超限 → 熔断,绝不 Lead 接手,转 Step 7 清理
|
|
47
|
+
# ---- Step 5: 超限 → 熔断,绝不 Lead 接手,转 Step 7 清理 ----
|
|
69
48
|
TaskUpdate(taskId=task_id, status="failed")
|
|
70
|
-
|
|
71
|
-
|
|
49
|
+
idle_state.pop(task_id, None)
|
|
50
|
+
record_progress("idle-circuit-broken", task_id)
|
|
51
|
+
# 输出: "🔴 idle 自愈超限: task {task_id} 重试 {st['retry_count']}/{max_retries} 仍 idle,熔断标记 failed,绝不 Lead 接手,转 Step 7 清理"
|
|
72
52
|
```
|
|
73
53
|
|
|
74
|
-
|
|
54
|
+
> 上下文压缩后 `idle_state` 清零,恢复时按 `{"started_at": start_time, "idle_nudge_sent": False, "retry_count": 0}` 兜底——最坏后果是多催促一次。
|
|
55
|
+
|
|
56
|
+
## 重派发 restart 规格(SKILL.md Step 8 的展开)
|
|
57
|
+
|
|
58
|
+
`failingDrivers` 每项 `{wpId, category, item, reason}`(来源 loop Step 4.2,Reflect 从 `lastChecklist.failedItems` 归一化);仅 retry/resplit 有值,dispatch 首次执行为空。
|
|
59
|
+
|
|
60
|
+
```
|
|
61
|
+
# 1. 定位目标 Task:按 dispatchTarget.wpId 匹配 TaskList 中 subject "WP-XXX: ..."(或 wp_assignments 的 wp_id)
|
|
62
|
+
# 2. 逻辑销毁旧 Teamee(无协议帧):markTeameeDestroyed(teamee_map, task_id)
|
|
63
|
+
# 3. 命名与路由
|
|
64
|
+
assignment = wp_assignments[task_id]
|
|
65
|
+
new_teamee_name = f"{assignment.role_id}-t{task_id}-retry"
|
|
66
|
+
# 4. prompt:两种策略都注入 failing_drivers(refine 通道),让承接重做的 Teamee 优先修这些失败项
|
|
67
|
+
context = dispatchTarget.get("context", {})
|
|
68
|
+
if dispatchTarget["strategy"] == "checkpoint_resume":
|
|
69
|
+
prompt = build_resume_prompt( # 复杂任务:注入已完成文件上下文 + 失败项重点修复段
|
|
70
|
+
teamee_name=new_teamee_name, task_id=task_id, role_prompt=assignment.role_prompt,
|
|
71
|
+
completed_files=context.get("completedFiles", []), remaining=context.get("remaining", []),
|
|
72
|
+
failing_drivers=dispatchTarget["failingDrivers"])
|
|
73
|
+
else: # full_restart / resplit:从头执行,仍注入失败项重点修复段(区分 retry 与首次 dispatch)
|
|
74
|
+
prompt = build_refine_prompt(
|
|
75
|
+
teamee_name=new_teamee_name, task_id=task_id, role_prompt=assignment.role_prompt,
|
|
76
|
+
memories=assignment.memories, wp_doc_path=assignment.wp_doc_path,
|
|
77
|
+
failing_drivers=dispatchTarget["failingDrivers"])
|
|
78
|
+
# 5. 重 spawn + 三合一 idle 赋值
|
|
79
|
+
Agent(name=new_teamee_name, subagent_type=resolve_subagent_type(assignment.role_id), prompt=prompt)
|
|
80
|
+
TaskUpdate(taskId=task_id, owner=new_teamee_name)
|
|
81
|
+
teamee_map[task_id] = new_teamee_name
|
|
82
|
+
st = idle_state.setdefault(task_id, {"retry_count": 0})
|
|
83
|
+
idle_state[task_id] = {"started_at": now(), "idle_nudge_sent": False, "retry_count": st["retry_count"] + 1}
|
|
84
|
+
record_progress("redispatch", task_id, dispatchTarget["mode"], dispatchTarget["strategy"], len(dispatchTarget["failingDrivers"]))
|
|
85
|
+
# 6. 回 Step 6.5 监控循环
|
|
86
|
+
```
|
|
75
87
|
|
|
76
|
-
|
|
88
|
+
**resplit 模式补充**:`strategy='resplit'` 时把当前失败 WP 拆为子 WP(TaskCreate 子任务 + blockedBy,按 monitoring-reference.md「拆分工作包执行支持」调度),旧 Teamee 同样逻辑销毁;只拆当前失败 WP,不越界 P0。
|
|
77
89
|
|
|
78
|
-
|
|
90
|
+
### build_resume_prompt / build_refine_prompt(重点修复段)
|
|
79
91
|
|
|
92
|
+
`failing_drivers` 非空时输出「重点修复」段,为空不输出(退化为标准 prompt,向后兼容):
|
|
93
|
+
|
|
94
|
+
```
|
|
95
|
+
def render_refine_section(failing_drivers, mode_label):
|
|
96
|
+
refine_lines = "\n".join(f"- [{d.get('category','?')}] {d.get('item','?')} — {d.get('reason','?')}(WP: {d.get('wpId','?')})" for d in failing_drivers)
|
|
97
|
+
return f'''
|
|
98
|
+
## 🔴 本轮重点修复的失败项(来自上轮 checklist,优先处理)
|
|
99
|
+
你是在 {mode_label} 模式下重新执行任务。以下是你上轮 checklist 未通过的失败项明细。
|
|
100
|
+
**请优先、针对性地修复这些项**,而非盲目原样重做:
|
|
101
|
+
{refine_lines}
|
|
102
|
+
逐条核对你修复了每一项的失败原因(reason)。只有它们通过,本轮才算有效改进(而非无效重做)。'''
|
|
103
|
+
|
|
104
|
+
def build_resume_prompt(teamee_name, task_id, role_prompt, completed_files, remaining, failing_drivers=None):
|
|
105
|
+
base = f'''你是 {teamee_name},是一名 {role_prompt}。
|
|
106
|
+
## 任务重启 (Checkpoint Resume)
|
|
107
|
+
你正在重新执行任务 #{task_id}。之前的执行已完成部分工作,你将从断点继续。
|
|
108
|
+
### 已完成的文件
|
|
109
|
+
{chr(10).join(f"- {f}" for f in completed_files)}
|
|
110
|
+
### 待完成的工作
|
|
111
|
+
{chr(10).join(f"- {r}" for r in remaining)}
|
|
112
|
+
请阅读已完成文件的最新状态,然后继续执行剩余工作。不要重复已完成的工作,直接从断点继续。'''
|
|
113
|
+
return base + (render_refine_section(failing_drivers, "checkpoint_resume") if failing_drivers else "")
|
|
114
|
+
|
|
115
|
+
def build_refine_prompt(teamee_name, task_id, role_prompt, memories, wp_doc_path, failing_drivers=None):
|
|
116
|
+
base = build_single_task_prompt(teamee_name, task_id, role_prompt, memories, wp_doc_path)
|
|
117
|
+
return base + (render_refine_section(failing_drivers, "retry(full_restart)") if failing_drivers else "")
|
|
80
118
|
```
|
|
81
|
-
1. Read 状态文件(多窗口模式读 windows/{window_id}/state.json)
|
|
82
|
-
- 不存在 → 首次运行或已清理,从头开始
|
|
83
|
-
- status == "completed" → 执行已完成,无需恢复
|
|
84
|
-
- status == "monitoring" → 进入恢复流程
|
|
85
119
|
|
|
86
|
-
|
|
120
|
+
## 上下文恢复协议
|
|
87
121
|
|
|
88
|
-
|
|
122
|
+
监控循环因上下文压缩(auto-compact)中断后恢复(dispatcher 不写自有 state 文件,PROGRESS.md 是唯一持久层):
|
|
89
123
|
|
|
90
|
-
|
|
124
|
+
```
|
|
125
|
+
1. Read PROGRESS.md 尾部最近 history(loop 记录 / spawn / 催促 / 重 spawn / 重派发事件)
|
|
126
|
+
- 无记录 → 首次运行,从头开始;已终止(completed/failed)→ 无需恢复
|
|
127
|
+
2. TaskList() 取任务状态,重建 teamee_map:in_progress 且 owner 非空的 task → teamee_map[task.id] = owner
|
|
128
|
+
3. 重建 idle_state:history 有最近 spawn/重 spawn 时间则以此为 started_at,
|
|
129
|
+
否则按 {"started_at": start_time, "idle_nudge_sent": False, "retry_count": 0} 兜底(最坏后果 = 多催促一次)
|
|
130
|
+
4. 校验有效性:teamee_map 中的 Teamee 已失联(SendMessage 无响应且超过 idle_threshold)→ 走 Phase D2-idle-heal
|
|
131
|
+
5. 继续监控循环(loop_iteration 从恢复值 +1 开始)
|
|
91
132
|
```
|