Skip to content

handbook: an implementer digest beside each coding-rules handbook - #128

Draft
buzzdan wants to merge 9 commits into
mainfrom
claude/coding-rules-implementer-digest-c34dd2
Draft

buzzdan wants to merge 9 commits into
mainfrom
claude/coding-rules-implementer-digest-c34dd2

Conversation

@buzzdan

@buzzdan buzzdan commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

The generator now renders an implementer digest beside each coding-rules handbook: coding-rules/<lang>.digest.md. The digest keeps the shape decisions of the twelve rules and drops the examples. It is for an agent that writes code and imports the rules into its fixed context. The full handbooks do not change.

  • New template core/handbook/coding-rules.digest.md and new profile key digest: in all four bindings.
  • One new line per rule in core/includes/handbook/Rn/digest.md. No binding override is necessary today.
  • Two new digest-only constructs, documented in the core/README.md handbook table:
    • maximName: the maxim title only. It fails when maxims.md has no such heading. The existing maxim renders the full Ask paragraph, which is too long.
    • handbookPath: the full handbook's path relative to the digest, percent-encoded per segment, as the destination of the pointer link.
  • Generator: the handbook code path is now a list of documents (tools/ldd-gen/internal/gen/documents.go). The digest gets the same marker, overwrite refusal, drift check (missing, changed, exec bit), path claims and residue gate as the handbook. The render fails when a digest is over 8,000 bytes (render.DigestMaxBytes), so task generate and task check both stop growth.
  • Docs: docs/handbook.md (what the digest is, who it is for, how to consume both, the ceiling), experiment 8 in docs/eval-return-experiments.md (optional digest cell), docs/generator.md, docs/language-residue.md, docs/index.md, README.md, CLAUDE.md, Taskfile.yaml task descriptions.

Sizes

Words are wc -w. Tokens are bytes ÷ 4, the method that reproduces the four token figures of the request. wc -w counts about 3 percent more words than those figures.

Binding Full handbook Digest Digest / full
go 4,875 words, 30,246 B, ~7.6k tokens 1,230 words, 7,246 B, ~1.8k tokens 24%
python 5,417 words, 35,034 B, ~8.8k tokens 1,265 words, 7,451 B, ~1.8k tokens 21%
generic 5,202 words, 32,317 B, ~8.1k tokens 1,220 words, 7,188 B, ~1.8k tokens 22%
ts-react 6,598 words, 42,794 B, ~10.7k tokens 1,300 words, 7,743 B, ~1.9k tokens 18%

The ceiling is 8,000 bytes. ts-react has 257 bytes left. Its house-rule review lines are the largest fixed part (about 900 bytes).

Weighting

Judgment questions per rule

Detect: judgment lines in each binding's rules/Rn/falsifying-questions.md (generic reads the core default). Numbers in brackets are the question numbers.

Rule go python ts-react generic
R1 1/8 [2] 1/8 [2] 1/8 [2] 5/8 [2 5 6 7 8]
R2 2/6 [1 3] 2/6 [1 3] 2/6 [1 3] 5/6 [1 2 3 5 6]
R3 1/5 [1] 1/5 [1] 1/5 [1] 4/5 [1 2 3 5]
R4 4/6 [1 4 5 6] 4/6 [1 4 5 6] 4/6 [1 4 5 6] 5/6 [1 2 4 5 6]
R5 4/7 [2 3 4 5] 4/7 [2 3 4 5] 4/7 [2 3 4 5] 4/7 [2 3 4 5]
R6 3/5 [2 3 4] 2/5 [3 4] 2/5 [3 4] 4/5 [1 2 3 4]
R7 1/7 [3] 1/7 [3] 1/7 [3] 3/7 [2 3 4]
R8 0/6 0/6 0/6 5/6 [1 2 3 4 6]
R9 2/7 [5 6] 2/7 [5 6] 2/7 [5 6] 3/7 [4 5 6]
R10 3/6 [2 3 6] 3/6 [2 3 6] 2/6 [3 6] 5/6 [1 2 3 4 6]
R11 2/5 [3 5] 2/5 [3 5] 2/5 [3 5] 2/5 [3 5]
R12 3/6 [2 3 5] 3/6 [2 3 5] 3/6 [2 3 5] 4/6 [1 2 3 5]

The generic binding has no language-specific search, so most of its questions are judgment. The picks follow go, python and ts-react, because the numbers are one list for all four.

What the recommended lint configs in core/setup/ hold

