# STEP4 gatecheck: contract v1 Python 3.9+; standard library only. Download `step4-gatecheck.py` from this directory. For each transition run: ``` python step4-gatecheck.py --workspace PATH_TO_WORKSPACE --target F4 python step4-gatecheck.py --workspace PATH_TO_WORKSPACE --target F11 ``` Exit 0 / `PASS_GATE` permits the requested transition only alongside the agent's actual separate checks and all STEP4 gates. Exit 2 / `FAIL_GATE` forbids the transition, returns `earliest_repair`, lists reasons, and never permits publication. Repair the earliest failed stage, mark affected dependent stages `NEEDS_RECHECK`, redo their checks and checkpoints, then run the gate again. The program checks locally recorded evidence and hashes; it does not prove the truth of a translation, the reliability of timestamps, or independence of the same agent. Nor can a command prevent an agent from bypassing it; STEP4 makes running it mandatory. The workspace contains `gate-manifest.json` with `schema_version: step4-gate/1`, `checkpoints` mapping each phase ID to its JSON file and `artifacts` mapping keys to files. Paths are relative to the workspace, must remain inside it and must be files. See `fixture/` or downloadable `fixture.zip` for a complete, executable miniature example. A pre-v1 workspace must add the contract as a new evidence layer; it is never automatically passed based on legacy PASS labels. Each F0–F10 checkpoint contains `phase`, `status`, timezone-aware `started_at` and `completed_at`, `review: SELF_CHECK_ONLY`, `verification` with `criterion`, `expected`, `actual`, and a nonempty list `evidence` containing workspace-relative `path` and exact SHA-256. F7/F8 may use `NOT_APPLICABLE` with a substantive reason. Checkpoints bind the phase-specific artifacts to their hashes, and later phase start times must not precede the preceding phase's completion. F5 `SOURCE_GAPS_PENDING` additionally requires `source_100: true`, zero `translation_losses` and `critical_risks`, nonempty `gap_ids`, and a hashed `gap_registry` JSON containing `{ "gaps": [{"gap_id":..., "source_quote":..., "question":...}] }`. F9 must provide `gap_resolutions` for each gap with `gap_id`, `action: PATCH|SAFE_LIMIT`, an exact `candidate_quote`, and substantive `reason` before F11. Artifact keys and formats: - `rights`, `q0`, `original`: permission document, Q0, original HTML. F0, F1 and F2 bind each respectively. - `source_ledger`: CSV with unique `source_id` and exact `source_quote`; `f3_review`: JSON `review`, `status`, `reviewed_at`, `entries` with `source_id`, `verdict`, `reason`. - `ru_base`: HTML with stable `id` anchors. `f5_review` has the same review metadata and one entry per source ID, adding `scope: fragment`, `ru_locator`, `ru_quote`, and a substantive `reason`. The quote must occur at the anchor. A whole block and automated matching alone do not prove semantic preservation. - `exam`: frozen CSV with `id`, `dimension`, `dimension_meaning`, `weight`, `question`, `expected`, `rubric`. D1=diagnose, D2=choose, D3=perform, D4=prevent, D5=verify, D6=remedy. Use `|` to delimit expected elements. `exam_freeze`: JSON `sha256`, timezone-aware `frozen_at`. `f6_review` contains entries with each question `id`, its `dimension`, and substantive `reason`. - `candidate` and `f9_review`: separate review JSON after F5 with `candidate_sha256`, `derived_from_f5_only: false`, and one `source_id`, `verdict`, `candidate_locator`, `candidate_quote`, `reason` per source ID. - `scores`: CSV, each question × ORIGINAL/BASE/CANDIDATE with `question_id`, `version`, integer `score` 0–4, locatable `evidence`, substantive `reason`, and `element_evidence`, a JSON object mapping every expected element to an exact quotation in that version. `f10_review` is a separate review JSON after freeze. This structural contract is deliberately strict: a partial answer without exact evidence fails closed until a verifiable representation is supplied. Every review is an actual separately performed `SELF_CHECK_ONLY` pass with `status: PASS` and `reviewed_at`. Providing formally valid placeholders or invented timestamps does not satisfy STEP4. Results can still contain errors and must not be presented as independent expertise.