@agentproto/corpus-cli 0.9.0 → 0.9.3

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.
@@ -52,6 +52,12 @@
52
52
  "items": { "$ref": "#/$defs/trigger" },
53
53
  "default": []
54
54
  },
55
+ "routines": {
56
+ "type": "array",
57
+ "items": { "$ref": "#/$defs/routineRef" },
58
+ "default": [],
59
+ "description": "AIP-41 ROUTINE.md routines that fire this workflow (see AIP-15, `Routines`) — the preferred, decoupled form of a `kind: schedule` trigger: one schedule can drive N workflows, one workflow can be driven by N schedules. Each entry follows the `inline | ref | file` pattern. Legacy inline `triggers: [{ kind: schedule }]` remains valid."
60
+ },
55
61
  "requires": {
56
62
  "type": "object",
57
63
  "additionalProperties": false,
@@ -158,6 +164,45 @@
158
164
  }
159
165
  ]
160
166
  },
167
+ "routineRef": {
168
+ "oneOf": [
169
+ {
170
+ "type": "object",
171
+ "required": ["ref"],
172
+ "additionalProperties": false,
173
+ "properties": {
174
+ "ref": {
175
+ "type": "string",
176
+ "minLength": 1,
177
+ "description": "Ref to a published or local ROUTINE.md (AIP-41), e.g. \"@agentik/routines-standard/daily-9am-utc\"."
178
+ }
179
+ }
180
+ },
181
+ {
182
+ "type": "object",
183
+ "required": ["file"],
184
+ "additionalProperties": false,
185
+ "properties": {
186
+ "file": {
187
+ "type": "string",
188
+ "minLength": 1,
189
+ "description": "File path to a ROUTINE.md (AIP-41), relative to this WORKFLOW.md."
190
+ }
191
+ }
192
+ },
193
+ {
194
+ "type": "object",
195
+ "required": ["inline"],
196
+ "additionalProperties": false,
197
+ "properties": {
198
+ "inline": {
199
+ "type": "object",
200
+ "description": "Equivalent to a one-shot ROUTINE.md (AIP-41) declared inside this workflow: `schedule` (required), `target` (required — typically `{ workflow: { ref: \"./\" } }`), optional `identity`, `retry`, `on_failure`, `history`. Shape SHOULD satisfy the AIP-41 ROUTINE.schema.json `$defs`."
201
+ }
202
+ }
203
+ }
204
+ ]
205
+ },
161
206
  "stepCommon": {
162
207
  "type": "object",
163
208
  "required": ["id", "kind"],
@@ -179,7 +224,9 @@
179
224
  "approval",
180
225
  "map",
181
226
  "loop",
182
- "subworkflow"
227
+ "subworkflow",
228
+ "agent",
229
+ "gate"
183
230
  ]
184
231
  },
185
232
  "inputs": { "type": "object" },
@@ -204,7 +251,9 @@
204
251
  { "$ref": "#/$defs/stepApproval" },
205
252
  { "$ref": "#/$defs/stepMap" },
206
253
  { "$ref": "#/$defs/stepLoop" },
207
- { "$ref": "#/$defs/stepSubworkflow" }
254
+ { "$ref": "#/$defs/stepSubworkflow" },
255
+ { "$ref": "#/$defs/stepAgent" },
256
+ { "$ref": "#/$defs/stepGate" }
208
257
  ]
209
258
  }
210
259
  ]
@@ -290,6 +339,7 @@
290
339
  },
