aodw-skill 0.10.0 → 0.11.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/.aodw-next/01-core/git-discipline.md +99 -52
- package/.aodw-next/02-workflow/orca-multi-session.md +80 -0
- package/.aodw-next/02-workflow/rt-manager.md +19 -12
- package/.aodw-next/README.md +1 -1
- package/.aodw-next/manifest.yaml +8 -2
- package/.aodw-next/project.yaml +4 -0
- package/.aodw-next/skills/handover-pack/scripts/next-number.sh +1 -1
- package/.aodw-next/skills/handover-pack/templates/handover-template.md +3 -1
- package/.aodw-next/templates/dev-session-guide-template.md +20 -0
- package/.aodw-next/templates/main-session-handover-template.md +19 -0
- package/.aodw-next/templates/orca-handoff-template.md +30 -0
- package/.aodw-next/templates/rt-meta-template.yaml +2 -2
- package/.aodw-next/tools/next-rt-id.sh +39 -0
- package/.aodw-next/tools/worktree-gc.sh +260 -0
- package/bin/aodw.js +85 -8
- package/bin/commands/new.js +21 -25
- package/package.json +1 -1
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
本文件定义 AODW 工作流中必须遵守的 Git 操作规范。
|
|
4
4
|
这些规则旨在确保代码历史清晰、可回溯,并便于自动化工具检查。
|
|
5
|
+
文中以 `main` 为主分支示例,执行时用项目实际的主分支名。
|
|
5
6
|
|
|
6
7
|
> **核心原则**:AI 可以执行所有 Git 操作,但涉及不可逆操作前必须向用户明确确认,获得同意后立即执行。
|
|
7
8
|
|
|
@@ -28,8 +29,12 @@ AI 可以执行所有 Git 操作,包括提交、合并、推送、打标签、
|
|
|
28
29
|
| `git push` | 推送到哪个远程、推送内容(分支 + tag) |
|
|
29
30
|
| `git tag` | 打什么 tag、打在哪个 commit 上 |
|
|
30
31
|
| `git worktree add -b` | 创建哪个 worktree、新建哪个分支、对应哪个 RT(分支与 worktree 一起创建,见 §2.1) |
|
|
31
|
-
| `git worktree remove` | 删除哪个 worktree
|
|
32
|
-
| `git branch -d` |
|
|
32
|
+
| `git worktree remove` / `orca worktree rm` | 删除哪个 worktree、§2.6 四条核对的结果 |
|
|
33
|
+
| `git branch -d` | 删除哪个本地分支,见 §2.6 |
|
|
34
|
+
| `worktree-gc.sh --apply` | 展示当前【可删】清单并确认 §2.5 的判定规则 |
|
|
35
|
+
|
|
36
|
+
确认 `--apply` 时,确认的是 §2.5 的判定规则。脚本执行时重新判定,
|
|
37
|
+
只删当时满足 §2.6 四条核对且符合 §2.5 清理规则的工作树,并逐条打印结果。
|
|
33
38
|
|
|
34
39
|
### 确认格式规范
|
|
35
40
|
|
|
@@ -42,12 +47,12 @@ AI 可以执行所有 Git 操作,包括提交、合并、推送、打标签、
|
|
|
42
47
|
|
|
43
48
|
```
|
|
44
49
|
合并前:
|
|
45
|
-
"RT
|
|
46
|
-
|
|
50
|
+
"我准备在本 RT 工作树里以 detached HEAD 将 feature/RT-XXX-short-name 用 --no-ff 合并到项目主分支,
|
|
51
|
+
验收通过后推送主分支,再打 done-RT-XXX 标签并推送标签。要我现在执行吗?"
|
|
47
52
|
|
|
48
53
|
Worktree 清理:
|
|
49
|
-
"
|
|
50
|
-
feature/RT-XXX-short-name
|
|
54
|
+
"核对结果是 HEAD 已并入远端主分支、无未提交改动、无进程占用、该工作树也不是主目录。
|
|
55
|
+
我准备删除 .claude/worktrees/RT-XXX-short-name/ 工作树和 feature/RT-XXX-short-name 本地分支。要我现在执行吗?"
|
|
51
56
|
|
|
52
57
|
代码提交:
|
|
53
58
|
"我准备提交以下文件到 feature/RT-XXX:[文件列表],
|
|
@@ -60,7 +65,7 @@ commit message 为 'feat(stt): xxx — Refs: RT-XXX'。要我现在执行吗?"
|
|
|
60
65
|
- 创建 RT 目录和文档(在主仓库、`main` 上进行,Intake/Decision 阶段,见 §2.1)
|
|
61
66
|
- 切换到已存在的分支(`git checkout`)
|
|
62
67
|
|
|
63
|
-
>
|
|
68
|
+
> 主目录始终停在项目主分支,并快进到最新的远端主分支(见 §8 Step 3)。按 §2.1 一步创建 feature 分支与工作树,避免把开发分支检出到主目录,挡住并行 RT。
|
|
64
69
|
|
|
65
70
|
---
|
|
66
71
|
|
|
@@ -119,7 +124,7 @@ commit message 为 'feat(stt): xxx — Refs: RT-XXX'。要我现在执行吗?"
|
|
|
119
124
|
|
|
120
125
|
只有以下几类变更允许不经 feature 分支、直接提交到 main(其余一律必须走 §1.1 的 feature 分支流程):
|
|
121
126
|
|
|
122
|
-
- `RT/<id>/meta.yaml`
|
|
127
|
+
- `RT/<id>/meta.yaml` 与 `RT/index.yaml` 的关单状态回填,包括 `status` 和 `closed_at`(不改 `plan.md`/`spec.md`/代码);
|
|
123
128
|
- `git tag done-<RT-ID>` 相关的收尾提交;
|
|
124
129
|
- §9 定义的看板快照类生成产物重新生成提交;
|
|
125
130
|
- 本文件(`git-discipline.md`)及其它纯文档/规则文件的勘误。
|
|
@@ -143,19 +148,23 @@ commit message 为 'feat(stt): xxx — Refs: RT-XXX'。要我现在执行吗?"
|
|
|
143
148
|
RT 文档进 main 是安全的——它不是业务代码,不改变任何运行行为,`main` 本来就是
|
|
144
149
|
RT 台账的所在地。
|
|
145
150
|
|
|
146
|
-
修订依据(2026-08-13 实测):当天经手的 6 个 worktree 里,RT-115 全部 724 行改动
|
|
147
|
-
都是 RT 文档,却占用了一个 98M 的 worktree,还在其中留下一处与 main 分叉的未提交
|
|
148
|
-
改动,收敛时差点误删。而 RT-110 当时没建 worktree、直接在 main 上写文档,反而是对的。
|
|
149
|
-
|
|
150
|
-
⚠️ **在 main 上写 RT 文档必须随写随提交。** 同一天 RT-110 的目录在 main 工作区里
|
|
151
|
-
放了一整天未提交(`git status` 显示 `?? RT/RT-110/`),掉盘即失。
|
|
152
|
-
|
|
153
151
|
| 角色 | 路径 | 分支 |
|
|
154
152
|
|------|------|------|
|
|
155
|
-
|
|
|
156
|
-
| RT
|
|
153
|
+
| 主目录 | 项目根目录 | 项目主分支,始终快进到最新远端主分支。直接提交的例外见 §1.4 |
|
|
154
|
+
| RT 工作区(常规) | 固定在 `.claude/worktrees/RT-{seq}-{short-name}/`。将 `.claude/worktrees/` 加入 `.git/info/exclude` | `feature/RT-{seq}-{short-name}` |
|
|
155
|
+
| RT 工作区(Orca) | 由 Orca 建在仓库外 | `feature/RT-{seq}-{short-name}` |
|
|
156
|
+
|
|
157
|
+
`worktree-gc.sh` 只报告放在其他位置的工作树,不删除它们。
|
|
157
158
|
|
|
158
|
-
|
|
159
|
+
**工作树整洁规则**:
|
|
160
|
+
|
|
161
|
+
1. 一个 RT 只用一个工作树,所有返工在原工作树里完成。
|
|
162
|
+
2. 在本 RT 的工作树里以 detached HEAD 合并,见 §8 Step 2。
|
|
163
|
+
3. 关单时删除本 RT 的工作树和本地分支,见 §8 Step 3。
|
|
164
|
+
4. 除主目录外,工作树只为当前任务保留。为合并或跑基线临时建的工作树,用完即删。
|
|
165
|
+
5. 按 §2.5 巡检,删除前完成 §2.6 四条核对。
|
|
166
|
+
|
|
167
|
+
及时清理能减少遗留工作树占用的空间,也让并行任务的状态容易核对。
|
|
159
168
|
|
|
160
169
|
### 2.1 创建 Worktree(实现阶段,非立项阶段)
|
|
161
170
|
|
|
@@ -163,16 +172,17 @@ RT 台账的所在地。
|
|
|
163
172
|
decision 阶段,更不是立项当天——那时还不知道这个 RT 会不会马上做,甚至不知道
|
|
164
173
|
它最终要不要动代码。
|
|
165
174
|
|
|
166
|
-
|
|
175
|
+
先按 §2.5 巡检并完成下面的并行冲突检查。用户确认后,一步创建分支与工作树。
|
|
176
|
+
使用 Orca 的项目由 Orca 创建,其余项目从主目录执行以下命令。
|
|
167
177
|
|
|
168
178
|
```bash
|
|
169
179
|
git worktree add -b feature/RT-XXX-short-name .claude/worktrees/RT-XXX-short-name main
|
|
170
180
|
git worktree list # 验证
|
|
171
181
|
```
|
|
172
182
|
|
|
173
|
-
|
|
183
|
+
创建完成后,后续 spec、plan 和代码都在本 RT 的工作树里读写。
|
|
174
184
|
|
|
175
|
-
**并行 RT
|
|
185
|
+
**并行 RT 冲突检查(必须执行)**。可参考 `RT/index.yaml` 的登记,工作树以 `git worktree list` 为准。
|
|
176
186
|
|
|
177
187
|
```bash
|
|
178
188
|
git worktree list # 当前有哪些 worktree 活着
|
|
@@ -183,9 +193,7 @@ grep -l "^status: \(intaking\|decided\|in-progress\|reviewing\)$" RT/*/meta.yaml
|
|
|
183
193
|
`git worktree list` 里找不到对应 worktree(例如状态没有回写、worktree 已被误删),
|
|
184
194
|
必须先向用户说明这个不一致,不能假装它不存在。
|
|
185
195
|
|
|
186
|
-
|
|
187
|
-
> RT 里只有 23 个填了该字段,本条检查因此长期形同虚设——它建立在一个大多数 RT
|
|
188
|
-
> 都不填的字段上。改用下面这条直接比对实际改动文件:
|
|
196
|
+
用下面的命令比对实际改动文件,避免遗漏 `meta.yaml` 未登记的模块。
|
|
189
197
|
|
|
190
198
|
```bash
|
|
191
199
|
# 每个活跃 worktree 实际动了哪些非 RT 文档的文件
|
|
@@ -199,10 +207,6 @@ done
|
|
|
199
207
|
把新 RT 计划要改的文件与上面的输出比对。**有重叠就必须先告知用户重叠范围**,
|
|
200
208
|
由用户决定是并行做、还是等前一个合并后再开工。
|
|
201
209
|
|
|
202
|
-
实证(2026-08-13):RT-115 与 RT-111 都改了 `materialize-agentic-packs.py` 的同一段
|
|
203
|
-
`change_instruction`,两边各写了一遍。RT-111 先合并后,RT-115 那份就成了纯冗余——
|
|
204
|
-
这类重复劳动正是本检查要拦的。
|
|
205
|
-
|
|
206
210
|
### 2.2 工具隔离原则
|
|
207
211
|
|
|
208
212
|
每个 AI 工具实例(Cursor / Codex 等)只能读写自己绑定的 worktree 目录,禁止跨目录操作。多个实例可并行工作于各自的 worktree,互不干扰。
|
|
@@ -216,25 +220,53 @@ done
|
|
|
216
220
|
```bash
|
|
217
221
|
git worktree list # 查看所有 worktree
|
|
218
222
|
git worktree prune --dry-run # 检查可清理的 worktree
|
|
223
|
+
bash .aodw-next/tools/worktree-gc.sh # 只读分类,见 §2.5
|
|
219
224
|
```
|
|
220
225
|
|
|
221
|
-
### 2.5
|
|
222
|
-
|
|
223
|
-
> 背景:本项目曾出现 feature 分支开出后长期无人跟进、main 持续推进的情况(例如某分支只领先 main 1-3 个提交,却已落后 main 超过 150 个提交)。分支活得越久、漂移越大,回头合并的冲突成本越高,且没人会主动想起去检查一个"看起来还在"的 worktree 是否早已废弃。
|
|
226
|
+
### 2.5 工作树与分支巡检(必须定期执行)
|
|
224
227
|
|
|
225
|
-
|
|
228
|
+
从主目录执行以下命令。
|
|
226
229
|
|
|
227
230
|
```bash
|
|
228
|
-
git
|
|
229
|
-
|
|
230
|
-
|
|
231
|
+
git fetch origin
|
|
232
|
+
bash .aodw-next/tools/worktree-gc.sh # 默认只读
|
|
233
|
+
bash .aodw-next/tools/worktree-gc.sh --apply # 先按 §0 确认判定规则
|
|
231
234
|
```
|
|
232
235
|
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
- `
|
|
236
|
+
巡检依赖 `lsof` 检查进程的当前目录。脚本使用本地的 `origin/HEAD` 定位远端主分支,
|
|
237
|
+
没有该引用时使用 `origin/main`。两者都不可用时脚本报错退出。先运行 `git fetch origin`,
|
|
238
|
+
再用 `git remote set-head origin -a` 设置本地 `origin/HEAD`。脚本不自动 fetch。
|
|
236
239
|
|
|
237
|
-
|
|
240
|
+
- 【可删】默认目录 `.claude/worktrees/` 下通过 §2.6 核对的工作树。
|
|
241
|
+
- 【保留】主目录、内含其他已登记工作树的工作树,以及常规布局中被 `~/.claude/skills`、
|
|
242
|
+
`~/.codex/skills`、`~/.agents/skills` 或 `~/.cursor/skills` 中软链引用的工作树。
|
|
243
|
+
- 【未合入】【有未提交改动】【有进程在用】分别给出相应原因。
|
|
244
|
+
- 【仓库外/失效】只报告。默认目录外的工作树(包括 Orca 管理的工作树)附四条核对结果。
|
|
245
|
+
工作树目录已被手动删除时提示 `git worktree prune`,并继续巡检。
|
|
246
|
+
- 【主目录】报告领先、落后远端主分支的提交数以及未提交改动数。
|
|
247
|
+
- 【未合入的本地分支】【可疑分支】列出未合入的分支,以及最后提交超过 7 天或落后远端主分支超过 50 个提交的分支。
|
|
248
|
+
- 【已打完成标签但未关单】列出已有 `done-RT-xxx` 标签,但 index 或已有 meta 的状态尚未置为 `done` 的 RT。
|
|
249
|
+
|
|
250
|
+
在创建新工作树前、用户要求巡检时、关单时、部署窗口后以及关闭 Orca 等工具的会话后跑列表模式。
|
|
251
|
+
报告可疑项时附对应 RT 及其状态(如有),由用户决定后续处理。
|
|
252
|
+
|
|
253
|
+
确认 `--apply` 时,确认的是这套判定规则。执行时重新判定,只删当时满足 §2.6 四条核对、
|
|
254
|
+
位于常规布局且未受保护的工作树,并逐条打印清理结果。这可能包括其他已合入的 RT。
|
|
255
|
+
单个 RT 的关单按 §8 Step 3 清理自己的工作树。
|
|
256
|
+
|
|
257
|
+
### 2.6 删除前四条核对
|
|
258
|
+
|
|
259
|
+
删除任何工作树前,以下四条都要满足。任一条未通过就保留并报告原因。
|
|
260
|
+
|
|
261
|
+
1. 工作树 HEAD 已并入远端主分支,可用 `git merge-base --is-ancestor HEAD origin/<主分支>` 核对。
|
|
262
|
+
2. `git status --porcelain` 无未提交改动,未跟踪的 `node_modules` 除外。
|
|
263
|
+
被 `.gitignore` 忽略的文件不算改动,删除工作树时会一起删掉。
|
|
264
|
+
3. 没有进程的当前目录在这个工作树内。
|
|
265
|
+
4. 工作树不是主目录。
|
|
266
|
+
|
|
267
|
+
被 Skill 软链引用或内含其他已登记工作树的工作树继续保留。删除本地分支只用 `git branch -d`。
|
|
268
|
+
删除失败的分支会保留并报告,`worktree-gc.sh --apply` 以非 0 退出。
|
|
269
|
+
远端分支的删除由用户另行决定。
|
|
238
270
|
|
|
239
271
|
---
|
|
240
272
|
|
|
@@ -369,33 +401,48 @@ AI 或 CI 工具应检查:
|
|
|
369
401
|
### Step 2:确认合并
|
|
370
402
|
|
|
371
403
|
AI 向用户确认:
|
|
372
|
-
> "RT-XXX
|
|
404
|
+
> "RT-XXX 的知识蒸馏已完成。我准备使用 --no-ff 将 feature/RT-XXX-short-name 合并到主分支,验收后推送并打 done-RT-XXX 标签。要我现在执行吗?"
|
|
373
405
|
|
|
374
|
-
|
|
406
|
+
用户确认后,在本 RT 工作树中以 detached HEAD 合并:
|
|
375
407
|
```bash
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
git
|
|
379
|
-
git
|
|
380
|
-
git
|
|
408
|
+
trunk=main # 改为项目实际的主分支
|
|
409
|
+
merge_message_file=/path/to/merge-message.txt # 改为已写好的合并说明文件
|
|
410
|
+
git fetch origin
|
|
411
|
+
git checkout --detach "origin/$trunk"
|
|
412
|
+
git merge --no-ff -F "$merge_message_file" feature/RT-XXX-short-name
|
|
413
|
+
# 在合并结果上重跑验收,通过后再继续
|
|
414
|
+
git push origin "HEAD:refs/heads/$trunk" &&
|
|
415
|
+
git tag done-RT-XXX &&
|
|
381
416
|
git push origin done-RT-XXX
|
|
382
417
|
```
|
|
383
418
|
|
|
384
|
-
|
|
419
|
+
将合并说明写到 `merge_message_file` 指向的文件。若远端已前进导致推送被拒,重新 fetch,
|
|
420
|
+
从最新远端主分支重做 detached 合并并重新验收。禁止强推。
|
|
421
|
+
|
|
422
|
+
### Step 3:关单清理
|
|
385
423
|
|
|
386
424
|
AI 向用户确认:
|
|
387
|
-
> "RT-XXX
|
|
425
|
+
> "RT-XXX 已合并推送并打了完成标签。我准备快进主目录,核对并删除本 RT 的工作树和本地分支,再将 RT 状态更新为 done。要我现在执行吗?"
|
|
388
426
|
|
|
389
|
-
|
|
427
|
+
用户确认后,从主目录执行。快进失败时停下报告:
|
|
390
428
|
```bash
|
|
429
|
+
trunk=main # 改为项目实际的主分支
|
|
430
|
+
git fetch origin
|
|
431
|
+
git merge --ff-only "origin/$trunk"
|
|
432
|
+
# 完成 §2.6 四条核对后,按实际工作树路径删除
|
|
391
433
|
git worktree remove .claude/worktrees/RT-XXX-short-name
|
|
392
434
|
git branch -d feature/RT-XXX-short-name
|
|
393
|
-
# 更新 RT/RT-XXX/meta.yaml:status → done, closed_at → 当前时间
|
|
394
435
|
```
|
|
395
436
|
|
|
437
|
+
使用 Orca 时,从主目录用 `orca worktree rm` 删除该工作树,再用 `git branch -d` 清理仍存在的本地分支。
|
|
438
|
+
如果用 `worktree-gc.sh --apply` 清理 detached 工作树,【执行清理】会列出已合入远端主分支、
|
|
439
|
+
未被任何工作树检出的本地 `feature/` 分支。先确认本 RT 的 detached 工作树已删除,再用 `git branch -d` 删除对应分支。
|
|
440
|
+
按 §1.4 回填 `RT/RT-XXX/meta.yaml`(如有)的 `status: done`、`closed_at` 和 `RT/index.yaml` 的关单状态,
|
|
441
|
+
提交并推送。最后跑 `bash .aodw-next/tools/worktree-gc.sh`,确认主目录已同步且本 RT 没有遗留工作树或关单告警。
|
|
442
|
+
|
|
396
443
|
### Step 4:播报完成
|
|
397
444
|
|
|
398
|
-
> "RT-XXX
|
|
445
|
+
> "RT-XXX 全部完成。主分支及完成标签已推送,本 RT 的工作树和本地分支已删除,主目录已同步。"
|
|
399
446
|
|
|
400
447
|
---
|
|
401
448
|
|
|
@@ -406,6 +453,6 @@ git branch -d feature/RT-XXX-short-name
|
|
|
406
453
|
对这类"入库但内容由脚本生成"的文件,适用以下规则:
|
|
407
454
|
|
|
408
455
|
- **功能分支内不重新生成**:在 feature 分支上开发时,除非本次改动确实改变了快照的生成逻辑或字段,否则不要顺手跑生成脚本并把结果一起提交。快照内容的变化不是本次业务改动的一部分,会污染 PR diff、增加冲突面。
|
|
409
|
-
- **合并后单独重新生成**:需要刷新快照数据时,在 main 上单独执行生成脚本并提交,commit message 用 `chore(dashboard): 重新生成看板快照`,按 §1.
|
|
456
|
+
- **合并后单独重新生成**:需要刷新快照数据时,在 main 上单独执行生成脚本并提交,commit message 用 `chore(dashboard): 重新生成看板快照`,按 §1.4 例外直接提交 main。
|
|
410
457
|
- **合并前如遇快照冲突**:优先级是"以 main 上最新快照为准,废弃 feature 分支里的快照变更",冲突解决后在 main 上重新跑一次生成脚本,而不是手工合并 JSON diff。
|
|
411
458
|
- **新增此类生成文件前**:优先考虑能否像 `cases/` 一样整体 gitignore、改为部署/构建时生成;确实需要静态入库(例如前端构建时直接 import 的数据文件,没有运行时生成条件)才保留入库。
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# Orca 多会话协作
|
|
2
|
+
|
|
3
|
+
本规则适用于选择 Orca 的项目。开工前读 `06-project/dev-session-guide.md`,按 RT 流程完成立项和开工检查(见 `rt-manager.md` §3、§6)。
|
|
4
|
+
|
|
5
|
+
## 1. 用户只和主会话沟通
|
|
6
|
+
|
|
7
|
+
主会话负责立项、拆单、写任务书、开开发会话、巡查、验收、关单和对外沟通。业务代码由开发会话在自己的工作树里写。
|
|
8
|
+
|
|
9
|
+
这样用户只需跟进一个对话,主会话也能从交付目标出发独立验收。
|
|
10
|
+
|
|
11
|
+
## 2. 先推任务书,再开会话
|
|
12
|
+
|
|
13
|
+
用 `templates/orca-handoff-template.md` 写好 `RT/RT-xxx/handoff.md`。RT 文档按 `git-discipline.md` §2.0 直接在主干上提交,再推到远端主干。按项目指南填好主目录、主干和 Agent 后,用下面的命令开工作树和终端。
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
# 先填写 main_dir、trunk、agent、rt(例如 RT-123)和 short_name。
|
|
17
|
+
# 指定模型时,在命令里加 --model "$model"。
|
|
18
|
+
orca worktree create --repo "path:$main_dir" --name "$rt-$short_name" \
|
|
19
|
+
--branch "feature/$rt-$short_name" --base-branch "origin/$trunk" \
|
|
20
|
+
--no-parent --agent "$agent" --surface terminal \
|
|
21
|
+
--prompt "先读 RT/$rt/handoff.md 并照做" --json
|
|
22
|
+
orca agent list --json
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
在列表中核对本单会话为 `working`。
|
|
26
|
+
|
|
27
|
+
新工作树从远端主干起步,先推任务书才能让开发会话读到同一份交付要求。
|
|
28
|
+
|
|
29
|
+
## 3. 一单一工作树、一分支、一个可见会话
|
|
30
|
+
|
|
31
|
+
开工前确认本单已有的工作树和会话,遵循指南的在途上限。开发只能由 Orca 中可见的终端会话承担,禁止手工 `git worktree add` 或用后台无头 Agent 派开发。只读审查和调查可以在后台运行。返工时结束上一轮开发会话,在原工作树启动下一轮。开发会话不得新建或重命名工作树。
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
orca agent launch --agent "$agent" --worktree "path:$worktree_path" --surface terminal \
|
|
35
|
+
--prompt "先读 RT/$rt/handoff.md 及主会话的返工要求" --json
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
固定工作树和分支能保留本单上下文,可见会话让用户随时查看进度。
|
|
39
|
+
|
|
40
|
+
## 4. 做完、卡住、等决定时主动回报
|
|
41
|
+
|
|
42
|
+
开发会话在终端输出回执,然后立刻发给主会话,等决定时也要报告当前状态。回执分为「改了什么」「验证了什么」「没验证什么」「剩余风险」四节。验证附实际命令和关键输出,结论标【已核实】【推测】【猜测】。
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
orca orchestration send --to "$main_terminal" --type handoff \
|
|
46
|
+
--subject "$rt 回执" --body-file "$report_file"
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
发送失败时在终端注明失败原因,主会话巡查时接手。开发会话不能无声停在终端里。
|
|
50
|
+
|
|
51
|
+
及时回报能让主会话安排验收、排除阻塞或当场给出决定。
|
|
52
|
+
|
|
53
|
+
## 5. 合并、关单和巡查
|
|
54
|
+
|
|
55
|
+
验收及授权到位后,开发会话在本单工作树用 detached HEAD 合并、重跑验收并报告合并 SHA,按 `git-discipline.md` §8 执行。主会话核对合并证据,按该规则 §2.6 核对后清理工作树和已合入的分支。
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
orca worktree rm --worktree "path:$worktree_path" --force --delete-branch
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
确认工作树与分支的清理结果,按 `git-discipline.md` §8 快进主目录。若 Orca 留下已合入的本地分支,按该节用 `git branch -d` 清理,再将 `RT/index.yaml` 置 `done`。关单一致性见 `rt-manager.md` §7.2。汇报进行中任务前,先用 `orca worktree ps` 对照 `RT/index.yaml`,没有会话的注明等人、等环境或没人在做。
|
|
62
|
+
|
|
63
|
+
合并证据和关单核对能防止误删成果,也能让看板反映实际进度。
|
|
64
|
+
|
|
65
|
+
## 6. 门禁照常等待确认
|
|
66
|
+
|
|
67
|
+
开发会话到门禁时停下,将待确认的问题和当前证据发给主会话,收到明确答复后再继续。主会话在项目指南记录的用户授权范围内代答,并决定执行细节。不可恢复的删除、以用户名义对外发消息和业务口径取舍仍由用户本人确认。
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
orca orchestration send --to "$main_terminal" --type decision_gate \
|
|
71
|
+
--subject "$rt 门禁待确认" --body-file "$question_file"
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
门禁继续保留明确的确认点,主会话能收到证据并把涉及用户的决定交给用户。
|
|
75
|
+
|
|
76
|
+
## 7. 到期交接
|
|
77
|
+
|
|
78
|
+
主会话满 3 天或自动压缩满 5 次,用 `templates/main-session-handover-template.md` 写清在途 RT、后台任务、授权和下一步,再换新会话。开发会话一单一开,关单即结束。
|
|
79
|
+
|
|
80
|
+
定期交接能把正在发生的事和未完成的决定留给下一位接手者。
|
|
@@ -128,7 +128,7 @@ C(多单元、执行时间长、上下文压缩风险高的 RT)
|
|
|
128
128
|
### 3.3 执行步骤
|
|
129
129
|
1. **确认执行模式**(§ 3.2,未完成则停止)
|
|
130
130
|
2. **立项查重**(§ 3.4b,优先复用已有 RT)
|
|
131
|
-
3.
|
|
131
|
+
3. 按 §9.2 运行本地脚本生成 RT-ID
|
|
132
132
|
4. 创建 RT 目录结构(**在 main 上**,`execution_mode` 已写入 `meta.yaml`,
|
|
133
133
|
并按 §5 一次性生成必备文件;**随写随提交**,不要留在工作区未提交)
|
|
134
134
|
5. 执行交互式澄清(选项化提问;仅 Spec-Full 或范围有歧义时必问范围切割:最小可用版本是什么?哪些延后进 DI?——Constitution §1.8)
|
|
@@ -397,11 +397,14 @@ RT/RT-XXX/
|
|
|
397
397
|
|
|
398
398
|
**🚨 关键规则**:一个 RT = 一个 Worktree = 一个 Feature 分支
|
|
399
399
|
|
|
400
|
+
返工在原工作树内完成,合并也在该工作树内以 detached HEAD 进行。关单时删除该工作树和本地分支,
|
|
401
|
+
除主目录外不留常驻工作树。见 git-discipline §2.0、§2.6 和 §8。
|
|
402
|
+
|
|
400
403
|
### 6.1 worktree 按阶段创建,不在立项时创建(2026-08-13 修订)
|
|
401
404
|
|
|
402
405
|
| 阶段 | status | 在哪做 | 产物 |
|
|
403
406
|
|---|---|---|---|
|
|
404
|
-
| 立项与设计 | `intaking` / `decided` |
|
|
407
|
+
| 立项与设计 | `intaking` / `decided` | **项目主分支,随写随提交** | meta / intake / decision / spec / plan |
|
|
405
408
|
| 实现 | `in-progress` 起 | worktree + feature 分支 | 代码、测试、资源 |
|
|
406
409
|
|
|
407
410
|
判据只有一条:**要动 `RT/` 以外的文件,才建 worktree。**
|
|
@@ -410,7 +413,7 @@ RT/RT-XXX/
|
|
|
410
413
|
纯台账整理)。给这类 RT 建 worktree 是白占约 100M 磁盘,还会让并行 worktree
|
|
411
414
|
数量虚高、真正需要并行时看不清局面。
|
|
412
415
|
|
|
413
|
-
|
|
416
|
+
核心约定见 `01-core/git-discipline.md` §2.0。完整创建步骤与前置检查见该文档 §2.1。
|
|
414
417
|
|
|
415
418
|
### 6.2 建 worktree 前的三问(必答)
|
|
416
419
|
|
|
@@ -454,12 +457,15 @@ Autopilot 流程摘要:
|
|
|
454
457
|
|
|
455
458
|
### 7.2 关闭一致性检查
|
|
456
459
|
|
|
457
|
-
关闭任一 RT
|
|
460
|
+
关闭任一 RT 时,AI 必须检查:
|
|
458
461
|
|
|
459
462
|
- `meta.yaml.status`、`state.json.phase`、`rt-lite.md` 元数据行的 `status` 三者一致。
|
|
460
463
|
- Spec-Lite autopilot RT 必须具备 §5.3 的 7 件套。
|
|
461
464
|
- `rt-plan.md` 无未完成步骤,或未完成项已明确转入后续 RT。
|
|
462
465
|
- `execution-log.md` 记录最新验证命令和关闭结论。
|
|
466
|
+
- 已建工作树的 RT 按 git-discipline §8 Step 3 删除本 RT 的工作树和本地分支,并快进主目录。
|
|
467
|
+
关单时跑 `bash .aodw-next/tools/worktree-gc.sh`,确认本 RT 不在任何工作树组、
|
|
468
|
+
【未合入的本地分支】或【已打完成标签但未关单】里。
|
|
463
469
|
|
|
464
470
|
### 7.3 收口前验**目标**,不是验**改动**(2026-08-14 新增)
|
|
465
471
|
|
|
@@ -506,18 +512,19 @@ AODW 使用本地生成 RT-ID,不依赖远程服务。
|
|
|
506
512
|
|
|
507
513
|
### 9.2 生成逻辑
|
|
508
514
|
|
|
509
|
-
|
|
515
|
+
在仓库根目录执行 `bash .aodw-next/tools/next-rt-id.sh .`。
|
|
516
|
+
|
|
517
|
+
1. 取三个来源的**并集**找最大序号 `N`:
|
|
510
518
|
- `RT/` 目录下所有 `RT-XXX` 格式的目录;
|
|
511
|
-
- `RT/index.yaml` 的全部条目 id
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
冲突,返工撤号(见 RT-128 retrospective.md)。
|
|
519
|
+
- `RT/index.yaml` 的全部条目 id;
|
|
520
|
+
- 本地 Git 各 ref 历史中新增过的根目录 `RT/RT-XXX/` 路径(`git log --all --no-renames --diff-merges=separate --diff-filter=A`)。
|
|
521
|
+
|
|
522
|
+
三处一起查,才能找到只有索引条目或只在其他分支上出现的编号。
|
|
516
523
|
2. 生成新 ID:`RT-{N+1}`(补零到 3 位,如 `RT-001`, `RT-002`)
|
|
517
524
|
3. 如果生成的 ID 在**任一来源**已存在:递增序号直到找到可用 ID
|
|
518
525
|
|
|
519
526
|
### 9.3 检查清单
|
|
520
527
|
|
|
521
|
-
- [ ]
|
|
528
|
+
- [ ] 已运行 `next-rt-id.sh` 扫描目录、索引和 Git 历史
|
|
522
529
|
- [ ] 已生成 `RT-{N+1}` 格式的 ID
|
|
523
|
-
- [ ] 已确认该 ID
|
|
530
|
+
- [ ] 已确认该 ID 在三个来源中均未出现
|
package/.aodw-next/README.md
CHANGED
package/.aodw-next/manifest.yaml
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
# AODW Manifest (Level 1 metadata)
|
|
2
|
-
version: 0.
|
|
2
|
+
version: 0.11.0
|
|
3
3
|
last_updated_at: 2026-09-05T16:50:00+08:00
|
|
4
4
|
summary_preferred: true
|
|
5
5
|
|
|
@@ -38,7 +38,7 @@ rules:
|
|
|
38
38
|
|
|
39
39
|
- id: git-discipline
|
|
40
40
|
name: Git Discipline
|
|
41
|
-
description: Branching, commits, worktree
|
|
41
|
+
description: Branching, commits, confirm-gated worktree cleanup, and per-RT merge and closure.
|
|
42
42
|
path: 01-core/git-discipline.md
|
|
43
43
|
|
|
44
44
|
- id: rt-manager
|
|
@@ -46,6 +46,12 @@ rules:
|
|
|
46
46
|
description: RT lifecycle, branch rules, and mandatory checks.
|
|
47
47
|
path: 02-workflow/rt-manager.md
|
|
48
48
|
|
|
49
|
+
- id: orca-multi-session
|
|
50
|
+
name: Orca Multi-session Collaboration
|
|
51
|
+
description: Optional Orca workflow for main and development sessions and per-RT worktrees.
|
|
52
|
+
path: 02-workflow/orca-multi-session.md
|
|
53
|
+
load_when: [orca, worktree, session_handoff]
|
|
54
|
+
|
|
49
55
|
- id: spec-full-profile
|
|
50
56
|
name: Spec-Full Profile
|
|
51
57
|
description: Full specification workflow for complex changes.
|
package/.aodw-next/project.yaml
CHANGED
|
@@ -7,6 +7,10 @@ project_name: ""
|
|
|
7
7
|
# ── 以下均为**可选**声明块:不写则行为完全不变 ──────────────────────────────
|
|
8
8
|
# 这里给的是格式说明,不是实例值。接入的项目按需取消注释并填自己的值。
|
|
9
9
|
|
|
10
|
+
# ── 开发环境(可选)───────────────────────────────────────────────────────────
|
|
11
|
+
# 由 CLI 的 --dev-env 选项记录。orca 启用多会话协作模块,留空沿用标准 RT 流程。
|
|
12
|
+
# dev_env: orca
|
|
13
|
+
|
|
10
14
|
# ── 采纳溯源(可选)─────────────────────────────────────────────────────────
|
|
11
15
|
# 记录本项目的 .aodw-next/ 是从哪儿、哪个版本、什么时候拷过来的。
|
|
12
16
|
# 纯元数据:没有任何工具依据它改变行为,只为「这份规则是哪来的」可追溯。
|
|
@@ -59,7 +59,7 @@ scan_worktree() {
|
|
|
59
59
|
# (`交接/H004.md` → `"\344\272\244\346\216\245/H004.md"`),那样下面的 grep 全部落空,
|
|
60
60
|
# 历史与分支两路扫描静默失效——只剩工作区一路,正好漏掉它要防的那两类撞号事故。
|
|
61
61
|
scan_history() {
|
|
62
|
-
git -c core.quotepath=false log --all --pretty=format: --name-only --diff-filter=A -- "$DIR" 2>/dev/null \
|
|
62
|
+
git -c core.quotepath=false log --all --no-renames --pretty=format: --name-only --diff-filter=A -- "$DIR" 2>/dev/null \
|
|
63
63
|
| grep -o "$DIR/H[0-9]\{3\}" | sed "s|$DIR/||" | sed 's/^/历史 /'
|
|
64
64
|
}
|
|
65
65
|
# ③ 全部分支的当前内容(含未合并分支——已知事故 ① 正是栽在这)
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# {{PROJECT_NAME}} 开发会话指南
|
|
2
|
+
|
|
3
|
+
本项目使用 [Orca 多会话协作规则](../02-workflow/orca-multi-session.md)。按项目实际情况填写以下设置。
|
|
4
|
+
|
|
5
|
+
- 主干分支:`{{TRUNK}}`
|
|
6
|
+
- Orca 工作树根目录:项目自填
|
|
7
|
+
- 默认 Agent 和模型档:项目自填
|
|
8
|
+
- 同时在途上限:3(项目可调整)
|
|
9
|
+
- 验收与全量测试命令:项目自填
|
|
10
|
+
- 对外通知方式、发送人和授权范围:项目自填
|
|
11
|
+
|
|
12
|
+
## 主会话授权范围
|
|
13
|
+
|
|
14
|
+
默认由主会话确认提交、合并和开开发会话。遇到门禁,开发会话停下并把问题发给主会话,主会话在用户授权范围内代答。
|
|
15
|
+
|
|
16
|
+
不可恢复的删除、以用户名义对外发消息和业务口径取舍,仍须用户本人确认。
|
|
17
|
+
|
|
18
|
+
- 用户已明确授权的其他事项及限制:项目自填
|
|
19
|
+
|
|
20
|
+
开开发会话用 [任务书模板](../templates/orca-handoff-template.md),更换主会话用 [交接模板](../templates/main-session-handover-template.md)。
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# 主会话交接
|
|
2
|
+
|
|
3
|
+
- 项目、交接时间及换会话原因:项目自填
|
|
4
|
+
- 用户已确认的目标、决定与授权边界:项目自填
|
|
5
|
+
- 主目录、主干和 RT 索引位置:项目自填
|
|
6
|
+
|
|
7
|
+
## 在途 RT
|
|
8
|
+
|
|
9
|
+
| RT | 当前状态 | 工作树、分支和终端地址 | 验收证据或阻塞 | 下一步及负责人 |
|
|
10
|
+
| --- | --- | --- | --- | --- |
|
|
11
|
+
| 项目自填 | 项目自填 | 项目自填 | 项目自填 | 项目自填 |
|
|
12
|
+
|
|
13
|
+
交接前用 `orca worktree ps` 核对 RT 索引,标记会话空缺和等待原因。
|
|
14
|
+
|
|
15
|
+
## 后台任务与待办决定
|
|
16
|
+
|
|
17
|
+
- 后台任务的用途、状态、定位方式和后续处置:项目自填
|
|
18
|
+
- 等用户拍板的事项和已有选项:项目自填
|
|
19
|
+
- 新主会话优先处理的事:项目自填
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# RT-xxx 开发会话任务书
|
|
2
|
+
|
|
3
|
+
## 目标与范围
|
|
4
|
+
|
|
5
|
+
- 用户已确认的意图复述:项目自填
|
|
6
|
+
- 交付物、可改文件、禁改文件及外部环境禁区:项目自填
|
|
7
|
+
- 前置条件、依赖和真实样本:项目自填
|
|
8
|
+
|
|
9
|
+
## 开工信息
|
|
10
|
+
|
|
11
|
+
- 工作树、分支和主干:项目自填
|
|
12
|
+
- 所选 Agent、模型档及选用理由:项目自填
|
|
13
|
+
- 主会话终端地址、项目开发会话指南:项目自填
|
|
14
|
+
- 已获授权的提交、合并和推送动作:项目自填
|
|
15
|
+
|
|
16
|
+
## 验收
|
|
17
|
+
|
|
18
|
+
- 验收命令、预期输出和判据:项目自填
|
|
19
|
+
- 需要主会话确认的事项:项目自填
|
|
20
|
+
|
|
21
|
+
## 回报
|
|
22
|
+
|
|
23
|
+
做完、卡住或等待决定时,把四节回执发给主会话。
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
orca orchestration send --to "$main_terminal" --type handoff \
|
|
27
|
+
--subject "$rt 回执" --body-file "$report_file"
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
回执写清改了什么、验证了什么(命令与关键输出)、没验证什么及原因、剩余风险。结论标【已核实】【推测】【猜测】。如已合并,附合并 SHA。
|
|
@@ -38,8 +38,8 @@ status: created
|
|
|
38
38
|
# 涉及的业务/技术模块标识,来自你的模块体系(例如 orders / users / auth 等)
|
|
39
39
|
modules: []
|
|
40
40
|
|
|
41
|
-
# Git
|
|
42
|
-
#
|
|
41
|
+
# Git 分支与工作树(实现阶段创建后立即回填,见 git-discipline.md §2.1)
|
|
42
|
+
# 工作树与分支巡检(§2.5)以 git worktree list 为准。
|
|
43
43
|
branch: null # 例如 feature/RT-XXX-short-name
|
|
44
44
|
worktree: null # 例如 .claude/worktrees/RT-XXX-short-name
|
|
45
45
|
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# 取下一个可用的 RT-ID,合并目录、索引和所有本地 Git ref 三处记录。
|
|
3
|
+
# Git 路径只取根目录 RT/ 下的第一层编号,避免把嵌套夹具编号计入。
|
|
4
|
+
set -euo pipefail
|
|
5
|
+
|
|
6
|
+
root="${1:-.}"
|
|
7
|
+
cd "$root"
|
|
8
|
+
if ! git rev-parse --git-dir >/dev/null 2>&1; then
|
|
9
|
+
printf '错误:%s 不在 Git 仓库中。\n' "$root" >&2
|
|
10
|
+
exit 1
|
|
11
|
+
fi
|
|
12
|
+
|
|
13
|
+
max=0
|
|
14
|
+
note_max() { [ "$1" -gt "$max" ] && max="$1"; return 0; }
|
|
15
|
+
|
|
16
|
+
# 每个来源用一条管道取最大号;任一步失败都由 pipefail 让脚本退出,不输出编号。
|
|
17
|
+
# 来源不存在(首次使用)不算失败。
|
|
18
|
+
|
|
19
|
+
# 来源 ①:工作区里的 RT 目录
|
|
20
|
+
if [ -d RT ]; then
|
|
21
|
+
n="$(find RT -maxdepth 1 -type d -name 'RT-[0-9]*' |
|
|
22
|
+
sed -nE 's|^RT/RT-0*([0-9]+)$|\1|p' | sort -n | tail -n 1)"
|
|
23
|
+
[ -z "$n" ] || note_max "$n"
|
|
24
|
+
fi
|
|
25
|
+
|
|
26
|
+
# 来源 ②:index.yaml 里的条目(含「有条目、无目录」的合法占号)
|
|
27
|
+
if [ -f RT/index.yaml ]; then
|
|
28
|
+
n="$(sed -nE "s/^[[:space:]]*-[[:space:]]+id:[[:space:]]*[\"']?RT-0*([0-9]+)[\"']?[[:space:]]*(#.*)?$/\1/p" \
|
|
29
|
+
RT/index.yaml | sort -n | tail -n 1)"
|
|
30
|
+
[ -z "$n" ] || note_max "$n"
|
|
31
|
+
fi
|
|
32
|
+
|
|
33
|
+
# 来源 ③:**所有分支**上新增过的 RT 路径——包括还没合并的 feature 分支。
|
|
34
|
+
# `--no-renames` 将改名后的路径计为新增;`--diff-merges=separate` 计入只在合并提交里新增的路径(显式写出,不受 log.diffMerges 配置影响);`--all` 覆盖本地全部 ref。
|
|
35
|
+
n="$(git -c core.quotepath=off log --all --no-renames --diff-merges=separate --diff-filter=A --name-only --pretty=format: -- 'RT/RT-*' |
|
|
36
|
+
sed -nE 's|^RT/RT-0*([0-9]+)/.*|\1|p' | sort -n | tail -n 1)"
|
|
37
|
+
[ -z "$n" ] || note_max "$n"
|
|
38
|
+
|
|
39
|
+
printf 'RT-%03d\n' "$((max + 1))"
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# 默认只报告。--apply 清理默认工作树目录内通过全部核对的工作树。
|
|
3
|
+
set -euo pipefail
|
|
4
|
+
# 按字节解析路径,避免 macOS awk 在本地化排序下将不同中文路径判为相等。
|
|
5
|
+
export LC_ALL=C
|
|
6
|
+
apply=0
|
|
7
|
+
while [ "$#" -gt 0 ]; do
|
|
8
|
+
case "$1" in
|
|
9
|
+
--apply) apply=1; shift ;;
|
|
10
|
+
*) echo '用法:bash .aodw-next/tools/worktree-gc.sh [--apply]' >&2; exit 2 ;;
|
|
11
|
+
esac
|
|
12
|
+
done
|
|
13
|
+
base_ref="$(git symbolic-ref --quiet refs/remotes/origin/HEAD || printf '%s\n' refs/remotes/origin/main)"
|
|
14
|
+
trunk="${base_ref#refs/remotes/origin/}"
|
|
15
|
+
if ! base="$(git rev-parse --verify --quiet "${base_ref}^{commit}")"; then
|
|
16
|
+
printf '错误:无法解析 %s。请先运行 git fetch origin,再运行 git remote set-head origin -a。\n' "$base_ref" >&2
|
|
17
|
+
exit 1
|
|
18
|
+
fi
|
|
19
|
+
printf '本地 origin/%s:%s %s(未自动 fetch;需要更新时请先自行 fetch)\n' \
|
|
20
|
+
"$trunk" "$(git rev-parse --short "$base")" "$(git show -s --format=%cI "$base")"
|
|
21
|
+
tmp="$(mktemp -d "${TMPDIR:-/tmp}/aodw-worktree-gc-XXXXXX")"
|
|
22
|
+
trap 'rm -rf "$tmp"' EXIT
|
|
23
|
+
read_worktrees() {
|
|
24
|
+
local field worktree
|
|
25
|
+
paths=()
|
|
26
|
+
git worktree list --porcelain -z > "$tmp/worktrees"
|
|
27
|
+
while IFS= read -r -d '' field; do
|
|
28
|
+
case "$field" in
|
|
29
|
+
worktree\ *)
|
|
30
|
+
worktree=${field#worktree }
|
|
31
|
+
if [ -d "$worktree" ]; then worktree="$(cd -P "$worktree" && pwd -P)"; fi
|
|
32
|
+
paths[${#paths[@]}]=$worktree ;;
|
|
33
|
+
esac
|
|
34
|
+
done < "$tmp/worktrees"
|
|
35
|
+
}
|
|
36
|
+
read_worktrees
|
|
37
|
+
main=${paths[0]}
|
|
38
|
+
|
|
39
|
+
# 只读取 PID、命令名、cwd;命令失败或没有结果都不能推断为无人使用。
|
|
40
|
+
read_processes() {
|
|
41
|
+
# lsof 在 C locale 会转义中文路径,采集时保持 UTF-8,比较时仍按字节。
|
|
42
|
+
if ! LC_ALL=en_US.UTF-8 lsof -a -d cwd -Fpcn > "$tmp/cwd" || [ ! -s "$tmp/cwd" ]; then
|
|
43
|
+
echo '错误:无法取得进程 cwd,停止清理。' >&2
|
|
44
|
+
return 1
|
|
45
|
+
fi
|
|
46
|
+
}
|
|
47
|
+
read_processes
|
|
48
|
+
|
|
49
|
+
# 仅扫描顶层软链;用物理目录解析相对目标和多级软链,兼容 macOS bash 3.2。
|
|
50
|
+
IFS=: read -r -a skill_dirs <<< "${WORKTREE_GC_SKILL_DIRS-$HOME/.claude/skills:$HOME/.codex/skills:$HOME/.agents/skills:$HOME/.cursor/skills}"
|
|
51
|
+
read_skill_links() {
|
|
52
|
+
local directory link target value owner worktree
|
|
53
|
+
skill_links=(); skill_owners=()
|
|
54
|
+
if [ "${#skill_dirs[@]}" -eq 0 ]; then return 0; fi
|
|
55
|
+
for directory in "${skill_dirs[@]}"; do
|
|
56
|
+
[ -d "$directory" ] || continue
|
|
57
|
+
for link in "$directory"/* "$directory"/.[!.]* "$directory"/..?*; do
|
|
58
|
+
[ -L "$link" ] && [ -e "$link" ] || continue
|
|
59
|
+
target=$link
|
|
60
|
+
while [ -L "$target" ]; do
|
|
61
|
+
value="$(readlink "$target")"
|
|
62
|
+
case "$value" in /*) target=$value ;; *) target=${target%/*}/$value ;; esac
|
|
63
|
+
done
|
|
64
|
+
if [ -d "$target" ]; then
|
|
65
|
+
target="$(cd -P "$target" && pwd -P)"
|
|
66
|
+
else
|
|
67
|
+
target="$(cd -P "${target%/*}" && pwd -P)/${target##*/}"
|
|
68
|
+
fi
|
|
69
|
+
owner=''
|
|
70
|
+
for worktree in "${paths[@]}"; do
|
|
71
|
+
case "$target" in
|
|
72
|
+
"$worktree"|"$worktree"/*)
|
|
73
|
+
if [ "${#worktree}" -gt "${#owner}" ]; then owner=$worktree; fi ;;
|
|
74
|
+
esac
|
|
75
|
+
done
|
|
76
|
+
skill_links[${#skill_links[@]}]=$link
|
|
77
|
+
skill_owners[${#skill_owners[@]}]=$owner
|
|
78
|
+
done
|
|
79
|
+
done
|
|
80
|
+
}
|
|
81
|
+
read_skill_links
|
|
82
|
+
|
|
83
|
+
# 列表和每次删除共用同一核对,外部工作树也完整计算四条结论。
|
|
84
|
+
check_worktree() {
|
|
85
|
+
local worktree nested=''
|
|
86
|
+
if [ ! -d "$path" ]; then
|
|
87
|
+
branch='不可用'; class=5; reason='工作树目录不存在,可运行 git worktree prune'
|
|
88
|
+
return 0
|
|
89
|
+
fi
|
|
90
|
+
branch="$(git -C "$path" symbolic-ref --quiet --short HEAD || true)"
|
|
91
|
+
head="$(git -C "$path" rev-parse HEAD)"
|
|
92
|
+
merged=0; dirty=0; force=0; changes=0
|
|
93
|
+
reason='未合入'
|
|
94
|
+
if git merge-base --is-ancestor "$head" "$base"; then merged=1; reason='已合入'; fi
|
|
95
|
+
git --no-optional-locks -C "$path" status --porcelain -z --untracked-files=all > "$tmp/status"
|
|
96
|
+
while IFS= read -r -d '' entry; do
|
|
97
|
+
changes=$((changes + 1))
|
|
98
|
+
untracked=${entry#???}; untracked=${untracked%/}
|
|
99
|
+
case "$entry" in
|
|
100
|
+
'?? '*)
|
|
101
|
+
case "$untracked" in
|
|
102
|
+
node_modules/*) untracked=node_modules ;;
|
|
103
|
+
*/node_modules/*) untracked=${untracked%%/node_modules/*}/node_modules ;;
|
|
104
|
+
esac
|
|
105
|
+
case "$untracked" in node_modules|*/node_modules)
|
|
106
|
+
if [ -d "$path/$untracked" ] || [ -L "$path/$untracked" ]; then
|
|
107
|
+
force=1; continue
|
|
108
|
+
fi ;;
|
|
109
|
+
esac ;;
|
|
110
|
+
R*|?R*|C*|?C*) IFS= read -r -d '' source ;;
|
|
111
|
+
esac
|
|
112
|
+
dirty=1
|
|
113
|
+
done < "$tmp/status"
|
|
114
|
+
if [ "$dirty" -eq 1 ]; then reason="${reason}、有未提交改动";
|
|
115
|
+
elif [ "$force" -eq 1 ]; then reason="${reason}、无改动(仅有未跟踪 node_modules)";
|
|
116
|
+
else reason="${reason}、无改动"; fi
|
|
117
|
+
busy="$(awk -v root="$path" '
|
|
118
|
+
BEGIN {for (i=2; i<ARGC; i++) {roots[i]=ARGV[i]; delete ARGV[i]}}
|
|
119
|
+
/^p/ {pid=substr($0,2)} /^c/ {command=substr($0,2)}
|
|
120
|
+
/^n/ {
|
|
121
|
+
cwd=substr($0,2); owner=""
|
|
122
|
+
for (i in roots)
|
|
123
|
+
if ((cwd == roots[i] || index(cwd,roots[i] "/") == 1) &&
|
|
124
|
+
length(roots[i]) > length(owner)) owner=roots[i]
|
|
125
|
+
if (owner == root) {
|
|
126
|
+
count++
|
|
127
|
+
if (count <= 3) summary=summary (count > 1 ? "; " : "") "PID " pid " " command
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
END {if (count) printf "%d 个:%s%s", count, summary, (count > 3 ? " 等" : "")}
|
|
131
|
+
' "$tmp/cwd" "${paths[@]}")"
|
|
132
|
+
if [ -n "$busy" ]; then reason="${reason}、有进程在用(${busy})";
|
|
133
|
+
else reason="${reason}、无进程"; fi
|
|
134
|
+
keep=''
|
|
135
|
+
for ((k=0; k<${#skill_links[@]}; k++)); do
|
|
136
|
+
if [ "${skill_owners[$k]}" = "$path" ]; then
|
|
137
|
+
keep="${keep}被 Skill 软链引用:${skill_links[$k]};"
|
|
138
|
+
fi
|
|
139
|
+
done
|
|
140
|
+
class=0
|
|
141
|
+
if [ "$path" = "$main" ]; then
|
|
142
|
+
class=1; reason="${reason}、主目录"
|
|
143
|
+
else
|
|
144
|
+
reason="${reason}、不是主目录"
|
|
145
|
+
for worktree in "${paths[@]}"; do
|
|
146
|
+
case "$worktree" in
|
|
147
|
+
"$path"/*) nested="${nested}内含工作树:${worktree};" ;;
|
|
148
|
+
esac
|
|
149
|
+
done
|
|
150
|
+
case "$path" in
|
|
151
|
+
"$main"/.claude/worktrees/*)
|
|
152
|
+
if [ -n "$keep" ]; then class=1;
|
|
153
|
+
elif [ "$merged" -eq 0 ]; then class=2;
|
|
154
|
+
elif [ "$dirty" -eq 1 ]; then class=3;
|
|
155
|
+
elif [ -n "$busy" ]; then class=4; fi ;;
|
|
156
|
+
*) class=5; reason="${reason}(可由所属会话收尾)" ;;
|
|
157
|
+
esac
|
|
158
|
+
if [ -n "$nested" ]; then class=1; keep="${keep}${nested}"; fi
|
|
159
|
+
fi
|
|
160
|
+
if [ -n "$keep" ]; then reason="${reason};$keep"; fi
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
labels=('可删' '保留' '未合入' '有未提交改动' '有进程在用' '仓库外/失效')
|
|
164
|
+
lines=('' '' '' '' '' '')
|
|
165
|
+
candidates=()
|
|
166
|
+
for path in "${paths[@]}"; do
|
|
167
|
+
check_worktree
|
|
168
|
+
if [ "$path" = "$main" ]; then main_branch=${branch:-分离 HEAD}; main_changes=$changes; fi
|
|
169
|
+
if [ "$class" -eq 0 ]; then candidates[${#candidates[@]}]=$path; fi
|
|
170
|
+
lines[$class]="${lines[$class]}${path} | ${branch:-分离 HEAD} | ${reason}"$'\n'
|
|
171
|
+
done
|
|
172
|
+
for ((i=0; i<${#labels[@]}; i++)); do
|
|
173
|
+
printf '【%s】\n%s' "${labels[$i]}" "${lines[$i]}"
|
|
174
|
+
done
|
|
175
|
+
echo '【主目录】'
|
|
176
|
+
behind="$(git -C "$main" rev-list --count "HEAD..$base")"
|
|
177
|
+
ahead="$(git -C "$main" rev-list --count "$base..HEAD")"
|
|
178
|
+
printf '%s | %s | 落后 origin/%s %s 个提交、领先 origin/%s %s 个提交、未提交改动 %s 项\n' \
|
|
179
|
+
"$main" "$main_branch" "$trunk" "$behind" "$trunk" "$ahead" "$main_changes"
|
|
180
|
+
|
|
181
|
+
now="$(date +%s)"
|
|
182
|
+
unmerged=''; suspicious=''
|
|
183
|
+
git for-each-ref --format='%(refname:short)%09%(committerdate:unix)%09%(committerdate:iso8601)' refs/heads/ > "$tmp/branches"
|
|
184
|
+
while IFS=$'\t' read -r branch timestamp date; do
|
|
185
|
+
[ "$branch" != "$trunk" ] || continue
|
|
186
|
+
if ! git merge-base --is-ancestor "refs/heads/$branch" "$base"; then
|
|
187
|
+
unmerged="${unmerged}${branch} | 最后提交 ${date}"$'\n'
|
|
188
|
+
fi
|
|
189
|
+
behind="$(git rev-list --count "refs/heads/$branch..$base")"
|
|
190
|
+
if [ "$((now - timestamp))" -gt 604800 ] || [ "$behind" -gt 50 ]; then
|
|
191
|
+
suspicious="${suspicious}${branch} | 最后提交 ${date} | 落后 origin/${trunk} ${behind} 个提交"$'\n'
|
|
192
|
+
fi
|
|
193
|
+
done < "$tmp/branches"
|
|
194
|
+
printf '【未合入的本地分支】\n%s【可疑分支】\n%s' "$unmerged" "$suspicious"
|
|
195
|
+
|
|
196
|
+
echo '【已打完成标签但未关单】'
|
|
197
|
+
index="$main/RT/index.yaml"
|
|
198
|
+
[ -f "$index" ] || index=/dev/null
|
|
199
|
+
awk '
|
|
200
|
+
/^[[:space:]]*-[[:space:]]+id:[[:space:]]*/ {
|
|
201
|
+
id=$0; sub(/^.*id:[[:space:]]*/,"",id); sub(/[[:space:]]*(#.*)?$/, "", id)
|
|
202
|
+
gsub(/^["\047]|["\047]$/, "", id)
|
|
203
|
+
}
|
|
204
|
+
/^[[:space:]]*status:[[:space:]]*/ {
|
|
205
|
+
s=$0; sub(/^.*status:[[:space:]]*/,"",s); sub(/[[:space:]]*(#.*)?$/, "", s)
|
|
206
|
+
if (id != "") print id "\t" s
|
|
207
|
+
}
|
|
208
|
+
' "$index" > "$tmp/statuses"
|
|
209
|
+
git tag --list 'done-RT-*' > "$tmp/tags"
|
|
210
|
+
while IFS= read -r tag; do
|
|
211
|
+
[[ "$tag" =~ ^done-RT-[0-9]+$ ]] || continue
|
|
212
|
+
id=${tag#done-}
|
|
213
|
+
index_status="$(awk -F '\t' -v id="$id" '$1 == id {print $2}' "$tmp/statuses")"
|
|
214
|
+
meta_status='无 meta'; meta="$main/RT/$id/meta.yaml"
|
|
215
|
+
if [ -f "$meta" ]; then
|
|
216
|
+
meta_status="$(awk '/^[[:space:]]*status:[[:space:]]*/ {
|
|
217
|
+
sub(/^.*status:[[:space:]]*/, ""); sub(/[[:space:]]*(#.*)?$/, ""); print; exit
|
|
218
|
+
}' "$meta")"
|
|
219
|
+
fi
|
|
220
|
+
if [ "$index_status" != done ] || { [ -f "$meta" ] && [ "$meta_status" != done ]; }; then
|
|
221
|
+
printf '%s | index: %s | meta: %s\n' "$id" "${index_status:-未登记}" "${meta_status:-未登记}"
|
|
222
|
+
fi
|
|
223
|
+
done < "$tmp/tags"
|
|
224
|
+
|
|
225
|
+
failed=0
|
|
226
|
+
if [ "$apply" -eq 1 ]; then
|
|
227
|
+
echo '【执行清理】'
|
|
228
|
+
# bash 3.2 的 nounset 不接受空数组展开。
|
|
229
|
+
if [ "${#candidates[@]}" -gt 0 ]; then
|
|
230
|
+
for path in "${candidates[@]}"; do
|
|
231
|
+
read_processes
|
|
232
|
+
read_worktrees
|
|
233
|
+
read_skill_links
|
|
234
|
+
check_worktree
|
|
235
|
+
if [ "$class" -ne 0 ]; then echo "跳过:${path} | ${reason}"; continue; fi
|
|
236
|
+
options=(remove)
|
|
237
|
+
if [ "$force" -eq 1 ]; then options=(remove --force); fi
|
|
238
|
+
if git worktree "${options[@]}" "$path" > "$tmp/delete" 2>&1; then
|
|
239
|
+
echo "已删除工作树:${path}"
|
|
240
|
+
if [ -n "$branch" ]; then
|
|
241
|
+
if git branch -d "$branch" > "$tmp/delete" 2>&1; then
|
|
242
|
+
echo "已删除本地分支:${branch}"
|
|
243
|
+
else
|
|
244
|
+
echo "本地分支删除失败(保留,不强删):${branch}"
|
|
245
|
+
cat "$tmp/delete"; failed=1
|
|
246
|
+
fi
|
|
247
|
+
fi
|
|
248
|
+
else
|
|
249
|
+
echo "工作树删除失败(保留分支):${path}"
|
|
250
|
+
cat "$tmp/delete"; failed=1
|
|
251
|
+
fi
|
|
252
|
+
done
|
|
253
|
+
fi
|
|
254
|
+
merged_branches="$(git for-each-ref --merged="$base" \
|
|
255
|
+
--format='%(if)%(worktreepath)%(then)%(else)%(refname:lstrip=2)%(end)' refs/heads/feature/ | sed '/^$/d')"
|
|
256
|
+
if [ -n "$merged_branches" ]; then
|
|
257
|
+
printf '已合入、未被任何工作树检出的本地分支:\n%s\n先确认本 RT 的 detached 工作树已删除,再用 git branch -d 删除对应分支。\n' "$merged_branches"
|
|
258
|
+
fi
|
|
259
|
+
fi
|
|
260
|
+
exit "$failed"
|
package/bin/aodw.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { spawnSync } from 'child_process';
|
|
4
|
+
import { Command, Option } from 'commander';
|
|
4
5
|
import inquirer from 'inquirer';
|
|
5
6
|
import chalk from 'chalk';
|
|
6
7
|
import fs from 'fs-extra';
|
|
@@ -65,6 +66,14 @@ function getSourcePaths() {
|
|
|
65
66
|
|
|
66
67
|
const { SOURCE_CORE, SOURCE_ADAPTERS } = getSourcePaths();
|
|
67
68
|
const SOURCE_TEMPLATE = path.join(SOURCE_CORE, 'templates/aodw-kernel-loader-template.md');
|
|
69
|
+
const ORCA_RULE = '02-workflow/orca-multi-session.md';
|
|
70
|
+
const ORCA_GUIDE = '06-project/dev-session-guide.md';
|
|
71
|
+
const ORCA_FILES = [
|
|
72
|
+
ORCA_RULE,
|
|
73
|
+
'templates/orca-handoff-template.md',
|
|
74
|
+
'templates/dev-session-guide-template.md',
|
|
75
|
+
'templates/main-session-handover-template.md'
|
|
76
|
+
];
|
|
68
77
|
|
|
69
78
|
program
|
|
70
79
|
.version(packageJson.version)
|
|
@@ -155,16 +164,17 @@ async function isTemplateFile(filePath) {
|
|
|
155
164
|
}
|
|
156
165
|
|
|
157
166
|
// Helper: Smart copy that preserves user-generated files
|
|
158
|
-
async function copyCoreWithPreservation(sourceDir, targetDir, isUpdate
|
|
167
|
+
async function copyCoreWithPreservation(sourceDir, targetDir, isUpdate, excluded) {
|
|
159
168
|
const entries = await fs.readdir(sourceDir, { withFileTypes: true });
|
|
160
169
|
|
|
161
170
|
for (const entry of entries) {
|
|
162
171
|
const srcPath = path.join(sourceDir, entry.name);
|
|
172
|
+
if (excluded.has(srcPath)) continue;
|
|
163
173
|
const destPath = path.join(targetDir, entry.name);
|
|
164
174
|
|
|
165
175
|
if (entry.isDirectory()) {
|
|
166
176
|
await fs.ensureDir(destPath);
|
|
167
|
-
await copyCoreWithPreservation(srcPath, destPath, isUpdate);
|
|
177
|
+
await copyCoreWithPreservation(srcPath, destPath, isUpdate, excluded);
|
|
168
178
|
} else {
|
|
169
179
|
// Check if this is a user-generated file
|
|
170
180
|
if (isUserGeneratedFile(destPath, targetDir)) {
|
|
@@ -203,7 +213,7 @@ async function returnToMenu() {
|
|
|
203
213
|
}]);
|
|
204
214
|
}
|
|
205
215
|
|
|
206
|
-
async function runInit() {
|
|
216
|
+
async function runInit({ devEnv, updating = false } = {}) {
|
|
207
217
|
console.log(chalk.blue('🚀 正在初始化 AODW-Next...'));
|
|
208
218
|
|
|
209
219
|
// --- Safeguard: Prevent running in AODW-Next Source Repo ---
|
|
@@ -290,16 +300,51 @@ async function runInit() {
|
|
|
290
300
|
}
|
|
291
301
|
]);
|
|
292
302
|
|
|
303
|
+
if (devEnv === undefined) {
|
|
304
|
+
const previous = existingProjectConfig.dev_env;
|
|
305
|
+
if (previous === 'orca' || previous === 'none') {
|
|
306
|
+
devEnv = previous;
|
|
307
|
+
} else if (!updating) {
|
|
308
|
+
({ devEnv } = await inquirer.prompt([{
|
|
309
|
+
type: 'list',
|
|
310
|
+
name: 'devEnv',
|
|
311
|
+
message: '请选择开发环境:',
|
|
312
|
+
choices: [
|
|
313
|
+
{ name: 'Orca 多会话协作', value: 'orca' },
|
|
314
|
+
{ name: '其他', value: 'none' }
|
|
315
|
+
],
|
|
316
|
+
default: 'none'
|
|
317
|
+
}]));
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
const useOrca = devEnv === 'orca';
|
|
321
|
+
|
|
293
322
|
// 1. Install Core Rules (channel-aware core dir)
|
|
294
323
|
const targetCore = path.join(process.cwd(), CORE_DIRNAME);
|
|
295
324
|
const isUpdate = fs.existsSync(targetCore);
|
|
325
|
+
const excluded = new Set(useOrca ? [] : ORCA_FILES.map(file => path.join(SOURCE_CORE, file)));
|
|
296
326
|
|
|
297
327
|
if (isUpdate) {
|
|
298
328
|
console.log(chalk.blue('正在更新核心规则(保留用户生成的文件)...'));
|
|
299
|
-
await copyCoreWithPreservation(SOURCE_CORE, targetCore, true);
|
|
329
|
+
await copyCoreWithPreservation(SOURCE_CORE, targetCore, true, excluded);
|
|
300
330
|
} else {
|
|
301
331
|
console.log(chalk.blue('正在安装核心规则...'));
|
|
302
|
-
await fs.copy(SOURCE_CORE, targetCore);
|
|
332
|
+
await fs.copy(SOURCE_CORE, targetCore, { filter: source => !excluded.has(source) });
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
// 开发环境说明只留在源模板,安装产物保留原有 YAML 字节和注释。
|
|
336
|
+
const projectConfigPath = path.join(targetCore, 'project.yaml');
|
|
337
|
+
const projectConfig = (await fs.readFile(projectConfigPath, 'utf8'))
|
|
338
|
+
.replace(/^# ── 开发环境(可选).*\n(?:# .+\n)+\n/m, '');
|
|
339
|
+
await fs.writeFile(projectConfigPath, useOrca ? projectConfig + 'dev_env: orca\n' : projectConfig, 'utf8');
|
|
340
|
+
|
|
341
|
+
if (!useOrca) {
|
|
342
|
+
const manifestPath = path.join(targetCore, 'manifest.yaml');
|
|
343
|
+
const manifest = await fs.readFile(manifestPath, 'utf8');
|
|
344
|
+
await fs.writeFile(manifestPath, manifest.replace(/^ - id: orca-multi-session\n(?: .+\n)+\n/m, ''), 'utf8');
|
|
345
|
+
if (existingProjectConfig.dev_env === 'orca') {
|
|
346
|
+
for (const file of ORCA_FILES) await fs.remove(path.join(targetCore, file));
|
|
347
|
+
}
|
|
303
348
|
}
|
|
304
349
|
|
|
305
350
|
// 2. Initialize project files from templates (for both init and update)
|
|
@@ -344,6 +389,20 @@ async function runInit() {
|
|
|
344
389
|
console.log(chalk.gray(' • 项目文件已存在且为用户内容,跳过初始化'));
|
|
345
390
|
}
|
|
346
391
|
|
|
392
|
+
const guidePath = path.join(targetCore, ORCA_GUIDE);
|
|
393
|
+
if (useOrca && !fs.existsSync(guidePath)) {
|
|
394
|
+
const gitOptions = { encoding: 'utf8' };
|
|
395
|
+
const remoteHead = spawnSync('git', ['symbolic-ref', '--quiet', 'refs/remotes/origin/HEAD'], gitOptions).stdout?.trim();
|
|
396
|
+
const trunkRefs = ['refs/remotes/origin/main', 'refs/remotes/origin/master', 'refs/heads/main', 'refs/heads/master'];
|
|
397
|
+
const refs = spawnSync('git', ['for-each-ref', '--format=%(refname)', ...trunkRefs], gitOptions).stdout?.split('\n') || [];
|
|
398
|
+
const trunkRef = remoteHead || trunkRefs.find(ref => refs.includes(ref)) ||
|
|
399
|
+
spawnSync('git', ['symbolic-ref', '--quiet', 'HEAD'], gitOptions).stdout?.trim();
|
|
400
|
+
const trunk = trunkRef?.replace(/^refs\/(remotes\/origin|heads)\//, '') || 'main';
|
|
401
|
+
const template = await fs.readFile(path.join(targetCore, 'templates/dev-session-guide-template.md'), 'utf8');
|
|
402
|
+
const guide = template.replace(/\{\{(PROJECT_NAME|TRUNK)\}\}/g, (_, key) => key === 'PROJECT_NAME' ? projectName : trunk);
|
|
403
|
+
await fs.writeFile(guidePath, guide, 'utf8');
|
|
404
|
+
}
|
|
405
|
+
|
|
347
406
|
// 3. Install Adapters based on selected platforms
|
|
348
407
|
console.log(chalk.blue('正在安装适配器...'));
|
|
349
408
|
|
|
@@ -431,6 +490,22 @@ async function runInit() {
|
|
|
431
490
|
}
|
|
432
491
|
}
|
|
433
492
|
|
|
493
|
+
if (useOrca) {
|
|
494
|
+
const platformEntries = {
|
|
495
|
+
cursor: ['.cursor/rules/aodw-next.mdc'],
|
|
496
|
+
antigravity: ['.agent/rules/aodw-next.md'],
|
|
497
|
+
claude: ['.claude/CLAUDE.md'],
|
|
498
|
+
openclaw: ['AGENTS.md', 'SKILL.md']
|
|
499
|
+
};
|
|
500
|
+
for (const platform of platforms) {
|
|
501
|
+
const prefix = platform === 'cursor' ? '@' : '';
|
|
502
|
+
const reference = `\n本项目用 Orca 多会话协作。先读 ${prefix}${CORE_DIRNAME}/${ORCA_RULE} 和 ${prefix}${CORE_DIRNAME}/${ORCA_GUIDE}\n`;
|
|
503
|
+
for (const entry of platformEntries[platform]) {
|
|
504
|
+
if (fs.existsSync(entry)) await fs.appendFile(entry, reference, 'utf8');
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
|
|
434
509
|
// 4. Enable v0 guard hook automatically in user project
|
|
435
510
|
await enableGuardHook({ silent: true });
|
|
436
511
|
|
|
@@ -441,7 +516,7 @@ async function runInit() {
|
|
|
441
516
|
await printProjectInitPrompt({ writeFile: true });
|
|
442
517
|
}
|
|
443
518
|
|
|
444
|
-
async function runUpdate() {
|
|
519
|
+
async function runUpdate(options) {
|
|
445
520
|
// 升级保护:先备份现有规范目录,再执行更新(copyCoreWithPreservation 仅保留
|
|
446
521
|
// 06-project/ 与 tools-status.yaml,改过核心规则的项目需靠备份找回定制)
|
|
447
522
|
const targetCore = path.join(process.cwd(), CORE_DIRNAME);
|
|
@@ -454,7 +529,7 @@ async function runUpdate() {
|
|
|
454
529
|
console.log(chalk.yellow(' 若本项目定制过核心规则,请在升级后 diff 备份目录找回定制。'));
|
|
455
530
|
}
|
|
456
531
|
console.log(chalk.blue('🔄 正在更新 AODW-Next...'));
|
|
457
|
-
await runInit();
|
|
532
|
+
await runInit({ ...options, updating: true });
|
|
458
533
|
}
|
|
459
534
|
|
|
460
535
|
async function runUninstall() {
|
|
@@ -717,11 +792,13 @@ async function showMainMenu() {
|
|
|
717
792
|
program
|
|
718
793
|
.command('init')
|
|
719
794
|
.description('Initialize AODW-Next')
|
|
795
|
+
.addOption(new Option('--dev-env <environment>', '开发环境,跳过提问').choices(['orca', 'none']))
|
|
720
796
|
.action(runInit);
|
|
721
797
|
|
|
722
798
|
program
|
|
723
799
|
.command('update')
|
|
724
800
|
.description('Update AODW-Next')
|
|
801
|
+
.addOption(new Option('--dev-env <environment>', '覆盖已记录的开发环境').choices(['orca', 'none']))
|
|
725
802
|
.action(runUpdate);
|
|
726
803
|
|
|
727
804
|
program
|
package/bin/commands/new.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { spawnSync } from 'child_process';
|
|
1
2
|
import fs from 'fs-extra';
|
|
2
3
|
import path from 'path';
|
|
3
4
|
import { fileURLToPath } from 'url';
|
|
@@ -43,29 +44,6 @@ function getProjectName() {
|
|
|
43
44
|
return path.basename(process.cwd());
|
|
44
45
|
}
|
|
45
46
|
|
|
46
|
-
function getLocalMaxSeq() {
|
|
47
|
-
const rtDir = path.join(process.cwd(), 'RT');
|
|
48
|
-
if (!fs.existsSync(rtDir)) return 0;
|
|
49
|
-
|
|
50
|
-
const dirs = fs.readdirSync(rtDir);
|
|
51
|
-
let maxSeq = 0;
|
|
52
|
-
|
|
53
|
-
for (const dir of dirs) {
|
|
54
|
-
const match = dir.match(/^RT-(\d+)$/);
|
|
55
|
-
if (match) {
|
|
56
|
-
const seq = parseInt(match[1], 10);
|
|
57
|
-
if (seq > maxSeq) maxSeq = seq;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
return maxSeq;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
function getLocalNextId() {
|
|
65
|
-
const maxSeq = getLocalMaxSeq();
|
|
66
|
-
return `RT-${String(maxSeq + 1).padStart(3, '0')}`;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
47
|
const EXECUTION_MODES = ['collaborative', 'autopilot'];
|
|
70
48
|
|
|
71
49
|
async function resolveExecutionMode(options) {
|
|
@@ -101,6 +79,14 @@ async function resolveExecutionMode(options) {
|
|
|
101
79
|
}
|
|
102
80
|
|
|
103
81
|
export async function createNewRT(options) {
|
|
82
|
+
const root = spawnSync('git', ['rev-parse', '--show-toplevel'], { encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] });
|
|
83
|
+
if (root.status !== 0) {
|
|
84
|
+
console.error(chalk.red('错误:请在 Git 工作树里创建 RT。'));
|
|
85
|
+
process.exitCode = 1;
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
process.chdir(root.stdout.replace(/\r?\n$/, ''));
|
|
89
|
+
|
|
104
90
|
// Determine Project Name: Flag > Config/Package/Dir
|
|
105
91
|
const project = options.project || getProjectName();
|
|
106
92
|
|
|
@@ -118,8 +104,18 @@ export async function createNewRT(options) {
|
|
|
118
104
|
|
|
119
105
|
const executionMode = await resolveExecutionMode(options);
|
|
120
106
|
|
|
121
|
-
//
|
|
122
|
-
const
|
|
107
|
+
// 从 CLI 包取脚本,老项目无需先安装新版内核。
|
|
108
|
+
const binDir = path.dirname(fileURLToPath(import.meta.url));
|
|
109
|
+
const packagedScript = path.join(binDir, '../../.aodw-next/tools/next-rt-id.sh');
|
|
110
|
+
const script = fs.existsSync(packagedScript) ? packagedScript :
|
|
111
|
+
path.join(binDir, '../../../templates/.aodw-next/tools/next-rt-id.sh');
|
|
112
|
+
const result = spawnSync('bash', [script, '.'], { encoding: 'utf8', stdio: ['ignore', 'pipe', 'inherit'] });
|
|
113
|
+
if (result.status !== 0) {
|
|
114
|
+
console.error(chalk.red('错误:next-rt-id.sh 开号失败,未创建 RT。'));
|
|
115
|
+
process.exitCode = 1;
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
const id = result.stdout.trim();
|
|
123
119
|
console.log(chalk.yellow(`Using local ID generation: ${id}`));
|
|
124
120
|
|
|
125
121
|
// Create Directory
|