operon-agents-core 0.1.0-alpha.3 → 0.1.0-alpha.31

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 (344) hide show
  1. package/README.md +13 -0
  2. package/dist/agent/agent.d.ts +27 -12
  3. package/dist/agent/compose-hooks.d.ts +10 -1
  4. package/dist/agent/compose-hooks.js +61 -6
  5. package/dist/agent/concurrency.js +1 -1
  6. package/dist/agent/context-report.d.ts +10 -7
  7. package/dist/agent/context-report.js +39 -7
  8. package/dist/agent/durable-state.d.ts +22 -0
  9. package/dist/agent/durable-state.js +54 -0
  10. package/dist/agent/errors.d.ts +22 -0
  11. package/dist/agent/errors.js +39 -0
  12. package/dist/agent/handoff.js +1 -1
  13. package/dist/agent/index.d.ts +5 -3
  14. package/dist/agent/index.js +2 -1
  15. package/dist/agent/instruction-context.d.ts +6 -6
  16. package/dist/agent/instruction-context.js +23 -23
  17. package/dist/agent/lifecycle-recovery.d.ts +15 -0
  18. package/dist/agent/lifecycle-recovery.js +44 -0
  19. package/dist/agent/pause.js +0 -5
  20. package/dist/agent/profile-builtins.js +1 -1
  21. package/dist/agent/profiles.d.ts +3 -0
  22. package/dist/agent/profiles.js +1 -0
  23. package/dist/agent/recovery.js +2 -2
  24. package/dist/agent/run-support.d.ts +5 -5
  25. package/dist/agent/run-support.js +11 -13
  26. package/dist/agent/runner.d.ts +70 -42
  27. package/dist/agent/runner.js +324 -156
  28. package/dist/agent/session.d.ts +285 -169
  29. package/dist/agent/session.js +639 -440
  30. package/dist/agent/subagent-tools.js +5 -5
  31. package/dist/agent/subagent.js +28 -13
  32. package/dist/agent/toolset.d.ts +1 -0
  33. package/dist/agent/toolset.js +14 -8
  34. package/dist/agent/workflow/index.d.ts +1 -1
  35. package/dist/agent/workflow/index.js +1 -1
  36. package/dist/agent/workflow/journal.d.ts +2 -2
  37. package/dist/agent/workflow/journal.js +2 -2
  38. package/dist/agent/workflow/manager.d.ts +1 -1
  39. package/dist/agent/workflow/manager.js +1 -1
  40. package/dist/agent/workflow/prompt.js +2 -2
  41. package/dist/agent/workflow/sandbox.d.ts +1 -1
  42. package/dist/agent/workflow/sandbox.js +1 -1
  43. package/dist/agent/workflow/structured.d.ts +2 -0
  44. package/dist/agent/workflow/structured.js +4 -0
  45. package/dist/agent/workflow/tool.js +35 -47
  46. package/dist/agent/worktree.d.ts +8 -8
  47. package/dist/agent/worktree.js +15 -15
  48. package/dist/capabilities/assembler.d.ts +29 -5
  49. package/dist/capabilities/assembler.js +85 -9
  50. package/dist/capabilities/background/code-task.d.ts +43 -0
  51. package/dist/capabilities/background/code-task.js +75 -0
  52. package/dist/capabilities/background/command-task.d.ts +9 -2
  53. package/dist/capabilities/background/command-task.js +22 -6
  54. package/dist/capabilities/background/index.d.ts +6 -1
  55. package/dist/capabilities/background/index.js +26 -20
  56. package/dist/capabilities/background/manager.d.ts +57 -1
  57. package/dist/capabilities/background/manager.js +210 -45
  58. package/dist/capabilities/background/persist-disk.d.ts +1 -1
  59. package/dist/capabilities/background/persist-disk.js +1 -1
  60. package/dist/capabilities/background/persist.js +4 -2
  61. package/dist/capabilities/background/projections.d.ts +16 -0
  62. package/dist/capabilities/background/projections.js +86 -0
  63. package/dist/capabilities/background/stall-watchdog.d.ts +41 -0
  64. package/dist/capabilities/background/stall-watchdog.js +85 -0
  65. package/dist/capabilities/background/task.d.ts +8 -7
  66. package/dist/capabilities/background/tools.js +36 -10
  67. package/dist/capabilities/capability-data.d.ts +52 -0
  68. package/dist/capabilities/capability-data.js +88 -0
  69. package/dist/capabilities/capability-state.d.ts +2 -4
  70. package/dist/capabilities/capability-state.js +5 -23
  71. package/dist/capabilities/capability.d.ts +203 -38
  72. package/dist/capabilities/compaction/full.js +4 -3
  73. package/dist/capabilities/compaction/index.js +12 -6
  74. package/dist/capabilities/compaction/service.d.ts +20 -5
  75. package/dist/capabilities/compaction/service.js +27 -11
  76. package/dist/capabilities/compaction/tokens.js +2 -0
  77. package/dist/capabilities/goal/goal-store.d.ts +76 -12
  78. package/dist/capabilities/goal/goal-store.js +137 -53
  79. package/dist/capabilities/goal/index.d.ts +1 -1
  80. package/dist/capabilities/goal/index.js +30 -7
  81. package/dist/capabilities/goal/tools.js +3 -3
  82. package/dist/capabilities/index.d.ts +9 -6
  83. package/dist/capabilities/index.js +4 -3
  84. package/dist/capabilities/plan/index.js +22 -5
  85. package/dist/capabilities/plan/plan-mode.d.ts +30 -9
  86. package/dist/capabilities/plan/plan-mode.js +57 -32
  87. package/dist/capabilities/plan/tools.js +3 -3
  88. package/dist/capabilities/skills/flow-provider.js +4 -4
  89. package/dist/capabilities/skills/index.d.ts +13 -1
  90. package/dist/capabilities/skills/index.js +30 -21
  91. package/dist/capabilities/skills/parser.d.ts +2 -2
  92. package/dist/capabilities/skills/parser.js +3 -3
  93. package/dist/capabilities/skills/registry.d.ts +5 -6
  94. package/dist/capabilities/skills/registry.js +6 -9
  95. package/dist/capabilities/skills/scanner.d.ts +3 -3
  96. package/dist/capabilities/skills/scanner.js +14 -14
  97. package/dist/capabilities/skills/service.d.ts +2 -1
  98. package/dist/capabilities/skills/service.js +3 -3
  99. package/dist/capabilities/skills/skill-tool.d.ts +2 -0
  100. package/dist/capabilities/skills/skill-tool.js +2 -2
  101. package/dist/capabilities/task/index.js +2 -1
  102. package/dist/capabilities/task/persist-disk.d.ts +1 -1
  103. package/dist/capabilities/task/persist-disk.js +1 -1
  104. package/dist/capabilities/task/persist.js +1 -1
  105. package/dist/capabilities/task/tools.js +4 -4
  106. package/dist/capabilities/todo/index.js +11 -6
  107. package/dist/capabilities/todo/injector.js +2 -1
  108. package/dist/capabilities/todo/todo-store.d.ts +28 -7
  109. package/dist/capabilities/todo/todo-store.js +44 -11
  110. package/dist/capabilities/todo/tools.js +9 -4
  111. package/dist/capabilities/tool-provider.d.ts +3 -3
  112. package/dist/capabilities/user-hooks/engine.d.ts +3 -3
  113. package/dist/capabilities/user-hooks/engine.js +7 -7
  114. package/dist/capabilities/user-hooks/index.js +2 -1
  115. package/dist/capabilities/workflow/index.d.ts +5 -3
  116. package/dist/capabilities/workflow/index.js +3 -2
  117. package/dist/commands/index.js +34 -32
  118. package/dist/config/index.d.ts +6 -6
  119. package/dist/config/index.js +3 -3
  120. package/dist/config/merge.js +17 -6
  121. package/dist/config/resolver.d.ts +0 -3
  122. package/dist/config/resolver.js +0 -3
  123. package/dist/config/schema.d.ts +152 -104
  124. package/dist/config/schema.js +108 -46
  125. package/dist/config/session-config.d.ts +338 -0
  126. package/dist/config/session-config.js +208 -0
  127. package/dist/events/events.d.ts +49 -13
  128. package/dist/events/events.js +1 -0
  129. package/dist/events/index.d.ts +2 -2
  130. package/dist/events/index.js +1 -1
  131. package/dist/events/projection.d.ts +57 -1
  132. package/dist/events/projection.js +154 -19
  133. package/dist/events/publisher.js +5 -21
  134. package/dist/home.d.ts +1 -1
  135. package/dist/home.js +1 -1
  136. package/dist/index.d.ts +3 -2
  137. package/dist/index.js +2 -1
  138. package/dist/internal.d.ts +7 -2
  139. package/dist/internal.js +8 -2
  140. package/dist/llm/decision-model.d.ts +23 -0
  141. package/dist/llm/decision-model.js +26 -0
  142. package/dist/llm/define-model.d.ts +28 -26
  143. package/dist/llm/define-model.js +106 -63
  144. package/dist/llm/errors.d.ts +0 -3
  145. package/dist/llm/errors.js +0 -80
  146. package/dist/llm/index.d.ts +10 -6
  147. package/dist/llm/index.js +7 -4
  148. package/dist/llm/model-manager.d.ts +95 -0
  149. package/dist/llm/model-manager.js +233 -0
  150. package/dist/llm/model.d.ts +20 -19
  151. package/dist/llm/provider.d.ts +20 -0
  152. package/dist/llm/provider.js +17 -0
  153. package/dist/llm/request-retry.d.ts +18 -0
  154. package/dist/llm/request-retry.js +93 -0
  155. package/dist/llm/retry.d.ts +14 -0
  156. package/dist/llm/retry.js +85 -21
  157. package/dist/loop/context.d.ts +33 -1
  158. package/dist/loop/context.js +85 -9
  159. package/dist/loop/events.d.ts +5 -1
  160. package/dist/loop/index.d.ts +2 -2
  161. package/dist/loop/index.js +1 -1
  162. package/dist/loop/interruption.d.ts +9 -4
  163. package/dist/loop/interruption.js +11 -25
  164. package/dist/loop/run-turn.d.ts +18 -7
  165. package/dist/loop/run-turn.js +19 -10
  166. package/dist/loop/steer.d.ts +105 -18
  167. package/dist/loop/steer.js +172 -46
  168. package/dist/loop/tool-call.d.ts +13 -5
  169. package/dist/loop/tool-call.js +150 -7
  170. package/dist/loop/turn-step.d.ts +14 -5
  171. package/dist/loop/turn-step.js +36 -8
  172. package/dist/loop/types.d.ts +8 -0
  173. package/dist/mcp/auth-tool.d.ts +3 -1
  174. package/dist/mcp/auth-tool.js +2 -2
  175. package/dist/mcp/capability.d.ts +13 -0
  176. package/dist/mcp/capability.js +36 -17
  177. package/dist/mcp/config-loader.d.ts +5 -5
  178. package/dist/mcp/config-loader.js +17 -17
  179. package/dist/mcp/credentials.d.ts +35 -0
  180. package/dist/mcp/credentials.js +2 -0
  181. package/dist/mcp/filter.d.ts +2 -2
  182. package/dist/mcp/index.d.ts +4 -3
  183. package/dist/mcp/index.js +1 -1
  184. package/dist/mcp/manager.d.ts +115 -7
  185. package/dist/mcp/manager.js +298 -30
  186. package/dist/mcp/oauth/callback-server.d.ts +10 -1
  187. package/dist/mcp/oauth/callback-server.js +82 -16
  188. package/dist/mcp/oauth/index.d.ts +2 -2
  189. package/dist/mcp/oauth/provider.d.ts +18 -0
  190. package/dist/mcp/oauth/provider.js +31 -1
  191. package/dist/mcp/oauth/service.d.ts +9 -3
  192. package/dist/mcp/oauth/service.js +29 -4
  193. package/dist/mcp/provider.js +5 -1
  194. package/dist/mcp/sdk-transport.js +1 -1
  195. package/dist/mcp/server.js +1 -1
  196. package/dist/mcp/types.d.ts +4 -0
  197. package/dist/permission/auto-approver/decision-auto-approver.d.ts +45 -0
  198. package/dist/permission/auto-approver/decision-auto-approver.js +112 -0
  199. package/dist/permission/auto-approver/index.d.ts +1 -0
  200. package/dist/permission/auto-approver/index.js +1 -0
  201. package/dist/permission/auto-approver/llm-auto-approver.d.ts +1 -1
  202. package/dist/permission/auto-approver/llm-auto-approver.js +15 -10
  203. package/dist/permission/auto-approver/prompts-data.d.ts +1 -1
  204. package/dist/permission/auto-approver/prompts-data.js +1 -1
  205. package/dist/permission/index.d.ts +1 -1
  206. package/dist/permission/index.js +1 -1
  207. package/dist/permission/manager.d.ts +5 -3
  208. package/dist/permission/manager.js +7 -3
  209. package/dist/permission/policies.d.ts +2 -2
  210. package/dist/permission/policies.js +4 -4
  211. package/dist/permission/types.d.ts +6 -0
  212. package/dist/plugins/fields.d.ts +14 -0
  213. package/dist/plugins/fields.js +30 -0
  214. package/dist/plugins/hooks.d.ts +2 -2
  215. package/dist/plugins/hooks.js +12 -12
  216. package/dist/plugins/index.js +1 -0
  217. package/dist/plugins/manager.d.ts +8 -3
  218. package/dist/plugins/manager.js +18 -7
  219. package/dist/plugins/manifest.d.ts +2 -2
  220. package/dist/plugins/manifest.js +101 -91
  221. package/dist/plugins/marketplace.js +76 -57
  222. package/dist/plugins/store.d.ts +3 -3
  223. package/dist/plugins/store.js +6 -6
  224. package/dist/protocol/index.d.ts +1 -1
  225. package/dist/protocol/tool-schema.d.ts +6 -0
  226. package/dist/store/catalog-store.d.ts +4 -1
  227. package/dist/store/catalog-store.js +5 -1
  228. package/dist/store/checkpointing-store.d.ts +43 -0
  229. package/dist/store/checkpointing-store.js +90 -0
  230. package/dist/store/disk-store.d.ts +8 -0
  231. package/dist/store/disk-store.js +127 -5
  232. package/dist/store/index.d.ts +3 -2
  233. package/dist/store/index.js +2 -1
  234. package/dist/store/lock.d.ts +1 -1
  235. package/dist/store/lock.js +2 -2
  236. package/dist/store/log-store.d.ts +9 -1
  237. package/dist/store/log-store.js +68 -4
  238. package/dist/store/migrate.d.ts +8 -2
  239. package/dist/store/migrate.js +9 -2
  240. package/dist/store/origin.d.ts +30 -14
  241. package/dist/store/origin.js +0 -14
  242. package/dist/store/pg.d.ts +1 -0
  243. package/dist/store/pg.js +37 -2
  244. package/dist/store/redis.d.ts +1 -0
  245. package/dist/store/redis.js +30 -0
  246. package/dist/store/repository.d.ts +13 -1
  247. package/dist/store/repository.js +45 -2
  248. package/dist/store/session-catalog.d.ts +4 -0
  249. package/dist/store/session-catalog.js +6 -0
  250. package/dist/store/storage.js +3 -0
  251. package/dist/store/store.d.ts +100 -38
  252. package/dist/store/store.js +67 -10
  253. package/dist/telemetry/appender.d.ts +43 -0
  254. package/dist/telemetry/appender.js +46 -0
  255. package/dist/telemetry/events.d.ts +142 -0
  256. package/dist/telemetry/events.js +141 -0
  257. package/dist/telemetry/index.d.ts +10 -0
  258. package/dist/telemetry/index.js +6 -0
  259. package/dist/telemetry/projection.d.ts +23 -0
  260. package/dist/telemetry/projection.js +185 -0
  261. package/dist/telemetry/redact.d.ts +20 -0
  262. package/dist/telemetry/redact.js +40 -0
  263. package/dist/telemetry/service.d.ts +49 -0
  264. package/dist/telemetry/service.js +137 -0
  265. package/dist/testing.d.ts +58 -0
  266. package/dist/testing.js +123 -0
  267. package/dist/tool/background.d.ts +9 -6
  268. package/dist/tool/background.js +7 -1
  269. package/dist/tool/builtin/ask-user-question.js +7 -6
  270. package/dist/tool/builtin/bash.d.ts +6 -0
  271. package/dist/tool/builtin/bash.js +81 -43
  272. package/dist/tool/builtin/edit.js +38 -123
  273. package/dist/tool/builtin/glob.js +14 -14
  274. package/dist/tool/builtin/grep.js +14 -14
  275. package/dist/tool/builtin/read.js +54 -93
  276. package/dist/tool/builtin/write.js +20 -90
  277. package/dist/tool/define.d.ts +29 -32
  278. package/dist/tool/define.js +8 -20
  279. package/dist/tool/{machine-base.d.ts → environment-base.d.ts} +33 -49
  280. package/dist/tool/{machine-base.js → environment-base.js} +28 -136
  281. package/dist/tool/{machine-local.d.ts → environment-local.d.ts} +8 -9
  282. package/dist/tool/{machine-local.js → environment-local.js} +50 -82
  283. package/dist/tool/{machine-null.d.ts → environment-null.d.ts} +10 -10
  284. package/dist/tool/{machine-null.js → environment-null.js} +10 -10
  285. package/dist/tool/{machine-ssh.d.ts → environment-ssh.d.ts} +34 -19
  286. package/dist/tool/{machine-ssh.js → environment-ssh.js} +119 -150
  287. package/dist/tool/{machine.d.ts → environment.d.ts} +40 -113
  288. package/dist/tool/environment.js +2 -0
  289. package/dist/tool/filesystem-tools.d.ts +1 -1
  290. package/dist/tool/filesystem-tools.js +1 -1
  291. package/dist/tool/git-context.d.ts +2 -2
  292. package/dist/tool/git-context.js +8 -8
  293. package/dist/tool/index.d.ts +14 -14
  294. package/dist/tool/index.js +15 -13
  295. package/dist/tool/policies/path-access.d.ts +4 -4
  296. package/dist/tool/policies/path-access.js +12 -12
  297. package/dist/tool/questions.d.ts +8 -0
  298. package/dist/tool/search/catalog.d.ts +37 -0
  299. package/dist/tool/search/catalog.js +182 -0
  300. package/dist/tool/search/deferral.d.ts +3 -2
  301. package/dist/tool/search/loaded.d.ts +32 -0
  302. package/dist/tool/search/loaded.js +96 -0
  303. package/dist/tool/search/search-tool.d.ts +2 -6
  304. package/dist/tool/search/search-tool.js +18 -17
  305. package/dist/tool/shell-env.js +4 -0
  306. package/dist/tool/support/bash-paths.js +38 -7
  307. package/dist/tool/support/environment-ops.d.ts +32 -0
  308. package/dist/tool/support/environment-ops.js +20 -0
  309. package/dist/tool/support/git-worktree.d.ts +3 -3
  310. package/dist/tool/support/git-worktree.js +6 -6
  311. package/dist/tool/support/rg-locator.d.ts +6 -6
  312. package/dist/tool/support/rg-locator.js +6 -6
  313. package/dist/tool/support/ripgrep-run.d.ts +5 -5
  314. package/dist/tool/support/ripgrep-run.js +3 -3
  315. package/dist/tool/support/tool-path.d.ts +3 -3
  316. package/dist/tool/support/tool-path.js +7 -7
  317. package/dist/tool/types.d.ts +57 -15
  318. package/dist/tool/web/fetch-url.js +2 -2
  319. package/dist/tool/web/web-search.js +2 -2
  320. package/dist/tool/workspace-spec.d.ts +3 -3
  321. package/dist/tool/workspace-spec.js +29 -28
  322. package/dist/tracing/bridge.d.ts +9 -1
  323. package/dist/tracing/bridge.js +307 -77
  324. package/dist/tracing/index.d.ts +2 -2
  325. package/dist/tracing/otel.d.ts +28 -1
  326. package/dist/tracing/otel.js +150 -38
  327. package/dist/tracing/processor.d.ts +22 -0
  328. package/dist/tracing/processor.js +2 -0
  329. package/dist/tracing/spans.d.ts +54 -0
  330. package/dist/tracing/spans.js +5 -0
  331. package/package.json +6 -2
  332. package/dist/config/model-catalog.d.ts +0 -17
  333. package/dist/config/model-catalog.js +0 -37
  334. package/dist/config/provider-manager.d.ts +0 -57
  335. package/dist/config/provider-manager.js +0 -344
  336. package/dist/llm/runtime.d.ts +0 -25
  337. package/dist/llm/runtime.js +0 -38
  338. package/dist/tool/file-freshness.d.ts +0 -81
  339. package/dist/tool/file-freshness.js +0 -67
  340. package/dist/tool/machine.js +0 -15
  341. package/dist/tool/search/activation.d.ts +0 -13
  342. package/dist/tool/search/activation.js +0 -31
  343. package/dist/tool/support/machine-ops.d.ts +0 -34
  344. package/dist/tool/support/machine-ops.js +0 -34
