carlos-flow 2.8.0 → 2.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/CHANGELOG.md +35 -0
- package/README.en.md +10 -5
- package/README.md +9 -4
- package/README.zh.md +9 -4
- package/TRIGGER_GUIDE.md +3 -3
- package/ghost.json +72 -1
- package/package.json +1 -1
- package/scripts/check-no-dead-handler.mjs +2 -2
- package/src/dispatch.js +49 -19
- package/src/index.js +144 -1
- package/src/state.js +29 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,41 @@
|
|
|
5
5
|
|
|
6
6
|
---
|
|
7
7
|
|
|
8
|
+
## [2.9.0] - 2026-11-12 — 双轴审查门禁:PASS 裁定前必须收齐 Standards / Spec 两轴证据
|
|
9
|
+
|
|
10
|
+
### ✨ 新增 | Added
|
|
11
|
+
|
|
12
|
+
- **`flow_audit_axes`** —— 派发两个并行审计 subagent(Standards 轴 / Spec 轴),各生成一段中文审计合同 prompt。
|
|
13
|
+
- **`flow_audit_submit`** —— 保存某一审计轴的结论与证据,按 `card_ts` 绑定当前卡(同轴可重复提交、后者覆盖)。
|
|
14
|
+
- **`flow_audit_guard`** —— 两轴门禁自查,与 `flow_verdict` 内的门禁同口径;给主 Agent 一个「落 PASS 前先自查」的显式工具。
|
|
15
|
+
- **`flow_status` 暴露双轴状态** —— 新增 `audit_axes` / `audit_axes_ts` / `axes_ready`,主 Agent 落 PASS 前可读。
|
|
16
|
+
|
|
17
|
+
### 🔒 变更 | Changed
|
|
18
|
+
|
|
19
|
+
- **`flow_verdict` 新增双轴门禁**(防假闭环之六):落 `PASS` 前必须两轴证据齐全且无轴 FAIL。
|
|
20
|
+
- **位置**:在负对照门禁**之后**,是 PASS 落定前的最后一道。六道门各自独立、互不掩盖;
|
|
21
|
+
若前置会让「未验证 / 未派发 / 未做负对照」这些更基础的问题被双轴错误信息掩盖。
|
|
22
|
+
- **判定**:任一轴 FAIL 硬拦;WARN(坏味道等 judgement call)只标注不拦。
|
|
23
|
+
- **防冒充**:两轴证据均绑定 `card_ts`,旧卡的审查结果不能冒充新卡(也堵住「卡A的 standards + 卡B的 spec」跨卡拼接)。
|
|
24
|
+
- `DIRECTION` / `LOCAL` 不受限制(返工意见不构成完成)。
|
|
25
|
+
- **状态结构版本 v2 → v3**:`migrate()` 新增 v2→v3 迁移,补全旧状态的 `audit_axes` / `audit_axes_ts`。
|
|
26
|
+
|
|
27
|
+
### 🔧 实现 | Implementation
|
|
28
|
+
|
|
29
|
+
- `src/dispatch.js`:新增 `AXIS_PROMPTS` 配置表,`buildContractPrompt` 加第 4 参 `axis`(可缺省,旧调用不变);加新轴只改配置表,不动函数体。
|
|
30
|
+
- `src/state.js`:`defaultState()` 新增两字段;`migrate()` 加 v2→v3。
|
|
31
|
+
- `src/index.js`:新增 3 工具;`flow_verdict` 加门禁;`flow_status` 暴露双轴状态。
|
|
32
|
+
- `ghost.json`:工具清单 16 → 19,与服务端逐一对齐。
|
|
33
|
+
|
|
34
|
+
### 🔬 验证 | Verification
|
|
35
|
+
|
|
36
|
+
- 新增 11 条双轴专项用例(27a–27k):未齐拦截 / 单轴拦截 / 双轴 FAIL 对称拦截 / WARN 放行 / DIRECTION 兼容 / 旧卡防冒充 / guard 三种状态 / `flow_status` 暴露。
|
|
37
|
+
- 既有正向 PASS 用例全部补上双轴前置(e2e-carlos / package-e2e / scope-enforcement),负向用例不受影响。
|
|
38
|
+
- 主测试 **76/0** 通过(e2e);p0 22/0;scope-enforcement 10/0;package-e2e 19/0;trigger 29/0;concurrency 3/0;acceptance 13/0;lang 12/0;smoke 通过。
|
|
39
|
+
- `check:full` / `check:lang` / `check:anchors` / `check:parity` / `check:readme` 全部通过。
|
|
40
|
+
|
|
41
|
+
---
|
|
42
|
+
|
|
8
43
|
## [2.8.0] - 2026-11-08 — 角色门禁绑定会话 claimed_role + auditor 复核流程 + CI 修复
|
|
9
44
|
|
|
10
45
|
- flow_verdict PASS 现在必须由已 claim "auditor" 角色的会话落下(claimed_role 绑定会话 ID,而非调用方自述字符串)。
|
package/README.en.md
CHANGED
|
@@ -118,7 +118,7 @@ flowchart TB
|
|
|
118
118
|
Plugin["plugins/carlos-flow-trigger.js<br/>chat.message hook"]
|
|
119
119
|
end
|
|
120
120
|
|
|
121
|
-
subgraph Core["Core MCP Server (src/index.js) —
|
|
121
|
+
subgraph Core["Core MCP Server (src/index.js) — 19 tools"]
|
|
122
122
|
Protocol["flow_protocol"]
|
|
123
123
|
Submit["flow_submit_requirement"]
|
|
124
124
|
Dispatch["flow_claim / flow_dispatch"]
|
|
@@ -158,7 +158,7 @@ flowchart TB
|
|
|
158
158
|
|-------|----------|----------------|-------------------|
|
|
159
159
|
| **Host adapter** | `ghost.json` / `plugins/` / `templates/` | Discovery, launch, config, lifecycle | ⚠️ The **only** platform-specific layer |
|
|
160
160
|
| **Client** | `client/carlos.js` / `bridge/` | CLI, trigger check, Bridge daemon | Bridge is Cindy-only |
|
|
161
|
-
| **Protocol** | `src/index.js` |
|
|
161
|
+
| **Protocol** | `src/index.js` | 19 MCP tools + validation + gate semantics | ✅ Zero coupling, pure standard MCP |
|
|
162
162
|
| **Engine** | `src/trigger.js` / `src/card.js` / `src/state.js` | Trigger scoring, card validation, state/audit | ✅ Zero coupling, pure JS, no deps |
|
|
163
163
|
| **Persistence** | `~/.carlos-flow/` | State, audit chain, snapshots, trigger history | ✅ Cross-platform path convention |
|
|
164
164
|
|
|
@@ -277,7 +277,7 @@ node client/carlos.js flow_verdict '{"sessionId":"demo","verdict":"PASS","notes"
|
|
|
277
277
|
|
|
278
278
|
---
|
|
279
279
|
|
|
280
|
-
## 🔧 MCP Tool Reference (
|
|
280
|
+
## 🔧 MCP Tool Reference (19 tools)
|
|
281
281
|
|
|
282
282
|
| Tool | Purpose | Key constraint |
|
|
283
283
|
|------|---------|----------------|
|
|
@@ -286,18 +286,23 @@ node client/carlos.js flow_verdict '{"sessionId":"demo","verdict":"PASS","notes"
|
|
|
286
286
|
| `flow_submit_requirement` | Submit / replace the task card | Required fields enforced per risk tier; fake fillers rejected |
|
|
287
287
|
| `flow_claim` | Claim a dispatch slot (executor / auditor) | Rejected while the activation gate is open |
|
|
288
288
|
| `flow_dispatch` | Dispatch a sub-agent per the four-part contract | Auto-snapshots files in scope before dispatch |
|
|
289
|
+
| `flow_audit_axes` | **Dispatch dual-axis audit** (Standards / Spec) | Generates two parallel audit prompts, read-only |
|
|
290
|
+
| `flow_audit_submit` | **Submit one axis's verdict** | Bound to the current `card_ts`; WARN does not hard-block; same axis can be resubmitted |
|
|
291
|
+
| `flow_audit_guard` | **Dual-axis gate self-check** | Same criteria as the gate inside `flow_verdict` |
|
|
289
292
|
| `flow_save_result` | Save a sub-agent's result | — |
|
|
290
293
|
| `flow_run_verify` | **Really execute** `verify.cmd` | Returns exitCode / stdout / stderr + `output_hash` |
|
|
291
294
|
| `flow_falsify` | **Negative control**: run `verify.cmd` pre-change (must fail) and post-change (must pass) | Vacuous tests (`|| true`) rejected; required before PASS |
|
|
292
295
|
| `flow_check_scope` | Check whether files are in scope | Empty scope → fail-closed, everything out of scope |
|
|
293
|
-
| `flow_verdict` | Record verdict PASS / DIRECTION / LOCAL | No PASS without dispatch
|
|
294
|
-
| `flow_status` | Query gate state | Exposes `activation_pending` / `verify_passed` |
|
|
296
|
+
| `flow_verdict` | Record verdict PASS / DIRECTION / LOCAL | No PASS without dispatch / passing verification / passing negative control / **both audit axes**; any axis FAIL blocks PASS |
|
|
297
|
+
| `flow_status` | Query gate state | Exposes `activation_pending` / `verify_passed` / `audit_axes` / `axes_ready` |
|
|
295
298
|
| `flow_audit` | Read the audit stream | Includes 6 activation-related event kinds |
|
|
296
299
|
| `flow_diff_hunks` | Parse `git diff -U0` hunk ranges | — |
|
|
297
300
|
| `flow_bypass` | Toggle bypass mode | Requires `confirmed=true`; auto-cleared on dispatch |
|
|
298
301
|
| `flow_revert_plan` | Generate an atomic restore plan | Returns a plan only, never executes |
|
|
299
302
|
| `flow_trigger_check` | Smart trigger check | Activates on success; honestly reports score otherwise |
|
|
300
303
|
|
|
304
|
+
> **Dual-axis review** (anti-false-closure #6): before `flow_verdict` records PASS, run `flow_audit_axes` to dispatch the Standards axis (does it follow repo conventions / any code smells) and the Spec axis (does it faithfully implement acceptance). Each axis gathers evidence independently via sub-agents, then `flow_audit_submit` records the verdict. The gate sits **after** the negative control and is the last one before PASS is written; both axes are bound to the current `card_ts` (a previous card's audit cannot impersonate a new one), any FAIL hard-blocks, while WARN (code smells and other judgement calls) is annotated but allowed.
|
|
305
|
+
|
|
301
306
|
---
|
|
302
307
|
|
|
303
308
|
## ⚙️ Configuration
|
package/README.md
CHANGED
|
@@ -123,7 +123,7 @@ flowchart TB
|
|
|
123
123
|
Plugin["plugins/carlos-flow-trigger.js<br/>chat.message 钩子"]
|
|
124
124
|
end
|
|
125
125
|
|
|
126
|
-
subgraph Core["核心 MCP Server (src/index.js) —
|
|
126
|
+
subgraph Core["核心 MCP Server (src/index.js) — 19 个工具"]
|
|
127
127
|
Protocol["flow_protocol"]
|
|
128
128
|
Submit["flow_submit_requirement"]
|
|
129
129
|
Dispatch["flow_claim / flow_dispatch"]
|
|
@@ -283,7 +283,7 @@ node client/carlos.js flow_verdict '{"sessionId":"demo","verdict":"PASS","notes"
|
|
|
283
283
|
|
|
284
284
|
---
|
|
285
285
|
|
|
286
|
-
## 🔧 MCP 工具参考(
|
|
286
|
+
## 🔧 MCP 工具参考(19 个)
|
|
287
287
|
|
|
288
288
|
| 工具 | 作用 | 关键约束 |
|
|
289
289
|
|------|------|---------|
|
|
@@ -292,18 +292,23 @@ node client/carlos.js flow_verdict '{"sessionId":"demo","verdict":"PASS","notes"
|
|
|
292
292
|
| `flow_submit_requirement` | 提交/替换任务卡 | 按风险档强制必填项;伪填充被拒 |
|
|
293
293
|
| `flow_claim` | 领取派发名额(executor / auditor) | 激活闸门未解时拒绝 |
|
|
294
294
|
| `flow_dispatch` | 按四段合同派发子 Agent | 派发前自动快照 scope 内文件 |
|
|
295
|
+
| `flow_audit_axes` | **派发双轴审计**(Standards / Spec) | 生成两段并行审计 prompt,只读不改 |
|
|
296
|
+
| `flow_audit_submit` | **提交某一轴结论** | 按 `card_ts` 绑定当前卡;WARN 不硬拦;同轴可覆盖 |
|
|
297
|
+
| `flow_audit_guard` | **两轴门禁自查** | 与 `flow_verdict` 内的门禁同口径 |
|
|
295
298
|
| `flow_save_result` | 保存子 Agent 执行结果 | — |
|
|
296
299
|
| `flow_run_verify` | **真实执行** `verify.cmd` | 返回 exitCode / stdout / stderr + `output_hash` |
|
|
297
300
|
| `flow_falsify` | **负对照**:改动前跑 verify.cmd 必须失败、改动后必须通过 | 空测试(`|| true`)会被拒;记 PASS 前必做 |
|
|
298
301
|
| `flow_check_scope` | 检查文件是否越界 | 空 scope → fail-closed 全部越界 |
|
|
299
|
-
| `flow_verdict` | 记录裁定 PASS / DIRECTION / LOCAL |
|
|
300
|
-
| `flow_status` | 查询门禁状态 | 暴露 `activation_pending` / `verify_passed` |
|
|
302
|
+
| `flow_verdict` | 记录裁定 PASS / DIRECTION / LOCAL | 未派发 / 验证未过 / 负对照未过 / **双轴未齐**均不许 PASS;任一轴 FAIL 不许 PASS |
|
|
303
|
+
| `flow_status` | 查询门禁状态 | 暴露 `activation_pending` / `verify_passed` / `audit_axes` / `axes_ready` |
|
|
301
304
|
| `flow_audit` | 读取审计流水 | 含 6 类激活相关事件 |
|
|
302
305
|
| `flow_diff_hunks` | 解析 `git diff -U0` 的 hunk 范围 | — |
|
|
303
306
|
| `flow_bypass` | 开关免检模式 | 需 `confirmed=true`;派发自动清零 |
|
|
304
307
|
| `flow_revert_plan` | 生成原子还原计划 | 只返回计划,不自动执行 |
|
|
305
308
|
| `flow_trigger_check` | 智能触发检查 | 达标即实际激活;未达标如实返回评分 |
|
|
306
309
|
|
|
310
|
+
> **双轴审查**(防假闭环之六):`flow_verdict` 落 PASS 前,必须先 `flow_audit_axes` 派发 Standards(合不合规范 + 坏味道)与 Spec(忠不忠实实现验收)两轴,由 subagent 独立取证后 `flow_audit_submit` 提交。门禁位于负对照**之后**,是 PASS 落定前的最后一道;两轴证据都绑定当前 `card_ts`(旧卡审查不能冒充新卡),任一轴 FAIL 硬拦,WARN 只标注不拦。
|
|
311
|
+
|
|
307
312
|
---
|
|
308
313
|
|
|
309
314
|
## ⚙️ 配置
|
package/README.zh.md
CHANGED
|
@@ -123,7 +123,7 @@ flowchart TB
|
|
|
123
123
|
Plugin["plugins/carlos-flow-trigger.js<br/>chat.message 钩子"]
|
|
124
124
|
end
|
|
125
125
|
|
|
126
|
-
subgraph Core["核心 MCP Server (src/index.js) —
|
|
126
|
+
subgraph Core["核心 MCP Server (src/index.js) — 19 个工具"]
|
|
127
127
|
Protocol["flow_protocol"]
|
|
128
128
|
Submit["flow_submit_requirement"]
|
|
129
129
|
Dispatch["flow_claim / flow_dispatch"]
|
|
@@ -283,7 +283,7 @@ node client/carlos.js flow_verdict '{"sessionId":"demo","verdict":"PASS","notes"
|
|
|
283
283
|
|
|
284
284
|
---
|
|
285
285
|
|
|
286
|
-
## 🔧 MCP 工具参考(
|
|
286
|
+
## 🔧 MCP 工具参考(19 个)
|
|
287
287
|
|
|
288
288
|
| 工具 | 作用 | 关键约束 |
|
|
289
289
|
|------|------|---------|
|
|
@@ -292,18 +292,23 @@ node client/carlos.js flow_verdict '{"sessionId":"demo","verdict":"PASS","notes"
|
|
|
292
292
|
| `flow_submit_requirement` | 提交/替换任务卡 | 按风险档强制必填项;伪填充被拒 |
|
|
293
293
|
| `flow_claim` | 领取派发名额(executor / auditor) | 激活闸门未解时拒绝 |
|
|
294
294
|
| `flow_dispatch` | 按四段合同派发子 Agent | 派发前自动快照 scope 内文件 |
|
|
295
|
+
| `flow_audit_axes` | **派发双轴审计**(Standards / Spec) | 生成两段并行审计 prompt,只读不改 |
|
|
296
|
+
| `flow_audit_submit` | **提交某一轴结论** | 按 `card_ts` 绑定当前卡;WARN 不硬拦;同轴可覆盖 |
|
|
297
|
+
| `flow_audit_guard` | **两轴门禁自查** | 与 `flow_verdict` 内的门禁同口径 |
|
|
295
298
|
| `flow_save_result` | 保存子 Agent 执行结果 | — |
|
|
296
299
|
| `flow_run_verify` | **真实执行** `verify.cmd` | 返回 exitCode / stdout / stderr + `output_hash` |
|
|
297
300
|
| `flow_falsify` | **负对照**:改动前跑 verify.cmd 必须失败、改动后必须通过 | 空测试(`|| true`)会被拒;记 PASS 前必做 |
|
|
298
301
|
| `flow_check_scope` | 检查文件是否越界 | 空 scope → fail-closed 全部越界 |
|
|
299
|
-
| `flow_verdict` | 记录裁定 PASS / DIRECTION / LOCAL |
|
|
300
|
-
| `flow_status` | 查询门禁状态 | 暴露 `activation_pending` / `verify_passed` |
|
|
302
|
+
| `flow_verdict` | 记录裁定 PASS / DIRECTION / LOCAL | 未派发 / 验证未过 / 负对照未过 / **双轴未齐**均不许 PASS;任一轴 FAIL 不许 PASS |
|
|
303
|
+
| `flow_status` | 查询门禁状态 | 暴露 `activation_pending` / `verify_passed` / `audit_axes` / `axes_ready` |
|
|
301
304
|
| `flow_audit` | 读取审计流水 | 含 6 类激活相关事件 |
|
|
302
305
|
| `flow_diff_hunks` | 解析 `git diff -U0` 的 hunk 范围 | — |
|
|
303
306
|
| `flow_bypass` | 开关免检模式 | 需 `confirmed=true`;派发自动清零 |
|
|
304
307
|
| `flow_revert_plan` | 生成原子还原计划 | 只返回计划,不自动执行 |
|
|
305
308
|
| `flow_trigger_check` | 智能触发检查 | 达标即实际激活;未达标如实返回评分 |
|
|
306
309
|
|
|
310
|
+
> **双轴审查**(防假闭环之六):`flow_verdict` 落 PASS 前,必须先 `flow_audit_axes` 派发 Standards(合不合规范 + 坏味道)与 Spec(忠不忠实实现验收)两轴,由 subagent 独立取证后 `flow_audit_submit` 提交。门禁位于负对照**之后**,是 PASS 落定前的最后一道;两轴证据都绑定当前 `card_ts`(旧卡审查不能冒充新卡),任一轴 FAIL 硬拦,WARN 只标注不拦。
|
|
311
|
+
|
|
307
312
|
---
|
|
308
313
|
|
|
309
314
|
## ⚙️ 配置
|
package/TRIGGER_GUIDE.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Carlos Flow 智能触发引擎使用指南
|
|
2
2
|
|
|
3
|
-
> **版本**: v2.
|
|
3
|
+
> **版本**: v2.9.0
|
|
4
4
|
> **适用**:`carlos-flow` 单包架构(2.6.0+)
|
|
5
5
|
> **代码位置**:`src/trigger.js`(零外部依赖的纯 JavaScript 实现)
|
|
6
6
|
|
|
@@ -779,5 +779,5 @@ MIT License
|
|
|
779
779
|
|
|
780
780
|
---
|
|
781
781
|
|
|
782
|
-
**版本**: v2.
|
|
783
|
-
**更新日期**: 2026-11-
|
|
782
|
+
**版本**: v2.9.0
|
|
783
|
+
**更新日期**: 2026-11-12
|
package/ghost.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"name": "Carlos 工作流",
|
|
6
6
|
"description": "机械门禁 MCP:留痕/派发/裁定/审计/快照/免检/还原。自动管理 Bridge 后台常驻,首次调用 ~3-5s,后续 ~1s。",
|
|
7
7
|
"whenToUse": "需要走 Carlos 工作流门禁时使用:留痕/派发/裁定/审计/快照/免检/还原",
|
|
8
|
-
"version": "2.
|
|
8
|
+
"version": "2.9.0",
|
|
9
9
|
"kind": "mcp",
|
|
10
10
|
"entry": "client/carlos.js",
|
|
11
11
|
"command": "门禁",
|
|
@@ -196,6 +196,77 @@
|
|
|
196
196
|
]
|
|
197
197
|
}
|
|
198
198
|
},
|
|
199
|
+
{
|
|
200
|
+
"name": "flow_audit_axes",
|
|
201
|
+
"description": "派发两个并行审计 subagent(Standards 轴 / Spec 轴),生成两段审计合同 prompt。executor 改动通过 flow_run_verify 与负对照后、落 PASS 裁定前必须先调用本工具。",
|
|
202
|
+
"parameters": {
|
|
203
|
+
"type": "object",
|
|
204
|
+
"properties": {
|
|
205
|
+
"sessionId": {
|
|
206
|
+
"type": "string",
|
|
207
|
+
"description": "会话 ID"
|
|
208
|
+
},
|
|
209
|
+
"cwd": {
|
|
210
|
+
"type": "string",
|
|
211
|
+
"description": "仓库工作目录,默认 process.cwd()"
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
},
|
|
216
|
+
{
|
|
217
|
+
"name": "flow_audit_submit",
|
|
218
|
+
"description": "保存某一审计轴(standards|spec)的结论与证据到会话状态。PASS 裁定前必须两轴都提交,且各自绑定的 card_ts 与当前卡一致。同轴可重复提交(后者覆盖)。",
|
|
219
|
+
"parameters": {
|
|
220
|
+
"type": "object",
|
|
221
|
+
"properties": {
|
|
222
|
+
"sessionId": {
|
|
223
|
+
"type": "string",
|
|
224
|
+
"description": "会话 ID"
|
|
225
|
+
},
|
|
226
|
+
"axis": {
|
|
227
|
+
"type": "string",
|
|
228
|
+
"enum": [
|
|
229
|
+
"standards",
|
|
230
|
+
"spec"
|
|
231
|
+
],
|
|
232
|
+
"description": "审计轴"
|
|
233
|
+
},
|
|
234
|
+
"verdict": {
|
|
235
|
+
"type": "string",
|
|
236
|
+
"enum": [
|
|
237
|
+
"PASS",
|
|
238
|
+
"FAIL",
|
|
239
|
+
"WARN"
|
|
240
|
+
],
|
|
241
|
+
"description": "轴判定;WARN=坏味道等 judgement call,不硬拦"
|
|
242
|
+
},
|
|
243
|
+
"findings": {
|
|
244
|
+
"type": "array",
|
|
245
|
+
"items": {
|
|
246
|
+
"type": "string"
|
|
247
|
+
},
|
|
248
|
+
"description": "每条含 file:line 或证据"
|
|
249
|
+
},
|
|
250
|
+
"evidence": {
|
|
251
|
+
"type": "string",
|
|
252
|
+
"description": "实跑命令输出 / diff 摘录"
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
},
|
|
257
|
+
{
|
|
258
|
+
"name": "flow_audit_guard",
|
|
259
|
+
"description": "校验两轴是否已通过且证据齐全(与 flow_verdict 内的双轴门禁同口径)。主 Agent 落 PASS 前可主动自查;flow_verdict 不受此调用影响,仍会再拦一道。",
|
|
260
|
+
"parameters": {
|
|
261
|
+
"type": "object",
|
|
262
|
+
"properties": {
|
|
263
|
+
"sessionId": {
|
|
264
|
+
"type": "string",
|
|
265
|
+
"description": "会话 ID"
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
},
|
|
199
270
|
{
|
|
200
271
|
"name": "flow_verdict",
|
|
201
272
|
"description": "记录 auditor 的裁定结果(PASS / DIRECTION / LOCAL)。只有 PASS 会把 completed_ok 置为 true。",
|
package/package.json
CHANGED
|
@@ -71,8 +71,8 @@ try {
|
|
|
71
71
|
const hasValidation = /validateToolArgs\(/.test(src);
|
|
72
72
|
if (hasValidation) pass("CallTool handler 调用了 validateToolArgs(参数校验未丢失)");
|
|
73
73
|
else fail("CallTool handler 没有调用 validateToolArgs —— 参数校验可能已丢失");
|
|
74
|
-
if (declared.length ===
|
|
75
|
-
else fail(`TOOLS 声明了 ${declared.length} 个工具(期望
|
|
74
|
+
if (declared.length === 19) pass(`TOOLS 声明 ${declared.length} 个工具`);
|
|
75
|
+
else fail(`TOOLS 声明了 ${declared.length} 个工具(期望 19)`);
|
|
76
76
|
} catch (e) {
|
|
77
77
|
fail(`读取 src/index.js 失败:${e.message}`);
|
|
78
78
|
}
|
package/src/dispatch.js
CHANGED
|
@@ -7,36 +7,66 @@ import { RUNS_DIR, sanitizeId } from "./state.js";
|
|
|
7
7
|
|
|
8
8
|
export const MAX_DISPATCH = 5;
|
|
9
9
|
|
|
10
|
+
// Dispatcher 配置:双轴审查 prompt 配置表。
|
|
11
|
+
// 新增轴只改这里,不动 buildContractPrompt 的函数体(避免分支膨胀)。
|
|
12
|
+
const AXIS_PROMPTS = {
|
|
13
|
+
standards: {
|
|
14
|
+
objective: "审计:仓库代码规范与坏味道",
|
|
15
|
+
format: "判定(通过/违规/坏味道) / 规范依据 / file:line 证据 / 是否硬违规",
|
|
16
|
+
guidance: "对照仓库规范文件 + Fowler 坏味道基线,只读取证 git diff,不轻信 executor 自述",
|
|
17
|
+
boundaries: "零文件改动,只读取证",
|
|
18
|
+
},
|
|
19
|
+
spec: {
|
|
20
|
+
objective: "审计:任务卡验收标准忠实度",
|
|
21
|
+
format: "判定(通过/未实现验收/越界) / 卡上的验收标准逐条核对 / 越界改动",
|
|
22
|
+
guidance: "对照任务卡 goal/acceptance/scope,跑 flow_check_scope 校验越界,独立跑验证命令取证",
|
|
23
|
+
boundaries: "零文件改动,只读取证",
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
|
|
10
27
|
// role ∈ "executor" | "auditor"
|
|
11
|
-
|
|
28
|
+
// axis ∈ undefined(默认四段合同) | "standards" | "spec"(双轴审计模式)
|
|
29
|
+
export function buildContractPrompt(role, card, extra, axis) {
|
|
12
30
|
const isAuditor = role === "auditor";
|
|
13
31
|
const isExecutor = role === "executor";
|
|
14
32
|
if (!isAuditor && !isExecutor) {
|
|
15
33
|
throw new Error(`buildContractPrompt: 未知 role "${role}"(仅支持 executor/auditor)`);
|
|
16
34
|
}
|
|
17
|
-
const c = card && typeof card === "object" ? card : {};
|
|
18
35
|
|
|
19
|
-
|
|
36
|
+
// 模式注入:指定了 axis 就走配置表(覆盖式),否则走原有逻辑
|
|
37
|
+
let objective, outputFormat, toolGuidance, taskBoundaries;
|
|
20
38
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
39
|
+
if (axis && AXIS_PROMPTS[axis]) {
|
|
40
|
+
const cfg = AXIS_PROMPTS[axis];
|
|
41
|
+
objective = `objective: ${cfg.objective}`;
|
|
42
|
+
outputFormat = `output format: ${cfg.format}`;
|
|
43
|
+
toolGuidance = `tool guidance: ${cfg.guidance}`;
|
|
44
|
+
taskBoundaries = `task boundaries: ${cfg.boundaries}`;
|
|
45
|
+
} else {
|
|
46
|
+
const c = card && typeof card === "object" ? card : {};
|
|
24
47
|
|
|
25
|
-
|
|
26
|
-
let guidance = verifyCmd || "未指定验证命令,用只读取证";
|
|
27
|
-
if (isAuditor) {
|
|
28
|
-
guidance += ";独立跑 git status --porcelain 与 git diff 取证,不轻信 executor 自述";
|
|
29
|
-
}
|
|
30
|
-
const toolGuidance = `tool guidance: ${guidance}`;
|
|
48
|
+
objective = `objective: ${c.goal || ""}`;
|
|
31
49
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
50
|
+
outputFormat = isExecutor
|
|
51
|
+
? "output format: 报告 ≤300 字,四段:结论(一句话,做完/没做完) / 改动(file:line 逐条列出,没改写“无”) / 验证(命令 → 结果摘要,未跑写“未验证”) / 遗留风险"
|
|
52
|
+
: "output format: 报告 ≤200 字,五段:裁定(通过/不通过) / 失败类型(操作错误/环境问题/卡片问题) / scope 标注(是否越界改动) / 证据(file:line 或实跑命令输出) / 附注";
|
|
53
|
+
|
|
54
|
+
const verifyCmd = c.verify && c.verify.cmd ? String(c.verify.cmd) : "";
|
|
55
|
+
let guidance = verifyCmd || "未指定验证命令,用只读取证";
|
|
56
|
+
if (isAuditor) {
|
|
57
|
+
guidance += ";独立跑 git status --porcelain 与 git diff 取证,不轻信 executor 自述";
|
|
58
|
+
}
|
|
59
|
+
toolGuidance = `tool guidance: ${guidance}`;
|
|
60
|
+
|
|
61
|
+
const scopeArr = Array.isArray(c.scope) ? c.scope.map(String) : [];
|
|
62
|
+
let boundaries;
|
|
63
|
+
if (isAuditor) {
|
|
64
|
+
boundaries = "零文件改动,只读取证";
|
|
65
|
+
} else {
|
|
66
|
+
boundaries = scopeArr.length > 0 ? scopeArr.join(", ") : "无文件可改,只读任务";
|
|
67
|
+
}
|
|
68
|
+
taskBoundaries = `task boundaries: ${boundaries}`;
|
|
38
69
|
}
|
|
39
|
-
const taskBoundaries = `task boundaries: ${boundaries}`;
|
|
40
70
|
|
|
41
71
|
let prompt = [objective, outputFormat, toolGuidance, taskBoundaries].join("\n");
|
|
42
72
|
if (extra && String(extra) !== "") {
|
package/src/index.js
CHANGED
|
@@ -474,11 +474,104 @@ const TOOLS = [
|
|
|
474
474
|
},
|
|
475
475
|
|
|
476
476
|
// 5 -----------------------------------------------------------------------
|
|
477
|
+
{
|
|
478
|
+
name: "flow_audit_axes",
|
|
479
|
+
description:
|
|
480
|
+
"派发两个并行审计 subagent(Standards 轴 / Spec 轴),生成两段审计合同 prompt。" +
|
|
481
|
+
"executor 改动通过 flow_run_verify 与负对照后、落 PASS 裁定前必须先调用本工具。",
|
|
482
|
+
inputSchema: {
|
|
483
|
+
type: "object",
|
|
484
|
+
properties: {
|
|
485
|
+
sessionId: { type: "string", description: "会话 ID" },
|
|
486
|
+
cwd: { type: "string", description: "仓库工作目录,默认 process.cwd()" },
|
|
487
|
+
},
|
|
488
|
+
},
|
|
489
|
+
handler: async (args) => {
|
|
490
|
+
try {
|
|
491
|
+
const sid = args.sessionId || "unknown";
|
|
492
|
+
const state = loadState(sid);
|
|
493
|
+
if (!state.card) return fail("无卡,无法派发审计轴");
|
|
494
|
+
|
|
495
|
+
const cwd = args.cwd || process.cwd();
|
|
496
|
+
const res = { standards: null, spec: null };
|
|
497
|
+
for (const axis of ["standards", "spec"]) {
|
|
498
|
+
const prompt = buildContractPrompt("auditor", state.card, "", axis);
|
|
499
|
+
const { file } = writeDispatchPrompt(sid, "auditor", prompt, cwd);
|
|
500
|
+
res[axis] = { prompt, file };
|
|
501
|
+
}
|
|
502
|
+
return ok({ ok: true, ...res });
|
|
503
|
+
} catch (e) { return fail(String(e)); }
|
|
504
|
+
},
|
|
505
|
+
},
|
|
506
|
+
{
|
|
507
|
+
name: "flow_audit_submit",
|
|
508
|
+
description:
|
|
509
|
+
"保存某一审计轴(standards|spec)的结论与证据到会话状态。" +
|
|
510
|
+
"PASS 裁定前必须两轴都提交,且各自绑定的 card_ts 与当前卡一致。同轴可重复提交(后者覆盖)。",
|
|
511
|
+
inputSchema: {
|
|
512
|
+
type: "object",
|
|
513
|
+
properties: {
|
|
514
|
+
sessionId: { type: "string", description: "会话 ID" },
|
|
515
|
+
axis: { type: "string", enum: ["standards", "spec"], description: "审计轴" },
|
|
516
|
+
verdict: { type: "string", enum: ["PASS", "FAIL", "WARN"], description: "轴判定;WARN=坏味道等 judgement call,不硬拦" },
|
|
517
|
+
findings: { type: "array", items: { type: "string" }, description: "每条含 file:line 或证据" },
|
|
518
|
+
evidence: { type: "string", description: "实跑命令输出 / diff 摘录" },
|
|
519
|
+
},
|
|
520
|
+
},
|
|
521
|
+
handler: async (args) => {
|
|
522
|
+
try {
|
|
523
|
+
const sid = args.sessionId || "unknown";
|
|
524
|
+
const state = loadState(sid);
|
|
525
|
+
if (!state.card) return fail("无卡,无法提交审计轴结论");
|
|
526
|
+
state.audit_axes[args.axis] = {
|
|
527
|
+
verdict: args.verdict,
|
|
528
|
+
findings: args.findings,
|
|
529
|
+
evidence: args.evidence,
|
|
530
|
+
// 绑定提交时的卡片:换卡后该轴证据立即失效,必须重审
|
|
531
|
+
card_ts: state.card_ts,
|
|
532
|
+
ts: Date.now(),
|
|
533
|
+
};
|
|
534
|
+
state.audit_axes_ts = Date.now();
|
|
535
|
+
saveState(sid, state);
|
|
536
|
+
const stored = [state.audit_axes.standards, state.audit_axes.spec].filter(Boolean).length;
|
|
537
|
+
return ok({ ok: true, axis: args.axis, stored_axes_count: stored });
|
|
538
|
+
} catch (e) { return fail(String(e)); }
|
|
539
|
+
},
|
|
540
|
+
},
|
|
541
|
+
{
|
|
542
|
+
name: "flow_audit_guard",
|
|
543
|
+
description:
|
|
544
|
+
"校验两轴是否已通过且证据齐全(与 flow_verdict 内的双轴门禁同口径)。" +
|
|
545
|
+
"主 Agent 落 PASS 前可主动自查;flow_verdict 不受此调用影响,仍会再拦一道。",
|
|
546
|
+
inputSchema: {
|
|
547
|
+
type: "object",
|
|
548
|
+
properties: { sessionId: { type: "string", description: "会话 ID" } },
|
|
549
|
+
},
|
|
550
|
+
handler: async (args) => {
|
|
551
|
+
try {
|
|
552
|
+
const sid = args.sessionId || "unknown";
|
|
553
|
+
const state = loadState(sid);
|
|
554
|
+
const ax = state.audit_axes;
|
|
555
|
+
// 口径与 flow_verdict 的双轴门禁完全一致:
|
|
556
|
+
// 两轴都有 verdict(不能缺失/空)、card_ts 与当前卡一致、且无轴 FAIL。
|
|
557
|
+
const axisOk = (a) => ax && ax[a] && ax[a].verdict && ax[a].card_ts === state.card_ts;
|
|
558
|
+
if (!axisOk("standards") || !axisOk("spec")) {
|
|
559
|
+
return fail("两轴审计未齐或证据失效(需 flow_audit_axes 派发 + flow_audit_submit 两轴且 card_ts 与当前卡一致)");
|
|
560
|
+
}
|
|
561
|
+
if (ax.standards.verdict === "FAIL" || ax.spec.verdict === "FAIL") {
|
|
562
|
+
return fail("两轴中至少一轴 FAIL(standards=" + ax.standards.verdict +
|
|
563
|
+
", spec=" + ax.spec.verdict + ")。");
|
|
564
|
+
}
|
|
565
|
+
return ok({ ok: true });
|
|
566
|
+
} catch (e) { return fail(String(e)); }
|
|
567
|
+
},
|
|
568
|
+
},
|
|
477
569
|
{
|
|
478
570
|
name: "flow_verdict",
|
|
479
571
|
description:
|
|
480
572
|
"记录 auditor 的裁定结果(PASS / DIRECTION / LOCAL)。只有 PASS 会把 completed_ok 置为 true。" +
|
|
481
|
-
"DIRECTION 表示方向对但需返工,LOCAL 表示问题局限在局部。在向用户汇报完成前必须先落裁定,否则视为未复核。"
|
|
573
|
+
"DIRECTION 表示方向对但需返工,LOCAL 表示问题局限在局部。在向用户汇报完成前必须先落裁定,否则视为未复核。" +
|
|
574
|
+
"【双轴门禁】记 PASS 前必须先 flow_audit_axes 派发 Standards/Spec 两轴、由 subagent 取证后 flow_audit_submit 提交两轴结论;任一轴 FAIL 会被拒,WARN 不硬拦。",
|
|
482
575
|
inputSchema: {
|
|
483
576
|
type: "object",
|
|
484
577
|
properties: {
|
|
@@ -638,6 +731,46 @@ const TOOLS = [
|
|
|
638
731
|
return fail("已有的验证结果与负对照的运行结果不一致,不能记录 PASS 裁定。" +
|
|
639
732
|
"请重新调用 flow_falsify(它会把改动后的运行写为验证证据)。");
|
|
640
733
|
}
|
|
734
|
+
|
|
735
|
+
// 防假闭环之六:双轴审查门禁。
|
|
736
|
+
//
|
|
737
|
+
// 位置说明(重要):必须放在负对照**之后**。语义顺序是
|
|
738
|
+
// 「先证实验证有效 → 再证审查到位」,六道门各自独立、互不掩盖。
|
|
739
|
+
// 若前置,会让「未验证」「未派发」「未做负对照」这些更基础的问题被
|
|
740
|
+
// 双轴错误信息掩盖,调用方拿到的是不可操作的下一步。
|
|
741
|
+
//
|
|
742
|
+
// 判定口径:
|
|
743
|
+
// · 两轴都必须有结论,且 card_ts 与当前卡一致(防旧卡审查结果冒充新卡,
|
|
744
|
+
// 也防两轴跨卡拼接:卡A的 standards + 卡B的 spec 不算数);
|
|
745
|
+
// · FAIL 硬拦(规范硬违规 / 未实现验收);
|
|
746
|
+
// · WARN 不硬拦(坏味道是 judgement call),由主 Agent 读 audit_axes 后标注。
|
|
747
|
+
const ax = state.audit_axes;
|
|
748
|
+
const axisOk = (a) => ax && ax[a] && ax[a].verdict && ax[a].card_ts === state.card_ts;
|
|
749
|
+
const hasStandards = axisOk("standards");
|
|
750
|
+
const hasSpec = axisOk("spec");
|
|
751
|
+
if (!hasStandards || !hasSpec) {
|
|
752
|
+
audit("decision", sessionId, {
|
|
753
|
+
kind: "verdict_denied",
|
|
754
|
+
reason: "两轴审查未齐",
|
|
755
|
+
standards: ax && ax.standards ? ax.standards.verdict : null,
|
|
756
|
+
spec: ax && ax.spec ? ax.spec.verdict : null,
|
|
757
|
+
card_ts: state.card_ts,
|
|
758
|
+
});
|
|
759
|
+
return fail("两轴审查未齐,不能记录 PASS 裁定。请先 flow_audit_axes 派发两轴、" +
|
|
760
|
+
"由 subagent 取证后分别 flow_audit_submit 提交 Standards 与 Spec 两轴结论,再记录裁定。");
|
|
761
|
+
}
|
|
762
|
+
const standardsFail = ax.standards.verdict === "FAIL";
|
|
763
|
+
const specFail = ax.spec.verdict === "FAIL";
|
|
764
|
+
if (standardsFail || specFail) {
|
|
765
|
+
audit("decision", sessionId, {
|
|
766
|
+
kind: "verdict_denied",
|
|
767
|
+
reason: "有轴不通过",
|
|
768
|
+
standards: ax.standards.verdict,
|
|
769
|
+
spec: ax.spec.verdict,
|
|
770
|
+
});
|
|
771
|
+
return fail("PASS 被拒:两轴中至少一轴 FAIL(standards=" + ax.standards.verdict +
|
|
772
|
+
", spec=" + ax.spec.verdict + ")。请修复后重跑验证与审计。");
|
|
773
|
+
}
|
|
641
774
|
}
|
|
642
775
|
|
|
643
776
|
const findings = [];
|
|
@@ -697,6 +830,16 @@ const TOOLS = [
|
|
|
697
830
|
card: state.card,
|
|
698
831
|
card_ts: state.card_ts,
|
|
699
832
|
activation_pending: Array.isArray(state.activation_pending) ? state.activation_pending : [],
|
|
833
|
+
// 双轴审查证据:主 Agent 落 PASS 前可读它确认两轴状态与 card_ts 绑定。
|
|
834
|
+
// axes_ready = 两轴都有结论且 card_ts 与当前卡一致且无轴 FAIL。
|
|
835
|
+
audit_axes: state.audit_axes,
|
|
836
|
+
audit_axes_ts: state.audit_axes_ts,
|
|
837
|
+
axes_ready: (() => {
|
|
838
|
+
const ax = state.audit_axes;
|
|
839
|
+
const axisOk = (x) => ax && ax[x] && ax[x].verdict && ax[x].card_ts === state.card_ts;
|
|
840
|
+
return axisOk("standards") && axisOk("spec") &&
|
|
841
|
+
ax.standards.verdict !== "FAIL" && ax.spec.verdict !== "FAIL";
|
|
842
|
+
})(),
|
|
700
843
|
};
|
|
701
844
|
if (state.card && !state.verdict) result.unreviewed = true;
|
|
702
845
|
return ok(result);
|
package/src/state.js
CHANGED
|
@@ -93,7 +93,7 @@ export function sanitizeId(s) {
|
|
|
93
93
|
|
|
94
94
|
// 当前状态文件结构版本号。
|
|
95
95
|
// 改动 defaultState() 的**字段结构**时,必须 +1 并在 migrate() 里加一条迁移。
|
|
96
|
-
export const CURRENT_SCHEMA_VERSION =
|
|
96
|
+
export const CURRENT_SCHEMA_VERSION = 3;
|
|
97
97
|
|
|
98
98
|
/**
|
|
99
99
|
* 迁移旧版本的状态文件。
|
|
@@ -107,6 +107,10 @@ export const CURRENT_SCHEMA_VERSION = 2;
|
|
|
107
107
|
*
|
|
108
108
|
* v1 → v2:新增 last_falsify(负对照记录)。
|
|
109
109
|
* · 旧状态没有这个字段 → 补 null(表示「还没做负对照」,裁定会拒绝 PASS)
|
|
110
|
+
*
|
|
111
|
+
* v2 → v3:新增 audit_axes / audit_axes_ts(双轴审查证据)。
|
|
112
|
+
* · 旧状态没有这两个字段 → 补默认结构(两轴均为 null = 尚未审查,裁定会拒绝 PASS)
|
|
113
|
+
* · audit_axes 存在但结构不全时也在此补齐,避免读到半初始化对象
|
|
110
114
|
*/
|
|
111
115
|
export function migrate(parsed) {
|
|
112
116
|
if (!parsed || typeof parsed !== "object") return parsed;
|
|
@@ -128,6 +132,20 @@ export function migrate(parsed) {
|
|
|
128
132
|
v = 2;
|
|
129
133
|
}
|
|
130
134
|
|
|
135
|
+
if (v < 3) {
|
|
136
|
+
// v2 → v3
|
|
137
|
+
if (!out.audit_axes || typeof out.audit_axes !== "object") {
|
|
138
|
+
out.audit_axes = { standards: null, spec: null };
|
|
139
|
+
} else {
|
|
140
|
+
out.audit_axes = {
|
|
141
|
+
standards: out.audit_axes.standards || null,
|
|
142
|
+
spec: out.audit_axes.spec || null,
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
if (typeof out.audit_axes_ts !== "number") out.audit_axes_ts = 0;
|
|
146
|
+
v = 3;
|
|
147
|
+
}
|
|
148
|
+
|
|
131
149
|
out.schemaVersion = CURRENT_SCHEMA_VERSION;
|
|
132
150
|
return out;
|
|
133
151
|
}
|
|
@@ -173,6 +191,16 @@ export function defaultState() {
|
|
|
173
191
|
// 负对照要求:改动前必须失败、改动后必须通过,才证明这个测试真的在测本次改动。
|
|
174
192
|
// null = 还没做负对照(此时 flow_verdict 拒绝 PASS)。
|
|
175
193
|
last_falsify: null,
|
|
194
|
+
// 双轴审查证据(flow_audit_submit 写入)。
|
|
195
|
+
// 结构:{ standards: {verdict,findings,evidence,card_ts,ts} | null, spec: {...} | null }
|
|
196
|
+
//
|
|
197
|
+
// 为什么按轴绑定 card_ts,而不是只用一个全局时间戳:
|
|
198
|
+
// 两轴是**分两次**提交的。卡A提交 standards → 换新卡B → 只补 spec,
|
|
199
|
+
// 此时全局时间戳已被刷新到卡B之后,单看时间戳会放行,而 standards
|
|
200
|
+
// 仍是卡A的结论 —— 「两轴跨卡拼接」。绑定 card_ts 后,换卡即两轴全失效。
|
|
201
|
+
audit_axes: { standards: null, spec: null },
|
|
202
|
+
// 两轴最后提交时间(审计链留痕用;不参与冒充校验,校验看 card_ts)。
|
|
203
|
+
audit_axes_ts: 0,
|
|
176
204
|
};
|
|
177
205
|
}
|
|
178
206
|
|