From d6febf78d39009b4f6b97f7a5e8725c16de93a9c Mon Sep 17 00:00:00 2001 From: lukabor Date: Mon, 8 Jun 2026 23:07:03 +0200 Subject: [PATCH] refactor(skills): apply review-driven structural refinements * refactor(tdd-bdd): extract horizontal-slicing anti-pattern into anti-patterns.md * refactor(jj-atomic): extract anti-patterns into anti-patterns.md; trim See also list * refactor(dev-r): split SKILL.md into package-loop.md and analysis-loop.md siblings * fix(dev-python): repair CLAUDE.md URL mismatch and tdd-bdd self-referential link * docs(dev-python): rewrite phase 4 to forbid horizontal slicing; inline Karpathy summary * docs(dev-r): inline Karpathy guardrails summary in phase 0 --- skills/engineering/dev-python/SKILL.md | 21 ++-- skills/engineering/dev-r/SKILL.md | 95 ++++--------------- skills/engineering/dev-r/analysis-loop.md | 46 +++++++++ skills/engineering/dev-r/package-loop.md | 50 ++++++++++ skills/engineering/tdd-bdd/SKILL.md | 33 ++----- skills/engineering/tdd-bdd/anti-patterns.md | 39 ++++++++ skills/productivity/jj-atomic/SKILL.md | 21 +--- .../productivity/jj-atomic/anti-patterns.md | 36 +++++++ 8 files changed, 217 insertions(+), 124 deletions(-) create mode 100644 skills/engineering/dev-r/analysis-loop.md create mode 100644 skills/engineering/dev-r/package-loop.md create mode 100644 skills/engineering/tdd-bdd/anti-patterns.md create mode 100644 skills/productivity/jj-atomic/anti-patterns.md diff --git a/skills/engineering/dev-python/SKILL.md b/skills/engineering/dev-python/SKILL.md index 3431028..4509ade 100644 --- a/skills/engineering/dev-python/SKILL.md +++ b/skills/engineering/dev-python/SKILL.md @@ -20,10 +20,13 @@ Each phase must pass before the next. Do not advance silently. ## Phases ### 0. Frame -Apply Karpathy guardrails from [`../../../CLAUDE.md`](../../CLAUDE.md): -state assumptions, name the simpler approach, surface tradeoffs. If the -task is ambiguous, hand off to [`/grill-me`](../../productivity/grill-me/SKILL.md) -or [`/grill-with-docs`](../grill-with-docs/SKILL.md) first. +Karpathy guardrails — state assumptions explicitly, name the simpler +approach you're rejecting, surface tradeoffs. Push back when warranted; if +something is unclear, stop and ask. See +[`../../../CLAUDE.md`](../../../CLAUDE.md) for the full version. If the +task is ambiguous, hand off to +[`/grill-me`](../../productivity/grill-me/SKILL.md) or +[`/grill-with-docs`](../grill-with-docs/SKILL.md) first. ### 1. Implement - Write code under `src//`. @@ -47,13 +50,15 @@ Fix type errors. Don't suppress with `# type: ignore` unless genuinely unavoidable — explain inline why. ### 4. Test (TDD-BDD) -Hand to [`/tdd-bdd`](tdd-bdd/SKILL.md) to write Given/When/Then -scenarios and the failing tests. Then: +Hand to [`/tdd-bdd`](../tdd-bdd/SKILL.md), which loops red→green→refactor +**one scenario at a time** — never write all the tests upfront (that's the +horizontal-slicing anti-pattern called out in tdd-bdd itself). When every +scenario from step 0 is green: ```bash just test ``` -All tests must pass before commit. New edge case found mid-loop → add -to suite, don't skip. +The full suite must be green before commit. New edge case found mid-loop +→ add as the next scenario, don't skip. ### 5. Commit Hand to [`/jj-atomic`](../../productivity/jj-atomic/SKILL.md). The fix diff --git a/skills/engineering/dev-r/SKILL.md b/skills/engineering/dev-r/SKILL.md index 3404401..44758f8 100644 --- a/skills/engineering/dev-r/SKILL.md +++ b/skills/engineering/dev-r/SKILL.md @@ -7,10 +7,10 @@ description: Orchestrate the full R development workflow. Auto-detects project t Workflow for R repos. Detects project type from filesystem markers: -| Marker | Type | Loop | +| Marker | Type | Loop file | |---|---|---| -| `DESCRIPTION` only | R package | `lint → style → test → check → commit` | -| `_targets.R` only | R analysis | `lint → style → test → run pipeline → render → commit` | +| `DESCRIPTION` only | R package | [`package-loop.md`](package-loop.md) | +| `_targets.R` only | R analysis | [`analysis-loop.md`](analysis-loop.md) | | both | ambiguous | ask the user | | neither | refuse | suggest [`/build-r-package`](../../scaffold/build-r-package/SKILL.md) or [`/build-r-analysis`](../../scaffold/build-r-analysis/SKILL.md) | @@ -22,88 +22,29 @@ Apply [`/r-style`](../r-style/SKILL.md) at every implementation step. - Reviewing R style of one file → `/r-style` only. - Committing → `/jj-atomic` only. -## R-package phases (`DESCRIPTION` detected) +## Phase 0 — Frame (both loops) -### 0. Frame -Karpathy guardrails ([`../../../CLAUDE.md`](../../CLAUDE.md)). If -ambiguous, hand to [`/grill-me`](../../productivity/grill-me/SKILL.md) -or [`/grill-with-docs`](../grill-with-docs/SKILL.md). +Karpathy guardrails — state assumptions explicitly, name the simpler +approach you're rejecting, surface tradeoffs. Push back when warranted; if +something is unclear, stop and ask. See +[`../../../CLAUDE.md`](../../../CLAUDE.md) for the full version. -### 1. Implement -- Code in `R/`, following [`/r-style`](../r-style/SKILL.md) (box, native - pipe, `\(x)`, snake_case). -- Add/update roxygen2 docs on every exported function. +If the task is ambiguous, hand off to +[`/grill-me`](../../productivity/grill-me/SKILL.md) (no codebase needed) +or [`/grill-with-docs`](../grill-with-docs/SKILL.md) (anchors to +`CONTEXT.md`) before entering the loop. -### 2. Document -```bash -just document # devtools::document() -``` -Fix all roxygen2 warnings. +## Then enter the appropriate loop -### 3. Lint & style -```bash -just lint # lintr -just style-check # styler dry run -# if style-check fails: -just style -``` - -### 4. Test (TDD-BDD) -Hand to [`/tdd-bdd`](../tdd-bdd/SKILL.md). Test prologue follows -[`tdd-bdd/tests-r.md`](../tdd-bdd/tests-r.md). Run: -```bash -just test # devtools::test() -``` - -### 5. Full check -```bash -just check # devtools::check() -``` -All notes, warnings, and errors resolved before commit. - -### 6. Commit -Hand to [`/jj-atomic`](../../productivity/jj-atomic/SKILL.md). - -## R-analysis phases (`_targets.R` detected) - -### 0. Frame -Same as above. - -### 1. Implement -- Functions in `R/functions/` as box modules. -- Pipeline steps in `R/pipeline/` as box modules. -- All code under [`/r-style`](../r-style/SKILL.md). - -### 2. Lint & style -```bash -just lint -just style-check # fix with: just style -``` - -### 3. Test (TDD-BDD) -Hand to [`/tdd-bdd`](../tdd-bdd/SKILL.md) for `R/functions/`. Then: -```bash -just test -``` - -### 4. Pipeline -```bash -just run # targets::tar_make() -``` -Verify outputs in `data/processed/`. - -### 5. Render (if applicable) -```bash -just render # quarto render reports/ -``` - -### 6. Commit -Hand to [`/jj-atomic`](../../productivity/jj-atomic/SKILL.md). +- `DESCRIPTION` detected → [`package-loop.md`](package-loop.md) + (document → lint → style → test → check → commit) +- `_targets.R` detected → [`analysis-loop.md`](analysis-loop.md) + (lint → style → test → run pipeline → render → commit) ## See also - [`../tdd-bdd/SKILL.md`](../tdd-bdd/SKILL.md) and its R siblings (`tests-r.md`, `interface-design-r.md`, `mocking-r.md`, - `deep-modules-r.md`, `refactoring-r.md`). + `deep-modules-r.md`, `refactoring-r.md`, `anti-patterns.md`). - [`../diagnose/SKILL.md`](../diagnose/SKILL.md) — six-phase bug hunt with R-flavored siblings. - [`../r-style/SKILL.md`](../r-style/SKILL.md) — coding standards. diff --git a/skills/engineering/dev-r/analysis-loop.md b/skills/engineering/dev-r/analysis-loop.md new file mode 100644 index 0000000..beddde8 --- /dev/null +++ b/skills/engineering/dev-r/analysis-loop.md @@ -0,0 +1,46 @@ +# dev-r — R-analysis loop + +Detected by the presence of `_targets.R` at the repo root. Apply +[`../r-style/SKILL.md`](../r-style/SKILL.md) at every implementation step. + +## 1. Implement + +- Functions in `R/functions/` as box modules. +- Pipeline steps in `R/pipeline/` as box modules. +- All code under [`/r-style`](../r-style/SKILL.md). + +## 2. Lint & style + +```bash +just lint +just style-check # fix with: just style +``` + +## 3. Test (TDD-BDD) + +Hand to [`/tdd-bdd`](../tdd-bdd/SKILL.md), which loops red→green→refactor +**one scenario at a time** — never write all the tests upfront (see +[`../tdd-bdd/anti-patterns.md`](../tdd-bdd/anti-patterns.md)). Target +`R/functions/`. Then: + +```bash +just test +``` + +## 4. Pipeline + +```bash +just run # targets::tar_make() +``` + +Verify outputs in `data/processed/`. + +## 5. Render (if applicable) + +```bash +just render # quarto render reports/ +``` + +## 6. Commit + +Hand to [`/jj-atomic`](../../productivity/jj-atomic/SKILL.md). diff --git a/skills/engineering/dev-r/package-loop.md b/skills/engineering/dev-r/package-loop.md new file mode 100644 index 0000000..b89af0f --- /dev/null +++ b/skills/engineering/dev-r/package-loop.md @@ -0,0 +1,50 @@ +# dev-r — R-package loop + +Detected by the presence of `DESCRIPTION` at the repo root. Apply +[`../r-style/SKILL.md`](../r-style/SKILL.md) at every implementation step. + +## 1. Implement + +- Code in `R/`, following [`/r-style`](../r-style/SKILL.md) (box, native + pipe, `\(x)`, snake_case). +- Add/update roxygen2 docs on every exported function. + +## 2. Document + +```bash +just document # devtools::document() +``` + +Fix all roxygen2 warnings. + +## 3. Lint & style + +```bash +just lint # lintr +just style-check # styler dry run +# if style-check fails: +just style +``` + +## 4. Test (TDD-BDD) + +Hand to [`/tdd-bdd`](../tdd-bdd/SKILL.md), which loops red→green→refactor +**one scenario at a time** — never write all the tests upfront (see +[`../tdd-bdd/anti-patterns.md`](../tdd-bdd/anti-patterns.md)). Test +prologue follows [`../tdd-bdd/tests-r.md`](../tdd-bdd/tests-r.md). Run: + +```bash +just test # devtools::test() +``` + +## 5. Full check + +```bash +just check # devtools::check() +``` + +All notes, warnings, and errors resolved before commit. + +## 6. Commit + +Hand to [`/jj-atomic`](../../productivity/jj-atomic/SKILL.md). diff --git a/skills/engineering/tdd-bdd/SKILL.md b/skills/engineering/tdd-bdd/SKILL.md index 8d0d626..91f5d9b 100644 --- a/skills/engineering/tdd-bdd/SKILL.md +++ b/skills/engineering/tdd-bdd/SKILL.md @@ -72,32 +72,19 @@ Testthat ed. 3+, `box::use`, `describe`/`it`. - No production code exists that is not exercised by a test added in this loop. -## Anti-pattern: horizontal slicing +## Anti-patterns -**DO NOT write all the tests first, then all the implementation.** Treating -RED as "write every test from step 0" and GREEN as "make them all pass" is -horizontal slicing. It produces tests of *imagined* behavior — you commit to -shapes and signatures before the code teaches you what actually matters. - -``` -WRONG (horizontal): RIGHT (vertical, tracer bullets): - RED: t1 t2 t3 RED→GREEN: t1 → impl1 - GREEN: i1 i2 i3 RED→GREEN: t2 → impl2 - RED→GREEN: t3 → impl3 -``` - -Each cycle responds to what the previous cycle revealed. The scenario list -from step 0 is a *plan*; it is not a queue of tests to enqueue at once. +See [anti-patterns.md](anti-patterns.md) — horizontal slicing, passing on +first run, refactoring while red, silently dropping an untestable scenario. ## Guardrails -- **Never** skip the red step. If a test passes on first run, it is - testing the wrong thing — fix it before continuing. -- **Never** write more than one failing test at a time (horizontal-slicing - trap above). -- If a scenario turns out to be untestable at the chosen level, surface it - — don't silently drop it. Move it up (integration) or down (unit) one - level and reconfirm with the user. -- Refactor only with a green bar. No "tidy while red". +- **Never** skip the red step (see anti-patterns.md *"Passing on first run"*). +- **Never** write more than one failing test at a time (see anti-patterns.md + *"Horizontal slicing"*). +- Refactor only with a green bar (see anti-patterns.md + *"Refactoring while red"*). +- If a scenario turns out untestable at the chosen level, surface it (see + anti-patterns.md *"Silently dropping…"*). ## See also - [../diagnose/SKILL.md](../diagnose/SKILL.md) — chasing an existing bug? diff --git a/skills/engineering/tdd-bdd/anti-patterns.md b/skills/engineering/tdd-bdd/anti-patterns.md new file mode 100644 index 0000000..d40178c --- /dev/null +++ b/skills/engineering/tdd-bdd/anti-patterns.md @@ -0,0 +1,39 @@ +# tdd-bdd anti-patterns + +## Horizontal slicing + +**DO NOT write all the tests first, then all the implementation.** Treating +RED as "write every test from step 0" and GREEN as "make them all pass" is +horizontal slicing. It produces tests of *imagined* behavior — you commit to +shapes and signatures before the code teaches you what actually matters. + +``` +WRONG (horizontal): RIGHT (vertical, tracer bullets): + RED: t1 t2 t3 RED→GREEN: t1 → impl1 + GREEN: i1 i2 i3 RED→GREEN: t2 → impl2 + RED→GREEN: t3 → impl3 +``` + +Each cycle responds to what the previous cycle revealed. The scenario list +from step 0 is a *plan*; it is not a queue of tests to enqueue at once. + +## Passing on first run + +If a freshly written test passes without any production-code change, the +test is testing the wrong thing — the behavior was already present, or the +assertion is a tautology. Fix the test before continuing. Never let a green +bar on a brand-new test go unchallenged. + +## Refactoring while red + +If the suite is red, fix the test or fix the code — do not "tidy while +fixing". Two changes mixed together are two regressions waiting to happen. +Refactor only with a green bar. See also +[`refactoring-r.md`](refactoring-r.md). + +## Silently dropping an untestable scenario + +If a scenario from step 0 turns out to be untestable at the chosen level, +surface it — don't quietly delete it. Move it up (integration) or down +(unit) one level and reconfirm with the user. A dropped scenario is a +contract the suite no longer protects. diff --git a/skills/productivity/jj-atomic/SKILL.md b/skills/productivity/jj-atomic/SKILL.md index 80aa02b..a873ea1 100644 --- a/skills/productivity/jj-atomic/SKILL.md +++ b/skills/productivity/jj-atomic/SKILL.md @@ -79,18 +79,10 @@ change with an outdated message. Open a fresh empty `@` immediately so the next concern starts in a clean working copy. ## Anti-patterns -- **`jj describe` before `jj diff`.** You'll commit debug `cat()`s, - stray `browser()` calls, and TODO scratchpads. -- **"Mixed bag" commits.** `refactor + fix + new feature` in one change - is three regressions waiting to happen and an unrevertable mess. -- **Past-tense / declarative messages.** `"added auth"`, `"auth now - works"`. These don't complete "this change will…". -- **No scope.** `feat: add login` is weaker than `feat(auth): add - OAuth2 login flow`. Scope is the smallest area the change touches. -- **Docs in the next commit.** "I'll update the README after." You - won't. Same change or it doesn't ship. -- **Skipping `jj new` after describe.** Edits land in the just-described - change; its message rots into a lie. Always open a fresh `@`. + +See [anti-patterns.md](anti-patterns.md) — `jj describe` before +`jj diff`, mixed-bag commits, past-tense messages, missing scope, docs +deferred to the next commit, skipping `jj new` after describe. ## Examples See [examples.md](examples.md) for a real before/after where a @@ -104,7 +96,4 @@ working-copy is split into two atomic commits with proper messages. as the fix. - [`../../engineering/diagnose/SKILL.md`](../../engineering/diagnose/SKILL.md) — phase-6 post-mortem commit message names the confirmed hypothesis. -- [`../../engineering/dev-python/SKILL.md`](../../engineering/dev-python/SKILL.md) - and - [`../../engineering/dev-r/SKILL.md`](../../engineering/dev-r/SKILL.md) - — workflow orchestrators that hand off here for the commit phase. +- [`../../engineering/dev-python/SKILL.md`](../../engineering/dev-python/SKILL.md) / [`../../engineering/dev-r/SKILL.md`](../../engineering/dev-r/SKILL.md) — workflow orchestrators that hand off here for the commit phase. diff --git a/skills/productivity/jj-atomic/anti-patterns.md b/skills/productivity/jj-atomic/anti-patterns.md new file mode 100644 index 0000000..c2c7cf4 --- /dev/null +++ b/skills/productivity/jj-atomic/anti-patterns.md @@ -0,0 +1,36 @@ +# jj-atomic anti-patterns + +## `jj describe` before `jj diff` + +You'll commit debug `cat()`s, stray `browser()` calls, and TODO +scratchpads. Read every line of every diff before you describe. + +## "Mixed bag" commits + +`refactor + fix + new feature` in one change is three regressions waiting +to happen and an unrevertable mess. If the diff touches more than one +concern, `jj split` before describing. + +## Past-tense / declarative messages + +`"added auth"`, `"auth now works"`. These don't complete the implicit +prefix *"this change will…"*. Use the imperative — `"add OAuth2 login +flow"`, `"fix token refresh on 401"`. + +## No scope + +`feat: add login` is weaker than `feat(auth): add OAuth2 login flow`. +Scope is the smallest area the change touches; it makes the log +greppable and the change's footprint visible at a glance. + +## Docs in the next commit + +"I'll update the README after." You won't. Docstrings, README sections, +CLAUDE.md updates for a new flag or env var — same change or it doesn't +ship. See SKILL.md §5 *"Docs travel with the code"*. + +## Skipping `jj new` after describe + +Edits land in the just-described change; its message rots into a lie. Always +open a fresh `@` immediately after `jj describe`. See SKILL.md *"Workflow"* +step 5.