package/README.md CHANGED
@@ -5,3 +5,16 @@ Internal engine for `operon-agents`.
5
5
  Application code should import from `operon-agents`. This package intentionally
6
6
  contains lower-level runtime, loop, permission, storage, and capability modules
7
7
  that may change as the engine evolves.
8
+
9
+ ## Execution recovery
10
+
11
+ `Runner.run` and `runStream` reconcile abandoned lifecycle frames before a Session's
12
+ first fresh run, under its run lock and any configured `SessionLock`. Durable
13
+ approval/input pauses remain resumable through `Runner.resume`. `Session.open`
14
+ alone never closes unfinished turns: opening is not proof that another executor died.
15
+
16
+ Hosts can call `recoverOrphanedTurns` without opening a Session, or
17
+ `closeOrphanedTurns` to receive the committed repair events for broadcasting.
18
+ Both require exclusive execution ownership. For stores shared across processes,
19
+ provide a distributed lock to Runner or acquire a host-managed lease before takeover.
20
+ Recovery closes orphan frames; it does not retry tools with unknown side effects.
@@ -1,7 +1,7 @@
1
1
  import type { ChatModel } from "../llm/define-model.ts";
2
2
  import type { ModelSettings } from "../llm/model.ts";
3
3
  import type { Tool } from "../tool/types.ts";
