Skip to content

Commit c013be6

Browse files
authored
feat: support dirty worktree recovery
2 parents cc84938 + 0bfa9b5 commit c013be6

16 files changed

Lines changed: 224 additions & 26 deletions

File tree

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,20 @@
22

33
All notable changes to @rpamis/comet will be documented in this file.
44

5+
## What's Changed [0.3.0] - 2026-05-25
6+
7+
### Added
8+
9+
- **Dirty worktree recovery protocol**: Added shared English and Chinese `comet/reference/dirty-worktree.md` references so agents consistently protect, inspect, and attribute user or mixed-source working tree changes during resume
10+
11+
### Changed
12+
13+
- **Comet resume behavior**: Updated `/comet`, build, verify, hotfix, and tweak skills so manual code edits made during interruptions are treated as code evidence, not automatic state transitions; agents must attribute dirty worktree changes before continuing or advancing guards
14+
15+
### Fixed
16+
17+
- **Reference skill installation**: Added the dirty worktree reference file to the Comet manifest so installed English and Chinese skill sets can resolve `comet/reference/dirty-worktree.md`
18+
519
## What's Changed [0.2.9] - 2026-05-24
620

721
### Changed

assets/manifest.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"version": "0.2.6",
33
"skills": [
44
"comet/SKILL.md",
5+
"comet/reference/dirty-worktree.md",
56
"comet/scripts/comet-guard.sh",
67
"comet/scripts/comet-state.sh",
78
"comet/scripts/comet-handoff.sh",

assets/skills-zh/comet-build/SKILL.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,8 @@ Build 是最长阶段,可能跨越大量任务。为支持上下文压缩后
158158

159159
- **每完成一个 task**:立即勾选 tasks.md 并提交代码,确保 `.comet.yaml` 和文件状态持久化
160160
- **上下文压缩后恢复**:读取 `.comet.yaml``phase` 字段确认仍在 build 阶段,读取 plan 文件头的 `base-ref`,再读取 tasks.md 找到下一个未勾选任务继续执行
161+
- **用户手动修改恢复**:按 `comet/reference/dirty-worktree.md` 协议处理未提交改动。该协议定义了检查步骤、归因分类和禁令。build 阶段的特殊处理:
162+
1. 归因后,若 diff 暗示计划或 spec 已变化,按 Step 5「Spec 增量更新」分级处理
161163
- **长任务拆分**:单任务超过 200 行代码变更时,考虑拆分为多个子任务分别提交
162164

163165
## 退出条件

assets/skills-zh/comet-hotfix/SKILL.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ bash "$COMET_GUARD" <change-name> open --apply
6363

6464
使用 hotfix 默认值:`build_mode: direct`。跳过 `superpowers:brainstorming``superpowers:writing-plans`(除非任务 > 3 个;若超过 3 个任务,转入 `/comet-build` 的计划与执行方式选择)。
6565

66+
继续或开始修改前,按 `comet/reference/dirty-worktree.md` 协议处理未提交改动。若归因后发现修复范围超出 hotfix,按本文件“升级条件”处理。
67+
6668
**立即执行:** 按 tasks.md 逐个执行任务:
6769

6870
1. 读取 `openspec/changes/<name>/tasks.md`,获取未完成任务列表

assets/skills-zh/comet-tweak/SKILL.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ bash "$COMET_GUARD" <change-name> open --apply
6666

6767
使用 tweak 默认值:`build_mode: direct`。跳过 `superpowers:brainstorming``superpowers:writing-plans`
6868

69+
继续或开始修改前,按 `comet/reference/dirty-worktree.md` 协议处理未提交改动。若归因后发现范围超出 tweak,按本文件“升级条件”处理。
70+
6971
**立即执行:** 按 tasks.md 逐个执行任务:
7072

7173
1. 读取 `openspec/changes/<name>/tasks.md`,获取未完成任务列表

assets/skills-zh/comet-verify/SKILL.md

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ description: "Comet 阶段 4:验证与收尾。用 /comet-verify 调用。验
2020
COMET_SEARCH_ROOTS=("." "$HOME/.claude/skills" "$HOME/.codex/skills" "$HOME/.cursor/skills")
2121
COMET_STATE="${COMET_STATE:-$(find "${COMET_SEARCH_ROOTS[@]}" -path '*/comet/scripts/comet-state.sh' -type f -print -quit 2>/dev/null)}"
2222
COMET_GUARD="${COMET_GUARD:-$(find "${COMET_SEARCH_ROOTS[@]}" -path '*/comet/scripts/comet-guard.sh' -type f -print -quit 2>/dev/null)}"
23-
bash "$COMET_STATE" check <name> verify
23+
bash "$COMET_STATE" check <change-name> verify
2424
```
2525

2626
验证通过后继续 Step 1。验证失败时脚本会输出具体失败原因。
@@ -30,31 +30,43 @@ bash "$COMET_STATE" check <name> verify
3030
执行规模评估:
3131

3232
```bash
33-
bash "$COMET_STATE" scale <name>
33+
bash "$COMET_STATE" scale <change-name>
3434
```
3535

3636
脚本自动统计任务数、增量规格数、变更文件数,判断使用 light 或 full 验证模式,并设置 verify_mode 字段。
3737

38+
验证开始前,按 `comet/reference/dirty-worktree.md` 协议检查并处理未提交改动。verify 阶段的特殊处理:
39+
40+
1. 若 dirty diff 属于当前 change 且涉及实现、测试、tasks、delta spec 或 design doc 变更,不在 verify 阶段直接修复或提交;先记录失败并回退到 build 阶段
41+
2. 若 dirty diff 只是 verify 本阶段产物(例如验证报告草稿、分支处理记录),可继续在 verify 阶段完成并记录状态
42+
3. 若 dirty diff 已实现但 tasks.md 未勾选,视为 build 状态滞后;先记录失败并回退到 build 阶段,由 `/comet-build` 验证实现、补勾任务并提交
43+
44+
回退到 build 阶段:
45+
46+
```bash
47+
bash "$COMET_STATE" transition <change-name> verify-fail
48+
```
49+
3850
注意:如果 build 阶段每个任务都已提交,脚本基于工作区 diff 的文件数可能低估改动规模。此时必须读取 plan 文件头的 `base-ref` 并用提交区间复核:
3951

4052
```bash
41-
PLAN=$(bash "$COMET_STATE" get <name> plan)
53+
PLAN=$(bash "$COMET_STATE" get <change-name> plan)
4254
BASE_REF=$(grep '^base-ref:' "$PLAN" 2>/dev/null | head -1 | sed 's/^base-ref: *//')
4355
git diff --stat "$BASE_REF"...HEAD
4456
```
4557

4658
若提交区间显示改动超过轻量阈值(> 5 个文件、跨模块协调、或 delta spec 超过 1 个 capability),手动设置为完整验证:
4759

4860
```bash
49-
bash "$COMET_STATE" set <name> verify_mode full
61+
bash "$COMET_STATE" set <change-name> verify_mode full
5062
```
5163

5264
### 2a. 轻量验证(小改动)
5365

5466
当规模评估结果为"小"时,跳过 `openspec-verify-change`,直接执行以下检查:
5567

5668
1. tasks.md 全部任务已完成 `[x]`
57-
2. 改动文件与 tasks.md 描述一致(`git diff --stat` 对照 tasks 内容)
69+
2. 改动文件与 tasks.md 描述一致(`git diff --stat` / `git diff --cached --stat` / `git diff --stat <base-ref>...HEAD` 对照 tasks 内容)
5870
3. 编译通过(执行项目对应的构建命令,如 `npm run build``mvn compile``cargo build` 等)
5971
4. 相关测试通过
6072
5. 无明显安全问题(无硬编码密钥、无新增 unsafe 操作)
@@ -64,7 +76,7 @@ bash "$COMET_STATE" set <name> verify_mode full
6476
**不通过时**:报告失败项,记录失败并回退到 build 阶段,然后调用 `/comet-build` 修复。
6577

6678
```bash
67-
bash "$COMET_STATE" transition <name> verify-fail
79+
bash "$COMET_STATE" transition <change-name> verify-fail
6880
```
6981

7082
**报告格式**:简表列出 5 项检查结果 + PASS/FAIL。
@@ -93,7 +105,7 @@ bash "$COMET_STATE" transition <name> verify-fail
93105
验证不通过时:报告缺失项,记录失败并回退到 build 阶段,然后调用 `/comet-build` 补充。
94106

95107
```bash
96-
bash "$COMET_STATE" transition <name> verify-fail
108+
bash "$COMET_STATE" transition <change-name> verify-fail
97109
```
98110

99111
**Spec 漂移处理**
@@ -127,8 +139,8 @@ mkdir -p docs/superpowers/reports
127139
# 将本次验证结论写入报告文件,例如:
128140
# docs/superpowers/reports/YYYY-MM-DD-<change-name>-verify.md
129141

130-
bash "$COMET_STATE" set <name> verification_report docs/superpowers/reports/YYYY-MM-DD-<change-name>-verify.md
131-
bash "$COMET_STATE" set <name> branch_status handled
142+
bash "$COMET_STATE" set <change-name> verification_report docs/superpowers/reports/YYYY-MM-DD-<change-name>-verify.md
143+
bash "$COMET_STATE" set <change-name> branch_status handled
132144
```
133145

134146
## 退出条件

assets/skills-zh/comet/SKILL.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ agent 做决策只需读本节,参考附录按需查阅。
5252

5353
**断点恢复规则**
5454
- 每次恢复上下文时,先重新执行 Step 0 和 Step 1,不依赖对话历史判断阶段
55+
- 只要存在 active change 且工作区有未提交改动,必须按 `comet/reference/dirty-worktree.md` 协议处理。该协议定义了检查步骤、归因分类和禁令,本文件不重复
5556
-`phase: build`,读取 tasks.md 的下一个未勾选任务继续
5657
-`phase: verify``verify_result: fail`,先运行 `bash "$COMET_STATE" transition <name> verify-fail`,再调用 `/comet-build`
5758
-`phase: open` 但 proposal/design/tasks 已完整,先运行 `bash "$COMET_GUARD" <change-name> open --apply` 修正状态,再继续判定
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Dirty Worktree 协议
2+
3+
规范路径:`comet/reference/dirty-worktree.md`
4+
5+
本协议由所有涉及代码修改的 comet 子 skill 共享。当 agent 恢复上下文或继续执行时,必须按本协议处理未提交的工作区改动。
6+
7+
## 1. 检查步骤
8+
9+
继续或开始修改前,必须先运行以下命令:
10+
11+
```bash
12+
git status --short
13+
git diff --stat
14+
git diff --cached --stat
15+
git ls-files --others --exclude-standard
16+
```
17+
18+
必要时再查看 `git diff` / `git diff --cached` / 新建文件内容。
19+
20+
## 2. 核心规则
21+
22+
- 用户可能不会说明自己改了哪里。只要存在 dirty worktree(包括 Git 状态里显示为 `??` 的新建文件),就先假设改动可能来自用户或混合来源
23+
- dirty worktree 只代表代码事实,不会自动推进 `.comet.yaml``phase` 或勾选 `tasks.md`;只有完成归因、验证、同步必要文档,并通过对应阶段 guard 后,才允许推进 Comet 状态
24+
25+
## 3. 归因分类
26+
27+
将 dirty diff 分为三类:
28+
29+
1. **属于当前 change**:文件和内容能对应当前 change 的目标、tasks.md、plan 或 delta spec。将其纳入当前任务继续,不重复改同一处
30+
2. **不属于当前 change**:文件或内容与当前目标无关。暂停并询问用户:并入当前 change、拆成新 change、保留不处理,或明确授权丢弃
31+
3. **来源不确定**:无法从 diff 和文档判断归属。暂停并向用户汇报文件列表和判断依据,不继续推进阶段
32+
33+
## 4. 常见处理模式
34+
35+
### 已实现但 tasks.md 未勾选
36+
37+
先验证实现(运行构建和测试),通过后补勾任务。不要因为任务未勾选就重做一遍,也不要因为状态文件滞后而忽略代码事实。若当前子 skill 定义了阶段特例,以子 skill 为准。
38+
39+
### 暗示计划或范围已变化
40+
41+
按当前子 skill 的升级、增量更新或回退规则处理,本协议不重复阶段特例。
42+
43+
### 模糊恢复意图
44+
45+
用户说"继续""接着跑""我改了一点""刚才不满意""重新弄""代码动过""先按现在的来"等模糊恢复意图时,按本协议处理。不要要求用户先回忆具体改了哪里。
46+
47+
### open/design 阶段出现代码改动
48+
49+
若当前仍处于 `open``design`,但 dirty worktree 已经包含代码改动,先按本协议归因,不要直接推进阶段:
50+
51+
- 属于当前 change 的改动:作为需求或设计输入记录到 proposal/design/spec/design doc/tasks 中;进入 build 前仍需完成对应阶段 guard
52+
- 不属于当前 change 或来源不确定:暂停询问用户是并入当前 change、拆成新 change、保留不处理,还是明确授权丢弃
53+
- 禁止在 open/design 阶段直接把代码改动当作已完成实现并推进到 verify
54+
55+
## 5. 禁令
56+
57+
- 禁止在未理解 dirty diff 来源时覆盖、回滚、格式化重写或忽略用户改动
58+
- 禁止在 dirty diff 未解释清楚时判定验证通过

assets/skills/comet-build/SKILL.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,8 @@ Build is the longest phase and may span many tasks. To support resume after cont
158158

159159
- **After each task**: immediately check off tasks.md and commit code so `.comet.yaml` and file state are durable
160160
- **After context compaction**: read `.comet.yaml` to confirm the phase is still build, read the plan header `base-ref`, then read tasks.md to find the next unchecked task
161+
- **User manual-change resume**: handle uncommitted changes through `comet/reference/dirty-worktree.md`. That protocol defines checks, attribution, and prohibitions. Build-specific handling:
162+
1. After attribution, if the diff implies plan or spec changes, handle it through Step 5 "Spec Incremental Updates"
161163
- **Long task split**: if a single task exceeds 200 lines of code changes, consider splitting it into multiple subtasks and commits
162164

163165
## Exit Conditions

assets/skills/comet-hotfix/SKILL.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ Initialize Comet state file:
4747
bash "$COMET_STATE" init <name> hotfix
4848
```
4949

50+
Verify initialized state:
51+
52+
```bash
53+
bash "$COMET_STATE" check <name> open
54+
```
55+
5056
Run phase guard to transition open → build:
5157

5258
```bash
@@ -57,6 +63,8 @@ bash "$COMET_GUARD" <change-name> open --apply
5763

5864
Use hotfix defaults: `build_mode: direct`. Skip `superpowers:brainstorming` and `superpowers:writing-plans` (unless tasks > 3; if exceeds 3 tasks, transfer to `/comet-build`'s plan and execution method selection).
5965

66+
Before continuing or starting changes, handle uncommitted changes through `comet/reference/dirty-worktree.md`. If attribution shows the fix scope exceeds hotfix, handle it through this file's "Upgrade Conditions".
67+
6068
**Immediately execute:** Execute tasks one by one according to tasks.md:
6169

6270
1. Read `openspec/changes/<name>/tasks.md`, get incomplete task list

0 commit comments

Comments
 (0)