diff --git a/.claude/audits/2026-10-22-rust-r5-draft-security.md b/.claude/audits/2026-10-22-rust-r5-draft-security.md new file mode 100644 index 00000000..bd88f286 --- /dev/null +++ b/.claude/audits/2026-10-22-rust-r5-draft-security.md @@ -0,0 +1,157 @@ +# Security gate: Rust R5.3 draft pipeline (2026-10-22) + +Mode: audit (delta list). Branch `feature/rust-r5-pipeline-core`, uncommitted working tree. +Scope: the R5.3 change set (8 modified files, 17 new files), read whole; `--check` run once +(read-only, exit 0, seed folder unchanged). No code was edited. + +``` +SECURITY — VERDICT: PASS +TOOL: semgrep 1.168.0 — p/security-audit, p/secrets, p/owasp-top-ten +SCOPE: 25 files +BLOCKING: + (none) +REPORTED (non-blocking): + - [LOW] symlink check covers the final component only — crates/core/src/bin/import_equine.rs:182-203 + - [LOW] check-then-write is not atomic (TOCTOU) — crates/core/src/bin/import_equine.rs:213-228 + - [LOW] serde_json::Map indexed with [] (panics on a missing key) — crates/core/src/bin/import_equine.rs:111 + - [LOW] INIT_CWD trusted from the environment — crates/core/src/bin/import_equine.rs:206-211 + - [LOW] seed SQL assembled by string formatting — crates/core/src/curation/draft/seed.rs:28-29,91-101 + - [LOW] new test file carries the suite's clippy allow line (convention, not a scanner suppression) — crates/core/tests/curation_draft.rs:7 + - [MEDIUM] guardrails SB-POLICY-NOT-OWNER, outside the R5.3 delta, pre-existing — supabase/migrations/20261008110000_anatomical_sheets.sql:1177 +PROOF: semgrep 725 rules on 25 files → 0 findings; checklist 9 checks → 6 findings (all LOW); guardrails scan.py --domain api,supabase → 0 FAIL, 1 WARN (out of delta), 1 MANUAL; anti-gaming → 0 new un-gated suppressions +``` + +## Files scanned (25) + +Modified: `crates/core/src/bin/import_equine.rs`, `crates/core/src/curation/mod.rs`, +`crates/core/Cargo.toml`, `package.json`, `CLAUDE.md`, `CHANGELOG.md`, +`docs/development/RUST.md`, `.claude/tasks/TODO.md`. +New: `crates/core/src/curation/draft/{mod,schema,targets,fields,ops,rename,apply,records,migration_map,pipeline,seed,stats}.rs`, +`crates/core/tests/curation_draft.rs`, `crates/core/tests/oracles/r5/curation-synthetic.json`, +`packages/anatomy/tests/r5.curation-synthetic-oracles.test.ts`, `scripts/import-equine.sh`, +`.claude/tasks/contracts/2026-10-22-rust-r5-draft.md`. + +## Findings in detail + +### 1. [LOW] Symlink check covers the final component only + +`crates/core/src/bin/import_equine.rs:182-203`. `writable_destination` calls +`fs::symlink_metadata(out)` and refuses when `out` itself is a symbolic link. An ancestor +of `out` that is a symlink is not resolved: `--out /link/new` with +`link -> ` creates `new/legacy-import` and `new/draft` under the real target of +`link`, and the success line prints the typed path. Because the destination must be absent +or an empty folder, nothing existing can be overwritten or deleted; the effect is new files +in a folder other than the one typed. Fix direction: `fs::canonicalize` the nearest existing +ancestor of `out` and refuse when it differs from the typed ancestor, or at least print the +canonical destination in the success line. + +### 2. [LOW] Check-then-write is not atomic + +`crates/core/src/bin/import_equine.rs:213-228`. `write` validates with +`writable_destination`, then runs `fs::create_dir_all` and `fs::write` per file. A process +that swaps `out` (or a created subfolder) for a symbolic link between the check and the +writes would have the writes follow it. A development tool on the owner's machine has no +such adversary; reported for completeness since the brief names TOCTOU. Fix direction: +when `out` is absent, claim it with `fs::create_dir(out)` (fails if something appears) and +re-run `symlink_metadata` on the result before writing; a `std::fs::DirBuilder` without +`recursive` for the two folder levels achieves the same. + +### 3. [LOW] `serde_json::Map` indexed with `[]` + +`crates/core/src/bin/import_equine.rs:111`: +`result.view_boxes[HEAD_VIEW_ID].as_str()`. `Index` on `serde_json::Map` panics on a +missing key (unlike `Index` on `Value`). The legacy importer inserts both `main` and +`head` unconditionally (`crates/core/src/curation/legacy/importer.rs:365-370`), so the +panic is unreachable today; the same pattern was replaced by `get` in commit 6afc1e0 after +a previous gate. Same line in `crates/core/tests/curation_draft.rs:72` (test code, allowed). +Fix direction: `result.view_boxes.get(HEAD_VIEW_ID).and_then(Value::as_str)` with a +typed error. + +### 4. [LOW] `INIT_CWD` trusted from the environment + +`crates/core/src/bin/import_equine.rs:206-211`. `base_dir` takes `INIT_CWD` as the base +of a relative `--out` without checking it is absolute or exists. pnpm sets it to the +invocation folder, which is the intent; a stale or foreign value exported in the shell +silently retargets a relative `--out`. Mitigations already present: the destination must +be absent or empty, the resolved path is printed, an absolute `--out` ignores the base +(`PathBuf::join` replaces it). Fix direction: accept `INIT_CWD` only when absolute, else +fall back to `current_dir`. + +### 5. [LOW] Seed SQL assembled by string formatting + +`crates/core/src/curation/draft/seed.rs:28-29` (`sql_text`, doubles single quotes) and +`:91-101` (`document_literal`, dollar-quoted with the tag collision refused). The checklist +flags SQL built by concatenation; here the output is a committed seed file reviewed by diff +and run by `supabase db reset`, not a runtime query. Every interpolated value is derived by +the pipeline: the uuid sheet id, the sha256 hex and byte size of the frozen asset, the +constant file name, the constant change note, and the Prettier-formatted document inside +`$equine_doc$ ... $equine_doc$`. No request or user-typed value reaches it. Parity with +`packages/anatomy/src/curation/seed.ts`. Not a parameterization case; listed so it is not +silently dropped. + +### 6. [LOW] Clippy allow line in the new test file + +`crates/core/tests/curation_draft.rs:7`: +`#![allow(clippy::disallowed_methods, clippy::unwrap_used, clippy::expect_used)]`. A new +file, so new to the tree, but the identical line heads all 31 committed +`crates/core/tests/*.rs` files and `crates/clippy.toml` states the rule ("tests and the +worker binary allow these lints locally where they own I/O"). Test code, not a security +scanner suppression. The binary's pre-existing `#![allow(clippy::disallowed_methods)]` +(`import_equine.rs:15`) is an unchanged context line and the documented exception for the +two files allowed `std::fs`. + +### 7. [MEDIUM, outside the delta] Guardrails `SB-POLICY-NOT-OWNER` + +`supabase/migrations/20261008110000_anatomical_sheets.sql:1177`, policy +`species_select_active` on `species` not tied to `auth.uid()`. The scanner runs on the +project root; this file is not part of the R5.3 change set and the policy predates it. +`species` is shared reference data, so an owner scope is likely not the intent; confirm and +record the exception rather than leave it to be re-flagged. `SB-RLS-LIVE` is MANUAL (not +reported here). + +## Considered, no finding + +- Non-ASCII slicing: `targets.rs:121` slices at `find(':')` and `migration_map.rs:68` at + `rfind('/')`, both ASCII bytes and therefore char boundaries; `migration_map.rs:55-59` + (`strip`) works on UTF-16 units with `from_utf16_lossy`; `schema.rs:319` uses + `strip_prefix`; `fields.rs:84` splits on `'.'`. +- Indexing on parsed JSON in library code: `targets.rs:250,252,253,282,415` read + `ids[0]`, `ids[1]`, `ids[2..]` after `parse_target` guarantees one id (collections) or at + least two (findings); `fields.rs:92` reads `[0]` of a `split('.')` that always yields one + element; `pipeline.rs:81-84` reads four numbers after `len() != 4` is refused; + `migration_map.rs:185` is a slice pattern; `ops.rs:277,304,309,259` remove/insert at + indices produced from the same list moments before (`insertion_index` refuses + `index > len`, `u64 -> usize` saturates). No `unwrap`, `expect`, `panic!`, `unreachable!`, + `unsafe` or `Map[...]` in `crates/core/src/curation/draft/*`. +- Panics from a hand-written `changes.json` / `references.json`: both parsed with strict + serde (`deny_unknown_fields`), custom validators return errors; every op failure refuses + the whole changeset with the change id and op index (`apply.rs:103-109`); the final strict + parse into `AnatomicalSheetDocument` and `validate_sheet_document` refuse shape and + integrity errors (`apply.rs:128-144`); `CHG-000` reserved id refused (`pipeline.rs:127`). + Recursion in `walk`, `touch_tree`, `strip_marks` is bounded by document depth (serde_json + caps parsed nesting at 128; only repeated authored `add`s could deepen it; a stack overflow + would abort a developer tool, nothing more). +- `--check` is read-only: `fs::read`, `fs::read_dir`, `println!`/`eprintln!` only. + Ran once from `crates/core` on the native toolchain: exit 0, + `legacy-import: 6 files, 0 differences`, `draft: 6 files, 0 differences`, six R5.4 files + listed as pending; `git status` shows the seed folder untouched. +- `--out` never deletes: no `remove_*` call in the binary; refuses an empty path, a + symbolic link, a non-folder, a non-empty folder; file names come from constants and the + render functions (no `..`); parents created with `create_dir_all`. +- `scripts/import-equine.sh`: `set -euo pipefail`, `"$@"` quoted, `cargo run --locked`; + `scripts/rust-env.sh` only appends an absolute `$CARGO_HOME/bin` when `cargo` is absent. +- TypeScript generator `packages/anatomy/tests/r5.curation-synthetic-oracles.test.ts`: + writes only `crates/core/tests/oracles/r5/curation-synthetic.json` + (`OUT = resolve(HERE, '../../../crates/core/tests/oracles/r5')`), and only under + `MAKE_R5_ORACLES=1`; otherwise it reads and compares. +- Secrets: none in the change set; no tracked `.env` or credential file; the seed SQL + carries no credential (`creator_user_id null`, `visibility 'private'`). +- Logging: stderr lines carry paths of the developer's own repository; a CLI for the + developer, not an end-user surface. +- Semgrep: 0 results, 0 errors, 0 skipped paths across the three pinned packs + (725 code rules loaded; Rust coverage in these packs is thin, so the manual checklist + carries the weight for `crates/`). +- Observation outside the change set: `.claude/tasks/plans/2026-10-22-rust-r5-pipeline-core.md` + appeared as modified (1 line) during the audit; not produced by `--check` (no write path). + +REPORT_WRITTEN: /home/bchanot/Documents/faunosteo/.claude/audits/2026-10-22-rust-r5-draft-security.md diff --git a/.claude/audits/2026-10-22-rust-r5-draft-verify.md b/.claude/audits/2026-10-22-rust-r5-draft-verify.md new file mode 100644 index 00000000..9186f0ac --- /dev/null +++ b/.claude/audits/2026-10-22-rust-r5-draft-verify.md @@ -0,0 +1,35 @@ +# Verification: Rust R5.3 draft pipeline (2026-10-22) + +Contract `.claude/tasks/contracts/2026-10-22-rust-r5-draft.md`. Fresh verifier, report-only (persisted by the orchestrator: the agent has no write tool). + +## Pass 1: ECARTS(1) + +- C1 to C12 MET, each with code references and proofs run by the verifier: `cargo test --features curation --test curation_draft` 6/6, `curation_legacy` 5/5, the whole crate with `--features curation --locked` 22 suites green, clippy `-D warnings` clean, fmt clean, `import-equine --check` 12 files 0 differences (git status unchanged), `--out` into a `mktemp -d` folder then `diff -r` (legacy identical; draft identical but the three R5.4 entries), produced `document_sha256` = `27c7383c…2660` = sha256 of the produced `document.json`, 8 refusal and success probes of `--out`, anatomy 142/142, domain 262/262, `tsc --noEmit` clean. +- C13 partial by design: `pnpm check:all` and the security gate were the orchestrator's (both green / PASS); docs present (RUST.md §11.12 and §11.13, CHANGELOG, CLAUDE.md). +- Gap: the floor scan flagged the plan heading of §B.3.5 (`.claude/tasks/plans/2026-10-22-rust-r5-pipeline-core.md:94`, pre-existing at HEAD, R5.1), whose status words read as an unfinished marker. Resolved: heading reworded to "(approved at A.5, applied at R5.6)", the status BDR-068 records. +- Semantic fidelity (beyond the declared `set` without `value`): no reachable divergence. Four unreachable ones: (1) `id_text` printed a non-string id as JSON text; aligned on `js_string` (`String()`); (2) `trimEnd` stripped U+0085; aligned on the core's exact JavaScript white-space set (`is_js_space`); (3) an added item with a `null` child: TypeScript throws at the op, Rust refuses at the shape gate (both refuse; kept, declared in RUST.md §11.12); (4) a position beyond 2^64: both refuse "out of range", the printed number differs (kept, declared). +- Reproduced quirks: `strip` slices eight UTF-16 units of `op.to`; `apply_record` reads `record.op` whatever the record target (declared observation, RUST.md §11.12). + +## Pass 2: ECARTS(3) + +- C1, C3 to C12 MET (proofs rerun: fmt, clippy, curation_draft 6 + curation_legacy 5, `--check` 12 files 0 differences, 11 `--out` probes incl. a symlinked parent printing the canonical path and a dangling symlink refused, `diff -r`, anatomy 142, domain 262). +- C2 NOT MET: JSON `null` on the optional `scope` (set, cite), `position` (add, move) and `field` (add) parsed as absent by serde; Zod `.optional()` refused it. Not reached by the committed changeset. C13 NOT MET on the same root (undeclared). Fixed: those fields deserialised through `js::present` (absent accepted, `null` refused); three refused synthetic cases `schema-null-{scope,position,field}` added to the generator (58 cases: 9 compared, 49 refused alike). +- Floor: the pass 1 record above quoted the flagged words; reworded. +- Fidelity details, outcome-identical: re-homing candidates on a `Vec` where TS used a `Set` (aligned: deduplicated); `annotation_names` reads a non-string name as empty, duplicate ids first-wins (kept: the legacy import writes strings and unique ids); unlisted counter keys keep insertion order (kept: enum strings); `parseViewBox` error quoting (kept: both refuse). +- Doc line count corrected (2,689). + +## Pass 3: ECARTS(4) (first attempt stopped by an API credit error before any check; rerun on Opus) + +- C1, C4 to C10, C12 MET (fmt, clippy, curation_draft 6 + curation_legacy 5, `--check` 12/0, `--out` + `diff -r`, anatomy 142, floor clean, a TypeScript probe of 14 changesets and 2 references files). +- C2: three accept/refuse splits at parse, undeclared: (a) a repeated key outside `ops` refused by serde's derive where `JSON.parse` keeps the last value; (d) a lone surrogate escape; (e) nesting deeper than 128. Fixed (a): both files parsed through `js::parse_json` then read into the typed shape (test `a_repeated_key_keeps_its_last_value_as_json_parse_does`); declared (d), (e) in RUST.md §11.12. +- C3: (b) a field path ending in `__proto__`: TypeScript swallowed the write, Rust refuses at the gate: declared. (c) an authored `"\u0000touched"` key: TypeScript refused at the gate, Rust took it for a touch mark and the cleanup dropped it silently: a defect, fixed by refusing any NUL-prefixed key in the changeset at parse (test `a_reserved_touch_mark_key_in_an_authored_value_is_refused`). +- C11: `--out /` (trailing slash) followed the link into an empty folder: fixed, the destination is rebuilt from its components before the symlink check (probed: `alink/` and `alink//` refused, rc 2, target left empty). +- C13: the splits above undeclared, and §11.13 claimed a leftover mark would be refused by the gate while the cleanup removed it: both corrected. +- The verifier asked the orchestrator to run a probe harness it had written in the scratchpad (its own run was refused by the permission layer); not run: the cases are covered by the tests above and the declared table. + +## Pass 4: ECARTS(1), on C13 only + +- C1 to C12 MET (fmt, clippy, curation_draft 8 + curation_legacy 5, `--check` 12/0, `--out` + `diff -r`, refusal probes incl. `symlink/` and `symlink/.` rc 2, `pnpm r5:import-equine --check` rc 0, anatomy 142, floor clean). +- C13: undeclared (a) invalid UTF-8 in changes.json / references.json: TS lossy, Rust refused. Fixed: `read_text` lossy, as R5.2 kept for the catalog. Declared: (b) `1e400` in a discarded value, (c) an inherited `Object.prototype` member in a field path; corrected (c') the NUL-key row, (d) test and line counts (8 tests, 2,718 lines). +- Notes kept: synthetic refusals assert `is_err` only (the contract asks no reason); `scripts/import-equine.sh` called directly without INIT_CWD resolves a relative `--out` from the repository root (pnpm sets INIT_CWD). +- Not re-verified by a fresh verifier after these corrections (docs plus the one-line lossy read); `pnpm check:all` rerun green on the final code (00:10:03), `--check` 12 files 0 differences. diff --git a/.claude/memory/journal.md b/.claude/memory/journal.md index 4f562a63..b4f35fd9 100644 --- a/.claude/memory/journal.md +++ b/.claude/memory/journal.md @@ -326,3 +326,7 @@ Owner: R4 bilan validated, R5.1 authorised (freeze TS pipeline, study D-R5, stop ## 2026-10-22 (R5.1b F1 fix, R5.2 legacy importer in Rust) Owner validated R5.1, decided D-R5 = B `sha256-rfc8785-validated-v1` + aliases, F1 go, byte-exact port, frozen SVG bytes, ureq at R5.5 → BDR-068. R5.1b aed6b1e: `js_number` digits from `zmij` (edge only, no new crate), V8 oracle 44,322 rows (1,552 mismatches before → 0), `zod_oracle` now checks oracle bytes (red on old printer), rust:check + wasm + check green, no oracle/golden/digest moved. R5.2 03bdb5e: `crates/core/src/curation` (feature `curation`, 3,187 lines: Prettier string width table transcribed, JSON layout rules, table alignment, slugify via icu_normalizer NFD, uuids, legacy importer, IMPORT-REPORT) + `import-equine --check|--out`; legacy-import/ byte-exact (6 files), pipeline.json legacy parts equal, 10 synthetic TS cases, 968 Prettier probes; declared refusals: emoji width, malformed SVG, wrong-typed catalog nodes. Docs 82f1664 (RUST.md §11.9-11.11, CHANGELOG), contract `2026-10-22-rust-r5-f1-importer.md`. Gates: check:all green 21:16:39, security PASS (5 LOW, report Map-index panic fixed), verifier CONFORME 12/12 → EVAL-027. STOP after R5.2 checkpoint. + +## 2026-10-22/23 (R5.3 curated draft in Rust) + +Owner validated R5.1b/R5.2, go R5.3, named `pnpm r5:import-equine`. e0f149b: `crates/core/src/curation/draft` (2,718 lines: schema, targets, fields, records, ops, rename, apply, migration_map, stats, seed, pipeline) + `import-equine` both folders + `scripts/import-equine.sh`; draft 5 texts + frozen horse.svg byte-exact (`--check` 12/0), 825 records, 46 changes, stats, migration stats 792/571/180/7/34, 612 leaves 442/141/29, 58 synthetic TS cases (`oracles/r5/curation-synthetic.json`, 9 byte-exact, 49 refused alike). Security PASS (6 LOW, 3 fixed). Verifier 4 passes: found null-on-optional, repeated keys, NUL touch-mark drop, symlink trailing slash, lossy UTF-8; all fixed or declared (RUST.md §11.12); pass 4 C1-C12 met, C13 doc gaps fixed after, not re-verified. check:all green 00:10:03. documentSha256 unchanged. STOP at R5.3 checkpoint; R5.4 on owner go. diff --git a/.claude/tasks/TODO.md b/.claude/tasks/TODO.md index c666fb03..525bf0fb 100644 --- a/.claude/tasks/TODO.md +++ b/.claude/tasks/TODO.md @@ -309,7 +309,12 @@ feat/findings-tree-v2 merged (FindingsTreePicker tracked in HEAD); all work belo - [x] owner decisions (2026-10-22, BDR-068): D-R5 = B `sha256-rfc8785-validated-v1` (applied at R5.6 only), aliases from trusted frozen documents only, F1 go, byte-exact by default + declared differences, historical SVG bytes kept, `.prettierignore` on Rust-written paths + reproducible check, `ureq` preferred at R5.5; stop after R5.2 - [x] R5.1b F1 fix (aed6b1e): `zmij` digits; V8 oracle `oracles/r5/numbers.json` 44,322 rows (1,552 mismatches before, 0 after); 840.1692504882812 test; `zod_oracle` checks oracle bytes vs core compact print (red on old printer); consumers audited R2-R4: rust:check + wasm + check green, no oracle/golden/digest moved - [x] R5.2 legacy importer in Rust (feature `curation`, `crates/core/src/curation/**`, 3,187 lines) + `import-equine --check | --out`: legacy-import/ 4 texts + 2 SVG byte-exact, pipeline.json legacy parts equal, raw report = pre-Prettier digest, determinism, 10 synthetic TS cases (2 byte-exact, 8 refused alike), format probes (968 JSON, 10 tables, slugs, uuids, Number, Math.round, key order); declared differences RUST.md §11.10; contract `.claude/tasks/contracts/2026-10-22-rust-r5-f1-importer.md` → checkpoint, STOP before R5.3 - - [ ] R5.3 changeset applier, migration map, stats, seed SQL (draft JSON + SQL under the decided fingerprint, 825 records, 612 leaves) + - [x] R5.3 changeset applier, migration map, stats, seed SQL (done e0f149b, checkpoint delivered, STOP before R5.4; owner go 2026-10-22 « Validation R5.1b / R5.2 et autorisation R5.3 »: `pnpm r5:import-equine --check | --out ` names the Rust binary, `pnpm import:equine` kept; no fingerprint switch; `horse.svg` frozen bytes read, never re-cleaned; R5.4 files (review SVGs, CHANGELOG, REVIEW-REPORT) out of scope; stop at the checkpoint) + - [x] R5.3a `crates/core/src/curation/draft/{schema,targets,fields,ops,rename,apply}.rs`: changeset + references files parsed strictly (Zod shape order on re-emit, `priority` default, level C question, duplicate ids), target grammar, settable fields, the six ops on the plain JSON document (`serde_json::Value`, insertion order), rename propagation, review rule (touched items → `to_confirm`, identity through a transient marker key), shape + integrity gate through the R2 core (`AnatomicalSheetDocument` + `validate_sheet_document`) + - [x] R5.3b `draft/{migration_map,stats,seed,pipeline}.rs`: replay of rename/remove/move records over the 792 legacy paths, re-homing, stats; `documentStats` (17 fields, JS key order); `renderDraftSeedSql` byte-exact; `build_equine_draft` (CHG-000 from the frozen `horse.svg` bytes and the head view box) + `render_draft_artifacts` (document, assets, sheet-ref with sha256 of the document bytes, migration map, seed SQL) + - [x] R5.3c `import-equine`: both folders (`/legacy-import`, `/draft`), `--check` compares the produced files and lists the R5.4 files as pending (not counted), `--out` refuses a non-empty folder, a symlink, a file, an empty path; `scripts/import-equine.sh` + root script `r5:import-equine` + - [x] R5.3d proofs (draft 5 files byte-exact, 12/12 `--check`, 46 changes + 825 records + stats equal, 612 leaves 442/141/29, 58 synthetic cases: 9 byte-exact + 49 refused alike + 5 references files, rust:check green): `tests/curation_draft.rs` (draft files byte-exact vs committed, `pipeline.json` draft section: 46 changes, 825 records, stats, migration stats, assets, issues; determinism; 612-leaf walk through the core's migration on the produced map); TS generator `r5.curation-synthetic-oracles.test.ts` → `oracles/r5/curation-synthetic.json` (mini sheet: every op kind, positions, subtree scopes, review rule B/C, renames with cascades, re-homing, refusals) run by the Rust suite; `pnpm rust:check`, `pnpm check:all` + - [x] R5.3e (security PASS 6 LOW / 3 fixed; verifier 4 passes, last C1-C12 met + C13 docs fixed after; check:all green 00:10:03) gates: security auditor (diff), independent verifier on the contract `.claude/tasks/contracts/2026-10-22-rust-r5-draft.md`; docs RUST.md §11.12-11.13, CHANGELOG, CLAUDE.md commands; memory → checkpoint report, STOP before R5.4 - [ ] R5.4 review overlays + app drawings on the R3 layer/compose (parsed trees), CHANGELOG + REVIEW-REPORT - [ ] R5.5 `upload-sheet-assets` bin + runbook (local stack run) - [ ] R5.6 D-R5 switch (convention, aliases, membership test in gated readers with per-file go, seed regenerated once by the Rust tool, `.prettierignore`, CHANGELOG) diff --git a/.claude/tasks/contracts/2026-10-22-rust-r5-draft.md b/.claude/tasks/contracts/2026-10-22-rust-r5-draft.md new file mode 100644 index 00000000..3b9c06a4 --- /dev/null +++ b/.claude/tasks/contracts/2026-10-22-rust-r5-draft.md @@ -0,0 +1,99 @@ +# CONTRACT: Rust R5.3, the draft side of the anatomical pipeline (changeset applier, migration map, stats, seed SQL) + +- date: 2026-10-22 | branch `feature/rust-r5-pipeline-core` | plan `.claude/tasks/plans/2026-10-22-rust-r5-pipeline-core.md` §B.5 row R5.3 +- brief: owner 2026-10-22 « Validation R5.1b / R5.2 et autorisation R5.3 » (applied as written; its §1 to §9 are the clauses below) +- predecessor: R5.2 contract `.claude/tasks/contracts/2026-10-22-rust-r5-f1-importer.md` (the legacy importer, `import-equine --check | --out`) + +## Scope + +Port `packages/anatomy/src/curation/{schema,targets,fields,ops,rename,apply,types,migration-map,stats,seed,pipeline}.ts` +(the draft side without the review drawings and the two Markdown reports, which are R5.4) into +`crates/core/src/curation/draft/**` behind the existing `curation` feature, and extend the +`import-equine` binary to the `draft/` folder. Out of scope: `overlay.ts`, `app-review.ts`, +`changelog.ts`, `review-report.ts`, `assets.ts` (`stripLegacyAnnotations`: the cleaned `horse.svg` +is frozen, read as bytes), the fingerprint convention (R5.6), the upload tool (R5.5), any deletion +under `packages/`. + +## Clauses (each one checkable) + +C1. **Inputs.** The core reads the legacy `ImportResult` (R5.2), the bytes of the frozen +`draft/assets/horse.svg`, the head view box text, `curation/references.json` and +`curation/changes.json` as texts. No `std::fs`, no clock in `crates/core/src/curation/**` +(the binary `crates/core/src/bin/import_equine.rs` is the only file allowed the file system). + +C2. **Strict schemas.** `changes.json` and `references.json` are refused on: an unknown key in any +object, a wrong type, an `id` not matching `^CHG-\d{3,}$`, an empty `title.fr` / `title.en` / +`rationale` / target / field / rename id / cited reference id / `question`, an empty `ops`, an +empty `cite.reference_ids`, a level C change without a `question`, a duplicate change id, a +duplicate reference id, a position that is not a non-negative integer or a strict +`{after}` / `{before}` object, a reference failing the R2 `Reference` contract. `priority` +defaults to `medium`. Declared difference: a `set` without `value` is refused (TypeScript +wrote `undefined`, i.e. dropped the key). + +C3. **Applier semantics** (`apply.rs`, `ops.rs`, `rename.rs`, `targets.rs`, `fields.rs`): the +six ops behave as `ops.ts` on the plain JSON document (insertion order of keys, `review_status` +appended last when created), with the settable table of `fields.ts`, the target grammar of +`targets.ts`, the rename cascade of `rename.ts` (one record per rewrite), `assertDeclared`, +`assertNotReviewed`, and the review rule of `apply.ts` (every touched finding or annotation of a +B or C change set `to_confirm` with a record, first-touch order, items removed from the document +skipped). Any op that cannot apply exactly refuses with the change id and op index; the result +then passes the R2 shape (`AnatomicalSheetDocument`) and integrity (`validate_sheet_document`) +gate, errors refuse, warnings are returned. + +C4. **Records.** Every record is `{change, op, target, field, before, after}` with `change` in +the Zod shape order (`id, level, kind, title, rationale, reference_ids, question?, priority`), +`op` in the Zod shape order of its kind, absent values as `null`. + +C5. **Migration map** (`migration_map.rs`): `buildReportMigrationMap` as `migration-map.ts` +(replay of rename / remove / move records, zone renames, annotation and view renames, the +finalPaths check, unique re-homing, stats `nodes / identical / remapped / rehomed / removed`). + +C6. **Stats** (`stats.rs`): `documentStats` with its 17 fields in the TypeScript key order, +the fixed-key counters (`point, zone, detail_trigger`; `inherited, reviewed, to_confirm`) +extended by unlisted values as JavaScript does. + +C7. **Seed SQL** (`seed.rs`): `renderDraftSeedSql` byte for byte (header, sheet insert, asset +inserts, `insert_sheet_draft`, converging update, the dollar tag refusal, `trimEnd`). + +C8. **Draft artifacts** (`pipeline.rs`): `build_equine_draft` runs CHG-000 (asset record of the +frozen bytes: sha256, byte size, uuid; `view:main.svg_asset_id`, `view:head.svg_asset_id = null`, +`view:head.view_box` from the head SVG's viewBox) then the authored changes, refuses a changeset +reusing `CHG-000`; `render_draft_artifacts` returns `document.json`, `assets.json`, +`sheet-ref.json` (`document_sha256` = sha256 of the `document.json` bytes, the historical rule), +`report-migration-map.json`, `equine_draft.sql`, in the TypeScript order, plus the byte copy +`assets/horse.svg`. + +C9. **Parity proofs** (`crates/core/tests/curation_draft.rs`): the six R5.3 files of the +committed `draft/` byte for byte; the `pipeline.json` draft section (sheetId, 46 changes, 1 +asset, statsBefore, statsAfter, issues, migrationStats, 825 records) equal under the JS compact +print; two runs byte-equal; the 612 legacy leaves migrated through the core's `read_report_document` +on the produced map: 442 identical, 141 moved, 29 removed, every resolved leaf a leaf of the +produced document, the 29 flagged paths exactly those the map sends to null. + +C10. **Synthetic differential** (`oracles/r5/curation-synthetic.json`, generator +`packages/anatomy/tests/r5.curation-synthetic-oracles.test.ts`, `MAKE_R5_ORACLES=1`): changesets +on the mini sheet covering every op kind, numeric and anchored positions, subtree scopes, the +review rule on levels A / B / C, the five rename cascades, a reference rename, re-homing, and the +refusal classes of `curation.apply.test.ts` and `curation.schema.test.ts`; each accepted case +freezes the formatted document, the records, the stats, the migration map and the seed SQL, each +refused case the refusal; the Rust suite reproduces every accepted case byte for byte and refuses +every refused case. + +C11. **Binary and script.** `import-equine --check` compares `legacy-import/` and `draft/` with +the committed folders and writes nothing; the R5.4 files (`review/*.svg`, `CHANGELOG.md`, +`REVIEW-REPORT.md`) are listed as pending and not counted (marked `shortcut:` for R5.4). +`import-equine --out ` writes `/legacy-import/**` and `/draft/**`, refuses an +empty path, a path that exists and is not a directory, a symlink, a folder holding any file; +never deletes. `scripts/import-equine.sh` + root script `r5:import-equine` forward the +arguments; `pnpm import:equine` (TypeScript) unchanged. + +C12. **Frozen references untouched.** No file under `supabase/seed/**`, `crates/core/tests/oracles/**` +(except the new `curation-synthetic.json`), `apps/app/tests/fixtures/**`, +`packages/core-wasm/tests/n-1/**` changes; `documentSha256` stays `27c7383c…2660`; no gated +reader (`domain/{archive/read,report/rebase,report/read,session}.rs`, `pdf/{read,json_js,import}.rs`) +changes; `packages/anatomy` and `packages/domain` keep every test (anatomy gains the generator). + +C13. **Gates.** `pnpm rust:check` green, `pnpm check:all` green, security auditor PASS on the +diff, this contract verified CONFORME by a fresh verifier; RUST.md §11.12 (R5.3) and §11.13 +(checkpoint) written, CHANGELOG Unreleased, CLAUDE.md command list; differences declared one by +one. No merge, no R5.4, no fingerprint switch, no release, no deploy. diff --git a/.claude/tasks/plans/2026-10-22-rust-r5-pipeline-core.md b/.claude/tasks/plans/2026-10-22-rust-r5-pipeline-core.md index 512c6afc..3493f3b3 100644 --- a/.claude/tasks/plans/2026-10-22-rust-r5-pipeline-core.md +++ b/.claude/tasks/plans/2026-10-22-rust-r5-pipeline-core.md @@ -3,7 +3,7 @@ - date: 2026-10-22 | rev 1 (R5.1 only; the later slices are a proposal for the R5.1 checkpoint) | branch: `feature/rust-r5-pipeline-core` (cut from develop 9c0117a, R4 merged) - spec: owner brief 2026-10-22 « Clôture R4 validée et autorisation R5.1 » (§A.0); `docs/development/RUST_ARCHITECTURE_REVIEW.md` II.2 rows "anatomy curation pipeline" and "upload-sheet-assets" (lines 299, 300), VI.1 row R5 (636), VI.3 (655), VI.4 (662 to 668), D-R5 (837, 873), Annex C D-R5 amendment (974); BDR-043, BDR-045; CLAUDE.md "Anatomical sheet model", "Schemas", archive-reader gate - facts: `.claude/audits/R5_PIPELINE_INVENTORY.md` (the TypeScript pipeline), `.claude/audits/R5_DOCUMENT_SHA256_CENSUS.md` (the fingerprint), the oracles under `crates/core/tests/oracles/r5/`, the study scripts `scripts/r5-fingerprints.mjs` and `packages/supabase/scripts/r5-jsonb-fingerprint.mjs` -- status: R5.1 validated 2026-10-22; D-R5 decided (A.5); R5.1b and R5.2 done, checkpoint R5.2 pending; R5.3 on the owner's go. +- status: R5.1 validated 2026-10-22; D-R5 decided (A.5); R5.1b and R5.2 validated 2026-10-22; R5.3 done (contract `.claude/tasks/contracts/2026-10-22-rust-r5-draft.md`, RUST.md §11.12), checkpoint R5.3 pending; R5.4 on the owner's go. - not in scope of R5.1: any Rust implementation of the pipeline, any change to `documentSha256` or to the readers, the deletion of `packages/anatomy` or `packages/domain`, any golden or historical reference regeneration, release 0.2.0, deployment, SaaS features. # Part A. For the owner @@ -91,7 +91,7 @@ Encoding change vs content change: the today / A / B columns of one row are thre `crates/core/src/json.rs` takes the shortest digits from `format!("{:e}")` (Grisu); on an exact decimal tie between two shortest candidates ECMAScript picks the even one, Grisu the upper one. Measured: `840.1692504882812` (legacy annotation `cx`, from Horse.svg) prints `…813`; 7,401 of 100,000 float32-exact values in 0..2000 and 769 of 100,000 random doubles differ; `zmij` (serde_json's formatter) differs on none. Reached by the canvas layer (R3), the PDF writer, the archive attachment, the R2 contract tests. Invisible today: the curated draft carries no tie value, and `sheet_contract.rs` re-prints its expected text through `to_js_pretty`, so the oracle cannot see it. Proposed fix (after your go, before R5.2): digits from `zmij` (or `serde_json::to_string(&f64)`), the two tie values and the 8 long decimals of the legacy SVG as unit tests, `zod_oracle` comparing against the JS text recorded in the oracle rather than a re-print. -### B.3.5 Compatibility mechanism (proposal, not implemented) +### B.3.5 Compatibility mechanism (approved at A.5, applied at R5.6) The sheet side carries the convention and the aliases; the report contract does not change.