@mono-agent/agent-runtime 0.3.0 → 0.4.1

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 (123) hide show
  1. package/ARCHITECTURE.md +75 -9
  2. package/MIGRATION.md +293 -0
  3. package/README.md +46 -20
  4. package/package.json +104 -10
  5. package/src/agent/allowlists.js +3 -0
  6. package/src/agent/approval.js +3 -0
  7. package/src/agent/compaction.js +231 -654
  8. package/src/agent/index.js +1 -1
  9. package/src/agent/prompt/skill-index.js +6 -0
  10. package/src/agent/sandbox-seam.js +227 -0
  11. package/src/agent/tool-bloat.js +8 -2
  12. package/src/agent/tools/bash.js +16 -8
  13. package/src/agent/tools/edit.js +7 -3
  14. package/src/agent/tools/glob.js +11 -5
  15. package/src/agent/tools/grep.js +11 -5
  16. package/src/agent/tools/pi-bridge.js +272 -54
  17. package/src/agent/tools/read.js +28 -3
  18. package/src/agent/tools/shared/output-truncation.js +8 -3
  19. package/src/agent/tools/shared/path-resolver.js +24 -18
  20. package/src/agent/tools/shared/ripgrep.js +33 -6
  21. package/src/agent/tools/shared/runtime-context.js +60 -50
  22. package/src/agent/tools/shared/tool-context.js +157 -0
  23. package/src/agent/tools/web-fetch.js +65 -18
  24. package/src/agent/tools/web-search.js +11 -4
  25. package/src/agent/tools/write.js +7 -3
  26. package/src/agent/transcript.js +16 -1
  27. package/src/ai/cost.js +128 -3
  28. package/src/ai/failure.js +96 -4
  29. package/src/ai/index.js +1 -0
  30. package/src/ai/live-input-prompt.js +11 -1
  31. package/src/ai/providers/claude-cli.js +6 -2
  32. package/src/ai/providers/claude-sdk.js +55 -12
  33. package/src/ai/providers/codex-app.js +36 -23
  34. package/src/ai/providers/opencode-app.js +2 -2
  35. package/src/ai/providers/opencode-discovery.js +2 -2
  36. package/src/ai/providers/pi-errors.js +65 -0
  37. package/src/ai/providers/pi-events.js +5 -0
  38. package/src/ai/providers/pi-models.js +21 -4
  39. package/src/ai/providers/pi-native/compaction-driver.js +394 -0
  40. package/src/ai/providers/pi-native/result-builder.js +312 -0
  41. package/src/ai/providers/pi-native/session-lifecycle.js +438 -0
  42. package/src/ai/providers/pi-native/stream-subscriber.js +148 -0
  43. package/src/ai/providers/pi-native/structured-output.js +130 -0
  44. package/src/ai/providers/pi-native/turn-runner.js +278 -0
  45. package/src/ai/providers/pi-native.js +754 -0
  46. package/src/ai/runtime/capabilities.js +3 -0
  47. package/src/ai/runtime/model-refs.js +30 -0
  48. package/src/ai/runtime/registry.js +33 -2
  49. package/src/ai/runtime/router.js +119 -19
  50. package/src/ai/runtime/session-liveness.js +110 -0
  51. package/src/ai/runtime/sessions.js +19 -2
  52. package/src/ai/types.js +252 -20
  53. package/src/index.js +1 -1
  54. package/src/pi-auth.js +147 -16
  55. package/src/runtime-brand.js +21 -1
  56. package/src/runtime.js +75 -10
  57. package/types/agent/allowlists.d.ts +25 -0
  58. package/types/agent/approval.d.ts +30 -0
  59. package/types/agent/compaction.d.ts +97 -0
  60. package/types/agent/index.d.ts +5 -0
  61. package/types/agent/prompt/skill-index.d.ts +19 -0
  62. package/types/agent/sandbox-seam.d.ts +148 -0
  63. package/types/agent/tool-bloat.d.ts +22 -0
  64. package/types/agent/tools/bash.d.ts +16 -0
  65. package/types/agent/tools/edit.d.ts +14 -0
  66. package/types/agent/tools/glob.d.ts +16 -0
  67. package/types/agent/tools/grep.d.ts +22 -0
  68. package/types/agent/tools/index.d.ts +10 -0
  69. package/types/agent/tools/pi-bridge.d.ts +144 -0
  70. package/types/agent/tools/read.d.ts +19 -0
  71. package/types/agent/tools/shared/constants.d.ts +13 -0
  72. package/types/agent/tools/shared/dedup.d.ts +8 -0
  73. package/types/agent/tools/shared/output-truncation.d.ts +22 -0
  74. package/types/agent/tools/shared/path-resolver.d.ts +6 -0
  75. package/types/agent/tools/shared/ripgrep.d.ts +38 -0
  76. package/types/agent/tools/shared/runtime-context.d.ts +27 -0
  77. package/types/agent/tools/shared/tool-context.d.ts +48 -0
  78. package/types/agent/tools/web-fetch.d.ts +13 -0
  79. package/types/agent/tools/web-search.d.ts +11 -0
  80. package/types/agent/tools/write.d.ts +12 -0
  81. package/types/agent/transcript.d.ts +45 -0
  82. package/types/ai/backend.d.ts +41 -0
  83. package/types/ai/cost.d.ts +96 -0
  84. package/types/ai/failure.d.ts +117 -0
  85. package/types/ai/file-change-stats.d.ts +75 -0
  86. package/types/ai/index.d.ts +7 -0
  87. package/types/ai/live-input-prompt.d.ts +6 -0
  88. package/types/ai/observer.d.ts +68 -0
  89. package/types/ai/providers/claude-cli.d.ts +211 -0
  90. package/types/ai/providers/claude-sdk.d.ts +66 -0
  91. package/types/ai/providers/claude-subagents.d.ts +2 -0
  92. package/types/ai/providers/codex-app.d.ts +151 -0
  93. package/types/ai/providers/opencode-app.d.ts +95 -0
  94. package/types/ai/providers/opencode-discovery.d.ts +4 -0
  95. package/types/ai/providers/pi-errors.d.ts +3 -0
  96. package/types/ai/providers/pi-events.d.ts +24 -0
  97. package/types/ai/providers/pi-messages.d.ts +5 -0
  98. package/types/ai/providers/pi-models.d.ts +57 -0
  99. package/types/ai/providers/pi-native/compaction-driver.d.ts +86 -0
  100. package/types/ai/providers/pi-native/result-builder.d.ts +168 -0
  101. package/types/ai/providers/pi-native/session-lifecycle.d.ts +62 -0
  102. package/types/ai/providers/pi-native/stream-subscriber.d.ts +50 -0
  103. package/types/ai/providers/pi-native/structured-output.d.ts +69 -0
  104. package/types/ai/providers/pi-native/turn-runner.d.ts +60 -0
  105. package/types/ai/providers/pi-native.d.ts +18 -0
  106. package/types/ai/registry.d.ts +1 -0
  107. package/types/ai/runtime/capabilities-used.d.ts +21 -0
  108. package/types/ai/runtime/capabilities.d.ts +33 -0
  109. package/types/ai/runtime/context-windows.d.ts +8 -0
  110. package/types/ai/runtime/fast-mode.d.ts +2 -0
  111. package/types/ai/runtime/model-refs.d.ts +35 -0
  112. package/types/ai/runtime/registry.d.ts +38 -0
  113. package/types/ai/runtime/router.d.ts +56 -0
  114. package/types/ai/runtime/session-liveness.d.ts +55 -0
  115. package/types/ai/runtime/sessions.d.ts +38 -0
  116. package/types/ai/streaming/codex-events.d.ts +30 -0
  117. package/types/ai/streaming/opencode-events.d.ts +41 -0
  118. package/types/ai/types.d.ts +702 -0
  119. package/types/index.d.ts +7 -0
  120. package/types/pi-auth.d.ts +28 -0
  121. package/types/runtime-brand.d.ts +30 -0
  122. package/types/runtime.d.ts +10 -0
  123. package/src/ai/providers/pi-sdk.js +0 -1310
