* test(#2721): failing-first suite for the gsd-regen driver and CONTEXT.md parity Tests precede the implementation per the TDD gate. The driver module does not exist yet, so tests/git-merge-regen-driver.test.cjs fails at require time; the contributor-standards parity assertions fail against next as it stands today, where the standards doc names two CONTEXT.md headings that have never existed. Refs #2721 * feat(#2721): add the gsd-regen merge driver and regen:derived The golden parity manifests and the two size baselines are pure functions of the source tree, so their only correct merge is "recompute" -- something git's ours/theirs interface cannot express. 140 of 143 conflicted-file instances across the open PR queue are these files. The driver deliberately does NOT regenerate. Four probes established that at merge-driver time neither the working tree nor the index reflects the merge: both hold the ours side, a file added by theirs does not exist yet, and MERGE_HEAD is unwritten. Git also invokes the driver once per conflicted path (20 here). A regenerating driver would therefore read the ours-side tree and emit a plausible-but-wrong hash manifest -- worse than a conflict, because a conflict is visible. So it accepts %A, runs zero subprocesses, records the resolved paths, and prints one notice pointing at npm run regen:derived. Staleness stays caught where it already was, by golden-install-parity in CI. Every failure path degrades toward today's behaviour (a normal conflict). install-tree is deliberately excluded per ADR-2719 section 7. Also folded in, per the no-defer rule: workflow-size.cjs claimed .md files have no eol=lf in .gitattributes; git check-attr shows eol: lf, set by .gitattributes line 2 since #1088. Refs #2721 * docs(#2721): document regen:derived and the gsd-regen merge driver Adds the how-to a contributor actually reaches for when the generated parity manifests or size baselines conflict, in both places they would look: the merge-conflict path in CONTRIBUTING.md and the full guide in TESTING-SUITES.md, including what the driver deliberately does not do (it does not clear GitHub's CONFLICTING label, and it does not regenerate mid-merge). Also scopes the new contributor-standards parity assertion to the doc's own CONTEXT.md section. Its first run flagged `## Decision`, `## Consequences` and `## Standards followed`, which the doc attributes to an ADR body and a PR body rather than to CONTEXT.md -- a doc-wide extractor would have demanded CONTEXT.md grow headings that do not belong to it. Refs #2721 * fix(#2721): stop passing %P to the merge driver — shell injection The isolated adversarial review found, and I independently reproduced, local arbitrary command execution. Git does not invoke a merge driver with an argv array. It substitutes %O %A %B %L %P textually into the configured string and runs the whole thing through a shell, and $(...) executes inside POSIX double quotes -- so quoting the placeholder does not neutralise it. %O/%A/%B are git-generated temp names and %L is an integer, but %P is the file's own path, chosen freely by any contributor. A branch renaming a covered fixture to evil$(touch PWNED_SENTINEL).json executed that command on the machine of every maintainer who merged it, and the merge still reported success. Fix removes the input rather than filtering it: %P is no longer registered, so the driver receives no attacker-controlled argument at all. The marker records a count instead of path names. A metacharacter filter would have been a guess about shell grammar; passing nothing is a property. Re-ran the identical exploit against the fixed command: nothing executed, conflict still resolved. Two regressions guard it -- a platform-independent assertion that the registered command carries no %P, and a real merge driven by the actual planInstall output with a $(...) filename. Also from review: CLI dispatch had no coverage at all (CONTRIBUTING's "CLI and command routing" matrix), which is why runInstall/runStatus now take {repoRoot} -- hardcoding REPO_ROOT was what made them untestable. Renamed planResolution to resolveAndRecord since the plan* prefix promised purity it did not have. Reconciled the eleven-vs-twelve generator count across CONTEXT.md, CONTRIBUTING.md and the changeset. Refs #2721 * test(#2721): scope safe.directory for the check-attr helper The 66f4d85a run failed 11 assertions, all in the .gitattributes scoping block, with "fatal: detected dubious ownership in repository at '/work'". The test container checks the repo out at a path its user does not own, so git refuses check-attr outright. Everything else passed (27,185). `check-attr` is a pure read of .gitattributes -- no hooks, no filters -- so the exemption is scoped to that one invocation. It is deliberately NOT applied to the driver's own production `git config` calls, which run in the user's own clone and should keep the protection. Refs #2721 * test(#2721): delete the stale assertion that the driver command carries %P The plex2 run on bdfd0856 left exactly two failures, both this test: it still asserted the pre-fix command string, i.e. the vulnerable behaviour. Deleted rather than relaxed, per RULESET.TESTS.delete-bad-tests -- its useful half is already covered, in both directions, by registeredDriverCommandNeverPassesThePlaceholderForTheFilePath. Refs #2721 * test(#2721): drive the end-to-end merges from the real planInstall output The e2e helper hand-rolled its own driver registration, and still carried %P. That meant the five real-git tests were not exercising the production command string at all -- planInstall could drift and they would keep passing. They now register exactly what a contributor gets from npm run setup:merge-driver. Refs #2721 * chore(#2721): backfill changeset pr number to 2730
11 KiB
Contributor Standards
Standards for working with CONTEXT.md, docs/adr/, and AI-agent-assisted contributions.
These apply to every PR — fix, enhancement, or feature. They are part of the merge contract, not optional background reading.
Standards hierarchy (canonical, in order):
CONTEXT.md— domain language and module namingdocs/adr/— accepted architectural decisions- Approved issue scope
CONTEXT.md
What it is
CONTEXT.md is the single source of truth for domain vocabulary. It defines:
- Domain modules and seams — canonical Module names, seam vocabulary, and Interface names (e.g. Dispatch Policy Module, Command Contract Validation Module, Planning Workspace Module)
- Recurring PR mistakes — CodeRabbit findings that recur; covers tests, shell guards, changesets, docs
- Workflow learnings — patterns distilled from triage + PR cycles
Format
CONTEXT.md is written as flat named sections under ## Glossary — Domain modules and seams (for Modules/seams) and ## sections for recurring rules. Machine-oriented predicates use KEY.SUBKEY=value flat format, grouped into the ## section that owns the topic — ## Test rules and lint, ## CodeRabbit + repo-process guards (machine-oriented predicates), or ## Workspace seams (machine-oriented predicates).
Adding a new Module or seam:
- Add a
### <Module Name>entry under## Glossary — Domain modules and seams. - Write one paragraph. State what the Module owns. Be concrete — list the Interface names and policy boundaries it covers.
- Do not add synonyms; pick one name and use it everywhere.
Extending an existing predicate:
- Add a
KEY.SUBKEY=valueline inside the relevant predicate section — for a test or lint rule that is## Test rules and lint. - Do not create a new top-level section for a variation on an existing concept.
When to add a new predicate vs extend an existing one:
- New predicate: the concept has a distinct identity, distinct owner, and is not covered by any existing section.
- Extend existing: the new fact qualifies, constrains, or amends an already-named Module. Add it as a sub-entry or amendment paragraph.
Contributor requirements
- Read
CONTEXT.mdin full before naming anything (modules, interfaces, seams, tests, PRs). - Use
CONTEXT.mdvocabulary consistently in code comments, tests, issue/PR text, and docs. - Do not invent synonyms. If you need a concept that is not in the glossary, note it explicitly in the issue or PR rather than using ad-hoc language.
- Do not rewrite
CONTEXT.mdas part of drive-by cleanup; propose focused updates tied to the approved issue scope. CONTEXT.mdis maintainer-owned. Contributors can propose additions via issue discussion, but final wording is the maintainer's call.
Example (correct)
A PR that adds a new query adapter should use the term Native Dispatch Adapter Module (from CONTEXT.md), not "native adapter," "query native handler," or any other variant.
ADRs
What they are
docs/adr/ contains Architecture Decision Records. Each ADR is a concise record of one accepted decision: the problem, the decision, and the consequences. Accepted ADRs are the current standard.
Currently accepted ADRs:
| File | Decision |
|---|---|
0001-dispatch-policy-module.md |
Dispatch Policy Module as the single seam for query execution outcomes |
0002-command-contract-validation-module.md |
Command Contract Validation Module / command contract centralization |
0003-model-catalog-module.md |
Model Catalog Module as the single source of truth for agent profiles and runtime tier defaults |
0004-worktree-workstream-seam-module.md |
Planning Workspace Module as single seam for worktree and workstream state |
0005-sdk-architecture-seam-map.md |
SDK Architecture seam map for query/runtime surfaces |
0006-planning-path-projection-module.md |
Planning Path Projection Module for SDK query handlers |
0007-sdk-package-seam-module.md |
SDK Package Seam Module owns SDK-to-gsd-core compatibility |
When an ADR is required
An ADR is required when a decision:
- Introduces or removes a Module seam that other code will depend on.
- Changes the policy contract of an existing accepted ADR.
- Establishes a new architectural invariant (naming convention, test contract, CI enforcement).
An ADR is optional (a comment in the relevant issue or PR is sufficient) when:
- The change is a bugfix that lands squarely within an existing accepted decision.
- The change is a docs or test improvement with no architectural surface.
Naming conventions
New ADRs and PRDs use issue#-prefix slug naming. This is a contributor requirement, not a suggestion.
docs/adr/<issue#>-<kebab-slug>.md (new ADRs)
docs/prd/<issue#>-<kebab-slug>.md (new PRDs)
Example: docs/adr/3485-adr-prd-naming-convention.md.
Why: GitHub issue numbers are server-assigned and atomic — the reservation mechanism already exists because the issue-first rule requires it. Promoting the issue# to the artifact ID eliminates the entire collision class that the NNNN-* local-compute scheme created (see the 0010-* × 2 and 0011-* × 3 duplicates on disk).
Migration policy: Legacy ADRs 0001-* through 0011-* keep their numbers as immutable historical record. The new convention applies to all ADRs and PRDs created on or after the merge of the implementing PR (#3485). Do not renumber legacy files.
For the end-to-end workflow — opening the issue, waiting for approval, creating the file, and submitting the PR — see CONTRIBUTING.md — "Proposing an ADR or PRD".
The legacy four-digit scheme (0003-model-catalog-module.md) applies only to pre-existing files.
Required sections
Every ADR must open with:
# <Title>
- **Status:** Accepted | Proposed | Deprecated
- **Date:** YYYY-MM-DD
Body: one-paragraph decision summary, then ## Decision (specifics), then ## Consequences (behavioral changes downstream callers can rely on).
Amendments are appended as ## Amendment (YYYY-MM-DD): <topic> sections — the original body is never rewritten.
Status block format
- **Status:** Accepted
- **Date:** 2026-05-09
Status values: Proposed (under discussion), Accepted (current standard), Deprecated (superseded — include a forward reference to the replacement).
Cross-reference style
Reference sibling ADRs by filename, not by title prose: see \0001-dispatch-policy-module.md``. This survives title edits.
ADR README index
docs/adr/README.md maintains the canonical index table and the naming convention documentation. The table in this document (above) covers accepted ADRs for contributor reference. If an ADR is added, update both tables in the same PR.
Governance
- ADR creation and final wording is maintainer-owned. Contributors must not open ADR files as part of a contribution PR.
- Contributors can — and should — give input on proposed ADR direction in the linked issue discussion.
- Once an ADR is
Accepted, reopening the decision must be explicit (a dedicated issue with rationale), not implied by a drive-by PR change. - If your PR intentionally revisits an accepted ADR decision, call it out explicitly in the issue and the PR body: "This revisits ADR-0002 because…"
AI-agent-assisted work
When AI assistance is appropriate
AI assistance is appropriate for every contribution type. The bar for correctness and review quality does not change because the code was AI-assisted.
Pre-work requirements
Before any AI agent writes a single line of code or docs, it must read:
CONTEXT.mdin full.- The ADRs relevant to the area being changed (check
docs/adr/). - The approved issue scope.
If you are dispatching an AI agent, include these reads in the agent's prompt explicitly. An agent that invents synonyms for CONTEXT.md vocabulary or contradicts an accepted ADR without flagging it has failed the pre-work requirement.
In the PR body, state which ADR or standards section was followed. If using an AI assistant, this statement is your responsibility as the author — not the agent's.
Worktree isolation
Agent-written code must use an isolated worktree to prevent branch pollution. The standard pattern:
git worktree add ../my-feature-worktree fix/NNNN-short-description
Never commit agent output directly to main or to an already-open feature branch without review.
Model selection
Sonnet for most tasks — implementation, test writing, docs, triage. Use the current Sonnet model unless the task requires deep reasoning over a large context.
Opus for architecture-level tasks — ADR authorship (maintainer only), cross-cutting refactors, adversarial review of complex PRs. Using a more capable model when a capable model suffices wastes context and delays the cycle.
General-purpose vs specialist agents: prefer the specialist agent for the domain (e.g. a TypeScript-aware agent for SDK surface changes, a docs-aware agent for contributor docs) over a general-purpose agent. Specialist agents load less irrelevant context.
TDD discipline
For any Behavior-Adding Task (see CONTEXT.md):
- RED — commit a failing test that names the expected behavior before writing the implementation.
- GREEN — write the minimum implementation that makes the test pass.
- REFACTOR — polish without changing behavior; tests must still pass.
Commit each phase separately. A PR that has no failing-test commit for a new behavior will be asked to add one before merge.
Adversarial review requirement
Before opening a PR:
- Read each changed section as if you are a hostile reviewer. Does it stand alone? Does it cite existing artefacts accurately? Is anything aspirational that is not actually current practice?
- Mark aspirational items as
[proposed]in the text if they describe future intent rather than current behavior. - Check that every cross-reference (file path, ADR number, CONTEXT.md term) resolves to something that actually exists on disk.
CR-loop discipline
After a reviewer thread is addressed:
- Fix the code or docs in a new commit (never amend a pushed commit).
- Resolve the thread via GraphQL mutation — do not rely on auto-resolve and do not post a reply comment:
gh api graphql -f query='mutation { resolveReviewThread(input:{threadId:"PRRT_..."}) { thread { isResolved } } }'
Address every reviewer finding claim-by-claim. Do not dismiss a thread because one sub-claim is a false positive — read all sub-claims before deciding.
Standards followed — block (proposed)
The maintainer is evaluating whether to require a ## Standards followed block in every issue and PR body. Current proposal:
- Enhancements and features: required. List the ADR(s) and CONTEXT.md section(s) consulted.
- Bug fixes: lighter-weight. A one-line note suffices: "Follows ADR-0002 command contract."
This is marked [proposed] — it is not yet a merge gate. Feedback on workflow impact is welcome in issue #3232.