commit 2249e36bb76331cc01b18c1aca803c6c690da77a
parent 6b9c82e795bea1abae9ecf0eac25db324d37a22f
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Tue, 13 Oct 2026 10:46:48 -0400
plans: release 27 — S1, as shipped
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Diffstat:
1 file changed, 48 insertions(+), 0 deletions(-)
diff --git a/plans/release-27.md b/plans/release-27.md
@@ -258,6 +258,54 @@ Gates: common tsc clean; common tests 3827/3827 (9 new, `testing/fakes.test.ts`)
Found: as committed, the `paragraphs` fixture manifest shows two of the owed bugs (no title `foot`; Coverage a bare
chapter card). S7 fixes them and regenerates it.
+### S1, as shipped (2026-10-13, lane A, `r27/llm`)
+
+`common/lib/llm/`: the providers and the agent loop, with no settings read (everything comes in as options; S6 builds
+them from `settings.generation`). Raw `fetch`, no SDK; `fetch` and `sleep` are injectable.
+
+| Commit | What |
+| --- | --- |
+| `e664e9cc` | `prices.ts` (longest prefix; unknown Claude = Opus 5, local = free), `meter.ts` (`Meter`; writes 1.25x/2x by the API's split, else the run's TTL), `anthropic.ts` (`AnthropicClient`, `readApiKey`, `redact`; caching; the strict models' rules; retries), `ollama.ts` (`ollamaChat`, `unloadOllama`, `estimateTokens`, tools both ways), `config.ts` (`LlmConfig`, `providerOf`), `structured.ts` (`structuredAnswer`); tests |
+| `1beab231` | `agent.ts` (`runAgent`, `AgentTool`, `AgentEvent`, `TranscriptEntry`), `index.ts`; the agent tests and the key-leak test; the client's config made a `#private` field |
+| `8d1f2ed4` | `envVars.ts` declares `ANTHROPIC_API_KEY`; ENVIRONMENT.md regenerated |
+| `65a81a88` | the key-leak test's second key is not key-shaped |
+
+Rulings in the code:
+- **The key** is read from env `ANTHROPIC_API_KEY`, else `apiKeyFile` (`~` expanded; refused when group or others have any bit; `export` and quotes tolerated).
+ - It is sent only in `x-api-key`.
+ - Every message the client throws passes `redact` (the key and any 16-character run of it).
+ - The config and the key are `#private`, so neither `inspect()` nor `JSON.stringify` shows them.
+ - `env` is an option (tests pass `{}`).
+- **Strict models** are `claude-sonnet-5-5`, `claude-opus-5-5` and `claude-fable-5-1` / `claude-mythos-5-1`:
+ - no `temperature`;
+ - a forced `tool_choice` is refused before sending;
+ - append-only history (no prune).
+ - Only Sonnet 5.5 is sent `thinking: {type: "between_tools"}`; the others keep their default, and a `disabled` is dropped.
+- **Caching:** the top-level `cache_control` plus a system breakpoint, at the client's one TTL.
+- **Retries:** 408/429/5xx/529, `retry-after` (capped at 2 min) else 5 s × 2ⁿ (≤ 60 s), 5 by default. A 400 is not retried, except once without `temperature` when the model names it.
+- **`structuredAnswer`:**
+ - A non-strict Claude model is forced to the `answer` tool. A 400 naming `tool_choice` falls back to the strict way.
+ - A strict model gets `strict: true`, a closed schema, `tool_choice: auto` and one re-ask.
+ - ollama uses `format`, retried once on a fault or a non-JSON answer. A prompt over the cap is never sent or retried.
+- **ollama:** the estimate is 3.5 chars a token over messages + tools + format (safer than the fake's 4). The cap is ≤ 8000 and `num_ctx` ≤ 12288, both clamped. `think: false` is sent only to thinking models (qwen3, qwq, deepseek-r1, gpt-oss, magistral, cogito) unless asked.
+- **`runAgent`:**
+ - Claude's server web search is `web_search_20250305` (the stopgap's, proven live). A 400 naming `web_search` drops it, and the caller's own `web_search` tool, hidden while the server one is on, comes back.
+ - Tool results are cut at 60 000 chars for Claude and 2 500 local.
+ - A non-strict conversation is pruned past 90k context tokens (keeping 3), never once a thinking block exists.
+ - The wrap-up is one text block after the tool results at `wrapUpAt` (0.85) of `maxUsd ?? meter.maxUsd`.
+ - The budget is checked before each request and after tools. The local loop runs its tools one at a time.
+- **The transcript:**
+ - Request entries carry only the messages added since the previous request, with `system`/`tools` on turn 0 and when they change.
+ - Response entries carry the content, usage and USD.
+ - Tool entries carry the input, the result clipped to 4 000 chars, the full length, the error flag and the ms.
+ - Every string is clipped.
+- `digestApps.ts`'s `ollamaDirect` is unchanged (not required; its error and option semantics differ).
+
+Gates: tsc clean (all packages); common 3878/3878 (51 new in `lib/llm/`); mcp 306/306; `docs env --check` clean.
+No builds (no app code).
+
+Found and fixed: `inspect(client)` showed the config's `env`, key included (the key-leak test caught it).
+
## Rollout
- Fast-forward `main`.