package/ARCHITECTURE.md CHANGED
@@ -9,13 +9,18 @@ agent turn:
9
9
 
10
10
  - pick the right backend from a model reference and execution mode
11
11
  - expose built-in tools, MCP tools, approvals, structured output, and live input
12
- - enforce optional sandbox policy for built-in tool execution and stdio MCP startup
12
+ - enforce an optional sandbox policy for built-in tool execution and stdio MCP
13
+ startup, through an injectable seam (see `agent/sandbox-seam.js`) rather than
14
+ a bundled sandboxing implementation
13
15
  - normalize provider events into one runtime event stream
14
16
  - classify runtime failures and retryable provider errors
15
17
  - collect usage, cost, cache, capability, and warning telemetry
16
18
  - return raw text plus raw structured output to the host
17
19
 
18
- Hosts consume the package through `src/runtime.js`.
20
+ Hosts consume the package through `src/runtime.js`. The package has **zero
21
+ workspace-package dependencies**: everything a host-side integration would
22
+ otherwise need to inject (sandboxing, in this package's case) is expressed as
23
+ a plain-data/plain-function seam the host wires up, not an import.
19
24
 
20
25
  ## Package Boundary
21
26
 
@@ -135,11 +140,12 @@ flowchart TB
135
140
 
136
141
  Providers --> Claude["claude-sdk.js"]
137
142
  Providers --> ClaudeCode["claude-cli.js"]
138
- Providers --> Pi["pi-sdk.js<br/>pi-models/messages/events"]
143
+ Providers --> Pi["pi-native.js<br/>pi-models/messages/events"]
139
144
  Providers --> Codex["codex-app.js"]
140
145
 
141
146
  AgentExports --> Tools["agent/tools/*"]
142
- Tools --> ToolRuntime["shared/runtime-context.js<br/>workspace, repoRoot, rg, brand"]
147
+ Tools --> ToolContext["shared/tool-context.js<br/>per-instance ToolContext<br/>workspace, repoRoot, rg, sandbox, brand"]
148
+ ToolContext --> ToolRuntime["shared/runtime-context.js<br/>back-compat DEFAULT context<br/>(module-level singleton wrapping tool-context.js)"]
143
149
  Tools --> PiBridge["tools/pi-bridge.js<br/>built-ins + MCP adaptation"]
144
150
 
145
151
  AgentExports --> Compaction["agent/compaction.js"]
@@ -155,8 +161,9 @@ flowchart TB
155
161
 
156
162
  Key responsibilities by subsystem:
157
163
 
158
- - `runtime.js`: binds host callbacks once, configures tool runtime context, and
159
- routes each call to the resolved bridge.
164
+ - `runtime.js`: binds host callbacks once, builds a per-instance `ToolContext`
165
+ (`agent/tools/shared/tool-context.js`) threaded to every bridge call via
166
+ `options.toolContext`, and routes each call to the resolved bridge.
160
167
  - `ai/runtime/registry.js`: maps model reference plus execution mode to one of
161
168
  the built-in provider bridges.
162
169
  - `ai/runtime/router.js`: retries across an ordered fallback chain on retryable
@@ -166,8 +173,22 @@ Key responsibilities by subsystem:
166
173
  - `agent/tools/*`: implements built-in tools, path/workdir guards, sandbox
167
174
  policy checks, MCP tool adaptation, Playwright artifact routing, and output
168
175
  limits.
169
- - `agent/compaction.js`: estimates context pressure and compacts long agent
170
- conversations for providers that support the package's compaction loop.
176
+ - `agent/sandbox-seam.js`: the injectable `RuntimeSandbox` interface (policy
177
+ merge, command preparation, network-allow checks) and its zero-dependency
178
+ `passthroughSandbox` default (no policy configured → unsandboxed, exactly as
179
+ before; a policy configured with no implementation injected → fails closed).
180
+ Real hosts inject `@mono-agent/runtime-adapter`'s sandbox implementation.
181
+ - `agent/compaction.js`: pure helpers consumed by the pi bridge —
182
+ `resolveAgentCompactionPolicy` (derives the context-window compaction trigger +
183
+ tool-output payload limits from `agent_compaction_*` settings and the running
184
+ model), `estimateFixedOverheadTokens` (the proactive fixed-overhead correction:
185
+ system prompt + tool schemas + per-turn message), `isLikelyContextTermination`
186
+ (classifies a context-pressure error), and the typed-policy/`settings`-bag shim
187
+ helpers (`resolveRuntimePolicyInputs`, `deprecatedSettingsWarning`) that let a
188
+ present `toolLimits`/`compaction` object win wholesale per-group over the
189
+ deprecated flat `settings` bag (MIGRATION.md §8). The bridge drives compaction
190
+ itself via `AgentHarness.compact()` (proactive + reactive recovery); the legacy
191
+ in-loop `transformContext` manager was removed.
171
192
  - `agent/transcript.js`: builds bounded resume snapshots from prior provider
172
193
  events so a fallback or continuation can keep context.
173
194
  - `agent/approval.js`: provides host-driven human-in-the-loop tool approval
@@ -204,11 +225,56 @@ The host is responsible for:
204
225
  - resolving credentials and custom provider/model rows before provider calls
205
226
  - choosing model references, execution mode, effort, fallback chains, and
206
227
  runtime settings
207
- - persisting artifacts, compaction rows, raw logs, run rows, and UI-facing state
228
+ - persisting artifacts, raw logs, run rows, and UI-facing state (via the
229
+ `onCompactionRecorded` hook, which fires on every automatic compaction —
230
+ proactive or reactive — the pi bridge drives)
208
231
  - validating structured output against the host's domain contract
209
232
  - converting runtime failures into product workflow behavior
210
233
  - deciding when to retry, recover, continue, cancel, or ask for user input
211
234
 
235
+ ## Sessions, Follow-ups & Concurrency
236
+
237
+ When `runtime.session.mode = "continuous"`, the harness keeps a conversation's
238
+ provider session warm and serializes its turns through a per-conversation queue
239
+ (`@mono-agent/agent-harness` `LiveSessionManager`). A message that arrives while
240
+ a turn is in flight is **queued and answered on the warm session after the
241
+ current turn finishes** (queue-after-turn) rather than rejected — this is what
242
+ powers follow-up messages in chat channels. Different conversations run
243
+ concurrently; an optional `concurrency.maxConcurrentRuns` bounds simultaneous
244
+ model runs via admission control around the provider call (queued follow-ups
245
+ hold no slot, so the bound never deadlocks against the queue). Note this bound is
246
+ **per harness instance** — the app builds one harness per channel, so the limiter
247
+ is per-channel, not a single global cap; with N enabled channels the effective
248
+ ceiling is N× the configured value. Channels surface
249
+ a user cancel through `responder.cancel(conversationId)`, which aborts the
250
+ in-flight turn and clears that conversation's queue.
251
+
252
+ **Honest per-provider session behavior** — parity is *behavioral* (every
253
+ provider exposes queue-after-turn), not durability/cost:
254
+
255
+ The pi runtime is built on pi-agent-core's native `AgentHarness` (the hand-rolled
256
+ bridge was removed once native reached parity); it owns the session and
257
+ pi-ai-managed retry. `AgentHarness` itself has **no** automatic compaction, so
258
+ the pi bridge drives it directly: before each turn it estimates the running
259
+ model's context usage and calls `AgentHarness.compact()` when near the window
260
+ (proactive), and if a turn still overflows it compacts once and re-prompts
261
+ (reactive recovery). Runs report `context_compaction_applied` as `true` (a
262
+ compaction fired), `false` (enabled but not needed), or `null` (disabled via
263
+ `agent_compaction_enabled: false`).
264
+
265
+ | Provider | Warm session | Resume across turns | Survives process restart |
266
+ |---|---|---|---|
267
+ | **pi** | Yes (pi `AgentHarness` + JSONL session repo) | session repo | **Yes** (only one) |
268
+ | **claude-sdk** | No persistent process (stream closes at turn end) | `queryOptions.resume` | No (Anthropic-side id) |
269
+ | **claude-cli** | No — respawns `claude --resume` per turn (re-inits MCP) | `--resume` replay | No |
270
+ | **codex-app** | Live subprocess thread (dies with the subprocess) | next turn on the thread, else replay | No |
271
+
272
+ claude-cli and codex only *approximate* a warm session (resume/replay), so do
273
+ not assume warm-session latency wins there. Recall (memory embeddings) is bounded
274
+ by a timeout + circuit breaker and degrades to empty (with a `memory_degraded`
275
+ warning) rather than blocking or failing a turn; selected skills are mtime-cached
276
+ across turns.
277
+
212
278
  ## Essential Takeaway
