reasonweave 1.4.3 → 1.4.5
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/INSTALL.md +7 -6
- package/README.md +3 -2
- package/constitution.md +29 -9
- package/docs/CONSUMER-PROMPTS.md +47 -0
- package/docs/sop/01-installation-and-onboarding-sop.md +101 -0
- package/docs/sop/02-day-to-day-engineering-sop.md +115 -0
- package/docs/sop/03-handoffs-and-audit-sop.md +80 -0
- package/docs/sop/04-anti-orphan-governance-sop.md +57 -0
- package/docs/sop/README.md +22 -0
- package/group/architecture/adr/0017-three-state-verdict-runtime-fingerprinting-and-aef-2-discipline.md +105 -0
- package/group/architecture/adr/INDEX.md +1 -0
- package/package.json +2 -2
- package/units/handoffs/handoff-status.mjs +1 -0
- package/units/handoffs/handoff.mjs +3 -1
- package/units/review-gate/CHANGELOG.md +5 -0
- package/units/review-gate/VERSION.md +1 -1
- package/units/review-gate/clean-runner.mjs +24 -20
- package/units/review-gate/templates/pre-commit +84 -34
- package/units/review-gate/templates/scan.sh +16 -2
- package/units/spec-guard/core/mutation-runner.mjs +54 -26
- package/units/spec-guard/tests/spec-guard.test.mjs +19 -0
- package/units/worktree/CHANGELOG.md +6 -0
- package/units/worktree/VERSION.md +1 -1
- package/units/worktree/tests/worktree.test.mjs +57 -0
- package/units/worktree/worktree.mjs +20 -4
- package//344/275/277/347/224/250/350/257/264/346/230/216.md +5 -3
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
<!-- adr-template v1.0 · tier: frozen · source: ~/Documents/lab/adr/ -->
|
|
2
|
+
|
|
3
|
+
# ADR-0017: 三态裁决体系 (GO/NO-GO/BLOCKED)、宿主基座指纹与 AEF 2.0 研发纪律升维架构决策 (Three-State Verdict Protocol, Runtime Capability Fingerprinting & AEF 2.0 Engineering Discipline Invariant)
|
|
4
|
+
|
|
5
|
+
- **状态(Status)**:Accepted (🔒Frozen)
|
|
6
|
+
- **生效日期**:2026-11-26
|
|
7
|
+
- **决策人**:churze + Agent (AEF 架构委员会 · core/constitution/handoffs/playbook)
|
|
8
|
+
- **关联证据**:
|
|
9
|
+
- 宿主受限沙箱(无特权 Docker、seccomp 策略、macOS Seatbelt)拦截系统调用 `socketpair` / `fork` 导致 `pytest/preflight` 抛出 `E_ACCESSDENIED`,引发执行端 Agent 认知死锁案例
|
|
10
|
+
- Baton RBAC 权限拦截执行方越界 reject,但在二元(GO/NO-GO)模式下缺乏标准受阻呈报路径导致的长期挂起事故
|
|
11
|
+
- `constitution.md` 停留在 v1.0 与机件能力演进(ADR-0007 ~ ADR-0016)之间的体系性剪刀差
|
|
12
|
+
- **引擎版本**:`reasonweave` v1.4.3+ / `units/handoffs` v2.41.2+
|
|
13
|
+
- **关联契约**:[`constitution.md`](file:///Users/churze/Documents/lab/constitution.md) v2.0, [`units/handoffs/README.md`](file:///Users/churze/Documents/lab/units/handoffs/README.md)
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## 1. Context(背景与系统性矛盾)
|
|
18
|
+
|
|
19
|
+
随着 ReasonWeave 从单机辅助工具演进为覆盖异构多 Agent(Antigravity, WorkBuddy, Cursor, Claude Code, CI)的工程纪律机件,在真实复杂交付场景中暴露出了三大深层矛盾与制度死角:
|
|
20
|
+
|
|
21
|
+
### 1.1 二元裁决在宿主环境崩溃下的认知死锁(The Binary Verdict Trap)
|
|
22
|
+
- **现有设计**:AEF 宪法强调“实测是唯一准绳”,未通过测试严禁交付;Baton CLI 严格推行 RBAC 门禁,普通实现方(`to_lane: impl/worker`)严禁调用 `baton reject`(驳回权专属于发起方验收与独立审计方裁决)。
|
|
23
|
+
- **现实碰撞**:当测试环境本身发生底层故障(例如容器沙箱禁止 `socketpair`、缺系统共享库、缺设备依赖)导致测试套件启动阶段即崩溃时,实现方 Agent 既不能执行 `deliver`(违背实测律),又无法执行 `reject`(被 CLI 拦截),还不敢空手交付,导致 Agent 陷入“不敢交又退不回”的逻辑死锁(Catch-22),任务在 `forwarded` / `received` 态无限空转。
|
|
24
|
+
|
|
25
|
+
### 1.2 宿主环境探测的“静态假象”(Static Probe vs Dynamic Capability)
|
|
26
|
+
- 现有 `lab doctor` 与 `preflight` 只探查静态文件或命令是否存在(`node -v`, `git --version`),完全缺乏对**宿主底层动态系统调用与沙箱能力边界**(Syscall / IPC Capability:如 `AF_UNIX` 套接字、命名管道 FIFO、文件锁 `flock`、子进程派生)的探测。
|
|
27
|
+
- 当上游把任务派发至一个高度受限的沙箱时,测试运行器必然在启动时直接崩溃。
|
|
28
|
+
|
|
29
|
+
### 1.3 宪法与顶层方法论滞后(Constitutional Lag)
|
|
30
|
+
- `constitution.md` 自 2026-11-03 设立 1.0 版以来,仅收录 P1~P3、T1~T6、U1~U2 共 11 条早期原则。
|
|
31
|
+
- 过去 3 周内沉淀的 ADR-0007 至 ADR-0016(反未接线 L1~L3 垂直切片、密码学防伪凭据、Vibe 安全防抑噪、SDD RePPIT 闭环分级、全 CLI 契约律、微观原子技能零污染引擎等)全部分散在各子模块中,最高工程宪法缺乏收敛升维,导致研发纪律“头轻脚重”。
|
|
32
|
+
|
|
33
|
+
---
|
|
34
|
+
|
|
35
|
+
## 2. Decision(核心架构与纪律决策)
|
|
36
|
+
|
|
37
|
+
为彻底解决上述矛盾,确立 **AEF 2.0 研发纪律升维体系**,包含以下五大核心机制:
|
|
38
|
+
|
|
39
|
+
```
|
|
40
|
+
┌────────────────────────────────────────────────────────────────────────┐
|
|
41
|
+
│ AEF 2.0 Engineering Discipline Model │
|
|
42
|
+
├────────────────────────────────┬───────────────────────────────────────┤
|
|
43
|
+
│ 1. 三态裁决体系 (Three-State) │ GO (交付) / NO-GO (驳回) / BLOCKED (受阻) │
|
|
44
|
+
│ 确立受阻为一等公民 │ 终结“不敢交又退不回”的二元死锁 │
|
|
45
|
+
├────────────────────────────────┼───────────────────────────────────────┤
|
|
46
|
+
│ 2. 免责受阻呈报协议 (Blocked) │ 区分 E_ENV (环境故障) 与 E_LOGIC (缺陷) │
|
|
47
|
+
│ 实现方安全呈报通道 │ 强制 15 分钟内附带系统日志交付 BLOCKED │
|
|
48
|
+
├────────────────────────────────┼───────────────────────────────────────┤
|
|
49
|
+
│ 3. 宿主基座指纹与防御性降级 │ 动态探测 socketpair / IPC / tmpfs 权限 │
|
|
50
|
+
│ (Capability Fingerprinting) │ 提供 pytest --capture=sys 等优雅降级 │
|
|
51
|
+
├────────────────────────────────┼───────────────────────────────────────┤
|
|
52
|
+
│ 4. 异常死锁熔断纪律 │ 挂起与越界拦截时提供一键破局自愈引导 │
|
|
53
|
+
│ (Deadlock Circuit Breaker) │ 杜绝 Agent 在会话内静默失踪与长期空转 │
|
|
54
|
+
├────────────────────────────────┼───────────────────────────────────────┤
|
|
55
|
+
│ 5. 宪法升维至 Version 2.0 │ 固化 T7~T11 核心法条,统一生态最高法典 │
|
|
56
|
+
│ (Constitution v2.0 Sync) │ 确立标准作业程序(SOP)为工业级执行载体│
|
|
57
|
+
└────────────────────────────────┴───────────────────────────────────────┘
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### 2.1 确立三态裁决体系(Three-State Verdict Architecture)
|
|
61
|
+
彻底废除二元思维,在 Baton 回执协议、状态机和 AEF 研发纪律中,将裁决明确划分为正交的三态:
|
|
62
|
+
1. **GO(交付验收)**:全量测试真实 Exit 0 通过,产出客观 E1 级证据,由执行方签发 `baton receipt --deliver`;
|
|
63
|
+
2. **NO-GO(裁决驳回)**:业务逻辑或规约未达标,由发起方(`from_lane`)或独立审计方(`to_lane=audit`)签发 `baton reject -n "..."`;
|
|
64
|
+
3. **BLOCKED(受阻挂起)**:因宿主基础设施不可用、外部依赖宕机或沙箱权限硬拦截导致测试无法拉起,**普通实现方有权且必须提交受阻回执(BLOCKED Receipt)**,解除会话死锁。
|
|
65
|
+
|
|
66
|
+
### 2.2 制定《受阻与不可抗力免责呈报协议》(Blocked Reporting Protocol)
|
|
67
|
+
- **客观证据区分律**:必须严格区分 **`E_ENV`(环境阻断)** 与 **`E_LOGIC`(业务缺陷)**。
|
|
68
|
+
- `E_ENV`:如系统调用拒绝(`socketpair: E_ACCESSDENIED`)、磁盘只读、网络断开;
|
|
69
|
+
- `E_LOGIC`:断言失败、业务异常、崩溃退出码。
|
|
70
|
+
- **免责与时效保障**:遭遇不可抗力 `E_ENV` 时,执行方**严禁私自调用 `baton reject`**,亦**严禁挂起不作为**;必须在 15 分钟内执行:
|
|
71
|
+
```bash
|
|
72
|
+
baton receipt <ID> -n "## 状态 / 结论\n- **结论**:BLOCKED(受阻)\n- **阻断类型**:E_ENV (宿主环境权限限制)\n- **根因分析**:..." --evidence-note "宿主环境阻断日志与系统调用错误堆栈"
|
|
73
|
+
```
|
|
74
|
+
- 回执提交后,任务状态分流至 `recvBlocked`,发起方收到客观阻断证据后接入决策(放行环境特权、更换执行节点或由发起方合法关闭/驳回)。
|
|
75
|
+
|
|
76
|
+
### 2.3 宿主基座指纹探测与优雅降级(Runtime Capability Fingerprinting)
|
|
77
|
+
- 升级 `lab doctor` 与 `preflight` 探针,由单纯的静态 PATH 探查升级为**动态调用能力指纹扫描**:
|
|
78
|
+
- 检查当前沙箱是否支持 `socketpair` / `AF_UNIX`;
|
|
79
|
+
- 检查临时目录是否具备执行权限(`noexec` 探测);
|
|
80
|
+
- 检查 Git 是否配置完备 `user.name` 与 `user.email`(防 CI 静默假死)。
|
|
81
|
+
- **测试框架降级规范**:当检测到沙箱拦截 socket 时,自动化套件必须支持自适应降级配置(例如 pytest 自动切换为 `--capture=sys -p no:xdist`,禁用多进程通信管道,保证单进程核心测试可跑通)。
|
|
82
|
+
|
|
83
|
+
### 2.4 最高宪法升维(Constitution v2.0)
|
|
84
|
+
正式修订 `constitution.md`,将版本提升为 `Version 2.0`,在原有 T1~T6 基础上,正式注入过去实践验证成熟的 5 条铁律:
|
|
85
|
+
- **T7 — 反未接线垂直切片与分层治理律 (Anti-Orphan & Vertical Slicing)**
|
|
86
|
+
- **T8 — 三态裁决与环境阻断呈报律 (Three-State Verdict & Blocked Environment Protocol)**
|
|
87
|
+
- **T9 — 密码学防伪凭据与反自审闭环律 (Cryptographic Audit & Anti-Self-Closing Guarantee)**
|
|
88
|
+
- **T10 — 全 CLI 物理契约对齐与零环境寄生律 (CLI Contract & Hermetic Testing Invariant)**
|
|
89
|
+
- **T11 — 微观工程原子技能零污染切片调度律 (Zero-Pollution Micro-Skills Invariant)**
|
|
90
|
+
|
|
91
|
+
### 2.5 建立工业级标准作业程序(SOP)体系
|
|
92
|
+
在 `docs/sop/` 建立标准作业程序体系,解耦“长文理论指南”与“机械执行动作”,确立 4 大核心 SOP:
|
|
93
|
+
1. `docs/sop/01-installation-and-onboarding-sop.md`:全仓初始化与业务仓接入 SOP
|
|
94
|
+
2. `docs/sop/02-day-to-day-engineering-sop.md`:日常端到端工程协同作业 SOP
|
|
95
|
+
3. `docs/sop/03-handoffs-and-audit-sop.md`:任务交割与双盲独立审计流转 SOP
|
|
96
|
+
4. `docs/sop/04-anti-orphan-governance-sop.md`:死代码清道夫与反未接线排查治理 SOP
|
|
97
|
+
|
|
98
|
+
---
|
|
99
|
+
|
|
100
|
+
## 3. Consequences(影响与收益)
|
|
101
|
+
|
|
102
|
+
1. **彻底消除执行端死锁**:实现方在面对宿主环境崩溃时拥有合法合规的呈报退出通道(BLOCKED),杜绝越界 reject 被拦截后挂起空转。
|
|
103
|
+
2. **基座环境具备自愈与感知能力**:从盲目相信宿主环境,演进为主动探查沙箱边界并支持优雅降级。
|
|
104
|
+
3. **顶层宪法与底层机件重新统一**:最高法典与现有的 16 个 ADR 严密咬合,形成自顶向下的确定性工程纪律。
|
|
105
|
+
4. **可操作性大幅提升**:SOP 体系让无论新工程师还是新 Agent,均能对照 1-2-3-4 步骤精准执行,消除因阅读三万字手册产生的信息遗漏。
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
| 0014 | 全局工程生态更名为 ReasonWeave、权威远端迁移与文档规约联动防漂移律 | 🔒 Frozen | 2026-11-22 | global / bin / tests / doc | `0014-reasonweave-rebranding-and-doc-code-synchronization-invariant.md` |
|
|
24
24
|
| 0015 | 微观工程认知规训、渐进式原子技能库与双核门禁融合架构决策 | 🔒 Frozen | 2026-11-23 | units/skills / playbook / handoffs / global | `0015-micro-engineering-skills-and-dual-core-gate-invariant.md` |
|
|
25
25
|
| 0016 | 跨客户端交接角色锚定、CLI 执行态分流与状态机归属确定性架构决策 | 🔒 Frozen | 2026-11-24 | handoffs / global | `0016-cross-client-role-pinning-and-state-machine-deterministic-attribution.md` |
|
|
26
|
+
| 0017 | 三态裁决体系、宿主基座指纹与 AEF 2.0 研发纪律升维架构决策 | 🔒 Frozen | 2026-11-26 | global / constitution / handoffs / playbook | `0017-three-state-verdict-runtime-fingerprinting-and-aef-2-discipline.md` |
|
|
26
27
|
|
|
27
28
|
## 状态说明
|
|
28
29
|
- **Proposed** — 已起草,等待评审。不入 Agent 上下文。
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "reasonweave",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.5",
|
|
4
4
|
"description": "Agent Engineering Framework (AEF) & Disciplines Toolkit for multi-agent software engineering",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "bin/lab.mjs",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
},
|
|
33
33
|
"scripts": {
|
|
34
34
|
"sync:consumers": "node scripts/sync-all-consumers.mjs",
|
|
35
|
-
"test": "node bin/lab.mjs doctor && node units/handoffs/handoff.mjs status && node units/worktree/worktree.mjs --help && node units/review-gate/clean-runner.mjs --help && node units/orphan/bin/lab-orphan.mjs test-solver && node --test units/orphan/tests/*.test.mjs && node --test units/spec-guard/tests/*.test.mjs && node --test units/handoffs/tests/*.test.mjs && node --test units/review-gate/tests/*.test.mjs && node --test units/skills/tests/*.test.mjs && node --test tests/*.test.mjs",
|
|
35
|
+
"test": "node bin/lab.mjs doctor && node units/handoffs/handoff.mjs status && node units/worktree/worktree.mjs --help && node units/review-gate/clean-runner.mjs --help && node units/orphan/bin/lab-orphan.mjs test-solver && node --test units/orphan/tests/*.test.mjs && node --test units/spec-guard/tests/*.test.mjs && node --test units/handoffs/tests/*.test.mjs && node --test units/review-gate/tests/*.test.mjs && node --test units/worktree/tests/*.test.mjs && node --test units/skills/tests/*.test.mjs && node --test tests/*.test.mjs",
|
|
36
36
|
"postinstall": "chmod +x bin/lab.mjs units/handoffs/handoff.mjs units/worktree/worktree.mjs units/review-gate/clean-runner.mjs units/orphan/bin/lab-orphan.mjs units/spec-guard/bin/spec-guard.mjs units/skills/skills.mjs units/skills/bin/*.mjs units/adr/scripts/adr-init.sh units/preflight/templates/preflight.sh units/preflight/templates/check.sh units/review-gate/templates/scan.sh scripts/sync-all-consumers.mjs 2>/dev/null || true"
|
|
37
37
|
},
|
|
38
38
|
"files": [
|
|
@@ -157,6 +157,7 @@ function getSessionId() {
|
|
|
157
157
|
process.env.CURSOR_CONVERSATION_ID ||
|
|
158
158
|
process.env.CLAUDE_CONVERSATION_ID ||
|
|
159
159
|
process.env.CLAUDE_SESSION_ID ||
|
|
160
|
+
process.env.CODEX_SESSION_ID ||
|
|
160
161
|
process.env.WORKBUDDY_CONVERSATION_ID ||
|
|
161
162
|
process.env.WORKBUDDY_SESSION_ID ||
|
|
162
163
|
process.env.CODEBUDDY_CONVERSATION_ID ||
|
|
@@ -301,6 +301,7 @@ function isAgentEnvironment() {
|
|
|
301
301
|
process.env.BATON_AGENT_HOST ||
|
|
302
302
|
process.env.CLAUDE_CODE ||
|
|
303
303
|
process.env.CLAUDE_SESSION_ID ||
|
|
304
|
+
process.env.CODEX_SESSION_ID ||
|
|
304
305
|
process.env.CURSOR_AGENT ||
|
|
305
306
|
process.env.WORKBUDDY_AGENT ||
|
|
306
307
|
process.env.WORKBUDDY_SESSION_ID ||
|
|
@@ -974,6 +975,7 @@ const KNOWN_SESSION_ENV_KEYS = [
|
|
|
974
975
|
'CURSOR_CONVERSATION_ID',
|
|
975
976
|
'CLAUDE_CONVERSATION_ID',
|
|
976
977
|
'CLAUDE_SESSION_ID',
|
|
978
|
+
'CODEX_SESSION_ID',
|
|
977
979
|
'WORKBUDDY_CONVERSATION_ID',
|
|
978
980
|
'WORKBUDDY_SESSION_ID',
|
|
979
981
|
'CODEBUDDY_CONVERSATION_ID',
|
|
@@ -5607,7 +5609,7 @@ async function cmdWait(args) {
|
|
|
5607
5609
|
|
|
5608
5610
|
// 平息完成后:对自愈候选工单安全落盘推进为 delivered
|
|
5609
5611
|
promoteAutoDeliverCandidates();
|
|
5610
|
-
console.log(`🎉 [会话已平息]
|
|
5612
|
+
console.log(`🎉 [会话已平息] 执行方会话已平息,监听进程结束并以 Exit 0 唤醒宿主发起方!`);
|
|
5611
5613
|
}
|
|
5612
5614
|
|
|
5613
5615
|
cleanupAll();
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
# Changelog — review-gate
|
|
2
2
|
|
|
3
|
+
## v1.2.3 (2026-11-27)
|
|
4
|
+
- **Ruff 降级结果解析与门禁拦截漏洞彻底根治**:重构 `pre-commit` 门禁与 `scan.sh`,支持准确解析 Ruff 输出的 JSON 数组结构并归一化转换为基线比对模型,杜绝因 `dict.get` 在列表上抛错被捕获而静默放行 Python 安全漏洞的问题。
|
|
5
|
+
- **真实暂存区(Git Index Blob)快照扫描**:门禁扫描不再直接读取可能已被修改的工作区物理文件,改为通过 `git show :<staged_path>` 将待提交快照还原至独立沙箱目录进行扫描,彻底解决部分暂存误报或工作区未重新暂存导致的漏洞漏检。
|
|
6
|
+
- **双盲审计运行器(Clean Runner)多行判据块保持**:修复验收判据代码块按换行逐行切割导致 `cd` 上下文丢失、多行语句断裂的问题,完整保持脚本块原子执行。
|
|
7
|
+
|
|
3
8
|
## v1.2.2 (2026-11-22)
|
|
4
9
|
- **文档与审查防线增强(Layer-2 code-review-graph 集成指引)**:在 `README.md` §6 Layer-2 本地审查中明确补充与 `code-review-graph` 的协同工作模式,推荐在 Review 前运行 `code-review-graph impact` 提取爆炸半径精准切片。
|
|
5
10
|
- **OpenGrep 原生扫描产物补齐结构化引擎元数据**:修复 `scan.sh` 在 OpenGrep 原生扫描路径下输出 JSON 缺少顶层 `engine: "opengrep"` 与 `fallback: false` 字段的问题,实现与降级扫描模式对齐的对称契约。
|
|
@@ -16,12 +16,12 @@ const REVIEW_GATE_VERSION = (() => {
|
|
|
16
16
|
try {
|
|
17
17
|
const vPath = path.join(SCRIPT_ROOT, 'VERSION.md');
|
|
18
18
|
if (fs.existsSync(vPath)) {
|
|
19
|
-
const
|
|
20
|
-
const m =
|
|
19
|
+
const content = fs.readFileSync(vPath, 'utf8');
|
|
20
|
+
const m = content.match(/v?(\d+\.\d+\.\d+)/);
|
|
21
21
|
if (m) return m[1];
|
|
22
22
|
}
|
|
23
23
|
} catch {}
|
|
24
|
-
return '1.2.
|
|
24
|
+
return '1.2.3';
|
|
25
25
|
})();
|
|
26
26
|
|
|
27
27
|
const args = process.argv.slice(2);
|
|
@@ -91,11 +91,11 @@ function extractCommandsFromTicket(content) {
|
|
|
91
91
|
const codeBlockRegex = /```(?:bash|sh|zsh)?\n([\s\S]*?)```/g;
|
|
92
92
|
let match;
|
|
93
93
|
while ((match = codeBlockRegex.exec(sectionBody)) !== null) {
|
|
94
|
-
const
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
.
|
|
98
|
-
|
|
94
|
+
const block = match[1].trim();
|
|
95
|
+
if (block) {
|
|
96
|
+
// 保持代码块作为一个完整的 Shell 脚本块执行,避免逐行拆分导致 cd、变量与上下文断裂
|
|
97
|
+
commands.push(block);
|
|
98
|
+
}
|
|
99
99
|
}
|
|
100
100
|
}
|
|
101
101
|
return commands;
|
|
@@ -199,29 +199,33 @@ function runAudit(ticketId, options = {}) {
|
|
|
199
199
|
process.exit(1);
|
|
200
200
|
}
|
|
201
201
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
202
|
+
if (!options.json) {
|
|
203
|
+
console.log(`\n🛡️ [Clean Audit Runner] 启动无上下文双盲审计执行:`);
|
|
204
|
+
console.log(` • 工单 ID: \x1b[36m${cleanId}\x1b[0m`);
|
|
205
|
+
console.log(` • 执行物理目录: \x1b[32m${targetDir}\x1b[0m ${isWorktree ? '(隔离工作树)' : '(主代码库)'}`);
|
|
206
|
+
console.log(` • 待执行校验项 (${commands.length} 项):`);
|
|
207
|
+
commands.forEach((c, idx) => console.log(` ${idx + 1}. \x1b[33m${c}\x1b[0m`));
|
|
208
|
+
console.log('─'.repeat(70));
|
|
209
|
+
}
|
|
208
210
|
|
|
209
211
|
const results = [];
|
|
210
212
|
let allPassed = true;
|
|
211
213
|
|
|
212
214
|
for (const cmd of commands) {
|
|
213
|
-
process.stdout.write(`⏳ 正在执行: ${cmd} ... `);
|
|
215
|
+
if (!options.json) process.stdout.write(`⏳ 正在执行: ${cmd} ... `);
|
|
214
216
|
const execRes = executeClean(cmd, targetDir);
|
|
215
217
|
results.push(execRes);
|
|
216
218
|
|
|
217
219
|
if (execRes.exitCode === 0) {
|
|
218
|
-
console.log(`\x1b[32mPASS\x1b[0m (${(execRes.durationMs / 1000).toFixed(2)}s)`);
|
|
220
|
+
if (!options.json) console.log(`\x1b[32mPASS\x1b[0m (${(execRes.durationMs / 1000).toFixed(2)}s)`);
|
|
219
221
|
} else {
|
|
220
|
-
|
|
222
|
+
if (!options.json) {
|
|
223
|
+
console.log(`\x1b[31mFAIL (Exit ${execRes.exitCode})\x1b[0m (${(execRes.durationMs / 1000).toFixed(2)}s)`);
|
|
224
|
+
console.error('\n' + '─'.repeat(40) + ' [错误输出摘要] ' + '─'.repeat(40));
|
|
225
|
+
console.error(execRes.stderr.trim() || execRes.stdout.trim() || '(无标准输出)');
|
|
226
|
+
console.error('─'.repeat(96) + '\n');
|
|
227
|
+
}
|
|
221
228
|
allPassed = false;
|
|
222
|
-
console.error('\n' + '─'.repeat(40) + ' [错误输出摘要] ' + '─'.repeat(40));
|
|
223
|
-
console.error(execRes.stderr.trim() || execRes.stdout.trim() || '(无标准输出)');
|
|
224
|
-
console.error('─'.repeat(96) + '\n');
|
|
225
229
|
break;
|
|
226
230
|
}
|
|
227
231
|
}
|
|
@@ -17,9 +17,15 @@ set -uo pipefail
|
|
|
17
17
|
|
|
18
18
|
# 非交互 hook 可能没把 ~/.local/bin 放进 PATH
|
|
19
19
|
export PATH="$HOME/.local/bin:$PATH"
|
|
20
|
-
OG="${OPENGREP_BIN
|
|
21
|
-
if
|
|
22
|
-
|
|
20
|
+
OG="${OPENGREP_BIN:-__AUTO__}"
|
|
21
|
+
if [ "$OG" = "__AUTO__" ]; then
|
|
22
|
+
if [ -x "$HOME/.local/bin/opengrep" ]; then
|
|
23
|
+
OG="$HOME/.local/bin/opengrep"
|
|
24
|
+
else
|
|
25
|
+
OG=$(command -v opengrep || true)
|
|
26
|
+
fi
|
|
27
|
+
elif [ -n "$OG" ] && { [ ! -x "$OG" ] && ! command -v "$OG" >/dev/null 2>&1; }; then
|
|
28
|
+
OG=""
|
|
23
29
|
fi
|
|
24
30
|
|
|
25
31
|
USE_RUFF_FALLBACK=0
|
|
@@ -48,22 +54,33 @@ SCAN_EXTS="${SCAN_EXTS:-py kt kts java rs ts tsx go xml gradle toml}"
|
|
|
48
54
|
EXT_RE="\.(${SCAN_EXTS// /|})$"
|
|
49
55
|
|
|
50
56
|
# 只扫本次提交真正要落库的暂存代码文件
|
|
51
|
-
|
|
57
|
+
STAGED_FILES=()
|
|
52
58
|
while IFS= read -r f; do
|
|
53
|
-
[ -n "$f" ] &&
|
|
59
|
+
[ -n "$f" ] && STAGED_FILES+=("$f")
|
|
54
60
|
done < <(git -C "$REPO_ROOT" diff --cached --name-only --diff-filter=ACM | grep -E "$EXT_RE" || true)
|
|
55
61
|
|
|
62
|
+
if [ ${#STAGED_FILES[@]} -eq 0 ]; then
|
|
63
|
+
exit 0
|
|
64
|
+
fi
|
|
65
|
+
|
|
66
|
+
# 从 Git Index 中将暂存内容安全还原至独立临时目录进行扫描,确保真实扫描暂存快照
|
|
67
|
+
STAGED_DIR=$(mktemp -d /tmp/og-staged-XXXXXX)
|
|
68
|
+
TMP=$(mktemp /tmp/og-precommit-XXXXXX.json)
|
|
69
|
+
trap 'rm -rf "$STAGED_DIR" "$TMP"' EXIT
|
|
70
|
+
|
|
56
71
|
EXISTING=()
|
|
57
|
-
for f in "${
|
|
58
|
-
|
|
72
|
+
for f in "${STAGED_FILES[@]}"; do
|
|
73
|
+
dest="$STAGED_DIR/$f"
|
|
74
|
+
mkdir -p "$(dirname "$dest")"
|
|
75
|
+
if git -C "$REPO_ROOT" show ":$f" > "$dest" 2>/dev/null; then
|
|
76
|
+
EXISTING+=("$dest")
|
|
77
|
+
fi
|
|
59
78
|
done
|
|
79
|
+
|
|
60
80
|
if [ ${#EXISTING[@]} -eq 0 ]; then
|
|
61
81
|
exit 0
|
|
62
82
|
fi
|
|
63
83
|
|
|
64
|
-
TMP=$(mktemp /tmp/og-precommit-XXXXXX.json)
|
|
65
|
-
trap 'rm -f "$TMP"' EXIT
|
|
66
|
-
|
|
67
84
|
cd "$REPO_ROOT"
|
|
68
85
|
|
|
69
86
|
# 规则集 / 排除项与 scan.sh 同语义(按需用环境变量覆盖)
|
|
@@ -79,13 +96,14 @@ EXCLUDE_RULES=(
|
|
|
79
96
|
)
|
|
80
97
|
EXCLUDES=$(printf -- '--exclude-rule %s ' ${EXCLUDE_RULES[@]+"${EXCLUDE_RULES[@]}"})
|
|
81
98
|
|
|
99
|
+
SCAN_EXIT=0
|
|
82
100
|
if [ "$USE_RUFF_FALLBACK" = "1" ]; then
|
|
83
101
|
echo "🔍 Ruff Bandit fallback gate: scanning ${#EXISTING[@]} staged file(s)..."
|
|
84
|
-
"$RUFF" check --select S --output-format json "${EXISTING[@]}" > "$TMP" 2>/dev/null ||
|
|
102
|
+
"$RUFF" check --select S --output-format json "${EXISTING[@]}" > "$TMP" 2>/dev/null || SCAN_EXIT=$?
|
|
85
103
|
else
|
|
86
104
|
echo "🔍 OpenGrep gate: scanning ${#EXISTING[@]} staged file(s)..."
|
|
87
105
|
"$OG" scan ${CONFIG_ARGS[@]+"${CONFIG_ARGS[@]}"} --disable-version-check --timeout 60 ${EXCLUDES} \
|
|
88
|
-
--json --output "$TMP" "${EXISTING[@]}" >/dev/null 2>&1 ||
|
|
106
|
+
--json --output "$TMP" "${EXISTING[@]}" >/dev/null 2>&1 || SCAN_EXIT=$?
|
|
89
107
|
fi
|
|
90
108
|
|
|
91
109
|
PY=$(command -v python3 || command -v python || true)
|
|
@@ -94,37 +112,69 @@ if [ -z "$PY" ]; then
|
|
|
94
112
|
exit 0
|
|
95
113
|
fi
|
|
96
114
|
|
|
97
|
-
"$PY" - "$TMP" "$BASELINE" "$
|
|
98
|
-
import json, sys
|
|
115
|
+
"$PY" - "$TMP" "$BASELINE" "$STAGED_DIR" "$USE_RUFF_FALLBACK" "$SCAN_EXIT" <<'PYEOF'
|
|
116
|
+
import json, sys, os
|
|
117
|
+
|
|
118
|
+
tmp_path = sys.argv[1]
|
|
119
|
+
base_path = sys.argv[2]
|
|
120
|
+
staged_dir = os.path.realpath(sys.argv[3]).rstrip("/") + "/"
|
|
121
|
+
is_ruff = sys.argv[4] == "1"
|
|
122
|
+
scan_exit = int(sys.argv[5])
|
|
99
123
|
|
|
100
|
-
def load(p):
|
|
124
|
+
def load(p, is_ruff_output=False):
|
|
101
125
|
try:
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
126
|
+
with open(p, "r", encoding="utf-8") as f:
|
|
127
|
+
data = json.load(f)
|
|
128
|
+
except Exception as e:
|
|
129
|
+
print(f"❌ 门禁评估失败: 无法解析扫描报告 {p}: {e}", file=sys.stderr)
|
|
130
|
+
sys.exit(2)
|
|
131
|
+
|
|
132
|
+
if isinstance(data, list):
|
|
133
|
+
if is_ruff_output:
|
|
134
|
+
return [
|
|
135
|
+
{
|
|
136
|
+
"check_id": item.get("code") or item.get("check_id"),
|
|
137
|
+
"path": item.get("filename") or item.get("path"),
|
|
138
|
+
"start": {"line": (item.get("location") or {}).get("row")},
|
|
139
|
+
"extra": {"severity": "WARNING", "message": item.get("message", "")}
|
|
140
|
+
}
|
|
141
|
+
for item in data
|
|
142
|
+
if isinstance(item, dict)
|
|
143
|
+
]
|
|
144
|
+
return data
|
|
145
|
+
elif isinstance(data, dict):
|
|
146
|
+
return data.get("results", [])
|
|
147
|
+
return []
|
|
148
|
+
|
|
149
|
+
cur = load(tmp_path, is_ruff_output=is_ruff)
|
|
150
|
+
base = load(base_path, is_ruff_output=False)
|
|
105
151
|
|
|
106
|
-
# opengrep 对绝对路径入参会回写绝对 path,而基线多为相对根路径 → 归一化为相对仓库根再比对
|
|
107
|
-
REPO = sys.argv[3].rstrip("/") + "/"
|
|
108
152
|
def norm(p):
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
153
|
+
if not p:
|
|
154
|
+
return ""
|
|
155
|
+
p_real = os.path.realpath(str(p))
|
|
156
|
+
if p_real.startswith(staged_dir):
|
|
157
|
+
return p_real[len(staged_dir):]
|
|
158
|
+
p_str = str(p)
|
|
159
|
+
if p_str.startswith(sys.argv[3].rstrip("/") + "/"):
|
|
160
|
+
return p_str[len(sys.argv[3].rstrip("/") + "/"):]
|
|
161
|
+
return p_str
|
|
162
|
+
|
|
163
|
+
base_keys = {(r.get("check_id"), norm(r.get("path"))) for r in base if "check_id" in r and "path" in r}
|
|
164
|
+
new = [
|
|
165
|
+
r for r in cur
|
|
166
|
+
if ("check_id" in r and "path" in r) and (r.get("check_id"), norm(r.get("path"))) not in base_keys
|
|
167
|
+
]
|
|
119
168
|
|
|
120
169
|
if new:
|
|
121
|
-
|
|
170
|
+
gate_name = "Ruff Bandit" if is_ruff else "OpenGrep"
|
|
171
|
+
print(f"❌ {gate_name} gate: {len(new)} new finding(s) beyond accepted baseline:")
|
|
122
172
|
for r in new:
|
|
123
173
|
e = r.get("extra", {})
|
|
124
174
|
line = r.get("start", {}).get("line", "?")
|
|
125
|
-
print(" - [
|
|
126
|
-
print("\n Fix the issue, or re-baseline: RULESETS=... bash scan.sh
|
|
175
|
+
print(f" - [{r.get('check_id')}] {norm(r.get('path'))}:{line} ({e.get('severity', '?')})")
|
|
176
|
+
print(f"\n Fix the issue, or re-baseline: RULESETS=... bash scan.sh {sys.argv[2]}")
|
|
127
177
|
sys.exit(1)
|
|
128
178
|
|
|
129
|
-
print("✅
|
|
179
|
+
print(f"✅ Static-analysis gate passed (no new findings vs {len(base)} accepted baseline).")
|
|
130
180
|
PYEOF
|
|
@@ -136,8 +136,22 @@ else
|
|
|
136
136
|
python3 -c '
|
|
137
137
|
import sys, json
|
|
138
138
|
findings = []
|
|
139
|
-
try:
|
|
140
|
-
|
|
139
|
+
try:
|
|
140
|
+
raw = json.loads(sys.argv[1]) if sys.argv[1] else []
|
|
141
|
+
if isinstance(raw, list):
|
|
142
|
+
for f in raw:
|
|
143
|
+
if isinstance(f, dict):
|
|
144
|
+
loc = f.get("location") or {}
|
|
145
|
+
end_loc = f.get("end_location") or {}
|
|
146
|
+
findings.append({
|
|
147
|
+
"check_id": f.get("code"),
|
|
148
|
+
"path": f.get("filename"),
|
|
149
|
+
"start": { "line": loc.get("row"), "col": loc.get("column") },
|
|
150
|
+
"end": { "line": end_loc.get("row"), "col": end_loc.get("column") },
|
|
151
|
+
"extra": { "message": f.get("message", ""), "severity": "WARNING" }
|
|
152
|
+
})
|
|
153
|
+
except Exception as e:
|
|
154
|
+
sys.stderr.write(f"Ruff JSON parse warning: {e}\n")
|
|
141
155
|
payload = {
|
|
142
156
|
"engine": "fallback-ruff-bandit",
|
|
143
157
|
"fallback": True,
|
|
@@ -176,6 +176,14 @@ export function runMutationTest(options = {}) {
|
|
|
176
176
|
throw new Error(`Mutation runner target file not found: ${targetFile}`);
|
|
177
177
|
}
|
|
178
178
|
|
|
179
|
+
// 严格安全边界检查:确保 targetFile 位于 repoRoot 内部
|
|
180
|
+
const realRepoRoot = fs.existsSync(repoRoot) ? fs.realpathSync(repoRoot) : path.resolve(repoRoot);
|
|
181
|
+
const realTargetFile = fs.existsSync(targetFile) ? fs.realpathSync(targetFile) : path.resolve(targetFile);
|
|
182
|
+
const relativeTarget = path.relative(realRepoRoot, realTargetFile);
|
|
183
|
+
if (relativeTarget.startsWith('..') || path.isAbsolute(relativeTarget)) {
|
|
184
|
+
throw new Error(`Mutation runner target file must be located inside repoRoot: ${targetFile}`);
|
|
185
|
+
}
|
|
186
|
+
|
|
179
187
|
const cleanEnv = { ...process.env };
|
|
180
188
|
delete cleanEnv.NODE_TEST_CONTEXT;
|
|
181
189
|
|
|
@@ -207,42 +215,62 @@ export function runMutationTest(options = {}) {
|
|
|
207
215
|
}
|
|
208
216
|
|
|
209
217
|
// 3. 逐个注入变异并验证测试套件敏感度
|
|
218
|
+
// 安全防护:在进程退出或意外中断时注册保护兜底
|
|
210
219
|
let killedCount = 0;
|
|
211
220
|
const survivedMutants = [];
|
|
212
221
|
|
|
213
|
-
|
|
214
|
-
const mutatedContent =
|
|
215
|
-
originalContent.slice(0, mutant.index) +
|
|
216
|
-
mutant.replacement +
|
|
217
|
-
originalContent.slice(mutant.index + mutant.original.length);
|
|
218
|
-
|
|
222
|
+
const cleanupHandler = () => {
|
|
219
223
|
try {
|
|
220
|
-
fs.
|
|
224
|
+
if (fs.existsSync(targetFile)) {
|
|
225
|
+
fs.writeFileSync(targetFile, originalContent, 'utf8');
|
|
226
|
+
}
|
|
227
|
+
} catch {}
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
process.once('SIGINT', cleanupHandler);
|
|
231
|
+
process.once('SIGTERM', cleanupHandler);
|
|
232
|
+
process.once('exit', cleanupHandler);
|
|
233
|
+
|
|
234
|
+
try {
|
|
235
|
+
for (const mutant of mutants) {
|
|
236
|
+
const mutatedContent =
|
|
237
|
+
originalContent.slice(0, mutant.index) +
|
|
238
|
+
mutant.replacement +
|
|
239
|
+
originalContent.slice(mutant.index + mutant.original.length);
|
|
221
240
|
|
|
222
|
-
let testPassedWithMutant = false;
|
|
223
241
|
try {
|
|
224
|
-
|
|
225
|
-
testPassedWithMutant = true;
|
|
226
|
-
} catch {
|
|
227
|
-
// 测试报错 = 变异被消灭 (Killed)
|
|
228
|
-
testPassedWithMutant = false;
|
|
229
|
-
}
|
|
242
|
+
fs.writeFileSync(targetFile, mutatedContent, 'utf8');
|
|
230
243
|
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
244
|
+
let testPassedWithMutant = false;
|
|
245
|
+
try {
|
|
246
|
+
execSync(testCmd, { cwd: repoRoot, stdio: 'pipe', encoding: 'utf8', env: cleanEnv });
|
|
247
|
+
testPassedWithMutant = true;
|
|
248
|
+
} catch {
|
|
249
|
+
// 测试报错 = 变异被消灭 (Killed)
|
|
250
|
+
testPassedWithMutant = false;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
if (testPassedWithMutant) {
|
|
254
|
+
// 变异体存活 = 假测试!
|
|
255
|
+
survivedMutants.push(mutant);
|
|
256
|
+
} else {
|
|
257
|
+
killedCount++;
|
|
258
|
+
}
|
|
259
|
+
} finally {
|
|
260
|
+
// 必须立刻恢复原文件,保证工作区绝对干净零污染!
|
|
261
|
+
fs.writeFileSync(targetFile, originalContent, 'utf8');
|
|
236
262
|
}
|
|
237
|
-
} finally {
|
|
238
|
-
// 必须立刻恢复原文件,保证工作区绝对干净零污染!
|
|
239
|
-
fs.writeFileSync(targetFile, originalContent, 'utf8');
|
|
240
|
-
}
|
|
241
263
|
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
264
|
+
// 发现任何一个存活变异体,立即熔断报告
|
|
265
|
+
if (survivedMutants.length > 0) {
|
|
266
|
+
break;
|
|
267
|
+
}
|
|
245
268
|
}
|
|
269
|
+
} finally {
|
|
270
|
+
process.removeListener('SIGINT', cleanupHandler);
|
|
271
|
+
process.removeListener('SIGTERM', cleanupHandler);
|
|
272
|
+
process.removeListener('exit', cleanupHandler);
|
|
273
|
+
cleanupHandler();
|
|
246
274
|
}
|
|
247
275
|
|
|
248
276
|
if (survivedMutants.length > 0) {
|
|
@@ -478,6 +478,25 @@ assert.equal(ep, "/api/v1/device/interlock");
|
|
|
478
478
|
}
|
|
479
479
|
});
|
|
480
480
|
|
|
481
|
+
it('runMutationTest 边界防御:严禁变异 repoRoot 外部的文件', () => {
|
|
482
|
+
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'spec-guard-sec-'));
|
|
483
|
+
const outsideDir = fs.mkdtempSync(path.join(os.tmpdir(), 'spec-guard-out-'));
|
|
484
|
+
try {
|
|
485
|
+
const outsideFile = path.join(outsideDir, 'outside.mjs');
|
|
486
|
+
fs.writeFileSync(outsideFile, 'export const x = 1;');
|
|
487
|
+
assert.throws(() => {
|
|
488
|
+
runMutationTest({
|
|
489
|
+
repoRoot: tmpDir,
|
|
490
|
+
targetFile: outsideFile,
|
|
491
|
+
testCmd: 'node -e "process.exit(0)"',
|
|
492
|
+
});
|
|
493
|
+
}, /must be located inside repoRoot/);
|
|
494
|
+
} finally {
|
|
495
|
+
fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
496
|
+
fs.rmSync(outsideDir, { recursive: true, force: true });
|
|
497
|
+
}
|
|
498
|
+
});
|
|
499
|
+
|
|
481
500
|
it('orphan 单元联动测试:符号引用分类与倒排生产调用者检索', () => {
|
|
482
501
|
assert.equal(Classifier.isTestPath('src/test/java/Test.kt'), true);
|
|
483
502
|
assert.equal(Classifier.isTestPath('src/main/java/Main.kt'), false);
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# Changelog — units/worktree
|
|
2
2
|
|
|
3
|
+
## [v0.1.1] - 2026-11-27
|
|
4
|
+
|
|
5
|
+
### Fixed
|
|
6
|
+
- **诚实分支回收状态报告**:修复 `prune` 子命令在临时分支包含未合并修改且未加 `--force` 时静默吞掉 `git branch -d` 报错并虚报成功的问题;现在明确输出警告并返回 `worktree_removed_branch_retained` 状态与详细错误。
|
|
7
|
+
- **单元测试补齐**:新增 `units/worktree/tests/worktree.test.mjs`,常驻校验回收状态诚实性。
|
|
8
|
+
|
|
3
9
|
## [v0.1.0] - 2026-11-09
|
|
4
10
|
|
|
5
11
|
### Added
|
|
@@ -1 +1 @@
|
|
|
1
|
-
v0.1.
|
|
1
|
+
v0.1.1 — 2026-11-27
|