@yaag/runtime 0.11.0 → 0.13.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.
Files changed (44) hide show
  1. package/package.json +1 -1
  2. package/src/agent/agent-compaction.ts +1 -1
  3. package/src/agent/agent.ts +1 -1
  4. package/src/agent/define-agent.ts +7 -5
  5. package/src/agent/spawn-open.ts +2 -0
  6. package/src/ask/ask-exchange-events.ts +8 -3
  7. package/src/ask/ask-exchange.ts +6 -9
  8. package/src/catalog/agent-describe-fixture.ts +121 -0
  9. package/src/catalog/agent-describe.ts +210 -0
  10. package/src/catalog/catalog-entry.ts +39 -0
  11. package/src/catalog/catalog-fixture.ts +87 -0
  12. package/src/catalog/catalog-match.ts +77 -0
  13. package/src/catalog/catalog-result.ts +69 -0
  14. package/src/catalog/index.ts +57 -0
  15. package/src/catalog/load-catalog.ts +74 -0
  16. package/src/catalog/program-scan.ts +64 -0
  17. package/src/catalog/registry-paths.ts +26 -0
  18. package/src/catalog/registry-reader.ts +115 -0
  19. package/src/catalog/registry-schema.ts +119 -0
  20. package/src/config/config-paths.ts +14 -7
  21. package/src/config/index.ts +1 -0
  22. package/src/contract/agent-report.ts +42 -0
  23. package/src/contract/error-codes.ts +65 -0
  24. package/src/contract/handle.ts +132 -0
  25. package/src/contract/index.ts +34 -0
  26. package/src/contract/model-spec.ts +81 -0
  27. package/src/contract/spawn-options.ts +127 -0
  28. package/src/error-factories.ts +70 -0
  29. package/src/errors.ts +22 -118
  30. package/src/events.ts +13 -2
  31. package/src/index.ts +45 -0
  32. package/src/model/index.ts +1 -1
  33. package/src/model/model-resolution.ts +19 -71
  34. package/src/model/model-swap.ts +11 -2
  35. package/src/model/resolution-loop.ts +1 -1
  36. package/src/model/thinking-level.ts +5 -5
  37. package/src/public-api.ts +28 -0
  38. package/src/run/run-context.ts +4 -2
  39. package/src/summary/summary-agent.ts +8 -2
  40. package/src/summary/summary-model.ts +5 -1
  41. package/src/transport/live-transport.ts +2 -3
  42. package/src/transport/pi-state.ts +29 -9
  43. package/src/transport/transport.ts +10 -26
  44. package/src/types.ts +16 -243
package/src/types.ts CHANGED
@@ -1,246 +1,19 @@
1
- import type { Static, TSchema } from "typebox";
2
- import type { ModelSpec, ThinkingLevel, ThinkingSpec } from "./model/index.ts";
3
- import type { CompactionResult } from "./transport/index.ts";
4
-
5
- export type { ThinkingLevel } from "./model/index.ts";
6
- export type { CompactionResult } from "./transport/index.ts";
7
-
8
- /** Options for spawning one Agent (ADR-0001, ADR-0009, ADR-0026). */
9
- export interface SpawnOptions {
10
- /** Working directory. Defaults to the Orchestrator's cwd. */
11
- readonly cwd?: string;
12
- /**
13
- * Model pattern, e.g. "anthropic/claude-haiku-4". Unset inherits the user's default.
14
- *
15
- * An array is an ordered fallback list and a function picks the next candidate
16
- * from the failures so far. Any resolved pattern may carry an inline thinking
17
- * suffix (`"opus-5:medium"`), which wins over `thinking`. Each attempt settles
18
- * the model first, then the thinking level for that model. yaag starts a new
19
- * attempt only when pi reports `not_found`, `auth`, or `rate_limited`. See
20
- * `ModelSpec` and `ModelResolver` for the termination rules (ADR-0037).
21
- */
22
- readonly model?: ModelSpec;
23
- /** Replaces the default system prompt (`pi --system-prompt`). */
24
- readonly systemPrompt?: string;
25
- /**
26
- * Sets pi's thinking level; omission preserves pi's default. A function picks
27
- * the level from the settled model, and is not consulted for a model pattern
28
- * that carries an inline thinking suffix. The resolver runs again for each
29
- * attempt, with the model that settled for that attempt (ADR-0037).
30
- */
31
- readonly thinking?: ThinkingSpec;
32
- /** Appends text to pi's system prompt (`pi --append-system-prompt`). */
33
- readonly appendSystemPrompt?: string;
34
- /**
35
- * Restores pi discovery. Omission or false selects ADR-0026's hermetic baseline.
36
- */
37
- readonly inherit?: boolean;
38
- /**
39
- * Explicit pi extensions layer over either ADR-0026 baseline. Relative entries
40
- * resolve from the Orchestration Program file; each becomes `pi -e <path>`.
41
- */
42
- readonly extensions?: readonly string[];
43
- /**
44
- * Load the Effective Config's `agents.extensions` for this Agent. Default
45
- * true; false spawns with only the extensions this call declares (ADR-0040).
46
- */
47
- readonly configExtensions?: boolean;
48
- /**
49
- * Tool allowlist layered over the ADR-0026 baseline; omission is tool-free when hermetic.
50
- * `disallowedTools` applies last. A non-empty surviving allowlist is verified after startup;
51
- * a missing promised name rejects spawn.
52
- */
53
- readonly tools?: readonly string[];
54
- /**
55
- * Tool denylist applied last under ADR-0026; `['yaag_run']` prevents nested yaag Runs.
56
- * Denying an absent tool is inert and is not presence-validated.
57
- */
58
- readonly disallowedTools?: readonly string[];
59
- /**
60
- * Skill-name allowlist, not filesystem paths, layered over the ADR-0026 baseline.
61
- * Omission is skill-free when hermetic; `disallowedSkills` applies last. Unknown requested
62
- * names reject spawn.
63
- */
64
- readonly skills?: readonly string[];
65
- /** Skill-name denylist discovered from pi and applied last (ADR-0026). */
66
- readonly disallowedSkills?: readonly string[];
67
- /** Log and event label. Defaults to a1, a2, …; duplicate names are suffixed. */
68
- readonly name?: string;
69
- /** Request a fresh Git worktree. The requested cwd remains the base until spawn resolves. */
70
- readonly worktree?: boolean;
71
- /**
72
- * Names this Agent's parent in the Run tree (Parent Link). Data only: it is
73
- * no conversation channel and no lifetime rule.
74
- */
75
- readonly parent?: Handle;
76
- }
77
-
78
1
  /**
79
- * Spawn options after Model Resolution has settled one model and thinking level.
2
+ * The author-facing shapes of the runtime.
80
3
  *
81
- * This is the settled shape, and it is what the Cassette identity hashes
82
- * (ADR-0039).
83
- *
84
- * `parent` is omitted on purpose: a Handle must never reach this shape, because
85
- * an Ask records these options into the Cassette. Spawn resolves the Parent
86
- * Link to a name, which travels in `OpenOptions` and stays out of Ask identity.
87
- */
88
- export interface ResolvedSpawnOptions extends Omit<SpawnOptions, "model" | "thinking" | "parent"> {
89
- readonly model?: string;
90
- readonly thinking?: ThinkingLevel;
91
- }
92
-
93
- /**
94
- * What a fork may change about the Agent it copies (ADR-0044).
95
- *
96
- * A fork inherits the source's resolved spawn options verbatim: model,
97
- * thinking, tools, skills, system prompt, extensions and Ask defaults. `name`
98
- * is the exception — the child always gets a fresh auto-name unless this object
99
- * names one. The fork source becomes the child's default `parent`.
100
- *
101
- * The inherited model is the concrete one the source settled on, so the child
102
- * never re-runs the source's fallback list; `fork({ model })` is the way out.
103
- * A fork of a Worktree Agent gets its own fresh worktree, branched from the
104
- * source's branch, so only committed state transfers. The child re-runs the
105
- * ADR-0026 Tool Contract probe against its own effective options.
106
- */
107
- export interface ForkOptions extends SpawnOptions {
108
- /** true = pi's default compaction; a string = pi custom instructions. */
109
- readonly compact?: boolean | string;
110
- }
111
-
112
- /** Topology-only fields that may change when spawning an Agent Definition. */
113
- export interface SpawnOverrides {
114
- /** Log and event label. Defaults to the definition's name; duplicates are suffixed. */
115
- readonly name?: string;
116
- /** Working directory. Defaults to the Orchestrator's cwd. */
117
- readonly cwd?: string;
118
- /** Request a fresh Git worktree. */
119
- readonly worktree?: boolean;
120
- /** Names this Agent's parent in the Run tree (Parent Link). Data only. */
121
- readonly parent?: Handle;
122
- }
123
-
124
- /**
125
- * Options for one Ask (ADR-0003).
126
- *
127
- * Soft limits trip at their configured count: turns are `turn_start` frames and
128
- * tool calls are `tool_execution_start` frames between `agent_start` and
129
- * `agent_settled`; duration is wall time from prompt send. A trip steers the
130
- * Agent, permits one further turn (or a fixed duration grace), then aborts and
131
- * rejects with `ASK_LIMIT` if it has not settled. This leaves the Handle alive.
132
- * `timeoutMs` is independent: it kills the Agent and rejects with `ASK_TIMEOUT`.
133
- *
134
- * A model failure inside an Ask starts Model Fallback and retries the Ask
135
- * (ADR-0038). Each attempt gets fresh soft limits, a fresh Stall Watchdog and a
136
- * fresh output collector. `timeoutMs` is the exception: it is the hard ceiling
137
- * of the whole Ask, and every attempt shares one deadline.
138
- */
139
- export interface AskOptions {
140
- /** Reject and kill the Agent if it has not settled in time. Unset = no bound. */
141
- readonly timeoutMs?: number;
142
- /** Soft budget of `turn_start` frames between `agent_start` and `agent_settled`. */
143
- readonly maxTurns?: number;
144
- /** Soft budget of `tool_execution_start` frames between `agent_start` and `agent_settled`. */
145
- readonly maxToolCalls?: number;
146
- /** Soft wall-clock budget in milliseconds, measured from prompt send. */
147
- readonly maxDurationMs?: number;
148
- /**
149
- * Maximum silence in milliseconds: rejects with `ASK_STALLED` when no frame
150
- * arrives for this span. Complementary to `maxDurationMs` (silence vs.
151
- * trickle) and separate from `timeoutMs`, which always kills. Unset disables
152
- * idle detection (ADR-0020).
153
- */
154
- readonly idleMs?: number;
155
- /**
156
- * Silence budget in milliseconds for the Stall Watchdog, which guards every
157
- * live Ask by default (ADR-0029). On expiry yaag probes the Agent and either
158
- * recovers a missed settlement or rejects with `ASK_STALLED`. Omission uses
159
- * the 10-minute default. `false`, and any value that is not above zero,
160
- * disable the watchdog for this Ask. `ASK_STALLED` is a generic failure: it
161
- * never starts Model Fallback. If the silence budget ends the Ask before pi
162
- * reports a model failure, the Ask fails `ASK_STALLED` and no swap happens
163
- * (ADR-0029).
164
- */
165
- readonly stallMs?: number | false;
166
- /** Per-Ask replacement for the runtime's wrap-up steering message. */
167
- readonly wrapUpPrompt?: string;
168
- }
169
-
170
- /** Ask options that require a schema and preserve its inferred successful result. */
171
- export interface StructuredAskOptions<Schema extends TSchema> extends AskOptions {
172
- /**
173
- * TypeBox object schema the Agent reports its result against, instead of text.
174
- *
175
- * It becomes the input schema of one internal tool, so it must describe an
176
- * object (ADR-0032).
177
- */
178
- readonly outputSchema: Schema;
179
- /**
180
- * Maximum settlements without a reported result that this Ask corrects;
181
- * defaults to 3 when omitted. Argument repair inside a turn is the Agent's
182
- * own loop and costs nothing here.
183
- */
184
- readonly maxSteers?: number;
185
- }
186
-
187
- /**
188
- * A handle to one long-lived Agent.
189
- * ADR-0003: `ask()` is the only conversational verb; everything else is data.
4
+ * The declarations live in `contract/`, which imports nothing outside itself
5
+ * except `typebox` (ADR-0045). This file keeps the historic import path.
190
6
  */
