|
| 1 | +# DOC-IR × spider-rs Convergence — Integration Plan v1 (2026-07-13) |
| 2 | + |
| 3 | +> **Status:** PLAN — companion to `OGAR-DOC-LAYER-PROPOSAL.md` (see its |
| 4 | +> 2026-07-13 AMENDMENT A1–A5, which this plan sequences). The doc-layer |
| 5 | +> 5+3 council gates W1+; W0 is verification-only and runs now. |
| 6 | +> |
| 7 | +> **Ask (operator, 2026-07-13):** combine recognition and |
| 8 | +> processing/representation of knowledge **whether it comes from |
| 9 | +> tesseract-rs or spider-rs** (`AdaWorldAPI/spider`, fork of |
| 10 | +> `spider-rs/spider`) — "using the JSON-like structuring as a reusable |
| 11 | +> input awareness (2D-'spatial' focus of attention)." |
| 12 | +> |
| 13 | +> **One sentence:** the `doc.v1` structure is promoted from "OCR output" |
| 14 | +> to the substrate's **perceptual IR** (`ogar-doc-ir`), with tesseract-rs |
| 15 | +> (pixels) and spider-rs (DOM) as its two sanctioned producers — the |
| 16 | +> code-side pattern (N language frontends → one closed ndjson → one |
| 17 | +> ModelGraph) replayed on perception, so everything upstream (ogar-doc |
| 18 | +> persistence, DeepNSM, lance-graph discovery, MedCare-rs as abstract |
| 19 | +> document store) consumes ONE shape regardless of retina. |
| 20 | +
|
| 21 | +## P0. The convergence thesis (why one IR, stated once) |
| 22 | + |
| 23 | +| code side (shipped) | perception side (this plan) | |
| 24 | +|---|---| |
| 25 | +| Roslyn / ruff_python / ruff_ruby frontends | tesseract-rs (scan) / spider-rs (web) retinas | |
| 26 | +| closed 62-predicate ndjson, `from_ndjson` hard-fail gate | closed region-kind doc IR, `from_json` hard-fail gate | |
| 27 | +| `ruff_spo_triplet::ModelGraph` | `ogar-doc-ir` region tree | |
| 28 | +| `CompiledClass` in the graph | `document 0x080B` awareness subtree | |
| 29 | + |
| 30 | +spider-rs is an unusually good second retina because **HTML5 already |
| 31 | +declares its regions**: `<header>/<main>/<footer>/<table>` are the literal |
| 32 | +Kopfzeile/Fußzeile/main positions the amendment's A3 template projects — |
| 33 | +the web *self-labels* what OCR must *infer*. Same regions, two |
| 34 | +acquisition modes, one IR. |
| 35 | + |
| 36 | +## P1. Access preflight (blocking facts to verify, first spider-enabled session) |
| 37 | + |
| 38 | +`AdaWorldAPI/spider` was NOT readable from this session (repo-access gate). |
| 39 | +Before W3 is scoped in detail, a session with spider access verifies: |
| 40 | + |
| 41 | +- **PF-1** fork exists, default branch, divergence from upstream |
| 42 | + `spider-rs/spider`. |
| 43 | +- **PF-2** page output surface (assumed from upstream: `Website` crawl → |
| 44 | + per-page HTML string + URL + headers; a headless-chrome feature exists |
| 45 | + for rendered layout). Verify names/features before writing the seam. |
| 46 | +- **PF-3** whether rendered layout coordinates are obtainable (headless |
| 47 | + feature) or whether W3 ships DOM-order pseudo-geometry first (see W3 |
| 48 | + fallback — the plan works either way). |
| 49 | +- **PF-4** workspace layout: where a harvest crate lands in the fork |
| 50 | + (sibling crate, mirroring how `ruff_*_spo` crates live in the ruff fork). |
| 51 | + |
| 52 | +## P2. Wave plan |
| 53 | + |
| 54 | +### W0 — council gate (no code) |
| 55 | + |
| 56 | +The doc-layer 5+3 council verifies the AMENDED proposal: mints |
| 57 | +`typed_field 0x080A` + `document 0x080B`; one-crate `ogar-doc`; |
| 58 | +`ogar-doc-ir` as neutral tissue; the A2 one-leg runtime-binding rule; the |
| 59 | +A3 ClassView × WideFieldMask template. **The council verifies the |
| 60 | +source-agnostic boundary — a spec that only a tesseract producer could |
| 61 | +satisfy is a numbered factual error.** |
| 62 | + |
| 63 | +### W1 — `ogar-doc-ir` (the IR crate; gates everything downstream) |
| 64 | + |
| 65 | +- Types: region tree (page / region / table+cells / figure / header / |
| 66 | + footer), typed fields, quality. |
| 67 | +- **Closed region-kind vocabulary**; `from_json` HARD-FAILS on unknown |
| 68 | + kinds; explicit `doc.v1` version marker (v2 = a new marker, never a |
| 69 | + silent reshape). |
| 70 | +- **Spatial rails:** every bbox quantized to u8 × u8 unit square (the |
| 71 | + `X:Y` rail; the page IS a 256×256 tile on the existing centroid/Morton |
| 72 | + machinery). Raw coordinates = optional provenance, never the address. |
| 73 | +- **Provenance lane:** source enum (`ocr` / `dom`) + per-source confidence |
| 74 | + semantics (recognition confidence ≠ crawl trust; no shared float). |
| 75 | +- **Identity:** content sha256 as the subtree dedup key. |
| 76 | +- Deps: serde only. Tests: vocab closure, gate hard-fail on unknown kind, |
| 77 | + rail quantization round-trip, version-marker refusal. |
| 78 | + |
| 79 | +### W2 — tesseract-rs producer migration (byte-parity gated) |
| 80 | + |
| 81 | +`structured::{DocPage, render_json_with_regions, …}` emits `ogar-doc-ir` |
| 82 | +types; the **existing doc.v1 JSON output is the committed golden** and the |
| 83 | +migration must reproduce it byte-for-byte (same discipline as the sono |
| 84 | +parity witness: the shipped artifact gates its own refactor). tesseract-rs |
| 85 | +gains a dep on `ogar-doc-ir`; `ogar-doc-ir` never depends back. |
| 86 | + |
| 87 | +### W3 — spider-fork producer (`spider_doc_ir` harvest crate, in the fork) |
| 88 | + |
| 89 | +DOM → doc IR: HTML5 landmarks → region kinds; DOM order → reading order; |
| 90 | +`<table>` → cell grids; microdata/schema.org → typed fields; rendered |
| 91 | +layout coords → rails when PF-3 confirms the headless path, else |
| 92 | +**DOM-order pseudo-geometry** (top-to-bottom rail assignment) as the |
| 93 | +honest v1 — provenance lane marks which geometry mode produced the rails. |
| 94 | +Fixture-driven tests on committed HTML files; no live crawling in CI. |
| 95 | +Lives in the spider fork (PF-4), mirroring `ruff_*_spo`-in-ruff; depends |
| 96 | +on `ogar-doc-ir` via git dep floating on main (D-NEVER-PIN-BUMP). |
| 97 | + |
| 98 | +### W4 — `ogar-doc` (persistence + template + renderer trait) |
| 99 | + |
| 100 | +Per the amended proposal: `persist_document` / `read_document` / |
| 101 | +`reconstruct_document` facts; `DocTemplate` = ClassView × WideFieldMask |
| 102 | +(A3); `trait DocRenderer` with tesseract / Spire.Doc / askama adapters |
| 103 | +bound at runtime (A2). First consumer: MedCare-rs `routes/dms.rs` upload |
| 104 | +→ `recognize_document` → `persist_document` (raw-ref = encrypted |
| 105 | +`file_filelist` key) — sonography, histology, invoices as the abstract |
| 106 | +document store. |
| 107 | + |
| 108 | +### W5 — upstream foresight seams (small, deliberate, no redesign) |
| 109 | + |
| 110 | +- **DeepNSM** (stays 0-dep): entry point accepts |
| 111 | + `(text_span, region_kind, spatial_rail)` tuples in reading order — the |
| 112 | + tuple IS the contract; no doc-schema dep enters the crate. Gives the |
| 113 | + FSM region priors (a table cell is not a sentence), the temporal stream |
| 114 | + its reading order (per the temporal-stream ruling), and spatial |
| 115 | + adjacency (caption-near-figure). |
| 116 | +- **lance-graph discovery arm:** `document 0x080B` registered as a |
| 117 | + discoverable concept; sha256 as the convergence key. Typed fields are |
| 118 | + already SPO facts + rails — "all invoices from X with IBAN Y" is a |
| 119 | + graph query + rail scan, no new machinery. |
| 120 | + |
| 121 | +## P3. Probes (falsifiable; graded [H] until run) |
| 122 | + |
| 123 | +- **P-XRETINA (the killer witness):** the same invoice through both |
| 124 | + retinas (scan → tesseract; HTML → spider) must converge to the same |
| 125 | + typed-field facts and the same sha-keyed subtree identity. Diverse |
| 126 | + redundancy applied to perception — the MySQL-oracle pattern. GREEN |
| 127 | + promotes the whole IR from [S] to [G]; RED means the IR is |
| 128 | + tesseract-shaped-with-a-second-door and W1 gets corrected before more |
| 129 | + producers land. |
| 130 | +- **P-DOM-GROUNDTRUTH:** spider + headless render yields (pixels, |
| 131 | + DOM-labeled regions) pairs at zero annotation cost — a calibration |
| 132 | + corpus for tesseract's region classifier. The web trains the eye that |
| 133 | + reads paper. |
| 134 | +- **P-2D-MARKOV:** does spatial-neighborhood attention (Morton rail |
| 135 | + adjacency) beat pure reading-order for field harvest? Slots into the |
| 136 | + existing temporal-stream probe queue; not a W-gate. |
| 137 | + |
| 138 | +## P4. Non-goals (v1 of this plan) |
| 139 | + |
| 140 | +- No live crawling in any CI path (fixtures only). |
| 141 | +- No spider-side scheduling/politeness/auth policy — the fork's own |
| 142 | + concern; this plan touches only the page → doc-IR seam. |
| 143 | +- No multi-language OCR slot, no streaming payloads, no storage-backend |
| 144 | + choice (all inherited deferrals from the doc-layer proposal). |
| 145 | +- No DeepNSM redesign — W5's tuple signature is the entire ask. |
| 146 | + |
| 147 | +## P5. Sequencing + gates |
| 148 | + |
| 149 | +`W0 (council) → W1 (IR) → {W2, W3} in parallel → P-XRETINA → W4 → W5`. |
| 150 | +W2/W3 are independent once W1 lands; **P-XRETINA runs the moment both |
| 151 | +producers exist and BEFORE W4 persists anything** — persisting a |
| 152 | +tesseract-shaped subtree and discovering the divergence later would bake |
| 153 | +the bias into stored data. Merge-order discipline per house rule: |
| 154 | +OGAR-side crates first, fork-side producers second, in lockstep. |
0 commit comments