@wenaixi/dsh-superpower 7.3.0 → 7.5.1

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 (77) hide show
  1. package/README.md +112 -105
  2. package/README.zh.md +216 -0
  3. package/lib/catalog.d.ts +8 -2
  4. package/lib/catalog.d.ts.map +1 -1
  5. package/lib/catalog.js +64 -9
  6. package/lib/catalog.js.map +1 -1
  7. package/lib/client.js +120 -75
  8. package/lib/document.d.ts +8 -2
  9. package/lib/document.d.ts.map +1 -1
  10. package/lib/document.js +14 -4
  11. package/lib/document.js.map +1 -1
  12. package/lib/superpowers.d.ts +6 -0
  13. package/lib/superpowers.d.ts.map +1 -1
  14. package/lib/superpowers.js +25 -2
  15. package/lib/superpowers.js.map +1 -1
  16. package/lib/switches.d.ts +17 -18
  17. package/lib/switches.d.ts.map +1 -1
  18. package/lib/switches.js +78 -31
  19. package/lib/switches.js.map +1 -1
  20. package/package.json +3 -3
  21. package/skills/brainstorming/SKILL.md +234 -170
  22. package/skills/brainstorming/spec-document-reviewer-prompt.md +27 -25
  23. package/skills/brainstorming/visual-companion.md +84 -231
  24. package/skills/diagnosing-superpowers/SKILL.md +107 -43
  25. package/skills/diagnosing-superpowers/prompts/analyst-common.md +32 -18
  26. package/skills/diagnosing-superpowers/prompts/cost-and-time.md +25 -9
  27. package/skills/diagnosing-superpowers/prompts/plan-adherence.md +26 -12
  28. package/skills/diagnosing-superpowers/prompts/quality-evidence.md +23 -8
  29. package/skills/diagnosing-superpowers/prompts/repeated-work.md +25 -14
  30. package/skills/diagnosing-superpowers/prompts/request-conflicts.md +18 -9
  31. package/skills/diagnosing-superpowers/prompts/scrub-audit.md +23 -10
  32. package/skills/diagnosing-superpowers/prompts/scrub.md +25 -12
  33. package/skills/diagnosing-superpowers/prompts/similar-session.md +30 -22
  34. package/skills/diagnosing-superpowers/prompts/skill-timeline.md +26 -12
  35. package/skills/diagnosing-superpowers/prompts/stumbles.md +24 -12
  36. package/skills/diagnosing-superpowers/references/context-safety.md +15 -7
  37. package/skills/diagnosing-superpowers/references/github-issues.md +17 -9
  38. package/skills/diagnosing-superpowers/references/redaction-policy.md +27 -15
  39. package/skills/diagnosing-superpowers/references/session-discovery.md +31 -20
  40. package/skills/diagnosing-superpowers/templates/bundle-README.md +66 -40
  41. package/skills/diagnosing-superpowers/templates/case.md +49 -42
  42. package/skills/diagnosing-superpowers/templates/issue.md +32 -26
  43. package/skills/diagnosing-superpowers/templates/report.md +54 -48
  44. package/skills/dispatching-parallel-agents/SKILL.md +92 -90
  45. package/skills/executing-plans/SKILL.md +345 -197
  46. package/skills/finishing-a-development-branch/SKILL.md +107 -82
  47. package/skills/receiving-code-review/SKILL.md +129 -127
  48. package/skills/requesting-code-review/SKILL.md +52 -50
  49. package/skills/requesting-code-review/code-reviewer.md +132 -111
  50. package/skills/subagent-driven-development/SKILL.md +521 -298
  51. package/skills/subagent-driven-development/implementer-prompt.md +138 -117
  52. package/skills/subagent-driven-development/re-review-prompt.md +80 -48
  53. package/skills/subagent-driven-development/task-reviewer-prompt.md +189 -110
  54. package/skills/systematic-debugging/CREATION-LOG.md +85 -85
  55. package/skills/systematic-debugging/SKILL.md +221 -219
  56. package/skills/systematic-debugging/condition-based-waiting.md +48 -49
  57. package/skills/systematic-debugging/defense-in-depth.md +46 -46
  58. package/skills/systematic-debugging/root-cause-tracing.md +63 -63
  59. package/skills/systematic-debugging/test-academic.md +10 -10
  60. package/skills/systematic-debugging/test-pressure-1.md +40 -40
  61. package/skills/systematic-debugging/test-pressure-2.md +58 -58
  62. package/skills/systematic-debugging/test-pressure-3.md +48 -48
  63. package/skills/test-driven-development/SKILL.md +161 -153
  64. package/skills/test-driven-development/writing-good-tests.md +137 -84
  65. package/skills/using-git-worktrees/SKILL.md +74 -72
  66. package/skills/using-superpowers/SKILL.md +40 -39
  67. package/skills/using-superpowers/references/dsh-tools.md +36 -36
  68. package/skills/verification-before-completion/SKILL.md +85 -83
  69. package/skills/writing-plans/SKILL.md +123 -84
  70. package/skills/writing-skills/SKILL.md +419 -417
  71. package/skills/writing-skills/persuasion-principles.md +118 -118
  72. package/skills/writing-skills/testing-skills-with-subagents.md +190 -190
  73. package/skills/brainstorming/scripts/frame-template.html +0 -213
  74. package/skills/brainstorming/scripts/helper.js +0 -167
  75. package/skills/brainstorming/scripts/server.cjs +0 -715
  76. package/skills/brainstorming/scripts/start-server.sh +0 -204
  77. package/skills/brainstorming/scripts/stop-server.sh +0 -120
