pi-lean-host 0.7.1 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -13,11 +13,12 @@
13
13
  > `pi-lean-host` is the structured-data answer to that gap — author the API
14
14
  > once, reuse it forever.
15
15
  >
16
- > Part of the [pi-lean-dimension](https://github.com/coreyryanhanson/pi-lean-dimension)
16
+ > Part of the
17
+ > [pi-lean-dimension](https://github.com/coreyryanhanson/pi-lean-dimension)
17
18
  > web-tools suite. Host-only installs are valid — **`pi-lean-portal` is an
18
19
  > optional peer dependency**. For interactive browsing, install
19
- > [`pi-lean-portal`](https://www.npmjs.com/package/pi-lean-portal); for
20
- > SearXNG search, install
20
+ > [`pi-lean-portal`](https://www.npmjs.com/package/pi-lean-portal); for SearXNG
21
+ > search, install
21
22
  > [`pi-lean-search`](https://www.npmjs.com/package/pi-lean-search).
22
23
 
23
24
  ---
@@ -44,17 +45,18 @@
44
45
  pi install npm:pi-lean-host
45
46
  ```
46
47
 
47
- No browser binaries, no server, no setup wizard. The host tools are **enabled
48
- by default** — you'll see:
48
+ No browser binaries, no server, no setup wizard. The host tools are **enabled by
49
+ default** — you'll see:
49
50
 
50
- > 📡 API tools enabled. /api learn to make api-learn + api-probe + api-scaffold + api-store + oauth-mint available.
51
+ > 📡 API tools enabled. /api learn to make api-learn + api-probe +
52
+ > api-scaffold + api-store + oauth-mint available.
51
53
 
52
54
  From a fresh install you have no guides yet, so the next step is to get one:
53
55
 
54
56
  - **Author one** — see [Authoring Your First Guide](#authoring-your-first-guide)
55
- for the end-to-end workflow, including auth-gated APIs. The complete
56
- authoring manual (field reference, pagination styles, helper contracts)
57
- lives in [docs/authoring.md](docs/authoring.md).
57
+ for the end-to-end workflow, including auth-gated APIs. The complete authoring
58
+ manual (field reference, pagination styles, helper contracts) lives in
59
+ [docs/authoring.md](docs/authoring.md).
58
60
  - **Or copy a reference recipe** (see
59
61
  [Reference Recipes (caritas)](#reference-recipes-caritas)) into
60
62
  `~/.pi/agent/pi-lean-host/api-guides/<slug(shortName)>/` — it loads
@@ -65,46 +67,45 @@ From a fresh install you have no guides yet, so the next step is to get one:
65
67
  ## The Big Idea: Recipes, Not a Runtime
66
68
 
67
69
  The single most important discipline: **only files you place in
68
- `~/.pi/agent/pi-lean-host/` execute.** An API guide is a markdown file with
69
- YAML frontmatter declaring endpoints, auth, pagination, and response shape.
70
- A managed tool (`api-fetch`) executes the declared operation through a small
71
- fixed set of built-in helpers. The agent never writes TypeScript against the
72
- API — it authors (or copies) a recipe, and the tool does the call.
70
+ `~/.pi/agent/pi-lean-host/` execute.** An API guide is a markdown file with YAML
71
+ frontmatter declaring endpoints, auth, pagination, and response shape. A managed
72
+ tool (`api-fetch`) executes the declared operation through a small fixed set of
73
+ built-in helpers. The agent never writes TypeScript against the API — it authors
74
+ (or copies) a recipe, and the tool does the call.
73
75
 
74
76
  This kills two whole classes of recurring mistakes before they exist:
75
77
 
76
78
  - **Agents getting the same API wrong every session.** The reason they do is
77
- *they are the ones writing the calls.* Move call construction into a
78
- reviewed tool + fixed helpers, and those mistakes disappear at the source.
79
- - **Arbitrary eval / egress safety (default path).** Declarative recipes
80
- run no agent-authored code, and bundled recipes are inert. The exception is
81
- local helpers: in `/api learn` the agent can write `helper.ts` to your
82
- guides directory. These run in-process with the agent's privileges. Since
83
- the agent already has shell access, this isn't a privilege escalation,
84
- but it introduces persistent code.
79
+ _they are the ones writing the calls._ Move call construction into a reviewed
80
+ tool + fixed helpers, and those mistakes disappear at the source.
81
+ - **Arbitrary eval / egress safety (default path).** Declarative recipes run no
82
+ agent-authored code, and bundled recipes are inert. The exception is local
83
+ helpers: in `/api learn` the agent can write `helper.ts` to your guides
84
+ directory. These run in-process with the agent's privileges. Since the agent
85
+ already has shell access, this isn't a privilege escalation, but it introduces
86
+ persistent code.
85
87
 
86
88
  ### Why not just a skill?
87
89
 
88
90
  A skill is prose the agent re-interprets each turn; this plugin is a fixed
89
- executor it calls through. For a single clean endpoint you call
90
- occasionally, a few skill lines are the lazier answer. It earns its keep
91
- where re-derived curl goes wrong — **pagination to exhaustion** (cursor,
92
- nextLink, OAI-PMH tokens, Wikimedia continuation dicts walked in one call by
93
- reviewed code), **charset traps** (Latin-1 APIs serving bytes without a
94
- charset parameter — fixed once in the transport, not re-applied and
95
- forgotten), and **in-process TypeScript helpers** that transform params or
96
- responses directly (a skill can only instruct the agent to write and run
97
- that code). A skill is also always in context; the guide store loads on
98
- demand. A skill is pure text with no in-process eval, whereas a loaded
99
- `helper.ts` runs with the agent's privileges.
91
+ executor it calls through. For a single clean endpoint you call occasionally, a
92
+ few skill lines are the lazier answer. It earns its keep where re-derived curl
93
+ goes wrong — **pagination to exhaustion** (cursor, nextLink, OAI-PMH tokens,
94
+ Wikimedia continuation dicts walked in one call by reviewed code), **charset
95
+ traps** (Latin-1 APIs serving bytes without a charset parameter — fixed once in
96
+ the transport, not re-applied and forgotten), and **in-process TypeScript
97
+ helpers** that transform params or responses directly (a skill can only instruct
98
+ the agent to write and run that code). A skill is also always in context; the
99
+ guide store loads on demand. A skill is pure text with no in-process eval,
100
+ whereas a loaded `helper.ts` runs with the agent's privileges.
100
101
 
101
102
  ### Three tiers of code, separated by trust
102
103
 
103
- | Tier | Where it lives | Who writes it | Ships in tarball? | Trust |
104
- |------|----------------|---------------|-------------------|-------|
105
- | Built-in helpers | package source (`core/`) | maintainers | yes | reviewed |
106
- | Local user helpers | `~/.pi/agent/pi-lean-host/api-guides/<slug(shortName)>/helper.ts` | you, or the agent in `/api learn` | no | user-owned |
107
- | Bundled recipes | `caritas` repo (`api-guides/<slug(shortName)>/`) | maintainers | no (see [Reference Recipes](#reference-recipes-caritas)) | **inert: never auto-executed** |
104
+ | Tier | Where it lives | Who writes it | Ships in tarball? | Trust |
105
+ | ------------------ | ----------------------------------------------------------------- | --------------------------------- | -------------------------------------------------------- | ------------------------------ |
106
+ | Built-in helpers | package source (`core/`) | maintainers | yes | reviewed |
107
+ | Local user helpers | `~/.pi/agent/pi-lean-host/api-guides/<slug(shortName)>/helper.ts` | you, or the agent in `/api learn` | no | user-owned |
108
+ | Bundled recipes | `caritas` repo (`api-guides/<slug(shortName)>/`) | maintainers | no (see [Reference Recipes](#reference-recipes-caritas)) | **inert: never auto-executed** |
108
109
 
109
110
  Built-in helpers cover the common 90%. Local user helpers cover the weird 10%
110
111
  (computed signatures, strange date transforms, custom auth).
@@ -113,32 +114,33 @@ Built-in helpers cover the common 90%. Local user helpers cover the weird 10%
113
114
 
114
115
  ## `/api` Command — API Toggle
115
116
 
116
- | Command | Effect |
117
- |---------|--------|
118
- | `/api on` | **API access** — `api-guide` + `api-fetch` available. Authoring tools hidden. (Default for new sessions.) |
119
- | `/api learn` | **API access + authoring** — adds `api-learn` + `api-probe` + `api-scaffold` + `api-store` + `oauth-mint` on top of `on`. The agent never authors guides unprompted — it must be in learn mode. |
120
- | `/api off` | **All API tools hidden** — removes `api-*` from the agent's context to save tokens on sessions that aren't doing API work. |
121
- | `/api` | Show current state and available sub-commands. |
122
- | `/api status` | Detailed runtime status — toggle state, active guide count, domain list, and helper health (disabled helpers surface with a `⚠`). |
123
- | `/api helpers` | List local user helpers (or `/api helpers <domain>` to view one's source). |
124
- | `/api secrets [<domain> [<name>]]` | Manage stored API secrets — list, provision, delete (see [Authentication & Secrets](#authentication--secrets)). |
125
- | `/api verify <domain> [guide] [--force]` | Run every runnable op against the live API and stamp `verified` on success — strict: any runnable-op failure → no stamp; skipped ops named in the report (see [Recipe drift](docs/authoring.md#recipe-drift)). |
126
- | `/api delete <domain> [guide]` | Remove a guide directory and invalidate the guide-store cache — a human-typed recovery gesture (no agent tool surface); interactive confirm for a whole-domain delete. |
127
- | `/api oauth <domain> …` | OAuth2 token management — `init` / mint / `--status` / `--refresh` / `--revoke` / `--code <code>` per token slot (human-typed; the agent's mint path is `oauth-mint`). `init` runs an interactive wizard (or headless flags — see `--help` for `--redirect-uri`, which must match the provider app registration) and finishes a paste-based auth-code flow via `/api oauth init <domain> … --code <code>`. |
128
- | `/api bootstrap oauth <domain> <spec>` | Agent-driven OAuth2 bootstrap — validates args, auto-enables learn when off, injects a research brief into the session, and exits; the agent then researches the provider and calls `oauth-mint` (the human is the trust root for the secret-bearing endpoint). Refused headless. |
117
+ | Command | Effect |
118
+ | ---------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
119
+ | `/api on` | **API access** — `api-guide` + `api-fetch` available. Authoring tools hidden. (Default for new sessions.) |
120
+ | `/api learn` | **API access + authoring** — adds `api-learn` + `api-probe` + `api-scaffold` + `api-store` + `oauth-mint` on top of `on`. The agent never authors guides unprompted — it must be in learn mode. |
121
+ | `/api off` | **All API tools hidden** — removes `api-*` from the agent's context to save tokens on sessions that aren't doing API work. |
122
+ | `/api` | Show current state and available sub-commands. |
123
+ | `/api status` | Detailed runtime status — toggle state, active guide count, domain list, and helper health (disabled helpers surface with a `⚠`). |
124
+ | `/api helpers` | List local user helpers (or `/api helpers <domain>` to view one's source). |
125
+ | `/api secrets [<domain> [<name>]]` | Manage stored API secrets — list, provision, delete (see [Authentication & Secrets](#authentication--secrets)). |
126
+ | `/api verify <domain> [guide] [--force]` | Run every runnable op against the live API and stamp `verified` on success — strict: any runnable-op failure → no stamp; skipped ops named in the report (see [Recipe drift](docs/authoring.md#recipe-drift)). |
127
+ | `/api delete <domain> [guide]` | Remove a guide directory and invalidate the guide-store cache — a human-typed recovery gesture (no agent tool surface); interactive confirm for a whole-domain delete. |
128
+ | `/api oauth <domain> …` | OAuth2 token management — `init` / mint / `--status` / `--refresh` / `--revoke` / `--code <code>` per token slot (human-typed; the agent's mint path is `oauth-mint`). `init` runs an interactive wizard (or headless flags — see `--help` for `--redirect-uri`, which must match the provider app registration) and finishes a paste-based auth-code flow via `/api oauth init <domain> … --code <code>`. |
129
+ | `/api bootstrap oauth <domain> <spec>` | Agent-driven OAuth2 bootstrap — validates args, auto-enables learn when off, injects a research brief into the session, and exits; the agent then researches the provider and calls `oauth-mint` (the human is the trust root for the secret-bearing endpoint). Refused headless. |
129
130
 
130
131
  ### Persistence
131
132
 
132
- Toggle state persists via the [`pi-tool-masking`](https://github.com/coreyryanhanson/pi-tool-masking/)
133
- library (`persistKey: toolset-state:pi-lean-dimension.api`), surviving
134
- `/reload`, `/resume`, `/fork`, and `/tree` navigation. A fresh conversation
135
- starts from the `toolsetDefaults` block in merged Pi settings (see
133
+ Toggle state persists via the
134
+ [`pi-tool-masking`](https://github.com/coreyryanhanson/pi-tool-masking/) library
135
+ (`persistKey: toolset-state:pi-lean-dimension.api`), surviving `/reload`,
136
+ `/resume`, `/fork`, and `/tree` navigation. A fresh conversation starts from the
137
+ `toolsetDefaults` block in merged Pi settings (see
136
138
  [Configuration](#configuration-settingsjson)), falling back to the packaged
137
139
  defaults.
138
140
 
139
141
  The status bar shows an `api` glyph (independent of the `browser`/`search`
140
- slots). It reads `● api` when `/api` is on (colored to reflect learn state)
141
- and `○ api` when off.
142
+ slots). It reads `● api` when `/api` is on (colored to reflect learn state) and
143
+ `○ api` when off.
142
144
 
143
145
  ---
144
146
 
@@ -162,8 +164,8 @@ api-guide domain="wikipedia.org" guide="Wikipedia REST" → selected guide
162
164
  - `{domain, guide}` → the selected guide, resolved by `shortName`.
163
165
 
164
166
  When a guide is malformed on disk it shows with a `⚠ malformed` badge and the
165
- error inline rather than silently disappearing — so you can fix the one
166
- broken field instead of re-authoring from scratch.
167
+ error inline rather than silently disappearing — so you can fix the one broken
168
+ field instead of re-authoring from scratch.
167
169
 
168
170
  ### 2. `api-fetch` — Execute a Guided Operation (network read)
169
171
 
@@ -183,20 +185,20 @@ api-fetch domain="wikipedia.org" operation="searchPages" params={srsearch:"clima
183
185
  - `fresh` (optional) — `true` bypasses the response cache and forces a full
184
186
  network fetch.
185
187
 
186
- `api-fetch` resolves every guide claiming `domain`, finds the named
187
- `operation` across them, and executes it against the matching guide.
188
- Exactly one hit executes; zero hits lists the ops from all matching guides
189
- (a multi-guide domain — each guide in its own directory — so you can pick);
190
- an op name appearing in ≥2 guides is an ambiguous collision the guide
191
- authors must fix (re-author via `api-learn` to rename). The agent never sees an
192
- unredacted URL, never sees a header value, never sees the auth scheme. Output is an inline
193
- preview (~4000 chars) with larger responses spilled to a temp file under
194
- `/tmp/pi-lean-host/` (overridable via `PI_HOST_TEMP_DIR`) — `read` it with
195
- offset/limit for specific sections.
196
-
197
- When no guide exists for the domain, the call **fails informatively** and
198
- points at `api-guide({})` (to list guided domains) and `api-learn` (to author
199
- one) — turning a failed execute into a discovery moment in one round-trip.
188
+ `api-fetch` resolves every guide claiming `domain`, finds the named `operation`
189
+ across them, and executes it against the matching guide. Exactly one hit
190
+ executes; zero hits lists the ops from all matching guides (a multi-guide domain
191
+ — each guide in its own directory — so you can pick); an op name appearing in ≥2
192
+ guides is an ambiguous collision the guide authors must fix (re-author via
193
+ `api-learn` to rename). The agent never sees an unredacted URL, never sees a
194
+ header value, never sees the auth scheme. Output is an inline preview (~4000
195
+ chars) with larger responses spilled to a temp file under `/tmp/pi-lean-host/`
196
+ (overridable via `PI_HOST_TEMP_DIR`) — `read` it with offset/limit for specific
197
+ sections.
198
+
199
+ When no guide exists for the domain, the call **fails informatively** and points
200
+ at `api-guide({})` (to list guided domains) and `api-learn` (to author one) —
201
+ turning a failed execute into a discovery moment in one round-trip.
200
202
 
201
203
  ### 3. `api-learn` — Author / Update a Guide (local write)
202
204
 
@@ -206,26 +208,24 @@ api-learn domain="arxiv.org" → fetches an existing guide's
206
208
  api-learn domain="arxiv.org" dir="/tmp/pi-lean-host/arxiv.org" → validates + mirror-saves the staged dir to disk
207
209
  ```
208
210
 
209
- The working copy is staged under `/tmp/pi-lean-host/` (`/tmp`
210
- self-cleans, so drafts don't accumulate; `<domain>/` for starter
211
- templates (`new: true`), `<slug(shortName)>/` for fetched recipes) —
212
- a fresh fail-closed starter
213
- template, an existing guide's raw recipe + siblings for
214
- direct editing, or a validated mirror-save of the staged dir into
215
- `~/.pi/agent/pi-lean-host/api-guides/<slug(shortName)>/`. Every staged pull
216
- is prepended with the authoring manual.
217
- Full staging, deletion-gate, and slug-collision semantics:
211
+ The working copy is staged under `/tmp/pi-lean-host/` (`/tmp` self-cleans, so
212
+ drafts don't accumulate; `<domain>/` for starter templates (`new: true`),
213
+ `<slug(shortName)>/` for fetched recipes) — a fresh fail-closed starter
214
+ template, an existing guide's raw recipe + siblings for direct editing, or a
215
+ validated mirror-save of the staged dir into
216
+ `~/.pi/agent/pi-lean-host/api-guides/<slug(shortName)>/`. Every staged pull is
217
+ prepended with the authoring manual. Full staging, deletion-gate, and
218
+ slug-collision semantics:
218
219
  [docs/authoring.md](docs/authoring.md#the-authoring-tools-in-detail).
219
220
 
220
221
  ### 4. `api-probe` — Discover an Endpoint's Shape (network read, exploratory)
221
222
 
222
223
  Agent-driven shape discovery for the authoring loop. Fetches a not-yet-guided
223
- endpoint over the real transport (same UA, charset, retry, and ETag handling
224
- as `api-fetch` — the sanctioned way to reach even WAF'd hosts), summarizes the
225
- JSON shape, and emits a **draft YAML operation block** to paste into a recipe.
226
- It only **suggests** — it never writes the guide, and a draft still needs
227
- confirming against the provider's docs (probe surfaces evidence, not
228
- authority).
224
+ endpoint over the real transport (same UA, charset, retry, and ETag handling as
225
+ `api-fetch` — the sanctioned way to reach even WAF'd hosts), summarizes the JSON
226
+ shape, and emits a **draft YAML operation block** to paste into a recipe. It
227
+ only **suggests** — it never writes the guide, and a draft still needs
228
+ confirming against the provider's docs (probe surfaces evidence, not authority).
229
229
 
230
230
  ### 5. `api-scaffold` — Bootstrap `verify.json` / `helper.ts` (local write)
231
231
 
@@ -236,11 +236,11 @@ api-scaffold domain="arxiv.org" helper=true → writes a commented-out helper.t
236
236
 
237
237
  Bootstrap tool for the two artifacts the authoring loop needs but that
238
238
  `api-learn` can't draft from the recipe alone: a `verify.json` with
239
- `"__FILL_ME__"` sentinels for every op with unsatisfiable params (sentinels
240
- skip until you replace them; existing real values merge additively) and a
241
- commented-out `helper.ts` stub. Both staged to `/tmp` — never the guides
242
- dir, never overwriting an existing staged sibling. Save the guide **first**,
243
- then scaffold.
239
+ `"__FILL_ME__"` sentinels for every op with unsatisfiable params (sentinels skip
240
+ until you replace them; existing real values merge additively) and a
241
+ commented-out `helper.ts` stub. Both staged to `/tmp` — never the guides dir,
242
+ never overwriting an existing staged sibling. Save the guide **first**, then
243
+ scaffold.
244
244
 
245
245
  ### 6. `api-store` — Inspect Both Credential Stores (local read, learn-gated)
246
246
 
@@ -252,25 +252,25 @@ api-store domain="api.github.com" → combined secrets + tokens report for the d
252
252
  Read-only inspection of **both credential stores in one call** — the
253
253
  agent-facing view of `/api secrets` + `/api oauth --status`. The authoring
254
254
  question is never "show me tokens" in isolation; it is what credentials exist
255
- for a domain, what's declared vs provisioned vs minted, what's expired, and
256
- what needs minting next.
255
+ for a domain, what's declared vs provisioned vs minted, what's expired, and what
256
+ needs minting next.
257
257
 
258
- - Bare call → the authoring-bootstrap (orphan) view: unscoped secret domains
259
- and token domains with no guide. Token domains resolve through the same
258
+ - Bare call → the authoring-bootstrap (orphan) view: unscoped secret domains and
259
+ token domains with no guide. Token domains resolve through the same
260
260
  store-domain seam minting uses, so an `api.`-subdomain token maps to its
261
261
  parent's guides instead of false-positive as guideless.
262
- - With `domain` (or `apiHost`, resolved the same way) → the combined
263
- per-domain report: provisioned/declared/gap secret names, token slots
264
- (issuer, granted scope, expiry, refreshable), and **declared-slot gaps** —
265
- "guide declares client_credentials via `tokenUrl`: no token minted" — the
266
- pointer to `oauth-mint` that replaces a trial-and-error 401.
262
+ - With `domain` (or `apiHost`, resolved the same way) → the combined per-domain
263
+ report: provisioned/declared/gap secret names, token slots (issuer, granted
264
+ scope, expiry, refreshable), and **declared-slot gaps** — "guide declares
265
+ client_credentials via `tokenUrl`: no token minted" — the pointer to
266
+ `oauth-mint` that replaces a trial-and-error 401.
267
267
 
268
268
  Metadata only: `accessToken`/`refreshToken` are dropped at the collection
269
269
  boundary and secret values never enter the tool — they can't appear in the
270
270
  rendered text **or** the structured `details`. When a token's granted scope
271
- wasn't echoed by the provider, the requested scopes render with an
272
- "(assumed)" marker (RFC 6749 §5.1). Mint via `oauth-mint`; refresh/revoke
273
- stay human-typed (`/api oauth`).
271
+ wasn't echoed by the provider, the requested scopes render with an "(assumed)"
272
+ marker (RFC 6749 §5.1). Mint via `oauth-mint`; refresh/revoke stay human-typed
273
+ (`/api oauth`).
274
274
 
275
275
  ### 7. `oauth-mint` — Human-in-the-Loop OAuth2 Mint (network write, consented)
276
276
 
@@ -280,12 +280,11 @@ oauth-mint domain="github.com" grant="authorization_code" tokenUrl="https://gith
280
280
 
281
281
  The learn-gated mint half of the agent-driven OAuth2 bootstrap. The agent
282
282
  supplies researched params (grant, token/authorize URLs, scopes, client
283
- credentials as **store NAMES**); the tool validates fail-closed, prechecks
284
- the store names, then prompts the human — token-URL confirm (the human is
285
- the trust root for the secret-bearing endpoint), a ✓/○ scopes checklist,
286
- and a paste prompt for the redirect URL (which never enters the
287
- transcript). Any cancel prints the two-call `/api oauth init <domain> …
288
- --code` escape-hatch hint.
283
+ credentials as **store NAMES**); the tool validates fail-closed, prechecks the
284
+ store names, then prompts the human — token-URL confirm (the human is the trust
285
+ root for the secret-bearing endpoint), a ✓/○ scopes checklist, and a paste
286
+ prompt for the redirect URL (which never enters the transcript). Any cancel
287
+ prints the two-call `/api oauth init <domain> … --code` escape-hatch hint.
289
288
 
290
289
  ---
291
290
 
@@ -294,72 +293,71 @@ transcript). Any cancel prints the two-call `/api oauth init <domain> …
294
293
  The simplest case — a public API with no auth — end to end:
295
294
 
296
295
  1. **`/api learn`** — enable the authoring tools.
297
- 2. **Ask your agent to author a guide** — point it at the API's
298
- documentation (a saved spec document or an online docs URL) and say
299
- which endpoints you want. The agent stages a starter template
300
- (`api-learn({domain, new: true})`), fills in the recipe — `apiHost`,
301
- one operation to start, no pagination needed for a single flat
302
- endpoint — and confirms every op block against the spec you supplied.
303
- For an endpoint that isn't documented, the agent calls `api-probe` on
304
- the live URL to draft the YAML op block for your review.
296
+ 2. **Ask your agent to author a guide** — point it at the API's documentation (a
297
+ saved spec document or an online docs URL) and say which endpoints you want.
298
+ The agent stages a starter template (`api-learn({domain, new: true})`), fills
299
+ in the recipe — `apiHost`, one operation to start, no pagination needed for a
300
+ single flat endpoint — and confirms every op block against the spec you
301
+ supplied. For an endpoint that isn't documented, the agent calls `api-probe`
302
+ on the live URL to draft the YAML op block for your review.
305
303
  3. **Review and save** — the agent validates the draft and saves it to
306
- `~/.pi/agent/pi-lean-host/api-guides/<slug(shortName)>/guide.md`
307
- (via `api-learn({domain, dir: …})`).
308
- 4. **Use it** — from now on, just ask your agent for data from that API
309
- in plain language; it calls `api-fetch`, which discovers the guide by
310
- domain and handles URL construction, auth, and pagination. Then run
304
+ `~/.pi/agent/pi-lean-host/api-guides/<slug(shortName)>/guide.md` (via
305
+ `api-learn({domain, dir: …})`).
306
+ 4. **Use it** — from now on, just ask your agent for data from that API in plain
307
+ language; it calls `api-fetch`, which discovers the guide by domain and
308
+ handles URL construction, auth, and pagination. Then run
311
309
  `/api verify <your-domain>` to check every op against the live API — a
312
310
  passing run stamps `verified` on the guide.
313
311
 
314
312
  Auth-gated API? Two additions, both handled before the guide will fetch
315
313
  successfully:
316
314
 
317
- - **Static key** — you provision the value once via `/api secrets <domain>`;
318
- the guide declares it by name with `auth.kind: static-key`. See
315
+ - **Static key** — you provision the value once via `/api secrets <domain>`; the
316
+ guide declares it by name with `auth.kind: static-key`. See
319
317
  [Authentication & Secrets](#authentication--secrets).
320
- - **OAuth2** — `/api bootstrap oauth <domain> <spec>` injects a research
321
- brief and the agent drives `oauth-mint`; you confirm the token URL, tick
322
- the scopes, and paste the redirect URL back. See the `/api bootstrap` row
323
- in the [command table](#api-command--api-toggle).
318
+ - **OAuth2** — `/api bootstrap oauth <domain> <spec>` injects a research brief
319
+ and the agent drives `oauth-mint`; you confirm the token URL, tick the scopes,
320
+ and paste the redirect URL back. See the `/api bootstrap` row in the
321
+ [command table](#api-command--api-toggle).
324
322
 
325
- The complete field reference, pagination styles, and helper contracts live
326
- in [docs/authoring.md](docs/authoring.md).
323
+ The complete field reference, pagination styles, and helper contracts live in
324
+ [docs/authoring.md](docs/authoring.md).
327
325
 
328
326
  ---
329
327
 
330
328
  ## Reference Recipes (caritas)
331
329
 
332
330
  The comprehensive recipe library lives in the
333
- [**caritas**](https://github.com/coreyryanhanson/caritas) repo — real,
334
- verified recipes spanning the no-auth **and keyed** axes, each with a
335
- per-recipe `verified:`-date provenance and the perpetual drift disclaimer.
336
- They are inert reference material: nothing executes until you copy a recipe
337
- into your own `~/.pi/agent/pi-lean-host/api-guides/<slug(shortName)>/`
338
- directory.
331
+ [**caritas**](https://github.com/coreyryanhanson/caritas) repo — real, verified
332
+ recipes spanning the no-auth **and keyed** axes, each with a per-recipe
333
+ `verified:`-date provenance and the perpetual drift disclaimer. They are inert
334
+ reference material: nothing executes until you copy a recipe into your own
335
+ `~/.pi/agent/pi-lean-host/api-guides/<slug(shortName)>/` directory.
339
336
 
340
337
  Host itself ships only a **synthetic axis-guide set** under `api-guides/` —
341
338
  minimal coverage fixtures (no `verified:` date, no live endpoints) that keep
342
339
  every guide-driven framework axis exercised via mocked transport. They are
343
- framework fixtures for host's own tests, not recipes for you to copy
344
- (membership pinned by `__tests__/axis-coverage.test.ts`).
340
+ framework fixtures for host's own tests, not recipes for you to copy (membership
341
+ pinned by `__tests__/axis-coverage.test.ts`).
345
342
 
346
343
  The domains caritas covers (a discoverability index, may drift from the live
347
344
  repo):
348
345
 
349
346
  ```text
350
- arxiv federal-register mastodon twitch-user
351
- boletin-oficial-del-estado frost-server-sensorthings musicbrainz usgs-earthquake
352
- coingecko gbif open-food-facts wayback-availability
353
- data-gov github open-library wayback-cdx-server
354
- datos-gob-es gitlab pubmed-e-utilities wikidata
355
- deutsche-nationalbibliothek inaturalist stripe wikimedia-action
356
- ecb-data-portal internet-archive telegram-bot-api wikipedia-rest
357
- etherscan library-of-congress twitch world-bank-indicators
347
+ arxiv frost-server-sensorthings musicbrainz usgs-earthquake
348
+ boletin-oficial-del-estado gbif open-food-facts wayback-availability
349
+ coingecko github open-library wayback-cdx-server
350
+ data-gov gitlab pubmed-e-utilities wikidata
351
+ datos-gob-es google-drive stripe wikimedia-action
352
+ deutsche-nationalbibliothek inaturalist telegram-bot-api wikipedia-rest
353
+ ecb-data-portal internet-archive twitch world-bank-indicators
354
+ etherscan library-of-congress twitch-user
355
+ federal-register mastodon
358
356
  ```
359
357
 
360
- Several are **keyed** (`auth.kind: static-key`), the spread that exercises
361
- header-vs-query refs and the required/optional split (see [Authentication &
362
- Secrets](#authentication--secrets)).
358
+ The spread covers **no-auth** APIs, **keyed** APIs (`auth.kind: static-key`) and
359
+ **oauth2** (`authorization_code` with refresh tokens) — see
360
+ [Authentication & Secrets](#authentication--secrets).
363
361
 
364
362
  To use them, copy the guides into your own directory from a clone of caritas:
365
363
 
@@ -368,13 +366,13 @@ git clone https://github.com/coreyryanhanson/caritas.git /tmp/caritas
368
366
  cp -r /tmp/caritas/api-guides/* ~/.pi/agent/pi-lean-host/api-guides/
369
367
  ```
370
368
 
371
- To grab a single domain instead of all of them, copy just its folder
372
- (e.g. `.../api-guides/wikipedia-rest`).
369
+ To grab a single domain instead of all of them, copy just its folder (e.g.
370
+ `.../api-guides/wikipedia-rest`).
373
371
 
374
- A recipe may carry `operation.helper: true` plus an accompanying `helper.ts`
375
- in its domain subdir as a worked example. See caritas's `CONTRIBUTING.md`
376
- for contributing a recipe to the library; for authoring one for yourself,
377
- see [docs/authoring.md](docs/authoring.md).
372
+ A recipe may carry `operation.helper: true` plus an accompanying `helper.ts` in
373
+ its domain subdir as a worked example. See caritas's `CONTRIBUTING.md` for
374
+ contributing a recipe to the library; for authoring one for yourself, see
375
+ [docs/authoring.md](docs/authoring.md).
378
376
 
379
377
  ## Configuration (`settings.json`)
380
378
 
@@ -384,15 +382,15 @@ Host settings are read from `~/.pi/agent/settings.json` (global) and
384
382
  ### `toolsetDefaults` (toolset on/off defaults)
385
383
 
386
384
  Whether the API tools are enabled on fresh conversations. Read by the
387
- `pi-tool-masking` library at restore time, between the chat-branch tier and
388
- the toolset's packaged default:
385
+ `pi-tool-masking` library at restore time, between the chat-branch tier and the
386
+ toolset's packaged default:
389
387
 
390
388
  ```jsonc
391
389
  {
392
- "toolsetDefaults": {
393
- "toolset-state:pi-lean-dimension.api": { "enabled": true },
394
- "toolset-state:pi-lean-dimension.api-learn": { "enabled": false }
395
- }
390
+ "toolsetDefaults": {
391
+ "toolset-state:pi-lean-dimension.api": { "enabled": true },
392
+ "toolset-state:pi-lean-dimension.api-learn": { "enabled": false }
393
+ }
396
394
  }
397
395
  ```
398
396
 
@@ -406,8 +404,8 @@ the toolset's packaged default:
406
404
 
407
405
  There is no `host.*` settings block. The transport layer (per-domain undici
408
406
  `Agent` with retry-on-429, redirect policy, timeouts, ETag/`Cache-Control`
409
- caching) is configured internally; `apiHost` and operation paths live **in
410
- the recipe frontmatter**, not in settings. Credentials are **not** stored in
407
+ caching) is configured internally; `apiHost` and operation paths live **in the
408
+ recipe frontmatter**, not in settings. Credentials are **not** stored in
411
409
  `settings.json` — they live in the per-domain secrets store, provisioned via
412
410
  `/api secrets` (see [Authentication & Secrets](#authentication--secrets)).
413
411
 
@@ -415,19 +413,18 @@ the recipe frontmatter**, not in settings. Credentials are **not** stored in
415
413
 
416
414
  ## Co-Installing with `pi-lean-portal`
417
415
 
418
- Portal is fully optional. When co-installed, host registers a **projection**
419
- of its user-authored `ApiGuide`s with portal's guide-source registry at load
420
- time — recipe fields stripped, presentation fields kept — so they **surface
421
- in the navigate footer** in browse mode (`/web on` + `/api on`), the same
422
- reactive mechanism web guides use. Host→portal opt-in; portal never imports
423
- host.
416
+ Portal is fully optional. When co-installed, host registers a **projection** of
417
+ its user-authored `ApiGuide`s with portal's guide-source registry at load time —
418
+ recipe fields stripped, presentation fields kept — so they **surface in the
419
+ navigate footer** in browse mode (`/web on` + `/api on`), the same reactive
420
+ mechanism web guides use. Host→portal opt-in; portal never imports host.
424
421
 
425
422
  - **Host-first ordering.** When both a host guide and a web guide match a
426
- domain, the host guide surfaces first (API access is cheaper, more
427
- reliable, lower-context than browsing). Both still surface; you choose.
428
- Host guides surface only when `/api` is on; web guides only when `/web`
429
- is on. No suppression — partial-coverage APIs keep their web guide for the
430
- gaps the API doesn't cover.
423
+ domain, the host guide surfaces first (API access is cheaper, more reliable,
424
+ lower-context than browsing). Both still surface; you choose. Host guides
425
+ surface only when `/api` is on; web guides only when `/web` is on. No
426
+ suppression — partial-coverage APIs keep their web guide for the gaps the API
427
+ doesn't cover.
431
428
  - **The projection carries one extra field**, `kind: "web" | "api"` (default
432
429
  `"web"`), which portal consumes only for ordering and the footer `reason`
433
430
  string. No recipe-structured data (`apiHost`, `operations`, `pagination`,
@@ -443,46 +440,45 @@ enhancement for co-installs, not a host-only requirement. The on-demand path
443
440
 
444
441
  ### `api-fetch` vs `web-fetch` vs `api-probe`
445
442
 
446
- | Use `api-fetch` | Use `api-probe` | Use `web-fetch` (portal) |
447
- |-----------------|-----------------|--------------------------|
448
- | An API you've guided | Discovering shape before authoring a guide | A one-off unguided fetch against a known URL |
449
- | Repeated/paginated pulls | Drafting an op block from a live endpoint | Reading docs to author a recipe |
443
+ | Use `api-fetch` | Use `api-probe` | Use `web-fetch` (portal) |
444
+ | ------------------------ | ------------------------------------------ | -------------------------------------------- |
445
+ | An API you've guided | Discovering shape before authoring a guide | A one-off unguided fetch against a known URL |
446
+ | Repeated/paginated pulls | Drafting an op block from a live endpoint | Reading docs to author a recipe |
450
447
 
451
- `api-fetch` is the guided path — the guide is the product. It has no
452
- ad-hoc bare-fetch mode on purpose: that would recreate the exact mistakes
453
- the tool exists to prevent. The escape
454
- hatches are `api-learn` (write a guide, then execute through it) and
455
- `web-fetch` (portal) for a one-off.
448
+ `api-fetch` is the guided path — the guide is the product. It has no ad-hoc
449
+ bare-fetch mode on purpose: that would recreate the exact mistakes the tool
450
+ exists to prevent. The escape hatches are `api-learn` (write a guide, then
451
+ execute through it) and `web-fetch` (portal) for a one-off.
456
452
 
457
453
  ---
458
454
 
459
455
  ## Authentication & Secrets
460
456
 
461
- Many read APIs authenticate with a static key (`X-Api-Key`, `Authorization:
462
- Bearer`, or a `?key=` query param). pi-lean-host supports these end-to-end
463
- without the credential ever appearing in the agent's context — a guide
464
- **declares the secret by name**, you provision the value once, and `api-fetch`
465
- injects it in code.
457
+ Many read APIs authenticate with a static key (`X-Api-Key`,
458
+ `Authorization: Bearer`, or a `?key=` query param). pi-lean-host supports these
459
+ end-to-end without the credential ever appearing in the agent's context — a
460
+ guide **declares the secret by name**, you provision the value once, and
461
+ `api-fetch` injects it in code.
466
462
 
467
463
  ### A candid note on storage and threat model
468
464
 
469
465
  The secrets store is **plaintext JSON at rest** — mode `0600`, no encryption.
470
- That matches pi's own posture for its credentials (an API key in
471
- `settings.json` or the env). The threat this guards against is not another
472
- process reading the file; it's accidental **transcript exfiltration**.
473
-
474
- That containment is plugin discipline, not a vault. `read`/`cat` on the
475
- store file is one tool-call from the agent, which runs with your privileges,
476
- so nothing here is a hard guarantee. **That's why the real rule is: store
477
- read-only keys.** Scope every credential to the smallest read surface it needs
478
- (e.g. a GitHub fine-grained token with read-only `contents`). A leaked read
479
- key is a data-exposure incident; a leaked write key is a takeover — and the
480
- plugin is GET-only, so a read-only key is always enough for what it does.
466
+ That matches pi's own posture for its credentials (an API key in `settings.json`
467
+ or the env). The threat this guards against is not another process reading the
468
+ file; it's accidental **transcript exfiltration**.
469
+
470
+ That containment is plugin discipline, not a vault. `read`/`cat` on the store
471
+ file is one tool-call from the agent, which runs with your privileges, so
472
+ nothing here is a hard guarantee. **That's why the real rule is: store read-only
473
+ keys.** Scope every credential to the smallest read surface it needs (e.g. a
474
+ GitHub fine-grained token with read-only `contents`). A leaked read key is a
475
+ data-exposure incident; a leaked write key is a takeover — and the plugin is
476
+ GET-only, so a read-only key is always enough for what it does.
481
477
 
482
478
  ### Guide-side: declare the name, never the value
483
479
 
484
- In `guide.md`, set `auth.kind: static-key` and point at store secrets by name
485
- — the value never lives in the guide (a real key committed there would be one
480
+ In `guide.md`, set `auth.kind: static-key` and point at store secrets by name —
481
+ the value never lives in the guide (a real key committed there would be one
486
482
  `cat` from the agent's context). The full guide-side YAML (`secretRefs` /
487
483
  `secretQueryRefs` / `secretPathRefs`, `prefix`, `optional`, and the
488
484
  parser-enforced invariants) is documented in
@@ -505,60 +501,58 @@ Migrating a guide from the old flat shape (`requires`/`optional` rosters,
505
501
  Provisioning is interactive (`ctx.ui` dialogs — the value is captured
506
502
  **transcript-safely** and written straight to the store, never returned). On
507
503
  headless hosts there is no dialog, so `/api secrets` prints the direct
508
- file-write instructions instead — write a `{ "<name>": "<value>" }` JSON
509
- mapping into the `0600` `<domain>.json` file yourself before pi starts. Secrets persist at
510
- `~/.pi/agent/pi-lean-host/secrets/<domain>.json` (mode `0600`).
504
+ file-write instructions instead — write a `{ "<name>": "<value>" }` JSON mapping
505
+ into the `0600` `<domain>.json` file yourself before pi starts. Secrets persist
506
+ at `~/.pi/agent/pi-lean-host/secrets/<domain>.json` (mode `0600`).
511
507
 
512
508
  ### The status footer
513
509
 
514
510
  Every `api-guide` / `api-fetch` result on an auth-bearing guide (static-key
515
- `secretRefs`/`secretQueryRefs`/`secretPathRefs`, or an `oauth2` token slot)
516
- ends with a
517
- `🔑 auth:` line — `ok`, `requires <name> — not provisioned`, or an optional
518
- state — showing name and presence only, never the value, so it's safe
511
+ `secretRefs`/`secretQueryRefs`/`secretPathRefs`, or an `oauth2` token slot) ends
512
+ with a `🔑 auth:` line — `ok`, `requires <name> — not provisioned`, or an
513
+ optional state — showing name and presence only, never the value, so it's safe
519
514
  anywhere it renders.
520
515
 
521
516
  ## Security & Scope
522
517
 
523
518
  ### SSRF guard (server-supplied URLs only)
524
519
 
525
- Host guards only the one URL path that earns it: `paginate`'s `nextLink`
526
- style, where the next URL comes from the **remote API's response body** — a
527
- URL neither you nor the agent chose. `ssrfGuard()` (a minimal `core/ssrf-guard.ts`,
528
- no deps, no portal import) blocks loopback, private RFC1918 ranges, and cloud
529
- metadata endpoints (`169.254.169.254`, `metadata.google.internal`,
530
- `100.100.100.200`) on that server-supplied `nextUrl` before it is followed.
520
+ Host guards only the one URL path that earns it: `paginate`'s `nextLink` style,
521
+ where the next URL comes from the **remote API's response body** — a URL neither
522
+ you nor the agent chose. `ssrfGuard()` (a minimal `core/ssrf-guard.ts`, no deps,
523
+ no portal import) blocks loopback, private RFC1918 ranges, and cloud metadata
524
+ endpoints (`169.254.169.254`, `metadata.google.internal`, `100.100.100.200`) on
525
+ that server-supplied `nextUrl` before it is followed.
531
526
 
532
527
  Agent-supplied URLs are **not** guarded. `restGet` assembles a URL from
533
- `apiHost` + `operation.path` + query params — all agent- or user-directed.
534
- The agent runs on your own machine with your own privileges and has `bash`,
535
- `read`, and `write` over the filesystem; blocking `http://169.254.169.254/`
536
- on `restGet` while `curl` is one tool-call away is a sieve with one hole
537
- patched. With keyed auth shipped, the guard is now **load-bearing**: a server-supplied
538
- `nextUrl` to an internal host would leak the attached `Authorization` header,
539
- and any keyed `restGet`/`paginate` that redirects is forced through the
540
- guarded loop — with injected secrets stripped on a cross-domain hop — so the
541
- channel stays closed.
528
+ `apiHost` + `operation.path` + query params — all agent- or user-directed. The
529
+ agent runs on your own machine with your own privileges and has `bash`, `read`,
530
+ and `write` over the filesystem; blocking `http://169.254.169.254/` on `restGet`
531
+ while `curl` is one tool-call away is a sieve with one hole patched. With keyed
532
+ auth shipped, the guard is now **load-bearing**: a server-supplied `nextUrl` to
533
+ an internal host would leak the attached `Authorization` header, and any keyed
534
+ `restGet`/`paginate` that redirects is forced through the guarded loop — with
535
+ injected secrets stripped on a cross-domain hop — so the channel stays closed.
542
536
 
543
537
  ### v1 scope (what it is not)
544
538
 
545
- - **GET-read only.** No mutation helper. Add one only when a real *retrieval*
539
+ - **GET-read only.** No mutation helper. Add one only when a real _retrieval_
546
540
  guide needs it (e.g. a search-then-fetch POST), behind a real auth-review
547
541
  gate.
548
542
  - **GET-read auth surface.** `auth.kind: static-key` (store-backed
549
543
  header/query-param secrets) and `auth.kind: oauth2` (`client_credentials`
550
- - paste-based `authorization_code`) are realized; cookie-login stays
551
- deferred. See [Authentication & Secrets](#authentication--secrets).
544
+ - paste-based `authorization_code`) are realized; cookie-login stays deferred.
545
+ See [Authentication & Secrets](#authentication--secrets).
552
546
 
553
547
  ### Mission
554
548
 
555
- `pi-lean-host` is a navigation and information-retrieval aide. It exists to
556
- help an agent obtain information from structured APIs with as little friction
557
- as possible — not to author content or automate online actions. Features
558
- whose primary value is creating, mutating, or bot-automating will not be
559
- added, even when technically feasible, unless they serve retrieval. The
560
- local-helper escape hatch means a capable user *can* build bots on their own
561
- machine; the package does not aim to make that easy.
549
+ `pi-lean-host` is a navigation and information-retrieval aide. It exists to help
550
+ an agent obtain information from structured APIs with as little friction as
551
+ possible — not to author content or automate online actions. Features whose
552
+ primary value is creating, mutating, or bot-automating will not be added, even
553
+ when technically feasible, unless they serve retrieval. The local-helper escape
554
+ hatch means a capable user _can_ build bots on their own machine; the package
555
+ does not aim to make that easy.
562
556
 
563
557
  ---
564
558