4
- import type { Machine } from "../tool/machine.ts";
4
+ import type { Environment } from "../tool/environment.ts";
5
5
  import type { Handoff } from "./handoff.ts";
6
6
  import type { InputGuardrail, OutputGuardrail, ToolInputGuardrail, ToolOutputGuardrail } from "./guardrail.ts";
7
7
  import type { SystemPromptContext } from "./instruction-context.ts";
@@ -10,8 +10,8 @@ export interface AgentRunContext<TContext = unknown> {
10
10
  readonly address: string;
11
11
  readonly signal: AbortSignal;
12
12
  readonly context?: TContext;
13
- /** Machine of the current runtime frame (root/subagent/worktree), never captured by Agent. */
14
- readonly machine?: Machine;
13
+ /** Environment of the current runtime frame (root/subagent/worktree), never captured by Agent. */
14
+ readonly environment?: Environment;
15
15
  /** Lazily resolves Session-cached environment + AGENTS.md data for this runtime frame. */
16
16
  readonly resolveSystemPromptContext?: () => Promise<SystemPromptContext>;
17
17
  }
@@ -21,7 +21,14 @@ export interface AgentGuardrails<TContext = unknown> {
21
21
  readonly toolInput?: readonly ToolInputGuardrail<TContext>[];
22
22
  readonly toolOutput?: readonly ToolOutputGuardrail<TContext>[];
23
23
  }
