Repository navigation
feat(client): versioned JSON output, validate --file, and associate/refs/parse/fold verbs (Phase 5 stage 2) - #326
Conversation
ec1b756 to
1ef3897
Compare
|
Recorded open after the audit: F4 — Note on F2: 🤖 Generated with Claude Code |
…se onto 9c2d9c4) Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…e verb The Go client gains the answers the Python client's last consumers read from its in-process objects, as a stable contract (`schema: 1`, documented in README.md → "Machine-readable output"), so packages.cairn can be retired (v1 plan Phase 5): - `recall --json`: the reader's report — status, exit, warning, scope, instance, cache_root, state, candidates, entries with sections keyed by heading. Same exit code and stderr warning as the text form; a refusal prints no document. - `validate --file PATH`: one draft, offline, judged by `write.CheckEntryBytes` — the predicate create/put run on the pod (loader parse + closed tag vocabulary) — then the write-protocol advisories. Exit 0 / 5 malformed / 2 unreadable. - `associate --scope S --paths-from FILE|- [--min-paths N] [--json]`: which entries a list of repo-relative paths names, through store.AssociatePaths (the matcher recall's focus window already uses). Go-only verb, ledger class `resolved`. - `routes --json`: every instance's cache root (via instanceCache, the read verbs' own resolver) and the scope->instance table (null when none). `--json --check` is refused. doctor --json is unchanged (the parity gate pins its bytes until Phase 5 removes it). Tests: internal/client/jsonout_test.go pins literal key sets and fixture values. Mutation sweep, 17 mutants over the four features, 17 killed, each by the test that names its feature (incl. M6: validate --file on the loader alone, no vocabulary — killed only by the off-vocabulary-tag case). Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…nswers scope-absent Audit round 1 findings (no 🔴; ladder ended): - F1: `validate --file` judged a draft under its OWN basename/directory while create uses NormalizeRef(--ref)+".md" and the folded scope, and ignored the 1 MiB body cap. New `--ref REF` derives (scope, filename) exactly as create does and refuses a scope/ref that is not a safe path component (the pod 400s those before reading the body); without `--ref` the path-based judgement stays. The body cap (write.MaxEntryBytes, which api.maxBodyBytes is now defined from) is checked in both modes. README/CHANGELOG/comment narrowed to what holds. Expectations measured against the real pod first: draft.md/widget-api 5->0 with --ref (create 201); widget-api.md/--ref other 0->5 (create 6 entry-shape); x.runbook.md/--ref x 5->0; --ref x.process -> 2 (create 400); >1 MiB -> 5 in both modes (create 400). - F2: `associate` on a scope the cache does not hold printed nothing and exited 2 like a usage error. It now answers recall's way: a document with `status: scope-absent` (new `status` field, `associated` otherwise), exit 0 — the same answer for "never existed" and "not visible". Text form: one `scope-absent\t<scope>` line. - F3: the text form prints `below-threshold` lines. - F5: CheckEntryBytes's doc comment no longer splits validateEntryBytes's from its func; the caller-ledger sentence names CheckEntryBytes. - F4 (recall --json omits some report fields) stays open, additive. Red at the previous head, green here: the three F1 tests and the two associate tests (TestValidateRefWithoutFileIsAUsageError passes at both — an invariant guard). Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…e reader's entry parse) Operator decision on devrc#3529: no local copies of cairn logic in devrc. Two generic read verbs so consumers ask the reader instead of re-implementing it (schema 1, README "Machine-readable output"): - `refs (--scope S | --all-scopes) [--json]`: every ref the cached entries make addressable, and every one `store.ResolveRefTiered` calls ambiguous (tier + candidate filenames). `refs_tried` is the denominator. `--all-scopes` counts each scope once, in the instance the routing table sends it to; a copy cached on another instance is listed in that instance's `not_routed_here`. - `parse --file PATH|- [--bullets] --json`: front matter, headings, sections and the nuance journal's bullets (start_line, date, openness, resolved_by, population, citation_id); `--bullets` parses any text as one journal body. Offline; not a well-formedness verdict. Both Go-only; ledgers updated (capability_ledger, want-go-only-verbs, read-ledger class probes). Tests: internal/client/parserefs_test.go — literal fixtures (alias-tier and filename-tier collisions, the alias-equals-another-slug non-collision, the routed instance count, all six populations). Mutation sweep 9/9 killed. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
9c2d9c4 to
b39c18a
Compare
…se onto 9c2d9c4) Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Audit round 0 — requirements & deletion (head
|
| # | requirement | author | devrc #3529 consumer (measured in its diff) |
|---|---|---|---|
| R1 | recall --json |
operator (retire oracle / use the client) | service_recon.py (recall --repo … --ref … --no-sync) |
| R2 | validate --file [--ref] |
operator | cairn-ops/write.sh create, subsystem_touch.run_validate |
| R3 | associate verb |
operator | subsystem_touch touch report (--paths-from - --min-paths N --json) |
| R4 | routes --json |
operator | cairn-ops / skills (routes --json → routes, instances[].cache_root) |
| R5 | refs (--scope, --all-scopes) |
operator ("client verbs" for ref questions) | subsystem_touch.census, subsystem-audit.py |
| R6 | parse (+ --bullets) |
operator ("client verbs" for entry parsing) | handoff_doc.durable_reason, census, subsystem_touch, subsystem-audit.py |
| R7 | schema: 1 contract + refuse-unknown-schema rule |
UNATTRIBUTED-UNKNOWN (agent design; consumer cairn_cli.KNOWN_SCHEMAS={1} honours it) |
— |
| R8 | text (non---json) renderings of associate / refs |
UNATTRIBUTED-UNKNOWN | none: every devrc call passes --json; skills name the verbs only |
| R9 | api.maxBodyBytes := write.MaxEntryBytes |
follows from R2 (same cap offline and on the pod) | — |
Requirement questioned (not a premise — the decision is already made): the "no local copies" ask is not fully served by this PR. devrc #3529 still carries scripts/lib/cairn_ref.py — a port of store.NormalizeRef and store.PathRefs — and labels it "the last local copy … pending a cairn verb". No verb in this PR folds an arbitrary string or path (the recorded Python reference's refs rows, 7 of them, have no verb to run against). Either this PR, or a named follow-up, owes that verb; the operator's decision already says which way.
Step 2 — delete
Examined every new verb/flag against devrc #3529's call sites: R1–R6 each have a consumer, so none is retired on question (a). Only:
- R8 has no consumer; it is small (a few
Fprintfloops, with tests) and gives an operator something to read at a terminal, so it is a candidate, not a recommendation.
Step 3 / 4
Simplify recommendation for the operator: /simplify over internal/client/{refs,parse,associate}.go. Accelerate note (devrc side, for awareness): census and durable_reason spawn one cairn parse subprocess per entry file / per bullet-shaped line; a multi-file parse would cut that, but nothing here should be accelerated before the fold-verb gap is settled.
Ledger: round 0 · requirements: 9 (unattributed: 0; UNATTRIBUTED-UNKNOWN: 2) · deletion candidates: 1
D1 — the text (non --json) renderings of `associate` and `refs`: no consumer in devrc #3529, every call passes --json
Audit round 1 — first full adversarial audit (head
|
…, scope-absent Round-1 follow-ups on #326 (ladder ended, 0 🔴; these are not re-audited): - F1: new Go-only verb `fold --file PATH|- --json`: the reader's ref fold for strings that are not an entry's. Input is ONE JSON array of strings (any string carried exactly; a null element or non-array is 2). Output `{schema: 1, verb: "fold", results: [{input, ref, path_refs: [{component, ref}]}]}` — `ref` is store.NormalizeRef, `path_refs` store.PathRefs, in input order. Lets a consumer delete its local copy of the fold. Ledgers: cli Verbs, capability_ledger, want-go-only-verbs, read-ledger class probe; README + CHANGELOG. - F2: `refs --all-scopes` no longer files a cached scope with NO route under `not_routed_here` at exit 0. It goes in the instance's new `unrouted` list, is named on stderr, and the run exits 11 (recall's refusal for the same scope); the document is still printed. - F3: an instance whose cache cannot be read no longer aborts `refs --all-scopes` with empty stdout. As `search --all-scopes` does: the answered instances are printed, the unread ones are named in the new top-level `unread_instances` and a `PARTIAL` stderr line, exit 3 (the unread state's code — search's, not a new code). Exit is the highest that applies. - F4: `refs --scope S` on a scope the cache does not hold answers `status: scope-absent` exit 0 (new top-level `status`, `answered` otherwise), like recall/associate; text form prints `scope-absent\t<scope>`. - F5: every level of the `refs` document's key set is pinned literally. - F6: `parse` bounds its read by write.MaxEntryBytes, not a private 1 MiB copy. Red at b39c18a, green here: TestRefsOnAScopeTheCacheDoesNotHoldAnswersScopeAbsent (exit 2), TestRefsAllScopesIsLoudAboutAnUnroutedScope (exit 0, want 11), TestRefsAllScopesPrintsAPartialAnswerWhenAnInstanceIsUnread (empty stdout), TestRefsDocumentFieldNamesArePinned, TestFoldIsTheReadersRefFold, TestFoldRefusesAnythingButAJSONArrayOfStrings. TestParseCapIsTheStoresBodyCap is an INVARIANT guard (green at both: the private constant had the same value). Fold expectations are literal: the 7 folding rows of a consumer's oracle-produced fixture, and path_refs rows produced by that consumer's own Python copy. Mutation sweep 23/24 killed, each by the guard's own test; the survivor (LimitReader bound doubled in parse) is equivalent — the length check still refuses at MaxEntryBytes+1. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Stage 2 of the Python-oracle retirement (v1 plan Phase 5): give the Go client the answers devrc's last Python-lib consumers read, as a versioned JSON contract (
schema: 1, README → Machine-readable output). Operator rule behind B5–B7: devrc keeps no local copies of cairn logic, so every question it used to answer itself is a verb here.recall --jsonservice_recon.py(/analyze-service)validate --file PATH [--ref R]— offline, viawrite.CheckEntryBytes(the pod's create/put predicate) and the store's body capsubsystem_touch.py --validate <draft>associate --scope S --paths-from FILE|- [--min-paths N] [--json]overstore.AssociatePathssubsystem_touch.py's touch reportroutes --json— each instance's cache root + the tablecairn-ops/health.sh(replaces banner scraping)refs (--scope S | --all-scopes) [--json]— every ref the cached entries make addressable, and every onestore.ResolveRefTieredcalls ambiguous.--all-scopescounts each scope once, in its routed instance; a cached scope with no route is listed underunroutedand exits 11; an instance whose cache is unreadable is a PARTIAL answer (unread_instances, exit 3, assearch --all-scopes); a--scopethe cache does not hold isstatus: scope-absent, exit 0parse --file PATH|- [--bullets] --json— the reader's parse of an entry (front matter, headings, sections, journal bullets)cairn_entry.py)fold --file PATH|- --json— input one JSON array of strings; outputresults: [{input, ref, path_refs: [{component, ref}]}]=store.NormalizeRef/store.PathRefsscripts/lib/cairn_ref.py(the last local copy)doctor --jsonis deliberately untouched: the parity gate pins its bytes until Stage 4 deletes that gate.Evidence
internal/client/jsonout_test.go(B1–B4: literal key sets, fixture-chosen values, exit-code equality with the text form, refusal ⇒ empty stdout) andinternal/client/parserefs_test.go(B5–B7: literal collision fixtures, every level of therefskey set pinned, the two-instance unrouted and partial cases, the 7 fold rows of devrc's oracle-produced fixture pluspath_refsrows from devrc's own copy).parse's read bound doubled while the length check still refuses atMaxEntryBytes+1).associate,refs,parse,foldincapability_ledger(go_only),want-go-only-verbs.txt, and the read-ledger class probes (+recall --json/routes --jsonprobes).go test ./internal/client ./internal/write ./internal/store(+./internal/reportin earlier rounds),tests/test_capability_ledger.py,tests/test_go_client_ledgers.py, leakscan + self-test. The whole suite is CI's.Audits: round 0 #326 (comment), round 1 (ladder ended, no 🔴) #326 (comment). Round-1 follow-ups (510f6d2) are not re-audited; round-0 D1 (keep text renderings) deliberately skipped.
🤖 Generated with Claude Code