# Documentation Index Batch 0.1.0-rc2

Generate a local JSONL batch when a bounded set of public documentation pages
changes. Each watched URL gets exactly one `upsert`, `delete`, `unchanged`, or
`hold` row. Holds preserve prior chunks. The proposed job is a batch within
24 hours of a source change. That is a discovery hypothesis. Schedule a run
at a cadence that fits your sources and give holds an owner.

## Try the free worked example

Use Linux and Python 3.12. Extract the TAR archive and run from the extracted
directory. The example uses authored responses and has no network dependency.

```sh
python3 run_index.py run example/watch.json ./demo-state 20261205T070000Z \
  --seed example/prior.json --fixture example/responses.json \
  --approve-removals example/approve-removals.json
python3 verify_index.py ./demo-state/runs/20261205T070000Z --watch example/watch.json
python3 run_index.py replay ./demo-state 20261205T070000Z
```

Expect six rows: an updated HTML page with a same-origin redirect, one approved
410 removal, one unchanged page, and three holds for a 404, a robots rule, and
a timeout. Compare the output with `example/expected.json`. Run the packaged
checks with `python3 -B -m unittest discover -s tests -v`.

## Run with your own inputs

Linux live mode also uses the system certificate store, `getent`, and curl
8.4 or newer. The package uses Python's standard library. It needs no provider
account, API key, proxy, browser, or index credentials.

Supply version-1 JSON with `words_per_chunk` (25–400) and a `watch` list of
1–12 unique HTTPS URLs. Each item specifies `mode` (`text`, `main`, or
`article`) and an exact page-specific `required_text` phrase after whitespace
normalization. Supply a version-1 seed whose `pages` maps exactly those URLs
to index entries in chunk order. Each entry has a globally unique existing
`id` and a SHA-256 of the normalized chunk text. Use `[]` for a new page.
The seed represents the downstream index as of the start. Export it from that
index before using update or delete deltas. Example inputs show the format.

Choose a UTC slot for the first capture. For subsequent invocations use a
later UTC slot, reuse the state directory, omit `--seed`, and omit `--fixture`
for live reads.

```sh
python3 run_index.py run /path/watch.json /path/state "$(date -u +%Y%m%dT%H%M%SZ)"
```

Pass `--seed /path/prior.json` on the first live invocation. Schedule the
subsequent command in your own scheduler with an external 90-second deadline.
Capture is bounded to 45 seconds, plus return/verification overhead. A current
UTC slot sorts later than the committed head. Reuse the exact slot to recover
a lost acknowledgement. A successful repeat replays the original bytes
without fetching. An uncommitted older slot or a competing writer exits
nonzero. A changed watch or chunk profile requires a fresh state directory
and a deliberately migrated seed. The history bound is 366 commits per state
directory. Rotate from a verified `next.json` and retain the archived state.

Use a local filesystem offering atomic rename and file/directory fsync. The
runner verifies a staged batch in a separate process, publishes it atomically,
and checks the previous committed batch before advancing. Consumers should read
only committed `runs/<slot>/` directories, apply in parent order using the
prior manifest hash as a precondition, and deduplicate by event ID. Apply all
chunk deltas for a URL together and reconcile consumer state to `next.json`.
A local commit and downstream ingestion are separate operations. The package
does not deploy an agent, a scheduler, or an index connector.

## Versioned content and access rules

- Watch only public, lowercase DNS names and plain HTTPS paths on port 443.
  Use URLs whose site access terms you have reviewed. Cross-origin redirects
  and any URLs requiring credentials, ports, percent-encoded paths, queries,
  or fragments are unsupported. There is no link discovery.
- Consult same-origin robots.txt before fetching a watched path, with allow and
  disallow matching for this client and the wildcard group. A direct 404 for
  robots.txt permits the check to proceed. Ambiguous robots rules, redirecting
  robots files, access errors, crawl delays and request rates produce holds.
  Follow at most two same-origin document redirects and check each target.
  Pause an origin for the rest of the run on a 429 or a final Retry-After.
- Across robots and document requests, issue at most 32 HTTP attempts, with a
  request deadline of 6 seconds, up to one retry on a timeout or eligible
  502/503/504, 512 KiB per response and 6 MiB aggregate body bytes. Roots are
  processed serially. Hostnames must resolve to public addresses; curl is
  pinned to a checked address and uses direct HTTPS without inherited settings.
- Parse UTF-8 text/plain or exactly one closed static HTML main/article
  landmark. Exclude navigation, top and bottom page chrome, scripts and hidden
  elements recognized by the parser. Honor recognized robots indexing
  exclusions. Require the configured phrase and at least ten normalized
  whitespace-separated words. Treat plaintext form feeds as page-separator whitespace.
  Split contiguous groups of N words (no overlap)
  with up to 512 chunks per URL. CSS layout, browser rendering, concurrent
  origin revisions and content semantics are outside this policy.
- Stable document IDs hash the submitted URL. Matching chunk text reuses an
  existing ID, including across position changes. New chunk IDs bind the
  URL, position, text hash and prior page manifest. File and JSONL SHA-256
  values bind the retained artifacts. These are local integrity checks.
- A reliable 200 can replace a page's chunks, upserting current records and
  deleting stale chunks within the same URL event. A chunk-count drop by more
  than half holds the previous state. A whole-page delete requires an
  unredirected HTTP 410 on the first attempt and explicit local buyer approval
  matching that URL's current `prior_page_sha256`. Review a prior hold and
  its source evidence before approving. 404s, blocking pages, timeouts,
  unsupported content and uncertain disappearance preserve the old chunks.

A committed batch includes the captured HTTP status, selected headers,
redirects, response retrieval time, body bytes and hash, prior and next
manifests, JSONL events, file hashes and the verifier result. Keep captures
local and manage retention based on your sources' terms and your index policy.
A hold is a successful, independently verified accounting row that needs
review. Check hold counts in scheduler monitoring even when the exit is zero.
The independent checker recomputes the transition from retained evidence in
another process using the same versioned extraction and access rules. It
does not authenticate publisher intent or prove site-wide capture reliability.
