# Runtime and host integration

## Forms

Use `assets/forms/intake-and-term-sheet.md` for intake and deal comparison, and `assets/forms/agreement-outline.md` for optional drafting sections. Copy `assets/forms/review-record.json` and `assets/forms/revision-plan.json` into the working record and replace every placeholder with current project data. These are intentionally incomplete forms, not validated records. Keep `approved: false` until the user's substantive decision is recorded; do not manufacture approval. For missing provisions, follow the absence-basis format in `review-record.md` rather than inventing a quotation. Generate decision cards and a choices form from the actual review with `cards` and `choice-template`; validate completed choices before applying edits. Generate structure choices with `preview` and the final comparison/report with `compare` and `report`.

## Commands

In a distributed skill folder, run `python scripts/contract_check_cli.py`. In the source repository, run `python -m contract_check` from the repository root, or install with `python -m pip install .` when package installation is available. The core uses only the Python standard library. Commands:

- `ingest INPUT.txt PROJECT.json` stores the exact UTF-8 source and splits at blank lines into body blocks with stable IDs. It does not infer clauses or headings.
- `apply PROJECT.json PLAN.json REVISED.json [--review REVIEW.json --choices CHOICES.json]` applies approved operations. Plan fields: `base_version`, `source_sha256`, `operations`, optional complete `order`, `order_reason`, `order_approved: true` for reorders, and `decisions`. Every operation has `action`, `id`, `reason`, `approved: true`. `label`, `replace`, and `delete` also require exact `before` text. `insert` requires a new `n`-prefixed ID and `text`, plus a complete order. A heading operation has `kind: heading`, `title`, `level` (1–6), optional `old_label`, and `old_kind` (`Section`/`Article`). Replacing a heading requires an explicit title. Any content-changing replacement, body insertion, or deletion needs a `finding_id` linked to an `adopt` or `custom` choice, with the review and choice record supplied. A formatting-only replacement may omit it when nonwhitespace characters are identical and `classification: formatting`. A heading insertion/deletion may instead use `section_decision_id` linked to an include/omit decision. Decisions are keyed objects with `status: include|omit|defer` and `reason`. Preserve prior projects, choices and plans as audit records.
- `render PROJECT.json CLEAN.txt --style preserve|decimal|articles [--update-refs] [--map-output MAP.json]` numbers labeled headings only. Heading text must consist solely of the confirmed heading; split mixed heading/obligation blocks before labeling to avoid losing content. With `--update-refs`, explicit singular `Section N` or `Article N` references in body blocks are updated only when every target maps uniquely from `old_label` and `old_kind`. It aborts on unmapped, ambiguous, or unsupported forms such as plural references, subsection letters, ranges, clause, schedule, or exhibit references. Decimal style numbers by heading depth; article style renders top-level Article and lower-level Section. Unsupported cross-reference syntax requires manual review.
- `check PROJECT.json CLEAN.txt` reports duplicate numbered headings, unresolved explicit singular references, unsupported compound/subclause reference forms, and duplicate quoted `"Term" means` definitions, with a limited scope. Exit 2 means findings; exit 0 does not mean substantive completeness.
- `validate-review PROJECT.json REVIEW.json` checks version, finding shape, and verbatim block quotes. It does not validate analysis or law.
- `compare ORIGINAL.json REVISED.json DIFF.json [--style ...]` returns insertion, deletion, replacement, or movement by ID and a unified text diff. The diff is not Word tracked changes.
- `audit ORIGINAL.json REVISED.json FLAGS.json` flags changed numerical strings and words such as `not`, `unless`, `shall`, and `may`, plus block insertions/deletions. Review each flag and all substantive edits; token matches do not establish semantic equivalence.
- `extract-docx INPUT.docx TEXT.txt MANIFEST.json` extracts paragraphs and table cells in order. Inspect the manifest warnings for tracked changes, headers, footnotes, comments, drawings, and field codes. The original file remains authoritative; format and layout are not retained.
- `cards PROJECT.json REVIEW.json CHOICES.md` renders a decision sheet. It does not record selections automatically; capture them in the approved plan.
- `choice-template PROJECT.json REVIEW.json CHOICES.json` creates an unselected JSON record. After the user chooses, fill every selection with `choice: adopt|retain|defer|custom` and a reason; custom choices require `custom_instruction`. Run `validate-choices PROJECT.json REVIEW.json CHOICES.json`. A Markdown card is a presentation, while this JSON is the controlled record.
- `inventory PROJECT.json INVENTORY.json` suggests heading labels and inventories quoted `"Term" means` definitions. Confirm all candidates; the text's typography alone cannot establish contract structure.
- `preview PROJECT.json STRUCTURE.md` shows three layout choices and a candidate-section decision table. These are prompts, not mandatory contract content.
- `report ORIGINAL.json REVISED.json REPORT.md [--style ...]` combines recorded decisions, lexical flags, and a text diff. It does not replace semantic review.

Optional enforcement issue assessment: read `enforcement-analysis.md`. Commands: `enforcement-template PROJECT REVIEW REQUEST.json`, `enforcement-validate PROJECT REVIEW REQUEST.json`, `enforcement-assess PROJECT REVIEW REQUEST.json ASSESSMENT.json [--authorities AUTHORITIES.json] [--local-endpoint LOOPBACK_URL --model MODEL]`, and `enforcement-report PROJECT REVIEW REQUEST.json ASSESSMENT.json REPORT.md [--authorities AUTHORITIES.json]`. The report revalidates the source, request, authority manifest, and gates. An authority excerpt is checked against user-supplied text, not fetched or authenticated by this module. No probability is produced.

Host capability adapter: use file readers or OCR for intake, code execution for core operations, research for law, and document export when available. Verify text extraction and attachments before substantive review. If execution is unavailable, preserve the same state and decision fields in the conversation and identify which checks were manual. Do not claim cross-session persistence without a durable store. External APIs are optional and require configured endpoints, authorization, bounded retries, minimal data transfer, and visible failure. This repository does not contain vendor-specific connectors.