@@ -1,145 +1,198 @@
1
- # 编写高质量测试
1
+ # Writing Good Tests
2
2
 
3
- **何时加载本文档:** 编写或修改测试、添加 mock,或为测试添加清理/辅助方法时。
3
+ **Load this reference when:** writing or changing tests, adding mocks, or
4
+ adding cleanup/helper methods for tests.
4
5
 
5
- ## 概述
6
+ ## Overview
6
7
 
7
- 测试的存在是为了捕获特定的缺陷。以下两条原则贯穿始终:
8
+ A test exists to catch a specific break. Two principles govern everything
9
+ here:
8
10
 
9
11
  ```
10
- 1. 每个测试都要明确它能捕获什么缺陷
11
- 2. 每个测试都要验证真实对象
12
+ 1. Every test names the break it catches
13
+ 2. Every test exercises the real thing
12
14
  ```
13
15
 
14
- 严格的 TDD 能自然地满足这两点:先写测试并观察其在真实代码上失败,就已经证明了它具备失败能力;只有当真实依赖被证明缓慢或涉及外部系统时,才引入 mock。
16
+ Strict TDD produces both naturally: a test written first and watched
17
+ failing against real code has already proven it can fail, and only earns
18
+ a mock when the real dependency proves slow or external.
15
19
 
16
- ## 原则一:明确测试要捕获的缺陷
20
+ ## Principle 1: Name the Break
17
21
 
18
- 在编写测试体之前,先回答:**什么样的生产代码变更应该让这个测试失败——而这个变更是缺陷还是有意决策?** 只有当测试能够捕获错误分支、缺失的副作用、错误参数、边界情况或被破坏的契约时,它才有存在的价值。
22
+ Before writing the test body, answer: **what production change should
23
+ make this test fail — and is that change a bug or a decision?** A test
24
+ earns its place by catching a wrong branch, missing side effect, wrong
25
+ argument, boundary case, or broken contract.
19
26
 
20
- **独立推导期望值。** 使用字面量和人工校验的固件;表格驱动测试中 `want` 使用字面量是首选形式。由被测代码(或其辅助函数)计算出的期望值,无论代码做什么都能通过:
27
+ **Derive expectations independently.** Use literals and hand-checked
28
+ fixtures; table-driven tests with literal `want` values are the preferred
29
+ shape. An expectation computed by the code under test — or its helpers —
30
+ passes no matter what that code does:
21
31
 
22
32
  ```typescript
23
- // [FAIL] 镜像断言:同一个构造器算出两侧——永远为真
33
+ // [FAIL] Mirror assertion: the same builder computes both sides — always true
24
34
  const expected = buildSearchQuery({ tag: 'urgent' });
25
35
  expect(buildSearchQuery({ tag: 'urgent' })).toBe(expected);
26
36
 
27
- // [OK] 手工推导的字面量
37
+ // [OK] Hand-derived literal
28
38
  expect(buildSearchQuery({ tag: 'urgent' })).toBe('tag:"urgent"');
29
39
  ```
30
40
 
