farming-code 2.2.30 → 2.2.32

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 (377) hide show
  1. package/THIRD_PARTY_NOTICES.md +7 -0
  2. package/backend/acp/{client-services.js → client-services.cjs} +132 -134
  3. package/backend/acp/packaged-claude-acp.cjs +37 -0
  4. package/backend/acp/packaged-codex-acp.cjs +37 -0
  5. package/backend/acp/patch-decisions.cjs +182 -0
  6. package/backend/acp/permission-security.cjs +131 -0
  7. package/backend/{acp-checkpoint-store.js → acp-checkpoint-store.cjs} +90 -59
  8. package/backend/{acp-runtime.js → acp-runtime.cjs} +1220 -1112
  9. package/backend/acp-session-state.cjs +622 -0
  10. package/backend/acp-transcript.cjs +525 -0
  11. package/backend/agent-env.cjs +257 -0
  12. package/backend/agent-extension-discovery.cjs +452 -0
  13. package/backend/agent-extension-inventory.cjs +116 -0
  14. package/backend/agent-json-stream.cjs +283 -0
  15. package/backend/agent-lifecycle-journal.cjs +185 -0
  16. package/backend/{agent-manager.js → agent-manager.cjs} +3116 -4275
  17. package/backend/agent-order-transaction.cjs +85 -0
  18. package/backend/agent-order.cjs +159 -0
  19. package/backend/agent-provider-session.cjs +98 -0
  20. package/backend/agent-runtime-binding.cjs +179 -0
  21. package/backend/agent-session-history.cjs +1022 -0
  22. package/backend/agent-session-inventory.cjs +291 -0
  23. package/backend/async-cache.cjs +104 -0
  24. package/backend/atomic-json-store.cjs +67 -0
  25. package/backend/auth.cjs +261 -0
  26. package/backend/authoritative-inventory-cache.cjs +383 -0
  27. package/backend/business-health.cjs +68 -0
  28. package/backend/chat-runtime.cjs +50 -0
  29. package/backend/claude-settings.cjs +132 -0
  30. package/backend/cli-agents.cjs +435 -0
  31. package/backend/codex-context-window.cjs +196 -0
  32. package/backend/codex-models.cjs +228 -0
  33. package/backend/codex-session-archive.cjs +82 -0
  34. package/backend/codex-session-history.cjs +590 -0
  35. package/backend/{codex-terminal-profile.js → codex-terminal-profile.cjs} +149 -155
  36. package/backend/codex-transcript-sanitizer.cjs +130 -0
  37. package/backend/codex-transcript.cjs +2107 -0
  38. package/backend/command-runner-child.cjs +105 -0
  39. package/backend/config-manager.cjs +1263 -0
  40. package/backend/control-api.cjs +439 -0
  41. package/backend/data/LICENSE.cua +21 -0
  42. package/backend/executable-discovery.cjs +204 -0
  43. package/backend/farming-agent-bootstrap.cjs +81 -0
  44. package/backend/farming-agent-bootstrap.zh_cn.md +6 -2
  45. package/backend/{farming-app-cli.js → farming-app-cli.cjs} +441 -493
  46. package/backend/farming-cli.cjs +414 -0
  47. package/backend/farming-net-pass.cjs +319 -0
  48. package/backend/farming-net-registry.cjs +123 -0
  49. package/backend/farming-net-server.cjs +309 -0
  50. package/backend/farming-session-store.cjs +651 -0
  51. package/backend/git-worktree-info.cjs +181 -0
  52. package/backend/haiku-token.cjs +828 -0
  53. package/backend/index-html.cjs +96 -0
  54. package/backend/input-parts.cjs +68 -0
  55. package/backend/input-routing.cjs +40 -0
  56. package/backend/{local-session-engine.js → local-session-engine.cjs} +276 -282
  57. package/backend/main-agent-skills.cjs +309 -0
  58. package/backend/main-page-session.cjs +132 -0
  59. package/backend/native-pty-controller-generation.cjs +139 -0
  60. package/backend/{native-pty-host-client.js → native-pty-host-client.cjs} +338 -346
  61. package/backend/native-pty-host-identity.cjs +125 -0
  62. package/backend/native-pty-host-path.cjs +68 -0
  63. package/backend/{native-pty-host.js → native-pty-host.cjs} +480 -569
  64. package/backend/native-session-engine.cjs +296 -0
  65. package/backend/network.cjs +57 -0
  66. package/backend/npm-update-helper.cjs +399 -0
  67. package/backend/packaged-node-pty.cjs +120 -0
  68. package/backend/preview-session-manager.cjs +89 -0
  69. package/backend/provider-adapters.cjs +492 -0
  70. package/backend/provider-home-configuration.cjs +211 -0
  71. package/backend/provider-session-id.cjs +79 -0
  72. package/backend/provider-session-service.cjs +333 -0
  73. package/backend/qr-share-tickets.cjs +119 -0
  74. package/backend/resource-broadcast-protocol.cjs +50 -0
  75. package/backend/review-diff-router.cjs +202 -0
  76. package/backend/review-diff-service.cjs +1267 -0
  77. package/backend/review-session-router.cjs +93 -0
  78. package/backend/review-session-service.cjs +470 -0
  79. package/backend/review-session-store.cjs +161 -0
  80. package/backend/review-state-router.cjs +132 -0
  81. package/backend/review-state-store.cjs +299 -0
  82. package/backend/run-history-store.cjs +97 -0
  83. package/backend/runtime-dependency-manager.cjs +893 -0
  84. package/backend/runtime-executable-invocation.cjs +37 -0
  85. package/backend/runtime-observation.cjs +96 -0
  86. package/backend/server-process-identity.cjs +70 -0
  87. package/backend/server.cjs +3356 -0
  88. package/backend/session-engine-bridge.cjs +144 -0
  89. package/backend/session-engine-router.cjs +105 -0
  90. package/backend/session-engine.cjs +64 -0
  91. package/backend/session-stream-protocol.cjs +181 -0
  92. package/backend/shell-busy-integration.cjs +442 -0
  93. package/backend/slash-command-discovery.cjs +423 -0
  94. package/backend/storage-layout.cjs +263 -0
  95. package/backend/system-monitor.cjs +96 -0
  96. package/backend/terminal-attach-checkpoint.cjs +73 -0
  97. package/backend/terminal-exit-quiescence.cjs +57 -0
  98. package/backend/{terminal-reducer-flow-control.js → terminal-reducer-flow-control.cjs} +45 -22
  99. package/backend/terminal-runtime-cleanup.cjs +99 -0
  100. package/backend/{terminal-screen-state.js → terminal-screen-state.cjs} +100 -108
  101. package/backend/{terminal-screen-worker-pool.js → terminal-screen-worker-pool.cjs} +89 -79
  102. package/backend/{terminal-screen-worker-thread.js → terminal-screen-worker-thread.cjs} +64 -65
  103. package/backend/terminal-screen-worker.cjs +352 -0
  104. package/backend/terminal-state-serialization.cjs +147 -0
  105. package/backend/{terminal-status.js → terminal-status.cjs} +137 -187
  106. package/backend/theme-manager.cjs +185 -0
  107. package/backend/{update-service.js → update-service.cjs} +258 -248
  108. package/backend/usage-forecast.cjs +95 -0
  109. package/backend/{usage-history-client.js → usage-history-client.cjs} +144 -94
  110. package/backend/usage-history-smoke.cjs +85 -0
  111. package/backend/usage-history-worker.cjs +60 -0
  112. package/backend/{usage-monitor.js → usage-monitor.cjs} +363 -390
  113. package/backend/workspace-directory.cjs +239 -0
  114. package/backend/workspace-discovery.cjs +271 -0
  115. package/backend/{workspace-file-router.js → workspace-file-router.cjs} +213 -282
  116. package/backend/{workspace-file-service.js → workspace-file-service.cjs} +1139 -1318
  117. package/backend/workspace-root-registry.cjs +192 -0
  118. package/bin/farming +1 -1
  119. package/dist/acp/codex-acp-1.1.4.mjs +18 -1
  120. package/dist/assets/App-BCkdpWB6.css +1 -0
  121. package/dist/assets/App-CRjKpaGp.js +697 -0
  122. package/dist/assets/CodeSelect-Ci8sKZPU.js +1 -0
  123. package/dist/assets/CodeSelect-T2eNzrOc.css +1 -0
  124. package/dist/assets/{FileEditorMarkdownPreview-Cs9cLv8a.js → FileEditorMarkdownPreview-V06QHlAg.js} +55 -55
  125. package/dist/assets/FileEditorPane-BX-Wjg9U.js +2 -0
  126. package/dist/assets/IconGlyphs-YhV7tqd4.js +1 -0
  127. package/dist/assets/ProjectFilesSection-BDT2_r0o.js +12 -0
  128. package/dist/assets/ReviewPage-BqAs5sG1.js +3 -0
  129. package/dist/assets/code-dark-B7eM_9G9.css +1 -0
  130. package/dist/assets/{cssMode-Bdg5RpcJ.js → cssMode-ADdAlxTO.js} +1 -1
  131. package/dist/assets/{editor.api2-D74ufkbr.js → editor.api2-BFLAr0YF.js} +162 -162
  132. package/dist/assets/file-icons-BpeqWkIB.js +1 -0
  133. package/dist/assets/{freemarker2-DfMDJfnE.js → freemarker2-C90q5jrp.js} +1 -1
  134. package/dist/assets/{handlebars-BEdPtzMT.js → handlebars-BwUQcEDq.js} +1 -1
  135. package/dist/assets/{html-B1fPb1QD.js → html-1s3uPKfh.js} +1 -1
  136. package/dist/assets/{htmlMode-CY2ZjHxH.js → htmlMode-xtKD99de.js} +1 -1
  137. package/dist/assets/{index-D-zetSol.js → index-C8MchCem.js} +3 -3
  138. package/dist/assets/{javascript-BV2OsWA0.js → javascript-Ph7ijyny.js} +1 -1
  139. package/dist/assets/{jsonMode-zd07aeuX.js → jsonMode-D-jGAnFH.js} +1 -1
  140. package/dist/assets/linkComputer-CbGyI_qx.js +1 -0
  141. package/dist/assets/{liquid-BParI24X.js → liquid-0IamE_cI.js} +1 -1
  142. package/dist/assets/{lspLanguageFeatures-BzredkoV.js → lspLanguageFeatures-BxnQunWF.js} +1 -1
  143. package/dist/assets/main-CLKXa6hf.css +1 -0
  144. package/dist/assets/{mdx-vGzUJN98.js → mdx-DdNmfivn.js} +1 -1
  145. package/dist/assets/{monaco.contribution-BmaeBQEc.js → monaco.contribution-B43jsUs1.js} +2 -2
  146. package/dist/assets/{python-CUwdLgsI.js → python-IAt4X5TS.js} +1 -1
  147. package/dist/assets/{razor-BScebUxU.js → razor-DRkFYW0S.js} +1 -1
  148. package/dist/assets/review-C8-oPKXk.css +1 -0
  149. package/dist/assets/{tsMode-DzUAibXK.js → tsMode-_d_4U2gf.js} +1 -1
  150. package/dist/assets/{typescript-D9EOeM7N.js → typescript-C7zcMq9l.js} +1 -1
  151. package/dist/assets/{workers-DAiomYZM.js → workers-D0nOyJzf.js} +1 -1
  152. package/dist/assets/workspace-editor-model-DND_Y-Bj.js +1 -0
  153. package/dist/assets/workspace-editor-monaco-BPWhgcIB.js +4 -0
  154. package/dist/assets/workspace-editor-monaco-N641qPjX.js +1 -0
  155. package/dist/assets/workspace-view-state-k1bTlJ_Z.js +13 -0
  156. package/dist/assets/{xml-wWl1dhkQ.js → xml-BR-HvxT8.js} +1 -1
  157. package/dist/assets/{yaml-Dc2WDaOZ.js → yaml-YtFQwh4q.js} +1 -1
  158. package/dist/index.html +1 -1
  159. package/extensions/browser/backend/agent-browser-runtime.cjs +1040 -0
  160. package/extensions/browser/backend/agent-capability.cjs +85 -0
  161. package/extensions/browser/backend/browser-mcp-server.cjs +655 -0
  162. package/extensions/browser/backend/browser-resource-manager.cjs +1486 -0
  163. package/extensions/browser/backend/browser-resource-store.cjs +228 -0
  164. package/extensions/browser/backend/browser-router.cjs +203 -0
  165. package/extensions/browser/backend/executable-discovery.cjs +248 -0
  166. package/extensions/browser/backend/farming-browser-client.cjs +116 -0
  167. package/extensions/browser/backend/index.cjs +32 -0
  168. package/extensions/browser/backend/managed-chromium-installer.cjs +833 -0
  169. package/extensions/browser/bin/farming-browser +16 -7
  170. package/extensions/computer/backend/agent-capability.cjs +72 -0
  171. package/extensions/computer/backend/computer-constants.cjs +59 -0
  172. package/extensions/computer/backend/computer-mcp-server.cjs +182 -0
  173. package/extensions/computer/backend/computer-resource-manager.cjs +1219 -0
  174. package/extensions/computer/backend/computer-resource-store.cjs +190 -0
  175. package/extensions/computer/backend/computer-router.cjs +257 -0
  176. package/extensions/computer/backend/cua-tools.json +3067 -0
  177. package/extensions/computer/backend/farming-computer-client.cjs +84 -0
  178. package/extensions/computer/backend/index.cjs +35 -0
  179. package/extensions/computer/backend/isolated-browser-provider.cjs +157 -0
  180. package/extensions/computer/bin/farming-computer +131 -0
  181. package/frontend/farming-net/app.js +255 -262
  182. package/frontend/ghostty-loader.js +24 -20
  183. package/frontend/reading-anchor.js +210 -193
  184. package/frontend/runtime-paths.js +24 -26
  185. package/frontend/session-bridge.js +90 -111
  186. package/frontend/session-modal-bridge.js +184 -302
  187. package/frontend/skin-bridge.js +20 -23
  188. package/frontend/skins/crt/app.js +7686 -7901
  189. package/frontend/skins/crt/effects.js +7 -6
  190. package/frontend/skins/crt/index.html +6 -6
  191. package/frontend/skins/crt/styles/markdown.css +4 -4
  192. package/frontend/terminal-bridge.js +174 -181
  193. package/frontend/terminal-replay.js +320 -345
  194. package/frontend/theme-loader.js +55 -71
  195. package/package.json +64 -37
  196. package/shared/backend-connection-status.js +38 -69
  197. package/shared/browser-protocol.js +235 -110
  198. package/shared/websocket-liveness.js +40 -0
  199. package/backend/acp/packaged-claude-acp.js +0 -13
  200. package/backend/acp/packaged-codex-acp.js +0 -13
  201. package/backend/acp/patch-decisions.js +0 -153
  202. package/backend/acp/permission-security.js +0 -108
  203. package/backend/acp-session-state.js +0 -634
  204. package/backend/acp-transcript.js +0 -512
  205. package/backend/agent-env.js +0 -250
  206. package/backend/agent-json-stream.js +0 -268
  207. package/backend/agent-lifecycle-journal.js +0 -133
  208. package/backend/agent-order.js +0 -166
  209. package/backend/agent-provider-session.js +0 -76
  210. package/backend/agent-runtime-binding.js +0 -174
  211. package/backend/agent-session-history.js +0 -986
  212. package/backend/async-cache.js +0 -94
  213. package/backend/atomic-json-store.js +0 -37
  214. package/backend/auth.js +0 -251
  215. package/backend/chat-runtime.js +0 -28
  216. package/backend/claude-settings.js +0 -121
  217. package/backend/cli-agents.js +0 -486
  218. package/backend/codex-context-window.js +0 -189
  219. package/backend/codex-models.js +0 -226
  220. package/backend/codex-session-archive.js +0 -65
  221. package/backend/codex-session-history.js +0 -647
  222. package/backend/codex-transcript-sanitizer.js +0 -115
  223. package/backend/codex-transcript.js +0 -2362
  224. package/backend/command-runner-child.js +0 -67
  225. package/backend/config-manager.js +0 -1117
  226. package/backend/control-api.js +0 -455
  227. package/backend/executable-discovery.js +0 -216
  228. package/backend/farming-agent-bootstrap.js +0 -49
  229. package/backend/farming-cli.js +0 -403
  230. package/backend/farming-net-pass.js +0 -285
  231. package/backend/farming-net-registry.js +0 -112
  232. package/backend/farming-net-server.js +0 -298
  233. package/backend/farming-session-store.js +0 -677
  234. package/backend/git-worktree-info.js +0 -181
  235. package/backend/haiku-token.js +0 -772
  236. package/backend/index-html.js +0 -80
  237. package/backend/input-parts.js +0 -54
  238. package/backend/input-routing.js +0 -24
  239. package/backend/json-cli-runtime.js +0 -275
  240. package/backend/main-agent-skills.js +0 -288
  241. package/backend/main-page-session.js +0 -122
  242. package/backend/native-pty-controller-generation.js +0 -106
  243. package/backend/native-pty-host-identity.js +0 -86
  244. package/backend/native-pty-host-path.js +0 -42
  245. package/backend/native-session-engine.js +0 -268
  246. package/backend/network.js +0 -23
  247. package/backend/npm-update-helper.js +0 -374
  248. package/backend/packaged-node-pty.js +0 -99
  249. package/backend/preview-session-manager.js +0 -68
  250. package/backend/provider-adapters.js +0 -399
  251. package/backend/provider-session-id.js +0 -47
  252. package/backend/provider-session-service.js +0 -345
  253. package/backend/qr-share-tickets.js +0 -100
  254. package/backend/review-diff-router.js +0 -180
  255. package/backend/review-diff-service.js +0 -1270
  256. package/backend/review-session-router.js +0 -74
  257. package/backend/review-session-service.js +0 -446
  258. package/backend/review-session-store.js +0 -151
  259. package/backend/review-state-router.js +0 -116
  260. package/backend/review-state-store.js +0 -286
  261. package/backend/run-history-store.js +0 -67
  262. package/backend/runtime-dependency-manager.js +0 -759
  263. package/backend/runtime-executable-invocation.js +0 -20
  264. package/backend/runtime-observation.js +0 -81
  265. package/backend/server-process-identity.js +0 -47
  266. package/backend/server.js +0 -3225
  267. package/backend/session-engine-bridge.js +0 -129
  268. package/backend/session-engine-router.js +0 -66
  269. package/backend/session-engine.js +0 -39
  270. package/backend/session-stream-protocol.js +0 -185
  271. package/backend/shell-busy-integration.js +0 -472
  272. package/backend/slash-command-discovery.js +0 -433
  273. package/backend/storage-layout.js +0 -205
  274. package/backend/system-monitor.js +0 -77
  275. package/backend/terminal-attach-checkpoint.js +0 -74
  276. package/backend/terminal-exit-quiescence.js +0 -39
  277. package/backend/terminal-runtime-cleanup.js +0 -80
  278. package/backend/terminal-screen-worker.js +0 -337
  279. package/backend/terminal-state-serialization.js +0 -127
  280. package/backend/theme-manager.js +0 -163
  281. package/backend/usage-forecast.js +0 -86
  282. package/backend/usage-history-scanner.ts +0 -2718
  283. package/backend/usage-history-smoke.js +0 -64
  284. package/backend/usage-history-worker.js +0 -34
  285. package/backend/workspace-directory.js +0 -232
  286. package/backend/workspace-discovery.js +0 -311
  287. package/backend/workspace-root-registry.js +0 -166
  288. package/dist/assets/App-BKNUILuL.css +0 -1
  289. package/dist/assets/App-Z1N7T0eM.js +0 -695
  290. package/dist/assets/FileEditorPane-CNtuGjQ3.js +0 -2
  291. package/dist/assets/IconGlyphs-BClgag6E.js +0 -1
  292. package/dist/assets/ProjectFilesSection-K3GHuQ4U.js +0 -12
  293. package/dist/assets/ReviewPage-BRuxFaH5.js +0 -3
  294. package/dist/assets/code-dark-kLsQLvpf.css +0 -1
  295. package/dist/assets/file-icons-BOlcJ0ZF.js +0 -1
  296. package/dist/assets/main-DUTz-Rd2.css +0 -1
  297. package/dist/assets/review-BcnwQtJv.css +0 -1
  298. package/dist/assets/workspace-editor-model-CSGCl21x.js +0 -1
  299. package/dist/assets/workspace-editor-monaco-CJNwbpCy.js +0 -4
  300. package/dist/assets/workspace-editor-monaco-CO9w8YV0.js +0 -1
  301. package/dist/assets/workspace-view-state-BjKPYp0E.js +0 -7
  302. package/extensions/browser/backend/agent-browser-runtime.js +0 -1041
  303. package/extensions/browser/backend/agent-capability.js +0 -55
  304. package/extensions/browser/backend/browser-mcp-server.js +0 -621
  305. package/extensions/browser/backend/browser-resource-manager.js +0 -1331
  306. package/extensions/browser/backend/browser-resource-store.js +0 -190
  307. package/extensions/browser/backend/browser-router.js +0 -141
  308. package/extensions/browser/backend/executable-discovery.js +0 -238
  309. package/extensions/browser/backend/farming-browser-client.js +0 -83
  310. package/extensions/browser/backend/index.js +0 -7
  311. package/extensions/browser/backend/managed-chromium-installer.js +0 -593
  312. package/extensions/browser/frontend/BrowserSidebarPortals.tsx +0 -360
  313. package/extensions/browser/frontend/BrowserViewer.tsx +0 -500
  314. package/extensions/browser/frontend/browser-resource-state.ts +0 -60
  315. package/extensions/browser/frontend/browser.css +0 -567
  316. package/extensions/browser/frontend/types.ts +0 -38
  317. package/extensions/browser/frontend/useBrowserResources.ts +0 -166
  318. package/frontend/vendor/ghostty-web/index.d.ts +0 -1842
  319. package/shared/backend-connection-status.d.ts +0 -37
  320. package/shared/browser-protocol.d.ts +0 -5
  321. /package/dist/assets/{api-w2x5QfxB.js → api-ByCV9MEr.js} +0 -0
  322. /package/dist/assets/{core-vPkV8P_m.js → core-Czwdx12k.js} +0 -0
  323. /package/dist/assets/{fsharp-DNZNZyEE.js → fsharp-BjPpkoJe.js} +0 -0
  324. /package/dist/assets/{go-_kPJjNc_.js → go-BkIDmSUP.js} +0 -0
  325. /package/dist/assets/{graphql-4HCNVt5g.js → graphql-CCJTpqi1.js} +0 -0
  326. /package/dist/assets/{hcl-C87ymY0o.js → hcl-s4z8lUFg.js} +0 -0
  327. /package/dist/assets/{ini-BYrrGNTc.js → ini-CyUW1I7Z.js} +0 -0
  328. /package/dist/assets/{java-B211rJbk.js → java-CFCcGRiM.js} +0 -0
  329. /package/dist/assets/{julia-DVPsRtBm.js → julia-DQyH_EYb.js} +0 -0
  330. /package/dist/assets/{kotlin-BYyNerjp.js → kotlin-B8hA5O51.js} +0 -0
  331. /package/dist/assets/{less-EC9UblGE.js → less-DaVdaas0.js} +0 -0
  332. /package/dist/assets/{lexon-B1yuUdqW.js → lexon-DLBhPd3y.js} +0 -0
  333. /package/dist/assets/{lua-Bo6GFzxT.js → lua-gB1c_cif.js} +0 -0
  334. /package/dist/assets/{m3-C-Y9cBVI.js → m3-C2T3z3gB.js} +0 -0
  335. /package/dist/assets/{markdown-BHu-wLbe.js → markdown-CKq-Euj1.js} +0 -0
  336. /package/dist/assets/{mips-Dkds26rX.js → mips-Bcs5qIDX.js} +0 -0
  337. /package/dist/assets/{msdax-PU4g-8_g.js → msdax-CBP48FHF.js} +0 -0
  338. /package/dist/assets/{mysql-fPpuGpS7.js → mysql-c7tiPcFj.js} +0 -0
  339. /package/dist/assets/{objective-c-Wy1e5JUf.js → objective-c-D4BZkeEV.js} +0 -0
  340. /package/dist/assets/{pascal-BIXwvrqU.js → pascal-CJDZg0MN.js} +0 -0
  341. /package/dist/assets/{pascaligo-DwR0AtL_.js → pascaligo-Bygi8Ynl.js} +0 -0
  342. /package/dist/assets/{perl-CGHAl8my.js → perl-aS8bkf7E.js} +0 -0
  343. /package/dist/assets/{pgsql-B91M73E2.js → pgsql-CzNAYFYl.js} +0 -0
  344. /package/dist/assets/{php-C70ttrCx.js → php-DOtoEFTT.js} +0 -0
  345. /package/dist/assets/{pla-BNrXaRh0.js → pla-DugRnao1.js} +0 -0
  346. /package/dist/assets/{postiats-Dv2IAZR9.js → postiats-DsXwusKh.js} +0 -0
  347. /package/dist/assets/{powerquery-CkY5Wq7J.js → powerquery-DL3o72oD.js} +0 -0
  348. /package/dist/assets/{powershell-uGIYLU3C.js → powershell-C1qHekys.js} +0 -0
  349. /package/dist/assets/{protobuf-CavfmJu-.js → protobuf-DHgsc-cH.js} +0 -0
  350. /package/dist/assets/{pug-Drqnyitx.js → pug-FZXlE_Iu.js} +0 -0
  351. /package/dist/assets/{qrcode-7uGsTEmi.js → qrcode-DJDTdjL7.js} +0 -0
  352. /package/dist/assets/{qsharp-C7yF-Dti.js → qsharp-bLyhI3DT.js} +0 -0
  353. /package/dist/assets/{r-HXLGP0_-.js → r-DjFGXbAa.js} +0 -0
  354. /package/dist/assets/{redis-C4y6mf2p.js → redis-DSoZ_V6u.js} +0 -0
  355. /package/dist/assets/{redshift-DdQrFPrv.js → redshift-CzkdCsrg.js} +0 -0
  356. /package/dist/assets/{restructuredtext-CBrf2PNj.js → restructuredtext-B_XPrGCQ.js} +0 -0
  357. /package/dist/assets/{ruby-CVtMoX2B.js → ruby-Cry2RneJ.js} +0 -0
  358. /package/dist/assets/{rust-Ckq4sbMP.js → rust-CWzdbFq1.js} +0 -0
  359. /package/dist/assets/{sb-er66OpE3.js → sb-DmofU59h.js} +0 -0
  360. /package/dist/assets/{scala-BdWZz-hH.js → scala-BUC2l-vN.js} +0 -0
  361. /package/dist/assets/{scheme-kTV_s2kP.js → scheme-CNIB_72f.js} +0 -0
  362. /package/dist/assets/{scss-Bymy2VJQ.js → scss-DcL4-NbX.js} +0 -0
  363. /package/dist/assets/{shell-bwEP1LQ1.js → shell-CgAGvSSA.js} +0 -0
  364. /package/dist/assets/{solidity-DCddeBgL.js → solidity-DSkt6O_P.js} +0 -0
  365. /package/dist/assets/{sophia-BMN3AQig.js → sophia--5ytcjDN.js} +0 -0
  366. /package/dist/assets/{sparql-CSXOLjzi.js → sparql-C1Srr7cD.js} +0 -0
  367. /package/dist/assets/{sql-COg8ewmK.js → sql-2k_O5fj7.js} +0 -0
  368. /package/dist/assets/{st-CIaZtBS_.js → st-DCCCPqfz.js} +0 -0
  369. /package/dist/assets/{swift-DXiOhUHu.js → swift-Dd8mAfOt.js} +0 -0
  370. /package/dist/assets/{systemverilog-BTDE6Dr2.js → systemverilog-B0-aZYXu.js} +0 -0
  371. /package/dist/assets/{tcl-B0zy9NvV.js → tcl-CZAZwPVX.js} +0 -0
  372. /package/dist/assets/{twig-D594l4Z1.js → twig-D-Ag0tdS.js} +0 -0
  373. /package/dist/assets/{typespec-XKVjaPqo.js → typespec-B7kTFp0Z.js} +0 -0
  374. /package/dist/assets/{useWorkspaceMenuKeyboard-Bpy_s69Z.js → useWorkspaceMenuKeyboard-uYZpDxhU.js} +0 -0
  375. /package/dist/assets/{vb-B2wYoKRV.js → vb-20w1JPum.js} +0 -0
  376. /package/dist/assets/{wgsl-D0Yf2LbK.js → wgsl-CLJfqFt0.js} +0 -0
  377. /package/dist/assets/{workspace-working-copy-C3FSR3N6.js → workspace-working-copy-Cfz07cOd.js} +0 -0