291
340
  "stepApproval": {
292
341
  "type": "object",
342
+ "description": "A human-in-the-loop gate. The HOST resolves the step — it MUST park the run (visible in its status output, e.g. an `awaitingApproval` record) and wait for a human decision; it MUST NOT auto-approve. The decision carries `who` (who decided) and an optional `note`, and is recorded on the host's state ledger (`by: \"human\"`) — state is written only from gate results and approvals. `timeout_ms` bounds the wait: when it elapses with no human decision, the host resolves the step as REJECTED with `who: \"timeout\"` (the `on_timeout`/`on_reject` branch, never an approval).",
293
343
  "required": ["kind", "prompt", "approvers"],
294
344
  "properties": {
295
345
  "kind": { "const": "approval" },
@@ -349,7 +399,153 @@
349
399
  "required": ["kind", "workflow"],
350
400
  "properties": {
351
401
  "kind": { "const": "subworkflow" },
352
- "workflow": { "type": "string" }
402
+ "workflow": { "type": "string" },
403
+ "with": {
404
+ "type": "object",
405
+ "description": "Optional input projection for the child workflow — an alias of `inputs` with identical semantics. Each key is a field of the child's `$input`; each value is either a literal, a reference to a parent input field (`$input.*`), or a reference to a prior step's output (`$steps.<id>.*`), resolved against the PARENT's bindings when the step runs. A referenced field that does not exist is an error naming the step and key — never a silent `undefined`. A step with neither `with` nor `inputs` passes the parent's own input object to the child verbatim. Declaring both `with` and `inputs` on one step is invalid."
406
+ }
407
+ }
408
+ },
409
+ "harness": {
410
+ "type": "object",
411
+ "description": "Harness pinning for a `kind: \"agent\"` step's spawn. Precedence when a field is also set elsewhere: step `harness` (highest) > the resolved AGENT.md's own frontmatter > `app_run` caller args > the adapter's own default (lowest).",
412
+ "additionalProperties": false,
413
+ "properties": {
414
+ "model": { "type": "string", "description": "Model id override for this spawn." },
415
+ "effort": { "type": "string", "description": "Reasoning-effort override for this spawn (adapter-defined vocabulary, e.g. \"low\" | \"medium\" | \"high\")." },
416
+ "role": { "type": "string", "description": "Spawn-time role governing the child's tool-policy disposition (e.g. \"executor\" | \"supervisor\")." },
417
+ "tools": {
418
+ "type": "array",
419
+ "items": { "type": "string" },
420
+ "description": "Per-spawn tool allowlist. Applied where the resolved adapter supports a generic per-spawn allowlist mechanism; where it doesn't, the host records `toolsApplied: false` on the step's run record and emits a warning event instead of silently ignoring the field."
421
+ },
422
+ "skills": {
423
+ "type": "array",
424
+ "items": { "type": "string" },
425
+ "description": "Skill ids auto-mounted into the spawn — adapters with no such option (e.g. claude-code, which auto-discovers skills) ignore it."
426
+ },
427
+ "cwd": { "type": "string", "description": "Working directory override for this step's spawn; takes precedence over the run-level cwd." },
428
+ "promptFile": { "type": "string", "description": "Read this file (relative to the WORKFLOW.md's directory) at load time and use its contents as the step's `prompt`, replacing any inline `prompt`." },
429
+ "promptSha": { "type": "string", "description": "Computed by the loader at load time — sha256 (hex) of `promptFile`'s raw bytes. Not hand-authored; present only when `promptFile` was resolved." },
430
+ "knowledge": {
431
+ "type": "array",
432
+ "items": { "$ref": "#/$defs/knowledgeSelector" },
433
+ "description": "AIP-10 corpus knowledge to materialize into this step's working directory before the session runs. For each selector, the host resolves the workspace (relative paths resolve against the WORKFLOW.md's own directory), queries its refined `entries/**/*.md` (anyOf = tag OR, allOf = tag AND post-filter, kinds = refined-kind filter), sorts matches by slug ascending, caps at `maxEntries` (default 50), and writes each raw entry (frontmatter + body) to `<cwd>/.knowledge/<workspaceBasename>/<slug>.md` plus a deterministic `<cwd>/.knowledge/INDEX.md` (one `- [<title>](<relpath>) — kind, tags` line per entry, grouped per workspace). One line naming the INDEX is prepended to the step's prompt. An empty match is not an error — it is recorded (`matched: 0`) and warned via the harness-warning event (`knowledge-empty`). Mode is v1 `\"files\"` only; `\"tool\"` is reserved. Example:\n\nknowledge:\n - workspace: ../corpus-writer\n anyOf: [book-factory, drafting]\n allOf: [style-guide]\n kinds: [fact]\n maxEntries: 20\n mode: files"
434
+ }
435
+ }
436
+ },
437
+ "knowledgeSelector": {
438
+ "type": "object",
439
+ "description": "One AIP-10 corpus workspace attachment on a `kind: \"agent\"` step's `harness.knowledge[]` — see the `harness.knowledge` description for the full materialization contract. String fields (`workspace`, `anyOf[]`, `allOf[]`, `kinds[]`) may carry leading `$…` run-time references; the loader defers such selectors (`deferred` is an internal field, rejected when user-authored) and the runtime resolves them against the run bindings before materialization.",
440
+ "required": ["workspace"],
441
+ "additionalProperties": false,
442
+ "properties": {
443
+ "workspace": { "type": "string", "minLength": 1, "description": "Path to an AIP-10 corpus workspace root — relative to the WORKFLOW.md's directory (resolved by the loader to an absolute path) or absolute. A workspace that does not exist fails the load. Ref rule: a string containing a `$…` run-time reference (AIP-16 grammar) is left untouched at load time and resolved per run against the run bindings — only the LEADING reference token (up to the next `/`) is replaced, e.g. `$input.bookDir/knowledge` becomes `<resolved bookDir>/knowledge`; a relative resolved workspace joins to the run cwd, and a workspace that still does not exist after resolution is warned (`knowledge-workspace-missing`), not thrown." },
444
+ "anyOf": { "type": "array", "items": { "type": "string" }, "description": "Tags with OR semantics — an entry matching ANY of these passes. Empty/absent = no tag filter. Tag strings may carry leading `$…` run-time references, resolved per run like `workspace`." },
445
+ "allOf": { "type": "array", "items": { "type": "string" }, "description": "Tags that must ALL be present on an entry (post-filter applied after anyOf)." },
446
+ "kinds": { "type": "array", "items": { "type": "string" }, "description": "Refined-kind filter (e.g. \"fact\" | \"howto\") — only entries of these kinds pass." },
447
+ "maxEntries": { "type": "integer", "minimum": 1, "description": "Cap on materialized entries, applied after sorting by slug ascending (deterministic). Default 50." },
448
+ "mode": { "const": "files", "description": "Materialization mode. v1 supports only \"files\" (write entries into the step cwd's .knowledge/); other values are rejected." }
449
+ }
450
+ },
451
+ "stepAgent": {
452
+ "type": "object",
453
+ "description": "Spawn or reuse an agent session and send it a prompt.",
454
+ "required": ["kind", "prompt"],
455
+ "properties": {
456
+ "kind": { "const": "agent" },
457
+ "agent": {
458
+ "type": "object",
459
+ "description": "App-scoped agent id to resolve at compile time. Omit to spawn a plain `adapter` (no app-ref resolution) or reuse via `sessionRef`.",
460
+ "required": ["ref"],
461
+ "properties": {
462
+ "ref": { "type": "string" }
463
+ }
464
+ },
465
+ "prompt": { "type": "string" },
466
+ "adapter": {
467
+ "type": "string",
468
+ "description": "Adapter slug for spawning a NEW session. Ignored (and unnecessary) when `agent.ref` resolves one for you. Omit both to reuse via `sessionRef`."
469
+ },
470
+ "sessionRef": {
471
+ "type": "string",
472
+ "description": "Reuse an earlier agent step's spawned session, by that step's id."
473
+ },
474
+ "sandbox": {
475
+ "anyOf": [
476
+ { "type": "string" },
477
+ {
478
+ "type": "object",
479
+ "required": ["provider"],
480
+ "properties": { "provider": { "type": "string" } }
481
+ }
482
+ ]
483
+ },
484
+ "cacheable": {
485
+ "type": "boolean",
486
+ "description": "Cache this step's output under the run's cacheKey. Default false."
487
+ },
488
+ "maxRetries": {
489
+ "type": "integer",
490
+ "minimum": 0,
491
+ "description": "Re-prompt-and-retry attempts on `outputSchema` mismatch. Default 2."
492
+ },
493
+ "outputSchema": {
494
+ "description": "A JSON Schema (or, in a TS-authored workflow, a zod ZodType) validating the session's final message; re-prompts on mismatch."
495
+ },
496
+ "policy": {
497
+ "anyOf": [
498
+ {
499
+ "type": "object",
500
+ "required": ["awaiting", "prompt"],
501
+ "properties": {
502
+ "awaiting": { "const": "auto-allow" },
503
+ "prompt": { "type": "string" }
504
+ }
505
+ },
506
+ {
507
+ "type": "object",
508
+ "required": ["awaiting"],
509
+ "properties": {
510
+ "awaiting": { "const": "escalate" },
511
+ "webhookUrl": { "type": "string" },
512
+ "timeoutMs": { "type": "integer", "minimum": 1 }
513
+ }
514
+ },
515
+ {
516
+ "type": "object",
517
+ "required": ["awaiting"],
518
+ "properties": { "awaiting": { "const": "fail" } }
519
+ }
520
+ ]
521
+ },
522
+ "options": {
523
+ "type": "object",
524
+ "additionalProperties": { "type": ["boolean", "number", "string"] },
525
+ "description": "Manifest-declared adapter option id → value, forwarded to a NEW spawn's `startSession({ options })` — e.g. mastra-agent's `agent` option, set by `agent.ref` resolution at compile time. Only meaningful with `adapter`; ignored on a `sessionRef` reuse. May also be authored directly on the step."
526
+ },
527
+ "harness": { "$ref": "#/$defs/harness" }
528
+ }
529
+ },
530
+ "stepGate": {
531
+ "type": "object",
532
+ "description": "Run a shell command through the host's subprocess runner (AIP-17) as a deterministic pass/fail check. Exit code 0 is a pass; any other exit code is a failure, subject to `retry`. The process' stdout, if it parses as JSON, becomes the gate's report; otherwise, when `report` names a file, that file is read (relative to `cwd`) and parsed as JSON instead. The report — plus `ok` and `exitCode` — is bound at `$steps.<id>.report` / `.ok` / `.exitCode`, and emitted as a `gate-report` lifecycle event on the run's event stream.",
533
+ "required": ["kind", "command"],
534
+ "properties": {
535
+ "kind": { "const": "gate" },
536
+ "command": { "type": "string" },
537
+ "args": { "type": "array", "items": { "type": "string", "description": "May carry a LEADING `$…` run-time reference (AIP-16): a leading `$input|$item|$steps.<id>|$index` token is resolved per run against the run bindings and any trailing text is appended verbatim (`$input.bookDir/knowledge` → `<resolved>/knowledge`; a string that is exactly a ref resolves to that value's string form); `$$` escapes a literal `$`; an unresolvable ref throws naming the step and the arg index." } },
538
+ "cwd": { "type": "string", "description": "Working directory. Defaults to the workflow run's own cwd. May carry the same leading-`$…` ref rule as `args` (leading token + trailing text, `$$` escape, unresolvable ref throws). The resolved cwd is made absolute: absolute stays absolute; a relative resolved cwd (incl. `.`) resolves against the run's cwd, never the daemon process cwd." },
539
+ "report": { "type": "string", "description": "Path (relative to `cwd`) of a JSON report file, consulted when stdout doesn't itself parse as JSON." },
540
+ "on_fail": {
541
+ "type": "object",
542
+ "required": ["reprompt"],
543
+ "description": "Re-prompt-and-rerun on a failing exit code, bounded by `retry.max_attempts`. Runs BEFORE each retry attempt after the first: sends the named prior agent step's session (reused the same way a `kind: \"agent\"` step's `sessionRef` reuse works) a prompt with this gate's last report injected, waits for its turn, then re-runs the gate command.",
544
+ "properties": {
545
+ "reprompt": { "type": "string", "description": "The prior `kind: \"agent\"` step id to re-prompt." },
546
+ "with": { "type": "object", "description": "Extra literal context merged into the reprompt, alongside the gate's `$steps.<id>.report`." }
547
+ }
548
+ }
353
549
  }
354
550
  }
355
551
  }
