@aria-cli/tools 1.0.13 → 1.0.15

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 (478) hide show
  1. package/dist/.aria-build-stamp.json +1 -1
  2. package/dist/ask-user-interaction.d.ts +0 -1
  3. package/dist/cache/web-cache.d.ts +0 -1
  4. package/dist/definitions/arion.d.ts +0 -1
  5. package/dist/definitions/browser/browser.d.ts +0 -1
  6. package/dist/definitions/browser/index.d.ts +0 -1
  7. package/dist/definitions/browser/pw-downloads.d.ts +0 -1
  8. package/dist/definitions/browser/pw-interactions.d.ts +0 -1
  9. package/dist/definitions/browser/pw-responses.d.ts +0 -1
  10. package/dist/definitions/browser/pw-session.d.ts +0 -1
  11. package/dist/definitions/browser/pw-shared.d.ts +0 -1
  12. package/dist/definitions/browser/pw-snapshot.d.ts +0 -1
  13. package/dist/definitions/browser/pw-state.d.ts +0 -1
  14. package/dist/definitions/browser/types.d.ts +0 -1
  15. package/dist/definitions/code-intelligence.d.ts +0 -1
  16. package/dist/definitions/core.d.ts +0 -1
  17. package/dist/definitions/delegation.d.ts +0 -1
  18. package/dist/definitions/deploy.d.ts +0 -1
  19. package/dist/definitions/filesystem.d.ts +0 -1
  20. package/dist/definitions/frg.d.ts +0 -1
  21. package/dist/definitions/index.d.ts +0 -1
  22. package/dist/definitions/memory.d.ts +0 -1
  23. package/dist/definitions/messaging.d.ts +0 -1
  24. package/dist/definitions/meta.d.ts +0 -1
  25. package/dist/definitions/network.d.ts +0 -1
  26. package/dist/definitions/outlook.d.ts +0 -1
  27. package/dist/definitions/patch/apply-patch.d.ts +0 -1
  28. package/dist/definitions/patch/fuzzy-match.d.ts +0 -1
  29. package/dist/definitions/patch/index.d.ts +0 -1
  30. package/dist/definitions/patch/patch-parser.d.ts +0 -1
  31. package/dist/definitions/patch/sandbox-paths.d.ts +0 -1
  32. package/dist/definitions/process/index.d.ts +0 -1
  33. package/dist/definitions/process/process-registry.d.ts +0 -1
  34. package/dist/definitions/process/process.d.ts +0 -1
  35. package/dist/definitions/process/pty-keys.d.ts +0 -1
  36. package/dist/definitions/process/session-slug.d.ts +0 -1
  37. package/dist/definitions/quip.d.ts +0 -1
  38. package/dist/definitions/search.d.ts +0 -1
  39. package/dist/definitions/session-history.d.ts +0 -1
  40. package/dist/definitions/shell.d.ts +0 -1
  41. package/dist/definitions/slack.d.ts +0 -1
  42. package/dist/definitions/web.d.ts +0 -1
  43. package/dist/dns-pinning-vc0r0vpx.js +1 -0
  44. package/dist/executors/apply-patch.d.ts +0 -1
  45. package/dist/executors/arion.d.ts +0 -1
  46. package/dist/executors/code-intelligence.d.ts +0 -1
  47. package/dist/executors/deploy.d.ts +0 -1
  48. package/dist/executors/filesystem.d.ts +0 -1
  49. package/dist/executors/frg-freshness.d.ts +0 -1
  50. package/dist/executors/frg.d.ts +0 -1
  51. package/dist/executors/index.d.ts +0 -1
  52. package/dist/executors/learning-meta.d.ts +0 -1
  53. package/dist/executors/lsp-client.d.ts +0 -1
  54. package/dist/executors/memory.d.ts +0 -1
  55. package/dist/executors/meta.d.ts +0 -1
  56. package/dist/executors/process-registry.d.ts +0 -1
  57. package/dist/executors/pty-session-store.d.ts +0 -1
  58. package/dist/executors/pty.d.ts +0 -1
  59. package/dist/executors/restart.d.ts +0 -1
  60. package/dist/executors/search-freshness.d.ts +0 -1
  61. package/dist/executors/search-types.d.ts +0 -1
  62. package/dist/executors/search.d.ts +0 -1
  63. package/dist/executors/self-diagnose.d.ts +0 -1
  64. package/dist/executors/session-history.d.ts +0 -1
  65. package/dist/executors/shell-safety.d.ts +0 -1
  66. package/dist/executors/shell.d.ts +0 -1
  67. package/dist/executors/utils.d.ts +0 -1
  68. package/dist/executors/web.d.ts +0 -1
  69. package/dist/extraction/content-extraction.d.ts +0 -1
  70. package/dist/extraction/index.d.ts +0 -1
  71. package/dist/headless-control-contract.d.ts +0 -1
  72. package/dist/index-6qew5tp1.js +2 -0
  73. package/dist/index-8xap0se3.js +6 -0
  74. package/dist/index-a2fr1b3x.js +2 -0
  75. package/dist/index-e1r4t0h0.js +8 -0
  76. package/dist/index-syg9gyvy.js +2 -0
  77. package/dist/index-x52t2mbj.js +4 -0
  78. package/dist/index.d.ts +0 -1
  79. package/dist/index.js +372 -71
  80. package/dist/local-control-http-auth.d.ts +0 -1
  81. package/dist/lsp-client-msnj763y.js +1 -0
  82. package/dist/mcp/client.d.ts +0 -1
  83. package/dist/mcp/connection.d.ts +0 -1
  84. package/dist/mcp/index.d.ts +0 -1
  85. package/dist/mcp/jsonrpc.d.ts +0 -1
  86. package/dist/mcp/types.d.ts +0 -1
  87. package/dist/network-control-adapter.d.ts +0 -1
  88. package/dist/network-runtime/address-types.d.ts +0 -1
  89. package/dist/network-runtime/db-owner-fencing.d.ts +0 -1
  90. package/dist/network-runtime/delivery-receipts.d.ts +0 -1
  91. package/dist/network-runtime/direct-endpoint-authority.d.ts +0 -1
  92. package/dist/network-runtime/index.d.ts +0 -1
  93. package/dist/network-runtime/index.js +1 -13
  94. package/dist/network-runtime/local-control-contract.d.ts +0 -1
  95. package/dist/network-runtime/node-store-contract.d.ts +0 -1
  96. package/dist/network-runtime/pair-route-contract.d.ts +0 -1
  97. package/dist/network-runtime/peer-capabilities.d.ts +0 -1
  98. package/dist/network-runtime/peer-principal-ref.d.ts +0 -1
  99. package/dist/network-runtime/peer-state-machine.d.ts +0 -1
  100. package/dist/network-runtime/protocol-schemas.d.ts +0 -1
  101. package/dist/network-runtime/runtime-bootstrap-contract.d.ts +0 -1
  102. package/dist/outlook/desktop-session.d.ts +0 -1
  103. package/dist/policy.d.ts +0 -1
  104. package/dist/providers/brave.d.ts +0 -1
  105. package/dist/providers/duckduckgo.d.ts +0 -1
  106. package/dist/providers/exa.d.ts +0 -1
  107. package/dist/providers/firecrawl.d.ts +0 -1
  108. package/dist/providers/index.d.ts +0 -1
  109. package/dist/providers/jina.d.ts +0 -1
  110. package/dist/providers/router.d.ts +0 -1
  111. package/dist/providers/search-provider.d.ts +0 -1
  112. package/dist/providers/tavily.d.ts +0 -1
  113. package/dist/pty-ff59hy75.js +1 -0
  114. package/dist/quip/desktop-session.d.ts +0 -1
  115. package/dist/registry/index.d.ts +0 -1
  116. package/dist/registry/registry.d.ts +0 -1
  117. package/dist/runtime-socket-local-control-client.d.ts +0 -1
  118. package/dist/security/dns-normalization.d.ts +0 -1
  119. package/dist/security/dns-pinning.d.ts +0 -1
  120. package/dist/security/external-content.d.ts +0 -1
  121. package/dist/security/ssrf.d.ts +0 -1
  122. package/dist/session-history-6gn52xhp.js +1 -0
  123. package/dist/slack/desktop-session.d.ts +0 -1
  124. package/dist/tool-factory.d.ts +0 -1
  125. package/dist/types.d.ts +0 -1
  126. package/dist/utils/retry.d.ts +0 -1
  127. package/dist/utils/safe-parse-json.d.ts +0 -1
  128. package/dist/utils/url.d.ts +0 -1
  129. package/dist-cjs/headless-control-contract.d.ts +35 -35
  130. package/dist-cjs/index.js +171 -186
  131. package/dist-cjs/network-runtime/index.js +3 -3
  132. package/dist-cjs/network-runtime/local-control-contract.d.ts +12 -12
  133. package/package.json +8 -6
  134. package/dist/.tsbuildinfo +0 -1
  135. package/dist/ask-user-interaction.d.ts.map +0 -1
  136. package/dist/ask-user-interaction.js +0 -23
  137. package/dist/ask-user-interaction.js.map +0 -1
  138. package/dist/cache/web-cache.d.ts.map +0 -1
  139. package/dist/cache/web-cache.js +0 -67
  140. package/dist/cache/web-cache.js.map +0 -1
  141. package/dist/definitions/arion.d.ts.map +0 -1
  142. package/dist/definitions/arion.js +0 -105
  143. package/dist/definitions/arion.js.map +0 -1
  144. package/dist/definitions/browser/browser.d.ts.map +0 -1
  145. package/dist/definitions/browser/browser.js +0 -419
  146. package/dist/definitions/browser/browser.js.map +0 -1
  147. package/dist/definitions/browser/index.d.ts.map +0 -1
  148. package/dist/definitions/browser/index.js +0 -5
  149. package/dist/definitions/browser/index.js.map +0 -1
  150. package/dist/definitions/browser/pw-downloads.d.ts.map +0 -1
  151. package/dist/definitions/browser/pw-downloads.js +0 -115
  152. package/dist/definitions/browser/pw-downloads.js.map +0 -1
  153. package/dist/definitions/browser/pw-interactions.d.ts.map +0 -1
  154. package/dist/definitions/browser/pw-interactions.js +0 -200
  155. package/dist/definitions/browser/pw-interactions.js.map +0 -1
  156. package/dist/definitions/browser/pw-responses.d.ts.map +0 -1
  157. package/dist/definitions/browser/pw-responses.js +0 -77
  158. package/dist/definitions/browser/pw-responses.js.map +0 -1
  159. package/dist/definitions/browser/pw-session.d.ts.map +0 -1
  160. package/dist/definitions/browser/pw-session.js +0 -311
  161. package/dist/definitions/browser/pw-session.js.map +0 -1
  162. package/dist/definitions/browser/pw-shared.d.ts.map +0 -1
  163. package/dist/definitions/browser/pw-shared.js +0 -67
  164. package/dist/definitions/browser/pw-shared.js.map +0 -1
  165. package/dist/definitions/browser/pw-snapshot.d.ts.map +0 -1
  166. package/dist/definitions/browser/pw-snapshot.js +0 -302
  167. package/dist/definitions/browser/pw-snapshot.js.map +0 -1
  168. package/dist/definitions/browser/pw-state.d.ts.map +0 -1
  169. package/dist/definitions/browser/pw-state.js +0 -63
  170. package/dist/definitions/browser/pw-state.js.map +0 -1
  171. package/dist/definitions/browser/types.d.ts.map +0 -1
  172. package/dist/definitions/browser/types.js +0 -5
  173. package/dist/definitions/browser/types.js.map +0 -1
  174. package/dist/definitions/code-intelligence.d.ts.map +0 -1
  175. package/dist/definitions/code-intelligence.js +0 -471
  176. package/dist/definitions/code-intelligence.js.map +0 -1
  177. package/dist/definitions/core.d.ts.map +0 -1
  178. package/dist/definitions/core.js +0 -110
  179. package/dist/definitions/core.js.map +0 -1
  180. package/dist/definitions/delegation.d.ts.map +0 -1
  181. package/dist/definitions/delegation.js +0 -513
  182. package/dist/definitions/delegation.js.map +0 -1
  183. package/dist/definitions/deploy.d.ts.map +0 -1
  184. package/dist/definitions/deploy.js +0 -66
  185. package/dist/definitions/deploy.js.map +0 -1
  186. package/dist/definitions/filesystem.d.ts.map +0 -1
  187. package/dist/definitions/filesystem.js +0 -197
  188. package/dist/definitions/filesystem.js.map +0 -1
  189. package/dist/definitions/frg.d.ts.map +0 -1
  190. package/dist/definitions/frg.js +0 -64
  191. package/dist/definitions/frg.js.map +0 -1
  192. package/dist/definitions/index.d.ts.map +0 -1
  193. package/dist/definitions/index.js +0 -21
  194. package/dist/definitions/index.js.map +0 -1
  195. package/dist/definitions/memory.d.ts.map +0 -1
  196. package/dist/definitions/memory.js +0 -124
  197. package/dist/definitions/memory.js.map +0 -1
  198. package/dist/definitions/messaging.d.ts.map +0 -1
  199. package/dist/definitions/messaging.js +0 -626
  200. package/dist/definitions/messaging.js.map +0 -1
  201. package/dist/definitions/meta.d.ts.map +0 -1
  202. package/dist/definitions/meta.js +0 -350
  203. package/dist/definitions/meta.js.map +0 -1
  204. package/dist/definitions/network.d.ts.map +0 -1
  205. package/dist/definitions/network.js +0 -160
  206. package/dist/definitions/network.js.map +0 -1
  207. package/dist/definitions/outlook.d.ts.map +0 -1
  208. package/dist/definitions/outlook.js +0 -278
  209. package/dist/definitions/outlook.js.map +0 -1
  210. package/dist/definitions/patch/apply-patch.d.ts.map +0 -1
  211. package/dist/definitions/patch/apply-patch.js +0 -185
  212. package/dist/definitions/patch/apply-patch.js.map +0 -1
  213. package/dist/definitions/patch/fuzzy-match.d.ts.map +0 -1
  214. package/dist/definitions/patch/fuzzy-match.js +0 -167
  215. package/dist/definitions/patch/fuzzy-match.js.map +0 -1
  216. package/dist/definitions/patch/index.d.ts.map +0 -1
  217. package/dist/definitions/patch/index.js +0 -2
  218. package/dist/definitions/patch/index.js.map +0 -1
  219. package/dist/definitions/patch/patch-parser.d.ts.map +0 -1
  220. package/dist/definitions/patch/patch-parser.js +0 -208
  221. package/dist/definitions/patch/patch-parser.js.map +0 -1
  222. package/dist/definitions/patch/sandbox-paths.d.ts.map +0 -1
  223. package/dist/definitions/patch/sandbox-paths.js +0 -106
  224. package/dist/definitions/patch/sandbox-paths.js.map +0 -1
  225. package/dist/definitions/process/index.d.ts.map +0 -1
  226. package/dist/definitions/process/index.js +0 -5
  227. package/dist/definitions/process/index.js.map +0 -1
  228. package/dist/definitions/process/process-registry.d.ts.map +0 -1
  229. package/dist/definitions/process/process-registry.js +0 -214
  230. package/dist/definitions/process/process-registry.js.map +0 -1
  231. package/dist/definitions/process/process.d.ts.map +0 -1
  232. package/dist/definitions/process/process.js +0 -387
  233. package/dist/definitions/process/process.js.map +0 -1
  234. package/dist/definitions/process/pty-keys.d.ts.map +0 -1
  235. package/dist/definitions/process/pty-keys.js +0 -255
  236. package/dist/definitions/process/pty-keys.js.map +0 -1
  237. package/dist/definitions/process/session-slug.d.ts.map +0 -1
  238. package/dist/definitions/process/session-slug.js +0 -143
  239. package/dist/definitions/process/session-slug.js.map +0 -1
  240. package/dist/definitions/quip.d.ts.map +0 -1
  241. package/dist/definitions/quip.js +0 -196
  242. package/dist/definitions/quip.js.map +0 -1
  243. package/dist/definitions/search.d.ts.map +0 -1
  244. package/dist/definitions/search.js +0 -61
  245. package/dist/definitions/search.js.map +0 -1
  246. package/dist/definitions/session-history.d.ts.map +0 -1
  247. package/dist/definitions/session-history.js +0 -70
  248. package/dist/definitions/session-history.js.map +0 -1
  249. package/dist/definitions/shell.d.ts.map +0 -1
  250. package/dist/definitions/shell.js +0 -182
  251. package/dist/definitions/shell.js.map +0 -1
  252. package/dist/definitions/slack.d.ts.map +0 -1
  253. package/dist/definitions/slack.js +0 -181
  254. package/dist/definitions/slack.js.map +0 -1
  255. package/dist/definitions/web.d.ts.map +0 -1
  256. package/dist/definitions/web.js +0 -110
  257. package/dist/definitions/web.js.map +0 -1
  258. package/dist/executors/apply-patch.d.ts.map +0 -1
  259. package/dist/executors/apply-patch.js +0 -902
  260. package/dist/executors/apply-patch.js.map +0 -1
  261. package/dist/executors/arion.d.ts.map +0 -1
  262. package/dist/executors/arion.js +0 -120
  263. package/dist/executors/arion.js.map +0 -1
  264. package/dist/executors/code-intelligence.d.ts.map +0 -1
  265. package/dist/executors/code-intelligence.js +0 -883
  266. package/dist/executors/code-intelligence.js.map +0 -1
  267. package/dist/executors/deploy.d.ts.map +0 -1
  268. package/dist/executors/deploy.js +0 -849
  269. package/dist/executors/deploy.js.map +0 -1
  270. package/dist/executors/filesystem.d.ts.map +0 -1
  271. package/dist/executors/filesystem.js +0 -1123
  272. package/dist/executors/filesystem.js.map +0 -1
  273. package/dist/executors/frg-freshness.d.ts.map +0 -1
  274. package/dist/executors/frg-freshness.js +0 -577
  275. package/dist/executors/frg-freshness.js.map +0 -1
  276. package/dist/executors/frg.d.ts.map +0 -1
  277. package/dist/executors/frg.js +0 -299
  278. package/dist/executors/frg.js.map +0 -1
  279. package/dist/executors/index.d.ts.map +0 -1
  280. package/dist/executors/index.js +0 -47
  281. package/dist/executors/index.js.map +0 -1
  282. package/dist/executors/learning-meta.d.ts.map +0 -1
  283. package/dist/executors/learning-meta.js +0 -1147
  284. package/dist/executors/learning-meta.js.map +0 -1
  285. package/dist/executors/lsp-client.d.ts.map +0 -1
  286. package/dist/executors/lsp-client.js +0 -297
  287. package/dist/executors/lsp-client.js.map +0 -1
  288. package/dist/executors/memory.d.ts.map +0 -1
  289. package/dist/executors/memory.js +0 -751
  290. package/dist/executors/memory.js.map +0 -1
  291. package/dist/executors/meta.d.ts.map +0 -1
  292. package/dist/executors/meta.js +0 -221
  293. package/dist/executors/meta.js.map +0 -1
  294. package/dist/executors/process-registry.d.ts.map +0 -1
  295. package/dist/executors/process-registry.js +0 -466
  296. package/dist/executors/process-registry.js.map +0 -1
  297. package/dist/executors/pty-session-store.d.ts.map +0 -1
  298. package/dist/executors/pty-session-store.js +0 -31
  299. package/dist/executors/pty-session-store.js.map +0 -1
  300. package/dist/executors/pty.d.ts.map +0 -1
  301. package/dist/executors/pty.js +0 -272
  302. package/dist/executors/pty.js.map +0 -1
  303. package/dist/executors/restart.d.ts.map +0 -1
  304. package/dist/executors/restart.js +0 -120
  305. package/dist/executors/restart.js.map +0 -1
  306. package/dist/executors/search-freshness.d.ts.map +0 -1
  307. package/dist/executors/search-freshness.js +0 -196
  308. package/dist/executors/search-freshness.js.map +0 -1
  309. package/dist/executors/search-types.d.ts.map +0 -1
  310. package/dist/executors/search-types.js +0 -53
  311. package/dist/executors/search-types.js.map +0 -1
  312. package/dist/executors/search.d.ts.map +0 -1
  313. package/dist/executors/search.js +0 -67
  314. package/dist/executors/search.js.map +0 -1
  315. package/dist/executors/self-diagnose.d.ts.map +0 -1
  316. package/dist/executors/self-diagnose.js +0 -399
  317. package/dist/executors/self-diagnose.js.map +0 -1
  318. package/dist/executors/session-history.d.ts.map +0 -1
  319. package/dist/executors/session-history.js +0 -284
  320. package/dist/executors/session-history.js.map +0 -1
  321. package/dist/executors/shell-safety.d.ts.map +0 -1
  322. package/dist/executors/shell-safety.js +0 -474
  323. package/dist/executors/shell-safety.js.map +0 -1
  324. package/dist/executors/shell.d.ts.map +0 -1
  325. package/dist/executors/shell.js +0 -955
  326. package/dist/executors/shell.js.map +0 -1
  327. package/dist/executors/utils.d.ts.map +0 -1
  328. package/dist/executors/utils.js +0 -34
  329. package/dist/executors/utils.js.map +0 -1
  330. package/dist/executors/web.d.ts.map +0 -1
  331. package/dist/executors/web.js +0 -543
  332. package/dist/executors/web.js.map +0 -1
  333. package/dist/extraction/content-extraction.d.ts.map +0 -1
  334. package/dist/extraction/content-extraction.js +0 -236
  335. package/dist/extraction/content-extraction.js.map +0 -1
  336. package/dist/extraction/index.d.ts.map +0 -1
  337. package/dist/extraction/index.js +0 -5
  338. package/dist/extraction/index.js.map +0 -1
  339. package/dist/headless-control-contract.d.ts.map +0 -1
  340. package/dist/headless-control-contract.js +0 -968
  341. package/dist/headless-control-contract.js.map +0 -1
  342. package/dist/index.d.ts.map +0 -1
  343. package/dist/index.js.map +0 -1
  344. package/dist/local-control-http-auth.d.ts.map +0 -1
  345. package/dist/local-control-http-auth.js +0 -3
  346. package/dist/local-control-http-auth.js.map +0 -1
  347. package/dist/mcp/client.d.ts.map +0 -1
  348. package/dist/mcp/client.js +0 -182
  349. package/dist/mcp/client.js.map +0 -1
  350. package/dist/mcp/connection.d.ts.map +0 -1
  351. package/dist/mcp/connection.js +0 -481
  352. package/dist/mcp/connection.js.map +0 -1
  353. package/dist/mcp/index.d.ts.map +0 -1
  354. package/dist/mcp/index.js +0 -11
  355. package/dist/mcp/index.js.map +0 -1
  356. package/dist/mcp/jsonrpc.d.ts.map +0 -1
  357. package/dist/mcp/jsonrpc.js +0 -145
  358. package/dist/mcp/jsonrpc.js.map +0 -1
  359. package/dist/mcp/types.d.ts.map +0 -1
  360. package/dist/mcp/types.js +0 -8
  361. package/dist/mcp/types.js.map +0 -1
  362. package/dist/network-control-adapter.d.ts.map +0 -1
  363. package/dist/network-control-adapter.js +0 -73
  364. package/dist/network-control-adapter.js.map +0 -1
  365. package/dist/network-runtime/address-types.d.ts.map +0 -1
  366. package/dist/network-runtime/address-types.js +0 -166
  367. package/dist/network-runtime/address-types.js.map +0 -1
  368. package/dist/network-runtime/db-owner-fencing.d.ts.map +0 -1
  369. package/dist/network-runtime/db-owner-fencing.js +0 -70
  370. package/dist/network-runtime/db-owner-fencing.js.map +0 -1
  371. package/dist/network-runtime/delivery-receipts.d.ts.map +0 -1
  372. package/dist/network-runtime/delivery-receipts.js +0 -268
  373. package/dist/network-runtime/delivery-receipts.js.map +0 -1
  374. package/dist/network-runtime/direct-endpoint-authority.d.ts.map +0 -1
  375. package/dist/network-runtime/direct-endpoint-authority.js +0 -26
  376. package/dist/network-runtime/direct-endpoint-authority.js.map +0 -1
  377. package/dist/network-runtime/index.d.ts.map +0 -1
  378. package/dist/network-runtime/index.js.map +0 -1
  379. package/dist/network-runtime/local-control-contract.d.ts.map +0 -1
  380. package/dist/network-runtime/local-control-contract.js +0 -628
  381. package/dist/network-runtime/local-control-contract.js.map +0 -1
  382. package/dist/network-runtime/node-store-contract.d.ts.map +0 -1
  383. package/dist/network-runtime/node-store-contract.js +0 -35
  384. package/dist/network-runtime/node-store-contract.js.map +0 -1
  385. package/dist/network-runtime/pair-route-contract.d.ts.map +0 -1
  386. package/dist/network-runtime/pair-route-contract.js +0 -78
  387. package/dist/network-runtime/pair-route-contract.js.map +0 -1
  388. package/dist/network-runtime/peer-capabilities.d.ts.map +0 -1
  389. package/dist/network-runtime/peer-capabilities.js +0 -29
  390. package/dist/network-runtime/peer-capabilities.js.map +0 -1
  391. package/dist/network-runtime/peer-principal-ref.d.ts.map +0 -1
  392. package/dist/network-runtime/peer-principal-ref.js +0 -13
  393. package/dist/network-runtime/peer-principal-ref.js.map +0 -1
  394. package/dist/network-runtime/peer-state-machine.d.ts.map +0 -1
  395. package/dist/network-runtime/peer-state-machine.js +0 -122
  396. package/dist/network-runtime/peer-state-machine.js.map +0 -1
  397. package/dist/network-runtime/protocol-schemas.d.ts.map +0 -1
  398. package/dist/network-runtime/protocol-schemas.js +0 -206
  399. package/dist/network-runtime/protocol-schemas.js.map +0 -1
  400. package/dist/network-runtime/runtime-bootstrap-contract.d.ts.map +0 -1
  401. package/dist/network-runtime/runtime-bootstrap-contract.js +0 -61
  402. package/dist/network-runtime/runtime-bootstrap-contract.js.map +0 -1
  403. package/dist/outlook/desktop-session.d.ts.map +0 -1
  404. package/dist/outlook/desktop-session.js +0 -280
  405. package/dist/outlook/desktop-session.js.map +0 -1
  406. package/dist/policy.d.ts.map +0 -1
  407. package/dist/policy.js +0 -150
  408. package/dist/policy.js.map +0 -1
  409. package/dist/providers/brave.d.ts.map +0 -1
  410. package/dist/providers/brave.js +0 -63
  411. package/dist/providers/brave.js.map +0 -1
  412. package/dist/providers/duckduckgo.d.ts.map +0 -1
  413. package/dist/providers/duckduckgo.js +0 -177
  414. package/dist/providers/duckduckgo.js.map +0 -1
  415. package/dist/providers/exa.d.ts.map +0 -1
  416. package/dist/providers/exa.js +0 -64
  417. package/dist/providers/exa.js.map +0 -1
  418. package/dist/providers/firecrawl.d.ts.map +0 -1
  419. package/dist/providers/firecrawl.js +0 -56
  420. package/dist/providers/firecrawl.js.map +0 -1
  421. package/dist/providers/index.d.ts.map +0 -1
  422. package/dist/providers/index.js +0 -8
  423. package/dist/providers/index.js.map +0 -1
  424. package/dist/providers/jina.d.ts.map +0 -1
  425. package/dist/providers/jina.js +0 -50
  426. package/dist/providers/jina.js.map +0 -1
  427. package/dist/providers/router.d.ts.map +0 -1
  428. package/dist/providers/router.js +0 -97
  429. package/dist/providers/router.js.map +0 -1
  430. package/dist/providers/search-provider.d.ts.map +0 -1
  431. package/dist/providers/search-provider.js +0 -33
  432. package/dist/providers/search-provider.js.map +0 -1
  433. package/dist/providers/tavily.d.ts.map +0 -1
  434. package/dist/providers/tavily.js +0 -55
  435. package/dist/providers/tavily.js.map +0 -1
  436. package/dist/quip/desktop-session.d.ts.map +0 -1
  437. package/dist/quip/desktop-session.js +0 -318
  438. package/dist/quip/desktop-session.js.map +0 -1
  439. package/dist/registry/index.d.ts.map +0 -1
  440. package/dist/registry/index.js +0 -2
  441. package/dist/registry/index.js.map +0 -1
  442. package/dist/registry/registry.d.ts.map +0 -1
  443. package/dist/registry/registry.js +0 -757
  444. package/dist/registry/registry.js.map +0 -1
  445. package/dist/runtime-socket-local-control-client.d.ts.map +0 -1
  446. package/dist/runtime-socket-local-control-client.js +0 -331
  447. package/dist/runtime-socket-local-control-client.js.map +0 -1
  448. package/dist/security/dns-normalization.d.ts.map +0 -1
  449. package/dist/security/dns-normalization.js +0 -20
  450. package/dist/security/dns-normalization.js.map +0 -1
  451. package/dist/security/dns-pinning.d.ts.map +0 -1
  452. package/dist/security/dns-pinning.js +0 -124
  453. package/dist/security/dns-pinning.js.map +0 -1
  454. package/dist/security/external-content.d.ts.map +0 -1
  455. package/dist/security/external-content.js +0 -92
  456. package/dist/security/external-content.js.map +0 -1
  457. package/dist/security/ssrf.d.ts.map +0 -1
  458. package/dist/security/ssrf.js +0 -182
  459. package/dist/security/ssrf.js.map +0 -1
  460. package/dist/slack/desktop-session.d.ts.map +0 -1
  461. package/dist/slack/desktop-session.js +0 -325
  462. package/dist/slack/desktop-session.js.map +0 -1
  463. package/dist/tool-factory.d.ts.map +0 -1
  464. package/dist/tool-factory.js +0 -48
  465. package/dist/tool-factory.js.map +0 -1
  466. package/dist/types.d.ts.map +0 -1
  467. package/dist/types.js +0 -8
  468. package/dist/types.js.map +0 -1
  469. package/dist/utils/retry.d.ts.map +0 -1
  470. package/dist/utils/retry.js +0 -133
  471. package/dist/utils/retry.js.map +0 -1
  472. package/dist/utils/safe-parse-json.d.ts.map +0 -1
  473. package/dist/utils/safe-parse-json.js +0 -161
  474. package/dist/utils/safe-parse-json.js.map +0 -1
  475. package/dist/utils/url.d.ts.map +0 -1
  476. package/dist/utils/url.js +0 -20
  477. package/dist/utils/url.js.map +0 -1
  478. package/dist-cjs/.tsbuildinfo +0 -1