213
279
 
214
280
  Think of `@mono-agent/agent-runtime` as the portable agent process engine
package/MIGRATION.md ADDED
@@ -0,0 +1,293 @@
1
+ # `@mono-agent/agent-runtime` — Migration Guide
2
+
3
+ Breaking and behavioral changes for consumers upgrading **from `0.3.x`** (the
4
+ `feat/runtime-live-sessions` line). The public entry points are unchanged —
5
+ `createRuntime` / `createMonoRuntime`, the run-options contract, and provider
6
+ session support (`sessionId` in, `provider_session_id` out, `disposeSession` /
7
+ `disposeAllSessions`) all keep their shapes. The changes below affect the **Pi
8
+ runtime bridge, a few run options, durable-session semantics, the fallback
9
+ router, and some diagnostics**.
10
+
11
+ If you only use the Claude SDK / Claude CLI / Codex backends and do not touch Pi
12
+ or durable sessions, this is a no-op upgrade.
13
+
14
+ ---
15
+
16
+ ## 1. Pi is now native-only (`pi-sdk.js` → `pi-native.js`)
17
+
18
+ The hand-rolled Pi bridge that drove the low-level `Agent` was replaced by a
19
+ bridge built on `@earendil-works/pi-agent-core`'s high-level `AgentHarness`. The
20
+ registry resolves `pi` → the native bridge unconditionally; there is no
21
+ `piEngine` flag.
22
+
23
+ - **Public runtime API** (`createRuntime`, model reference `"pi:<provider>:<model>"`)
24
+ is unchanged — `pi:openai:gpt-5.5` etc. still work.
25
+ - **Deep imports** of `@mono-agent/agent-runtime/ai/providers/pi-sdk.js` **no
26
+ longer resolve**: the deprecated compatibility shim was removed and, with the
27
+ Phase-6 explicit `exports` map (no `./ai/*` / `./agent/*` wildcards), that
28
+ subpath is not exported. **Action:** import `generatePiNativeResponse` /
29
+ `piNativeRuntimeBridge` from `./ai`, and
30
+ `isContextLimitError` / `normalizePiErrorMessage` from `./ai/providers/pi-errors.js`
31
+ (or reach for the public runtime registry). The `pi*Backend` aliases are gone —
32
+ all Pi routes through the one native bridge.
33
+
34
+ ## 2. Removed run options: `piReasoningSummary`, `piCodexTransport`
35
+
36
+ These were Pi-bridge knobs the native path does not consume.
37
+
38
+ - `piReasoningSummary` is **no longer read** and was removed from the run-options
39
+ type. Pi-native derives reasoning from `effort` (`thinkingLevel`); the
40
+ codex/claude CLIs emit reasoning summaries on their own. **Action:** stop
41
+ passing `piReasoningSummary` — it was already a no-op on the native path; remove
42
+ it from your call sites. (Host config `runtime.reasoningSummary` still validates
43
+ for back-compat but is not wired to a runtime option.)
44
+ - `piCodexTransport` was doc-only and is removed. No replacement is needed.
45
+
46
+ ## 3. Pi context compaction: bridge-driven via AgentHarness.compact()
47
+
48
+ `AgentHarness` has no automatic compaction, so the pi bridge drives it directly
49
+ (the legacy low-level `transformContext` / `afterToolCall` hooks and
50
+ `createAgentCompactionManager` were removed):
51
+
52
+ - Before each turn the bridge estimates the running model's context usage and
53
+ calls `AgentHarness.compact()` when near the window (proactive). If a turn still
54
+ overflows the bridge compacts once and re-prompts (reactive recovery).
55
+ - Runs report **`capabilitiesUsed.context_compaction_applied`** as `true` (a
56
+ compaction fired), `false` (enabled but not needed), or `null` (disabled via
57
+ `agent_compaction_enabled: false`). If you assert on this value, expect this
58
+ tristate on the Pi path.
59
+ - The host **`onCompactionRecorded`** callback now **fires on each automatic
60
+ compaction** on the Pi path (previously inert).
61
+ - The trigger window auto-tracks the model actually serving the request
62
+ (`harness.getModel()`) and self-corrects from any real ceiling stated in an
63
+ overflow error, so a wrong/default `context_window` no longer defeats it.
64
+ `resolveAgentCompactionPolicy` (`agent_compaction_*` settings) remains exported.
65
+
66
+ ## 4. Durable Pi session resume: create-on-miss semantics
67
+
68
+ When a run supplies a `sessionId` **and** durable storage is configured
69
+ (`piSessionsRoot`), Pi-native now **creates the session with that id if no
70
+ on-disk JSONL exists** (create-on-miss), instead of returning
71
+ `session_not_found`. An existing JSONL is reopened and resumed as before.
72
+
73
+ This makes a **stable, conversation-derived session id resume across process
74
+ restarts** (the on-disk transcript is the durable history; the in-memory
75
+ conversation→session map is no longer required to resume). **Action:** if you
76
+ passed an arbitrary `sessionId` to a durable run expecting a hard
77
+ `session_not_found` on first use, note it now succeeds by creating that session.
78
+ The in-memory (non-durable) resume path still fast-fails `session_not_found` on a
79
+ miss.
80
+
81
+ ## 5. Fallback router enforces requested native-subagent capability
82
+
83
+ Pi advertises `supports_native_subagents: false`. The fallback router now infers
84
+ a `supports_native_subagents` requirement when a run passes
85
+ `options.nativeSubagents.teammates` (non-empty), the same way it already infers
86
+ `structured_output` from `outputSchema`. A chain entry that cannot satisfy it
87
+ (e.g. a Pi fallback behind a Claude primary that was handed native teammates) is
88
+ **skipped** (`skipped_capability_mismatch`) rather than silently succeeding with
89
+ `nativeSubagentsUsed: []`. **Action:** if you configure fallback chains for
90
+ native-subagent runs, ensure at least one entry supports native subagents, or the
91
+ run reports exhausted instead of degrading silently.
92
+
93
+ ## 6. Diagnostics & internal behavior changes (no API change)
94
+
95
+ - **Pi multimodal**: image inputs are delivered to the model as image content
96
+ blocks (internal fix; affects behavior, not the call shape).
97
+ - **Tool-output limits**: settings-driven clamps (`agent_tool_text_limit_chars`,
98
+ `agent_search_result_limit`, `toolPayloadMaxBytes`, …) are honored again on the
99
+ Pi path (built-ins + MCP). The 256 KB tool-payload ceiling is unchanged.
100
+ - **WebFetch** retries transient network errors (timeout / ECONNRESET / 5xx)
101
+ in-tool with backoff before returning an error.
102
+ - **Claude CLI**: the temporary `mcp.json` written for a CLI run is now created
103
+ with `0600` (owner-only) permissions.
104
+ - Pi session lifecycle is hardened: aborts during setup are honored before the
105
+ provider call, fresh durable sessions are deleted on setup/abort failure, and
106
+ resumed sessions roll back to their pre-turn leaf on host-side (outer-catch)
107
+ failures. These are correctness fixes with no API surface change.
108
+
109
+ ## 7. Sandbox enforcement is now an injectable seam (agent-runtime has zero workspace-package dependencies)
110
+
111
+ `@mono-agent/agent-runtime` does not depend on `@mono-agent/runtime-adapter`. Sandbox
112
+ enforcement (command sandboxing, network-policy checks, and monotonic policy
113
+ merging) is now driven through an injectable `RuntimeSandbox` seam
114
+ (`agent/sandbox-seam.js`): `createRuntime({sandbox})` / `createRouterRuntime({host: {sandbox}})`
115
+ accept an implementation. `@mono-agent/runtime-adapter` injects the real
116
+ sandbox implementation automatically for every
117
+ `createMonoRuntime(...)` call, so behavior is **byte-identical** for existing
118
+ mono-agent hosts — no action needed if you build your runtime through
119
+ `@mono-agent/runtime-adapter`.
120
+
121
+ - **No sandbox policy configured, no implementation injected:** unchanged —
122
+ every tool runs unsandboxed, exactly as before.
123
+ - **A sandbox policy IS configured, but no `RuntimeSandbox` implementation is
124
+ injected** (only possible if you call `@mono-agent/agent-runtime`'s
125
+ `createRuntime` directly, bypassing `@mono-agent/runtime-adapter`): **this
126
+ now fails closed** with a `sandbox_unavailable` error instead of silently
127
+ running the command unsandboxed. Previously `@mono-agent/agent-runtime`
128
+ always bundled the real sandbox implementation and always enforced the policy; a
129
+ host that built on `createRuntime` directly and relied on that implicit
130
+ availability must now also inject a `RuntimeSandbox` implementation (the
131
+ real one from `@mono-agent/runtime-adapter`, or a custom one) to keep policies
132
+ enforced. **Action:** if you configure `sandboxPolicy` and call
133
+ `createRuntime`/`createRouterRuntime` directly instead of going through
134
+ `@mono-agent/runtime-adapter`, also pass a `sandbox` implementation, or drop
135
+ the policy.
136
+
137
+ ## 8. Typed run options replace the `settings` bag (`toolLimits` / `compaction` / `prompts`)
138
+
139
+ The flat `options.settings` bag is **deprecated** as the way to configure
140
+ tool-output clamps and context compaction. The supported replacements are typed,
141
+ per-run objects on `RuntimeRunOptions`:
142
+
143
+ - **`options.toolLimits`** (`RuntimeToolLimits`) — `toolTextLimitChars`,
144
+ `bashOutputLimitChars`, `mcpTextLimitChars`, `searchResultLimit`,
145
+ `imageInlineMaxBytes`, `toolPayloadMaxBytes`, `mcpCallTimeoutMs`,
146
+ `mcpCallMaxTotalTimeoutMs`, `bashTimeoutMs`.
147
+ - **`options.compaction`** (`RuntimeCompactionPolicy`) — `enabled`,
148
+ `triggerRatio`, `keepRecentTokens`, `summaryMaxTokens`, `minSavingsTokens`,
149
+ `fixedOverheadEnabled`, `contextWindowOverride`.
150
+
151
+ Precedence is **per-group**: a present typed object wins wholesale for its group
152
+ and that group's legacy `settings` keys are ignored; an absent typed object lets
153
+ its group's `settings` keys through as a fallback. Consuming **any** legacy
154
+ `settings` key emits exactly one `runtime_warning` with
155
+ **`warning_kind: "deprecated_settings_option"`** per run (listing the consumed
156
+ keys). Passing no `settings` — or an empty/irrelevant bag — never warns, so a host
157
+ that never passed `settings` is byte-for-byte unchanged (mono-agent hosts do not
158
+ pass it, so this is a no-op there).
159
+
160
+ `resolveAgentCompactionPolicy(settings, model)` stays exported (the canonical
161
+ clamp/mapper both paths route through), and `@mono-agent/runtime-adapter` exposes
162
+ `resolveRuntimePolicies(settings)` to map a legacy bag to the typed objects.
163
+ **Action:** migrate `settings` → `toolLimits` / `compaction`; until then the shim
164
+ keeps working with one deprecation warning per run.
165
+
166
+ ## 9. New per-run overrides: `sandbox`, `sandboxPolicy`, `prompts`
167
+
168
+ Beyond `toolLimits` / `compaction`, `RuntimeRunOptions` gained:
169
+
170
+ - **`sandbox`** — a per-run `RuntimeSandbox` implementation override. Precedence
171
+ is run > host > passthrough; it overrides only the *enforcing code*, while the
172
+ policy **data** still merges monotonically (I13, section 7).
173
+ - **`sandboxPolicy`** — per-run policy data, merged monotonically with the host
174
+ policy (it can **tighten**, never weaken or disable).
175
+ - **`prompts`** (`RuntimePromptOverrides`) — per-run overrides of the kernel's
176
+ built-in prompt fragments: `structuredOutputInstruction(systemPrompt)`,
177
+ `structuredOutputFinalization()`, `liveInputGuidance(body)`. Run wins over the
178
+ host-level `prompts` default; an absent field keeps the built-in string
179
+ (byte-identical default). These are also accepted on `AgentRuntimeHostOptions`
180
+ as the host-level default.
181
+
182
+ ## 10. Pi 0.80 auth: `Models` credential store (`resolvePiApiKey` semantics preserved)
183
+
184
+ Pi 0.80 removed the harness `getApiKeyAndHeaders` hook; request auth now resolves
185
+ through a `Models` collection's `CredentialStore`. The bridge's **per-run
186
+ key-resolution contract is unchanged**: an `apiKeys` map entry wins, else the host
187
+ `resolvePiApiKey(provider)` callback is consulted; a callback failure emits a
188
+ `pi_auth_failed` runtime warning and proceeds keyless (a builtin provider then
189
+ falls back to its own env vars, exactly as returning `undefined` from the old hook
190
+ did). **No host action needed** — `resolvePiApiKey` behaves as before.
191
+
192
+ Dependency bump: **`@earendil-works/pi-ai` and `@earendil-works/pi-agent-core` are
193
+ now `^0.80.x`** (were `^0.79.1`). Compaction is driven natively (section 3).
194
+
195
+ ## 11. Exports map: wildcards removed (explicit deep-path map)
196
+
197
+ The package's `./ai/*` and `./agent/*` **wildcard exports were replaced by an
198
+ explicit `exports` map**: 3 barrels (`.`, `./ai`, `./agent`) plus **21 named deep
199
+ `.js` subpaths**, each carrying its own generated `types` condition. A deep import
200
+ that is not on the map **no longer resolves** — a wildcard used to silently
201
+ resolve anything under `src/`, so a moved/renamed/mistyped subpath is now a loud
202
+ failure (guarded by `scripts/verify-deep-imports.mjs`).
203
+
204
+ The 21 supported deep paths:
205
+
206
+ ```
207
+ ./ai/failure.js ./agent/tools/index.js
208
+ ./ai/cost.js ./agent/tools/shared/runtime-context.js
209
+ ./ai/backend.js ./agent/tools/shared/ripgrep.js
210
+ ./ai/runtime/model-refs.js ./agent/prompt/skill-index.js
211
+ ./ai/runtime/registry.js ./agent/allowlists.js
212
+ ./ai/runtime/context-windows.js ./agent/transcript.js
213
+ ./ai/runtime/fast-mode.js ./agent/compaction.js
214
+ ./ai/streaming/codex-events.js
215
+ ./ai/live-input-prompt.js
216
+ ./ai/file-change-stats.js
217
+ ./ai/providers/claude-sdk.js
218
+ ./ai/providers/claude-cli.js
219
+ ./ai/providers/codex-app.js
220
+ ./ai/providers/opencode-discovery.js
221
+ ```
222
+
223
+ **Action:** if you deep-import a subpath not in this list, switch to the closest
224
+ supported one, a barrel (`./ai` / `./agent`), or the public runtime registry.
225
+ `pi-sdk.js` is gone and remains intentionally unexported (section 1). Worklab
226
+ ports should import `generatePiNativeResponse` from `@mono-agent/agent-runtime/ai`
227
+ instead of adding a `pi-sdk.js` compatibility subpath.
228
+
229
+ ---
230
+
231
+ ## Version
232
+
233
+ These changes ship in the first `agent-runtime` release after `0.3.0` on the
234
+ `feat/runtime-live-sessions` line (a minor/major bump; see the release tag). The
235
+ paired `@mono-agent/runtime-adapter` drops the `piReasoningSummary` field from its
236
+ run-options type in lockstep.
237
+
238
+ ---
239
+
240
+ ## Appendix — Porting this kernel to a new scope/host (worklab port-readiness)
241
+
242
+ This kernel is designed to be vendored into a differently-scoped host (the
243
+ concrete target is **worklab**, `@worklab-ai/agent-runtime`, GPL-3.0-only, npm
244
+ workspaces, pure-JS no-build, consuming this package's raw `src/`). The port
245
+ itself is a follow-up; this is the executable checklist, with the port-readiness
246
+ dry-run results recorded inline (verified against the worklab tree read-only).
247
+
248
+ Run these before/at the port:
249
+
250
+ 1. **Scope rename `@mono-agent/` → `@worklab-ai/`.** Touches `package.json`
251
+ (`name` + the package-name prefix inside each `exports` key's consumer
252
+ specifier) only — the kernel's own source uses **relative** imports, so no
253
+ source import references the scope. *(Verified: zero `@mono-agent/*` specifiers
254
+ in `src/`.)*
255
+ 2. **Dependencies.** Post-decoupling the kernel has **zero workspace-package
256
+ deps**; only the third-party pins need aligning: `@earendil-works/pi-ai` +
257
+ `@earendil-works/pi-agent-core` (`^0.80.x`), `@modelcontextprotocol/sdk`,
258
+ `@opencode-ai/sdk`, `@anthropic-ai/claude-agent-sdk`, `zod`.
259
+ 3. **Pi bump `^0.74.0` → `^0.80.x` in lockstep.** worklab tests that use old pi
260
+ APIs are rewritten at the port. Do not restore the old `pi-sdk.js` deep
261
+ import; use `generatePiNativeResponse` from `@mono-agent/agent-runtime/ai`.
262
+ 4. **Sandbox.** worklab passes **no** `sandbox` implementation → `passthroughSandbox`,
263
+ and **never sets `sandboxPolicy`** *(verified: zero `sandboxPolicy` /
264
+ `sandbox:` in worklab `src/`)*, so with no policy every tool runs unsandboxed
265
+ exactly as today — behavior is byte-identical. (If worklab later adds a policy,
266
+ it must also inject a `RuntimeSandbox` impl — section 7's fail-closed rule.)
267
+ 5. **License / packaging.** GPL-3.0-only stays; `files` includes `types/`
268
+ (additive — worklab consumes raw `src/`, `.d.ts` generation is optional).
269
+ 6. **Deep imports resolve.** `node scripts/verify-deep-imports.mjs` (default +
270
+ types conditions) is green. Every worklab **non-test** deep import resolves in
271
+ the explicit exports map *(verified — no gap)*, and the Worklab-test provider
272
+ bridge imports for `claude-sdk.js`, `claude-cli.js`, and `codex-app.js` are
273
+ supported as exported subpaths. The only worklab deep import NOT in the map is
274
+ the removed **test-only** `pi-sdk.js`; those tests are rewritten at the port
275
+ (step 3), so no export entry is added for it.
276
+ 7. **Contract supersets.** `HOST_KEYS` ⊇ worklab's host bag *(verified:
277
+ worklab passes `resolveCustomPricing`, `onCompactionRecorded`, `persistArtifact`,
278
+ `resolvePiApiKey`, `observers` — all covered)*; the deep-import
279
+ `configureToolRuntime` accepts worklab's keys *(verified: `workspace`,
280
+ `repoRoot`, `runId`, `toolArtifactDir`, `ripgrepPath`, `qaOutputDir` ⊂
281
+ `TOOL_CONTEXT_KEYS`)*; and every `RuntimeResult` field worklab's
282
+ `worker/agent-turn.js` reads exists on the result *(verified: `cancelled`,
283
+ `providerSessionId`, `error`, `failureKind`, `errorDetails`, `diagnostics`,
284
+ `runtimeWarnings`, plus `text`/`usage`/`model`/`effort`/`numTurns`/
285
+ `structuredResult`/`capabilitiesUsed`/`durationMs`/`failoverHistory`;
286
+ `observerSnapshot` is worklab-side, folded from its own metrics observer)*.
287
+ 8. **`options.settings` day one.** Works via the deprecated shim (section 8) with
288
+ one `deprecated_settings_option` warning per run; worklab later maps
289
+ `settings` → the typed policy objects in its `core/ai.js`.
290
+ 9. **Test layout + no-build consumption.** `src/__tests__` + vitest already match;
291
+ the package is fully consumable from raw `src/` with **no build**
292
+ *(verified: a smoke import of `createRuntime` / `createRouterRuntime` from
293
+ `src/index.js` constructs a runtime with no model call)*.
package/README.md CHANGED
@@ -6,7 +6,7 @@ Category: `runtime`
6
6
 