@@ -28,6 +28,14 @@
28
28
  },
29
29
  "config": {
30
30
  "type": "object",
31
+ "additionalProperties": true,
32
+ "properties": {
33
+ "installAdapters": {
34
+ "type": "array",
35
+ "items": { "type": "string", "minLength": 1 },
36
+ "description": "Semantic harness slugs to pre-install in the box at boot (e.g. [\"hermes\", \"claude-code\"]). Each expands to @agentproto/adapter-<slug>@latest plus that adapter's declared boot extras; a config.installPackages pin for the same package always wins. Additive — absent means no extra install."
37
+ }
38
+ },
31
39
  "description": "Provider-specific connection fields. Shape varies per provider (see AIP-36 §Provider config shapes)."
32
40
  },
33
41
  "limits": {
@@ -50,6 +58,10 @@
50
58
  "items": { "type": "string" },
51
59
  "default": [],
52
60
  "description": "Static host env-var names to forward into the sandbox."
61
+ },
62
+ "autoPassthrough": {
63
+ "type": "boolean",
64
+ "description": "Opt-in: forward the spawn's resolved billing-credential env-var NAME (e.g. ANTHROPIC_API_KEY) into passthrough so a fresh box inherits host auth without the caller naming vars. Only the name is injected — the value travels via the normal passthrough mechanism."
53
65
  }
54
66
  }
55
67
  },
@@ -100,6 +112,11 @@
100
112
  "default": false,
