operon-agents-core 0.1.0-alpha.0

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 (511) hide show
  1. package/LICENSE +55 -0
  2. package/README.md +7 -0
  3. package/dist/agent/agent.d.ts +65 -0
  4. package/dist/agent/agent.js +39 -0
  5. package/dist/agent/compose-hooks.d.ts +13 -0
  6. package/dist/agent/compose-hooks.js +197 -0
  7. package/dist/agent/concurrency.d.ts +22 -0
  8. package/dist/agent/concurrency.js +70 -0
  9. package/dist/agent/context-report.d.ts +60 -0
  10. package/dist/agent/context-report.js +45 -0
  11. package/dist/agent/graph.d.ts +48 -0
  12. package/dist/agent/graph.js +129 -0
  13. package/dist/agent/guardrail.d.ts +105 -0
  14. package/dist/agent/guardrail.js +314 -0
  15. package/dist/agent/handoff-executor.d.ts +21 -0
  16. package/dist/agent/handoff-executor.js +95 -0
  17. package/dist/agent/handoff.d.ts +42 -0
  18. package/dist/agent/handoff.js +70 -0
  19. package/dist/agent/index.d.ts +25 -0
  20. package/dist/agent/index.js +19 -0
  21. package/dist/agent/instruction-context.d.ts +33 -0
  22. package/dist/agent/instruction-context.js +100 -0
  23. package/dist/agent/pause.d.ts +12 -0
  24. package/dist/agent/pause.js +82 -0
  25. package/dist/agent/profile-builtins.d.ts +8 -0
  26. package/dist/agent/profile-builtins.js +130 -0
  27. package/dist/agent/profiles.d.ts +94 -0
  28. package/dist/agent/profiles.js +264 -0
  29. package/dist/agent/recovery.d.ts +10 -0
  30. package/dist/agent/recovery.js +151 -0
  31. package/dist/agent/run-support.d.ts +79 -0
  32. package/dist/agent/run-support.js +211 -0
  33. package/dist/agent/runner.d.ts +246 -0
  34. package/dist/agent/runner.js +786 -0
  35. package/dist/agent/session.d.ts +363 -0
  36. package/dist/agent/session.js +937 -0
  37. package/dist/agent/subagent-tools.d.ts +18 -0
  38. package/dist/agent/subagent-tools.js +650 -0
  39. package/dist/agent/subagent.d.ts +56 -0
  40. package/dist/agent/subagent.js +50 -0
  41. package/dist/agent/toolset.d.ts +24 -0
  42. package/dist/agent/toolset.js +112 -0
  43. package/dist/agent/workflow/index.d.ts +9 -0
  44. package/dist/agent/workflow/index.js +8 -0
  45. package/dist/agent/workflow/journal.d.ts +180 -0
  46. package/dist/agent/workflow/journal.js +224 -0
  47. package/dist/agent/workflow/manager.d.ts +27 -0
  48. package/dist/agent/workflow/manager.js +33 -0
  49. package/dist/agent/workflow/parse.d.ts +17 -0
  50. package/dist/agent/workflow/parse.js +174 -0
  51. package/dist/agent/workflow/prompt.d.ts +8 -0
  52. package/dist/agent/workflow/prompt.js +84 -0
  53. package/dist/agent/workflow/runtime.d.ts +64 -0
  54. package/dist/agent/workflow/runtime.js +380 -0
  55. package/dist/agent/workflow/sandbox.d.ts +35 -0
  56. package/dist/agent/workflow/sandbox.js +90 -0
  57. package/dist/agent/workflow/snapshot.d.ts +36 -0
  58. package/dist/agent/workflow/snapshot.js +9 -0
  59. package/dist/agent/workflow/structured.d.ts +35 -0
  60. package/dist/agent/workflow/structured.js +79 -0
  61. package/dist/agent/workflow/tool.d.ts +14 -0
  62. package/dist/agent/workflow/tool.js +569 -0
  63. package/dist/agent/workflow/types.d.ts +100 -0
  64. package/dist/agent/workflow/types.js +17 -0
  65. package/dist/agent/worktree.d.ts +38 -0
  66. package/dist/agent/worktree.js +56 -0
  67. package/dist/capabilities/assembler.d.ts +39 -0
  68. package/dist/capabilities/assembler.js +171 -0
  69. package/dist/capabilities/background/agent-task.d.ts +51 -0
  70. package/dist/capabilities/background/agent-task.js +101 -0
  71. package/dist/capabilities/background/command-task.d.ts +43 -0
  72. package/dist/capabilities/background/command-task.js +86 -0
  73. package/dist/capabilities/background/index.d.ts +20 -0
  74. package/dist/capabilities/background/index.js +57 -0
  75. package/dist/capabilities/background/manager.d.ts +194 -0
  76. package/dist/capabilities/background/manager.js +1131 -0
  77. package/dist/capabilities/background/persist-disk.d.ts +17 -0
  78. package/dist/capabilities/background/persist-disk.js +66 -0
  79. package/dist/capabilities/background/persist.d.ts +61 -0
  80. package/dist/capabilities/background/persist.js +117 -0
  81. package/dist/capabilities/background/question-task.d.ts +32 -0
  82. package/dist/capabilities/background/question-task.js +56 -0
  83. package/dist/capabilities/background/registrar.d.ts +12 -0
  84. package/dist/capabilities/background/registrar.js +9 -0
  85. package/dist/capabilities/background/swappable-sink.d.ts +20 -0
  86. package/dist/capabilities/background/swappable-sink.js +20 -0
  87. package/dist/capabilities/background/task.d.ts +114 -0
  88. package/dist/capabilities/background/task.js +20 -0
  89. package/dist/capabilities/background/tools.d.ts +6 -0
  90. package/dist/capabilities/background/tools.js +190 -0
  91. package/dist/capabilities/background/workflow-task.d.ts +48 -0
  92. package/dist/capabilities/background/workflow-task.js +91 -0
  93. package/dist/capabilities/capability-state.d.ts +13 -0
  94. package/dist/capabilities/capability-state.js +37 -0
  95. package/dist/capabilities/capability.d.ts +145 -0
  96. package/dist/capabilities/capability.js +2 -0
  97. package/dist/capabilities/compaction/full.d.ts +27 -0
  98. package/dist/capabilities/compaction/full.js +155 -0
  99. package/dist/capabilities/compaction/index.d.ts +17 -0
  100. package/dist/capabilities/compaction/index.js +145 -0
  101. package/dist/capabilities/compaction/instruction.d.ts +2 -0
  102. package/dist/capabilities/compaction/instruction.js +31 -0
  103. package/dist/capabilities/compaction/micro.d.ts +17 -0
  104. package/dist/capabilities/compaction/micro.js +57 -0
  105. package/dist/capabilities/compaction/service.d.ts +28 -0
  106. package/dist/capabilities/compaction/service.js +52 -0
  107. package/dist/capabilities/compaction/strategy.d.ts +43 -0
  108. package/dist/capabilities/compaction/strategy.js +116 -0
  109. package/dist/capabilities/compaction/tokens.d.ts +5 -0
  110. package/dist/capabilities/compaction/tokens.js +28 -0
  111. package/dist/capabilities/goal/goal-store.d.ts +69 -0
  112. package/dist/capabilities/goal/goal-store.js +172 -0
  113. package/dist/capabilities/goal/index.d.ts +6 -0
  114. package/dist/capabilities/goal/index.js +31 -0
  115. package/dist/capabilities/goal/injector.d.ts +9 -0
  116. package/dist/capabilities/goal/injector.js +79 -0
  117. package/dist/capabilities/goal/tools.d.ts +6 -0
  118. package/dist/capabilities/goal/tools.js +86 -0
  119. package/dist/capabilities/index.d.ts +25 -0
  120. package/dist/capabilities/index.js +22 -0
  121. package/dist/capabilities/injection.d.ts +44 -0
  122. package/dist/capabilities/injection.js +112 -0
  123. package/dist/capabilities/plan/index.d.ts +6 -0
  124. package/dist/capabilities/plan/index.js +25 -0
  125. package/dist/capabilities/plan/injector.d.ts +13 -0
  126. package/dist/capabilities/plan/injector.js +83 -0
  127. package/dist/capabilities/plan/plan-mode.d.ts +38 -0
  128. package/dist/capabilities/plan/plan-mode.js +113 -0
  129. package/dist/capabilities/plan/policies.d.ts +6 -0
  130. package/dist/capabilities/plan/policies.js +89 -0
  131. package/dist/capabilities/plan/tools.d.ts +15 -0
  132. package/dist/capabilities/plan/tools.js +87 -0
  133. package/dist/capabilities/skills/flow-provider.d.ts +6 -0
  134. package/dist/capabilities/skills/flow-provider.js +50 -0
  135. package/dist/capabilities/skills/index.d.ts +43 -0
  136. package/dist/capabilities/skills/index.js +48 -0
  137. package/dist/capabilities/skills/injector.d.ts +11 -0
  138. package/dist/capabilities/skills/injector.js +27 -0
  139. package/dist/capabilities/skills/parser.d.ts +36 -0
  140. package/dist/capabilities/skills/parser.js +334 -0
  141. package/dist/capabilities/skills/registry.d.ts +33 -0
  142. package/dist/capabilities/skills/registry.js +118 -0
  143. package/dist/capabilities/skills/scanner.d.ts +26 -0
  144. package/dist/capabilities/skills/scanner.js +154 -0
  145. package/dist/capabilities/skills/service.d.ts +39 -0
  146. package/dist/capabilities/skills/service.js +68 -0
  147. package/dist/capabilities/skills/skill-tool.d.ts +13 -0
  148. package/dist/capabilities/skills/skill-tool.js +72 -0
  149. package/dist/capabilities/skills/types.d.ts +62 -0
  150. package/dist/capabilities/skills/types.js +26 -0
  151. package/dist/capabilities/task/index.d.ts +23 -0
  152. package/dist/capabilities/task/index.js +38 -0
  153. package/dist/capabilities/task/injector.d.ts +9 -0
  154. package/dist/capabilities/task/injector.js +62 -0
  155. package/dist/capabilities/task/persist-disk.d.ts +19 -0
  156. package/dist/capabilities/task/persist-disk.js +84 -0
  157. package/dist/capabilities/task/persist.d.ts +52 -0
  158. package/dist/capabilities/task/persist.js +84 -0
  159. package/dist/capabilities/task/task-store.d.ts +44 -0
  160. package/dist/capabilities/task/task-store.js +106 -0
  161. package/dist/capabilities/task/tools.d.ts +12 -0
  162. package/dist/capabilities/task/tools.js +164 -0
  163. package/dist/capabilities/todo/index.d.ts +8 -0
  164. package/dist/capabilities/todo/index.js +21 -0
  165. package/dist/capabilities/todo/injector.d.ts +9 -0
  166. package/dist/capabilities/todo/injector.js +68 -0
  167. package/dist/capabilities/todo/todo-store.d.ts +19 -0
  168. package/dist/capabilities/todo/todo-store.js +36 -0
  169. package/dist/capabilities/todo/tools.d.ts +6 -0
  170. package/dist/capabilities/todo/tools.js +70 -0
  171. package/dist/capabilities/tool-provider.d.ts +12 -0
  172. package/dist/capabilities/tool-provider.js +20 -0
  173. package/dist/capabilities/user-hooks/engine.d.ts +22 -0
  174. package/dist/capabilities/user-hooks/engine.js +105 -0
  175. package/dist/capabilities/user-hooks/index.d.ts +13 -0
  176. package/dist/capabilities/user-hooks/index.js +126 -0
  177. package/dist/capabilities/user-hooks/types.d.ts +26 -0
  178. package/dist/capabilities/user-hooks/types.js +19 -0
  179. package/dist/capabilities/workflow/index.d.ts +16 -0
  180. package/dist/capabilities/workflow/index.js +15 -0
  181. package/dist/commands/index.d.ts +31 -0
  182. package/dist/commands/index.js +318 -0
  183. package/dist/config/config-store.d.ts +29 -0
  184. package/dist/config/config-store.js +103 -0
  185. package/dist/config/file-source.d.ts +40 -0
  186. package/dist/config/file-source.js +78 -0
  187. package/dist/config/flags.d.ts +13 -0
  188. package/dist/config/flags.js +25 -0
  189. package/dist/config/index.d.ts +17 -0
  190. package/dist/config/index.js +10 -0
  191. package/dist/config/merge.d.ts +5 -0
  192. package/dist/config/merge.js +57 -0
  193. package/dist/config/model-catalog.d.ts +17 -0
  194. package/dist/config/model-catalog.js +37 -0
  195. package/dist/config/paths.d.ts +31 -0
  196. package/dist/config/paths.js +28 -0
  197. package/dist/config/provider-manager.d.ts +57 -0
  198. package/dist/config/provider-manager.js +344 -0
  199. package/dist/config/resolver.d.ts +40 -0
  200. package/dist/config/resolver.js +52 -0
  201. package/dist/config/schema.d.ts +389 -0
  202. package/dist/config/schema.js +132 -0
  203. package/dist/events/events.d.ts +348 -0
  204. package/dist/events/events.js +146 -0
  205. package/dist/events/index.d.ts +10 -0
  206. package/dist/events/index.js +5 -0
  207. package/dist/events/projection.d.ts +207 -0
  208. package/dist/events/projection.js +438 -0
  209. package/dist/events/publisher.d.ts +48 -0
  210. package/dist/events/publisher.js +404 -0
  211. package/dist/events/redacting-sink.d.ts +11 -0
  212. package/dist/events/redacting-sink.js +31 -0
  213. package/dist/home.d.ts +16 -0
  214. package/dist/home.js +20 -0
  215. package/dist/index.d.ts +22 -0
  216. package/dist/index.js +22 -0
  217. package/dist/internal.d.ts +33 -0
  218. package/dist/internal.js +29 -0
  219. package/dist/llm/auth.d.ts +22 -0
  220. package/dist/llm/auth.js +112 -0
  221. package/dist/llm/capability.d.ts +13 -0
  222. package/dist/llm/capability.js +45 -0
  223. package/dist/llm/define-model.d.ts +110 -0
  224. package/dist/llm/define-model.js +252 -0
  225. package/dist/llm/errors.d.ts +33 -0
  226. package/dist/llm/errors.js +154 -0
  227. package/dist/llm/index.d.ts +14 -0
  228. package/dist/llm/index.js +8 -0
  229. package/dist/llm/model.d.ts +43 -0
  230. package/dist/llm/model.js +9 -0
  231. package/dist/llm/retry.d.ts +35 -0
  232. package/dist/llm/retry.js +160 -0
  233. package/dist/llm/runtime.d.ts +25 -0
  234. package/dist/llm/runtime.js +38 -0
  235. package/dist/logging/diagnostics.d.ts +21 -0
  236. package/dist/logging/diagnostics.js +46 -0
  237. package/dist/logging/index.d.ts +11 -0
  238. package/dist/logging/index.js +7 -0
  239. package/dist/logging/logger.d.ts +25 -0
  240. package/dist/logging/logger.js +54 -0
  241. package/dist/logging/paths.d.ts +11 -0
  242. package/dist/logging/paths.js +20 -0
  243. package/dist/logging/policy.d.ts +5 -0
  244. package/dist/logging/policy.js +19 -0
  245. package/dist/logging/redact.d.ts +10 -0
  246. package/dist/logging/redact.js +95 -0
  247. package/dist/logging/sinks.d.ts +67 -0
  248. package/dist/logging/sinks.js +117 -0
  249. package/dist/loop/context.d.ts +69 -0
  250. package/dist/loop/context.js +129 -0
  251. package/dist/loop/errors.d.ts +8 -0
  252. package/dist/loop/errors.js +27 -0
  253. package/dist/loop/events.d.ts +14 -0
  254. package/dist/loop/events.js +2 -0
  255. package/dist/loop/index.d.ts +10 -0
  256. package/dist/loop/index.js +7 -0
  257. package/dist/loop/interruption.d.ts +118 -0
  258. package/dist/loop/interruption.js +191 -0
  259. package/dist/loop/run-turn.d.ts +54 -0
  260. package/dist/loop/run-turn.js +203 -0
  261. package/dist/loop/scheduler.d.ts +18 -0
  262. package/dist/loop/scheduler.js +71 -0
  263. package/dist/loop/steer.d.ts +122 -0
  264. package/dist/loop/steer.js +209 -0
  265. package/dist/loop/tool-call.d.ts +41 -0
  266. package/dist/loop/tool-call.js +326 -0
  267. package/dist/loop/turn-step.d.ts +57 -0
  268. package/dist/loop/turn-step.js +298 -0
  269. package/dist/loop/types.d.ts +217 -0
  270. package/dist/loop/types.js +2 -0
  271. package/dist/loop/usage.d.ts +6 -0
  272. package/dist/loop/usage.js +44 -0
  273. package/dist/mcp/auth-tool.d.ts +12 -0
  274. package/dist/mcp/auth-tool.js +92 -0
  275. package/dist/mcp/capability.d.ts +7 -0
  276. package/dist/mcp/capability.js +91 -0
  277. package/dist/mcp/config-loader.d.ts +28 -0
  278. package/dist/mcp/config-loader.js +115 -0
  279. package/dist/mcp/filter.d.ts +18 -0
  280. package/dist/mcp/filter.js +35 -0
  281. package/dist/mcp/index.d.ts +23 -0
  282. package/dist/mcp/index.js +13 -0
  283. package/dist/mcp/manager.d.ts +51 -0
  284. package/dist/mcp/manager.js +412 -0
  285. package/dist/mcp/mock-transport.d.ts +40 -0
  286. package/dist/mcp/mock-transport.js +68 -0
  287. package/dist/mcp/oauth/callback-server.d.ts +14 -0
  288. package/dist/mcp/oauth/callback-server.js +122 -0
  289. package/dist/mcp/oauth/index.d.ts +9 -0
  290. package/dist/mcp/oauth/index.js +5 -0
  291. package/dist/mcp/oauth/provider.d.ts +39 -0
  292. package/dist/mcp/oauth/provider.js +121 -0
  293. package/dist/mcp/oauth/service.d.ts +34 -0
  294. package/dist/mcp/oauth/service.js +130 -0
  295. package/dist/mcp/oauth/store.d.ts +40 -0
  296. package/dist/mcp/oauth/store.js +134 -0
  297. package/dist/mcp/output.d.ts +12 -0
  298. package/dist/mcp/output.js +110 -0
  299. package/dist/mcp/provider.d.ts +7 -0
  300. package/dist/mcp/provider.js +56 -0
  301. package/dist/mcp/sdk-transport.d.ts +25 -0
  302. package/dist/mcp/sdk-transport.js +228 -0
  303. package/dist/mcp/server.d.ts +77 -0
  304. package/dist/mcp/server.js +120 -0
  305. package/dist/mcp/tool-naming.d.ts +4 -0
  306. package/dist/mcp/tool-naming.js +26 -0
  307. package/dist/mcp/types.d.ts +75 -0
  308. package/dist/mcp/types.js +2 -0
  309. package/dist/net/index.d.ts +3 -0
  310. package/dist/net/index.js +2 -0
  311. package/dist/net/proxy.d.ts +16 -0
  312. package/dist/net/proxy.js +42 -0
  313. package/dist/permission/auto-approver/index.d.ts +3 -0
  314. package/dist/permission/auto-approver/index.js +3 -0
  315. package/dist/permission/auto-approver/llm-auto-approver.d.ts +53 -0
  316. package/dist/permission/auto-approver/llm-auto-approver.js +122 -0
  317. package/dist/permission/auto-approver/prompts-data.d.ts +9 -0
  318. package/dist/permission/auto-approver/prompts-data.js +155 -0
  319. package/dist/permission/auto-approver/prompts.d.ts +18 -0
  320. package/dist/permission/auto-approver/prompts.js +40 -0
  321. package/dist/permission/auto-approver/transcript.d.ts +22 -0
  322. package/dist/permission/auto-approver/transcript.js +75 -0
  323. package/dist/permission/auto-approver/xml.d.ts +5 -0
  324. package/dist/permission/auto-approver/xml.js +25 -0
  325. package/dist/permission/index.d.ts +7 -0
  326. package/dist/permission/index.js +5 -0
  327. package/dist/permission/manager.d.ts +74 -0
  328. package/dist/permission/manager.js +162 -0
  329. package/dist/permission/matches-rule.d.ts +27 -0
  330. package/dist/permission/matches-rule.js +54 -0
  331. package/dist/permission/policies.d.ts +14 -0
  332. package/dist/permission/policies.js +233 -0
  333. package/dist/permission/types.d.ts +84 -0
  334. package/dist/permission/types.js +2 -0
  335. package/dist/plugins/archive.d.ts +3 -0
  336. package/dist/plugins/archive.js +58 -0
  337. package/dist/plugins/github-resolver.d.ts +13 -0
  338. package/dist/plugins/github-resolver.js +20 -0
  339. package/dist/plugins/hooks.d.ts +28 -0
  340. package/dist/plugins/hooks.js +296 -0
  341. package/dist/plugins/index.d.ts +23 -0
  342. package/dist/plugins/index.js +23 -0
  343. package/dist/plugins/injector.d.ts +11 -0
  344. package/dist/plugins/injector.js +32 -0
  345. package/dist/plugins/manager.d.ts +37 -0
  346. package/dist/plugins/manager.js +330 -0
  347. package/dist/plugins/manifest.d.ts +9 -0
  348. package/dist/plugins/manifest.js +234 -0
  349. package/dist/plugins/marketplace.d.ts +85 -0
  350. package/dist/plugins/marketplace.js +205 -0
  351. package/dist/plugins/source.d.ts +23 -0
  352. package/dist/plugins/source.js +87 -0
  353. package/dist/plugins/store.d.ts +20 -0
  354. package/dist/plugins/store.js +30 -0
  355. package/dist/plugins/types.d.ts +118 -0
  356. package/dist/plugins/types.js +5 -0
  357. package/dist/protocol/index.d.ts +4 -0
  358. package/dist/protocol/index.js +2 -0
  359. package/dist/protocol/tool-schema.d.ts +6 -0
  360. package/dist/protocol/tool-schema.js +2 -0
  361. package/dist/store/blob-store.d.ts +45 -0
  362. package/dist/store/blob-store.js +120 -0
  363. package/dist/store/catalog-store.d.ts +32 -0
  364. package/dist/store/catalog-store.js +73 -0
  365. package/dist/store/disk-store.d.ts +58 -0
  366. package/dist/store/disk-store.js +369 -0
  367. package/dist/store/index.d.ts +23 -0
  368. package/dist/store/index.js +15 -0
  369. package/dist/store/lock.d.ts +86 -0
  370. package/dist/store/lock.js +104 -0
  371. package/dist/store/log-store.d.ts +89 -0
  372. package/dist/store/log-store.js +296 -0
  373. package/dist/store/migrate.d.ts +26 -0
  374. package/dist/store/migrate.js +32 -0
  375. package/dist/store/origin.d.ts +89 -0
  376. package/dist/store/origin.js +16 -0
  377. package/dist/store/pg.d.ts +90 -0
  378. package/dist/store/pg.js +344 -0
  379. package/dist/store/redacting-store.d.ts +21 -0
  380. package/dist/store/redacting-store.js +46 -0
  381. package/dist/store/redis.d.ts +89 -0
  382. package/dist/store/redis.js +370 -0
  383. package/dist/store/repository.d.ts +150 -0
  384. package/dist/store/repository.js +508 -0
  385. package/dist/store/session-catalog.d.ts +32 -0
  386. package/dist/store/session-catalog.js +117 -0
  387. package/dist/store/storage.d.ts +27 -0
  388. package/dist/store/storage.js +54 -0
  389. package/dist/store/store.d.ts +262 -0
  390. package/dist/store/store.js +129 -0
  391. package/dist/store/workdir-key.d.ts +4 -0
  392. package/dist/store/workdir-key.js +28 -0
  393. package/dist/tool/access.d.ts +37 -0
  394. package/dist/tool/access.js +79 -0
  395. package/dist/tool/ask.d.ts +22 -0
  396. package/dist/tool/ask.js +38 -0
  397. package/dist/tool/background.d.ts +109 -0
  398. package/dist/tool/background.js +39 -0
  399. package/dist/tool/builtin/ask-user-question.d.ts +2 -0
  400. package/dist/tool/builtin/ask-user-question.js +175 -0
  401. package/dist/tool/builtin/bash.d.ts +2 -0
  402. package/dist/tool/builtin/bash.js +407 -0
  403. package/dist/tool/builtin/edit.d.ts +2 -0
  404. package/dist/tool/builtin/edit.js +202 -0
  405. package/dist/tool/builtin/glob.d.ts +3 -0
  406. package/dist/tool/builtin/glob.js +260 -0
  407. package/dist/tool/builtin/grep.d.ts +2 -0
  408. package/dist/tool/builtin/grep.js +574 -0
  409. package/dist/tool/builtin/line-endings.d.ts +10 -0
  410. package/dist/tool/builtin/line-endings.js +41 -0
  411. package/dist/tool/builtin/read.d.ts +28 -0
  412. package/dist/tool/builtin/read.js +498 -0
  413. package/dist/tool/builtin/write.d.ts +2 -0
  414. package/dist/tool/builtin/write.js +179 -0
  415. package/dist/tool/define.d.ts +46 -0
  416. package/dist/tool/define.js +45 -0
  417. package/dist/tool/file-freshness.d.ts +81 -0
  418. package/dist/tool/file-freshness.js +67 -0
  419. package/dist/tool/filesystem-tools.d.ts +16 -0
  420. package/dist/tool/filesystem-tools.js +19 -0
  421. package/dist/tool/git-context.d.ts +20 -0
  422. package/dist/tool/git-context.js +114 -0
  423. package/dist/tool/index.d.ts +37 -0
  424. package/dist/tool/index.js +34 -0
  425. package/dist/tool/machine-base.d.ts +138 -0
  426. package/dist/tool/machine-base.js +388 -0
  427. package/dist/tool/machine-local.d.ts +35 -0
  428. package/dist/tool/machine-local.js +316 -0
  429. package/dist/tool/machine-null.d.ts +36 -0
  430. package/dist/tool/machine-null.js +64 -0
  431. package/dist/tool/machine-ssh.d.ts +86 -0
  432. package/dist/tool/machine-ssh.js +576 -0
  433. package/dist/tool/machine.d.ts +333 -0
  434. package/dist/tool/machine.js +15 -0
  435. package/dist/tool/policies/path-access.d.ts +48 -0
  436. package/dist/tool/policies/path-access.js +186 -0
  437. package/dist/tool/policies/sensitive.d.ts +3 -0
  438. package/dist/tool/policies/sensitive.js +60 -0
  439. package/dist/tool/questions.d.ts +40 -0
  440. package/dist/tool/questions.js +8 -0
  441. package/dist/tool/search/activation.d.ts +13 -0
  442. package/dist/tool/search/activation.js +31 -0
  443. package/dist/tool/search/deferral.d.ts +37 -0
  444. package/dist/tool/search/deferral.js +128 -0
  445. package/dist/tool/search/search-tool.d.ts +9 -0
  446. package/dist/tool/search/search-tool.js +62 -0
  447. package/dist/tool/shell-env.d.ts +9 -0
  448. package/dist/tool/shell-env.js +34 -0
  449. package/dist/tool/support/bash-destructive.d.ts +24 -0
  450. package/dist/tool/support/bash-destructive.js +63 -0
  451. package/dist/tool/support/bash-paths.d.ts +7 -0
  452. package/dist/tool/support/bash-paths.js +247 -0
  453. package/dist/tool/support/bash-read-only.d.ts +8 -0
  454. package/dist/tool/support/bash-read-only.js +165 -0
  455. package/dist/tool/support/bash-rule-match.d.ts +20 -0
  456. package/dist/tool/support/bash-rule-match.js +191 -0
  457. package/dist/tool/support/file-type.d.ts +10 -0
  458. package/dist/tool/support/file-type.js +149 -0
  459. package/dist/tool/support/git-worktree.d.ts +10 -0
  460. package/dist/tool/support/git-worktree.js +63 -0
  461. package/dist/tool/support/image-compress.d.ts +69 -0
  462. package/dist/tool/support/image-compress.js +265 -0
  463. package/dist/tool/support/machine-ops.d.ts +34 -0
  464. package/dist/tool/support/machine-ops.js +34 -0
  465. package/dist/tool/support/path-glob-match.d.ts +12 -0
  466. package/dist/tool/support/path-glob-match.js +84 -0
  467. package/dist/tool/support/result-builder.d.ts +27 -0
  468. package/dist/tool/support/result-builder.js +108 -0
  469. package/dist/tool/support/rg-locator.d.ts +20 -0
  470. package/dist/tool/support/rg-locator.js +42 -0
  471. package/dist/tool/support/ripgrep-run.d.ts +65 -0
  472. package/dist/tool/support/ripgrep-run.js +40 -0
  473. package/dist/tool/support/rule-match.d.ts +6 -0
  474. package/dist/tool/support/rule-match.js +23 -0
  475. package/dist/tool/support/tool-path.d.ts +8 -0
  476. package/dist/tool/support/tool-path.js +28 -0
  477. package/dist/tool/support/workspace.d.ts +5 -0
  478. package/dist/tool/support/workspace.js +2 -0
  479. package/dist/tool/types.d.ts +131 -0
  480. package/dist/tool/types.js +2 -0
  481. package/dist/tool/web/fetch-url.d.ts +4 -0
  482. package/dist/tool/web/fetch-url.js +61 -0
  483. package/dist/tool/web/index.d.ts +11 -0
  484. package/dist/tool/web/index.js +7 -0
  485. package/dist/tool/web/providers/direct-fetch.d.ts +33 -0
  486. package/dist/tool/web/providers/direct-fetch.js +198 -0
  487. package/dist/tool/web/providers/firecrawl.d.ts +16 -0
  488. package/dist/tool/web/providers/firecrawl.js +59 -0
  489. package/dist/tool/web/providers/tavily.d.ts +14 -0
  490. package/dist/tool/web/providers/tavily.js +43 -0
  491. package/dist/tool/web/types.d.ts +41 -0
  492. package/dist/tool/web/types.js +7 -0
  493. package/dist/tool/web/web-search.d.ts +4 -0
  494. package/dist/tool/web/web-search.js +68 -0
  495. package/dist/tool/workspace-spec.d.ts +74 -0
  496. package/dist/tool/workspace-spec.js +177 -0
  497. package/dist/tracing/bridge.d.ts +7 -0
  498. package/dist/tracing/bridge.js +171 -0
  499. package/dist/tracing/index.d.ts +9 -0
  500. package/dist/tracing/index.js +5 -0
  501. package/dist/tracing/otel.d.ts +38 -0
  502. package/dist/tracing/otel.js +221 -0
  503. package/dist/tracing/processor.d.ts +47 -0
  504. package/dist/tracing/processor.js +94 -0
  505. package/dist/tracing/spans.d.ts +94 -0
  506. package/dist/tracing/spans.js +56 -0
  507. package/dist/ui/ai-sdk.d.ts +114 -0
  508. package/dist/ui/ai-sdk.js +175 -0
  509. package/dist/ui/index.d.ts +2 -0
  510. package/dist/ui/index.js +2 -0
  511. package/package.json +101 -0
