@nordhavnhq/runner 0.0.0-stage → 0.95.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (338) hide show
  1. package/bin/cliclick +0 -0
  2. package/dist/brand.d.ts +5 -0
  3. package/dist/brand.js +18 -0
  4. package/dist/cli/agent.d.ts +9 -0
  5. package/dist/cli/agent.js +80 -0
  6. package/dist/cli/folder.d.ts +2 -0
  7. package/dist/cli/folder.js +103 -0
  8. package/dist/cli/init.d.ts +2 -0
  9. package/dist/cli/init.js +67 -0
  10. package/dist/cli/lifecycle.d.ts +3 -0
  11. package/dist/cli/lifecycle.js +149 -0
  12. package/dist/cli/link.d.ts +42 -0
  13. package/dist/cli/link.js +314 -0
  14. package/dist/cli/logs.d.ts +2 -0
  15. package/dist/cli/logs.js +147 -0
  16. package/dist/cli/prompts.d.ts +7 -0
  17. package/dist/cli/prompts.js +13 -0
  18. package/dist/cli/ps.d.ts +2 -0
  19. package/dist/cli/ps.js +81 -0
  20. package/dist/cli/relay.d.ts +4 -0
  21. package/dist/cli/relay.js +29 -0
  22. package/dist/cli/update.d.ts +6 -0
  23. package/dist/cli/update.js +131 -0
  24. package/dist/config.d.ts +166 -0
  25. package/dist/config.js +383 -0
  26. package/dist/index.d.ts +2 -0
  27. package/dist/index.js +145 -0
  28. package/dist/legacy-env.d.ts +4 -0
  29. package/dist/legacy-env.js +32 -0
  30. package/dist/paths.d.ts +37 -0
  31. package/dist/paths.js +92 -0
  32. package/dist/runtime/daemon.d.ts +57 -0
  33. package/dist/runtime/daemon.js +159 -0
  34. package/dist/runtime/dev-start.d.ts +31 -0
  35. package/dist/runtime/dev-start.js +110 -0
  36. package/dist/runtime/file-claims.d.ts +58 -0
  37. package/dist/runtime/file-claims.js +174 -0
  38. package/dist/runtime/fs-browse.d.ts +18 -0
  39. package/dist/runtime/fs-browse.js +104 -0
  40. package/dist/runtime/fs-checkout.d.ts +154 -0
  41. package/dist/runtime/fs-checkout.js +1049 -0
  42. package/dist/runtime/fs-git-index.d.ts +22 -0
  43. package/dist/runtime/fs-git-index.js +133 -0
  44. package/dist/runtime/fs-git.d.ts +16 -0
  45. package/dist/runtime/fs-git.js +424 -0
  46. package/dist/runtime/git-relay.d.ts +46 -0
  47. package/dist/runtime/git-relay.js +259 -0
  48. package/dist/runtime/git-unpushed.d.ts +36 -0
  49. package/dist/runtime/git-unpushed.js +93 -0
  50. package/dist/runtime/node-version.d.ts +12 -0
  51. package/dist/runtime/node-version.js +39 -0
  52. package/dist/runtime/preview-tunnel.d.ts +16 -0
  53. package/dist/runtime/preview-tunnel.js +135 -0
  54. package/dist/runtime/processes.d.ts +61 -0
  55. package/dist/runtime/processes.js +408 -0
  56. package/dist/runtime/project-node-download.d.ts +17 -0
  57. package/dist/runtime/project-node-download.js +137 -0
  58. package/dist/runtime/project-node.d.ts +65 -0
  59. package/dist/runtime/project-node.js +223 -0
  60. package/dist/runtime/reap-scratch.d.ts +22 -0
  61. package/dist/runtime/reap-scratch.js +112 -0
  62. package/dist/runtime/spill-tool-output.d.ts +14 -0
  63. package/dist/runtime/spill-tool-output.js +84 -0
  64. package/dist/runtime/up.d.ts +6 -0
  65. package/dist/runtime/up.js +1325 -0
  66. package/dist/tools/_coerce.d.ts +2 -0
  67. package/dist/tools/_coerce.js +26 -0
  68. package/dist/tools/_commit-scope.d.ts +14 -0
  69. package/dist/tools/_commit-scope.js +70 -0
  70. package/dist/tools/_jail.d.ts +68 -0
  71. package/dist/tools/_jail.js +209 -0
  72. package/dist/tools/_output.d.ts +24 -0
  73. package/dist/tools/_output.js +48 -0
  74. package/dist/tools/_ripgrep.d.ts +46 -0
  75. package/dist/tools/_ripgrep.js +148 -0
  76. package/dist/tools/_run-worktree.d.ts +10 -0
  77. package/dist/tools/_run-worktree.js +27 -0
  78. package/dist/tools/_shell-words.d.ts +15 -0
  79. package/dist/tools/_shell-words.js +43 -0
  80. package/dist/tools/_sonar/astro.d.ts +6 -0
  81. package/dist/tools/_sonar/astro.js +45 -0
  82. package/dist/tools/_sonar/blade.d.ts +3 -0
  83. package/dist/tools/_sonar/blade.js +53 -0
  84. package/dist/tools/_sonar/build.d.ts +44 -0
  85. package/dist/tools/_sonar/build.js +147 -0
  86. package/dist/tools/_sonar/changed.d.ts +21 -0
  87. package/dist/tools/_sonar/changed.js +230 -0
  88. package/dist/tools/_sonar/diagnose/delta.d.ts +27 -0
  89. package/dist/tools/_sonar/diagnose/delta.js +64 -0
  90. package/dist/tools/_sonar/diagnose/detect.d.ts +39 -0
  91. package/dist/tools/_sonar/diagnose/detect.js +117 -0
  92. package/dist/tools/_sonar/diagnose/index.d.ts +13 -0
  93. package/dist/tools/_sonar/diagnose/index.js +217 -0
  94. package/dist/tools/_sonar/diagnose/lint-worker.d.ts +1 -0
  95. package/dist/tools/_sonar/diagnose/lint-worker.js +48 -0
  96. package/dist/tools/_sonar/diagnose/pool.d.ts +22 -0
  97. package/dist/tools/_sonar/diagnose/pool.js +149 -0
  98. package/dist/tools/_sonar/diagnose/rules.d.ts +23 -0
  99. package/dist/tools/_sonar/diagnose/rules.js +131 -0
  100. package/dist/tools/_sonar/diagnose/types-worker.d.ts +1 -0
  101. package/dist/tools/_sonar/diagnose/types-worker.js +183 -0
  102. package/dist/tools/_sonar/files.d.ts +14 -0
  103. package/dist/tools/_sonar/files.js +121 -0
  104. package/dist/tools/_sonar/graph.d.ts +34 -0
  105. package/dist/tools/_sonar/graph.js +164 -0
  106. package/dist/tools/_sonar/hints.d.ts +116 -0
  107. package/dist/tools/_sonar/hints.js +545 -0
  108. package/dist/tools/_sonar/imports.d.ts +38 -0
  109. package/dist/tools/_sonar/imports.js +275 -0
  110. package/dist/tools/_sonar/index.d.ts +79 -0
  111. package/dist/tools/_sonar/index.js +462 -0
  112. package/dist/tools/_sonar/keys.d.ts +5 -0
  113. package/dist/tools/_sonar/keys.js +248 -0
  114. package/dist/tools/_sonar/laravel-routes.d.ts +15 -0
  115. package/dist/tools/_sonar/laravel-routes.js +263 -0
  116. package/dist/tools/_sonar/laravel.d.ts +64 -0
  117. package/dist/tools/_sonar/laravel.js +326 -0
  118. package/dist/tools/_sonar/location.d.ts +33 -0
  119. package/dist/tools/_sonar/location.js +137 -0
  120. package/dist/tools/_sonar/map.d.ts +43 -0
  121. package/dist/tools/_sonar/map.js +212 -0
  122. package/dist/tools/_sonar/parse.d.ts +3 -0
  123. package/dist/tools/_sonar/parse.js +76 -0
  124. package/dist/tools/_sonar/prewarm.d.ts +9 -0
  125. package/dist/tools/_sonar/prewarm.js +96 -0
  126. package/dist/tools/_sonar/prisma.d.ts +9 -0
  127. package/dist/tools/_sonar/prisma.js +51 -0
  128. package/dist/tools/_sonar/refs.d.ts +7 -0
  129. package/dist/tools/_sonar/refs.js +273 -0
  130. package/dist/tools/_sonar/render.d.ts +66 -0
  131. package/dist/tools/_sonar/render.js +498 -0
  132. package/dist/tools/_sonar/resolve.d.ts +63 -0
  133. package/dist/tools/_sonar/resolve.js +402 -0
  134. package/dist/tools/_sonar/roots.d.ts +4 -0
  135. package/dist/tools/_sonar/roots.js +42 -0
  136. package/dist/tools/_sonar/routes.d.ts +5 -0
  137. package/dist/tools/_sonar/routes.js +247 -0
  138. package/dist/tools/_sonar/serve.d.ts +12 -0
  139. package/dist/tools/_sonar/serve.js +104 -0
  140. package/dist/tools/_sonar/suggest.d.ts +23 -0
  141. package/dist/tools/_sonar/suggest.js +114 -0
  142. package/dist/tools/_sonar/tests.d.ts +21 -0
  143. package/dist/tools/_sonar/tests.js +134 -0
  144. package/dist/tools/_sonar/tsconfig.d.ts +34 -0
  145. package/dist/tools/_sonar/tsconfig.js +188 -0
  146. package/dist/tools/_sonar/types.d.ts +81 -0
  147. package/dist/tools/_sonar/types.js +6 -0
  148. package/dist/tools/_symbols.d.ts +27 -0
  149. package/dist/tools/_symbols.js +461 -0
  150. package/dist/tools/_test-report.d.ts +47 -0
  151. package/dist/tools/_test-report.js +203 -0
  152. package/dist/tools/_touched.d.ts +44 -0
  153. package/dist/tools/_touched.js +195 -0
  154. package/dist/tools/_upload.d.ts +26 -0
  155. package/dist/tools/_upload.js +132 -0
  156. package/dist/tools/_worktree-setup.d.ts +29 -0
  157. package/dist/tools/_worktree-setup.js +204 -0
  158. package/dist/tools/browser.d.ts +2 -0
  159. package/dist/tools/browser.js +8 -0
  160. package/dist/tools/commit-guard.d.ts +44 -0
  161. package/dist/tools/commit-guard.js +165 -0
  162. package/dist/tools/computer.d.ts +13 -0
  163. package/dist/tools/computer.js +952 -0
  164. package/dist/tools/console.d.ts +44 -0
  165. package/dist/tools/console.js +739 -0
  166. package/dist/tools/database.d.ts +28 -0
  167. package/dist/tools/database.js +152 -0
  168. package/dist/tools/filesystem.d.ts +36 -0
  169. package/dist/tools/filesystem.js +506 -0
  170. package/dist/tools/git-tag.d.ts +10 -0
  171. package/dist/tools/git-tag.js +164 -0
  172. package/dist/tools/git.d.ts +52 -0
  173. package/dist/tools/git.js +1272 -0
  174. package/dist/tools/http.d.ts +12 -0
  175. package/dist/tools/http.js +119 -0
  176. package/dist/tools/image.d.ts +8 -0
  177. package/dist/tools/image.js +551 -0
  178. package/dist/tools/index.d.ts +13 -0
  179. package/dist/tools/index.js +58 -0
  180. package/dist/tools/outline.d.ts +20 -0
  181. package/dist/tools/outline.js +98 -0
  182. package/dist/tools/search.d.ts +17 -0
  183. package/dist/tools/search.js +391 -0
  184. package/dist/tools/sonar.d.ts +17 -0
  185. package/dist/tools/sonar.js +231 -0
  186. package/dist/tools/testing.d.ts +36 -0
  187. package/dist/tools/testing.js +273 -0
  188. package/dist/tools/upload.d.ts +8 -0
  189. package/dist/tools/upload.js +106 -0
  190. package/dist/tools/webcam.d.ts +28 -0
  191. package/dist/tools/webcam.js +967 -0
  192. package/dist/update/install-kind.d.ts +35 -0
  193. package/dist/update/install-kind.js +109 -0
  194. package/dist/update/install.d.ts +32 -0
  195. package/dist/update/install.js +187 -0
  196. package/dist/update/manifest.d.ts +18 -0
  197. package/dist/update/manifest.js +73 -0
  198. package/dist/update/peers.d.ts +18 -0
  199. package/dist/update/peers.js +43 -0
  200. package/dist/update/policy.d.ts +20 -0
  201. package/dist/update/policy.js +49 -0
  202. package/dist/update/supervisor.d.ts +25 -0
  203. package/dist/update/supervisor.js +83 -0
  204. package/dist/update/updater.d.ts +44 -0
  205. package/dist/update/updater.js +116 -0
  206. package/dist/utils/format.d.ts +50 -0
  207. package/dist/utils/format.js +190 -0
  208. package/dist/version.d.ts +17 -0
  209. package/dist/version.js +63 -0
  210. package/dist/version.json +5 -0
  211. package/node_modules/@nordhavnhq/runner-browser/dist/act-tools.d.ts +15 -0
  212. package/node_modules/@nordhavnhq/runner-browser/dist/act-tools.js +541 -0
  213. package/node_modules/@nordhavnhq/runner-browser/dist/cast-hub.d.ts +25 -0
  214. package/node_modules/@nordhavnhq/runner-browser/dist/cast-hub.js +137 -0
  215. package/node_modules/@nordhavnhq/runner-browser/dist/guard.d.ts +21 -0
  216. package/node_modules/@nordhavnhq/runner-browser/dist/guard.js +104 -0
  217. package/node_modules/@nordhavnhq/runner-browser/dist/host-protocol.d.ts +47 -0
  218. package/node_modules/@nordhavnhq/runner-browser/dist/host-protocol.js +41 -0
  219. package/node_modules/@nordhavnhq/runner-browser/dist/host.d.ts +18 -0
  220. package/node_modules/@nordhavnhq/runner-browser/dist/host.js +15 -0
  221. package/node_modules/@nordhavnhq/runner-browser/dist/index.d.ts +13 -0
  222. package/node_modules/@nordhavnhq/runner-browser/dist/index.js +28 -0
  223. package/node_modules/@nordhavnhq/runner-browser/dist/live-input.d.ts +74 -0
  224. package/node_modules/@nordhavnhq/runner-browser/dist/live-input.js +93 -0
  225. package/node_modules/@nordhavnhq/runner-browser/dist/live-open.d.ts +4 -0
  226. package/node_modules/@nordhavnhq/runner-browser/dist/live-open.js +57 -0
  227. package/node_modules/@nordhavnhq/runner-browser/dist/live.d.ts +148 -0
  228. package/node_modules/@nordhavnhq/runner-browser/dist/live.js +179 -0
  229. package/node_modules/@nordhavnhq/runner-browser/dist/local-live.d.ts +31 -0
  230. package/node_modules/@nordhavnhq/runner-browser/dist/local-live.js +262 -0
  231. package/node_modules/@nordhavnhq/runner-browser/dist/marks.d.ts +36 -0
  232. package/node_modules/@nordhavnhq/runner-browser/dist/marks.js +173 -0
  233. package/node_modules/@nordhavnhq/runner-browser/dist/page-events.d.ts +27 -0
  234. package/node_modules/@nordhavnhq/runner-browser/dist/page-events.js +82 -0
  235. package/node_modules/@nordhavnhq/runner-browser/dist/page-tools.d.ts +13 -0
  236. package/node_modules/@nordhavnhq/runner-browser/dist/page-tools.js +526 -0
  237. package/node_modules/@nordhavnhq/runner-browser/dist/params.d.ts +12 -0
  238. package/node_modules/@nordhavnhq/runner-browser/dist/params.js +32 -0
  239. package/node_modules/@nordhavnhq/runner-browser/dist/pick.d.ts +24 -0
  240. package/node_modules/@nordhavnhq/runner-browser/dist/pick.js +76 -0
  241. package/node_modules/@nordhavnhq/runner-browser/dist/session.d.ts +225 -0
  242. package/node_modules/@nordhavnhq/runner-browser/dist/session.js +507 -0
  243. package/node_modules/@nordhavnhq/runner-browser/dist/shots.d.ts +11 -0
  244. package/node_modules/@nordhavnhq/runner-browser/dist/shots.js +103 -0
  245. package/node_modules/@nordhavnhq/runner-browser/dist/show.d.ts +10 -0
  246. package/node_modules/@nordhavnhq/runner-browser/dist/show.js +190 -0
  247. package/node_modules/@nordhavnhq/runner-browser/dist/target.d.ts +37 -0
  248. package/node_modules/@nordhavnhq/runner-browser/dist/target.js +82 -0
  249. package/node_modules/@nordhavnhq/runner-browser/dist/tour.d.ts +19 -0
  250. package/node_modules/@nordhavnhq/runner-browser/dist/tour.js +178 -0
  251. package/node_modules/@nordhavnhq/runner-browser/package.json +18 -0
  252. package/node_modules/@nordhavnhq/runner-runtime/dist/config.d.ts +96 -0
  253. package/node_modules/@nordhavnhq/runner-runtime/dist/config.js +25 -0
  254. package/node_modules/@nordhavnhq/runner-runtime/dist/connection.d.ts +276 -0
  255. package/node_modules/@nordhavnhq/runner-runtime/dist/connection.js +507 -0
  256. package/node_modules/@nordhavnhq/runner-runtime/dist/constants.d.ts +48 -0
  257. package/node_modules/@nordhavnhq/runner-runtime/dist/constants.js +95 -0
  258. package/node_modules/@nordhavnhq/runner-runtime/dist/contract/batch.d.ts +94 -0
  259. package/node_modules/@nordhavnhq/runner-runtime/dist/contract/batch.js +219 -0
  260. package/node_modules/@nordhavnhq/runner-runtime/dist/contract/calls.d.ts +136 -0
  261. package/node_modules/@nordhavnhq/runner-runtime/dist/contract/calls.js +214 -0
  262. package/node_modules/@nordhavnhq/runner-runtime/dist/contract/fs.d.ts +735 -0
  263. package/node_modules/@nordhavnhq/runner-runtime/dist/contract/fs.js +40 -0
  264. package/node_modules/@nordhavnhq/runner-runtime/dist/contract/loop.d.ts +362 -0
  265. package/node_modules/@nordhavnhq/runner-runtime/dist/contract/loop.js +703 -0
  266. package/node_modules/@nordhavnhq/runner-runtime/dist/contract/own-files.d.ts +105 -0
  267. package/node_modules/@nordhavnhq/runner-runtime/dist/contract/own-files.js +202 -0
  268. package/node_modules/@nordhavnhq/runner-runtime/dist/contract/phases.d.ts +204 -0
  269. package/node_modules/@nordhavnhq/runner-runtime/dist/contract/phases.js +497 -0
  270. package/node_modules/@nordhavnhq/runner-runtime/dist/contract/pins.d.ts +45 -0
  271. package/node_modules/@nordhavnhq/runner-runtime/dist/contract/pins.js +176 -0
  272. package/node_modules/@nordhavnhq/runner-runtime/dist/contract/processes.d.ts +74 -0
  273. package/node_modules/@nordhavnhq/runner-runtime/dist/contract/processes.js +72 -0
  274. package/node_modules/@nordhavnhq/runner-runtime/dist/contract/release-tag.d.ts +59 -0
  275. package/node_modules/@nordhavnhq/runner-runtime/dist/contract/release-tag.js +117 -0
  276. package/node_modules/@nordhavnhq/runner-runtime/dist/contract/replay.d.ts +62 -0
  277. package/node_modules/@nordhavnhq/runner-runtime/dist/contract/replay.js +84 -0
  278. package/node_modules/@nordhavnhq/runner-runtime/dist/contract/tool-names.d.ts +27 -0
  279. package/node_modules/@nordhavnhq/runner-runtime/dist/contract/tool-names.js +80 -0
  280. package/node_modules/@nordhavnhq/runner-runtime/dist/contract/version.d.ts +22 -0
  281. package/node_modules/@nordhavnhq/runner-runtime/dist/contract/version.js +22 -0
  282. package/node_modules/@nordhavnhq/runner-runtime/dist/contract/wire.d.ts +595 -0
  283. package/node_modules/@nordhavnhq/runner-runtime/dist/contract/wire.js +85 -0
  284. package/node_modules/@nordhavnhq/runner-runtime/dist/index.d.ts +43 -0
  285. package/node_modules/@nordhavnhq/runner-runtime/dist/index.js +50 -0
  286. package/node_modules/@nordhavnhq/runner-runtime/dist/inference.d.ts +135 -0
  287. package/node_modules/@nordhavnhq/runner-runtime/dist/inference.js +945 -0
  288. package/node_modules/@nordhavnhq/runner-runtime/dist/mcp.d.ts +67 -0
  289. package/node_modules/@nordhavnhq/runner-runtime/dist/mcp.js +47 -0
  290. package/node_modules/@nordhavnhq/runner-runtime/dist/platform.d.ts +21 -0
  291. package/node_modules/@nordhavnhq/runner-runtime/dist/platform.js +25 -0
  292. package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/auto-load.d.ts +39 -0
  293. package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/auto-load.js +67 -0
  294. package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/background-commands.d.ts +61 -0
  295. package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/background-commands.js +58 -0
  296. package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/chat-run-ends.d.ts +23 -0
  297. package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/chat-run-ends.js +42 -0
  298. package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/duration.d.ts +6 -0
  299. package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/duration.js +12 -0
  300. package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/events.d.ts +150 -0
  301. package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/events.js +36 -0
  302. package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/extract-json.d.ts +14 -0
  303. package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/extract-json.js +49 -0
  304. package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/handle-chat.d.ts +109 -0
  305. package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/handle-chat.js +894 -0
  306. package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/handle-task.d.ts +73 -0
  307. package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/handle-task.js +765 -0
  308. package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/loop.d.ts +246 -0
  309. package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/loop.js +621 -0
  310. package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/messages.d.ts +88 -0
  311. package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/messages.js +188 -0
  312. package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/pending-steers.d.ts +15 -0
  313. package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/pending-steers.js +10 -0
  314. package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/phased-loop.d.ts +16 -0
  315. package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/phased-loop.js +97 -0
  316. package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/project-instructions.d.ts +22 -0
  317. package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/project-instructions.js +47 -0
  318. package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/run-tools.d.ts +26 -0
  319. package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/run-tools.js +48 -0
  320. package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/scratch-prompt.d.ts +8 -0
  321. package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/scratch-prompt.js +19 -0
  322. package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/side-question.d.ts +76 -0
  323. package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/side-question.js +155 -0
  324. package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/task-validation.d.ts +43 -0
  325. package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/task-validation.js +37 -0
  326. package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/unload-toolset.d.ts +49 -0
  327. package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/unload-toolset.js +104 -0
  328. package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/write-scope.d.ts +16 -0
  329. package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/write-scope.js +6 -0
  330. package/node_modules/@nordhavnhq/runner-runtime/dist/tools/delegate.d.ts +86 -0
  331. package/node_modules/@nordhavnhq/runner-runtime/dist/tools/delegate.js +141 -0
  332. package/node_modules/@nordhavnhq/runner-runtime/dist/tools/index.d.ts +179 -0
  333. package/node_modules/@nordhavnhq/runner-runtime/dist/tools/index.js +35 -0
  334. package/node_modules/@nordhavnhq/runner-runtime/dist/tools/mcp.d.ts +21 -0
  335. package/node_modules/@nordhavnhq/runner-runtime/dist/tools/mcp.js +179 -0
  336. package/node_modules/@nordhavnhq/runner-runtime/package.json +18 -0
  337. package/package.json +33 -4
  338. package/README.md +0 -3