Rule golangci (go) ruff (python) eslint (ts-react)
R1 partly: dupl, maintidx, argument-limit, function-result-limit partly: PLR0913, PLR2004 partly: max-params, no-duplicate-string, max-union-size, no-magic-numbers
R2 no no partly: no-explicit-any, no-unsafe-*, no-non-null-assertion
R3 yes: gocyclo, gocognit, funlen, nestif, maintidx yes: C901, PLR0911/0912/0915/1702 yes: sonarjs complexity, length and nesting rules
R4 no no no
R5 partly: file-length-limit no partly: max-lines, no-multi-comp
R6 partly: ireturn no no
R7 no no no
R8 yes for declarations: gochecknoglobals, gochecknoinits partly: PLW0603 partly: import/no-mutable-exports
R9 no no no
R10 partly: govet copylocks no partly: exhaustive-deps, no-floating-promises, no-misused-promises
R11 partly: exhaustive partly: FBT001/002 partly: switch-exhaustiveness-check, switch-size rules
R12 no partly: B006, B008 partly: no-param-reassign, prefer-read-only-props

The generic binding ships no lint config.

The picks

Rule order: judgment questions first, because no search finds them and few linters hold them. Then the questions that decide a type's shape at write time, because that shape is expensive to change in review.

Rule Questions Why
R1 2, 6, 8 Q2 is its one judgment question. Q6 (ceremony type) and Q8 (container across a boundary) decide a type's shape at write time. Q1 and Q4 are search hits that a review finds cheaply.
R2 1, 3, 4 Q1 and Q3 are judgment. Q4 (upstream validation) decides where validation lives. Q5 (the missing value as a value) is left out: its headline without its body reads as if a declared optional return were a violation.
R3 2, 5 Q1 is judgment but the complexity linters hold it in all three configs. Q2 and Q5 no linter holds.
R4 1, 5, 6 Three of its four judgment questions. Q4 (single-noun package) applies only when a new shared package appears.
R5 2, 3, 4 Three of its four judgment questions. Q5 (migration plan) is a repository-level question, not a write-time one.
R6 3, 4 The two questions that are judgment in every binding. Go's Q2 is also judgment, but python and ts-react detect it by search.
R7 3, 5 Q3 is its one judgment question. Q5 (asserts on a fake's internals) needs no exemption. Q4 is left out: its headline without its body contradicts the move "Delete private-function tests".
R8 3, 5 No judgment question. Q1 and Q2 (globals, init) are lint-held in go and partly in python and ts-react. Q3 and Q5 are not.
R9 5, 6 Its two judgment questions.
R10 2, 3, 6 Its judgment questions in go and python. In ts-react Q2 is a search.
R11 1, 3, 5 Q3 and Q5 are judgment. Q1 (one discriminator in two places) is the shape decision the rule exists for.
R12 2, 3, 5 All three judgment questions.

R4, R5, R10 and R12 (judgment-heavy) and R1, R2 and R11 (shape at write time) get three questions. The others get two.

The twelve draft summaries, for your review

Each is one sentence of 20 words or fewer. The wording is a draft.

Rule Line
R1 Make a primitive a type when it carries validation, behavior or an invariant, and name each nested container; a wrapper with none of these is over-abstraction.
R2 Validate in the constructor, the only way to get a value, so that no method checks it again.
R3 Write each top-level function as a short list of named steps at one level of abstraction.
R4 Test a private function through its public caller, and give a juicy helper type its own package with direct tests.
R5 Put new code in its feature's package, but in a layered repository follow the architecture doc or the nearby code.
R6 Depend on the concrete type, add an interface only for a second production implementation, and fix an import cycle in the layering.
R7 Test each behavior at the lowest rung that holds it, with real collaborators, and fake only the external boundary.
R8 Pass each dependency in from the caller, and read configuration only at the entry point.
R9 Write a {{.DocComment}} that says why, and change the feature doc in the same change as the behavior.
R10 Give each {{.Task}} an owner that stops it and waits for it, and guard shared state where it lives.
R11 Switch on a value's kind at most once, exhaustively; a second switch on the same kind wants a polymorphic type chosen at the boundary.
R12 Copy collections into a validated type, return copies or iterators, and change it only through methods that keep its invariants.

R4 uses "juicy", the handbook's term for an R1 score of 4 or more; the digest does not define it. R9 and R10 use the binding's scalars ("godoc comment", "docstring", "JSDoc comment"; "goroutine", "concurrent task", "async task").

Maxims are names only. The request allows "at most one short line". Nine extra lines (about 600 to 900 bytes) do not fit in ts-react's 257 bytes of margin. The names are short imperatives already. If you want the lines, the price is a trim elsewhere in the digest, for example one question less on R1, R2 and R11.

Audit of the full handbooks (not changed in this PR)

Bytes per ## section, as rendered on main:

Section go python ts-react generic
Header 590 602 628 607
1. Mindset 2,092 2,092 2,092 2,092
2. The twelve rules 20,089 23,619 30,165 22,654
3. House rules 4,040 5,003 5,613 3,422
4. Self-review 2,453 2,648 2,915 2,364
5. Mechanics 977 1,097 1,372 1,173
Total 30,246 35,066 42,790 32,317

Inside "The twelve rules", summed over the twelve rules:

Part go python ts-react generic
Principle (core, with heading) 6,515 6,560 6,510 6,524
Example fence 7,392 8,672 12,830 7,294
> In <Lang> / > Spelling aside 3,715 5,916 8,342 6,359
Moves (core) 2,007 2,007 2,007 2,007

Where each binding is longer than go:

  • ts-react, +12,544 B (~3.1k tokens). Examples +5,438, asides +4,627, house rules +1,573 (the H1 and H2 spelling asides are 1,125 and 1,334 B against go's 549 and 805), self-review +462, mechanics +395.
  • python, +4,820 B (~1.2k tokens). Asides +2,201, examples +1,280, house rules +963.
  • generic, +2,071 B (~0.5k tokens). The > Spelling: asides are +2,644. Its house rules are 618 B shorter.

The longest single items: the ts-react R1 example (1,746 B; go 1,382), the ts-react R11 example (1,345 B; go 630), the ts-react R2 example (1,241 B; go 667), the R4 Principle (1,353 B in every binding, twice the next Principle), and the "When in Rome" maxim (about 560 B).

Proposed trims, for a separate decision

Handbook-only (no plugin file changes, so no eval): none proposed.

A rewrite of the asides in ASD-STE100 that keeps every fact was measured on the twelve ts-react asides: 8,342 to 8,200 bytes, 2% less. It makes the text clearer for a human reader, not shorter, so it is not proposed as a trim. The defects that the rewrite found are fixed in this PR (see below).

Three cuts are not proposed, because each one removes a lesson:

  • One example pair per rule. Each second pair teaches a different point: R1 names a container, R2 binds a Null Object, and R11 closes a switch with assertNever.
  • H1 and H2 spelling asides at Go's length. TypeScript has seven suppression forms and Go has two, so the longer aside holds facts, not words.
  • Only the first question of each maxim. The text after the question is its answer, for example how test pain maps to a design fault.

A fixed cap of about 400 B per aside is not proposed. Each aside holds the language's position, and most of its sentences are separate facts that no other part of the handbook has. For example, the ts-react R8 aside lists what is never a finding, what is a finding only outside the composition root, and what is always a finding. A 400 B cap keeps the findings and removes the "never a finding" list, which stops a reader from applying the rule too widely.

A split of the examples into a separate document is not proposed. The digest is already that split: teams import the digest, and the full handbook costs tokens only when someone opens it. A file per rule would cut an on-demand read from about 43 kB to about 3 kB. Consider it only if evals show that agents often open the full handbook.

Plugin text (would need an eval under docs/eval-baseline.md, "Core text that all bindings render"):

# Trim File Saves
1 Move the constructor paragraph of R4's Principle into its Fix pattern core/rules/R4-helper-placement.md ~600 B in every binding
2 Shorten the "When in Rome" Ask core/maxims.md ~400 B in every binding

No plugin file changed, so no eval

git diff --stat origin/main -- over the four plugin directories, core/rules, core/includes/rules, core/agents, core/skills, core/commands, core/maxims.md and lang/*/passthrough is empty.

The full handbooks coding-rules/ts-react.md and coding-rules/python.md change only in their asides (lang/<lang>/handbook/, which no plugin reads). The fixes make each aside stand alone:

  • Remove the references to other sections: "shown under R1" (ts-react and python R2), "the fence above" (python R2), "the second fence" (ts-react R2).
  • Remove the internal codes "(T3)" (ts-react R11) and "R2 Q5" (ts-react H2).
  • Complete the ts-react R9 sentence about the props doc, which had no verb.

The fixes do not change the go and generic handbooks or any digest.

The scope row in docs/eval-baseline.md, "Choosing the eval scope for a change": "Shared script or generator, plugin text byte-identical | Shell tests and task check. No eval."

lang/ts-react/passthrough/README.md names only the full handbook. It is plugin text, so this PR does not change it.

docs/quick-start.md has no passage that tells a team what to import. The import advice lives in README.md, which this PR changes.

Test plan

  • task generate for go, generic, python and ts-react
  • task check: every plugin directory, handbook and digest matches its rendering
  • task lint-core (the Residue section of core/README.md gains one soft row for the interface aside in R6/digest.md)
  • go test ./... and golangci-lint run ./... in tools/ldd-gen: 0 issues
  • bash scripts/check-docs.sh
  • task test-gate
  • New tests: profile digest: validation; render.Digest (output, unknown maxim, no digest in the profile, at and over the ceiling, not a plugin file); generate and check for a digest (missing, changed, exec bit), residue gate on a non-Go digest, refusal to overwrite a hand-written digest, path conflicts between digests and handbooks

🤖 Generated with Claude Code

buzzdan and others added 2 commits November 18, 2026 16:19
The generator renders coding-rules/<lang>.digest.md for each binding that
names a digest: path. The digest keeps the shape decisions of the rules
(maxim names, one line per rule, move names, two or three question
headlines, house-rule review lines) and drops the examples. It has the
handbook's marker, overwrite refusal, drift check and residue gate, and
its render fails over 8,000 bytes.

No plugin file changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ines

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings November 18, 2026 14:24

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The digests omit required qualifications on architecture layout and helper-type placement and testing, risking unapproved restructuring and missed direct tests.

2 open issues
What changed in this PR

Adds compact implementer digests beside the four coding-rules handbooks, giving coding agents a smaller fixed-context reference while leaving the full handbooks and plugin text unchanged.

Changes:

  • Adds a shared digest template, twelve rule summaries, and generated digests for all four bindings.
  • Extends generation, validation, drift checks, and tests to cover digests, including an 8,000-byte ceiling.
  • Documents digest consumption, generation, and an optional evaluation experiment.
File Description
tools/​ldd-gen/​internal/​render/​handbook.go Adds digest rendering, maxim titles, relative links, and size enforcement.
tools/​ldd-gen/​internal/​render/​digest_test.go Tests rendering, errors, size limits, and plugin exclusion.
tools/​ldd-gen/​internal/​profile/​profile.go Adds and validates digest output paths.
tools/​ldd-gen/​internal/​profile/​profile_test.go Tests digest profile constraints.
tools/​ldd-gen/​internal/​gen/​gen.go Generalizes handbook handling to standalone documents.
tools/​ldd-gen/​internal/​gen/​gen_test.go Updates path-conflict error expectations.
tools/​ldd-gen/​internal/​gen/​documents.go Centralizes document rendering, ownership, writing, and checks.
tools/​ldd-gen/​internal/​gen/​documents_test.go Tests digest generation, drift, residue, and overwrite protection.
Taskfile.yaml Updates task descriptions to include digests.
README.md Introduces digests and updates consumption guidance.
lang/​ts-react/​profile.yaml Configures the TypeScript/React digest path.
lang/​python/​profile.yaml Configures the Python digest path.
lang/​go/​profile.yaml Configures the Go digest path.
lang/​generic/​profile.yaml Configures the generic digest path.
docs/​language-residue.md Documents digest residue checks.
docs/​index.md Expands the handbook documentation entry.
docs/​handbook.md Explains digest content, consumption, and size limits.
docs/​generator.md Documents digest generation and drift checking.
docs/​eval-return-experiments.md Adds an optional digest evaluation cell.
core/​README.md Documents digest templating and updates residue counts.
core/​includes/​handbook/​R9/​digest.md Adds the documentation summary.
core/​includes/​handbook/​R8/​digest.md Adds the dependency-injection summary.
core/​includes/​handbook/​R7/​digest.md Adds the test-placement summary.
core/​includes/​handbook/​R6/​digest.md Adds the interface-use summary.
core/​includes/​handbook/​R5/​digest.md Adds the feature-placement summary.
core/​includes/​handbook/​R4/​digest.md Adds the helper-testing summary.
core/​includes/​handbook/​R3/​digest.md Adds the function-structure summary.
core/​includes/​handbook/​R2/​digest.md Adds the constructor-validation summary.
core/​includes/​handbook/​R12/​digest.md Adds the mutation-discipline summary.
core/​includes/​handbook/​R11/​digest.md Adds the conditional-dispatch summary.
core/​includes/​handbook/​R10/​digest.md Adds the concurrency-ownership summary.
core/​includes/​handbook/​R1/​digest.md Adds the domain-type summary.
core/​handbook/​coding-rules.digest.md Defines the shared digest layout and question selections.
coding-rules/​ts-react.digest.md Adds the generated TypeScript/React digest.
coding-rules/​python.digest.md Adds the generated Python digest.
coding-rules/​go.digest.md Adds the generated Go digest.
coding-rules/​generic.digest.md Adds the generated language-neutral digest.
CLAUDE.md Includes digests in generated-file guidance.

Review effort: Balanced

Comment thread core/includes/handbook/R4/digest.md Resolved
Comment thread core/includes/handbook/R5/digest.md Resolved
…s in the digest

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings November 18, 2026 14:30

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The digest omits essential exceptions for optional returns and direct-test requirements, creating misleading and contradictory guidance that needs correction and regeneration.

No open issues 🎉

2 previously missed issues

In code that hasn't changed since last review

Low severity Preserve optional-return exceptions in Q5 digest text

core/​handbook/​coding-rules.digest.md:39

Extracting Q5's headline alone makes valid X | None and X | undefined returns look like violations, although the Python and TypeScript R2 question bodies explicitly allow narrowed ordinary absence and exempt procedures/platform cases. Preserve those distinctions in binding-specific digest text and regenerate the affected outputs so implementers do not replace valid optional returns with exceptions or null objects.

Low severity Clarify Q4 test requirement scope in standalone digests

core/​handbook/​coding-rules.digest.md:74

Q4's headline loses an essential scope restriction when rendered without its body: private functions and helper types scoring ≤3 do not require direct tests (lang/go/rules/R7/falsifying-questions.md:29–49, with the same exclusions in the other bindings). The standalone digest now asks whether a private leaf lacks a direct test while also listing “Delete private-function tests,” giving implementers contradictory guidance. Qualify this question to cover qualifying helper types after promotion and new public leaf behavior, then regenerate the digests.

2 resolved since last review

Review effort: Balanced

…ions

R2 Q5 (the missing value as a value) and R7 Q4 (no direct test) need their
bodies' exemptions, which the digest does not render. R2 Q4 and R7 Q5 do not.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings November 18, 2026 14:40

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Digest Markdown links use unescaped filesystem paths, causing incorrect destinations for accepted handbook filenames containing URL-significant characters such as '#'.

No open issues 🎉

1 previously missed issue

In code that hasn't changed since last review

Medium severity Markdown link destination fails to encode special filename characters

tools/​ldd-gen/​internal/​render/​handbook.go:217

This returns a filesystem path directly into a Markdown link destination, but profile validation accepts URL-significant characters. For example, handbook: coding-rules/c#.md with a sibling digest produces [c#.md](c#.md), which links to c with fragment .md, not to the generated handbook. Encode the relative path for use as a link destination (including literal #, ?, % and spaces), and cover such accepted filenames in the digest renderer tests.

Review effort: Balanced

A '#' or a space in a profile path ended the Markdown link destination.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings November 18, 2026 14:50

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Human review is needed to assess the impact of mandatory stop-and-wait guidance that conflicts with supported TypeScript cleanup and query-layer lifecycle alternatives.

No open issues 🎉

Review effort: Balanced

Remove the references to other sections ("shown under R1", "the fence
above", "the second fence") and the internal codes "(T3)" and "R2 Q5".
Complete the R9 sentence about the props doc, which had no verb.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings November 19, 2026 19:13

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Human assessment is needed because several digests omit qualifications from the source rules, potentially steering implementers toward unnecessary abstractions or collection copies.

No open issues 🎉

Review effort: Balanced

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings November 19, 2026 19:24

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Human judgment is needed because the digests conflict with source guidance on vocabulary types and import-cycle repairs.

No open issues 🎉

Review effort: Balanced

…digest

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings November 19, 2026 19:34

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Human assessment is needed to judge whether the digest summaries adequately preserve structural justifications for introducing types and valid exceptions to the dispatch guidance.

No open issues 🎉

Review effort: Balanced

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings November 19, 2026 19:44

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Human assessment is needed because the digests omit lint-policy safeguards and error-boundary context requirements, leaving digest-only agents without that guidance.

No open issues 🎉

Review effort: Balanced

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants