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
@@ -0,0 +1,185 @@
1
+ /**
2
+ * Built-in projection: the `AgentEvent` stream → registry events.
3
+ *
4
+ * Mirrors `tracing/bridge.ts` in shape (subscribe to a session's sink, keep per-address state,
5
+ * emit on lifecycle boundaries) but counts instead of building a tree. One subscription per
6
+ * session; sub-agents are told apart by `address`, which is stamped as a property here rather
7
+ * than by nested context views.
8
+ *
9
+ * Owns its own clock: `AgentEvent` carries no timestamp.
10
+ *
11
+ * Deliberately NOT projected: `assistant.delta`, `thinking.delta`, `tool.call.delta`,
12
+ * `content.part`, `history.*`, `log` — content or volume, never a count.
13
+ */
14
+ import { capTelemetryText, redactTelemetryString } from "./redact.js";
15
+ /** Segments in an address: `""` is 0, `"a"` is 1, `"a/b"` is 2. */
16
+ function depthOf(address) {
17
+ return address === "" ? 0 : address.split("/").length;
18
+ }
19
+ export function subscribeTelemetryProjection(sink, telemetry, options = {}) {
20
+ const now = options.now ?? (() => Date.now());
21
+ const resumed = options.resumed ?? false;
22
+ /** Active turn per agent address. Sub-agent turns nest under their own address. */
23
+ const turnByAddress = new Map();
24
+ const toolById = new Map();
25
+ const agentByAddress = new Map();
26
+ let sessionStarted = false;
27
+ let rootAddress;
28
+ const at = (address) => telemetry.withContext({ address, agent: agentByAddress.get(address) ?? null });
29
+ const handle = (event) => {
30
+ const { address } = event;
31
+ switch (event.type) {
32
+ case "agent.started": {
33
+ agentByAddress.set(address, event.agent);
34
+ if (!sessionStarted) {
35
+ sessionStarted = true;
36
+ rootAddress = address;
37
+ at(address).track("session_started", { resumed });
38
+ }
39
+ else if (address !== rootAddress) {
40
+ at(address).track("subagent_spawned", { agent_name: event.agent, depth: depthOf(address) - depthOf(rootAddress ?? "") });
41
+ }
42
+ break;
43
+ }
44
+ case "agent.ended": {
45
+ // A finished agent's dangling turn (cancelled mid-flight without turn.ended) is closed
46
+ // here so counts do not leak into the next agent at the same address.
47
+ const turn = turnByAddress.get(address);
48
+ if (turn !== undefined) {
49
+ turnByAddress.delete(address);
50
+ finish(address, turn, "cancelled");
51
+ }
52
+ break;
53
+ }
54
+ case "turn.started": {
55
+ turnByAddress.set(address, {
56
+ turnId: event.turnId,
57
+ startedAt: now(),
58
+ stepCount: 0,
59
+ toolCallCount: 0,
60
+ input: 0,
61
+ output: 0,
62
+ cacheRead: 0,
63
+ cacheWrite: 0,
64
+ model: null,
65
+ });
66
+ at(address).track("turn_started", { turn_id: event.turnId, origin: event.origin?.kind ?? "unknown" });
67
+ break;
68
+ }
69
+ case "turn.ended": {
70
+ const turn = turnByAddress.get(address);
71
+ if (turn === undefined || turn.turnId !== event.turnId)
72
+ break;
73
+ turnByAddress.delete(address);
74
+ finish(address, turn, event.reason);
75
+ break;
76
+ }
77
+ case "turn.step.started": {
78
+ const turn = turnByAddress.get(address);
79
+ if (turn !== undefined && turn.turnId === event.turnId)
80
+ turn.stepCount += 1;
81
+ break;
82
+ }
83
+ case "turn.step.retrying": {
84
+ at(address).track("step_retry", {
85
+ turn_id: event.turnId,
86
+ attempt: event.attempt,
87
+ max_attempts: event.maxAttempts,
88
+ delay_ms: event.delayMs,
89
+ reason: event.reason === undefined ? null : capTelemetryText(redactTelemetryString(event.reason), 64),
90
+ });
91
+ break;
92
+ }
93
+ case "message.appended": {
94
+ const turn = turnByAddress.get(address);
95
+ const message = event.message;
96
+ if (turn === undefined || message.role !== "assistant")
97
+ break;
98
+ turn.input += message.usage.input;
99
+ turn.output += message.usage.output;
100
+ turn.cacheRead += message.usage.cacheRead;
101
+ turn.cacheWrite += message.usage.cacheWrite;
102
+ turn.model = message.model;
103
+ break;
104
+ }
105
+ case "tool.call.started": {
106
+ const turn = turnByAddress.get(address);
107
+ if (turn !== undefined)
108
+ turn.toolCallCount += 1;
109
+ toolById.set(event.toolCallId, { turnId: turn?.turnId ?? null, startedAt: now() });
110
+ break;
111
+ }
112
+ case "tool.result": {
113
+ const tool = toolById.get(event.toolCallId);
114
+ toolById.delete(event.toolCallId);
115
+ at(address).track("tool_call", {
116
+ turn_id: tool?.turnId ?? turnByAddress.get(address)?.turnId ?? null,
117
+ tool_name: event.toolName,
118
+ outcome: event.isError ? "error" : "success",
119
+ duration_ms: tool === undefined ? 0 : now() - tool.startedAt,
120
+ });
121
+ break;
122
+ }
123
+ case "tool.suspended": {
124
+ at(address).track("tool_suspended", {
125
+ turn_id: toolById.get(event.toolCallId)?.turnId ?? turnByAddress.get(address)?.turnId ?? null,
126
+ tool_name: event.toolName,
127
+ has_request: event.request !== undefined,
128
+ });
129
+ break;
130
+ }
131
+ case "compaction.completed": {
132
+ at(address).track("compaction", {
133
+ before_tokens: event.tokensBefore,
134
+ after_tokens: event.tokensAfter,
135
+ compacted_count: event.compactedCount,
136
+ });
137
+ break;
138
+ }
139
+ case "guardrail.blocked": {
140
+ at(address).track("guardrail_blocked", { stage: event.stage, guardrail: event.guardrail });
141
+ break;
142
+ }
143
+ case "skill.activated": {
144
+ at(address).track("skill_activated", { skill_name: event.skillName, trigger: event.trigger });
145
+ break;
146
+ }
147
+ case "steer.queued": {
148
+ at(address).track("steer_queued", { channel: event.channel, origin: event.origin.kind });
149
+ break;
150
+ }
151
+ case "error": {
152
+ at(address).track("turn_error", {
153
+ turn_id: turnByAddress.get(address)?.turnId ?? null,
154
+ message: capTelemetryText(redactTelemetryString(event.message)),
155
+ });
156
+ break;
157
+ }
158
+ default:
159
+ break;
160
+ }
161
+ };
162
+ const finish = (address, turn, reason) => {
163
+ at(address).track("turn_finished", {
164
+ turn_id: turn.turnId,
165
+ reason,
166
+ duration_ms: now() - turn.startedAt,
167
+ step_count: turn.stepCount,
168
+ tool_call_count: turn.toolCallCount,
169
+ input_tokens: turn.input,
170
+ output_tokens: turn.output,
171
+ cache_read_tokens: turn.cacheRead,
172
+ cache_write_tokens: turn.cacheWrite,
173
+ model: turn.model,
174
+ });
175
+ };
176
+ return sink.subscribe((event) => {
177
+ try {
178
+ handle(event);
179
+ }
180
+ catch {
181
+ // A projection bug must never reach the session's event loop.
182
+ }
183
+ });
184
+ }
185
+ //# sourceMappingURL=projection.js.map
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Outbound redaction for telemetry properties.
3
+ *
4
+ * Builds on `logging/redact.ts` (key-based masking + secret shapes) and adds the three shapes
5
+ * that are fine in a log file but not in an analytics warehouse: emails, URLs and absolute
6
+ * paths. Paths keep their `node_modules/` tail — that part is a package name, not the user's
7
+ * directory layout, and it is what makes a dependency problem diagnosable.
8
+ *
9
+ * Runs in the appender, AFTER context merge, so context strings are covered too.
10
+ */
11
+ import { type RedactOptions } from "../logging/redact.ts";
12
+ import type { TelemetryPrimitive } from "./events.ts";
13
+ export declare const REDACTED_EMAIL = "<redacted:email>";
14
+ export declare const REDACTED_URL = "<redacted:url>";
15
+ export declare const REDACTED_PATH = "<redacted:path>";
16
+ export declare function redactTelemetryString(value: string, options?: RedactOptions): string;
17
+ export declare function redactTelemetryProperties(properties: Readonly<Record<string, TelemetryPrimitive>>, options?: RedactOptions): Record<string, TelemetryPrimitive>;
18
+ /** Bound a free-text property (error messages) so a stack trace never becomes an event. */
19
+ export declare function capTelemetryText(value: string, max?: number): string;
20
+ //# sourceMappingURL=redact.d.ts.map
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Outbound redaction for telemetry properties.
3
+ *
4
+ * Builds on `logging/redact.ts` (key-based masking + secret shapes) and adds the three shapes
5
+ * that are fine in a log file but not in an analytics warehouse: emails, URLs and absolute
6
+ * paths. Paths keep their `node_modules/` tail — that part is a package name, not the user's
7
+ * directory layout, and it is what makes a dependency problem diagnosable.
8
+ *
9
+ * Runs in the appender, AFTER context merge, so context strings are covered too.
10
+ */
11
+ import { redactText } from "../logging/redact.js";
12
+ const EMAIL = /\b[\w.%+-]+@[\w.-]+\.[A-Za-z]{2,}\b/g;
13
+ const URL = /\b(?:https?|wss?|ftp):\/\/[^\s"'<>]+/gi;
14
+ // Absolute POSIX paths (two or more segments) and Windows drive paths. Home-relative `~/x` too.
15
+ const ABSOLUTE_PATH = /(?:~|[A-Za-z]:)?(?:\/|\\)(?:[\w.@+-]+(?:\/|\\))+[\w.@+-]*/g;
16
+ export const REDACTED_EMAIL = "<redacted:email>";
17
+ export const REDACTED_URL = "<redacted:url>";
18
+ export const REDACTED_PATH = "<redacted:path>";
19
+ export function redactTelemetryString(value, options = {}) {
20
+ let out = redactText(value, options);
21
+ out = out.replace(URL, REDACTED_URL);
22
+ out = out.replace(EMAIL, REDACTED_EMAIL);
23
+ out = out.replace(ABSOLUTE_PATH, (match) => {
24
+ const index = match.indexOf("node_modules/");
25
+ return index === -1 ? REDACTED_PATH : match.slice(index);
26
+ });
27
+ return out;
28
+ }
29
+ export function redactTelemetryProperties(properties, options = {}) {
30
+ const out = {};
31
+ for (const [key, value] of Object.entries(properties)) {
32
+ out[key] = typeof value === "string" ? redactTelemetryString(value, options) : value;
33
+ }
34
+ return out;
35
+ }
36
+ /** Bound a free-text property (error messages) so a stack trace never becomes an event. */
37
+ export function capTelemetryText(value, max = 200) {
38
+ return value.length <= max ? value : `${value.slice(0, max)}…`;
39
+ }
40
+ //# sourceMappingURL=redact.js.map
@@ -0,0 +1,49 @@
1
+ /**
2
+ * TelemetryService — the `track()` facade.
3
+ *
4
+ * Deliberately thin: it merges context, drops `undefined`, stamps a timestamp and fans out to
5
+ * appenders. No enrichment, no batching, no transport — those live in appenders, so a product can
6
+ * swap the sink without touching a single call site.
7
+ *
8
+ * Context is environmental. `withContext({ session_id })` returns a forwarding VIEW: appenders, the
9
+ * enabled switch, `flush` and `shutdown` stay on the root, so an appender added after boot applies
10
+ * to every view already handed out (desktop attaches PostHog only once consent is known).
11
+ *
12
+ * `withRegistry(...)` is a type-only re-view: a product declares its own registry and tracks its
13
+ * own events through the same root. Nothing is validated at runtime — the registry is a compile-time
14
+ * contract — except the one thing types cannot see: a non-primitive value, which is dropped.
15
+ */
16
+ import type { TelemetryAppender } from "./appender.ts";
17
+ import { FRAMEWORK_TELEMETRY_EVENTS, type Exact, type FrameworkTelemetryEvents, type PayloadOf, type TelemetryPrimitive, type TelemetryRegistry } from "./events.ts";
18
+ export type TelemetryContext = Readonly<Record<string, TelemetryPrimitive | undefined>>;
19
+ export interface TelemetryService<R extends TelemetryRegistry = FrameworkTelemetryEvents> {
20
+ /** Record one event. Never throws, never awaits. A no-op while disabled or with no appender. */
21
+ track<K extends keyof R & string, P extends PayloadOf<R[K]>>(name: K, properties: Exact<PayloadOf<R[K]>, P>): void;
22
+ /** A view that prepends `context` to every event. Cheap; make one per session / agent. */
23
+ withContext(context: TelemetryContext): TelemetryService<R>;
24
+ /** The same root seen through another registry. Type-only. */
25
+ withRegistry<R2 extends TelemetryRegistry>(registry: R2): TelemetryService<R2>;
26
+ /** Attach an appender to the ROOT (views forward here). Returns a detach function. */
27
+ addAppender(appender: TelemetryAppender): () => void;
28
+ /** Master switch. Off = dropped at the root before any appender sees the event. */
29
+ setEnabled(enabled: boolean): void;
30
+ readonly enabled: boolean;
31
+ flush(): Promise<void>;
32
+ /** Drain every appender. Call before process exit or buffered events are lost. */
33
+ shutdown(): Promise<void>;
34
+ }
35
+ export interface TelemetryServiceOptions {
36
+ /** Clock for `TelemetryEvent.timestamp`. Tests inject a counter. */
37
+ readonly now?: () => number;
38
+ /** Where an appender's throw goes. Default: `console.warn`, once per appender. */
39
+ readonly onError?: (error: unknown, appender: TelemetryAppender) => void;
40
+ /** Initial switch position. Default `true`; a product with a consent gate starts `false`. */
41
+ readonly enabled?: boolean;
42
+ }
43
+ /** A root service with no appender: every `track` is a no-op until `addAppender`. */
44
+ export declare function createTelemetryService(options?: TelemetryServiceOptions): TelemetryService<FrameworkTelemetryEvents>;
45
+ /** Shared no-op instance for the "nothing configured" path. `addAppender` on it is a bug; it throws. */
46
+ export declare const noopTelemetryService: TelemetryService<FrameworkTelemetryEvents>;
47
+ /** Re-exported so `service.withRegistry(FRAMEWORK_TELEMETRY_EVENTS)` reads naturally at call sites. */
48
+ export { FRAMEWORK_TELEMETRY_EVENTS };
49
+ //# sourceMappingURL=service.d.ts.map
@@ -0,0 +1,137 @@
1
+ /**
2
+ * TelemetryService — the `track()` facade.
3
+ *
4
+ * Deliberately thin: it merges context, drops `undefined`, stamps a timestamp and fans out to
5
+ * appenders. No enrichment, no batching, no transport — those live in appenders, so a product can
6
+ * swap the sink without touching a single call site.
7
+ *
8
+ * Context is environmental. `withContext({ session_id })` returns a forwarding VIEW: appenders, the
9
+ * enabled switch, `flush` and `shutdown` stay on the root, so an appender added after boot applies
10
+ * to every view already handed out (desktop attaches PostHog only once consent is known).
11
+ *
12
+ * `withRegistry(...)` is a type-only re-view: a product declares its own registry and tracks its
13
+ * own events through the same root. Nothing is validated at runtime — the registry is a compile-time
14
+ * contract — except the one thing types cannot see: a non-primitive value, which is dropped.
15
+ */
16
+ import { nullTelemetryAppender } from "./appender.js";
17
+ import { FRAMEWORK_TELEMETRY_EVENTS } from "./events.js";
18
+ class Root {
19
+ appenders = [];
20
+ warned = new WeakSet();
21
+ now;
22
+ onError;
23
+ enabled;
24
+ constructor(options) {
25
+ this.now = options.now ?? (() => Date.now());
26
+ this.enabled = options.enabled ?? true;
27
+ this.onError =
28
+ options.onError ??
29
+ ((error, appender) => {
30
+ if (this.warned.has(appender))
31
+ return;
32
+ this.warned.add(appender);
33
+ console.warn(`[telemetry] appender threw; further errors from it are silenced: ${String(error)}`);
34
+ });
35
+ }
36
+ emit(name, properties, context) {
37
+ if (!this.enabled || this.appenders.length === 0)
38
+ return;
39
+ const merged = {};
40
+ // Context first, payload second: a payload key wins (the registry forbids overlap anyway).
41
+ for (const source of [context, properties]) {
42
+ for (const [key, value] of Object.entries(source)) {
43
+ if (value === undefined)
44
+ continue;
45
+ if (value === null || typeof value === "string" || typeof value === "number" || typeof value === "boolean")
46
+ merged[key] = value;
47
+ // Anything else is not representable on the wire; the types forbid it, so it is a bug in
48
+ // a `withRegistry` product caller that cast its way past them. Drop, do not throw.
49
+ }
50
+ }
51
+ const event = { name, properties: merged, timestamp: this.now() };
52
+ for (const appender of this.appenders) {
53
+ try {
54
+ appender.track(event);
55
+ }
56
+ catch (error) {
57
+ this.onError(error, appender);
58
+ }
59
+ }
60
+ }
61
+ add(appender) {
62
+ if (appender === nullTelemetryAppender)
63
+ return () => { };
64
+ this.appenders = [...this.appenders, appender];
65
+ return () => {
66
+ this.appenders = this.appenders.filter((a) => a !== appender);
67
+ };
68
+ }
69
+ async flush() {
70
+ await Promise.all(this.appenders.map((a) => Promise.resolve(a.flush()).catch((error) => this.onError(error, a))));
71
+ }
72
+ async shutdown() {
73
+ const appenders = this.appenders;
74
+ this.appenders = [];
75
+ await Promise.all(appenders.map((a) => Promise.resolve(a.shutdown()).catch((error) => this.onError(error, a))));
76
+ }
77
+ }
78
+ class View {
79
+ root;
80
+ context;
81
+ raw;
82
+ constructor(root, context) {
83
+ this.root = root;
84
+ this.context = context;
85
+ this.raw = (name, properties, context) => root.emit(name, properties, context);
86
+ }
87
+ track(name, properties) {
88
+ this.raw(name, properties, this.context);
89
+ }
90
+ withContext(context) {
91
+ return new View(this.root, { ...this.context, ...context });
92
+ }
93
+ withRegistry(_registry) {
94
+ return new View(this.root, this.context);
95
+ }
96
+ addAppender(appender) {
97
+ return this.root.add(appender);
98
+ }
99
+ setEnabled(enabled) {
100
+ this.root.enabled = enabled;
101
+ }
102
+ get enabled() {
103
+ return this.root.enabled;
104
+ }
105
+ flush() {
106
+ return this.root.flush();
107
+ }
108
+ shutdown() {
109
+ return this.root.shutdown();
110
+ }
111
+ }
112
+ /** A root service with no appender: every `track` is a no-op until `addAppender`. */
113
+ export function createTelemetryService(options = {}) {
114
+ return new View(new Root(options), {});
115
+ }
116
+ /** Shared no-op instance for the "nothing configured" path. `addAppender` on it is a bug; it throws. */
117
+ export const noopTelemetryService = (() => {
118
+ const service = createTelemetryService({ enabled: false });
119
+ const frozen = {
120
+ track: () => { },
121
+ withContext: () => frozen,
122
+ withRegistry: () => frozen,
123
+ addAppender: () => {
124
+ throw new Error("noopTelemetryService is shared and immutable; create one with createTelemetryService()");
125
+ },
126
+ setEnabled: () => { },
127
+ get enabled() {
128
+ return false;
129
+ },
130
+ flush: () => service.flush(),
131
+ shutdown: () => service.shutdown(),
132
+ };
133
+ return frozen;
134
+ })();
135
+ /** Re-exported so `service.withRegistry(FRAMEWORK_TELEMETRY_EVENTS)` reads naturally at call sites. */
136
+ export { FRAMEWORK_TELEMETRY_EVENTS };
137
+ //# sourceMappingURL=service.js.map
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Session-wiring helpers for tests and quick scripts (exported via `operon-agents-core/internal`).
3
+ *
4
+ * A test describes a session's objects as a flat options bag; these turn that bag into the
5
+ * `Session.open` options the engine actually takes. Nothing here is a compatibility layer for
6
+ * production code — hosts compose sessions through the harness hooks.
7
+ */
8
+ import { Runner, type RunnerConfig } from "./agent/runner.ts";
9
+ import { Session, type SessionOpenOptions } from "./agent/session.ts";
10
+ import type { Environment, EnvironmentFactory } from "./tool/environment.ts";
11
+ import { type AgentRecord, type SessionStore } from "./store/index.ts";
12
+ import { type EventSink, type EventPublicationMode } from "./events/index.ts";
13
+ import type { TracingProcessor } from "./tracing/index.ts";
14
+ import type { Responder } from "./permission/types.ts";
15
+ import type { PermissionManagerOptions } from "./permission/manager.ts";
16
+ import type { Capability, SessionContext, RunContext } from "./capabilities/capability.ts";
17
+ import { SteerBus } from "./loop/steer.ts";
18
+ import type { BackgroundSpawner } from "./tool/background.ts";
19
+ import type { Logger } from "./logging/index.ts";
20
+ export interface TestSessionWiring {
21
+ readonly environment?: Environment | EnvironmentFactory;
22
+ readonly store?: SessionStore;
23
+ readonly events?: EventSink;
24
+ readonly tracing?: TracingProcessor;
25
+ readonly responder?: Responder;
26
+ readonly permission?: PermissionManagerOptions;
27
+ readonly capabilities?: readonly Capability[];
28
+ readonly steer?: SteerBus;
29
+ readonly background?: BackgroundSpawner;
30
+ readonly eventPublication?: EventPublicationMode;
31
+ readonly logger?: Logger;
32
+ }
33
+ export type TestRunnerOptions<TContext = unknown> = TestSessionWiring & RunnerConfig<TContext>;
34
+ /** A wiring bag as `Session.open` wants it. The bag's names are the older, shorter ones. */
35
+ export declare function sessionOptionsFrom(wiring: TestSessionWiring): SessionOpenOptions;
36
+ /** `new Runner(...)` for tests: the wiring bag becomes the per-session options hook. */
37
+ export declare function testRunner<TContext = unknown>(options?: TestRunnerOptions<TContext>): Runner<TContext>;
38
+ export interface TestSessionOptions extends TestSessionWiring, SessionOpenOptions {
39
+ readonly sessionId?: string;
40
+ readonly signal?: AbortSignal;
41
+ readonly preloadedLog?: readonly AgentRecord[];
42
+ }
43
+ /** `Session.open(...)` for tests, from a wiring bag. */
44
+ export declare function openTestSession(options?: TestSessionOptions): Promise<Session>;
45
+ export interface TestCapabilityHandle {
46
+ readonly ctx: SessionContext;
47
+ /** What the capability published (`cap.service`). */
48
+ readonly service: unknown;
49
+ close(): Promise<void>;
50
+ }
51
+ /** The session context a capability's `openSession` gets, built from a wiring bag. */
52
+ export declare function testSessionContext(wiring?: TestSessionWiring): SessionContext;
53
+ /** @deprecated The provision context is now the whole {@link SessionContext}. */
54
+ export declare const testProvisionContext: typeof testSessionContext;
55
+ export declare function testRunContext(wiring?: TestSessionWiring): RunContext;
56
+ /** Open one capability against a fresh session context — what `Session.open` does for it. */
57
+ export declare function provisionCapability(cap: Capability, wiring?: TestSessionWiring): Promise<TestCapabilityHandle>;
58
+ //# sourceMappingURL=testing.d.ts.map
@@ -0,0 +1,123 @@
1
+ /**
2
+ * Session-wiring helpers for tests and quick scripts (exported via `operon-agents-core/internal`).
3
+ *
4
+ * A test describes a session's objects as a flat options bag; these turn that bag into the
5
+ * `Session.open` options the engine actually takes. Nothing here is a compatibility layer for
6
+ * production code — hosts compose sessions through the harness hooks.
7
+ */
8
+ import { Runner } from "./agent/runner.js";
9
+ import { Session } from "./agent/session.js";
10
+ import { appendAudit, DEFAULT_ADDRESS, readAudit } from "./store/index.js";
11
+ import { ListenerSink } from "./events/index.js";
12
+ import { InjectionManager } from "./capabilities/injection.js";
13
+ import { readLog } from "./capabilities/capability-state.js";
14
+ import { CapabilityData } from "./capabilities/capability-data.js";
15
+ import { SteerBus } from "./loop/steer.js";
16
+ import { NullEnvironment } from "./tool/environment-null.js";
17
+ /** A wiring bag as `Session.open` wants it. The bag's names are the older, shorter ones. */
18
+ export function sessionOptionsFrom(wiring) {
19
+ return {
20
+ ...(wiring.environment !== undefined ? { environment: wiring.environment } : {}),
21
+ ...(wiring.store !== undefined ? { store: wiring.store } : {}),
22
+ ...(wiring.events !== undefined ? { events: wiring.events } : {}),
23
+ ...(wiring.tracing !== undefined ? { tracing: wiring.tracing } : {}),
24
+ ...(wiring.responder !== undefined ? { responder: wiring.responder } : {}),
25
+ ...(wiring.permission !== undefined ? { permissionOptions: wiring.permission } : {}),
26
+ ...(wiring.steer !== undefined ? { steer: wiring.steer } : {}),
27
+ ...(wiring.background !== undefined ? { spawner: wiring.background } : {}),
28
+ ...(wiring.eventPublication !== undefined ? { eventPublication: wiring.eventPublication } : {}),
29
+ ...(wiring.logger !== undefined ? { logger: wiring.logger } : {}),
30
+ ...(wiring.capabilities !== undefined ? { capabilities: wiring.capabilities } : {}),
31
+ };
32
+ }
33
+ /** `new Runner(...)` for tests: the wiring bag becomes the per-session options hook. */
34
+ export function testRunner(options = {}) {
35
+ const { environment, store, events, tracing, responder, permission, capabilities, steer, background, eventPublication, logger, session, ...config } = options;
36
+ const wiring = { environment, store, events, tracing, responder, permission, capabilities, steer, background, eventPublication, logger };
37
+ return new Runner({
38
+ ...config,
39
+ session: async (ctx) => {
40
+ const extra = session !== undefined ? await session(ctx) : {};
41
+ return {
42
+ ...sessionOptionsFrom(wiring),
43
+ ...extra,
44
+ capabilities: [...(capabilities ?? []), ...(extra.capabilities ?? [])],
45
+ };
46
+ },
47
+ });
48
+ }
49
+ /** `Session.open(...)` for tests, from a wiring bag. */
50
+ export async function openTestSession(options = {}) {
51
+ const { sessionId, signal, capabilities, preloadedLog, ...wiring } = options;
52
+ return Session.open({
53
+ ...sessionOptionsFrom(wiring),
54
+ ...(capabilities !== undefined ? { capabilities } : {}),
55
+ ...(preloadedLog !== undefined ? { preloadedLog } : {}),
56
+ ...(sessionId !== undefined ? { sessionId } : {}),
57
+ ...(signal !== undefined ? { signal } : {}),
58
+ });
59
+ }
60
+ /** The session context a capability's `openSession` gets, built from a wiring bag. */
61
+ export function testSessionContext(wiring = {}) {
62
+ const store = wiring.store;
63
+ const environment = wiring.environment !== undefined && typeof wiring.environment !== "function" ? wiring.environment : new NullEnvironment();
64
+ return {
65
+ sessionId: "s",
66
+ environment,
67
+ events: wiring.events ?? new ListenerSink(),
68
+ signal: new AbortController().signal,
69
+ steer: wiring.steer ?? new SteerBus(),
70
+ logRecords: () => readLog(store),
71
+ // No session owns a `durableState` here to snapshot, so persisting is inert.
72
+ persistState: () => Promise.resolve(),
73
+ ...(store !== undefined ? { store } : {}),
74
+ // The same partitioned view a real session hands a capability, owned by "test".
75
+ ...capabilityDataView(store),
76
+ ...(wiring.logger !== undefined ? { logger: wiring.logger } : {}),
77
+ // No Session behind this context, so the controls are inert rather than absent: a capability
78
+ // under test should find the field filled, as it would in a real session.
79
+ controls: {
80
+ abort: () => undefined,
81
+ compact: () => Promise.reject(new Error("no compaction in a test session context")),
82
+ getContextBreakdown: () => undefined,
83
+ setModel: () => undefined,
84
+ setThinking: () => undefined,
85
+ },
86
+ };
87
+ }
88
+ function capabilityDataView(store) {
89
+ const data = new CapabilityData({
90
+ ...(store !== undefined ? { store } : {}),
91
+ readAudit: async () => (store !== undefined ? readAudit(store) : []),
92
+ append: (body) => {
93
+ if (store !== undefined)
94
+ void appendAudit(store, body, DEFAULT_ADDRESS).catch(() => undefined);
95
+ },
96
+ });
97
+ return { state: data.stateFor("test"), records: data.recordsFor("test"), record: data.recorderFor("test") };
98
+ }
99
+ /** @deprecated The provision context is now the whole {@link SessionContext}. */
100
+ export const testProvisionContext = testSessionContext;
101
+ export function testRunContext(wiring = {}) {
102
+ const base = testSessionContext(wiring);
103
+ return {
104
+ sessionId: base.sessionId,
105
+ signal: base.signal,
106
+ injection: new InjectionManager(),
107
+ gates: { compaction: [] },
108
+ controls: {
109
+ abort: () => undefined,
110
+ compact: () => Promise.reject(new Error("no compaction in a test run context")),
111
+ getContextBreakdown: () => undefined,
112
+ setModel: () => undefined,
113
+ setThinking: () => undefined,
114
+ },
115
+ };
116
+ }
117
+ /** Open one capability against a fresh session context — what `Session.open` does for it. */
118
+ export async function provisionCapability(cap, wiring = {}) {
119
+ const ctx = testSessionContext(wiring);
120
+ await cap.openSession?.(ctx);
121
+ return { ctx, service: cap.service, close: async () => await cap.closeSession?.("close") };
122
+ }
123
+ //# sourceMappingURL=testing.js.map
@@ -1,4 +1,4 @@
1
- import type { Machine, RunCommandResult } from "./machine.ts";
1
+ import type { Environment, RunCommandResult } from "./environment.ts";
2
2
  import type { ToolResult } from "./types.ts";
3
3
  /**
4
4
  * Starts ONE command and resolves with how it ended.
@@ -12,7 +12,7 @@ import type { ToolResult } from "./types.ts";
12
12
  export type CommandStarter = (opts: {
13
13
  readonly signal: AbortSignal;
14
14
  /** Live pipe tap for an inline foreground run. File-backed background/attached commands omit
15
- * it because their canonical output is already on the Machine. */
15
+ * it because their canonical output is already on the Environment. */
16
16
  readonly onOutput?: (chunk: string) => void;
17
17
  }) => Promise<RunCommandResult>;
