@myagentroam/agent 0.9.141 → 0.9.143

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 (234) hide show
  1. package/dist/agent-core/host/contracts.d.ts +64 -0
  2. package/dist/{host → agent-core/host}/local-agent-host.d.ts +6 -5
  3. package/dist/{host → agent-core/host}/local-agent-host.js +4 -4
  4. package/dist/{model → agent-core/model}/anthropic-messages.js +24 -13
  5. package/dist/{model → agent-core/model}/contracts.d.ts +6 -16
  6. package/dist/{model → agent-core/model}/openai-responses.js +16 -9
  7. package/dist/agent-core/model/recovery.d.ts +4 -0
  8. package/dist/agent-core/model/recovery.js +71 -0
  9. package/dist/{prompts → agent-core/prompts}/core.d.ts +3 -13
  10. package/dist/{prompts → agent-core/prompts}/index.d.ts +1 -1
  11. package/dist/{prompts → agent-core/prompts}/modes.d.ts +1 -1
  12. package/dist/{prompts → agent-core/prompts}/resources.d.ts +1 -1
  13. package/dist/{runtime/compact.d.ts → agent-core/runtime/compaction/history.d.ts} +2 -23
  14. package/dist/{runtime/compact.js → agent-core/runtime/compaction/history.js} +2 -92
  15. package/dist/agent-core/runtime/compaction/operation.d.ts +22 -0
  16. package/dist/agent-core/runtime/compaction/operation.js +91 -0
  17. package/dist/agent-core/runtime/context/contracts.d.ts +12 -0
  18. package/dist/{runtime/environment-context.d.ts → agent-core/runtime/context/environment.d.ts} +2 -2
  19. package/dist/{runtime/environment-context.js → agent-core/runtime/context/environment.js} +1 -1
  20. package/dist/{runtime/context-gc-runtime.d.ts → agent-core/runtime/context/gc-runtime.d.ts} +4 -4
  21. package/dist/{runtime/context-gc-runtime.js → agent-core/runtime/context/gc-runtime.js} +3 -3
  22. package/dist/{runtime/context-gc-tokens.d.ts → agent-core/runtime/context/gc-tokens.d.ts} +2 -2
  23. package/dist/{runtime/context-gc-tokens.js → agent-core/runtime/context/gc-tokens.js} +7 -5
  24. package/dist/{runtime/context-gc.d.ts → agent-core/runtime/context/gc.d.ts} +3 -3
  25. package/dist/{runtime/context-gc.js → agent-core/runtime/context/gc.js} +152 -19
  26. package/dist/{runtime → agent-core/runtime/context}/instructions.d.ts +1 -1
  27. package/dist/{runtime → agent-core/runtime/context}/instructions.js +1 -1
  28. package/dist/{runtime → agent-core/runtime/context}/normalize.d.ts +1 -1
  29. package/dist/{runtime/context-projection.d.ts → agent-core/runtime/context/projection.d.ts} +3 -3
  30. package/dist/{runtime/context-projection.js → agent-core/runtime/context/projection.js} +35 -4
  31. package/dist/agent-core/runtime/context/request-budget.d.ts +6 -0
  32. package/dist/agent-core/runtime/context/request-budget.js +22 -0
  33. package/dist/agent-core/runtime/context/restore.d.ts +15 -0
  34. package/dist/agent-core/runtime/context/restore.js +85 -0
  35. package/dist/agent-core/runtime/context/usage.d.ts +18 -0
  36. package/dist/agent-core/runtime/context/usage.js +138 -0
  37. package/dist/agent-core/runtime/context/world-state.d.ts +35 -0
  38. package/dist/agent-core/runtime/context/world-state.js +133 -0
  39. package/dist/agent-core/runtime/contracts.d.ts +37 -0
  40. package/dist/agent-core/runtime/event-projection.d.ts +5 -0
  41. package/dist/agent-core/runtime/event-projection.js +17 -0
  42. package/dist/agent-core/runtime/events.d.ts +143 -0
  43. package/dist/agent-core/runtime/execution.d.ts +50 -0
  44. package/dist/agent-core/runtime/execution.js +397 -0
  45. package/dist/{runtime → agent-core/runtime}/rollout-budget.d.ts +1 -1
  46. package/dist/agent-core/sdk/agent.js +209 -0
  47. package/dist/agent-core/sdk/model-runtime.d.ts +13 -0
  48. package/dist/agent-core/sdk/model-runtime.js +63 -0
  49. package/dist/agent-core/sdk/session-title.d.ts +3 -0
  50. package/dist/agent-core/sdk/session-title.js +42 -0
  51. package/dist/agent-core/sdk/session.d.ts +62 -0
  52. package/dist/agent-core/sdk/session.js +1147 -0
  53. package/dist/agent-core/sdk/subagent-backend.d.ts +3 -0
  54. package/dist/agent-core/sdk/subagent-backend.js +46 -0
  55. package/dist/agent-core/sdk/types.d.ts +56 -0
  56. package/dist/{session → agent-core/session}/catalog.d.ts +2 -1
  57. package/dist/{session → agent-core/session}/context-gc-checkpoint.d.ts +3 -0
  58. package/dist/{session → agent-core/session}/context-gc-checkpoint.js +122 -23
  59. package/dist/agent-core/session/context-gc-observations.d.ts +38 -0
  60. package/dist/agent-core/session/context-gc-observations.js +150 -0
  61. package/dist/{session → agent-core/session}/context-gc-replacements.d.ts +1 -1
  62. package/dist/{session → agent-core/session}/context-gc-replacements.js +6 -2
  63. package/dist/{session → agent-core/session}/jsonl-store.d.ts +2 -2
  64. package/dist/{session → agent-core/session}/jsonl-store.js +1 -1
  65. package/dist/agent-core/subagent/contracts.d.ts +91 -0
  66. package/dist/agent-core/subagent/contracts.js +1 -0
  67. package/dist/agent-core/subagent/scheduler.d.ts +117 -0
  68. package/dist/{subagent → agent-core/subagent}/session-controller.d.ts +3 -2
  69. package/dist/agent-core/tools/agent/agent-cancel.d.ts +7 -0
  70. package/dist/{tools → agent-core/tools/agent}/agent-cancel.js +1 -1
  71. package/dist/agent-core/tools/agent/agent-message.d.ts +7 -0
  72. package/dist/{tools → agent-core/tools/agent}/agent-message.js +2 -2
  73. package/dist/{tools → agent-core/tools/agent}/agent-start.d.ts +3 -3
  74. package/dist/{tools → agent-core/tools/agent}/agent-start.js +3 -3
  75. package/dist/agent-core/tools/agent/agent-wait.d.ts +7 -0
  76. package/dist/{tools → agent-core/tools/agent}/agent-wait.js +2 -2
  77. package/dist/{tools → agent-core/tools/agent}/question.d.ts +2 -2
  78. package/dist/{tools → agent-core/tools/agent}/question.js +2 -2
  79. package/dist/{tools → agent-core/tools/agent}/skill.d.ts +2 -2
  80. package/dist/{tools → agent-core/tools/agent}/skill.js +2 -2
  81. package/dist/{tools → agent-core/tools/agent}/todo-read.d.ts +2 -2
  82. package/dist/{tools → agent-core/tools/agent}/todo-write.d.ts +2 -2
  83. package/dist/{tools → agent-core/tools/agent}/todo-write.js +2 -2
  84. package/dist/{tools → agent-core/tools/agent}/todo.d.ts +2 -9
  85. package/dist/{tools → agent-core/tools/agent}/todo.js +1 -1
  86. package/dist/{tools → agent-core/tools}/code-mode/cells.d.ts +4 -1
  87. package/dist/{tools → agent-core/tools}/code-mode/cells.js +60 -6
  88. package/dist/{tools → agent-core/tools}/code-mode/dispatch.d.ts +2 -4
  89. package/dist/{tools → agent-core/tools}/code-mode/dispatch.js +10 -6
  90. package/dist/{tools → agent-core/tools}/code-mode/engine.d.ts +13 -1
  91. package/dist/agent-core/tools/code-mode/engine.js +1 -0
  92. package/dist/{tools/code-mode.d.ts → agent-core/tools/code-mode/index.d.ts} +7 -7
  93. package/dist/{tools/code-mode.js → agent-core/tools/code-mode/index.js} +190 -28
  94. package/dist/agent-core/tools/code-mode/observations.d.ts +103 -0
  95. package/dist/agent-core/tools/code-mode/observations.js +195 -0
  96. package/dist/{tools → agent-core/tools}/code-mode/quickjs-engine.js +91 -17
  97. package/dist/{tools → agent-core/tools}/code-mode/state.d.ts +2 -13
  98. package/dist/agent-core/tools/code-mode/worker.d.ts +1 -0
  99. package/dist/{tools → agent-core/tools}/code-mode/worker.js +8 -1
  100. package/dist/agent-core/tools/contracts.d.ts +172 -0
  101. package/dist/agent-core/tools/contracts.js +1 -0
  102. package/dist/agent-core/tools/execution.d.ts +36 -0
  103. package/dist/agent-core/tools/execution.js +111 -0
  104. package/dist/agent-core/tools/local/apply-patch.d.ts +19 -0
  105. package/dist/{tools → agent-core/tools/local}/apply-patch.js +8 -2
  106. package/dist/{tools → agent-core/tools/local}/exec.d.ts +5 -17
  107. package/dist/{tools → agent-core/tools/local}/exec.js +4 -4
  108. package/dist/{tools → agent-core/tools/local}/read.d.ts +7 -15
  109. package/dist/{tools → agent-core/tools/local}/read.js +185 -2
  110. package/dist/{tools/local-registry.d.ts → agent-core/tools/local/registry.d.ts} +5 -5
  111. package/dist/agent-core/tools/local/registry.js +101 -0
  112. package/dist/{tools → agent-core/tools/local}/view-image.d.ts +4 -9
  113. package/dist/{tools → agent-core/tools/local}/view-image.js +2 -2
  114. package/dist/agent-core/tools/local/web-fetch.d.ts +4 -0
  115. package/dist/agent-core/tools/local/web-fetch.js +85 -0
  116. package/dist/agent-core/tools/local/web-search.d.ts +7 -0
  117. package/dist/agent-core/tools/local/web-search.js +34 -0
  118. package/dist/{tools/local-workspace-tools.js → agent-core/tools/local/workspace-tools.js} +1 -1
  119. package/dist/{sdk/mcp-catalog.d.ts → agent-core/tools/mcp/catalog.d.ts} +1 -2
  120. package/dist/{sdk/mcp-catalog.js → agent-core/tools/mcp/catalog.js} +1 -1
  121. package/dist/agent-core/tools/mcp/history.d.ts +4 -0
  122. package/dist/agent-core/tools/mcp/history.js +33 -0
  123. package/dist/{tools → agent-core/tools/mcp}/tool-search.d.ts +3 -3
  124. package/dist/{tools → agent-core/tools/mcp}/tool-search.js +4 -4
  125. package/dist/agent-core/tools/output-projection.d.ts +14 -0
  126. package/dist/agent-core/tools/output-projection.js +223 -0
  127. package/dist/{tools → agent-core/tools}/registry.d.ts +1 -1
  128. package/dist/agent-core/tools/registry.js +47 -0
  129. package/dist/{tools → agent-core/tools}/runtime-context.d.ts +8 -7
  130. package/dist/agent-core/tools/runtime-context.js +1 -0
  131. package/dist/{tools → agent-core/tools}/runtime.d.ts +1 -1
  132. package/dist/cli/codex-auth-file.d.ts +1 -1
  133. package/dist/cli/codex-auth-file.js +2 -2
  134. package/dist/cli/main.js +9 -9
  135. package/dist/index.d.ts +17 -15
  136. package/dist/index.js +8 -8
  137. package/dist/sandbox/linux/bubblewrap-sandbox-executor.d.ts +1 -1
  138. package/dist/sandbox/linux/bubblewrap-sandbox-executor.js +1 -1
  139. package/package.json +3 -3
  140. package/dist/host/contracts.d.ts +0 -21
  141. package/dist/sdk/agent.js +0 -2548
  142. package/dist/sdk/types.d.ts +0 -349
  143. package/dist/subagent/scheduler.d.ts +0 -206
  144. package/dist/tools/agent-cancel.d.ts +0 -7
  145. package/dist/tools/agent-message.d.ts +0 -7
  146. package/dist/tools/agent-wait.d.ts +0 -7
  147. package/dist/tools/apply-patch.d.ts +0 -32
  148. package/dist/tools/local-registry.js +0 -373
  149. package/dist/tools/registry.js +0 -47
  150. package/dist/tools/web-fetch.d.ts +0 -2
  151. package/dist/tools/web-fetch.js +0 -12
  152. package/dist/tools/web-search.d.ts +0 -2
  153. package/dist/tools/web-search.js +0 -15
  154. /package/dist/{error.d.ts → agent-core/error.d.ts} +0 -0
  155. /package/dist/{error.js → agent-core/error.js} +0 -0
  156. /package/dist/{host → agent-core/host}/contracts.js +0 -0
  157. /package/dist/{host → agent-core/host}/local-process-executor.d.ts +0 -0
  158. /package/dist/{host → agent-core/host}/local-process-executor.js +0 -0
  159. /package/dist/{host → agent-core/host}/network.d.ts +0 -0
  160. /package/dist/{host → agent-core/host}/network.js +0 -0
  161. /package/dist/{model → agent-core/model}/anthropic-messages.d.ts +0 -0
  162. /package/dist/{model → agent-core/model}/anthropic-thinking.d.ts +0 -0
  163. /package/dist/{model → agent-core/model}/anthropic-thinking.js +0 -0
  164. /package/dist/{model → agent-core/model}/catalog-file.d.ts +0 -0
  165. /package/dist/{model → agent-core/model}/catalog-file.js +0 -0
  166. /package/dist/{model → agent-core/model}/configuration.d.ts +0 -0
  167. /package/dist/{model → agent-core/model}/configuration.js +0 -0
  168. /package/dist/{model → agent-core/model}/contracts.js +0 -0
  169. /package/dist/{model → agent-core/model}/http.d.ts +0 -0
  170. /package/dist/{model → agent-core/model}/http.js +0 -0
  171. /package/dist/{model → agent-core/model}/openai-responses.d.ts +0 -0
  172. /package/dist/{model → agent-core/model}/runtime-credential.d.ts +0 -0
  173. /package/dist/{model → agent-core/model}/runtime-credential.js +0 -0
  174. /package/dist/{model → agent-core/model}/sse.d.ts +0 -0
  175. /package/dist/{model → agent-core/model}/sse.js +0 -0
  176. /package/dist/{model → agent-core/model}/transport-test.d.ts +0 -0
  177. /package/dist/{model → agent-core/model}/transport-test.js +0 -0
  178. /package/dist/{prompts → agent-core/prompts}/compact.d.ts +0 -0
  179. /package/dist/{prompts → agent-core/prompts}/compact.js +0 -0
  180. /package/dist/{prompts → agent-core/prompts}/core.js +0 -0
  181. /package/dist/{prompts → agent-core/prompts}/execution-budget.d.ts +0 -0
  182. /package/dist/{prompts → agent-core/prompts}/execution-budget.js +0 -0
  183. /package/dist/{prompts → agent-core/prompts}/index.js +0 -0
  184. /package/dist/{prompts → agent-core/prompts}/modes.js +0 -0
  185. /package/dist/{prompts → agent-core/prompts}/output.d.ts +0 -0
  186. /package/dist/{prompts → agent-core/prompts}/output.js +0 -0
  187. /package/dist/{prompts → agent-core/prompts}/resources.js +0 -0
  188. /package/dist/{prompts → agent-core/prompts}/subagent.d.ts +0 -0
  189. /package/dist/{prompts → agent-core/prompts}/subagent.js +0 -0
  190. /package/dist/{prompts → agent-core/prompts}/title.d.ts +0 -0
  191. /package/dist/{prompts → agent-core/prompts}/title.js +0 -0
  192. /package/dist/{prompts → agent-core/prompts}/workflow.d.ts +0 -0
  193. /package/dist/{prompts → agent-core/prompts}/workflow.js +0 -0
  194. /package/dist/{runtime → agent-core/runtime}/async-queue.d.ts +0 -0
  195. /package/dist/{runtime → agent-core/runtime}/async-queue.js +0 -0
  196. /package/dist/{sdk/types.js → agent-core/runtime/context/contracts.js} +0 -0
  197. /package/dist/{runtime → agent-core/runtime/context}/normalize.js +0 -0
  198. /package/dist/{session/types.js → agent-core/runtime/contracts.js} +0 -0
  199. /package/dist/{tools/code-mode/engine.js → agent-core/runtime/events.js} +0 -0
  200. /package/dist/{runtime → agent-core/runtime}/execution-policy.d.ts +0 -0
  201. /package/dist/{runtime → agent-core/runtime}/execution-policy.js +0 -0
  202. /package/dist/{runtime → agent-core/runtime}/plan-output.d.ts +0 -0
  203. /package/dist/{runtime → agent-core/runtime}/plan-output.js +0 -0
  204. /package/dist/{runtime → agent-core/runtime}/rollout-budget.js +0 -0
  205. /package/dist/{runtime → agent-core/runtime}/token-budget.d.ts +0 -0
  206. /package/dist/{runtime → agent-core/runtime}/token-budget.js +0 -0
  207. /package/dist/{sdk → agent-core/sdk}/agent.d.ts +0 -0
  208. /package/dist/{tools/code-mode/worker.d.ts → agent-core/sdk/types.js} +0 -0
  209. /package/dist/{session → agent-core/session}/catalog.js +0 -0
  210. /package/dist/{session → agent-core/session}/context-gc-subagent.d.ts +0 -0
  211. /package/dist/{session → agent-core/session}/context-gc-subagent.js +0 -0
  212. /package/dist/{session → agent-core/session}/transaction-recovery.d.ts +0 -0
  213. /package/dist/{session → agent-core/session}/transaction-recovery.js +0 -0
  214. /package/dist/{session → agent-core/session}/types.d.ts +0 -0
  215. /package/dist/{tools/runtime-context.js → agent-core/session/types.js} +0 -0
  216. /package/dist/{subagent → agent-core/subagent}/scheduler.js +0 -0
  217. /package/dist/{subagent → agent-core/subagent}/session-controller.js +0 -0
  218. /package/dist/{tools → agent-core/tools/agent}/todo-read.js +0 -0
  219. /package/dist/{tools → agent-core/tools}/callers.d.ts +0 -0
  220. /package/dist/{tools → agent-core/tools}/callers.js +0 -0
  221. /package/dist/{tools → agent-core/tools}/code-mode/quickjs-engine.d.ts +0 -0
  222. /package/dist/{tools → agent-core/tools}/code-mode/state.js +0 -0
  223. /package/dist/{tools → agent-core/tools}/code-mode/text-output.d.ts +0 -0
  224. /package/dist/{tools → agent-core/tools}/code-mode/text-output.js +0 -0
  225. /package/dist/{tools → agent-core/tools}/execution-limits.d.ts +0 -0
  226. /package/dist/{tools → agent-core/tools}/execution-limits.js +0 -0
  227. /package/dist/{tools → agent-core/tools/local}/read-context.d.ts +0 -0
  228. /package/dist/{tools → agent-core/tools/local}/read-context.js +0 -0
  229. /package/dist/{tools/local-workspace-tools.d.ts → agent-core/tools/local/workspace-tools.d.ts} +0 -0
  230. /package/dist/{tools → agent-core/tools}/runtime.js +0 -0
  231. /package/dist/{tools → agent-core/tools}/scheduler.d.ts +0 -0
  232. /package/dist/{tools → agent-core/tools}/scheduler.js +0 -0
  233. /package/dist/{tools → agent-core/tools}/shared/path-resolver.d.ts +0 -0
  234. /package/dist/{tools → agent-core/tools}/shared/path-resolver.js +0 -0