@@ -1,902 +0,0 @@
1
- /**
2
- * @aria/tools - Apply Patch executor
3
- *
4
- * Parses and applies unified diff patches with:
5
- * - Path traversal protection (SECURITY-CRITICAL)
6
- * - Atomic writes (all-or-nothing application)
7
- * - Fuzzy hunk matching (offset tolerance)
8
- * - CRLF normalization
9
- */
10
- import * as crypto from "node:crypto";
11
- import * as fs from "node:fs/promises";
12
- import * as fsSync from "node:fs";
13
- import * as nodePath from "node:path";
14
- import { success, fail, getErrorMessage, isPathWithinBase } from "./utils.js";
15
- import { recordFrgMutation } from "./frg-freshness.js";
16
- import { recordSearchMutation } from "./search-freshness.js";
17
- function getErrnoCode(err) {
18
- if (typeof err !== "object" || err === null) {
19
- return undefined;
20
- }
21
- const withCode = err;
22
- return typeof withCode.code === "string" ? withCode.code : undefined;
23
- }
24
- // Maximum fuzzy offset when searching for hunk context
25
- const MAX_FUZZ_OFFSET = 3;
26
- const BEGIN_PATCH = "*** Begin Patch";
27
- const END_PATCH = "*** End Patch";
28
- const ADD_FILE = "*** Add File: ";
29
- const DELETE_FILE = "*** Delete File: ";
30
- const UPDATE_FILE = "*** Update File: ";
31
- const MOVE_TO = "*** Move to: ";
32
- const END_OF_FILE = "*** End of File";
33
- // ============================================================================
34
- // Unified Diff Parser
35
- // ============================================================================
36
- /**
37
- * Parse a unified diff string into an array of file diffs.
38
- * Handles standard unified diff and git-style diffs.
39
- */
40
- export function parseUnifiedDiff(patch) {
41
- // Normalize CRLF to LF
42
- const normalized = patch.replace(/\r\n/g, "\n");
43
- const lines = normalized.split("\n");
44
- const diffs = [];
45
- let i = 0;
46
- while (i < lines.length) {
47
- const line = lines[i];
48
- // Look for --- header
49
- if (line.startsWith("--- ")) {
50
- // Check for binary diff markers before this point
51
- // (we check later too, but early check is good)
52
- const nextLine = lines[i + 1];
53
- if (!nextLine || !nextLine.startsWith("+++ ")) {
54
- i++;
55
- continue;
56
- }
57
- const oldPath = parseDiffPath(line.slice(4));
58
- const newPath = parseDiffPath(nextLine.slice(4));
59
- i += 2;
60
- // Parse hunks for this file
61
- const hunks = [];
62
- while (i < lines.length) {
63
- const hunkLine = lines[i];
64
- if (hunkLine.startsWith("@@ ")) {
65
- const hunk = parseHunkHeader(hunkLine);
66
- if (!hunk) {
67
- throw new Error(`Invalid hunk header: ${hunkLine}`);
68
- }
69
- i++;
70
- // Collect hunk lines
71
- const hunkLines = [];
72
- let oldSeen = 0;
73
- let newSeen = 0;
74
- while (i < lines.length) {
75
- const l = lines[i];
76
- const prefix = l[0];
77
- if (prefix === " " || prefix === "+" || prefix === "-") {
78
- hunkLines.push(l);
79
- if (prefix === " " || prefix === "-")
80
- oldSeen++;
81
- if (prefix === " " || prefix === "+")
82
- newSeen++;
83
- i++;
84
- // Unified diff hunks define old/new line counts explicitly.
85
- // Stop when we consumed the declared line counts so a following
86
- // file header ("--- ...") is not misread as hunk content.
87
- if (oldSeen >= hunk.oldCount && newSeen >= hunk.newCount) {
88
- break;
89
- }
90
- }
91
- else if (l === "\") {
92
- // Skip this marker — we handle trailing newlines via content
93
- i++;
94
- }
95
- else {
96
- break;
97
- }
98
- }
99
- if (i < lines.length) {
100
- const next = lines[i];
101
- const nextPrefix = next[0];
102
- const looksLikeHunkLine = nextPrefix === " " ||
103
- (nextPrefix === "+" && !next.startsWith("+++ ")) ||
104
- (nextPrefix === "-" && !next.startsWith("--- "));
105
- if (looksLikeHunkLine) {
106
- throw new Error(`Malformed hunk: expected old/new counts ${hunk.oldCount}/${hunk.newCount} but found extra hunk lines`);
107
- }
108
- }
109
- if (oldSeen !== hunk.oldCount || newSeen !== hunk.newCount) {
110
- throw new Error(`Malformed hunk: expected old/new counts ${hunk.oldCount}/${hunk.newCount} but found ${oldSeen}/${newSeen}`);
111
- }
112
- hunks.push({ ...hunk, lines: hunkLines });
113
- }
114
- else if (hunkLine.startsWith("--- ") || hunkLine.startsWith("diff ") || hunkLine === "") {
115
- // Start of next file diff or blank line separator
116
- break;
117
- }
118
- else {
119
- // Skip git diff metadata lines (index, mode, etc.)
120
- i++;
121
- }
122
- }
123
- if (hunks.length > 0 || oldPath === null || newPath === null) {
124
- diffs.push({ oldPath, newPath, hunks });
125
- }
126
- }
127
- else if (line.startsWith("Binary files") || line.startsWith("GIT binary patch")) {
128
- throw new Error(`Binary diffs are not supported: ${line}`);
129
- }
130
- else {
131
- i++;
132
- }
133
- }
134
- return diffs;
135
- }
136
- function buildCountedHunk(lines) {
137
- let oldCount = 0;
138
- let newCount = 0;
139
- for (const line of lines) {
140
- if (line.startsWith(" ") || line.startsWith("-"))
141
- oldCount++;
142
- if (line.startsWith(" ") || line.startsWith("+"))
143
- newCount++;
144
- }
145
- return {
146
- oldStart: 1,
147
- oldCount,
148
- newStart: 1,
149
- newCount,
150
- lines,
151
- };
152
- }
153
- function parseHeaderPath(line, prefix) {
154
- const raw = line.slice(prefix.length).trim();
155
- if (!raw) {
156
- throw new Error(`Missing file path after header: ${prefix.trim()}`);
157
- }
158
- return raw;
159
- }
160
- function parseBeginPatchFormat(patch) {
161
- const lines = normalizePatchText(patch).split("\n");
162
- if ((lines[0] ?? "").trim() !== BEGIN_PATCH) {
163
- throw new Error("Invalid apply_patch envelope: missing *** Begin Patch");
164
- }
165
- const diffs = [];
166
- let i = 1;
167
- while (i < lines.length) {
168
- const line = lines[i] ?? "";
169
- if (line === END_PATCH) {
170
- return diffs;
171
- }
172
- if (line.trim() === "") {
173
- i++;
174
- continue;
175
- }
176
- if (line.startsWith(ADD_FILE)) {
177
- const newPath = parseHeaderPath(line, ADD_FILE);
178
- i++;
179
- const addLines = [];
180
- while (i < lines.length) {
181
- const current = lines[i] ?? "";
182
- if (current.startsWith("*** "))
183
- break;
184
- if (!current.startsWith("+")) {
185
- throw new Error(`Invalid add-file line (must start with '+'): ${current}`);
186
- }
187
- addLines.push(current);
188
- i++;
189
- }
190
- diffs.push({
191
- oldPath: null,
192
- newPath,
193
- hunks: [buildCountedHunk(addLines)],
194
- });
195
- continue;
196
- }
197
- if (line.startsWith(DELETE_FILE)) {
198
- const oldPath = parseHeaderPath(line, DELETE_FILE);
199
- diffs.push({ oldPath, newPath: null, hunks: [] });
200
- i++;
201
- continue;
202
- }
203
- if (line.startsWith(UPDATE_FILE)) {
204
- const oldPath = parseHeaderPath(line, UPDATE_FILE);
205
- i++;
206
- let newPath = oldPath;
207
- if ((lines[i] ?? "").startsWith(MOVE_TO)) {
208
- newPath = parseHeaderPath(lines[i], MOVE_TO);
209
- i++;
210
- }
211
- const hunks = [];
212
- let currentHunkLines = [];
213
- while (i < lines.length) {
214
- const current = lines[i] ?? "";
215
- if (current.startsWith("*** "))
216
- break;
217
- if (current.startsWith("@@")) {
218
- if (currentHunkLines.length > 0) {
219
- hunks.push(buildCountedHunk(currentHunkLines));
220
- currentHunkLines = [];
221
- }
222
- i++;
223
- continue;
224
- }
225
- if (current === END_OF_FILE) {
226
- i++;
227
- continue;
228
- }
229
- if (current.startsWith(" ") || current.startsWith("+") || current.startsWith("-")) {
230
- currentHunkLines.push(current);
231
- i++;
232
- continue;
233
- }
234
- throw new Error(`Invalid update-file line: ${current}`);
235
- }
236
- if (currentHunkLines.length > 0) {
237
- hunks.push(buildCountedHunk(currentHunkLines));
238
- }
239
- if (hunks.length === 0 && oldPath === newPath) {
240
- throw new Error(`Update section has no hunks: ${oldPath}`);
241
- }
242
- diffs.push({ oldPath, newPath, hunks });
243
- continue;
244
- }
245
- throw new Error(`Invalid apply_patch section header: ${line}`);
246
- }
247
- throw new Error("Invalid apply_patch envelope: missing *** End Patch");
248
- }
249
- function normalizePatchText(patch) {
250
- return patch.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
251
- }
252
- function parsePatchInput(patch) {
253
- const normalized = normalizePatchText(patch).trimStart();
254
- if (normalized.startsWith(BEGIN_PATCH)) {
255
- return parseBeginPatchFormat(normalized);
256
- }
257
- return parseUnifiedDiff(normalized);
258
- }
259
- /**
260
- * Parse a file path from a --- or +++ line.
261
- * Strips a/ or b/ git-style prefixes.
262
- * Returns null for /dev/null (new file or deleted file).
263
- */
264
- function parseDiffPath(raw) {
265
- // Remove trailing timestamp (e.g., "2024-01-01 00:00:00.000000000 +0000")
266
- const path = raw.replace(/\t.*$/, "").trim();
267
- if (path === "/dev/null") {
268
- return null;
269
- }
270
- // Strip git-style a/ or b/ prefix
271
- if (path.startsWith("a/") || path.startsWith("b/")) {
272
- return path.slice(2);
273
- }
274
- return path;
275
- }
276
- /**
277
- * Parse a hunk header line: @@ -oldStart,oldCount +newStart,newCount @@
278
- */
279
- function parseHunkHeader(line) {
280
- const match = line.match(/^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@/);
281
- if (!match)
282
- return null;
283
- return {
284
- oldStart: parseInt(match[1], 10),
285
- oldCount: match[2] !== undefined ? parseInt(match[2], 10) : 1,
286
- newStart: parseInt(match[3], 10),
287
- newCount: match[4] !== undefined ? parseInt(match[4], 10) : 1,
288
- };
289
- }
290
- // ============================================================================
291
- // Path Validation (SECURITY-CRITICAL)
292
- // ============================================================================
293
- /**
294
- * Validate all paths in a parsed diff against path traversal attacks.
295
- *
296
- * SECURITY: This is the primary defense against malicious patches that
297
- * attempt to write outside the working directory.
298
- */
299
- function validatePatchPaths(diffs, cwd) {
300
- const resolved = new Map();
301
- for (const diff of diffs) {
302
- const paths = [diff.oldPath, diff.newPath].filter((p) => p !== null);
303
- for (const rawPath of paths) {
304
- if (resolved.has(rawPath))
305
- continue;
306
- // 1. Reject absolute paths
307
- if (nodePath.isAbsolute(rawPath)) {
308
- return {
309
- valid: false,
310
- error: `Absolute path not allowed in patch: ${rawPath}`,
311
- };
312
- }
313
- // 2. Reject paths with .. components
314
- const segments = rawPath.split(/[/\\]/);
315
- if (segments.includes("..")) {
316
- return {
317
- valid: false,
318
- error: `Path traversal (..) not allowed in patch: ${rawPath}`,
319
- };
320
- }
321
- // 3. Reject system paths (even though relative shouldn't reach these,
322
- // defense-in-depth against creative path construction)
323
- const systemPrefixes = ["/dev/", "/proc/", "/sys/", "/etc/"];
324
- for (const prefix of systemPrefixes) {
325
- if (rawPath.startsWith(prefix) || rawPath === prefix.slice(0, -1)) {
326
- return {
327
- valid: false,
328
- error: `System path not allowed in patch: ${rawPath}`,
329
- };
330
- }
331
- }
332
- // 4. Resolve relative to cwd
333
- const fullPath = nodePath.resolve(cwd, rawPath);
334
- // 5. Verify the resolved path is within cwd
335
- // Resolve symlinks on cwd to handle platforms where /tmp -> /private/tmp
336
- let realCwd = cwd;
337
- try {
338
- realCwd = fsSync.realpathSync(cwd);
339
- }
340
- catch {
341
- // Fall back to original cwd if it doesn't exist yet
342
- }
343
- // Resolve symlinks on the target path (walk up to nearest existing ancestor)
344
- let realPath = fullPath;
345
- try {
346
- realPath = fsSync.realpathSync(fullPath);
347
- }
348
- catch {
349
- // Path may not exist yet — walk up to find nearest existing ancestor
350
- let current = fullPath;
351
- let suffix = "";
352
- while (current !== nodePath.dirname(current)) {
353
- const parent = nodePath.dirname(current);
354
- suffix = suffix
355
- ? nodePath.join(nodePath.basename(current), suffix)
356
- : nodePath.basename(current);
357
- try {
358
- const realAncestor = fsSync.realpathSync(parent);
359
- realPath = nodePath.join(realAncestor, suffix);
360
- break;
361
- }
362
- catch {
363
- current = parent;
364
- }
365
- }
366
- }
367
- if (!isPathWithinBase(realPath, realCwd)) {
368
- return {
369
- valid: false,
370
- error: `Resolved path escapes working directory: ${rawPath} -> ${realPath} (cwd: ${realCwd})`,
371
- };
372
- }
373
- resolved.set(rawPath, realPath);
374
- }
375
- }
376
- return { valid: true, resolved };
377
- }
378
- // ============================================================================
379
- // Windows Drive Letter Detection
380
- // ============================================================================
381
- /**
382
- * Check if a path looks like a Windows drive letter (e.g., C:\, D:/)
383
- */
384
- function isWindowsDrivePath(p) {
385
- return /^[a-zA-Z]:[/\\]/.test(p);
386
- }
387
- // ============================================================================
388
- // Hunk Application
389
- // ============================================================================
390
- /**
391
- * Apply hunks to file content.
392
- * Uses fuzzy matching with a configurable offset tolerance.
393
- *
394
- * Returns the modified content or an error describing what went wrong.
395
- */
396
- function applyHunks(originalContent, hunks, filePath) {
397
- // Normalize CRLF
398
- const normalized = originalContent.replace(/\r\n/g, "\n");
399
- let lines = normalized.split("\n");
400
- // Track cumulative offset from insertions/deletions
401
- let lineOffset = 0;
402
- for (let hunkIdx = 0; hunkIdx < hunks.length; hunkIdx++) {
403
- const hunk = hunks[hunkIdx];
404
- // Extract context and removal lines (lines that must exist in original)
405
- const expectedLines = [];
406
- const newLines = [];
407
- for (const line of hunk.lines) {
408
- const prefix = line[0];
409
- const content = line.slice(1);
410
- if (prefix === " ") {
411
- expectedLines.push(content);
412
- newLines.push(content);
413
- }
414
- else if (prefix === "-") {
415
- expectedLines.push(content);
416
- }
417
- else if (prefix === "+") {
418
- newLines.push(content);
419
- }
420
- }
421
- // Find the position where context matches
422
- const expectedStart = hunk.oldStart - 1 + lineOffset; // Convert 1-based to 0-based
423
- let matchPos = -1;
424
- // Try exact position first, then fuzzy within tolerance
425
- for (let offset = 0; offset <= MAX_FUZZ_OFFSET; offset++) {
426
- for (const dir of [0, 1, -1]) {
427
- const tryPos = expectedStart + offset * (dir === 0 ? 0 : dir);
428
- if (dir === 0 && offset > 0)
429
- continue; // Skip duplicate 0-offset
430
- if (tryPos < 0 || tryPos + expectedLines.length > lines.length)
431
- continue;
432
- let matches = true;
433
- for (let j = 0; j < expectedLines.length; j++) {
434
- if (lines[tryPos + j] !== expectedLines[j]) {
435
- matches = false;
436
- break;
437
- }
438
- }
439
- if (matches) {
440
- matchPos = tryPos;
441
- break;
442
- }
443
- }
444
- if (matchPos >= 0)
445
- break;
446
- }
447
- if (matchPos < 0) {
448
- // Fallback: global scan for context (used by relaxed patch formats where line numbers may be approximate)
449
- const candidates = [];
450
- for (let pos = 0; pos + expectedLines.length <= lines.length; pos++) {
451
- let matches = true;
452
- for (let j = 0; j < expectedLines.length; j++) {
453
- if (lines[pos + j] !== expectedLines[j]) {
454
- matches = false;
455
- break;
456
- }
457
- }
458
- if (matches)
459
- candidates.push(pos);
460
- }
461
- if (candidates.length === 1) {
462
- matchPos = candidates[0];
463
- }
464
- else {
465
- // Build a helpful error message
466
- const contextPreview = expectedLines.slice(0, 3).join("\n ");
467
- const ambiguity = candidates.length > 1
468
- ? `Context matched ${candidates.length} locations; provide more surrounding lines.`
469
- : "Context not found.";
470
- return {
471
- ok: false,
472
- error: `Hunk ${hunkIdx + 1} failed to apply to ${filePath} ` +
473
- `(expected at line ${hunk.oldStart}, searched ±${MAX_FUZZ_OFFSET} lines). ` +
474
- `${ambiguity}\n ${contextPreview}`,
475
- };
476
- }
477
- }
478
- // Apply: replace the matched range with the new lines
479
- lines = [
480
- ...lines.slice(0, matchPos),
481
- ...newLines,
482
- ...lines.slice(matchPos + expectedLines.length),
483
- ];
484
- // Update offset for subsequent hunks
485
- lineOffset += newLines.length - expectedLines.length;
486
- }
487
- return { ok: true, content: lines.join("\n") };
488
- }
489
- // ============================================================================
490
- // Atomic Patch Application
491
- // ============================================================================
492
- /**
493
- * Apply all file diffs atomically.
494
- * Writes to temp files first, then renames on success.
495
- * On any failure, cleans up all temp files.
496
- */
497
- async function applyPatchAtomic(diffs, resolvedPaths) {
498
- const actions = [];
499
- const tempFiles = [];
500
- let totalAdded = 0;
501
- let totalRemoved = 0;
502
- try {
503
- // Phase 1: Compute all file actions (read + apply hunks)
504
- for (const diff of diffs) {
505
- const isNewFile = diff.oldPath === null;
506
- const isDeleteFile = diff.newPath === null;
507
- const sourcePath = diff.oldPath ? resolvedPaths.get(diff.oldPath) : undefined;
508
- const targetPath = diff.newPath ? resolvedPaths.get(diff.newPath) : undefined;
509
- if (isDeleteFile) {
510
- // Deletion: mark for removal
511
- if (!sourcePath) {
512
- return fail(`Patch references missing delete source path: ${diff.oldPath}`);
513
- }
514
- let sourceStat;
515
- try {
516
- sourceStat = await fs.stat(sourcePath);
517
- }
518
- catch (err) {
519
- return fail(`Cannot delete missing path: ${sourcePath}: ${getErrorMessage(err)}`);
520
- }
521
- if (sourceStat.isDirectory()) {
522
- return fail(`Patch delete targets a directory (unsupported): ${sourcePath}`);
523
- }
524
- actions.push({ resolvedPath: sourcePath, type: "delete" });
525
- // Count removed lines
526
- for (const hunk of diff.hunks) {
527
- for (const line of hunk.lines) {
528
- if (line.startsWith("-"))
529
- totalRemoved++;
530
- }
531
- }
532
- continue;
533
- }
534
- if (isNewFile) {
535
- if (!targetPath) {
536
- return fail(`Patch references missing create target path: ${diff.newPath}`);
537
- }
538
- // New file: build content from additions
539
- const contentLines = [];
540
- for (const hunk of diff.hunks) {
541
- for (const line of hunk.lines) {
542
- if (line.startsWith("+")) {
543
- contentLines.push(line.slice(1));
544
- totalAdded++;
545
- }
546
- }
547
- }
548
- const content = contentLines.join("\n") + "\n";
549
- actions.push({ resolvedPath: targetPath, type: "create", content });
550
- }
551
- else {
552
- if (!sourcePath || !targetPath) {
553
- return fail(`Patch references missing update source/target paths: ${diff.oldPath} -> ${diff.newPath}`);
554
- }
555
- // Modify existing file
556
- let originalContent;
557
- try {
558
- originalContent = await fs.readFile(sourcePath, "utf-8");
559
- }
560
- catch (err) {
561
- return fail(`Cannot read file for patching: ${sourcePath}: ${getErrorMessage(err)}`);
562
- }
563
- const result = applyHunks(originalContent, diff.hunks, diff.newPath);
564
- if (!result.ok) {
565
- return fail(result.error);
566
- }
567
- // Count additions and removals
568
- for (const hunk of diff.hunks) {
569
- for (const line of hunk.lines) {
570
- if (line.startsWith("+"))
571
- totalAdded++;
572
- else if (line.startsWith("-"))
573
- totalRemoved++;
574
- }
575
- }
576
- actions.push({
577
- sourcePath,
578
- resolvedPath: targetPath,
579
- type: sourcePath === targetPath ? "modify" : "move",
580
- content: result.content,
581
- });
582
- }
583
- }
584
- // Phase 2: Write all changes to temp files
585
- for (const action of actions) {
586
- if (action.type === "delete")
587
- continue;
588
- const dir = nodePath.dirname(action.resolvedPath);
589
- const base = nodePath.basename(action.resolvedPath);
590
- const suffix = crypto.randomBytes(6).toString("hex");
591
- const tempPath = nodePath.join(dir, `.${base}.patch-${suffix}`);
592
- // Ensure parent directory exists (needed for new files)
593
- await fs.mkdir(dir, { recursive: true });
594
- await fs.writeFile(tempPath, action.content, "utf-8");
595
- tempFiles.push(tempPath);
596
- }
597
- // Phase 3: Atomic rename — all temp files to final destinations
598
- // Back up targets and deletion sources for rollback on failure
599
- const targetBackups = new Map();
600
- const sourceRemovalBackups = new Map();
601
- const appliedTargets = [];
602
- const removedSources = [];
603
- const backupTargetIfExists = async (targetPath) => {
604
- if (targetBackups.has(targetPath)) {
605
- return;
606
- }
607
- const backupSuffix = crypto.randomBytes(6).toString("hex");
608
- const backupPath = targetPath + `.patch-backup-${backupSuffix}`;
609
- try {
610
- await fs.copyFile(targetPath, backupPath);
611
- targetBackups.set(targetPath, backupPath);
612
- }
613
- catch (err) {
614
- const code = getErrnoCode(err);
615
- if (code === "ENOENT") {
616
- return;
617
- }
618
- throw err;
619
- }
620
- };
621
- const backupSourceRemovalPath = async (sourcePath) => {
622
- if (sourceRemovalBackups.has(sourcePath)) {
623
- return;
624
- }
625
- const backupSuffix = crypto.randomBytes(6).toString("hex");
626
- const backupPath = sourcePath + `.patch-source-backup-${backupSuffix}`;
627
- await fs.copyFile(sourcePath, backupPath);
628
- sourceRemovalBackups.set(sourcePath, backupPath);
629
- };
630
- const unlinkSourcePath = async (sourcePath) => {
631
- try {
632
- await fs.unlink(sourcePath);
633
- removedSources.push(sourcePath);
634
- }
635
- catch (err) {
636
- const code = getErrnoCode(err);
637
- // If the path is already gone, desired end-state (removed) is satisfied.
638
- if (code === "ENOENT") {
639
- return;
640
- }
641
- throw err;
642
- }
643
- };
644
- try {
645
- // Backup all existing target files that may be overwritten.
646
- for (const action of actions) {
647
- if (action.type === "delete")
648
- continue;
649
- await backupTargetIfExists(action.resolvedPath);
650
- }
651
- // Backup all files that will be removed (delete + move source path).
652
- for (const action of actions) {
653
- if (action.type === "delete") {
654
- await backupSourceRemovalPath(action.resolvedPath);
655
- continue;
656
- }
657
- if (action.type === "move" &&
658
- action.sourcePath &&
659
- action.sourcePath !== action.resolvedPath) {
660
- await backupSourceRemovalPath(action.sourcePath);
661
- }
662
- }
663
- let tempIdx = 0;
664
- for (const action of actions) {
665
- if (action.type === "delete")
666
- continue;
667
- const tempPath = tempFiles[tempIdx];
668
- await fs.rename(tempPath, action.resolvedPath);
669
- appliedTargets.push(action.resolvedPath);
670
- tempIdx++;
671
- }
672
- // Apply delete/move source removals as part of the same transaction.
673
- for (const action of actions) {
674
- if (action.type === "delete") {
675
- await unlinkSourcePath(action.resolvedPath);
676
- }
677
- else if (action.type === "move" &&
678
- action.sourcePath &&
679
- action.sourcePath !== action.resolvedPath) {
680
- await unlinkSourcePath(action.sourcePath);
681
- }
682
- }
683
- }
684
- catch (renameErr) {
685
- // Rollback: restore backup-backed targets, remove newly-created targets
686
- for (let idx = appliedTargets.length - 1; idx >= 0; idx--) {
687
- const target = appliedTargets[idx];
688
- const backup = targetBackups.get(target);
689
- try {
690
- if (backup) {
691
- await fs.rename(backup, target);
692
- }
693
- else {
694
- await fs.unlink(target);
695
- }
696
- }
697
- catch {
698
- /* best-effort */
699
- }
700
- }
701
- // Rollback removed source paths (delete/move) in reverse order.
702
- for (let idx = removedSources.length - 1; idx >= 0; idx--) {
703
- const sourcePath = removedSources[idx];
704
- const backup = sourceRemovalBackups.get(sourcePath);
705
- if (!backup)
706
- continue;
707
- try {
708
- await fs.rename(backup, sourcePath);
709
- sourceRemovalBackups.delete(sourcePath);
710
- }
711
- catch {
712
- /* best-effort */
713
- }
714
- }
715
- // Clean up any remaining backup files
716
- for (const backup of targetBackups.values()) {
717
- try {
718
- await fs.unlink(backup);
719
- }
720
- catch {
721
- /* best-effort */
722
- }
723
- }
724
- for (const backup of sourceRemovalBackups.values()) {
725
- try {
726
- await fs.unlink(backup);
727
- }
728
- catch {
729
- /* best-effort */
730
- }
731
- }
732
- // Clean up any remaining temp files
733
- for (const tempPath of tempFiles) {
734
- try {
735
- await fs.unlink(tempPath);
736
- }
737
- catch {
738
- /* best-effort */
739
- }
740
- }
741
- throw renameErr; // Will be caught by outer try/catch
742
- }
743
- // Success — clean up backups
744
- for (const backup of targetBackups.values()) {
745
- try {
746
- await fs.unlink(backup);
747
- }
748
- catch {
749
- /* best-effort */
750
- }
751
- }
752
- for (const backup of sourceRemovalBackups.values()) {
753
- try {
754
- await fs.unlink(backup);
755
- }
756
- catch {
757
- /* best-effort */
758
- }
759
- }
760
- // Build summary
761
- const filesChanged = actions.length;
762
- const created = actions.filter((a) => a.type === "create").length;
763
- const modified = actions.filter((a) => a.type === "modify").length;
764
- const deleted = actions.filter((a) => a.type === "delete").length;
765
- const moved = actions.filter((a) => a.type === "move").length;
766
- const parts = [];
767
- if (created > 0)
768
- parts.push(`${created} created`);
769
- if (modified > 0)
770
- parts.push(`${modified} modified`);
771
- if (moved > 0)
772
- parts.push(`${moved} moved`);
773
- if (deleted > 0)
774
- parts.push(`${deleted} deleted`);
775
- const summary = `Patch applied: ${filesChanged} file${filesChanged !== 1 ? "s" : ""} ` +
776
- `(${parts.join(", ")}), +${totalAdded}/-${totalRemoved} lines`;
777
- for (const action of actions) {
778
- if (action.type === "delete") {
779
- recordFrgMutation(action.resolvedPath, "delete");
780
- recordSearchMutation(action.resolvedPath, "delete");
781
- }
782
- else {
783
- recordFrgMutation(action.resolvedPath, "write", action.content);
784
- recordSearchMutation(action.resolvedPath, "write", action.content);
785
- if (action.type === "move" &&
786
- action.sourcePath &&
787
- action.sourcePath !== action.resolvedPath) {
788
- recordFrgMutation(action.sourcePath, "delete");
789
- recordSearchMutation(action.sourcePath, "delete");
790
- }
791
- }
792
- }
793
- return success(summary, {
794
- filesChanged,
795
- created,
796
- modified,
797
- moved,
798
- deleted,
799
- linesAdded: totalAdded,
800
- linesRemoved: totalRemoved,
801
- files: actions.map((a) => ({
802
- path: a.type === "move" ? `${a.sourcePath} -> ${a.resolvedPath}` : a.resolvedPath,
803
- action: a.type,
804
- })),
805
- });
806
- }
807
- catch (err) {
808
- // Cleanup: remove all temp files on failure
809
- for (const tempPath of tempFiles) {
810
- try {
811
- await fs.unlink(tempPath);
812
- }
813
- catch {
814
- // Best-effort cleanup
815
- }
816
- }
817
- return fail(`Patch application failed: ${getErrorMessage(err)}`);
818
- }
819
- }
820
- // ============================================================================
821
- // Main Executor
822
- // ============================================================================
823
- /**
824
- * Execute the apply_patch tool.
825
- *
826
- * Parses a unified diff, validates all paths for security,
827
- * and applies changes atomically.
828
- */
829
- export async function executeApplyPatch(input, ctx) {
830
- try {
831
- if (!input.patch || input.patch.trim() === "") {
832
- return fail("Patch content is empty");
833
- }
834
- // Size guard: reject patches > 1MB to prevent memory exhaustion
835
- const MAX_PATCH_SIZE = 1_048_576; // 1MB
836
- if (input.patch.length > MAX_PATCH_SIZE) {
837
- return fail(`Patch too large: ${input.patch.length} bytes (max: ${MAX_PATCH_SIZE})`);
838
- }
839
- // Determine working directory
840
- const cwd = input.cwd ? nodePath.resolve(ctx.workingDir, input.cwd) : ctx.workingDir;
841
- // SECURITY: Validate cwd is within the working directory
842
- if (input.cwd) {
843
- let realCwd;
844
- try {
845
- realCwd = fsSync.realpathSync(cwd);
846
- }
847
- catch {
848
- return fail(`Working directory does not exist: ${cwd}`);
849
- }
850
- let realWorkingDir;
851
- try {
852
- realWorkingDir = fsSync.realpathSync(ctx.workingDir);
853
- }
854
- catch {
855
- return fail(`Base working directory does not exist: ${ctx.workingDir}`);
856
- }
857
- if (!isPathWithinBase(realCwd, realWorkingDir)) {
858
- return fail(`cwd must be within the working directory: ${input.cwd}`);
859
- }
860
- }
861
- // Verify cwd exists and is a directory
862
- try {
863
- const stat = await fs.stat(cwd);
864
- if (!stat.isDirectory()) {
865
- return fail(`Working directory is not a directory: ${cwd}`);
866
- }
867
- }
868
- catch {
869
- return fail(`Working directory does not exist: ${cwd}`);
870
- }
871
- // Step 1: Parse patch input (unified diff or apply_patch envelope)
872
- let diffs;
873
- try {
874
- diffs = parsePatchInput(input.patch);
875
- }
876
- catch (err) {
877
- return fail(`Failed to parse patch: ${getErrorMessage(err)}`);
878
- }
879
- if (diffs.length === 0) {
880
- return fail("No file diffs found in patch");
881
- }
882
- // Step 2: Validate paths (SECURITY-CRITICAL)
883
- // Check for Windows drive letters in paths (cross-platform safety)
884
- for (const diff of diffs) {
885
- for (const p of [diff.oldPath, diff.newPath]) {
886
- if (p !== null && isWindowsDrivePath(p)) {
887
- return fail(`Absolute path not allowed in patch: ${p}`);
888
- }
889
- }
890
- }
891
- const validation = validatePatchPaths(diffs, cwd);
892
- if (!validation.valid) {
893
- return fail(validation.error);
894
- }
895
- // Step 3: Apply atomically
896
- return await applyPatchAtomic(diffs, validation.resolved);
897
- }
898
- catch (err) {
899
- return fail(`apply_patch failed: ${getErrorMessage(err)}`);
900
- }
901
- }
902
- //# sourceMappingURL=apply-patch.js.map