operon-agents-core 0.1.0-alpha.6 → 0.1.0-alpha.9

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 (233) hide show
  1. package/dist/agent/agent.d.ts +8 -7
  2. package/dist/agent/compose-hooks.d.ts +10 -1
  3. package/dist/agent/compose-hooks.js +55 -5
  4. package/dist/agent/concurrency.js +1 -1
  5. package/dist/agent/context-report.d.ts +1 -1
  6. package/dist/agent/instruction-context.d.ts +6 -6
  7. package/dist/agent/instruction-context.js +23 -23
  8. package/dist/agent/profile-builtins.js +1 -1
  9. package/dist/agent/run-support.d.ts +1 -1
  10. package/dist/agent/run-support.js +5 -4
  11. package/dist/agent/runner.d.ts +18 -21
  12. package/dist/agent/runner.js +152 -100
  13. package/dist/agent/session.d.ts +164 -113
  14. package/dist/agent/session.js +381 -363
  15. package/dist/agent/toolset.d.ts +1 -0
  16. package/dist/agent/toolset.js +13 -7
  17. package/dist/agent/workflow/journal.d.ts +2 -2
  18. package/dist/agent/workflow/journal.js +2 -2
  19. package/dist/agent/workflow/manager.d.ts +1 -1
  20. package/dist/agent/workflow/manager.js +1 -1
  21. package/dist/agent/workflow/prompt.js +1 -1
  22. package/dist/agent/workflow/sandbox.d.ts +1 -1
  23. package/dist/agent/workflow/sandbox.js +1 -1
  24. package/dist/agent/workflow/tool.js +21 -21
  25. package/dist/agent/worktree.d.ts +8 -8
  26. package/dist/agent/worktree.js +15 -15
  27. package/dist/capabilities/assembler.d.ts +24 -2
  28. package/dist/capabilities/assembler.js +75 -4
  29. package/dist/capabilities/background/code-task.d.ts +43 -0
  30. package/dist/capabilities/background/code-task.js +75 -0
  31. package/dist/capabilities/background/command-task.d.ts +9 -2
  32. package/dist/capabilities/background/command-task.js +22 -6
  33. package/dist/capabilities/background/index.d.ts +6 -1
  34. package/dist/capabilities/background/index.js +31 -32
  35. package/dist/capabilities/background/manager.d.ts +47 -0
  36. package/dist/capabilities/background/manager.js +189 -42
  37. package/dist/capabilities/background/persist-disk.d.ts +1 -1
  38. package/dist/capabilities/background/persist-disk.js +1 -1
  39. package/dist/capabilities/background/persist.js +4 -2
  40. package/dist/capabilities/background/projections.d.ts +16 -0
  41. package/dist/capabilities/background/projections.js +86 -0
  42. package/dist/capabilities/background/stall-watchdog.d.ts +41 -0
  43. package/dist/capabilities/background/stall-watchdog.js +85 -0
  44. package/dist/capabilities/background/task.d.ts +8 -7
  45. package/dist/capabilities/background/tools.js +1 -1
  46. package/dist/capabilities/capability-data.d.ts +52 -0
  47. package/dist/capabilities/capability-data.js +88 -0
  48. package/dist/capabilities/capability-state.d.ts +18 -6
  49. package/dist/capabilities/capability-state.js +25 -6
  50. package/dist/capabilities/capability.d.ts +143 -32
  51. package/dist/capabilities/compaction/index.js +10 -5
  52. package/dist/capabilities/compaction/service.d.ts +20 -5
  53. package/dist/capabilities/compaction/service.js +27 -11
  54. package/dist/capabilities/goal/goal-store.d.ts +34 -0
  55. package/dist/capabilities/goal/goal-store.js +82 -0
  56. package/dist/capabilities/goal/index.d.ts +0 -1
  57. package/dist/capabilities/goal/index.js +15 -12
  58. package/dist/capabilities/index.d.ts +8 -5
  59. package/dist/capabilities/index.js +3 -2
  60. package/dist/capabilities/plan/index.js +16 -12
  61. package/dist/capabilities/plan/plan-mode.d.ts +14 -3
  62. package/dist/capabilities/plan/plan-mode.js +30 -11
  63. package/dist/capabilities/skills/index.d.ts +7 -7
  64. package/dist/capabilities/skills/index.js +17 -22
  65. package/dist/capabilities/skills/parser.d.ts +2 -2
  66. package/dist/capabilities/skills/parser.js +3 -3
  67. package/dist/capabilities/skills/registry.d.ts +2 -2
  68. package/dist/capabilities/skills/registry.js +2 -2
  69. package/dist/capabilities/skills/scanner.d.ts +3 -3
  70. package/dist/capabilities/skills/scanner.js +14 -14
  71. package/dist/capabilities/skills/service.d.ts +2 -1
  72. package/dist/capabilities/skills/service.js +2 -2
  73. package/dist/capabilities/task/index.js +6 -11
  74. package/dist/capabilities/task/persist-disk.d.ts +1 -1
  75. package/dist/capabilities/task/persist-disk.js +1 -1
  76. package/dist/capabilities/task/persist.js +1 -1
  77. package/dist/capabilities/todo/index.js +7 -12
  78. package/dist/capabilities/todo/injector.js +2 -1
  79. package/dist/capabilities/todo/todo-store.d.ts +17 -5
  80. package/dist/capabilities/todo/todo-store.js +30 -10
  81. package/dist/capabilities/todo/tools.js +8 -3
  82. package/dist/capabilities/user-hooks/engine.d.ts +3 -3
  83. package/dist/capabilities/user-hooks/engine.js +7 -7
  84. package/dist/capabilities/user-hooks/index.js +17 -22
  85. package/dist/capabilities/workflow/index.d.ts +3 -3
  86. package/dist/capabilities/workflow/index.js +8 -14
  87. package/dist/commands/index.js +36 -36
  88. package/dist/events/events.d.ts +31 -10
  89. package/dist/events/projection.js +12 -4
  90. package/dist/events/publisher.js +1 -19
  91. package/dist/home.d.ts +1 -1
  92. package/dist/home.js +1 -1
  93. package/dist/index.d.ts +2 -3
  94. package/dist/index.js +1 -2
  95. package/dist/internal.d.ts +4 -3
  96. package/dist/internal.js +5 -4
  97. package/dist/llm/deferred-tools.d.ts +7 -0
  98. package/dist/llm/deferred-tools.js +27 -0
  99. package/dist/llm/define-model.d.ts +1 -0
  100. package/dist/llm/define-model.js +13 -6
  101. package/dist/llm/index.d.ts +1 -0
  102. package/dist/llm/index.js +1 -0
  103. package/dist/llm/model.d.ts +2 -0
  104. package/dist/llm/provider.d.ts +17 -0
  105. package/dist/llm/provider.js +14 -0
  106. package/dist/llm/retry.js +1 -1
  107. package/dist/loop/context.js +7 -2
  108. package/dist/loop/index.d.ts +2 -2
  109. package/dist/loop/index.js +1 -1
  110. package/dist/loop/interruption.d.ts +9 -4
  111. package/dist/loop/interruption.js +11 -25
  112. package/dist/loop/run-turn.d.ts +12 -3
  113. package/dist/loop/run-turn.js +11 -4
  114. package/dist/loop/steer.d.ts +78 -14
  115. package/dist/loop/steer.js +96 -38
  116. package/dist/loop/tool-call.d.ts +11 -2
  117. package/dist/loop/tool-call.js +93 -4
  118. package/dist/loop/turn-step.d.ts +9 -2
  119. package/dist/loop/turn-step.js +11 -4
  120. package/dist/mcp/capability.d.ts +13 -0
  121. package/dist/mcp/capability.js +18 -4
  122. package/dist/mcp/config-loader.d.ts +5 -5
  123. package/dist/mcp/config-loader.js +17 -17
  124. package/dist/mcp/index.d.ts +2 -2
  125. package/dist/mcp/index.js +1 -1
  126. package/dist/mcp/manager.d.ts +77 -26
  127. package/dist/mcp/manager.js +140 -84
  128. package/dist/mcp/oauth/callback-server.js +55 -12
  129. package/dist/mcp/oauth/provider.js +1 -1
  130. package/dist/mcp/sdk-transport.js +1 -1
  131. package/dist/mcp/server.js +1 -1
  132. package/dist/permission/auto-approver/prompts-data.d.ts +1 -1
  133. package/dist/permission/auto-approver/prompts-data.js +1 -1
  134. package/dist/permission/manager.d.ts +3 -3
  135. package/dist/permission/manager.js +3 -3
  136. package/dist/permission/policies.d.ts +2 -2
  137. package/dist/permission/policies.js +4 -4
  138. package/dist/plugins/fields.d.ts +14 -0
  139. package/dist/plugins/fields.js +30 -0
  140. package/dist/plugins/hooks.d.ts +2 -2
  141. package/dist/plugins/hooks.js +12 -12
  142. package/dist/plugins/index.js +5 -10
  143. package/dist/plugins/manager.d.ts +8 -3
  144. package/dist/plugins/manager.js +18 -7
  145. package/dist/plugins/manifest.d.ts +2 -2
  146. package/dist/plugins/manifest.js +95 -91
  147. package/dist/plugins/marketplace.js +76 -57
  148. package/dist/plugins/store.d.ts +3 -3
  149. package/dist/plugins/store.js +6 -6
  150. package/dist/store/index.d.ts +1 -1
  151. package/dist/store/log-store.d.ts +1 -1
  152. package/dist/store/log-store.js +1 -1
  153. package/dist/store/origin.d.ts +30 -14
  154. package/dist/store/origin.js +0 -14
  155. package/dist/store/pg.d.ts +1 -0
  156. package/dist/store/pg.js +8 -0
  157. package/dist/store/redis.d.ts +1 -0
  158. package/dist/store/redis.js +7 -0
  159. package/dist/store/repository.d.ts +4 -0
  160. package/dist/store/repository.js +23 -0
  161. package/dist/store/storage.js +3 -0
  162. package/dist/store/store.d.ts +9 -16
  163. package/dist/store/store.js +12 -8
  164. package/dist/testing.d.ts +19 -23
  165. package/dist/testing.js +82 -80
  166. package/dist/tool/background.d.ts +9 -6
  167. package/dist/tool/background.js +7 -1
  168. package/dist/tool/builtin/ask-user-question.js +6 -5
  169. package/dist/tool/builtin/bash.d.ts +6 -0
  170. package/dist/tool/builtin/bash.js +79 -42
  171. package/dist/tool/builtin/edit.js +82 -109
  172. package/dist/tool/builtin/glob.js +13 -13
  173. package/dist/tool/builtin/grep.js +13 -13
  174. package/dist/tool/builtin/read.js +25 -15
  175. package/dist/tool/builtin/write.js +49 -33
  176. package/dist/tool/{machine-base.d.ts → environment-base.d.ts} +37 -37
  177. package/dist/tool/{machine-base.js → environment-base.js} +45 -119
  178. package/dist/tool/{machine-local.d.ts → environment-local.d.ts} +9 -8
  179. package/dist/tool/{machine-local.js → environment-local.js} +60 -81
  180. package/dist/tool/{machine-null.d.ts → environment-null.d.ts} +9 -9
  181. package/dist/tool/{machine-null.js → environment-null.js} +9 -9
  182. package/dist/tool/{machine-ssh.d.ts → environment-ssh.d.ts} +33 -18
  183. package/dist/tool/{machine-ssh.js → environment-ssh.js} +118 -149
  184. package/dist/tool/{machine.d.ts → environment.d.ts} +53 -82
  185. package/dist/tool/environment.js +2 -0
  186. package/dist/tool/file-freshness.d.ts +33 -19
  187. package/dist/tool/file-freshness.js +39 -30
  188. package/dist/tool/filesystem-tools.d.ts +1 -1
  189. package/dist/tool/filesystem-tools.js +1 -1
  190. package/dist/tool/git-context.d.ts +2 -2
  191. package/dist/tool/git-context.js +8 -8
  192. package/dist/tool/index.d.ts +11 -12
  193. package/dist/tool/index.js +9 -10
  194. package/dist/tool/policies/path-access.d.ts +4 -4
  195. package/dist/tool/policies/path-access.js +12 -12
  196. package/dist/tool/questions.d.ts +8 -0
  197. package/dist/tool/search/activation.d.ts +4 -0
  198. package/dist/tool/search/activation.js +4 -0
  199. package/dist/tool/search/catalog.d.ts +33 -0
  200. package/dist/tool/search/catalog.js +180 -0
  201. package/dist/tool/search/loaded.d.ts +22 -0
  202. package/dist/tool/search/loaded.js +61 -0
  203. package/dist/tool/search/search-tool.d.ts +2 -6
  204. package/dist/tool/search/search-tool.js +13 -11
  205. package/dist/tool/shell-env.js +4 -0
  206. package/dist/tool/support/bash-paths.js +1 -1
  207. package/dist/tool/support/{machine-ops.d.ts → environment-ops.d.ts} +12 -14
  208. package/dist/tool/support/{machine-ops.js → environment-ops.js} +21 -2
  209. package/dist/tool/support/git-worktree.d.ts +3 -3
  210. package/dist/tool/support/git-worktree.js +6 -6
  211. package/dist/tool/support/rg-locator.d.ts +6 -6
  212. package/dist/tool/support/rg-locator.js +6 -6
  213. package/dist/tool/support/ripgrep-run.d.ts +5 -5
  214. package/dist/tool/support/ripgrep-run.js +3 -3
  215. package/dist/tool/support/tool-path.d.ts +3 -3
  216. package/dist/tool/support/tool-path.js +7 -7
  217. package/dist/tool/types.d.ts +43 -2
  218. package/dist/tool/web/fetch-url.js +1 -1
  219. package/dist/tool/web/web-search.js +1 -1
  220. package/dist/tool/workspace-spec.d.ts +3 -3
  221. package/dist/tool/workspace-spec.js +27 -27
  222. package/dist/tracing/bridge.js +26 -0
  223. package/dist/tracing/otel.js +33 -33
  224. package/package.json +1 -1
  225. package/dist/scope/index.d.ts +0 -7
  226. package/dist/scope/index.js +0 -4
  227. package/dist/scope/scope.d.ts +0 -154
  228. package/dist/scope/scope.js +0 -428
  229. package/dist/scope/token.d.ts +0 -29
  230. package/dist/scope/token.js +0 -29
  231. package/dist/scope/tokens.d.ts +0 -114
  232. package/dist/scope/tokens.js +0 -65
  233. package/dist/tool/machine.js +0 -15
