pi-lean-host 0.2.0 → 0.3.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 +113 -117
- package/core/api-guide-types.ts +39 -0
- package/core/api-toggle.ts +23 -1
- package/core/auth.ts +42 -5
- package/core/delete-command.ts +190 -0
- package/core/guide-picker.ts +104 -0
- package/core/guide-store.ts +0 -26
- package/core/helpers-command.ts +2 -4
- package/core/helpers.ts +72 -24
- package/core/local-helpers.ts +2 -1
- package/core/parse-api-guide.ts +491 -57
- package/core/path-template.ts +30 -1
- package/core/resolve-op.ts +222 -0
- package/core/secrets-command.ts +25 -2
- package/core/secrets-store.ts +11 -1
- package/core/ssrf-guard.ts +5 -0
- package/core/transport.ts +2 -16
- package/core/verify-command.ts +399 -0
- package/package.json +15 -1
- package/tools/api-fetch.ts +147 -233
- package/tools/api-guide.ts +35 -46
- package/tools/api-learn.ts +438 -125
- package/tools/api-probe.ts +501 -88
- package/tools/utils.ts +21 -0
package/README.md
CHANGED
|
@@ -20,11 +20,11 @@
|
|
|
20
20
|
> SearXNG search, install
|
|
21
21
|
> [`pi-lean-search`](https://www.npmjs.com/package/pi-lean-search).
|
|
22
22
|
|
|
23
|
-
> ⚠️ **Early release (0.
|
|
23
|
+
> ⚠️ **Early release (0.3.0).** The API tools here work today, but this is a
|
|
24
24
|
> development preview. The recipe schema, tool surfaces, and guide format are
|
|
25
25
|
> still settling as we test more APIs to finalize the shape — **future
|
|
26
26
|
> compatibility is not guaranteed** until the package reaches lockstep with
|
|
27
|
-
> `pi-lean-dimension` 0.5.0. Guides authored against 0.
|
|
27
|
+
> `pi-lean-dimension` 0.5.0. Guides authored against 0.3.x may need revision
|
|
28
28
|
> as the schema firms up.
|
|
29
29
|
|
|
30
30
|
---
|
|
@@ -67,7 +67,8 @@ From a fresh install you have no guides yet, so the workflow is:
|
|
|
67
67
|
1. **`/api learn`** — enable the authoring tools (`api-learn` + `api-probe`).
|
|
68
68
|
2. **`api-probe({apiHost, path})`** — discover the shape of a not-yet-guided
|
|
69
69
|
endpoint; it drafts a YAML operation block to paste into a recipe.
|
|
70
|
-
3. **`api-learn({domain,
|
|
70
|
+
3. **`api-learn({domain, recipeFile})`** — validate the staged draft and write
|
|
71
|
+
the guide to
|
|
71
72
|
`~/.pi/agent/pi-lean-host/api-guides/<domain>/guide.md`.
|
|
72
73
|
4. **`api-fetch({domain, operation})`** — execute and verify.
|
|
73
74
|
|
|
@@ -127,13 +128,14 @@ demand. A skill is pure text with no in-process eval, whereas a loaded
|
|
|
127
128
|
|------|----------------|---------------|-------------------|-------|
|
|
128
129
|
| Built-in helpers | package source (`core/`) | maintainers | yes | reviewed |
|
|
129
130
|
| Local user helpers | `~/.pi/agent/pi-lean-host/api-guides/<domain>/helper.ts` | you, or the agent in `/api learn` | no | user-owned |
|
|
130
|
-
| Bundled recipes | `api-guides/<domain>/`
|
|
131
|
+
| Bundled recipes | `caritas` repo (`api-guides/<domain>/`) | maintainers | no (reference) | **inert — never auto-executed** |
|
|
131
132
|
|
|
132
133
|
Built-in helpers cover the common 90%. Local user helpers cover the weird 10%
|
|
133
134
|
(computed signatures, strange date transforms, custom auth). Bundled recipes
|
|
134
|
-
are inert reference material
|
|
135
|
-
from the package. You adopt one by
|
|
136
|
-
own directory; only then does it
|
|
135
|
+
are inert reference material in the [`caritas`](https://github.com/coreyryanhanson/caritas)
|
|
136
|
+
repo — the loader never reads `api-guides/` from the package. You adopt one by
|
|
137
|
+
copying the whole domain folder into your own directory; only then does it
|
|
138
|
+
load and execute.
|
|
137
139
|
|
|
138
140
|
---
|
|
139
141
|
|
|
@@ -152,6 +154,8 @@ touches the other's tools.
|
|
|
152
154
|
| `/api status` | Detailed runtime status — state, active guides, domains, helpers. |
|
|
153
155
|
| `/api helpers` | List local user helpers (or `/api helpers <domain>` to view one's source). |
|
|
154
156
|
| `/api secrets [<domain> [<name>]]` | Manage stored API secrets — list, provision, delete (see [Authentication & Secrets](#authentication--secrets)). |
|
|
157
|
+
| `/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](#recipe-drift)). |
|
|
158
|
+
| `/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. |
|
|
155
159
|
|
|
156
160
|
### Why a peer toggle?
|
|
157
161
|
|
|
@@ -234,22 +238,33 @@ one) — turning a failed execute into a discovery moment in one round-trip.
|
|
|
234
238
|
### 3. `api-learn` — Author / Update a Guide (local write)
|
|
235
239
|
|
|
236
240
|
```text
|
|
237
|
-
api-learn →
|
|
238
|
-
api-learn domain="
|
|
241
|
+
api-learn → field reference + pointer to the starter template
|
|
242
|
+
api-learn domain="arxiv.org" new=true → stages a fresh placeholder template to /tmp/pi-lean-host/arxiv.org/guide.md
|
|
243
|
+
api-learn domain="arxiv.org" → fetches an existing guide's raw recipe into the staged file
|
|
244
|
+
api-learn domain="arxiv.org" recipeFile="/tmp/pi-lean-host/arxiv.org/guide.md" → validates + writes the guide to disk
|
|
239
245
|
```
|
|
240
246
|
|
|
241
|
-
- No parameters → a
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
247
|
+
- No parameters → a concise field reference plus a pointer to
|
|
248
|
+
`{domain, new: true}` for a domain-specific starter template.
|
|
249
|
+
- `{domain, new: true}` → a fresh starter template with `domains: [<domain>]`
|
|
250
|
+
**staged to `/tmp/pi-lean-host/<domain>/guide.md`**. Only `domains` is real;
|
|
251
|
+
the other fields are `<placeholder>` values that **fail closed**, so a
|
|
252
|
+
pasted template cannot save until you fill it in.
|
|
253
|
+
- `{domain}` (no `recipeFile`) → fetch the current raw recipe of an existing
|
|
254
|
+
guide into the staged file (surfaces `dirName` to prevent sibling-clobber
|
|
255
|
+
in multi-recipe domains); a disambiguation menu if several guides claim the
|
|
256
|
+
domain.
|
|
257
|
+
- `{domain, recipeFile}` → reads the staged draft, validates it **before**
|
|
258
|
+
touching disk, then writes to
|
|
259
|
+
`~/.pi/agent/pi-lean-host/api-guides/<domain>/guide.md`, overwriting any
|
|
260
|
+
existing guide for that domain. On a structural error it names the field,
|
|
261
|
+
the expected shape, and what was found — the file on disk is left untouched
|
|
262
|
+
(no half-written guide). Requires `/api learn`.
|
|
263
|
+
|
|
264
|
+
The working copy is staged at `/tmp/pi-lean-host/<domain>/guide.md` (`/tmp`
|
|
265
|
+
self-cleans, so drafts don't accumulate) — fetch/template calls write the
|
|
266
|
+
draft there and you edit that file between saves; saving reads it and
|
|
267
|
+
publishes to the guides dir. No session-held state, no `/api save`.
|
|
253
268
|
|
|
254
269
|
### 4. `api-probe` — Discover an Endpoint's Shape (network read, exploratory)
|
|
255
270
|
|
|
@@ -262,7 +277,18 @@ real transport (same UA, charset, 429-retry, ETag cache as `api-fetch` — the
|
|
|
262
277
|
sanctioned way to reach even WAF'd hosts), summarizes the JSON shape, suggests
|
|
263
278
|
`via` / `itemsPath` / pagination style, echoes a representative record id, and
|
|
264
279
|
emits a **draft YAML operation block** to paste straight into a recipe. On 404
|
|
265
|
-
it
|
|
280
|
+
it walks the `apiHost` version backward (e.g. `/v3` → `/v2` → `/v1`) to recover
|
|
281
|
+
an over-claimed version; a draft carries the version prefix that was actually
|
|
282
|
+
fetched (disable with `walkVersions=false`). A stale version that still
|
|
283
|
+
returns 200 is not detected as old — read the provider's docs to supply the
|
|
284
|
+
newest version up front.
|
|
285
|
+
|
|
286
|
+
Pass `scaffold: true` to emit a **full recipe skeleton** (frontmatter +
|
|
287
|
+
`auth:` translated from the inline auth block + a draft op block) instead of
|
|
288
|
+
just the op block — opt-in, and auto-degrades by guide count (0 guides →
|
|
289
|
+
skeleton, 1/N → op block + a merge note). The scaffolded `schemaVersion`
|
|
290
|
+
matches what `api-learn` stamps on save, so the guide is detection-ready the
|
|
291
|
+
moment it's saved.
|
|
266
292
|
|
|
267
293
|
`api-probe` only **suggests** — it never writes the guide. The operation must
|
|
268
294
|
still be traceable to your plan source (the API docs or a working curl
|
|
@@ -278,68 +304,20 @@ agent (advisory). `api-fetch` reads the recipe slice and executes against it;
|
|
|
278
304
|
`api-guide` reads the detail slice for introspection. **The prose is
|
|
279
305
|
advisory, the frontmatter is authoritative.**
|
|
280
306
|
|
|
281
|
-
###
|
|
307
|
+
### File shape
|
|
282
308
|
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
icon: ⚖️
|
|
288
|
-
shortName: BOE
|
|
289
|
-
updated: 2026-07-17
|
|
290
|
-
# organization: boe.es # optional — org identity across guides
|
|
291
|
-
# description: BOE open-data API. # optional — ≤200 chars, one line; aids disambiguation
|
|
292
|
-
apiHost: https://apidatos.boe.es/v1
|
|
293
|
-
verified: 2026-07-17
|
|
294
|
-
gatherAllMax: 500
|
|
295
|
-
|
|
296
|
-
auth:
|
|
297
|
-
kind: none
|
|
298
|
-
|
|
299
|
-
pagination:
|
|
300
|
-
style: offset-limit
|
|
301
|
-
pageParam: page
|
|
302
|
-
pageSizeParam: limit
|
|
303
|
-
pageSize: 50
|
|
304
|
-
itemsPath: data
|
|
305
|
-
# totalCountPath: meta.totalCount # optional, any style → server total in the footer
|
|
306
|
-
|
|
307
|
-
responseShape:
|
|
308
|
-
format: json
|
|
309
|
-
charset: utf-8
|
|
310
|
-
|
|
311
|
-
operations:
|
|
312
|
-
- name: searchDiary
|
|
313
|
-
via: restGet
|
|
314
|
-
path: /diario/{date}
|
|
315
|
-
accept: json
|
|
316
|
-
params:
|
|
317
|
-
limit:
|
|
318
|
-
default: 50
|
|
319
|
-
helper: true # run this domain's local helper.ts for this op
|
|
320
|
-
parse:
|
|
321
|
-
format: xml
|
|
322
|
-
charset: iso-8859-1
|
|
323
|
-
|
|
324
|
-
- name: listConsolidada
|
|
325
|
-
via: paginate
|
|
326
|
-
path: /legislacion-consolidada
|
|
327
|
-
accept: json
|
|
328
|
-
pagination:
|
|
329
|
-
style: cursor
|
|
330
|
-
cursorParam: cursor
|
|
331
|
-
cursorPath: pagination.nextCursor
|
|
332
|
-
itemsPath: results
|
|
333
|
-
gatherAllMax: 1000 # op-level ceiling override
|
|
334
|
-
---
|
|
335
|
-
# BOE Legislación Consolidada — structured API access
|
|
309
|
+
A `guide.md` opens with a `---`-delimited YAML frontmatter block and
|
|
310
|
+
closes it with a second `---`; the prose body follows. An operation can
|
|
311
|
+
override the guide-level `pagination` / `responseShape` with its own block
|
|
312
|
+
in the frontmatter.
|
|
336
313
|
|
|
337
|
-
|
|
338
|
-
`
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
314
|
+
The fastest way to a first guide is to let the tools draft it:
|
|
315
|
+
`api-learn({domain, new: true})` returns a fail-closed starter template,
|
|
316
|
+
and `api-probe({scaffold: true})` emits a full skeleton from a live
|
|
317
|
+
endpoint — fill the placeholders, then save with `api-learn`. For
|
|
318
|
+
**complete worked recipes** (real endpoints, `verified:` provenance,
|
|
319
|
+
auth-in-place, helper examples), see the [Caritas](#bundled-reference-recipes)
|
|
320
|
+
recipe library and copy a domain folder that matches your target.
|
|
343
321
|
|
|
344
322
|
### Field reference
|
|
345
323
|
|
|
@@ -352,11 +330,13 @@ laws (capped at 1000 by the op override). The `boe-datefmt` helper formats the
|
|
|
352
330
|
| `organization` | guide | — | optional org identity (registrable domain); catalog grouping + disambiguation. Recipe-slice only |
|
|
353
331
|
| `description` | guide | — | optional one-line summary (≤200 chars); primary disambiguation signal for multi-guide domains |
|
|
354
332
|
| `docs` | guide | — | optional canonical API documentation URL (http/https); surfaced in api-guide detail |
|
|
355
|
-
| `verified` | guide | creation date | drift signal — **defaulted, not enforced
|
|
333
|
+
| `verified` | guide | creation date | drift signal — **defaulted, not enforced**; stamped on success by `/api verify` |
|
|
334
|
+
| `schemaVersion` | guide | `0` (floor) | breaking-change detection — stamped on save by `api-learn`; a stale guide (`< current`) gets a non-blocking `⚠` warning in `api-guide`/`api-fetch`, **never a gate** |
|
|
356
335
|
| `gatherAllMax` | guide / op | `1000` | `gatherAll` ceiling; an op can override |
|
|
357
336
|
| `auth.kind` | guide | `none` | `none` \| `static-key` (store-backed header/query secrets). `oauth2` is a declared-but-unrealized seam (rejected at parse) |
|
|
358
337
|
| `auth.headers` | guide | — | literal extra headers merged into every request (e.g. X-Api-Key: DEMO_KEY) — **literal values only**, never the path for real credentials |
|
|
359
338
|
| `auth.secretRefs` | guide | — | `Record<headerName, secretName>` — store-backed header injection (`static-key`) |
|
|
339
|
+
| `auth.headerPrefixes` | guide | — | `Record<headerName, prefix>` — prefix prepended to a secretRefs header value, e.g. `Authorization: "Bearer "` (store holds the raw credential) |
|
|
360
340
|
| `auth.secretQueryRefs` | guide | — | `Record<paramName, secretName>` — store-backed query-param injection (`static-key`) |
|
|
361
341
|
| `auth.requires` | guide | — | secret names the guide hard-requires; absent → `api-fetch` fails closed before the request |
|
|
362
342
|
| `auth.optional` | guide | — | secret names used if present, skipped if absent (e.g. GitHub rate-limit token) |
|
|
@@ -373,6 +353,7 @@ laws (capped at 1000 by the op override). The `boe-datefmt` helper formats the
|
|
|
373
353
|
| `operations[].dateParams` | op | — | optional `{param: format}` → normalizes ISO dates to `iso8601` \| `yyyymmdd` \| `yyyy-mm-dd` (query params only) |
|
|
374
354
|
| `operations[].helper` | op | `false` | `true` runs this domain's local helper for the op |
|
|
375
355
|
| `operations[].transform` | op | `false` | `true` runs the helper's `transform` export on the parsed response (graceful — a throw returns raw data, never disables the op) |
|
|
356
|
+
| `operations[].requiresAnyOf` | op | — | `[param, ...]` — at least one of these params must be supplied (single group per op, v1; members are plain optional params — not `required: true`, not `default`-bearing: both rejected at parse) |
|
|
376
357
|
| `operations[].passthrough` | op | `false` | `true` forwards undeclared caller params onto the query string (for open-param APIs) |
|
|
377
358
|
| `operations[].parse` | op | inherits `responseShape` | op-level override of format/charset |
|
|
378
359
|
| `operations[].pagination` | op | inherits top-level | op-level override of pagination |
|
|
@@ -405,7 +386,10 @@ loader enforces:
|
|
|
405
386
|
- The `verified` frontmatter date records when a guide was last verified
|
|
406
387
|
against the live API (defaulted to creation date, **never enforced**). It's
|
|
407
388
|
rendered in the guide-detail footer alongside the current date — the agent
|
|
408
|
-
reads both and judges.
|
|
389
|
+
reads both and judges. `/api verify <domain>` runs every runnable op
|
|
390
|
+
against the live API and stamps `verified` on success (strict: any
|
|
391
|
+
runnable-op failure → no stamp; skipped ops named in the report; `--force`
|
|
392
|
+
is human-typed only, no agent tool surface).
|
|
409
393
|
- The **live HTTP response is the actual drift signal.** A 401 on a no-auth
|
|
410
394
|
guide, a 404 on a pinned path, a changed response shape — the agent reads
|
|
411
395
|
those directly. The `verified` date is predictive; the response is actual.
|
|
@@ -505,11 +489,11 @@ Authoring is via `api-learn` in learn mode, or hand-editing the file.
|
|
|
505
489
|
## Pagination Styles
|
|
506
490
|
|
|
507
491
|
`paginate` follows the style declared in the recipe. Six styles cover the
|
|
508
|
-
patterns the
|
|
492
|
+
patterns the recipe library (caritas) pressure-tested:
|
|
509
493
|
|
|
510
494
|
| Style | What it sends | Key fields |
|
|
511
495
|
|-------|---------------|------------|
|
|
512
|
-
| `offset-limit` | absolute offset + page size | `pageParam`, `pageSizeParam`, `pageSize`, `itemsPath` |
|
|
496
|
+
| `offset-limit` | absolute offset + page size | `pageParam`, `pageSizeParam`, `pageSize`, `base`, `itemsPath` |
|
|
513
497
|
| `page` | 1-based page number + page size | same fields as `offset-limit` (semantic difference only) |
|
|
514
498
|
| `nextLink` | follows a URL from the response body | `nextLinkPath`, `itemsPath` — the **only** SSRF-guarded path (see [Security](#security--scope)) |
|
|
515
499
|
| `cursor` | echoes an opaque cursor query param | `cursorParam`, `cursorPath`, `itemsPath` |
|
|
@@ -532,7 +516,7 @@ Agents mangle encodings constantly; `parseResponse` fixes it once. Declared
|
|
|
532
516
|
per-guide (top-level `responseShape`) and overridable per-op (`parse:`):
|
|
533
517
|
|
|
534
518
|
- `format: json | xml | text` — XML is converted to JSON via `fast-xml-parser`; `text` is raw passthrough.
|
|
535
|
-
- `charset: utf-8 | <IANA name>` — the transport decodes using the response's Content-Type charset, falling back to this value when the header omits one (essential for Latin-1 / ISO-8859-1 APIs
|
|
519
|
+
- `charset: utf-8 | <IANA name>` — the transport decodes using the response's Content-Type charset, falling back to this value when the header omits one (essential for Latin-1 / ISO-8859-1 APIs that serve bytes without a charset parameter). An explicit header charset always wins.
|
|
536
520
|
- `accept` (request-side, on each operation) is declared **independently**
|
|
537
521
|
from `responseShape.format` (response-side) — they usually match but an API
|
|
538
522
|
may return XML regardless of `Accept`, so they're separate fields.
|
|
@@ -562,9 +546,15 @@ you know you're in disambiguation territory.
|
|
|
562
546
|
|
|
563
547
|
## Bundled Reference Recipes
|
|
564
548
|
|
|
565
|
-
The
|
|
566
|
-
**
|
|
567
|
-
|
|
549
|
+
The comprehensive recipe library lives in the
|
|
550
|
+
[**caritas**](https://github.com/coreyryanhanson/caritas) repo — real,
|
|
551
|
+
verified recipes spanning the no-auth **and keyed** axes, each with a
|
|
552
|
+
per-recipe `verified:`-date provenance and the perpetual drift disclaimer.
|
|
553
|
+
They are inert reference material: nothing executes until you copy a recipe
|
|
554
|
+
into your own `~/.pi/agent/pi-lean-host/api-guides/<domain>/` directory.
|
|
555
|
+
|
|
556
|
+
The domains caritas covers (a discoverability index, may drift from the live
|
|
557
|
+
repo):
|
|
568
558
|
|
|
569
559
|
```
|
|
570
560
|
api.gbif.org api.github.com archive.org archive.org-wayback
|
|
@@ -575,19 +565,15 @@ musicbrainz.org openlibrary.org resources.data.gov servi
|
|
|
575
565
|
web.archive.org www.federalregister.gov www.wikidata.org
|
|
576
566
|
```
|
|
577
567
|
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
required/optional split (see [Authentication & Secrets](#authentication--secrets)).
|
|
568
|
+
Several are **keyed** (`auth.kind: static-key`), the spread that exercises
|
|
569
|
+
header-vs-query refs and the required/optional split (see [Authentication &
|
|
570
|
+
Secrets](#authentication--secrets)).
|
|
582
571
|
|
|
583
|
-
To use them, copy the guides into your own directory from a
|
|
584
|
-
the feature branch ([browse the folder on GitHub](https://github.com/coreyryanhanson/pi-lean-dimension/tree/feat/pi-lean-host-package/packages/pi-lean-host/api-guides)):
|
|
572
|
+
To use them, copy the guides into your own directory from a clone of caritas:
|
|
585
573
|
|
|
586
574
|
```bash
|
|
587
|
-
git clone
|
|
588
|
-
|
|
589
|
-
cp -r /tmp/pi-lean-dimension/packages/pi-lean-host/api-guides/* \
|
|
590
|
-
~/.pi/agent/pi-lean-host/api-guides/
|
|
575
|
+
git clone https://github.com/coreyryanhanson/caritas.git /tmp/caritas
|
|
576
|
+
cp -r /tmp/caritas/api-guides/* ~/.pi/agent/pi-lean-host/api-guides/
|
|
591
577
|
```
|
|
592
578
|
|
|
593
579
|
To grab a single domain instead of all of them, copy just its folder
|
|
@@ -596,11 +582,16 @@ To grab a single domain instead of all of them, copy just its folder
|
|
|
596
582
|
Only then does it load and execute. A recipe may carry
|
|
597
583
|
`operation.helper: true` plus an accompanying `helper.ts` in its domain
|
|
598
584
|
subdir as a worked example — but it stays inert until you copy the folder.
|
|
599
|
-
See
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
585
|
+
See caritas's `CONTRIBUTING.md` for authoring a recipe.
|
|
586
|
+
|
|
587
|
+
### What host ships instead
|
|
588
|
+
|
|
589
|
+
Host itself ships only a **synthetic axis-guide set** under `api-guides/` —
|
|
590
|
+
minimal coverage fixtures (no `verified:` date, no live endpoints) that keep
|
|
591
|
+
every guide-driven framework axis exercised via mocked transport. They are
|
|
592
|
+
framework fixtures for host's own tests, not recipes for you to copy. The
|
|
593
|
+
membership is pinned by `__tests__/axis-coverage.test.ts` (which encodes the
|
|
594
|
+
axis-set audit matrix).
|
|
604
595
|
|
|
605
596
|
---
|
|
606
597
|
|
|
@@ -673,12 +664,10 @@ the recipe frontmatter**, not in settings. Credentials are **not** stored in
|
|
|
673
664
|
|
|
674
665
|
## Co-Installing with `pi-lean-portal`
|
|
675
666
|
|
|
676
|
-
> **Planned for a future release.** Portal integration is
|
|
677
|
-
>
|
|
678
|
-
>
|
|
679
|
-
>
|
|
680
|
-
> Host-side projection code is present but inert until portal ships the
|
|
681
|
-
> receiving global (`__piLeanPortalRegisterGuideProvider`).
|
|
667
|
+
> **Planned for a future release.** Portal integration is not yet shipped:
|
|
668
|
+
> the projection and navigate-footer surfacing described below are what that
|
|
669
|
+
> release delivers. Host-side projection code is present but inert until
|
|
670
|
+
> portal ships the receiving global (`__piLeanPortalRegisterGuideProvider`).
|
|
682
671
|
|
|
683
672
|
Portal is fully optional. When co-installed, host registers a **projection**
|
|
684
673
|
of its user-authored `ApiGuide`s with portal's guide-source registry at load
|
|
@@ -778,10 +767,18 @@ auth:
|
|
|
778
767
|
requires: [api_key] # absent → api-fetch fails closed
|
|
779
768
|
# secretQueryRefs: { apikey: api_key } # query-param injection (?key=)
|
|
780
769
|
# optional: [api_key] # used if present, skipped if absent
|
|
770
|
+
# headerPrefixes: # headerName → prefix for scheme-style headers
|
|
771
|
+
# Authorization: "Bearer " # (GitHub/GitLab) — the store holds the
|
|
772
|
+
# # RAW token; the guide adds the prefix
|
|
781
773
|
```
|
|
782
774
|
|
|
783
775
|
- **`auth.secretRefs`** — `Record<headerName, secretName>`: inject the store
|
|
784
776
|
value into that request header.
|
|
777
|
+
- **`auth.headerPrefixes`** — `Record<headerName, prefix>`: prepend a scheme
|
|
778
|
+
prefix to the resolved value for that header (e.g. `Authorization: "Bearer "`).
|
|
779
|
+
The store holds the **raw credential**; the guide declares how it is
|
|
780
|
+
presented. Absent = verbatim value. Every key must also be a `secretRefs`
|
|
781
|
+
header (parser-enforced).
|
|
785
782
|
- **`auth.secretQueryRefs`** — `Record<paramName, secretName>`: inject the
|
|
786
783
|
store value as that query param.
|
|
787
784
|
- **`auth.requires`** — names the guide **hard-requires**. If one is absent
|
|
@@ -825,9 +822,10 @@ never the value, so it's safe anywhere it renders.
|
|
|
825
822
|
`api-probe` accepts an inline `auth` block (injection fields only) plus a
|
|
826
823
|
`domain` selector, so you can prove a keyed shape before writing the guide —
|
|
827
824
|
a store miss reports the name and fetches unauthenticated (authoring is
|
|
828
|
-
human-in-the-loop, not fail-closed).
|
|
829
|
-
|
|
830
|
-
|
|
825
|
+
human-in-the-loop, not fail-closed). A learn-gated `listSecrets: true` mode
|
|
826
|
+
lists provisioned secret names (names only) to close the authoring bootstrap
|
|
827
|
+
gap; a bare `listSecrets` call (no `domain`, no `apiHost`) lists
|
|
828
|
+
provisioned-but-guideless store domains first.
|
|
831
829
|
|
|
832
830
|
## Security & Scope
|
|
833
831
|
|
|
@@ -882,8 +880,6 @@ machine; the package does not aim to make that easy.
|
|
|
882
880
|
> [pi-lean-dimension](https://github.com/coreyryanhanson/pi-lean-dimension)
|
|
883
881
|
> web-tools suite. For the security model behind the secrets store (the
|
|
884
882
|
> two-threat model and the output-channel audit), see
|
|
885
|
-
> [Authentication & Secrets](#authentication--secrets).
|
|
886
|
-
> escape-valve policy and the 23-recipe spread, see
|
|
887
|
-
> [`docs/design/api-helper-escape-valve.md`](docs/design/api-helper-escape-valve.md).
|
|
883
|
+
> [Authentication & Secrets](#authentication--secrets).
|
|
888
884
|
>
|
|
889
885
|
> License: AGPL-3.0-only
|
package/core/api-guide-types.ts
CHANGED
|
@@ -19,6 +19,14 @@ import type { Guide } from "./guide-loader.js";
|
|
|
19
19
|
*/
|
|
20
20
|
export const GATHER_ALL_MAX_FALLBACK = 1000;
|
|
21
21
|
|
|
22
|
+
/**
|
|
23
|
+
* The schema version of the guide recipe format. Metadata-only attribution:
|
|
24
|
+
* it is surfaced on the parsed guide but NEVER gates/warns/alters parse
|
|
25
|
+
* (see __tests__/schema-version.test.ts). Absent frontmatter defaults to the
|
|
26
|
+
* semantic 0. Bumped to 1 at lockstep (a label change, not a break).
|
|
27
|
+
*/
|
|
28
|
+
export const GUIDE_SCHEMA_VERSION = 0 as const;
|
|
29
|
+
|
|
22
30
|
/** Auth strategies recognized by the schema (the seam). v1 realizes `none` and `static-key`; `oauth2` is rejected at parse. */
|
|
23
31
|
export const KNOWN_AUTH_KINDS: ReadonlySet<string> = new Set([
|
|
24
32
|
"none",
|
|
@@ -43,6 +51,14 @@ export interface AuthConfig {
|
|
|
43
51
|
* `requires` or `optional` (parser-enforced).
|
|
44
52
|
*/
|
|
45
53
|
secretRefs?: Record<string, string>;
|
|
54
|
+
/**
|
|
55
|
+
* static-key only: maps request header name → prefix string prepended to
|
|
56
|
+
* the stored secret value before it is sent. The store holds the raw
|
|
57
|
+
* credential; the guide declares how it is presented (e.g.
|
|
58
|
+
* `Authorization: "Bearer "`). Absent = verbatim value. Every key must
|
|
59
|
+
* also appear in `secretRefs` (parser-enforced).
|
|
60
|
+
*/
|
|
61
|
+
headerPrefixes?: Record<string, string>;
|
|
46
62
|
/**
|
|
47
63
|
* static-key only: maps query param name → secret store name.
|
|
48
64
|
* Values are injected below the agent-supplied params map at fetch time
|
|
@@ -81,6 +97,14 @@ export interface PaginationConfig {
|
|
|
81
97
|
pageSizeParam?: string;
|
|
82
98
|
/** offset-limit / page: requested page size. */
|
|
83
99
|
pageSize?: number;
|
|
100
|
+
/**
|
|
101
|
+
* offset-limit / page: the seed value for the page param — where this
|
|
102
|
+
* API's index starts (e.g. `base: 1` for 1-based offset APIs). Used only
|
|
103
|
+
* as the pagination seed; the seed precedence is caller value → `base` →
|
|
104
|
+
* the param `default` → the style fallback (0 for offset-limit, 1 for
|
|
105
|
+
* page). Accepted but never read by the non-seeding styles.
|
|
106
|
+
*/
|
|
107
|
+
base?: number;
|
|
84
108
|
/** nextLink: JSON path to the next-page URL. */
|
|
85
109
|
nextLinkPath?: string;
|
|
86
110
|
/** cursor: the cursor query param name. */
|
|
@@ -150,6 +174,15 @@ export interface Operation {
|
|
|
150
174
|
* the model via api-guide only.
|
|
151
175
|
*/
|
|
152
176
|
pathParamDocs?: Record<string, string>;
|
|
177
|
+
/**
|
|
178
|
+
* At-least-one-of constraint: at least one of these param names must be
|
|
179
|
+
* supplied. Members may not be `required: true` nor carry a `default`
|
|
180
|
+
* (both parser-enforced) — they are mutually exclusive peers, so a
|
|
181
|
+
* default would fire alongside a caller-supplied sibling and a
|
|
182
|
+
* `required` flag would defeat the group. One group per op (v1); a
|
|
183
|
+
* multi-group `requiresAnyOfGroups` upgrade is purely additive.
|
|
184
|
+
*/
|
|
185
|
+
requiresAnyOf?: string[];
|
|
153
186
|
/**
|
|
154
187
|
* Whether this operation uses the domain's local helper (coarse, pre-call).
|
|
155
188
|
* A `true` value means call `<guidesDir>/<domain>/helper.ts` for this op.
|
|
@@ -190,6 +223,12 @@ export interface Operation {
|
|
|
190
223
|
*/
|
|
191
224
|
export interface ApiGuide extends Guide {
|
|
192
225
|
kind: "api";
|
|
226
|
+
/**
|
|
227
|
+
* Recipe schema version (attribution, not enforcement — see
|
|
228
|
+
* GUIDE_SCHEMA_VERSION). Parsed from frontmatter `schemaVersion:`; absent
|
|
229
|
+
* stays `undefined` (semantic default 0). Never gates/warns/alters parse.
|
|
230
|
+
*/
|
|
231
|
+
schemaVersion?: number;
|
|
193
232
|
/** Execution root: scheme + host + base path; version prefix lives here. */
|
|
194
233
|
apiHost: string;
|
|
195
234
|
/** Drift signal; defaulted not enforced. */
|
package/core/api-toggle.ts
CHANGED
|
@@ -30,6 +30,8 @@ import {
|
|
|
30
30
|
import type { ToolsetSpec } from "pi-tool-masking";
|
|
31
31
|
import { handleHelpersSubcommand } from "./helpers-command.js";
|
|
32
32
|
import { handleSecretsSubcommand } from "./secrets-command.js";
|
|
33
|
+
import { handleVerifySubcommand } from "./verify-command.js";
|
|
34
|
+
import { handleDeleteSubcommand } from "./delete-command.js";
|
|
33
35
|
import { loadAllGuides } from "./guide-store.js";
|
|
34
36
|
import { getAllHelpers, getDisabledHelperDomains } from "./local-helpers.js";
|
|
35
37
|
|
|
@@ -187,6 +189,8 @@ function handleStatusSubcommand(
|
|
|
187
189
|
` /api on enable api-guide + api-fetch`,
|
|
188
190
|
` /api learn enable all four tools (adds api-learn + api-probe)`,
|
|
189
191
|
` /api off disable all API tools`,
|
|
192
|
+
` /api verify verify a guide's ops against its live API (stamps verified)`,
|
|
193
|
+
` /api delete delete a guide directory (human-typed recovery gesture)`,
|
|
190
194
|
);
|
|
191
195
|
|
|
192
196
|
ctx.ui.notify(lines.join("\n"), "info");
|
|
@@ -217,7 +221,7 @@ export default function initApiToggle(pi: ExtensionAPI): void {
|
|
|
217
221
|
pi.registerCommand("api", {
|
|
218
222
|
description:
|
|
219
223
|
"Enable/disable API tools. " +
|
|
220
|
-
"Usage: /api on | off | learn | status | helpers [domain] | secrets [domain [name] | --help]",
|
|
224
|
+
"Usage: /api on | off | learn | status | helpers [domain] | secrets [domain [name] | --help] | verify <domain> [guide] [--force] | delete <domain> [guide]",
|
|
221
225
|
handler: async (args: string, ctx: ExtensionCommandContext) => {
|
|
222
226
|
const trimmed = args.trim();
|
|
223
227
|
const parts = trimmed.split(/\s+/);
|
|
@@ -288,6 +292,22 @@ export default function initApiToggle(pi: ExtensionAPI): void {
|
|
|
288
292
|
return;
|
|
289
293
|
}
|
|
290
294
|
|
|
295
|
+
case "verify": {
|
|
296
|
+
// Peer of status/helpers/secrets — verifies a guide's ops and
|
|
297
|
+
// stamps verified: (writes guide.md, not toolset state), so the
|
|
298
|
+
// focus-mode guard does not apply.
|
|
299
|
+
await handleVerifySubcommand(rest, ctx);
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
case "delete": {
|
|
304
|
+
// Peer of status/helpers/secrets/verify — removes a guide
|
|
305
|
+
// directory and invalidates the cache (writes guide.md, not
|
|
306
|
+
// toolset state), so the focus-mode guard does not apply.
|
|
307
|
+
await handleDeleteSubcommand(rest, ctx);
|
|
308
|
+
return;
|
|
309
|
+
}
|
|
310
|
+
|
|
291
311
|
default: {
|
|
292
312
|
const apiStatus = apiToolset.isEnabled(pi) ? "✅ on" : "❌ off";
|
|
293
313
|
const learnStatus = learnToolset.isEnabled(pi) ? "✅ on" : "❌ off";
|
|
@@ -302,6 +322,8 @@ export default function initApiToggle(pi: ExtensionAPI): void {
|
|
|
302
322
|
` /api status detailed status (guides, helpers)`,
|
|
303
323
|
` /api helpers list local helpers`,
|
|
304
324
|
` /api secrets list/provision stored secrets (names only)`,
|
|
325
|
+
` /api verify verify a guide's ops against its live API (stamps verified)`,
|
|
326
|
+
` /api delete delete a guide directory (human-typed recovery gesture)`,
|
|
305
327
|
` /api show this status`,
|
|
306
328
|
];
|
|
307
329
|
|
package/core/auth.ts
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import type { AuthConfig, ApiGuide } from "./api-guide-types.js";
|
|
11
|
-
import { readSecret } from "./secrets-store.js";
|
|
11
|
+
import { readSecret, provisionedDomainsSuffix } from "./secrets-store.js";
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* The canonical secret-store key for a guide: its primary browsable domain.
|
|
@@ -24,8 +24,13 @@ export function canonicalStoreDomain(guide: ApiGuide): string {
|
|
|
24
24
|
|
|
25
25
|
/** Result of resolving a guide's `auth.secretRefs` against the store. */
|
|
26
26
|
export interface SecretResolution {
|
|
27
|
-
/** headerName → resolved value, ready to merge into the request. */
|
|
27
|
+
/** headerName → resolved value (with prefix applied), ready to merge into the request. */
|
|
28
28
|
headers: Record<string, string>;
|
|
29
|
+
/**
|
|
30
|
+
* The unprefixed (raw) resolved secret values, for the output-channel
|
|
31
|
+
* audit — a server may echo the bare token, not just the prefixed form.
|
|
32
|
+
*/
|
|
33
|
+
rawHeaderValues: string[];
|
|
29
34
|
/** secret names referenced by `requires` that are absent from the store. */
|
|
30
35
|
absentRequired: string[];
|
|
31
36
|
/** secret names referenced by `optional` that are absent from the store. */
|
|
@@ -38,6 +43,7 @@ export function resolveSecretHeaders(
|
|
|
38
43
|
domain: string,
|
|
39
44
|
): SecretResolution {
|
|
40
45
|
const headers: Record<string, string> = {};
|
|
46
|
+
const rawHeaderValues: string[] = [];
|
|
41
47
|
const absentRequired: string[] = [];
|
|
42
48
|
const absentOptional: string[] = [];
|
|
43
49
|
const requires = auth.requires ?? [];
|
|
@@ -47,10 +53,11 @@ export function resolveSecretHeaders(
|
|
|
47
53
|
if (requires.includes(secretName)) absentRequired.push(secretName);
|
|
48
54
|
else absentOptional.push(secretName);
|
|
49
55
|
} else {
|
|
50
|
-
headers[headerName] = value;
|
|
56
|
+
headers[headerName] = (auth.headerPrefixes?.[headerName] ?? "") + value;
|
|
57
|
+
rawHeaderValues.push(value);
|
|
51
58
|
}
|
|
52
59
|
}
|
|
53
|
-
return { headers, absentRequired, absentOptional };
|
|
60
|
+
return { headers, rawHeaderValues, absentRequired, absentOptional };
|
|
54
61
|
}
|
|
55
62
|
|
|
56
63
|
/** Result of resolving a guide's `auth.secretQueryRefs` against the store. */
|
|
@@ -121,7 +128,8 @@ export function authStatusLine(
|
|
|
121
128
|
if (absentRequired.length > 0) {
|
|
122
129
|
return (
|
|
123
130
|
`🔑 auth: requires ${absentRequired.join(", ")} — not provisioned. ` +
|
|
124
|
-
`Run /api secrets ${domain}.`
|
|
131
|
+
`Run /api secrets ${domain}.` +
|
|
132
|
+
provisionedDomainsSuffix(domain)
|
|
125
133
|
);
|
|
126
134
|
}
|
|
127
135
|
// The optional dimension only exists for optional names actually referenced
|
|
@@ -147,3 +155,32 @@ export function authStatusLine(
|
|
|
147
155
|
}
|
|
148
156
|
return "🔑 auth: ok";
|
|
149
157
|
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Output-channel audit — true when `value` contains any known store-injected
|
|
161
|
+
* secret value. Shared by the body/error scrub and the response-header
|
|
162
|
+
* echo drop.
|
|
163
|
+
*/
|
|
164
|
+
export function containsSecret(
|
|
165
|
+
value: string,
|
|
166
|
+
secretValues?: string[],
|
|
167
|
+
): boolean {
|
|
168
|
+
if (!secretValues) return false;
|
|
169
|
+
return secretValues.some((s) => s && s.length > 0 && value.includes(s));
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Output-channel audit — replace every occurrence of a known store-injected
|
|
174
|
+
* secret value in `text` with `***`, so a request/response body or error
|
|
175
|
+
* echoing the key can't leak it into agent context. No-op when no secrets.
|
|
176
|
+
*/
|
|
177
|
+
export function scrubSecretValues(
|
|
178
|
+
text: string,
|
|
179
|
+
secretValues?: string[],
|
|
180
|
+
): string {
|
|
181
|
+
if (!secretValues) return text;
|
|
182
|
+
for (const v of secretValues) {
|
|
183
|
+
if (v && v.length > 0) text = text.split(v).join("***");
|
|
184
|
+
}
|
|
185
|
+
return text;
|
|
186
|
+
}
|