@myagentroam/agent 0.11.33 → 0.11.34

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 (856) hide show
  1. package/dist/cli/catalog-file.d.ts +78 -0
  2. package/dist/cli/catalog-file.js +102 -0
  3. package/dist/cli/codex-auth-file.d.ts +1 -1
  4. package/dist/cli/codex-auth-file.js +9 -10
  5. package/dist/cli/main.js +44 -54
  6. package/dist/error.d.ts +15 -0
  7. package/dist/error.js +74 -0
  8. package/dist/extensions/agents.d.ts +100 -0
  9. package/dist/extensions/agents.js +121 -0
  10. package/dist/extensions/capabilities.d.ts +4 -0
  11. package/dist/extensions/commands.d.ts +23 -0
  12. package/dist/extensions/commands.js +45 -0
  13. package/dist/extensions/compaction.d.ts +36 -0
  14. package/dist/extensions/contracts.d.ts +147 -0
  15. package/dist/extensions/data.d.ts +81 -0
  16. package/dist/extensions/data.js +78 -0
  17. package/dist/extensions/environment.d.ts +39 -0
  18. package/dist/extensions/environment.js +52 -0
  19. package/dist/extensions/files.d.ts +68 -0
  20. package/dist/extensions/files.js +26 -0
  21. package/dist/extensions/hooks.d.ts +32 -0
  22. package/dist/extensions/host-ports.d.ts +24 -0
  23. package/dist/extensions/manager.d.ts +42 -0
  24. package/dist/extensions/manager.js +457 -0
  25. package/dist/extensions/mcp.d.ts +116 -0
  26. package/dist/extensions/mcp.js +434 -0
  27. package/dist/extensions/model-request.d.ts +65 -0
  28. package/dist/extensions/model-request.js +197 -0
  29. package/dist/extensions/model-stream.d.ts +18 -0
  30. package/dist/extensions/model-stream.js +108 -0
  31. package/dist/extensions/models.d.ts +46 -0
  32. package/dist/extensions/models.js +7 -0
  33. package/dist/extensions/network.d.ts +40 -0
  34. package/dist/extensions/network.js +97 -0
  35. package/dist/extensions/operation.d.ts +32 -0
  36. package/dist/extensions/processes.d.ts +64 -0
  37. package/dist/extensions/processes.js +284 -0
  38. package/dist/extensions/prompt-composition.d.ts +38 -0
  39. package/dist/extensions/prompt-composition.js +100 -0
  40. package/dist/extensions/prompt-input.d.ts +30 -0
  41. package/dist/extensions/prompt-input.js +48 -0
  42. package/dist/extensions/prompts.d.ts +31 -0
  43. package/dist/extensions/prompts.js +88 -0
  44. package/dist/extensions/resources.d.ts +26 -0
  45. package/dist/extensions/resources.js +221 -0
  46. package/dist/extensions/services.d.ts +31 -0
  47. package/dist/extensions/services.js +61 -0
  48. package/dist/extensions/session-api.d.ts +6 -0
  49. package/dist/extensions/session-api.js +52 -0
  50. package/dist/extensions/session-input.d.ts +184 -0
  51. package/dist/extensions/session-input.js +422 -0
  52. package/dist/extensions/session-messages.d.ts +41 -0
  53. package/dist/extensions/session-messages.js +76 -0
  54. package/dist/extensions/session-tools.d.ts +32 -0
  55. package/dist/extensions/session-tools.js +208 -0
  56. package/dist/extensions/session.d.ts +60 -0
  57. package/dist/extensions/session.js +265 -0
  58. package/dist/extensions/settings.d.ts +76 -0
  59. package/dist/extensions/settings.js +115 -0
  60. package/dist/extensions/store.d.ts +10 -0
  61. package/dist/extensions/store.js +131 -0
  62. package/dist/extensions/tool-runtime.d.ts +16 -0
  63. package/dist/extensions/tools.d.ts +80 -0
  64. package/dist/extensions/tools.js +270 -0
  65. package/dist/extensions.d.ts +22 -0
  66. package/dist/host/contracts.d.ts +58 -0
  67. package/dist/host/contracts.js +18 -0
  68. package/dist/host/description.d.ts +19 -0
  69. package/dist/host/local-agent-host.d.ts +96 -0
  70. package/dist/host/local-agent-host.js +429 -0
  71. package/dist/host/local-exec-tool.d.ts +26 -0
  72. package/dist/host/local-exec-tool.js +686 -0
  73. package/dist/host/local-file-access.d.ts +30 -0
  74. package/dist/host/local-file-access.js +107 -0
  75. package/dist/host/local-network-access.d.ts +6 -0
  76. package/dist/host/local-network-access.js +101 -0
  77. package/dist/host/local-process-executor.d.ts +5 -0
  78. package/dist/host/local-process-executor.js +17 -0
  79. package/dist/host/local-session-environment.d.ts +18 -0
  80. package/dist/host/local-shell.d.ts +3 -0
  81. package/dist/host/local-tool-registry.d.ts +34 -0
  82. package/dist/host/local-tool-registry.js +134 -0
  83. package/dist/host/network.d.ts +5 -0
  84. package/dist/host/network.js +42 -0
  85. package/dist/host/process-control.d.ts +2 -0
  86. package/dist/host/process-control.js +26 -0
  87. package/dist/host/skill-contract.d.ts +6 -0
  88. package/dist/host.d.ts +17 -0
  89. package/dist/host.js +3 -0
  90. package/dist/index.d.ts +26 -51
  91. package/dist/index.js +9 -12
  92. package/dist/model/anthropic-messages.d.ts +10 -0
  93. package/dist/model/anthropic-messages.js +692 -0
  94. package/dist/model/anthropic-thinking.js +33 -0
  95. package/dist/model/configuration.d.ts +111 -0
  96. package/dist/model/configuration.js +201 -0
  97. package/dist/model/contracts.d.ts +229 -0
  98. package/dist/model/http.d.ts +13 -0
  99. package/dist/model/http.js +119 -0
  100. package/dist/model/image-contract.d.ts +10 -0
  101. package/dist/model/image.d.ts +9 -0
  102. package/dist/model/inline-media-budget.d.ts +7 -0
  103. package/dist/model/inline-media-budget.js +36 -0
  104. package/dist/model/input-images.d.ts +3 -0
  105. package/dist/model/input-images.js +16 -0
  106. package/dist/model/openai-responses.d.ts +59 -0
  107. package/dist/model/openai-responses.js +1586 -0
  108. package/dist/model/recovery.js +80 -0
  109. package/dist/model/request-configuration.d.ts +17 -0
  110. package/dist/model/request-configuration.js +47 -0
  111. package/dist/model/responses-event-projection.d.ts +24 -0
  112. package/dist/model/responses-event-projection.js +194 -0
  113. package/dist/model/responses-request.d.ts +5 -0
  114. package/dist/model/responses-request.js +363 -0
  115. package/dist/model/responses-session-cache.d.ts +33 -0
  116. package/dist/model/responses-session-cache.js +64 -0
  117. package/dist/model/runtime-credential.d.ts +1 -0
  118. package/dist/model/runtime-credential.js +1 -0
  119. package/dist/model/sse.js +281 -0
  120. package/dist/model/text-blocks.js +40 -0
  121. package/dist/model/tool-declarations.d.ts +4 -0
  122. package/dist/model/tool-definition-projection.d.ts +6 -0
  123. package/dist/model/tool-definition-projection.js +11 -0
  124. package/dist/model/tool-schema.d.ts +2 -0
  125. package/dist/model/tool-schema.js +17 -0
  126. package/dist/model/transport-test.d.ts +10 -0
  127. package/dist/model/transport-test.js +27 -0
  128. package/dist/model/usage-observer.d.ts +5 -0
  129. package/dist/model/usage.d.ts +40 -0
  130. package/dist/network/credential-runtime.d.ts +8 -0
  131. package/dist/network/credential-runtime.js +72 -0
  132. package/dist/network/credentials.d.ts +20 -0
  133. package/dist/network/credentials.js +18 -0
  134. package/dist/network/http.d.ts +20 -0
  135. package/dist/network/http.js +421 -0
  136. package/dist/network/product-user-agent.d.ts +5 -0
  137. package/dist/network/product-user-agent.js +22 -0
  138. package/dist/network/transport-error.d.ts +5 -0
  139. package/dist/network/transport-error.js +31 -0
  140. package/dist/process/contracts.d.ts +26 -0
  141. package/dist/prompts/index.d.ts +20 -0
  142. package/dist/prompts/index.js +49 -0
  143. package/dist/prompts/prompt-sections.d.ts +6 -0
  144. package/dist/prompts/prompt-sections.js +6 -0
  145. package/dist/prompts/read-context.js +152 -0
  146. package/dist/runtime/compaction/contracts.d.ts +23 -0
  147. package/dist/runtime/compaction/coordinator.js +88 -0
  148. package/dist/runtime/compaction/generate.d.ts +31 -0
  149. package/dist/runtime/compaction/generate.js +84 -0
  150. package/dist/runtime/compaction/history.d.ts +16 -0
  151. package/dist/runtime/compaction/operation.d.ts +30 -0
  152. package/dist/runtime/compaction/operation.js +131 -0
  153. package/dist/runtime/compaction/requests.d.ts +16 -0
  154. package/dist/runtime/compaction/requests.js +114 -0
  155. package/dist/runtime/compaction/retained-context.d.ts +6 -0
  156. package/dist/runtime/compaction/retained-context.js +48 -0
  157. package/dist/runtime/compaction/smart.d.ts +14 -0
  158. package/dist/runtime/compaction/smart.js +59 -0
  159. package/dist/runtime/context/contextual-blocks.d.ts +31 -0
  160. package/dist/runtime/context/contextual-blocks.js +158 -0
  161. package/dist/runtime/context/environment.d.ts +5 -0
  162. package/dist/runtime/context/gc-candidates-code.d.ts +6 -0
  163. package/dist/runtime/context/gc-candidates-code.js +102 -0
  164. package/dist/runtime/context/gc-candidates-exec.d.ts +6 -0
  165. package/dist/runtime/context/gc-candidates-exec.js +131 -0
  166. package/dist/runtime/context/gc-candidates-read-patch.d.ts +7 -0
  167. package/dist/runtime/context/gc-candidates-read-patch.js +118 -0
  168. package/dist/runtime/context/gc-candidates-subagent.d.ts +6 -0
  169. package/dist/runtime/context/gc-candidates-subagent.js +100 -0
  170. package/dist/runtime/context/gc-candidates-web.d.ts +6 -0
  171. package/dist/runtime/context/gc-candidates-web.js +58 -0
  172. package/dist/runtime/context/gc-candidates.d.ts +12 -0
  173. package/dist/runtime/context/gc-candidates.js +192 -0
  174. package/dist/runtime/context/gc-contracts.d.ts +57 -0
  175. package/dist/runtime/context/gc-economics.d.ts +48 -0
  176. package/dist/runtime/context/gc-economics.js +161 -0
  177. package/dist/runtime/context/gc-runtime.d.ts +43 -0
  178. package/dist/runtime/context/gc-tokens.d.ts +26 -0
  179. package/dist/runtime/context/gc-tokens.js +106 -0
  180. package/dist/runtime/context/gc.d.ts +7 -0
  181. package/dist/runtime/context/gc.js +552 -0
  182. package/dist/runtime/context/instructions.d.ts +37 -0
  183. package/dist/runtime/context/instructions.js +297 -0
  184. package/dist/runtime/context/normalize.d.ts +5 -0
  185. package/dist/runtime/context/projection.d.ts +23 -0
  186. package/dist/runtime/context/projection.js +284 -0
  187. package/dist/runtime/context/request-budget.d.ts +5 -0
  188. package/dist/runtime/context/request-budget.js +25 -0
  189. package/dist/runtime/context/restore.d.ts +27 -0
  190. package/dist/runtime/context/restore.js +186 -0
  191. package/dist/runtime/context/usage.d.ts +17 -0
  192. package/dist/runtime/context/usage.js +124 -0
  193. package/dist/runtime/context/world-state.d.ts +34 -0
  194. package/dist/runtime/context/world-state.js +232 -0
  195. package/dist/runtime/contracts.d.ts +29 -0
  196. package/dist/runtime/event-projection.d.ts +14 -0
  197. package/dist/runtime/event-projection.js +87 -0
  198. package/dist/runtime/events.d.ts +195 -0
  199. package/dist/runtime/execution-handle.d.ts +12 -0
  200. package/dist/runtime/execution-handle.js +1 -0
  201. package/dist/runtime/execution.d.ts +55 -0
  202. package/dist/runtime/execution.js +444 -0
  203. package/dist/runtime/model-progress.js +85 -0
  204. package/dist/runtime/resource-publication.d.ts +27 -0
  205. package/dist/runtime/resource-publication.js +60 -0
  206. package/dist/runtime/tool-round-contract.d.ts +19 -0
  207. package/dist/runtime/tool-round-contract.js +1 -0
  208. package/dist/runtime/wait.js +82 -0
  209. package/dist/sandbox/linux/bubblewrap-sandbox-executor.d.ts +1 -1
  210. package/dist/sandbox/linux/bubblewrap-sandbox-executor.js +8 -8
  211. package/dist/sdk/agent.d.ts +7 -0
  212. package/dist/sdk/agent.js +321 -0
  213. package/dist/sdk/execution-code-mode.d.ts +18 -0
  214. package/dist/sdk/execution-code-mode.js +51 -0
  215. package/dist/sdk/execution-compact-commit.d.ts +23 -0
  216. package/dist/sdk/execution-compact-commit.js +41 -0
  217. package/dist/sdk/execution-compact-extension.d.ts +12 -0
  218. package/dist/sdk/execution-compact-extension.js +46 -0
  219. package/dist/sdk/execution-compact-generation.d.ts +17 -0
  220. package/dist/sdk/execution-compact-generation.js +30 -0
  221. package/dist/sdk/execution-compaction-flight.d.ts +31 -0
  222. package/dist/sdk/execution-compaction-flight.js +50 -0
  223. package/dist/sdk/execution-compaction.d.ts +47 -0
  224. package/dist/sdk/execution-compaction.js +121 -0
  225. package/dist/sdk/execution-context-coordinator.d.ts +56 -0
  226. package/dist/sdk/execution-context-coordinator.js +102 -0
  227. package/dist/sdk/execution-input.d.ts +58 -0
  228. package/dist/sdk/execution-input.js +266 -0
  229. package/dist/sdk/execution-model-context.d.ts +52 -0
  230. package/dist/sdk/execution-model-context.js +156 -0
  231. package/dist/sdk/execution-model-lifecycle.d.ts +39 -0
  232. package/dist/sdk/execution-model-lifecycle.js +73 -0
  233. package/dist/sdk/execution-model-request.d.ts +40 -0
  234. package/dist/sdk/execution-model-request.js +45 -0
  235. package/dist/sdk/execution-round-preparation.d.ts +11 -0
  236. package/dist/sdk/execution-round-preparation.js +18 -0
  237. package/dist/sdk/execution-round-request.d.ts +30 -0
  238. package/dist/sdk/execution-round-request.js +31 -0
  239. package/dist/sdk/execution-tool-catalog.d.ts +46 -0
  240. package/dist/sdk/execution-tool-catalog.js +103 -0
  241. package/dist/sdk/execution-tool-scope.d.ts +67 -0
  242. package/dist/sdk/execution-tool-scope.js +147 -0
  243. package/dist/sdk/extension-agent-controller.d.ts +3 -0
  244. package/dist/sdk/extension-agent-controller.js +69 -0
  245. package/dist/sdk/extension-agents.d.ts +9 -0
  246. package/dist/sdk/extension-agents.js +58 -0
  247. package/dist/sdk/extension-models.d.ts +17 -0
  248. package/dist/sdk/extension-models.js +142 -0
  249. package/dist/sdk/extension-session-launch.d.ts +18 -0
  250. package/dist/sdk/extension-session-launch.js +73 -0
  251. package/dist/sdk/extension-session.d.ts +30 -0
  252. package/dist/sdk/extension-session.js +107 -0
  253. package/dist/sdk/extension-tool-runtime.d.ts +2 -0
  254. package/dist/sdk/extension-tool-runtime.js +14 -0
  255. package/dist/sdk/extension-tools.d.ts +16 -0
  256. package/dist/sdk/extension-tools.js +126 -0
  257. package/dist/sdk/model-input-projection.d.ts +4 -0
  258. package/dist/sdk/model-input-projection.js +27 -0
  259. package/dist/sdk/model-runtime.d.ts +21 -0
  260. package/dist/sdk/model-runtime.js +91 -0
  261. package/dist/sdk/native-steer.d.ts +20 -0
  262. package/dist/sdk/native-steer.js +84 -0
  263. package/dist/sdk/request-preparation.d.ts +9 -0
  264. package/dist/sdk/resource-input.d.ts +33 -0
  265. package/dist/sdk/resource-input.js +402 -0
  266. package/dist/sdk/session-catalog.d.ts +2 -0
  267. package/dist/sdk/session-catalog.js +12 -0
  268. package/dist/sdk/session-composition.d.ts +54 -0
  269. package/dist/sdk/session-composition.js +1 -0
  270. package/dist/sdk/session-execution-factory.d.ts +43 -0
  271. package/dist/sdk/session-execution-factory.js +937 -0
  272. package/dist/sdk/session-execution.d.ts +163 -0
  273. package/dist/sdk/session-execution.js +388 -0
  274. package/dist/sdk/session-extension-messages.d.ts +16 -0
  275. package/dist/sdk/session-extension-messages.js +64 -0
  276. package/dist/sdk/session-extension-prompt.d.ts +35 -0
  277. package/dist/sdk/session-extension-prompt.js +62 -0
  278. package/dist/sdk/session-maintenance.d.ts +25 -0
  279. package/dist/sdk/session-maintenance.js +205 -0
  280. package/dist/sdk/session-model-adapters.d.ts +28 -0
  281. package/dist/sdk/session-model-adapters.js +96 -0
  282. package/dist/sdk/session-open.d.ts +22 -0
  283. package/dist/sdk/session-open.js +44 -0
  284. package/dist/sdk/session-registry.d.ts +17 -0
  285. package/dist/sdk/session-registry.js +83 -0
  286. package/dist/sdk/session-runtime.d.ts +72 -0
  287. package/dist/sdk/session-runtime.js +205 -0
  288. package/dist/sdk/session.d.ts +3 -0
  289. package/dist/sdk/session.js +313 -0
  290. package/dist/sdk/subagent-backend.d.ts +3 -0
  291. package/dist/sdk/subagent-backend.js +49 -0
  292. package/dist/sdk/types.d.ts +80 -0
  293. package/dist/sdk/types.js +1 -0
  294. package/dist/session/catalog.d.ts +70 -0
  295. package/dist/session/catalog.js +194 -0
  296. package/dist/session/code-observation-contract.d.ts +40 -0
  297. package/dist/session/code-observation-contract.js +1 -0
  298. package/dist/session/code-observation-projection.d.ts +54 -0
  299. package/dist/session/code-observation-projection.js +165 -0
  300. package/dist/session/code-state.d.ts +27 -0
  301. package/dist/session/code-state.js +89 -0
  302. package/dist/session/context-gc-checkpoint.d.ts +26 -0
  303. package/dist/session/context-gc-checkpoint.js +935 -0
  304. package/dist/session/context-gc-contract.d.ts +141 -0
  305. package/dist/session/context-gc-contract.js +1 -0
  306. package/dist/session/context-gc-observations.d.ts +58 -0
  307. package/dist/session/context-gc-observations.js +187 -0
  308. package/dist/session/context-gc-replacements.d.ts +63 -0
  309. package/dist/session/context-gc-subagent.d.ts +54 -0
  310. package/dist/session/deferred-input.d.ts +5 -0
  311. package/dist/session/deferred-input.js +74 -0
  312. package/dist/session/extension-checkpoint.d.ts +8 -0
  313. package/dist/session/extension-checkpoint.js +30 -0
  314. package/dist/session/history-input-limits.d.ts +4 -0
  315. package/dist/session/history-input-limits.js +4 -0
  316. package/dist/session/inline-media-contract.d.ts +16 -0
  317. package/dist/session/inline-media-contract.js +1 -0
  318. package/dist/session/inline-media.d.ts +26 -0
  319. package/dist/session/inline-media.js +138 -0
  320. package/dist/session/model-request.d.ts +14 -0
  321. package/dist/session/model-request.js +1 -0
  322. package/dist/session/record-contract.d.ts +19 -0
  323. package/dist/session/record-contract.js +1 -0
  324. package/dist/session/record-projection.d.ts +6 -0
  325. package/dist/session/record-projection.js +80 -0
  326. package/dist/session/resource-contract.d.ts +9 -0
  327. package/dist/session/resource-contract.js +1 -0
  328. package/dist/session/rollback.d.ts +13 -0
  329. package/dist/session/rollback.js +46 -0
  330. package/dist/session/store/contracts.d.ts +160 -0
  331. package/dist/session/store/contracts.js +1 -0
  332. package/dist/session/store/current-state.d.ts +17 -0
  333. package/dist/session/store/current-state.js +53 -0
  334. package/dist/session/store/execution-state.d.ts +13 -0
  335. package/dist/session/store/execution-state.js +103 -0
  336. package/dist/session/store/index.d.ts +4 -0
  337. package/dist/session/store/index.js +2 -0
  338. package/dist/session/store/jsonl/directory-index.d.ts +26 -0
  339. package/dist/session/store/jsonl/directory-index.js +283 -0
  340. package/dist/session/store/jsonl/fs-durability.d.ts +3 -0
  341. package/dist/session/store/jsonl/fs-durability.js +17 -0
  342. package/dist/session/store/jsonl/history-replacement.d.ts +48 -0
  343. package/dist/session/store/jsonl/history-replacement.js +147 -0
  344. package/dist/session/store/jsonl/history.d.ts +25 -0
  345. package/dist/session/store/jsonl/history.js +181 -0
  346. package/dist/session/store/jsonl/images.d.ts +19 -0
  347. package/dist/session/store/jsonl/images.js +122 -0
  348. package/dist/session/store/jsonl/index-transaction.d.ts +13 -0
  349. package/dist/session/store/jsonl/index-transaction.js +87 -0
  350. package/dist/session/store/jsonl/jsonl-admission.d.ts +10 -0
  351. package/dist/session/store/jsonl/jsonl-admission.js +205 -0
  352. package/dist/session/store/jsonl/jsonl-codec.d.ts +11 -0
  353. package/dist/session/store/jsonl/jsonl-codec.js +138 -0
  354. package/dist/session/store/jsonl/jsonl-migration.d.ts +12 -0
  355. package/dist/session/store/jsonl/jsonl-migration.js +105 -0
  356. package/dist/session/store/jsonl/jsonl-store.d.ts +171 -0
  357. package/dist/session/store/jsonl/jsonl-store.js +2482 -0
  358. package/dist/session/store/jsonl/open-recovery.d.ts +13 -0
  359. package/dist/session/store/jsonl/open-recovery.js +131 -0
  360. package/dist/session/store/jsonl/read-pins.d.ts +4 -0
  361. package/dist/session/store/jsonl/read-pins.js +131 -0
  362. package/dist/session/store/jsonl/record-append.d.ts +16 -0
  363. package/dist/session/store/jsonl/record-append.js +49 -0
  364. package/dist/session/store/jsonl/records.d.ts +30 -0
  365. package/dist/session/store/jsonl/records.js +313 -0
  366. package/dist/session/store/jsonl/resources.d.ts +19 -0
  367. package/dist/session/store/jsonl/resources.js +209 -0
  368. package/dist/session/store/jsonl/store-pool.d.ts +12 -0
  369. package/dist/session/store/jsonl/store-pool.js +55 -0
  370. package/dist/session/store/jsonl/transaction-recovery.d.ts +48 -0
  371. package/dist/session/store/jsonl/transaction-recovery.js +374 -0
  372. package/dist/session/store/jsonl/tree-maintenance.d.ts +12 -0
  373. package/dist/session/store/jsonl/tree-maintenance.js +59 -0
  374. package/dist/session/store/types.d.ts +69 -0
  375. package/dist/session/store/types.js +1 -0
  376. package/dist/session/summary.d.ts +18 -0
  377. package/dist/session/summary.js +1 -0
  378. package/dist/session/todo.d.ts +11 -0
  379. package/dist/session/todo.js +30 -0
  380. package/dist/session/tool-result-resources.d.ts +27 -0
  381. package/dist/session/tool-result-resources.js +255 -0
  382. package/dist/session/types.js +1 -0
  383. package/dist/session/user-history.d.ts +17 -0
  384. package/dist/session/user-history.js +1 -0
  385. package/dist/session-store.d.ts +2 -0
  386. package/dist/session-store.js +1 -0
  387. package/dist/shared/auto-title.d.ts +3 -3
  388. package/dist/shared/auto-title.js +6 -6
  389. package/dist/shared/model-text.d.ts +8 -8
  390. package/dist/shared/model-text.js +8 -7
  391. package/dist/storage/file-lock.js +83 -0
  392. package/dist/subagent/contracts.d.ts +107 -0
  393. package/dist/subagent/contracts.js +1 -0
  394. package/dist/subagent/limits.d.ts +17 -0
  395. package/dist/subagent/limits.js +17 -0
  396. package/dist/subagent/model-update.js +81 -0
  397. package/dist/subagent/session-controller.d.ts +148 -0
  398. package/dist/subagent/session-controller.js +1761 -0
  399. package/dist/subagent/wait-targets.d.ts +10 -0
  400. package/dist/subagent/wait-targets.js +26 -0
  401. package/dist/subagent/wait.d.ts +26 -0
  402. package/dist/subagent/wait.js +73 -0
  403. package/dist/tools/agent/agent-cancel.d.ts +7 -0
  404. package/dist/tools/agent/agent-cancel.js +29 -0
  405. package/dist/tools/agent/agent-message.d.ts +7 -0
  406. package/dist/tools/agent/agent-message.js +57 -0
  407. package/dist/tools/agent/agent-start.d.ts +12 -0
  408. package/dist/tools/agent/agent-start.js +106 -0
  409. package/dist/tools/agent/agent-wait.d.ts +7 -0
  410. package/dist/tools/agent/agent-wait.js +91 -0
  411. package/dist/tools/agent/question.d.ts +7 -0
  412. package/dist/tools/agent/question.js +125 -0
  413. package/dist/tools/agent/skill.d.ts +11 -0
  414. package/dist/tools/agent/skill.js +38 -0
  415. package/dist/tools/agent/sleep.d.ts +9 -0
  416. package/dist/tools/agent/sleep.js +54 -0
  417. package/dist/tools/agent/smart-compact.d.ts +9 -0
  418. package/dist/tools/agent/smart-compact.js +23 -0
  419. package/dist/tools/agent/todo-read.d.ts +14 -0
  420. package/dist/tools/agent/todo-write.d.ts +14 -0
  421. package/dist/tools/agent/todo-write.js +66 -0
  422. package/dist/tools/agent/todo.d.ts +25 -0
  423. package/dist/tools/agent/todo.js +32 -0
  424. package/dist/tools/callers.d.ts +7 -0
  425. package/dist/tools/callers.js +39 -0
  426. package/dist/tools/code-mode/cells.d.ts +29 -0
  427. package/dist/tools/code-mode/cells.js +338 -0
  428. package/dist/tools/code-mode/dispatch.d.ts +20 -0
  429. package/dist/tools/code-mode/dispatch.js +80 -0
  430. package/dist/tools/code-mode/engine.d.ts +60 -0
  431. package/dist/tools/code-mode/engine.js +1 -0
  432. package/dist/tools/code-mode/index.d.ts +31 -0
  433. package/dist/tools/code-mode/index.js +751 -0
  434. package/dist/tools/code-mode/observations.d.ts +8 -0
  435. package/dist/tools/code-mode/observations.js +64 -0
  436. package/dist/tools/code-mode/worker.d.ts +1 -0
  437. package/dist/tools/contracts.d.ts +193 -0
  438. package/dist/tools/contracts.js +1 -0
  439. package/dist/tools/definition-projection.d.ts +1 -0
  440. package/dist/tools/definition-projection.js +1 -0
  441. package/dist/tools/execution-limits.d.ts +69 -0
  442. package/dist/tools/execution-limits.js +58 -0
  443. package/dist/tools/execution.d.ts +30 -0
  444. package/dist/tools/execution.js +191 -0
  445. package/dist/tools/local/apply-patch-parser.js +177 -0
  446. package/dist/tools/local/apply-patch.d.ts +19 -0
  447. package/dist/tools/local/apply-patch.js +489 -0
  448. package/dist/tools/local/exec.d.ts +28 -0
  449. package/dist/tools/local/exec.js +194 -0
  450. package/dist/tools/local/image-processing.js +146 -0
  451. package/dist/tools/local/read.d.ts +43 -0
  452. package/dist/tools/local/read.js +470 -0
  453. package/dist/tools/local/view-image.d.ts +15 -0
  454. package/dist/tools/local/view-image.js +317 -0
  455. package/dist/tools/mcp/catalog.js +220 -0
  456. package/dist/tools/mcp/history.d.ts +4 -0
  457. package/dist/tools/mcp/tool-search.d.ts +45 -0
  458. package/dist/tools/mcp/tool-search.js +294 -0
  459. package/dist/tools/output-projection.d.ts +18 -0
  460. package/dist/tools/output-projection.js +341 -0
  461. package/dist/tools/permission-contract.d.ts +25 -0
  462. package/dist/tools/permission-contract.js +1 -0
  463. package/dist/tools/permissions.d.ts +61 -0
  464. package/dist/tools/permissions.js +237 -0
  465. package/dist/tools/registry.d.ts +7 -0
  466. package/dist/tools/result-extension-contract.d.ts +37 -0
  467. package/dist/tools/result-extension-contract.js +32 -0
  468. package/dist/tools/result-extensions.d.ts +12 -0
  469. package/dist/tools/result-extensions.js +104 -0
  470. package/dist/tools/runtime-context.d.ts +89 -0
  471. package/dist/tools/runtime-context.js +1 -0
  472. package/dist/tools/runtime-resource-handles.js +28 -0
  473. package/dist/tools/runtime.js +77 -0
  474. package/dist/tools/scheduler.d.ts +12 -0
  475. package/dist/tools/shared/path-resolver.js +133 -0
  476. package/dist/tools/wait.d.ts +1 -0
  477. package/dist/tools/wait.js +1 -0
  478. package/package.json +15 -3
  479. package/dist/agent-core/error.d.ts +0 -15
  480. package/dist/agent-core/error.js +0 -74
  481. package/dist/agent-core/extensions/agents.d.ts +0 -79
  482. package/dist/agent-core/extensions/agents.js +0 -186
  483. package/dist/agent-core/extensions/compaction.d.ts +0 -48
  484. package/dist/agent-core/extensions/contracts.d.ts +0 -265
  485. package/dist/agent-core/extensions/data.d.ts +0 -84
  486. package/dist/agent-core/extensions/data.js +0 -83
  487. package/dist/agent-core/extensions/environment.d.ts +0 -27
  488. package/dist/agent-core/extensions/environment.js +0 -52
  489. package/dist/agent-core/extensions/files.d.ts +0 -64
  490. package/dist/agent-core/extensions/files.js +0 -26
  491. package/dist/agent-core/extensions/hooks.d.ts +0 -32
  492. package/dist/agent-core/extensions/manager.d.ts +0 -39
  493. package/dist/agent-core/extensions/manager.js +0 -458
  494. package/dist/agent-core/extensions/mcp.d.ts +0 -99
  495. package/dist/agent-core/extensions/mcp.js +0 -433
  496. package/dist/agent-core/extensions/model-request.d.ts +0 -56
  497. package/dist/agent-core/extensions/model-request.js +0 -197
  498. package/dist/agent-core/extensions/model-stream.d.ts +0 -9
  499. package/dist/agent-core/extensions/model-stream.js +0 -108
  500. package/dist/agent-core/extensions/models.d.ts +0 -43
  501. package/dist/agent-core/extensions/network.d.ts +0 -32
  502. package/dist/agent-core/extensions/network.js +0 -97
  503. package/dist/agent-core/extensions/operation.d.ts +0 -30
  504. package/dist/agent-core/extensions/processes.d.ts +0 -52
  505. package/dist/agent-core/extensions/processes.js +0 -284
  506. package/dist/agent-core/extensions/prompt-composition.d.ts +0 -24
  507. package/dist/agent-core/extensions/prompt-composition.js +0 -106
  508. package/dist/agent-core/extensions/prompt-input.d.ts +0 -23
  509. package/dist/agent-core/extensions/prompt-input.js +0 -48
  510. package/dist/agent-core/extensions/resources.d.ts +0 -27
  511. package/dist/agent-core/extensions/resources.js +0 -221
  512. package/dist/agent-core/extensions/services.d.ts +0 -31
  513. package/dist/agent-core/extensions/services.js +0 -61
  514. package/dist/agent-core/extensions/session-input.d.ts +0 -163
  515. package/dist/agent-core/extensions/session-input.js +0 -411
  516. package/dist/agent-core/extensions/session-messages.d.ts +0 -41
  517. package/dist/agent-core/extensions/session-messages.js +0 -76
  518. package/dist/agent-core/extensions/session.d.ts +0 -69
  519. package/dist/agent-core/extensions/session.js +0 -607
  520. package/dist/agent-core/extensions/settings.d.ts +0 -59
  521. package/dist/agent-core/extensions/settings.js +0 -115
  522. package/dist/agent-core/extensions/store.d.ts +0 -10
  523. package/dist/agent-core/extensions/store.js +0 -131
  524. package/dist/agent-core/extensions/tools.d.ts +0 -61
  525. package/dist/agent-core/extensions/tools.js +0 -269
  526. package/dist/agent-core/host/contracts.d.ts +0 -100
  527. package/dist/agent-core/host/contracts.js +0 -18
  528. package/dist/agent-core/host/local-agent-host.d.ts +0 -96
  529. package/dist/agent-core/host/local-agent-host.js +0 -425
  530. package/dist/agent-core/host/local-file-access.d.ts +0 -30
  531. package/dist/agent-core/host/local-file-access.js +0 -107
  532. package/dist/agent-core/host/local-network-access.d.ts +0 -6
  533. package/dist/agent-core/host/local-network-access.js +0 -101
  534. package/dist/agent-core/host/local-process-executor.d.ts +0 -29
  535. package/dist/agent-core/host/local-process-executor.js +0 -41
  536. package/dist/agent-core/host/local-session-environment.d.ts +0 -18
  537. package/dist/agent-core/host/local-shell.d.ts +0 -3
  538. package/dist/agent-core/host/network.d.ts +0 -4
  539. package/dist/agent-core/host/network.js +0 -6
  540. package/dist/agent-core/model/anthropic-messages.d.ts +0 -10
  541. package/dist/agent-core/model/anthropic-messages.js +0 -707
  542. package/dist/agent-core/model/anthropic-thinking.js +0 -33
  543. package/dist/agent-core/model/catalog-file.d.ts +0 -80
  544. package/dist/agent-core/model/catalog-file.js +0 -103
  545. package/dist/agent-core/model/configuration.d.ts +0 -127
  546. package/dist/agent-core/model/configuration.js +0 -168
  547. package/dist/agent-core/model/contracts.d.ts +0 -229
  548. package/dist/agent-core/model/http.d.ts +0 -27
  549. package/dist/agent-core/model/http.js +0 -534
  550. package/dist/agent-core/model/image.d.ts +0 -17
  551. package/dist/agent-core/model/openai-responses.d.ts +0 -77
  552. package/dist/agent-core/model/openai-responses.js +0 -2123
  553. package/dist/agent-core/model/product-user-agent.d.ts +0 -5
  554. package/dist/agent-core/model/product-user-agent.js +0 -22
  555. package/dist/agent-core/model/recovery.js +0 -80
  556. package/dist/agent-core/model/request-configuration.d.ts +0 -17
  557. package/dist/agent-core/model/request-configuration.js +0 -47
  558. package/dist/agent-core/model/runtime-credential.d.ts +0 -8
  559. package/dist/agent-core/model/runtime-credential.js +0 -72
  560. package/dist/agent-core/model/sse.js +0 -281
  561. package/dist/agent-core/model/text-blocks.js +0 -40
  562. package/dist/agent-core/model/tool-declarations.d.ts +0 -4
  563. package/dist/agent-core/model/transport-test.d.ts +0 -3
  564. package/dist/agent-core/model/transport-test.js +0 -23
  565. package/dist/agent-core/model/usage-observer.d.ts +0 -31
  566. package/dist/agent-core/prompts/index.d.ts +0 -20
  567. package/dist/agent-core/prompts/index.js +0 -49
  568. package/dist/agent-core/runtime/compaction/coordinator.js +0 -88
  569. package/dist/agent-core/runtime/compaction/generate.d.ts +0 -28
  570. package/dist/agent-core/runtime/compaction/generate.js +0 -84
  571. package/dist/agent-core/runtime/compaction/history.d.ts +0 -16
  572. package/dist/agent-core/runtime/compaction/operation.d.ts +0 -29
  573. package/dist/agent-core/runtime/compaction/operation.js +0 -131
  574. package/dist/agent-core/runtime/compaction/requests.d.ts +0 -16
  575. package/dist/agent-core/runtime/compaction/requests.js +0 -114
  576. package/dist/agent-core/runtime/compaction/retained-context.d.ts +0 -6
  577. package/dist/agent-core/runtime/compaction/retained-context.js +0 -47
  578. package/dist/agent-core/runtime/compaction/smart.d.ts +0 -14
  579. package/dist/agent-core/runtime/compaction/smart.js +0 -59
  580. package/dist/agent-core/runtime/context/contextual-blocks.d.ts +0 -30
  581. package/dist/agent-core/runtime/context/contextual-blocks.js +0 -146
  582. package/dist/agent-core/runtime/context/environment.d.ts +0 -5
  583. package/dist/agent-core/runtime/context/gc-runtime.d.ts +0 -38
  584. package/dist/agent-core/runtime/context/gc-tokens.d.ts +0 -25
  585. package/dist/agent-core/runtime/context/gc-tokens.js +0 -103
  586. package/dist/agent-core/runtime/context/gc.d.ts +0 -75
  587. package/dist/agent-core/runtime/context/gc.js +0 -1386
  588. package/dist/agent-core/runtime/context/instructions.d.ts +0 -37
  589. package/dist/agent-core/runtime/context/instructions.js +0 -297
  590. package/dist/agent-core/runtime/context/normalize.d.ts +0 -5
  591. package/dist/agent-core/runtime/context/projection.d.ts +0 -23
  592. package/dist/agent-core/runtime/context/projection.js +0 -284
  593. package/dist/agent-core/runtime/context/request-budget.d.ts +0 -4
  594. package/dist/agent-core/runtime/context/request-budget.js +0 -25
  595. package/dist/agent-core/runtime/context/restore.d.ts +0 -25
  596. package/dist/agent-core/runtime/context/restore.js +0 -186
  597. package/dist/agent-core/runtime/context/usage.d.ts +0 -17
  598. package/dist/agent-core/runtime/context/usage.js +0 -124
  599. package/dist/agent-core/runtime/context/world-state.d.ts +0 -33
  600. package/dist/agent-core/runtime/context/world-state.js +0 -232
  601. package/dist/agent-core/runtime/contracts.d.ts +0 -41
  602. package/dist/agent-core/runtime/event-projection.d.ts +0 -14
  603. package/dist/agent-core/runtime/event-projection.js +0 -87
  604. package/dist/agent-core/runtime/events.d.ts +0 -197
  605. package/dist/agent-core/runtime/execution-handle.d.ts +0 -12
  606. package/dist/agent-core/runtime/execution.d.ts +0 -50
  607. package/dist/agent-core/runtime/execution.js +0 -445
  608. package/dist/agent-core/runtime/model-progress.js +0 -85
  609. package/dist/agent-core/runtime/resource-publication.d.ts +0 -8
  610. package/dist/agent-core/runtime/resource-publication.js +0 -60
  611. package/dist/agent-core/sdk/agent.d.ts +0 -11
  612. package/dist/agent-core/sdk/agent.js +0 -474
  613. package/dist/agent-core/sdk/extension-agents.d.ts +0 -9
  614. package/dist/agent-core/sdk/extension-agents.js +0 -58
  615. package/dist/agent-core/sdk/extension-models.d.ts +0 -13
  616. package/dist/agent-core/sdk/extension-models.js +0 -137
  617. package/dist/agent-core/sdk/extension-session.d.ts +0 -30
  618. package/dist/agent-core/sdk/extension-session.js +0 -105
  619. package/dist/agent-core/sdk/extension-tools.d.ts +0 -16
  620. package/dist/agent-core/sdk/extension-tools.js +0 -126
  621. package/dist/agent-core/sdk/model-runtime.d.ts +0 -18
  622. package/dist/agent-core/sdk/model-runtime.js +0 -93
  623. package/dist/agent-core/sdk/native-steer.d.ts +0 -20
  624. package/dist/agent-core/sdk/native-steer.js +0 -84
  625. package/dist/agent-core/sdk/request-preparation.d.ts +0 -7
  626. package/dist/agent-core/sdk/resource-input.d.ts +0 -32
  627. package/dist/agent-core/sdk/resource-input.js +0 -403
  628. package/dist/agent-core/sdk/session.d.ts +0 -94
  629. package/dist/agent-core/sdk/session.js +0 -2377
  630. package/dist/agent-core/sdk/subagent-backend.d.ts +0 -3
  631. package/dist/agent-core/sdk/subagent-backend.js +0 -49
  632. package/dist/agent-core/sdk/types.d.ts +0 -81
  633. package/dist/agent-core/session/catalog.d.ts +0 -99
  634. package/dist/agent-core/session/catalog.js +0 -200
  635. package/dist/agent-core/session/context-gc-checkpoint.d.ts +0 -165
  636. package/dist/agent-core/session/context-gc-checkpoint.js +0 -935
  637. package/dist/agent-core/session/context-gc-observations.d.ts +0 -60
  638. package/dist/agent-core/session/context-gc-observations.js +0 -187
  639. package/dist/agent-core/session/context-gc-replacements.d.ts +0 -62
  640. package/dist/agent-core/session/context-gc-subagent.d.ts +0 -53
  641. package/dist/agent-core/session/deferred-input.d.ts +0 -5
  642. package/dist/agent-core/session/deferred-input.js +0 -74
  643. package/dist/agent-core/session/inline-media.d.ts +0 -45
  644. package/dist/agent-core/session/inline-media.js +0 -163
  645. package/dist/agent-core/session/rollback.d.ts +0 -13
  646. package/dist/agent-core/session/rollback.js +0 -46
  647. package/dist/agent-core/session/store/contracts.d.ts +0 -158
  648. package/dist/agent-core/session/store/current-state.d.ts +0 -17
  649. package/dist/agent-core/session/store/current-state.js +0 -53
  650. package/dist/agent-core/session/store/directory-index.d.ts +0 -18
  651. package/dist/agent-core/session/store/directory-index.js +0 -169
  652. package/dist/agent-core/session/store/execution-state.d.ts +0 -18
  653. package/dist/agent-core/session/store/execution-state.js +0 -175
  654. package/dist/agent-core/session/store/history.d.ts +0 -25
  655. package/dist/agent-core/session/store/history.js +0 -181
  656. package/dist/agent-core/session/store/images.d.ts +0 -19
  657. package/dist/agent-core/session/store/images.js +0 -110
  658. package/dist/agent-core/session/store/index.d.ts +0 -4
  659. package/dist/agent-core/session/store/index.js +0 -2
  660. package/dist/agent-core/session/store/jsonl-store.d.ts +0 -171
  661. package/dist/agent-core/session/store/jsonl-store.js +0 -2078
  662. package/dist/agent-core/session/store/records.d.ts +0 -23
  663. package/dist/agent-core/session/store/records.js +0 -261
  664. package/dist/agent-core/session/store/resources.d.ts +0 -26
  665. package/dist/agent-core/session/store/resources.js +0 -197
  666. package/dist/agent-core/session/store/types.d.ts +0 -82
  667. package/dist/agent-core/session/tool-result-resources.d.ts +0 -26
  668. package/dist/agent-core/session/tool-result-resources.js +0 -256
  669. package/dist/agent-core/session/transaction-recovery.d.ts +0 -16
  670. package/dist/agent-core/session/transaction-recovery.js +0 -135
  671. package/dist/agent-core/storage/file-lock.js +0 -83
  672. package/dist/agent-core/subagent/contracts.d.ts +0 -117
  673. package/dist/agent-core/subagent/model-update.js +0 -81
  674. package/dist/agent-core/subagent/scheduler.d.ts +0 -135
  675. package/dist/agent-core/subagent/scheduler.js +0 -369
  676. package/dist/agent-core/subagent/session-controller.d.ts +0 -138
  677. package/dist/agent-core/subagent/session-controller.js +0 -1594
  678. package/dist/agent-core/subagent/wait.d.ts +0 -14
  679. package/dist/agent-core/subagent/wait.js +0 -32
  680. package/dist/agent-core/tools/agent/agent-cancel.d.ts +0 -7
  681. package/dist/agent-core/tools/agent/agent-cancel.js +0 -29
  682. package/dist/agent-core/tools/agent/agent-message.d.ts +0 -7
  683. package/dist/agent-core/tools/agent/agent-message.js +0 -57
  684. package/dist/agent-core/tools/agent/agent-start.d.ts +0 -12
  685. package/dist/agent-core/tools/agent/agent-start.js +0 -106
  686. package/dist/agent-core/tools/agent/agent-wait.d.ts +0 -7
  687. package/dist/agent-core/tools/agent/agent-wait.js +0 -91
  688. package/dist/agent-core/tools/agent/question.d.ts +0 -7
  689. package/dist/agent-core/tools/agent/question.js +0 -125
  690. package/dist/agent-core/tools/agent/skill.d.ts +0 -11
  691. package/dist/agent-core/tools/agent/skill.js +0 -38
  692. package/dist/agent-core/tools/agent/sleep.d.ts +0 -12
  693. package/dist/agent-core/tools/agent/sleep.js +0 -54
  694. package/dist/agent-core/tools/agent/smart-compact.d.ts +0 -9
  695. package/dist/agent-core/tools/agent/smart-compact.js +0 -23
  696. package/dist/agent-core/tools/agent/todo-read.d.ts +0 -14
  697. package/dist/agent-core/tools/agent/todo-write.d.ts +0 -14
  698. package/dist/agent-core/tools/agent/todo-write.js +0 -66
  699. package/dist/agent-core/tools/agent/todo.d.ts +0 -26
  700. package/dist/agent-core/tools/agent/todo.js +0 -60
  701. package/dist/agent-core/tools/callers.d.ts +0 -6
  702. package/dist/agent-core/tools/callers.js +0 -39
  703. package/dist/agent-core/tools/code-mode/cells.d.ts +0 -29
  704. package/dist/agent-core/tools/code-mode/cells.js +0 -337
  705. package/dist/agent-core/tools/code-mode/dispatch.d.ts +0 -20
  706. package/dist/agent-core/tools/code-mode/dispatch.js +0 -80
  707. package/dist/agent-core/tools/code-mode/engine.d.ts +0 -60
  708. package/dist/agent-core/tools/code-mode/index.d.ts +0 -29
  709. package/dist/agent-core/tools/code-mode/index.js +0 -749
  710. package/dist/agent-core/tools/code-mode/observations.d.ts +0 -98
  711. package/dist/agent-core/tools/code-mode/observations.js +0 -228
  712. package/dist/agent-core/tools/code-mode/state.d.ts +0 -9
  713. package/dist/agent-core/tools/code-mode/state.js +0 -82
  714. package/dist/agent-core/tools/contracts.d.ts +0 -211
  715. package/dist/agent-core/tools/definition-projection.d.ts +0 -7
  716. package/dist/agent-core/tools/definition-projection.js +0 -26
  717. package/dist/agent-core/tools/execution-limits.d.ts +0 -69
  718. package/dist/agent-core/tools/execution-limits.js +0 -69
  719. package/dist/agent-core/tools/execution.d.ts +0 -46
  720. package/dist/agent-core/tools/execution.js +0 -191
  721. package/dist/agent-core/tools/local/apply-patch-parser.js +0 -177
  722. package/dist/agent-core/tools/local/apply-patch.d.ts +0 -19
  723. package/dist/agent-core/tools/local/apply-patch.js +0 -489
  724. package/dist/agent-core/tools/local/exec.d.ts +0 -53
  725. package/dist/agent-core/tools/local/exec.js +0 -877
  726. package/dist/agent-core/tools/local/image-processing.js +0 -146
  727. package/dist/agent-core/tools/local/read-context.js +0 -152
  728. package/dist/agent-core/tools/local/read.d.ts +0 -43
  729. package/dist/agent-core/tools/local/read.js +0 -470
  730. package/dist/agent-core/tools/local/registry.d.ts +0 -34
  731. package/dist/agent-core/tools/local/registry.js +0 -132
  732. package/dist/agent-core/tools/local/view-image.d.ts +0 -15
  733. package/dist/agent-core/tools/local/view-image.js +0 -317
  734. package/dist/agent-core/tools/local/workspace-tools.d.ts +0 -12
  735. package/dist/agent-core/tools/local/workspace-tools.js +0 -28
  736. package/dist/agent-core/tools/mcp/catalog.js +0 -220
  737. package/dist/agent-core/tools/mcp/history.d.ts +0 -4
  738. package/dist/agent-core/tools/mcp/tool-search.d.ts +0 -45
  739. package/dist/agent-core/tools/mcp/tool-search.js +0 -294
  740. package/dist/agent-core/tools/output-projection.d.ts +0 -18
  741. package/dist/agent-core/tools/output-projection.js +0 -341
  742. package/dist/agent-core/tools/permissions.d.ts +0 -85
  743. package/dist/agent-core/tools/permissions.js +0 -237
  744. package/dist/agent-core/tools/registry.d.ts +0 -7
  745. package/dist/agent-core/tools/result-extensions.d.ts +0 -46
  746. package/dist/agent-core/tools/result-extensions.js +0 -134
  747. package/dist/agent-core/tools/runtime-context.d.ts +0 -74
  748. package/dist/agent-core/tools/runtime-resource-handles.js +0 -28
  749. package/dist/agent-core/tools/runtime.js +0 -77
  750. package/dist/agent-core/tools/scheduler.d.ts +0 -12
  751. package/dist/agent-core/tools/shared/path-resolver.js +0 -133
  752. package/dist/agent-core/tools/wait.js +0 -82
  753. /package/dist/{agent-core/extensions/models.js → extensions/capabilities.js} +0 -0
  754. /package/dist/{agent-core/extensions → extensions}/compaction.js +0 -0
  755. /package/dist/{agent-core/model → extensions}/contracts.js +0 -0
  756. /package/dist/{agent-core/extensions → extensions}/hooks.js +0 -0
  757. /package/dist/{agent-core/runtime/context/contracts.js → extensions/host-ports.js} +0 -0
  758. /package/dist/{agent-core/extensions → extensions}/operation.js +0 -0
  759. /package/dist/{agent-core/runtime/contracts.js → extensions/tool-runtime.js} +0 -0
  760. /package/dist/{agent-core/extensions/contracts.js → extensions.js} +0 -0
  761. /package/dist/{agent-core/runtime/events.js → host/description.js} +0 -0
  762. /package/dist/{agent-core/host → host}/local-session-environment.js +0 -0
  763. /package/dist/{agent-core/host → host}/local-shell.js +0 -0
  764. /package/dist/{agent-core/runtime/execution-handle.js → host/skill-contract.js} +0 -0
  765. /package/dist/{agent-core/model → model}/anthropic-thinking.d.ts +0 -0
  766. /package/dist/{agent-core/model → model}/attempt-diagnostics.d.ts +0 -0
  767. /package/dist/{agent-core/model → model}/attempt-diagnostics.js +0 -0
  768. /package/dist/{agent-core/session/store → model}/contracts.js +0 -0
  769. /package/dist/{agent-core/sdk/types.js → model/image-contract.js} +0 -0
  770. /package/dist/{agent-core/model → model}/image.js +0 -0
  771. /package/dist/{agent-core/model → model}/native-context.d.ts +0 -0
  772. /package/dist/{agent-core/model → model}/native-context.js +0 -0
  773. /package/dist/{agent-core/model → model}/recovery.d.ts +0 -0
  774. /package/dist/{agent-core/model → model}/sse.d.ts +0 -0
  775. /package/dist/{agent-core/model → model}/text-blocks.d.ts +0 -0
  776. /package/dist/{agent-core/model → model}/tool-declarations.js +0 -0
  777. /package/dist/{agent-core/model → model}/tool-input.d.ts +0 -0
  778. /package/dist/{agent-core/model → model}/tool-input.js +0 -0
  779. /package/dist/{agent-core/model → model}/usage-observer.js +0 -0
  780. /package/dist/{agent-core/session/store/types.js → model/usage.js} +0 -0
  781. /package/dist/{agent-core/subagent → process}/contracts.js +0 -0
  782. /package/dist/{agent-core/prompts → prompts}/compact.d.ts +0 -0
  783. /package/dist/{agent-core/prompts → prompts}/compact.js +0 -0
  784. /package/dist/{agent-core/prompts → prompts}/core.d.ts +0 -0
  785. /package/dist/{agent-core/prompts → prompts}/core.js +0 -0
  786. /package/dist/{agent-core/prompts → prompts}/markup.d.ts +0 -0
  787. /package/dist/{agent-core/prompts → prompts}/markup.js +0 -0
  788. /package/dist/{agent-core/prompts → prompts}/modes.d.ts +0 -0
  789. /package/dist/{agent-core/prompts → prompts}/modes.js +0 -0
  790. /package/dist/{agent-core/prompts → prompts}/output.d.ts +0 -0
  791. /package/dist/{agent-core/prompts → prompts}/output.js +0 -0
  792. /package/dist/{agent-core/prompts → prompts}/permissions.d.ts +0 -0
  793. /package/dist/{agent-core/prompts → prompts}/permissions.js +0 -0
  794. /package/dist/{agent-core/tools/local → prompts}/read-context.d.ts +0 -0
  795. /package/dist/{agent-core/prompts → prompts}/resources.d.ts +0 -0
  796. /package/dist/{agent-core/prompts → prompts}/resources.js +0 -0
  797. /package/dist/{agent-core/prompts → prompts}/subagent.d.ts +0 -0
  798. /package/dist/{agent-core/prompts → prompts}/subagent.js +0 -0
  799. /package/dist/{agent-core/prompts → prompts}/workflow.d.ts +0 -0
  800. /package/dist/{agent-core/prompts → prompts}/workflow.js +0 -0
  801. /package/dist/{agent-core/runtime → runtime}/async-queue.d.ts +0 -0
  802. /package/dist/{agent-core/runtime → runtime}/async-queue.js +0 -0
  803. /package/dist/{agent-core/tools → runtime/compaction}/contracts.js +0 -0
  804. /package/dist/{agent-core/runtime → runtime}/compaction/coordinator.d.ts +0 -0
  805. /package/dist/{agent-core/runtime → runtime}/compaction/history.js +0 -0
  806. /package/dist/{agent-core/runtime → runtime}/context/contracts.d.ts +0 -0
  807. /package/dist/{agent-core/session/types.js → runtime/context/contracts.js} +0 -0
  808. /package/dist/{agent-core/runtime → runtime}/context/environment.js +0 -0
  809. /package/dist/{agent-core/tools/code-mode/engine.js → runtime/context/gc-contracts.js} +0 -0
  810. /package/dist/{agent-core/runtime → runtime}/context/gc-runtime.js +0 -0
  811. /package/dist/{agent-core/runtime → runtime}/context/normalize.js +0 -0
  812. /package/dist/{agent-core/tools/code-mode/worker.d.ts → runtime/contracts.js} +0 -0
  813. /package/dist/{agent-core/tools/runtime-context.js → runtime/events.js} +0 -0
  814. /package/dist/{agent-core/runtime → runtime}/execution-policy.d.ts +0 -0
  815. /package/dist/{agent-core/runtime → runtime}/execution-policy.js +0 -0
  816. /package/dist/{agent-core/runtime → runtime}/model-generation-timing.d.ts +0 -0
  817. /package/dist/{agent-core/runtime → runtime}/model-generation-timing.js +0 -0
  818. /package/dist/{agent-core/runtime → runtime}/model-progress.d.ts +0 -0
  819. /package/dist/{agent-core/runtime → runtime}/plan-output.d.ts +0 -0
  820. /package/dist/{agent-core/runtime → runtime}/plan-output.js +0 -0
  821. /package/dist/{agent-core/tools/public-metadata.d.ts → runtime/public-tool-metadata.d.ts} +0 -0
  822. /package/dist/{agent-core/tools/public-metadata.js → runtime/public-tool-metadata.js} +0 -0
  823. /package/dist/{agent-core/runtime → runtime}/token-budget.d.ts +0 -0
  824. /package/dist/{agent-core/runtime → runtime}/token-budget.js +0 -0
  825. /package/dist/{agent-core/tools → runtime}/wait.d.ts +0 -0
  826. /package/dist/{agent-core/sdk → sdk}/request-preparation.js +0 -0
  827. /package/dist/{agent-core/session → session}/context-gc-markup.d.ts +0 -0
  828. /package/dist/{agent-core/session → session}/context-gc-markup.js +0 -0
  829. /package/dist/{agent-core/session → session}/context-gc-replacements.js +0 -0
  830. /package/dist/{agent-core/session → session}/context-gc-subagent.js +0 -0
  831. /package/dist/{agent-core/session → session}/types.d.ts +0 -0
  832. /package/dist/{agent-core/storage → storage}/file-lock.d.ts +0 -0
  833. /package/dist/{agent-core/subagent → subagent}/model-update.d.ts +0 -0
  834. /package/dist/{agent-core/tools → tools}/agent/todo-read.js +0 -0
  835. /package/dist/{agent-core/tools → tools}/code-mode/quickjs-engine.d.ts +0 -0
  836. /package/dist/{agent-core/tools → tools}/code-mode/quickjs-engine.js +0 -0
  837. /package/dist/{agent-core/tools → tools}/code-mode/text-output.d.ts +0 -0
  838. /package/dist/{agent-core/tools → tools}/code-mode/text-output.js +0 -0
  839. /package/dist/{agent-core/tools → tools}/code-mode/worker.js +0 -0
  840. /package/dist/{agent-core/tools → tools}/file-change-diff.d.ts +0 -0
  841. /package/dist/{agent-core/tools → tools}/file-change-diff.js +0 -0
  842. /package/dist/{agent-core/tools → tools}/input-diagnostics/source-preview.d.ts +0 -0
  843. /package/dist/{agent-core/tools → tools}/input-diagnostics/source-preview.js +0 -0
  844. /package/dist/{agent-core/tools → tools}/input.d.ts +0 -0
  845. /package/dist/{agent-core/tools → tools}/input.js +0 -0
  846. /package/dist/{agent-core/tools → tools}/local/apply-patch-parser.d.ts +0 -0
  847. /package/dist/{agent-core/tools → tools}/local/image-processing.d.ts +0 -0
  848. /package/dist/{agent-core/tools → tools}/mcp/catalog.d.ts +0 -0
  849. /package/dist/{agent-core/tools → tools}/mcp/history.js +0 -0
  850. /package/dist/{agent-core/tools → tools}/registry.js +0 -0
  851. /package/dist/{agent-core/tools → tools}/runtime-resource-handles.d.ts +0 -0
  852. /package/dist/{agent-core/tools → tools}/runtime.d.ts +0 -0
  853. /package/dist/{agent-core/tools → tools}/scheduler.js +0 -0
  854. /package/dist/{agent-core/tools → tools}/shared/patch-result.d.ts +0 -0
  855. /package/dist/{agent-core/tools → tools}/shared/patch-result.js +0 -0
  856. /package/dist/{agent-core/tools → tools}/shared/path-resolver.d.ts +0 -0