@@ -0,0 +1,408 @@
1
+ import { EventEmitter } from 'node:events';
2
+ import { randomUUID } from 'node:crypto';
3
+ import { PROCESS_OUTPUT_FRAME_MAX_CHARS, PROCESS_TAIL_MAX_CHARS, } from '@nordhavnhq/runner-runtime';
4
+ import { openPreviewTunnel } from './preview-tunnel.js';
5
+ export const processEvents = new EventEmitter();
6
+ // One set of listeners per agent of this runner (up.ts).
7
+ processEvents.setMaxListeners(0);
8
+ const tracked = new Map();
9
+ /**
10
+ * The background commands of each task dispatch (by queue uid), kept apart from
11
+ * `tracked` (which forgets ended processes) until the run collects them at its
12
+ * end (`waitForBackgroundCommands`). A chat is left out: it never collects.
13
+ */
14
+ const runBackground = new Map();
15
+ /** Runs that never collected (they crashed) are dropped, oldest first, past this many. */
16
+ const RUN_BACKGROUND_MAX_RUNS = 100;
17
+ /** An ended process stays this long, and at most this many, so a person can read why. */
18
+ const ENDED_KEEP_MS = 30 * 60_000;
19
+ const ENDED_KEEP_MAX = 20;
20
+ const OUTPUT_FLUSH_MS = 250;
21
+ const STOP_GRACE_MS = 5_000;
22
+ /** How often a process whose shell ended is checked for what it left running. */
23
+ const GROUP_POLL_MS = 1_000;
24
+ const PREVIEW_RETRY_MAX = 10;
25
+ const ANSI = /\x1b\[[0-9;?]*[ -/]*[@-~]|\x1b\][^\x07]*\x07/g;
26
+ const LOOPBACK = String.raw `(?:localhost|127\.0\.0\.1|0\.0\.0\.0|\[::1?\])`;
27
+ const IPV4_URL = String.raw `https?:\/\/(?:\d{1,3}\.){3}\d{1,3}`;
28
+ const PORT_PATTERNS = [
29
+ new RegExp(String.raw `\b${LOOPBACK}\s*:\s*(\d{2,5})\b`, 'i'),
30
+ new RegExp(String.raw `${IPV4_URL}:(\d{2,5})\b`, 'i'),
31
+ /\bport\s*[:=]?\s*(\d{2,5})\b/i,
32
+ ];
33
+ /** A local address with a port, or an IP one behind a scheme (a bare `10.0.0.5:5432` is a client's target). */
34
+ const SERVER_ADDRESS = new RegExp(String.raw `(?:\b${LOOPBACK}|${IPV4_URL})\s*:\s*(\d{2,5})\b`, 'i');
35
+ const SERVER_WORDS = /\b(?:local|network|listen(?:s|ing)?|running|started|serving|server|ready|available|open)\b/i;
36
+ /** How much of the tail is read again with each chunk: the chunk plus the line it ends. */
37
+ const PORT_SCAN_OVERLAP = 512;
38
+ const asPort = (value) => {
39
+ const port = Number(value);
40
+ return port >= 1 && port <= 65535 ? port : null;
41
+ };
42
+ /** The port a dev server says it listens on, from what it printed. Exported for tests. */
43
+ export function portFromOutput(output) {
44
+ const text = output.replace(ANSI, '');
45
+ for (const pattern of PORT_PATTERNS) {
46
+ const port = asPort(text.match(pattern)?.[1]);
47
+ if (port)
48
+ return port;
49
+ }
50
+ return null;
51
+ }
52
+ /**
53
+ * The port a background command announces it serves on: a line with a local
54
+ * (or `http://<ip>:`) address and a word that says it serves there (`Local:`,
55
+ * `listening`, `running on`, `Serving`). Stricter than `portFromOutput`, so a
56
+ * test suite or a build that mentions a port does not get a preview.
57
+ * Exported for tests.
58
+ */
59
+ export function serverPortFromOutput(output) {
60
+ for (const line of output.replace(ANSI, '').split('\n')) {
61
+ const port = asPort(line.match(SERVER_ADDRESS)?.[1]);
62
+ if (port && SERVER_WORDS.test(line))
63
+ return port;
64
+ }
65
+ return null;
66
+ }
67
+ const previewsWanted = () => !process.env.NORDHAVN_NO_PREVIEW;
68
+ /**
69
+ * Is anything left in the process group `pgid` leads? Every tracked command
70
+ * is spawned detached, so it leads its own group, and what it starts in the
71
+ * background (`server &`) stays in it after the command itself has ended.
72
+ * Exported for tests.
73
+ */
74
+ export function groupAlive(pgid) {
75
+ try {
76
+ process.kill(-pgid, 0);
77
+ return true;
78
+ }
79
+ catch (err) {
80
+ return err.code === 'EPERM';
81
+ }
82
+ }
83
+ /** Is this process of the agent `ctx` names? */
84
+ const ownedBy = (p, agentSlug, organisationSlug) => p.info.agentSlug === agentSlug && p.organisationSlug === organisationSlug;
85
+ function emitState(p) {
86
+ processEvents.emit('state', p.info, p.organisationSlug);
87
+ }
88
+ function flush(p) {
89
+ while (p.pending) {
90
+ const data = p.pending.slice(0, PROCESS_OUTPUT_FRAME_MAX_CHARS);
91
+ p.pending = p.pending.slice(data.length);
92
+ processEvents.emit('output', p.info, p.organisationSlug, data);
93
+ }
94
+ }
95
+ function prune() {
96
+ const ended = [...tracked.values()].filter(p => p.info.status === 'exited');
97
+ const now = Date.now();
98
+ ended.forEach((p, i) => {
99
+ const old = now - Date.parse(p.info.endedAt ?? p.info.startedAt) > ENDED_KEEP_MS;
100
+ if (old || ended.length - i > ENDED_KEEP_MAX)
101
+ tracked.delete(p.info.id);
102
+ });
103
+ }
104
+ /**
105
+ * Track a process `runner_run_command` started. Its stdout and stderr must be
106
+ * pipes: the output is read here (and handed on through `onOutput` to the
107
+ * caller that still waits on it).
108
+ */
109
+ export function trackProcess(child, opts) {
110
+ const id = opts.id ?? randomUUID();
111
+ let markEnded;
112
+ const p = {
113
+ info: {
114
+ id,
115
+ command: opts.command,
116
+ cwd: opts.cwd,
117
+ pid: child.pid ?? null,
118
+ kind: opts.kind,
119
+ status: 'running',
120
+ exitCode: null,
121
+ port: null,
122
+ startedAt: new Date().toISOString(),
123
+ endedAt: null,
124
+ agentSlug: opts.context?.agentSlug ?? '',
125
+ conversationUid: opts.context?.conversationId ?? null,
126
+ taskUid: opts.context?.taskUid ?? null,
127
+ ...(opts.startedBy ? { startedBy: opts.startedBy } : {}),
128
+ },
129
+ child,
130
+ tail: '',
131
+ pending: '',
132
+ organisationSlug: opts.context?.organisationSlug ?? null,
133
+ preview: null,
134
+ waiters: [],
135
+ retries: 0,
136
+ log: opts.log ?? null,
137
+ ended: new Promise((resolve) => { markEnded = resolve; }),
138
+ };
139
+ tracked.set(id, p);
140
+ prune();
141
+ rememberForRun(p, opts.context);
142
+ let timer = null;
143
+ const onData = (chunk) => {
144
+ const text = chunk.toString();
145
+ p.tail = (p.tail + text).slice(-PROCESS_TAIL_MAX_CHARS);
146
+ p.pending = (p.pending + text).slice(-PROCESS_TAIL_MAX_CHARS);
147
+ if (!p.info.port) {
148
+ const recent = p.tail.slice(-(text.length + PORT_SCAN_OVERLAP));
149
+ const port = p.info.kind === 'server' ? portFromOutput(recent) : serverPortFromOutput(recent);
150
+ if (port) {
151
+ p.info.port = port;
152
+ emitState(p);
153
+ if (previewsWanted() && port >= PREVIEW_PORT_MIN)
154
+ requestPreview(p);
155
+ }
156
+ }
157
+ timer ??= setTimeout(() => { timer = null; flush(p); }, OUTPUT_FLUSH_MS);
158
+ };
159
+ child.stdout?.on('data', onData);
160
+ child.stderr?.on('data', onData);
161
+ child.on('close', (code, signal) => {
162
+ if (timer) {
163
+ clearTimeout(timer);
164
+ timer = null;
165
+ }
166
+ flush(p);
167
+ const end = () => {
168
+ p.info.status = 'exited';
169
+ p.info.exitCode = code ?? (signal ? 128 : 1);
170
+ p.info.endedAt = new Date().toISOString();
171
+ closePreview(p);
172
+ settleWaiters(p, null);
173
+ emitState(p);
174
+ markEnded();
175
+ };
176
+ const pid = child.pid;
177
+ if (!pid || !groupAlive(pid))
178
+ return end();
179
+ // The shell ended but what it started in the background still runs: it
180
+ // stays running (its preview, and a person can stop it) until its group is empty.
181
+ const poll = setInterval(() => {
182
+ if (groupAlive(pid))
183
+ return;
184
+ clearInterval(poll);
185
+ end();
186
+ }, GROUP_POLL_MS);
187
+ poll.unref();
188
+ });
189
+ emitState(p);
190
+ return id;
191
+ }
192
+ /** Keep a background command of a task dispatch for the end of that run. */
193
+ function rememberForRun(p, context) {
194
+ const queueUid = context?.queueUid;
195
+ if (p.info.kind !== 'background' || !queueUid || context?.userPresent)
196
+ return;
197
+ const list = runBackground.get(queueUid) ?? [];
198
+ list.push(p);
199
+ runBackground.set(queueUid, list);
200
+ while (runBackground.size > RUN_BACKGROUND_MAX_RUNS) {
201
+ const oldest = runBackground.keys().next().value;
202
+ if (oldest === undefined)
203
+ break;
204
+ runBackground.delete(oldest);
205
+ }
206
+ }
207
+ const outcomeOf = (p) => ({
208
+ command: p.info.command,
209
+ status: p.info.status,
210
+ exitCode: p.info.exitCode,
211
+ log: p.log,
212
+ });
213
+ /** Settles when every promise has, the time is up or the signal fires, whichever comes first. */
214
+ function settleWithin(ends, timeoutMs, signal) {
215
+ return new Promise((resolve) => {
216
+ const done = () => {
217
+ clearTimeout(timer);
218
+ signal?.removeEventListener('abort', done);
219
+ resolve();
220
+ };
221
+ const timer = setTimeout(done, timeoutMs);
222
+ signal?.addEventListener('abort', done, { once: true });
223
+ void Promise.all(ends).then(done);
224
+ });
225
+ }
226
+ /**
227
+ * The end of a task run (`HandleTaskDeps.waitForBackgroundCommands`): wait for
228
+ * the background commands dispatch `queueUid` started, within `timeoutMs`, and
229
+ * say how each stands. Dev servers are never waited for, nothing is stopped,
230
+ * and the run's list is forgotten once collected.
231
+ */
232
+ export async function waitForBackgroundCommands(queueUid, opts) {
233
+ const mine = runBackground.get(queueUid) ?? [];
234
+ runBackground.delete(queueUid);
235
+ const running = mine.filter(p => p.info.status === 'running');
236
+ const startedAt = Date.now();
237
+ if (running.length > 0 && opts.timeoutMs > 0 && !opts.signal?.aborted) {
238
+ opts.onWait?.(running.map(outcomeOf));
239
+ await settleWithin(running.map(p => p.ended), opts.timeoutMs, opts.signal);
240
+ }
241
+ return { commands: mine.map(outcomeOf), waitedMs: Date.now() - startedAt };
242
+ }
243
+ /** Every process of one agent, with the end of its output: what `proc:sync` sends. */
244
+ export function listProcesses(agentSlug, organisationSlug) {
245
+ prune();
246
+ return [...tracked.values()]
247
+ .filter(p => ownedBy(p, agentSlug, organisationSlug))
248
+ .map(p => ({ ...p.info, tail: p.tail }));
249
+ }
250
+ /** End a process and everything it started (its group), harder after a grace. */
251
+ export function stopProcess(id, agentSlug, organisationSlug) {
252
+ const p = tracked.get(id);
253
+ if (!p || !ownedBy(p, agentSlug, organisationSlug) || p.info.status !== 'running' || !p.child.pid)
254
+ return false;
255
+ const pid = p.child.pid;
256
+ const kill = (signal) => {
257
+ try {
258
+ process.kill(-pid, signal);
259
+ }
260
+ catch {
261
+ try {
262
+ p.child.kill(signal);
263
+ }
264
+ catch { /* gone */ }
265
+ }
266
+ };
267
+ kill('SIGTERM');
268
+ setTimeout(() => { if (p.info.status === 'running')
269
+ kill('SIGKILL'); }, STOP_GRACE_MS).unref();
270
+ return true;
271
+ }
272
+ // ─── Previews ────────────────────────────────────────────────────
273
+ const requests = new Map();
274
+ function requestPreview(p) {
275
+ if (p.info.status !== 'running' || p.preview?.closed)
276
+ return;
277
+ const requestId = randomUUID();
278
+ requests.set(requestId, p.info.id);
279
+ processEvents.emit('preview-request', p.info, p.organisationSlug, requestId, p.preview?.name);
280
+ }
281
+ function settleWaiters(p, url) {
282
+ for (const resolve of p.waiters.splice(0))
283
+ resolve(url);
284
+ }
285
+ function closePreview(p) {
286
+ if (!p.preview)
287
+ return;
288
+ p.preview.closed = true;
289
+ p.preview.tunnel?.close();
290
+ p.preview.tunnel = null;
291
+ }
292
+ function retryPreview(p) {
293
+ if (p.info.status !== 'running' || p.preview?.closed || p.retries >= PREVIEW_RETRY_MAX)
294
+ return;
295
+ const delay = Math.min(30_000, 2_000 * 2 ** p.retries++);
296
+ setTimeout(() => requestPreview(p), delay).unref();
297
+ }
298
+ /**
299
+ * Wait for the preview of a process: its address once the tunnel is up, or
300
+ * null when there is none within `timeoutMs` (no port, refused, previews off).
301
+ */
302
+ export function waitForPreview(id, timeoutMs) {
303
+ const p = tracked.get(id);
304
+ if (!p || p.info.status !== 'running' || !p.info.port)
305
+ return Promise.resolve(null);
306
+ if (p.preview?.tunnel)
307
+ return Promise.resolve(p.preview.url);
308
+ return new Promise((resolve) => {
309
+ const timer = setTimeout(() => {
310
+ p.waiters = p.waiters.filter(w => w !== done);
311
+ resolve(null);
312
+ }, timeoutMs);
313
+ const done = (url) => { clearTimeout(timer); resolve(url); };
314
+ p.waiters.push(done);
315
+ });
316
+ }
317
+ /** Below this a port belongs to a system service, never to a dev server an agent started. */
318
+ const PREVIEW_PORT_MIN = 1024;
319
+ /**
320
+ * The port a preview of `p` may tunnel to: only the one this runner read from
321
+ * the output of a process it started itself, and only an unprivileged one.
322
+ * The port in the studio's frame must match it; whatever else the frame names
323
+ * (another local service, the studio's own database) is refused. Exported for tests.
324
+ */
325
+ function previewPortFor(p, requested) {
326
+ const port = p.info.port;
327
+ if (!port || port !== requested)
328
+ return null;
329
+ if (!Number.isInteger(port) || port < PREVIEW_PORT_MIN || port > 65535)
330
+ return null;
331
+ return port;
332
+ }
333
+ /** The studio opened a preview (ours, or one a person asked for): hold its tunnel. */
334
+ export function onPreviewOpen(frame, studioUrl, agentSlug, organisationSlug) {
335
+ if (frame.requestId)
336
+ requests.delete(frame.requestId);
337
+ const p = tracked.get(frame.processId);
338
+ if (!p || !ownedBy(p, agentSlug, organisationSlug) || p.info.status !== 'running')
339
+ return;
340
+ const port = previewPortFor(p, frame.port);
341
+ if (port === null) {
342
+ console.warn(`[preview] refused a tunnel to port ${frame.port} for process ${p.info.id}: it listens on ${p.info.port ?? 'no port'} as far as this runner read`);
343
+ settleWaiters(p, null);
344
+ return;
345
+ }
346
+ if (p.preview?.id === frame.previewId && p.preview.tunnel) {
347
+ settleWaiters(p, p.preview.url);
348
+ return;
349
+ }
350
+ p.preview?.tunnel?.close();
351
+ const name = new URL(frame.url).hostname.split('.')[0] ?? '';
352
+ const preview = { id: frame.previewId, name, url: frame.url, tunnel: null, closed: false };
353
+ p.preview = preview;
354
+ preview.tunnel = openPreviewTunnel({
355
+ url: `${studioUrl.replace(/^http/, 'ws')}/_ws/preview?id=${encodeURIComponent(frame.previewId)}&key=${encodeURIComponent(frame.key)}`,
356
+ port,
357
+ onReady: () => {
358
+ p.retries = 0;
359
+ settleWaiters(p, preview.url);
360
+ },
361
+ onClose: (code) => {
362
+ if (p.preview !== preview)
363
+ return;
364
+ preview.tunnel = null;
365
+ // 4000: the studio closed it on purpose. Anything else (a restart, the
366
+ // network) is asked for again, under the same name.
367
+ if (code === 4000)
368
+ preview.closed = true;
369
+ else
370
+ retryPreview(p);
371
+ },
372
+ });
373
+ }
374
+ /** The studio closed a preview: drop its tunnel for good. */
375
+ export function onPreviewClose(previewId) {
376
+ for (const p of tracked.values()) {
377
+ if (p.preview?.id === previewId)
378
+ closePreview(p);
379
+ }
380
+ }
381
+ /** No preview for our request: whoever waits hears none, a dropped one tries again later. */
382
+ export function onPreviewRefused(requestId) {
383
+ const id = requests.get(requestId);
384
+ requests.delete(requestId);
385
+ const p = id ? tracked.get(id) : undefined;
386
+ if (!p)
387
+ return;
388
+ settleWaiters(p, null);
389
+ if (p.preview)
390
+ retryPreview(p);
391
+ }
392
+ /** Every process still running is stopped with the runner. */
393
+ export function stopAllProcesses() {
394
+ for (const p of tracked.values()) {
395
+ closePreview(p);
396
+ if (p.info.status === 'running' && p.child.pid) {
397
+ try {
398
+ process.kill(-p.child.pid, 'SIGTERM');
399
+ }
400
+ catch {
401
+ try {
402
+ p.child.kill('SIGKILL');
403
+ }
404
+ catch { /* gone */ }
405
+ }
406
+ }
407
+ }
408
+ }
@@ -0,0 +1,17 @@
1
+ export interface NodeTarget {
2
+ platform: NodeJS.Platform;
3
+ arch: string;
4
+ }
5
+ /** Installs the newest release that satisfies `spec` into `cacheDir`; resolves its exact version. */
6
+ export type NodeDownloader = (spec: string, cacheDir: string, target: NodeTarget) => Promise<string>;
7
+ /** The name of the official build for a version and machine: `node-v26.13.0-darwin-arm64`. */
8
+ export declare function nodeDistName(version: string, target: NodeTarget): string;
9
+ /** The sha256 of `file` in a SHASUMS256.txt, or null when it is not listed. */
10
+ export declare function shasumFor(shasums: string, file: string): string | null;
11
+ /**
12
+ * The default downloader: resolves a partial spec against nodejs.org's index,
13
+ * then fetches the build unless the cache has it (another run may have got
14
+ * there while this one waited for the lock).
15
+ */
16
+ export declare function createNodeDownloader(fetchImpl?: typeof fetch): NodeDownloader;
17
+ export declare const downloadNode: NodeDownloader;
@@ -0,0 +1,137 @@
1
+ import { execFile } from 'node:child_process';
2
+ import { createHash } from 'node:crypto';
3
+ import { existsSync, mkdirSync, mkdtempSync, renameSync, rmSync, writeFileSync } from 'node:fs';
4
+ import { join } from 'node:path';
5
+ import { acquireLock } from '../update/install.js';
6
+ import { isExactVersion, pickHighest } from './node-version.js';
7
+ // ─── Downloading a project's Node ───────────
8
+ //
9
+ // The official build from nodejs.org, checked against the release's
10
+ // SHASUMS256.txt and unpacked into the runner's cache as `<cache>/v<x>`. One
11
+ // download per version at a time on this machine (a lock file next to it):
12
+ // two runs that need the same node wait for the first.
13
+ const NODE_DIST_URL = 'https://nodejs.org/dist';
14
+ const LOCK_STALE_MS = 20 * 60_000;
15
+ const LOCK_WAIT_MS = 10 * 60_000;
16
+ const TEXT_TIMEOUT_MS = 30_000;
17
+ const TARBALL_TIMEOUT_MS = 10 * 60_000;
18
+ const ARCHES = { x64: 'x64', arm64: 'arm64', arm: 'armv7l', ppc64: 'ppc64le', s390x: 's390x' };
19
+ /** The name of the official build for a version and machine: `node-v26.13.0-darwin-arm64`. */
20
+ export function nodeDistName(version, target) {
21
+ if (target.platform !== 'darwin' && target.platform !== 'linux') {
22
+ throw new Error(`no automatic Node download for ${target.platform} (install it with a version manager)`);
23
+ }
24
+ const arch = ARCHES[target.arch];
25
+ if (!arch)
26
+ throw new Error(`no official Node build for ${target.platform}-${target.arch}`);
27
+ return `node-v${version}-${target.platform}-${arch}`;
28
+ }
29
+ /** The sha256 of `file` in a SHASUMS256.txt, or null when it is not listed. */
30
+ export function shasumFor(shasums, file) {
31
+ for (const line of shasums.split('\n')) {
32
+ const [hash, name] = line.trim().split(/\s+/);
33
+ if (name === file && hash)
34
+ return hash.toLowerCase();
35
+ }
36
+ return null;
37
+ }
38
+ async function fetchOk(fetchImpl, url, timeoutMs) {
39
+ let res;
40
+ try {
41
+ res = await fetchImpl(url, { signal: AbortSignal.timeout(timeoutMs) });
42
+ }
43
+ catch (err) {
44
+ const cause = err.cause?.code;
45
+ throw new Error(`download failed (${cause ?? err.message}): ${url}`, { cause: err });
46
+ }
47
+ if (res.status === 404)
48
+ throw new Error(`not on nodejs.org: ${url}`);
49
+ if (!res.ok)
50
+ throw new Error(`download failed (HTTP ${res.status}): ${url}`);
51
+ return res;
52
+ }
53
+ /** The newest released version that satisfies a partial spec (`26`, `26.13`). */
54
+ async function latestRelease(spec, fetchImpl) {
55
+ const res = await fetchOk(fetchImpl, `${NODE_DIST_URL}/index.json`, TEXT_TIMEOUT_MS);
56
+ const releases = await res.json();
57
+ const best = pickHighest(releases.map(r => r.version ?? ''), spec);
58
+ if (!best)
59
+ throw new Error(`no Node release matches ${spec}`);
60
+ return best;
61
+ }
62
+ async function waitForLock(path) {
63
+ const deadline = Date.now() + LOCK_WAIT_MS;
64
+ for (;;) {
65
+ const release = acquireLock(path, LOCK_STALE_MS);
66
+ if (release)
67
+ return release;
68
+ if (Date.now() >= deadline)
69
+ return null;
70
+ await new Promise(done => setTimeout(done, 1_000));
71
+ }
72
+ }
73
+ function untar(tarball, into) {
74
+ return new Promise((done, fail) => {
75
+ execFile('tar', ['-xzf', tarball, '-C', into], { timeout: 5 * 60_000 }, (err, _out, stderr) => {
76
+ if (err)
77
+ fail(new Error(`unpacking failed: ${stderr.trim() || err.message}`));
78
+ else
79
+ done();
80
+ });
81
+ });
82
+ }
83
+ /** Fetches, verifies and unpacks one exact version into `dest`. */
84
+ async function installVersion(version, cacheDir, dest, target, fetchImpl) {
85
+ const name = nodeDistName(version, target);
86
+ const file = `${name}.tar.gz`;
87
+ const sums = await (await fetchOk(fetchImpl, `${NODE_DIST_URL}/v${version}/SHASUMS256.txt`, TEXT_TIMEOUT_MS)).text();
88
+ const expected = shasumFor(sums, file);
89
+ if (!expected)
90
+ throw new Error(`${file} is not in the SHASUMS256.txt of v${version}`);
91
+ const data = Buffer.from(await (await fetchOk(fetchImpl, `${NODE_DIST_URL}/v${version}/${file}`, TARBALL_TIMEOUT_MS)).arrayBuffer());
92
+ const actual = createHash('sha256').update(data).digest('hex');
93
+ if (actual !== expected)
94
+ throw new Error(`checksum mismatch for ${file}`);
95
+ const work = mkdtempSync(join(cacheDir, '.download-'));
96
+ try {
97
+ const tarball = join(work, file);
98
+ writeFileSync(tarball, data);
99
+ await untar(tarball, work);
100
+ if (!existsSync(join(work, name, 'bin', 'node')))
101
+ throw new Error(`${file} holds no ${name}/bin/node`);
102
+ // A half-unpacked leftover of a crashed run is in the way of the rename.
103
+ rmSync(dest, { recursive: true, force: true });
104
+ renameSync(join(work, name), dest);
105
+ }
106
+ finally {
107
+ rmSync(work, { recursive: true, force: true });
108
+ }
109
+ }
110
+ /**
111
+ * The default downloader: resolves a partial spec against nodejs.org's index,
112
+ * then fetches the build unless the cache has it (another run may have got
113
+ * there while this one waited for the lock).
114
+ */
115
+ export function createNodeDownloader(fetchImpl = fetch) {
116
+ return async (spec, cacheDir, target) => {
117
+ if (target.platform === 'win32')
118
+ throw new Error('no automatic Node download on Windows (install it with nvm-windows)');
119
+ const version = isExactVersion(spec) ? spec : await latestRelease(spec, fetchImpl);
120
+ const dest = join(cacheDir, `v${version}`);
121
+ if (existsSync(join(dest, 'bin', 'node')))
122
+ return version;
123
+ mkdirSync(cacheDir, { recursive: true });
124
+ const release = await waitForLock(join(cacheDir, `v${version}.lock`));
125
+ if (!release)
126
+ throw new Error(`another download of v${version} still holds the lock`);
127
+ try {
128
+ if (!existsSync(join(dest, 'bin', 'node')))
129
+ await installVersion(version, cacheDir, dest, target, fetchImpl);
130
+ return version;
131
+ }
132
+ finally {
133
+ release();
134
+ }
135
+ };
136
+ }
137
+ export const downloadNode = (spec, cacheDir, target) => createNodeDownloader()(spec, cacheDir, target);
@@ -0,0 +1,65 @@
1
+ import { type NodeDownloader } from './project-node-download.js';
2
+ export interface NodePin {
3
+ /** The version as pinned, without a leading `v`: `26.13.0`, `26.13` or `26`. */
4
+ spec: string;
5
+ /** Absolute path of the file that pins it. */
6
+ file: string;
7
+ }
8
+ export interface ProjectNode {
9
+ pin: NodePin;
10
+ /** The file, relative to the project base, for messages. */
11
+ pinFile: string;
12
+ /** Bin dir of the resolved node, null when it could not be had. */
13
+ binDir: string | null;
14
+ /** The exact version found, null when none. */
15
+ version: string | null;
16
+ /** Why there is no bin dir. */
17
+ reason?: string;
18
+ }
19
+ /**
20
+ * The nearest version file from `cwd` up to `base` (never above it, never
21
+ * outside it). In one folder `.node-version` comes before `.nvmrc`; a folder
22
+ * whose files hold only aliases ends the search without a pin.
23
+ */
24
+ export declare function findNodePin(cwd: string, base: string): NodePin | null;
25
+ export interface NodeLookupOptions {
26
+ /** The real user's home (not the agent's). */
27
+ home?: string;
28
+ /** The runner's environment, for NVM_DIR, VOLTA_HOME and friends. */
29
+ env?: NodeJS.ProcessEnv;
30
+ platform?: NodeJS.Platform;
31
+ /** The runner's own cache of downloaded nodes. */
32
+ cacheDir?: string;
33
+ }
34
+ /**
35
+ * An installed node that satisfies `spec`: the highest match over all stores,
36
+ * so `26` takes the newest 26 the machine has. Only a folder with a node
37
+ * binary in its bin dir counts.
38
+ */
39
+ export declare function findInstalledNode(spec: string, opts?: NodeLookupOptions): {
40
+ version: string;
41
+ binDir: string;
42
+ } | null;
43
+ /**
44
+ * The child environment with `binDir` first on PATH. nvm's NVM_BIN, when it
45
+ * names another node, leaves PATH and the environment, so `npm` and `npx`
46
+ * follow the pinned node instead of the one the runner was started with.
47
+ */
48
+ export declare function withNodeBin(env: NodeJS.ProcessEnv, binDir: string): NodeJS.ProcessEnv;
49
+ export interface ResolveProjectNodeOptions extends NodeLookupOptions {
50
+ download?: NodeDownloader;
51
+ /** Node version on the runner's own PATH, for the fallback note. */
52
+ fallbackVersion?: () => Promise<string>;
53
+ }
54
+ /** Forgets every resolution (tests). */
55
+ export declare function resetProjectNodeCache(): void;
56
+ /**
57
+ * The node a command in `cwd` should run on: null when the project pins none
58
+ * (or the feature is off). Resolved once per (base, pinned version) and kept
59
+ * in memory; a missing version is downloaded into the runner's cache.
60
+ */
61
+ export declare function resolveProjectNode(cwd: string, base: string, opts?: ResolveProjectNodeOptions): Promise<ProjectNode | null>;
62
+ /** The line a tool result carries when the pinned node could not be had. */
63
+ export declare function projectNodeNote(node: ProjectNode | null, opts?: ResolveProjectNodeOptions): Promise<string | null>;
64
+ /** A short label for a result when the pinned node is in use. */
65
+ export declare function projectNodeLabel(node: ProjectNode | null): string | null;