@@ -0,0 +1,893 @@
1
+ // Generated by scripts/build-backend-runtime.ts. Do not edit.
2
+ "use strict";
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __export = (target, all) => {
10
+ for (var name in all)
11
+ __defProp(target, name, { get: all[name], enumerable: true });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from))
16
+ if (!__hasOwnProp.call(to, key) && key !== except)
17
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
+ }
19
+ return to;
20
+ };
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ // If the importer is in node compatibility mode or this is not an ESM
23
+ // file that has been converted to a CommonJS file using a Babel-
24
+ // compatible transform (i.e. "__esModule" has not been set), then set
25
+ // "default" to the CommonJS "module.exports" for node compatibility.
26
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
+ mod
28
+ ));
29
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
+ var runtime_dependency_manager_exports = {};
31
+ __export(runtime_dependency_manager_exports, {
32
+ DEPENDENCIES: () => DEPENDENCIES,
33
+ MANIFEST: () => MANIFEST,
34
+ SOURCE_CONFIG: () => SOURCE_CONFIG,
35
+ applyRuntimeEnvironment: () => applyRuntimeEnvironment,
36
+ dependencyCacheDir: () => dependencyCacheDir,
37
+ dependencyPlatformKey: () => dependencyPlatformKey,
38
+ downloadArtifact: () => downloadArtifact,
39
+ extractArtifact: () => extractArtifact,
40
+ managedRuntimeUsesConfiguredLoader: () => managedRuntimeUsesConfiguredLoader,
41
+ prepareRuntimeDependencies: () => prepareRuntimeDependencies,
42
+ pruneRuntimeDependencies: () => pruneRuntimeDependencies,
43
+ readRuntimeBinding: () => readRuntimeBinding,
44
+ runtimeArtifactDownloadUrls: () => runtimeArtifactDownloadUrls,
45
+ runtimeBindingId: () => runtimeBindingId,
46
+ runtimeBindings: () => runtimeBindings,
47
+ runtimePlatformKey: () => runtimePlatformKey,
48
+ selectedDependencyDefinitions: () => selectedDependencyDefinitions,
49
+ verifyExecutable: () => verifyExecutable
50
+ });
51
+ module.exports = __toCommonJS(runtime_dependency_manager_exports);
52
+ var crypto = __toESM(require("crypto"));
53
+ var fs = __toESM(require("fs"));
54
+ var path = __toESM(require("path"));
55
+ var import_child_process = require("child_process");
56
+ var import_promises = require("stream/promises");
57
+ var import_stream = require("stream");
58
+ var tar = __toESM(require("tar"));
59
+ var storageLayout = __toESM(require("./storage-layout.cjs"));
60
+ var import_runtime_executable_invocation = require("./runtime-executable-invocation.cjs");
61
+ const MANIFEST = require("./data/runtime-dependency-manifest.json");
62
+ const SOURCE_CONFIG = require("./data/runtime-dependency-sources.json");
63
+ const MAX_DOWNLOAD_BYTES = 512 * 1024 * 1024;
64
+ const DOWNLOAD_TIMEOUT_MS = 18e4;
65
+ const MIRROR_LOOKUP_TIMEOUT_MS = 3e3;
66
+ const LOCK_TIMEOUT_MS = 18e4;
67
+ const LOCK_STALE_MS = 10 * 6e4;
68
+ const LOCK_POLL_MS = 100;
69
+ const DEFAULT_RETAINED_BINDINGS = 3;
70
+ const SAFE_SEGMENT = /^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/;
71
+ const AUTHORITATIVE_NPM_ORIGIN = new URL(SOURCE_CONFIG.authoritativeNpmRegistry).origin;
72
+ const DEPENDENCIES = Object.freeze([
73
+ {
74
+ id: "codex",
75
+ envKeys: ["FARMING_CODEX_BIN", "CODEX_PATH"],
76
+ commands: ["codex"]
77
+ },
78
+ {
79
+ id: "claude",
80
+ envKeys: ["FARMING_CLAUDE_BIN", "CLAUDE_CODE_EXECUTABLE"],
81
+ commands: ["claude"]
82
+ },
83
+ {
84
+ id: "agentBrowser",
85
+ envKeys: ["FARMING_AGENT_BROWSER_BIN", "FARMING_AGENT_BROWSER_EXECUTABLE"],
86
+ commands: ["agent-browser"],
87
+ allowSystem: false
88
+ }
89
+ ]);
90
+ const DEPENDENCY_BY_ID = new Map(DEPENDENCIES.map((definition) => [definition.id, definition]));
91
+ function errorCode(error) {
92
+ if (!error || typeof error !== "object" || !("code" in error)) return "";
93
+ return typeof error.code === "string" ? error.code : "";
94
+ }
95
+ function errorName(error) {
96
+ if (!error || typeof error !== "object" || !("name" in error)) return "";
97
+ return typeof error.name === "string" ? error.name : "";
98
+ }
99
+ function errorMessage(error) {
100
+ return error instanceof Error ? error.message : String(error);
101
+ }
102
+ function delay(ms) {
103
+ return new Promise((resolve) => setTimeout(resolve, ms));
104
+ }
105
+ function safeSegment(value, label) {
106
+ const text = String(value || "").trim();
107
+ if (!SAFE_SEGMENT.test(text) || text === "." || text === "..") {
108
+ throw new Error(`Invalid runtime dependency ${label}`);
109
+ }
110
+ return text;
111
+ }
112
+ function safeRelative(value, label = "entry") {
113
+ const text = String(value || "").replace(/\\/g, "/");
114
+ if (!text || path.posix.isAbsolute(text) || text.split("/").some((part) => !part || part === "." || part === "..")) {
115
+ throw new Error(`Invalid runtime dependency ${label}`);
116
+ }
117
+ return text;
118
+ }
119
+ function selectedDependencyDefinitions(ids) {
120
+ if (ids === void 0) return [...DEPENDENCIES];
121
+ const requested = new Set(ids.map((id) => safeSegment(id, "id")));
122
+ for (const id of requested) {
123
+ if (!DEPENDENCY_BY_ID.has(id)) throw new Error(`Unknown runtime dependency: ${id}`);
124
+ }
125
+ return DEPENDENCIES.filter((definition) => requested.has(definition.id));
126
+ }
127
+ function runtimeBindingId(manifestId, platformKey) {
128
+ return `${safeSegment(manifestId, "manifest id")}.${safeSegment(platformKey, "platform key")}`;
129
+ }
130
+ function normalizeRuntimeBinding(value) {
131
+ if (!value || !SAFE_SEGMENT.test(String(value.manifestId || ""))) return null;
132
+ if (!SAFE_SEGMENT.test(String(value.platformKey || ""))) return null;
133
+ if (!value.dependencies || typeof value.dependencies !== "object") return null;
134
+ return {
135
+ schemaVersion: Number(value.schemaVersion) || 1,
136
+ bindingId: SAFE_SEGMENT.test(String(value.bindingId || "")) ? String(value.bindingId) : String(value.manifestId),
137
+ manifestId: String(value.manifestId),
138
+ platformKey: String(value.platformKey),
139
+ dependencies: value.dependencies,
140
+ preparedAt: String(value.preparedAt || "")
141
+ };
142
+ }
143
+ function readRuntimeBinding(configDir, bindingId) {
144
+ if (!SAFE_SEGMENT.test(bindingId)) return null;
145
+ return normalizeRuntimeBinding(readJson(
146
+ storageLayout.runtimeDependencyBindingFile(configDir, bindingId)
147
+ ));
148
+ }
149
+ function writeRuntimeBinding(configDir, binding) {
150
+ const bindingId = safeSegment(binding.bindingId, "binding id");
151
+ fs.mkdirSync(storageLayout.runtimeDependencyBindingsDir(configDir), { recursive: true, mode: 448 });
152
+ writeJsonAtomic(
153
+ storageLayout.runtimeDependencyBindingFile(configDir, bindingId),
154
+ binding
155
+ );
156
+ }
157
+ function runtimeBindings(configDir) {
158
+ const bindingsDir = storageLayout.runtimeDependencyBindingsDir(configDir);
159
+ if (!fs.existsSync(bindingsDir)) return [];
160
+ const bindings = [];
161
+ for (const entry of fs.readdirSync(bindingsDir, { withFileTypes: true })) {
162
+ if (!entry.isFile() || !entry.name.endsWith(".json")) continue;
163
+ const bindingId = entry.name.slice(0, -".json".length);
164
+ if (!SAFE_SEGMENT.test(bindingId)) continue;
165
+ const binding = readRuntimeBinding(configDir, bindingId);
166
+ if (binding && binding.bindingId === bindingId) bindings.push(binding);
167
+ }
168
+ return bindings;
169
+ }
170
+ function isMuslRuntime() {
171
+ if (process.platform !== "linux") return false;
172
+ if (process.report?.getReport) {
173
+ const report = process.report.getReport();
174
+ if (report?.header?.glibcVersionRuntime) return false;
175
+ }
176
+ return true;
177
+ }
178
+ function runtimePlatformKey(options = {}) {
179
+ const platform = safeSegment(options.platform || process.platform, "platform");
180
+ const arch = safeSegment(options.arch || process.arch, "architecture");
181
+ if (options.platformKey) return safeSegment(options.platformKey, "platform key");
182
+ const musl = options.musl ?? (platform === process.platform && isMuslRuntime());
183
+ return platform === "linux" && musl ? `${platform}-${arch}-musl` : `${platform}-${arch}`;
184
+ }
185
+ function legacyGlibcNeedsStaticAgentBrowser(platformKey, env = process.env) {
186
+ if (!/^linux-(?:x64|arm64)$/.test(platformKey)) return false;
187
+ if (env.FARMING_NODE_LD && env.FARMING_NODE_LIBRARY_PATH) return true;
188
+ if (process.platform !== "linux") return false;
189
+ const version = process.report?.getReport ? process.report.getReport()?.header?.glibcVersionRuntime : "";
190
+ const match = String(version || "").match(/^(\d+)\.(\d+)/);
191
+ if (!match) return false;
192
+ return Number(match[1]) < 2 || Number(match[1]) === 2 && Number(match[2]) < 28;
193
+ }
194
+ function dependencyPlatformKey(id, platformKey, env = process.env) {
195
+ return id === "agentBrowser" && legacyGlibcNeedsStaticAgentBrowser(platformKey, env) ? `${platformKey}-musl` : platformKey;
196
+ }
197
+ function dependencyCacheDir(configDir, id, version, platformKey) {
198
+ return path.join(
199
+ storageLayout.runtimeDependenciesDir(configDir),
200
+ safeSegment(id, "id"),
201
+ safeSegment(version, "version"),
202
+ safeSegment(platformKey, "platform key")
203
+ );
204
+ }
205
+ function fileSha256(filePath) {
206
+ return crypto.createHash("sha256").update(fs.readFileSync(filePath)).digest("hex");
207
+ }
208
+ function parseIntegrity(integrity) {
209
+ const match = String(integrity || "").match(/^(sha256|sha512)-([A-Za-z0-9+/=]+)$/);
210
+ if (!match) throw new Error("Runtime artifact integrity must use sha256 or sha512 SRI");
211
+ return {
212
+ algorithm: match[1],
213
+ digest: Buffer.from(match[2], "base64")
214
+ };
215
+ }
216
+ function which(command, env = process.env) {
217
+ try {
218
+ const program = process.platform === "win32" ? "where.exe" : "which";
219
+ const output = (0, import_child_process.execFileSync)(program, [command], {
220
+ encoding: "utf8",
221
+ timeout: 1e3,
222
+ maxBuffer: 64 * 1024,
223
+ env
224
+ });
225
+ return String(output).split(/\r?\n/).map((value) => value.trim()).find(Boolean) || "";
226
+ } catch {
227
+ return "";
228
+ }
229
+ }
230
+ function semanticVersion(output) {
231
+ return String(output || "").match(/\b\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+)?\b/)?.[0] || "";
232
+ }
233
+ async function verifyExecutable(executablePath, expectedVersion, options = {}) {
234
+ const execute = options.execFile || import_child_process.execFile;
235
+ const args = options.args || ["--version"];
236
+ const invocation = options.useConfiguredLoader ? (0, import_runtime_executable_invocation.runtimeExecutableInvocation)(
237
+ executablePath,
238
+ args,
239
+ options.env || process.env,
240
+ options.platform || process.platform
241
+ ) : { command: executablePath, args };
242
+ return new Promise((resolve) => {
243
+ execute(invocation.command, invocation.args, {
244
+ encoding: "utf8",
245
+ timeout: options.timeoutMs || 5e3,
246
+ maxBuffer: 1024 * 1024,
247
+ windowsHide: true,
248
+ env: options.env || process.env
249
+ }, (error, stdout, stderr) => {
250
+ const output = `${stdout || ""}
251
+ ${stderr || ""}`.trim();
252
+ const version = semanticVersion(output);
253
+ resolve({
254
+ valid: !error && version === expectedVersion,
255
+ version,
256
+ output,
257
+ error: error?.message || ""
258
+ });
259
+ });
260
+ });
261
+ }
262
+ function explicitCandidate(dependency, env) {
263
+ for (const key of dependency.envKeys) {
264
+ const value = String(env[key] || "").trim();
265
+ if (value) return { path: path.resolve(value), key };
266
+ }
267
+ return null;
268
+ }
269
+ function systemCandidates(dependency, env) {
270
+ const explicit = explicitCandidate(dependency, env);
271
+ if (explicit) return [explicit];
272
+ return dependency.commands.map((command) => which(command, env)).filter(Boolean).map((candidate) => ({ path: path.resolve(candidate), key: "" }));
273
+ }
274
+ function resolutionEnvironment(env) {
275
+ if (!env.FARMING_RUNTIME_MANIFEST_ID || env.FARMING_RUNTIME_MANIFEST_ID === MANIFEST.manifestId) {
276
+ return env;
277
+ }
278
+ const resolved = { ...env };
279
+ for (const dependency of DEPENDENCIES) {
280
+ for (const key of dependency.envKeys) delete resolved[key];
281
+ }
282
+ delete resolved.FARMING_RUNTIME_MANIFEST_ID;
283
+ return resolved;
284
+ }
285
+ function managedRuntimeUsesConfiguredLoader(id, platformKey = "") {
286
+ return id === "agentBrowser" && !platformKey.endsWith("-musl");
287
+ }
288
+ function readJson(filePath) {
289
+ try {
290
+ return JSON.parse(fs.readFileSync(filePath, "utf8"));
291
+ } catch {
292
+ return null;
293
+ }
294
+ }
295
+ function writeJsonAtomic(filePath, value) {
296
+ const temporary = `${filePath}.${process.pid}.${crypto.randomUUID()}.tmp`;
297
+ fs.mkdirSync(path.dirname(filePath), { recursive: true });
298
+ fs.writeFileSync(temporary, `${JSON.stringify(value, null, 2)}
299
+ `, {
300
+ flag: "wx",
301
+ mode: 384
302
+ });
303
+ fs.renameSync(temporary, filePath);
304
+ }
305
+ function processRunning(pid) {
306
+ if (!Number.isSafeInteger(pid) || pid <= 0) return false;
307
+ try {
308
+ process.kill(pid, 0);
309
+ return true;
310
+ } catch (error) {
311
+ return errorCode(error) === "EPERM" || errorCode(error) === "EACCES";
312
+ }
313
+ }
314
+ async function acquirePrepareLock(configDir, options = {}) {
315
+ const lockDir = storageLayout.runtimeDependenciesLockDir(configDir);
316
+ const startedAt = Date.now();
317
+ while (true) {
318
+ try {
319
+ fs.mkdirSync(lockDir, { recursive: false, mode: 448 });
320
+ writeJsonAtomic(path.join(lockDir, "owner.json"), {
321
+ pid: process.pid,
322
+ token: options.token || crypto.randomUUID(),
323
+ createdAt: (/* @__PURE__ */ new Date()).toISOString()
324
+ });
325
+ return () => fs.rmSync(lockDir, { recursive: true, force: true });
326
+ } catch (error) {
327
+ if (errorCode(error) !== "EEXIST") {
328
+ if (errorCode(error) === "ENOENT") {
329
+ fs.mkdirSync(path.dirname(lockDir), { recursive: true });
330
+ continue;
331
+ }
332
+ throw error;
333
+ }
334
+ const owner = readJson(path.join(lockDir, "owner.json"));
335
+ let ageMs = 0;
336
+ try {
337
+ ageMs = Date.now() - fs.statSync(lockDir).mtimeMs;
338
+ } catch {
339
+ continue;
340
+ }
341
+ if (owner && !processRunning(Number(owner.pid)) || !owner && ageMs >= LOCK_STALE_MS) {
342
+ const stale = `${lockDir}.stale-${Date.now()}-${crypto.randomUUID()}`;
343
+ try {
344
+ fs.renameSync(lockDir, stale);
345
+ fs.rmSync(stale, { recursive: true, force: true });
346
+ continue;
347
+ } catch {
348
+ }
349
+ }
350
+ if (Date.now() - startedAt >= (options.lockTimeoutMs || LOCK_TIMEOUT_MS)) {
351
+ throw new Error(
352
+ "Timed out waiting for another Farming startup dependency preparation",
353
+ { cause: error }
354
+ );
355
+ }
356
+ await (options.wait || delay)(options.lockPollMs || LOCK_POLL_MS);
357
+ }
358
+ }
359
+ }
360
+ function npmArtifactIdentity(artifactUrl) {
361
+ const artifact = new URL(artifactUrl);
362
+ const segments = artifact.pathname.split("/").filter(Boolean).map(decodeURIComponent);
363
+ const separator = segments.indexOf("-");
364
+ if (separator < 1 || separator !== segments.length - 2) {
365
+ throw new Error("Runtime artifact must use a standard npm tarball URL");
366
+ }
367
+ const packageName = segments.slice(0, separator).join("/");
368
+ const packageBase = packageName.split("/").pop();
369
+ const filename = segments[separator + 1];
370
+ const prefix = `${packageBase}-`;
371
+ if (!filename.startsWith(prefix) || !filename.endsWith(".tgz")) {
372
+ throw new Error("Runtime artifact tarball does not match its npm package");
373
+ }
374
+ return {
375
+ packageName,
376
+ version: filename.slice(prefix.length, -".tgz".length)
377
+ };
378
+ }
379
+ function configuredRuntimeNpmMirror(env) {
380
+ if (Object.prototype.hasOwnProperty.call(env, "FARMING_RUNTIME_NPM_MIRROR")) {
381
+ const configured = String(env.FARMING_RUNTIME_NPM_MIRROR || "").trim();
382
+ if (!configured || /^(0|false|none|off)$/i.test(configured)) return "";
383
+ return configured;
384
+ }
385
+ return String(SOURCE_CONFIG.defaultNpmMirror || "").trim();
386
+ }
387
+ async function runtimeArtifactDownloadUrls(artifact, options = {}) {
388
+ const authoritative = new URL(artifact.url);
389
+ if (authoritative.origin !== AUTHORITATIVE_NPM_ORIGIN) {
390
+ throw new Error("Runtime artifact must use the authoritative public npm registry");
391
+ }
392
+ const env = options.env || process.env;
393
+ const configuredMirror = configuredRuntimeNpmMirror(env);
394
+ if (!configuredMirror) return [authoritative.href];
395
+ const mirror = new URL(configuredMirror);
396
+ if (mirror.protocol !== "https:" || mirror.username || mirror.password || mirror.search || mirror.hash || !["", "/"].includes(mirror.pathname)) {
397
+ throw new Error("FARMING_RUNTIME_NPM_MIRROR must be an HTTPS registry origin");
398
+ }
399
+ if (mirror.origin === authoritative.origin) return [authoritative.href];
400
+ const { packageName, version } = npmArtifactIdentity(authoritative);
401
+ const metadataUrl = new URL(
402
+ `${encodeURIComponent(packageName)}/${encodeURIComponent(version)}`,
403
+ mirror
404
+ );
405
+ const controller = new globalThis.AbortController();
406
+ const timeout = setTimeout(
407
+ () => controller.abort(),
408
+ options.mirrorLookupTimeoutMs || MIRROR_LOOKUP_TIMEOUT_MS
409
+ );
410
+ timeout.unref?.();
411
+ try {
412
+ const request = options.fetch || fetch;
413
+ const response = await request(metadataUrl, {
414
+ headers: { accept: "application/json" },
415
+ redirect: "follow",
416
+ signal: controller.signal
417
+ });
418
+ if (!response.ok) return [authoritative.href];
419
+ const metadata = await response.json();
420
+ const mirroredTarball = metadata.dist?.tarball;
421
+ if (metadata.version !== version || metadata.dist?.integrity !== artifact.integrity || !mirroredTarball) {
422
+ return [authoritative.href];
423
+ }
424
+ const mirrored = new URL(mirroredTarball);
425
+ if (mirrored.protocol !== "https:" || mirrored.origin !== mirror.origin) {
426
+ return [authoritative.href];
427
+ }
428
+ return [mirrored.href, authoritative.href];
429
+ } catch {
430
+ return [authoritative.href];
431
+ } finally {
432
+ clearTimeout(timeout);
433
+ }
434
+ }
435
+ async function downloadArtifactFromUrl(artifact, url, destination, options = {}) {
436
+ const { algorithm, digest } = parseIntegrity(artifact.integrity);
437
+ const controller = new globalThis.AbortController();
438
+ const timeout = setTimeout(
439
+ () => controller.abort(),
440
+ options.downloadTimeoutMs || DOWNLOAD_TIMEOUT_MS
441
+ );
442
+ timeout.unref?.();
443
+ const hash = crypto.createHash(algorithm);
444
+ let received = 0;
445
+ try {
446
+ const request = options.fetch || fetch;
447
+ const response = await request(url, {
448
+ redirect: "follow",
449
+ signal: controller.signal
450
+ });
451
+ if (!response.ok || !response.body) {
452
+ throw new Error(`Runtime download failed with HTTP ${response.status}`);
453
+ }
454
+ const expectedSize = Number(artifact.size) || 0;
455
+ const limit = expectedSize || MAX_DOWNLOAD_BYTES;
456
+ const meter = new import_stream.Transform({
457
+ transform(chunk, _encoding, callback) {
458
+ received += chunk.length;
459
+ if (received > limit) {
460
+ callback(new Error(`Runtime download exceeded ${limit} bytes`));
461
+ return;
462
+ }
463
+ hash.update(chunk);
464
+ callback(null, chunk);
465
+ }
466
+ });
467
+ await (0, import_promises.pipeline)(
468
+ import_stream.Readable.fromWeb(
469
+ response.body
470
+ ),
471
+ meter,
472
+ fs.createWriteStream(destination, { flags: "wx", mode: 384 })
473
+ );
474
+ if (expectedSize && received !== expectedSize) {
475
+ throw new Error(`Runtime download size mismatch: expected ${expectedSize}, received ${received}`);
476
+ }
477
+ if (!crypto.timingSafeEqual(hash.digest(), digest)) {
478
+ throw new Error("Runtime artifact failed integrity verification");
479
+ }
480
+ } catch (error) {
481
+ fs.rmSync(destination, { force: true });
482
+ if (errorName(error) === "AbortError") {
483
+ throw new Error("Runtime download timed out", { cause: error });
484
+ }
485
+ throw error;
486
+ } finally {
487
+ clearTimeout(timeout);
488
+ }
489
+ }
490
+ async function downloadArtifact(artifact, destination, options = {}) {
491
+ const urls = await runtimeArtifactDownloadUrls(artifact, options);
492
+ for (const [index, url] of urls.entries()) {
493
+ try {
494
+ await downloadArtifactFromUrl(artifact, url, destination, options);
495
+ return;
496
+ } catch (error) {
497
+ if (index === urls.length - 1) throw error;
498
+ console.warn(
499
+ `Runtime npm mirror download failed; retrying the authoritative npm registry: ${errorMessage(error)}`
500
+ );
501
+ }
502
+ }
503
+ }
504
+ async function extractArtifact(artifact, archivePath, stagingDir) {
505
+ const entry = safeRelative(artifact.entry);
506
+ if (artifact.archive === "file") {
507
+ const destination = path.join(stagingDir, entry);
508
+ fs.mkdirSync(path.dirname(destination), { recursive: true });
509
+ fs.renameSync(archivePath, destination);
510
+ return destination;
511
+ }
512
+ if (artifact.archive !== "tgz") throw new Error(`Unsupported runtime archive: ${artifact.archive}`);
513
+ if (artifact.archiveEntry) {
514
+ const archiveEntry = safeRelative(artifact.archiveEntry, "archive entry");
515
+ const extractionDir = path.join(stagingDir, ".artifact");
516
+ const extractedName = path.posix.basename(archiveEntry);
517
+ fs.mkdirSync(extractionDir, { recursive: true });
518
+ await tar.x({
519
+ cwd: extractionDir,
520
+ file: archivePath,
521
+ gzip: true,
522
+ preserveOwner: false,
523
+ strict: true,
524
+ strip: archiveEntry.split("/").length - 1,
525
+ filter: (candidate) => candidate === archiveEntry
526
+ });
527
+ const extractedPath = path.join(extractionDir, extractedName);
528
+ const extractedStat = fs.lstatSync(extractedPath);
529
+ if (!extractedStat.isFile() || extractedStat.isSymbolicLink()) {
530
+ throw new Error("Runtime archive entry must be a regular file");
531
+ }
532
+ const destination = path.join(stagingDir, entry);
533
+ fs.mkdirSync(path.dirname(destination), { recursive: true });
534
+ fs.renameSync(extractedPath, destination);
535
+ fs.rmSync(extractionDir, { recursive: true, force: true });
536
+ fs.rmSync(archivePath, { force: true });
537
+ return destination;
538
+ }
539
+ const prefix = safeRelative(artifact.archivePrefix, "archive prefix");
540
+ const prefixWithSlash = `${prefix}/`;
541
+ await tar.x({
542
+ cwd: stagingDir,
543
+ file: archivePath,
544
+ gzip: true,
545
+ preserveOwner: false,
546
+ strict: true,
547
+ strip: prefix.split("/").length,
548
+ filter: (archiveEntry) => archiveEntry === prefix || archiveEntry.startsWith(prefixWithSlash)
549
+ });
550
+ fs.rmSync(archivePath, { force: true });
551
+ const executablePath = path.resolve(stagingDir, entry);
552
+ if (!executablePath.startsWith(`${path.resolve(stagingDir)}${path.sep}`)) {
553
+ throw new Error("Runtime executable escaped the staging directory");
554
+ }
555
+ const realExecutablePath = fs.realpathSync(executablePath);
556
+ const executableStat = fs.lstatSync(executablePath);
557
+ if (!executableStat.isFile() || executableStat.isSymbolicLink() || !realExecutablePath.startsWith(`${fs.realpathSync(stagingDir)}${path.sep}`)) {
558
+ throw new Error("Runtime executable must be a regular file inside the staging directory");
559
+ }
560
+ return executablePath;
561
+ }
562
+ function dependencyManifest(id, platformKey) {
563
+ if (MANIFEST.schemaVersion !== 1 || !MANIFEST.manifestId) {
564
+ throw new Error("Runtime dependency manifest is invalid");
565
+ }
566
+ const dependency = MANIFEST.dependencies?.[id];
567
+ const artifact = dependency?.artifacts?.[platformKey];
568
+ if (!dependency || !artifact) {
569
+ throw new Error(`${id} has no runtime artifact for ${platformKey}`);
570
+ }
571
+ parseIntegrity(artifact.integrity);
572
+ safeRelative(artifact.entry);
573
+ if (artifact.archive === "tgz") {
574
+ if (artifact.archiveEntry) safeRelative(artifact.archiveEntry, "archive entry");
575
+ else safeRelative(artifact.archivePrefix, "archive prefix");
576
+ }
577
+ return { dependency, artifact };
578
+ }
579
+ async function resolveCachedRuntime(configDir, id, platformKey, options = {}) {
580
+ const { dependency, artifact } = dependencyManifest(id, platformKey);
581
+ const cacheDir = dependencyCacheDir(configDir, id, dependency.version, platformKey);
582
+ const record = readJson(path.join(cacheDir, "runtime.json"));
583
+ const executablePath = path.resolve(cacheDir, artifact.entry);
584
+ if (!record || record.schemaVersion !== 1 || record.manifestId !== MANIFEST.manifestId || record.id !== id || record.version !== dependency.version || record.platformKey !== platformKey || record.integrity !== artifact.integrity || record.entry !== artifact.entry || !fs.existsSync(executablePath) || fileSha256(executablePath) !== record.executableSha256) {
585
+ return null;
586
+ }
587
+ if (dependency.managedProbe !== false) {
588
+ const verification = await verifyExecutable(
589
+ executablePath,
590
+ dependency.reportedVersion || dependency.version,
591
+ {
592
+ args: dependency.probe?.args,
593
+ env: options.env,
594
+ useConfiguredLoader: managedRuntimeUsesConfiguredLoader(id, platformKey)
595
+ }
596
+ );
597
+ if (!verification.valid) return null;
598
+ }
599
+ return {
600
+ id,
601
+ version: dependency.version,
602
+ platformKey,
603
+ source: "managed",
604
+ executablePath
605
+ };
606
+ }
607
+ async function findExactRuntime(configDir, definition, platformKey, env) {
608
+ const { dependency } = dependencyManifest(definition.id, platformKey);
609
+ const expectedVersion = dependency.reportedVersion || dependency.version;
610
+ const candidates = definition.allowSystem === false ? [] : systemCandidates(definition, env);
611
+ for (const candidate of candidates) {
612
+ if (!fs.existsSync(candidate.path)) {
613
+ if (candidate.key) {
614
+ throw new Error(`${candidate.key} points to a missing executable: ${candidate.path}`);
615
+ }
616
+ continue;
617
+ }
618
+ const verification = await verifyExecutable(candidate.path, expectedVersion, {
619
+ args: dependency.probe?.args,
620
+ env
621
+ });
622
+ if (verification.valid) {
623
+ return {
624
+ id: definition.id,
625
+ version: dependency.version,
626
+ reportedVersion: expectedVersion,
627
+ platformKey,
628
+ source: "system",
629
+ executablePath: candidate.path
630
+ };
631
+ }
632
+ if (candidate.key) {
633
+ throw new Error(
634
+ `${candidate.key} must provide ${definition.id} ${expectedVersion}; found ${verification.version || "an unverifiable executable"}`
635
+ );
636
+ }
637
+ }
638
+ return resolveCachedRuntime(configDir, definition.id, platformKey, { env });
639
+ }
640
+ async function installExactRuntime(configDir, definition, platformKey, options = {}) {
641
+ const { dependency, artifact } = dependencyManifest(definition.id, platformKey);
642
+ const cacheDir = dependencyCacheDir(configDir, definition.id, dependency.version, platformKey);
643
+ const stagingDir = `${cacheDir}.preparing-${process.pid}-${crypto.randomUUID()}`;
644
+ const archivePath = path.join(stagingDir, "artifact.download");
645
+ const quarantine = `${cacheDir}.invalid-${Date.now()}-${crypto.randomUUID()}`;
646
+ fs.mkdirSync(stagingDir, { recursive: true, mode: 448 });
647
+ try {
648
+ await downloadArtifact(artifact, archivePath, options);
649
+ const executablePath = await extractArtifact(artifact, archivePath, stagingDir);
650
+ if (!fs.existsSync(executablePath)) throw new Error(`${definition.id} archive omitted ${artifact.entry}`);
651
+ fs.chmodSync(executablePath, 448);
652
+ if (dependency.managedProbe !== false) {
653
+ const verification = await verifyExecutable(
654
+ executablePath,
655
+ dependency.reportedVersion || dependency.version,
656
+ {
657
+ args: dependency.probe?.args,
658
+ env: options.env,
659
+ useConfiguredLoader: managedRuntimeUsesConfiguredLoader(definition.id, platformKey)
660
+ }
661
+ );
662
+ if (!verification.valid) {
663
+ throw new Error(
664
+ `${definition.id} runtime reported ${verification.version || "no version"}; expected ${dependency.reportedVersion || dependency.version}`
665
+ );
666
+ }
667
+ }
668
+ writeJsonAtomic(path.join(stagingDir, "runtime.json"), {
669
+ schemaVersion: 1,
670
+ manifestId: MANIFEST.manifestId,
671
+ id: definition.id,
672
+ version: dependency.version,
673
+ platformKey,
674
+ integrity: artifact.integrity,
675
+ entry: artifact.entry,
676
+ executableSha256: fileSha256(executablePath),
677
+ installedAt: (/* @__PURE__ */ new Date()).toISOString()
678
+ });
679
+ const hadCache = fs.existsSync(cacheDir);
680
+ if (hadCache) fs.renameSync(cacheDir, quarantine);
681
+ try {
682
+ fs.renameSync(stagingDir, cacheDir);
683
+ } catch (error) {
684
+ if (hadCache && !fs.existsSync(cacheDir) && fs.existsSync(quarantine)) {
685
+ fs.renameSync(quarantine, cacheDir);
686
+ }
687
+ throw error;
688
+ }
689
+ fs.rmSync(quarantine, { recursive: true, force: true });
690
+ } catch (error) {
691
+ fs.rmSync(stagingDir, { recursive: true, force: true });
692
+ throw error;
693
+ }
694
+ const resolved = await resolveCachedRuntime(
695
+ configDir,
696
+ definition.id,
697
+ platformKey,
698
+ { env: options.env }
699
+ );
700
+ if (!resolved) throw new Error(`${definition.id} runtime did not pass post-install verification`);
701
+ return resolved;
702
+ }
703
+ function applyRuntimeEnvironment(env, prepared) {
704
+ const byId = new Map(prepared.map((item) => [item.id, item]));
705
+ const codex = byId.get("codex")?.executablePath;
706
+ const claude = byId.get("claude")?.executablePath;
707
+ const agentBrowser = byId.get("agentBrowser")?.executablePath;
708
+ if (codex) {
709
+ env.FARMING_CODEX_BIN = codex;
710
+ env.CODEX_PATH = codex;
711
+ }
712
+ if (claude) {
713
+ env.FARMING_CLAUDE_BIN = claude;
714
+ env.CLAUDE_CODE_EXECUTABLE = claude;
715
+ }
716
+ if (agentBrowser) {
717
+ env.FARMING_AGENT_BROWSER_BIN = agentBrowser;
718
+ env.FARMING_AGENT_BROWSER_EXECUTABLE = agentBrowser;
719
+ if (byId.get("agentBrowser")?.platformKey?.endsWith("-musl")) {
720
+ env.FARMING_AGENT_BROWSER_STATIC = "1";
721
+ } else {
722
+ delete env.FARMING_AGENT_BROWSER_STATIC;
723
+ }
724
+ }
725
+ env.FARMING_RUNTIME_MANIFEST_ID = MANIFEST.manifestId;
726
+ return env;
727
+ }
728
+ async function prepareRuntimeDependencies(options = {}) {
729
+ const env = options.env || process.env;
730
+ const candidateEnv = resolutionEnvironment(env);
731
+ const configDir = options.configDir || storageLayout.farmingConfigDir(env);
732
+ const platformKey = runtimePlatformKey(options);
733
+ fs.mkdirSync(storageLayout.runtimeDependenciesDir(configDir), { recursive: true });
734
+ const releaseLock = await acquirePrepareLock(configDir, options);
735
+ const prepared = [];
736
+ try {
737
+ for (const definition of selectedDependencyDefinitions(options.dependencyIds)) {
738
+ const selectedPlatformKey = dependencyPlatformKey(
739
+ definition.id,
740
+ platformKey,
741
+ candidateEnv
742
+ );
743
+ let runtime = await findExactRuntime(
744
+ configDir,
745
+ definition,
746
+ selectedPlatformKey,
747
+ candidateEnv
748
+ );
749
+ if (!runtime) {
750
+ const installRuntime = options.installRuntime || installExactRuntime;
751
+ runtime = await installRuntime(configDir, definition, selectedPlatformKey, options);
752
+ }
753
+ runtime.platformKey ||= selectedPlatformKey;
754
+ prepared.push(runtime);
755
+ }
756
+ applyRuntimeEnvironment(env, prepared);
757
+ const bindingId = runtimeBindingId(MANIFEST.manifestId, platformKey);
758
+ const existing = readRuntimeBinding(configDir, bindingId);
759
+ const binding = {
760
+ schemaVersion: 2,
761
+ bindingId,
762
+ manifestId: MANIFEST.manifestId,
763
+ platformKey,
764
+ dependencies: {
765
+ ...existing?.platformKey === platformKey ? existing.dependencies : {},
766
+ ...Object.fromEntries(prepared.map((item) => [item.id, {
767
+ version: item.version,
768
+ platformKey: item.platformKey,
769
+ source: item.source,
770
+ executablePath: item.executablePath
771
+ }]))
772
+ },
773
+ preparedAt: (/* @__PURE__ */ new Date()).toISOString()
774
+ };
775
+ writeRuntimeBinding(configDir, binding);
776
+ if (options.activate !== false) {
777
+ writeJsonAtomic(storageLayout.runtimeDependenciesActiveFile(configDir), binding);
778
+ }
779
+ return { binding, manifestId: MANIFEST.manifestId, platformKey, dependencies: prepared };
780
+ } finally {
781
+ releaseLock();
782
+ }
783
+ }
784
+ async function pruneRuntimeDependencies(options = {}) {
785
+ const env = options.env || process.env;
786
+ const configDir = options.configDir || storageLayout.farmingConfigDir(env);
787
+ const releaseLock = await acquirePrepareLock(configDir, options);
788
+ const removed = [];
789
+ try {
790
+ const active = normalizeRuntimeBinding(readJson(
791
+ storageLayout.runtimeDependenciesActiveFile(configDir)
792
+ ));
793
+ const storedBindings = runtimeBindings(configDir).sort((left, right) => (Date.parse(right.preparedAt || "") || 0) - (Date.parse(left.preparedAt || "") || 0));
794
+ if (!active && storedBindings.length === 0) return { removed };
795
+ const retainedCount = Math.max(
796
+ 1,
797
+ Math.min(10, Math.floor(Number(options.retainedBindings) || DEFAULT_RETAINED_BINDINGS))
798
+ );
799
+ const retainedIds = /* @__PURE__ */ new Set();
800
+ if (active?.bindingId) retainedIds.add(active.bindingId);
801
+ for (const binding of storedBindings) {
802
+ if (retainedIds.size >= retainedCount) break;
803
+ if (binding.bindingId) retainedIds.add(binding.bindingId);
804
+ }
805
+ const retainedBindings = storedBindings.filter((binding) => binding.bindingId && retainedIds.has(binding.bindingId));
806
+ if (active && !retainedBindings.some((binding) => binding.bindingId === active.bindingId)) {
807
+ retainedBindings.push(active);
808
+ }
809
+ for (const binding of storedBindings) {
810
+ if (!binding.bindingId || retainedIds.has(binding.bindingId)) continue;
811
+ const bindingFile = storageLayout.runtimeDependencyBindingFile(configDir, binding.bindingId);
812
+ fs.rmSync(bindingFile, { force: true });
813
+ removed.push(bindingFile);
814
+ }
815
+ const keepDirs = /* @__PURE__ */ new Map();
816
+ for (const binding of retainedBindings) {
817
+ for (const [id, dependency] of Object.entries(binding.dependencies || {})) {
818
+ if (dependency.source !== "managed") continue;
819
+ if (!DEPENDENCY_BY_ID.has(id)) continue;
820
+ const selectedPlatform = safeSegment(
821
+ dependency.platformKey || binding.platformKey,
822
+ "platform key"
823
+ );
824
+ const keepDir = dependencyCacheDir(
825
+ configDir,
826
+ id,
827
+ safeSegment(dependency.version, "version"),
828
+ selectedPlatform
829
+ );
830
+ const paths = keepDirs.get(id) || /* @__PURE__ */ new Set();
831
+ paths.add(path.resolve(keepDir));
832
+ keepDirs.set(id, paths);
833
+ }
834
+ }
835
+ for (const definition of DEPENDENCIES) {
836
+ const dependencyRoot = path.join(
837
+ storageLayout.runtimeDependenciesDir(configDir),
838
+ safeSegment(definition.id, "id")
839
+ );
840
+ if (!fs.existsSync(dependencyRoot)) continue;
841
+ const dependencyRootStat = fs.lstatSync(dependencyRoot);
842
+ if (!dependencyRootStat.isDirectory() || dependencyRootStat.isSymbolicLink()) {
843
+ fs.rmSync(dependencyRoot, { recursive: true, force: true });
844
+ removed.push(dependencyRoot);
845
+ continue;
846
+ }
847
+ const dependencyKeepDirs = keepDirs.get(definition.id) || /* @__PURE__ */ new Set();
848
+ for (const versionEntry of fs.readdirSync(dependencyRoot, { withFileTypes: true })) {
849
+ const versionDir = path.join(dependencyRoot, versionEntry.name);
850
+ if (!versionEntry.isDirectory()) {
851
+ fs.rmSync(versionDir, { recursive: true, force: true });
852
+ removed.push(versionDir);
853
+ continue;
854
+ }
855
+ for (const platformEntry of fs.readdirSync(versionDir, { withFileTypes: true })) {
856
+ const platformDir = path.join(versionDir, platformEntry.name);
857
+ if (platformEntry.isDirectory() && dependencyKeepDirs.has(path.resolve(platformDir))) continue;
858
+ fs.rmSync(platformDir, { recursive: true, force: true });
859
+ removed.push(platformDir);
860
+ }
861
+ if (fs.readdirSync(versionDir).length === 0) {
862
+ fs.rmdirSync(versionDir);
863
+ removed.push(versionDir);
864
+ }
865
+ }
866
+ if (fs.readdirSync(dependencyRoot).length === 0) fs.rmdirSync(dependencyRoot);
867
+ }
868
+ return { removed };
869
+ } finally {
870
+ releaseLock();
871
+ }
872
+ }
873
+ // Annotate the CommonJS export names for ESM import in node:
874
+ 0 && (module.exports = {
875
+ DEPENDENCIES,
876
+ MANIFEST,
877
+ SOURCE_CONFIG,
878
+ applyRuntimeEnvironment,
879
+ dependencyCacheDir,
880
+ dependencyPlatformKey,
881
+ downloadArtifact,
882
+ extractArtifact,
883
+ managedRuntimeUsesConfiguredLoader,
884
+ prepareRuntimeDependencies,
885
+ pruneRuntimeDependencies,
886
+ readRuntimeBinding,
887
+ runtimeArtifactDownloadUrls,
888
+ runtimeBindingId,
889
+ runtimeBindings,
890
+ runtimePlatformKey,
891
+ selectedDependencyDefinitions,
892
+ verifyExecutable
893
+ });