7
7
  ## Responsibility
8
8
 
9
- Provides the multi-backend agent runtime bridges (Claude SDK, Claude Code CLI, Codex app-server, Pi SDK) with provider session support. This is the runtime layer that `@mono-agent/runtime-adapter` wraps behind runtime contracts, and it enforces optional `@mono-agent/sandbox` policy for runtime-owned tools.
9
+ Provides the multi-backend agent runtime bridges (Claude SDK, Claude Code CLI, Codex app-server, Pi SDK) with provider session support. This is the runtime layer that `@mono-agent/runtime-adapter` wraps behind runtime contracts, and it enforces an optional sandbox policy for runtime-owned tools through an injectable `RuntimeSandbox` seam (a fail-closed passthrough by default; `@mono-agent/runtime-adapter` injects the real sandbox implementation for mono-agent hosts).
10
10
 
11
11
  ## Public API
12
12
 
@@ -15,17 +15,17 @@ Provides the multi-backend agent runtime bridges (Claude SDK, Claude Code CLI, C
15
15
  - `ai/runtime/registry.js` — `listRuntimeBridges`
16
16
  - Provider bridges for `claude` (SDK + CLI), `codex` (app-server), `pi` (Pi SDK), and `opencode`
17
17
  - Provider session support: bridges accept `sessionId` in run options and report `provider_session_id`; the runtime exposes `disposeSession` / `disposeAllSessions`
18
- - Sandbox-aware built-in tools and stdio MCP startup through `@mono-agent/sandbox`
18
+ - Sandbox-aware built-in tools and stdio MCP startup through an injectable `RuntimeSandbox` seam (`agent/sandbox-seam.js`) — no direct dependency on `@mono-agent/runtime-adapter`
19
19
 
20
20
  ## Dependency Boundary
21
21
 
22
- Depends on external provider SDKs (`@anthropic-ai/claude-agent-sdk`, `@earendil-works/pi-agent-core`, `@earendil-works/pi-ai`, `@modelcontextprotocol/sdk`, `@opencode-ai/sdk`, `zod`) plus `@mono-agent/sandbox` for runtime-owned command preparation and network/path policy checks.
22
+ Depends on external provider SDKs only (`@anthropic-ai/claude-agent-sdk`, `@earendil-works/pi-agent-core`, `@earendil-works/pi-ai`, `@modelcontextprotocol/sdk`, `@opencode-ai/sdk`, `zod`) **zero `@mono-agent/*` workspace-package dependencies**. Sandbox enforcement for runtime-owned command preparation and network/path policy checks is an injectable `RuntimeSandbox` seam; `@mono-agent/runtime-adapter` wires in the real sandbox implementation automatically for mono-agent hosts.
23
23
 
24
24
  ## What This Package Does Not Own
25
25
 
26
26
  - runtime contracts and backend descriptors (`@mono-agent/runtime-adapter`)
27
27
  - Conversation history, context building, or host-side session TTL policy (`@mono-agent/agent-harness`)
28
- - Host configuration (`@mono-agent/config`, `@mono-agent/agent-host`)
28
+ - Host configuration (`@mono-agent/config`, `@mono-agent/agent-app`)
29
29
 
30
30
  ## Verification
31
31
 
@@ -42,10 +42,12 @@ Generic agent runtime that supports four backends out of the box:
42
42
  - **Pi SDK** (`@earendil-works/pi-agent-core`, used for OpenAI / Codex / Gemini / OpenRouter / Ollama / etc. via Pi providers)
43
43
  - **Codex CLI** (the `codex` app-server)
44
44
 
45
- Hosts wire in their own pricing, persistence, credential, and compaction-recording callbacks. The runtime returns raw text + raw structured output; hosts that want a domain-specific contract parse it on their end.
45
+ Hosts wire in their own pricing, persistence, and credential callbacks (plus an `onCompactionRecorded` hook that fires on every automatic compaction — proactive or reactive — the pi bridge drives; see "Context compaction"). The runtime returns raw text + raw structured output; hosts that want a domain-specific contract parse it on their end.
46
46
 
47
47
  See [ARCHITECTURE.md](./ARCHITECTURE.md) for the package boundary, runtime
48
- selection flow, lifecycle diagrams, and host responsibilities.
48
+ selection flow, lifecycle diagrams, and host responsibilities. Upgrading from
49
+ `0.3.x`? See [MIGRATION.md](./MIGRATION.md) for the Pi-native bridge, removed run
50
+ options, durable-session resume semantics, and fallback-router changes.
49
51
 
50
52
  ## Install / Usage
51
53
 
@@ -89,7 +91,7 @@ console.log(result.text);
89
91
  `@mono-agent/agent-runtime` is purpose-built for **autonomous, long-running agent work** with provider portability and operational resilience as first-class concerns. It is *not* a streaming-chat UI kit. Where each peer fits:
90
92
 
91
93
  - **Vercel AI SDK** — best when you're building a chat / generative-UI experience inside a React or Next.js app. `useChat`, `useCompletion`, streaming server components, and edge-runtime compatibility are their strengths. Their provider list is curated (Anthropic, OpenAI, Google, etc., via `@ai-sdk/*` packages); there's no Pi gateway, no Claude Code CLI, no Codex CLI app-server, and no per-call provider fallback. If you're rendering a streaming chat into a browser, use them. If you're orchestrating multi-turn autonomous work that must survive a rate-limited primary provider, use us.
92
- - **Claude Agent SDK** (`@anthropic-ai/claude-agent-sdk`) — first-party Anthropic SDK. Tight integration with Claude features (canUseTool, sub-agents, hooks, MCP). We *wrap* it as one of our four backends and add context compaction, transcript-resume across provider drops, a 22-kind failure taxonomy, a tool-bloat guard with artifact persistence, and a provider fallback router. Reach for the bare Anthropic SDK when you only ever talk to Claude and don't need cross-provider portability or resume.
94
+ - **Claude Agent SDK** (`@anthropic-ai/claude-agent-sdk`) — first-party Anthropic SDK. Tight integration with Claude features (canUseTool, sub-agents, hooks, MCP). We *wrap* it as one of our four backends and add transcript-resume across provider drops, a 22-kind failure taxonomy, a tool-bloat guard with artifact persistence, and a provider fallback router. Context/window handling stays with the provider — the runtime does not run its own in-loop summarization pass. Reach for the bare Anthropic SDK when you only ever talk to Claude and don't need cross-provider portability or resume.
93
95
  - **Mastra** — a workflow engine + memory + RAG stack. Different category: it's the layer *above* a runtime. You can layer Mastra workflows on top of `@mono-agent/agent-runtime` if you want both.
94
96
  - **OpenAI Agents SDK** — first-party OpenAI SDK. Same trade-off as the Claude Agent SDK: tight integration with OpenAI, no other providers. Pi providers in our runtime cover OpenAI plus a dozen others through a single API.
95
97
  - **LangChain.js** — kitchen sink with deep abstraction stacks. We're deliberately lean; if you want chains, agents, vector stores, and parsers under one umbrella, LangChain is built for that. If you want a focused runtime kernel, use us.
@@ -109,7 +111,7 @@ console.log(result.text);
109
111
  | Multi-provider portability | ✓ (4 backends, 15+ providers) | partial | ✗ |
110
112
  | CLI providers (claude/codex binaries) | ✓ | ✗ | ✗ |
111
113
  | Provider fallback on rate limit / overload | ✓ (`createRouterRuntime`) | ✗ | ✗ |
112
- | Aggressive context compaction with summarization | ✓ | | partial |
114
+ | Context handling delegated to the provider (no host auto-summarization) | ✓ | | |
113
115
  | Transcript-tail resume after provider drops | ✓ | ✗ | ✗ |
114
116
  | Tool-output bloat guard + artifact persistence | ✓ | ✗ | ✗ |
115
117
  | MCP transports out of the box (stdio/SSE/HTTP) | ✓ | partial | ✓ |
@@ -142,14 +144,20 @@ createRuntime({
142
144
  resolveCustomPricing, // (parsed) => NormalizedPricing | null
143
145
  resolvePiApiKey, // async (provider) => string | undefined
144
146
  persistArtifact, // ({ filename, buffer, toolName, toolUseId }) => path | null
145
- onCompactionRecorded, // (compactionRow) => void
147
+ onCompactionRecorded, // (compactionRow) => void — fired when the pi bridge
148
+ // runs an automatic compaction (proactive or reactive
149
+ // recovery) via AgentHarness.compact()
146
150
 
147
151
  // -- tool runtime context (process-level config for the tool kernel) --
148
152
  workspace, // primary allowed root for path-based tools
149
153
  repoRoot, // secondary allowed root
150
154
  ripgrepPath, // explicit path to `rg`; falls back to vendored binary, then PATH
151
155
  qaOutputDir, // fallback dir for Playwright MCP filename routing
152
- sandboxPolicy, // optional @mono-agent/sandbox policy for tools and stdio MCP
156
+ sandboxPolicy, // optional SandboxPolicy for tools and stdio MCP (enforced
157
+ // through the injectable RuntimeSandbox seam, not a bundled dep)
158
+ sandbox, // optional RuntimeSandbox implementation override (defaults to
159
+ // the zero-dependency passthroughSandbox; runtime-adapter injects
160
+ // the real runtime-adapter sandbox implementation for mono-agent hosts)
153
161
 
154
162
  // -- observers (multi-subscriber telemetry) --
155
163
  // Optional. Each observer receives every event the runtime emits.
@@ -228,7 +236,6 @@ Per-call options (a non-exhaustive selection):
228
236
  | `runId` | `string` | Tag this run for downstream callbacks (e.g. `onCompactionRecorded`). |
229
237
  | `providerSessionId` | `string` | Resume a prior provider session. |
230
238
  | `runArtifactDir` | `string` | Used by some providers as the Playwright MCP filename target. |
231
- | `piCodexTransport` | `string` | Forwarded to Pi when running OpenAI Codex models. |
232
239
  | `codexAppServerCommand` | `string` | Override the Codex CLI binary. |
233
240
  | `codexAppServerArgs` | `string[]` | Override the Codex CLI arguments. |
234
241
 
@@ -312,8 +319,9 @@ console.log(result.failoverHistory);
312
319
  Behaviour:
313
320
 
314
321
  - Successful run on entry N → returns the result with `failoverHistory` set to attempts 0..N-1.
315
- - Retryable failure → emits `provider_failover_started`, builds a transcript snapshot, and retries on the next entry.
316
- - Non-retryable failure (auth, billing, invalid request) returns immediately with `failoverHistory` containing the one attempt.
322
+ - Retryable provider failure → emits `provider_failover_started`, builds a transcript snapshot, and retries on the next entry.
323
+ - Provider auth failure retries the next chain entry and preserves `failureKind: "provider_auth"` in `failoverHistory` for the failed attempt.
324
+ - Malformed request/config/billing-type non-retryable failure → returns immediately with `failoverHistory` containing the one attempt.
317
325
  - Cancellation → returns immediately.
318
326
  - Chain exhausted → `failureKind: "provider_unavailable_exhausted"`, `failoverHistory` lists every attempt.
319
327
 
@@ -395,7 +403,7 @@ Approval lifecycle is observable via `onEvent`:
395
403
 
396
404
  ## Tool-result bloat handling
397
405
 
398
- `@mono-agent/agent-runtime/agent/tool-bloat.js` enforces a 256 KB default cap per `tool_result`. When a payload exceeds the cap, the kernel:
406
+ The kernel's tool-bloat guard (`agent/tool-bloat.js`, internal) enforces a 256 KB default cap per `tool_result`. When a payload exceeds the cap, the kernel:
399
407
 
400
408
  1. Calls your `persistArtifact({ filename, buffer, toolName, toolUseId })` callback (if you supplied one).
401
409
  2. Substitutes a compact text reference in the agent's transcript.
@@ -405,18 +413,36 @@ Hosts that don't supply `persistArtifact` get the truncation summary but no on-d
405
413
 
406
414
  ## Context compaction
407
415
 
408
- `@mono-agent/agent-runtime/agent/compaction.js` provides `createAgentCompactionManager(...)` which the Pi SDK provider invokes automatically. Configure via the agent's settings (`agent_compaction_*` keys). When a compaction completes, the kernel hands a structured row to your `onCompactionRecorded(record)` callback so the host can persist it however it likes.
416
+ The sole pi bridge runs on pi-agent-core's native `AgentHarness`. pi performs **no**
417
+ automatic in-loop compaction, so the bridge drives it: before each turn it estimates the
418
+ running model's context usage and calls `AgentHarness.compact()` when near the window
419
+ (proactive), and if a turn still overflows it compacts once and re-prompts (reactive
420
+ recovery). The context window auto-tracks the model actually serving the request
421
+ (`harness.getModel()`), self-correcting from any real ceiling stated in an overflow error.
422
+ Runs report `context_compaction_applied: true` (fired), `false` (enabled but not needed),
423
+ or `null` (disabled). The other backends manage their windows per their own behavior.
424
+ (`docs/reference/feature-registry.md` is the source of truth for this row.)
425
+
426
+ `resolveAgentCompactionPolicy(...)` (the `agent_compaction_*` settings: trigger ratio,
427
+ keep-recent, enable/disable) and the `onCompactionRecorded(record)` host callback (fired
428
+ on each automatic compaction) are exported from
429
+ `@mono-agent/agent-runtime/agent/compaction.js` and consumed by the pi bridge.
409
430
 
410
431
  ## Advanced exports
411
432
 
412
- The package exposes its inner pieces via subpath imports:
433
+ The package exposes a fixed set of inner pieces via subpath imports. The
434
+ `exports` map is explicit (no `./ai/*` / `./agent/*` wildcards): only the mapped
435
+ subpaths resolve, each carrying generated `.d.ts` types. `node
436
+ scripts/verify-deep-imports.mjs` asserts every mapped subpath still loads.
413
437
 
414
438
  ```js
415
- import { resolveRuntimeBridge, listRuntimeBridges, runtimeCapabilities } from "@mono-agent/agent-runtime/ai/runtime/registry.js";
416
- import { generateClaudeResponse } from "@mono-agent/agent-runtime/ai/providers/claude-sdk.js";
417
- import { createAgentCompactionManager, estimateFirstTurnInput } from "@mono-agent/agent-runtime/agent/compaction.js";
439
+ import { resolveRuntimeBridge, listRuntimeBridges } from "@mono-agent/agent-runtime/ai/runtime/registry.js";
440
+ import { parseRuntimeModelReference } from "@mono-agent/agent-runtime/ai/runtime/model-refs.js";
441
+ import { classifyFailure, FAILURE_KINDS } from "@mono-agent/agent-runtime/ai/failure.js";
442
+ import { resolvePricing, estimateCost } from "@mono-agent/agent-runtime/ai/cost.js";
443
+ import { resolveAgentCompactionPolicy, isLikelyContextTermination } from "@mono-agent/agent-runtime/agent/compaction.js";
418
444
  import { configureToolRuntime, readToolRuntime } from "@mono-agent/agent-runtime/agent/tools/shared/runtime-context.js";
419
- // ...
445
+ // see package.json "exports" for the full mapped set
420
446
  ```
421
447
 
422
448
  These are stable but treated as advanced API. Most consumers should reach for `createRuntime` first.