@@ -1,7 +1,7 @@
1
1
  import type { ModelUsage } from '../model/contracts.js';
2
- import type { EnvironmentContextState } from '../prompts/core.js';
2
+ import type { EnvironmentContextState } from '../runtime/context/contracts.js';
3
3
  import { type CodeModeStateEntry } from '../tools/code-mode/state.js';
4
- import { type TodoSnapshot } from '../tools/todo.js';
4
+ import { type TodoSnapshot } from '../tools/agent/todo.js';
5
5
  import { type ContextGcCheckpointDraft } from './context-gc-checkpoint.js';
6
6
  import type { SessionListInput, SessionSource } from './types.js';
7
7
  export type { SessionListInput, SessionSource } from './types.js';
@@ -6,7 +6,7 @@ import { setTimeout as delay } from 'node:timers/promises';
6
6
  import { isDeepStrictEqual } from 'node:util';
7
7
  import { MarAgentError } from '../error.js';
8
8
  import { applyCodeModeStateMutations, parseCodeModeStateMutations, restoreCodeModeState } from '../tools/code-mode/state.js';
9
- import { todoItemsFromSnapshot } from '../tools/todo.js';
9
+ import { todoItemsFromSnapshot } from '../tools/agent/todo.js';
10
10
  import { contextGcBaseFromRecords, contextGcBaseSequence, contextGcMinimumUsageGrowth, contextGcSourceProjectionHash, latestValidContextGcCheckpoint, normalizeContextGcReplacements, parseContextGcCheckpoint, sameContextGcBase, validateContextGcCheckpoint } from './context-gc-checkpoint.js';
