dsh-punky-swarm 0.3.6
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/CHANGELOG.md +120 -0
- package/LICENSE +661 -0
- package/README.en.md +281 -0
- package/README.md +281 -0
- package/cordis.patch.yml +59 -0
- package/lib/acps/certs.js +310 -0
- package/lib/acps/discovery-client.js +283 -0
- package/lib/acps/registry-client.js +527 -0
- package/lib/acps/server.js +302 -0
- package/lib/aip/agent-descriptor.js +170 -0
- package/lib/aip/identity.js +469 -0
- package/lib/aip/tool-descriptor.js +93 -0
- package/lib/api.js +266 -0
- package/lib/artifact-types.js +48 -0
- package/lib/assembly/audit-blind-review.js +170 -0
- package/lib/assembly/schema.js +253 -0
- package/lib/assembly.js +41 -0
- package/lib/assets.js +103 -0
- package/lib/bridge/trajectory.js +202 -0
- package/lib/client.js +704 -0
- package/lib/comms/acps-bridge.js +219 -0
- package/lib/comms/aip-format.js +141 -0
- package/lib/comms/budget.js +124 -0
- package/lib/comms/mailbox.js +221 -0
- package/lib/comms/topic-runtime.js +76 -0
- package/lib/comms/topic.js +115 -0
- package/lib/discovery/filter.js +199 -0
- package/lib/discovery/schema.js +157 -0
- package/lib/discovery/service.js +251 -0
- package/lib/hot/config-watch.js +252 -0
- package/lib/index.js +433 -0
- package/lib/lock.js +69 -0
- package/lib/panel/batch-detail.js +163 -0
- package/lib/panel/batch-list.js +84 -0
- package/lib/panel/locales.js +93 -0
- package/lib/panel/main.js +270 -0
- package/lib/panel/stream.js +348 -0
- package/lib/panel/theme.js +103 -0
- package/lib/panel/widgets.js +63 -0
- package/lib/schema.d.ts +192 -0
- package/lib/schema.js +259 -0
- package/lib/schema.ts +398 -0
- package/lib/state/archive.js +174 -0
- package/lib/state/command-exec.js +148 -0
- package/lib/state/constants.js +37 -0
- package/lib/state/corrupt-registry.js +103 -0
- package/lib/state/event-types.js +65 -0
- package/lib/state/gates.d.ts +226 -0
- package/lib/state/gates.js +428 -0
- package/lib/state/gates.ts +348 -0
- package/lib/state/machine-rules.d.ts +14 -0
- package/lib/state/machine-rules.js +76 -0
- package/lib/state/machine-rules.ts +88 -0
- package/lib/state/machine.js +68 -0
- package/lib/state/resume.js +201 -0
- package/lib/state/schema-v3.d.ts +10 -0
- package/lib/state/schema-v3.js +57 -0
- package/lib/state/schema-v3.ts +80 -0
- package/lib/state/store.js +607 -0
- package/lib/state/task-utils.js +40 -0
- package/lib/tools/core.js +323 -0
- package/lib/tools/git-utils.js +44 -0
- package/lib/tools/lane-tools.js +455 -0
- package/lib/tools/log-tools.js +173 -0
- package/lib/tools/mailbox-tools.js +121 -0
- package/lib/tools/merge-agent.js +127 -0
- package/lib/tools/register.js +85 -0
- package/lib/tools/shared.js +32 -0
- package/lib/types/contracts.d.ts +277 -0
- package/lib/types/contracts.js +17 -0
- package/lib/types/contracts.ts +279 -0
- package/lib/verify/evidence.js +249 -0
- package/lib/verify/gate.js +161 -0
- package/lib/verify/mount.js +48 -0
- package/lib/verify/selector.js +101 -0
- package/lib/watch/lane-heartbeat.js +333 -0
- package/lib/wave-plan.d.ts +48 -0
- package/lib/wave-plan.js +473 -0
- package/lib/wave-plan.ts +465 -0
- package/package.json +71 -0
- package/presets/jiufeng/NOTICE +5 -0
- package/presets/jiufeng/agent.cordis.yml +275 -0
- package/presets/jiufeng/preset.yml +3 -0
- package/skills/jiufeng-team/SKILL.md +214 -0
- package/skills/jiufeng-team/references/constitution.md +62 -0
- package/skills/jiufeng-team/references/roles/coder.md +17 -0
- package/skills/jiufeng-team/references/roles/coordinator.md +13 -0
- package/skills/jiufeng-team/references/roles/designer.md +14 -0
- package/skills/jiufeng-team/references/roles/doc-manager.md +13 -0
- package/skills/jiufeng-team/references/roles/manager.md +22 -0
- package/skills/jiufeng-team/references/roles/reviewer.md +19 -0
- package/skills/jiufeng-team/references/roles/supervisor.md +13 -0
- package/skills/jiufeng-team/references/roles/tester.md +13 -0
- package/skills/jiufeng-team/references/templates/call-chain-matrix-template.md +121 -0
- package/skills/jiufeng-team/references/templates/endpoint-behavior-template.md +60 -0
- package/skills/jiufeng-team/references/templates/gap-list.json +33 -0
- package/skills/jiufeng-team/references/templates/leader-decision-pack.md +92 -0
- package/skills/jiufeng-team/references/templates/plan-template.md +61 -0
- package/skills/jiufeng-team/references/templates/success-pattern-seeds.md +126 -0
- package/skills/jiufeng-team/references/workflow.md +98 -0
- package/skills/jiufeng-team/scripts/check-v3-density.mjs +98 -0
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright (C) 2025-2026 Punky
|
|
3
|
+
|
|
4
|
+
This program is free software: you can redistribute it and/or modify
|
|
5
|
+
it under the terms of the GNU Affero General Public License as
|
|
6
|
+
published by the Free Software Foundation, either version 3 of the
|
|
7
|
+
License, or (at your option) any later version.
|
|
8
|
+
|
|
9
|
+
This program is distributed in the hope that it will be useful,
|
|
10
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
+
GNU Affero General Public License for more details.
|
|
13
|
+
|
|
14
|
+
You should have received a copy of the GNU Affero General Public License
|
|
15
|
+
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
// 蟛蜞模式治理核心工具(11 个),defineTool 规范含 output.schema + output.render
|
|
19
|
+
// 拆分自 lib/tools.js(core 域原样搬移,行为不变)
|
|
20
|
+
// 导出:createCoreTools(ctx, deps) => Array<defineTool>;installDifficultyGuard(ctx, deps)(难度门禁注册,原样搬移一字不改)
|
|
21
|
+
// 共享辅助(P2-01 下沉至零依赖 shared.js):TEXT_OUTPUT / sessionOf——本文件 re-export 保持对外导出兼容
|
|
22
|
+
// (mailbox-tools/log-tools/lane-tools 已直引 shared.js;watch/lane-heartbeat 不再依赖 core.js)
|
|
23
|
+
import { defineTool } from '@deepseek-ai/dsh-tools';
|
|
24
|
+
import { buildWavePlan, validateWavePlan } from '../wave-plan.js';
|
|
25
|
+
import { resolveAssembly } from '../assembly.js';
|
|
26
|
+
import { ARTIFACT_TYPES } from '../artifact-types.js';
|
|
27
|
+
import * as lock from '../lock.js';
|
|
28
|
+
import { join } from 'node:path';
|
|
29
|
+
import { TEXT_OUTPUT, sessionOf } from './shared.js';
|
|
30
|
+
export { TEXT_OUTPUT, sessionOf }; // P2-01 re-export:既有消费方(lib/tools/core.js 的 import 者)不受影响
|
|
31
|
+
// R-01 发端收敛:gate.role_* 事件字面量(:123 发端)改引 EVT 常量单点
|
|
32
|
+
import * as EVT from '../state/event-types.js';
|
|
33
|
+
|
|
34
|
+
// 执行型工具名单(有副作用/写盘/派发执行):guard 计数与拦截用;可被 config.escalation.execTools 覆盖
|
|
35
|
+
export const EXEC_TOOLS = [
|
|
36
|
+
'pwsh', 'bash', 'write', 'edit', 'run_code', 'workflow', 'ralph',
|
|
37
|
+
'ssh_exec', 'ssh_cluster', 'ssh_upload', 'ssh_download', 'subagent', 'subagent_fork',
|
|
38
|
+
];
|
|
39
|
+
|
|
40
|
+
// 清 pendingBatch(wave_plan 建批 / 批次 complete|aborted 后调用;无治理状态时不创建文件)
|
|
41
|
+
// session-compat:本会话曾把评估镜像到执行会话(mirroredTo)时,解锁同步传播到镜像会话,
|
|
42
|
+
// 避免 C@命名会话建批后,执行会话 guard 残留「先建批」幻觉锁
|
|
43
|
+
export function clearPendingBatch(store, sessionId) {
|
|
44
|
+
const g = store.readGovernance(sessionId);
|
|
45
|
+
const mirroredTo = g.mirroredTo ?? null;
|
|
46
|
+
if (g.pendingBatch || g.pendingSince || g.lastAssign || mirroredTo) {
|
|
47
|
+
store.writeGovernance(sessionId, { pendingBatch: false, pendingSince: null, mirroredTo: null });
|
|
48
|
+
}
|
|
49
|
+
if (mirroredTo && mirroredTo !== sessionId) {
|
|
50
|
+
const gm = store.readGovernance(mirroredTo);
|
|
51
|
+
if (gm.mirror?.from === sessionId) {
|
|
52
|
+
store.writeGovernance(mirroredTo, { pendingBatch: false, pendingSince: null, mirror: null });
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function lockPath(root, sessionId, batchId, lane) { return join(root, 'sessions', sessionId, '.locks', batchId + '.' + lane + '.lock'); }
|
|
58
|
+
|
|
59
|
+
// 任务难度值门禁注册:guard 逻辑原样搬移自 lib/tools.js(一字不改),注册顺序保持现状(createTools 开头)
|
|
60
|
+
export function installDifficultyGuard(ctx, deps) {
|
|
61
|
+
const { store, config = {} } = deps;
|
|
62
|
+
// 任务难度值门禁(design task-difficulty-gate §3,引擎强制不依赖自觉):执行型工具前置 guard
|
|
63
|
+
// 同步签名 (execution) => string | undefined;execution 含 name / agent.session.id;返回 string 即拒绝
|
|
64
|
+
if (typeof ctx.tools?.guard === 'function') {
|
|
65
|
+
ctx.tools.guard((execution) => {
|
|
66
|
+
// ② subagent 降级豁免(guard 开头):subagent/subagent_fork 派发的 worker 会话
|
|
67
|
+
// (delegationDepth>0 或带 parentSession)继承 Leader 侧已评估的任务形态,难度门禁不重复评估——
|
|
68
|
+
// 会话隔离(worker 无 Leader 侧 lastAssign)+ 同块并行时序下重复评估必然误拦。豁免仅限难度门禁,
|
|
69
|
+
// 其余 guard 语义(EXEC_TOOLS 名单、计数)不受影响;Leader 会话(无 header)仍走完整门禁。
|
|
70
|
+
const header = execution?.agent?.session?.header;
|
|
71
|
+
if (header && (header.delegationDepth > 0 || header.parentSession)) return undefined;
|
|
72
|
+
// ③′ session 解析对称:与 sessionOf 同序——execution.arguments.session 优先,缺省回退 agent.session.id。
|
|
73
|
+
// 修复显式传 session 时评估(args.session 落点)与拦截(只认 agent.session)不同步导致的误拦
|
|
74
|
+
const sessionId = execution?.arguments?.session ?? execution?.agent?.session?.id;
|
|
75
|
+
if (!sessionId) return undefined;
|
|
76
|
+
const execTools = config?.escalation?.execTools ?? EXEC_TOOLS;
|
|
77
|
+
// ① 非执行型:放行(治理/查询,防死锁)
|
|
78
|
+
// ⚠ P2-05 豁免边界(明示):
|
|
79
|
+
// - 豁免类别:治理/查询类工具(batch_status/gate_status/member_status/artifact_types/lane_checkpoint_status/
|
|
80
|
+
// lane_heartbeat 等不在 EXEC_TOOLS 名单者)+ 非执行型写(如 mailbox_read 读回执、assign_check 评估本身)。
|
|
81
|
+
// - 豁免理由:防死锁——难度门禁是「先评估后执行」的护栏,评估/查询动作若也被拦截将形成
|
|
82
|
+
// 「评估→被拦→无法评估」死循环(worker 被派发后须先读状态再干活,读状态不能被门禁卡死)。
|
|
83
|
+
// - 豁免范围:仅限难度门禁(本 guard);其余 guard 语义(EXEC_TOOLS 计数 bumpExecCount、
|
|
84
|
+
// 执行型调用次数统计)不受影响——下方 store.bumpExecCount 仍对所有执行型调用计数。
|
|
85
|
+
// - 名单可覆盖:config.escalation.execTools 可增减执行型名单(名单外即豁免)。
|
|
86
|
+
if (!execTools.includes(execution.name)) return undefined;
|
|
87
|
+
const g = store.readGovernance(sessionId);
|
|
88
|
+
let reason;
|
|
89
|
+
// 门禁 1:从未评估 或 已过期(execCallsSince≥20 / 距 lastAssign.at≥30min)→ 要求先评估
|
|
90
|
+
if (!g?.lastAssign?.form || store.stale(sessionId)) {
|
|
91
|
+
reason = '[task-difficulty-gate] 本回合尚未进行任务难度评估(A/B/C)。请先调用 assign_check(scope=full) 给出难度与执行主体,再执行 ' + execution.name;
|
|
92
|
+
} else if (g.lastAssign.form === 'C' && g.pendingBatch) {
|
|
93
|
+
// 门禁 2:判 C 且未建批 → 拒绝执行型(必须先 wave_plan 建批)
|
|
94
|
+
reason = '[task-difficulty-gate] 任务难度=C(集群方案),必须先 wave_plan 建批。已直做产物用 asset_claim 归位,然后建批派发。';
|
|
95
|
+
} else if ((execution.name === 'subagent' || execution.name === 'subagent_fork') && g.lastAssign.form === 'A') {
|
|
96
|
+
// 门禁 3(一致性):A 类不派发 subagent(需要独立上下文请重评 B)
|
|
97
|
+
reason = '[task-difficulty-gate] A 类任务不派发 subagent;如确实需要独立上下文请重评 B。';
|
|
98
|
+
}
|
|
99
|
+
store.bumpExecCount(sessionId); // 计数与拦截分离:无论是否拦截,执行型调用都计(机制 A 观察)
|
|
100
|
+
return reason;
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export function createCoreTools(ctx, deps) {
|
|
106
|
+
const { store, root, config = {} } = deps;
|
|
107
|
+
|
|
108
|
+
return [
|
|
109
|
+
defineTool({
|
|
110
|
+
name: "wave_plan",
|
|
111
|
+
description: "把任务按 DAG 依赖分层为 waves 并持久化为批次(wavePlan 固定语义,绝不在中途重算)。Tier3:任务可声明 layer(plan/exec/audit)/consume/produce/outputs/role/skills,建批时做三层契约静态校验;team 装配按 role 注入 skill 前缀(可插拔,不绑定 jiufeng)。批次绑定当前会话。产物落盘契约:引擎产物根 = <~/.dsh/jiufeng>/sessions/<sessionId>/artifacts/<batchId>/,consume/produce/outputs 相对路径均解析到该根下(worker 落盘按此根,勿落工作区根)。",
|
|
112
|
+
parameters: {"batchId":{"type":"string","required":true,"description":"批次 ID(kebab-case)"},"tasks":{"type":"array","required":true,"description":"任务列表 [{id, cmd, deps?, model?, tools?, layer?, role?, skills?, consume?, produce?, outputs?}]","items":{"type":"object","additionalProperties":true}},"concurrency":{"type":"integer","description":"并发上限(默认 5)"},"team":{"type":"string","description":"装配团队(默认 generic;三层批推荐 jiufeng)"},"session":{"type":"string","description":"批次归属会话(缺省=当前执行会话,cli 兜底)"}},
|
|
113
|
+
output: {
|
|
114
|
+
schema: {"type":"object","additionalProperties":false,"properties":{"batchId":{"type":"string","required":true},"sessionId":{"type":"string","required":true},"wavePlan":{"type":"array","required":true,"items":{"type":"object","additionalProperties":true}},"concurrency":{"type":"integer","required":true},"lanes":{"type":"object","required":true,"additionalProperties":true},"warnings":{"type":"array","items":{"type":"object","additionalProperties":true}}}},
|
|
115
|
+
render: (_args, value) => TEXT_OUTPUT('wavePlan created: ' + value.batchId + ' @' + value.sessionId + ' (' + value.wavePlan.length + ' waves)' + (value.warnings?.length ? '; role warnings: ' + value.warnings.length : '')),
|
|
116
|
+
},
|
|
117
|
+
async execute(args, exec) {
|
|
118
|
+
const sessionId = sessionOf(args, exec);
|
|
119
|
+
const assembly = resolveAssembly(args.team, config.assembly);
|
|
120
|
+
const plan = buildWavePlan({ batchId: args.batchId, tasks: args.tasks, concurrency: args.concurrency ?? 5, team: args.team, assembly });
|
|
121
|
+
validateWavePlan(plan);
|
|
122
|
+
const batch = store.createBatch(sessionId, { batchId: plan.batchId, wavePlan: plan, concurrency: plan.concurrency });
|
|
123
|
+
// role 校验告警留痕(GATE_ROLE_INVALID / GATE_ROLE_MISSING,warning 语义:事件留痕、不阻断建批;Leader 经返回值 warnings 可见)
|
|
124
|
+
for (const w of plan.warnings ?? []) {
|
|
125
|
+
store.appendEvent(sessionId, plan.batchId, w.code === 'GATE_ROLE_MISSING' ? EVT.EVT_GATE_ROLE_MISSING : EVT.EVT_GATE_ROLE_INVALID, { code: w.code, task: w.task ?? null, role: w.role ?? null, layer: w.layer ?? null, missing: w.missing ?? null });
|
|
126
|
+
}
|
|
127
|
+
clearPendingBatch(store, sessionId); // 建批解锁:判 C 后 pendingBatch=false(design §4 写入点)
|
|
128
|
+
return { batchId: plan.batchId, sessionId, wavePlan: plan.wavePlan, concurrency: plan.concurrency, lanes: batch.lanes, warnings: plan.warnings ?? [] };
|
|
129
|
+
},
|
|
130
|
+
}),
|
|
131
|
+
defineTool({
|
|
132
|
+
name: "batch_phase",
|
|
133
|
+
description: "批次阶段迁移:planning->running->paused->aborted|complete(终态后拒绝再写)。complete 前置:audit 层验收齐备(Tier3 门禁)。批次按会话隔离,缺省取当前执行会话。",
|
|
134
|
+
parameters: {"batchId":{"type":"string","required":true},"phase":{"type":"string","required":true,"enum":["running","paused","aborted","complete"]},"session":{"type":"string","description":"批次归属会话"}},
|
|
135
|
+
output: {
|
|
136
|
+
schema: {"type":"object","additionalProperties":false,"properties":{"batchId":{"type":"string","required":true},"phase":{"type":"string","required":true}}},
|
|
137
|
+
render: (_args, value) => TEXT_OUTPUT('batch ' + value.batchId + ' phase -> ' + value.phase),
|
|
138
|
+
},
|
|
139
|
+
async execute(args, exec) {
|
|
140
|
+
const sessionId = sessionOf(args, exec);
|
|
141
|
+
const b = store.setPhase(sessionId, args.batchId, args.phase);
|
|
142
|
+
if (b.phase === 'complete' || b.phase === 'aborted') clearPendingBatch(store, sessionId); // 兜底清理旧锁
|
|
143
|
+
return { batchId: args.batchId, phase: b.phase };
|
|
144
|
+
},
|
|
145
|
+
}),
|
|
146
|
+
defineTool({
|
|
147
|
+
name: "batch_status",
|
|
148
|
+
description: "查询批次状态(唯一事实源):phase/lanes/wavePlan/事件摘要;不传 batchId 则列出当前会话全部批次。可用 session 指定会话。",
|
|
149
|
+
parameters: {"batchId":{"type":"string","description":"批次 ID;缺省时列出该会话全部"},"session":{"type":"string","description":"批次归属会话"}},
|
|
150
|
+
output: {
|
|
151
|
+
schema: {"type":"object","additionalProperties":false,"properties":{"batchId":{"type":"string"},"phase":{"type":"string"},"concurrency":{"type":"integer"},"lanes":{"type":"object","additionalProperties":true},"wavePlan":{"type":"array","items":{"type":"object","additionalProperties":true}},"eventCount":{"type":"integer"},"recentEvents":{"type":"array","items":{"type":"object","additionalProperties":true}},"settled":{"type":"boolean"},"sessionId":{"type":"string"},"batches":{"type":"array","items":{"type":"object","additionalProperties":true}}}},
|
|
152
|
+
render: (_args, value) => value.batchId ? TEXT_OUTPUT('batch ' + value.batchId + ' phase=' + value.phase + ' settled=' + value.settled) : TEXT_OUTPUT('batches: ' + (value.batches ?? []).length),
|
|
153
|
+
},
|
|
154
|
+
async execute(args, exec) {
|
|
155
|
+
const sessionId = sessionOf(args, exec);
|
|
156
|
+
if (!args.batchId) {
|
|
157
|
+
return { sessionId, batches: store.listBatches(sessionId).map((id) => { const b = store.readBatch(sessionId, id); return { batchId: id, sessionId, phase: b.phase, lanes: b.lanes }; }) };
|
|
158
|
+
}
|
|
159
|
+
const b = store.readBatch(sessionId, args.batchId);
|
|
160
|
+
if (!b) throw new Error('batch not found: ' + args.batchId + ' @' + sessionId);
|
|
161
|
+
return { batchId: b.batchId, sessionId, phase: b.phase, concurrency: b.concurrency, lanes: b.lanes, wavePlan: b.wavePlan, eventCount: b.events.length, recentEvents: b.events.slice(-20), settled: store.batchSettled(b) };
|
|
162
|
+
},
|
|
163
|
+
}),
|
|
164
|
+
defineTool({
|
|
165
|
+
name: "artifact_types",
|
|
166
|
+
description: "产物类型注册表(只读,Tier3 通用任务治理):列出产物类型 → 层/目录前缀约定,供 wave_plan 声明产物与模板对齐。不绑定任何团队模板。",
|
|
167
|
+
parameters: {},
|
|
168
|
+
output: {
|
|
169
|
+
schema: {"type":"object","additionalProperties":false,"properties":{"types":{"type":"array","required":true,"items":{"type":"object","additionalProperties":true}}}},
|
|
170
|
+
render: (_args, value) => TEXT_OUTPUT('artifact types: ' + value.types.length),
|
|
171
|
+
},
|
|
172
|
+
async execute() {
|
|
173
|
+
return { types: ARTIFACT_TYPES.map((t) => ({ type: t.type, dir: t.dir, layer: t.layer, desc: t.desc })) };
|
|
174
|
+
},
|
|
175
|
+
}),
|
|
176
|
+
defineTool({
|
|
177
|
+
name: "assign_check",
|
|
178
|
+
description: "委派形态判定(设计 §10/§15.3 N3):判断任务应由 Leader 直做(A)/ 轻量委派 subagent(B,需独立上下文/工具面时)/ 必须走流水线批次(C)。输入任务特征(并行?/多角色?/门禁?/可恢复?/需独立上下文?),返回判定与原因;C 类任务应走 wave_plan 建批。每次调用写入会话治理状态(governance.lastAssign+history),guard 依据其做执行型工具门禁。显式 session 时输出回显 sessionId 并镜像到执行会话(guard 兼容不误拦);缺省=当前执行会话,cli 兜底并提示。",
|
|
179
|
+
parameters: {"parallel":{"type":"boolean","description":"需要并行或任务间依赖(DAG)"},"multiRole":{"type":"boolean","description":"需要多角色协作(编码+测试+审查分离)"},"gate":{"type":"boolean","description":"需要门禁/审计(人审、验收、gap-list)"},"recoverable":{"type":"boolean","description":"需要跨轮治理/可恢复/可审计"},"needIsolation":{"type":"boolean","description":"需要独立上下文/工具面(查代码、跑测试等)"},"scope":{"type":"string","enum":["current","full"],"description":"评估对象:current=当前动作,full=完整目标任务(纪律强制 full,防把小动作当整体难度)"},"session":{"type":"string","description":"显式指定评估落点会话(当前会话 ID 或命名黑板);缺省=当前执行会话,cli 兜底;与执行会话不同时自动镜像到执行会话(guard 兼容)"}},
|
|
180
|
+
output: {
|
|
181
|
+
schema: {"type":"object","additionalProperties":false,"properties":{"form":{"type":"string","required":true},"allowed":{"type":"boolean","required":true},"reasons":{"type":"array","required":true,"items":{"type":"string"}},"next":{"type":"array","required":true,"items":{"type":"string"}},"execToolCount":{"type":"integer","required":true},"escalationHint":{"type":"string","required":true},"sessionId":{"type":"string","required":true},"mirroredTo":{"type":"string"},"notice":{"type":"string"},"history":{"type":"array","items":{"type":"object","additionalProperties":true}}}},
|
|
182
|
+
render: (_args, value) => {
|
|
183
|
+
let s = 'assign form: ' + value.form + (value.form === 'C' ? ' (must use batch) → next: wave_plan' : ' (allowed)') + (value.sessionId ? ' @' + value.sessionId : '');
|
|
184
|
+
if (value.mirroredTo) s += ' [mirror→' + value.mirroredTo + ']';
|
|
185
|
+
if (value.escalationHint) s += ' ⚠ ' + value.escalationHint;
|
|
186
|
+
if (value.notice) s += ' ⚠ ' + value.notice;
|
|
187
|
+
return TEXT_OUTPUT(s);
|
|
188
|
+
},
|
|
189
|
+
},
|
|
190
|
+
async execute(args, exec) {
|
|
191
|
+
const sessionId = sessionOf(args, exec);
|
|
192
|
+
const reasons = [];
|
|
193
|
+
if (args.parallel) reasons.push('需要并行或任务依赖(DAG)');
|
|
194
|
+
if (args.multiRole) reasons.push('需要多角色协作(编码+测试+审查分离)');
|
|
195
|
+
if (args.gate) reasons.push('需要门禁/审计(人审、验收、gap-list)');
|
|
196
|
+
if (args.recoverable) reasons.push('需要跨轮治理/可恢复/可审计');
|
|
197
|
+
const form = reasons.length ? 'C' : (args.needIsolation ? 'B' : 'A');
|
|
198
|
+
// 写入治理状态:lastAssign + history 追加(审计:每回合评估留痕);C 类且无活跃批次 → pendingBatch=true
|
|
199
|
+
const now = new Date().toISOString();
|
|
200
|
+
const scope = args.scope ?? 'full';
|
|
201
|
+
const g0 = store.readGovernance(sessionId);
|
|
202
|
+
const history = [...(g0.history ?? []), { turn: (g0.history?.length ?? 0) + 1, form, at: now, reasons }];
|
|
203
|
+
const hasActive = store.hasActiveBatch(sessionId);
|
|
204
|
+
const patch = { lastAssign: { form, scope, at: now, reasons, execCallsSince: 0 }, history };
|
|
205
|
+
if (form === 'C' && !hasActive) { patch.pendingBatch = true; patch.pendingSince = now; }
|
|
206
|
+
// 新评估总是把 pendingBatch 收敛到正确状态——已有活跃批次,或残留 pendingBatch(C 判定后重评为 A/B),一律清锁
|
|
207
|
+
else if (hasActive || g0.pendingBatch) { patch.pendingBatch = false; patch.pendingSince = null; }
|
|
208
|
+
// session-compat:显式 session 与执行会话不同 → 镜像到执行会话(guard 落点兼容)。
|
|
209
|
+
// 镜像只写 lastAssign + pendingBatch + mirror 指针,不污染执行会话 history;解锁经 clearPendingBatch 传播
|
|
210
|
+
const execSessionId = exec?.agent?.session?.id ?? null;
|
|
211
|
+
const mirror = Boolean(args?.session && execSessionId && args.session !== execSessionId);
|
|
212
|
+
if (mirror) patch.mirroredTo = execSessionId;
|
|
213
|
+
const g = store.writeGovernance(sessionId, patch);
|
|
214
|
+
let mirroredTo = null;
|
|
215
|
+
if (mirror) {
|
|
216
|
+
mirroredTo = execSessionId;
|
|
217
|
+
store.writeGovernance(execSessionId, {
|
|
218
|
+
lastAssign: { ...patch.lastAssign, mirroredFrom: sessionId },
|
|
219
|
+
pendingBatch: patch.pendingBatch ?? g.pendingBatch ?? false,
|
|
220
|
+
pendingSince: patch.pendingSince ?? g.pendingSince ?? null,
|
|
221
|
+
mirror: { from: sessionId, at: now },
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
const execToolCount = g.execToolCount ?? 0;
|
|
225
|
+
// 升级信号(design escalation-hardgate §2.2 S4):execToolCount≥5 且无活跃批次 → 软提示
|
|
226
|
+
const escalationHint = (execToolCount >= 5 && !hasActive)
|
|
227
|
+
? 'execToolCount=' + execToolCount + ' ≥5 且无批次:任务已升级为复杂形态,必须 wave_plan 建批'
|
|
228
|
+
: '';
|
|
229
|
+
// session-compat:cli 兜底警示(共享黑板跨调用互相覆盖)
|
|
230
|
+
const notice = sessionId === 'cli'
|
|
231
|
+
? 'session 未显式指定且无 agent.session:评估落点 cli 共享黑板,跨调用互相覆盖,建议显式传 session'
|
|
232
|
+
: '';
|
|
233
|
+
// 条件构造返回对象:不触发镜像时镜像字段完全缺席——undefined/null 值均会触发 harness lossless JSON 校验拒绝
|
|
234
|
+
const out = { form, allowed: form !== 'C', reasons, next: form === 'C' ? ['wave_plan'] : [], execToolCount, escalationHint, notice, sessionId, history: g.history };
|
|
235
|
+
if (mirroredTo) out.mirroredTo = mirroredTo;
|
|
236
|
+
return out;
|
|
237
|
+
},
|
|
238
|
+
}),
|
|
239
|
+
defineTool({
|
|
240
|
+
name: "asset_claim",
|
|
241
|
+
description: "归位(设计 6.3):Leader 已直做产物(探索/探测/排障)注册为批次资产——复制 source 进 <artifacts>/<batchId>/<target>(保留内容,不移动),批次事件 asset.claimed 留痕,返回批次内路径供 wave_plan consume/produce 声明。路径防逃逸:target 必须是批次内相对路径,拒绝 .. 与绝对路径。引擎产物根 = <~/.dsh/jiufeng>/sessions/<sessionId>/artifacts/<batchId>/;worker 按工作区落盘的产物,结算前须经本工具归位到该根下。",
|
|
242
|
+
parameters: {"batchId":{"type":"string","required":true,"description":"批次 ID"},"source":{"type":"string","required":true,"description":"源文件绝对路径(已直做产物)"},"target":{"type":"string","required":true,"description":"批次内目标路径(相对 artifacts/<batchId>/,不得含 .. 或绝对路径)"},"session":{"type":"string","description":"批次归属会话(缺省=当前执行会话,cli 兜底)"}},
|
|
243
|
+
output: {
|
|
244
|
+
schema: {"type":"object","additionalProperties":false,"properties":{"ok":{"type":"boolean","required":true},"claimedPath":{"type":"string"},"batchId":{"type":"string"}}},
|
|
245
|
+
render: (_args, value) => TEXT_OUTPUT('asset claimed: ' + value.claimedPath),
|
|
246
|
+
},
|
|
247
|
+
async execute(args, exec) {
|
|
248
|
+
const sessionId = sessionOf(args, exec);
|
|
249
|
+
const r = store.claimAsset(sessionId, args.batchId, { source: args.source, target: args.target });
|
|
250
|
+
return { ok: r.ok, claimedPath: r.claimedPath, batchId: r.batchId };
|
|
251
|
+
},
|
|
252
|
+
}),
|
|
253
|
+
defineTool({
|
|
254
|
+
name: "gate_status",
|
|
255
|
+
description: "查询批次/ lane 的门禁状态(设计 §8 M1):layer、consume/produce/outputs 缺失清单、plan 契约问题。不传 lane 列出全部 lane。",
|
|
256
|
+
parameters: {"batchId":{"type":"string","required":true},"lane":{"type":"string","description":"lane ID;缺省列出全部"},"session":{"type":"string","description":"批次归属会话"}},
|
|
257
|
+
output: {
|
|
258
|
+
schema: {"type":"object","additionalProperties":false,"properties":{"batchId":{"type":"string","required":true},"sessionId":{"type":"string","required":true},"lanes":{"type":"array","required":true,"items":{"type":"object","additionalProperties":true}}}},
|
|
259
|
+
render: (_args, value) => TEXT_OUTPUT('gate status: ' + value.lanes.length + ' lane(s)'),
|
|
260
|
+
},
|
|
261
|
+
async execute(args, exec) {
|
|
262
|
+
const sessionId = sessionOf(args, exec);
|
|
263
|
+
const batch = store.readBatch(sessionId, args.batchId);
|
|
264
|
+
if (!batch) throw new Error('batch not found: ' + args.batchId);
|
|
265
|
+
const ids = args.lane ? [args.lane] : Object.keys(batch.lanes);
|
|
266
|
+
return { batchId: args.batchId, sessionId, lanes: ids.map((l) => store.gateStatus(sessionId, args.batchId, l)) };
|
|
267
|
+
},
|
|
268
|
+
}),
|
|
269
|
+
defineTool({
|
|
270
|
+
name: "lane_claim",
|
|
271
|
+
description: "以 O_EXCL 单写者锁认领 lane(同一批次同一 lane 同时只允许一个写者)。冲突先拒绝;可 wait 或 force 接管。锁按会话隔离。",
|
|
272
|
+
parameters: {"batchId":{"type":"string","required":true},"lane":{"type":"string","required":true,"description":"任务 ID"},"waitMs":{"type":"integer","description":"等待毫秒(默认 0 = 直接冲突返回)"},"force":{"type":"boolean","description":"force 接管(默认 false)"},"session":{"type":"string","description":"批次归属会话"}},
|
|
273
|
+
output: {
|
|
274
|
+
schema: {"type":"object","additionalProperties":false,"properties":{"ok":{"type":"boolean","required":true},"token":{"type":"string"},"conflict":{"type":"boolean"},"reason":{"type":"string"},"lockPath":{"type":"string"}}},
|
|
275
|
+
render: (_args, value) => value.ok ? TEXT_OUTPUT('lane claimed') : TEXT_OUTPUT('lane conflict'),
|
|
276
|
+
},
|
|
277
|
+
async execute(args, exec) {
|
|
278
|
+
const sessionId = sessionOf(args, exec);
|
|
279
|
+
const r = await lock.acquire(lockPath(root, sessionId, args.batchId, args.lane), { waitMs: args.waitMs ?? 0, force: args.force === true });
|
|
280
|
+
if (!r.ok) return { ok: false, conflict: true, reason: 'lane locked' };
|
|
281
|
+
return { ok: true, token: r.token };
|
|
282
|
+
},
|
|
283
|
+
}),
|
|
284
|
+
defineTool({
|
|
285
|
+
name: "lane_release",
|
|
286
|
+
description: "释放 lane 锁(需持有 token;token 不匹配拒绝释放)。锁按会话隔离。",
|
|
287
|
+
parameters: {"batchId":{"type":"string","required":true},"lane":{"type":"string","required":true},"token":{"type":"string","required":true},"session":{"type":"string","description":"批次归属会话"}},
|
|
288
|
+
output: {
|
|
289
|
+
schema: {"type":"object","additionalProperties":false,"properties":{"ok":{"type":"boolean","required":true},"reason":{"type":"string"}}},
|
|
290
|
+
render: (_args, value) => value.ok ? TEXT_OUTPUT('lane released') : TEXT_OUTPUT('release failed: ' + (value.reason ?? '')),
|
|
291
|
+
},
|
|
292
|
+
async execute(args, exec) {
|
|
293
|
+
return lock.release(lockPath(root, sessionOf(args, exec), args.batchId, args.lane), args.token);
|
|
294
|
+
},
|
|
295
|
+
}),
|
|
296
|
+
defineTool({
|
|
297
|
+
name: "member_settle",
|
|
298
|
+
description: "成员结算:按状态机迁移(running->review->merged/failed/skipped/conflict),写入 member.settled 事件。Tier3 门禁:plan merged 前 Plan 契约校验(spec 必填章节 + task-tree JSON)、exec merged 前 outputs 校验、audit merged 前 produce 校验;lane 声明 targets 时,merged 前逐一核对 targets 落盘(存在性,不读正文),缺则拒 merged 抛 GATE_TARGET_MISSING、未变更抛 GATE_TARGET_UNCHANGED。needHuman:audit lane 产物含独立行 `needHuman: true` 声明时,merged 须 note 携带人工裁决证据(契约 `human:<裁决人>:<时间>:<结论>`,如 human:user@2026-08-21:accept),缺则拒 GATE_NEEDHUMAN_PENDING;conflict 驳回不强制(评审驳回语义)。命令 gate(V1):exec 层产物可含独立行 `gate: <命令>`(行首锚定,可多行顺序执行),merged 前置确定性执行并以退出码判定(exit 0 通过,事件 gate.exit);失败拒 merged 抛 GATE_EXIT_*(lane 留 review);失败且产物声明 `needHuman: true` → 转人工闸(merged 须 note 含 human: 证据,缺则 GATE_NEEDHUMAN_PENDING)。批次按会话隔离。",
|
|
299
|
+
parameters: {"batchId":{"type":"string","required":true},"lane":{"type":"string","required":true},"status":{"type":"string","required":true,"enum":["merged","failed","skipped","conflict"]},"note":{"type":"string","description":"简短备注(只留元数据,不复制正文)"},"session":{"type":"string","description":"批次归属会话"}},
|
|
300
|
+
output: {
|
|
301
|
+
schema: {"type":"object","additionalProperties":false,"properties":{"batchId":{"type":"string","required":true},"lane":{"type":"string","required":true},"status":{"type":"string","required":true},"settled":{"type":"boolean","required":true}}},
|
|
302
|
+
render: (_args, value) => TEXT_OUTPUT('member ' + value.lane + ' settled -> ' + value.status),
|
|
303
|
+
},
|
|
304
|
+
async execute(args, exec) {
|
|
305
|
+
const b = store.setMember(sessionOf(args, exec), args.batchId, args.lane, args.status, args.note ?? null);
|
|
306
|
+
return { batchId: args.batchId, lane: args.lane, status: b.lanes[args.lane], settled: store.batchSettled(b) };
|
|
307
|
+
},
|
|
308
|
+
}),
|
|
309
|
+
defineTool({
|
|
310
|
+
name: "member_status",
|
|
311
|
+
description: '成员状态操作(非终态):pending->running(派发,Tier3 门禁:exec 需 consume 齐备)、running->review(提交评审)、idle->running(恢复重派)。终态结算请用 member_settle。批次按会话隔离。',
|
|
312
|
+
parameters: {"batchId":{"type":"string","required":true},"lane":{"type":"string","required":true},"status":{"type":"string","required":true,"enum":["pending","running","review","idle"]},"session":{"type":"string","description":"批次归属会话"}},
|
|
313
|
+
output: {
|
|
314
|
+
schema: {"type":"object","additionalProperties":false,"properties":{"batchId":{"type":"string","required":true},"lane":{"type":"string","required":true},"status":{"type":"string","required":true},"settled":{"type":"boolean","required":true}}},
|
|
315
|
+
render: (_args, value) => TEXT_OUTPUT('member ' + value.lane + ' status -> ' + value.status),
|
|
316
|
+
},
|
|
317
|
+
async execute(args, exec) {
|
|
318
|
+
const b = store.setMember(sessionOf(args, exec), args.batchId, args.lane, args.status, null);
|
|
319
|
+
return { batchId: args.batchId, lane: args.lane, status: b.lanes[args.lane], settled: store.batchSettled(b) };
|
|
320
|
+
},
|
|
321
|
+
}),
|
|
322
|
+
];
|
|
323
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright (C) 2025-2026 Punky
|
|
3
|
+
|
|
4
|
+
This program is free software: you can redistribute it and/or modify
|
|
5
|
+
it under the terms of the GNU Affero General Public License as
|
|
6
|
+
published by the Free Software Foundation, either version 3 of the
|
|
7
|
+
License, or (at your option) any later version.
|
|
8
|
+
|
|
9
|
+
This program is distributed in the hope that it will be useful,
|
|
10
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
+
GNU Affero General Public License for more details.
|
|
13
|
+
|
|
14
|
+
You should have received a copy of the GNU Affero General Public License
|
|
15
|
+
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
// lib/tools/git-utils.js —— git 调用单点(R-06 runGit 下沉)
|
|
19
|
+
// -----------------------------------------------------------------------------
|
|
20
|
+
// 原 runGit 定义于 lane-tools.js(P1-05 起 merge-agent 消费 lane-tools 导出版),
|
|
21
|
+
// lane-tools.js ↔ merge-agent.js 相互 import 构成双向环(运行时 live binding 无碍,
|
|
22
|
+
// 但静态引用环可读性差、易踩初始化顺序坑)。R-06 把 runGit/gitBin 下沉到本零依赖
|
|
23
|
+
// 模块:lane-tools.js 与 merge-agent.js 均改引本文件,双向环消除。
|
|
24
|
+
// 零依赖:仅 node:child_process(不 import 任何本包模块,避免环)。
|
|
25
|
+
import { execFileSync } from 'node:child_process';
|
|
26
|
+
|
|
27
|
+
const gitBin = () => process.env.DSH_GIT_BIN ?? 'git';
|
|
28
|
+
|
|
29
|
+
// git 调用统一契约(仿 study-taskswarm git.ts runGit):同步、{ ok, stdout, stderr, code };
|
|
30
|
+
// git 缺失/不可执行 → ok:false + 清晰错误(不挂起、不静默失败,验收 T5)
|
|
31
|
+
export function runGit(repo, args, { cwd } = {}) {
|
|
32
|
+
try {
|
|
33
|
+
const out = execFileSync(gitBin(), args, {
|
|
34
|
+
cwd: cwd ?? repo,
|
|
35
|
+
encoding: 'utf8',
|
|
36
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
37
|
+
windowsHide: true,
|
|
38
|
+
});
|
|
39
|
+
return { ok: true, stdout: String(out ?? '').trim(), stderr: '', code: 0 };
|
|
40
|
+
} catch (e) {
|
|
41
|
+
const stderr = e?.stderr ? String(e.stderr).trim() : (e?.message ? String(e.message) : String(e));
|
|
42
|
+
return { ok: false, stdout: '', stderr, code: typeof e?.status === 'number' ? e.status : -1 };
|
|
43
|
+
}
|
|
44
|
+
}
|