Repository navigation
Description
Code references are at 98e1ea8a5. Decisions are from #935's grilling of 2026-12-02 (resolution). Building waits on #935's return trigger (#936 closes or 2027-01-15) and on #1056 (Run cost), whose cost estimate it uses.
Problem Statement
First map drafts a repository's names, captions and purposes, and the computed import links. Its writer is told "Don't write held items, links or laws" (server/src/map_draft.rs:2045), and Write builds the accepted map with laws: [] (map_draft.rs:1762-1768; docs/studio/behaviour/map.md:302). So a First map gives Back a law nothing to back, the plan view nothing under "the laws on those parts", and fog no thick layer from laws until someone writes them by hand.
#753 left depth to a later spec that adds to an accepted map and never redrafts it (#753, Out of Scope, Q5). Depth is also where the drafting model errs: in the 2026-11-27 chery re-run all 6 errors were held items or link reasons, none in 30 purposes and captions (#935's 2026-11-30 decision). This spec takes the one layer of depth that is fewest, easiest to check, and has its own safety net in Back a law: laws.
Solution
Right after a First map is accepted, plotkeeper drafts laws for it, as the follow-on step of Draft the map: 0–3 per part and 0–1 per import link, each citing the code that makes it true, all on trust. A Draft laws button on a part's sheet drafts more for one part, on any map. Drafted laws reach the map the way the map lives: a committed map gets one draft PR per fill, whose brief offers each law as a Ratify item once Daniel marks it ready; a map that is only the checkout file gets the Law draft panel, where Daniel keeps, edits or drops each law before it is written. A trial on two repositories picks the cheapest model that drafts at most 1 false law in 10.
User Stories
Drafting
- As Daniel, Draft the map's button says it drafts laws too, with its time and cost estimate (Studio: Run cost — what a background run takes from your plan, before and after #1056) covering them, so pressing it is my consent to both.
- As Daniel, once I accept a First map, its laws are drafted without another click, on every part whatever its tier.
- As Daniel, a part gets 0 to 3 laws and an import link 0 or 1, and a part or link with nothing worth stating gets none, so I never read filler like "the server serves the page".
- As Daniel, each drafted law is one plain sentence that must stay true, and cites the files that make it true, so I can check it.
- As Daniel, every drafted law is on trust, and none starts Back a law by itself; each keeps its Back a law button.
- As Daniel, a part's sheet has Draft laws, with its cost estimate, on any map, First map's or hand-written, so I can ask for laws on one part.
- As Daniel, Draft laws on a part that already has laws only adds: the writer sees the existing ones, skips what they already say, and never edits or removes one.
On a map that is only the checkout file
- As Daniel, the after-Accept laws arrive in one Law draft panel, in the Map draft panel's look, with one row per part and each link's laws under its "from" part.
- As Daniel, each law has Keep, Edit and Drop, and the panel has Keep all, so trusting 20 of 22 laws is three clicks, not twenty.
- As Daniel, a law I have not decided stays in the Law draft until I decide it, with no expiry, and only kept laws are written to
system-map.json. - As Daniel, a law reached me only after First map's reviewer checked it against the code, and one it flagged says why.
- As Daniel, a one-part Draft laws on such a map shows its laws in that part's sheet with the same Keep, Edit and Drop.
On a committed map
- As Daniel, the fill opens one draft PR with every drafted law, whether it was the after-Accept batch or one part's Draft laws.
- As Daniel, once I mark that PR ready, its brief offers each law as a Ratify item and Map text review checks each law's text against the code, so I accept or overturn them where I already review map changes.
On a map waiting in its own draft PR
- As Daniel, when I accepted through Open a draft PR, laws wait until that PR merges, then are drafted and open their own draft PR, so nothing is drafted for a map I might still discard.
Without Claude
- As a user without Claude, First map's copy-prompt asks my agent for laws by the same rules, all on trust, so my map gets them too.
Implementation Decisions
When a fill starts (Q3, Q8)
- After Write: the fill starts when Write succeeds. After Open a draft PR: the fill starts once
MapDrafts::followhas seen the PRMERGEDafter a passed fetch and deleted the pending copy, so the default branch's map has taken over (map_draft.rs:1244-1254;map.md, "Following the PR"). AMERGEDseen before a passed fetch starts nothing yet, and the fill starts once per merged PR. A CLOSED PR starts nothing. - A one-part fill starts on Draft laws.
docs/studio/behaviour/background-runs.md:3and:88, and Background run indocs/studio/CONTEXT.md:386, say a run starts only on a click, but for the map text review of Daniel's own PR. The after-Accept fill becomes the second exception, covered by Draft the map's click, and all three say so. Nothing starts a fill on a timer.
The run
- A new run kind,
law-draft, with First map's tools (Read,Glob,Grep,docs/studio/behaviour/background-runs.md:9), so Run cost (Studio: Run cost — what a background run takes from your plan, before and after #1056) estimates it apart from First map. It answers in its result, as First map's runs do. - The writer is given the accepted map (parts, purposes, paths, links, existing laws) and asked for laws as JSON: per law its target (
part:<id>orlink:<id>), its sentence, and the files it rests on. The prompt carries the caps (0–3 per part, 0–1 per import link, zero allowed), the rule that a law needs evidence in code (a guard, a lock, one entry point, shared types), and, for a one-part fill, the part's existing laws to skip. - Writer groups follow First map's: up to 4 in parallel, by part group (
docs/studio/behaviour/background-runs.md:143;server/src/map_draft.rs:44-47). - Code checks every answer before it is kept: target exists; sentence non-empty and at most 140 characters (the map's shape caps no law text; 140 is the held item's and link reason's cap,
map.md:16,21); caps per target; each cited file is tracked and owned by the target part (for a link, by either end). A law that fails is dropped and counted, never shown. - Law ids are the target's id and a short slug of the sentence, cut so the whole id, with any
-2,-3that makes it unique against the map, is at most 40 characters and a valid id. Map text review skips any item whose id is longer (MAX_ID,server/src/map_review.rs:288-294). - Checkout path: First map's reviewer, scoped to laws, checks each law against its cited files before the Law draft shows it. Its input today is item ids and the map file (
server/src/map_review.rs:556-612), and a map law has no citations field, so the law-draft reviewer is given each law's sentence with its cited files in its prompt; a flagged law shows with its flag and stays droppable. PR path: no reviewer run; Map text review does that job once the PR is ready (docs/studio/behaviour/background-runs.md:132).
The model (Q19)
- A trial before the build drafts laws for chery
124ebdband observability-sdk7894bdf(the 2026-11-27 trial's commits) with Haiku, Sonnet and Opus, and Daniel judges each law by hand as true, false or filler. The cheapest model with at most 1 false law in 10 becomes the default; filler counts against it only when it exceeds 1 in 5. The trial's numbers go todocs/studio/research/law-draft.md. - The model is a constant in the code with that doc as its source. The runner passes only
backgroundRuns.modeltoday (server/src/runner.rs:206-207,1477), so a run request gains an optional model: a law-draft run passes the trial's constant, andbackgroundRuns.model, when set, still wins.background-runs.mdandsettings.mdsay so.
Delivery (Q4, Q8, Q11, Q12, Q15)
- Which route: decided when the fill's answers are kept, by where the map is read from (
map.md:334): the default branch → PR; the checkout file → Law draft. A map pending in plotkeeper's own draft PR never gets a fill until it merges. - PR route: reuses Back a law's draft-PR flow (
back_a_law::open_draft,server/src/back_a_law.rs:1054), as Open a draft PR does: a temporary worktree of the default branch, branchlaw-draft/<id>, the map with the laws added,system-map checkpassing, a commit with Daniel's git identity,gh pr create --draft. The brief is written once the PR is ready (docs/studio/behaviour/pr-briefs.md:9: a PR is ready when open and not a draft;gh pr listlists hand-made PRs too,server/src/prs.rs:253), and Ratify and Map text review follow from there. - Law draft: kept by plotkeeper in the data folder per project, like the Map draft, never in the repository, with a hash of the checkout map it was drafted on. Keep and Keep all update that readable map, which Write never does (Write refuses a readable map,
server/src/map_draft.rs:1889-1954): read the file, add the kept laws, runcheck_text, and replace it by a temporary file and rename only while it still holds what was read; never through a symbolic link. If the file changed since the Law draft was made, a law whose target is gone is dropped and counted, and the rest are added. If by then the map reads from the default branch (someone committed and merged it), Keep opens a draft PR with the kept laws instead, and says so. - Dropping a law removes it from the Law draft. Edit changes only its sentence; code checks the edited sentence as it checks an answer.
The copy-prompt (Q22)
- The copy-prompt for another agent (
scanPrompt,ui/map-model.ts:362-373) gains the laws rules: caps, evidence,"backing": "trust", ids, and thatnpx plotkeeper map checkmust still pass.
Glossary and docs
docs/studio/CONTEXT.mdgains Law draft ("the laws plotkeeper drafted for a map's parts and links, kept by plotkeeper until Daniel keeps or drops each; only kept laws reach the map") and Run-time link if Studio: Run cost — what a background run takes from your plan, before and after #1056 has not added it.docs/studio/behaviour/map.mdgains the fill, the Law draft panel and the two routes beside "Accepting";docs/studio/behaviour/background-runs.mdgains thelaw-draftkind and the second automatic start.system-map.json: the new module on its part (the research doc is underdocs/, which the map ignores).
Testing Decisions
- The answer check: one table test in Rust over writer answers: unknown target, over the caps, blank or over-long sentence, cited file untracked or owned by another part, a link law citing either end, a duplicate of an existing law, and a clean answer.
- Law ids: a table test of the law-id function: collision with a part, a link and an earlier law, a long sentence cut to 40 characters, and characters an id may not hold.
- The route: a table test of the route decision over map sources (default branch, checkout file, pending draft PR, pending PR merged, closed).
- Keep's write: a table test of Keep over the checkout map: unchanged, changed since (a target gone), a symbolic link, a file that no longer reads, and the map now read from the default branch (opens a PR).
- The fill's start: a test with
studio_test_support::fakeas the harness (AGENTS.md, Tests): Write starts one fill; aMERGEDfollow after a passed fetch starts one, before it none, twice still one; a CLOSED one none. - The page: snap fixtures for the Law draft panel (undecided, flagged, kept), the part sheet's Draft laws with its estimate and its one-part laws, and Draft the map's button text.
- Not tested by code: whether a law is true. The trial measures that, and the reviewer or Map text review checks each one in use.
Out of Scope
- Held items and run-time links: later specs (Q2).
- Laws on flows: First map drafts no flows.
- Backing laws automatically (Q7).
- Replacing or editing existing laws (Q14).
- Any change to how the First map itself is drafted, beyond Draft the map's button text.
Further Notes
- The Run cost figure (Studio: Run cost — what a background run takes from your plan, before and after #1056) is the only cost UI; this spec adds none of its own.
Made without Daniel
- A new run kind
law-draft(set aside: reusingfirst-map, which would mix their costs in Studio: Run cost — what a background run takes from your plan, before and after #1056's estimates). - Code drops a law that fails the answer check silently except for a count (set aside: showing invalid laws, which only adds noise).
- The checkout path's reviewer runs before the Law draft shows; the PR path relies on Map text review (set aside: both, which doubles the spend).
- The trial's error bar counts filler apart from false laws, at 1 in 5 (set aside: counting filler as false).
- The model is a code constant from the trial, overridable by
backgroundRuns.model(set aside: a new setting). - If the map moved to the default branch before Keep, Keep opens a draft PR (set aside: writing the checkout file anyway, which would stay invisible until merged).
- Law text is capped at 140 characters by the answer check (set aside: no cap, or adding a cap to the map's shape, which would change
system-map checkfor every map).
Activity