operon-agents-core 0.1.0-alpha.2 → 0.1.0-alpha.21

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 (289) 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 +61 -6
  4. package/dist/agent/concurrency.js +1 -1
  5. package/dist/agent/context-report.d.ts +2 -2
  6. package/dist/agent/durable-state.d.ts +22 -0
  7. package/dist/agent/durable-state.js +54 -0
  8. package/dist/agent/index.d.ts +2 -2
  9. package/dist/agent/index.js +1 -1
  10. package/dist/agent/instruction-context.d.ts +6 -6
  11. package/dist/agent/instruction-context.js +23 -23
  12. package/dist/agent/profile-builtins.js +1 -1
  13. package/dist/agent/run-support.d.ts +1 -1
  14. package/dist/agent/run-support.js +6 -5
  15. package/dist/agent/runner.d.ts +25 -22
  16. package/dist/agent/runner.js +217 -121
  17. package/dist/agent/session.d.ts +262 -156
  18. package/dist/agent/session.js +590 -418
  19. package/dist/agent/subagent-tools.js +3 -3
  20. package/dist/agent/subagent.js +28 -13
  21. package/dist/agent/toolset.d.ts +1 -0
  22. package/dist/agent/toolset.js +13 -7
  23. package/dist/agent/workflow/journal.d.ts +2 -2
  24. package/dist/agent/workflow/journal.js +2 -2
  25. package/dist/agent/workflow/manager.d.ts +1 -1
  26. package/dist/agent/workflow/manager.js +1 -1
  27. package/dist/agent/workflow/prompt.js +2 -2
  28. package/dist/agent/workflow/sandbox.d.ts +1 -1
  29. package/dist/agent/workflow/sandbox.js +1 -1
  30. package/dist/agent/workflow/tool.js +30 -43
  31. package/dist/agent/worktree.d.ts +8 -8
  32. package/dist/agent/worktree.js +15 -15
  33. package/dist/capabilities/assembler.d.ts +29 -5
  34. package/dist/capabilities/assembler.js +85 -9
  35. package/dist/capabilities/background/code-task.d.ts +43 -0
  36. package/dist/capabilities/background/code-task.js +75 -0
  37. package/dist/capabilities/background/command-task.d.ts +9 -2
  38. package/dist/capabilities/background/command-task.js +22 -6
  39. package/dist/capabilities/background/index.d.ts +6 -1
  40. package/dist/capabilities/background/index.js +26 -20
  41. package/dist/capabilities/background/manager.d.ts +57 -1
  42. package/dist/capabilities/background/manager.js +210 -45
  43. package/dist/capabilities/background/persist-disk.d.ts +1 -1
  44. package/dist/capabilities/background/persist-disk.js +1 -1
  45. package/dist/capabilities/background/persist.js +4 -2
  46. package/dist/capabilities/background/projections.d.ts +16 -0
  47. package/dist/capabilities/background/projections.js +86 -0
  48. package/dist/capabilities/background/stall-watchdog.d.ts +41 -0
  49. package/dist/capabilities/background/stall-watchdog.js +85 -0
  50. package/dist/capabilities/background/task.d.ts +8 -7
  51. package/dist/capabilities/background/tools.js +33 -7
  52. package/dist/capabilities/capability-data.d.ts +52 -0
  53. package/dist/capabilities/capability-data.js +88 -0
  54. package/dist/capabilities/capability-state.d.ts +2 -4
  55. package/dist/capabilities/capability-state.js +5 -23
  56. package/dist/capabilities/capability.d.ts +203 -38
  57. package/dist/capabilities/compaction/index.js +10 -4
  58. package/dist/capabilities/compaction/service.d.ts +20 -5
  59. package/dist/capabilities/compaction/service.js +27 -11
  60. package/dist/capabilities/goal/goal-store.d.ts +76 -12
  61. package/dist/capabilities/goal/goal-store.js +137 -53
  62. package/dist/capabilities/goal/index.d.ts +1 -1
  63. package/dist/capabilities/goal/index.js +30 -7
  64. package/dist/capabilities/index.d.ts +9 -6
  65. package/dist/capabilities/index.js +4 -3
  66. package/dist/capabilities/plan/index.js +22 -5
  67. package/dist/capabilities/plan/plan-mode.d.ts +30 -9
  68. package/dist/capabilities/plan/plan-mode.js +57 -32
  69. package/dist/capabilities/plan/tools.js +1 -1
  70. package/dist/capabilities/skills/flow-provider.js +3 -3
  71. package/dist/capabilities/skills/index.d.ts +13 -1
  72. package/dist/capabilities/skills/index.js +30 -21
  73. package/dist/capabilities/skills/parser.d.ts +2 -2
  74. package/dist/capabilities/skills/parser.js +3 -3
  75. package/dist/capabilities/skills/registry.d.ts +5 -6
  76. package/dist/capabilities/skills/registry.js +6 -9
  77. package/dist/capabilities/skills/scanner.d.ts +3 -3
  78. package/dist/capabilities/skills/scanner.js +14 -14
  79. package/dist/capabilities/skills/service.d.ts +2 -1
  80. package/dist/capabilities/skills/service.js +3 -3
  81. package/dist/capabilities/skills/skill-tool.d.ts +2 -0
  82. package/dist/capabilities/skills/skill-tool.js +1 -1
  83. package/dist/capabilities/task/index.js +2 -1
  84. package/dist/capabilities/task/persist-disk.d.ts +1 -1
  85. package/dist/capabilities/task/persist-disk.js +1 -1
  86. package/dist/capabilities/task/persist.js +1 -1
  87. package/dist/capabilities/todo/index.js +11 -6
  88. package/dist/capabilities/todo/injector.js +2 -1
  89. package/dist/capabilities/todo/todo-store.d.ts +28 -7
  90. package/dist/capabilities/todo/todo-store.js +44 -11
  91. package/dist/capabilities/todo/tools.js +8 -3
  92. package/dist/capabilities/tool-provider.d.ts +3 -3
  93. package/dist/capabilities/user-hooks/engine.d.ts +3 -3
  94. package/dist/capabilities/user-hooks/engine.js +7 -7
  95. package/dist/capabilities/user-hooks/index.js +2 -1
  96. package/dist/capabilities/workflow/index.d.ts +5 -3
  97. package/dist/capabilities/workflow/index.js +3 -2
  98. package/dist/commands/index.js +34 -32
  99. package/dist/config/index.d.ts +1 -1
  100. package/dist/config/provider-manager.js +0 -28
  101. package/dist/config/schema.d.ts +53 -4
  102. package/dist/config/schema.js +53 -1
  103. package/dist/events/events.d.ts +43 -11
  104. package/dist/events/events.js +1 -0
  105. package/dist/events/index.d.ts +2 -2
  106. package/dist/events/index.js +1 -1
  107. package/dist/events/projection.d.ts +49 -1
  108. package/dist/events/projection.js +144 -19
  109. package/dist/events/publisher.js +2 -21
  110. package/dist/home.d.ts +1 -1
  111. package/dist/home.js +1 -1
  112. package/dist/index.d.ts +3 -2
  113. package/dist/index.js +2 -1
  114. package/dist/internal.d.ts +5 -2
  115. package/dist/internal.js +5 -2
  116. package/dist/llm/define-model.d.ts +4 -0
  117. package/dist/llm/define-model.js +63 -25
  118. package/dist/llm/index.d.ts +1 -0
  119. package/dist/llm/index.js +1 -0
  120. package/dist/llm/model.d.ts +2 -0
  121. package/dist/llm/provider.d.ts +17 -0
  122. package/dist/llm/provider.js +14 -0
  123. package/dist/llm/retry.js +1 -1
  124. package/dist/loop/context.d.ts +21 -1
  125. package/dist/loop/context.js +47 -9
  126. package/dist/loop/events.d.ts +5 -1
  127. package/dist/loop/index.d.ts +2 -2
  128. package/dist/loop/index.js +1 -1
  129. package/dist/loop/interruption.d.ts +9 -4
  130. package/dist/loop/interruption.js +11 -25
  131. package/dist/loop/run-turn.d.ts +16 -3
  132. package/dist/loop/run-turn.js +13 -4
  133. package/dist/loop/steer.d.ts +78 -12
  134. package/dist/loop/steer.js +101 -38
  135. package/dist/loop/tool-call.d.ts +13 -2
  136. package/dist/loop/tool-call.js +135 -5
  137. package/dist/loop/turn-step.d.ts +13 -2
  138. package/dist/loop/turn-step.js +29 -7
  139. package/dist/loop/types.d.ts +6 -0
  140. package/dist/mcp/auth-tool.d.ts +3 -1
  141. package/dist/mcp/auth-tool.js +2 -2
  142. package/dist/mcp/capability.d.ts +13 -0
  143. package/dist/mcp/capability.js +36 -17
  144. package/dist/mcp/config-loader.d.ts +5 -5
  145. package/dist/mcp/config-loader.js +17 -17
  146. package/dist/mcp/credentials.d.ts +35 -0
  147. package/dist/mcp/credentials.js +2 -0
  148. package/dist/mcp/filter.d.ts +2 -2
  149. package/dist/mcp/index.d.ts +4 -3
  150. package/dist/mcp/index.js +1 -1
  151. package/dist/mcp/manager.d.ts +108 -6
  152. package/dist/mcp/manager.js +262 -18
  153. package/dist/mcp/oauth/callback-server.d.ts +10 -1
  154. package/dist/mcp/oauth/callback-server.js +82 -16
  155. package/dist/mcp/oauth/index.d.ts +2 -2
  156. package/dist/mcp/oauth/provider.d.ts +18 -0
  157. package/dist/mcp/oauth/provider.js +31 -1
  158. package/dist/mcp/oauth/service.d.ts +9 -3
  159. package/dist/mcp/oauth/service.js +29 -4
  160. package/dist/mcp/sdk-transport.js +1 -1
  161. package/dist/mcp/server.js +1 -1
  162. package/dist/permission/auto-approver/prompts-data.d.ts +1 -1
  163. package/dist/permission/auto-approver/prompts-data.js +1 -1
  164. package/dist/permission/manager.d.ts +5 -3
  165. package/dist/permission/manager.js +7 -3
  166. package/dist/permission/policies.d.ts +2 -2
  167. package/dist/permission/policies.js +4 -4
  168. package/dist/plugins/fields.d.ts +14 -0
  169. package/dist/plugins/fields.js +30 -0
  170. package/dist/plugins/hooks.d.ts +2 -2
  171. package/dist/plugins/hooks.js +12 -12
  172. package/dist/plugins/index.js +1 -0
  173. package/dist/plugins/manager.d.ts +8 -3
  174. package/dist/plugins/manager.js +18 -7
  175. package/dist/plugins/manifest.d.ts +2 -2
  176. package/dist/plugins/manifest.js +101 -91
  177. package/dist/plugins/marketplace.js +76 -57
  178. package/dist/plugins/store.d.ts +3 -3
  179. package/dist/plugins/store.js +6 -6
  180. package/dist/protocol/index.d.ts +1 -1
  181. package/dist/store/catalog-store.d.ts +4 -1
  182. package/dist/store/catalog-store.js +5 -1
  183. package/dist/store/checkpointing-store.d.ts +41 -0
  184. package/dist/store/checkpointing-store.js +86 -0
  185. package/dist/store/disk-store.d.ts +8 -0
  186. package/dist/store/disk-store.js +127 -5
  187. package/dist/store/index.d.ts +3 -2
  188. package/dist/store/index.js +2 -1
  189. package/dist/store/log-store.d.ts +9 -1
  190. package/dist/store/log-store.js +68 -4
  191. package/dist/store/migrate.d.ts +8 -2
  192. package/dist/store/migrate.js +9 -2
  193. package/dist/store/origin.d.ts +31 -6
  194. package/dist/store/origin.js +0 -14
  195. package/dist/store/pg.d.ts +1 -0
  196. package/dist/store/pg.js +37 -2
  197. package/dist/store/redis.d.ts +1 -0
  198. package/dist/store/redis.js +30 -0
  199. package/dist/store/repository.d.ts +13 -1
  200. package/dist/store/repository.js +45 -2
  201. package/dist/store/session-catalog.d.ts +4 -0
  202. package/dist/store/session-catalog.js +6 -0
  203. package/dist/store/storage.js +3 -0
  204. package/dist/store/store.d.ts +97 -34
  205. package/dist/store/store.js +64 -10
  206. package/dist/telemetry/appender.d.ts +43 -0
  207. package/dist/telemetry/appender.js +46 -0
  208. package/dist/telemetry/events.d.ts +142 -0
  209. package/dist/telemetry/events.js +141 -0
  210. package/dist/telemetry/index.d.ts +10 -0
  211. package/dist/telemetry/index.js +6 -0
  212. package/dist/telemetry/projection.d.ts +23 -0
  213. package/dist/telemetry/projection.js +185 -0
  214. package/dist/telemetry/redact.d.ts +20 -0
  215. package/dist/telemetry/redact.js +40 -0
  216. package/dist/telemetry/service.d.ts +49 -0
  217. package/dist/telemetry/service.js +137 -0
  218. package/dist/testing.d.ts +58 -0
  219. package/dist/testing.js +123 -0
  220. package/dist/tool/background.d.ts +9 -6
  221. package/dist/tool/background.js +7 -1
  222. package/dist/tool/builtin/ask-user-question.js +6 -5
  223. package/dist/tool/builtin/bash.d.ts +6 -0
  224. package/dist/tool/builtin/bash.js +79 -42
  225. package/dist/tool/builtin/edit.js +82 -109
  226. package/dist/tool/builtin/glob.js +13 -13
  227. package/dist/tool/builtin/grep.js +13 -13
  228. package/dist/tool/builtin/read.js +25 -15
  229. package/dist/tool/builtin/write.js +49 -33
  230. package/dist/tool/define.d.ts +14 -8
  231. package/dist/tool/define.js +8 -2
  232. package/dist/tool/{machine-base.d.ts → environment-base.d.ts} +37 -37
  233. package/dist/tool/{machine-base.js → environment-base.js} +45 -119
  234. package/dist/tool/{machine-local.d.ts → environment-local.d.ts} +9 -8
  235. package/dist/tool/{machine-local.js → environment-local.js} +60 -81
  236. package/dist/tool/{machine-null.d.ts → environment-null.d.ts} +9 -9
  237. package/dist/tool/{machine-null.js → environment-null.js} +9 -9
  238. package/dist/tool/{machine-ssh.d.ts → environment-ssh.d.ts} +33 -18
  239. package/dist/tool/{machine-ssh.js → environment-ssh.js} +118 -149
  240. package/dist/tool/{machine.d.ts → environment.d.ts} +53 -82
  241. package/dist/tool/environment.js +2 -0
  242. package/dist/tool/file-freshness.d.ts +33 -19
  243. package/dist/tool/file-freshness.js +39 -30
  244. package/dist/tool/filesystem-tools.d.ts +1 -1
  245. package/dist/tool/filesystem-tools.js +1 -1
  246. package/dist/tool/git-context.d.ts +2 -2
  247. package/dist/tool/git-context.js +8 -8
  248. package/dist/tool/index.d.ts +12 -12
  249. package/dist/tool/index.js +12 -10
  250. package/dist/tool/policies/path-access.d.ts +4 -4
  251. package/dist/tool/policies/path-access.js +12 -12
  252. package/dist/tool/questions.d.ts +8 -0
  253. package/dist/tool/search/catalog.d.ts +37 -0
  254. package/dist/tool/search/catalog.js +182 -0
  255. package/dist/tool/search/deferral.d.ts +3 -2
  256. package/dist/tool/search/loaded.d.ts +32 -0
  257. package/dist/tool/search/loaded.js +96 -0
  258. package/dist/tool/search/search-tool.d.ts +2 -6
  259. package/dist/tool/search/search-tool.js +16 -15
  260. package/dist/tool/shell-env.js +4 -0
  261. package/dist/tool/support/bash-paths.js +38 -7
  262. package/dist/tool/support/{machine-ops.d.ts → environment-ops.d.ts} +12 -14
  263. package/dist/tool/support/{machine-ops.js → environment-ops.js} +21 -2
  264. package/dist/tool/support/git-worktree.d.ts +3 -3
  265. package/dist/tool/support/git-worktree.js +6 -6
  266. package/dist/tool/support/rg-locator.d.ts +6 -6
  267. package/dist/tool/support/rg-locator.js +6 -6
  268. package/dist/tool/support/ripgrep-run.d.ts +5 -5
  269. package/dist/tool/support/ripgrep-run.js +3 -3
  270. package/dist/tool/support/tool-path.d.ts +3 -3
  271. package/dist/tool/support/tool-path.js +7 -7
  272. package/dist/tool/types.d.ts +54 -10
  273. package/dist/tool/web/fetch-url.js +1 -1
  274. package/dist/tool/web/web-search.js +1 -1
  275. package/dist/tool/workspace-spec.d.ts +3 -3
  276. package/dist/tool/workspace-spec.js +27 -27
  277. package/dist/tracing/bridge.d.ts +9 -1
  278. package/dist/tracing/bridge.js +307 -77
  279. package/dist/tracing/index.d.ts +2 -2
  280. package/dist/tracing/otel.d.ts +28 -1
  281. package/dist/tracing/otel.js +150 -38
  282. package/dist/tracing/processor.d.ts +22 -0
  283. package/dist/tracing/processor.js +2 -0
  284. package/dist/tracing/spans.d.ts +54 -0
  285. package/dist/tracing/spans.js +5 -0
  286. package/package.json +6 -2
  287. package/dist/tool/machine.js +0 -15
  288. package/dist/tool/search/activation.d.ts +0 -13
  289. package/dist/tool/search/activation.js +0 -31