24
- export interface AgentConfig<TContext = unknown> {
24
+ /**
25
+ * What `outputType` needs from a schema: a `parse` that returns the value or throws. A zod schema
26
+ * satisfies it, and is how `RunResult.outputParsed` gets its type.
27
+ */
28
+ export interface OutputSchema<TOutput = unknown> {
29
+ parse(value: unknown): TOutput;
30
+ }
31
+ export interface AgentConfig<TContext = unknown, TOutput = unknown> {
25
32
  readonly name: string;
26
33
  readonly instructions?: string | ((ctx: AgentRunContext<TContext>) => string | Promise<string>);
27
34
  readonly handoffDescription?: string;
@@ -35,17 +42,18 @@ export interface AgentConfig<TContext = unknown> {
35
42
  readonly handoffs?: readonly Handoff<TContext>[];
36
43
  readonly subagents?: readonly Agent<TContext>[];
37
44
  readonly guardrails?: AgentGuardrails<TContext>;
38
- readonly outputType?: unknown;
45
+ readonly outputType?: OutputSchema<TOutput>;
39
46
  readonly maxStepsPerTurn?: number;
40
47
  /**
41
- * Opt into deferred tool loading: capability/MCP tools are discovered on
42
- * demand through SearchTool, then pi materializes their definitions from
43
- * `ToolResultMessage.addedToolNames`. A no-op for models whose compat data
44
- * does not advertise native deferred-tool support. Off by default.
48
+ * Capability/MCP tools are discovered on demand through SearchTool; only loaded ones are
49
+ * sent to the model, so the catalog can change mid-conversation without touching the
50
+ * request prefix. On models with native deferred-tool support (Anthropic tool_reference,
51
+ * Kimi, OpenAI tool search) pi also keeps a loaded definition out of the prefix. Default:
52
+ * on for those models, off elsewhere. `false` loads capability tools up front.
45
53
  */
46
54
  readonly deferTools?: boolean;
47
55
  }
48
- export declare class Agent<TContext = unknown> {
56
+ export declare class Agent<TContext = unknown, TOutput = unknown> {
49
57
  readonly name: string;
50
58
  readonly instructions?: AgentConfig<TContext>["instructions"];
51
59
  readonly handoffDescription?: string;
@@ -55,11 +63,18 @@ export declare class Agent<TContext = unknown> {
55
63
  readonly handoffs: readonly Handoff<TContext>[];
56
64
  readonly subagents: readonly Agent<TContext>[];
57
65
  readonly guardrails: AgentGuardrails<TContext>;
58
- readonly outputType?: unknown;
66
+ readonly outputType?: OutputSchema<TOutput>;
59
67
  readonly maxStepsPerTurn?: number;
60
68
  readonly deferTools?: boolean;
61
- constructor(config: AgentConfig<TContext>);
69
+ constructor(config: AgentConfig<TContext, TOutput>);
62
70
  resolveInstructions(ctx: AgentRunContext<TContext>): Promise<string | undefined>;
63
71
  }
72
+ /**
73
+ * Build an agent. `outputType` types `RunResult.outputParsed` — unless the agent has handoffs:
74
+ * another agent may then give the final answer, under its own schema, so the output is `unknown`.
75
+ */
76
+ export declare function defineAgent<TContext = unknown, TOutput = unknown>(config: AgentConfig<TContext, TOutput> & {
77
+ readonly handoffs?: undefined | readonly [];
78
+ }): Agent<TContext, TOutput>;
64
79
  export declare function defineAgent<TContext = unknown>(config: AgentConfig<TContext>): Agent<TContext>;
65
80
  //# sourceMappingURL=agent.d.ts.map
@@ -1,5 +1,7 @@
1
1
  import type { LoopHooks } from "../loop/types.ts";
2
2
  import type { Tool } from "../tool/types.ts";
3
+ import type { LlmRequest } from "../llm/model.ts";
4
+ import type { CapabilityProviderHooks, ProviderHookContext } from "../capabilities/capability.ts";
3
5
  import type { ConversationContext } from "../loop/context.ts";
4
6
  import type { Agent } from "./agent.ts";
5
7
  import type { RunState } from "./runner.ts";
@@ -8,6 +10,13 @@ import type { RunState } from "./runner.ts";
8
10
  * (compaction beforeStep/afterStep …) → permission authorizer (single) → tool guardrails.
9
11
  * Extracted from the Engine; only TYPES are imported from `runner.ts`.
10
12
  */
11
- export declare function buildRunHooks<TContext>(active: Agent<TContext>, state: RunState<TContext>, context: ConversationContext, tools: readonly Tool[]): LoopHooks;
13
+ export declare function buildRunHooks<TContext>(active: Agent<TContext>, state: RunState<TContext>, context: ConversationContext, tools: readonly Tool[] | (() => readonly Tool[])): LoopHooks;
14
+ /**
15
+ * Fold every capability's provider hooks into the request's `providerOptions` callbacks — the
16
+ * only way to reach them, since the provider layer invokes them from inside its HTTP path. A
17
+ * callback already on the request (set by a `beforeModelRequest` hook) runs FIRST and is kept,
18
+ * so nothing that wrote `providerOptions` directly is silently replaced.
19
+ */
20
+ export declare function withProviderHooks(request: LlmRequest, hooks: readonly CapabilityProviderHooks[], ctx: ProviderHookContext): LlmRequest;
12
21
  export declare function composeLoopHooks(parts: ReadonlyArray<Partial<LoopHooks> | undefined>): LoopHooks;
13
22
  //# sourceMappingURL=compose-hooks.d.ts.map
@@ -9,6 +9,14 @@ import { withToolCallRecoveryContext } from "./recovery.js";
9
9
  export function buildRunHooks(active, state, context, tools) {
10
10
  const ctx = runCtxFor(state);
11
11
  const parts = [...state.capabilities.loopHookParts];
12
+ const providerHooks = state.capabilities.providerHooks;
13
+ if (providerHooks.length > 0) {
14
+ parts.push({
15
+ beforeModelRequest: async ({ request, turnId, stepNumber, address }) => ({
16
+ request: withProviderHooks(request, providerHooks, { turnId, stepNumber, ...(address !== undefined ? { address } : {}) }),
17
+ }),
18
+ });
19
+ }
12
20
  parts.push({ authorizeToolExecution: buildAuthorizer(state, context, tools) });
13
21
  if (active.guardrails.toolInput && active.guardrails.toolInput.length > 0) {
14
22
  parts.push({ prepareToolExecution: toolInputGuardrailHook(active, ctx, active.guardrails.toolInput) });
@@ -26,21 +34,68 @@ export function buildRunHooks(active, state, context, tools) {
26
34
  });
27
35
  return composeLoopHooks(parts);
28
36
  }
37
+ /**
38
+ * Fold every capability's provider hooks into the request's `providerOptions` callbacks — the
39
+ * only way to reach them, since the provider layer invokes them from inside its HTTP path. A
40
+ * callback already on the request (set by a `beforeModelRequest` hook) runs FIRST and is kept,
41
+ * so nothing that wrote `providerOptions` directly is silently replaced.
42
+ */
43
+ export function withProviderHooks(request, hooks, ctx) {
44
+ const options = { ...request.providerOptions };
45
+ const headerHooks = hooks.map((h) => h.headers).filter(isDefined);
46
+ const payloadHooks = hooks.map((h) => h.payload).filter(isDefined);
47
+ const responseHooks = hooks.map((h) => h.response).filter(isDefined);
48
+ if (headerHooks.length > 0) {
49
+ const prior = options.transformHeaders;
50
+ options.transformHeaders = async (headers) => {
51
+ let current = prior !== undefined ? await prior(headers) : headers;
52
+ for (const hook of headerHooks)
53
+ current = (await hook(current, ctx)) ?? current;
54
+ return current;
55
+ };
56
+ }
57
+ if (payloadHooks.length > 0) {
58
+ const prior = options.onPayload;
59
+ options.onPayload = async (payload) => {
60
+ let current = prior !== undefined ? await prior(payload) : payload;
61
+ for (const hook of payloadHooks) {
62
+ const result = await hook(current, ctx);
63
+ if (result !== undefined && result !== null)
64
+ current = result.payload;
65
+ }
66
+ return current;
67
+ };
68
+ }
69
+ if (responseHooks.length > 0) {
70
+ const prior = options.onResponse;
71
+ options.onResponse = async (response) => {
72
+ if (prior !== undefined)
73
+ await prior(response);
74
+ for (const hook of responseHooks)
75
+ await hook(response, ctx);
76
+ };
77
+ }
78
+ return { ...request, providerOptions: options };
79
+ }
29
80
  function buildAuthorizer(state, context, tools) {
30
81
  // The `auto`-mode judge needs THIS frame's live transcript + tool registry (the authorize
31
82
  // ctx carries neither). Bind them per turn as closure state — the manager is a session
32
83
  // singleton shared by concurrent frames, so they must never be stored on it.
33
- const base = state.permission.authorizerFor({ getTranscript: () => context.messages, getTools: () => tools });
34
- const answers = state.answers;
35
- if (!answers)
36
- return base;
84
+ const base = state.permission.authorizerFor({ getTranscript: () => context.messages, getTools: typeof tools === "function" ? tools : () => tools });
37
85
  return async (ctx) => {
38
- const answer = answers[ctx.toolCall.id];
86
+ // Read at call time, not captured: a nested call (`ToolRunContext.dispatch`) may add an
87
+ // answer while the batch runs.
88
+ const answer = state.answers?.[ctx.toolCall.id];
39
89
  if (answer) {
40
90
  // Audit record: this is the single chokepoint both live and durable approvals
41
91
  // flow through (the responder/resume answer is applied here).
42
- context.record({ type: "permission.record_approval", toolCallId: ctx.toolCall.id, toolName: ctx.toolCall.name, decision: answer.decision, feedback: answer.feedback, approvalRule: ctx.plan.approvalRule, scope: answer.scope });
92
+ context.audit({ type: "permission.record_approval", toolCallId: ctx.toolCall.id, toolName: ctx.toolCall.name, decision: answer.decision, feedback: answer.feedback, approvalRule: ctx.plan.approvalRule, scope: answer.scope });
93
+ // That record is this frame's audit trail. A session grant is the SESSION's state, so the
94
+ // session persists it — what a reopen restores from — whichever frame earned it.
95
+ const grants = answer.decision === "approved" && answer.scope === "session" && !state.permission.sessionGrants.includes(ctx.plan.approvalRule);
43
96
  const ok = state.permission.applyApproval(ctx.plan.approvalRule, answer);
97
+ if (grants)
98
+ state.session.persistPermissionState();
44
99
  if (ok)
45
100
  return undefined;
46
101
  return { block: true, reason: answer.feedback ?? `Tool ${ctx.toolCall.name} was ${answer.decision}.` };
@@ -40,7 +40,7 @@ export function defaultSpawnConcurrency() {
40
40
  }
41
41
  /**
42
42
  * One limiter per session. Keyed off the session port (not the frame) because a run's frames come
43
- * and go while the session is what actually owns the machine's capacity; a session holds its run
43
+ * and go while the session is what actually owns the environment's capacity; a session holds its run
44
44
  * lock, so this bounds the whole tree beneath one prompt.
45
45
  */
46
46
  const perSession = new WeakMap();
@@ -4,14 +4,14 @@
4
4
  * turn-boundary injections (skills catalog, todo/task mirrors, …), the compaction reserve,
5
5
  * and the free remainder.
6
6
  *
7
- * The numbers are ESTIMATES (same char/4 heuristic the compaction strategy uses), computed
8
- * from exactly the `{ system, tools, messages }` the Runner is about to send — so the buckets
9
- * sum to the real request, not a separate re-derivation.
7
+ * Total occupancy comes from the provider's last measured request when available. Category
8
+ * weights are estimates of `{ system, tools, messages }`, normalised to that measured total.
9
+ * Before any usage is available (or after history replacement), the total is estimated too.
10
10
  */
11
11
  import type { ChatModel } from "../llm/define-model.ts";
12
12
  import type { Message } from "../protocol/index.ts";
13
13
  import type { Tool } from "../tool/types.ts";
14
- /** One additive slice of the context window: its token estimate and share of the whole window. */
14
+ /** Estimated attribution of occupancy; normalised to the provider total when available. */
15
15
  export interface ContextSlice {
16
16
  readonly tokens: number;
17
17
  /** Percent of the full context window, 0..100. */
@@ -26,8 +26,9 @@ export interface ContextBreakdown {
26
26
  /** The active model's full context window (tokens). */
27
27
  readonly contextWindow: number;
28
28
  readonly model: string;
29
- /** systemPrompt + tools + messages + injections (everything actually sent this turn). */
29
+ /** Last measured input occupancy; falls back to an estimate until provider usage is available. */
30
30
  readonly used: number;
31
+ readonly usageSource: "provider" | "estimate";
31
32
  readonly usedPercent: number;
32
33
  readonly systemPrompt: ContextSlice;
33
34
  /** Built-in / handoff / spawn tool schemas. */
@@ -42,19 +43,21 @@ export interface ContextBreakdown {
42
43
  readonly compactBuffer: ContextSlice;
43
44
  /** contextWindow − used − compactBuffer, clamped at 0. */
44
45
  readonly free: ContextSlice;
45
- /** Epoch ms the snapshot was taken (turn boundary). */
46
+ /** Epoch ms the snapshot was taken (turn boundary, then each step's request). */
46
47
  readonly capturedAt: number;
47
48
  }
48
49
  export interface ComputeContextBreakdownInput {
49
50
  readonly model: ChatModel;
50
51
  readonly system: string | undefined;
51
- readonly tools: readonly Tool[];
52
+ readonly tools: readonly Pick<Tool, "schema">[];
52
53
  readonly messages: readonly Message[];
53
54
  /** Per-injector token estimates captured while injecting at the turn boundary. */
54
55
  readonly injectionTokens: ReadonlyMap<string, number>;
55
56
  /** Compaction reserve (`CompactionService.reservedContextTokens`), or 0 if absent. */
56
57
  readonly compactBufferTokens: number;
57
58
  readonly capturedAt: number;
59
+ /** Exact input tokens, including cached input, from the latest provider response. */
60
+ readonly observedInputTokens?: number;
58
61
  }
59
62
  export declare function computeContextBreakdown(input: ComputeContextBreakdownInput): ContextBreakdown;
60
63
  //# sourceMappingURL=context-report.d.ts.map
@@ -8,7 +8,9 @@ export function computeContextBreakdown(input) {
8
8
  let builtinTools = 0;
9
9
  let mcpTools = 0;
10
10
  for (const tool of input.tools) {
11
- const tokens = estimateTokens(JSON.stringify(tool.schema));
11
+ // What goes on the wire: `outputSchema` is for programs calling the tool, never sent to the model.
12
+ const { outputSchema: _programOnly, ...sent } = tool.schema;
13
+ const tokens = estimateTokens(JSON.stringify(sent));
12
14
  if (isMcpToolName(tool.schema.name))
13
15
  mcpTools += tokens;
14
16
  else
@@ -25,18 +27,48 @@ export function computeContextBreakdown(input) {
25
27
  }
26
28
  injections.sort((a, b) => b.tokens - a.tokens);
27
29
  const conversationTokens = Math.max(0, messagesTotal - injectionsTotal);
28
- const used = systemTokens + builtinTools + mcpTools + messagesTotal;
30
+ const estimatedUsed = systemTokens + builtinTools + mcpTools + messagesTotal;
31
+ const observed = input.observedInputTokens;
32
+ const measured = observed !== undefined && Number.isFinite(observed) && observed > 0;
33
+ const used = measured ? observed : estimatedUsed;
34
+ // Allocate rounded estimates cumulatively so every category adds up to the measured total.
35
+ // These remain attribution estimates, not provider-supplied per-category token counts.
36
+ let estimatedSoFar = 0;
37
+ let allocated = 0;
38
+ const attributed = (tokens) => {
39
+ if (!measured || estimatedUsed === 0)
40
+ return slice(tokens);
41
+ estimatedSoFar += tokens;
42
+ const next = Math.round(estimatedSoFar / estimatedUsed * used);
43
+ const result = slice(Math.max(0, next - allocated));
44
+ allocated = next;
45
+ return result;
46
+ };
47
+ const systemSlice = attributed(systemTokens);
48
+ const builtinSlice = attributed(builtinTools);
49
+ const mcpSlice = attributed(mcpTools);
50
+ // Stale injection estimates must not create extra occupancy.
51
+ let injectionRemaining = messagesTotal;
52
+ const attributedInjections = injections.map((item) => {
53
+ const tokens = Math.min(item.tokens, injectionRemaining);
54
+ injectionRemaining -= tokens;
55
+ return { id: item.id, ...attributed(tokens) };
56
+ });
57
+ const messagesSlice = measured && estimatedUsed === 0
58
+ ? slice(used)
59
+ : attributed(measured ? injectionRemaining : conversationTokens);
29
60
  const free = Math.max(0, window - used - input.compactBufferTokens);
30
61
  return {
31
62
  contextWindow: window,
32
63
  model: input.model.id,
33
64
  used,
65
+ usageSource: measured ? "provider" : "estimate",
34
66
  usedPercent: pct(used),
35
- systemPrompt: slice(systemTokens),
36
- toolsBuiltin: slice(builtinTools),
37
- toolsMcp: slice(mcpTools),
38
- messages: slice(conversationTokens),
39
- injections,
67
+ systemPrompt: systemSlice,
68
+ toolsBuiltin: builtinSlice,
69
+ toolsMcp: mcpSlice,
70
+ messages: messagesSlice,
71
+ injections: measured ? attributedInjections : injections,
40
72
  compactBuffer: slice(input.compactBufferTokens),
41
73
  free: slice(free),
42
74
  capturedAt: input.capturedAt,
@@ -0,0 +1,22 @@
1
+ import type { Logger } from "../logging/index.ts";
2
+ import type { SessionStore, StateKey } from "../store/index.ts";
3
+ /**
4
+ * Writes current-state values to the store's key/value side, one key at a time.
5
+ *
6
+ * A write reads its value (`read()`) when it RUNS, not when it is asked for, so asking again
7
+ * while a write is waiting to start changes nothing — that write will carry the newer value —
8
+ * and writes for one key land in the order they were asked for. Nothing here touches the log.
9
+ */
10
+ export declare class DurableStateWriter {
11
+ private readonly slots;
12
+ private readonly store;
13
+ private readonly logger;
14
+ constructor(store: SessionStore | undefined, logger: Logger);
15
+ /** Store `read()` under `key` (null/undefined removes it). See the class doc for ordering. */
16
+ write(key: StateKey, read: () => unknown): Promise<void>;
17
+ /** Settles once every write asked for `key` so far has finished (succeeded or failed). */
18
+ settled(key: StateKey): Promise<void>;
19
+ /** Settles once every write asked for so far has finished (succeeded or failed). */
20
+ flush(): Promise<void>;
21
+ }
22
+ //# sourceMappingURL=durable-state.d.ts.map
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Writes current-state values to the store's key/value side, one key at a time.
3
+ *
4
+ * A write reads its value (`read()`) when it RUNS, not when it is asked for, so asking again
5
+ * while a write is waiting to start changes nothing — that write will carry the newer value —
6
+ * and writes for one key land in the order they were asked for. Nothing here touches the log.
7
+ */
8
+ export class DurableStateWriter {
9
+ slots = new Map();
10
+ store;
11
+ logger;
12
+ constructor(store, logger) {
13
+ this.store = store;
14
+ this.logger = logger;
15
+ }
16
+ /** Store `read()` under `key` (null/undefined removes it). See the class doc for ordering. */
17
+ write(key, read) {
18
+ const store = this.store;
19
+ if (store === undefined)
20
+ return Promise.resolve();
21
+ let slot = this.slots.get(key);
22
+ if (slot === undefined) {
23
+ slot = { tail: Promise.resolve(), waiting: undefined };
24
+ this.slots.set(key, slot);
25
+ }
26
+ if (slot.waiting !== undefined)
27
+ return slot.waiting;
28
+ const current = slot;
29
+ const write = current.tail.then(async () => {
30
+ // Running now: a change from here on must be carried by a write after this one.
31
+ current.waiting = undefined;
32
+ const value = read();
33
+ if (value === undefined || value === null)
34
+ await store.deleteState(key);
35
+ else
36
+ await store.putState(key, value);
37
+ });
38
+ current.waiting = write;
39
+ current.tail = write.catch(() => undefined);
40
+ write.catch((error) => {
41
+ this.logger.log("warn", `failed to persist state "${key}"`, { error: error instanceof Error ? error.message : String(error) });
42
+ });
43
+ return write;
44
+ }
45
+ /** Settles once every write asked for `key` so far has finished (succeeded or failed). */
46
+ settled(key) {
47
+ return this.slots.get(key)?.tail ?? Promise.resolve();
48
+ }
49
+ /** Settles once every write asked for so far has finished (succeeded or failed). */
50
+ async flush() {
51
+ await Promise.all([...this.slots.values()].map((slot) => slot.tail));
52
+ }
53
+ }
54
+ //# sourceMappingURL=durable-state.js.map
@@ -0,0 +1,22 @@
1
+ /** The session is closed: nothing can be sent to it or run on it. */
2
+ export declare class SessionClosedError extends Error {
3
+ readonly sessionId: string;
4
+ constructor(sessionId: string);
5
+ }
6
+ /** The session is waiting for an answer to an interrupted run, and nothing else can go in first. */
7
+ export declare class SessionInterruptedError extends Error {
8
+ readonly sessionId: string;
9
+ constructor(sessionId: string);
10
+ }
11
+ /** An answer was given, but the session has no interrupted run to apply it to. */
12
+ export declare class SessionNotInterruptedError extends Error {
13
+ readonly sessionId: string;
14
+ constructor(sessionId: string);
15
+ }
16
+ /** No frame is running at the address a message was sent to. */
17
+ export declare class SteerTargetNotFoundError extends Error {
18
+ readonly sessionId: string;
19
+ readonly address: string;
20
+ constructor(sessionId: string, address: string);
21
+ }
22
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1,39 @@
1
+ /** The session is closed: nothing can be sent to it or run on it. */
2
+ export class SessionClosedError extends Error {
3
+ sessionId;
4
+ constructor(sessionId) {
5
+ super(`session "${sessionId}" is closed`);
6
+ this.name = "SessionClosedError";
7
+ this.sessionId = sessionId;
8
+ }
9
+ }
10
+ /** The session is waiting for an answer to an interrupted run, and nothing else can go in first. */
11
+ export class SessionInterruptedError extends Error {
12
+ sessionId;
13
+ constructor(sessionId) {
14
+ super(`session "${sessionId}" has an interrupted run. Respond to it or resolve it before sending anything else.`);
15
+ this.name = "SessionInterruptedError";
16
+ this.sessionId = sessionId;
17
+ }
18
+ }
19
+ /** An answer was given, but the session has no interrupted run to apply it to. */
20
+ export class SessionNotInterruptedError extends Error {
21
+ sessionId;
22
+ constructor(sessionId) {
23
+ super(`No interrupted run to respond to on session "${sessionId}" (no persisted interruption state).`);
24
+ this.name = "SessionNotInterruptedError";
25
+ this.sessionId = sessionId;
26
+ }
27
+ }
28
+ /** No frame is running at the address a message was sent to. */
29
+ export class SteerTargetNotFoundError extends Error {
30
+ sessionId;
31
+ address;
32
+ constructor(sessionId, address) {
33
+ super(`no frame is running at "${address}" in session "${sessionId}"`);
34
+ this.name = "SteerTargetNotFoundError";
35
+ this.sessionId = sessionId;
36
+ this.address = address;
37
+ }
38
+ }
39
+ //# sourceMappingURL=errors.js.map
@@ -52,7 +52,7 @@ export class Handoff {
52
52
  return defineTool({
53
53
  name: toolName,
54
54
  description: this.toolDescription,
55
- params,
55
+ parameters: params,
56
56
  resolve: (args) => ({
57
57
  approvalRule: toolName,
58
58
  accesses: ToolAccesses.none(),
@@ -1,4 +1,6 @@
1
1
  export { Agent, defineAgent } from "./agent.ts";
2
+ export { SessionClosedError, SessionInterruptedError, SessionNotInterruptedError, SteerTargetNotFoundError } from "./errors.ts";
3
+ export type { OutputSchema } from "./agent.ts";
2
4
  export type { AgentConfig, AgentGuardrails, AgentRunContext } from "./agent.ts";
3
5
  export { Handoff, handoff, getTransferMessage, toFunctionToolName } from "./handoff.ts";
4
6
  export type { HandoffOptions, HandoffInputData, HandoffInputFilter } from "./handoff.ts";
@@ -8,8 +10,8 @@ export { composeLoopHooks } from "./compose-hooks.ts";
8
10
  /** Agent profile + session runtime → the params one request carries. Exported so embedders
9
11
  * that drive `runTurn` directly resolve precedence the same way the Runner does. */
10
12
  export { resolveModelParams } from "./run-support.ts";
11
- export { CapabilityMissingError, Session, newSessionId } from "./session.ts";
12
- export type { BackgroundTaskListOptions, ReadBackgroundTaskOutputDeltaOptions, ReadBackgroundTaskOutputOptions, ConversationHead, CreateGoalInput, GoalBudgetInput, GoalStatusInput, PlanModeOptions, SessionConfig, SessionPort, } from "./session.ts";
13
+ export { Session, newSessionId } from "./session.ts";
14
+ export type { BackgroundTaskListOptions, ReadBackgroundTaskOutputDeltaOptions, ReadBackgroundTaskOutputOptions, ConversationHead, CreateGoalInput, GoalBudgetInput, GoalStatusInput, PlanModeOptions, SessionOpenOptions, SessionPort, } from "./session.ts";
13
15
  export { newAgentId } from "./subagent.ts";
14
16
  export type { SubagentRecord, SubagentStatus, AgentSpawnDetails } from "./subagent.ts";
15
17
  export { RawAgentProfileSchema, resolveAgentProfiles, resolveProfileDirs, loadAgentProfiles, loadAgentProfilesFromSources, prepareSystemPromptContext, buildAgentFromProfile, profileSubagentProvider, } from "./profiles.ts";
@@ -20,6 +22,6 @@ export type { WorktreeHandle } from "./worktree.ts";
20
22
  export { computeContextBreakdown } from "./context-report.ts";
21
23
  export type { ContextBreakdown, ContextSlice, ContextInjectionSlice, ComputeContextBreakdownInput, } from "./context-report.ts";
22
24
  export { Runner } from "./runner.ts";
23
- export type { AgentInput, ResumeInput, RunInterruption, RunnerConfig, RunOptions, RunResult, RunStatus, } from "./runner.ts";
25
+ export type { AgentInput, CompletedRunResult, FailedRunResult, GuardrailBlockedRunResult, InterruptedRunResult, ResumeInput, RunError, RunnerConfig, RunOptions, RunResult, RunStatus, StoppedRunResult, } from "./runner.ts";
24
26
  export * from "./workflow/index.ts";
25
27
  //# sourceMappingURL=index.d.ts.map
@@ -1,11 +1,12 @@
1
1
  export { Agent, defineAgent } from "./agent.js";
2
+ export { SessionClosedError, SessionInterruptedError, SessionNotInterruptedError, SteerTargetNotFoundError } from "./errors.js";
2
3
  export { Handoff, handoff, getTransferMessage, toFunctionToolName } from "./handoff.js";
3
4
  export { GuardrailTripwireError, isGuardrailTripwireError, runInputGuardrails, runOutputGuardrails, toolGuardrail, toolInputGuardrailHook, toolOutputGuardrailHook, } from "./guardrail.js";
4
5
  export { composeLoopHooks } from "./compose-hooks.js";
5
6
  /** Agent profile + session runtime → the params one request carries. Exported so embedders
6
7
  * that drive `runTurn` directly resolve precedence the same way the Runner does. */
7
8
  export { resolveModelParams } from "./run-support.js";
8
- export { CapabilityMissingError, Session, newSessionId } from "./session.js";
9
+ export { Session, newSessionId } from "./session.js";
9
10
  export { newAgentId } from "./subagent.js";
10
11
  export { RawAgentProfileSchema, resolveAgentProfiles, resolveProfileDirs, loadAgentProfiles, loadAgentProfilesFromSources, prepareSystemPromptContext, buildAgentFromProfile, profileSubagentProvider, } from "./profiles.js";
11
12
  export { DEFAULT_AGENT_PROFILES, DEFAULT_AGENT_PROFILE_NAME, DEFAULT_SUBAGENT_NAMES } from "./profile-builtins.js";
@@ -1,4 +1,4 @@
1
- import type { Machine } from "../tool/machine.ts";
1
+ import type { Environment } from "../tool/environment.ts";
2
2
  /** Runtime-only values used to render a profile system prompt. */
3
3
  export interface SystemPromptContext {
4
4
  readonly osKind: string;
@@ -13,20 +13,20 @@ export interface SystemPromptContext {
13
13
  }
14
14
  /** Format a date without adding a timezone conversion that could move it to another day. */
15
15
  export declare function formatSystemPromptDate(date: Date): string;
16
- /** Build the environment portion of a profile prompt from the active runtime machine. */
17
- export declare function prepareSystemPromptContext(machine: Machine, now?: string, cwd?: string): Promise<SystemPromptContext>;
16
+ /** Build the environment portion of a profile prompt from the active runtime environment. */
17
+ export declare function prepareSystemPromptContext(environment: Environment, now?: string, cwd?: string): Promise<SystemPromptContext>;
18
18
  /**
19
19
  * Live-Session cache for system-prompt environment data.
20
20
  *
21
- * Machine object identity separates independent local/remote/worktree runtimes; normalized cwd
22
- * separates differently rooted frames backed by the same machine. Promise values also coalesce
21
+ * Environment object identity separates independent local/remote/worktree runtimes; normalized cwd
22
+ * separates differently rooted frames backed by the same environment. Promise values also coalesce
23
23
  * concurrent root/subagent reads. Nothing here is persisted, timed, or checked every turn.
24
24
  */
25
25
  export declare class SystemPromptContextCache {
26
26
  private readonly sessionDate;
27
27
  private readonly entries;
28
28
  constructor(createdAt?: Date);
29
- resolve(machine: Machine, revision?: number): Promise<SystemPromptContext>;
29
+ resolve(environment: Environment, revision?: number): Promise<SystemPromptContext>;
30
30
  /** Release runtime references when the owning Session closes. */
31
31
  clear(): void;
32
32
  }