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,333 @@
1
+ /** One increment of command output. `stream` keeps stdout and stderr distinguishable —
2
+ * a PTY would merge them, which is why tool execution deliberately does not use one. */
3
+ export interface OutputChunk {
4
+ readonly stream: "stdout" | "stderr";
5
+ readonly data: string;
6
+ }
7
+ /**
8
+ * What the caller WANTS from a command run. Every field is an intent the backend fulfils
9
+ * with its own native means — local spawn + signals, SSH channel teardown, a vendor's
10
+ * `timeoutMs` + `kill(pid)`. The alternative this replaced was handing back POSIX process
11
+ * MACHINERY and making the caller assemble timeout/capping around it — an assembly that
12
+ * only ever worked on local backends, and silently did nothing everywhere else.
13
+ */
14
+ export interface RunCommandOptions {
15
+ readonly cwd?: string;
16
+ /** Overrides layered over the ambient environment, not a replacement. */
17
+ readonly env?: Record<string, string>;
18
+ readonly stdin?: string;
19
+ /** Kill the command after this long. `RunCommandResult.timedOut` reports whether it fired. */
20
+ readonly timeoutMs?: number;
21
+ /**
22
+ * Cap on captured output. Backends should stop the command at the source when they can
23
+ * rather than transferring everything and trimming after.
24
+ */
25
+ readonly maxOutputBytes?: number;
26
+ readonly signal?: AbortSignal;
27
+ /**
28
+ * Incremental output. Backends that can stream call this as output arrives; backends
29
+ * that cannot call it once at the end. Degradation lives in the contract, so a caller
30
+ * writes one code path and never queries a capability.
31
+ */
32
+ readonly onOutput?: (chunk: OutputChunk) => void;
33
+ }
34
+ export interface RunCommandResult {
35
+ readonly stdout: string;
36
+ readonly stderr: string;
37
+ /**
38
+ * `undefined` means the backend cannot confirm the command finished (e.g. a sandbox that
39
+ * yielded while it kept running). The type forces callers to face that case instead of
40
+ * receiving a fabricated 0.
41
+ */
42
+ readonly exitCode: number | undefined;
43
+ readonly timedOut: boolean;
44
+ /** Output hit `maxOutputBytes` and was cut. */
45
+ readonly truncated: boolean;
46
+ /**
47
+ * Whether the command was actually stopped when a timeout or abort demanded it. `false`
48
+ * means the backend could only walk away — surface it to the user, never pretend.
49
+ */
50
+ readonly terminated: boolean;
51
+ }
52
+ /** A byte window of a file. Both ends optional: `{}` is the whole file, `{length}` a prefix,
53
+ * `{offset}` everything from there on, both a slice. Reads past EOF return what exists. */
54
+ export interface ByteRange {
55
+ /** 0-based byte to start at. Default 0. */
56
+ readonly offset?: number;
57
+ /** Maximum bytes to return. Omit to read to EOF. */
58
+ readonly length?: number;
59
+ }
60
+ export type DecodeErrors = "strict" | "replace" | "ignore";
61
+ export type OsKind = "Linux" | "Darwin" | "Windows" | (string & {});
62
+ export type ShellName = "bash" | "zsh" | "sh" | "powershell" | "cmd" | (string & {});
63
+ export interface Environment {
64
+ readonly osKind: OsKind;
65
+ readonly osArch: string;
66
+ readonly osVersion: string;
67
+ readonly shellName: ShellName;
68
+ readonly shellPath: string;
69
+ }
70
+ export type FileKind = "file" | "dir" | "symlink" | "other";
71
+ /**
72
+ * The metadata tools actually consume — the honest cross-backend subset of stat.
73
+ * Backends without an mtime (some sandbox vendors) leave `mtimeMs` undefined;
74
+ * there is no 0-sentinel anywhere in the new surface.
75
+ */
76
+ export interface FileInfo {
77
+ readonly kind: FileKind;
78
+ /** File size in bytes. */
79
+ readonly size: number;
80
+ /** stat mtime in milliseconds. undefined = backend does not provide one. */
81
+ readonly mtimeMs?: number;
82
+ }
83
+ /**
84
+ * One entry of a directory listing, with the kind the backend already knew.
85
+ *
86
+ * `kind` is LSTAT semantics — a symlink reads as `"symlink"`, never as its target's
87
+ * kind. That is what `opendir`/`readdir` hand back for free on every backend, so a
88
+ * listing costs one round trip instead of one-per-entry. A caller that needs the
89
+ * target kind resolves just the `"symlink"` entries with `fileInfo` (which follows
90
+ * by default), paying a stat only for the entries that actually need one.
91
+ */
92
+ export interface DirEntry {
93
+ /** Entry basename, as `listDir` would return it. */
94
+ readonly name: string;
95
+ readonly kind: FileKind;
96
+ }
97
+ /**
98
+ * Version stamp for optimistic-concurrency writes. mtime and nothing else
99
+ * (local-first): on hosts with a reliable mtime the check is free; hosts
100
+ * without one (some sandbox vendors) leave `mtimeMs` undefined, and every
101
+ * check there falls back to content comparison (see FileFreshnessLedger).
102
+ * No hashing anywhere.
103
+ *
104
+ * Size deliberately plays no part. It only ever ruled on cases the mtime had
105
+ * already decided, except for one it decided WRONG: an mtime-less backend
106
+ * with an unchanged size was read as "no evidence of a change" when it is in
107
+ * fact no evidence either way. Without it, mtime-less means unverifiable
108
+ * means fall back to content — one rule instead of a matrix.
109
+ */
110
+ export interface FileVersion {
111
+ /** stat mtime in milliseconds. undefined = backend does not provide one. */
112
+ readonly mtimeMs?: number;
113
+ }
114
+ export type LineEndings = "LF" | "CRLF" | "mixed";
115
+ export interface WriteTextOptions {
116
+ readonly encoding?: BufferEncoding;
117
+ /** Line-ending style to restore on write; `data` is LF-normalized. Default LF. */
118
+ readonly lineEndings?: "LF" | "CRLF";
119
+ }
120
+ export interface WriteTextIfUnchangedOptions extends WriteTextOptions {
121
+ /**
122
+ * Expected pre-write state (REQUIRED — the name must not lie; an unconditional
123
+ * write is {@link Machine.writeText}):
124
+ * - FileVersion: file must still match (mtime-first); mismatch throws StaleFileError.
125
+ * - "must-not-exist": create-new semantics; an existing file throws FileExistsError.
126
+ */
127
+ readonly expected: FileVersion | "must-not-exist";
128
+ /**
129
+ * Prior full content (LF-normalized) for false-positive review when the mtime moved
130
+ * or is unavailable. Omit to treat any mtime change as a conflict.
131
+ */
132
+ readonly expectedContent?: string;
133
+ }
134
+ export interface WriteTextResult {
135
+ readonly bytesWritten: number;
136
+ }
137
+ export interface WriteFileResult {
138
+ readonly bytesWritten: number;
139
+ /** Post-write version, for the caller to record in its ledger. */
140
+ readonly version: FileVersion;
141
+ }
142
+ export declare class StaleFileError extends Error {
143
+ readonly code = "FILE_MODIFIED_SINCE_READ";
144
+ constructor(message?: string);
145
+ }
146
+ export declare class FileExistsError extends Error {
147
+ readonly code = "FILE_ALREADY_EXISTS";
148
+ constructor(message?: string);
149
+ }
150
+ /**
151
+ * Handle to the machine the workspace lives on.
152
+ *
153
+ * Not a filesystem abstraction: files, processes and path/OS semantics are one
154
+ * contract precisely because they must agree — a command started by `run` sees
155
+ * the same files `readBytes` reads. Every member is defined at the altitude
156
+ * each backend (local / SSH / sandbox vendor) can implement honestly:
157
+ *
158
+ * - `run` is the universal primitive — the single way anything executes, from a
159
+ * one-shot `git status` to a background build. Search-shaped operations (grep,
160
+ * glob) run a uniform binary through it rather than getting their own member.
161
+ * - File I/O is three members: `readBytes` (every read, whole file or a byte
162
+ * window), and two write contracts that are deliberately separate so each
163
+ * name is honest: `writeText` ("just write" — no staleness check, no stats,
164
+ * no version) and `writeTextIfUnchanged` (compare-and-swap for the
165
+ * read-before-write tool path; `expected` is required by the type).
166
+ * - `realpath` exists for symlink anti-bypass: path-access
167
+ * checks canonicalize before prefix-matching. The threat model is the tool
168
+ * call escaping the workspace, not the backend lying — so a `readlink -f` run
169
+ * through `run` is as authoritative as the backend's own FS view.
170
+ *
171
+ * Implementations extend {@link BaseMachine} (machine-base.ts):
172
+ * it derives the high-level operations from a small SPI so a new backend only
173
+ * writes the dumb primitives, and overrides them only where it can do better
174
+ * (single round trip, true atomicity, bounded-memory streaming).
175
+ *
176
+ * Agent bookkeeping (cron/background task state, plans, plugin registries)
177
+ * does NOT belong here — that is SessionStore's job. The rule: content owned
178
+ * by the user's workspace goes through the host; content owned by the agent's
179
+ * session goes through the store.
180
+ */
181
+ export interface Machine {
182
+ readonly name: string;
183
+ readonly osEnv: Environment;
184
+ pathClass(): "posix" | "win32";
185
+ normpath(path: string): string;
186
+ gethome(): string;
187
+ getcwd(): string;
188
+ /**
189
+ * Extra workspace roots granted the same path access as the cwd tree (the
190
+ * `--add-dir` equivalent). Consumed by the path-access policy: a path inside any of these
191
+ * resolves like an in-workspace path instead of tripping the outside-workspace guard.
192
+ * Optional — absent means "cwd only".
193
+ */
194
+ additionalDirs?(): readonly string[];
195
+ /**
196
+ * Return a sibling machine rooted at `cwd`, sharing this machine's backend
197
+ * resources (the same ssh connection / sandbox session / local machine) — only
198
+ * the working directory differs. Purely structural and cheap (no I/O); the
199
+ * symmetric counterpart of `getcwd()`. Callers that need an isolated workspace
200
+ * (e.g. a git worktree for a subagent) build it on top of this rather than the
201
+ * machine knowing anything about isolation. A relative `cwd` resolves against
202
+ * the current one. Never mutates this machine, so re-rooting one copy can't
203
+ * clobber the cwd of another that shares the same connection.
204
+ */
205
+ withCwd(cwd: string): Machine;
206
+ /**
207
+ * Public URL for a port listening inside this machine, or `undefined` when the backend
208
+ * has no way to expose one (local, ssh, a sandbox without port forwarding). A dev server
209
+ * the agent just started is only useful if someone can reach it, and only the backend
210
+ * knows the mapping — E2B's `getHost`, a vendor tunnel, and so on.
211
+ *
212
+ * This is an OPERATION on a running machine, not workspace lifecycle: it answers a
213
+ * question about a machine we were handed, and never creates or destroys anything.
214
+ * `undefined` rather than a throw, so a caller writes one code path.
215
+ */
216
+ exposedPortUrl?(port: number): Promise<string | undefined>;
217
+ /**
218
+ * Run a command to completion — the ONE way callers execute anything.
219
+ *
220
+ * Everything a caller might want from a running command is stated here as INTENT
221
+ * (timeout / output cap / cancellation / incremental output / stdin) and fulfilled by the
222
+ * backend natively. There is deliberately no "give me a process handle" alternative: a
223
+ * handle is POSIX machinery only local backends implement honestly, so callers built on
224
+ * one end up with timeouts and kills that silently do nothing over a sandbox transport.
225
+ *
226
+ * Long-running work is this same call, not-awaited: cancel through `signal`, watch through
227
+ * `onOutput`, learn how it ended from the resolved result. That is exactly what the
228
+ * background-task machinery does.
229
+ *
230
+ * `BaseMachine` derives it from a process-spawning SPI, so local and SSH backends get it
231
+ * for free; backends with native support (a vendor `timeoutMs` + `kill`) override it.
232
+ */
233
+ run(argv: readonly string[], options?: RunCommandOptions): Promise<RunCommandResult>;
234
+ /** Metadata for one path. Follows symlinks by default; `followSymlinks: false` = lstat semantics. */
235
+ fileInfo(path: string, options?: {
236
+ followSymlinks?: boolean;
237
+ }): Promise<FileInfo>;
238
+ /**
239
+ * Shallow listing: one entry per child, no `.`/`..`. Maps 1:1 to opendir / SFTP readdir /
240
+ * vendor listDir.
241
+ *
242
+ * Entries carry their `kind` because every backend's readdir already knows it — handing
243
+ * back bare names would force callers into a stat per entry, which is free locally and
244
+ * seconds of serial round trips on a remote machine. `kind` is lstat semantics; resolve
245
+ * `"symlink"` entries with `fileInfo` when the target kind matters (see `DirEntry`).
246
+ */
247
+ listDir(path: string): Promise<readonly DirEntry[]>;
248
+ /**
249
+ * Create a directory. Option contract:
250
+ * - `parents: true` — `mkdir -p`: missing ancestors are created and an existing
251
+ * directory is always OK (`existOk` is implied and effectively ignored).
252
+ * - `existOk: true` (with `parents` unset/false) — an existing DIRECTORY at `path` is
253
+ * OK; anything else occupying the path (a file) must still throw EEXIST.
254
+ * (Known deviation: `SshMachine` currently passes a file occupant through.)
255
+ * - neither — plain mkdir: throws if `path` exists or its parent is missing.
256
+ */
257
+ mkdir(path: string, options?: {
258
+ parents?: boolean;
259
+ existOk?: boolean;
260
+ }): Promise<void>;
261
+ /**
262
+ * Raw bytes, optionally a byte RANGE of them. Omit `range` for the whole file.
263
+ *
264
+ * The range is a genuine pushdown, not a convenience: every backend can read a slice
265
+ * without moving the rest (local `read(fd, …, position)`, SFTP `read` at an offset, a
266
+ * sandbox's `tail -c +N | head -c L`). That is what makes two very different callers cheap
267
+ * on every backend — sniffing a media header off the front of a 500 MB file, and following
268
+ * a growing log by reading only what is new since the last offset.
269
+ */
270
+ readBytes(path: string, range?: ByteRange): Promise<Buffer>;
271
+ /**
272
+ * Unconditional binary write — the exact bytes, no encoding and no line-ending rewriting.
273
+ * The counterpart of `readBytes`: without it, anything not valid UTF-8 (an image, an
274
+ * archive being unpacked into the workspace) has no way in, and callers resort to base64
275
+ * through a shell.
276
+ */
277
+ writeBytes(path: string, data: Buffer): Promise<void>;
278
+ /** Unconditional text write — no staleness check, no stat round trips, no version stamp. */
279
+ writeText(path: string, data: string, options?: WriteTextOptions): Promise<WriteTextResult>;
280
+ /**
281
+ * Compare-and-swap text write for the read-before-write tool path (Edit/Write + ledger).
282
+ *
283
+ * What "if unchanged" guarantees is TIERED — this is optimistic concurrency over
284
+ * backends without a CAS primitive, not an atomic instruction:
285
+ * - Same-process writers: fully serialized per file (BaseMachine's path lock;
286
+ * LocalMachine's synchronous critical section). Two concurrent calls cannot
287
+ * interleave their compare and write, and the returned `version` is the one
288
+ * this write produced, not a later sibling's.
289
+ * - External writers (other processes, remote users): the compare and the write
290
+ * are separate operations. LocalMachine's gap is sub-millisecond; remote
291
+ * backends' is ~1 round trip (SFTP and sandbox file APIs have no CAS). An
292
+ * external write landing inside that window is silently overwritten — the
293
+ * protocol ceiling, documented rather than papered over.
294
+ * - `expected: "must-not-exist"` on SshMachine is the exception: strictly atomic
295
+ * (server-enforced SFTP EXCL create), even against external writers.
296
+ *
297
+ * Errors: {@link StaleFileError} — the file changed, OR the backend could not
298
+ * establish that it hadn't (no mtime and no `expectedContent` to review against;
299
+ * unverifiable is refused, not waved through); {@link FileExistsError} —
300
+ * "must-not-exist" violated.
301
+ */
302
+ writeTextIfUnchanged(path: string, data: string, options: WriteTextIfUnchangedOptions): Promise<WriteFileResult>;
303
+ /**
304
+ * Canonicalize symlinks (security: path-access checks must canonicalize before
305
+ * prefix-matching). Derived default is `readlink -f` on posix / normpath on
306
+ * win32; hosts with a native resolver (local fs.realpath, SFTP realpath)
307
+ * override for exactness.
308
+ */
309
+ realpath(path: string): Promise<string>;
310
+ }
311
+ export interface MachineOpenContext {
312
+ readonly sessionId: string;
313
+ readonly signal: AbortSignal;
314
+ }
315
+ /**
316
+ * Lazy, per-session way to hand a session its {@link Machine} — for hosts that can only
317
+ * build one once they know the session (or that must `await` a connection). Pass a
318
+ * `Machine` directly whenever one already exists; that is the common case.
319
+ *
320
+ * Sandbox LIFECYCLE — creating, snapshotting, pausing, destroying — deliberately lives
321
+ * outside this framework. A sandbox is typically a user- or workspace-scoped resource
322
+ * whose lifetime spans many sessions (new, resumed and forked alike), so the layer that
323
+ * knows when a user is actually done is the host, not a session. The host creates the
324
+ * sandbox, hands the machine in, and disposes of it on its own terms; everything here
325
+ * only ever OPERATES a machine it was given — which is also why this type has no
326
+ * teardown half: a factory that mints a machine per session has nowhere to release it.
327
+ *
328
+ * The concrete thing this buys: nothing in a session's durable state points at a sandbox,
329
+ * so forking a session cannot silently make two sessions share one workspace, and closing
330
+ * one session cannot pull the sandbox out from under the others.
331
+ */
332
+ export type MachineFactory = (ctx: MachineOpenContext) => Machine | Promise<Machine>;
333
+ //# sourceMappingURL=machine.d.ts.map
@@ -0,0 +1,15 @@
1
+ export class StaleFileError extends Error {
2
+ code = "FILE_MODIFIED_SINCE_READ";
3
+ constructor(message = "File has been modified since read, either by the user or by a linter. Read it again before attempting to write it.") {
4
+ super(message);
5
+ this.name = "StaleFileError";
6
+ }
7
+ }
8
+ export class FileExistsError extends Error {
9
+ code = "FILE_ALREADY_EXISTS";
10
+ constructor(message = "Cannot create new file - file already exists.") {
11
+ super(message);
12
+ this.name = "FileExistsError";
13
+ }
14
+ }
15
+ //# sourceMappingURL=machine.js.map
@@ -0,0 +1,48 @@
1
+ import type { WorkspaceConfig } from "../support/workspace.ts";
2
+ import type { Machine } from "../machine.ts";
3
+ export type PathClass = "posix" | "win32";
4
+ export type PathSecurityCode = "PATH_OUTSIDE_WORKSPACE" | "PATH_SENSITIVE" | "PATH_INVALID";
5
+ export type PathAccessOperation = "read" | "write" | "search";
6
+ export type WorkspaceGuardMode = "absolute-outside-allowed" | "disabled";
7
+ export interface WorkspaceAccessPolicy {
8
+ readonly guardMode: WorkspaceGuardMode;
9
+ readonly checkSensitive: boolean;
10
+ }
11
+ export declare const DEFAULT_WORKSPACE_ACCESS_POLICY: WorkspaceAccessPolicy;
12
+ export interface PathAccess {
13
+ readonly path: string;
14
+ readonly outsideWorkspace: boolean;
15
+ }
16
+ export declare class PathSecurityError extends Error {
17
+ readonly code: PathSecurityCode;
18
+ readonly rawPath: string;
19
+ readonly canonicalPath: string;
20
+ constructor(code: PathSecurityCode, rawPath: string, canonicalPath: string, message: string);
21
+ }
22
+ export declare function normalizeUserPath(path: string, pathClass?: PathClass): string;
23
+ export declare function canonicalizePath(path: string, cwd: string, pathClass?: PathClass): string;
24
+ export declare function isWithinDirectory(candidate: string, base: string, pathClass?: PathClass): boolean;
25
+ export declare function isWithinWorkspace(candidate: string, config: WorkspaceConfig, pathClass?: PathClass): boolean;
26
+ export declare function relativePathParts(targetPath: string, cwd: string, pathClass: PathClass): string[];
27
+ export interface ResolvePathAccessOptions {
28
+ readonly operation: PathAccessOperation;
29
+ readonly policy?: WorkspaceAccessPolicy | undefined;
30
+ readonly pathClass?: PathClass | undefined;
31
+ readonly homeDir?: string;
32
+ }
33
+ export interface ResolvePathAccessPathOptions {
34
+ readonly machine: Pick<Machine, "pathClass" | "gethome" | "realpath">;
35
+ readonly workspace: WorkspaceConfig;
36
+ readonly operation: PathAccessOperation;
37
+ readonly policy?: WorkspaceAccessPolicy;
38
+ readonly expandHome?: boolean;
39
+ }
40
+ export declare function resolvePathAccess(path: string, cwd: string, config: WorkspaceConfig, options: ResolvePathAccessOptions): PathAccess;
41
+ /**
42
+ * Resolve and symlink-check a user-supplied path against the workspace. Unlike
43
+ * {@link resolvePathAccess} (pure string canonicalization), this also resolves
44
+ * symlinks via the machine so a workspace-internal symlink that targets an
45
+ * outside/sensitive path cannot be used to bypass the guard — see `Machine.realpath`.
46
+ */
47
+ export declare function resolvePathAccessPath(path: string, options: ResolvePathAccessPathOptions): Promise<string>;
48
+ //# sourceMappingURL=path-access.d.ts.map
@@ -0,0 +1,186 @@
1
+ import * as pathe from "pathe";
2
+ import { isSensitiveFile } from "./sensitive.js";
3
+ export const DEFAULT_WORKSPACE_ACCESS_POLICY = {
4
+ guardMode: "absolute-outside-allowed",
5
+ checkSensitive: true,
6
+ };
7
+ export class PathSecurityError extends Error {
8
+ code;
9
+ rawPath;
10
+ canonicalPath;
11
+ constructor(code, rawPath, canonicalPath, message) {
12
+ super(message);
13
+ this.name = "PathSecurityError";
14
+ this.code = code;
15
+ this.rawPath = rawPath;
16
+ this.canonicalPath = canonicalPath;
17
+ }
18
+ }
19
+ const DEFAULT_PATH_CLASS = process.platform === "win32" ? "win32" : "posix";
20
+ function isWin32DriveRelative(path) {
21
+ return /^[A-Za-z]:(?:$|[^\\/])/.test(path);
22
+ }
23
+ export function normalizeUserPath(path, pathClass = DEFAULT_PATH_CLASS) {
24
+ if (pathClass !== "win32")
25
+ return path;
26
+ if (path === "/")
27
+ return "/";
28
+ if (path.startsWith("//"))
29
+ return path;
30
+ const cygdriveMatch = /^\/cygdrive\/([A-Za-z])(?:\/|$)/.exec(path);
31
+ if (cygdriveMatch !== null) {
32
+ const drive = cygdriveMatch[1].toUpperCase();
33
+ const rest = path.slice(`/cygdrive/${cygdriveMatch[1]}`.length);
34
+ return `${drive}:${rest === "" ? "/" : rest}`;
35
+ }
36
+ const driveMatch = /^\/([A-Za-z])(?:\/|$)/.exec(path);
37
+ if (driveMatch !== null) {
38
+ const drive = driveMatch[1].toUpperCase();
39
+ const rest = path.slice(2);
40
+ return `${drive}:${rest === "" ? "/" : rest}`;
41
+ }
42
+ return path;
43
+ }
44
+ function expandUserPath(path, homeDir, pathClass) {
45
+ if (homeDir === undefined)
46
+ return path;
47
+ if (path === "~")
48
+ return homeDir;
49
+ if (path.startsWith("~/") || (pathClass === "win32" && path.startsWith("~\\"))) {
50
+ return pathe.join(homeDir, path.slice(2));
51
+ }
52
+ return path;
53
+ }
54
+ export function canonicalizePath(path, cwd, pathClass = DEFAULT_PATH_CLASS) {
55
+ if (path === "")
56
+ throw new PathSecurityError("PATH_INVALID", path, path, "Path cannot be empty");
57
+ const normalizedPath = normalizeUserPath(path, pathClass);
58
+ if (pathClass === "win32" && isWin32DriveRelative(normalizedPath)) {
59
+ throw new PathSecurityError("PATH_INVALID", path, normalizedPath, `"${path}" is a drive-relative Windows path. Use an absolute path like C:\\path or a path relative to the working directory.`);
60
+ }
61
+ if (!pathe.isAbsolute(normalizedPath) && !pathe.isAbsolute(cwd)) {
62
+ throw new PathSecurityError("PATH_INVALID", path, normalizedPath, `Cannot resolve "${path}" against non-absolute cwd "${cwd}".`);
63
+ }
64
+ const abs = pathe.isAbsolute(normalizedPath) ? normalizedPath : pathe.resolve(cwd, normalizedPath);
65
+ return pathe.normalize(abs);
66
+ }
67
+ export function isWithinDirectory(candidate, base, pathClass = DEFAULT_PATH_CLASS) {
68
+ const nc = pathe.normalize(candidate);
69
+ const nb = pathe.normalize(base);
70
+ const comparableCandidate = pathClass === "win32" ? nc.toLowerCase() : nc;
71
+ const comparableBase = pathClass === "win32" ? nb.toLowerCase() : nb;
72
+ if (comparableCandidate === comparableBase)
73
+ return true;
74
+ const prefix = comparableBase.endsWith("/") ? comparableBase : comparableBase + "/";
75
+ return comparableCandidate.startsWith(prefix);
76
+ }
77
+ export function isWithinWorkspace(candidate, config, pathClass = DEFAULT_PATH_CLASS) {
78
+ if (isWithinDirectory(candidate, config.workspaceDir, pathClass))
79
+ return true;
80
+ for (const dir of config.additionalDirs) {
81
+ if (isWithinDirectory(candidate, dir, pathClass))
82
+ return true;
83
+ }
84
+ return false;
85
+ }
86
+ export function relativePathParts(targetPath, cwd, pathClass) {
87
+ const rel = pathClass === "win32" ? pathe.relative(cwd, targetPath) : pathe.relative(cwd, targetPath);
88
+ return rel.split(/[\\/]+/).filter((part) => part.length > 0);
89
+ }
90
+ /**
91
+ * Symlink resolution for a path that may not fully exist yet (e.g. a file `Write`
92
+ * is about to create). Backends disagree on whether `realpath` throws for a missing
93
+ * leaf (LocalMachine does, the posix `readlink -f` fallback does not); walking up to the
94
+ * longest existing ancestor and rejoining the remainder normalizes that away so a
95
+ * merely-missing path never throws ENOENT.
96
+ *
97
+ * Only not-found errors trigger the walk-up. Anything else (EACCES, a dropped SSH
98
+ * connection, ELOOP, EIO) propagates: this function feeds a security check, and
99
+ * swallowing a transient backend failure would silently degrade the guard back to
100
+ * string-only matching — fail closed instead.
101
+ */
102
+ async function resolveRealPath(machine, path) {
103
+ try {
104
+ return await machine.realpath(path);
105
+ }
106
+ catch (error) {
107
+ if (!isNotFoundError(error))
108
+ throw error;
109
+ const parent = pathe.dirname(path);
110
+ if (parent === path)
111
+ return path;
112
+ const parentReal = await resolveRealPath(machine, parent);
113
+ return pathe.join(parentReal, pathe.basename(path));
114
+ }
115
+ }
116
+ function isNotFoundError(error) {
117
+ if (typeof error !== "object" || error === null)
118
+ return false;
119
+ const code = error["code"];
120
+ return code === "ENOENT" || code === "ENOTDIR";
121
+ }
122
+ function relativeOutsideMessage(path, operation) {
123
+ const verb = operation === "write" ? "write or edit a file" : operation === "search" ? "search" : "read a file";
124
+ return `"${path}" is not an absolute path. You must provide an absolute path to ${verb} outside the working directory.`;
125
+ }
126
+ export function resolvePathAccess(path, cwd, config, options) {
127
+ const pathClass = options.pathClass ?? DEFAULT_PATH_CLASS;
128
+ const normalizedPath = normalizeUserPath(path, pathClass);
129
+ const expandedPath = expandUserPath(normalizedPath, options.homeDir, pathClass);
130
+ const rawIsAbsolute = pathe.isAbsolute(expandedPath);
131
+ const canonical = canonicalizePath(expandedPath, cwd, pathClass);
132
+ const outsideWorkspace = !isWithinWorkspace(canonical, config, pathClass);
133
+ const policy = options.policy ?? DEFAULT_WORKSPACE_ACCESS_POLICY;
134
+ if (policy.checkSensitive && isSensitiveFile(canonical)) {
135
+ throw new PathSecurityError("PATH_SENSITIVE", path, canonical, `"${path}" matches a sensitive-file pattern (env / credential / SSH key). Access is blocked to protect secrets.`);
136
+ }
137
+ if (outsideWorkspace) {
138
+ switch (policy.guardMode) {
139
+ case "absolute-outside-allowed":
140
+ if (!rawIsAbsolute) {
141
+ throw new PathSecurityError("PATH_OUTSIDE_WORKSPACE", path, canonical, relativeOutsideMessage(path, options.operation));
142
+ }
143
+ break;
144
+ case "disabled":
145
+ break;
146
+ }
147
+ }
148
+ return { path: canonical, outsideWorkspace };
149
+ }
150
+ /**
151
+ * Resolve and symlink-check a user-supplied path against the workspace. Unlike
152
+ * {@link resolvePathAccess} (pure string canonicalization), this also resolves
153
+ * symlinks via the machine so a workspace-internal symlink that targets an
154
+ * outside/sensitive path cannot be used to bypass the guard — see `Machine.realpath`.
155
+ */
156
+ export async function resolvePathAccessPath(path, options) {
157
+ const { machine, workspace, operation, policy, expandHome = true } = options;
158
+ const pathClass = machine.pathClass();
159
+ const effectivePolicy = policy ?? DEFAULT_WORKSPACE_ACCESS_POLICY;
160
+ const access = resolvePathAccess(path, workspace.workspaceDir, workspace, {
161
+ operation,
162
+ policy,
163
+ pathClass,
164
+ homeDir: expandHome ? machine.gethome() : undefined,
165
+ });
166
+ const real = await resolveRealPath(machine, access.path);
167
+ if (real !== access.path) {
168
+ if (effectivePolicy.checkSensitive && isSensitiveFile(real)) {
169
+ throw new PathSecurityError("PATH_SENSITIVE", path, real, `"${path}" resolves through a symlink to a sensitive-file pattern (env / credential / SSH key). Access is blocked to protect secrets.`);
170
+ }
171
+ // The workspace root itself may sit behind ancestor symlinks (e.g. macOS
172
+ // /tmp -> /private/tmp), so compare against the *resolved* boundary — otherwise
173
+ // every path would spuriously look like it escaped a workspace it never left.
174
+ const realWorkspace = {
175
+ workspaceDir: await resolveRealPath(machine, workspace.workspaceDir),
176
+ additionalDirs: await Promise.all(workspace.additionalDirs.map((dir) => resolveRealPath(machine, dir))),
177
+ };
178
+ if (effectivePolicy.guardMode !== "disabled" &&
179
+ !access.outsideWorkspace &&
180
+ !isWithinWorkspace(real, realWorkspace, pathClass)) {
181
+ throw new PathSecurityError("PATH_OUTSIDE_WORKSPACE", path, real, `"${path}" resolves through a symlink to "${real}", which is outside the working directory. Access is blocked.`);
182
+ }
183
+ }
184
+ return access.path;
185
+ }
186
+ //# sourceMappingURL=path-access.js.map
@@ -0,0 +1,3 @@
1
+ export declare const SENSITIVE_DOT_VARIANT_SUFFIXES: readonly [".bak", ".backup", ".copy", ".disabled", ".key", ".old", ".orig", ".pem", ".save", ".tmp"];
2
+ export declare function isSensitiveFile(path: string): boolean;
3
+ //# sourceMappingURL=sensitive.d.ts.map
@@ -0,0 +1,60 @@
1
+ import { basename } from "node:path";
2
+ const SENSITIVE_BASENAMES = new Set([".env", "id_rsa", "id_ed25519", "id_ecdsa", "credentials"]);
3
+ const SENSITIVE_PATH_SUFFIXES = [
4
+ [".aws", "credentials"],
5
+ [".gcp", "credentials"],
6
+ ];
7
+ const ENV_PREFIX = ".env.";
8
+ const ENV_EXEMPTIONS = new Set([".env.example", ".env.sample", ".env.template"]);
9
+ const SENSITIVE_BASENAME_PREFIXES = ["id_rsa", "id_ed25519", "id_ecdsa", "credentials"];
10
+ const PUBLIC_KEY_BASENAMES = new Set(["id_rsa.pub", "id_ed25519.pub", "id_ecdsa.pub"]);
11
+ export const SENSITIVE_DOT_VARIANT_SUFFIXES = [
12
+ ".bak",
13
+ ".backup",
14
+ ".copy",
15
+ ".disabled",
16
+ ".key",
17
+ ".old",
18
+ ".orig",
19
+ ".pem",
20
+ ".save",
21
+ ".tmp",
22
+ ];
23
+ const SENSITIVE_DOT_VARIANT_SUFFIX_SET = new Set(SENSITIVE_DOT_VARIANT_SUFFIXES);
24
+ function comparable(path) {
25
+ return path.toLowerCase();
26
+ }
27
+ export function isSensitiveFile(path) {
28
+ const name = basename(path);
29
+ const comparableName = comparable(name);
30
+ const comparablePath = comparable(path);
31
+ if (ENV_EXEMPTIONS.has(comparableName))
32
+ return false;
33
+ if (PUBLIC_KEY_BASENAMES.has(comparableName))
34
+ return false;
35
+ if (SENSITIVE_BASENAMES.has(comparableName))
36
+ return true;
37
+ if (comparableName.startsWith(ENV_PREFIX))
38
+ return true;
39
+ for (const prefix of SENSITIVE_BASENAME_PREFIXES) {
40
+ if (comparableName === prefix)
41
+ return true;
42
+ if (comparableName.length > prefix.length && comparableName.startsWith(prefix)) {
43
+ const suffix = comparableName.slice(prefix.length);
44
+ const next = suffix[0];
45
+ if (next === "-" || next === "_")
46
+ return true;
47
+ if (next === "." && SENSITIVE_DOT_VARIANT_SUFFIX_SET.has(suffix))
48
+ return true;
49
+ }
50
+ }
51
+ for (const suffixParts of SENSITIVE_PATH_SUFFIXES) {
52
+ const suffix = suffixParts.join("/");
53
+ const comparableSuffix = comparable(suffix);
54
+ if (comparablePath.endsWith(`/${comparableSuffix}`) || comparablePath.includes(`/${comparableSuffix}/`)) {
55
+ return true;
56
+ }
57
+ }
58
+ return false;
59
+ }
60
+ //# sourceMappingURL=sensitive.js.map