@@ -1,16 +1,14 @@
1
- /**
2
- * Shared building blocks for Machine implementations and their callers.
3
- *
4
- * The high-level operations (writeTextIfUnchanged / realpath) are mandatory
5
- * Machine members; their default compositions live in BaseMachine
6
- * (machine-base.ts). This module carries what both sides agree on: FileVersion
7
- * helpers, the decode contract, and the caller-side text-file helpers
8
- * (readTextFile / writeTextFile) composed from the core members.
9
- */
10
- import type { DecodeErrors, Machine, FileInfo, FileVersion } from "../machine.ts";
1
+ import type { DecodeErrors, Environment, FileInfo, FileVersion } from "../environment.ts";
11
2
  export declare function fileVersionFromInfo(info: FileInfo): FileVersion;
12
3
  /** Strip a UTF BOM and normalize CRLF to LF — the form ledger content comparisons use. */
13
4
  export declare function normalizeForCompare(text: string): string;
5
+ /**
6
+ * Digest of a `normalizeForCompare`d text — what the ledger retains and the CAS
7
+ * compares instead of the text itself. Keeps a record's footprint constant no matter
8
+ * how large the file is. It is a content-review key, never the freshness criterion:
9
+ * the mtime still decides whenever both sides have one.
10
+ */
11
+ export declare function hashFileContent(normalizedText: string): string;
14
12
  /**
15
13
  * Both sides must HAVE an mtime and agree on it. A missing mtime is never a match:
16
14
  * it is the absence of evidence, and the caller's next move is a content review,
@@ -23,12 +21,12 @@ export declare function decodeText(data: Buffer, options?: {
23
21
  errors?: DecodeErrors;
24
22
  }): string;
25
23
  /** Whole-file text read composed from the core members (readBytes + decode). */