@@ -0,0 +1,54 @@
1
+ import { DiskSessionRepository, MemorySessionRepository } from "./repository.js";
2
+ /** Default workdir for an anonymous {@link SessionStorage.scratch} session. */
3
+ const SCRATCH_WORKDIR = "/";
4
+ /** Adapts a bare {@link SessionRepository} into the public {@link SessionStorage} door. */
5
+ class RepositoryStorage {
6
+ repo;
7
+ constructor(repo) {
8
+ this.repo = repo;
9
+ }
10
+ create(input) {
11
+ return this.repo.create(input);
12
+ }
13
+ open(id, options) {
14
+ return this.repo.open(id, options);
15
+ }
16
+ get(id) {
17
+ return this.repo.get(id);
18
+ }
19
+ list(filter) {
20
+ return this.repo.list(filter);
21
+ }
22
+ fork(sourceId, input) {
23
+ return this.repo.fork(sourceId, input);
24
+ }
25
+ delete(id, options) {
26
+ return this.repo.delete(id, options);
27
+ }
28
+ restore(id) {
29
+ return this.repo.restore(id);
30
+ }
31
+ async scratch(workDir = SCRATCH_WORKDIR) {
32
+ return (await this.repo.create({ workDir })).store;
33
+ }
34
+ async close() {
35
+ // Forward to the repository if it owns resources (pg/redis do); memory/disk don't.
36
+ await this.repo.close?.();
37
+ }
38
+ }
39
+ /**
40
+ * Wrap a bare {@link SessionRepository} as the public {@link SessionStorage} door. Used by the
41
+ * built-in factories and by add-on backings (pg/redis) so they don't re-implement scratch/close.
42
+ */
43
+ export function storageOver(repo) {
44
+ return new RepositoryStorage(repo);
45
+ }
46
+ /** In-process storage: sessions, stores, and blobs live in memory (gone on restart). */
47
+ export function memoryStorage() {
48
+ return storageOver(new MemorySessionRepository());
49
+ }
50
+ /** Filesystem storage rooted at `homeDir` (sharded logs + state.json + blobs per session). */
51
+ export function diskStorage(homeDir) {
52
+ return storageOver(new DiskSessionRepository(homeDir));
53
+ }
54
+ //# sourceMappingURL=storage.js.map
@@ -0,0 +1,262 @@
1
+ import type { ImageContent, Message, TextContent, Usage } from "../protocol/index.ts";
2
+ import type { ExternalPromptOrigin, PromptOrigin } from "./origin.ts";
3
+ /**
4
+ * A record in a session's append log. The log is a FLAT, linear, append-only stream
5
+ * — NOT a tree. Each address has its own shard; a shard's
6
+ * conversation context is its records read in append order and reduced (see `reduceHistory`).
7
+ *
8
+ * The first record of every shard is `metadata` (protocol version + creation time); the store
9
+ * prepends it automatically on the first append (see `SessionStore.appendRecord`).
10
+ */
11
+ export type AgentRecord = {
12
+ readonly type: string;
13
+ /** Public identity of the AgentEvent projected from this record. Records that have no
14
+ * AgentEvent projection (metadata/config/etc.) omit it. */
15
+ readonly eventId?: string;
16
+ /** Wall-clock stamp (ms). Set by the store if the writer omitted it. */
17
+ readonly time?: number;
18
+ /** Which conversation shard this record belongs to (defaults to `main`). */
19
+ readonly address?: string;
20
+ } & AgentRecordBody;
21
+ export type AgentRecordBody = {
22
+ readonly type: "metadata";
23
+ readonly protocol_version: number;
24
+ readonly created_at: number;
25
+ } | {
26
+ readonly type: "context.append_message";
27
+ readonly message: Message;
28
+ readonly origin?: PromptOrigin;
29
+ } | {
30
+ readonly type: "context.replace";
31
+ readonly messages: readonly Message[];
32
+ readonly origins?: readonly (PromptOrigin | null)[];
33
+ } | {
34
+ readonly type: "context.apply_compaction";
35
+ readonly summary: string;
36
+ /** Timestamp of the live summary message, so cold replay rebuilds it byte-for-byte. */
37
+ readonly summaryTimestamp?: number;
38
+ readonly cutoff: number;
39
+ readonly compactedCount: number;
40
+ readonly tokensBefore: number;
41
+ readonly tokensAfter: number;
42
+ } | {
43
+ readonly type: "inbox.received";
44
+ readonly input: string;
45
+ readonly origin: ExternalPromptOrigin;
46
+ /** Delivery mode as accepted — `steer` targets a running turn, `follow_up` queues after it. */
47
+ readonly mode: "auto" | "steer" | "follow_up";
48
+ } | {
49
+ readonly type: "custom_message";
50
+ readonly customType: string;
51
+ readonly content: string | (TextContent | ImageContent)[];
52
+ readonly display: boolean;
53
+ readonly details?: unknown;
54
+ readonly origin?: PromptOrigin;
55
+ } | {
56
+ readonly type: "usage.record";
57
+ readonly model?: string;
58
+ /** Per-turn usage retained for audit/cost aggregation. */
59
+ readonly usage: Usage;
60
+ /** Run-total usage at this boundary, projected as `usage.updated`. */
61
+ readonly total?: Usage;
62
+ } | {
63
+ readonly type: "permission.record_approval";
64
+ readonly toolCallId: string;
65
+ readonly toolName: string;
66
+ readonly decision: string;
67
+ readonly feedback?: string;
68
+ /** The approval-rule subject of the approved call — the pattern an
69
+ * `approve for session` grant memorizes. */
70
+ readonly approvalRule?: string;
71
+ /** "session" when the user granted approve-for-session; folded back into the
72
+ * session's approval-pattern set on reopen. */
73
+ readonly scope?: string;
74
+ } | {
75
+ readonly type: "permission.set_mode";
76
+ readonly mode: string;
77
+ } | {
78
+ readonly type: "config.update";
79
+ readonly model?: string;
80
+ readonly thinking?: string;
81
+ readonly tools?: readonly string[];
82
+ }
83
+ /** Durable commit record for transferring the conversation head to a new root shard. */
84
+ | {
85
+ readonly type: "agent.handoff";
86
+ readonly from: string;
87
+ readonly to: string;
88
+ /** Absent on legacy audit-only records, which cannot move the durable conversation head. */
89
+ readonly handoffId?: string;
90
+ readonly toAddress?: string;
91
+ readonly seedCount?: number;
92
+ }
93
+ /** Written to the target shard before the source-side `agent.handoff` commit record. */
94
+ | {
95
+ readonly type: "agent.handoff.accepted";
96
+ readonly handoffId: string;
97
+ readonly from: string;
98
+ readonly to: string;
99
+ readonly fromAddress: string;
100
+ readonly seedCount: number;
101
+ } | {
102
+ readonly type: "guardrail.blocked";
103
+ readonly stage: "input" | "output" | "tool_input" | "tool_output";
104
+ readonly guardrail: string;
105
+ readonly agent?: string;
106
+ readonly turnId?: string;
107
+ readonly step?: number;
108
+ readonly stepId?: string;
109
+ readonly message: string;
110
+ /** Present only when a newly submitted input was rejected before entering model history. */
111
+ readonly input?: readonly Message[];
112
+ }
113
+ /** Low-frequency lifecycle needed to reconstruct current UI state from events.list().
114
+ * Token deltas and tool progress remain live-only; message/tool payloads continue to live
115
+ * in their canonical context records instead of being duplicated here. */
116
+ | {
117
+ readonly type: "event.lifecycle";
118
+ readonly event: import("../events/events.ts").PersistedLifecycleEvent;
119
+ } | {
120
+ readonly type: "custom";
121
+ readonly name: string;
122
+ readonly data: unknown;
123
+ };
124
+ /**
125
+ * THE STORAGE RULE — what lives where:
126
+ *
127
+ * - The append log (①) is the record for CONVERSATION-derived state. Anything whose loss
128
+ * loses conversation information — history, audit — is a record, and its current-state
129
+ * views are REDUCTIONS of it (a forward pass over the shard's records).
130
+ * - BACKGROUND-TASK lifecycle is the one deliberate exception: a background task's status
131
+ * (running → completed/failed/lost) lives in a dedicated per-task store, NOT a reduction of
132
+ * the log — disk sessions keep it under `<sessionDir>/tasks/<id>/`, other backends in KV
133
+ * state (see capabilities/background/persist.ts). This is what lets a task orphaned by a dead
134
+ * process be reconciled to `lost` on reopen. The spawn ack + settle notification stay in the
135
+ * log as the model-facing conversation record, but are no longer the reconcile source of
136
+ * truth. `session.listSubagents()`/`listWorkflows()` PROJECT that task store — a foreground
137
+ * subagent/workflow is a plain tool call (conversation + its own shard), never a task.
138
+ * - KV state (②) may hold only (a) handles to external systems (`machine`), (b)
139
+ * rebuildable foreground control state (`interrupt`), (c) capability current-state (goal/plan/permission/
140
+ * config/cron/subagents), and (d) the background task store on non-disk backends. If deleting
141
+ * a KV key would lose information not recoverable elsewhere, that information belonged in the
142
+ * log or the task store.
143
+ * - The Machine filesystem holds work products (process logs, plan drafts) —
144
+ * cache-grade relative to the log; harvest what must outlive it into a record.
145
+ * - Pure runtime (live output tails) is not storage at all: its durable record is the
146
+ * entity it drives.
147
+ */
148
+ export type StateKey = "interrupt" | "meta" | "machine" | "cron" | (string & {});
149
+ export interface ReadRecordsFilter {
150
+ readonly address?: string;
151
+ }
152
+ /** One durable append-log record together with its store-assigned position.
153
+ * `sequence` is stable for the lifetime of the session: rewrites may migrate or
154
+ * offload `record`, but must never renumber it. Gaps are valid. */
155
+ export interface StoredAgentRecord {
156
+ readonly sequence: string;
157
+ readonly record: AgentRecord;
158
+ }
159
+ export type RecordOrder = "asc" | "desc";
160
+ /** Cursor pagination over the session-wide append order. `after` is exclusive and
161
+ * interpreted in the requested traversal direction (`>` for asc, `<` for desc). */
162
+ export interface ReadRecordPageOptions extends ReadRecordsFilter {
163
+ readonly limit: number;
164
+ readonly after?: string;
165
+ readonly order?: RecordOrder;
166
+ }
167
+ export interface RecordPage {
168
+ readonly data: readonly StoredAgentRecord[];
169
+ /** Sequence of the last returned record when another page exists. */
170
+ readonly next?: string;
171
+ }
172
+ export interface WatchRecordsOptions {
173
+ /** Resume after this sequence. Omit to start from the beginning of the log. */
174
+ readonly after?: string;
175
+ readonly address?: string;
176
+ /** Stop watching. The iterable ends; it does not throw. */
177
+ readonly signal?: AbortSignal;
178
+ /** Idle delay between polls for the generic implementation. Ignored by push backends. */
179
+ readonly pollMs?: number;
180
+ }
181
+ export interface SessionStore {
182
+ appendRecord(record: AgentRecord): Promise<string>;
183
+ readRecords(filter?: ReadRecordsFilter): AsyncIterable<AgentRecord>;
184
+ readRecordPage(options: ReadRecordPageOptions): Promise<RecordPage>;
185
+ putState(key: StateKey, value: unknown): Promise<void>;
186
+ getState(key: StateKey): Promise<unknown | null>;
187
+ deleteState(key: StateKey): Promise<void>;
188
+ /** Every key currently present in ② (optional; all in-repo backends implement it). Lets a
189
+ * generic fork copy the FULL state instead of a hardcoded key list — without it, fork
190
+ * falls back to the known-handles subset and backend-specific keys (bg:*, goal, …) are lost. */
191
+ listStateKeys?(): Promise<readonly StateKey[]>;
192
+ /**
193
+ * Follow the log from `after` onwards, yielding records as they land (optional).
194
+ *
195
+ * A reader that is not the writer — an out-of-process transport tailing a session, or a runner
196
+ * looking for sessions with unprocessed input — otherwise has to poll `readRecordPage` itself.
197
+ * `watchRecords` is the generic form of that loop, so every backend has one for free; a backend
198
+ * with a native push (Postgres `LISTEN/NOTIFY`, a Redis stream) overrides it to avoid the
199
+ * polling interval entirely.
200
+ *
201
+ * NOT a delivery channel for live UI. Fan-out to connected clients belongs in a broadcast path
202
+ * the writer publishes to; a store is the source of truth, and using it as a message bus makes
203
+ * its read load scale with connected viewers rather than with data.
204
+ */
205
+ watch?(options: WatchRecordsOptions): AsyncIterable<StoredAgentRecord>;
206
+ flush?(): Promise<void>;
207
+ close?(): Promise<void>;
208
+ rewrite?(address?: string): Promise<void>;
209
+ /** The filesystem directory this store is backed by, when it has one (disk sessions).
210
+ * Lets adjuncts that want a real directory — e.g. the background task store's
211
+ * `<dir>/tasks/<id>/` layout — co-locate under the session's home; undefined for
212
+ * in-memory / remote-KV backends, which fall back to KV-state persistence. */
213
+ storageDir?(): string | undefined;
214
+ }
215
+ export declare const DEFAULT_ADDRESS = "main";
216
+ interface ReducedHistory {
217
+ readonly messages: Message[];
218
+ readonly origins: (PromptOrigin | undefined)[];
219
+ }
220
+ /**
221
+ * Reduce a shard's records (append order) into live history, in a single forward pass.
222
+ *
223
+ * History-bearing records (`context.append_message` / `custom_message`) append a message;
224
+ * `context.replace` resets the list; `context.apply_compaction` drops the first `cutoff`
225
+ * messages and prepends the summary. Everything else (metadata / usage / approval / config /
226
+ * handoff / custom) is audit/bookkeeping and never enters history.
227
+ */
228
+ /**
229
+ * The mutable pair every history fold maintains. `origins[i]` describes `messages[i]`.
230
+ *
231
+ * Exists so replay (folding RECORDS) and any live consumer (folding EVENTS) can share the
232
+ * three operations below rather than each implementing history semantics. They are the same
233
+ * semantics reached through two different doors; implemented twice they drift, and the drift
234
+ * shows up as "the transcript changed after a reopen" — the hardest kind to notice.
235
+ */
236
+ export interface HistoryFold {
237
+ messages: Message[];
238
+ origins: (PromptOrigin | undefined)[];
239
+ }
240
+ /** Append one message. */
241
+ export declare function foldAppend(state: HistoryFold, message: Message, origin?: PromptOrigin): void;
242
+ /** Reset the list to `messages` (micro-compaction's trim commits through this). */
243
+ export declare function foldReplace(state: HistoryFold, messages: readonly Message[], origins?: readonly (PromptOrigin | null)[]): void;
244
+ /** Drop the first `cutoff` messages and prepend the summary in their place. */
245
+ export declare function foldCompaction(state: HistoryFold, cutoff: number, summary: string, summaryTimestamp?: number): void;
246
+ export declare function reduceHistory(records: readonly AgentRecord[]): ReducedHistory;
247
+ export declare function summaryMessage(summary: string, timestamp?: number): Message;
248
+ export declare function customMessage(content: string | (TextContent | ImageContent)[], timestamp?: number): Message;
249
+ /**
250
+ * Follow a store's log by polling — the generic `SessionStore.watch` every backend inherits.
251
+ *
252
+ * Drains everything already past `after` before waiting, so a watcher that starts on a busy
253
+ * session catches up at page speed rather than one poll interval per page. Sequences are
254
+ * allocated monotonically and the log is append-only, so the cursor never needs to move
255
+ * backwards and a record is never yielded twice.
256
+ *
257
+ * Prefer a backend's native push where one exists: this trades latency (up to `pollMs`) and a
258
+ * steady query rate for working anywhere.
259
+ */
260
+ export declare function watchRecordsByPolling(store: SessionStore, options?: WatchRecordsOptions): AsyncIterable<StoredAgentRecord>;
261
+ export {};
262
+ //# sourceMappingURL=store.d.ts.map
@@ -0,0 +1,129 @@
1
+ export const DEFAULT_ADDRESS = "main";
2
+ /** Append one message. */
3
+ export function foldAppend(state, message, origin) {
4
+ state.messages.push(message);
5
+ state.origins.push(origin);
6
+ }
7
+ /** Reset the list to `messages` (micro-compaction's trim commits through this). */
8
+ export function foldReplace(state, messages, origins) {
9
+ state.messages.splice(0, state.messages.length, ...messages);
10
+ const next = origins?.map((origin) => origin ?? undefined) ?? messages.map(() => undefined);
11
+ state.origins.splice(0, state.origins.length, ...next.slice(0, messages.length));
12
+ while (state.origins.length < state.messages.length)
13
+ state.origins.push(undefined);
14
+ }
15
+ /** Drop the first `cutoff` messages and prepend the summary in their place. */
16
+ export function foldCompaction(state, cutoff, summary, summaryTimestamp) {
17
+ const clamped = Math.min(cutoff, state.messages.length);
18
+ state.messages.splice(0, clamped, summaryMessage(summary, summaryTimestamp));
19
+ state.origins.splice(0, clamped, { kind: "compaction_summary" });
20
+ }
21
+ export function reduceHistory(records) {
22
+ const state = { messages: [], origins: [] };
23
+ const { messages, origins } = state;
24
+ for (const record of records) {
25
+ switch (record.type) {
26
+ case "context.append_message":
27
+ foldAppend(state, record.message, record.origin);
28
+ break;
29
+ case "custom_message":
30
+ foldAppend(state, customMessage(record.content, record.time), record.origin);
31
+ break;
32
+ case "context.replace":
33
+ foldReplace(state, record.messages, record.origins);
34
+ break;
35
+ case "context.apply_compaction":
36
+ foldCompaction(state, record.cutoff, record.summary, record.summaryTimestamp);
37
+ break;
38
+ // Audit / bookkeeping — not reduced into history.
39
+ // `inbox.received` is the accepted input, not the seen input: what the model saw is
40
+ // journaled as `context.append_message` after capabilities and guardrails have had
41
+ // their say. Folding it here would double-count, or resurrect a rejected prompt.
42
+ case "inbox.received":
43
+ case "metadata":
44
+ case "usage.record":
45
+ case "permission.record_approval":
46
+ case "permission.set_mode":
47
+ case "config.update":
48
+ case "agent.handoff":
49
+ case "agent.handoff.accepted":
50
+ case "guardrail.blocked":
51
+ case "event.lifecycle":
52
+ case "custom":
53
+ break;
54
+ default: {
55
+ const exhaustive = record;
56
+ throw new Error(`reduceHistory: unhandled AgentRecord type ${String(exhaustive.type)}`);
57
+ }
58
+ }
59
+ }
60
+ return { messages, origins };
61
+ }
62
+ export function summaryMessage(summary, timestamp = Date.now()) {
63
+ return {
64
+ role: "user",
65
+ content: [{ type: "text", text: `<context-summary>\n${summary}\n</context-summary>` }],
66
+ timestamp,
67
+ };
68
+ }
69
+ export function customMessage(content, timestamp = Date.now()) {
70
+ return {
71
+ role: "user",
72
+ content: typeof content === "string" ? [{ type: "text", text: content }] : [...content],
73
+ timestamp,
74
+ };
75
+ }
76
+ /**
77
+ * Follow a store's log by polling — the generic `SessionStore.watch` every backend inherits.
78
+ *
79
+ * Drains everything already past `after` before waiting, so a watcher that starts on a busy
80
+ * session catches up at page speed rather than one poll interval per page. Sequences are
81
+ * allocated monotonically and the log is append-only, so the cursor never needs to move
82
+ * backwards and a record is never yielded twice.
83
+ *
84
+ * Prefer a backend's native push where one exists: this trades latency (up to `pollMs`) and a
85
+ * steady query rate for working anywhere.
86
+ */
87
+ export async function* watchRecordsByPolling(store, options = {}) {
88
+ const pollMs = options.pollMs ?? 250;
89
+ const pageSize = 256;
90
+ // A function, not a captured boolean: `aborted` flips during the awaits below, and reading it
91
+ // through a narrowed local would freeze it at its value on entry.
92
+ const aborted = () => options.signal?.aborted === true;
93
+ let cursor = options.after;
94
+ while (!aborted()) {
95
+ const page = await store.readRecordPage({
96
+ limit: pageSize,
97
+ ...(cursor !== undefined ? { after: cursor } : {}),
98
+ ...(options.address !== undefined ? { address: options.address } : {}),
99
+ });
100
+ for (const stored of page.data) {
101
+ if (aborted())
102
+ return;
103
+ cursor = stored.sequence;
104
+ yield stored;
105
+ }
106
+ // A full page means more is already there; keep draining before idling.
107
+ if (page.data.length === pageSize)
108
+ continue;
109
+ if (aborted())
110
+ return;
111
+ await sleep(pollMs, options.signal);
112
+ }
113
+ }
114
+ function sleep(ms, signal) {
115
+ return new Promise((resolve) => {
116
+ if (signal?.aborted === true)
117
+ return resolve();
118
+ const timer = setTimeout(() => {
119
+ signal?.removeEventListener("abort", onAbort);
120
+ resolve();
121
+ }, ms);
122
+ const onAbort = () => {
123
+ clearTimeout(timer);
124
+ resolve();
125
+ };
126
+ signal?.addEventListener("abort", onAbort, { once: true });
127
+ });
128
+ }
129
+ //# sourceMappingURL=store.js.map
@@ -0,0 +1,4 @@
1
+ export declare function normalizeWorkDir(workDir: string): string;
2
+ export declare function slugifyWorkDirName(name: string): string;
3
+ export declare function encodeWorkdirKey(workDir: string): string;
4
+ //# sourceMappingURL=workdir-key.d.ts.map
@@ -0,0 +1,28 @@
1
+ import { createHash } from "node:crypto";
2
+ import { basename, resolve } from "node:path";
3
+ const WORKDIR_KEY_PREFIX = "wd_";
4
+ const HASH_LENGTH = 12;
5
+ const SLUG_MAX = 32;
6
+ // Known limitation: `resolve` only lexically normalizes — it does NOT resolve symlinks or fold
7
+ // case. So `/tmp/x` vs `/private/tmp/x` (a macOS ancestor symlink), or `/Users/Foo` vs
8
+ // `/Users/foo` (case-insensitive APFS), hash to DIFFERENT workdir keys and thus split one real
9
+ // directory across session namespaces. Deliberate (local-first: no realpath I/O on the hot path,
10
+ // and case-sensitivity can't be probed reliably); the risk is a split, not a collision.
11
+ export function normalizeWorkDir(workDir) {
12
+ return resolve(workDir);
13
+ }
14
+ export function slugifyWorkDirName(name) {
15
+ const slug = name
16
+ .toLowerCase()
17
+ .replaceAll(/[^a-z0-9]+/g, "-")
18
+ .replaceAll(/^-+|-+$/g, "")
19
+ .slice(0, SLUG_MAX);
20
+ return slug.length > 0 ? slug : "root";
21
+ }
22
+ export function encodeWorkdirKey(workDir) {
23
+ const normalized = normalizeWorkDir(workDir);
24
+ const slug = slugifyWorkDirName(basename(normalized));
25
+ const hash = createHash("sha256").update(normalized).digest("hex").slice(0, HASH_LENGTH);
26
+ return `${WORKDIR_KEY_PREFIX}${slug}_${hash}`;
27
+ }
28
+ //# sourceMappingURL=workdir-key.js.map
@@ -0,0 +1,37 @@
1
+ export type ToolFileAccessOperation = "read" | "write" | "readwrite" | "search";
2
+ export interface ToolFileAccess {
3
+ readonly kind: "file";
4
+ readonly operation: ToolFileAccessOperation;
5
+ readonly path: string;
6
+ readonly recursive?: boolean;
7
+ }
8
+ export interface ToolResourceAccessAll {
9
+ readonly kind: "all";
10
+ }
11
+ export type ToolResourceAccess = ToolFileAccess | ToolResourceAccessAll;
12
+ /**
13
+ * SCHEDULING metadata, not a security boundary. A tool self-reports what it touches so
14
+ * the scheduler can serialize conflicting calls in one batch; nothing verifies the claim
15
+ * against the tool's actual behavior, and permissions gate every call independently of
16
+ * it. Trust model: under-declaring (a third-party/MCP tool claiming less than it does)
17
+ * can only cause unsafe PARALLEL INTERLEAVING with sibling calls — never grants access.
18
+ * When in doubt declare `ToolAccesses.all()`; an omitted `ToolPlan.accesses` already
19
+ * defaults to that (see tool-call.ts), so the unknown-tool default is the safe one.
20
+ */
21
+ export type ToolAccesses = readonly ToolResourceAccess[];
22
+ export declare const ToolAccesses: {
23
+ none(): ToolAccesses;
24
+ all(): ToolAccesses;
25
+ file(operation: ToolFileAccessOperation, path: string, options?: {
26
+ readonly recursive?: boolean;
27
+ }): ToolAccesses;
28
+ readFile(path: string): ToolAccesses;
29
+ readTree(path: string): ToolAccesses;
30
+ writeFile(path: string): ToolAccesses;
31
+ writeTree(path: string): ToolAccesses;
32
+ readWriteFile(path: string): ToolAccesses;
33
+ readWriteTree(path: string): ToolAccesses;
34
+ searchTree(path: string): ToolAccesses;
35
+ conflict(left: ToolAccesses, right: ToolAccesses): boolean;
36
+ };
37
+ //# sourceMappingURL=access.d.ts.map
@@ -0,0 +1,79 @@
1
+ export const ToolAccesses = {
2
+ none() {
3
+ return [];
4
+ },
5
+ all() {
6
+ return [{ kind: "all" }];
7
+ },
8
+ file(operation, path, options = {}) {
9
+ return [{ kind: "file", operation, path, recursive: options.recursive }];
10
+ },
11
+ readFile(path) {
12
+ return ToolAccesses.file("read", path);
13
+ },
14
+ readTree(path) {
15
+ return ToolAccesses.file("read", path, { recursive: true });
16
+ },
17
+ writeFile(path) {
18
+ return ToolAccesses.file("write", path);
19
+ },
20
+ writeTree(path) {
21
+ return ToolAccesses.file("write", path, { recursive: true });
22
+ },
23
+ readWriteFile(path) {
24
+ return ToolAccesses.file("readwrite", path);
25
+ },
26
+ readWriteTree(path) {
27
+ return ToolAccesses.file("readwrite", path, { recursive: true });
28
+ },
29
+ searchTree(path) {
30
+ return ToolAccesses.file("search", path, { recursive: true });
31
+ },
32
+ conflict(left, right) {
33
+ return left.some((leftAccess) => right.some((rightAccess) => resourceAccessesConflict(leftAccess, rightAccess)));
34
+ },
35
+ };
36
+ function resourceAccessesConflict(left, right) {
37
+ if (left.kind === "all" || right.kind === "all")
38
+ return true;
39
+ if (!fileOperationsConflict(left.operation, right.operation))
40
+ return false;
41
+ return fileAccessesOverlap(left, right);
42
+ }
43
+ function fileOperationsConflict(left, right) {
44
+ return fileOperationWrites(left) || fileOperationWrites(right);
45
+ }
46
+ function fileOperationWrites(operation) {
47
+ switch (operation) {
48
+ case "read":
49
+ case "search":
50
+ return false;
51
+ case "write":
52
+ case "readwrite":
53
+ return true;
54
+ }
55
+ }
56
+ function fileAccessesOverlap(left, right) {
57
+ const leftPath = normalizePath(left.path);
58
+ const rightPath = normalizePath(right.path);
59
+ if (leftPath === rightPath)
60
+ return true;
61
+ const leftPrefix = leftPath.endsWith("/") ? leftPath : `${leftPath}/`;
62
+ const rightPrefix = rightPath.endsWith("/") ? rightPath : `${rightPath}/`;
63
+ return ((left.recursive === true && rightPath.startsWith(leftPrefix)) ||
64
+ (right.recursive === true && leftPath.startsWith(rightPrefix)));
65
+ }
66
+ function normalizePath(path) {
67
+ const normalized = path.replaceAll("\\", "/").replaceAll(/\/+/g, "/");
68
+ // Deliberate unconditional case-fold: the volume's case sensitivity is unknowable from
69
+ // here (macOS APFS defaults to case-insensitive despite a posix pathClass), and the
70
+ // failure modes are asymmetric — folding on a case-SENSITIVE volume merely serializes
71
+ // two independent calls, while not folding on a case-INSENSITIVE one would run two
72
+ // writers to the same file in parallel. Always fold: over-serialize, never under.
73
+ const folded = normalized.toLowerCase();
74
+ if (folded.length > 1 && folded.endsWith("/")) {
75
+ return folded.slice(0, -1);
76
+ }
77
+ return folded;
78
+ }
79
+ //# sourceMappingURL=access.js.map
@@ -0,0 +1,22 @@
1
+ import type { QuestionItem, QuestionResult } from "./questions.ts";
2
+ import type { ToolRunContext } from "./types.ts";
3
+ /**
4
+ * Ask the user from inside a tool, on whatever channel is available:
5
+ *
6
+ * - live question channel present (`ctx.responder.requestQuestion`) → ask inline, return
7
+ * the answer immediately;
8
+ * - otherwise → suspend durably (`ctx.suspend`): the run pauses, the questions surface on
9
+ * the paused run's pending list, and the answer arrives through `Runner.resume` — this
10
+ * call then returns it on the re-run.
11
+ *
12
+ * This mirrors the permission layer's rule: a live responder answers in place, an absent
13
+ * one means durable. `state` is persisted across the suspension and comes back on
14
+ * `ctx.resumed.state` — pass whatever the re-run needs to skip already-done work.
15
+ *
16
+ * Contract: at most ONE `askUser` per tool run — enforced at runtime: a second call in
17
+ * the same run throws (on a resumed run it would otherwise silently return the SAME
18
+ * stale answer). Multi-round tools should use `ctx.suspend` directly with a state field
19
+ * tracking the round.
20
+ */
21
+ export declare function askUser(ctx: ToolRunContext, questions: readonly QuestionItem[], state?: unknown): Promise<QuestionResult>;
22
+ //# sourceMappingURL=ask.d.ts.map
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Ask the user from inside a tool, on whatever channel is available:
3
+ *
4
+ * - live question channel present (`ctx.responder.requestQuestion`) → ask inline, return
5
+ * the answer immediately;
6
+ * - otherwise → suspend durably (`ctx.suspend`): the run pauses, the questions surface on
7
+ * the paused run's pending list, and the answer arrives through `Runner.resume` — this
8
+ * call then returns it on the re-run.
9
+ *
10
+ * This mirrors the permission layer's rule: a live responder answers in place, an absent
11
+ * one means durable. `state` is persisted across the suspension and comes back on
12
+ * `ctx.resumed.state` — pass whatever the re-run needs to skip already-done work.
13
+ *
14
+ * Contract: at most ONE `askUser` per tool run — enforced at runtime: a second call in
15
+ * the same run throws (on a resumed run it would otherwise silently return the SAME
16
+ * stale answer). Multi-round tools should use `ctx.suspend` directly with a state field
17
+ * tracking the round.
18
+ */
19
+ export async function askUser(ctx, questions, state) {
20
+ if (asked.has(ctx)) {
21
+ throw new Error("askUser was called twice in one tool run. A resumed run delivers exactly one answer; for multi-round questions use ctx.suspend directly with round-tracking state.");
22
+ }
23
+ asked.add(ctx);
24
+ if (ctx.resumed)
25
+ return ctx.resumed.answer;
26
+ if (ctx.responder?.requestQuestion) {
27
+ return await ctx.responder.requestQuestion({ turnId: ctx.turnId, toolCallId: ctx.toolCallId, questions }, { signal: ctx.signal });
28
+ }
29
+ ctx.suspend({ kind: "question", display: { questions } }, state);
30
+ // suspend() is typed `never`, but that's a runtime promise the type system cannot
31
+ // verify. A non-conforming ToolRunContext that returns here would resolve `undefined`
32
+ // as the "answer" — fail loudly instead of handing the tool a phantom result.
33
+ throw new Error("ToolRunContext.suspend() returned instead of interrupting the run — non-conforming implementation.");
34
+ }
35
+ /** One entry per tool-run context: each run (including each post-suspend re-run) gets a
36
+ * fresh `ToolRunContext` object, so identity tracks "this run" exactly. */
37
+ const asked = new WeakSet();
38
+ //# sourceMappingURL=ask.js.map