11
11
  import { beginSessionStorageTransaction, isUnjournaledTransactionFile, recoverSessionStorageTransaction } from './transaction-recovery.js';
12
12
  const MAX_SEGMENT_BYTES = 16 * 1024 * 1024;
@@ -0,0 +1,91 @@
1
+ import type { MarAgentReasoningEffort } from '../model/configuration.js';
2
+ export interface SubagentTaskInput {
3
+ description: string;
4
+ prompt: string;
5
+ role: 'general-purpose' | 'explore';
6
+ modelId?: string;
7
+ reasoningEffort?: MarAgentReasoningEffort;
8
+ background?: boolean;
9
+ parentSubagentId?: string;
10
+ }
11
+ export interface SubagentTaskResult {
12
+ summary: string;
13
+ changedFiles: string[];
14
+ verification: string[];
15
+ evidence: Array<{
16
+ path: string;
17
+ startLine?: number;
18
+ endLine?: number;
19
+ }>;
20
+ }
21
+ export interface SubagentLatestMessage {
22
+ itemId: string;
23
+ turnId: string;
24
+ phase: 'commentary' | 'final_answer';
25
+ text: string;
26
+ timestamp: string;
27
+ truncated: boolean;
28
+ }
29
+ export type SubagentLatestActivity = {
30
+ kind: 'message';
31
+ timestamp: string;
32
+ phase: 'commentary' | 'final_answer';
33
+ } | {
34
+ kind: 'tool';
35
+ timestamp: string;
36
+ toolName: string;
37
+ status: 'started' | 'completed' | 'failed';
38
+ };
39
+ export interface SubagentTaskSnapshot extends Record<string, unknown> {
40
+ agentId: string;
41
+ description: string;
42
+ status: 'queued' | 'running' | 'completed' | 'failed' | 'cancelled' | 'interrupted';
43
+ modelId?: string;
44
+ modelName?: string;
45
+ reasoningEffort?: MarAgentReasoningEffort;
46
+ latestMessage?: SubagentLatestMessage;
47
+ latestActivity?: SubagentLatestActivity;
48
+ summary?: string;
49
+ changedFiles?: string[];
50
+ verification?: string[];
51
+ evidence?: Array<{
52
+ path: string;
53
+ startLine?: number;
54
+ endLine?: number;
55
+ }>;
56
+ errorCode?: string;
57
+ errorMessage?: string;
58
+ messageId?: string;
59
+ turnId?: string;
60
+ deliveryStatus?: 'accepted' | 'applied' | 'cancelled' | 'failed';
61
+ waitOutcome?: SubagentWaitOutcome;
62
+ }
63
+ export type SubagentWaitFor = 'completion' | 'message';
64
+ export type SubagentWaitOutcome = 'snapshot' | 'message' | 'completion' | 'timeout';
65
+ export interface SubagentMessageOptions {
66
+ delivery?: 'append' | 'replace';
67
+ signal?: AbortSignal;
68
+ }
69
+ export interface SubagentRunOptions {
70
+ signal?: AbortSignal;
71
+ onCreated?: (task: SubagentTaskSnapshot) => Promise<void> | void;
72
+ }
73
+ export interface SubagentOutputOptions {
74
+ waitMs?: number;
75
+ waitFor?: SubagentWaitFor;
76
+ signal?: AbortSignal;
77
+ }
78
+ export interface SubagentController {
79
+ beginExecution?(runner: (task: SubagentTaskInput, signal: AbortSignal) => Promise<SubagentTaskResult>): void;
80
+ run(input: SubagentTaskInput, options?: SubagentRunOptions): Promise<SubagentTaskSnapshot>;
81
+ output(agentId: string, options?: SubagentOutputOptions): Promise<SubagentTaskSnapshot>;
82
+ outputAny(options?: SubagentOutputOptions): Promise<SubagentTaskSnapshot>;
83
+ message(agentId: string, message: string, options?: SubagentMessageOptions): Promise<SubagentTaskSnapshot>;
84
+ cancel(agentId: string): Promise<SubagentTaskSnapshot>;
85
+ listSessionResources(): readonly {
86
+ agentId: string;
87
+ status: SubagentTaskSnapshot['status'];
88
+ description: string;
89
+ }[];
90
+ dispose(): Promise<void>;
91
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,117 @@
1
+ import type { SubagentController, SubagentOutputOptions, SubagentRunOptions, SubagentTaskInput, SubagentTaskResult, SubagentTaskSnapshot } from './contracts.js';
2
+ export type { SubagentController, SubagentLatestActivity, SubagentLatestMessage, SubagentMessageOptions, SubagentOutputOptions, SubagentRunOptions, SubagentTaskInput, SubagentTaskResult, SubagentTaskSnapshot, SubagentWaitFor, SubagentWaitOutcome } from './contracts.js';
3
+ export declare class SubagentScheduler implements SubagentController {
4
+ #private;
5
+ readonly limits: {
6
+ maxTasks: number;
7
+ maxConcurrent: number;
8
+ };
9
+ constructor(runner: (task: SubagentTaskInput, signal: AbortSignal) => Promise<SubagentTaskResult>, limits?: {
10
+ maxTasks: number;
11
+ maxConcurrent: number;
12
+ });
13
+ beginExecution(runner: (task: SubagentTaskInput, signal: AbortSignal) => Promise<SubagentTaskResult>): void;
14
+ run(input: SubagentTaskInput, options?: SubagentRunOptions): Promise<SubagentTaskSnapshot>;
15
+ output(agentId: string, options?: SubagentOutputOptions): Promise<{
16
+ waitOutcome: "snapshot";
17
+ agentId: string;
18
+ description: string;
19
+ status: "queued" | "running" | "completed" | "failed" | "cancelled" | "interrupted";
20
+ modelId?: string;
21
+ modelName?: string;
22
+ reasoningEffort?: import("../model/configuration.js").MarAgentReasoningEffort;
23
+ latestMessage?: import("./contracts.js").SubagentLatestMessage;
24
+ latestActivity?: import("./contracts.js").SubagentLatestActivity;
25
+ summary?: string;
26
+ changedFiles?: string[];
27
+ verification?: string[];
28
+ evidence?: Array<{
29
+ path: string;
30
+ startLine?: number;
31
+ endLine?: number;
32
+ }>;
33
+ errorCode?: string;
34
+ errorMessage?: string;
35
+ messageId?: string;
36
+ turnId?: string;
37
+ deliveryStatus?: "accepted" | "applied" | "cancelled" | "failed";
38
+ } | {
39
+ waitOutcome: "completion" | "timeout";
40
+ agentId: string;
41
+ description: string;
42
+ status: "queued" | "running" | "completed" | "failed" | "cancelled" | "interrupted";
43
+ modelId?: string;
44
+ modelName?: string;
45
+ reasoningEffort?: import("../model/configuration.js").MarAgentReasoningEffort;
46
+ latestMessage?: import("./contracts.js").SubagentLatestMessage;
47
+ latestActivity?: import("./contracts.js").SubagentLatestActivity;
48
+ summary?: string;
49
+ changedFiles?: string[];
50
+ verification?: string[];
51
+ evidence?: Array<{
52
+ path: string;
53
+ startLine?: number;
54
+ endLine?: number;
55
+ }>;
56
+ errorCode?: string;
57
+ errorMessage?: string;
58
+ messageId?: string;
59
+ turnId?: string;
60
+ deliveryStatus?: "accepted" | "applied" | "cancelled" | "failed";
61
+ }>;
62
+ outputAny(options?: SubagentOutputOptions): Promise<{
63
+ waitOutcome: "snapshot";
64
+ agentId: string;
65
+ description: string;
66
+ status: "queued" | "running" | "completed" | "failed" | "cancelled" | "interrupted";
67
+ modelId?: string;
68
+ modelName?: string;
69
+ reasoningEffort?: import("../model/configuration.js").MarAgentReasoningEffort;
70
+ latestMessage?: import("./contracts.js").SubagentLatestMessage;
71
+ latestActivity?: import("./contracts.js").SubagentLatestActivity;
72
+ summary?: string;
73
+ changedFiles?: string[];
74
+ verification?: string[];
75
+ evidence?: Array<{
76
+ path: string;
77
+ startLine?: number;
78
+ endLine?: number;
79
+ }>;
80
+ errorCode?: string;
81
+ errorMessage?: string;
82
+ messageId?: string;
83
+ turnId?: string;
84
+ deliveryStatus?: "accepted" | "applied" | "cancelled" | "failed";
85
+ } | {
86
+ waitOutcome: "completion" | "timeout";
87
+ agentId: string;
88
+ description: string;
89
+ status: "queued" | "running" | "completed" | "failed" | "cancelled" | "interrupted";
90
+ modelId?: string;
91
+ modelName?: string;
92
+ reasoningEffort?: import("../model/configuration.js").MarAgentReasoningEffort;
93
+ latestMessage?: import("./contracts.js").SubagentLatestMessage;
94
+ latestActivity?: import("./contracts.js").SubagentLatestActivity;
95
+ summary?: string;
96
+ changedFiles?: string[];
97
+ verification?: string[];
98
+ evidence?: Array<{
99
+ path: string;
100
+ startLine?: number;
101
+ endLine?: number;
102
+ }>;
103
+ errorCode?: string;
104
+ errorMessage?: string;
105
+ messageId?: string;
106
+ turnId?: string;
107
+ deliveryStatus?: "accepted" | "applied" | "cancelled" | "failed";
108
+ }>;
109
+ cancel(agentId: string): Promise<SubagentTaskSnapshot>;
110
+ message(_agentId: string, _message: string): Promise<SubagentTaskSnapshot>;
111
+ listSessionResources(): {
112
+ agentId: string;
113
+ status: "completed" | "failed" | "cancelled" | "running" | "queued";
114
+ description: string;
115
+ }[];
116
+ dispose(): Promise<void>;
117
+ }
@@ -1,5 +1,6 @@
1
1
  import type { MarAgentReasoningEffort } from '../model/configuration.js';
2
- import type { MarAgentEvent, ExecutionResult } from '../sdk/types.js';
2
+ import type { ExecutionResult } from '../runtime/contracts.js';
3
+ import type { MarAgentEvent } from '../runtime/events.js';
3
4
  import type { SessionRecord, SessionSource } from '../session/jsonl-store.js';
4
5
  import type { SubagentController, SubagentMessageOptions, SubagentOutputOptions, SubagentRunOptions, SubagentTaskInput, SubagentTaskSnapshot } from './scheduler.js';
5
6
  export interface SubagentModelOption {
@@ -93,7 +94,7 @@ export declare class SubagentSessionController implements SubagentController {
93
94
  cancel(agentId: string): Promise<SubagentTaskSnapshot>;
94
95
  listSessionResources(): {
95
96
  agentId: string;
96
- status: "completed" | "cancelled" | "running" | "queued" | "failed" | "interrupted";
97
+ status: "completed" | "failed" | "cancelled" | "running" | "queued" | "interrupted";
97
98
  description: string;
98
99
  }[];
99
100
  dispose(): Promise<void>;
@@ -0,0 +1,7 @@
1
+ import type { ClientToolDefinition } from '../../model/contracts.js';
2
+ import type { ToolRuntimeContext } from '../runtime-context.js';
3
+ export declare const agentCancelToolDefinition: ClientToolDefinition;
4
+ export declare function executeAgentCancel(arguments_: unknown, context: ToolRuntimeContext): Promise<{
5
+ content: string;
6
+ data: import("../../subagent/contracts.js").SubagentTaskSnapshot;
7
+ }>;
@@ -1,4 +1,4 @@
1
- import { MarAgentError } from '../error.js';
1
+ import { MarAgentError } from '../../error.js';
2
2
  export const agentCancelToolDefinition = {
3
3
  name: 'agent_cancel',
4
4
  allowedCallers: ['direct', 'programmatic'],
@@ -0,0 +1,7 @@
1
+ import type { ClientToolDefinition } from '../../model/contracts.js';
2
+ import type { ToolRuntimeContext } from '../runtime-context.js';
3
+ export declare const agentMessageToolDefinition: ClientToolDefinition;
4
+ export declare function executeAgentMessage(arguments_: unknown, context: ToolRuntimeContext): Promise<{
5
+ content: string;
6
+ data: import("../../subagent/contracts.js").SubagentTaskSnapshot;
7
+ }>;
@@ -1,5 +1,5 @@
1
- import { MarAgentError } from '../error.js';
2
- import { TOOL_EXECUTION_LIMITS } from './execution-limits.js';
1
+ import { MarAgentError } from '../../error.js';
2
+ import { TOOL_EXECUTION_LIMITS } from '../execution-limits.js';
3
3
  export const agentMessageToolDefinition = {
4
4
  name: 'agent_message',
5
5
  allowedCallers: ['direct', 'programmatic'],
@@ -1,5 +1,5 @@
1
- import type { ClientToolDefinition } from '../model/contracts.js';
2
- import type { ToolRuntimeContext } from './runtime-context.js';
1
+ import type { ClientToolDefinition } from '../../model/contracts.js';
2
+ import type { ToolRuntimeContext } from '../runtime-context.js';
3
3
  export declare const agentStartToolDefinition: ClientToolDefinition;
4
4
  export declare function agentStartToolDefinitionWithModels(models: readonly {
5
5
  readonly id: string;
@@ -8,5 +8,5 @@ export declare function agentStartToolDefinitionWithModels(models: readonly {
8
8
  }[]): ClientToolDefinition;
9
9
  export declare function executeAgentStart(arguments_: unknown, context: ToolRuntimeContext): Promise<{
10
10
  content: string;
11
- data: import("../subagent/scheduler.js").SubagentTaskSnapshot;
11
+ data: import("../../subagent/contracts.js").SubagentTaskSnapshot;
12
12
  }>;
@@ -1,6 +1,6 @@
1
- import { MarAgentError } from '../error.js';
2
- import { marAgentReasoningEffortSchema } from '../model/configuration.js';
3
- import { TOOL_EXECUTION_LIMITS } from './execution-limits.js';
1
+ import { MarAgentError } from '../../error.js';
2
+ import { marAgentReasoningEffortSchema } from '../../model/configuration.js';
3
+ import { TOOL_EXECUTION_LIMITS } from '../execution-limits.js';
4
4
  export const agentStartToolDefinition = {
5
5
  name: 'agent_start',
6
6
  allowedCallers: ['direct', 'programmatic'],
@@ -0,0 +1,7 @@
1
+ import type { ClientToolDefinition } from '../../model/contracts.js';
2
+ import type { ToolRuntimeContext } from '../runtime-context.js';
3
+ export declare const agentWaitToolDefinition: ClientToolDefinition;
4
+ export declare function executeAgentWait(arguments_: unknown, context: ToolRuntimeContext): Promise<{
5
+ content: string;
6
+ data: import("../../subagent/contracts.js").SubagentTaskSnapshot;
7
+ }>;
@@ -1,5 +1,5 @@
1
- import { MarAgentError } from '../error.js';
2
- import { TOOL_EXECUTION_LIMITS } from './execution-limits.js';
1
+ import { MarAgentError } from '../../error.js';
2
+ import { TOOL_EXECUTION_LIMITS } from '../execution-limits.js';
3
3
  export const agentWaitToolDefinition = {
4
4
  name: 'agent_wait',
5
5
  allowedCallers: ['direct', 'programmatic'],
@@ -1,5 +1,5 @@
1
- import type { ClientToolDefinition } from '../model/contracts.js';
2
- import type { ToolRuntimeContext } from './runtime-context.js';
1
+ import type { ClientToolDefinition } from '../../model/contracts.js';
2
+ import type { ToolRuntimeContext } from '../runtime-context.js';
3
3
  export declare const questionToolDefinition: ClientToolDefinition;
4
4
  export declare function executeQuestion(arguments_: unknown, context: ToolRuntimeContext): Promise<{
5
5
  content: string;
@@ -1,6 +1,6 @@
1
1
  import { randomUUID } from 'node:crypto';
2
- import { MarAgentError } from '../error.js';
3
- import { TOOL_EXECUTION_LIMITS } from './execution-limits.js';
2
+ import { MarAgentError } from '../../error.js';
3
+ import { TOOL_EXECUTION_LIMITS } from '../execution-limits.js';
4
4
  export const questionToolDefinition = {
5
5
  name: 'question',
6
6
  allowedCallers: ['direct'],
@@ -1,5 +1,5 @@
1
- import type { ClientToolDefinition } from '../model/contracts.js';
2
- import type { ToolRuntimeContext } from './runtime-context.js';
1
+ import type { ClientToolDefinition } from '../../model/contracts.js';
2
+ import type { ToolRuntimeContext } from '../runtime-context.js';
3
3
  export declare const skillToolDefinition: ClientToolDefinition;
4
4
  export declare function executeSkill(arguments_: unknown, context: ToolRuntimeContext): Promise<{
5
5
  content: string;
@@ -1,5 +1,5 @@
1
- import { MarAgentError } from '../error.js';
2
- import { agentSkillSource, loadAgentSkill } from '../runtime/instructions.js';
1
+ import { MarAgentError } from '../../error.js';
2
+ import { agentSkillSource, loadAgentSkill } from '../../runtime/context/instructions.js';
3
3
  export const skillToolDefinition = {
4
4
  name: 'skill',
5
5
  allowedCallers: ['direct'],
@@ -1,5 +1,5 @@
1
- import type { ClientToolDefinition } from '../model/contracts.js';
2
- import type { ToolRuntimeContext } from './runtime-context.js';
1
+ import type { ClientToolDefinition } from '../../model/contracts.js';
2
+ import type { ToolRuntimeContext } from '../runtime-context.js';
3
3
  export declare const todoReadToolDefinition: ClientToolDefinition;
4
4
  export declare function executeTodoRead(context: ToolRuntimeContext): Promise<{
5
5
  content: string;
@@ -1,5 +1,5 @@
1
- import type { ClientToolDefinition } from '../model/contracts.js';
2
- import type { ToolRuntimeContext } from './runtime-context.js';
1
+ import type { ClientToolDefinition } from '../../model/contracts.js';
2
+ import type { ToolRuntimeContext } from '../runtime-context.js';
3
3
  export declare const todoWriteToolDefinition: ClientToolDefinition;
4
4
  export declare function executeTodoWrite(arguments_: unknown, context: ToolRuntimeContext): Promise<{
5
5
  content: string;
@@ -1,5 +1,5 @@
1
- import { MarAgentError } from '../error.js';
2
- import { TOOL_EXECUTION_LIMITS } from './execution-limits.js';
1
+ import { MarAgentError } from '../../error.js';
2
+ import { TOOL_EXECUTION_LIMITS } from '../execution-limits.js';
3
3
  export const todoWriteToolDefinition = {
4
4
  name: 'todo_write',
5
5
  allowedCallers: ['direct', 'programmatic'],
@@ -1,12 +1,5 @@
1
- export interface TodoItem {
2
- id: string;
3
- step: string;
4
- status: 'pending' | 'in_progress' | 'completed';
5
- }
6
- export interface TodoSnapshot {
7
- revision: number;
8
- items: TodoItem[];
9
- }
1
+ import type { TodoItem, TodoSnapshot } from '../contracts.js';
2
+ export type { TodoItem, TodoSnapshot } from '../contracts.js';
10
3
  export declare class TodoStore {
11
4
  #private;
12
5
  static restore(snapshot: TodoSnapshot): TodoStore;
@@ -1,4 +1,4 @@
1
- import { MarAgentError } from '../error.js';
1
+ import { MarAgentError } from '../../error.js';
2
2
  export class TodoStore {
3
3
  #revision = 0;
4
4
  #items = [];
@@ -1,6 +1,9 @@
1
1
  import { MarAgentError } from '../../error.js';
2
- import type { ToolExecutionContext, ToolExecutionResult } from '../../sdk/types.js';
2
+ import type { ToolExecutionContext, ToolExecutionResult } from '../contracts.js';
3
+ import { type CodeObservation } from './observations.js';
3
4
  export interface CellOutput {
5
+ call(value: import('./observations.js').CodeToolCallRecord): void;
6
+ observe(value: CodeObservation): void;
4
7
  text(value: string, originalBytes?: number): void;
5
8
  image(value: NonNullable<ToolExecutionResult['images']>[number]): void;
6
9
  yield(): void;
@@ -1,8 +1,9 @@
1
1
  import { randomUUID } from 'node:crypto';
2
2
  import { MarAgentError, describeMarAgentError } from '../../error.js';
3
- import { TOOL_EXECUTION_LIMITS as limits } from '../execution-limits.js';
4
3
  import { truncateModelText } from '../../runtime/token-budget.js';
4
+ import { TOOL_EXECUTION_LIMITS as limits } from '../execution-limits.js';
5
5
  import { BoundedTextOutput, renderCapturedText } from './text-output.js';
6
+ import { boundObservations, selectObservationImages, newObservationId, visibleObservation } from './observations.js';
6
7
  /** Keeps a failed tool call observable without discarding earlier explicit output. */
7
8
  export class CodeCellExecutionError extends MarAgentError {
8
9
  result;
@@ -88,6 +89,9 @@ export class CodeCells {
88
89
  status: 'running',
89
90
  text: new BoundedTextOutput(limits.codeMaxOutputBytes),
90
91
  images: [],
92
+ observations: [],
93
+ calls: new Map(),
94
+ imageOffset: 0,
91
95
  yielded: false,
92
96
  truncated: false,
93
97
  listeners: new Set(),
@@ -104,6 +108,8 @@ export class CodeCells {
104
108
  .then(async () => {
105
109
  releaseSession = await context.codeMode?.retainSession?.();
106
110
  return run(source, { ...context, signal: controller.signal }, {
111
+ call: (value) => cell.calls.set(value.callId, value),
112
+ observe: (value) => cell.observations.push(value),
107
113
  text: (text, originalBytes) => cell.text.append(text, originalBytes),
108
114
  image: (image) => cell.images.push(image),
109
115
  yield: () => {
@@ -199,6 +205,31 @@ export class CodeCells {
199
205
  if (!supportsImages && (cell.images.length || cell.terminal?.images?.length))
200
206
  throw new MarAgentError('MAR_AGENT_INPUT_CAPABILITY_UNSUPPORTED', 'The current model cannot receive this cell image output.');
201
207
  if (cell.terminal) {
208
+ if (cell.terminal.observations) {
209
+ const bounded = boundObservations(cell.terminal.observations, input.maxOutputTokens);
210
+ const visible = selectObservationImages(bounded.observations, cell.terminal.images ?? []);
211
+ const original = cell.terminal.data;
212
+ const data = {
213
+ ...original,
214
+ output: truncateModelText(original.output ?? '', input.maxOutputTokens).content,
215
+ observations: visible.observations,
216
+ cached: true,
217
+ truncated: cell.terminal.truncated === true || bounded.truncated
218
+ };
219
+ return {
220
+ ...cell.terminal,
221
+ observations: visible.observations,
222
+ images: visible.images,
223
+ content: JSON.stringify({
224
+ ...data,
225
+ output: undefined,
226
+ calls: undefined,
227
+ observations: visible.observations.map(visibleObservation)
228
+ }),
229
+ data,
230
+ truncated: data.truncated
231
+ };
232
+ }
202
233
  const snapshot = cell.terminal.data;
203
234
  const bounded = truncateModelText(snapshot.output, input.maxOutputTokens);
204
235
  const data = {
@@ -219,7 +250,21 @@ export class CodeCells {
219
250
  const text = renderCapturedText(captured, images.length);
220
251
  cell.yielded = false;
221
252
  const bounded = truncateModelText(text, input.maxOutputTokens);
222
- cell.truncated ||= captured.droppedBytes > 0 || bounded.truncated;
253
+ const pending = cell.observations.splice(0);
254
+ if (!pending.length && captured.text)
255
+ pending.push({
256
+ type: 'value',
257
+ id: newObservationId(),
258
+ format: 'text',
259
+ value: captured.text,
260
+ truncated: captured.droppedBytes > 0
261
+ });
262
+ const structured = boundObservations(pending, input.maxOutputTokens);
263
+ const visible = selectObservationImages(structured.observations, images, cell.imageOffset);
264
+ const remapped = visible.observations;
265
+ const visibleImages = visible.images;
266
+ cell.imageOffset += images.length;
267
+ cell.truncated ||= captured.droppedBytes > 0 || bounded.truncated || structured.truncated;
223
268
  const error = cell.error === undefined
224
269
  ? undefined
225
270
  : describeMarAgentError(cell.error, 'MAR_AGENT_CODE_FAILED');
@@ -227,6 +272,8 @@ export class CodeCells {
227
272
  cellId: cell.cellId,
228
273
  status: cell.status,
229
274
  output: bounded.content,
275
+ observations: remapped,
276
+ calls: [...cell.calls.values()],
230
277
  ...cell.result?.data,
231
278
  outputBytes: captured.originalBytes,
232
279
  outputDroppedBytes: captured.droppedBytes,
@@ -235,10 +282,17 @@ export class CodeCells {
235
282
  cached: false
236
283
  };
237
284
  const result = {
238
- content: JSON.stringify(data),
285
+ content: JSON.stringify({
286
+ ...data,
287
+ output: undefined,
288
+ calls: undefined,
289
+ observations: remapped.map(visibleObservation)
290
+ }),
291
+ calls: [...cell.calls.values()],
292
+ observations: remapped,
239
293
  data,
240
- truncated: cell.truncated,
241
- ...(images.length ? { images } : {})
294
+ truncated: cell.truncated || structured.truncated,
295
+ ...(visibleImages.length ? { images: visibleImages } : {})
242
296
  };
243
297
  if (cell.status !== 'running')
244
298
  cell.terminal = result;
@@ -246,7 +300,7 @@ export class CodeCells {
246
300
  if (initial && cell.status !== 'running') {
247
301
  if (cell.error !== undefined)
248
302
  throw new CodeCellExecutionError(cell.error, result);
249
- return { ...result, content: bounded.content || 'Code Exec completed without emitted text.' };
303
+ return result;
250
304
  }
251
305
  return result;
252
306
  }
@@ -1,5 +1,6 @@
1
1
  import type { ClientToolDefinition } from '../../model/contracts.js';
2
- import type { MarAgentEvent, ToolCall, ToolExecutionResult, McpToolCallContext } from '../../sdk/types.js';
2
+ import type { MarAgentEvent } from '../../runtime/events.js';
3
+ import type { McpToolCallContext, ToolCall, ToolExecutionResult } from '../contracts.js';
3
4
  import type { ToolRuntimeContext } from '../runtime-context.js';
4
5
  import type { createSessionToolScheduler } from '../scheduler.js';
5
6
  type ToolEvent = Extract<MarAgentEvent, {
@@ -14,8 +15,5 @@ export declare function createCodeToolDispatch(input: {
14
15
  parentCallId: string;
15
16
  schedule: ReturnType<typeof createSessionToolScheduler>;
16
17
  emit: (event: Payload) => Promise<void>;
17
- projectData: (name: string, data: unknown) => Extract<ToolEvent, {
18
- type: 'tool.completed';
19
- }>['data'];
20
18
  }): (call: ToolCall, signal: AbortSignal) => Promise<ToolExecutionResult>;
21
19
  export {};
@@ -1,9 +1,9 @@
1
1
  import { randomUUID } from 'node:crypto';
2
2
  import { MarAgentError, describeMarAgentError } from '../../error.js';
3
- import { executeRegisteredTool } from '../runtime.js';
4
- import { allowsToolCaller } from '../callers.js';
5
- import { truncateModelText } from '../../runtime/token-budget.js';
6
3
  import { AGENT_EXECUTION_POLICY } from '../../runtime/execution-policy.js';
4
+ import { allowsToolCaller } from '../callers.js';
5
+ import { boundedModelToolOutput, structuredToolEventData } from '../output-projection.js';
6
+ import { executeRegisteredTool } from '../runtime.js';
7
7
  /** Capture only the cell's immutable dispatch identity, never the model loop or its AbortSignal. */
8
8
  export function createCodeToolDispatch(input) {
9
9
  const definitions = new Map(input.tools.map((tool) => [tool.name, tool]));
@@ -23,8 +23,8 @@ export function createCodeToolDispatch(input) {
23
23
  signal,
24
24
  ...(expected ? { expectedMcpTool: expected } : {})
25
25
  });
26
- const bounded = truncateModelText(result.content, AGENT_EXECUTION_POLICY.modelToolOutputTokens);
27
- const data = input.projectData(call.name, result.data);
26
+ const bounded = boundedModelToolOutput(call.name, result.content, result.data);
27
+ const data = structuredToolEventData(call.name, result.data);
28
28
  const summary = result.content.slice(0, AGENT_EXECUTION_POLICY.toolEventSummaryCharacters);
29
29
  await input.emit({
30
30
  type: 'tool.completed',
@@ -36,7 +36,11 @@ export function createCodeToolDispatch(input) {
36
36
  summary.length < result.content.length,
37
37
  ...(result.artifacts ? { artifacts: result.artifacts } : {})
38
38
  });
39
- return { ...result, content: bounded.content };
39
+ return {
40
+ ...result,
41
+ content: bounded.content,
42
+ truncated: result.truncated === true || bounded.truncated
43
+ };
40
44
  }
41
45
  catch (error) {
42
46
  const diagnostic = describeMarAgentError(error, 'MAR_AGENT_HOST_OPERATION_FAILED');
@@ -1,4 +1,4 @@
1
- import type { ToolCall, ToolExecutionResult } from '../../sdk/types.js';
1
+ import type { ToolCall, ToolExecutionResult } from '../contracts.js';
2
2
  import type { CodeModeStateEntry, CodeModeStateMutation } from './state.js';
3
3
  export type ProgrammaticToolResult = Omit<ToolExecutionResult, 'content'> & {
4
4
  content?: string;
@@ -32,6 +32,18 @@ export interface CodeModeEngine {
32
32
  onToolCall(call: ToolCall): Promise<ProgrammaticToolResult>;
33
33
  onText(value: string, originalBytes?: number): void;
34
34
  onImage(value: unknown): void;
35
+ onObserve(value: {
36
+ type: 'tool_result';
37
+ operationId: string;
38
+ } | {
39
+ type: 'value';
40
+ format: 'text' | 'json';
41
+ value: string;
42
+ originalBytes: number;
43
+ } | {
44
+ type: 'image';
45
+ value: unknown;
46
+ }): void;
35
47
  onYield(): void;
36
48
  }): Promise<{
37
49
  readonly stateMutations: readonly CodeModeStateMutation[];
@@ -0,0 +1 @@
1
+ export {};