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,11 @@
1
+ export interface LogPathOptions {
2
+ readonly appName?: string;
3
+ readonly homeDir?: string;
4
+ }
5
+ /** The shared, rolling application log: `<home>/logs/<app>.log`. */
6
+ export declare function resolveGlobalLogPath(options?: LogPathOptions): string;
7
+ /** The troubleshooting log, kept apart from the app log: `<home>/logs/diagnostics.log`. */
8
+ export declare function resolveDiagnosticLogPath(options?: LogPathOptions): string;
9
+ /** Per-session log living next to the session's data. */
10
+ export declare function resolveSessionLogPath(sessionDir: string): string;
11
+ //# sourceMappingURL=paths.d.ts.map
@@ -0,0 +1,20 @@
1
+ import { homedir } from "node:os";
2
+ import { join } from "node:path";
3
+ function logsDir(options) {
4
+ const appName = options.appName ?? "agents";
5
+ const homeDir = options.homeDir ?? join(homedir(), `.${appName}`);
6
+ return join(homeDir, "logs");
7
+ }
8
+ /** The shared, rolling application log: `<home>/logs/<app>.log`. */
9
+ export function resolveGlobalLogPath(options = {}) {
10
+ return join(logsDir(options), `${options.appName ?? "agents"}.log`);
11
+ }
12
+ /** The troubleshooting log, kept apart from the app log: `<home>/logs/diagnostics.log`. */
13
+ export function resolveDiagnosticLogPath(options = {}) {
14
+ return join(logsDir(options), "diagnostics.log");
15
+ }
16
+ /** Per-session log living next to the session's data. */
17
+ export function resolveSessionLogPath(sessionDir) {
18
+ return join(sessionDir, "session.log");
19
+ }
20
+ //# sourceMappingURL=paths.js.map
@@ -0,0 +1,5 @@
1
+ export declare const logDataPolicy: {
2
+ readonly dontLogModelData: boolean;
3
+ readonly dontLogToolData: boolean;
4
+ };
5
+ //# sourceMappingURL=policy.d.ts.map
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Coarse opt-outs for the bulky LLM/tool payloads in debug logs, read from the environment.
3
+ * Mirrors OpenAI Agents' `dontLogModelData` / `dontLogToolData`: when set, the loop still logs
4
+ * the "llm request/response" and "tool invoke/result" lines, but without the message/args/result
5
+ * bodies. Read per-call so the host can flip them without a load-order race.
6
+ */
7
+ function envFlag(name) {
8
+ const v = process.env[name];
9
+ return v === "1" || v === "true" || v === "yes";
10
+ }
11
+ export const logDataPolicy = {
12
+ get dontLogModelData() {
13
+ return envFlag("AGENTS_LOG_NO_MODEL_DATA");
14
+ },
15
+ get dontLogToolData() {
16
+ return envFlag("AGENTS_LOG_NO_TOOL_DATA");
17
+ },
18
+ };
19
+ //# sourceMappingURL=policy.js.map
@@ -0,0 +1,10 @@
1
+ export interface RedactOptions {
2
+ readonly mask?: string;
3
+ readonly extraPatterns?: readonly RegExp[];
4
+ readonly sensitiveKeyPattern?: RegExp;
5
+ readonly maxDepth?: number;
6
+ }
7
+ export declare function isSensitiveKey(key: string): boolean;
8
+ export declare function redactText(input: string, options?: RedactOptions): string;
9
+ export declare function redactDeep<T>(value: T, options?: RedactOptions): T;
10
+ //# sourceMappingURL=redact.d.ts.map
@@ -0,0 +1,95 @@
1
+ const DEFAULT_MASK = "[REDACTED]";
2
+ const SENSITIVE_KEY_WORDS = new Set([
3
+ "password",
4
+ "passwd",
5
+ "secret",
6
+ "token",
7
+ "apikey",
8
+ "accesskey",
9
+ "secretkey",
10
+ "clientsecret",
11
+ "authorization",
12
+ "auth",
13
+ "credential",
14
+ "credentials",
15
+ "privatekey",
16
+ "sessionkey",
17
+ "bearer",
18
+ "cookie",
19
+ "setcookie",
20
+ ]);
21
+ export function isSensitiveKey(key) {
22
+ const compact = key.toLowerCase().replace(/[_\-\s]/g, "");
23
+ if (SENSITIVE_KEY_WORDS.has(compact))
24
+ return true;
25
+ const segments = key
26
+ .split(/[_\-\s]+|(?<=[a-z0-9])(?=[A-Z])/)
27
+ .map((segment) => segment.toLowerCase())
28
+ .filter((segment) => segment.length > 0);
29
+ for (let i = 0; i < segments.length; i += 1) {
30
+ if (SENSITIVE_KEY_WORDS.has(segments[i]))
31
+ return true;
32
+ // Merge adjacent segments so multi-word keys whose secret word is itself split —
33
+ // `x-api-key`/`x-goog-api-key` → ["x","api","key"], `access_key_id` → ["access","key","id"] —
34
+ // still match `apikey`/`accesskey`. Without this they leak (no single segment matches, and an
35
+ // opaque value matches no VALUE_PATTERN either).
36
+ if (i + 1 < segments.length && SENSITIVE_KEY_WORDS.has(segments[i] + segments[i + 1]))
37
+ return true;
38
+ }
39
+ return false;
40
+ }
41
+ const VALUE_PATTERNS = [
42
+ // PEM private-key blocks (any flavour).
43
+ /-----BEGIN(?:[ A-Z]*)PRIVATE KEY-----[\s\S]*?-----END(?:[ A-Z]*)PRIVATE KEY-----/g,
44
+ /\bsk-ant-[A-Za-z0-9_-]{16,}/g,
45
+ /\bsk-[A-Za-z0-9]{20,}/g,
46
+ // GitHub tokens (classic + fine-grained + app).
47
+ /\b(?:ghp|gho|ghu|ghs|ghr)_[A-Za-z0-9]{36,}/g,
48
+ /\bgithub_pat_[A-Za-z0-9_]{22,}/g,
49
+ // AWS access key id, Slack, Google API keys.
50
+ /\bAKIA[0-9A-Z]{16}\b/g,
51
+ /\bxox[baprs]-[A-Za-z0-9-]{10,}/g,
52
+ /\bAIza[0-9A-Za-z_-]{35}\b/g,
53
+ // JSON Web Tokens (three base64url segments).
54
+ /\beyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}/g,
55
+ // `Authorization: Bearer <token>` / bare `Bearer <token>`.
56
+ /\bBearer\s+[A-Za-z0-9._~+/=-]{8,}/gi,
57
+ ];
58
+ const KEY_VALUE_PATTERN = /\b(pass(?:word|wd)?|secret|token|api[_-]?key|access[_-]?key|secret[_-]?key|client[_-]?secret|auth(?:orization)?|private[_-]?key|session[_-]?key)(\s*[=:]\s*)(?:"[^"]*"|'[^']*'|[^\s"'&,;]+)/gi;
59
+ export function redactText(input, options = {}) {
60
+ const mask = options.mask ?? DEFAULT_MASK;
61
+ // Standalone secret shapes FIRST — e.g. `Authorization: Bearer <tok>` must be caught by the
62
+ // Bearer pattern before the key=value pass (which would otherwise only mask the word "Bearer").
63
+ let out = input;
64
+ for (const re of VALUE_PATTERNS)
65
+ out = out.replace(re, mask);
66
+ for (const re of options.extraPatterns ?? [])
67
+ out = out.replace(re, mask);
68
+ out = out.replace(KEY_VALUE_PATTERN, (_m, key, sep) => `${key}${sep}${mask}`);
69
+ return out;
70
+ }
71
+ export function redactDeep(value, options = {}) {
72
+ return walk(value, options, options.maxDepth ?? 16);
73
+ }
74
+ function walk(value, options, depth) {
75
+ if (typeof value === "string")
76
+ return redactText(value, options);
77
+ if (depth <= 0 || value === null || typeof value !== "object")
78
+ return value;
79
+ if (Array.isArray(value))
80
+ return value.map((item) => walk(item, options, depth - 1));
81
+ const customPattern = options.sensitiveKeyPattern;
82
+ const sensitive = customPattern ? (key) => customPattern.test(key) : isSensitiveKey;
83
+ const mask = options.mask ?? DEFAULT_MASK;
84
+ const out = {};
85
+ for (const [key, item] of Object.entries(value)) {
86
+ if (sensitive(key) && (typeof item === "string" || typeof item === "number" || typeof item === "boolean")) {
87
+ out[key] = mask;
88
+ }
89
+ else {
90
+ out[key] = walk(item, options, depth - 1);
91
+ }
92
+ }
93
+ return out;
94
+ }
95
+ //# sourceMappingURL=redact.js.map
@@ -0,0 +1,67 @@
1
+ import type { LogLevel } from "./logger.ts";
2
+ export interface LogRecord {
3
+ readonly level: LogLevel;
4
+ readonly message: string;
5
+ readonly fields?: Record<string, unknown>;
6
+ readonly timestamp: number;
7
+ }
8
+ /** A destination for log records. `flush` settles pending async writes. */
9
+ export interface Sink {
10
+ write(record: LogRecord): void;
11
+ flush(): Promise<void>;
12
+ close(): Promise<void>;
13
+ }
14
+ export interface ConsoleSinkOptions {
15
+ readonly write?: (line: string) => void;
16
+ }
17
+ /** Human-readable line to the console (default stderr). */
18
+ export declare class ConsoleSink implements Sink {
19
+ private readonly out;
20
+ constructor(options?: ConsoleSinkOptions);
21
+ write(record: LogRecord): void;
22
+ flush(): Promise<void>;
23
+ close(): Promise<void>;
24
+ }
25
+ export interface RotatingFileSinkOptions {
26
+ readonly path: string;
27
+ /** Rotate once the active file would exceed this many bytes. Default 5 MiB. */
28
+ readonly maxBytes?: number;
29
+ /** Keep this many rotated files (`path.1` … `path.N`). Default 3. */
30
+ readonly maxFiles?: number;
31
+ /** Override the on-disk line format. Default JSON line. */
32
+ readonly format?: (record: LogRecord) => string;
33
+ /** Notified when a line fails to reach disk (disk full, perms, missing dir). Lets a host
34
+ * observe log loss that flush()/close() otherwise hide — they still resolve, because a
35
+ * logging sink must never throw into its callers. */
36
+ readonly onError?: (error: Error, droppedTotal: number) => void;
37
+ }
38
+ /** Appends JSON lines to a file, rotating `path` → `path.1` … `path.N` by size. Writes are
39
+ * serialized on an internal queue so order + the byte counter stay consistent. */
40
+ export declare class RotatingFileSink implements Sink {
41
+ private readonly path;
42
+ private readonly maxBytes;
43
+ private readonly maxFiles;
44
+ private readonly format;
45
+ private readonly onError;
46
+ private tail;
47
+ private currentBytes;
48
+ private droppedWrites;
49
+ constructor(options: RotatingFileSinkOptions);
50
+ /** Count of log lines lost to write failures. Non-zero ⇒ the log is incomplete even though
51
+ * flush()/close() resolved (a sink must not throw into its callers). */
52
+ get dropped(): number;
53
+ write(record: LogRecord): void;
54
+ flush(): Promise<void>;
55
+ close(): Promise<void>;
56
+ private appendLine;
57
+ private rotate;
58
+ }
59
+ /** Fans one record out to several sinks. */
60
+ export declare class MultiSink implements Sink {
61
+ private readonly sinks;
62
+ constructor(sinks: readonly Sink[]);
63
+ write(record: LogRecord): void;
64
+ flush(): Promise<void>;
65
+ close(): Promise<void>;
66
+ }
67
+ //# sourceMappingURL=sinks.d.ts.map
@@ -0,0 +1,117 @@
1
+ import { appendFile, mkdir, rename, rm, stat } from "node:fs/promises";
2
+ import { dirname } from "node:path";
3
+ function jsonLine(record) {
4
+ const base = { time: record.timestamp, level: record.level, msg: record.message };
5
+ if (record.fields !== undefined && Object.keys(record.fields).length > 0)
6
+ base["fields"] = record.fields;
7
+ try {
8
+ return JSON.stringify(base);
9
+ }
10
+ catch {
11
+ return JSON.stringify({ time: record.timestamp, level: record.level, msg: record.message, fields: "[unserializable]" });
12
+ }
13
+ }
14
+ /** Human-readable line to the console (default stderr). */
15
+ export class ConsoleSink {
16
+ out;
17
+ constructor(options = {}) {
18
+ this.out = options.write ?? ((line) => console.error(line));
19
+ }
20
+ write(record) {
21
+ const hasFields = record.fields !== undefined && Object.keys(record.fields).length > 0;
22
+ const suffix = hasFields ? ` ${safeFields(record.fields)}` : "";
23
+ this.out(`[${record.level}] ${record.message}${suffix}`);
24
+ }
25
+ async flush() { }
26
+ async close() { }
27
+ }
28
+ function safeFields(fields) {
29
+ try {
30
+ return JSON.stringify(fields);
31
+ }
32
+ catch {
33
+ return "[unserializable]";
34
+ }
35
+ }
36
+ /** Appends JSON lines to a file, rotating `path` → `path.1` … `path.N` by size. Writes are
37
+ * serialized on an internal queue so order + the byte counter stay consistent. */
38
+ export class RotatingFileSink {
39
+ path;
40
+ maxBytes;
41
+ maxFiles;
42
+ format;
43
+ onError;
44
+ tail = Promise.resolve();
45
+ currentBytes;
46
+ droppedWrites = 0;
47
+ constructor(options) {
48
+ this.path = options.path;
49
+ this.maxBytes = options.maxBytes ?? 5 * 1024 * 1024;
50
+ this.maxFiles = Math.max(1, options.maxFiles ?? 3);
51
+ this.format = options.format ?? jsonLine;
52
+ this.onError = options.onError;
53
+ }
54
+ /** Count of log lines lost to write failures. Non-zero ⇒ the log is incomplete even though
55
+ * flush()/close() resolved (a sink must not throw into its callers). */
56
+ get dropped() {
57
+ return this.droppedWrites;
58
+ }
59
+ write(record) {
60
+ const line = `${this.format(record)}\n`;
61
+ this.tail = this.tail.then(() => this.appendLine(line)).catch((error) => {
62
+ this.droppedWrites += 1;
63
+ this.onError?.(error instanceof Error ? error : new Error(String(error)), this.droppedWrites);
64
+ });
65
+ }
66
+ async flush() {
67
+ await this.tail;
68
+ }
69
+ async close() {
70
+ await this.flush();
71
+ }
72
+ async appendLine(line) {
73
+ await mkdir(dirname(this.path), { recursive: true, mode: 0o700 });
74
+ if (this.currentBytes === undefined)
75
+ this.currentBytes = await fileSize(this.path);
76
+ const bytes = Buffer.byteLength(line);
77
+ if (this.currentBytes > 0 && this.currentBytes + bytes > this.maxBytes) {
78
+ await this.rotate();
79
+ this.currentBytes = 0;
80
+ }
81
+ await appendFile(this.path, line, { mode: 0o600 });
82
+ this.currentBytes += bytes;
83
+ }
84
+ async rotate() {
85
+ await rm(`${this.path}.${this.maxFiles}`, { force: true });
86
+ for (let i = this.maxFiles - 1; i >= 1; i--) {
87
+ await rename(`${this.path}.${i}`, `${this.path}.${i + 1}`).catch(() => { });
88
+ }
89
+ await rename(this.path, `${this.path}.1`).catch(() => { });
90
+ }
91
+ }
92
+ async function fileSize(path) {
93
+ try {
94
+ return (await stat(path)).size;
95
+ }
96
+ catch {
97
+ return 0;
98
+ }
99
+ }
100
+ /** Fans one record out to several sinks. */
101
+ export class MultiSink {
102
+ sinks;
103
+ constructor(sinks) {
104
+ this.sinks = sinks;
105
+ }
106
+ write(record) {
107
+ for (const sink of this.sinks)
108
+ sink.write(record);
109
+ }
110
+ async flush() {
111
+ await Promise.all(this.sinks.map((s) => s.flush()));
112
+ }
113
+ async close() {
114
+ await Promise.all(this.sinks.map((s) => s.close()));
115
+ }
116
+ }
117
+ //# sourceMappingURL=sinks.js.map
@@ -0,0 +1,69 @@
1
+ import type { Message } from "../protocol/index.ts";
2
+ import type { PromptOrigin } from "../store/origin.ts";
3
+ import { type AgentRecord, type AgentRecordBody, type SessionStore } from "../store/store.ts";
4
+ export { summaryMessage } from "../store/store.ts";
5
+ export interface CompactionApply {
6
+ readonly summary: string;
7
+ readonly compactedCount: number;
8
+ readonly tokensBefore: number;
9
+ readonly tokensAfter: number;
10
+ }
11
+ /**
12
+ * Called for EVERY journaled history mutation, in the same synchronous block as the mutation.
13
+ *
14
+ * This exists so journaling and broadcasting are one act instead of two. Before it, each call
15
+ * site had to remember to emit an event next to its mutation — and three times it didn't:
16
+ * `injectAtTurnBoundary` skipped `message.appended`, `replaceHistory` emitted nothing at all,
17
+ * and `applyCompaction`'s event carried counts but not enough to reproduce the splice. The
18
+ * shape of that bug is always the same: the hand that writes the log and the hand that
19
+ * broadcasts are two hands.
20
+ *
21
+ * MUST be synchronous. A consumer folding these into state (see `SessionProjection`) relies on
22
+ * mutation-and-notify being one uninterrupted block; an `await` in here reopens exactly the
23
+ * race the projection exists to remove.
24
+ */
25
+ export type HistoryChangeListener = (record: AgentRecord) => void;
26
+ export interface ConversationContextOptions {
27
+ readonly store?: SessionStore;
28
+ readonly address?: string;
29
+ readonly history?: readonly Message[];
30
+ /** See {@link HistoryChangeListener}. Independent of `store`: a storeless context still
31
+ * broadcasts, because observability must not depend on persistence being configured. */
32
+ readonly onHistoryChange?: HistoryChangeListener;
33
+ }
34
+ export declare class ConversationContext {
35
+ private readonly _history;
36
+ private readonly store?;
37
+ private readonly onHistoryChange?;
38
+ readonly address: string;
39
+ /** Runtime provenance for live messages; replay rebuilds it from record origins. */
40
+ private readonly origins;
41
+ private writeChain;
42
+ /** Errors from failed appendRecord calls, surfaced (and cleared) on the next flush(). */
43
+ private writeErrors;
44
+ constructor(options?: ConversationContextOptions);
45
+ get history(): readonly Message[];
46
+ /** Live model-visible history. READONLY on purpose: every mutation must go through
47
+ * `appendMessage`/`replaceHistory`/`applyCompaction` so it is journaled — pushing into
48
+ * this array directly would silently diverge the live context from what replay
49
+ * reconstructs (the same live-vs-durable split the shard log exists to prevent). */
50
+ get messages(): readonly Message[];
51
+ seed(messages: readonly Message[]): void;
52
+ appendMessage(message: Message, origin?: PromptOrigin): void;
53
+ applyCompaction(c: CompactionApply): void;
54
+ replaceHistory(messages: readonly Message[]): void;
55
+ originOf(message: Message): PromptOrigin | undefined;
56
+ record(body: AgentRecordBody): void;
57
+ /**
58
+ * Wait for all journaled records to finish writing. Throws (once) if any write in the
59
+ * batch since the last flush failed — a failed record is never silently dropped from
60
+ * this check, even though the chain itself keeps moving so later records still get their
61
+ * own write attempt (see `journal`).
62
+ */
63
+ flush(): Promise<void>;
64
+ /** Replace live state from a shard's records, WITHOUT re-journaling (resume). */
65
+ loadFromRecords(records: readonly AgentRecord[]): void;
66
+ private journal;
67
+ }
68
+ export declare function replayContext(store: SessionStore, address?: string, onHistoryChange?: HistoryChangeListener): Promise<ConversationContext>;
69
+ //# sourceMappingURL=context.d.ts.map
@@ -0,0 +1,129 @@
1
+ import { DEFAULT_ADDRESS, reduceHistory, summaryMessage, } from "../store/store.js";
2
+ export { summaryMessage } from "../store/store.js";
3
+ export class ConversationContext {
4
+ _history;
5
+ store;
6
+ onHistoryChange;
7
+ address;
8
+ /** Runtime provenance for live messages; replay rebuilds it from record origins. */
9
+ origins = new WeakMap();
10
+ writeChain = Promise.resolve();
11
+ /** Errors from failed appendRecord calls, surfaced (and cleared) on the next flush(). */
12
+ writeErrors = [];
13
+ constructor(options = {}) {
14
+ this.store = options.store;
15
+ this.onHistoryChange = options.onHistoryChange;
16
+ this.address = options.address ?? DEFAULT_ADDRESS;
17
+ this._history = [];
18
+ if (options.history)
19
+ this.seed(options.history);
20
+ }
21
+ get history() {
22
+ return this._history;
23
+ }
24
+ /** Live model-visible history. READONLY on purpose: every mutation must go through
25
+ * `appendMessage`/`replaceHistory`/`applyCompaction` so it is journaled — pushing into
26
+ * this array directly would silently diverge the live context from what replay
27
+ * reconstructs (the same live-vs-durable split the shard log exists to prevent). */
28
+ get messages() {
29
+ return this._history;
30
+ }
31
+ seed(messages) {
32
+ for (const message of messages)
33
+ this.appendMessage(message);
34
+ }
35
+ // The three history mutators. Each applies the change to live state FIRST and journals
36
+ // second, so that by the time `onHistoryChange` fires (inside `journal`) this context
37
+ // already reads as the new state — matching the order call sites used to emit in by hand.
38
+ appendMessage(message, origin) {
39
+ this._history.push(message);
40
+ if (origin !== undefined)
41
+ this.origins.set(message, origin);
42
+ this.journal({ type: "context.append_message", message, origin });
43
+ }
44
+ applyCompaction(c) {
45
+ // Every model-visible message is journaled, so replay drops the same prefix count as live.
46
+ const summary = summaryMessage(c.summary);
47
+ this._history.splice(0, c.compactedCount, summary);
48
+ this.origins.set(summary, { kind: "compaction_summary" });
49
+ this.journal({
50
+ type: "context.apply_compaction",
51
+ summary: c.summary,
52
+ // Pinned so the summary message replay builds is identical to this one.
53
+ summaryTimestamp: summary.timestamp,
54
+ cutoff: c.compactedCount,
55
+ compactedCount: c.compactedCount,
56
+ tokensBefore: c.tokensBefore,
57
+ tokensAfter: c.tokensAfter,
58
+ });
59
+ }
60
+ replaceHistory(messages) {
61
+ const origins = messages.map((message) => this.origins.get(message) ?? null);
62
+ this._history.splice(0, this._history.length, ...messages);
63
+ this.journal({
64
+ type: "context.replace",
65
+ messages: [...messages],
66
+ ...(origins.some((origin) => origin !== null) ? { origins } : {}),
67
+ });
68
+ }
69
+ originOf(message) {
70
+ return this.origins.get(message);
71
+ }
72
+ record(body) {
73
+ this.journal(body);
74
+ }
75
+ /**
76
+ * Wait for all journaled records to finish writing. Throws (once) if any write in the
77
+ * batch since the last flush failed — a failed record is never silently dropped from
78
+ * this check, even though the chain itself keeps moving so later records still get their
79
+ * own write attempt (see `journal`).
80
+ */
81
+ async flush() {
82
+ await this.writeChain;
83
+ if (this.writeErrors.length > 0) {
84
+ const errors = this.writeErrors.splice(0, this.writeErrors.length);
85
+ throw new AggregateError(errors, `${String(errors.length)} record(s) failed to persist to the session store`);
86
+ }
87
+ }
88
+ /** Replace live state from a shard's records, WITHOUT re-journaling (resume). */
89
+ loadFromRecords(records) {
90
+ const { messages, origins } = reduceHistory(records);
91
+ this._history.splice(0, this._history.length, ...messages);
92
+ for (let i = 0; i < messages.length; i++) {
93
+ const origin = origins[i];
94
+ if (origin !== undefined)
95
+ this.origins.set(messages[i], origin);
96
+ }
97
+ }
98
+ journal(body) {
99
+ const record = { time: Date.now(), address: this.address, ...body };
100
+ // Storeless contexts broadcast here. Stored contexts normally omit this listener: their
101
+ // publication-aware SessionStore turns this same record into the event, immediately or
102
+ // after commit according to the session policy.
103
+ this.onHistoryChange?.(record);
104
+ if (this.store === undefined)
105
+ return;
106
+ const store = this.store;
107
+ // Start the append synchronously. A publication-aware store uses this exact call boundary
108
+ // to emit immediately (local mode) or enqueue append→emit atomically (managed mode). The
109
+ // chain below remains the flush/error ledger; store implementations own append ordering.
110
+ const write = store.appendRecord(record);
111
+ this.writeChain = this.writeChain.then(async () => {
112
+ await write.catch((error) => {
113
+ this.writeErrors.push(error);
114
+ });
115
+ });
116
+ }
117
+ }
118
+ export async function replayContext(store, address, onHistoryChange) {
119
+ // The listener is wired but deliberately not fired for the replayed records: `loadFromRecords`
120
+ // bypasses `journal`, because replaying is not a new history change — a consumer that seeded
121
+ // itself from the same log would otherwise see every message twice.
122
+ const ctx = new ConversationContext({ store, address, ...(onHistoryChange !== undefined ? { onHistoryChange } : {}) });
123
+ const records = [];
124
+ for await (const record of store.readRecords({ address }))
125
+ records.push(record);
126
+ ctx.loadFromRecords(records);
127
+ return ctx;
128
+ }
129
+ //# sourceMappingURL=context.js.map
@@ -0,0 +1,8 @@
1
+ export declare class MaxStepsExceededError extends Error {
2
+ readonly maxSteps: number;
3
+ constructor(maxSteps: number);
4
+ }
5
+ export declare function isMaxStepsExceededError(error: unknown): error is MaxStepsExceededError;
6
+ export declare function isAbortError(error: unknown): boolean;
7
+ export declare function errorMessage(error: unknown): string;
8
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1,27 @@
1
+ export class MaxStepsExceededError extends Error {
2
+ maxSteps;
3
+ constructor(maxSteps) {
4
+ super(`max steps exceeded: ${maxSteps}`);
5
+ this.name = "MaxStepsExceededError";
6
+ this.maxSteps = maxSteps;
7
+ }
8
+ }
9
+ export function isMaxStepsExceededError(error) {
10
+ return error instanceof MaxStepsExceededError;
11
+ }
12
+ export function isAbortError(error) {
13
+ return error instanceof Error && (error.name === "AbortError" || error.name === "TimeoutError");
14
+ }
15
+ export function errorMessage(error) {
16
+ if (error instanceof Error)
17
+ return error.message;
18
+ if (typeof error === "string")
19
+ return error;
20
+ try {
21
+ return JSON.stringify(error);
22
+ }
23
+ catch {
24
+ return String(error);
25
+ }
26
+ }
27
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1,14 @@
1
+ import type { AgentEventBody } from "../events/events.ts";
2
+ /**
3
+ * Sink for events emitted from inside the loop.
4
+ *
5
+ * ONE sink is threaded through run-turn → turn-step → tool-call. Each layer dispatches the
6
+ * REAL `AgentEventBody` directly (`tool_execution_start`, `message_update`, …) — there is no
7
+ * intermediate vocabulary to translate. The Runner provides the sink and its only job is to
8
+ * add the `{ address, sessionId }` envelope (`emit(state, body)`). This mirrors the upstream
9
+ * pi-agent design, where the loop emits AgentEvents through a single sink.
10
+ *
11
+ * (The loop has no `state`, so it cannot add the envelope itself — that is the sink's job.)
12
+ */
13
+ export type LoopEventDispatcher = (event: AgentEventBody) => void;
14
+ //# sourceMappingURL=events.d.ts.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=events.js.map
@@ -0,0 +1,10 @@
1
+ export type * from "./types.ts";
2
+ export { addUsage, emptyUsage, subtractUsage } from "./usage.ts";
3
+ export { MaxStepsExceededError, isMaxStepsExceededError, isAbortError } from "./errors.ts";
4
+ export { SteerBus, renderSteerText, steerOriginToPromptOrigin } from "./steer.ts";
5
+ export type { SteerOrigin, SteerMessage, SteerContent, SteerContentPart, SteerBusOptions, SteerChannel, SteerReceipt, NowFn } from "./steer.ts";
6
+ export { INTERRUPTION_STATE_KEY, INTERRUPTION_STATE_VERSION, applyInterruptionAnswers, flattenPendingInterrupts, getInterruptionState, parseInterruptionState, } from "./interruption.ts";
7
+ export type { AgentDefinitionReference, InterruptAnswer, InterruptionAnchor, InterruptionExecution, InterruptionFrame, InterruptionPhase, InterruptionState, PendingRunInterrupt, } from "./interruption.ts";
8
+ export { ConversationContext, replayContext, summaryMessage } from "./context.ts";
9
+ export type { ConversationContextOptions, CompactionApply } from "./context.ts";
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,7 @@
1
+ export { addUsage, emptyUsage, subtractUsage } from "./usage.js";
2
+ export { MaxStepsExceededError, isMaxStepsExceededError, isAbortError } from "./errors.js";
3
+ export { SteerBus, renderSteerText, steerOriginToPromptOrigin } from "./steer.js";
4
+ export { INTERRUPTION_STATE_KEY, INTERRUPTION_STATE_VERSION, applyInterruptionAnswers, flattenPendingInterrupts, getInterruptionState, parseInterruptionState, } from "./interruption.js";
5
+ // source of truth lives in the log; `replayContext` rebuilds it on resume.
6
+ export { ConversationContext, replayContext, summaryMessage } from "./context.js";
7
+ //# sourceMappingURL=index.js.map