Skip to content

Commit 61a49bf

Browse files
ethanresnickclaude
andauthored
docs(skills): add design-iteration, simplify, module-and-api-design, and shared-checkout skills (#28)
* docs(agents): add design-iteration and shared-checkout skills Adapted copies of the monorepo skills that came out of the PR #27 retro: - simplify: six review angles, including Structure, which reviews the touched modules as a whole, and a loop that repeats the review until a pass changes nothing. Run it before every commit. - module-and-api-design: API surface, module shape after a change, and what a change report must disclose. - shared-checkout: rules for a worktree the user edits at the same time. .claude/skills is a symlink to .agents/skills so Claude Code finds them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * docs(skills): add design-iteration passes and sync simplify with the monorepo Add a design-iteration skill: the questions an agent asks of its own design before it reports done. Sync simplify and module-and-api-design with joinava/monorepo#16676 (Baseline & naming angle, Structure additions, Phase 2 skip rule), keeping this repo's adaptations. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * docs(skills): fix review findings in simplify and the shared-checkout rules - Stage an own-only version of a shared file from a scratch file, with the two-diff proof and the full --cacheinfo syntax. Stop on user-staged paths. - Diff against the merge base with origin/main, not @{upstream}, and add untracked files to the review scope. - Keep cross-scope proposals out of TODO comments. - Migrate only copies of an idiom that must evolve together. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * docs(skills): apply review comments to simplify and the shared-checkout rule - Reword when to extract a helper, per review. - Remove the vague variant-flag paragraph. The Structure "Modes" check covers the same smell. - Name `Tagged` and `#private` fields as the ways to carry a brand. - Keep the path's file mode when staging a scratch blob. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * docs(skills): apply second round of review comments to simplify - Show how a Tagged brand outlives a spread-and-mutate. - Losses from a rewrite: assess whether restoring the old output is worth its cost, and flag it when unsure. - "usually" -> "often" for single-class wrappers. - Remove the Structure "Modes" check. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * docs(skills): allow composing helpers, drop the angle-wide real case - Callers must be able to compose a tool easily. A helper whose point is to do a tricky composition for the caller is the exception. - Remove the "Real case for this whole angle" paragraph. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent a2ee9ee commit 61a49bf

5 files changed

Lines changed: 594 additions & 0 deletions

File tree

Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
---
2+
name: design-iteration
3+
description: "Design-iteration passes that an agent runs over its own code before it reports a structural change as done. Use after adding or splitting a component, changing a contract or public API, rewriting a module, or moving responsibility between modules, and before listing a design smell as an accepted cost. Covers the pass loop, the question bank, and when to apply versus propose."
4+
---
5+
6+
# Design iteration
7+
8+
A design is not done when it works and its tests pass. It is done when a pass
9+
over it finds nothing simpler.
10+
11+
The failure this skill fixes: an agent ships a working design, then the user
12+
asks "why does X need Y?" and the agent answers with the better design in one
13+
turn. The agent had the knowledge. It did not ask the question. In one session
14+
of this package's v4 work, the user started nearly all of several dozen
15+
design rounds. Most rounds began with one of these questions:
16+
17+
- "Do we still need X?"
18+
- "Why does Y care about Z?"
19+
- "Is X derived from Y?"
20+
- "Can't A just call B directly?"
21+
- "Should this exist at all?"
22+
23+
Ask them yourself, before the user has to.
24+
25+
## When to run a pass
26+
27+
Run a pass before you report done, after any of these:
28+
29+
- You add a component, or split or merge components.
30+
- You change a contract, a public API, or a type that other modules read.
31+
- You rewrite a function or module.
32+
- You move responsibility from one module to another.
33+
- A pass applied a change. Run another pass, because one change often makes
34+
another piece obsolete.
35+
36+
Also run a pass when you are about to write "accepted cost", "acceptable
37+
because it is private", "mostly theoretical", or "behavior change" about your
38+
own design.
39+
40+
## The loop
41+
42+
1. Run the question bank below over every field, parameter, option, type,
43+
helper, and module boundary the change adds or touches.
44+
2. Apply each fix that stays inside the task's scope.
45+
3. Propose each fix that crosses scope, and let the user decide whether to
46+
widen it. Give the fix. Do not only name the smell.
47+
4. Repeat from step 1 until a pass finds nothing, or after three passes.
48+
5. Run `/simplify` on the result. Its Structure angle reviews the touched
49+
modules as a whole, and its report lists what a reviewer must see.
50+
51+
## Rules
52+
53+
- **If you could answer it when asked, it is yours to fix now.** When you can
54+
name the better shape, propose or apply it. Do not wait for the question.
55+
- **A smell you list must come with a fix.** "This is worse than before",
56+
"no requirement forces this order", and "the names still differ" are the
57+
start of a change, not its report. (Real case: the agent listed four
58+
regressions against an earlier version, including an `any[]` result and
59+
mutable state that user code could reach. The user then had to request each
60+
fix one at a time.)
61+
- **An API you own is not fixed.** Change the lower layer when that is the
62+
simpler design. Do not add a side channel in the consumer to avoid it. (Real
63+
case: the agent saved and restored a mutable variable around every call to
64+
its own `TaskSharer`, because adding a context argument "would change the
65+
sharer's API". The context argument deleted the save-and-restore in two
66+
places.)
67+
- **Ask whether it should exist before you rename it.** A rename keeps the
68+
thing. (Real case: the agent renamed `Work.accumulated` to `autoBatch`. A
69+
later pass deleted the whole `Work` type, because the batcher already
70+
computed the only value that depended on it.)
71+
- **Extraction does not remove state.** A helper extraction lowers nesting but
72+
keeps every variable. Check that your simplification deleted something.
73+
- **Do not keep an order because the old code had it.** When the old shape
74+
forced a guard, a deferred, or a failure path, ask what requirement forced
75+
that shape. Remove the shape when no requirement does.
76+
- **Read the prior art before you design its replacement.** When you replace a
77+
well-known library, read its source to learn its semantics, and run its own
78+
tests against your replacement. Write down each difference.
79+
80+
## Question bank
81+
82+
### Existence
83+
84+
- Does each field, parameter, option, and type have a reader? Delete it when
85+
nothing reads it, along with the type parameters it carries.
86+
- Can a value be computed from other state, or from another value you also
87+
return? Derive it on demand, or state why it is stored.
88+
- Did this change make an earlier workaround unnecessary? Look for guards,
89+
boxes, deferrals, and dedup steps that existed only for the removed problem.
90+
- Is a helper or named type used in one place only? Inline it when it hides
91+
the flow or the contract.
92+
- Does a public export have a real consumer? If it cannot honor a guarantee
93+
that every other entry point honors, remove it instead of documenting the
94+
gap or adding a hook.
95+
96+
### Responsibility
97+
98+
- Does this module import or name a type from a module that sits above it?
99+
The composer imports the parts. A part never imports its composer.
100+
- Does a flag or parameter repeat a decision that the caller already expresses
101+
through another input? (Real case: a `background` flag only dropped the
102+
signal, and the caller already passed no signal.)
103+
- Does a generic component encode one caller's modes, such as an
104+
`"automatic" | "direct"` parameter? Move that policy to the caller.
105+
- Does a concern live on an object with a different lifetime? A lease that
106+
must last for a task's whole life belongs on the task, not on the queue.
107+
- Does a method mostly touch another object's fields? Move it to that object.
108+
- Does every call to X sit next to a call to Y? Fold Y into X.
109+
110+
### Composition
111+
112+
- Make a table of callers against features. If the table is sparse, split the
113+
component into blocks, and let each caller compose the blocks it needs.
114+
(Real case: one scheduler did batching and sharing. Store reads used only
115+
batching, single-request producers used only sharing, and only bulk
116+
producers used both.)
117+
- Does any caller pay for a part that it switches off? It should not use that
118+
part.
119+
- After a split, re-justify each option that came from the old component. Some
120+
options exist only because one object did two jobs.
121+
- Is a special case a general mechanism in disguise? A task "without
122+
cancellation" is a task with no signal.
123+
124+
### API shape
125+
126+
- Does any caller work around the API? Signs are a pre-filter, `[0]!`,
127+
inferring a value the callee knows, or two settings to express one intent.
128+
A workaround is evidence of a callee defect.
129+
- Does a callback receive information that its caller already has? Return
130+
data and let the caller act after the call.
131+
- Is each fact at the level where it varies? A per-call fact belongs on the
132+
call, not repeated on each item.
133+
- In a batch API, does one bad item affect the other items? It must not.
134+
- Is each fixed collaborator a constructor option, and each per-call choice an
135+
argument?
136+
- Does a flag keep the promise that its name makes? Fix the flag. Do not add a
137+
second option beside it.
138+
139+
### Invariants
140+
141+
- Does correctness depend on call order that only a comment states? Make one
142+
operation do both steps, or use a hold, lock, or refcount that makes the
143+
wrong order impossible.
144+
- Did you make a field optional and then add an "impossible" throw? Model the
145+
new case as a union where the paths meet, and leave the old type unchanged.
146+
- Can the API express an illegal combination of options? Make it untypeable.
147+
- Does a doc comment describe a known gap? Look for the primitive that closes
148+
it before you accept it.
149+
- Do you represent absence with a sentinel? Use `undefined` and an optional
150+
field. Do not export an internal constant so that another module can compare
151+
against it.
152+
- Did you write `T | undefined` at the use site of a type parameter? Write
153+
`T`, and let a caller that needs `undefined` put it in the type argument. For
154+
an omittable trailing argument, default the type parameter to `void`:
155+
TypeScript lets a caller omit a trailing argument only when its type accepts
156+
`void`.
157+
158+
### Names
159+
160+
- Does each concept have one name across every layer, including the wrapper
161+
around a component? Trace a value from its entry point to its last use.
162+
- Does each name refer to exactly one concept?
163+
- Does a name describe what the thing is, or only its mechanism or first use?
164+
- Does a function's name match what it takes and every effect it has? A name
165+
like `flush` must cover a permanent mode change, if the method makes one.
166+
167+
### Baseline
168+
169+
- Diff the rewrite against the base branch. For each lost name, log, comment,
170+
helper, `async`, or assertion, confirm that the change needs it gone.
171+
- Did a refactor onto a new abstraction drop an output that callers had, such
172+
as a log field or a metric? Extend the abstraction to expose the fact. Do not
173+
report the loss as a behavior change.
174+
175+
### Verifiability
176+
177+
- Before you propose a design, write the call trace for two or three
178+
interleaved calls, including the edge modes. Two design errors in the cache
179+
work appeared only when the user asked for pseudo-code.
180+
- Are `map`, `filter`, and `flatMap` callbacks free of side effects? Decide
181+
first, then act.
182+
- Is each acquire paired with its release on every path, close enough that a
183+
reader can check it line by line?
184+
185+
## Apply versus propose
186+
187+
Apply a fix in the same task when it stays inside the files and contracts the
188+
task already changes. Propose it with a concrete fix when it edits a module
189+
the task never named, turns a test-only change into a production change, or
190+
changes a public contract the user has not asked to change. In both
191+
cases, say what the pass found.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
---
2+
name: module-and-api-design
3+
description: "Use before adding a public API, a required argument, an option, a new file, a wrapper class, or shared code, and before reporting a change that moves, splits, or merges modules. Covers minimizing the API surface, reading the module first, the shape a module should take after a change, what a change report must disclose, and when to duplicate code that only looks identical."
4+
---
5+
6+
# Module and API design
7+
8+
## Minimize Your API Surface — Promise Less, Demand Less
9+
10+
Every piece of code makes promises to its consumers (return types, supported operations, available fields) and demands from them (required arguments). Both constrain future evolution.
11+
12+
- **Promise only what's truly necessary.** Don't return extra data or support operations that aren't needed yet. The smaller the contract, the easier the code is to change.
13+
- **Consider your consumers.** This package is a published library, so most consumers are outside your control. Every exported symbol, option, and documented behavior is a promise that only a major version can break. Keep promises small.
14+
- **Demand only what's truly necessary — but understand _why_ it's a cost, so you can tell when it isn't.** Making an argument required (vs. optional-with-a-default) is only costly for two concrete reasons: (1) **backward-compatibility** — a new required argument breaks every existing caller, so this bites in proportion to how many callers exist and whether you control them; and (2) **portability/usability** — a required argument a caller can't produce locks the functionality out of contexts that lack it. When _neither_ bites, requiredness is nearly free, and the countervailing concern usually wins: **a default silently answers "what does a caller who didn't think about this want?", and for a capability whose absence quietly removes behavior (observability, a safety/deadlock guard, auth, durability) on the platform you actually run on, the didn't-think-about-it case is precisely the production bug.** So: if there are few/no existing callers to break, _and_ every target context can supply the argument (e.g. the module itself exports a ready-made no-op implementation, so opting out costs one explicit token rather than the ability to run), prefer **required with the no-op exported as an _explicit_ opt-out** over optional-with-a-silent-default. Flip back toward a default only when a cost genuinely applies — the API is already widely deployed, or no usable no-op can be shipped. Enforce a required capability at every layer that can be bypassed: the type, a boundary runtime check (naming the real impls and the explicit no-op), and an internal fail-loud `throw` instead of a `?? noop` fallback — "nothing was chosen" must never behave like "the no-op was chosen".
15+
- **Nullable vs non-null is a real tradeoff.** Promising non-null simplifies consumers but limits evolvability. Default to nullable for fields that could plausibly be absent in future use cases; promise non-null when it saves significant consumer complexity and the field is stable.
16+
- **Before you add an option, check whether callers can easily compose it.** If a caller gets the same behavior by wrapping their own function or object with a tool they already have, add no option. Write a doc note that names the composition instead. The exception is a helper whose whole point is to do that composition for the caller, usually because it is tricky to do correctly. (Real case: a proposed `maxConcurrentBatches` knob on a cache library was dropped. Callers that want a limit wrap their producer in `pLimit`.)
17+
- **Make a function-valued public member `readonly`.** A public arrow-function property is reassignable unless you mark it `readonly`, and reassignment silently changes the behavior of every internal caller.
18+
- **A missing prerequisite is not a reason to add a bypass method.** If the canonical path into a module is blocked only because setup data is missing (e.g., a service profile with no seeded auth method, so you "can't" authenticate), seed the prerequisite — don't add a new public method that skips the canonical path.
19+
20+
## Understand the Module Before Changing It
21+
22+
**Before making changes to a module, read its structure first.** Understand the existing files, their responsibilities, and how they relate to each other. Then make your changes fit the existing architecture — don't create new files when the logic belongs in an existing one.
23+
24+
- **Read the module directory** (`ls` or `Glob`) before writing any code. Know what files exist and what each one does.
25+
- **Default to adding to existing files.** A new helper function belongs in the file that already contains related helpers. A new service method belongs on the existing service class. A new type belongs in the existing types file. Only create a new file when the responsibility is genuinely new and doesn't fit anywhere.
26+
- **Respect encapsulation boundaries.** `src/index.ts` defines the public API. Don't export an internal helper from it, and mark a member that must stay reachable inside the package but is not public with `@internal`.
27+
- **One file per clear responsibility, not one file per function.** Splitting a 50-line helper into its own file doesn't improve encapsulation — it just adds indirection. Files should represent coherent responsibilities, not individual functions.
28+
- **Ask yourself before creating a file**: Does this responsibility already have a home? Would a teammate look for this logic in an existing file? If yes, put it there.
29+
30+
## Shape the Module After the Change, Not Only the Diff
31+
32+
A change can be correct and still leave its module in a worse shape. Before you report a change, review the files, classes, and folders it touched as a whole. The Structure angle of the `simplify` skill lists the checks: consumers, size and concerns, dependency direction, repeated idioms, placement, primitive meanings, and the smallest mechanism. Run it on your own; do not wait for the user to ask why a file grew. While you write the code, ask the questions in the `design-iteration` skill. Three design rules apply while you write the code:
33+
34+
- **A wrapper must fully replace what it wraps.** When you put a class around a dependency to add behavior, make it wide enough that the consumer holds only the wrapper. A consumer that holds both the wrapper and the raw dependency can bypass the added behavior. If the wrapper adds behavior to exactly one class, merge it into that class instead. Keep the original method bodies as private methods (for example `#getWithoutPending`), and make the wrapper's methods the public ones.
35+
- **Keep a mechanism that serves one consumer out of the shared core.** If only one builder or variant needs a mechanism, let the code that creates that variant own it. Prefer existing object identity and lifetime (a `WeakMap` keyed on an object that already exists) over a new field or protocol that every shared layer must carry.
36+
- **Group by role, not by "touches the feature".** Code that builds X and code that consumes X are different roles, even when both mention X. Put them in different modules, and let the dependency run one way.
37+
38+
## Report What Your Change Promises
39+
40+
A user reviews your report, not every line. So the report must disclose the decisions a reviewer would otherwise have to find in the diff:
41+
42+
- **Each widening of the public API, with its reason.** A member that became public "for convenience" is a promise to every consumer. (Real case: `normalizeParams` and `normalizeVary` became public during a class merge, and the report did not say so. The user found it and asked why.)
43+
- **Each precondition that only a comment enforces.** Name the module that must uphold it and what breaks if it does not. Offer the type that would enforce it.
44+
- **Each deliberate behavior difference from `main`.** Label it as intent, not as a bug. In a review, check the PR's description and commits for intent before you call a deliberate change incorrect.
45+
- **The measured size change.** Give the line count of each touched file before and after. Do not estimate it.
46+
47+
## Duplicate Coincidentally-Identical Code
48+
49+
Two pieces of code that currently look the same should only share logic (base class, utility function) if they **must always evolve together**. DRY is a double-edged sword — automatic propagation of changes prevents bugs when consumers should stay in sync, but causes bugs when they shouldn't.
50+
51+
Key examples:
52+
53+
- **Create vs Update input types**: Never have Update extend Create. A new field on create shouldn't automatically be settable on update — force the developer to decide for each field.
54+
- **Storage row shapes vs public types**: Never link a Store's row or column shapes to the public resource types. A storage format change needs an explicit migration; linking the types hides this requirement and turns the row types into lies.
55+
- **Rule of thumb**: DRY up code you're confident should always evolve together. When in doubt, duplicate — three similar lines are better than a premature abstraction that couples unrelated concerns.

0 commit comments

Comments
 (0)