101
113
  "description": "Reject command execution at the sandbox layer. Read-only sandbox calls fail with `sandbox_read_only`."
102
114
  },
115
+ "extraPorts": {
116
+ "type": "array",
117
+ "items": { "type": "integer", "minimum": 1 },
118
+ "description": "App ports to expose at boot time. Resolved into BootedSandbox.ports (port → public URL) by providers that support port exposure."
119
+ },
103
120
  "metadata": {
104
121
  "type": "object",
105
122
  "additionalProperties": true,
@@ -2,9 +2,17 @@
2
2
  "$schema": "https://json-schema.org/draft/2020-12/schema",
3
3
  "$id": "https://agentproto.sh/schemas/aip-40/EXTENSION.schema.json",
4
4
  "title": "ExtensionDefinition",
5
- "description": "Validates the YAML frontmatter portion of an AIP-40 EXTENSION.md manifest. An extension declares a workspace-local doctype that inherits a public AIP's schema and may add fields, tighten constraints, set defaults, and override the path convention.",
5
+ "description": "Validates the YAML frontmatter portion of an AIP-40 EXTENSION.md manifest. An extension declares a workspace-local doctype that inherits a public AIP's schema \u2014 adding fields (add_fields), tightening constraints (tighten), selectively REMOVING non-required parent fields (remove_fields, guarded: parent-required fields refuse removal, mirroring AIP-18's inherited-status rule), choosing which aspects compose per-aspect (inherit: {schema, defaults, parse, path}; omitted = v1 wholesale inheritance), setting defaults, and overriding the path convention.",
6
6
  "type": "object",
7
- "required": ["schema", "slug", "title", "description", "version", "status", "extends"],
7
+ "required": [
8
+ "schema",
9
+ "slug",
10
+ "title",
11
+ "description",
12
+ "version",
13
+ "status",
14
+ "extends"
15
+ ],
8
16
  "additionalProperties": false,
9
17
  "properties": {
10
18
  "schema": {
@@ -14,7 +22,7 @@
14
22
  "slug": {
15
23
  "type": "string",
16
24
  "pattern": "^[a-z][a-z0-9-]*:[a-z][a-z0-9-]*[a-z0-9]$",
17
- "description": "Namespaced identifier — `<namespace>:<name>`. Lowercase, digits, dashes; single colon separator. Example: `acme:deal`."
25
+ "description": "Namespaced identifier \u2014 `<namespace>:<name>`. Lowercase, digits, dashes; single colon separator. Example: `acme:deal`."
18
26
  },
19
27
  "title": {
20
28
  "type": "string",
@@ -35,7 +43,7 @@
35
43
  },
36
44
  "status": {
37
45
  "const": "Local",
38
- "description": "Extensions are perpetually Local — they never enter the public registry's Draft/Review/Final lifecycle."
46
+ "description": "Extensions are perpetually Local \u2014 they never enter the public registry's Draft/Review/Final lifecycle."
39
47
  },
40
48
  "extends": {
41
49
  "anyOf": [
@@ -58,11 +66,13 @@
58
66
  "properties": {
59
67
  "type": "object",
60
68
  "additionalProperties": true,
61
- "description": "JSON Schema property definitions to merge into the parent's properties. Collisions are an error — use `tighten` to narrow an existing field."
69
+ "description": "JSON Schema property definitions to merge into the parent's properties. Collisions are an error \u2014 use `tighten` to narrow an existing field."
62
70
  },
63
71
  "required": {
64
72
  "type": "array",
65
- "items": { "type": "string" },
73
+ "items": {
74
+ "type": "string"
75
+ },
66
76
  "uniqueItems": true,
67
77
  "default": [],
68
78
  "description": "Field names that become required in addition to parent's required[]. Unioned with parent's required, never replaces."
@@ -76,12 +86,26 @@
76
86
  "type": "object",
77
87
  "additionalProperties": false,
78
88
  "properties": {
79
- "pattern": { "type": "string" },
80
- "enum": { "type": "array" },
81
- "minLength": { "type": "integer", "minimum": 0 },
82
- "maxLength": { "type": "integer", "minimum": 0 },
83
- "minimum": { "type": "number" },
84
- "maximum": { "type": "number" }
89
+ "pattern": {
90
+ "type": "string"
91
+ },
92
+ "enum": {
93
+ "type": "array"
94
+ },
95
+ "minLength": {
96
+ "type": "integer",
97
+ "minimum": 0
98
+ },
99
+ "maxLength": {
100
+ "type": "integer",
101
+ "minimum": 0
102
+ },
103
+ "minimum": {
104
+ "type": "number"
105
+ },
106
+ "maximum": {
107
+ "type": "number"
108
+ }
85
109
  }
86
110
  },
87
111
  "description": "Per-field constraint overrides. Each entry MUST tighten (not loosen) the parent's constraints; runtimes verify monotonicity at registration."
@@ -111,6 +135,43 @@
111
135
  "additionalProperties": true,
112
136
  "default": {},
113
137
  "description": "Free-form vendor extensions under namespaced keys (`metadata.<vendor>.<field>`)."
138
+ },
139
+ "remove_fields": {
140
+ "type": "array",
141
+ "items": {
142
+ "type": "string"
143
+ },
144
+ "uniqueItems": true,
145
+ "default": [],
146
+ "description": "OPTIONAL \u2014 parent property names this extension REMOVES from the inherited schema. GUARDED: a field listed in the parent's required[] MUST NOT be removed (removing it would invalidate parent-validated instances; mirrors AIP-18's 'children MUST NOT remove an inherited status'). Runtimes MUST refuse registration when the guard is violated. Also independent of `inherit.schema`: removing fields implies schema inheritance stays on."
147
+ },
148
+ "inherit": {
149
+ "type": "object",
150
+ "additionalProperties": false,
151
+ "default": {},
152
+ "properties": {
153
+ "schema": {
154
+ "type": "boolean",
155
+ "default": true,
156
+ "description": "Inherit the parent's schema (properties/required minus remove_fields). When false, add_fields becomes the full schema (root-like composition)."
157
+ },
158
+ "defaults": {
159
+ "type": "boolean",
160
+ "default": true,
161
+ "description": "Layer the parent's defaults under the extension's. When false, parent defaults are NOT applied."
162
+ },
163
+ "parse": {
164
+ "type": "boolean",
165
+ "default": true,
166
+ "description": "Reuse the parent's manifest parser. When false, the extension MUST supply its own parser at registration (root-doctype rule)."
167
+ },
168
+ "path": {
169
+ "type": "boolean",
170
+ "default": true,
171
+ "description": "Fall back to the parent's pathOf convention. When false, path_convention becomes REQUIRED."
172
+ }
173
+ },
174
+ "description": "Per-aspect selection \u2014 choose which aspects of the parent compose, instead of AIP-40 v1's wholesale merge. Omitted keys default to true (backwards compatible with v1: wholesale inheritance)."
114
175
  }
115
176
  }
116
177
  }
@@ -0,0 +1,89 @@
1
+ # AIP-54 — Ref · Implementer Guide
2
+
3
+ > **Status:** Draft
4
+ > **Schema:** `REF.schema.json`
5
+ > **Reference runtime:** `@agentproto/ref`
6
+
7
+ ## What is a Ref?
8
+
9
+ A Ref is **one typed, cross-AIP reference** — `{aip, id, version?}`,
10
+ serialized in string contexts as `aip://<aip>/<id>[@version]`. It is
11
+ the general answer to a question every AIP has answered differently:
12
+
13
+ - AIP-18's `ref` field — an id string scoped to ONE named collection,
14
+ no shape guarantee.
15
+ - app-kit's `attach` — a structural `DoctypeHandle` that serializes
16
+ the whole bundle and carries no reliable discriminator.
17
+ - AIP-42's `AnyRef` — bare strings, typed only by call-site convention.
18
+ - AIP-55's first draft — bespoke `appRef`/`packRef` per target kind.
19
+
20
+ A Ref IS NOT a handle. It is inert data pointing at one; the AIP-43
21
+ registry owns the handle. A Ref IS NOT resolvable by itself —
22
+ resolution is the host's `RefCatalog`, which joins per-family AIP-43
23
+ registries.
24
+
25
+ ## Reference runtime
26
+
27
+ ```ts
28
+ import { RefCatalog, refFor, refToUri, refFromUri } from "@agentproto/ref"
29
+
30
+ const cat = new RefCatalog()
31
+ cat.registerFamily(42, { family: "app", keyBy: h => h.id! }, appRegistry)
32
+ cat.registerFamily(52, { family: "pack", keyBy: h => h.name }, packRegistry)
33
+
34
+ const ref = refFor({ aip: 52, keyBy: h => h.name }, packHandle, "1.0.0")
35
+ // { aip: 52, id: "the-agentic-coder", version: "1.0.0" }
36
+
37
+ const hit = cat.resolveStrict(ref) // { handle, family } — throws if dangling
38
+ const uri = refToUri(ref) // "aip://52/the-agentic-coder@1.0.0"
39
+ ```
40
+
41
+ ### Normative rules
42
+
43
+ 1. **keyBy identity.** The `keyBy` passed to `refFor` MUST be the same
44
+ function the family's registry uses. A ref id that drifts from its
45
+ registry key is a HARD authoring error.
46
+ 2. **Unreferenceable handles.** A handle with no registry key (no
47
+ `id`/`provider`/`slug`/`name`) MUST be refused by `refFor` — the
48
+ pre-AIP-54 world silently produced dangling id strings. Anonymous
49
+ AIP-42 apps (no `id`) are unreferenceable; hosts MUST refuse.
50
+ 3. **Loud failure.** `resolve` on an unknown aip or id returns
51
+ `undefined` (default) or throws `RefFamilyError` /
52
+ `RefUnresolvableError` (`onUnresolvable: "throw"` / `resolveStrict`).
53
+ A dangling ref MUST never masquerade as a resolution.
54
+ 4. **Ref is inert.** Frozen at construction; carries no behavior. All
55
+ semantics live in the catalog + registries.
56
+ 5. **One family per aip.** Re-registering replaces the binding
57
+ (hot-reload parity with AIP-43's `replace`).
58
+
59
+ ### Conventions for referenced handles
60
+
61
+ - **Handles SHOULD carry `schema: "<doctype>/vN"`.** Several existing
62
+ handles don't (e.g. the in-memory AIP-42 `AppHandle` never carries
63
+ the `schema: "app/v1"` literal that `emit` writes into `APP.md`) —
64
+ until they do, `refFor` requires the family spec to be supplied
65
+ explicitly, and a bare serialized handle cannot self-describe into a
66
+ ref. New doctypes SHOULD include it in `createDoctype`'s default
67
+ `build()`.
68
+ - **Family keys are the family's choice.** Most families key on `id`
69
+ (or `provider`/`slug` per AIP-43's default), but packs (AIP-52) key
70
+ on `name`. The `RefCatalog` owns the `aip → family + keyBy` table;
71
+ `refFor` MUST be given the same `keyBy` the family's registry uses.
72
+
73
+ ## Migration notes for existing mechanisms
74
+
75
+ | Existing | Migration |
76
+ |---|---|
77
+ | AIP-18 `ref` field + `refKind` | Validate ref values as `aip://` URIs; `refKind` narrows the accepted `aip`(s). |
78
+ | app-kit `attach` (DoctypeHandle) | Carry `ArtifactRef`s; the host resolves through its catalog. Fixes the inline-the-whole-bundle flaw. |
79
+ | AIP-42 `AnyRef` string form | Unchanged at the string layer; `aip://` URIs are a valid `ref:` value hosts narrow to `ref/v1`. |
80
+ | AIP-52 `$resolver` | A URI rendering of the same coordinates. |
81
+ | AIP-53 draft `target` union | Replaced by `on: ref/v1` (see AIP-53). |
82
+
83
+ ## What a new AIP needs to be referenceable
84
+
85
+ Nothing ref-specific. It needs what every AIP needs anyway: a
86
+ `defineX` handle with a stable identity field, and (for hosts that
87
+ resolve in-memory) an AIP-43 registry entry with a `family` + `keyBy`.
88
+ Pricing, entitling, or any future capability composes ON TOP via a
89
+ capability attached to a ref — the target AIP never learns about it.
@@ -0,0 +1,27 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://agentproto.sh/schemas/aip-54/REF.schema.json",
4
+ "title": "ref/v1 frontmatter (AIP-54)",
5
+ "description": "Validates an AIP-54 typed artifact reference — the one cross-AIP reference shape. An ArtifactRef names an artifact by its owning AIP number and that AIP's registry key, optionally pinned to a version. It replaces every per-primitive reference mechanism (AIP-18's collection-scoped refKind, inline doctype handles, AIP-53's draft appRef/packRef union, bare id strings). Resolution is host-side via AIP-43 registries joined by a RefCatalog; an unresolvable ref is a HARD failure in strict hosts and MUST never silently degrade to a dangling id string.",
6
+ "type": "object",
7
+ "required": ["aip", "id"],
8
+ "additionalProperties": false,
9
+ "properties": {
10
+ "aip": {
11
+ "type": "integer",
12
+ "minimum": 1,
13
+ "description": "The referenced artifact's owning AIP number — the type discriminator that names the registry family (42 = app, 52 = pack, 14 = tool, …)."
14
+ },
15
+ "id": {
16
+ "type": "string",
17
+ "minLength": 1,
18
+ "maxLength": 512,
19
+ "description": "The artifact's registry key in its family — the same key the family's AIP-43 registry (or the family's keyBy) derives. Hosts MUST use the family's keyBy; a ref id and its registry key can never be allowed to drift."
20
+ },
21
+ "version": {
22
+ "type": "string",
23
+ "pattern": "^[0-9]+\\.[0-9]+\\.[0-9]+(-[A-Za-z0-9.-]+)?$",
24
+ "description": "OPTIONAL semver pin recording what was meant at authoring time. Absent = floating (resolve whatever is registered now). Pins are advisory metadata for hosts; AIP-43 registries do not version."
25
+ }
26
+ }
27
+ }
@@ -0,0 +1,143 @@
1
+ # AIP-55 — Product (pricing capability) · Implementer Guide
2
+
3
+ > **Status:** Draft (v2 — capability form)
4
+ > **Schema:** `PRODUCT.schema.json`
5
+ > **Reference runtime:** `@agentproto/product`
6
+ > **Depends on:** AIP-54 (`ref/v1`) — this spec's `on` field IS an AIP-54 ref.
7
+
8
+ ## What is a Product?
9
+
10
+ A Product is **a pricing capability attached to any referenced AIP
11
+ artifact**. It is not a wrapper doctype: there is no per-target-kind
12
+ union, no `appRef`/`packRef`, no inlined handles. The target is
13
+ addressed by an AIP-54 `ref/v1` and needs zero pricing awareness —
14
+ "sandbox has a price" is expressible without the sandbox AIP changing.
15
+
16
+ A Product IS NOT:
17
+
18
+ - an AIP-49 wallet `asset` — AIP-49 models value *movement*; AIP-55
19
+ models the *catalog entry*. `defineAsset` is taken.
20
+ - an AIP-18 collection item — no money type, no discriminated union,
21
+ `refKind` is collection-scoped.
22
+ - an AIP-40 extension of AIP-42 — pricing is not app-specific.
23
+
24
+ ## Filesystem layout
25
+
26
+ ```
27
+ products/
28
+ <id>.md ← one manifest per pricing capability
29
+ ```
30
+
31
+ The markdown body (after the frontmatter block) is purely documentary.
32
+
33
+ ## Manifest shape
34
+
35
+ ```yaml
36
+ ---
37
+ schema: product/v1
38
+ id: book1-coder
39
+ kind: pricing
40
+ title: book1 companion — coder
41
+ description: Open-source companion code, pay per call.
42
+ on: aip://14/coder # AIP-54 ref — the ONLY reference field
43
+
44
+ price:
45
+ model: pay-per-call
46
+ unitPriceMinor: 2
47
+ currency: usd
48
+ meter: agent-call
49
+
50
+ billingRail:
51
+ rail: stripe
52
+ priceId: price_metered_1
53
+ meterId: meter_abc
54
+ recurrence: month
55
+ ```
56
+
57
+ ## Normative fields
58
+
59
+ | Field | Req | Notes |
60
+ |---|---|---|
61
+ | `schema` | MUST | `product/v1` |
62
+ | `id` | MUST | kebab-case |
63
+ | `on` | MUST | AIP-54 `ref/v1`. May also be given as the `aip://<aip>/<id>[@version]` string form, which implementations MUST normalize (parse + validate) into `ref/v1` before storing. The target AIP needs zero pricing awareness. Hosts MUST refuse unresolvable refs. |
64
+ | `price` | MUST | Discriminated on `model`: `one-time` \| `prepaid-pool` \| `pay-per-call`. **Minor units are normative.** |
65
+ | `billingRail` | MAY | Projection config, never the price's source of truth. See § Billing rails. |
66
+ | `kind` | MUST | `pricing` (fixed — this AIP defines the pricing capability; future capability kinds may share the pattern). |
67
+ | `title`, `description`, `metadata` | MAY | |
68
+
69
+ ## Billing rails
70
+
71
+ The rail is **config, not truth**. A generator derives the provider
72
+ objects from `price`; the ids stored on the rail are caches of the last
73
+ projection.
74
+
75
+ - **`stripe`** — `one-time` → Product + `one_time` Price (1:1, no leak).
76
+ `pay-per-call` → metered Price **plus a Stripe Meter**, created
77
+ out-of-band: `meterId` is REQUIRED. `prepaid-pool` has NO native
78
+ Stripe primitive — pool state lives host-side on every rail; Stripe
79
+ only initiates the top-up payment.
80
+ - **`autumn`** — natively models both metered usage and prepaid credit
81
+ grants; both metered shapes project onto one `featureId`. No leak.
82
+ - **`tbd`** — shape decided, provider not chosen.
83
+ - **Vendor rails** — open, config rides along.
84
+
85
+ ## Worked examples (Agentik verticals)
86
+
87
+ ```yaml
88
+ # book1/coder — open repo, pay-per-call
89
+ schema: product/v1
90
+ id: book1-coder
91
+ kind: pricing
92
+ on: aip://14/coder
93
+ price: { model: pay-per-call, unitPriceMinor: 2, currency: usd, meter: agent-call }
94
+ billingRail: { rail: stripe, meterId: meter_abc, recurrence: month }
95
+ ```
96
+
97
+ ```yaml
98
+ # book3/SEO — private bundle, prepaid pool
99
+ schema: product/v1
100
+ id: book3-seo
101
+ kind: pricing
102
+ on: aip://14/seo-private@1.2.0
103
+ price: { model: prepaid-pool, unitPriceMinor: 5, currency: usd, grantUnits: 200 }
104
+ billingRail: { rail: autumn, featureId: seo-credits }
105
+ ```
106
+
107
+ ```yaml
108
+ # default vertical — book + private app bundle, one-time
109
+ schema: product/v1
110
+ id: bookN-companion
111
+ kind: pricing
112
+ on: aip://42/book-companion
113
+ price: { model: one-time, amountMinor: 4900, currency: usd }
114
+ billingRail: { rail: tbd }
115
+ ```
116
+
117
+ ## Implementation sketch (TS path)
118
+
119
+ ```ts
120
+ import { attachPricing } from "@agentproto/product"
121
+ import { refFor } from "@agentproto/ref"
122
+
123
+ const cap = attachPricing(refFor(appSpec, appHandle, "1.2.0"), {
124
+ model: "one-time", amountMinor: 4900, currency: "usd",
125
+ })
126
+ ```
127
+
128
+ "a collection of priced things" = `collectPriced(products, ref =>
129
+ catalog.resolve(ref))` — returns `{resolved, dangling}`: `resolved` pairs
130
+ each product with its resolved target, and `dangling` lists the products
131
+ whose `on` ref did not resolve, so a host can surface them instead of
132
+ having them silently dropped from the collection.
133
+
134
+ ## Residual risks (from dogfooding)
135
+
136
+ 1. **AIP-52's legacy `pricing` block** (unitless `{ebook?, bundle,
137
+ step?}`) predates this spec. THIS product's price is authoritative;
138
+ hosts SHOULD warn when a pack's `pricing` diverges from a pricing
139
+ capability attached to it.
140
+ 2. **Stripe prepaid-pool leak is inherent**: Stripe has no credit-pool
141
+ concept; pool state lives host-side on every rail. The schema says
142
+ so rather than implying a clean projection.
143
+ 3. **Autumn composes cleanly for both metered shapes.**
@@ -0,0 +1,107 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://agentproto.sh/schemas/aip-55/PRODUCT.schema.json",
4
+ "title": "product/v1 frontmatter (AIP-55)",
5
+ "description": "Validates the YAML frontmatter portion of an AIP-55 PRODUCT.md — a pricing CAPABILITY attached to any referenced AIP artifact. The target is addressed by an AIP-54 ref/v1 (aip:// URI in string contexts); the target AIP needs zero pricing awareness. Price models: 'one-time', 'prepaid-pool', 'pay-per-call'. Minor units are normative. billingRail is projection config, never the source of truth.",
6
+ "$defs": {
7
+ "price": {
8
+ "oneOf": [
9
+ {
10
+ "type": "object",
11
+ "required": ["model", "amountMinor", "currency"],
12
+ "additionalProperties": false,
13
+ "properties": {
14
+ "model": { "const": "one-time", "description": "Single payment for perpetual access." },
15
+ "amountMinor": { "type": "integer", "minimum": 0, "description": "Amount in MINOR units of the currency (cents for usd). Minor units are normative — major-unit floats are the x100 bug class." },
16
+ "currency": { "type": "string", "pattern": "^[a-z]{3}$", "description": "ISO-4217 lowercase, e.g. 'usd'." }
17
+ }
18
+ },
19
+ {
20
+ "type": "object",
21
+ "required": ["model", "unitPriceMinor", "currency", "grantUnits"],
22
+ "additionalProperties": false,
23
+ "properties": {
24
+ "model": { "const": "prepaid-pool", "description": "Buy a pool of meter units up front; consumption draws the pool down. Pool STATE is host-side on every rail — the rail only initiates the top-up payment." },
25
+ "unitPriceMinor": { "type": "integer", "minimum": 0, "description": "Price per unit in minor units of the currency." },
26
+ "currency": { "type": "string", "pattern": "^[a-z]{3}$" },
27
+ "grantUnits": { "type": "integer", "minimum": 1, "description": "Meter units granted per purchase. Unit semantics are declared by the host, not the spec; if a wallet asset backs the pool, units MUST be minor units of that asset's `decimals` (AIP-49)." }
28
+ }
29
+ },
30
+ {
31
+ "type": "object",
32
+ "required": ["model", "unitPriceMinor", "currency", "meter"],
33
+ "additionalProperties": false,
34
+ "properties": {
35
+ "model": { "const": "pay-per-call", "description": "Post-paid metering: each unit consumed is billed." },
36
+ "unitPriceMinor": { "type": "integer", "minimum": 0, "description": "Price per meter unit in minor units." },
37
+ "currency": { "type": "string", "pattern": "^[a-z]{3}$" },
38
+ "meter": { "type": "string", "minLength": 1, "maxLength": 96, "description": "Host-declared meter id, e.g. 'agent-call', 'tokens-1k', 'sandbox-hour'. Open vocabulary; hosts SHOULD namespace host-specific meters." }
39
+ }
40
+ }
41
+ ]
42
+ },
43
+ "billingRail": {
44
+ "oneOf": [
45
+ {
46
+ "type": "object",
47
+ "required": ["rail"],
48
+ "additionalProperties": false,
49
+ "properties": {
50
+ "rail": { "const": "stripe" },
51
+ "productId": { "type": "string", "description": "Stripe Product id — a CACHE of the last projection, never the source of truth for the price." },
52
+ "priceId": { "type": "string", "description": "Stripe Price id." },
53
+ "meterId": { "type": "string", "description": "Stripe Meter id — REQUIRED when price.model is 'pay-per-call'; Stripe meters are created out-of-band and cannot be derived from the Price id." },
54
+ "recurrence": { "enum": ["month", "year", "week", "day"], "description": "Billing recurrence for metered prices. Absent = per-unit without period." }
55
+ }
56
+ },
57
+ {
58
+ "type": "object",
59
+ "required": ["rail"],
60
+ "additionalProperties": false,
61
+ "properties": {
62
+ "rail": { "const": "autumn" },
63
+ "featureId": { "type": "string", "description": "Autumn feature id. Autumn natively models both metered usage and prepaid credit grants, so prepaid-pool and pay-per-call both project onto one featureId." },
64
+ "grantId": { "type": "string", "description": "Autumn credit-grant id for prepaid-pool products, if distinct from featureId." }
65
+ }
66
+ },
67
+ {
68
+ "type": "object",
69
+ "required": ["rail"],
70
+ "additionalProperties": false,
71
+ "properties": {
72
+ "rail": { "const": "tbd", "description": "Commerce shape decided, provider not chosen yet." }
73
+ }
74
+ },
75
+ {
76
+ "type": "object",
77
+ "required": ["rail"],
78
+ "additionalProperties": true,
79
+ "properties": {
80
+ "rail": { "type": "string", "pattern": "^[a-z][a-z0-9-]*$", "not": { "enum": ["stripe", "autumn", "tbd"] }, "description": "Vendor-specific rail. Rail-specific config lives under namespaced keys; unknown rails MUST be tolerated by hosts that only consume the price union." }
81
+ }
82
+ }
83
+ ]
84
+ }
85
+ },
86
+ "type": "object",
87
+ "required": ["schema", "id", "on", "price"],
88
+ "additionalProperties": false,
89
+ "properties": {
90
+ "schema": { "const": "product/v1", "description": "Doctype discriminator." },
91
+ "id": { "type": "string", "pattern": "^[a-z][a-z0-9-]*$", "minLength": 2, "maxLength": 96, "description": "Stable kebab-case pricing-capability id." },
92
+ "kind": { "const": "pricing", "description": "Capability kind. AIP-55 v2 is a capability; other capability kinds may exist under the capability/v1 pattern without their own AIP." },
93
+ "on": {
94
+ "$ref": "https://agentproto.sh/schemas/aip-54/REF.schema.json",
95
+ "description": "The referenced artifact this pricing attaches to (AIP-54 ref/v1). String contexts use the aip:// URI form, e.g. 'aip://42/book-companion@1.2.0'. The target AIP needs zero pricing awareness; hosts MUST refuse when the ref does not resolve."
96
+ },
97
+ "title": { "type": "string", "minLength": 1, "maxLength": 200, "description": "Human-readable display name, e.g. a checkout label." },
98
+ "description": { "type": "string", "minLength": 1, "maxLength": 2000 },
99
+ "price": { "$ref": "#/$defs/price", "description": "The source of truth for what is charged. billingRail is projection config; a generator derives Stripe Prices / Autumn features FROM this." },
100
+ "billingRail": { "$ref": "#/$defs/billingRail" },
101
+ "metadata": {
102
+ "type": "object",
103
+ "additionalProperties": true,
104
+ "description": "Vendor-specific extensions, namespaced under <vendor>. Hosts MUST tolerate unknown keys."
105
+ }
106
+ }
107
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentproto/corpus-cli",
3
- "version": "0.9.0",
3
+ "version": "0.9.3",
4
4
  "description": "@agentproto/corpus-cli — the `corpus` binary. Validate, lint, and operate an AIP-10 corpus workspace from the command line. Local-topology host for @agentproto/corpus — pair with a local backing engine (qdrant docker / gbrain) for a fully offline corpus runtime.",
5
5
  "keywords": [
6
6
  "agentproto",
@@ -52,17 +52,17 @@
52
52
  "gray-matter": "^4.0.3",
53
53
  "unpdf": "~1.8.1",
54
54
  "zod": "^4.5.4",
55
- "@agentproto/batch": "0.2.0",
56
- "@agentproto/cli-exec": "0.1.0",
57
- "@agentproto/corpus": "0.7.0",
58
- "@agentproto/corpus-presets": "0.2.8"
55
+ "@agentproto/batch": "0.2.1",
56
+ "@agentproto/corpus": "0.7.3",
57
+ "@agentproto/cli-exec": "0.1.1",
58
+ "@agentproto/corpus-presets": "0.2.11"
59
59
  },
60
60
  "devDependencies": {
61
- "@types/node": "^25.6.2",
61
+ "@types/node": "^25.9.5",
62
62
  "tsup": "^8.5.1",
63
63
  "typescript": "^5.9.3",
64
- "vitest": "^3.2.4",
65
- "@agentproto/tooling": "0.1.0-alpha.0"
64
+ "vitest": "^3.2.7",
65
+ "@agentproto/tooling": "0.1.0"
66
66
  },
67
67
  "engines": {
68
68
  "node": ">=20.9.0"