191
- export interface Handle {
192
- /** Stable identity, used in every Lifecycle Event and log line. */
193
- readonly name: string;
194
- /** Resolved absolute working directory; a worktree's actual cwd after spawn resolves. */
195
- readonly cwd: string;
196
- /** Fresh branch for a worktree Agent; undefined for ordinary Agents. */
197
- readonly branch: string | undefined;
198
- /**
199
- * Model id as reported by the Agent's own `get_state` — not the requested
200
- * pattern. A mid-Ask model swap updates it (ADR-0038).
201
- */
202
- readonly model: string;
203
-
204
- /**
205
- * Sends a prompt and resolves after the Agent's turn settles.
206
- *
207
- * Schema-free calls resolve with the exact final assistant text. Calls with
208
- * `outputSchema` resolve with the TypeBox-validated value the Agent reports
209
- * through one internal tool call (ADR-0032). Rejects with a YaagError for a
210
- * failed or empty turn, timeout, `ASK_LIMIT`, or dead Agent. An Ask that
211
- * settles without a reported result is corrected at most `maxSteers` times
212
- * (default 3) and then rejects recoverably with `ASK_INVALID_OUTPUT` after an
213
- * abort settlement; a reported value the schema rejects fails the same way
214
- * without a correction. These recoverable outcomes leave the Handle reusable.
215
- * A retry after a Model Fallback discards the result the failed attempt
216
- * reported, and arms the collector again, so a stale result cannot settle the
217
- * retried Ask (ADR-0032, ADR-0038).
218
- * A concurrent call rejects with `AGENT_BUSY`.
219
- */
220
- ask<Schema extends TSchema>(
221
- prompt: string,
222
- options: StructuredAskOptions<Schema>,
223
- ): Promise<Static<Schema>>;
224
- ask(prompt: string, options?: AskOptions): Promise<string>;
225
-
226
- /**
227
- * Spawns a new Agent from a copy of this Agent's session (ADR-0044).
228
- *
229
- * The fork point is a settled Ask boundary: a call while an Ask is in flight
230
- * rejects with `FORK_DURING_ASK`. An Agent that died mid-Ask, or that holds
231
- * no session file, rejects with `FORK_REFUSED`. An Agent that exited cleanly
232
- * stays forkable, so a program can build context, let the Agent exit, then
233
- * fork its final state many times.
234
- */
235
- fork(overrides?: ForkOptions): Promise<Handle>;
236
-
237
- /**
238
- * Replaces this Agent's context with a summary of it (ADR-0043).
239
- *
240
- * `instructions` becomes pi's `customInstructions`. A call while an Ask is in
241
- * flight rejects with `COMPACT_DURING_ASK`; a refusal from pi rejects with
242
- * `COMPACT_FAILED`. The result reports what the summary call cost; each field
243
- * is null when pi reported nothing for it.
244
- */
245
- compact(instructions?: string): Promise<CompactionResult>;
246
- }
7
+ export type {
8
+ AgentProgress,
9
+ AskOptions,
10
+ CompactionResult,
11
+ ForkOptions,
12
+ Handle,
13
+ ModelError,
14
+ ResolvedSpawnOptions,
15
+ SpawnOptions,
16
+ SpawnOverrides,
17
+ StructuredAskOptions,
18
+ ThinkingLevel,
19
+ } from "./contract/index.ts";