# Rules from documents: design

**State: designed, not built.** A policy, an SOP or a maker's manual arrives today as a document event. The file is
stored under its sha256, its text is extracted where it has a text layer, and a ticket asks a person to review the
rules it states. Nothing reads the rules out of the text yet.

## What is built

- The PDF drop: `POST /collect` with `x-source: file-drop`, then `doc.file.received`, then a document record with
  `text.state` (extracted, no_text_layer or not_extracted) and `rules.state: designed`.
- The `policy-document` path: a checklist action (`review-document-rules`) and a review ticket.
- The `maintenance_policy` load template, which is where confirmed rules land.

## The design

1. **Read.** Claude Code reads the stored text and proposes the rules it states. Each proposal is a row in the
   `maintenance_policy` template: asset class, task, interval, source document, page and clause.
2. **Prompts in files.** The prompt lives in a file beside the other house prompts, never in code.
3. **Confirm, one by one.** A person sees each proposed rule beside the page it came from and confirms, edits or
   rejects it. Nothing is loaded without that confirmation.
4. **Load.** Confirmed rows go through the same template check as a sheet. Each record names the document's sha256
   and the clause, with provenance "read".
5. **Link.** A confirmed rule links its document to the paths and triggers it governs. A path's policy changes from
   `to_link` to `linked`.
6. **Fail visibly.** If Claude Code is not reachable, the document stays at "rules not read", with the error. No
   default rules are written in its place.

## Not covered yet

- **Scans.** A scanned page has no text layer, so it needs OCR first. That is not built.
- **Revisions.** A second edition of a policy is a new document. Comparing it with the first is a later step.