31
- **不要写变更探测器。** 如果只有有意决策才能让测试失败——如常量的取值、精确的措辞、内部结构——那么它只会在重新设计时触发,却在真正的缺陷面前保持沉默。应测试依赖于该决策的行为:不要写 `expect(MAX_RETRIES).toBe(5)`,而要验证“失败调用会被重试 5 次,且第 6 次绝不会发生”。
32
-
33
- **测行为,而非文本。** 断言脚本、技能或配置包含某一行,只能证明源码就是源码本身。应在受控输入下运行脚本,并断言其输出、副作用或退出码。面向 agent 的指令性文档,应通过消费方 agent 的行为来测试(writing-skills);面向人的 prose 则完全不需要测试。
34
-
35
- **测你的代码,而非框架。** 测试你的代码在其边界上做出的契约——你注册的路由、你发出的查询、你生成的负载。上游的实现机制应由其维护者来测试(典型反例:断言你的路由会调用已注册的处理器——那是框架的测试,不是你的)。当上游行为确实出乎意料时,针对该假设写一个窄范围的特征测试(characterization test),并命名该假设。同样的边界也适用于你的内部代码:构造函数、getter、常量和简单透传,只有在它们承担校验、归一化、默认值、推导、约束或副作用时才值得测试——否则应断言首个依赖于它们的、消费者可见的结果。
36
-
37
- ### 门禁检查
41
+ **No change detectors.** If only intentional decisions can fail a test —
42
+ a constant's value, exact message wording, private structure — it fires
43
+ on redesign and sleeps through bugs. Test the behavior that depends on
44
+ the decision: not `expect(MAX_RETRIES).toBe(5)` but "a failing call is
45
+ retried 5 times and the 6th attempt never happens."
46
+
47
+ **Behavior, not text.** Asserting that a script, skill, or config
48
+ contains an exact line proves only that the source is the source. Run
49
+ scripts against controlled inputs and assert outputs, side effects, or
50
+ exit codes. Documents that instruct agents are tested by the consuming
51
+ agent's behavior (superpowers:writing-skills); prose for humans earns no
52
+ test at all.
53
+
54
+ **Your code, not the framework.** Test the contract your code makes at
55
+ its boundaries — the route you register, the query you emit, the payload
56
+ you produce. Upstream mechanics are their maintainers' tests to write
57
+ (the classic: asserting your router invokes a registered handler — that
58
+ is the framework's test, not yours). When upstream behavior genuinely
59
+ surprised you, write one narrow characterization test naming the
60
+ assumption. The same boundary applies inside your code: constructors,
61
+ getters, constants, and trivial forwarding earn tests only when they
62
+ validate, normalize, default, derive, enforce, or cause side effects —
63
+ otherwise assert the first consumer-visible result that depends on them.
64
+
65
+ ### Gate Function
38
66
 
39
67
  ```
40
- 编写测试体之前:
41
- 明确什么样的生产代码变更会让该测试失败。
68
+ BEFORE writing the test body:
69
+ Name the production change that would make this test fail.
42
70
 
43
- 无法命名 → 围绕可观测行为重新设计
44
- “源码文本变了” → 运行产物并断言其效果
45
- 只有有意决策会失败 → 这是变更探测器;改为测试
46
- 依赖于该决策的行为
71
+ Cannot name one → redesign around an observable behavior
72
+ "The source text changed" → run the artifact and assert its effects
73
+ Only intentional decisions → change detector; test the behavior
74
+ that depends on the decision
47
75
 
48
- 确认期望值未使用被测代码推导。
49
- 如果复用了被测代码的逻辑或辅助函数:
50
- 替换为字面量或人工校验的固件
76
+ Confirm the expected value is derived without the code under test.
77
+ IF it reuses the code's logic or helpers:
78
+ Replace it with a literal or hand-checked fixture
51
79
  ```
52
80
 
53
- ## 原则二:使用真实对象
81
+ ## Principle 2: Exercise the Real Thing
54
82
 
55
- **mock 本身不值得断言。** 对 mock 的断言,只在 mock 存在时通过、不存在时失败——它对组件本身一无所言。应断言真实组件的行为;如果你发现自己在检查 mock,那就去掉 mock 或删掉该断言。
83
+ **The mock earns no assertions.** A mock assertion passes when the mock
84
+ is present and fails when it is absent — it says nothing about the
85
+ component. Assert the real component's behavior; if the mock is what you
86
+ are checking, unmock it or delete the assertion.
56
87
 
57
88
  ```typescript
58
- // [OK] 真实行为
89
+ // [OK] Real behavior
59
90
  expect(screen.getByRole('navigation')).toBeInTheDocument();
60
91
 
61
- // [FAIL] mock 的存在性
92
+ // [FAIL] Mock existence
62
93
  expect(screen.getByTestId('sidebar-mock')).toBeInTheDocument();
63
94
  ```
64
95
 
65
- **你的 human partner 的提醒:**“我们在测试 mock 的行为吗?”
96
+ **your human partner's correction:** "Are we testing the behavior of a
97
+ mock?"
66
98
 
67
- **在正确的层级 mock。** 在替换真实方法前,先了解它的所有副作用;只 mock 缓慢或外部的操作,保留测试所依赖的部分为真实实现。不确定时,先让测试跑在真实实现上,观察究竟需要发生什么。
99
+ **Mock at the right level.** Learn every side effect of the real method
100
+ before replacing it; mock the slow or external operation and keep what
101
+ the test depends on real. When unsure, run the test against the real
102
+ implementation first and observe what actually needs to happen.
68
103
 
69
104
  ```typescript
70
- // [FAIL] mock 吞掉了重复检测所读取的配置写入
105
+ // [FAIL] The mock swallows the config write that duplicate detection reads
71
106
  vi.mock('ToolCatalog', () => ({
72
107
  discoverAndCacheTools: vi.fn().mockResolvedValue(undefined)
73
108
  }));
74
109
 
75
- // [OK] 只 mock 缓慢的服务器启动;配置写入保持真实
110
+ // [OK] Mock only the slow server startup; the config write stays real
76
111
  vi.mock('MCPServerManager');
77
112
  ```
78
113
 
79
- **让替身足够具体。** 当参数、调用次数或顺序属于契约的一部分时,就要断言它们——一个接受任意参数的假对象什么也验证不了。为每个分支(成功、失败、畸形输入)提供独立的固件或 spy,这样错误的分支就无法满足期望。
114
+ **Make doubles specific.** When arguments, call counts, or ordering are
115
+ part of the contract, assert them — a fake that accepts anything verifies
116
+ nothing. Give each branch (success, error, malformed) its own fixture or
117
+ spy, so the wrong branch cannot satisfy the expectation.
80
118
 
81
- **完整镜像真实数据。** 按真实存在的完整结构来 mock——包含所有已文档化的字段——而不仅仅是你测试中读取的字段。部分 mock 会在下游代码读取缺失字段时静默失败:测试通过,而集成已损坏。
119
+ **Mirror real data completely.** Mock the complete structure as it exists
120
+ in reality — all documented fields — not just the ones your test reads.
121
+ Partial mocks fail silently when downstream code reads an omitted field:
122
+ the test passes while integration breaks.
82
123
 
83
- **生产类只承载生产方法。** 仅测试需要的清理逻辑应放在测试工具中,绝不要以 `destroy()` 的形式出现在生产类上。自问:这个方法是否只被测试调用?这个类是否拥有该资源的lifecycle?答案有误 → 放到测试工具里。
124
+ **Production classes carry production methods only.** Cleanup that only
125
+ tests need lives in test utilities, never as a `destroy()` on the
126
+ production class. Ask: is this method called only from tests? Does this
127
+ class own this resource's lifecycle? Wrong answers → test utility.
84
128
 
85
- **复杂 mock 不如真实组件。** 当 mock 的搭建超过测试逻辑本身、mock 缺少真实组件拥有的方法、或测试因 mock 变更而崩溃时,改用基于真实组件的集成测试。**你的 human partner 的提问:**“这里真的需要用 mock 吗?”
129
+ **Prefer real components over complex mocks.** When mock setup outgrows
130
+ the test logic, mocks miss methods the real components have, or tests
131
+ break when the mock changes, switch to an integration test with real
132
+ components. **your human partner's question:** "Do we need to be using a
133
+ mock here?"
86
134
 
87
- ### 门禁检查
135
+ ### Gate Function
88
136
 
89
137
  ```
90
- 添加 mock 或测试辅助方法之前:
91
- 列出真实方法的所有副作用;测试所依赖的保持真实——
92
- 只在更底层的缓慢/外部层级进行 mock。
138
+ BEFORE adding a mock or test helper:
139
+ List the real method's side effects; keep the ones the test
140
+ depends on real — mock the slow/external level below them.
93
141
 
94
- mock 的响应需完整镜像真实结构。
142
+ Mock responses mirror the complete real structure.
95
143
 
96
- 仅被测试调用的方法归属于测试工具,而非生产代码。
144
+ A method only tests call lives in test utilities, not production.
97
145
 
98
- 正要对 mock 本身做断言?
99
- 去掉 mock 或删掉该断言。
146
+ About to assert on the mock itself?
147
+ Unmock it or delete the assertion.
100
148
  ```
101
149
 
102
- ## 测试与实现一同交付
150
+ ## Tests Ship With the Implementation
103
151
 
104
- TDD 循环——失败的测试、最小实现、重构——才是“完成”的定义。只交付行为所需的测试,且仅交付这些:平凡代码和面向人的 prose 不需要测试,为满足流程而写的测试会带来永久的维护成本。
152
+ The TDD cycle — failing test, minimal implementation, refactor — is what
153
+ "complete" means. Ship the tests the behavior needs and only those:
154
+ trivial code and human prose earn none, and a test written to satisfy
155
+ process costs maintenance forever.
105
156
 
106
- ## 变异检查
157
+ ## The Mutation Check
107
158
 
108
- 完成前,在脑中对生产代码做变异;对每一种现实的变异,至少应有一个测试会失败:
159
+ Before finishing, mentally mutate the production code; at least one test
160
+ should fail for each realistic mutation:
109
161
 
110
- - 错误的常量或参数
111
- - 错误的分支处理
112
- - 缺失的状态变更或副作用
113
- - 空返回或默认返回
114
- - 对 zero、空、nil、未授权或畸形输入缺失校验
162
+ - Wrong constant or argument
163
+ - Wrong branch handler
164
+ - Missing state change or side effect
165
+ - Empty or default return
166
+ - Missing validation for zero, empty, nil, unauthorized, or malformed input
115
167
 
116
- 没有任何测试能捕获的变异,意味着该行为未受保护——或测试本身是同义反复。
168
+ A mutation nothing catches marks the behavior as unprotected — or the
169
+ test as tautological.
117
170
 
118
- ## 速查表
171
+ ## Quick Reference
119
172
 
120
- | 当你…… | 应该…… |
173
+ | When you... | Do |
121
174
  |-------------|-----|
122
- | 写任何测试 | 明确它要捕获的缺陷——是缺陷,而非决策 |
123
- | 构造期望值 | 手工推导;绝不要用被测代码来计算 |
124
- | 测试脚本或文档 | 运行它 / 对其消费者做压力测试;不要 grep 文本 |
125
- | 想测试依赖 | 测试你的边界契约,而非对方已文档化的实现机制 |
126
- | 想对 mock 元素做断言 | 测试真实组件,或去掉 mock |
127
- | 准备 mock 方法 | 了解其副作用;在缓慢/外部层级 mock |
128
- | 构造 mock 响应 | 完整镜像真实结构 |
129
- | 需要仅测试使用的清理逻辑 | 放到测试工具中 |
130
- | mock 搭建急剧膨胀 | 改用基于真实组件的集成测试 |
131
- | 完成测试文件 | 执行变异检查 |
132
-
133
- ## 警示信号
134
-
135
- - 准备与断言共享同一对象,必然相等
136
- - 测试只能通过 panic、崩溃或缺失选择器而失败
137
- - 测试在每次有意变更时都失败,却从不在意外破坏时失败
138
- - 期望值隐藏在循环、构造器或辅助函数之后
139
- - 测试 grep 源码文本,或断言已移除的符号保持移除
140
- - 即使只剩下框架,该测试依然“有意义”
141
- - 测试仅为覆盖率而存在,未检查任何副作用或结果
142
- - 断言检查 `*-mock` 测试 ID,或在移除 mock 后失败
143
- - 某个方法只被测试文件调用
144
- - mock 搭建超过测试的一半,或你无法解释为何需要 mock
145
- - “为了保险”而 mock
175
+ | Write any test | Name the break it catches — a bug, not a decision |
176
+ | Build an expected value | Derive it by hand; never with the code under test |
177
+ | Test a script or document | Run it / pressure-test its consumer; never grep its text |
178
+ | Reach for a dependency test | Test your boundary contract, not their documented mechanics |
179
+ | Want to assert on a mocked element | Test the real component, or unmock it |
180
+ | Are about to mock a method | Learn its side effects; mock the slow/external level |
181
+ | Build a mock response | Mirror the real structure completely |
182
+ | Need cleanup only tests use | Put it in test utilities |
183
+ | Watch mock setup balloon | Switch to an integration test with real components |
184
+ | Finish a test file | Run the mutation check |
185
+
186
+ ## Warning Signs
187
+
188
+ - Setup and assertion share the same object, guaranteeing equality
189
+ - The test can fail only through a panic, crash, or missing selector
190
+ - The test fails on every intentional change, never on accidental breakage
191
+ - Expected values are hidden behind loops, builders, or helpers
192
+ - The test greps source text, or asserts a removed symbol stays removed
193
+ - The test would still matter if only the framework remained
194
+ - The test exists for coverage, checking no side effect or outcome
195
+ - An assertion checks a `*-mock` test ID, or fails if you remove the mock
196
+ - A method is called only from test files
197
+ - Mock setup is more than half the test, or you can't explain why the mock is needed
198
+ - Mocking "just to be safe"
@@ -1,21 +1,23 @@
1
1
  ---
2
2
  name: using-git-worktrees
3
- description: "Superpower Skill:适用于需与当前 worktree 隔离的功能开发或执行实现计划前,通过原生工具优先、git worktree 兜底的方式确保独立 worktree 就绪。"
3
+ description: "Superpower Skill: Use when starting feature work that needs isolation from current workspace or before executing implementation plans - ensures an isolated workspace exists via native tools or git worktree fallback"
4
+ description_zh: "Superpower Skill:适用于需与当前 worktree 隔离的功能开发或执行实现计划前,通过原生工具优先、git worktree 兜底的方式确保独立 worktree 就绪。"
4
5
  ---
5
6
 
6
- # 使用 Git Worktree
7
7
 
8
- ## 概述
8
+ # Using Git Worktrees
9
9
 
10
- 确保所有工作都在独立 worktree 中进行。优先使用平台原生的 worktree 工具,仅在无原生工具可用时再回退到手动 git worktree。
10
+ ## Overview
11
11
 
12
- **核心原则:** 先检测是否已处于隔离环境,再使用原生工具,最后回退到 git。不要与 harness 对抗。
12
+ Ensure work happens in an isolated workspace. Prefer your platform's native worktree tools. Fall back to manual git worktrees only when no native tool is available.
13
13
 
14
- **开始时声明:** “我正在使用 using-git-worktrees 技能来创建独立 worktree。”
14
+ **Core principle:** Detect existing isolation first. Then use native tools. Then fall back to git. Never fight the harness.
15
15
 
16
- ## 步骤 0:检测现有隔离状态
16
+ **Announce at start:** "I'm using the using-git-worktrees skill to set up an isolated workspace."
17
17
 
18
- **在创建任何内容之前,先检查是否已处于独立 worktree 中。**
18
+ ## Step 0: Detect Existing Isolation
19
+
20
+ **Before creating anything, check if you are already in an isolated workspace.**
19
21
 
20
22
  ```bash
21
23
  GIT_DIR=$(cd "$(git rev-parse --git-dir)" 2>/dev/null && pwd -P)
@@ -23,85 +25,85 @@ GIT_COMMON=$(cd "$(git rev-parse --git-common-dir)" 2>/dev/null && pwd -P)
23
25
  BRANCH=$(git branch --show-current)
24
26
  ```
25
27
 
26
- **子模块防护:** `GIT_DIR != GIT_COMMON` 在 git 子模块中同样为真。在判定“已处于 worktree”之前,需先确认是否处于子模块中:
28
+ **Submodule guard:** `GIT_DIR != GIT_COMMON` is also true inside git submodules. Before concluding "already in a worktree," verify you are not in a submodule:
27
29
 
28
30
  ```bash
29
- # 若返回路径,则处于子模块而非 worktree——按常规仓库处理
31
+ # If this returns a path, you're in a submodule, not a worktree — treat as normal repo
30
32
  git rev-parse --show-superproject-working-tree 2>/dev/null
31
33
  ```
32
34
 
33
- **若 `GIT_DIR != GIT_COMMON`(且不在子模块中):** 说明已处于关联 worktree 中。跳至步骤 2(项目初始化),不要再创建新的 worktree。
35
+ **If `GIT_DIR != GIT_COMMON` (and not a submodule):** You are already in a linked worktree. Skip to Step 2 (Project Setup). Do NOT create another worktree.
34
36
 
35
- 按分支状态报告:
36
- - 处于分支上:“已在独立 worktree `<path>`,分支为 `<name>`。”
37
- - 游离 HEAD:“已在独立 worktree `<path>`(游离 HEAD,外部托管),结束时需创建分支。”
37
+ Report with branch state:
38
+ - On a branch: "Already in isolated workspace at `<path>` on branch `<name>`."
39
+ - Detached HEAD: "Already in isolated workspace at `<path>` (detached HEAD, externally managed). Branch creation needed at finish time."
38
40
 
39
- **若 `GIT_DIR == GIT_COMMON`(或处于子模块中):** 说明处于常规仓库检出状态。
41
+ **If `GIT_DIR == GIT_COMMON` (or in a submodule):** You are in a normal repo checkout.
40
42
 
41
- 用户是否已在指令中表明 worktree 偏好?若无,请在创建 worktree 前征得同意:
43
+ Has the user already indicated their worktree preference in your instructions? If not, ask for consent before creating a worktree:
42
44
 
43
- > “是否需要我为你创建一个独立 worktree?它可以保护当前分支不受改动影响。”
45
+ > "Would you like me to set up an isolated worktree? It protects your current branch from changes."
44
46
 
45
- 若已存在明确偏好则直接遵循,无需询问。若用户拒绝,则在原地工作并跳至步骤 2。
47
+ Honor any existing declared preference without asking. If the user declines consent, work in place and skip to Step 2.
46
48
 
47
- ## 步骤 1:创建独立 worktree
49
+ ## Step 1: Create Isolated Workspace
48
50
 
49
- **你有两种机制,请按以下顺序尝试。**
51
+ **You have two mechanisms. Try them in this order.**
50
52
 
51
- ### 1a. 原生 Worktree 工具(优先)
53
+ ### 1a. Native Worktree Tools (preferred)
52
54
 
53
- 用户已请求独立 worktree(步骤 0 已获同意)。你是否已有创建 worktree 的方式?可能是名为 `EnterWorktree`、`WorktreeCreate`、`/worktree` 命令或 `--worktree` 参数的工具。如果有,请直接使用并跳至步骤 2。
55
+ The user has asked for an isolated workspace (Step 0 consent). Do you already have a way to create a worktree? It might be a tool with a name like `EnterWorktree`, `WorktreeCreate`, a `/worktree` command, or a `--worktree` flag. If you do, use it and skip to Step 2.
54
56
 
55
- 原生工具会自动处理目录选址、分支创建和清理。使用 `git worktree add` 而绕过原生工具会产生 harness 无法感知和管理的幽灵状态。
57
+ Native tools handle directory placement, branch creation, and cleanup automatically. Using `git worktree add` when you have a native tool creates phantom state your harness can't see or manage.
56
58
 
57
- 仅在无原生 worktree 工具可用时,才进入步骤 1b。
59
+ Only proceed to Step 1b if you have no native worktree tool available.
58
60
 
59
- ### 1b. Git Worktree 兜底方案
61
+ ### 1b. Git Worktree Fallback
60
62
 
61
- **仅在步骤 1a 不适用时使用**——即你没有可用的原生 worktree 工具时,才手动通过 git 创建 worktree。
63
+ **Only use this if Step 1a does not apply** — you have no native worktree tool available. Create a worktree manually using git.
62
64
 
63
- #### 目录选择
65
+ #### Directory Selection
64
66
 
65
- 按以下优先级选择目录,用户的显式偏好始终优先于已观测到的文件系统状态。
67
+ Follow this priority order. Explicit user preference always beats observed filesystem state.
66
68
 
67
- 1. **检查指令中是否已声明 worktree 目录偏好。** 如用户已指定,直接使用,无需询问。
69
+ 1. **Check your instructions for a declared worktree directory preference.** If the user has already specified one, use it without asking.
68
70
 
69
- 2. **检查是否存在项目本地的 worktree 目录:**
71
+ 2. **Check for an existing project-local worktree directory:**
70
72
  ```bash
71
- ls -d .worktrees 2>/dev/null # 优先(隐藏目录)
72
- ls -d worktrees 2>/dev/null # 备选
73
+ ls -d .worktrees 2>/dev/null # Preferred (hidden)
74
+ ls -d worktrees 2>/dev/null # Alternative
73
75
  ```
74
- 如存在则直接使用;若两者都存在,以 `.worktrees` 为准。
76
+ If found, use it. If both exist, `.worktrees` wins.
75
77
 
76
- 3. **若无其他指引**,默认为项目根目录下的 `.worktrees/`。
78
+ 3. **If there is no other guidance available**, default to `.worktrees/` at the project root.
77
79
 
78
- #### 安全性校验(仅针对项目本地目录)
80
+ #### Safety Verification (project-local directories only)
79
81
 
80
- **创建 worktree 前必须确认目录已被忽略:**
82
+ **MUST verify directory is ignored before creating worktree:**
81
83
 
82
84
  ```bash
83
85
  git check-ignore -q .worktrees 2>/dev/null || git check-ignore -q worktrees 2>/dev/null
84
86
  ```
85
87
 
86
- **若未被忽略:** 加入 .gitignore 并提交该改动后再继续。
88
+ **If NOT ignored:** Add to .gitignore, commit the change, then proceed.
87
89
 
88
- **为何关键:** 防止将 worktree 内容误提交到仓库。
90
+ **Why critical:** Prevents accidentally committing worktree contents to repository.
89
91
 
90
- #### 创建 Worktree
92
+ #### Create the Worktree
91
93
 
92
94
  ```bash
93
- # 根据所选位置确定路径
95
+ # Determine path based on chosen location
94
96
  path="$LOCATION/$BRANCH_NAME"
95
97
 
96
98
  git worktree add "$path" -b "$BRANCH_NAME"
97
99
  cd "$path"
98
100
  ```
99
101
 
100
- **沙盒兜底:** 若 `git worktree add` 因权限错误(沙盒拒绝)失败,请告知用户沙盒已阻止 worktree 创建,改为在当前目录继续工作,并在原地完成初始化与基线测试。
102
+ **Sandbox fallback:** If `git worktree add` fails with a permission error (sandbox denial), tell the user the sandbox blocked worktree creation and you're working in the current directory instead. Then run setup and baseline tests in place.
101
103
 
102
- ## 步骤 2:项目初始化
104
+ ## Step 2: Project Setup
103
105
 
104
- 自动检测并执行对应的初始化:
106
+ Auto-detect and run appropriate setup:
105
107
 
106
108
  ```bash
107
109
  # Node.js
@@ -118,20 +120,20 @@ if [ -f pyproject.toml ]; then poetry install; fi
118
120
  if [ -f go.mod ]; then go mod download; fi
119
121
  ```
120
122
 
121
- ## 步骤 3:验证干净基线
123
+ ## Step 3: Verify Clean Baseline
122
124
 
123
- 运行测试以确保 worktree 初始状态干净:
125
+ Run tests to ensure workspace starts clean:
124
126
 
125
127
  ```bash
126
- # 使用项目对应的命令
128
+ # Use project-appropriate command
127
129
  npm test / cargo test / pytest / go test ./...
128
130
  ```
129
131
 
130
- **若测试失败:** 报告失败情况,询问是否继续或先行排查。
132
+ **If tests fail:** Report failures, ask whether to proceed or investigate.
131
133
 
132
- **若测试通过:** 报告就绪。
134
+ **If tests pass:** Report ready.
133
135
 
134
- ### 报告
136
+ ### Report
135
137
 
136
138
  ```
137
139
  Worktree ready at <full-path>
@@ -139,29 +141,29 @@ Tests passing (<N> tests, 0 failures)
139
141
  Ready to implement <feature-name>
140
142
  ```
141
143
 
142
- ## 快速参考
144
+ ## Quick Reference
143
145
 
144
- | 场景 | 操作 |
146
+ | Situation | Action |
145
147
  |-----------|--------|
146
- | 已处于关联 worktree | 跳过创建(步骤 0) |
147
- | 处于子模块中 | 视为常规仓库(步骤 0 防护) |
148
- | 存在原生 worktree 工具 | 使用原生工具(步骤 1a) |
149
- | 无原生工具 | 使用 Git worktree 兜底(步骤 1b) |
150
- | `.worktrees/` 已存在 | 使用它(校验是否已忽略) |
151
- | `worktrees/` 已存在 | 使用它(校验是否已忽略) |
152
- | 两者都存在 | 使用 `.worktrees/` |
153
- | 两者都不存在 | 先检查指令文件,再默认使用 `.worktrees/` |
154
- | 目录未被忽略 | 加入 .gitignore 并提交 |
155
- | 创建时权限错误 | 沙盒兜底,原地工作 |
156
- | 基线测试失败 | 报告失败并询问 |
157
- | 无 package.json/Cargo.toml | 跳过依赖安装 |
158
-
159
- ## 常见托词
160
-
161
- | 托词 | 实际情况 |
148
+ | Already in linked worktree | Skip creation (Step 0) |
149
+ | In a submodule | Treat as normal repo (Step 0 guard) |
150
+ | Native worktree tool available | Use it (Step 1a) |
151
+ | No native tool | Git worktree fallback (Step 1b) |
152
+ | `.worktrees/` exists | Use it (verify ignored) |
153
+ | `worktrees/` exists | Use it (verify ignored) |
154
+ | Both exist | Use `.worktrees/` |
155
+ | Neither exists | Check instruction file, then default `.worktrees/` |
156
+ | Directory not ignored | Add to .gitignore + commit |
157
+ | Permission error on create | Sandbox fallback, work in place |
158
+ | Tests fail during baseline | Report failures + ask |
159
+ | No package.json/Cargo.toml | Skip dependency install |
160
+
161
+ ## Common Rationalizations
162
+
163
+ | Excuse | Reality |
162
164
  |--------|---------|
163
- | “我显然不在 worktree 里,没必要检查” | 执行步骤 0。harness 创建的隔离和子模块都会让肉眼判断失误,用检测命令才能确定。 |
164
- | “`git worktree add` 比到处找原生工具更快” | 原生工具(如 `EnterWorktree`)负责选址、分支和清理。绕过它是头号错误——会产生 harness 无法感知和管理的幽灵状态。 |
165
- | “worktree 目录肯定已经被忽略了” | 请执行 `git check-ignore`。未被忽略的 worktree 目录会把整个 working tree 提交进仓库。 |
166
- | “随便起个目录名都行” | 显式指令优先于已存在的项目本地目录,项目本地目录优先于 `.worktrees/` 默认值。 |
167
- | “worktree 是全新的,基线测试可以等等再跑” | 脏基线会让后续所有失败变得无法定位。现在就跑测试;是否带病继续由你的 human partner 决定。 |
165
+ | "I'm obviously not in a worktree — no need to check" | Run Step 0. Harness-created isolation and submodules both fool eyeballing; the detection commands settle it. |
166
+ | "`git worktree add` is quicker than hunting for a native tool" | A native tool (e.g. `EnterWorktree`) owns placement, branching, and cleanup. Bypassing it is the #1 mistake — it creates phantom state your harness can't see or manage. |
167
+ | "The worktree directory is surely ignored already" | Run `git check-ignore`. An unignored worktree directory commits the whole tree into the repo. |
168
+ | "Any directory name works" | Explicit instructions beat an existing project-local directory, which beats the `.worktrees/` default. |
169
+ | "The workspace is fresh — baseline tests can wait" | A dirty baseline makes every later failure ambiguous. Run the tests now; proceeding past failures is your human partner's call. |