# AGENT-PROMPT-v5-P1-1b — Reference layer, 2026 history, seeding, hash swap, BRCode

**Date:** 2026-08-05
**Follows:** `docs/AGENT-PROMPT-v5-P1-1.md` (the P1-1 specification, which still governs),
`docs/p1-1a-signoff.md`, `docs/PROJECT-STATE.md`
**Authority:** Miguel. **This prompt is the P1-1b authorization** that the P1-1a acceptance
deliberately withheld, and it records three decisions taken 2026-08-05. It does not reopen any
closed decision, does not touch O5, and does not authorize production go-live or P1-2.

## Three decisions taken with this prompt

1. **O7 is decided — the prospective rule.** `DOCLOG.CaptureQuality` stays nullable. Historical
   rows imported from the prototype carry honest SQL `NULL` with provenance `absent` — no
   sentinel, no backfill, nothing invented. Every **new Sibyla capture** must supply
   `CaptureQuality` at capture time (a deterministic capture-gate requirement, enforced when the
   capture pipeline lands). The validation service's CaptureQuality **warning is re-scoped to
   non-imported rows only**: an imported historical row with NULL CaptureQuality is not a finding;
   a Sibyla-era row without it is. This mirrors D7's grandfathering logic and P1-0e's honest-NULL
   discipline. Record O7 as closed in `PROJECT-STATE.md` (decision table, open-items table,
   changelog) in your first records commit. The scoping change to the accepted validator is
   **additive P1-1b work with its own tests** — the accepted P1-1a migration itself is immutable.
2. **Import source: the prototype's current live state under a fresh pin.** Do not import from
   `9359c67` — it predates Luís's work since Aug 3. The gate below obtains his confirmation and
   takes a new pin; every count in the backlog is then **re-measured at that pin** (the recorded
   figures are marked indicative for exactly this reason). `9359c67` remains the historical
   reference for P1-0/P1-1a records and must not be re-litigated.
3. **Execution topology: disposable rehearsal first, live second.** The complete import — reference
   layer, history, validation, parity, join test — must run green end to end against a disposable
   PostgreSQL 17 database before a single write reaches the live base. The live pass then requires
   a fresh pre-import dump (SHA-256 recorded, `pg_restore --list` verified) before it starts.

## Gate — before anything else

Obtain Luís's confirmation that the prototype is stable and the queued documents are ingested;
then take the new pin: record the commit SHA, and the blob SHAs of every file you will read
(`Invoice Skill Build/Editor/Data/*.json`, `user_observations.json`,
`reference_only_documents.json`, control log). The prototype stays **read-only** at that pin for
the whole assignment. If Luís is unavailable or the prototype is mid-change: **stop and report.**

## Scope, in order

1. **Reference layer import** — ENTMST, ENTALS, ITMMST, ITMALS, ENTITM, ITMCLS, MNGACC, SNCACC,
   COCACC, EXCRAT, DOCTYP rules, DOCEFL rules, DOCFLG instances, `user_observations.json`,
   `reference_only_documents.json`. Permanent codes preserved verbatim; per-field provenance on
   anything not extracted; the DOCEFL import must satisfy the governed manifest exactly
   (`EF0000001`–`EF0000052`, `Imported=true`; authored rows keep their honest NULLs). The authored
   sentinel is `EF0000000`; the authored Monthly-gap rule is `EF0000053` and remains inactive
   behind its governed activation guard.
   **`document_gaps.json`/OFDGAP stays out** (C12: detector to reimplement, not a table to
   import). **The import fails closed on any unlisted vocabulary literal** — an unknown value is
   a finding, not a row to coerce. C8's five duplicate ENTBNK pairs fail closed knowingly if
   still unmerged; C13's three residual FL collisions pass on the `DetectedAt` tiebreaker.
2. **2026 history import (D4)** — DOCLOG, FDCHDR, FDCDTL, and the governed Layer 5 set, with:
   grandfathering derived and persisted at import from each instance's own `DetectedAt` against
   the rule's `EnforcementStartsAt` (never recomputed); D5 `ReferenceOnly` rows carrying no
   EntryCode; the seven comma-joined payroll aggregates through the ordered junction with exact
   cardinalities (2, 2, 2, 3, 3, 11, 15); occurrence discriminators preserved; prototype-era
   quirks flagged, never silently normalized.
3. **Validation service over the imported set** — must pass with zero failures under the O7
   scoping. Record the warning counts (synthetic FiscalNo, orphan DOCLOG) as measured; they are
   report content, not blockers.
4. **Re-measure and record** every backlog count at the new pin; update the indicative figures.
5. **Render parity** — the acceptance criterion says the seeded base reproduces the FDR sheets
   through the P1-12 renderer. P1-12 does not exist yet. Either implement the minimal read-only
   export path sufficient to prove parity on the imported set, or **stop and report** with a
   written deferral proposal for Miguel — do not silently skip and do not claim parity untested.
6. **Overlapping-statement join test** — re-ingest an overlapping bank statement and prove: every
   generated document re-anchors, zero duplicates, the seven aggregates resolve, and
   `UNIQUE (Company, BMCode)` holds.
7. **Content-hash index swap** — prepare it as its own reviewed change (new migration; the P1-1a
   migration is untouched), submit it to an independent review round, and apply it only after
   that review passes.
8. **BRCode issuance** — issue under `(Company, BMCode, EntryCode, FindingDiscriminator)` per the
   A3 resolution, after the sequencing above.
9. **Records** — `docs/p1-1b-status.md` with a control record per imported table
   (*Initial + Expected = Result*, counts at the new pin), `PROJECT-STATE.md` and
   `docs/project-todo.md` kept truthful as you go. Clean multi-line commit bodies; no literal
   `\n`; push each completed stage.

## The live pass

Only after the full disposable rehearsal is green: fresh pre-import dump of the live base
(SHA-256, `pg_restore --list`), stored under the approved `SibylaBackups` hierarchy; then the
import against the deployed base; then the validation service against live; then the join test's
read-only assertions. Record the evidence (sanitized) with its hash. If any live step diverges
from the rehearsal result: **stop, report, do not improvise a fix on the live base.**

## What you may not do

No edits to P1-0 drafts or to the accepted P1-1a migration. No prototype writes. No production
go-live claim (O5 is open). No P1-2 work. No history rewrite. No data value invented — every
imported field is `extracted` from the new pin or honestly `NULL`/`absent`. If sources conflict
or are silent, stop and report; if `PROJECT-STATE.md` contradicts this prompt, stop and report
the contradiction.

## Report at the end

Commit hashes per stage; the new pin and blob SHAs; per-table imported counts vs expected;
validator results (failures must be zero; warnings as measured); parity outcome or deferral;
join-test numbers; hash-swap review reference; BRCode issuance counts; dump hashes; and the exact
list of what still separates the project from P1-1 acceptance.
