@mccune1224/pi-pstack 0.1.0 → 0.2.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/README.md +52 -100
- package/agents/comment-sicko.md +1 -1
- package/agents/poteto-agent.md +2 -2
- package/docs/compare.md +122 -0
- package/docs/guide/01-setup.md +37 -12
- package/docs/guide/02-poteto-mode.md +1 -1
- package/docs/guide/03-understand.md +0 -8
- package/docs/guide/05-build-and-clean.md +1 -1
- package/docs/guide/06-verify-and-ship.md +1 -1
- package/docs/guide/07-overnight.md +2 -2
- package/docs/guide/08-principles.md +4 -2
- package/docs/guide/10-recipes-and-pitfalls.md +2 -2
- package/docs/guide/README.md +2 -2
- package/extensions/compaction.test.ts +132 -0
- package/extensions/compaction.ts +183 -0
- package/extensions/context-guard.test.ts +53 -0
- package/extensions/context-guard.ts +65 -0
- package/extensions/doctor.test.ts +85 -0
- package/extensions/doctor.ts +100 -0
- package/extensions/index.ts +289 -26
- package/extensions/settings.test.ts +71 -16
- package/extensions/settings.ts +57 -9
- package/extensions/skill-budget.test.ts +110 -0
- package/extensions/skill-budget.ts +101 -0
- package/package.json +9 -4
- package/scripts/check-pi-isms.mjs +106 -0
- package/scripts/lib/pi-delta-rules.mjs +110 -0
- package/scripts/lib/pi-delta-rules.test.mjs +100 -0
- package/scripts/lib/upstream-vendor.mjs +32 -0
- package/scripts/pi-deltas.json +754 -0
- package/scripts/sync-upstream.mjs +117 -0
- package/scripts/verify-guards.mjs +132 -0
- package/scripts/verify-sync.mjs +206 -0
- package/skills/architect/SKILL.md +10 -10
- package/skills/architect/references/rationale-template.md +2 -2
- package/skills/architect/references/runner-prompt.md +7 -7
- package/skills/arena/SKILL.md +11 -11
- package/skills/automate-me/SKILL.md +21 -26
- package/skills/blast-radius/SKILL.md +5 -5
- package/skills/create-verification-skill/SKILL.md +5 -5
- package/skills/figure-it-out/SKILL.md +11 -13
- package/skills/how/SKILL.md +30 -104
- package/skills/how/references/explainer-prompt.md +6 -6
- package/skills/how/references/explorer-prompt.md +1 -1
- package/skills/interrogate/SKILL.md +13 -14
- package/skills/interrogate/references/code-quality-review.md +1 -1
- package/skills/interrogate/references/lead-judgment.md +1 -1
- package/skills/interrogate/references/rubric.md +2 -2
- package/skills/maintain-verification-skill/SKILL.md +5 -5
- package/skills/no-comments/SKILL.md +3 -3
- package/skills/poteto-mode/SKILL.md +9 -8
- package/skills/poteto-mode/playbooks/authoring-a-skill.md +4 -4
- package/skills/poteto-mode/playbooks/autonomous-run.md +4 -4
- package/skills/poteto-mode/playbooks/autopilot-full.md +9 -9
- package/skills/poteto-mode/playbooks/autopilot-stack.md +8 -8
- package/skills/poteto-mode/playbooks/babysit.md +17 -17
- package/skills/poteto-mode/playbooks/bug-fix.md +6 -6
- package/skills/poteto-mode/playbooks/eval.md +6 -8
- package/skills/poteto-mode/playbooks/feature.md +7 -7
- package/skills/poteto-mode/playbooks/hillclimb.md +10 -10
- package/skills/poteto-mode/playbooks/investigation.md +3 -3
- package/skills/poteto-mode/playbooks/multi-phase-plan.md +26 -25
- package/skills/poteto-mode/playbooks/opening-a-pr.md +17 -13
- package/skills/poteto-mode/playbooks/orchestrate.md +37 -39
- package/skills/poteto-mode/playbooks/pause-safely.md +4 -4
- package/skills/poteto-mode/playbooks/perf-issue.md +9 -9
- package/skills/poteto-mode/playbooks/prototype.md +5 -5
- package/skills/poteto-mode/playbooks/refactoring.md +9 -9
- package/skills/poteto-mode/playbooks/runtime-forensics.md +3 -3
- package/skills/poteto-mode/playbooks/session-pickup.md +4 -6
- package/skills/poteto-mode/playbooks/shipping.md +11 -14
- package/skills/poteto-mode/playbooks/trace-forensics.md +4 -4
- package/skills/poteto-mode/playbooks/visual-parity.md +3 -3
- package/skills/poteto-mode/playbooks/worktree-cleanup.md +4 -4
- package/skills/poteto-mode/references/bugbot-triage.md +3 -3
- package/skills/poteto-mode/scripts/worktree-audit.mjs +0 -7
- package/skills/principle-attack-the-premise/SKILL.md +23 -0
- package/skills/principle-boundary-discipline/SKILL.md +2 -2
- package/skills/principle-build-the-lever/SKILL.md +5 -5
- package/skills/principle-encode-lessons-in-structure/SKILL.md +3 -3
- package/skills/principle-experience-first/SKILL.md +5 -5
- package/skills/principle-fix-root-causes/SKILL.md +4 -4
- package/skills/principle-foundational-thinking/SKILL.md +3 -3
- package/skills/principle-guard-the-context-window/SKILL.md +2 -2
- package/skills/principle-laziness-protocol/SKILL.md +2 -2
- package/skills/principle-migrate-callers-then-delete-legacy-apis/SKILL.md +1 -1
- package/skills/principle-minimize-reader-load/SKILL.md +2 -2
- package/skills/principle-model-the-domain/SKILL.md +3 -3
- package/skills/principle-never-block-on-the-human/SKILL.md +4 -5
- package/skills/principle-prove-it-works/SKILL.md +3 -3
- package/skills/principle-redesign-from-first-principles/SKILL.md +3 -3
- package/skills/principle-separate-before-serializing-shared-state/SKILL.md +3 -3
- package/skills/principle-sequence-verifiable-units/SKILL.md +3 -3
- package/skills/principle-subtract-before-you-add/SKILL.md +3 -4
- package/skills/principle-test-behavior-not-implementation/SKILL.md +25 -0
- package/skills/principle-type-system-discipline/SKILL.md +5 -5
- package/skills/recall/SKILL.md +7 -7
- package/skills/reflect/SKILL.md +14 -20
- package/skills/reflect/references/divergent-reviewer.md +3 -3
- package/skills/reflect/references/judgment-reviewer.md +3 -3
- package/skills/reflect/references/synthesizer.md +2 -2
- package/skills/reflect/references/tooling-reviewer.md +4 -6
- package/skills/setup-pstack/SKILL.md +61 -49
- package/skills/show-me-your-work/SKILL.md +17 -17
- package/skills/show-me-your-work/scripts/log.mjs +2 -8
- package/skills/swarm/SKILL.md +6 -6
- package/skills/tdd/SKILL.md +2 -2
- package/skills/teach/SKILL.md +7 -7
- package/skills/technical-writing/SKILL.md +5 -8
- package/skills/typescript-best-practices/SKILL.md +6 -3
- package/skills/typescript-best-practices/references/patterns.md +35 -14
- package/skills/unslop/SKILL.md +8 -20
- package/skills/why/SKILL.md +27 -100
- package/skills/why/references/epistemics.md +6 -6
- package/skills/why/references/investigator-prompt.md +5 -5
- package/skills/why/references/source-playbook.md +1 -1
- package/skills/why/references/sources/databricks.md +7 -7
- package/skills/why/references/sources/datadog.md +5 -5
- package/skills/why/references/sources/incident-postmortem.md +2 -2
- package/skills/why/references/sources/linear.md +2 -2
- package/skills/why/references/sources/notion.md +3 -3
- package/skills/why/references/sources/sentry.md +4 -4
- package/skills/why/references/sources/slack.md +2 -2
- package/skills/why/references/synthesizer-prompt.md +3 -3
- package/skills/how/references/critic-prompt.md +0 -59
- package/skills/how/references/critique-rubric.md +0 -58
|
@@ -1,20 +1,17 @@
|
|
|
1
1
|
### Shipping
|
|
2
2
|
|
|
3
|
-
**You own what lands. Verify each PR independently, land only the verified run from the root, then keep your hands off the queue.**
|
|
3
|
+
**You own what lands. Verify each PR independently, land only the verified run from the root, then keep your hands off the queue.**
|
|
4
4
|
|
|
5
|
-
This is the half after `playbooks/babysit.md`.
|
|
5
|
+
This is the half after `playbooks/babysit.md`.
|
|
6
6
|
|
|
7
|
-
1. **
|
|
8
|
-
2. **Land only the contiguous verified run rooted at the bottom.** Walk up from the lowest unmerged PR and stop at the first one without a passing verdict, where both `PASS` and `PASS+NOTES` pass. A verified PR sitting above an unverified one is not landable
|
|
9
|
-
3. **Re-check that
|
|
10
|
-
4. **
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
7. **Once the queue is draining, stop touching the stack.** No `gt sync`, no restack, no speculative pushes, and no `gt submit --stack`, which reaches downstack into PRs that are mid-merge. Even a plain `gt submit` can retarget a base if local Graphite tracking has diverged, so never run `gt` from a worktree whose parentage you have not just checked. Independent work gets re-parented onto trunk and shipped on its own.
|
|
17
|
-
8. **Watch the drain, do not drive it.** Arm the watcher in queued mode over the verified run and hold it in a long-running loop, re-armed after any verdict you act on, until COMPLETE at the ceiling. ADVANCE is progress, not termination. Bases retarget and `graphite-base/*` refs get cut as each PR merges; that is Graphite working, not damage. Report each merge and the new ceiling. If the queue stalls, diagnose before mutating, because a stalled queue and a broken stack look identical from the outside.
|
|
18
|
-
9. **Stop at the ceiling.** When the verified run is merged, report what landed, what the next unverified PR is, and what verifying it would take. Extending the run is a new pass through step 1, not a judgment call you make at 3am.
|
|
7
|
+
1. **Resolve the forge, then verify every PR independently.** GitHub CLI (`gh`) is the default. If `command -v origin` succeeds and Origin can resolve the repository, use `origin pr ...` for PR view, watch, edit, and merge operations. Otherwise stay on `gh` and record the fallback. Never require Graphite (`gt`). One subagent per PR, not batched, each a fresh subagent, each exercising the real surface (`control-ui` or `control-cli` from this package as the change demands) against parent versus head. Each returns `PASS`, `PASS+NOTES` or `FAIL` and posts that verdict on its own PR. Safe means a verdict from an agent that did not write the code. CI green is not a verdict, and an approving bot review is not a verdict.
|
|
8
|
+
2. **Land only the contiguous verified run rooted at the bottom.** Walk up from the lowest unmerged PR and stop at the first one without a passing verdict, where both `PASS` and `PASS+NOTES` pass. A verified PR sitting above an unverified one is not landable. Report the ceiling as a PR number and say what breaks the chain.
|
|
9
|
+
3. **Re-check that each verdict still describes the patch.** Record the verdict head SHA, base SHA, and stable `git patch-id` of that PR's base-to-head diff. A rebase or base retarget rewrites SHAs and can silently invalidate a verdict without touching a check. Before landing a PR, compare the recorded patch-id with its current base-to-head patch-id. Re-verify when the patch changed. When it did not, keep the code verdict but re-run mergeability and CI at the current head. Never use matching commit messages or a green check from an older SHA as a substitute.
|
|
10
|
+
4. **Prepare only the bottom PR.** Fetch current trunk. Rebase the lowest verified branch onto the exact trunk tip when needed, push it, and retarget only that PR to trunk with `origin pr edit <pr> --base <trunk>` or `gh pr edit <pr> --base <trunk>`. Re-run step 3 after the push. Do not retarget, arm, or merge descendants yet.
|
|
11
|
+
5. **Land one PR at a time.** If the bottom PR is mergeable now, squash it with `origin pr merge <pr> --squash` or `gh pr merge <pr> --squash`. If requirements are still running and the user asked for merge-when-ready, arm only that PR with `origin pr merge <pr> --squash --auto` or `gh pr merge <pr> --squash --auto`. Origin's `--auto` is Origin merge-when-ready. GitHub's `--auto` is GitHub auto-merge. Wait for that PR to merge before preparing the next one.
|
|
12
|
+
6. **Do not read GitHub `autoMergeRequest` as stack readiness.** At most it says GitHub auto-merge was requested for one GitHub PR. It does not prove Origin merge-when-ready is armed, that a descendant is queued, that a patch verdict is current, or that the contiguous stack is safe. Confirm the active forge's state for the current bottom PR, and say that the state is unknown if the active forge cannot report it.
|
|
13
|
+
7. **Recompute after every merge.** Fetch trunk, confirm the merged SHA is present, drop the merged PR from the frozen bottom-to-top list, and inspect the new bottom PR's base, head, checks, and patch-id. A host may retarget a child automatically, but do not assume it did. Repeat steps 3 through 6 for that one PR. Independent work stays outside this chain and ships on its own.
|
|
14
|
+
8. **Watch the current frontier until it merges or fails. Do not mutate the queue around it.** With Origin, use `origin pr view <pr> --checks --comments` and `origin pr checks <pr> --watch`, then re-read the PR until it reports merged or blocked. With GitHub, use `scripts/watch-pr/watch-pr --queued-stack --stack-prs <bottom>` only as an event wake and poll `gh pr view <pr> --json state,mergedAt,mergeStateStatus,statusCheckRollup,autoMergeRequest` after each wake, ignoring `READY` until `mergedAt` is non-null or `state` is `MERGED`. Only then run step 7. Hard-fail only when `state` is `CLOSED` with no `mergedAt`, a required check concludes `FAILURE` or `CANCELLED` and blocks merge after auto-merge is no longer pending, or `mergeStateStatus` is `UNSTABLE` or `DIRTY` with no auto-merge pending. `BLOCKED` while checks are pending or auto-merge is armed is not failure. Do not use Babysit's queued `WAITING`/`merge-queue` stop condition here. Hold the watch with a background subagent tick. Report each merge and the new ceiling. If the queue stalls, diagnose before mutating.
|
|
15
|
+
9. **Stop at the ceiling.** When the verified run is merged, report what landed, what the next unverified PR is, and what verifying it would take. Extending the run is a new pass through step 1.
|
|
19
16
|
|
|
20
17
|
**Reply:** the verified run and its ceiling, each PR's verdict and who produced it, what you armed and how you confirmed it, what landed, and what the next gap needs.
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
### Trace forensics
|
|
2
2
|
|
|
3
|
-
**You own the diagnosis from the artifact. Load it, shape it, narrow to the cause, attribute to source.**
|
|
3
|
+
**You own the diagnosis from the artifact. Load it, shape it, narrow to the cause, attribute to source.**
|
|
4
4
|
|
|
5
|
-
Distinct from **Runtime forensics**, which instruments the live process. Here the capture already exists
|
|
5
|
+
Distinct from **Runtime forensics**, which instruments the live process. Here the capture already exists. The artifact is a fixed dataset, read it, don't re-run it. Keep tooling generic so the playbook stays portable: a DevTools or trace parser for cpuprofile and `.json.gz`, a text editor for a spindump, your heap tooling for a heapsnapshot.
|
|
6
6
|
|
|
7
7
|
1. Identify the format and load it with the right tool. Parse large artifacts in a subagent (the **principle-guard-the-context-window** skill) and keep the reduced finding in the main thread.
|
|
8
8
|
2. Transform the raw artifact into a form you can query. Dump the trace or heap snapshot into sqlite, one row per sample, frame, or node. Reach the queryable shape before you read.
|
|
9
9
|
3. Narrow to the cause. Query for the frames that hold the most time and walk the call tree to the hot path. For a leak, follow the retainer chain from the leaked object to a GC root. For a spindump, find the thread stuck on-CPU or blocked and its wait reason.
|
|
10
|
-
4. Attribute to source. Map the hot frame to file, symbol, and line via the artifact's own symbols. A frame with no source mapping is not yet a diagnosis
|
|
11
|
-
5. Confirm against a paired capture when you have one. Diff a before and after artifact
|
|
10
|
+
4. Attribute to source. Map the hot frame to file, symbol, and line via the artifact's own symbols. A frame with no source mapping is not yet a diagnosis. Resolve the symbols, or say plainly the artifact does not carry them.
|
|
11
|
+
5. Confirm against a paired capture when you have one. Diff a before and after artifact. Without one, mark the finding as the strongest hypothesis the artifact supports, not a confirmed cause.
|
|
12
12
|
6. Hand back a cited diagnosis, no fix unless asked. Route to Bug fix or Perf issue once the cause is known. Throughput checkpoint stays one line: `throughput checkpoint: n/a, read-only forensics`.
|
|
13
13
|
|
|
14
14
|
**Reply:** the artifact and format, the reduced finding, the source location, the artifact paths, and whether a paired capture confirmed it.
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
### Visual parity
|
|
2
2
|
|
|
3
|
-
**You own pixel-exact equivalence. The baseline is the spec
|
|
3
|
+
**You own pixel-exact equivalence. The baseline is the spec. You do not touch it.** Equivalence is verified by image diff, not by eye.
|
|
4
4
|
|
|
5
5
|
1. Establish the baseline first, before any migration: a visual regression harness that screenshots the current component across its states, plus the target when matching two implementations. No baseline, no parity claim. A blocking prerequisite, not a follow-up.
|
|
6
6
|
2. Anti-shortcut clauses, stated and held: no harness modifications, no baseline tampering, no component restructuring to make a diff pass. If the baseline looks wrong, stop and ask, don't edit it.
|
|
7
|
-
3. Migrate one component at a time.
|
|
8
|
-
4. Verify each component against its baseline via image diff on the matching surface via the control skill. A nonzero diff is a fail
|
|
7
|
+
3. Migrate one component at a time. Parallelize across worktrees, one owner per component (the **separate-before-serializing-shared-state** principle skill). Shared primitives migrate first as a blocking phase.
|
|
8
|
+
4. Verify each component against its baseline via image diff on the matching surface via the control skill. A nonzero diff is a fail. Investigate the pixel delta. Re-check each component until the diff is zero.
|
|
9
9
|
5. Run **Opening a PR** per component or per safe batch.
|
|
10
10
|
|
|
11
11
|
**Reply:** components migrated, the diff result for each, the baseline harness location, what's left.
|
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
**You own the disk and the safety gate.** Prune merged or abandoned git worktrees and stale iOS simulators to reclaim space. Deletion is irreversible, so every step guards against deleting something in use or holding uncommitted work.
|
|
4
4
|
|
|
5
|
-
1. Snapshot and audit. Record `df -h /`, then run `node scripts/worktree-audit.mjs` (principle-build-the-lever). It reads paths from `git worktree list`, never hand-typed, since a hand-typed `myrepo-worktrees/x` misses one configured under a
|
|
5
|
+
1. Snapshot and audit. Record `df -h /`, then run `node scripts/worktree-audit.mjs` (principle-build-the-lever). It reads paths from `git worktree list`, never hand-typed, since a hand-typed `myrepo-worktrees/x` misses one configured under a different worktree root (principle-encode-lessons-in-structure). It classifies each worktree by size, age, merge state, uncommitted work, PR state, and the newest chat that touched it, then suggests a bucket. The transcript scan is slow, so background it.
|
|
6
6
|
2. The bucket is advice, not permission. The pinned and active chats are the real artifact (principle-prove-it-works). Get that set from the user or sidebar and cross-check every candidate. The lever has marked `safe` a worktree the user had pinned, so the pinned set wins.
|
|
7
7
|
3. Verify usage before deleting. For every `verify-recent-chat` row, or anything you doubt, fan subagents out to read the transcripts and report whether the chat is pinned or ongoing and which worktrees it touches (principle-guard-the-context-window, transcripts are bulk). A pinned chat spawns arena and repro trees into sibling worktrees via background subagents, and those are in use even when their names never hit the sidebar.
|
|
8
|
-
4. Pause on irreversible loss. `wip:N` is N tracked uncommitted edits. Show the diff and get a decision first, since removing a clean worktree is recoverable from its branch but uncommitted work is gone. `scratch:N` is untracked throwaway, safe to drop, but name the files. Per Autonomy, clean and merged and not-in-use proceeds
|
|
9
|
-
5. Prune the confirmed set. Per path, `git worktree remove --force <path
|
|
10
|
-
6. Simulators and other reclaimers. Simulators are usually the next-biggest win. `xcrun simctl --set testing delete all` (XCTestDevices clones), `xcrun simctl delete unavailable`, and `xcrun simctl runtime list` then `runtime delete <id>` for old runtimes. More when needed: Xcode `DerivedData` and `iOS DeviceSupport
|
|
8
|
+
4. Pause on irreversible loss. `wip:N` is N tracked uncommitted edits. Show the diff and get a decision first, since removing a clean worktree is recoverable from its branch but uncommitted work is gone. `scratch:N` is untracked throwaway, safe to drop, but name the files. Per Autonomy, clean and merged and not-in-use proceeds. `wip` and in-use pause.
|
|
9
|
+
5. Prune the confirmed set. Per path, `git worktree remove --force <path>`. If the dir survives on ignored build artifacts, `rm -rf` it, then `git worktree prune`. Branch refs survive, so no commits are lost. Confirm with `df -h /` and re-list.
|
|
10
|
+
6. Simulators and other reclaimers. Simulators are usually the next-biggest win. `xcrun simctl --set testing delete all` (XCTestDevices clones), `xcrun simctl delete unavailable`, and `xcrun simctl runtime list` then `runtime delete <id>` for old runtimes. More when needed: Xcode `DerivedData` and `iOS DeviceSupport`, `~/Library/Application Support/Cursor` (`state.vscdb.backup`, and `snapshots/roots/<root>` where a `<root>` named for a folder you opened as a workspace balloons), package caches (pnpm, uv, brew, yarn). Clear only caches the user has not said to keep.
|
|
11
11
|
|
|
12
12
|
This is the one playbook that deletes user state with no code review to catch a slip, so the gates above are the review.
|
|
13
13
|
|
|
@@ -40,7 +40,7 @@ Use `candidate` for one or two examples. Use `recurring` after multiple real dis
|
|
|
40
40
|
### Upstack or stack-local usage Bugbot cannot see
|
|
41
41
|
|
|
42
42
|
- Confidence: candidate
|
|
43
|
-
- Skip when: Bugbot flags an export, component, helper, or file as unused, and
|
|
43
|
+
- Skip when: Bugbot flags an export, component, helper, or file as unused, and the active forge's PR list and diffs, upper-stack diffs, or PR context show it is used by a later PR in the stack.
|
|
44
44
|
- Do not skip when: The current PR is not part of a stack, the symbol is public API, or the supposed upstack use cannot be verified.
|
|
45
45
|
- Example signal: "Exported component is never used" with a human reply like "used upstack".
|
|
46
46
|
|
|
@@ -95,7 +95,7 @@ Append new candidate learnings here during or after babysitting when they look t
|
|
|
95
95
|
- Example signal: "masks do not affect hit-testing", "overlay blocks wheel scroll", "ignores deltaMode", "runs in the IntersectionObserver callback before React applies state".
|
|
96
96
|
- Source: one sticky-occlusion PR: six Bugbot passes, roughly eighteen findings, every one fixed rather than dismissed.
|
|
97
97
|
|
|
98
|
-
### Contract-test drift claims are cheaply verifiable
|
|
98
|
+
### Contract-test drift claims are cheaply verifiable, so run the test first
|
|
99
99
|
|
|
100
100
|
- Confidence: candidate
|
|
101
101
|
- Skip when: Never skip the verification itself; it costs one command. When a PR
|
|
@@ -104,7 +104,7 @@ Append new candidate learnings here during or after babysitting when they look t
|
|
|
104
104
|
matches the doc" (or vice versa), run that test on the PR tip before
|
|
105
105
|
classifying. A red run confirms the claim empirically; a green run is a
|
|
106
106
|
concrete disproof for the dismissal reply.
|
|
107
|
-
- Do not skip when: n/a
|
|
107
|
+
- Do not skip when: n/a, this is a verification shortcut, not a dismissal
|
|
108
108
|
pattern. Note that repeat-pass lean-dismiss heuristics would misfire here:
|
|
109
109
|
prose-pinning tests drift precisely BECAUSE earlier fix rounds edit the prose.
|
|
110
110
|
- Example signal: "Contract test omits the pre-fix wait" on a PR whose earlier
|
|
@@ -1,11 +1,4 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
// Read-only worktree prune audit, cross-platform (Node only).
|
|
3
|
-
// Classifies every git worktree by size, merge state, uncommitted work,
|
|
4
|
-
// remote/PR state, and the most recent chat that operated in it. Emits a
|
|
5
|
-
// table sorted by size with a suggested bucket. Never deletes anything;
|
|
6
|
-
// deletion stays a human-gated step in the playbook.
|
|
7
|
-
//
|
|
8
|
-
// Usage: node worktree-audit.mjs [repo-path] (defaults to the current repo)
|
|
9
2
|
import { statSync, readdirSync, readFileSync, existsSync } from "node:fs";
|
|
10
3
|
import { homedir } from "node:os";
|
|
11
4
|
import { join } from "node:path";
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: principle-attack-the-premise
|
|
3
|
+
description: "Apply when two or more fixes that share one premise have failed the same gate. Take a census of which actors hold the imbalance before the next fix, then question the premise instead of writing another fix that assumes it."
|
|
4
|
+
disable-model-invocation: true
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Attack the Premise
|
|
8
|
+
|
|
9
|
+
When two or more fixes that share one premise have failed the same gate, suspect the premise, not the fixes.
|
|
10
|
+
|
|
11
|
+
**Why:** Each failure under a shared premise is evidence about the premise.
|
|
12
|
+
|
|
13
|
+
**Pattern:**
|
|
14
|
+
- **Write the premise down.** The premise is the one sentence that every failed fix assumed.
|
|
15
|
+
- **Take a census before the next fix.** Count the imbalance per actor. The census shows which actors hold the imbalance, not how large it is. Write the census as a rerunnable script per [Build the Lever](../principle-build-the-lever/SKILL.md).
|
|
16
|
+
- **Read the skew.** If the same few actors hold most of the imbalance on every run, something assigns them that role. Find what assigns the role. That assignment is the next "why" per [Fix Root Causes](../principle-fix-root-causes/SKILL.md).
|
|
17
|
+
- **Remove the asymmetry instead of compensating for it**, per the [Laziness Protocol](../principle-laziness-protocol/SKILL.md). Rotate the role between actors, randomize the assignment, or move the role, so that no actor holds it on every run. A return path, a shared pool, a batched hand-off, or a periodic rebalance leaves the assignment in place and adds work on every run.
|
|
18
|
+
|
|
19
|
+
**Stop:**
|
|
20
|
+
- Do not start the next fix before the premise is written down and the census exists.
|
|
21
|
+
- If the census is even across actors, the premise is not the cause. Look for the cause elsewhere and keep the census as evidence.
|
|
22
|
+
|
|
23
|
+
This principle is distinct from [Redesign from First Principles](../principle-redesign-from-first-principles/SKILL.md), which rebuilds a design around a new requirement. It questions a fact the current design assumes.
|
|
@@ -6,9 +6,9 @@ disable-model-invocation: true
|
|
|
6
6
|
|
|
7
7
|
# Boundary Discipline
|
|
8
8
|
|
|
9
|
-
Place validation, type narrowing, and error handling at system boundaries. Trust internal code unconditionally. Business logic lives in pure functions
|
|
9
|
+
Place validation, type narrowing, and error handling at system boundaries. Trust internal code unconditionally. Business logic lives in pure functions. The shell is thin and mechanical.
|
|
10
10
|
|
|
11
|
-
**Why:** Scattered validation is noisy, redundant, and gives a false sense of safety.
|
|
11
|
+
**Why:** Scattered validation is noisy, redundant, and gives a false sense of safety. Keep logic out of framework wiring so it can be tested without the framework.
|
|
12
12
|
|
|
13
13
|
**The pattern:**
|
|
14
14
|
- **At boundaries** (CLI args, config files, external APIs, network protocols): validate, return errors, handle defensively.
|
|
@@ -9,14 +9,14 @@ When the work isn't trivial, build the tool that does it instead of doing it by
|
|
|
9
9
|
|
|
10
10
|
**Why:** Two payoffs. Throughput: a codemod, generator, or script does the work the same way every time and reruns for free. Confidence: the tool is one artifact a reviewer can read and rerun to check the work. Hand-done changes can only be re-verified by redoing them. A deterministic script turns "trust me" into "run this".
|
|
11
11
|
|
|
12
|
-
**Pattern:** Default to building the lever. Skip it only when the task is
|
|
12
|
+
**Pattern:** Default to building the lever. Skip it only when the task is trivial, a couple of obvious edits you can see at a glance.
|
|
13
13
|
|
|
14
|
-
- Do the first unit by hand to learn the recipe, then build the tool. Prove it by rerunning it on that unit and diffing against your hand-done version. Make the lever safe to rerun.
|
|
14
|
+
- Do the first unit by hand to learn the recipe, then build the tool. Prove it by rerunning it on that unit and diffing against your hand-done version. Make the lever safe to rerun.
|
|
15
15
|
- Codemod or script for edits, generator for repetitive files, a dump-to-sqlite query for analysis, a rerunnable check for verification.
|
|
16
|
-
- A deterministic lever beats fan-out. If the tool can process every unit in one pass, run it yourself
|
|
17
|
-
- When you fan work out to subagents, write the lever as a skill they all read: the recipe, the verification contract, and the do-not-touch fences in one artifact
|
|
16
|
+
- A deterministic lever beats fan-out. If the tool can process every unit in one pass, run it yourself. Don't fan out delegates to hand-apply what a script can do.
|
|
17
|
+
- When you fan work out to subagents, write the lever as a skill they all read: the recipe, the verification contract, and the do-not-touch fences in one artifact. Keep it outside the delegates' write scope so they can't quietly edit the contract.
|
|
18
18
|
- Applying this principle produces a file. If you cited it and there is no codemod, script, generator, or delegate skill in the diff, you didn't apply it.
|
|
19
|
-
- Commit the lever when the work outlives the session
|
|
19
|
+
- Commit the lever when the work outlives the session.
|
|
20
20
|
|
|
21
21
|
**Balance:** The bar is triviality, not repetition. A one-off still earns a lever when the lever is what makes the work checkable. Per the [Laziness Protocol](../principle-laziness-protocol/SKILL.md), build the smallest script that does or proves the job, never a framework.
|
|
22
22
|
|
|
@@ -14,11 +14,11 @@ Encode recurring fixes in mechanisms (tools, code, metadata, automation) instead
|
|
|
14
14
|
When you catch yourself writing the same instruction a second time:
|
|
15
15
|
1. Ask: can this be a lint rule, a metadata flag, a runtime check, or a script?
|
|
16
16
|
2. If yes, encode it. Delete the instruction
|
|
17
|
-
3. If no (
|
|
17
|
+
3. If no (requires judgment), make the instruction more prominent and add an example of the failure mode
|
|
18
18
|
|
|
19
|
-
**Pick the strongest
|
|
19
|
+
**Pick the strongest mechanism.** When more than one mechanism would work, choose the strongest the situation allows (an unrepresentable state that cannot compile, then a lint or banned API that fails CI, then a canonical helper, then a runtime check), because agents copy whatever the surrounding code already does and a weaker guard becomes the next template.
|
|
20
20
|
|
|
21
|
-
**Corollary:**
|
|
21
|
+
**Corollary:** If the fix is structural, only use the structural fix. The instruction is the symptom.
|
|
22
22
|
|
|
23
23
|
**Feedback loop:**
|
|
24
24
|
- **Capture every correction.** When the human intervenes or tests fail, decide if it's a one-off or a pattern.
|
|
@@ -6,14 +6,14 @@ disable-model-invocation: true
|
|
|
6
6
|
|
|
7
7
|
# Experience First
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
When implementation convenience conflicts with user delight, choose delight.
|
|
10
10
|
|
|
11
|
-
-
|
|
11
|
+
- Every feature, control, and option must be justified
|
|
12
12
|
- Ship less, ship better (polished experience with three features beats rough one with ten)
|
|
13
13
|
- Prototype before committing (design decisions are cheaper in throwaway HTML than production code)
|
|
14
|
-
-
|
|
14
|
+
- Get the details right (transitions, alignment, spacing, feedback, error states)
|
|
15
15
|
- Tighten the core loop (every feature should serve the central workflow or get out of the way)
|
|
16
16
|
|
|
17
|
-
The user is whoever consumes the work. For a UI that is the end user. For a library or an internal API it is the colleague who imports it. The engineer who maintains the code next is a user too. Weigh their experience the same way, and explain impact from their
|
|
17
|
+
The user is whoever consumes the work. For a UI that is the end user. For a library or an internal API it is the colleague who imports it. The engineer who maintains the code next is a user too. Weigh their experience the same way, and explain impact from their perspective.
|
|
18
18
|
|
|
19
|
-
Foundations should serve the experience
|
|
19
|
+
Foundations should serve the experience. Foundational thinking governs the *sequence* of work. This principle governs the *target*.
|
|
@@ -6,18 +6,18 @@ disable-model-invocation: true
|
|
|
6
6
|
|
|
7
7
|
# Fix Root Causes
|
|
8
8
|
|
|
9
|
-
When debugging, do not
|
|
9
|
+
When debugging, do not fix symptoms. Trace every problem to its root cause and fix it there.
|
|
10
10
|
|
|
11
11
|
**Why:** Symptom fixes accumulate. Each workaround makes the system harder to reason about, and the real bug remains. Root-cause fixes are slower upfront but reduce total debugging time.
|
|
12
12
|
|
|
13
13
|
**Pattern:**
|
|
14
|
-
- Reproduce first
|
|
14
|
+
- Reproduce first
|
|
15
15
|
- Ask "why" until you hit the root cause
|
|
16
|
-
-
|
|
16
|
+
- Do not add guards (adding a nil check to silence a crash is a symptom fix)
|
|
17
17
|
- If a workaround needs a paragraph-long comment to justify it, the code is wrong (fix the code, not the comment)
|
|
18
18
|
- Check for the pattern, not just the instance (grep for the same pattern, fix all instances)
|
|
19
19
|
- When stuck, instrument. Don't guess (add logging, read the actual error)
|
|
20
20
|
|
|
21
21
|
**Restart bugs: suspect state before code**
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
When something "fails after restart," suspect stale persistent state first: config files, caches, lock files, serialized state. If clearing a state file restores behavior, prioritize state validation as the fix.
|
|
@@ -6,9 +6,9 @@ disable-model-invocation: true
|
|
|
6
6
|
|
|
7
7
|
# Foundational Thinking
|
|
8
8
|
|
|
9
|
-
**Structural decisions** protect option value. **Code-level decisions** protect simplicity.
|
|
9
|
+
**Structural decisions** protect option value. **Code-level decisions** protect simplicity.
|
|
10
10
|
|
|
11
|
-
**Data structures first.** Get the data shape right before writing logic.
|
|
11
|
+
**Data structures first.** Get the data shape right before writing logic. Define core types early, trace every access pattern, and choose structures that match the dominant paths.
|
|
12
12
|
|
|
13
13
|
At code level, DRY the structure, not every line. Types and data models should converge. Three similar statements still beat a premature abstraction. Prefer explicit over clever. Test behavior and edge cases, not line counts.
|
|
14
14
|
|
|
@@ -18,4 +18,4 @@ At code level, DRY the structure, not every line. Types and data models should c
|
|
|
18
18
|
|
|
19
19
|
Each increment should land a coherent abstraction or deepen one that exists. Do not spread a new capability across callers as special-case coordination.
|
|
20
20
|
|
|
21
|
-
Subtraction comes before scaffolding
|
|
21
|
+
Subtraction comes before scaffolding. Remove dead code first, then lay foundations.
|
|
@@ -6,9 +6,9 @@ disable-model-invocation: true
|
|
|
6
6
|
|
|
7
7
|
# Guard the Context Window
|
|
8
8
|
|
|
9
|
-
The context window is finite and non-renewable within a session. Every token
|
|
9
|
+
The context window is finite and non-renewable within a session. Every token should be worth its cost.
|
|
10
10
|
|
|
11
|
-
**Why:** Context overflow degrades reasoning quality, creates compression artifacts, and halts progress.
|
|
11
|
+
**Why:** Context overflow degrades reasoning quality, creates compression artifacts, and halts progress.
|
|
12
12
|
|
|
13
13
|
**Pattern:**
|
|
14
14
|
- **Isolate large payloads.** Route verbose outputs, screenshots, and large documents to subagents. The main context gets summaries, not raw data.
|
|
@@ -6,7 +6,7 @@ disable-model-invocation: true
|
|
|
6
6
|
|
|
7
7
|
# Laziness Protocol
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
Aim for the most result with the least code and complexity.
|
|
10
10
|
|
|
11
11
|
- **Prefer deletion.** When asked to refactor or improve, look for removals before additions.
|
|
12
12
|
- **Maintain a flat call hierarchy.** Avoid deep call chains. A rich interface that hides substantial work is not a deep call chain. If answering a question requires tracing through more than 3 files or layers, flatten it.
|
|
@@ -15,4 +15,4 @@ Writing code is cheap for you, which makes over-engineering easy. Counter it by
|
|
|
15
15
|
- **Question the threading.** If a task asks you to pass a new signal through types, schemas, pipelines, or similar layers, stop and look for a more direct path.
|
|
16
16
|
- **Sweat the small leaks.** Remove tiny pass-throughs, representation leaks, and duplicated choices before they spread. Small leaks compound into permanent coordination costs.
|
|
17
17
|
|
|
18
|
-
**
|
|
18
|
+
**The test:** If a human developer would find the code exhausting to maintain, it is a bad solution.
|
|
@@ -9,7 +9,7 @@ disable-model-invocation: true
|
|
|
9
9
|
When we decide a new API is the right design, migrate callers and remove the old API in the same refactor wave instead of preserving compatibility layers.
|
|
10
10
|
|
|
11
11
|
**Rule:**
|
|
12
|
-
- Do not keep legacy API paths
|
|
12
|
+
- Do not keep legacy API paths only because internal callers still exist
|
|
13
13
|
- Inventory callers, migrate them, and delete the old API immediately
|
|
14
14
|
- Treat temporary adapters as exceptional and time-boxed, not default architecture
|
|
15
15
|
- Update tests to assert the new contract, and delete tests that only protect pre-refactor implementation details
|
|
@@ -10,10 +10,10 @@ Maintainability is the work a reader must do to understand code. Track two axes:
|
|
|
10
10
|
1. **Layers to trace.** How many indirections sit between the question and the answer.
|
|
11
11
|
2. **State to hold.** How much hidden or mutable context the reader must keep in their head.
|
|
12
12
|
|
|
13
|
-
**Why:** Code is read far more than it is written. LOC, cyclomatic complexity, and "clean architecture" are proxies. Reader load is the thing that matters. The two axes are independent. A flat file with 50 globals can be as hard to reason about as a 6-layer adapter stack. Guard both. This is the human analog of [Guard the Context Window](../principle-guard-the-context-window/SKILL.md)
|
|
13
|
+
**Why:** Code is read far more than it is written. LOC, cyclomatic complexity, and "clean architecture" are proxies. Reader load is the thing that matters. The two axes are independent. A flat file with 50 globals can be as hard to reason about as a 6-layer adapter stack. Guard both. This is the human analog of [Guard the Context Window](../principle-guard-the-context-window/SKILL.md). Working memory is finite for readers too.
|
|
14
14
|
|
|
15
15
|
**The pattern:**
|
|
16
|
-
- **Collapse layers** that
|
|
16
|
+
- **Collapse layers** that cost more than they save: wrappers with one caller, adapters with no second implementation, speculative indirection that was never needed. Inline them.
|
|
17
17
|
- **Make adjacent layers change the abstraction.** A layer that repeats the same methods and arguments adds reader load without compression. Collapse pass-through layers.
|
|
18
18
|
- **Demand interface compression.** A broad interface that hides little complexity makes readers learn both the surface and the implementation. Prefer boundaries that hide meaningful decisions.
|
|
19
19
|
- **Shrink state scope:** prefer pure functions (returns over mutations), locals over fields, fields over module state, and module state over globals. Derive instead of sync.
|
|
@@ -8,7 +8,7 @@ disable-model-invocation: true
|
|
|
8
8
|
|
|
9
9
|
Encode the real domain in a data structure instead of scattering it across conditionals.
|
|
10
10
|
|
|
11
|
-
**Why:** Scattered booleans, repeated shape assumptions, and branching spread across files are accidental complexity. A structure that matches the domain makes invalid states unrepresentable and deletes branches. Choosing it at write time is cheap
|
|
11
|
+
**Why:** Scattered booleans, repeated shape assumptions, and branching spread across files are accidental complexity. A structure that matches the domain makes invalid states unrepresentable and deletes branches. Choosing it at write time is cheap. Recovering it later reads as a refactor and gets deferred.
|
|
12
12
|
|
|
13
13
|
**Reach for structures like these:**
|
|
14
14
|
|
|
@@ -19,8 +19,8 @@ Encode the real domain in a data structure instead of scattering it across condi
|
|
|
19
19
|
- A module organized around one body of domain knowledge instead of a sequence such as load, validate, transform, and save. Execution order is not ownership.
|
|
20
20
|
- A small module boundary that gathers repeated behavior, ownership, or invariants.
|
|
21
21
|
- A queue, cache, index, graph/tree, or normalized collection where the data access pattern calls for it.
|
|
22
|
-
- Any other structure that fits.
|
|
22
|
+
- Any other structure that fits. When none fits, work out what the code must never allow and how the data gets read, then find the structure that encodes exactly that.
|
|
23
23
|
|
|
24
24
|
Do not force an abstraction. Prefer boring code if the current shape is already clear, local, and unlikely to grow. Be skeptical of an abstraction that adds indirection without removing branches, duplicated rules, invalid states, or lifecycle risk.
|
|
25
25
|
|
|
26
|
-
The
|
|
26
|
+
The sign that you skipped this is a new feature that grows an existing if/else chain by one more branch, or a second boolean that must stay in sync with the first. Temporal decomposition is another sign. Phase-named modules repeat the same domain rules across steps.
|
|
@@ -6,18 +6,17 @@ disable-model-invocation: true
|
|
|
6
6
|
|
|
7
7
|
# Never Block on the Human
|
|
8
8
|
|
|
9
|
-
The human supervises asynchronously. Agents must stay unblocked
|
|
9
|
+
The human supervises asynchronously. Agents must stay unblocked. Make reasonable decisions, proceed, and let the human course-correct after the fact.
|
|
10
10
|
|
|
11
11
|
**Why:** Every permission pause stalls the pipeline and makes the human the bottleneck. Since code changes are reversible and reviewable, a wrong decision usually costs less than blocking.
|
|
12
12
|
|
|
13
13
|
**Pattern:**
|
|
14
14
|
- **Proceed, then present.** Do the work, show the result. Don't ask "should I do X?" Do X, explain why.
|
|
15
|
-
- **Reserve questions for genuine ambiguity.** Ask only when you
|
|
15
|
+
- **Reserve questions for genuine ambiguity.** Ask only when you cannot infer intent from context.
|
|
16
16
|
- **Make the system self-healing.** When you notice a problem, log it and fix it in the next round.
|
|
17
|
-
- **Supervision is async.**
|
|
18
|
-
- **Code is cheap, attention is scarce.** A wrong implementation costs minutes to fix. A blocked agent costs the human's attention to unblock.
|
|
17
|
+
- **Supervision is async.** Design workflows for review-after-the-fact.
|
|
19
18
|
|
|
20
19
|
**Boundaries:**
|
|
21
20
|
- **Irreversible actions** (force-push, delete production data, send external messages) still require confirmation.
|
|
22
21
|
- **Reversible actions** (write code, edit notes, split tasks) should proceed without blocking.
|
|
23
|
-
- **Product direction** comes from the human
|
|
22
|
+
- **Product direction** comes from the human. *Execution* should not block.
|
|
@@ -24,10 +24,10 @@ Code and features:
|
|
|
24
24
|
4. For integrations, test the full communication path end-to-end
|
|
25
25
|
|
|
26
26
|
Delegation: trust artifacts, not self-reports.
|
|
27
|
-
When verifying delegated work, inspect the actual output artifact (git diff, file contents, runtime behavior), not the delegate's summary.
|
|
27
|
+
When verifying delegated work, inspect the actual output artifact (git diff, file contents, runtime behavior), not the delegate's summary.
|
|
28
28
|
|
|
29
29
|
## Script the check when you can
|
|
30
30
|
|
|
31
|
-
The strongest proof is a deterministic script that re-runs the same comparison, not a one-time eyeball. Write the script, run it, and keep its output as an artifact a reviewer can re-run instead of trusting your word.
|
|
31
|
+
The strongest proof is a deterministic script that re-runs the same comparison, not a one-time eyeball. Write the script, run it, and keep its output as an artifact a reviewer can re-run instead of trusting your word.
|
|
32
32
|
|
|
33
|
-
Keep the artifact visible for the human. Commit it only for large or complex work where the trail has to be auditable later, like a big port or migration (the **show-me-your-work** skill).
|
|
33
|
+
Keep the artifact visible for the human. Commit it only for large or complex work where the trail has to be auditable later, like a big port or migration (the **show-me-your-work** skill).
|
|
@@ -6,11 +6,11 @@ disable-model-invocation: true
|
|
|
6
6
|
|
|
7
7
|
# Redesign From First Principles
|
|
8
8
|
|
|
9
|
-
When integrating a change, don't bolt it onto the existing design. Redesign as if the requirement had been there from the start.
|
|
9
|
+
When integrating a change, don't bolt it onto the existing design. Redesign as if the requirement had been there from the start.
|
|
10
10
|
|
|
11
|
-
- Read all affected files and understand the current design
|
|
11
|
+
- Read all affected files and understand the current design
|
|
12
12
|
- Ask: "if we were writing this from scratch with this new requirement, what would we build?"
|
|
13
13
|
- Propagate the change through every reference: types, docs, examples, rationale sections
|
|
14
|
-
- Think about the redesign
|
|
14
|
+
- Think about the whole redesign, then deliver it incrementally
|
|
15
15
|
|
|
16
16
|
This is the method for preserving option value when integrating changes into an existing design.
|
|
@@ -6,11 +6,11 @@ disable-model-invocation: true
|
|
|
6
6
|
|
|
7
7
|
# Separate Before Serializing Shared State
|
|
8
8
|
|
|
9
|
-
When concurrent actors might share mutable state, first ask whether they
|
|
9
|
+
When concurrent actors might share mutable state, first ask whether they need the same mutable object. If not, eliminate the sharing. When sharing is real, enforce serialization structurally: lockfiles, sequential phases, exclusive ownership. Instructions and conventions are not concurrency control.
|
|
10
10
|
|
|
11
|
-
**Why:** Concurrent writes to shared state create race conditions that are intermittent, hard to reproduce, and expensive to debug.
|
|
11
|
+
**Why:** Concurrent writes to shared state create race conditions that are intermittent, hard to reproduce, and expensive to debug.
|
|
12
12
|
|
|
13
13
|
**Pattern:**
|
|
14
14
|
1. **Identify shared mutable state** (files both read and write, branches both push to, APIs both define and consume).
|
|
15
|
-
2. **Default: eliminate the shared write target.** Ask: do these actors need one canonical object, or are they publishing independent facts? Give each actor its own owned file, key, branch, or state directory, and merge only at the read/reporting boundary. Two workers writing their own `lastX` field into one `state.json` is still shared mutation
|
|
15
|
+
2. **Default: eliminate the shared write target.** Ask: do these actors need one canonical object, or are they publishing independent facts? Give each actor its own owned file, key, branch, or state directory, and merge only at the read/reporting boundary. Two workers writing their own `lastX` field into one `state.json` is still shared mutation. `indexer-state.json` + `metrics-state.json` is not.
|
|
16
16
|
3. **Only when one shared write target is a real invariant, serialize access structurally** (lockfiles, sequential phases, single-writer actor, or atomic compare-and-swap). Treat "we need a lock" as a design smell to check, not as the default answer.
|
|
@@ -6,13 +6,13 @@ disable-model-invocation: true
|
|
|
6
6
|
|
|
7
7
|
# Sequence work into verifiable units
|
|
8
8
|
|
|
9
|
-
Order work as a sequence of small units, each ending in a state you can check, and don't advance until the current one is green.
|
|
9
|
+
Order work as a sequence of small units, each ending in a state you can check, and don't advance until the current one is green.
|
|
10
10
|
|
|
11
11
|
**Why:** A break caught at the unit that caused it is cheap to localize. A break caught after a batch is buried, and you have already built further on a broken base. Sequencing those same units into a delivery a reviewer can replay turns "trust me" into "watch it go red, then green."
|
|
12
12
|
|
|
13
|
-
**Execution.** In a sweep, migration, or any run of similar edits, verify each change before starting the next.
|
|
13
|
+
**Execution.** In a sweep, migration, or any run of similar edits, verify each change before starting the next. Each unit is a before/after bracket: known-good state, one change, run the check, then proceed. Rebase onto clean trunk first so every check measures against the real baseline. When a lever does the edits, the per-unit check is nearly free. Run it anyway.
|
|
14
14
|
|
|
15
|
-
**Delivery.** Stack commits and PRs in the order that proves the work. The canonical shape is the failing test first, then the fix on top.
|
|
15
|
+
**Delivery.** Stack commits and PRs in the order that proves the work. The canonical shape is the failing test first, then the fix on top. Other story orders are a subtraction before the reshape, a baseline capture before the treatment, the scaffold before the feature. Each commit lands on its own and the sequence reads as an argument.
|
|
16
16
|
|
|
17
17
|
**Pattern:**
|
|
18
18
|
- Pick the smallest unit that ends in a check: an edit plus its test, or a commit that stands alone.
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: principle-subtract-before-you-add
|
|
3
|
-
description: "Apply when sequencing an addition, refactor, or rewrite. Remove dead
|
|
3
|
+
description: "Apply when sequencing an addition, refactor, or rewrite. Remove dead code, redundant validators, and stub references first, then build on the simpler base."
|
|
4
4
|
disable-model-invocation: true
|
|
5
5
|
---
|
|
6
6
|
|
|
7
7
|
# Subtract Before You Add
|
|
8
8
|
|
|
9
|
-
When evolving a system, remove complexity first, then build.
|
|
9
|
+
When evolving a system, remove complexity first, then build.
|
|
10
10
|
|
|
11
|
-
**Why:** Adding to a complex system compounds complexity. Removing first
|
|
11
|
+
**Why:** Adding to a complex system compounds complexity. Removing first leaves less code, reveals the essential structure, and usually makes the next design obvious. Default to subtraction.
|
|
12
12
|
|
|
13
13
|
Make simplification a continual investment. Leave the design slightly simpler and more capable behind the same or smaller surface than you found it.
|
|
14
14
|
|
|
@@ -17,6 +17,5 @@ Make simplification a continual investment. Leave the design slightly simpler an
|
|
|
17
17
|
- Cut before you polish (get to the minimum before investing in quality)
|
|
18
18
|
- Design for observed usage, not speculative edge cases
|
|
19
19
|
- No speculative validators, parsers, or guards beyond what the spec demands
|
|
20
|
-
- Out-of-spec features drag validators behind them. Persistence, retry-on-startup, and schema migration each need guards to defend their inputs.
|
|
21
20
|
- Simplify prompts (remove redundant instructions, excessive templates)
|
|
22
21
|
- When a reference has no novel content, delete it rather than leaving a stub
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: principle-test-behavior-not-implementation
|
|
3
|
+
description: "Apply when you write, change, or keep a test. Call the code the way its users do and assert the result they observe against a literal expected value. If the test would still pass when every imported function returns undefined, rewrite the assertion or delete the test."
|
|
4
|
+
disable-model-invocation: true
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Test Behavior, Not Implementation
|
|
8
|
+
|
|
9
|
+
A test calls the code the way its users do and asserts the result they observe against a literal expected value. A test that asserts which calls the code made, or restates a constant the code contains, does neither.
|
|
10
|
+
|
|
11
|
+
The check: before you keep a test, ask whether it would still pass if every function it imports returned `undefined`. If yes, it observes no behavior and cannot fail for a defect. Rewrite the assertion or delete the test.
|
|
12
|
+
|
|
13
|
+
**Why:** A test that cannot fail for a defect costs CI time and review attention and catches nothing. A constant pin also fails when someone edits the constant or the prompt it restates, so it prevents that edit.
|
|
14
|
+
|
|
15
|
+
**Five shapes that still pass when every imported function returns `undefined`:**
|
|
16
|
+
|
|
17
|
+
- **Weak or no assertion.** No `expect`, or only `toBeDefined`, `toBeTruthy`, `not.toThrow`, `toBeInstanceOf`, `toBeGreaterThan(0)`.
|
|
18
|
+
- **Mock or absence only.** Only `toHaveBeenCalled`, `not.toHaveBeenCalled`, `toBeUndefined`, `toEqual([])`, `toHaveLength(0)`, `not.toBe(wrongValue)`.
|
|
19
|
+
- **Self-referential.** The expected value comes from the code under test: `expect(f(a)).toBe(f(a))`, `expect(parsed.url).toBe(buildUrl(...))`.
|
|
20
|
+
- **Constant pin.** The assertion restates a hand-maintained constant, config default, table row, or prompt string: `expect(LIMITS.maxTools).toBe(8)`, `expect(PROMPT).toContain("You are")`.
|
|
21
|
+
- **Fixture asserts fixture.** The assertion reads data the test built or a value computed in `beforeEach`, and the subject never runs inside the body.
|
|
22
|
+
|
|
23
|
+
**The fix:** call the subject inside the test body with one concrete input and assert the literal output or the observable effect, `expect(slugify("Hello, World!")).toBe("hello-world")`. For an absence, assert the presence on the other input in the same test. For a constant, test the mechanism that reads it with one input instead of restating the value. For a mock, assert the payload it received or the state after the call, not that it was called. When no such assertion exists, delete the test.
|
|
24
|
+
|
|
25
|
+
**Keep** a test of a relation across a table's rows (a key present in two tables, a parent that exists), and a compile-time check in a `*.test-d.ts` file.
|
|
@@ -6,20 +6,20 @@ disable-model-invocation: true
|
|
|
6
6
|
|
|
7
7
|
# Type System Discipline
|
|
8
8
|
|
|
9
|
-
The type checker is a proof assistant. Use it to eliminate impossible states, mismatched primitives, and unhandled variants at compile time. A case the types let you ignore becomes a runtime failure the compiler could have stopped. Prefer defining errors and special cases out of existence over proliferating handlers
|
|
9
|
+
The type checker is a proof assistant. Use it to eliminate impossible states, mismatched primitives, and unhandled variants at compile time. A case the types let you ignore becomes a runtime failure the compiler could have stopped. Prefer defining errors and special cases out of existence over proliferating handlers. Unrepresentable states, total functions, and interface redesign (the patterns below) are the tools.
|
|
10
10
|
|
|
11
11
|
Applies to any typed language. Skills like `typescript-best-practices` ground it in specific syntax.
|
|
12
12
|
|
|
13
13
|
**The patterns:**
|
|
14
14
|
|
|
15
|
-
- **Make illegal states unrepresentable.** Model variants as sum types: discriminated unions in TypeScript, enums with payloads in Rust/Swift/Kotlin, sealed classes in Scala, ADTs in Haskell/OCaml. Don't model state as a bag of optional fields where contradictory combinations compile. A subtle anti-pattern
|
|
15
|
+
- **Make illegal states unrepresentable.** Model variants as sum types: discriminated unions in TypeScript, enums with payloads in Rust/Swift/Kotlin, sealed classes in Scala, ADTs in Haskell/OCaml. Don't model state as a bag of optional fields where contradictory combinations compile. A subtle anti-pattern: `{ completed: boolean; completedAt?: Date }` admits `completed: true; completedAt: undefined`, which is meaningless. Derive the boolean from a single source like `completedAt !== null`, or model the variants explicitly as `{ kind: 'open' } | { kind: 'done'; at: Date }`. If a bug forces the question "wait, can this combination actually happen?", the type is too loose.
|
|
16
16
|
- **Types are constructions, not restrictions.** Build the type up from the values you want instead of carving them out of a looser type with checks. The invariant that seems to need a refinement type is usually a construction away. A non-empty list is a head plus a rest, not a list with a length check. A valid time range is a start plus a duration, not two timestamps you must keep ordered. No representation is privileged. A list of pairs is an even-length list if you interpret it that way, so choose the shape that cannot build the illegal value and expose the interface callers need on top.
|
|
17
17
|
- **Brand semantic primitives.** `UserId` and `OrderId` are strings underneath but should not be interchangeable. Newtypes in Rust, opaque types in Swift, value classes in Kotlin, phantom types in Haskell, branded intersections in TypeScript. Validate once at creation, trust the type downstream.
|
|
18
18
|
- **External data is untyped until parsed.** RPC payloads, JSON, IPC messages, CLI args, config files, environment variables, database rows. Have a parse function at every boundary that turns unstructured input into the typed model. See the **boundary-discipline** principle skill for where to put validation.
|
|
19
|
-
- **Don't lie to the type system.** Casts, unsafe coercions, and assertion functions that bypass the compiler are runtime crashes
|
|
19
|
+
- **Don't lie to the type system.** Casts, unsafe coercions, and assertion functions that bypass the compiler are latent runtime crashes. If the compiler can't prove a fact, prove it (validate, narrow, refine the model) or accept that the cast is a hazard.
|
|
20
20
|
- **Exhaustive matching is the compiler's job.** When you match on a sum type, the compiler must fail compilation if a new variant is added without handling. Use the idiom your language provides: `never`-typed binding in TypeScript, unannotated `match` in Rust, `-Wincomplete-patterns` in Haskell, sealed-class match exhaustiveness in Kotlin.
|
|
21
|
-
- **Derive types from authoritative schemas.** When a protocol buffer, OpenAPI spec, GraphQL schema, database migration, or design-system token file defines a shape, derive from it instead of hand-rolling a parallel type.
|
|
22
|
-
- **Strengthen a type only where partiality appears.** A runtime assertion, null check, or "this should never happen" throw marks the place a type is too weak. Push that check up into the type. Then stop. The type system's job is to track the cases each use site must handle, not to describe the data as precisely as possible. Prefer total functions. `sum` of an empty list is 0, so it takes the plain list. `head` of an empty list has no answer, so it demands the non-empty one.
|
|
21
|
+
- **Derive types from authoritative schemas.** When a protocol buffer, OpenAPI spec, GraphQL schema, database migration, or design-system token file defines a shape, derive from it instead of hand-rolling a parallel type. See the **encode-lessons-in-structure** principle skill.
|
|
22
|
+
- **Strengthen a type only where partiality appears.** A runtime assertion, null check, or "this should never happen" throw marks the place a type is too weak. Push that check up into the type. Then stop. The type system's job is to track the cases each use site must handle, not to describe the data as precisely as possible. Prefer total functions. `sum` of an empty list is 0, so it takes the plain list. `head` of an empty list has no answer, so it demands the non-empty one.
|
|
23
23
|
|
|
24
24
|
**The tests:**
|
|
25
25
|
|