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,46 @@
1
+ import { z, type ZodType } from "zod";
2
+ import type { Tool, ToolAccesses, ToolDisplay, ToolPlan, ToolResolveContext, ToolResult, ToolResultContent, ToolRunContext } from "./types.ts";
3
+ /**
4
+ * The full-control tool definition: `resolve(args)` runs BEFORE authorization and returns
5
+ * the complete `ToolPlan` — `approvalRule` (and everything else plan-level: `accesses`,
6
+ * `matchesRule`, `display`, `controlFlow`, `handoff`, `stopBatchAfterThis`) is computed
7
+ * there, which is why this shape has no top-level `approvalRule` field like
8
+ * {@link FunctionToolDef} does: the plan is its single source of truth.
9
+ *
10
+ * Choosing between the two APIs: reach for {@link tool} (the simple execute-only shape)
11
+ * unless you need resolve-time work — pre-approval validation (e.g. against
12
+ * `ctx.fileLedger`), plan fields beyond approvalRule/accesses/display, or an
13
+ * args-dependent plan structure.
14
+ */
15
+ export interface ToolDef<S extends ZodType> {
16
+ readonly name: string;
17
+ readonly description: string;
18
+ readonly params: S;
19
+ readonly resolve: (args: z.infer<S>, ctx: ToolResolveContext) => ToolPlan | Promise<ToolPlan>;
20
+ /** Security-relevant projection for the `auto`-mode judge. See `Tool.toAutoApprovalInput`. */
21
+ readonly toAutoApprovalInput?: (args: z.infer<S>) => unknown;
22
+ }
23
+ /** Build a tool from a {@link ToolDef}. See that type's doc for when to prefer {@link tool}. */
24
+ export declare function defineTool<S extends ZodType>(def: ToolDef<S>): Tool;
25
+ export type ToolReturn = string | ToolResultContent | ToolResult;
26
+ /**
27
+ * The simple tool definition (OpenAI-parity function tool): one `execute` plus optional
28
+ * plan sugar — `approvalRule` (string, or computed from args; defaults to the tool name),
29
+ * `accesses`, `display`. It expands into the same `ToolPlan` a {@link ToolDef} builds by
30
+ * hand; for resolve-time validation or plan fields not exposed here, use
31
+ * {@link defineTool} instead.
32
+ */
33
+ export interface FunctionToolDef<S extends ZodType> {
34
+ readonly name: string;
35
+ readonly description: string;
36
+ readonly parameters: S;
37
+ readonly execute: (args: z.infer<S>, ctx: ToolRunContext) => ToolReturn | Promise<ToolReturn>;
38
+ readonly approvalRule?: string | ((args: z.infer<S>) => string);
39
+ readonly accesses?: ToolAccesses;
40
+ readonly display?: (args: z.infer<S>) => ToolDisplay;
41
+ /** Security-relevant projection for the `auto`-mode judge. See `Tool.toAutoApprovalInput`. */
42
+ readonly toAutoApprovalInput?: (args: z.infer<S>) => unknown;
43
+ }
44
+ /** Build a tool from a {@link FunctionToolDef} — the right default for most tools. */
45
+ export declare function tool<S extends ZodType>(def: FunctionToolDef<S>): Tool;
46
+ //# sourceMappingURL=define.d.ts.map
@@ -0,0 +1,45 @@
1
+ import { z } from "zod";
2
+ /** Build a tool from a {@link ToolDef}. See that type's doc for when to prefer {@link tool}. */
3
+ export function defineTool(def) {
4
+ const parameters = z.toJSONSchema(def.params);
5
+ return {
6
+ schema: { name: def.name, description: def.description, parameters },
7
+ resolve(rawArgs, ctx) {
8
+ const args = def.params.parse(rawArgs);
9
+ return def.resolve(args, ctx);
10
+ },
11
+ // Project from the raw (history) args. The judge passes unvalidated tool_use input from
12
+ // the transcript, so parse defensively and let the judge's try/catch handle throws.
13
+ ...(def.toAutoApprovalInput
14
+ ? { toAutoApprovalInput: (rawArgs) => def.toAutoApprovalInput(def.params.parse(rawArgs)) }
15
+ : {}),
16
+ };
17
+ }
18
+ /** Build a tool from a {@link FunctionToolDef} — the right default for most tools. */
19
+ export function tool(def) {
20
+ const parameters = z.toJSONSchema(def.parameters);
21
+ return {
22
+ schema: { name: def.name, description: def.description, parameters },
23
+ ...(def.toAutoApprovalInput
24
+ ? { toAutoApprovalInput: (rawArgs) => def.toAutoApprovalInput(def.parameters.parse(rawArgs)) }
25
+ : {}),
26
+ resolve(rawArgs) {
27
+ const args = def.parameters.parse(rawArgs);
28
+ const approvalRule = typeof def.approvalRule === "function" ? def.approvalRule(args) : def.approvalRule ?? def.name;
29
+ return {
30
+ approvalRule,
31
+ accesses: def.accesses,
32
+ display: def.display?.(args),
33
+ run: async (ctx) => normalizeToolReturn(await def.execute(args, ctx)),
34
+ };
35
+ },
36
+ };
37
+ }
38
+ function normalizeToolReturn(value) {
39
+ if (typeof value === "string")
40
+ return { content: [{ type: "text", text: value }] };
41
+ if (Array.isArray(value))
42
+ return { content: value };
43
+ return value;
44
+ }
45
+ //# sourceMappingURL=define.js.map
@@ -0,0 +1,81 @@
1
+ /**
2
+ * Session-scoped file freshness ledger — the read-state record backing the
3
+ * tool path. Carries the safety invariants for Edit/Write (read-before-write,
4
+ * external-modification detection) plus the Read dedup stub, so it is core tool
5
+ * infrastructure, NOT a capability: it must not be toggleable by composition.
6
+ *
7
+ * Owned by the Session (one per agent; subagents get their own — a subagent has
8
+ * not "read" what its parent read). Threaded into ToolResolveContext/ToolRunContext
9
+ * by the loop. Keys are host-canonical absolute paths.
10
+ *
11
+ * Freshness is mtime-first (local-first): when both sides have an mtime and it
12
+ * matches, the file is fresh with zero extra I/O. Content comparison — against the
13
+ * retained prior text, no hashing — runs only when the mtime moved (false-positive
14
+ * review: cloud sync / antivirus / Windows) or is unavailable (mtime-less sandbox
15
+ * backends).
16
+ */
17
+ import type { FileVersion, LineEndings } from "./machine.ts";
18
+ /**
19
+ * Above this, content is not retained (version-only record) — freshness then degrades to
20
+ * conservative-stale on mtime change.
21
+ *
22
+ * It bounds the WRITE path, not the read path. A read can only retain content when it read
23
+ * the file whole, which the Read tool's own output caps already keep far below this. A write
24
+ * has no such ceiling: `recordWrite` retains whatever the model just produced, and nothing
25
+ * stops that from being a multi-megabyte generated file.
26
+ */
27
+ export declare const CONTENT_RETENTION_MAX_BYTES: number;
28
+ export declare const FILE_NOT_READ_MESSAGE = "File has not been read yet. Read it first before writing to it.";
29
+ export declare const FILE_MODIFIED_MESSAGE = "File has been modified since read, either by the user or by a linter. Read it again before attempting to write it.";
30
+ export declare const FILE_UNCHANGED_STUB = "File unchanged since last read. The content from the earlier Read tool_result in this conversation is still current; refer to that instead of re-reading.";
31
+ export interface FileReadRecord {
32
+ readonly version: FileVersion;
33
+ /** Full text (LF-normalized, BOM-stripped) retained for full reads within the size cap. */
34
+ readonly content?: string;
35
+ /** True when the read had no offset/limit. Partial reads never pass content review. */
36
+ readonly fullRead: boolean;
37
+ readonly range?: {
38
+ readonly lineOffset: number;
39
+ readonly maxLines?: number;
40
+ };
41
+ readonly lineEndings: LineEndings;
42
+ readonly encoding: BufferEncoding;
43
+ /** When the read happened (diagnostics only — plays no part in freshness). */
44
+ readonly readAt: number;
45
+ }
46
+ export type FreshnessVerdict = {
47
+ readonly kind: "fresh";
48
+ } | {
49
+ readonly kind: "not-read";
50
+ } | {
51
+ readonly kind: "stale";
52
+ };
53
+ export interface RecordWriteOptions {
54
+ readonly content?: string;
55
+ readonly lineEndings?: LineEndings;
56
+ readonly encoding?: BufferEncoding;
57
+ }
58
+ export declare class FileFreshnessLedger {
59
+ private readonly records;
60
+ recordRead(path: string, record: FileReadRecord): void;
61
+ /** A successful write makes the writer the last reader. */
62
+ recordWrite(path: string, version: FileVersion, options?: RecordWriteOptions): void;
63
+ get(path: string): FileReadRecord | undefined;
64
+ delete(path: string): void;
65
+ clear(): void;
66
+ get size(): number;
67
+ }
68
+ export interface CheckFreshnessInput {
69
+ readonly ledger: FileFreshnessLedger;
70
+ readonly path: string;
71
+ readonly current: FileVersion;
72
+ /**
73
+ * Lazily supplies the current full content (LF-normalized, BOM-stripped) for
74
+ * the content-review fallback. Edit passes the text it already read (free);
75
+ * Write reads on demand — which only happens when the mtime moved or is
76
+ * unavailable. Return undefined when the content cannot be produced.
77
+ */
78
+ readonly currentContent?: () => Promise<string | undefined>;
79
+ }
80
+ export declare function checkFreshness(input: CheckFreshnessInput): Promise<FreshnessVerdict>;
81
+ //# sourceMappingURL=file-freshness.d.ts.map
@@ -0,0 +1,67 @@
1
+ // Same predicate the Machine-side check uses (BaseMachine.assertUnchanged) — the two
2
+ // run at different moments and must never disagree about what "unchanged" means.
3
+ import { fileVersionsMatch } from "./support/machine-ops.js";
4
+ /**
5
+ * Above this, content is not retained (version-only record) — freshness then degrades to
6
+ * conservative-stale on mtime change.
7
+ *
8
+ * It bounds the WRITE path, not the read path. A read can only retain content when it read
9
+ * the file whole, which the Read tool's own output caps already keep far below this. A write
10
+ * has no such ceiling: `recordWrite` retains whatever the model just produced, and nothing
11
+ * stops that from being a multi-megabyte generated file.
12
+ */
13
+ export const CONTENT_RETENTION_MAX_BYTES = 10 * 1024 * 1024;
14
+ export const FILE_NOT_READ_MESSAGE = "File has not been read yet. Read it first before writing to it.";
15
+ export const FILE_MODIFIED_MESSAGE = "File has been modified since read, either by the user or by a linter. Read it again before attempting to write it.";
16
+ export const FILE_UNCHANGED_STUB = "File unchanged since last read. The content from the earlier Read tool_result in this conversation is still current; refer to that instead of re-reading.";
17
+ function clampContent(record) {
18
+ if (record.content === undefined)
19
+ return record;
20
+ if (Buffer.byteLength(record.content, "utf8") <= CONTENT_RETENTION_MAX_BYTES)
21
+ return record;
22
+ const { content: _dropped, ...rest } = record;
23
+ return rest;
24
+ }
25
+ export class FileFreshnessLedger {
26
+ records = new Map();
27
+ recordRead(path, record) {
28
+ this.records.set(path, clampContent(record));
29
+ }
30
+ /** A successful write makes the writer the last reader. */
31
+ recordWrite(path, version, options = {}) {
32
+ this.records.set(path, clampContent({
33
+ version,
34
+ fullRead: true,
35
+ lineEndings: options.lineEndings ?? "LF",
36
+ encoding: options.encoding ?? "utf8",
37
+ readAt: Date.now(),
38
+ ...(options.content !== undefined ? { content: options.content } : {}),
39
+ }));
40
+ }
41
+ get(path) {
42
+ return this.records.get(path);
43
+ }
44
+ delete(path) {
45
+ this.records.delete(path);
46
+ }
47
+ clear() {
48
+ this.records.clear();
49
+ }
50
+ get size() {
51
+ return this.records.size;
52
+ }
53
+ }
54
+ export async function checkFreshness(input) {
55
+ const record = input.ledger.get(input.path);
56
+ if (record === undefined)
57
+ return { kind: "not-read" };
58
+ if (fileVersionsMatch(record.version, input.current))
59
+ return { kind: "fresh" };
60
+ if (record.fullRead && record.content !== undefined && input.currentContent !== undefined) {
61
+ const currentText = await input.currentContent();
62
+ if (currentText !== undefined && currentText === record.content)
63
+ return { kind: "fresh" };
64
+ }
65
+ return { kind: "stale" };
66
+ }
67
+ //# sourceMappingURL=file-freshness.js.map
@@ -0,0 +1,16 @@
1
+ import type { Tool } from "./types.ts";
2
+ export interface FilesystemToolsOptions {
3
+ /**
4
+ * `"all"` (default): read/write/edit/glob/grep/bash.
5
+ * `"readonly"`: drops the mutating + shell tools, leaving read/glob/grep.
6
+ */
7
+ readonly mode?: "all" | "readonly";
8
+ }
9
+ /**
10
+ * The standard machine-backed builtin tools as a single array — convenience
11
+ * sugar for assembling an agent's toolset (`tools: filesystemTools()`). It is
12
+ * NOT a capability or a new mechanism: these are the same tools exported
13
+ * individually from this package. Omit it entirely for a no-filesystem agent.
14
+ */
15
+ export declare function filesystemTools(options?: FilesystemToolsOptions): Tool[];
16
+ //# sourceMappingURL=filesystem-tools.d.ts.map
@@ -0,0 +1,19 @@
1
+ import { bashTool } from "./builtin/bash.js";
2
+ import { editTool } from "./builtin/edit.js";
3
+ import { globTool } from "./builtin/glob.js";
4
+ import { grepTool } from "./builtin/grep.js";
5
+ import { readTool } from "./builtin/read.js";
6
+ import { writeTool } from "./builtin/write.js";
7
+ /**
8
+ * The standard machine-backed builtin tools as a single array — convenience
9
+ * sugar for assembling an agent's toolset (`tools: filesystemTools()`). It is
10
+ * NOT a capability or a new mechanism: these are the same tools exported
11
+ * individually from this package. Omit it entirely for a no-filesystem agent.
12
+ */
13
+ export function filesystemTools(options = {}) {
14
+ const readers = [readTool, globTool, grepTool];
15
+ if (options.mode === "readonly")
16
+ return readers;
17
+ return [...readers, writeTool, editTool, bashTool];
18
+ }
19
+ //# sourceMappingURL=filesystem-tools.js.map
@@ -0,0 +1,20 @@
1
+ import type { Machine } from "./machine.ts";
2
+ export interface GitContextOptions {
3
+ readonly maxDirtyFiles?: number;
4
+ readonly recentCommits?: number;
5
+ }
6
+ export interface GitContext {
7
+ readonly isRepo: boolean;
8
+ readonly cwd: string;
9
+ readonly remote?: string;
10
+ readonly project?: string;
11
+ readonly branch?: string;
12
+ readonly dirtyFiles: readonly string[];
13
+ readonly dirtyCount: number;
14
+ readonly recentCommits: readonly string[];
15
+ }
16
+ export declare function collectGitContext(machine: Machine, cwd: string, options?: GitContextOptions): Promise<GitContext>;
17
+ export declare function formatGitContext(ctx: GitContext): string;
18
+ export declare function sanitizeRemoteUrl(remoteUrl: string): string | null;
19
+ export declare function parseProjectName(remoteUrl: string): string | null;
20
+ //# sourceMappingURL=git-context.d.ts.map
@@ -0,0 +1,114 @@
1
+ const GIT_TIMEOUT_MS = 5_000;
2
+ const DEFAULT_MAX_DIRTY_FILES = 20;
3
+ const DEFAULT_RECENT_COMMITS = 3;
4
+ const MAX_COMMIT_LINE_LENGTH = 200;
5
+ const ALLOWED_HOSTS = ["github.com", "gitlab.com", "gitee.com", "bitbucket.org", "codeberg.org", "git.sr.ht"];
6
+ export async function collectGitContext(machine, cwd, options = {}) {
7
+ const maxDirty = options.maxDirtyFiles ?? DEFAULT_MAX_DIRTY_FILES;
8
+ const nCommits = options.recentCommits ?? DEFAULT_RECENT_COMMITS;
9
+ if ((await runGit(machine, cwd, ["rev-parse", "--is-inside-work-tree"])) === null) {
10
+ return { isRepo: false, cwd, dirtyFiles: [], dirtyCount: 0, recentCommits: [] };
11
+ }
12
+ const [remoteRaw, branchRaw, dirtyRaw, logRaw] = await Promise.all([
13
+ runGit(machine, cwd, ["remote", "get-url", "origin"]),
14
+ runGit(machine, cwd, ["branch", "--show-current"]),
15
+ runGit(machine, cwd, ["status", "--porcelain"]),
16
+ runGit(machine, cwd, ["log", `-${String(nCommits)}`, "--format=%h %s"]),
17
+ ]);
18
+ const remote = remoteRaw !== null ? (sanitizeRemoteUrl(remoteRaw) ?? undefined) : undefined;
19
+ const project = remote !== undefined ? (parseProjectName(remote) ?? undefined) : undefined;
20
+ const branch = branchRaw !== null && branchRaw.length > 0 ? branchRaw : undefined;
21
+ const allDirty = dirtyRaw !== null ? dirtyRaw.split("\n").filter((line) => line.trim().length > 0) : [];
22
+ const recentCommits = logRaw !== null
23
+ ? logRaw
24
+ .split("\n")
25
+ .filter((line) => line.trim().length > 0)
26
+ .map((line) => line.slice(0, MAX_COMMIT_LINE_LENGTH))
27
+ : [];
28
+ return {
29
+ isRepo: true,
30
+ cwd,
31
+ remote,
32
+ project,
33
+ branch,
34
+ dirtyFiles: allDirty.slice(0, maxDirty),
35
+ dirtyCount: allDirty.length,
36
+ recentCommits,
37
+ };
38
+ }
39
+ export function formatGitContext(ctx) {
40
+ if (!ctx.isRepo)
41
+ return "";
42
+ const sections = [`Working directory: ${ctx.cwd}`];
43
+ if (ctx.remote)
44
+ sections.push(`Remote: ${ctx.remote}`);
45
+ if (ctx.project)
46
+ sections.push(`Project: ${ctx.project}`);
47
+ if (ctx.branch)
48
+ sections.push(`Branch: ${ctx.branch}`);
49
+ if (ctx.dirtyCount > 0) {
50
+ let body = ctx.dirtyFiles.map((line) => ` ${line}`).join("\n");
51
+ if (ctx.dirtyCount > ctx.dirtyFiles.length) {
52
+ body += `\n ... and ${String(ctx.dirtyCount - ctx.dirtyFiles.length)} more`;
53
+ }
54
+ sections.push(`Dirty files (${String(ctx.dirtyCount)}):\n${body}`);
55
+ }
56
+ if (ctx.recentCommits.length > 0) {
57
+ sections.push(`Recent commits:\n${ctx.recentCommits.map((line) => ` ${line}`).join("\n")}`);
58
+ }
59
+ if (sections.length <= 1)
60
+ return "";
61
+ return `<git-context>\n${sections.join("\n")}\n</git-context>`;
62
+ }
63
+ export function sanitizeRemoteUrl(remoteUrl) {
64
+ // scp-like SSH (`git@host:owner/repo.git`) — no credentials possible.
65
+ for (const host of ALLOWED_HOSTS) {
66
+ if (remoteUrl.startsWith(`git@${host}:`))
67
+ return remoteUrl;
68
+ }
69
+ // HTTPS — parse the hostname exactly and drop any userinfo.
70
+ let parsed;
71
+ try {
72
+ parsed = new URL(remoteUrl);
73
+ }
74
+ catch {
75
+ return null;
76
+ }
77
+ if (ALLOWED_HOSTS.includes(parsed.hostname)) {
78
+ const port = parsed.port ? `:${parsed.port}` : "";
79
+ return `https://${parsed.hostname}${port}${parsed.pathname}`;
80
+ }
81
+ return null;
82
+ }
83
+ export function parseProjectName(remoteUrl) {
84
+ const scp = /^[^/]+@[^/:]+:(.+)$/.exec(remoteUrl);
85
+ const rawPath = scp?.[1] ?? tryUrlPath(remoteUrl);
86
+ if (rawPath === null)
87
+ return null;
88
+ const project = rawPath
89
+ .replace(/^\/+/, "")
90
+ .replace(/\/+$/, "")
91
+ .replace(/\.git$/, "");
92
+ return project.length > 0 ? project : null;
93
+ }
94
+ function tryUrlPath(remoteUrl) {
95
+ try {
96
+ return new URL(remoteUrl).pathname;
97
+ }
98
+ catch {
99
+ return null;
100
+ }
101
+ }
102
+ /**
103
+ * Git context is best-effort decoration: any failure — git missing, not a repo, a hung
104
+ * command — degrades to `null` rather than surfacing. The timeout is stated as intent, so
105
+ * the backend enforces it with its own kill (and a backend that cannot reports `timedOut`
106
+ * without pretending it stopped anything).
107
+ */
108
+ async function runGit(machine, cwd, args) {
109
+ const result = await machine.run(["git", "-C", cwd, ...args], { timeoutMs: GIT_TIMEOUT_MS }).catch(() => undefined);
110
+ if (result === undefined || result.timedOut || result.exitCode !== 0)
111
+ return null;
112
+ return result.stdout.trim();
113
+ }
114
+ //# sourceMappingURL=git-context.js.map
@@ -0,0 +1,37 @@
1
+ export type * from "./types.ts";
2
+ export { ToolAccesses } from "./access.ts";
3
+ export type { Machine, MachineFactory, MachineOpenContext, DecodeErrors, Environment, OsKind, ShellName, } from "./machine.ts";
4
+ export { StaleFileError, FileExistsError } from "./machine.ts";
5
+ export type { ByteRange, RunCommandResult, DirEntry, OutputChunk, RunCommandOptions, FileInfo, FileKind, FileVersion, LineEndings, WriteTextOptions, WriteTextResult, WriteTextIfUnchangedOptions, WriteFileResult, } from "./machine.ts";
6
+ export { BaseMachine } from "./machine-base.ts";
7
+ export type { SpawnedProcess } from "./machine-base.ts";
8
+ export { materializeWorkspace, describeWorkspace, WorkspaceMaterializeError } from "./workspace-spec.ts";
9
+ export type { HostReader, MaterializeOptions, WorkspaceEntry, WorkspaceSpec } from "./workspace-spec.ts";
10
+ export { FileFreshnessLedger, checkFreshness, CONTENT_RETENTION_MAX_BYTES, FILE_NOT_READ_MESSAGE, FILE_MODIFIED_MESSAGE, FILE_UNCHANGED_STUB, } from "./file-freshness.ts";
11
+ export type { FileReadRecord, FreshnessVerdict, RecordWriteOptions, CheckFreshnessInput } from "./file-freshness.ts";
12
+ export { LocalMachine, detectEnvironment } from "./machine-local.ts";
13
+ export { NullMachine } from "./machine-null.ts";
14
+ export { nonInteractiveShellEnv, proxyEnv, PROXY_ENV_VARS } from "./shell-env.ts";
15
+ export type { NonInteractiveEnvOptions } from "./shell-env.ts";
16
+ export { collectGitContext, formatGitContext, sanitizeRemoteUrl, parseProjectName } from "./git-context.ts";
17
+ export type { GitContext, GitContextOptions } from "./git-context.ts";
18
+ export { SshMachine } from "./machine-ssh.ts";
19
+ export type { SshMachineOptions, SshMachineExtraOptions } from "./machine-ssh.ts";
20
+ export type { BackgroundSpawner } from "./background.ts";
21
+ export { askUser } from "./ask.ts";
22
+ export { defineTool, tool } from "./define.ts";
23
+ export { globApproval } from "./support/tool-path.ts";
24
+ export type { ToolDef, FunctionToolDef, ToolReturn } from "./define.ts";
25
+ export { writeTool } from "./builtin/write.ts";
26
+ export { editTool } from "./builtin/edit.ts";
27
+ export { readTool } from "./builtin/read.ts";
28
+ export { globTool } from "./builtin/glob.ts";
29
+ export { bashTool } from "./builtin/bash.ts";
30
+ export { grepTool } from "./builtin/grep.ts";
31
+ export { askUserQuestionTool } from "./builtin/ask-user-question.ts";
32
+ export type { QuestionOption, QuestionItem, QuestionRequest, QuestionAnswerValue, QuestionAnswers, QuestionAnswerMethod, QuestionResponse, QuestionResult, QuestionResponder, } from "./questions.ts";
33
+ export type { QuestionSpawnOptions } from "./background.ts";
34
+ export { filesystemTools } from "./filesystem-tools.ts";
35
+ export type { FilesystemToolsOptions } from "./filesystem-tools.ts";
36
+ export * from "./web/index.ts";
37
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,34 @@
1
+ export { ToolAccesses } from "./access.js";
2
+ export { StaleFileError, FileExistsError } from "./machine.js";
3
+ // ── Writing a Machine backend ────────────────────────────────────────────────
4
+ // Everything above is the CALLER's surface: `Machine` and the shapes its methods take and
5
+ // return. What follows is the IMPLEMENTER's, and only a backend author needs it.
6
+ //
7
+ // Extend `BaseMachine` and it derives the high-level operations for you. Its process SPI —
8
+ // `spawn`, returning a `SpawnedProcess` — is what gets you `run` for free, and is optional:
9
+ // a transport with no OS process (a sandbox HTTP API, as in `operon-sandbox`) omits it and
10
+ // overrides `run` natively instead. Nothing outside the class hierarchy calls either one.
11
+ export { BaseMachine } from "./machine-base.js";
12
+ export { materializeWorkspace, describeWorkspace, WorkspaceMaterializeError } from "./workspace-spec.js";
13
+ // Low-level file-op helpers (readTextFile / decodeText / …) are on
14
+ // `operon-agents-core/internal`.
15
+ export { FileFreshnessLedger, checkFreshness, CONTENT_RETENTION_MAX_BYTES, FILE_NOT_READ_MESSAGE, FILE_MODIFIED_MESSAGE, FILE_UNCHANGED_STUB, } from "./file-freshness.js";
16
+ // Bash permission-rule matching helpers are on `operon-agents-core/internal`.
17
+ export { LocalMachine, detectEnvironment } from "./machine-local.js";
18
+ export { NullMachine } from "./machine-null.js";
19
+ export { nonInteractiveShellEnv, proxyEnv, PROXY_ENV_VARS } from "./shell-env.js";
20
+ export { collectGitContext, formatGitContext, sanitizeRemoteUrl, parseProjectName } from "./git-context.js";
21
+ export { SshMachine } from "./machine-ssh.js";
22
+ export { askUser } from "./ask.js";
23
+ export { defineTool, tool } from "./define.js";
24
+ export { globApproval } from "./support/tool-path.js";
25
+ export { writeTool } from "./builtin/write.js";
26
+ export { editTool } from "./builtin/edit.js";
27
+ export { readTool } from "./builtin/read.js";
28
+ export { globTool } from "./builtin/glob.js";
29
+ export { bashTool } from "./builtin/bash.js";
30
+ export { grepTool } from "./builtin/grep.js";
31
+ export { askUserQuestionTool } from "./builtin/ask-user-question.js";
32
+ export { filesystemTools } from "./filesystem-tools.js";
33
+ export * from "./web/index.js";
34
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,138 @@
1
+ /**
2
+ * Implementer-side base for Machine backends.
3
+ *
4
+ * A backend writes only the dumb primitives (the abstract SPI below); this
5
+ * class derives the high-level operations from them:
6
+ *
7
+ * - `writeTextIfUnchanged`: per-path lock → fileInfo compare → content review →
8
+ * write → version stamp, all inside the lock. The lock is the same-process
9
+ * floor of the contract (see Machine docs); the residual gap versus EXTERNAL
10
+ * writers is backend-dependent and can't be closed here. Hosts override for
11
+ * stronger swaps (local: sync critical section; SSH: EXCL create + tmp/rename).
12
+ * - `realpath`: `readlink -f` via `run` on posix, normpath on win32. Hosts with
13
+ * a native resolver (fs.realpath, SFTP realpath) override for exactness.
14
+ */
15
+ import type { Readable, Writable } from "node:stream";
16
+ import { type RunCommandResult, type DecodeErrors, type DirEntry, type Environment, type ByteRange, type Machine, type RunCommandOptions, type FileInfo, type WriteFileResult, type WriteTextIfUnchangedOptions, type WriteTextOptions, type WriteTextResult } from "./machine.ts";
17
+ /**
18
+ * A live OS process, normalized. IMPLEMENTER-SIDE ONLY — this is what {@link BaseMachine.spawn}
19
+ * hands back so ONE copy of `run`'s read/cap/decode/kill-escalate logic can serve backends
20
+ * whose native process objects disagree on the details: node's `ChildProcess` kills by signal
21
+ * name and reports exit on one event, while an ssh2 `ClientChannel` wants the signal without
22
+ * its `SIG` prefix, splits exit across `exit`/`close`, and drops output emitted before a
23
+ * consumer attaches. Each backend absorbs its own quirks here.
24
+ *
25
+ * No `pid`: nothing consumes one, and SSH could only ever have invented it.
26
+ */
27
+ export interface SpawnedProcess {
28
+ readonly stdin: Writable;
29
+ readonly stdout: Readable;
30
+ readonly stderr: Readable;
31
+ /** null while running. Read after a kill to tell "it stopped" from "it ignored us". */
32
+ readonly exitCode: number | null;
33
+ wait(): Promise<number>;
34
+ kill(signal?: NodeJS.Signals): Promise<void>;
35
+ }
36
+ export declare abstract class BaseMachine implements Machine {
37
+ abstract readonly name: string;
38
+ abstract readonly osEnv: Environment;
39
+ abstract pathClass(): "posix" | "win32";
40
+ abstract normpath(path: string): string;
41
+ abstract gethome(): string;
42
+ abstract getcwd(): string;
43
+ abstract withCwd(cwd: string): Machine;
44
+ /** Extra workspace roots (see Machine.additionalDirs). Default: cwd only. */
45
+ additionalDirs(): readonly string[];
46
+ /**
47
+ * Spawn a live process. IMPLEMENTER-SIDE ONLY — no caller reaches for this; it exists so
48
+ * `run` below can be derived on backends whose transport really does hand one back (local
49
+ * spawn, an SSH channel). `env` is a set of OVERRIDES layered over the ambient environment.
50
+ *
51
+ * Optional on purpose. A backend whose transport has no process handle — a sandbox HTTP
52
+ * API — omits it and overrides `run` natively instead. That is the honest shape: such a
53
+ * backend used to be forced to fabricate a handle whose `kill()` did nothing, which the
54
+ * callers above then trusted.
55
+ */
56
+ protected spawn?(argv: readonly string[], env?: Record<string, string>): Promise<SpawnedProcess>;
57
+ abstract fileInfo(path: string, options?: {
58
+ followSymlinks?: boolean;
59
+ }): Promise<FileInfo>;
60
+ abstract listDir(path: string): Promise<readonly DirEntry[]>;
61
+ abstract mkdir(path: string, options?: {
62
+ parents?: boolean;
63
+ existOk?: boolean;
64
+ }): Promise<void>;
65
+ abstract readBytes(path: string, range?: ByteRange): Promise<Buffer>;
66
+ /** Raw unconditional whole-file write — the single write primitive everything else derives from. */
67
+ protected abstract writeBytesRaw(path: string, data: Buffer): Promise<void>;
68
+ /**
69
+ * The write half of the compare-and-swap in `writeTextIfUnchanged`. Default: the same raw
70
+ * write as anywhere else — correct, but a reader racing it can observe a half-written file,
71
+ * and a crash mid-write leaves one behind.
72
+ *
73
+ * Backends that can swap a complete file into place in one indivisible step (write to a
74
+ * sibling temp path, then rename over the target on the same filesystem) override this. It
75
+ * is separate from `writeBytesRaw` because the extra round trip only earns its cost where
76
+ * torn state is observable — which is the CAS path, not every write.
77
+ */
78
+ protected writeBytesSwap(path: string, data: Buffer): Promise<void>;
79
+ /** Decode with the shared contract: strict UTF-8 throws on invalid bytes (binary detection). */
80
+ protected decodeText(data: Buffer, options?: {
81
+ encoding?: BufferEncoding;
82
+ errors?: DecodeErrors;
83
+ }): string;
84
+ /**
85
+ * `listDir` helper for backends whose native listing hands back bare names: stat each
86
+ * entry, but in PARALLEL — the serial stat-per-entry walk is exactly what putting `kind`
87
+ * in the listing contract exists to prevent. `lstat` semantics (`followSymlinks: false`)
88
+ * to match `DirEntry`, so a symlink stays a symlink as it would in a native readdir.
89
+ *
90
+ * Backends whose readdir already reports kinds (local opendir, SFTP readdir) never call
91
+ * this — they answer in one round trip.
92
+ */
93
+ protected entriesByStatting(path: string, names: readonly string[]): Promise<readonly DirEntry[]>;
94
+ /**
95
+ * `run` derived from the process-spawning SPI: spawn, cap both streams while reading, and
96
+ * on timeout/abort escalate SIGTERM → SIGKILL. This is the logic that used to live in the
97
+ * Grep/Glob and Bash tool layers — it belongs here, where "kill the process" is something
98
+ * the backend actually knows how to do (and where a backend that CANNOT do it reports
99
+ * `terminated: false` instead of the tool pretending it worked).
100
+ *
101
+ * Backends without a process handle override this wholesale; the throw below is the
102
+ * contract's other half made loud rather than silent.
103
+ */
104
+ run(argv: readonly string[], options?: RunCommandOptions): Promise<RunCommandResult>;
105
+ /** SIGTERM, then SIGKILL if it does not exit. Returns whether the process actually stopped. */
106
+ /** How long SIGTERM gets before SIGKILL, and SIGKILL before we give up. Overridable so a
107
+ * backend (or a test) can tighten it; the default matches the shell's own convention. */
108
+ protected sigtermGraceMs: number;
109
+ private escalatingKill;
110
+ /** `spawn` has no cwd parameter; a backend without a native one runs through a subshell. */
111
+ protected withCwdArgv(argv: readonly string[], cwd: string | undefined): string[];
112
+ writeText(path: string, data: string, options?: WriteTextOptions): Promise<WriteTextResult>;
113
+ /** Exact bytes through the same primitive `writeText` uses — no encoding, no CRLF rewrite. */
114
+ writeBytes(path: string, data: Buffer): Promise<void>;
115
+ protected pathLocks: Map<string, Promise<void>>;
116
+ /** Key identifying "the same file" for the write lock. Backends with real path
117
+ * resolution override so relative and absolute spellings share one lock. */
118
+ protected lockKeyFor(path: string): string;
119
+ protected withPathLock<T>(path: string, body: () => Promise<T>): Promise<T>;
120
+ /**
121
+ * The compare half of writeTextIfUnchanged: throws unless the file still matches
122
+ * `options.expected`. Shared by the base composition and by backend overrides
123
+ * that re-check right before an atomic swap (SshMachine).
124
+ */
125
+ protected assertUnchanged(path: string, options: WriteTextIfUnchangedOptions, encoding: BufferEncoding): Promise<void>;
126
+ writeTextIfUnchanged(path: string, data: string, options: WriteTextIfUnchangedOptions): Promise<WriteFileResult>;
127
+ /** Deadline for the readlink fallback; a test/backend subclass may shorten it. */
128
+ protected realpathTimeoutMs: number;
129
+ /**
130
+ * Exec-derived fallback (`readlink -f`). A readlink that is missing/unsupported or
131
+ * exits nonzero degrades to `normpath` (best effort for backends without a native
132
+ * resolver), but a HANG throws after {@link REALPATH_TIMEOUT_MS}: path-access relies
133
+ * on realpath for its symlink guard, and a timeout silently degrading to string
134
+ * matching would fail open. Hosts with a native resolver override this for exactness.
135
+ */
136
+ realpath(path: string): Promise<string>;
137
+ }
138
+ //# sourceMappingURL=machine-base.d.ts.map