fatsearch 0.2.5

Web pages and documents turned into small, clean, cached Markdown for AI agents
Documentation
# Working on fatsearch with a coding agent

This file is for agents (Claude Code, Codex, Cursor, Copilot, …) asked to change this repository. Humans:
[CONTRIBUTING.md](CONTRIBUTING.md) has the same rules in prose. Agents asked to *use* `fats` want
[skills/fatsearch/SKILL.md](skills/fatsearch/SKILL.md) instead.

## What this is

One Rust crate, one binary `fats`: CLI and stdio MCP server (`fats mcp`, one tool `fats(cmd)`). It fetches a web
page, PDF or file, cleans it to Markdown, prints a short outline with ids (`u1`, `u1#3`, `l4`) and caches it; the
agent reads one section at a time. Fetch = plain HTTP, then the user's own Oxylabs, Bright Data or Decodo key. No daemon,
no browser; anonymous usage counts and a daily update check, disclosed and one command off
([docs/telemetry.md](docs/telemetry.md), code in `src/telemetry.rs`). Reference: [docs/reference.md](docs/reference.md); user docs: `fats guide`, [README](README.md).

## Build and check

```sh
cargo build                 # debug, for tests
./check.sh                  # every commit: fmt, clippy, tests (cargo nextest), line budget  (~15–40 s warm)
./check.sh full             # before a PR: + clippy on shipped features, cargo deny, release build, size gate
scripts/ci-linux.sh         # CI's ubuntu job in a local podman container (arm64 host; ~8 min cold, ~1 min warm)
cargo install --locked cargo-nextest   # check.sh needs it
```

Toolchain pinned in `rust-toolchain.toml`; warnings are errors; `--locked` always. Tests never touch the
network (`FATS_OFFLINE=1`; the fake transport under `--features fake`). Run the built binary only with a scratch
home (`env -i HOME=$(mktemp -d) PATH=/usr/bin:/bin ./target/debug/fats …`): every command sweeps the cache it finds.

## Rules that reject a change

- **Generic HTML only.** No hostname, site name, selector or class name of a site in `src/` or in `src/data/*.json`
  (the ccTLD table and the provider endpoints are the exceptions). A page that comes out wrong gets a better
  generic rule plus a `!` row, never an adapter.
- **A wrong output is a wrong rule in its owner.** Find the function that owns the behaviour
  ([docs/reference.md]docs/reference.md names each rule; `src/` is split by job: fetch, clean, outline, lang, cache, provider, settings, stats), fix the rule there, add the case as a unit test.
- **Honesty.** Nothing is silently dropped: media are counted on the `=` line, missing things get a `!` row with the
  next command and its worst-case price (`≤$X`). Never a hint that costs money without the price.
- **Errors are records**, never panics: no `unwrap`/`expect` on user input (clippy denies it).
- **Observable.** Anything the binary does must show in `fats`, `fats stats`, `fats config` or `dry:true`.
- **Data, not code.** A new list of words, codes or limits is a row in `src/data/*.json` (`settings::TABLES`,
  `deny_unknown_fields`, `settings::tests::tables_load` pins the counts), never a Rust literal.
- **Line budget is a gate.** `scripts/linebudget.py` counts non-blank, non-comment, non-test lines of `src/`;
  `check.sh` fails above the budget. Pay for new lines by deleting duplication, never by packing lines,
  `rustfmt::skip` or moving code to tests. Readability lints (`too_many_lines` 60, nesting 5, args 6, …) are in
  `Cargo.toml` and `clippy.toml`.
- **`fats --help` stays ≤ 500 bytes**; `fats guide` is the one-screen manual.
- **Dependencies** need a maintainer's go-ahead first (CONTRIBUTING.md): name, version, licence, why. Verify the
  crate exists on crates.io before naming it.

## Commits

Conventional Commits, imperative, ≤ 72 chars, body says why, `git commit -s` (DCO), no AI trailers. One logical
change per commit; `./check.sh` green at every commit. `CHANGELOG.md` gets a line under `## Unreleased` in user
language. Never edit `src/tables.rs` (generated by `scripts/gen_tables.py`).

## Where things are

| path | what |
|---|---|
| `src/lang.rs` | the command language: words, ids, `key:value` mods, the `=` line printer, `!` rows |
| `src/cli.rs` · `src/mcp.rs` | dispatch, sessions, detached fetches, batches · the one-tool MCP server |
| `src/fetch.rs` · `src/provider.rs` | the fetch ladder, timeouts, pricing · Oxylabs / Bright Data / Decodo / plain, billing |
| `src/html.rs` · `src/clean.rs` · `src/outline.rs` | parse (html5ever) · prune, Markdown, cards, threads, islands · sections, parts, previews, next moves |
| `src/pdf.rs` · `src/text.rs` · `src/search.rs` | PDFs · text formats · in-page filter |
| `src/cache.rs` · `src/settings.rs` · `src/stats.rs` | ids, sessions, sweep · settings and their sources (mod → env → `settings.json` → built-in), keys (`auth.json` only; `fats setup import-env` copies exported ones in), on/off switches, the home-IP brake on plain fetches · `fats stats`, status, config |
| `src/setup.rs` | `fats setup` on a terminal (the menu, a key page per provider) and the one-time local key form an agent opens for its user |
| `src/data/*.json` | the tables: providers, errors, checks, clean rules, words, limits; `screens/` = the human screens' words, `setup-form.html` = the key form |
| `tests/cli.rs` · `tests/fixtures/` | end-to-end on the built binary · hand-trimmed pages, never full copies |
| `skills/fatsearch/SKILL.md` | the usage skill (`npx skills add fatsearch/fatsearch`) |
| `server.json` · `dist-workspace.toml` · `.github/workflows/` | MCP Registry entry · cargo-dist release config (edit this, never `release.yml`) · CI and release |