@rosenfan/matrix 0.1.1 → 0.1.3

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.
Files changed (38) hide show
  1. package/.claude/skills/matrix/SKILL.md +60 -17
  2. package/.claude/skills/matrix/agents/openai.yaml +4 -4
  3. package/.claude/skills/matrix/scripts/matrix_claude.py +3 -158
  4. package/.claude/skills/matrix/scripts/matrix_state.py +53 -107
  5. package/.claude/skills/matrix-archive/SKILL.md +23 -13
  6. package/.claude/skills/matrix-build/SKILL.md +24 -35
  7. package/.claude/skills/matrix-claude/SKILL.md +26 -24
  8. package/.claude/skills/matrix-design/SKILL.md +29 -26
  9. package/.claude/skills/matrix-hotfix/SKILL.md +8 -8
  10. package/.claude/skills/matrix-open/SKILL.md +25 -18
  11. package/.claude/skills/matrix-status/SKILL.md +3 -2
  12. package/.claude/skills/matrix-tweak/SKILL.md +8 -8
  13. package/.claude/skills/matrix-verify/SKILL.md +21 -30
  14. package/LICENSE +21 -21
  15. package/README.md +294 -255
  16. package/README.zh-CN.md +293 -255
  17. package/assets/skills-zh-CN/matrix/SKILL.md +80 -25
  18. package/assets/skills-zh-CN/matrix-archive/SKILL.md +33 -9
  19. package/assets/skills-zh-CN/matrix-build/SKILL.md +36 -10
  20. package/assets/skills-zh-CN/matrix-claude/SKILL.md +31 -28
  21. package/assets/skills-zh-CN/matrix-design/SKILL.md +19 -10
  22. package/assets/skills-zh-CN/matrix-hotfix/SKILL.md +8 -8
  23. package/assets/skills-zh-CN/matrix-open/SKILL.md +22 -7
  24. package/assets/skills-zh-CN/matrix-status/SKILL.md +15 -14
  25. package/assets/skills-zh-CN/matrix-tweak/SKILL.md +8 -8
  26. package/assets/skills-zh-CN/matrix-verify/SKILL.md +26 -10
  27. package/bin/matrix.js +15 -15
  28. package/package.json +56 -56
  29. package/src/catalog.js +92 -87
  30. package/src/cli.js +159 -101
  31. package/src/distribution.js +281 -186
  32. package/src/installer.js +45 -45
  33. package/src/matt.js +45 -45
  34. package/src/messages.js +33 -33
  35. package/src/self-update.js +81 -0
  36. package/src/ui.js +89 -89
  37. package/src/workflow-transaction.js +622 -0
  38. package/src/workflow.js +787 -82