@@ -1,749 +0,0 @@
1
- import { randomUUID } from 'node:crypto';
2
- import { isToolPermissionFailure, permissionStopFromError, ToolPermissionStopError } from '../permissions.js';
3
- import { readFile } from 'node:fs/promises';
4
- import { createRequire } from 'node:module';
5
- import { dirname, sep } from 'node:path';
6
- import { StringDecoder } from 'node:string_decoder';
7
- import { fileURLToPath, pathToFileURL } from 'node:url';
8
- import { MarAgentError, describeMarAgentError } from '../../error.js';
9
- import { directLocalProcessExecutor, signalProcessTree } from '../../host/local-process-executor.js';
10
- import { allowsDirectTool, allowsToolCaller } from '../callers.js';
11
- import { orderToolDefinitions, stableToolSchema, stableToolDefinition } from '../definition-projection.js';
12
- import { CodeCells } from './cells.js';
13
- import { newObservationId, renderObservations } from './observations.js';
14
- import { parseCodeModeStateMutations } from './state.js';
15
- import { BoundedTextOutput, renderCapturedText } from './text-output.js';
16
- import { TOOL_EXECUTION_LIMITS as limits } from '../execution-limits.js';
17
- import { createToolCallScheduler } from '../scheduler.js';
18
- import { detectImageMime } from '../local/view-image.js';
19
- import { isModelImageUrl } from '../../model/image.js';
20
- import { structuredToolFailureData } from '../output-projection.js';
21
- import { failedToolResultExtensions } from '../result-extensions.js';
22
- export const codeModeToolDefinition = {
23
- name: 'code_exec',
24
- description: `Run JavaScript to orchestrate or compose tool calls.
25
- - Code Mode Only by default: call the programmatic tools listed below through tools.NAME, including single-tool operations. Tools explicitly exposed in both places may also be called directly; follow each tool's calling guidance. Direct-only tools remain separate model tools and cannot be called here.
26
- - Run independent calls concurrently with Promise.all; await sequentially when data, side effects, or failure handling require ordering.
27
- - Complete known, bounded steps and deterministic result processing in code when this avoids a model round trip. Return to the model when interpretation or a new decision is needed; do not invent extra work to fill a cell.
28
- - Observe only evidence needed for the next decision or verification: use observe.result for original results, observe.text for derived values, and observe.image for image values. Preserve source and failure details needed for reasoning; keep other intermediate data in the cell.
29
- - Single-tool cells are valid. Keep loops and retries bounded, and do not blindly replay operations with side effects.
30
- - Evaluates source in a fresh restricted ECMAScript runtime with top-level await and Promise.all. It is not Node.js or a browser. JavaScript globals do not survive between cells; bounded JSON state is available through state.
31
- - Accepts JavaScript source text. When exposed as a freeform tool, send the source directly; when exposed with a JSON input schema, put the source in its code field. Do not add another JSON wrapper, quoted string, or markdown code fence inside the source.
32
- - Keep embedded commands, patches and source in JSON-escaped double-quoted strings when they contain backticks or literal \${...}; escape newlines as \\n, never put literal line breaks inside single- or double-quoted JS strings. JavaScript template literals would interpolate their contents before the tool runs. Do not paste Python literals such as None into JavaScript expressions.
33
- - Use only standard ECMAScript built-ins and the explicitly documented tools, observe, state, catalog and cell namespaces. Do not use Node.js, browser or Web APIs. Module imports, filesystem and network APIs are unavailable. Obtain external capabilities only through available tools. Use tools.exec to start managed processes when permitted; use tools.exec_wait afterward to wait, write stdin or cancel.
34
-
35
- Tool calls:
36
- - tools.NAME(input) returns a Promise. Pass a JavaScript value matching the current catalog inputSchema. For parameterless tools prefer tools.NAME({}); tools.NAME() is accepted only for explicitly closed empty-object schemas.
37
- - Results use the MAR envelope: { content?: string, data?: unknown, images?: Array<{mimeType:string,dataBase64:string,url?:string,urlExpiresAt?:number}>, truncated?: boolean }. Redundant JSON content is omitted when it exactly renders data; independent text remains in content. Prefer data for programmatic results: result.data.results[0].text for read source text and result.data.exitCode/result.data.stdout for exec. content, when present, is rendered text, not raw file bytes. Use only fields documented by that tool; do not invent success or ok flags.
38
- - Tool errors reject with code/message and may be caught, except nested Auto deny, which skips only that call and resolves with data.error/data.message. A failed cell preserves already emitted output alongside its status and error; completed tool effects are not rolled back. Inspect it before retrying completed work. Await every call; unawaited calls fail the cell. Use Promise.all for independent calls and sequential await for dependencies. Runtime preserves safe/serial barriers and Host checks.
39
- - skill, tool_search, question, code_exec, code_exec_wait and direct-only tools cannot be called here. Load Skills directly and read their instructions before the next tool call. Use direct tool_search before a later code cell for deferred tools; the current cell's tools do not change.
40
-
41
- Built-in namespaces:
42
- - observe.result(result): void registers an unmodified complete tools.NAME result or caught tool error as a trusted tool_result, using the original text and all images without repeating program data. Non-original, copied or modified values are rejected. This selects evidence for the next model response, not a log and not a new model call. Prefer observe.result for inspecting tool results.
43
- - observe.text(value): void registers text/JSON values. observe.image(value): void registers one image value when image input is supported. Both accept original tool results for compatibility and use the same complete tool_result observation path; they do not select part of an original result. Extracted single images, copies and computed summaries are value observations, never trusted tool results. Observations are returned in registration order. Only explicitly observed evidence reaches the model; registration does not prove inspection. Sources and types are runtime-assigned. No out or callable observe(value) alias exists.
44
- - state.get(key), state.has(key), state.set(key, value), state.delete(key) access bounded session JSON state. Mutations commit atomically only when the cell succeeds; failed or cancelled cells discard them.
45
- - catalog.tools() returns a read-only array of the tools callable in this cell, including name, description and inputSchema. It does not discover or authorize additional tools.
46
- - await cell.sleep(ms) performs a cancellable delay up to ${limits.codeSleepMaxMs} ms.
47
- - await cell.yield_control() returns accumulated output to the model immediately while this cell continues running.
48
- - Optionally start source with // @options: {"yieldMs": ${limits.codeDefaultYieldMs}}. yieldMs defaults to ${limits.codeDefaultYieldMs} ms and controls this call's wait window (0..${limits.codeMaxYieldMs}), not nested tool timeouts or wait windows. A running result includes cellId (c_ plus 12 lowercase hex characters); use direct code_exec_wait for new output, completion or termination.
49
- - waitOutcome separates snapshot, completion, timeout, and yield from the cell status. A foreground steer returns interrupted with reason=steer without stopping the cell or its internal tool waits.
50
- - Registered cells are Session warm resources: ending or cancelling the model Execution cancels its wait, not the cell. Reuse retained cellId; do not start duplicate work. Host cleanup or explicit termination stops the cell.
51
- - tools, observe, state, catalog and cell are frozen bindings. Do not shadow their names.
52
-
53
- Examples (copy the JavaScript source, not the fences; use only tools available in the current directory):
54
- Independent reads, observing the original tool results:
55
- \`\`\`js
56
- const [a, b] = await Promise.all([
57
- tools.read({ reads: [{ path: "a.txt" }] }),
58
- tools.read({ reads: [{ path: "b.txt" }] })
59
- ]);
60
- observe.result(a);
61
- observe.result(b);
62
- \`\`\`
63
- Inspect before a dependent edit; successful await needs no invented success flag:
64
- \`\`\`js
65
- const inspected = await tools.read({ reads: [{ path: "source.txt" }] });
66
- const sourceText = inspected.data.results[0].text;
67
- if (!sourceText?.includes("original=1")) throw new Error("Unexpected source");
68
- const patched = await tools.apply_patch({ patch: "*** Begin Patch\\n*** Update File: source.txt\\n@@\\n original=1\\n+updated=2\\n*** End Patch" });
69
- observe.result(patched);
70
- \`\`\``,
71
- inputMode: 'freeform',
72
- inputSchema: {
73
- type: 'object',
74
- properties: { code: { type: 'string' } },
75
- required: ['code'],
76
- additionalProperties: false
77
- },
78
- allowedCallers: ['direct'],
79
- parallelSafety: 'serial'
80
- };
81
- export const codeExecWaitToolDefinition = {
82
- name: 'code_exec_wait',
83
- description: 'Wait for a retained Code Exec cell by cellId. It cannot start new work; use code_exec for that. A missing cellId does not mean code_exec is unavailable. Returns only new output, or a bounded terminal snapshot marked cached on repeat reads. yieldMs is a wait window, not a timeout. action defaults to poll (wait); action cancel stops the cell and waits for cleanup. Cancelling this wait does not cancel the cell. Cells belong to the current Session and cannot survive Host restart. Call directly, never inside code_exec. Poll results include waitOutcome; interrupted with reason=steer ends only the foreground wait and preserves the cell.',
84
- inputSchema: {
85
- type: 'object',
86
- properties: {
87
- cellId: {
88
- type: 'string',
89
- description: 'Copy the complete cellId returned by code_exec (c_ followed by 12 lowercase hex characters). Never use a processId (p_); use exec_wait for processes.'
90
- },
91
- yieldMs: {
92
- type: 'integer',
93
- minimum: 0,
94
- maximum: limits.codeMaxWaitYieldMs,
95
- default: limits.codeDefaultWaitYieldMs,
96
- description: `Wait up to this many milliseconds. Defaults to ${limits.codeDefaultWaitYieldMs}; maximum ${limits.codeMaxWaitYieldMs}. Zero returns immediately without stopping the cell. Waiting does not restart the cell or extend nested tool timeouts.`
97
- },
98
- action: {
99
- type: 'string',
100
- enum: ['poll', 'cancel'],
101
- description: 'Defaults to poll; cancel terminates the cell rather than just its current wait.'
102
- }
103
- },
104
- required: ['cellId'],
105
- additionalProperties: false
106
- },
107
- allowedCallers: ['direct'],
108
- parallelSafety: 'safe'
109
- };
110
- function projectProgrammaticTool(tool) {
111
- return {
112
- name: tool.name,
113
- description: `${allowsDirectTool(tool, true) ? `Call directly or as tools.${tool.name} inside code_exec.` : `Call only as tools.${tool.name} inside code_exec, never as a direct model tool.`}\nInside code_exec, pass a JavaScript value matching inputSchema.\n${tool.description}`,
114
- inputSchema: stableToolSchema(tool.inputSchema)
115
- };
116
- }
117
- /** Deferred definitions travel in search results, not in the stable Code Mode description. */
118
- export function projectCodeModeTools(tools, residentTools = tools) {
119
- const codeModeEnabled = tools.some((tool) => tool.name === 'code_exec' && allowsToolCaller(tool, 'direct'));
120
- const direct = tools
121
- .filter((tool) => allowsDirectTool(tool, codeModeEnabled))
122
- .map(stableToolDefinition);
123
- if (!codeModeEnabled)
124
- return direct;
125
- const programmatic = orderToolDefinitions(residentTools.filter((tool) => allowsToolCaller(tool, 'programmatic')));
126
- const directory = JSON.stringify({
127
- callableNames: programmatic.map((tool) => tool.name),
128
- tools: programmatic.map(projectProgrammaticTool)
129
- });
130
- if (Buffer.byteLength(directory) > 32 * 1024)
131
- throw new MarAgentError('MAR_AGENT_TOOL_EXPOSURE_LIMIT', 'Programmatic tool directory is too large.');
132
- return direct.map((tool) => tool.name === 'code_exec'
133
- ? {
134
- ...tool,
135
- description: `${codeModeToolDefinition.description}\nDeferred MCP definitions are returned by direct tool_search and become callable from the next model response, not later in the same response; they are not appended to this description.\nProgrammatic tools: ${directory}`
136
- }
137
- : tool);
138
- }
139
- /** Preserve native search definitions while providing the same discovery evidence to other protocols. */
140
- export function projectCodeModeSearchResult(message, codeModeEnabled) {
141
- if (!message.toolSearchTools)
142
- return message;
143
- if (!codeModeEnabled)
144
- return {
145
- ...message,
146
- toolSearchTools: message.toolSearchTools
147
- .filter((tool) => allowsToolCaller(tool, 'direct'))
148
- .map(stableToolDefinition)
149
- };
150
- const tools = message.toolSearchTools.map((tool) => ({
151
- ...(allowsToolCaller(tool, 'programmatic')
152
- ? {
153
- ...projectProgrammaticTool(tool),
154
- ...(allowsDirectTool(tool, true)
155
- ? { inputMode: tool.inputMode ?? 'json' }
156
- : {})
157
- }
158
- : {
159
- name: tool.name,
160
- description: tool.description,
161
- inputSchema: stableToolSchema(tool.inputSchema),
162
- inputMode: tool.inputMode ?? 'json'
163
- }),
164
- caller: allowsToolCaller(tool, 'programmatic')
165
- ? allowsDirectTool(tool, true)
166
- ? 'both'
167
- : 'programmatic'
168
- : 'direct'
169
- }));
170
- return {
171
- ...message,
172
- content: JSON.stringify({ tools }),
173
- toolSearchTools: tools.map(({ caller: _caller, ...tool }) => tool)
174
- };
175
- }
176
- function defaultEngineFactory() {
177
- const core = import.meta.resolve('quickjs-emscripten-core');
178
- const variant = import.meta.resolve('@jitl/quickjs-wasmfile-release-sync');
179
- const ffi = pathToFileURL(createRequire(core).resolve('@jitl/quickjs-ffi-types')).href;
180
- const dependencyRoot = (url) => {
181
- const root = dirname(dirname(fileURLToPath(url)));
182
- // pnpm's sibling dependencies are symlinks; keep the package-local node_modules tree visible.
183
- return root.includes(`${sep}.pnpm${sep}`) ? dirname(dirname(root)) : root;
184
- };
185
- return {
186
- moduleUrl: new URL('./quickjs-engine.js', import.meta.url).href,
187
- runtimeDirectories: [
188
- ...new Set([
189
- fileURLToPath(new URL('.', import.meta.url)),
190
- fileURLToPath(new URL('../input-diagnostics/', import.meta.url)),
191
- dependencyRoot(core),
192
- dependencyRoot(variant),
193
- dependencyRoot(ffi)
194
- ])
195
- ],
196
- options: { coreModuleUrl: core, variantModuleUrl: variant }
197
- };
198
- }
199
- const environmentKeys = [
200
- 'PATH',
201
- 'Path',
202
- 'SystemRoot',
203
- 'WINDIR',
204
- 'TEMP',
205
- 'TMP',
206
- 'LANG',
207
- 'LC_ALL',
208
- 'TZ'
209
- ];
210
- export class CodeModeTool {
211
- paths;
212
- environment;
213
- executor;
214
- engineFactory;
215
- #cells = new CodeCells();
216
- start(value, context) {
217
- return this.#cells.start(value, context, (code, detached, output) => this.execute(code, detached, output));
218
- }
219
- wait(value, context) {
220
- return this.#cells.wait(value, context);
221
- }
222
- listSessionResources(sessionId) {
223
- return this.#cells.snapshot(sessionId);
224
- }
225
- #active = new Map();
226
- constructor(paths, environment = {}, executor = directLocalProcessExecutor, engineFactory = defaultEngineFactory()) {
227
- this.paths = paths;
228
- this.environment = environment;
229
- this.executor = executor;
230
- this.engineFactory = engineFactory;
231
- }
232
- async execute(value, context, output) {
233
- const code = typeof value === 'string'
234
- ? value
235
- : value &&
236
- typeof value === 'object' &&
237
- !Array.isArray(value) &&
238
- Object.keys(value).length === 1 &&
239
- 'code' in value
240
- ? value.code
241
- : undefined;
242
- if (typeof code !== 'string' ||
243
- !code.trim() ||
244
- Buffer.byteLength(code) > limits.codeMaxInputBytes)
245
- throw new MarAgentError('MAR_AGENT_TOOL_INPUT_INVALID', 'Code must be a nonempty JavaScript string within the cell input limit.');
246
- if (!context.codeMode)
247
- throw new MarAgentError('MAR_AGENT_TOOL_NOT_AVAILABLE', 'Code Mode tool dispatch is unavailable.');
248
- context.signal.throwIfAborted();
249
- if (this.#active.size >= limits.codeMaxConcurrentCells)
250
- throw new MarAgentError('MAR_AGENT_PROCESS_LIMIT', `The Local Host shared running-cell limit (${limits.codeMaxConcurrentCells}) was reached.`);
251
- const controller = new AbortController();
252
- const signal = AbortSignal.any([context.signal, controller.signal]);
253
- let release;
254
- const done = new Promise((resolve) => {
255
- release = resolve;
256
- });
257
- this.#active.set(controller, { sessionId: context.sessionId, done });
258
- try {
259
- return await this.#run(code, { ...context, signal }, controller, output);
260
- }
261
- finally {
262
- this.#active.delete(controller);
263
- release();
264
- }
265
- }
266
- async dispose(sessionId) {
267
- await this.#cells.dispose(sessionId);
268
- const active = [...this.#active].filter(([, entry]) => sessionId === undefined || entry.sessionId === sessionId);
269
- for (const [controller] of active)
270
- controller.abort(new MarAgentError('MAR_AGENT_CODE_CANCELLED', 'Code Mode resources were released.'));
271
- await Promise.all(active.map(([, entry]) => entry.done));
272
- }
273
- async #run(code, context, controller, output) {
274
- const cwd = await this.paths.resolve('.');
275
- context.signal.throwIfAborted();
276
- const environment = Object.fromEntries(environmentKeys.flatMap((key) => {
277
- const value = this.environment[key];
278
- return value === undefined ? [] : [[key, value]];
279
- }));
280
- const child = await this.executor.spawn({
281
- command: process.execPath,
282
- args: [
283
- `--max-old-space-size=${limits.codeHeapMegabytes}`,
284
- '--input-type=module',
285
- '--eval',
286
- await readFile(new URL('./worker.js', import.meta.url), 'utf8')
287
- ],
288
- cwd,
289
- shell: false,
290
- environment,
291
- environmentKeys: Object.keys(environment),
292
- runtimeDirectories: this.engineFactory.runtimeDirectories,
293
- detached: process.platform !== 'win32',
294
- owner: { sessionId: context.sessionId, executionId: context.executionId },
295
- signal: context.signal
296
- });
297
- const text = new BoundedTextOutput(limits.codeMaxOutputBytes);
298
- const images = [];
299
- const observations = [];
300
- let observationBytes = 0;
301
- const appendObservation = (value, originalBytes) => {
302
- const capture = new BoundedTextOutput(Math.max(0, limits.codeMaxOutputBytes - observationBytes), '');
303
- const body = value.type === 'tool_result' ? value.result.content : value.value;
304
- capture.append(body);
305
- const bounded = capture.snapshot();
306
- observationBytes += bounded.retainedBytes;
307
- text.append(body, originalBytes ?? Buffer.byteLength(body));
308
- output?.text(body, originalBytes ?? Buffer.byteLength(body));
309
- const observation = value.type === 'tool_result'
310
- ? {
311
- ...value,
312
- result: {
313
- ...value.result,
314
- content: bounded.text,
315
- truncated: value.result.truncated === true || bounded.droppedBytes > 0
316
- }
317
- }
318
- : {
319
- ...value,
320
- value: bounded.text,
321
- truncated: value.truncated === true || bounded.droppedBytes > 0
322
- };
323
- observations.push(observation);
324
- output?.observe(observation);
325
- };
326
- const toolResults = new Map();
327
- let transportBytes = 0;
328
- let calls = 0;
329
- let complete = false;
330
- let stateMutations = [];
331
- let failure;
332
- let stderr = '';
333
- let buffered = '';
334
- const decoder = new StringDecoder('utf8');
335
- const seen = new Set();
336
- const pending = new Set();
337
- let exited;
338
- const exit = new Promise((resolve) => {
339
- exited = resolve;
340
- });
341
- const fail = (error) => {
342
- if (failure === undefined)
343
- failure = error;
344
- if (!controller.signal.aborted)
345
- controller.abort(error);
346
- };
347
- const abort = () => {
348
- if (failure === undefined)
349
- failure = context.signal.reason;
350
- void signalProcessTree(child, 'SIGKILL').catch((error) => {
351
- failure ??= error;
352
- });
353
- };
354
- context.signal.addEventListener('abort', abort, { once: true });
355
- const write = async (message) => {
356
- context.signal.throwIfAborted();
357
- const frame = JSON.stringify(message) + '\n';
358
- const bytes = Buffer.byteLength(frame);
359
- transportBytes += bytes;
360
- if (bytes > limits.codeMaxFrameBytes || transportBytes > limits.codeMaxTransportBytes)
361
- throw new MarAgentError('MAR_AGENT_TOOL_OUTPUT_LIMIT', 'Code Mode exceeded its message transfer limit.');
362
- await new Promise((resolve, reject) => {
363
- child.stdin.write(frame, (error) => (error ? reject(error) : resolve()));
364
- });
365
- };
366
- const invoke = createToolCallScheduler(context.codeMode.tools, async (call) => {
367
- context.signal.throwIfAborted();
368
- return context.codeMode.invoke(call, context.signal);
369
- });
370
- const available = new Set(context
371
- .codeMode.tools.filter((tool) => allowsToolCaller(tool, 'programmatic'))
372
- .map((tool) => tool.name));
373
- const receive = (frame) => {
374
- if (complete)
375
- throw new MarAgentError('MAR_AGENT_CODE_PROTOCOL_ERROR', 'Code Mode sent data after completion.');
376
- if (frame.kind === 'observe' && frame.observation && typeof frame.observation === 'object') {
377
- const value = frame.observation;
378
- if (observations.length >= 4096)
379
- throw new MarAgentError('MAR_AGENT_TOOL_OUTPUT_LIMIT', 'Too many Code Mode observations.');
380
- const addImage = (raw) => {
381
- if (!context.codeMode?.supportsImages)
382
- throw new MarAgentError('MAR_AGENT_INPUT_CAPABILITY_UNSUPPORTED', 'The current model cannot receive image observations.');
383
- const image = parseImage(raw);
384
- const index = images.length;
385
- images.push(image);
386
- output?.image(image);
387
- return index;
388
- };
389
- let observation;
390
- if (value.type === 'tool_result' && typeof value.operationId === 'string') {
391
- const original = toolResults.get(value.operationId);
392
- if (!original)
393
- throw new MarAgentError('MAR_AGENT_CODE_PROTOCOL_ERROR', 'Unknown observation source.');
394
- const bounded = {
395
- content: original.result.content,
396
- truncated: original.result.truncated === true
397
- };
398
- const indices = original.result.images?.map(addImage);
399
- const data = [
400
- 'apply_patch',
401
- 'todo_read',
402
- 'todo_write',
403
- 'agent_start',
404
- 'agent_wait',
405
- 'agent_message',
406
- 'agent_cancel'
407
- ].includes(original.source.toolName)
408
- ? original.result.data
409
- : undefined;
410
- observation = {
411
- type: 'tool_result',
412
- id: newObservationId(),
413
- source: original.source,
414
- outcome: original.outcome,
415
- result: {
416
- content: bounded.content,
417
- truncated: original.result.truncated === true || bounded.truncated,
418
- ...(data === undefined ? {} : { data }),
419
- ...(indices?.length ? { imageIndices: indices } : {})
420
- }
421
- };
422
- }
423
- else if (value.type === 'image') {
424
- observation = {
425
- type: 'value',
426
- id: newObservationId(),
427
- format: 'image',
428
- value: '',
429
- imageIndices: [addImage(value.value)]
430
- };
431
- }
432
- else if (value.type === 'value' &&
433
- typeof value.value === 'string' &&
434
- ['text', 'json'].includes(String(value.format))) {
435
- observation = {
436
- type: 'value',
437
- id: newObservationId(),
438
- format: value.format,
439
- value: value.value,
440
- truncated: typeof value.originalBytes === 'number' &&
441
- value.originalBytes > Buffer.byteLength(value.value)
442
- };
443
- }
444
- else
445
- throw new MarAgentError('MAR_AGENT_CODE_PROTOCOL_ERROR', 'Invalid observation frame.');
446
- appendObservation(observation, value.type === 'value' && typeof value.originalBytes === 'number'
447
- ? value.originalBytes
448
- : undefined);
449
- }
450
- else if (frame.kind === 'text' && typeof frame.value === 'string') {
451
- const originalBytes = frame.originalBytes ?? Buffer.byteLength(frame.value);
452
- if (!Number.isSafeInteger(originalBytes) ||
453
- originalBytes < Buffer.byteLength(frame.value))
454
- throw new MarAgentError('MAR_AGENT_CODE_PROTOCOL_ERROR', 'Code Mode sent invalid text byte counts.');
455
- appendObservation({
456
- type: 'value',
457
- id: newObservationId(),
458
- format: 'text',
459
- value: frame.value,
460
- truncated: originalBytes > Buffer.byteLength(frame.value)
461
- }, originalBytes);
462
- }
463
- else if (frame.kind === 'image') {
464
- if (!context.codeMode?.supportsImages)
465
- throw new MarAgentError('MAR_AGENT_INPUT_CAPABILITY_UNSUPPORTED', 'The current Code Mode context does not support image output.');
466
- const image = parseImage(frame.value);
467
- images.push(image);
468
- output?.image(image);
469
- appendObservation({
470
- type: 'value',
471
- id: newObservationId(),
472
- format: 'image',
473
- value: '',
474
- imageIndices: [images.length - 1]
475
- });
476
- }
477
- else if (frame.kind === 'yield') {
478
- output?.yield();
479
- }
480
- else if (frame.kind === 'call' &&
481
- Number.isSafeInteger(frame.id) &&
482
- typeof frame.name === 'string') {
483
- const id = frame.id;
484
- if (seen.has(id) || ++calls > limits.codeMaxCalls)
485
- throw new MarAgentError('MAR_AGENT_CODE_PROTOCOL_ERROR', 'Code Mode call ID or call count is invalid.');
486
- seen.add(id);
487
- const source = {
488
- callId: randomUUID(),
489
- toolName: frame.name,
490
- input: frame.arguments
491
- };
492
- const operationId = typeof frame.operationId === 'string' ? frame.operationId : String(id);
493
- const recordCall = (value) => output?.call(value);
494
- recordCall({ ...source, status: 'running' });
495
- const job = (async () => {
496
- try {
497
- if (frame.name === 'code_exec' || !available.has(frame.name))
498
- throw new MarAgentError('MAR_AGENT_TOOL_NOT_AVAILABLE', 'The requested nested tool is unavailable.');
499
- const rawOutput = await invoke({
500
- name: frame.name,
501
- arguments: frame.arguments,
502
- callId: source.callId
503
- });
504
- const { resultExtensions, ...output } = rawOutput;
505
- toolResults.set(operationId, { source, outcome: 'completed', result: output });
506
- recordCall({
507
- ...source,
508
- status: 'completed',
509
- ...(resultExtensions ? { resultExtensions } : {}),
510
- result: {
511
- content: '',
512
- truncated: output.truncated === true,
513
- data: [
514
- 'apply_patch',
515
- 'todo_read',
516
- 'todo_write',
517
- 'agent_start',
518
- 'agent_wait',
519
- 'agent_message',
520
- 'agent_cancel'
521
- ].includes(source.toolName)
522
- ? output.data
523
- : undefined
524
- }
525
- });
526
- const { content, ...structured } = output;
527
- const projected = output.data !== undefined && content === JSON.stringify(output.data)
528
- ? structured
529
- : output;
530
- await write({ id, ok: true, output: projected });
531
- }
532
- catch (error) {
533
- // Serialization/transport failures cannot undo an already completed tool call.
534
- if (toolResults.get(operationId)?.outcome === 'completed')
535
- throw error;
536
- if (context.signal.aborted)
537
- return;
538
- const diagnostic = describeMarAgentError(error, 'MAR_AGENT_HOST_OPERATION_FAILED');
539
- const data = structuredToolFailureData(source.toolName, error);
540
- recordCall({
541
- ...source,
542
- status: 'failed',
543
- ...(failedToolResultExtensions(error)
544
- ? { resultExtensions: failedToolResultExtensions(error) }
545
- : {}),
546
- error: { code: diagnostic.code, message: diagnostic.message }
547
- });
548
- const failureResult = {
549
- content: JSON.stringify({
550
- error: diagnostic.code,
551
- message: diagnostic.message,
552
- ...(data === undefined ? {} : { data })
553
- }),
554
- ...(data === undefined ? {} : { data })
555
- };
556
- const permissionStop = permissionStopFromError(error);
557
- if (isToolPermissionFailure(error))
558
- failureResult.data = { error: diagnostic.code, message: diagnostic.message };
559
- toolResults.set(operationId, { source, outcome: 'failed', result: failureResult });
560
- if (isToolPermissionFailure(error)) {
561
- await write({ id, ok: true, output: { data: failureResult.data } });
562
- return;
563
- }
564
- if (permissionStop) {
565
- fail(error);
566
- return;
567
- }
568
- await write({
569
- id,
570
- ok: false,
571
- error: {
572
- code: diagnostic.code,
573
- message: diagnostic.message
574
- }
575
- });
576
- }
577
- })().catch(fail);
578
- pending.add(job);
579
- void job.finally(() => pending.delete(job));
580
- }
581
- else if (frame.kind === 'done') {
582
- // Child completion cannot undo Host tool effects from calls it did not await.
583
- if (pending.size)
584
- throw new MarAgentError('MAR_AGENT_CODE_INCOMPLETE', 'Code Mode returned with unawaited tool calls; completed operations are not rolled back.');
585
- stateMutations = parseCodeModeStateMutations(frame.stateMutations);
586
- complete = true;
587
- void signalProcessTree(child, 'SIGKILL').catch(fail);
588
- }
589
- else if (frame.kind === 'error' && typeof frame.message === 'string') {
590
- throw new MarAgentError(typeof frame.code === 'string' ? frame.code.slice(0, 128) : 'MAR_AGENT_CODE_FAILED', frame.message.slice(0, 4096));
591
- }
592
- else
593
- throw new MarAgentError('MAR_AGENT_CODE_PROTOCOL_ERROR', 'Code Mode sent an invalid message.');
594
- };
595
- child.stdout.on('data', (chunk) => {
596
- if (context.signal.aborted)
597
- return;
598
- try {
599
- transportBytes += chunk.length;
600
- if (transportBytes > limits.codeMaxTransportBytes ||
601
- Buffer.byteLength(buffered) + chunk.length > limits.codeMaxFrameBytes)
602
- throw new MarAgentError('MAR_AGENT_TOOL_OUTPUT_LIMIT', 'Code Mode exceeded its message transfer limit.');
603
- buffered += decoder.write(chunk);
604
- let end;
605
- while ((end = buffered.indexOf('\n')) >= 0) {
606
- const line = buffered.slice(0, end);
607
- buffered = buffered.slice(end + 1);
608
- let frame;
609
- try {
610
- frame = JSON.parse(line);
611
- }
612
- catch {
613
- throw new MarAgentError('MAR_AGENT_CODE_PROTOCOL_ERROR', 'Code Mode sent invalid JSON.');
614
- }
615
- if (!frame || typeof frame !== 'object' || Array.isArray(frame))
616
- throw new MarAgentError('MAR_AGENT_CODE_PROTOCOL_ERROR', 'Code Mode sent an invalid message.');
617
- receive(frame);
618
- }
619
- }
620
- catch (error) {
621
- fail(error);
622
- }
623
- });
624
- child.stderr.on('data', (chunk) => {
625
- stderr = (stderr + chunk.toString('utf8')).slice(0, 4096);
626
- });
627
- child.stdin.on('error', (error) => {
628
- if (!complete)
629
- fail(error);
630
- });
631
- child.once('error', (error) => {
632
- fail(error);
633
- exited();
634
- });
635
- child.once('exit', (code, signal) => {
636
- if (code !== 0 && !complete && failure === undefined)
637
- failure = new MarAgentError('MAR_AGENT_CODE_FAILED', `Code Mode exited with ${signal ?? code}. ${stderr}`.trim());
638
- exited();
639
- });
640
- try {
641
- if (context.signal.aborted)
642
- abort();
643
- else
644
- await write({
645
- code,
646
- tools: [...available],
647
- catalog: context
648
- .codeMode.tools.filter((tool) => available.has(tool.name))
649
- .map((tool) => ({
650
- ...projectProgrammaticTool(tool),
651
- ...(tool.parameterless ? { parameterless: true } : {}),
652
- inputMode: tool.inputMode ?? 'json'
653
- })),
654
- state: context.codeMode.state ?? [],
655
- engine: this.engineFactory,
656
- limits: {
657
- memoryBytes: limits.codeMemoryBytes,
658
- stackBytes: limits.codeStackBytes,
659
- timeoutMs: limits.codeTimeoutMs,
660
- outputBytes: limits.codeMaxOutputBytes,
661
- stateEntries: limits.codeStateMaxEntries,
662
- stateMutations: limits.codeStateMaxMutations,
663
- stateKeyBytes: limits.codeStateMaxKeyBytes,
664
- stateValueBytes: limits.codeStateMaxValueBytes,
665
- stateTotalBytes: limits.codeStateMaxTotalBytes,
666
- sleepMs: limits.codeSleepMaxMs
667
- }
668
- });
669
- await exit;
670
- const permissionStop = context.codeMode?.permissionStop?.();
671
- if (permissionStop)
672
- throw new ToolPermissionStopError(permissionStop);
673
- if (failure !== undefined)
674
- throw failure;
675
- if (!complete)
676
- throw new MarAgentError('MAR_AGENT_CODE_INCOMPLETE', 'Code Mode exited without a completion message.');
677
- if (stateMutations.length)
678
- await context.codeMode.commitState?.(stateMutations);
679
- const captured = text.snapshot();
680
- return {
681
- content: observations.length
682
- ? renderObservations(observations)
683
- : renderCapturedText(captured, images.length) || '[]',
684
- observations,
685
- data: {
686
- toolCalls: calls,
687
- outputBytes: captured.originalBytes,
688
- outputDroppedBytes: captured.droppedBytes
689
- },
690
- truncated: captured.droppedBytes > 0,
691
- ...(images.length ? { images } : {})
692
- };
693
- }
694
- finally {
695
- controller.abort(new MarAgentError('MAR_AGENT_CODE_CANCELLED', 'Code Mode cell has ended.'));
696
- await signalProcessTree(child, 'SIGKILL');
697
- await exit;
698
- child.stdin.destroy();
699
- child.stdout.destroy();
700
- child.stderr.destroy();
701
- context.signal.removeEventListener('abort', abort);
702
- await Promise.allSettled(pending);
703
- }
704
- }
705
- }
706
- function parseImage(value) {
707
- const invalid = () => new MarAgentError('MAR_AGENT_IMAGE_FORMAT_UNSUPPORTED', 'Code Mode image must contain valid PNG, JPEG or WebP base64 with matching MIME.');
708
- if (!value || typeof value !== 'object' || Array.isArray(value))
709
- throw invalid();
710
- const image = value;
711
- if (Object.keys(image).some((key) => !['mimeType', 'dataBase64', 'url', 'urlExpiresAt', 'resourceId', 'byteSize'].includes(key)) ||
712
- typeof image.mimeType !== 'string' ||
713
- (image.resourceId !== undefined &&
714
- (typeof image.resourceId !== 'string' || !/^[a-f0-9]{64}$/u.test(image.resourceId))) ||
715
- (image.byteSize !== undefined &&
716
- (!Number.isSafeInteger(image.byteSize) || image.byteSize <= 0)) ||
717
- (image.url !== undefined && !isModelImageUrl(image.url)) ||
718
- (image.urlExpiresAt !== undefined &&
719
- (typeof image.urlExpiresAt !== 'number' ||
720
- !Number.isSafeInteger(image.urlExpiresAt) ||
721
- image.urlExpiresAt <= 0)))
722
- throw invalid();
723
- if (image.dataBase64 === undefined && isModelImageUrl(image.url))
724
- return {
725
- mimeType: image.mimeType,
726
- url: image.url,
727
- ...(image.urlExpiresAt === undefined ? {} : { urlExpiresAt: image.urlExpiresAt }),
728
- ...(typeof image.resourceId === 'string' ? { resourceId: image.resourceId } : {}),
729
- ...(typeof image.byteSize === 'number' ? { byteSize: image.byteSize } : {})
730
- };
731
- if (typeof image.dataBase64 !== 'string' ||
732
- image.dataBase64.length === 0 ||
733
- image.dataBase64.length > Math.ceil(limits.viewImageMaxBytes / 3) * 4 ||
734
- image.dataBase64.length % 4 !== 0)
735
- throw invalid();
736
- const bytes = Buffer.from(image.dataBase64, 'base64');
737
- if (bytes.length > limits.viewImageMaxBytes ||
738
- bytes.toString('base64') !== image.dataBase64 ||
739
- detectImageMime(bytes) !== image.mimeType)
740
- throw invalid();
741
- return {
742
- mimeType: image.mimeType,
743
- dataBase64: image.dataBase64,
744
- ...(typeof image.resourceId === 'string' ? { resourceId: image.resourceId } : {}),
745
- ...(typeof image.byteSize === 'number' ? { byteSize: image.byteSize } : {}),
746
- ...(image.url === undefined ? {} : { url: image.url }),
747
- ...(image.urlExpiresAt === undefined ? {} : { urlExpiresAt: image.urlExpiresAt })
748
- };
749
- }