continuous-improvement 3.1.0 → 3.9.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.
- package/.claude-plugin/marketplace.json +66 -0
- package/CHANGELOG.md +216 -0
- package/QUICKSTART.md +79 -12
- package/README.md +229 -349
- package/SKILL.md +87 -9
- package/action.yml +1 -1
- package/bin/analyze.sh +9 -1
- package/bin/backfill.mjs +172 -0
- package/bin/check-doc-runtime-claims.mjs +120 -0
- package/bin/check-docs-substrings.mjs +333 -0
- package/bin/check-everything-mirror.mjs +145 -0
- package/bin/check-routing-targets.mjs +151 -0
- package/bin/check-skill-law-tag.mjs +128 -0
- package/bin/check-skill-mirror.mjs +119 -0
- package/bin/check-skill-tiers.mjs +116 -0
- package/bin/check-third-party-shape.mjs +202 -0
- package/bin/generate-plugin-manifests.mjs +171 -0
- package/bin/harvest-friction.mjs +279 -0
- package/bin/hook-stats.mjs +258 -0
- package/bin/install.mjs +407 -499
- package/bin/lint-transcript.mjs +182 -210
- package/bin/mcp-server.mjs +834 -608
- package/bin/observe.mjs +148 -0
- package/bin/pre-commit-block-strays.sh +49 -0
- package/bin/refresh-third-party.mjs +416 -0
- package/bin/unified-cli.mjs +533 -0
- package/commands/continuous-improvement.md +43 -2
- package/commands/discipline.md +14 -0
- package/commands/harvest.md +76 -0
- package/commands/learn-eval.md +117 -0
- package/commands/planning-with-files.md +66 -0
- package/commands/proceed-with-the-recommendation.md +62 -0
- package/commands/ralph.md +103 -0
- package/commands/release-train.md +81 -0
- package/commands/seven-laws.md +16 -0
- package/commands/superpowers.md +180 -0
- package/commands/swarm.md +101 -0
- package/commands/workspace-surface-audit.md +77 -0
- package/hooks/gateguard.mjs +172 -0
- package/hooks/observe.sh +42 -4
- package/hooks/session.sh +3 -3
- package/hooks/three-section-close.mjs +181 -0
- package/instinct-packs/meta.json +16 -0
- package/lib/cli-anything.mjs +401 -0
- package/lib/compound-engineering.mjs +831 -0
- package/lib/gateguard-state.mjs +85 -0
- package/lib/observe-event.mjs +128 -0
- package/lib/plugin-metadata.mjs +435 -0
- package/lib/pm-marketplace.mjs +61 -0
- package/lib/pm-skills.mjs +1274 -0
- package/lib/resolve-home-dir.mjs +43 -0
- package/lib/skill-tiers.mjs +137 -0
- package/lib/unified-plugin.mjs +924 -0
- package/llms.txt +32 -7
- package/package.json +29 -19
- package/plugins/beginner.json +17 -6
- package/plugins/continuous-improvement/.claude-plugin/marketplace.json +20 -0
- package/plugins/continuous-improvement/.claude-plugin/plugin.json +26 -0
- package/plugins/continuous-improvement/LICENSE +21 -0
- package/plugins/continuous-improvement/README.md +57 -0
- package/plugins/continuous-improvement/agents/README.md +120 -0
- package/plugins/continuous-improvement/agents/code-reviewer.md +97 -0
- package/plugins/continuous-improvement/agents/security-auditor.md +101 -0
- package/plugins/continuous-improvement/agents/test-engineer.md +95 -0
- package/plugins/continuous-improvement/bin/backfill.mjs +172 -0
- package/plugins/continuous-improvement/bin/mcp-server.mjs +889 -0
- package/plugins/continuous-improvement/bin/observe.mjs +148 -0
- package/plugins/continuous-improvement/commands/continuous-improvement.md +115 -0
- package/plugins/continuous-improvement/commands/dashboard.md +56 -0
- package/plugins/continuous-improvement/commands/discipline.md +51 -0
- package/plugins/continuous-improvement/commands/harvest.md +76 -0
- package/plugins/continuous-improvement/commands/learn-eval.md +117 -0
- package/plugins/continuous-improvement/commands/planning-with-files.md +66 -0
- package/plugins/continuous-improvement/commands/proceed-with-the-recommendation.md +62 -0
- package/plugins/continuous-improvement/commands/ralph.md +103 -0
- package/plugins/continuous-improvement/commands/release-train.md +81 -0
- package/plugins/continuous-improvement/commands/seven-laws.md +16 -0
- package/plugins/continuous-improvement/commands/superpowers.md +180 -0
- package/plugins/continuous-improvement/commands/swarm.md +101 -0
- package/plugins/continuous-improvement/commands/workspace-surface-audit.md +77 -0
- package/plugins/continuous-improvement/hooks/gateguard.mjs +172 -0
- package/plugins/continuous-improvement/hooks/hooks.json +65 -0
- package/plugins/continuous-improvement/hooks/observe.sh +172 -0
- package/plugins/continuous-improvement/hooks/session.sh +106 -0
- package/plugins/continuous-improvement/hooks/three-section-close.mjs +181 -0
- package/plugins/continuous-improvement/instinct-packs/go.json +58 -0
- package/plugins/continuous-improvement/instinct-packs/meta.json +16 -0
- package/plugins/continuous-improvement/instinct-packs/python.json +58 -0
- package/plugins/continuous-improvement/instinct-packs/react.json +58 -0
- package/plugins/continuous-improvement/lib/observe-event.mjs +128 -0
- package/plugins/continuous-improvement/lib/plugin-metadata.mjs +435 -0
- package/plugins/continuous-improvement/lib/resolve-home-dir.mjs +43 -0
- package/plugins/continuous-improvement/skills/README.md +37 -0
- package/plugins/continuous-improvement/skills/continuous-improvement/SKILL.md +249 -0
- package/plugins/continuous-improvement/skills/deploy-receipt/SKILL.md +178 -0
- package/plugins/continuous-improvement/skills/gateguard/SKILL.md +163 -0
- package/plugins/continuous-improvement/skills/para-memory-files/SKILL.md +108 -0
- package/plugins/continuous-improvement/skills/proceed-with-the-recommendation/SKILL.md +447 -0
- package/plugins/continuous-improvement/skills/ralph/SKILL.md +221 -0
- package/plugins/continuous-improvement/skills/recovery-classification/SKILL.md +73 -0
- package/plugins/continuous-improvement/skills/safety-guard/SKILL.md +76 -0
- package/plugins/continuous-improvement/skills/state-reconciliation/SKILL.md +63 -0
- package/plugins/continuous-improvement/skills/strategic-compact/SKILL.md +104 -0
- package/plugins/continuous-improvement/skills/superpowers/SKILL.md +219 -0
- package/plugins/continuous-improvement/skills/tdd-workflow/SKILL.md +411 -0
- package/plugins/continuous-improvement/skills/token-budget-advisor/SKILL.md +136 -0
- package/plugins/continuous-improvement/skills/verification-loop/SKILL.md +224 -0
- package/plugins/continuous-improvement/skills/wild-risa-balance/SKILL.md +191 -0
- package/plugins/continuous-improvement/skills/workspace-surface-audit/SKILL.md +147 -0
- package/plugins/continuous-improvement/skills/worktree-safety/SKILL.md +66 -0
- package/plugins/continuous-improvement/templates/planning-with-files/findings.md +8 -0
- package/plugins/continuous-improvement/templates/planning-with-files/progress.md +7 -0
- package/plugins/continuous-improvement/templates/planning-with-files/task_plan.md +23 -0
- package/plugins/expert.json +26 -5
- package/skills/README.md +79 -0
- package/skills/deploy-receipt.md +178 -0
- package/skills/gateguard.md +163 -0
- package/skills/para-memory-files.md +108 -0
- package/skills/proceed-with-the-recommendation.md +447 -0
- package/skills/ralph.md +221 -0
- package/skills/recovery-classification.md +73 -0
- package/skills/safety-guard.md +76 -0
- package/skills/state-reconciliation.md +63 -0
- package/skills/strategic-compact.md +104 -0
- package/skills/superpowers.md +219 -0
- package/skills/tdd-workflow.md +411 -0
- package/skills/token-budget-advisor.md +136 -0
- package/skills/verification-loop.md +224 -0
- package/skills/wild-risa-balance.md +191 -0
- package/skills/workspace-surface-audit.md +147 -0
- package/skills/worktree-safety.md +66 -0
- package/templates/insights-claude-md.md +91 -0
- package/templates/planning-with-files/findings.md +8 -0
- package/templates/planning-with-files/progress.md +7 -0
- package/templates/planning-with-files/task_plan.md +23 -0
- package/templates/verify-ladder.example.json +60 -0
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: ralph
|
|
3
|
+
tier: companion
|
|
4
|
+
description: "Enforces Law 6 (Iterate Means One Thing) of the 7 Laws of AI Agent Discipline at PRD scale. Ralph is an autonomous AI agent loop that runs repeatedly until all PRD items are complete. Converts PRDs to executable JSON, implements stories iteratively with quality checks, and tracks progress."
|
|
5
|
+
origin: https://github.com/snarktank/ralph
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# Ralph — Autonomous Agent Loop
|
|
9
|
+
|
|
10
|
+
Ralph runs iteratively until all PRD stories are complete. Each iteration: picks highest priority story, implements, runs quality checks, commits if passing, updates progress, repeats.
|
|
11
|
+
|
|
12
|
+
## When to Use
|
|
13
|
+
|
|
14
|
+
- Large features that exceed a single context window
|
|
15
|
+
- Multi-story PRDs that need consistent implementation
|
|
16
|
+
- Tasks requiring repeated verification and commit cycles
|
|
17
|
+
- Long-running development that benefits from persistence across interruptions
|
|
18
|
+
|
|
19
|
+
## Do NOT Use When
|
|
20
|
+
|
|
21
|
+
- Task is a one-shot fix completable in a single edit — just edit the file
|
|
22
|
+
- You haven't written a PRD yet — write the PRD first, then run Ralph against it
|
|
23
|
+
- The work spans fewer than 3 stories — single-iteration verification is enough
|
|
24
|
+
- You need to explore or plan before committing to scope — use a planning skill first; Ralph is for execution, not discovery
|
|
25
|
+
- You want manual control over each iteration — run quality checks yourself, no need for Ralph's loop
|
|
26
|
+
|
|
27
|
+
## Prerequisites
|
|
28
|
+
|
|
29
|
+
- Git repository
|
|
30
|
+
- PRD document (markdown format)
|
|
31
|
+
- `jq` installed (`brew install jq` on macOS)
|
|
32
|
+
|
|
33
|
+
## Workflow
|
|
34
|
+
|
|
35
|
+
### 1. Create a PRD
|
|
36
|
+
|
|
37
|
+
Generate a detailed requirements document using the PRD skill:
|
|
38
|
+
|
|
39
|
+
```
|
|
40
|
+
Load the prd skill and create a PRD for [your feature description]
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Output saved to `tasks/prd-[feature-name].md`
|
|
44
|
+
|
|
45
|
+
**CRITICAL — refine generic criteria before iteration begins.** Auto-generated PRD scaffolds often produce generic acceptance criteria like `["Implementation is complete", "Code compiles without errors"]`. These are theater — Ralph cannot prove a story passes against criteria that don't actually constrain it. Replace every generic criterion with a concrete, testable statement before moving to step 2.
|
|
46
|
+
|
|
47
|
+
- Bad: `"Function is implemented correctly"`
|
|
48
|
+
- Good: `"Function parseUserInput(s) returns {ok: true, value} for valid s and {ok: false, error} for invalid s, asserted by tests/parse-user-input.test.ts"`
|
|
49
|
+
- Bad: `"Code compiles"`
|
|
50
|
+
- Good: `"TypeScript compiles with no errors (npm run build) AND lsp diagnostics show 0 errors on src/parse-user-input.ts"`
|
|
51
|
+
|
|
52
|
+
If you cannot write a testable criterion, the story is too big. Break it down before continuing.
|
|
53
|
+
|
|
54
|
+
**Example — refining a scaffold criterion**
|
|
55
|
+
|
|
56
|
+
Auto-generated:
|
|
57
|
+
|
|
58
|
+
```json
|
|
59
|
+
"acceptanceCriteria": [
|
|
60
|
+
"Implementation is complete",
|
|
61
|
+
"Code compiles without errors"
|
|
62
|
+
]
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
After refinement:
|
|
66
|
+
|
|
67
|
+
```json
|
|
68
|
+
"acceptanceCriteria": [
|
|
69
|
+
"POST /api/users returns 201 with {id, email} for valid input, asserted by tests/api-users.test.ts",
|
|
70
|
+
"POST /api/users returns 400 with {error} for missing email, asserted by tests/api-users.test.ts",
|
|
71
|
+
"TypeScript compiles with 0 errors (npm run build)",
|
|
72
|
+
"lsp diagnostics show 0 errors on src/api/users.ts"
|
|
73
|
+
]
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### 2. Convert PRD to Ralph Format
|
|
77
|
+
|
|
78
|
+
Convert the markdown PRD to executable JSON:
|
|
79
|
+
|
|
80
|
+
```
|
|
81
|
+
Load the ralph skill and convert tasks/prd-[feature-name].md to prd.json
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
This creates `prd.json` with user stories structured for autonomous execution.
|
|
85
|
+
|
|
86
|
+
### 3. Run Ralph
|
|
87
|
+
|
|
88
|
+
Execute the autonomous loop:
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
# Using Amp (default)
|
|
92
|
+
./scripts/ralph/ralph.sh [max_iterations]
|
|
93
|
+
|
|
94
|
+
# Using Claude Code
|
|
95
|
+
./scripts/ralph/ralph.sh --tool claude [max_iterations]
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
Default: 10 iterations. Use `--tool amp` or `--tool claude` to select your AI tool.
|
|
99
|
+
|
|
100
|
+
## Ralph Loop Steps
|
|
101
|
+
|
|
102
|
+
1. **Create feature branch** — from PRD `branchName`
|
|
103
|
+
2. **Pick highest priority story** — where `passes: false`
|
|
104
|
+
3. **Implement that single story** — fresh context per iteration
|
|
105
|
+
4. **Run quality checks** — verify the current story's specific acceptance criteria with fresh evidence:
|
|
106
|
+
- For EACH acceptance criterion, run the test/build/lint that proves it
|
|
107
|
+
- Read the output, do not assume
|
|
108
|
+
- If ANY criterion is not met, continue working — do NOT mark the story as `passes: true`
|
|
109
|
+
- **Suite-level "all tests pass" is NOT a substitute for criterion-level proof.**
|
|
110
|
+
|
|
111
|
+
**Example — story-by-story verification**
|
|
112
|
+
|
|
113
|
+
Bad:
|
|
114
|
+
|
|
115
|
+
```
|
|
116
|
+
Story US-002: "Add /api/users endpoint"
|
|
117
|
+
- Ran npm test → all green → marked passes: true
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
Why bad: suite-level pass doesn't prove THIS story's criteria. Other tests could be passing while the new endpoint is broken.
|
|
121
|
+
|
|
122
|
+
Good:
|
|
123
|
+
|
|
124
|
+
```
|
|
125
|
+
Story US-002: "Add /api/users endpoint"
|
|
126
|
+
- Criterion 1: POST /api/users → 201 → ran `npx vitest tests/api-users.test.ts -t "valid input"` → PASS
|
|
127
|
+
- Criterion 2: POST /api/users → 400 → ran `npx vitest tests/api-users.test.ts -t "missing email"` → PASS
|
|
128
|
+
- Criterion 3: typecheck → ran `npm run build` → 0 errors
|
|
129
|
+
- All criteria met with fresh evidence → marked passes: true
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
Why good: each criterion proven with a targeted run; the output was read before the mark.
|
|
133
|
+
|
|
134
|
+
5. **Commit if checks pass** — atomic commits per story
|
|
135
|
+
6. **Update prd.json** — mark story as `passes: true`
|
|
136
|
+
7. **Append learnings** — to `progress.txt`
|
|
137
|
+
8. **Repeat** — until all stories pass or max iterations reached
|
|
138
|
+
|
|
139
|
+
## Key Concepts
|
|
140
|
+
|
|
141
|
+
### Each Iteration = Fresh Context
|
|
142
|
+
|
|
143
|
+
Every story gets a clean slate. Previous work is visible only via git history and `prd.json`, preventing context pollution.
|
|
144
|
+
|
|
145
|
+
### Small Tasks
|
|
146
|
+
|
|
147
|
+
Stories should be completable in 10-30 minutes. If a story stalls, break it down.
|
|
148
|
+
|
|
149
|
+
### AGENTS.md Updates Are Critical
|
|
150
|
+
|
|
151
|
+
Ralph updates `AGENTS.md` after each story so subsequent iterations know what's already done.
|
|
152
|
+
|
|
153
|
+
### Feedback Loops
|
|
154
|
+
|
|
155
|
+
- Build/test failures: immediate fix or rollback
|
|
156
|
+
- Test failures: investigate before declaring pass
|
|
157
|
+
- Confusion: log to `progress.txt` for human review
|
|
158
|
+
|
|
159
|
+
### Browser Verification for UI Stories
|
|
160
|
+
|
|
161
|
+
Ralph starts a dev server and uses Playwright to verify UI stories actually render.
|
|
162
|
+
|
|
163
|
+
### Stop Condition
|
|
164
|
+
|
|
165
|
+
Ralph stops when:
|
|
166
|
+
- All stories have `passes: true`
|
|
167
|
+
- Max iterations reached
|
|
168
|
+
- Critical failure encountered (user intervention required)
|
|
169
|
+
|
|
170
|
+
## Anti-patterns
|
|
171
|
+
|
|
172
|
+
These thoughts mean STOP — Ralph is about to slip:
|
|
173
|
+
|
|
174
|
+
| Thought | Why it's wrong |
|
|
175
|
+
|---|---|
|
|
176
|
+
| "All stories pass, time to summarise and wait for the user" mid-loop | Polite-stop. Ralph continues through commit + progress update + next pick in the same turn. |
|
|
177
|
+
| "Tests pass at the suite level, the story must be done" | Suite-level pass is not criterion-level proof. Verify each criterion with fresh evidence. |
|
|
178
|
+
| "Story is bigger than expected, I'll mark it passes: true and add a TODO" | Scope reduction. Either complete the story or break it down — never declare partial completion. |
|
|
179
|
+
| "The criterion is generic but obviously the test covers it" | PRD theater. Refine the criterion to something specific before proceeding. |
|
|
180
|
+
| "I'll skip the failing test by deleting/skipping it" | Tests are evidence. Fix the implementation, not the test. |
|
|
181
|
+
| "Reviewer said it looks good" — without running fresh checks | "Looks good" is not verification. Run the build, run the tests, read the output. |
|
|
182
|
+
|
|
183
|
+
## Final Checklist (Hard Gate)
|
|
184
|
+
|
|
185
|
+
Ralph cannot exit cleanly until ALL of these are true:
|
|
186
|
+
|
|
187
|
+
- [ ] Every story in `prd.json` has `passes: true` (no incomplete stories)
|
|
188
|
+
- [ ] Acceptance criteria are task-specific (no `"Implementation is complete"` generics)
|
|
189
|
+
- [ ] All requirements from the original task are met (no scope reduction)
|
|
190
|
+
- [ ] Fresh test run output shows all tests pass (read it, don't assume)
|
|
191
|
+
- [ ] Fresh build output shows success (read it, don't assume)
|
|
192
|
+
- [ ] No tests were deleted, skipped, or weakened to make checks green
|
|
193
|
+
- [ ] `progress.txt` records implementation details and learnings per iteration
|
|
194
|
+
- [ ] Working tree is clean (every story committed atomically)
|
|
195
|
+
|
|
196
|
+
A failing checkbox is a hard halt — do not declare done.
|
|
197
|
+
|
|
198
|
+
## Files
|
|
199
|
+
|
|
200
|
+
- `prd.json` — executable PRD with user stories
|
|
201
|
+
- `progress.txt` — accumulated learnings and status
|
|
202
|
+
- `ralph.sh` — the loop script
|
|
203
|
+
- `AGENTS.md` — iteration memory
|
|
204
|
+
|
|
205
|
+
## Debugging
|
|
206
|
+
|
|
207
|
+
If Ralph gets stuck:
|
|
208
|
+
|
|
209
|
+
1. Check `prd.json` for malformed stories
|
|
210
|
+
2. Review `progress.txt` for accumulated errors
|
|
211
|
+
3. Verify tests pass independently: `npm test` or equivalent
|
|
212
|
+
4. Check git status for uncommitted changes
|
|
213
|
+
5. Run single iteration manually to isolate issues
|
|
214
|
+
|
|
215
|
+
## Customizing the Prompt
|
|
216
|
+
|
|
217
|
+
Edit the prompt template in `scripts/ralph/prompt.md` (Amp) or `scripts/ralph/CLAUDE.md` (Claude Code) to adjust behavior.
|
|
218
|
+
|
|
219
|
+
## Archiving
|
|
220
|
+
|
|
221
|
+
After completion, archive `prd.json` and `progress.txt` to `tasks/archive/[date]/` for future reference.
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: recovery-classification
|
|
3
|
+
tier: "2"
|
|
4
|
+
description: "Enforces Law 4 (Verify Before Reporting) of the 7 Laws of AI Agent Discipline. After any failure in the verification ladder or auto-loop, classify the failure class before retrying — provider, tool-schema, deterministic-policy, git, worktree, runtime — so retry-vs-pause-vs-self-heal-vs-stop is an intentional decision, not a generic 'try again'."
|
|
5
|
+
origin: continuous-improvement
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# Recovery Classification Skill
|
|
9
|
+
|
|
10
|
+
When a phase or unit fails, name the failure class first. Generic "retry on failure" hides repeatable failure modes and turns them into flaky tests.
|
|
11
|
+
|
|
12
|
+
## When to Use
|
|
13
|
+
|
|
14
|
+
- After any Phase 1–6 failure in `verification-loop`.
|
|
15
|
+
- After any auto-loop unit that exits non-zero.
|
|
16
|
+
- After any tool call the harness rejects (schema validation, policy gate, deterministic block).
|
|
17
|
+
- Before re-running anything that just failed — classification fires once, before the first retry.
|
|
18
|
+
|
|
19
|
+
## Why This Skill Exists
|
|
20
|
+
|
|
21
|
+
GSD-2's [CONTEXT.md](https://github.com/gsd-build/gsd-2/blob/main/CONTEXT.md) names "Recovery Classification" as one of four runtime invariant modules. Common failure modes it catches:
|
|
22
|
+
|
|
23
|
+
- **Deterministic-policy blocks misclassified as generic provider failures** — gateguard denials retried in a loop until budget is exhausted.
|
|
24
|
+
- **Schema-validation failures retried verbatim** — wasting tokens on a call the validator will keep rejecting.
|
|
25
|
+
- **Stale-worker / stale-lock states** — no retry can resolve a worker that died holding a lock; the loop just spins.
|
|
26
|
+
- **Worktree-invalidity errors** — recovery can't fix without operator intervention; retrying writes to a broken root.
|
|
27
|
+
|
|
28
|
+
A retry without a class is a guess; a guess at scale is a budget leak.
|
|
29
|
+
|
|
30
|
+
## The Classification Taxonomy
|
|
31
|
+
|
|
32
|
+
Six classes. Each maps to one intentional action:
|
|
33
|
+
|
|
34
|
+
| Class | Signal | Action |
|
|
35
|
+
|---|---|---|
|
|
36
|
+
| **provider** | API timeout, 5xx, rate limit, network, transient cloud error | retry with exponential backoff |
|
|
37
|
+
| **tool-schema** | tool input rejected by validator, missing required field, type mismatch | repair input, do **not** retry verbatim |
|
|
38
|
+
| **deterministic-policy** | gateguard / write-gate / permission denied / explicit policy block | pause, ask operator (do **not** retry) |
|
|
39
|
+
| **git** | merge conflict, detached HEAD, unmerged paths, lockfile, pre-commit hook | self-heal if known recipe, else pause |
|
|
40
|
+
| **worktree** | missing `.git`, invalid root, lease lost, prunable worktree, foreign session | stop — never spawn workers into unresolved paths |
|
|
41
|
+
| **runtime** | OOM, segfault, host kill, parent process gone, context exhaustion | stop, surface to operator |
|
|
42
|
+
|
|
43
|
+
A failure that fits no class is `unclassified` — that itself is a signal: the taxonomy is incomplete and needs a new entry, not a retry.
|
|
44
|
+
|
|
45
|
+
## The Output Contract
|
|
46
|
+
|
|
47
|
+
Before any retry, emit one fenced block:
|
|
48
|
+
|
|
49
|
+
```
|
|
50
|
+
recovery-classification:
|
|
51
|
+
failure: <one-line summary>
|
|
52
|
+
class: tool-schema
|
|
53
|
+
evidence: stderr line 14: "missing required field: workspace_id"
|
|
54
|
+
action: repair input (add workspace_id from session context), do NOT retry verbatim
|
|
55
|
+
retry budget: 2/3 remaining (this class)
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Retry budgets are **per-class**, not global. A failed class that resolves on retry resets its budget; a class that exhausts its budget escalates to `pause` regardless of remaining global retries. This keeps a flaky network from masking a persistent schema bug.
|
|
59
|
+
|
|
60
|
+
## Anti-Patterns
|
|
61
|
+
|
|
62
|
+
- **One retry budget for all classes.** A network blip and a schema mismatch consume the same counter, so persistent schema bugs masquerade as "flaky network."
|
|
63
|
+
- **Auto-retry on `deterministic-policy`.** The gate exists exactly because retry is wrong. Pause instead and surface the policy that fired.
|
|
64
|
+
- **Classifying after retry.** The class informs the action; classifying afterward turns it into a post-mortem label and the loop has already misspent its budget.
|
|
65
|
+
- **Coalescing `worktree` into `git`.** Worktree errors are stop-class; git errors are usually self-heal-class. Conflating them lets workers spawn into broken roots.
|
|
66
|
+
- **Treating `unclassified` as `provider`.** Unknown is not transient. Force a taxonomy update; do not paper over the gap with a backoff.
|
|
67
|
+
|
|
68
|
+
## Pairs With
|
|
69
|
+
|
|
70
|
+
- [verification-loop](verification-loop.md) — every Phase 1–6 failure routes through here before any retry.
|
|
71
|
+
- [state-reconciliation](state-reconciliation.md) — runs before the next loop iteration when class is `git` or `runtime`, since those classes often leave drift behind.
|
|
72
|
+
- [worktree-safety](worktree-safety.md) — class `worktree` is exactly worktree-safety's failure surface; the two are co-defined.
|
|
73
|
+
- [gateguard](gateguard.md) — class `deterministic-policy` is gateguard's surface; recovery-classification names what gateguard already blocked.
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: safety-guard
|
|
3
|
+
tier: "2"
|
|
4
|
+
description: Enforces Law 3 (One Thing at a Time) of the 7 Laws of AI Agent Discipline by scoping edits to a directory and blocking destructive shell commands. Use this skill to prevent destructive operations when working on production systems or running agents autonomously.
|
|
5
|
+
origin: continuous-improvement
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# Safety Guard — Prevent Destructive Operations
|
|
9
|
+
|
|
10
|
+
## When to Use
|
|
11
|
+
|
|
12
|
+
- When working on production systems
|
|
13
|
+
- When agents are running autonomously (full-auto mode)
|
|
14
|
+
- When you want to restrict edits to a specific directory
|
|
15
|
+
- During sensitive operations (migrations, deploys, data changes)
|
|
16
|
+
|
|
17
|
+
## How It Works
|
|
18
|
+
|
|
19
|
+
Three modes of protection:
|
|
20
|
+
|
|
21
|
+
### Mode 1: Careful Mode
|
|
22
|
+
|
|
23
|
+
Intercepts destructive commands before execution and warns:
|
|
24
|
+
|
|
25
|
+
```
|
|
26
|
+
Watched patterns:
|
|
27
|
+
- rm -rf (especially /, ~, or project root)
|
|
28
|
+
- git push --force
|
|
29
|
+
- git reset --hard
|
|
30
|
+
- git checkout . (discard all changes)
|
|
31
|
+
- DROP TABLE / DROP DATABASE
|
|
32
|
+
- docker system prune
|
|
33
|
+
- kubectl delete
|
|
34
|
+
- chmod 777
|
|
35
|
+
- sudo rm
|
|
36
|
+
- npm publish (accidental publishes)
|
|
37
|
+
- Any command with --no-verify
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
When detected: shows what the command does, asks for confirmation, suggests safer alternative.
|
|
41
|
+
|
|
42
|
+
### Mode 2: Freeze Mode
|
|
43
|
+
|
|
44
|
+
Locks file edits to a specific directory tree:
|
|
45
|
+
|
|
46
|
+
```
|
|
47
|
+
/safety-guard freeze src/components/
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Any Write/Edit outside `src/components/` is blocked with an explanation. Useful when you want an agent to focus on one area without touching unrelated code.
|
|
51
|
+
|
|
52
|
+
### Mode 3: Guard Mode (Careful + Freeze combined)
|
|
53
|
+
|
|
54
|
+
Both protections active. Maximum safety for autonomous agents.
|
|
55
|
+
|
|
56
|
+
```
|
|
57
|
+
/safety-guard guard --dir src/api/ --allow-read-all
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Agents can read anything but only write to `src/api/`. Destructive commands are blocked everywhere.
|
|
61
|
+
|
|
62
|
+
### Unlock
|
|
63
|
+
|
|
64
|
+
```
|
|
65
|
+
/safety-guard off
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Implementation
|
|
69
|
+
|
|
70
|
+
Currently implemented as skill-side discipline: when restricted-mode is active, the agent reads this skill and refuses Bash, Write, Edit, and MultiEdit calls that violate the rules before invoking the tool. There is no bundled tool-call gate today — the same enforcement gap that existed for `gateguard` before issue #106 / PR #108. A future runtime version would track via a follow-up issue.
|
|
71
|
+
|
|
72
|
+
## Integration
|
|
73
|
+
|
|
74
|
+
- Enable by default for `codex -a never` sessions
|
|
75
|
+
- Pair with observability risk scoring in continuous-improvement v2
|
|
76
|
+
- Logs all blocked actions to `~/.claude/safety-guard.log`
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: state-reconciliation
|
|
3
|
+
tier: "2"
|
|
4
|
+
description: "Enforces Law 4 (Verify Before Reporting) of the 7 Laws of AI Agent Discipline. Pre-dispatch invariant: reconcile DB-vs-disk-vs-memory state before any unit runs, so a stale flag, missing artifact, or out-of-sync row never re-dispatches a unit that already completed or never started."
|
|
5
|
+
origin: continuous-improvement
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# State Reconciliation Skill
|
|
9
|
+
|
|
10
|
+
A pre-dispatch invariant. Before the verification ladder runs (or any auto-loop unit dispatches), reconcile the three state sources — DB / disk / in-memory — and surface any divergence as a blocker, not a silent re-dispatch.
|
|
11
|
+
|
|
12
|
+
## When to Use
|
|
13
|
+
|
|
14
|
+
- Before Phase 1 of `verification-loop` if the project tracks runtime state outside source control (sqlite, KV, redis, `completed-units.json`, milestone JSON, lockfiles).
|
|
15
|
+
- Before any auto-loop iteration in long-running sessions.
|
|
16
|
+
- After a crash, pause/resume, or context compaction — the in-memory loop state is gone but DB and disk persist.
|
|
17
|
+
- When a flag like `is_sketch`, `in_progress`, or a stale lock keeps re-firing the same unit.
|
|
18
|
+
|
|
19
|
+
## Why This Skill Exists
|
|
20
|
+
|
|
21
|
+
GSD-2's [CONTEXT.md](https://github.com/gsd-build/gsd-2/blob/main/CONTEXT.md) names "State Reconciliation" as one of four runtime invariant modules. Common failure modes it catches:
|
|
22
|
+
|
|
23
|
+
- **Stale flags re-dispatch completed units** — `is_sketch`, stale worker rows, stale sequence/dependency rows that no one cleared.
|
|
24
|
+
- **Disk artifacts present, DB status lags** — `PROJECT.md` milestone registration, completion timestamps, roadmap divergence.
|
|
25
|
+
- **Recovery helpers exist but aren't wired into dispatch** — divergence accrues silently between iterations.
|
|
26
|
+
|
|
27
|
+
A verification ladder that runs against unreconciled state reports green on the wrong inputs.
|
|
28
|
+
|
|
29
|
+
## The Reconciliation Contract
|
|
30
|
+
|
|
31
|
+
For every state class the project tracks, define and run before dispatch:
|
|
32
|
+
|
|
33
|
+
1. **Authority** — which surface is the source of truth (DB, disk artifact, in-memory loop state).
|
|
34
|
+
2. **Projection** — direction of state flow (DB → disk, disk → DB, or both with a named winner).
|
|
35
|
+
3. **Reconciliation** — the deterministic check that proves authority and projection match.
|
|
36
|
+
4. **Failure mode** — what happens on divergence (block dispatch, repair, ask operator).
|
|
37
|
+
|
|
38
|
+
Output a single fenced block before any dispatch, so the operator sees the resolved state before it costs a misread:
|
|
39
|
+
|
|
40
|
+
```
|
|
41
|
+
state-reconciliation (resolved):
|
|
42
|
+
participants table: DB authoritative; disk projection at data/participants.json — match (1247 rows)
|
|
43
|
+
completed_units.json: project root authoritative after crash; worktree projection — match
|
|
44
|
+
is_sketch flag: DB authoritative — clear (no re-dispatch risk)
|
|
45
|
+
open lock at /tmp/foo.lck: stale (PID 1234 not running) — STALE, blocks dispatch
|
|
46
|
+
milestone registration: PROJECT.md authoritative; DB row — DIVERGED (DB shows in_progress, disk shows complete)
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Each row shows class + authority + reconciliation result. `STALE`, `DIVERGED`, `MISSING` surface as blockers; only every-row-`match` unblocks dispatch.
|
|
50
|
+
|
|
51
|
+
## Anti-Patterns
|
|
52
|
+
|
|
53
|
+
- **Reconciling at unit boundary, not lifecycle boundary.** Checking only when a unit is about to run lets earlier units write to invalid state. Reconcile once at lifecycle start and on every resume.
|
|
54
|
+
- **One-way trust.** Assuming DB is always right (or disk always right) without naming authority per state class. Authority is a per-class decision; codify it.
|
|
55
|
+
- **Silent repair.** Auto-fixing divergence without surfacing it. If reconciliation fixes 12 rows, the operator must see the count and the classes.
|
|
56
|
+
- **Reconciling the wrong direction.** Projecting disk → DB when DB was the authority overwrites correct state with stale data. The direction is part of the contract, not a default.
|
|
57
|
+
- **Treating "missing" as "match".** An absent state class is not the same as a reconciled one. Missing means the projection never ran; surface it explicitly.
|
|
58
|
+
|
|
59
|
+
## Pairs With
|
|
60
|
+
|
|
61
|
+
- [verification-loop](verification-loop.md) — runs as a pre-Phase-0 invariant; the resolved-state block fires before the resolved-ladder block.
|
|
62
|
+
- [worktree-safety](worktree-safety.md) — both fire before dispatch; safety runs first because reconciliation depends on a valid worktree root.
|
|
63
|
+
- [recovery-classification](recovery-classification.md) — divergence found here routes through recovery-classification on the next loop iteration if the reconciler can't auto-repair.
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: strategic-compact
|
|
3
|
+
tier: "2"
|
|
4
|
+
description: Enforces Law 5 (Reflect After Every Session) of the 7 Laws of AI Agent Discipline at phase boundaries. Suggests manual context compaction at logical intervals to preserve context through task phases rather than arbitrary auto-compaction.
|
|
5
|
+
origin: continuous-improvement
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# Strategic Compact Skill
|
|
9
|
+
|
|
10
|
+
Suggests manual `/compact` at strategic points in your workflow rather than relying on arbitrary auto-compaction.
|
|
11
|
+
|
|
12
|
+
## When to Activate
|
|
13
|
+
|
|
14
|
+
- Running long sessions that approach context limits (200K+ tokens)
|
|
15
|
+
- Working on multi-phase tasks (research → plan → implement → test)
|
|
16
|
+
- Switching between unrelated tasks within the same session
|
|
17
|
+
- After completing a major milestone and starting new work
|
|
18
|
+
- When responses slow down or become less coherent (context pressure)
|
|
19
|
+
|
|
20
|
+
## Why Strategic Compaction?
|
|
21
|
+
|
|
22
|
+
Auto-compaction triggers at arbitrary points:
|
|
23
|
+
- Often mid-task, losing important context
|
|
24
|
+
- No awareness of logical task boundaries
|
|
25
|
+
- Can interrupt complex multi-step operations
|
|
26
|
+
|
|
27
|
+
Strategic compaction at logical boundaries:
|
|
28
|
+
- **After exploration, before execution** — Compact research context, keep implementation plan
|
|
29
|
+
- **After completing a milestone** — Fresh start for next phase
|
|
30
|
+
- **Before major context shifts** — Clear exploration context before different task
|
|
31
|
+
|
|
32
|
+
## How It Works
|
|
33
|
+
|
|
34
|
+
The `suggest-compact.js` script runs on PreToolUse (Edit/Write) and:
|
|
35
|
+
|
|
36
|
+
1. **Tracks tool calls** — Counts tool invocations in session
|
|
37
|
+
2. **Threshold detection** — Suggests at configurable threshold (default: 50 calls)
|
|
38
|
+
3. **Periodic reminders** — Reminds every 25 calls after threshold
|
|
39
|
+
|
|
40
|
+
## Hook Setup
|
|
41
|
+
|
|
42
|
+
Add to your `~/.claude/settings.json`:
|
|
43
|
+
|
|
44
|
+
```json
|
|
45
|
+
{
|
|
46
|
+
"hooks": {
|
|
47
|
+
"PreToolUse": [
|
|
48
|
+
{
|
|
49
|
+
"matcher": "Edit",
|
|
50
|
+
"hooks": [{ "type": "command", "command": "node ~/.claude/skills/strategic-compact/suggest-compact.js" }]
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
"matcher": "Write",
|
|
54
|
+
"hooks": [{ "type": "command", "command": "node ~/.claude/skills/strategic-compact/suggest-compact.js" }]
|
|
55
|
+
}
|
|
56
|
+
]
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Configuration
|
|
62
|
+
|
|
63
|
+
Environment variables:
|
|
64
|
+
- `COMPACT_THRESHOLD` — Tool calls before first suggestion (default: 50)
|
|
65
|
+
|
|
66
|
+
## Compaction Decision Guide
|
|
67
|
+
|
|
68
|
+
Use this table to decide when to compact:
|
|
69
|
+
|
|
70
|
+
| Phase Transition | Compact? | Why |
|
|
71
|
+
|-----------------|----------|-----|
|
|
72
|
+
| Research → Planning | Yes | Research context is bulky; plan is the distilled output |
|
|
73
|
+
| Planning → Implementation | Yes | Plan is in TodoWrite or a file; free up context for code |
|
|
74
|
+
| Implementation → Testing | Maybe | Keep if tests reference recent code; compact if switching focus |
|
|
75
|
+
| Debugging → Next feature | Yes | Debug traces pollute context for unrelated work |
|
|
76
|
+
| Mid-implementation | No | Losing variable names, file paths, and partial state is costly |
|
|
77
|
+
| After a failed approach | Yes | Clear the dead-end reasoning before trying a new approach |
|
|
78
|
+
|
|
79
|
+
## What Survives Compaction
|
|
80
|
+
|
|
81
|
+
Understanding what persists helps you compact with confidence:
|
|
82
|
+
|
|
83
|
+
| Persists | Lost |
|
|
84
|
+
|----------|------|
|
|
85
|
+
| Agent instructions (from CLAUDE.md / AGENTS.md) | Intermediate reasoning and analysis |
|
|
86
|
+
| TodoWrite task list | File contents you previously read |
|
|
87
|
+
| Memory files (`~/.claude/memory/`) | Multi-step conversation context |
|
|
88
|
+
| Git state (commits, branches) | Tool call history and counts |
|
|
89
|
+
| Files on disk | Nuanced user preferences stated verbally |
|
|
90
|
+
|
|
91
|
+
## Best Practices
|
|
92
|
+
|
|
93
|
+
1. **Compact after planning** — Once plan is finalized in TodoWrite, compact to start fresh
|
|
94
|
+
2. **Compact after debugging** — Clear error-resolution context before continuing
|
|
95
|
+
3. **Don't compact mid-implementation** — Preserve context for related changes
|
|
96
|
+
4. **Read the suggestion** — The hook tells you *when*, you decide *if*
|
|
97
|
+
5. **Write before compacting** — Save important context to files or memory before compacting
|
|
98
|
+
6. **Use `/compact` with a summary** — Add a custom message: `/compact Focus on implementing auth middleware next`
|
|
99
|
+
|
|
100
|
+
## Related
|
|
101
|
+
|
|
102
|
+
- [The Longform Guide](https://x.com/affaanmustafa/status/2014040193557471352) — Token optimization section
|
|
103
|
+
- Memory persistence hooks — For state that survives compaction
|
|
104
|
+
- `continuous-learning` skill — Extracts patterns before session ends
|