package/README.zh-CN.md CHANGED
@@ -1,271 +1,309 @@
1
- # Matrix Workflow
1
+ # Matrix Workflow
2
+
3
+ 一个提供 Prim 与 Arch 编排的证据驱动开发工作流,灵感来自 [Comet](https://github.com/rpamis/comet)。Matrix 可以使用自身能力,也可以按事实调用已验证的 [Matt Pocock agent skills](https://github.com/mattpocock/skills),但生命周期所有权始终由 Matrix 保持。
4
+
5
+ **[English](./README.md)** | 中文
6
+
7
+ <p align="center">
8
+ <img src="./assets/matrix-workflow-poster-zh.svg" alt="Matrix Workflow" width="100%">
9
+ </p>
10
+
11
+ ---
12
+
13
+ ## 目录
14
+
15
+ - [为什么需要 Matrix](#为什么需要-matrix)
16
+ - [它做了什么](#它做了什么)
17
+ - [前置条件](#前置条件)
18
+ - [安装](#安装)
19
+ - [快速开始](#快速开始)
20
+ - [工作流阶段](#工作流阶段)
21
+ - [工作原理](#工作原理)
22
+ - [工作流类型](#工作流类型)
23
+ - [与 Matt Pocock Skills 的集成](#与-matt-pocock-skills-的集成)
24
+ - [许可证](#许可证)
25
+
26
+ ---
27
+
28
+ ## 为什么需要 Matrix
29
+
30
+ [Matt Pocock 的 skills](https://github.com/mattpocock/skills) 提供 `/grilling`、`/tdd`、`/code-review` 等聚焦能力。但缺少统一生命周期所有者时会导致常见问题:
31
+
32
+ - **无流程记忆**:你进行了 grilling,然后实现,但没有记录决策过程
33
+ - **阶段混乱**:设计完成了吗?我们在构建阶段吗?上下文丢失后很难判断
34
+ - **静默范围蔓延**:需求在构建过程中变更,却没有返回设计阶段
35
+ - **缺少证据**:"看起来完成了"却没有验证证明
36
+
37
+ Matrix 通过唯一的确定性状态机解决这些问题 —— 包含明确的阶段、守卫条件和产物追踪。Skill 可以协助阶段,但生命周期始终由 Matrix 拥有。
38
+
39
+ ---
40
+
41
+ ## 它做了什么
42
+
43
+ Matrix 在集中定义的两种 workflow profile 上提供两种能力编排:
2
44
 
3
- 一个基于 [Matt Pocock 的 Claude Code skills](https://github.com/mattpocock/skills) 的结构化工作流编排器,灵感来自 [Comet](https://github.com/rpamis/comet)。它通过强制执行基于证据的阶段转换,规范使用这些 skills 时的开发流程。
4
-
5
- **[English](./README.md)** | 中文
6
-
7
- <p align="center">
8
- <img src="./assets/matrix-workflow-poster-zh.svg" alt="Matrix Workflow" width="100%">
9
- </p>
10
-
11
- ---
12
-
13
- ## 目录
14
-
15
- - [为什么需要 Matrix](#为什么需要-matrix)
16
- - [它做了什么](#它做了什么)
17
- - [前置条件](#前置条件)
18
- - [安装](#安装)
19
- - [快速开始](#快速开始)
20
- - [工作流阶段](#工作流阶段)
21
- - [工作原理](#工作原理)
22
- - [工作流类型](#工作流类型)
23
- - [与 Matt Pocock Skills 的集成](#与-matt-pocock-skills-的集成)
24
- - [许可证](#许可证)
25
-
26
- ---
27
-
28
- ## 为什么需要 Matrix
29
-
30
- [Matt Pocock 的 skills](https://github.com/mattpocock/skills) 是优秀的独立工具 —— `/grill-with-docs` 用于需求澄清,`/tdd` 用于测试驱动开发,`/implement` 用于执行实现。但单独使用它们会导致常见问题:
31
-
32
- - **无流程记忆**:你进行了 grilling,然后实现,但没有记录决策过程
33
- - **阶段混乱**:设计完成了吗?我们在构建阶段吗?上下文丢失后很难判断
34
- - **静默范围蔓延**:需求在构建过程中变更,却没有返回设计阶段
35
- - **缺少证据**:"看起来完成了"却没有验证证明
36
-
37
- Matrix 通过将这些 skills 封装到确定性状态机中来解决这些问题 —— 包含明确的阶段、守卫条件和产物追踪。灵感来自 [Comet](https://github.com/rpamis/comet) 的阶段式方法。
38
-
39
- ---
40
-
41
- ## 它做了什么
42
-
43
- Matrix 将 Matt Pocock 的 skills 编排成结构化工作流:
44
-
45
- ```
46
- open → design → build → verify → archive
47
- (开放) (设计) (构建) (验证) (归档)
48
- ↓ ↓ ↓ ↓ ↓
49
- grill plan implement tdd commit
50
- design review
51
- ```
52
-
53
- 每个阶段:
54
- - 有特定的交付物(产物)
55
- - 有必须通过的守卫条件
56
- - 记录所有转换
57
- - 可承受上下文丢失(状态存储在磁盘上)
58
-
59
- ---
60
-
61
- ## 前置条件
62
-
63
- - 已安装 [Claude Code](https://docs.anthropic.com/claude-code)
64
- - Node.js 18+(用于运行安装器)
65
- - Python 3.8+ 已添加到 PATH
66
-
67
- ---
68
-
69
- ## 安装
70
-
71
- 只需全局安装一次 Matrix CLI:
72
-
73
- ```bash
74
- npm install --global @rosenfan/matrix
75
45
  ```
76
-
77
- 之后在任意项目中初始化:
78
-
79
- ```bash
80
- cd /path/to/your/project
81
- matrix init
82
- ```
83
-
84
- 交互式初始化支持:
85
-
86
- - 选择安装到当前项目或全局
87
- - 复制 skills(推荐)或为本地开发创建符号链接
88
- - 更新已有安装,并自动备份被替换的 Matrix 文件
89
- - 在同一流程中安装 Matt Pocock 的配套 skills
90
-
91
- 自动化或 CI 环境可以使用:
92
-
93
- ```bash
94
- # 使用推荐的项目级默认值,不显示交互问题
95
- matrix init --yes --with-mattpocock
96
-
46
+ full: open → design → build → verify → archive
47
+ hotfix/tweak lightweight:open ─────────→ build → verify → archive
48
+
49
+ Prim:Matrix 使用自身能力
50
+ Arch:仅在任务事实满足触发条件时调用已验证的原子 Skill
51
+ ```
52
+
53
+ 恢复路径由 Runtime 受控执行:
54
+
55
+ ```text
56
+ build --design-gap--------------------> design
57
+ verify --verification-failed-----------> build
58
+ verify --acceptance-or-design-gap------> design
59
+ 任意活动阶段 --abort-------------------> aborted
60
+ ```
61
+
62
+ 每个阶段:
63
+ - 有特定的交付物(产物)
64
+ - 有必须通过的守卫条件
65
+ - 记录所有转换
66
+ - 可承受上下文丢失(状态存储在磁盘上)
67
+
68
+ ---
69
+
70
+ ## 前置条件
71
+
72
+ - 已安装 [Claude Code](https://docs.anthropic.com/claude-code) 和/或 Codex,作为 Skill 宿主
73
+ - Node.js 18+,且 `npm` 已加入 PATH(用于 Matrix CLI)
74
+ - Python 仅在兼容窗口内的旧适配器路径使用;新安装使用内置 Node workflow runtime
75
+ - Git 仅在从 GitHub 安装或参与 Matrix 开发时需要
76
+
77
+ ---
78
+
79
+ ## 安装
80
+
81
+ 只需全局安装一次 Matrix CLI:
82
+
83
+ ```bash
84
+ npm install --global @rosenfan/matrix
85
+ ```
86
+
87
+ 之后在任意项目中初始化:
88
+
89
+ ```bash
90
+ cd /path/to/your/project
91
+ matrix init
92
+ ```
93
+
94
+ 交互式初始化支持:
95
+
96
+ - 选择安装到当前项目或全局
97
+ - 复制 skills(推荐)或为本地开发创建符号链接
98
+ - 安全地重新配置已有安装,并自动备份被替换的 Matrix 文件
99
+ - 在同一流程中安装 Matt Pocock 的配套 skills
100
+ - 选择 Prim 或 Arch 作为项目默认值,且不禁用另一种可用模式
101
+
102
+ 自动化或 CI 环境可以使用:
103
+
104
+ ```bash
105
+ # 使用推荐的项目级默认值,不显示交互问题
106
+ matrix init --yes --with-mattpocock
107
+
108
+ # 显式选择项目默认编排
109
+ matrix init --yes --with-mattpocock --default-orchestration arch
110
+
97
111
  # 检查安装完整性和运行环境
98
112
  matrix doctor
99
113
  ```
100
114
 
101
- npm 包正式发布前,也可以直接从 GitHub 安装:
115
+ 更新已经初始化的项目:
102
116
 
103
117
  ```bash
104
- npm install --global github:Rosenfan/Matrix
105
- ```
106
-
107
- Matrix 将安装:
108
- - `matrix/` — 入口点和状态管理
109
- - `matrix-open/` — 开放阶段(使用 `/grill-with-docs`)
110
- - `matrix-design/` — 设计阶段(使用 `/prototype`、`/research`)
111
- - `matrix-build/` — 构建阶段(使用 `/implement`、`/tdd`)
112
- - `matrix-verify/` — 验证阶段(使用 `/code-review`)
113
- - `matrix-archive/` — 归档阶段
114
- - `matrix-hotfix/` — 小型 Bug 快捷方式
115
- - `matrix-tweak/` — 有界变更快捷方式
116
- - `matrix-status/` — 检查当前状态
117
- - `matrix-claude/` — 可选:导出供 Claude Code 使用
118
+ # 检查新版 Matrix CLI,确认计划后更新 CLI 并同步当前项目资产
119
+ matrix update
118
120
 
119
- ---
121
+ # 离线或本地开发:不访问 npm registry,只用当前 CLI 同步资产
122
+ matrix update --skip-self-update
120
123
 
121
- ## 快速开始
122
-
123
- 在 Claude Code 中:
124
-
125
- ```
126
- $matrix 我想给 API 添加用户认证
124
+ # 已在自动化中明确授权写入
125
+ matrix update --yes
127
126
  ```
128
127
 
129
- Matrix 将会:
130
- 1. 用工作流类型 `full` 初始化一个变更
131
- 2. 进入 `open` 阶段 → 调用 `/grill-with-docs` 澄清需求
132
- 3. 创建 `proposal.md`,包含目标、范围、验收标准、风险
133
- 4. 守卫检查:所有章节是否内容充实?
134
- 5. 如果通过 → 转换到 `design`
135
-
136
- ---
137
-
138
- ## 工作流阶段
139
-
140
- | 阶段 | 使用的 Matt Pocock Skills | 交付物 | 守卫条件 |
141
- |------|---------------------------|--------|----------|
142
- | **open** | `/grill-with-docs`(自动调用 `/grilling` + `/domain-modeling`) | `proposal.md`、`CONTEXT.md`、ADRs | 目标、范围、验收标准、风险存在 |
143
- | **design** | `/domain-modeling` → `/research` → `/wayfinder` → `/prototype` → `/codebase-design` | `design.md`、`plan.md` | 决策、测试点、步骤已记录 |
144
- | **build** | `/implement`(自动调用 `/tdd` + `/code-review`)、`/diagnosing-bugs`、`/resolving-merge-conflicts` | 代码、`verification.md` | 计划存在,构建证据已记录 |
145
- | **verify** | `/code-review`(双轴:Standards + Spec)、`/improve-codebase-architecture` | 测试和审查证据 | 测试和审查证据存在 |
146
- | **archive** | — | Git commit | 验证守卫通过 |
147
-
148
- ---
149
-
150
- ## 工作原理
151
-
152
- 状态存储在 `.matrix/` 目录:
153
-
154
- ```
155
- .matrix/
156
- ├── active.json # 当前变更 ID
157
- ├── config.yaml
158
- ├── changes/
159
- │ └── <change-id>/
160
- │ ├── matrix.yaml # 阶段、工作流、时间戳
161
- │ ├── run-state.json
128
+ `matrix update` 会保留既有安装的 scope、平台、语言、mode 与 orchestration。它先隔离验证 npm 新包,再由新 CLI 同步项目资产。npm 与项目资产是两个事务:若 CLI 已更新但资产同步失败,可运行 `matrix update --skip-self-update` 重试。修改安装选择请使用 `matrix init`;只读诊断请使用 `matrix doctor`。
129
+
130
+ `matrix init` 选择的语言决定新 Matrix 产物的正文语言:`zh-CN` 使用中文、`en` 使用英文。Runtime 守卫依赖的 Markdown 英文标题 token 保持不变;每个 change 在创建时冻结该语言。
131
+
132
+ 也可以直接从 GitHub 安装,而不是 npm:
133
+
134
+ ```bash
135
+ npm install --global github:Rosenfan/Matrix
136
+ ```
137
+
138
+ Matrix 将安装:
139
+ - `matrix/` — 入口点和状态管理
140
+ - `matrix-open/` — Open 阶段与 canonical proposal
141
+ - `matrix-design/` — Design、plan 与 Contract 批准
142
+ - `matrix-build/` — 有界实现与构建证据
143
+ - `matrix-verify/` — 测试和双轴审查证据
144
+ - `matrix-archive/` — 归档阶段
145
+ - `matrix-hotfix/` — 小型 Bug 快捷方式
146
+ - `matrix-tweak/` — 有界变更快捷方式
147
+ - `matrix-status/` — 检查当前状态
148
+ - `matrix-claude/` — 可选:导出供 Claude Code 使用
149
+
150
+ ---
151
+
152
+ ## 快速开始
153
+
154
+ 在 Claude Code 中:
155
+
156
+ ```
157
+ $matrix 我想给 API 添加用户认证
158
+ ```
159
+
160
+ Matrix 将会:
161
+ 1. 用工作流类型 `full` 和冻结的 `prim|arch` 编排初始化变更
162
+ 2. 进入 `open`;Prim 直接处理,Arch 只调用已证明的需求触发能力
163
+ 3. 创建 `proposal.md`,包含目标、范围、验收标准、风险
164
+ 4. 守卫检查:所有章节是否内容充实?
165
+ 5. 如果通过 → 转换到 `design`
166
+
167
+ ---
168
+
169
+ ## 工作流阶段
170
+
171
+ | 阶段 | Arch 能力(按事实触发,不是固定序列) | 交付物 | 守卫条件 |
172
+ |------|----------------------------------------|--------|----------|
173
+ | **open** | `/grilling`、`/domain-modeling` | `proposal.md`;可选仓库约定的 context/ADR 证据 | 目标、范围、验收标准、风险存在 |
174
+ | **design** | `/domain-modeling`、`/research`、`/wayfinder`、`/prototype`、`/codebase-design` | `design.md`、`plan.md` | 决策、测试点、步骤已记录 |
175
+ | **build** | `/tdd`、`/diagnosing-bugs`、`/resolving-merge-conflicts` | 代码、`verification.md` | 已批准的精确 Contract 匹配,且已记录构建证据 |
176
+ | **verify** | `/code-review` | 测试和审查证据 | 测试和审查证据存在 |
177
+ | **archive** | 无;两种模式均由 Matrix 拥有 | 归档记录 | 验证守卫通过 |
178
+
179
+ ---
180
+
181
+ ## 工作原理
182
+
183
+ 状态存储在 `.matrix/` 目录:
184
+
185
+ ```
186
+ .matrix/
187
+ ├── active.json # 当前变更 ID
188
+ ├── config.yaml
189
+ ├── changes/
190
+ │ └── <change-id>/
191
+ │ ├── matrix.yaml # 唯一 workflow、orchestration、阶段、状态与 revision 事实
192
+ │ ├── workspace-baseline.json # lightweight 的实施顺序边界
162
193
  │ ├── events.jsonl
163
- │ └── artifacts/
164
- │ ├── proposal.md
165
- │ ├── design.md
166
- │ ├── plan.md
167
- │ └── verification.md
168
- └── archive/
169
- ```
170
-
171
- 状态机强制执行转换:
172
-
173
- ```bash
174
- # 检查守卫
175
- python .claude/skills/matrix/scripts/matrix_state.py guard open
176
-
194
+ │ └── artifacts/
195
+ │ ├── proposal.md
196
+ │ ├── design.md
197
+ │ ├── plan.md
198
+ │ ├── verification.md
199
+ │ └── evidence-history/
200
+ └── archive/
201
+ ```
202
+
203
+ 状态机强制执行转换:
204
+
205
+ ```bash
206
+ # 检查守卫
207
+ matrix workflow guard open
208
+
177
209
  # 推进(仅在守卫通过时)
178
- python .claude/skills/matrix/scripts/matrix_state.py transition design
179
- ```
180
-
181
- ---
182
-
183
- ## 工作流类型
184
-
185
- | 类型 | 使用场景 | 阶段 |
186
- |------|----------|------|
187
- | **full** | 新功能、架构变更 | 全部 5 个阶段 |
188
- | **hotfix** | 可复现的小型 Bug | 简化:open → build → verify → archive |
210
+ matrix workflow transition design
211
+
212
+ # lightweight:确认紧凑 proposal 后进入 Build
213
+ matrix workflow transition build --confirmed
214
+
215
+ # 验证失败时返回 Build;旧证据保留在历史目录
216
+ matrix workflow return build --reason verification-failed
217
+
218
+ # 终止变更但保留产物,不撤销工作区代码
219
+ matrix workflow abort --reason requirement-cancelled
220
+
221
+ # 最终归档强制使用两步乐观提交
222
+ matrix workflow archive --dry-run
223
+ matrix workflow archive --expect-preflight <dry-run-返回的-sha256>
224
+ # hotfix/tweak 的提交命令还必须带 --confirmed
225
+
226
+ # 只读诊断中断的 Workflow
227
+ matrix workflow doctor
228
+
229
+ # 只恢复 doctor 明确报告的 transaction 或陈旧锁
230
+ matrix workflow doctor --repair --transaction <id> --strategy <continue|rollback>
231
+ matrix workflow doctor --repair --lock <id>
232
+ ```
233
+
234
+ `matrix.yaml` 仍是 workflow、orchestration、阶段、状态与 revision 的唯一事实来源。full 批准 proposal/design/plan 的精确字节;lightweight 批准紧凑 proposal,要求明确确认,并与初始化工作区基线比较,阻止先实现后补方案。Contract 漂移会阻断后续阶段。最终 Archive 仍使用只读 dry-run 与 hash-bound commit,shortcut 还要求明确确认;所有多文件 mutation 继续受持久 journal 保护。
235
+
236
+ ---
237
+
238
+ ## 工作流类型
239
+
240
+ | 类型 | 使用场景 | 阶段 |
241
+ |------|----------|------|
242
+ | **full** | 新功能、架构变更 | 全部 5 个阶段 |
243
+ | **hotfix** | 可复现的小型 Bug | 简化:open → build → verify → archive |
189
244
  | **tweak** | 有界变更,无 API/架构影响 | 简化:open → build → verify → archive |
190
245
 
191
- ---
192
-
193
- ## 特别功能:matrix-claude
194
-
195
- **默认用法**:直接使用主流程即可。无论你用 Codex 还是 Claude Code,标准流程都适用:
196
-
197
- ```
198
- $matrix → open → design → build → verify → archive
199
- ```
200
-
201
- **何时使用 `$matrix-claude`**:仅当你想**跨工具拆分工作**时 —— 用 Codex 设计,然后交给 Claude Code 实现。
202
-
203
- | 场景 | 操作 |
204
- |------|------|
205
- | 一个工具完成所有工作(默认) | 直接用 `$matrix`,无需额外步骤 |
206
- | Codex 设计 + Codex 实现 | 标准流程:design → build → verify |
207
- | Codex 设计 + Claude Code 实现 | design → `$matrix-claude` → Claude Code → verify |
208
-
209
- ### matrix-claude 工作原理
210
-
211
- 1. 设计阶段完成,守卫通过
212
- 2. 运行 `$matrix-claude` → 导出冻结的设计为 `artifacts/claude-task.md`
213
- 3. Claude Code 读取任务包并实现
214
- 4. Claude Code 在 `artifacts/verification.md` 中产生证据
215
- 5. 返回 Matrix:构建守卫 → 验证 → 归档
216
-
217
- 此 sidecar 不会改变 Matrix 状态。它只是纯粹的导出 —— 就像为另一个工具拍一张设计快照。
218
-
219
- ---
220
-
221
- ## 与 Matt Pocock Skills 的集成
222
-
223
- Matrix 设计为**在 Matt Pocock 的 skills 之上工作**,而非替代它们。以下是各阶段的详细映射:
224
-
225
- ### open 阶段
226
-
227
- | Skill | Matrix 如何使用 |
228
- |-------|-----------------|
229
- | `/grill-with-docs` | 主技能:运行 `/grilling` + `/domain-modeling` 澄清需求 |
230
- | `/grilling` | 通过连续提问压力测试计划 |
231
- | `/domain-modeling` | 建立共享词汇,创建 `CONTEXT.md` 和 ADRs |
232
-
233
- ### design 阶段(推荐顺序)
234
-
235
- | 顺序 | Skill | Matrix 如何使用 |
236
- |------|-------|-----------------|
237
- | 1 | `/domain-modeling` | 从提案中建立或精炼领域词汇 |
238
- | 2 | `/research` | 调查外部 API、文档、规范(后台运行) |
239
- | 3 | `/wayfinder` | 探索复杂代码库结构和依赖 |
240
- | 4 | `/prototype` | 用一次性实验验证设计问题 |
241
- | 5 | `/codebase-design` | 定义模块边界、接口、测试点 |
242
-
243
- ### build 阶段
244
-
245
- | Skill | Matrix 如何使用 |
246
- |-------|-----------------|
247
- | `/implement` | 主技能:执行计划,使用 TDD,运行代码审查,然后提交 |
248
- | `/tdd` | 由 `/implement` 自动调用:在确认的接缝处进行红绿重构 |
249
- | `/diagnosing-bugs` | 遇到失败时:先构建紧凑的反馈循环再修复 |
250
- | `/resolving-merge-conflicts` | 遇到合并冲突时:系统性解决 |
251
-
252
- ### verify 阶段
253
-
254
- | Skill | Matrix 如何使用 |
255
- |-------|-----------------|
256
- | `/code-review` | 双轴审查:**Standards**(编码规范)+ **Spec**(需求忠实度) |
257
- | `/improve-codebase-architecture` | 可选:扫描浅模块深化机会 |
258
-
259
- ---
260
-
261
- **关键区别**:Matt Pocock 的 skills 是独立工具。Matrix 增加了:
262
- - **状态持久化**:可承受上下文丢失
263
- - **阶段强制**:不能跳过设计直接进入构建
264
- - **证据要求**:守卫检查产物,而非断言
265
- - **转换日志**:完整的阶段变更审计记录
266
-
267
- ---
268
-
269
- ## 许可证
270
-
271
- [MIT](./LICENSE)
246
+ hotfix 与 tweak 引用同一个内部 `lightweight` 迁移 profile,只在入口和证据上区分:hotfix 要求复现、根因、回归证据;tweak 要求行为边界、diff 与范围审查证据。
247
+
248
+ ---
249
+
250
+ ## 特别功能:matrix-claude
251
+
252
+ **默认用法**:直接使用主流程即可。无论你用 Codex 还是 Claude Code,标准流程都适用:
253
+
254
+ ```
255
+ $matrix → open → design → build → verify → archive
256
+ ```
257
+
258
+ **何时使用 `$matrix-claude`**:仅当你想**跨工具拆分工作**时 —— 用 Codex 设计,然后交给 Claude Code 实现。
259
+
260
+ | 场景 | 操作 |
261
+ |------|------|
262
+ | 一个工具完成所有工作(默认) | 直接用 `$matrix`,无需额外步骤 |
263
+ | Codex 设计 + Codex 实现 | 标准流程:design → build → verify |
264
+ | Codex 设计 + Claude Code 实现 | design → build(批准 Contract)→ `$matrix-claude` → Claude Code → verify |
265
+
266
+ ### matrix-claude 工作原理
267
+
268
+ 1. 设计阶段完成,守卫通过
269
+ 2. 运行 `$matrix-claude` → 导出冻结的设计为 `artifacts/claude-task.md`
270
+ 3. Claude Code 读取任务包并实现
271
+ 4. Claude Code 在 `artifacts/verification.md` 中产生证据
272
+ 5. 返回 Matrix:构建守卫 → 验证 → 归档
273
+
274
+ 此 sidecar 不会改变 Matrix 状态。它只是纯粹的导出 —— 就像为另一个工具拍一张设计快照。
275
+
276
+ ---
277
+
278
+ ## 与 Matt Pocock Skills 的集成
279
+
280
+ Prim 使用 Matrix 自身能力。Arch 使用初始化时验证的十项原子能力:
281
+
282
+ | 阶段 | 能力 | 触发条件 |
283
+ |---|---|---|
284
+ | open | `/grilling` | 存在重大歧义或用户明确要求压力测试 |
285
+ | open/design | `/domain-modeling` | 词汇、不变量或架构决定不清晰 |
286
+ | design | `/research` | 仓库内无法获得必需的外部事实 |
287
+ | design | `/wayfinder` | 模块归属或依赖接缝未知 |
288
+ | design | `/prototype` | 重大设计问题需要一次性实验证据 |
289
+ | design | `/codebase-design` | 深模块、接口或测试接缝决定尚未完成 |
290
+ | build | `/tdd` | 可测试接缝上的可观察行为发生变化 |
291
+ | build | `/diagnosing-bugs` | 存在真实失败且根因未知 |
292
+ | build | `/resolving-merge-conflicts` | 正在发生 merge/rebase 冲突 |
293
+ | verify | `/code-review` | 需要 Standards 与 Spec 双轴证据 |
294
+
295
+ `grill-with-docs`、`implement`、`improve-codebase-architecture` 不受 Matrix 管理,也不会自动调用。用户已安装的副本会作为非受管额外 Skill 保留。companion 不得推进、提交、归档或写 Matrix 状态。
296
+
297
+ ---
298
+
299
+ **关键区别**:Matt Pocock 的 skills 是独立工具。Matrix 增加了:
300
+ - **状态持久化**:可承受上下文丢失
301
+ - **阶段强制**:full 不能跳过 Design;lightweight 不能在确认 Open Contract 前修改实现
302
+ - **证据要求**:守卫检查产物,而非断言
303
+ - **转换日志**:完整的阶段变更审计记录
304
+
305
+ ---
306
+
307
+ ## 许可证
308
+
309
+ [MIT](./LICENSE)
@@ -1,28 +1,83 @@
1
- ---
2
- name: matrix
3
- description: 启动、恢复并治理持久化的 Matrix 开发工作流。
4
- ---
5
-
1
+ ---
2
+ name: matrix
3
+ description: 启动、恢复并治理持久化的 Matrix 开发工作流。
4
+ ---
5
+
6
6
  # Matrix
7
7
 
8
- Matrix 的事实来源是当前项目的 `.matrix/`,不得从聊天记录推断阶段。
9
-
10
- 先执行:
11
-
12
- ```powershell
13
- matrix workflow inspect
14
- ```
15
-
16
- 只有当系统明确报告 `matrix` 命令不存在时,才解析当前 Matrix Skill 目录并执行:
17
-
18
- ```powershell
19
- node <matrix-skill-directory>/scripts/matrix-runtime.mjs inspect
20
- ```
21
-
22
- 若没有活动变更,为开发请求创建 kebab-case 变更 ID:
23
-
24
- ```powershell
25
- matrix workflow init <change-id> --workflow <full|hotfix|tweak> --title "<title>"
26
- ```
8
+ 以当前仓库的 `.matrix/` 为唯一状态来源;不得从聊天记录推断阶段。
27
9
 
28
- 阶段只能由 `matrix workflow transition` 推进;架构、范围或归档前必须征求用户确认。
10
+ 读取 `matrix workflow inspect` 的 `artifact_language`。规范 Markdown 标题 token 必须保持不变;面向用户的产物正文、说明和 handoff 在 `zh-CN` 时写中文,在 `en` 时写英文。
11
+
12
+ 先执行:
13
+
14
+ ```powershell
15
+ matrix workflow inspect
16
+ ```
17
+
18
+ 只有系统明确报告 `matrix` 命令不存在时,才使用当前 Matrix Skill 目录中的 bundled runtime:
19
+
20
+ ```powershell
21
+ node <matrix-skill-directory>/scripts/matrix-runtime.mjs inspect
22
+ ```
23
+
24
+ 有活动变更时,报告其 phase、冻结的 `orchestration` 以及 Arch 安装完整性,再按 Runtime 结果进入 `next_skill`。没有活动变更时,为开发请求创建简短 kebab-case ID:
25
+
26
+ ```powershell
27
+ matrix workflow init <change-id> --workflow <full|hotfix|tweak> --orchestration <prim|arch> --title "<title>"
28
+ ```
29
+
30
+ 显式模式优先,否则使用项目 `default_orchestration`。解析后的模式在整个 change 生命周期中不可切换。
31
+
32
+ ## 编排模式
33
+
34
+ - **Prim**:各阶段使用 Matrix 自身能力,不依赖 Matt Skills。
35
+ - **Arch**:仅在任务事实满足触发条件时,调用初始化阶段已验证的十项原子能力。
36
+
37
+ 两种编排模式使用已选定的 workflow profile:`full` 走 `open → design → build → verify → archive`;`hotfix` 与 `tweak` 共用内部 `lightweight` profile,走 `open → build → verify → archive`,仅证据策略不同。Arch 能力不得写 Matrix 状态、推进阶段、提交、归档或创建竞争工作流。
38
+
39
+ 正确安装的 Arch 能力执行失败时,最多允许一次同能力的 Matrix fallback,并记录失败与证据。缺失、修改或不完整的 Arch 安装必须通过 `matrix init --with-mattpocock` 修复,不得切换活动 change 到 Prim。
40
+
41
+ ## 恢复
42
+
43
+ 只能通过 Runtime 恢复,不得手工修改状态:
44
+
45
+ ```powershell
46
+ matrix workflow return design --reason design-gap
47
+ matrix workflow return build --reason verification-failed
48
+ matrix workflow return design --reason acceptance-or-design-gap
49
+ matrix workflow abort --reason <requirement-cancelled|superseded|no-longer-valuable|blocked|other>
50
+ ```
51
+
52
+ Return 会把当前 `verification.md` 轮换至按 revision 编号的证据历史。Archive 等待确认期间若验收或设计改变,只能使用 `archive -> design` 的 `acceptance-or-design-gap` Return。Abort 将终态变更移入 `.matrix/archive/`,但不会撤销工作区代码。
53
+
54
+ 任何 mutation 返回 `WORKFLOW_RECOVERY_REQUIRED` 时,停止正常阶段操作并先执行只读诊断:
55
+
56
+ ```powershell
57
+ matrix workflow doctor
58
+ ```
59
+
60
+ 不得推断恢复目标或策略,只能执行 doctor 返回的精确命令:
61
+
62
+ ```powershell
63
+ matrix workflow doctor --repair --transaction <id> --strategy <continue|rollback>
64
+ matrix workflow doctor --repair --lock <id>
65
+ ```
66
+
67
+ ## 精确 Contract
68
+
69
+ full 的 `design -> build` 会批准 proposal/design/plan;lightweight 的 `open -> build --confirmed` 只批准紧凑 proposal,并拒绝初始化后、批准前发生的项目实现改动。Contract 后续漂移都会阻断推进。
70
+
71
+ ## 可选 Claude 交接
72
+
73
+ `$matrix-claude` 只在已批准的 Build 中使用,导出同一 Contract 快照给 Claude Code。它不拥有阶段推进或验收;直接由 Codex 实现仍使用原有 Matrix 主流程。
74
+ 只有用户明确选择“Codex 设计、Claude Code 实现”时才使用,不得自动插入标准流程。
75
+
76
+ ## 规则
77
+
78
+ - 阶段只能经 `matrix workflow transition` 正向推进。
79
+ - 只能经上述明确的 `matrix workflow return` 反向推进。
80
+ - 成功 Archive 必须使用两步乐观提交:先运行 `matrix workflow archive --dry-run`,再将其精确 hash 传给 `matrix workflow archive --expect-preflight <sha256>`;不得绕过预演。
81
+ - `matrix workflow doctor` 始终只读;transaction 与陈旧锁 repair 必须显式绑定 doctor 报告的 identity,不得手工编辑或删除 `.matrix/transactions/`、`.matrix/workflow.lock`。
82
+ - 重大架构/范围决定和 archive/commit 前应暂停等待用户确认。
83
+ - shortcut 范围扩大时执行 `matrix workflow return design --reason design-gap`;Runtime 将其升级为 full。