feat(hive-claude): add InfiniteSession (name+store+compaction policy)

This commit is contained in:
müde 2026-07-05 19:38:16 +02:00
commit 80d819e444
8 changed files with 501 additions and 283 deletions

View file

@ -15,19 +15,31 @@ on it rather than shelling out to `claude` by hand.
## Shape
- **`Claude::run(&config, &session, prompt, &sink)`** → `Result<(), Error>`. A
clean turn is `Ok(())`; every non-completion state is an [`Error`] variant, so
you branch with a single `match`.
- **`Claude::run_resume_or_create(&config, title, prompt, &sink)`** →
`Result<bool>`. Resumes a titled session, creating it on first use.
`Ok(true)` means a fresh session was minted.
Two layers — reach for the high-level one:
- **`InfiniteSession { name, store, policy }`** — a durable session that keeps
itself alive across the context window. `.run(&config, prompt, &sink)`
`Result<Progress, Error>` does resume-or-create, compacts **reactively** on
overflow (compact + retry once), and **proactively** after a clean turn when
the policy says so (optional checkpoint turn, then compact). `.compact(…)`
forces one. `Progress { created, compacted }` reports what happened.
- **`Claude::run(&config, &attach, prompt, &sink)`** → `Result<(), Error>`
the low-level driver: one turn, one `Attach` target (`Resume` / `Create` /
`Continue` / `OneOff`). A clean turn is `Ok(())`; every other state is an
`Error` variant.
Supporting pieces:
- **`CompactionPolicy`** — decides *when* to compact. **`PercentPolicy`**
(`percent`, `default_window`, `checkpoint_prompt`) compacts at a percent of
the model window; **`NeverCompact`** never does.
- **`Config`** — the invocation (model, effort, cwd, prompt/MCP files, tools,
extra args). **`Session`** — which session to attach to (`Resume` / `Create`
/ `Continue` / `OneOff`).
- **`Sink`** — a trait with no-op defaults; implement the methods you care
about to observe stream events, non-JSON stdout, and stderr. Use `NoopSink`
when you only want the result.
extra args).
- **`Sink`** — a trait with no-op defaults; implement what you care about to
observe stream events, non-JSON stdout, and stderr. `NoopSink` ignores all.
- **`SessionStore`** — locate and archive on-disk sessions by title.
- **`Usage`** — the minimal context signal (`context_tokens`,
`context_window`) the policy sees.
`Error` unifies the two things that can stop a turn: recognized **sentinels**
(`PromptTooLong`, `RateLimited`, `AuthFailed`, `SessionNotFound`) and **hard