26
- export declare function readTextFile(host: Pick<Machine, "readBytes">, path: string, options?: {
24
+ export declare function readTextFile(host: Pick<Environment, "readBytes">, path: string, options?: {
27
25
  encoding?: BufferEncoding;
28
26
  errors?: DecodeErrors;
29
27
  }): Promise<string>;
30
- /** Unconditional whole-file text write — thin sugar over Machine.writeText. */
31
- export declare function writeTextFile(host: Pick<Machine, "writeText">, path: string, data: string, options?: {
28
+ /** Unconditional whole-file text write — thin sugar over Environment.writeText. */
29
+ export declare function writeTextFile(host: Pick<Environment, "writeText">, path: string, data: string, options?: {
32
30
  encoding?: BufferEncoding;
33
31
  }): Promise<void>;
34
- //# sourceMappingURL=machine-ops.d.ts.map
32
+ //# sourceMappingURL=environment-ops.d.ts.map
@@ -1,3 +1,13 @@
1
+ /**
2
+ * Shared building blocks for Environment implementations and their callers.
3
+ *
4
+ * The high-level operations (writeTextIfUnchanged / realpath) are mandatory
5
+ * Environment members; their default compositions live in BaseEnvironment
6
+ * (environment-base.ts). This module carries what both sides agree on: FileVersion
7
+ * helpers, the decode contract, and the caller-side text-file helpers
8
+ * (readTextFile / writeTextFile) composed from the core members.
9
+ */
10
+ import { createHash } from "node:crypto";
1
11
  export function fileVersionFromInfo(info) {
2
12
  return info.mtimeMs === undefined ? {} : { mtimeMs: info.mtimeMs };
3
13
  }
@@ -6,6 +16,15 @@ export function normalizeForCompare(text) {
6
16
  const stripped = text.charCodeAt(0) === 0xfeff ? text.slice(1) : text;
7
17
  return stripped.replaceAll("\r\n", "\n");
8
18
  }
19
+ /**
20
+ * Digest of a `normalizeForCompare`d text — what the ledger retains and the CAS
21
+ * compares instead of the text itself. Keeps a record's footprint constant no matter
22
+ * how large the file is. It is a content-review key, never the freshness criterion:
23
+ * the mtime still decides whenever both sides have one.
24
+ */
25
+ export function hashFileContent(normalizedText) {
26
+ return createHash("sha256").update(normalizedText, "utf8").digest("base64url");
27
+ }
9
28
  /**
10
29
  * Both sides must HAVE an mtime and agree on it. A missing mtime is never a match:
11
30
  * it is the absence of evidence, and the caller's next move is a content review,
@@ -27,8 +46,8 @@ export function decodeText(data, options) {
27
46
  export async function readTextFile(host, path, options) {
28
47
  return decodeText(await host.readBytes(path), options);
29
48
  }
30
- /** Unconditional whole-file text write — thin sugar over Machine.writeText. */
49
+ /** Unconditional whole-file text write — thin sugar over Environment.writeText. */
31
50
  export async function writeTextFile(host, path, data, options) {
32
51
  await host.writeText(path, data, options?.encoding !== undefined ? { encoding: options.encoding } : {});
33
52
  }
34
- //# sourceMappingURL=machine-ops.js.map
53
+ //# sourceMappingURL=environment-ops.js.map
@@ -1,10 +1,10 @@
1
- import type { Machine } from "../machine.ts";
1
+ import type { Environment } from "../environment.ts";
2
2
  import { type PathClass } from "../policies/path-access.ts";
3
- export type GitWorkTreeMachine = Pick<Machine, "fileInfo" | "readBytes">;
3
+ export type GitWorkTreeEnvironment = Pick<Environment, "fileInfo" | "readBytes">;
4
4
  export interface GitWorkTreeMarker {
5
5
  readonly dotGitPath: string;
6
6
  readonly controlDirPath: string;
7
7
  }
8
- export declare function findGitWorkTreeMarker(machine: GitWorkTreeMachine, cwd: string): Promise<GitWorkTreeMarker | null>;
8
+ export declare function findGitWorkTreeMarker(environment: GitWorkTreeEnvironment, cwd: string): Promise<GitWorkTreeMarker | null>;
9
9
  export declare function isGitControlPath(targetPath: string, marker: GitWorkTreeMarker, pathClass: PathClass): boolean;
10
10
  //# sourceMappingURL=git-worktree.d.ts.map
@@ -1,14 +1,14 @@
1
1
  import * as pathe from "pathe";
2
2
  import { isWithinDirectory } from "../policies/path-access.js";
3
- import { readTextFile } from "./machine-ops.js";
3
+ import { readTextFile } from "./environment-ops.js";
4
4
  const MAX_WALK_DEPTH = 256;
5
- export async function findGitWorkTreeMarker(machine, cwd) {
5
+ export async function findGitWorkTreeMarker(environment, cwd) {
6
6
  if (cwd.length === 0 || !pathe.isAbsolute(cwd))
7
7
  return null;
8
8
  let current = pathe.normalize(cwd);
9
9
  for (let depth = 0; depth < MAX_WALK_DEPTH; depth += 1) {
10
10
  const dotGitPath = pathe.join(current, ".git");
11
- const hit = await probeGitMarker(machine, dotGitPath, current);
11
+ const hit = await probeGitMarker(environment, dotGitPath, current);
12
12
  if (hit !== null)
13
13
  return hit;
14
14
  const parent = pathe.dirname(current);
@@ -18,10 +18,10 @@ export async function findGitWorkTreeMarker(machine, cwd) {
18
18
  }
19
19
  return null;
20
20
  }
21
- async function probeGitMarker(machine, dotGitPath, markerParent) {
21
+ async function probeGitMarker(environment, dotGitPath, markerParent) {
22
22
  let kind;
23
23
  try {
24
- kind = (await machine.fileInfo(dotGitPath)).kind;
24
+ kind = (await environment.fileInfo(dotGitPath)).kind;
25
25
  }
26
26
  catch {
27
27
  return null;
@@ -32,7 +32,7 @@ async function probeGitMarker(machine, dotGitPath, markerParent) {
32
32
  return null;
33
33
  let content;
34
34
  try {
35
- content = await readTextFile(machine, dotGitPath);
35
+ content = await readTextFile(environment, dotGitPath);
36
36
  }
37
37
  catch {
38
38
  return null;
@@ -1,4 +1,4 @@
1
- import type { Machine } from "../machine.ts";
1
+ import type { Environment } from "../environment.ts";
2
2
  export interface RgResolution {
3
3
  readonly path: string;
4
4
  }
@@ -6,14 +6,14 @@ export declare function ensureRgPath(_options?: {
6
6
  signal?: AbortSignal;
7
7
  }): Promise<RgResolution>;
8
8
  /**
9
- * Decide how to invoke ripgrep on a given machine.
10
- * - Local machine → the absolute path found on the orchestrator's PATH (the
9
+ * Decide how to invoke ripgrep on a given environment.
10
+ * - Local environment → the absolute path found on the orchestrator's PATH (the
11
11
  * process runs here, so the resolved path is correct and avoids PATH ambiguity).
12
- * - Remote machines (ssh, sandbox) → the bare command name `rg`, resolved against
12
+ * - Remote environments (ssh, sandbox) → the bare command name `rg`, resolved against
13
13
  * the REMOTE host's PATH when exec'd. The local absolute path would be meaningless
14
- * there, so we never probe it for non-local machines.
14
+ * there, so we never probe it for non-local environments.
15
15
  */
16
- export declare function resolveRgCommand(machine: Pick<Machine, "name">, options?: {
16
+ export declare function resolveRgCommand(environment: Pick<Environment, "name">, options?: {
17
17
  signal?: AbortSignal;
18
18
  }): Promise<string>;
19
19
  export declare function rgUnavailableMessage(cause: unknown): string;
@@ -21,15 +21,15 @@ export function ensureRgPath(_options = {}) {
21
21
  return Promise.resolve({ path: found });
22
22
  }
23
23
  /**
24
- * Decide how to invoke ripgrep on a given machine.
25
- * - Local machine → the absolute path found on the orchestrator's PATH (the
24
+ * Decide how to invoke ripgrep on a given environment.
25
+ * - Local environment → the absolute path found on the orchestrator's PATH (the
26
26
  * process runs here, so the resolved path is correct and avoids PATH ambiguity).
27
- * - Remote machines (ssh, sandbox) → the bare command name `rg`, resolved against
27
+ * - Remote environments (ssh, sandbox) → the bare command name `rg`, resolved against
28
28
  * the REMOTE host's PATH when exec'd. The local absolute path would be meaningless
29
- * there, so we never probe it for non-local machines.
29
+ * there, so we never probe it for non-local environments.
30
30
  */
31
- export async function resolveRgCommand(machine, options = {}) {
32
- if (machine.name === "local")
31
+ export async function resolveRgCommand(environment, options = {}) {
32
+ if (environment.name === "local")
33
33
  return (await ensureRgPath(options)).path;
34
34
  return "rg";
35
35
  }
@@ -1,7 +1,7 @@
1
- import type { Machine } from "../machine.ts";
1
+ import type { Environment } from "../environment.ts";
2
2
  /**
3
- * One ripgrep invocation, run on the given machine (local / ssh / sandbox) through
4
- * `machine.run`. The Grep and Glob tools share this so their handling of a search that
3
+ * One ripgrep invocation, run on the given environment (local / ssh / sandbox) through
4
+ * `environment.run`. The Grep and Glob tools share this so their handling of a search that
5
5
  * runs too long or prints too much stays identical.
6
6
  *
7
7
  * Timeout, output capping and cancellation are stated as INTENT and fulfilled by the
@@ -56,10 +56,10 @@ export interface RipgrepRunOptions {
56
56
  }
57
57
  /**
58
58
  * Wording for a timeout, honest about whether the backend could actually stop ripgrep.
59
- * A backend that can only walk away leaves the search running on the remote machine —
59
+ * A backend that can only walk away leaves the search running on the remote environment —
60
60
  * the model should hear that instead of being told the search "timed out" as if it were
61
61
  * cleanly cancelled. Phrasing only: no caller branches on it.
62
62
  */
63
63
  export declare function stillRunningNote(terminated: boolean): string;
64
- export declare function runRipgrep(machine: Machine, rgArgs: readonly string[], signal: AbortSignal, options: RipgrepRunOptions): Promise<RipgrepRunOutcome>;
64
+ export declare function runRipgrep(environment: Environment, rgArgs: readonly string[], signal: AbortSignal, options: RipgrepRunOptions): Promise<RipgrepRunOutcome>;
65
65
  //# sourceMappingURL=ripgrep-run.d.ts.map
@@ -1,18 +1,18 @@
1
1
  /**
2
2
  * Wording for a timeout, honest about whether the backend could actually stop ripgrep.
3
- * A backend that can only walk away leaves the search running on the remote machine —
3
+ * A backend that can only walk away leaves the search running on the remote environment —
4
4
  * the model should hear that instead of being told the search "timed out" as if it were
5
5
  * cleanly cancelled. Phrasing only: no caller branches on it.
6
6
  */
7
7
  export function stillRunningNote(terminated) {
8
8
  return terminated ? "" : " (the search could not be stopped and may still be running)";
9
9
  }
10
- export async function runRipgrep(machine, rgArgs, signal, options) {
10
+ export async function runRipgrep(environment, rgArgs, signal, options) {
11
11
  if (signal.aborted)
12
12
  return { kind: "aborted" };
13
13
  let result;
14
14
  try {
15
- result = await machine.run(rgArgs, {
15
+ result = await environment.run(rgArgs, {
16
16
  timeoutMs: options.timeoutMs,
17
17
  maxOutputBytes: options.maxOutputBytes,
18
18
  ...(options.cwd !== undefined ? { cwd: options.cwd } : {}),
@@ -1,8 +1,8 @@
1
1
  import { type PathAccessOperation, type WorkspaceAccessPolicy } from "../policies/path-access.ts";
2
- import type { Machine } from "../machine.ts";
2
+ import type { Environment } from "../environment.ts";
3
3
  import type { ToolPlan } from "../types.ts";
4
4
  export declare const SEARCH_ACCESS_POLICY: WorkspaceAccessPolicy;
5
- export declare function resolveToolPath(path: string, machine: Machine, operation: PathAccessOperation, policy?: WorkspaceAccessPolicy): Promise<string>;
6
- export declare function pathApproval(toolName: string, machine: Machine, path: string): Pick<ToolPlan, "approvalRule" | "matchesRule">;
5
+ export declare function resolveToolPath(path: string, environment: Environment, operation: PathAccessOperation, policy?: WorkspaceAccessPolicy): Promise<string>;
6
+ export declare function pathApproval(toolName: string, environment: Environment, path: string): Pick<ToolPlan, "approvalRule" | "matchesRule">;
7
7
  export declare function globApproval(toolName: string, subject: string): Pick<ToolPlan, "approvalRule" | "matchesRule">;
8
8
  //# sourceMappingURL=tool-path.d.ts.map
@@ -1,21 +1,21 @@
1
1
  import { resolvePathAccessPath } from "../policies/path-access.js";
2
2
  import { literalRulePattern, matchesGlobRuleSubject, matchesPathRuleSubject } from "./rule-match.js";
3
3
  export const SEARCH_ACCESS_POLICY = { guardMode: "absolute-outside-allowed", checkSensitive: false };
4
- export function resolveToolPath(path, machine, operation, policy) {
4
+ export function resolveToolPath(path, environment, operation, policy) {
5
5
  return resolvePathAccessPath(path, {
6
- machine,
7
- workspace: { workspaceDir: machine.getcwd(), additionalDirs: machine.additionalDirs?.() ?? [] },
6
+ environment,
7
+ workspace: { workspaceDir: environment.getcwd(), additionalDirs: environment.additionalDirs?.() ?? [] },
8
8
  operation,
9
9
  policy,
10
10
  });
11
11
  }
12
- export function pathApproval(toolName, machine, path) {
12
+ export function pathApproval(toolName, environment, path) {
13
13
  return {
14
14
  approvalRule: literalRulePattern(toolName, path),
15
15
  matchesRule: (ruleArgs) => matchesPathRuleSubject(ruleArgs, path, {
16
- cwd: machine.getcwd(),
17
- pathClass: machine.pathClass(),
18
- homeDir: machine.gethome(),
16
+ cwd: environment.getcwd(),
17
+ pathClass: environment.pathClass(),
18
+ homeDir: environment.gethome(),
19
19
  }),
20
20
  };
21
21
  }
@@ -1,6 +1,7 @@
1
1
  import type { ImageContent, TextContent, ToolSchema } from "../protocol/index.ts";
2
+ import type { ApprovalResponse } from "../permission/types.ts";
2
3
  import type { ToolAccesses } from "./access.ts";
3
- import type { Machine } from "./machine.ts";
4
+ import type { Environment } from "./environment.ts";
4
5
  import type { BackgroundSpawner } from "./background.ts";
5
6
  import type { FileFreshnessLedger } from "./file-freshness.ts";
6
7
  import type { QuestionResponder } from "./questions.ts";
@@ -40,11 +41,6 @@ export interface ToolResumeContext {
40
41
  export interface ToolResult<Details = unknown> {
41
42
  readonly content: ToolResultContent;
42
43
  readonly details?: Details;
43
- /**
44
- * Tool definitions made available by this result. pi 0.81 uses these names
45
- * as the transcript load point for native deferred-tool serialization.
46
- */
47
- readonly addedToolNames?: readonly string[];
48
44
  readonly isError?: boolean;
49
45
  readonly stopTurn?: boolean;
50
46
  }
@@ -52,11 +48,18 @@ export interface ToolResult<Details = unknown> {
52
48
  * The call identity + execution surface shared by the resolve phase and the run phase of
53
49
  * one tool call. New fields needed by both phases belong here, not on both subtypes.
54
50
  */
55
- export interface ToolContextBase {
51
+ export interface ToolContextBase<TContext = unknown> {
56
52
  readonly turnId: string;
57
53
  readonly toolCallId: string;
58
54
  readonly signal: AbortSignal;
59
- readonly machine: Machine;
55
+ readonly environment: Environment;
56
+ /**
57
+ * The host's application context for this run — `RunOptions.context` (or the Harness
58
+ * session's), the same value `instructions` and guardrails receive. Runtime-only: never
59
+ * journaled. Typed by the tool author's declaration, not checked: a tool written for one
60
+ * context shape must not be handed to a run that passes another.
61
+ */
62
+ readonly context?: TContext;
60
63
  /**
61
64
  * Journal address of the frame running this call — `main` for the root agent, `main/<agentId>`
62
65
  * for a subagent. It is the frame's identity: what `agent.started`/`agent.ended` events carry,
@@ -72,9 +75,50 @@ export interface ToolContextBase {
72
75
  */
73
76
  readonly fileLedger?: FileFreshnessLedger;
74
77
  }
75
- export interface ToolRunContext extends ToolContextBase {
78
+ /**
79
+ * Run another tool from inside a running tool, through the same pipeline a model-issued call
80
+ * takes — prepare hook, plan resolution, authorization, execution, finalize hook — so a program
81
+ * the model wrote (Code Mode) cannot reach a tool without the permissions and hooks a direct
82
+ * call would face. The loop hands one to every tool run; a hand-built context may omit it.
83
+ */
84
+ export interface NestedToolDispatcher {
85
+ /** Schemas of every tool the calling step can execute: the full registry, deferred ones included. */
86
+ readonly schemas: readonly ToolSchema[];
87
+ /**
88
+ * Run `name` with `args`. Resolves to the tool's result; an unknown, denied or failed call is
89
+ * an error RESULT (`isError: true`), never a rejection. An approval the call needs is asked in
90
+ * place when the run has a live approver; the promise waits for the answer. A call that would
91
+ * pause the run — an approval with no live approver, a tool that suspends for input — comes back as an
92
+ * error result: a nested call cannot park the turn. For the approval case the result carries
93
+ * `interrupt`, so a caller able to pause ITSELF (`ToolRunContext.suspend`) can, and later
94
+ * re-issue the same call with the user's answer in `options.approval`.
95
+ */
96
+ call(name: string, args: unknown, options?: NestedCallOptions): Promise<NestedCallResult>;
97
+ }
98
+ export interface NestedCallOptions {
99
+ /**
100
+ * The user's answer to the approval this same call reported earlier (`interrupt`). Applied
101
+ * exactly as a resumed batch applies its answers — recorded for audit, then honoured — so a
102
+ * rejection blocks the call and an approval runs it without asking again.
103
+ */
104
+ readonly approval?: ApprovalResponse;
105
+ }
106
+ /** An approval a nested call needs and cannot obtain in place: what to ask the user. */
107
+ export interface NestedCallInterrupt {
108
+ readonly toolCallId: string;
109
+ readonly toolName: string;
110
+ readonly approvalRule: string;
111
+ readonly policyName?: string;
112
+ readonly display?: unknown;
113
+ }
114
+ export type NestedCallResult = ToolResult & {
115
+ readonly interrupt?: NestedCallInterrupt;
116
+ };
117
+ export interface ToolRunContext<TContext = unknown> extends ToolContextBase<TContext> {
76
118
  readonly onUpdate?: (update: ToolUpdate) => void;
77
119
  readonly background?: BackgroundSpawner;
120
+ /** Run other tools through the full pipeline (see {@link NestedToolDispatcher}). */
121
+ readonly dispatch?: NestedToolDispatcher;
78
122
  /**
79
123
  * Client channel for interactive questions (AskUserQuestion). Absent — or present
80
124
  * without `requestQuestion` — when the connected client cannot render questions;
@@ -113,7 +157,7 @@ export interface ToolPlan {
113
157
  readonly controlFlow?: boolean;
114
158
  readonly run: (ctx: ToolRunContext) => Promise<ToolResult>;
115
159
  }
116
- export interface ToolResolveContext extends ToolContextBase {
160
+ export interface ToolResolveContext<TContext = unknown> extends ToolContextBase<TContext> {
117
161
  }
118
162
  export interface Tool {
119
163
  readonly schema: ToolSchema;
@@ -22,7 +22,7 @@ export function fetchUrlTool(provider) {
22
22
  accesses: ToolAccesses.none(),
23
23
  approvalRule: "FetchURL",
24
24
  matchesRule: (rulePattern) => ruleMatchesUrl(rulePattern, args.url),
25
- display: { title: `Fetching ${args.url}` },
25
+ display: { title: `Fetching ${args.url}`, url: args.url },
26
26
  run: async (ctx) => {
27
27
  try {
28
28
  const result = await provider.fetch(args.url, { signal: ctx.signal });
@@ -27,7 +27,7 @@ export function webSearchTool(provider) {
27
27
  return {
28
28
  accesses: ToolAccesses.none(),
29
29
  approvalRule: "WebSearch",
30
- display: { title: `Searching: ${preview}` },
30
+ display: { title: `Searching: ${preview}`, query: args.query },
31
31
  run: async (ctx) => {
32
32
  try {
33
33
  const results = await provider.search(args.query, {
@@ -7,10 +7,10 @@
7
7
  * secret-store environment references, and cross-language serialization compatibility. Those
8
8
  * are where nearly all the size of such formats goes. Add one only when a real need appears.
9
9
  *
10
- * Written against `Machine`, so it works on local, SSH and sandbox backends alike rather than
10
+ * Written against `Environment`, so it works on local, SSH and sandbox backends alike rather than
11
11
  * being reimplemented per vendor.
12
12
  */
13
- import type { Machine } from "./machine.ts";
13
+ import type { Environment } from "./environment.ts";
14
14
  export type WorkspaceEntry = {
15
15
  readonly type: "dir";
16
16
  readonly children?: Readonly<Record<string, WorkspaceEntry>>;
@@ -59,7 +59,7 @@ export declare class WorkspaceMaterializeError extends Error {
59
59
  * Create everything the spec declares. Entries are materialized in declaration order so a
60
60
  * later entry may depend on an earlier one (config written into a freshly cloned repo).
61
61
  */
62
- export declare function materializeWorkspace(machine: Machine, spec: WorkspaceSpec, options?: MaterializeOptions): Promise<void>;
62
+ export declare function materializeWorkspace(environment: Environment, spec: WorkspaceSpec, options?: MaterializeOptions): Promise<void>;
63
63
  /**
64
64
  * Render a spec as a tree, for telling a MODEL what its workspace contains.
65
65
  *
@@ -1,4 +1,4 @@
1
- /** Concurrent host→machine file writes. Latency-bound work, so this is well above CPU count. */
1
+ /** Concurrent host→environment file writes. Latency-bound work, so this is well above CPU count. */
2
2
  const HOST_DIR_CONCURRENCY = 8;
3
3
  /** Run `body` over every item, at most `limit` in flight. The first rejection propagates. */
4
4
  async function inParallel(items, limit, body) {
@@ -24,61 +24,61 @@ export class WorkspaceMaterializeError extends Error {
24
24
  * Create everything the spec declares. Entries are materialized in declaration order so a
25
25
  * later entry may depend on an earlier one (config written into a freshly cloned repo).
26
26
  */
27
- export async function materializeWorkspace(machine, spec, options = {}) {
28
- const root = machine.normpath(spec.root);
29
- await machine.mkdir(root, { parents: true });
30
- await materializeEntries(machine, root, root, spec.entries, options);
27
+ export async function materializeWorkspace(environment, spec, options = {}) {
28
+ const root = environment.normpath(spec.root);
29
+ await environment.mkdir(root, { parents: true });
30
+ await materializeEntries(environment, root, root, spec.entries, options);
31
31
  }
32
- async function materializeEntries(machine, root, base, entries, options) {
32
+ async function materializeEntries(environment, root, base, entries, options) {
33
33
  for (const [relative, entry] of Object.entries(entries)) {
34
34
  options.signal?.throwIfAborted();
35
- const target = safeJoin(machine, root, base, relative);
36
- await materializeEntry(machine, root, target, entry, options);
35
+ const target = safeJoin(environment, root, base, relative);
36
+ await materializeEntry(environment, root, target, entry, options);
37
37
  }
38
38
  }
39
- async function materializeEntry(machine, root, target, entry, options) {
39
+ async function materializeEntry(environment, root, target, entry, options) {
40
40
  switch (entry.type) {
41
41
  case "dir": {
42
- await machine.mkdir(target, { parents: true });
42
+ await environment.mkdir(target, { parents: true });
43
43
  if (entry.children !== undefined) {
44
- await materializeEntries(machine, root, target, entry.children, options);
44
+ await materializeEntries(environment, root, target, entry.children, options);
45
45
  }
46
46
  return;
47
47
  }
48
48
  case "file": {
49
- await machine.mkdir(parentOf(machine, target), { parents: true });
50
- await machine.writeText(target, entry.content, {
49
+ await environment.mkdir(parentOf(environment, target), { parents: true });
50
+ await environment.writeText(target, entry.content, {
51
51
  ...(entry.lineEndings !== undefined ? { lineEndings: entry.lineEndings } : {}),
52
52
  });
53
53
  return;
54
54
  }
55
55
  case "host_file": {
56
56
  const reader = requireReader(options, target);
57
- await machine.mkdir(parentOf(machine, target), { parents: true });
57
+ await environment.mkdir(parentOf(environment, target), { parents: true });
58
58
  // writeBytes, not writeText: a host file may be an image, a binary, or text in an
59
59
  // encoding we have no business guessing at. Decoding to UTF-8 here corrupted every
60
60
  // one of those, silently.
61
- await machine.writeBytes(target, await reader.readFile(entry.src));
61
+ await environment.writeBytes(target, await reader.readFile(entry.src));
62
62
  return;
63
63
  }
64
64
  case "host_dir": {
65
65
  const reader = requireReader(options, target);
66
- await machine.mkdir(target, { parents: true });
66
+ await environment.mkdir(target, { parents: true });
67
67
  const files = (await reader.listFiles(entry.src)).map((relative) => ({
68
68
  relative,
69
- dest: safeJoin(machine, root, target, relative),
69
+ dest: safeJoin(environment, root, target, relative),
70
70
  }));
71
71
  // Create each parent directory once rather than once per file it holds.
72
- for (const dir of new Set(files.map(({ dest }) => parentOf(machine, dest)))) {
72
+ for (const dir of new Set(files.map(({ dest }) => parentOf(environment, dest)))) {
73
73
  options.signal?.throwIfAborted();
74
- await machine.mkdir(dir, { parents: true });
74
+ await environment.mkdir(dir, { parents: true });
75
75
  }
76
76
  // Copy with bounded concurrency. Serially, every file cost a full round trip, so on a
77
- // remote machine a directory of any size was seconds of pure latency; the cap keeps a
77
+ // remote environment a directory of any size was seconds of pure latency; the cap keeps a
78
78
  // large tree from opening an unbounded number of writes at once.
79
79
  await inParallel(files, HOST_DIR_CONCURRENCY, async ({ relative, dest }) => {
80
80
  options.signal?.throwIfAborted();
81
- await machine.writeBytes(dest, await reader.readFile(`${entry.src}/${relative}`));
81
+ await environment.writeBytes(dest, await reader.readFile(`${entry.src}/${relative}`));
82
82
  });
83
83
  return;
84
84
  }
@@ -89,7 +89,7 @@ async function materializeEntry(machine, root, target, entry, options) {
89
89
  if (entry.ref !== undefined)
90
90
  argv.push("--branch", entry.ref);
91
91
  argv.push("--", entry.repo, target);
92
- const result = await machine.run(argv, {
92
+ const result = await environment.run(argv, {
93
93
  ...(options.gitTimeoutMs !== undefined ? { timeoutMs: options.gitTimeoutMs } : {}),
94
94
  ...(options.signal !== undefined ? { signal: options.signal } : {}),
95
95
  });
@@ -156,8 +156,8 @@ function requireReader(options, path) {
156
156
  }
157
157
  return options.hostReader;
158
158
  }
159
- function parentOf(machine, path) {
160
- const sep = machine.pathClass() === "win32" ? "\\" : "/";
159
+ function parentOf(environment, path) {
160
+ const sep = environment.pathClass() === "win32" ? "\\" : "/";
161
161
  const cut = path.lastIndexOf(sep);
162
162
  return cut <= 0 ? path : path.slice(0, cut);
163
163
  }
@@ -165,9 +165,9 @@ function parentOf(machine, path) {
165
165
  * Join and verify the result stays under `root`. Entry paths often come from user config, so
166
166
  * `../` escaping the workspace must be refused rather than normalized away silently.
167
167
  */
168
- function safeJoin(machine, root, base, relative) {
169
- const sep = machine.pathClass() === "win32" ? "\\" : "/";
170
- const joined = machine.normpath(`${base}${sep}${relative}`);
168
+ function safeJoin(environment, root, base, relative) {
169
+ const sep = environment.pathClass() === "win32" ? "\\" : "/";
170
+ const joined = environment.normpath(`${base}${sep}${relative}`);
171
171
  const prefix = root.endsWith(sep) ? root : `${root}${sep}`;
172
172
  if (joined !== root && !joined.startsWith(prefix)) {
173
173
  throw new WorkspaceMaterializeError(`entry path escapes the workspace root: ${relative}`, joined);
@@ -1,7 +1,15 @@
1
1
  import type { EventSink } from "../events/index.ts";
2
- import type { TracingProcessor } from "./processor.ts";
2
+ import type { TracingContentMode, TracingProcessor } from "./processor.ts";
3
3
  export interface TracingBridgeOptions {
4
4
  readonly now?: () => number;
5
+ /** Overrides `processor.content`. See `TracingContentMode`. */
6
+ readonly content?: TracingContentMode;
5
7
  }
8
+ /**
9
+ * Subscribes to a session's `AgentEvent` stream and drives a `TracingProcessor` with a span tree:
10
+ * agent → turn → generation | tool | message, sub-agents nested by address. With content enabled
11
+ * (processor or option) the spans also carry the prompt, messages, tool args/results — see
12
+ * `TracingContentMode`.
13
+ */
6
14
  export declare function eventSinkTracingBridge(sink: EventSink, processor: TracingProcessor, options?: TracingBridgeOptions): () => void;
7
15
  //# sourceMappingURL=bridge.d.ts.map