@@ -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
  }
@@ -38,10 +38,11 @@ export interface AgentConfig<TContext = unknown> {
38
38
  readonly outputType?: unknown;
39
39
  readonly maxStepsPerTurn?: number;
40
40
  /**
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.
41
+ * Capability/MCP tools are discovered on demand through SearchTool; only loaded ones are
42
+ * sent to the model, so the catalog can change mid-conversation without touching the
43
+ * request prefix. On models with native deferred-tool support (Anthropic tool_reference,
44
+ * Kimi, OpenAI tool search) pi also keeps a loaded definition out of the prefix. Default:
45
+ * on for those models, off elsewhere. `false` loads capability tools up front.
45
46
  */
46
47
  readonly deferTools?: boolean;
47
48
  }
@@ -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,16 +34,58 @@ 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).
@@ -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();
@@ -48,7 +48,7 @@ export interface ContextBreakdown {
48
48
  export interface ComputeContextBreakdownInput {
49
49
  readonly model: ChatModel;
50
50
  readonly system: string | undefined;
51
- readonly tools: readonly Tool[];
51
+ readonly tools: readonly Pick<Tool, "schema">[];
52
52
  readonly messages: readonly Message[];
53
53
  /** Per-injector token estimates captured while injecting at the turn boundary. */
54
54
  readonly injectionTokens: ReadonlyMap<string, number>;
@@ -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
  }
@@ -1,5 +1,5 @@
1
1
  import { dirname, join } from "pathe";
2
- import { readTextFile } from "../tool/support/machine-ops.js";
2
+ import { readTextFile } from "../tool/support/environment-ops.js";
3
3
  const AGENTS_MD_MAX_CHARS = 32 * 1024;
4
4
  /** Format a date without adding a timezone conversion that could move it to another day. */
5
5
  export function formatSystemPromptDate(date) {
@@ -8,23 +8,23 @@ export function formatSystemPromptDate(date) {
8
8
  const day = String(date.getDate()).padStart(2, "0");
9
9
  return `${year}-${month}-${day}`;
10
10
  }
11
- /** Build the environment portion of a profile prompt from the active runtime machine. */
12
- export async function prepareSystemPromptContext(machine, now = formatSystemPromptDate(new Date()), cwd = machine.normpath(machine.getcwd())) {
11
+ /** Build the environment portion of a profile prompt from the active runtime environment. */
12
+ export async function prepareSystemPromptContext(environment, now = formatSystemPromptDate(new Date()), cwd = environment.normpath(environment.getcwd())) {
13
13
  return {
14
- osKind: machine.osEnv.osKind,
15
- osArch: machine.osEnv.osArch,
16
- osVersion: machine.osEnv.osVersion,
17
- shell: `${machine.osEnv.shellName} (${machine.osEnv.shellPath})`,
14
+ osKind: environment.osInfo.osKind,
15
+ osArch: environment.osInfo.osArch,
16
+ osVersion: environment.osInfo.osVersion,
17
+ shell: `${environment.osInfo.shellName} (${environment.osInfo.shellPath})`,
18
18
  now,
19
19
  cwd,
20
- agentsMd: await loadAgentsMd(machine, cwd),
20
+ agentsMd: await loadAgentsMd(environment, cwd),
21
21
  };
22
22
  }
23
23
  /**
24
24
  * Live-Session cache for system-prompt environment data.
25
25
  *
26
- * Machine object identity separates independent local/remote/worktree runtimes; normalized cwd
27
- * separates differently rooted frames backed by the same machine. Promise values also coalesce
26
+ * Environment object identity separates independent local/remote/worktree runtimes; normalized cwd
27
+ * separates differently rooted frames backed by the same environment. Promise values also coalesce
28
28
  * concurrent root/subagent reads. Nothing here is persisted, timed, or checked every turn.
29
29
  */
30
30
  export class SystemPromptContextCache {
@@ -33,17 +33,17 @@ export class SystemPromptContextCache {
33
33
  constructor(createdAt = new Date()) {
34
34
  this.sessionDate = formatSystemPromptDate(createdAt);
35
35
  }
36
- resolve(machine, revision = 0) {
37
- const cwd = machine.normpath(machine.getcwd());
38
- let byCwd = this.entries.get(machine);
36
+ resolve(environment, revision = 0) {
37
+ const cwd = environment.normpath(environment.getcwd());
38
+ let byCwd = this.entries.get(environment);
39
39
  if (byCwd === undefined) {
40
40
  byCwd = new Map();
41
- this.entries.set(machine, byCwd);
41
+ this.entries.set(environment, byCwd);
42
42
  }
43
43
  const cached = byCwd.get(cwd);
44
44
  if (cached?.revision === revision)
45
45
  return cached.value;
46
- const value = prepareSystemPromptContext(machine, this.sessionDate, cwd).catch((error) => {
46
+ const value = prepareSystemPromptContext(environment, this.sessionDate, cwd).catch((error) => {
47
47
  if (byCwd?.get(cwd)?.value === value)
48
48
  byCwd.delete(cwd);
49
49
  throw error;
@@ -57,13 +57,13 @@ export class SystemPromptContextCache {
57
57
  }
58
58
  }
59
59
  /** Collect AGENTS.md from the user dir then filesystem root→cwd (nearest appended last). */
60
- async function loadAgentsMd(machine, cwd) {
61
- const paths = agentsMdPaths(machine, cwd);
60
+ async function loadAgentsMd(environment, cwd) {
61
+ const paths = agentsMdPaths(environment, cwd);
62
62
  // Reads are independent. Keep result order deterministic while avoiding a serial RPC walk on
63
- // remote machines.
63
+ // remote environments.
64
64
  const files = await Promise.all(paths.map(async (path) => {
65
65
  try {
66
- const text = (await readTextFile(machine, path)).slice(0, AGENTS_MD_MAX_CHARS).trim();
66
+ const text = (await readTextFile(environment, path)).slice(0, AGENTS_MD_MAX_CHARS).trim();
67
67
  return text.length > 0 ? { path, text } : undefined;
68
68
  }
69
69
  catch {
@@ -75,10 +75,10 @@ async function loadAgentsMd(machine, cwd) {
75
75
  .map((file) => `# ${file.path}\n${file.text}`)
76
76
  .join("\n\n");
77
77
  }
78
- function agentsMdPaths(machine, cwd) {
79
- const candidates = [join(machine.gethome(), ".agents", "AGENTS.md")];
78
+ function agentsMdPaths(environment, cwd) {
79
+ const candidates = [join(environment.gethome(), ".agents", "AGENTS.md")];
80
80
  const dirs = [];
81
- let current = machine.normpath(cwd);
81
+ let current = environment.normpath(cwd);
82
82
  for (;;) {
83
83
  dirs.unshift(current);
84
84
  const parent = dirname(current);
@@ -90,7 +90,7 @@ function agentsMdPaths(machine, cwd) {
90
90
  candidates.push(join(dir, "AGENTS.md"));
91
91
  const seen = new Set();
92
92
  return candidates.filter((path) => {
93
- const key = machine.normpath(path);
93
+ const key = environment.normpath(path);
94
94
  if (seen.has(key))
95
95
  return false;
96
96
  seen.add(key);
@@ -73,7 +73,7 @@ whenToUse: |
73
73
  Delegate non-trivial software-engineering work (reading files, editing code, running commands) that should return a compact but technically complete summary to the parent agent.
74
74
  promptVars:
75
75
  roleAdditional: |
76
- You are running as a subagent. Every user message comes from the parent agent, which sees only your final message — not your intermediate context. Treat the parent as your caller: do not ask the end user questions; machine any ambiguity in your final summary instead.
76
+ You are running as a subagent. Every user message comes from the parent agent, which sees only your final message — not your intermediate context. Treat the parent as your caller: do not ask the end user questions; environment any ambiguity in your final summary instead.
77
77
  tools:
78
78
  - Read
79
79
  - Write
@@ -55,7 +55,7 @@ export declare function resolveModelParams(settings: ModelSettings | undefined,
55
55
  export declare function runCtxFor<TContext>(state: RunState<TContext>): AgentRunContext<TContext>;
56
56
  /**
57
57
  * Fork a child runtime for a spawned sub-agent: fresh usage/turns ledger and a new
58
- * `address` shard, inheriting the parent's shared machine (session/store/permission/…)
58
+ * `address` shard, inheriting the parent's shared environment (session/store/permission/…)
59
59
  * unless an override is given. This is the single place child frames are minted — the
60
60
  * subagent, Agent, and Workflow tools all go through it.
61
61
  */
@@ -57,6 +57,7 @@ export function historyChangeEmitter(events, sessionId) {
57
57
  cutoff: record.cutoff,
58
58
  summary: record.summary,
59
59
  summaryTimestamp: record.summaryTimestamp,
60
+ ...(record.loadedTools !== undefined ? { loadedTools: record.loadedTools } : {}),
60
61
  address,
61
62
  sessionId,
62
63
  });
@@ -98,13 +99,13 @@ export function runCtxFor(state) {
98
99
  address: state.address,
99
100
  signal: state.signal,
100
101
  context: state.context,
101
- machine: state.machine,
102
- resolveSystemPromptContext: () => state.session.resolveSystemPromptContext(state.machine),
102
+ environment: state.environment,
103
+ resolveSystemPromptContext: () => state.session.resolveSystemPromptContext(state.environment),
103
104
  };
104
105
  }
105
106
  /**
106
107
  * Fork a child runtime for a spawned sub-agent: fresh usage/turns ledger and a new
107
- * `address` shard, inheriting the parent's shared machine (session/store/permission/…)
108
+ * `address` shard, inheriting the parent's shared environment (session/store/permission/…)
108
109
  * unless an override is given. This is the single place child frames are minted — the
109
110
  * subagent, Agent, and Workflow tools all go through it.
110
111
  */
@@ -124,7 +125,7 @@ export function deriveChild(parent, opts) {
124
125
  currentTurnId: frame?.turnId,
125
126
  parentToolCallId: opts.parentToolCallId,
126
127
  ...(opts.signal ? { signal: opts.signal } : {}),
127
- ...(opts.machine ? { machine: opts.machine } : {}),
128
+ ...(opts.environment ? { environment: opts.environment } : {}),
128
129
  ...(opts.steer ? { steer: opts.steer } : {}),
129
130
  };
130
131
  }
@@ -1,38 +1,36 @@
1
1
  import type { ChatModel } from "../llm/define-model.ts";
2
2
  import type { AssistantMessage, Message, Usage } from "../protocol/index.ts";
3
3
  import { ConversationContext } from "../loop/context.ts";
4
- import type { Machine } from "../tool/machine.ts";
4
+ import type { Environment } from "../tool/environment.ts";
5
5
  import type { BackgroundSpawner } from "../tool/background.ts";
6
6
  import { PermissionManager } from "../permission/manager.ts";
7
7
  import type { ApprovalResponse, Responder } from "../permission/types.ts";
8
- import type { Capability } from "../capabilities/capability.ts";
9
- import { Scope } from "../scope/scope.ts";
10
8
  import { type AssembledCapabilities } from "../capabilities/assembler.ts";
11
9
  import { type EventSink, type RunHandle } from "../events/index.ts";
12
10
  import { type SessionStore } from "../store/index.ts";
13
11
  import type { PromptOrigin, SessionLock } from "../store/index.ts";
14
12
  import { SteerBus } from "../loop/steer.ts";
15
13
  import { type InterruptAnswer, type InterruptionFrame, type InterruptionState, type PendingRunInterrupt } from "../loop/interruption.ts";
16
- import { Session, type SessionPort } from "./session.ts";
14
+ import { Session, type SessionOpenOptions, type SessionPort } from "./session.ts";
17
15
  import { Agent, type AgentRunContext } from "./agent.ts";
18
16
  import type { SubagentInfo, SubagentProvider } from "./profiles.ts";
19
17
  import { type GuardrailStage } from "./guardrail.ts";
20
18
  /**
21
- * Engine configuration — VALUES, not lifetimes. Everything with a lifetime (machine, store,
22
- * events, responder, permission options, capabilities' services) lives in a `Scope`: the
23
- * harness-tier scope the Runner is constructed on, and the session-tier scope the `session`
19
+ * Engine configuration — VALUES, not lifetimes. Everything with a lifetime (environment, store,
20
+ * events, responder, permission options, capabilities' services) is passed to `Session.open`:
24
21
  * hook fills for each session the Runner opens itself.
25
22
  */
26
23
  export interface RunnerConfig<TContext = unknown> {
27
24
  readonly resolveModel?: (modelId: string) => ChatModel | Promise<ChatModel>;
28
25
  /**
29
- * Called once per session the Runner opens on its own (no `RunOptions.session`): register
30
- * this session's objects (`T.Store`, `T.Machine`, `T.PermissionOptions`, …) on `scope` and
31
- * return its capabilities. A caller-supplied session is never passed through here.
26
+ * Called once per session the Runner opens on its own (no `RunOptions.session`): return
27
+ * everything that session is built from — its capabilities and the objects it depends on
28
+ * (store, environment, permission options, …). A caller-supplied session never comes through
29
+ * here. `sessionId` and `signal` are the Runner's to set and are overwritten if returned.
32
30
  */
33
- readonly session?: (scope: Scope<"session">, ctx: {
31
+ readonly session?: (ctx: {
34
32
  readonly sessionId: string | undefined;
35
- }) => readonly Capability[] | Promise<readonly Capability[]>;
33
+ }) => SessionOpenOptions | Promise<SessionOpenOptions>;
36
34
  readonly maxTurns?: number;
37
35
  readonly maxStepsPerTurn?: number;
38
36
  readonly maxRetriesPerStep?: number;
@@ -126,7 +124,7 @@ export interface RunOptions<TContext = unknown> {
126
124
  readonly inputOrigin?: PromptOrigin;
127
125
  }
128
126
  /**
129
- * A run's runtime: the shared machine (session/store/machine/permission/…, one per
127
+ * A run's runtime: the shared environment (session/store/environment/permission/…, one per
130
128
  * agent graph) plus the per-(sub)run frame (`address`, `usage`, `turns`). `Engine.run`
131
129
  * takes one of these; `deriveChild` forks a child frame for a spawned sub-agent.
132
130
  */
@@ -145,7 +143,7 @@ export interface RunState<TContext> {
145
143
  readonly maxTurns: number;
146
144
  address: string;
147
145
  readonly events: EventSink;
148
- readonly machine: Machine;
146
+ readonly environment: Environment;
149
147
  readonly store?: SessionStore;
150
148
  readonly responder?: Responder;
151
149
  readonly background?: BackgroundSpawner;
@@ -175,8 +173,8 @@ export interface DeriveOptions {
175
173
  readonly parentToolCallId?: string;
176
174
  /** Per-child abort (background / workflow per-agent); defaults to the parent's. */
177
175
  readonly signal?: AbortSignal;
178
- /** Isolated machine (e.g. a workflow worktree); defaults to the parent's. */
179
- readonly machine?: Machine;
176
+ /** Isolated environment (e.g. a workflow worktree); defaults to the parent's. */
177
+ readonly environment?: Environment;
180
178
  /** Own SteerBus (parallel workflow agents can't share the parent's single-turn bus). */
181
179
  readonly steer?: SteerBus;
182
180
  /** Stable instance identity for a fresh child. Defaults to the address tail. */
@@ -208,11 +206,9 @@ export interface SubagentSpawner<TContext> {
208
206
  ctxFor(state: RunState<TContext>): AgentRunContext<TContext>;
209
207
  }
210
208
  export declare class Runner<TContext = unknown> {
211
- /** The harness-tier scope every Runner-opened session hangs under. */
212
- readonly scope: Scope<"harness" | "workspace">;
213
209
  private readonly config;
214
210
  private readonly engine;
215
- constructor(scope: Scope<"harness" | "workspace">, config?: RunnerConfig<TContext>);
211
+ constructor(config?: RunnerConfig<TContext>);
216
212
  run(agent: Agent<TContext>, input: AgentInput, opts?: RunOptions<TContext>): Promise<RunResult>;
217
213
  /**
218
214
  * Hold the session lease for the duration of `fn`, when a lock is configured.
@@ -235,8 +231,9 @@ export declare class Runner<TContext = unknown> {
235
231
  private resolveConversationHead;
236
232
  private execute;
237
233
  /**
238
- * Chain the capabilities' run-tier input hooks. Each sees the previous one's rewrite; a hook
239
- * that throws is skipped (fault isolation — a broken capability must not sink the prompt).
234
+ * Chain the capabilities' run-tier input hooks. Each sees the previous one's rewrite. A broken
235
+ * detachable capability does not sink the prompt — its hook is isolated at assembly — while an
236
+ * invariant one does, as its contract says.
240
237
  */
241
238
  private applyRunStarts;
242
239
  /**