18
18
  export interface QuestionSpawnOptions {
@@ -21,10 +21,10 @@ export interface QuestionSpawnOptions {
21
21
  readonly toolCallId?: string;
22
22
  }
23
23
  export interface ProcessSpawnOptions {
24
- /** The Machine file the process's output is redirected to (its durable work product);
25
- * set together with `machine` so the task can read it back on demand. */
24
+ /** The Environment file the process's output is redirected to (its durable work product);
25
+ * set together with `environment` so the task can read it back on demand. */
26
26
  readonly logPath?: string;
27
- readonly machine?: Machine;
27
+ readonly environment?: Environment;
28
28
  /** Parent conversation line. Namespaces `toolCallId`, which is not globally unique. */
29
29
  readonly parentAddress?: string;
30
30
  /** The tool call that started this command. Carried onto the settle notification so a UI can
@@ -35,7 +35,7 @@ export interface ProcessSpawnOptions {
35
35
  /** Terminal status of an attached run that finished in the foreground (never detached). */
36
36
  export type AttachedSettleStatus = "completed" | "failed" | "timed_out" | "killed";
37
37
  /** Options for {@link BackgroundSpawner.runCommandAttached}. Extends the command spawn
38
- * options (log file / machine) with the foreground-attachment seams. */
38
+ * options (log file / environment) with the foreground-attachment seams. */
39
39
  export interface AttachedRunOptions extends ProcessSpawnOptions {
40
40
  /** The tool call's abort signal. While attached, aborting it KILLS the process
41
41
  * (foreground semantics). Dropped the instant the run detaches. */
@@ -72,6 +72,9 @@ export type AttachedOutcome = {
72
72
  readonly kind: "settled";
73
73
  readonly status: AttachedSettleStatus;
74
74
  readonly exitCode: number | null;
75
+ /** The run was stopped (timeout or abort) but the backend could not confirm the command
76
+ * ended — it may still be running. Absent when the stop was confirmed or never needed. */
77
+ readonly stillRunning?: boolean;
75
78
  } | {
76
79
  readonly kind: "detached";
77
80
  readonly taskId: string;