hero-mmt-kit 1.0.0 → 1.1.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/CHANGELOG.md +25 -0
- package/README.md +143 -158
- package/bin/hero-mmt-kit.js +0 -1
- package/package.json +2 -3
- package/skills.manifest.json +72 -72
- package/src/doctor.cjs +22 -27
- package/src/init.cjs +3 -25
- package/src/integrations.cjs +1 -1
- package/src/skills.cjs +1 -1
- package/src/update.cjs +1 -9
- package/templates/common/.claude/hooks/active-state-bridge.cjs +58 -0
- package/templates/common/.claude/hooks/git-guard.cjs +60 -20
- package/templates/common/.claude/hooks/stop-reminder.cjs +3 -11
- package/templates/common/.claude/settings.json +2 -3
- package/templates/docs/ACTIVE_STATE.md +6 -8
- package/templates/docs/SECURITY_STANDARDS.md +1 -1
- package/templates/skills/NOTICE +6 -3
- package/templates/skills/executing-plans/SKILL.md +4 -5
- package/templates/skills/hero-coding/SKILL.md +7 -7
- package/templates/skills/hero-planning/SKILL.md +2 -7
- package/templates/skills/hero-report/SKILL.md +46 -0
- package/templates/skills/hero-reviewing/SKILL.md +9 -6
- package/templates/skills/hero-security/SKILL.md +427 -425
- package/templates/skills/hero-strict/SKILL.md +5 -5
- package/templates/skills/hero-unit-test/SKILL.md +9 -10
- package/templates/skills/subagent-driven-development/SKILL.md +0 -1
- package/templates/skills/using-git-worktrees/SKILL.md +0 -2
- package/templates/skills/using-hero/SKILL.md +16 -10
- package/presets/enterprise.json +0 -3
- package/presets/small-team.json +0 -3
- package/presets/solo.json +0 -3
- package/src/workflow-state.cjs +0 -65
- package/templates/.hero-mmt-kit/session.schema.json +0 -15
- package/templates/common/.claude/hooks/session-bridge.cjs +0 -43
- package/templates/skills/finishing-a-development-branch/SKILL.md +0 -253
|
@@ -38,11 +38,11 @@ Missing artifacts are not a blocker — they're a gap to flag in step 4 of the p
|
|
|
38
38
|
- `doctor --strict` for hero-mmt-kit's own install health, when the change touches the kit itself.
|
|
39
39
|
3. **Use `verification-before-completion`'s discipline throughout**: don't claim a check passed unless you actually ran it and read the output. No inferring success from "it should work."
|
|
40
40
|
4. **Flag stages that should have run but didn't** — e.g. a risky change with no review. Recommend the corresponding independent hero-* skill (`hero-reviewing`, `hero-unit-test`, `hero-security`) or note the gap explicitly; don't silently skip it.
|
|
41
|
-
5. **Summarize the strict pass** — what was checked, what passed, what didn't
|
|
41
|
+
5. **Summarize the strict pass** in chat — what was checked, what passed, what didn't. If a written report exists (or the user wants one), append a "Strict verification" section to it via `hero-report`; don't create a new report file for this.
|
|
42
42
|
|
|
43
43
|
## Output
|
|
44
44
|
|
|
45
|
-
A "Strict verification"
|
|
45
|
+
A "Strict verification" summary in chat, appended to the most relevant existing report (coding report, review report, or test report) via `hero-report` if one exists or is requested. hero-strict has no artifact convention of its own — it never produces a standalone file.
|
|
46
46
|
|
|
47
47
|
```markdown
|
|
48
48
|
## Strict verification
|
|
@@ -66,12 +66,12 @@ Strict verification style:
|
|
|
66
66
|
- Every check listed is backed by actual evidence — a command and its result — not an assumption.
|
|
67
67
|
- Any stage that should have run but didn't is explicitly called out, not silently skipped.
|
|
68
68
|
- Nothing is claimed "done" without evidence.
|
|
69
|
-
- The strict verification
|
|
69
|
+
- The strict verification summary was given in chat, and appended to the relevant report via `hero-report` if one exists or was requested.
|
|
70
70
|
|
|
71
71
|
## ACTIVE_STATE.md Update
|
|
72
72
|
|
|
73
|
-
|
|
73
|
+
If the strict pass surfaces new blockers, add them to the Blockers/Pending Actions section of `docs/ACTIVE_STATE.md`.
|
|
74
74
|
|
|
75
75
|
## Related Skills
|
|
76
76
|
|
|
77
|
-
Wraps `verification-before-completion` for its evidence discipline. Can recommend a re-run of `hero-unit-test`, `hero-reviewing`, or
|
|
77
|
+
Wraps `verification-before-completion` for its evidence discipline. Can recommend a re-run of `hero-unit-test`, `hero-reviewing`, or a `hero-security` pass if a gap is found. Typically invoked after `hero-coding`, `hero-reviewing`, or `hero-unit-test` have already run once — see `using-hero` for the full skill map. Use `hero-report` to append its section to an existing (or newly written) report.
|
|
@@ -40,11 +40,13 @@ If an input is missing, continue with what is available and note the gap in the
|
|
|
40
40
|
- Post-implementation: write tests that pin down the behavior the implementation already exhibits, including edge cases the implementation should handle.
|
|
41
41
|
3. **Run the test suite.** Capture pass/fail results and note how the changed behavior is covered.
|
|
42
42
|
4. **Verify before claiming.** Use the vendored `verification-before-completion` skill: actually run the test command and read its output — never assume or infer that tests pass.
|
|
43
|
-
5. **Document gaps.**
|
|
43
|
+
5. **Document gaps.** State any known gaps or deliberately-skipped cases and why they're acceptable, in the chat summary. Don't write a report file by default — see Report Convention below.
|
|
44
44
|
|
|
45
|
-
##
|
|
45
|
+
## Report Convention (on request)
|
|
46
46
|
|
|
47
|
-
`docs/test-reports/YYYY-MM-DD-<slug>.md`
|
|
47
|
+
hero-unit-test does not write a report file automatically. If the user asks for a written report, invoke the `hero-report` skill — it writes to `docs/test-reports/YYYY-MM-DD-<slug>.md` using the contract below.
|
|
48
|
+
|
|
49
|
+
Report should cover:
|
|
48
50
|
- Mode: TDD-first or post-implementation.
|
|
49
51
|
- Commands run and their actual output (pass/fail counts).
|
|
50
52
|
- Coverage of the changed behavior, in plain terms.
|
|
@@ -60,16 +62,12 @@ Test report style:
|
|
|
60
62
|
|
|
61
63
|
- Tests are green, or failures are explicitly documented with a reason they're acceptable.
|
|
62
64
|
- The changed behavior has meaningful test coverage.
|
|
63
|
-
- The
|
|
65
|
+
- The exact commands run and their results were stated, at minimum in the chat summary — not a claim without evidence.
|
|
66
|
+
- If a report was requested, it was written via `hero-report` at the path above.
|
|
64
67
|
|
|
65
68
|
## ACTIVE_STATE.md Update
|
|
66
69
|
|
|
67
|
-
- Update the relevant row in `docs/ACTIVE_STATE.md`'s Active Features table with current status.
|
|
68
|
-
- Write `.hero-mmt-kit/session.json`:
|
|
69
|
-
- `currentSkill: "hero-unit-test"`
|
|
70
|
-
- `resumePath`: path to the test report
|
|
71
|
-
- `nextAction`: what to do next (e.g., proceed to `hero-reviewing`, or fix a documented failure)
|
|
72
|
-
- `updatedAt`: ISO timestamp
|
|
70
|
+
- Update the relevant row in `docs/ACTIVE_STATE.md`'s Active Features table with current status. Link the test report only if `hero-report` wrote one.
|
|
73
71
|
|
|
74
72
|
## Related Skills
|
|
75
73
|
|
|
@@ -77,3 +75,4 @@ Test report style:
|
|
|
77
75
|
- Reads output from `hero-planning` (for TDD-first) and/or `hero-coding` (for post-implementation).
|
|
78
76
|
- Complements `hero-reviewing`, which is a parallel/independent fresh-eyes check rather than a test pass.
|
|
79
77
|
- `hero-strict` may require re-running this skill's checks under a stricter bar before a "done" claim.
|
|
78
|
+
- Use `hero-report` on request to write the test report.
|
|
@@ -261,7 +261,6 @@ Useful companion skills:
|
|
|
261
261
|
- **superpowers:requesting-code-review** - Provides a reviewer prompt when review budget calls for it.
|
|
262
262
|
- **superpowers:verification-before-completion** - Ensures final claims match evidence.
|
|
263
263
|
- **superpowers:using-git-worktrees** - Use when parallel agents may conflict or the user requests isolation.
|
|
264
|
-
- **superpowers:finishing-a-development-branch** - Use when finishing branch/MR work.
|
|
265
264
|
|
|
266
265
|
Subagents may use **superpowers:test-driven-development** when the selected workflow requires tests-first development or the task is a bugfix/behavior change.
|
|
267
266
|
|
|
@@ -11,8 +11,6 @@ Ensure work happens in an isolated workspace. Prefer your platform's native work
|
|
|
11
11
|
|
|
12
12
|
**Core principle:** Detect existing isolation first. Then use native tools. Then fall back to git. Never fight the harness.
|
|
13
13
|
|
|
14
|
-
**See also:** `finishing-a-development-branch` — when implementation is complete, use that skill to merge/PR/clean up the workspace set up here.
|
|
15
|
-
|
|
16
14
|
**Announce at start:** "I'm using the using-git-worktrees skill to set up an isolated workspace."
|
|
17
15
|
|
|
18
16
|
## Step 0: Detect Existing Isolation
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: using-hero
|
|
3
|
-
description: Use when starting any coding-assistant task in this project — routes to the right hero-* skill for the current stage of work and explains how
|
|
3
|
+
description: Use when starting any coding-assistant task in this project — routes to the right hero-* skill for the current stage of work and explains how workflow state carries across sessions
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# Using Hero
|
|
@@ -11,29 +11,35 @@ hero-mmt-kit is a human-led workflow: the developer decides what to work on and
|
|
|
11
11
|
|
|
12
12
|
## The core skills
|
|
13
13
|
|
|
14
|
-
| Skill | Use when |
|
|
14
|
+
| Skill | Use when | Artifact / report |
|
|
15
15
|
|---|---|---|
|
|
16
|
-
| `hero-planning` | Starting new work — a feature, bugfix, or refactor that needs a plan before code changes. | `docs/plans/YYYY-MM-DD-slug.md` |
|
|
16
|
+
| `hero-planning` | Starting new work — a feature, bugfix, or refactor that needs a plan before code changes. | `docs/plans/YYYY-MM-DD-slug.md` — always written (it's the deliverable, not a report) |
|
|
17
17
|
| `hero-coding` | Implementing an approved plan (or a small change that doesn't need one). | `docs/coding-reports/YYYY-MM-DD-slug.md` |
|
|
18
18
|
| `hero-reviewing` | Fresh-eyes check of an implementation against its plan, before merge. | `docs/reviews/YYYY-MM-DD-slug.md` |
|
|
19
19
|
| `hero-unit-test` | Verifying implementation correctness — TDD-first or post-implementation. | `docs/test-reports/YYYY-MM-DD-slug.md` |
|
|
20
|
-
| `hero-security` | You want an independent OWASP + AI/LLM security review of a sensitive surface. | `docs/security-reports/YYYY-MM-DD-slug.md` |
|
|
21
|
-
| `hero-strict` | Extra rigor is wanted before a "done" claim — a full verification pass. |
|
|
20
|
+
| `hero-security` | You want an independent OWASP + AI/LLM security review of a sensitive surface. | `docs/security-reports/YYYY-MM-DD-slug.md` — always written for the security pass. |
|
|
21
|
+
| `hero-strict` | Extra rigor is wanted before a "done" claim — a full verification pass. | Appends to the current report, if one exists/was requested. |
|
|
22
|
+
| `hero-report` | A written report is actually wanted for a finished `hero-coding`/`hero-reviewing`/`hero-unit-test` phase. | Writes the report at the path the source skill defines. |
|
|
22
23
|
|
|
23
24
|
A typical flow is `hero-planning` → `hero-coding` → `hero-unit-test` and/or `hero-reviewing` → done. Invoke `hero-security` separately when you want a dedicated security pass. Skip stages that don't fit the size of the change — a one-line typo fix doesn't need a plan artifact.
|
|
24
25
|
|
|
26
|
+
`hero-planning`, `hero-coding`, `hero-reviewing`, and `hero-unit-test` are done per-phase, not gated into an automatic full pipeline — finishing one doesn't trigger the next; the developer decides what to invoke next.
|
|
27
|
+
|
|
28
|
+
## Report writing
|
|
29
|
+
|
|
30
|
+
`hero-coding`, `hero-reviewing`, and `hero-unit-test` end each phase with a concise chat summary, not a report file by default. If a written report is wanted for those phases, invoke `hero-report` — it writes to the path convention documented in the source skill's own SKILL.md. `hero-planning`'s plan file is always written because it's the phase's deliverable. `hero-security` is also independent and always writes its own `docs/security-reports/...` artifact; do not replace that with an appended section in another report.
|
|
31
|
+
|
|
25
32
|
## Session state
|
|
26
33
|
|
|
27
|
-
|
|
34
|
+
`docs/ACTIVE_STATE.md`'s Active Features table is the single source of durable workflow state — there is no separate session pointer file. It's injected into context automatically at the start of a session. Each hero-* skill's Definition of Done includes updating it.
|
|
28
35
|
|
|
29
36
|
Resuming work in a fresh session:
|
|
30
|
-
1.
|
|
31
|
-
2.
|
|
32
|
-
3. If session.json is blank/stale, read `docs/ACTIVE_STATE.md`'s Active Features table instead.
|
|
37
|
+
1. Check the injected Active Features context (or read `docs/ACTIVE_STATE.md` directly if it wasn't injected).
|
|
38
|
+
2. If a row names an artifact (plan/report), open it for concrete next steps.
|
|
33
39
|
|
|
34
40
|
## Related vendored skills
|
|
35
41
|
|
|
36
|
-
The hero-* skills wrap general-purpose technique skills rather than duplicate them: `brainstorming`, `writing-plans`, `executing-plans`, `test-driven-development`, `systematic-debugging`, `verification-before-completion`, `requesting-code-review`, `receiving-code-review`, `dispatching-parallel-agents`, `subagent-driven-development`, `using-git-worktrees
|
|
42
|
+
The hero-* skills wrap general-purpose technique skills rather than duplicate them: `brainstorming`, `writing-plans`, `executing-plans`, `test-driven-development`, `systematic-debugging`, `verification-before-completion`, `requesting-code-review`, `receiving-code-review`, `dispatching-parallel-agents`, `subagent-driven-development`, `using-git-worktrees`. `hero-security` is the standalone security review skill rather than a wrapper. Each hero-* skill names the vendored skill(s) it invokes.
|
|
37
43
|
|
|
38
44
|
## Output Style
|
|
39
45
|
|
package/presets/enterprise.json
DELETED
package/presets/small-team.json
DELETED
package/presets/solo.json
DELETED
package/src/workflow-state.cjs
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
const fs = require('fs');
|
|
3
|
-
const path = require('path');
|
|
4
|
-
|
|
5
|
-
const SESSION_FILE = path.join('.hero-mmt-kit', 'session.json');
|
|
6
|
-
|
|
7
|
-
function defaultSession() {
|
|
8
|
-
return {
|
|
9
|
-
schemaVersion: 1,
|
|
10
|
-
currentSkill: null,
|
|
11
|
-
lastCheckpoint: null,
|
|
12
|
-
resumePath: null,
|
|
13
|
-
nextAction: null,
|
|
14
|
-
updatedAt: null,
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const STRING_OR_NULL_FIELDS = ['currentSkill', 'lastCheckpoint', 'resumePath', 'nextAction', 'updatedAt'];
|
|
19
|
-
|
|
20
|
-
function validateSession(obj) {
|
|
21
|
-
const errors = [];
|
|
22
|
-
if (!obj || typeof obj !== 'object') { errors.push('session must be an object'); return { ok: false, errors }; }
|
|
23
|
-
if (obj.schemaVersion !== 1) errors.push(`schemaVersion must be 1, got ${obj.schemaVersion}`);
|
|
24
|
-
for (const key of STRING_OR_NULL_FIELDS) {
|
|
25
|
-
if (Object.prototype.hasOwnProperty.call(obj, key) && obj[key] !== null && typeof obj[key] !== 'string') {
|
|
26
|
-
errors.push(`${key} must be a string or null, got "${obj[key]}"`);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
return { ok: errors.length === 0, errors };
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
function readSession(target) {
|
|
33
|
-
const filePath = path.join(target, SESSION_FILE);
|
|
34
|
-
if (!fs.existsSync(filePath)) return null;
|
|
35
|
-
try {
|
|
36
|
-
const raw = fs.readFileSync(filePath, 'utf8');
|
|
37
|
-
const parsed = JSON.parse(raw);
|
|
38
|
-
return parsed;
|
|
39
|
-
} catch {
|
|
40
|
-
return null;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function writeSession(target, partial) {
|
|
45
|
-
const filePath = path.join(target, SESSION_FILE);
|
|
46
|
-
const existing = readSession(target) || defaultSession();
|
|
47
|
-
const merged = deepMergeSession(existing, partial);
|
|
48
|
-
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
|
49
|
-
fs.writeFileSync(filePath, JSON.stringify(merged, null, 2) + '\n');
|
|
50
|
-
return merged;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
function deepMergeSession(base, partial) {
|
|
54
|
-
const out = Object.assign({}, base);
|
|
55
|
-
for (const [k, v] of Object.entries(partial)) {
|
|
56
|
-
if (v !== null && typeof v === 'object' && !Array.isArray(v) && typeof base[k] === 'object' && base[k] !== null) {
|
|
57
|
-
out[k] = deepMergeSession(base[k], v);
|
|
58
|
-
} else {
|
|
59
|
-
out[k] = v;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
return out;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
module.exports = { defaultSession, validateSession, readSession, writeSession };
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
3
|
-
"title": "hero-mmt-kit session state",
|
|
4
|
-
"description": "Observable workflow pointer for resuming work across sessions. Hero skills update this at checkpoints; doctor reads it. Authoritative state lives in ACTIVE_STATE.md and artifact files under docs/ — this file is a derived convenience pointer.",
|
|
5
|
-
"type": "object",
|
|
6
|
-
"required": ["schemaVersion"],
|
|
7
|
-
"properties": {
|
|
8
|
-
"schemaVersion": { "type": "integer", "const": 1 },
|
|
9
|
-
"currentSkill": { "type": ["string", "null"], "description": "Name of the hero-* skill currently in progress" },
|
|
10
|
-
"lastCheckpoint": { "type": ["string", "null"], "description": "ISO 8601 timestamp of the last session write" },
|
|
11
|
-
"resumePath": { "type": ["string", "null"], "description": "Path to the artifact/report to resume from" },
|
|
12
|
-
"nextAction": { "type": ["string", "null"], "description": "First concrete action for continuing the work" },
|
|
13
|
-
"updatedAt": { "type": ["string", "null"], "description": "ISO 8601 timestamp of the last update" }
|
|
14
|
-
}
|
|
15
|
-
}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
'use strict';
|
|
3
|
-
/*
|
|
4
|
-
* session-bridge.cjs — one-time session context injector (v1.0.0)
|
|
5
|
-
* Claude Code: PostToolUse (matcher: .*)
|
|
6
|
-
*
|
|
7
|
-
* On the first tool call of the session, reads session.json and emits
|
|
8
|
-
* current workflow state to stderr. Guarded by a flag file so it only
|
|
9
|
-
* fires once per session. Flag is cleaned up by stop-reminder.cjs.
|
|
10
|
-
*/
|
|
11
|
-
const fs = require('fs');
|
|
12
|
-
const path = require('path');
|
|
13
|
-
|
|
14
|
-
let raw = '';
|
|
15
|
-
process.stdin.on('data', (d) => { raw += d; });
|
|
16
|
-
process.stdin.on('end', () => {
|
|
17
|
-
let payload = {};
|
|
18
|
-
try { payload = JSON.parse(raw || '{}'); } catch (_) { process.exit(0); }
|
|
19
|
-
|
|
20
|
-
const cwd = (payload && payload.cwd) || process.cwd();
|
|
21
|
-
const flagPath = path.join(cwd, '.hero-mmt-kit', 'session-injected.flag');
|
|
22
|
-
const sessionPath = path.join(cwd, '.hero-mmt-kit', 'session.json');
|
|
23
|
-
|
|
24
|
-
if (fs.existsSync(flagPath)) process.exit(0);
|
|
25
|
-
|
|
26
|
-
let session;
|
|
27
|
-
try { session = JSON.parse(fs.readFileSync(sessionPath, 'utf8')); } catch (_) { process.exit(0); }
|
|
28
|
-
if (!session || typeof session !== 'object') process.exit(0);
|
|
29
|
-
|
|
30
|
-
const sep = '─'.repeat(55);
|
|
31
|
-
process.stderr.write([
|
|
32
|
-
sep,
|
|
33
|
-
'[hero-mmt-kit] Session state (auto-injected)',
|
|
34
|
-
` Current skill : ${session.currentSkill ?? '(none)'}`,
|
|
35
|
-
` Resume path : ${session.resumePath ?? '(not set)'}`,
|
|
36
|
-
` Next action : ${session.nextAction ?? '(none)'}`,
|
|
37
|
-
sep,
|
|
38
|
-
].join('\n') + '\n');
|
|
39
|
-
|
|
40
|
-
try { fs.writeFileSync(flagPath, ''); } catch (_) { /* best-effort */ }
|
|
41
|
-
|
|
42
|
-
process.exit(0);
|
|
43
|
-
});
|
|
@@ -1,253 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: finishing-a-development-branch
|
|
3
|
-
description: Use when implementation is complete, all tests pass, and you need to decide how to integrate the work - guides completion of development work by presenting structured options for merge, PR, or cleanup
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
# Finishing a Development Branch
|
|
7
|
-
|
|
8
|
-
## Overview
|
|
9
|
-
|
|
10
|
-
Guide completion of development work by presenting clear options and handling chosen workflow.
|
|
11
|
-
|
|
12
|
-
**Core principle:** Verify tests → Detect environment → Present options → Execute choice → Clean up.
|
|
13
|
-
|
|
14
|
-
**See also:** `using-git-worktrees` — this skill finishes and cleans up the workspace that `using-git-worktrees` sets up. Directory ownership and provenance conventions are defined there.
|
|
15
|
-
|
|
16
|
-
**Announce at start:** "I'm using the finishing-a-development-branch skill to complete this work."
|
|
17
|
-
|
|
18
|
-
## The Process
|
|
19
|
-
|
|
20
|
-
### Step 1: Verify Tests
|
|
21
|
-
|
|
22
|
-
**Before presenting options, verify tests pass:**
|
|
23
|
-
|
|
24
|
-
```bash
|
|
25
|
-
# Run project's test suite
|
|
26
|
-
npm test / cargo test / pytest / go test ./...
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
**If tests fail:**
|
|
30
|
-
```
|
|
31
|
-
Tests failing (<N> failures). Must fix before completing:
|
|
32
|
-
|
|
33
|
-
[Show failures]
|
|
34
|
-
|
|
35
|
-
Cannot proceed with merge/PR until tests pass.
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
Stop. Don't proceed to Step 2.
|
|
39
|
-
|
|
40
|
-
**If tests pass:** Continue to Step 2.
|
|
41
|
-
|
|
42
|
-
### Step 2: Detect Environment
|
|
43
|
-
|
|
44
|
-
**Determine workspace state before presenting options:**
|
|
45
|
-
|
|
46
|
-
```bash
|
|
47
|
-
GIT_DIR=$(cd "$(git rev-parse --git-dir)" 2>/dev/null && pwd -P)
|
|
48
|
-
GIT_COMMON=$(cd "$(git rev-parse --git-common-dir)" 2>/dev/null && pwd -P)
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
This determines which menu to show and how cleanup works:
|
|
52
|
-
|
|
53
|
-
| State | Menu | Cleanup |
|
|
54
|
-
|-------|------|---------|
|
|
55
|
-
| `GIT_DIR == GIT_COMMON` (normal repo) | Standard 4 options | No worktree to clean up |
|
|
56
|
-
| `GIT_DIR != GIT_COMMON`, named branch | Standard 4 options | Provenance-based (see Step 6) |
|
|
57
|
-
| `GIT_DIR != GIT_COMMON`, detached HEAD | Reduced 3 options (no merge) | No cleanup (externally managed) |
|
|
58
|
-
|
|
59
|
-
### Step 3: Determine Base Branch
|
|
60
|
-
|
|
61
|
-
```bash
|
|
62
|
-
# Try common base branches
|
|
63
|
-
git merge-base HEAD main 2>/dev/null || git merge-base HEAD master 2>/dev/null
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
Or ask: "This branch split from main - is that correct?"
|
|
67
|
-
|
|
68
|
-
### Step 4: Present Options
|
|
69
|
-
|
|
70
|
-
**Normal repo and named-branch worktree — present exactly these 4 options:**
|
|
71
|
-
|
|
72
|
-
```
|
|
73
|
-
Implementation complete. What would you like to do?
|
|
74
|
-
|
|
75
|
-
1. Merge back to <base-branch> locally
|
|
76
|
-
2. Push and create a Pull Request
|
|
77
|
-
3. Keep the branch as-is (I'll handle it later)
|
|
78
|
-
4. Discard this work
|
|
79
|
-
|
|
80
|
-
Which option?
|
|
81
|
-
```
|
|
82
|
-
|
|
83
|
-
**Detached HEAD — present exactly these 3 options:**
|
|
84
|
-
|
|
85
|
-
```
|
|
86
|
-
Implementation complete. You're on a detached HEAD (externally managed workspace).
|
|
87
|
-
|
|
88
|
-
1. Push as new branch and create a Pull Request
|
|
89
|
-
2. Keep as-is (I'll handle it later)
|
|
90
|
-
3. Discard this work
|
|
91
|
-
|
|
92
|
-
Which option?
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
**Don't add explanation** - keep options concise.
|
|
96
|
-
|
|
97
|
-
### Step 5: Execute Choice
|
|
98
|
-
|
|
99
|
-
#### Option 1: Merge Locally
|
|
100
|
-
|
|
101
|
-
```bash
|
|
102
|
-
# Get main repo root for CWD safety
|
|
103
|
-
MAIN_ROOT=$(git -C "$(git rev-parse --git-common-dir)/.." rev-parse --show-toplevel)
|
|
104
|
-
cd "$MAIN_ROOT"
|
|
105
|
-
|
|
106
|
-
# Merge first — verify success before removing anything
|
|
107
|
-
git checkout <base-branch>
|
|
108
|
-
git pull
|
|
109
|
-
git merge <feature-branch>
|
|
110
|
-
|
|
111
|
-
# Verify tests on merged result
|
|
112
|
-
<test command>
|
|
113
|
-
|
|
114
|
-
# Only after merge succeeds: cleanup worktree (Step 6), then delete branch
|
|
115
|
-
```
|
|
116
|
-
|
|
117
|
-
Then: Cleanup worktree (Step 6), then delete branch:
|
|
118
|
-
|
|
119
|
-
```bash
|
|
120
|
-
git branch -d <feature-branch>
|
|
121
|
-
```
|
|
122
|
-
|
|
123
|
-
#### Option 2: Push and Create PR
|
|
124
|
-
|
|
125
|
-
```bash
|
|
126
|
-
# Push branch
|
|
127
|
-
git push -u origin <feature-branch>
|
|
128
|
-
|
|
129
|
-
# Create PR
|
|
130
|
-
gh pr create --title "<title>" --body "$(cat <<'EOF'
|
|
131
|
-
## Summary
|
|
132
|
-
<2-3 bullets of what changed>
|
|
133
|
-
|
|
134
|
-
## Test Plan
|
|
135
|
-
- [ ] <verification steps>
|
|
136
|
-
EOF
|
|
137
|
-
)"
|
|
138
|
-
```
|
|
139
|
-
|
|
140
|
-
**Do NOT clean up worktree** — user needs it alive to iterate on PR feedback.
|
|
141
|
-
|
|
142
|
-
#### Option 3: Keep As-Is
|
|
143
|
-
|
|
144
|
-
Report: "Keeping branch <name>. Worktree preserved at <path>."
|
|
145
|
-
|
|
146
|
-
**Don't cleanup worktree.**
|
|
147
|
-
|
|
148
|
-
#### Option 4: Discard
|
|
149
|
-
|
|
150
|
-
**Confirm first:**
|
|
151
|
-
```
|
|
152
|
-
This will permanently delete:
|
|
153
|
-
- Branch <name>
|
|
154
|
-
- All commits: <commit-list>
|
|
155
|
-
- Worktree at <path>
|
|
156
|
-
|
|
157
|
-
Type 'discard' to confirm.
|
|
158
|
-
```
|
|
159
|
-
|
|
160
|
-
Wait for exact confirmation.
|
|
161
|
-
|
|
162
|
-
If confirmed:
|
|
163
|
-
```bash
|
|
164
|
-
MAIN_ROOT=$(git -C "$(git rev-parse --git-common-dir)/.." rev-parse --show-toplevel)
|
|
165
|
-
cd "$MAIN_ROOT"
|
|
166
|
-
```
|
|
167
|
-
|
|
168
|
-
Then: Cleanup worktree (Step 6), then force-delete branch:
|
|
169
|
-
```bash
|
|
170
|
-
git branch -D <feature-branch>
|
|
171
|
-
```
|
|
172
|
-
|
|
173
|
-
### Step 6: Cleanup Workspace
|
|
174
|
-
|
|
175
|
-
**Only runs for Options 1 and 4.** Options 2 and 3 always preserve the worktree.
|
|
176
|
-
|
|
177
|
-
```bash
|
|
178
|
-
GIT_DIR=$(cd "$(git rev-parse --git-dir)" 2>/dev/null && pwd -P)
|
|
179
|
-
GIT_COMMON=$(cd "$(git rev-parse --git-common-dir)" 2>/dev/null && pwd -P)
|
|
180
|
-
WORKTREE_PATH=$(git rev-parse --show-toplevel)
|
|
181
|
-
```
|
|
182
|
-
|
|
183
|
-
**If `GIT_DIR == GIT_COMMON`:** Normal repo, no worktree to clean up. Done.
|
|
184
|
-
|
|
185
|
-
**If the worktree path is under one of the owned directories defined in `using-git-worktrees` § Directory Selection (`.worktrees/` or `worktrees/`):** Superpowers created this worktree — we own cleanup.
|
|
186
|
-
|
|
187
|
-
```bash
|
|
188
|
-
MAIN_ROOT=$(git -C "$(git rev-parse --git-common-dir)/.." rev-parse --show-toplevel)
|
|
189
|
-
cd "$MAIN_ROOT"
|
|
190
|
-
git worktree remove "$WORKTREE_PATH"
|
|
191
|
-
git worktree prune # Self-healing: clean up any stale registrations
|
|
192
|
-
```
|
|
193
|
-
|
|
194
|
-
**Otherwise:** The host environment (harness) owns this workspace. Do NOT remove it. If your platform provides a workspace-exit tool, use it. Otherwise, leave the workspace in place.
|
|
195
|
-
|
|
196
|
-
## Quick Reference
|
|
197
|
-
|
|
198
|
-
| Option | Merge | Push | Keep Worktree | Cleanup Branch |
|
|
199
|
-
|--------|-------|------|---------------|----------------|
|
|
200
|
-
| 1. Merge locally | yes | - | - | yes |
|
|
201
|
-
| 2. Create PR | - | yes | yes | - |
|
|
202
|
-
| 3. Keep as-is | - | - | yes | - |
|
|
203
|
-
| 4. Discard | - | - | - | yes (force) |
|
|
204
|
-
|
|
205
|
-
## Common Mistakes
|
|
206
|
-
|
|
207
|
-
**Skipping test verification**
|
|
208
|
-
- **Problem:** Merge broken code, create failing PR
|
|
209
|
-
- **Fix:** Always verify tests before offering options
|
|
210
|
-
|
|
211
|
-
**Open-ended questions**
|
|
212
|
-
- **Problem:** "What should I do next?" is ambiguous
|
|
213
|
-
- **Fix:** Present exactly 4 structured options (or 3 for detached HEAD)
|
|
214
|
-
|
|
215
|
-
**Cleaning up worktree for Option 2**
|
|
216
|
-
- **Problem:** Remove worktree user needs for PR iteration
|
|
217
|
-
- **Fix:** Only cleanup for Options 1 and 4
|
|
218
|
-
|
|
219
|
-
**Deleting branch before removing worktree**
|
|
220
|
-
- **Problem:** `git branch -d` fails because worktree still references the branch
|
|
221
|
-
- **Fix:** Merge first, remove worktree, then delete branch
|
|
222
|
-
|
|
223
|
-
**Running git worktree remove from inside the worktree**
|
|
224
|
-
- **Problem:** Command fails silently when CWD is inside the worktree being removed
|
|
225
|
-
- **Fix:** Always `cd` to main repo root before `git worktree remove`
|
|
226
|
-
|
|
227
|
-
**Cleaning up harness-owned worktrees**
|
|
228
|
-
- **Problem:** Removing a worktree the harness created causes phantom state
|
|
229
|
-
- **Fix:** Only clean up worktrees under the owned directories from `using-git-worktrees` § Directory Selection (`.worktrees/` or `worktrees/`)
|
|
230
|
-
|
|
231
|
-
**No confirmation for discard**
|
|
232
|
-
- **Problem:** Accidentally delete work
|
|
233
|
-
- **Fix:** Require typed "discard" confirmation
|
|
234
|
-
|
|
235
|
-
## Red Flags
|
|
236
|
-
|
|
237
|
-
**Never:**
|
|
238
|
-
- Proceed with failing tests
|
|
239
|
-
- Merge without verifying tests on result
|
|
240
|
-
- Delete work without confirmation
|
|
241
|
-
- Force-push without explicit request
|
|
242
|
-
- Remove a worktree before confirming merge success
|
|
243
|
-
- Clean up worktrees you didn't create (provenance check)
|
|
244
|
-
- Run `git worktree remove` from inside the worktree
|
|
245
|
-
|
|
246
|
-
**Always:**
|
|
247
|
-
- Verify tests before offering options
|
|
248
|
-
- Detect environment before presenting menu
|
|
249
|
-
- Present exactly 4 options (or 3 for detached HEAD)
|
|
250
|
-
- Get typed confirmation for Option 4
|
|
251
|
-
- Clean up worktree for Options 1 & 4 only
|
|
252
|
-
- `cd` to main repo root before worktree removal
|
|
253
|
-
- Run `git worktree prune` after removal
|