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
This commit is contained in:
Łukasz Boryń 2026-06-08 23:07:03 +02:00
parent 9d2fbe2307
commit d6febf78d3
8 changed files with 217 additions and 124 deletions

View File

@ -20,10 +20,13 @@ Each phase must pass before the next. Do not advance silently.
## Phases ## Phases
### 0. Frame ### 0. Frame
Apply Karpathy guardrails from [`../../../CLAUDE.md`](../../CLAUDE.md): Karpathy guardrails — state assumptions explicitly, name the simpler
state assumptions, name the simpler approach, surface tradeoffs. If the approach you're rejecting, surface tradeoffs. Push back when warranted; if
task is ambiguous, hand off to [`/grill-me`](../../productivity/grill-me/SKILL.md) something is unclear, stop and ask. See
or [`/grill-with-docs`](../grill-with-docs/SKILL.md) first. [`../../../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 ### 1. Implement
- Write code under `src/<package>/`. - Write code under `src/<package>/`.
@ -47,13 +50,15 @@ Fix type errors. Don't suppress with `# type: ignore` unless genuinely
unavoidable — explain inline why. unavoidable — explain inline why.
### 4. Test (TDD-BDD) ### 4. Test (TDD-BDD)
Hand to [`/tdd-bdd`](tdd-bdd/SKILL.md) to write Given/When/Then Hand to [`/tdd-bdd`](../tdd-bdd/SKILL.md), which loops red→green→refactor
scenarios and the failing tests. Then: **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 ```bash
just test just test
``` ```
All tests must pass before commit. New edge case found mid-loop → add The full suite must be green before commit. New edge case found mid-loop
to suite, don't skip. → add as the next scenario, don't skip.
### 5. Commit ### 5. Commit
Hand to [`/jj-atomic`](../../productivity/jj-atomic/SKILL.md). The fix Hand to [`/jj-atomic`](../../productivity/jj-atomic/SKILL.md). The fix

View File

@ -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: 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` | | `DESCRIPTION` only | R package | [`package-loop.md`](package-loop.md) |
| `_targets.R` only | R analysis | `lint → style → test → run pipeline → render → commit` | | `_targets.R` only | R analysis | [`analysis-loop.md`](analysis-loop.md) |
| both | ambiguous | ask the user | | 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) | | 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. - Reviewing R style of one file → `/r-style` only.
- Committing → `/jj-atomic` only. - Committing → `/jj-atomic` only.
## R-package phases (`DESCRIPTION` detected) ## Phase 0 — Frame (both loops)
### 0. Frame Karpathy guardrails — state assumptions explicitly, name the simpler
Karpathy guardrails ([`../../../CLAUDE.md`](../../CLAUDE.md)). If approach you're rejecting, surface tradeoffs. Push back when warranted; if
ambiguous, hand to [`/grill-me`](../../productivity/grill-me/SKILL.md) something is unclear, stop and ask. See
or [`/grill-with-docs`](../grill-with-docs/SKILL.md). [`../../../CLAUDE.md`](../../../CLAUDE.md) for the full version.
### 1. Implement If the task is ambiguous, hand off to
- Code in `R/`, following [`/r-style`](../r-style/SKILL.md) (box, native [`/grill-me`](../../productivity/grill-me/SKILL.md) (no codebase needed)
pipe, `\(x)`, snake_case). or [`/grill-with-docs`](../grill-with-docs/SKILL.md) (anchors to
- Add/update roxygen2 docs on every exported function. `CONTEXT.md`) before entering the loop.
### 2. Document ## Then enter the appropriate loop
```bash
just document # devtools::document()
```
Fix all roxygen2 warnings.
### 3. Lint & style - `DESCRIPTION` detected → [`package-loop.md`](package-loop.md)
```bash (document → lint → style → test → check → commit)
just lint # lintr - `_targets.R` detected → [`analysis-loop.md`](analysis-loop.md)
just style-check # styler dry run (lint → style → test → run pipeline → render → commit)
# 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).
## See also ## See also
- [`../tdd-bdd/SKILL.md`](../tdd-bdd/SKILL.md) and its R siblings - [`../tdd-bdd/SKILL.md`](../tdd-bdd/SKILL.md) and its R siblings
(`tests-r.md`, `interface-design-r.md`, `mocking-r.md`, (`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 - [`../diagnose/SKILL.md`](../diagnose/SKILL.md) — six-phase bug hunt
with R-flavored siblings. with R-flavored siblings.
- [`../r-style/SKILL.md`](../r-style/SKILL.md) — coding standards. - [`../r-style/SKILL.md`](../r-style/SKILL.md) — coding standards.

View File

@ -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).

View File

@ -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).

View File

@ -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 - No production code exists that is not exercised by a test added in this
loop. loop.
## Anti-pattern: horizontal slicing ## Anti-patterns
**DO NOT write all the tests first, then all the implementation.** Treating See [anti-patterns.md](anti-patterns.md) — horizontal slicing, passing on
RED as "write every test from step 0" and GREEN as "make them all pass" is first run, refactoring while red, silently dropping an untestable scenario.
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.
## Guardrails ## Guardrails
- **Never** skip the red step. If a test passes on first run, it is - **Never** skip the red step (see anti-patterns.md *"Passing on first run"*).
testing the wrong thing — fix it before continuing. - **Never** write more than one failing test at a time (see anti-patterns.md
- **Never** write more than one failing test at a time (horizontal-slicing *"Horizontal slicing"*).
trap above). - Refactor only with a green bar (see anti-patterns.md
- If a scenario turns out to be untestable at the chosen level, surface it *"Refactoring while red"*).
— don't silently drop it. Move it up (integration) or down (unit) one - If a scenario turns out untestable at the chosen level, surface it (see
level and reconfirm with the user. anti-patterns.md *"Silently dropping…"*).
- Refactor only with a green bar. No "tidy while red".
## See also ## See also
- [../diagnose/SKILL.md](../diagnose/SKILL.md) — chasing an existing bug? - [../diagnose/SKILL.md](../diagnose/SKILL.md) — chasing an existing bug?

View File

@ -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.

View File

@ -79,18 +79,10 @@ change with an outdated message. Open a fresh empty `@` immediately so
the next concern starts in a clean working copy. the next concern starts in a clean working copy.
## Anti-patterns ## Anti-patterns
- **`jj describe` before `jj diff`.** You'll commit debug `cat()`s,
stray `browser()` calls, and TODO scratchpads. See [anti-patterns.md](anti-patterns.md) — `jj describe` before
- **"Mixed bag" commits.** `refactor + fix + new feature` in one change `jj diff`, mixed-bag commits, past-tense messages, missing scope, docs
is three regressions waiting to happen and an unrevertable mess. deferred to the next commit, skipping `jj new` after describe.
- **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 `@`.
## Examples ## Examples
See [examples.md](examples.md) for a real before/after where a 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. as the fix.
- [`../../engineering/diagnose/SKILL.md`](../../engineering/diagnose/SKILL.md) - [`../../engineering/diagnose/SKILL.md`](../../engineering/diagnose/SKILL.md)
— phase-6 post-mortem commit message names the confirmed hypothesis. — phase-6 post-mortem commit message names the confirmed hypothesis.
- [`../../engineering/dev-python/SKILL.md`](../../engineering/dev-python/SKILL.md) - [`../../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.
and
[`../../engineering/dev-r/SKILL.md`](../../engineering/dev-r/SKILL.md)
— workflow orchestrators that hand off here for the commit phase.

View File

@ -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.