@nordhavnhq/runner 0.0.0-stage → 0.96.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 +39 -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 +20 -0
  13. package/dist/cli/link.js +312 -0
  14. package/dist/cli/logs.d.ts +2 -0
  15. package/dist/cli/logs.js +144 -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 +80 -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 +135 -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 +1324 -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,2 @@
1
+ #!/usr/bin/env node
2
+ import './legacy-env.js';
package/dist/index.js ADDED
@@ -0,0 +1,135 @@
1
+ #!/usr/bin/env node
2
+ // First: maps pre-rename env names (JUSTMADE_*, HAVEN_*) before anything reads them.
3
+ import './legacy-env.js';
4
+ import { dim, bold, cyan, red, accent, logo, stripAnsi, VERSION } from './utils/format.js';
5
+ import { init } from './cli/init.js';
6
+ import { link, unlink } from './cli/link.js';
7
+ import { removedAgentCommand, show } from './cli/agent.js';
8
+ import { folderCommand } from './cli/folder.js';
9
+ import { up } from './runtime/up.js';
10
+ import { ps } from './cli/ps.js';
11
+ import { down, restart } from './cli/lifecycle.js';
12
+ import { logs } from './cli/logs.js';
13
+ import { relay } from './cli/relay.js';
14
+ import { update } from './cli/update.js';
15
+ import { migrateLegacyDir } from './paths.js';
16
+ // Before anything reads config: move a pre-rename ~/.justmade-studio (or
17
+ // ~/.studiolayer) dir into place, so an existing machine keeps its pairing
18
+ // across the update.
19
+ migrateLegacyDir();
20
+ const args = process.argv.slice(2);
21
+ const command = args[0] ?? '';
22
+ let resolvedCommand = command;
23
+ let cmdArgs = args.slice(1);
24
+ // `nordhavn agent` shows the runner's agent; `agent ls` is the old spelling.
25
+ if (command === 'agent' && args[1] && args[1] !== '-h' && args[1] !== '--help') {
26
+ resolvedCommand = `agent:${args[1]}`;
27
+ cmdArgs = args.slice(2);
28
+ }
29
+ if (command === 'folder' && args[1]) {
30
+ if (args[1] === '-h' || args[1] === '--help') {
31
+ resolvedCommand = 'folder:help';
32
+ cmdArgs = [];
33
+ }
34
+ else {
35
+ resolvedCommand = `folder:${args[1]}`;
36
+ cmdArgs = args.slice(2);
37
+ }
38
+ }
39
+ const aliases = {
40
+ add: 'agent:add',
41
+ remove: 'agent:remove',
42
+ ls: 'agent',
43
+ list: 'agent',
44
+ 'agent:ls': 'agent',
45
+ 'agent:list': 'agent',
46
+ '-h': 'help',
47
+ '--help': 'help',
48
+ '--version': 'version',
49
+ '-V': 'version',
50
+ };
51
+ const alias = aliases[resolvedCommand];
52
+ if (alias)
53
+ resolvedCommand = alias;
54
+ const FLAG_TOKENS = new Set(['--debug', '-v', '--detach', '-d', '--once', '-h', '--help', '--check', '--force']);
55
+ const positionalArgs = cmdArgs.filter(a => !FLAG_TOKENS.has(a));
56
+ const subarg = positionalArgs[0];
57
+ const ctx = { subarg, cmdArgs, resolvedCommand };
58
+ const wantsHelpFlag = (c) => c.cmdArgs.includes('-h') || c.cmdArgs.includes('--help') || c.subarg === '-h' || c.subarg === '--help';
59
+ const wantsDebug = (c) => c.cmdArgs.includes('--debug') || c.cmdArgs.includes('-v');
60
+ const wantsDetach = (c) => c.cmdArgs.includes('--detach') || c.cmdArgs.includes('-d');
61
+ const commands = {
62
+ init,
63
+ link,
64
+ unlink,
65
+ agent: show,
66
+ 'agent:add': removedAgentCommand,
67
+ 'agent:remove': removedAgentCommand,
68
+ 'agent:relink': removedAgentCommand,
69
+ folder: folderCommand,
70
+ 'folder:add': folderCommand,
71
+ 'folder:rm': folderCommand,
72
+ 'folder:ls': folderCommand,
73
+ 'folder:help': folderCommand,
74
+ up: (c) => up({ ref: c.subarg, wantsHelp: wantsHelpFlag(c), debug: wantsDebug(c), detach: wantsDetach(c) }),
75
+ ps,
76
+ down,
77
+ restart,
78
+ logs,
79
+ relay,
80
+ update,
81
+ version: async () => { console.log(VERSION); },
82
+ };
83
+ const handler = commands[resolvedCommand];
84
+ if (!handler) {
85
+ printRootHelp();
86
+ process.exit(0);
87
+ }
88
+ handler(ctx).catch((err) => {
89
+ console.error(red(` Fatal: ${err.message}`));
90
+ process.exit(1);
91
+ });
92
+ function printRootHelp() {
93
+ logo();
94
+ // Data-driven so every description lines up in one column across all sections,
95
+ // and section rules share one width - no hand-counted dashes or per-section
96
+ // padding to drift out of sync.
97
+ const sections = [
98
+ { title: 'Runtime', rows: [
99
+ [cyan('up'), 'Bring the agent online (foreground)'],
100
+ [cyan('up -d'), 'Bring the agent online in the background'],
101
+ [cyan('down'), 'Take the agent offline'],
102
+ [cyan('ps'), 'Show the agent\'s status'],
103
+ [cyan('logs'), 'Tail the agent\'s log live (--once to dump)'],
104
+ [cyan('restart'), 'Restart the agent in the background'],
105
+ [`${cyan('relay')} ${dim('[off]')}`, 'Git relay: push for you from here (off disconnects)'],
106
+ ] },
107
+ { title: 'Setup', rows: [
108
+ [cyan('init'), 'Configure this runner (studio URL + home)'],
109
+ [`${cyan('link')} ${dim('<code>')}`, 'Pair this runner with an agent (replaces the current one)'],
110
+ [cyan('unlink'), 'Remove the pairing and its agent'],
111
+ [cyan('agent'), 'Show the agent of this runner'],
112
+ [`${cyan('update')} ${dim('[--check]')}`, 'Install the latest runner release'],
113
+ [cyan('--version'), 'Print the installed version'],
114
+ ] },
115
+ { title: 'Folders', rows: [
116
+ [cyan('folder ls'), 'List folders and the projects they expose'],
117
+ [`${cyan('folder add')} ${dim('<path>')}`, 'Let the runner open projects from a folder'],
118
+ [`${cyan('folder rm')} ${dim('<path>')}`, 'Stop opening projects from a folder'],
119
+ ] },
120
+ ];
121
+ const RULE_WIDTH = 40;
122
+ const col = Math.max(...sections.flatMap(s => s.rows.map(([cmd]) => stripAnsi(cmd).length))) + 3;
123
+ console.log(bold(' Usage:') + ' ' + dim('nordhavn') + ' ' + cyan('<command>') + '\n');
124
+ for (const section of sections) {
125
+ const dashes = Math.max(3, RULE_WIDTH - section.title.length - 1);
126
+ console.log(accent(` ─── ${section.title} ${'─'.repeat(dashes)}`));
127
+ for (const [cmd, desc] of section.rows) {
128
+ const pad = col - stripAnsi(cmd).length;
129
+ console.log(` ${cmd}${' '.repeat(pad)}${dim(desc)}`);
130
+ }
131
+ console.log('');
132
+ }
133
+ console.log(dim(' One runner hosts one agent. Another agent on this machine gets its own profile:'));
134
+ console.log(dim(` ${cyan('NORDHAVN_PROFILE=<name> nordhavn init')}, then ${cyan('nordhavn link <code>')}.`) + '\n');
135
+ }
@@ -0,0 +1,4 @@
1
+ /** The current name of a pre-rename variable, or null when it is not one. */
2
+ export declare function renamedEnvName(name: string): string | null;
3
+ /** Copies every pre-rename variable onto its new name, unless that is set. */
4
+ export declare function applyLegacyEnv(env?: NodeJS.ProcessEnv): void;
@@ -0,0 +1,32 @@
1
+ // Environment variables from before the rename to Nordhavn OS.
2
+ //
3
+ // `JUSTMADE_STUDIO_*`, `JUSTMADE_*` and `HAVEN_*` are now `NORDHAVN_OS_*` and
4
+ // `NORDHAVN_*`. A machine that still exports an old name (a shell profile, a
5
+ // service definition, a CI job) keeps working: the old value is copied onto
6
+ // the new name when that one is not set. Imported first in `index.ts`, so it
7
+ // runs before any module reads the environment. Safe to delete once no
8
+ // installation sets the old names.
9
+ const RENAMES = [
10
+ ['JUSTMADE_STUDIO_', 'NORDHAVN_OS_'],
11
+ ['JUSTMADE_', 'NORDHAVN_'],
12
+ ['HAVEN_', 'NORDHAVN_'],
13
+ ];
14
+ /** The current name of a pre-rename variable, or null when it is not one. */
15
+ export function renamedEnvName(name) {
16
+ for (const [from, to] of RENAMES) {
17
+ if (name.startsWith(from))
18
+ return to + name.slice(from.length);
19
+ }
20
+ return null;
21
+ }
22
+ /** Copies every pre-rename variable onto its new name, unless that is set. */
23
+ export function applyLegacyEnv(env = process.env) {
24
+ for (const [name, value] of Object.entries(env)) {
25
+ if (value === undefined)
26
+ continue;
27
+ const next = renamedEnvName(name);
28
+ if (next && env[next] === undefined)
29
+ env[next] = value;
30
+ }
31
+ }
32
+ applyLegacyEnv();
@@ -0,0 +1,37 @@
1
+ /** True for the production profile, which uses the plain ~/.nordhavn-os dir. */
2
+ export declare function isDefaultProfile(): boolean;
3
+ /**
4
+ * Per-profile base directory. Production lives at ~/.nordhavn-os; every other
5
+ * profile lives under ~/.nordhavn-os-<profile> and never shares config,
6
+ * pairing, status, or logs with production.
7
+ *
8
+ * `.nordhavn-os` rather than the shorter `.nordhavn` on purpose: a
9
+ * predecessor of this runner already used `~/.nordhavn`, and machines that ran
10
+ * it still have that directory with its own config.json. Landing on the same
11
+ * path would make `migrateLegacyDir` skip (the target exists) and then load a
12
+ * stale, incompatible config instead of the real one.
13
+ */
14
+ export declare function nordhavnDir(): string;
15
+ /** Display label for the active profile, or '' for production. */
16
+ export declare function profileLabel(): string;
17
+ /**
18
+ * Where this profile's config lived before the rename to Nordhavn OS, newest
19
+ * name first: `~/.justmade-studio` (Justmade Studio), then `~/.studiolayer`.
20
+ */
21
+ export declare function legacyDirs(): string[];
22
+ /**
23
+ * One-time move of a pre-rename config directory into place.
24
+ *
25
+ * The runner used to live at `~/.justmade-studio` and before that at
26
+ * `~/.studiolayer` (each with a `-<profile>` variant). That directory holds the
27
+ * host pairing token, every agent's connection token and the agent homes, so
28
+ * leaving it behind would silently un-pair every machine that updates.
29
+ * Renamed once, on the first run that finds an old directory and no new one;
30
+ * the newest old name wins.
31
+ *
32
+ * Deliberately narrow: it never merges, never overwrites, and never touches
33
+ * anything once the new directory exists. Safe to delete this function,
34
+ * `legacyDirs`, its call in `index.ts` and the `home` re-rooting in `config.ts`
35
+ * once no installation is on an old layout.
36
+ */
37
+ export declare function migrateLegacyDir(): void;
package/dist/paths.js ADDED
@@ -0,0 +1,92 @@
1
+ import { existsSync, renameSync } from 'node:fs';
2
+ import { homedir } from 'node:os';
3
+ import { join } from 'node:path';
4
+ // ─── Environment profiles ────────────────────
5
+ //
6
+ // Which studio environment this runner process is bound to, selected once at
7
+ // process start from the NORDHAVN_PROFILE env var. This lets a single
8
+ // machine run a dev runner against a local studio AND the published
9
+ // `nordhavn` binary against production at the same time, each fully isolated
10
+ // - its own config, host pairing, agents, status files, and logs.
11
+ //
12
+ // npm run dev -> sets NORDHAVN_PROFILE=dev -> ~/.nordhavn-os-dev
13
+ // nordhavn -> unset / production -> ~/.nordhavn-os
14
+ //
15
+ // A profile is just a directory namespace; nothing about the wire protocol or
16
+ // tooling differs between them. The studio URL each profile talks to is stored
17
+ // in that profile's own config.json (set during `init`).
18
+ /**
19
+ * The active profile slug. Unset / "default" / "prod" / "production" all map to
20
+ * the canonical production profile (`default`). Any other value is sanitised to
21
+ * `[a-z0-9_-]` and used as its own namespace.
22
+ */
23
+ function activeProfile() {
24
+ const raw = (process.env.NORDHAVN_PROFILE || '').trim().toLowerCase();
25
+ if (!raw || raw === 'default' || raw === 'prod' || raw === 'production')
26
+ return 'default';
27
+ return raw.replace(/[^a-z0-9_-]/g, '') || 'default';
28
+ }
29
+ /** True for the production profile, which uses the plain ~/.nordhavn-os dir. */
30
+ export function isDefaultProfile() {
31
+ return activeProfile() === 'default';
32
+ }
33
+ /**
34
+ * Per-profile base directory. Production lives at ~/.nordhavn-os; every other
35
+ * profile lives under ~/.nordhavn-os-<profile> and never shares config,
36
+ * pairing, status, or logs with production.
37
+ *
38
+ * `.nordhavn-os` rather than the shorter `.nordhavn` on purpose: a
39
+ * predecessor of this runner already used `~/.nordhavn`, and machines that ran
40
+ * it still have that directory with its own config.json. Landing on the same
41
+ * path would make `migrateLegacyDir` skip (the target exists) and then load a
42
+ * stale, incompatible config instead of the real one.
43
+ */
44
+ export function nordhavnDir() {
45
+ const profile = activeProfile();
46
+ return profile === 'default' ? join(homedir(), '.nordhavn-os') : join(homedir(), `.nordhavn-os-${profile}`);
47
+ }
48
+ /** Display label for the active profile, or '' for production. */
49
+ export function profileLabel() {
50
+ const profile = activeProfile();
51
+ return profile === 'default' ? '' : profile;
52
+ }
53
+ /**
54
+ * Where this profile's config lived before the rename to Nordhavn OS, newest
55
+ * name first: `~/.justmade-studio` (Justmade Studio), then `~/.studiolayer`.
56
+ */
57
+ export function legacyDirs() {
58
+ const profile = activeProfile();
59
+ const suffix = profile === 'default' ? '' : `-${profile}`;
60
+ return ['.justmade-studio', '.studiolayer'].map(name => join(homedir(), `${name}${suffix}`));
61
+ }
62
+ /**
63
+ * One-time move of a pre-rename config directory into place.
64
+ *
65
+ * The runner used to live at `~/.justmade-studio` and before that at
66
+ * `~/.studiolayer` (each with a `-<profile>` variant). That directory holds the
67
+ * host pairing token, every agent's connection token and the agent homes, so
68
+ * leaving it behind would silently un-pair every machine that updates.
69
+ * Renamed once, on the first run that finds an old directory and no new one;
70
+ * the newest old name wins.
71
+ *
72
+ * Deliberately narrow: it never merges, never overwrites, and never touches
73
+ * anything once the new directory exists. Safe to delete this function,
74
+ * `legacyDirs`, its call in `index.ts` and the `home` re-rooting in `config.ts`
75
+ * once no installation is on an old layout.
76
+ */
77
+ export function migrateLegacyDir() {
78
+ const target = nordhavnDir();
79
+ if (existsSync(target))
80
+ return;
81
+ const legacy = legacyDirs().find(dir => existsSync(dir));
82
+ if (!legacy)
83
+ return;
84
+ try {
85
+ renameSync(legacy, target);
86
+ console.log(` Moved ${legacy} to ${target} (the platform is now Nordhavn OS).`);
87
+ }
88
+ catch {
89
+ // A cross-device or permission failure is not worth aborting the command
90
+ // for: the runner simply starts from an empty config and says so.
91
+ }
92
+ }
@@ -0,0 +1,57 @@
1
+ type RuntimeStatus = 'connecting' | 'connected' | 'reconnecting';
2
+ export interface AgentStatus {
3
+ /** Local agent ref (`slug` or `slug@org`) - the status file's name and the
4
+ * key every lifecycle command addresses this entry by. */
5
+ ref: string;
6
+ slug: string;
7
+ /** Organisation the agent belongs to; null for a pre-multi-org agent. Shown
8
+ * by `ps` / `agent ls` once more than one pairing exists. */
9
+ organisationSlug: string | null;
10
+ agentName?: string;
11
+ /** pid of the `nordhavn up` process driving this agent. */
12
+ pid: number;
13
+ mode: 'foreground' | 'detached';
14
+ status: RuntimeStatus;
15
+ /** ISO timestamp the process came up. */
16
+ startedAt: string;
17
+ /** ISO timestamp of the last heartbeat refresh - staleness is measured from here. */
18
+ lastSeen: string;
19
+ /** Log file for detached runs; null when the agent runs in the foreground. */
20
+ logFile: string | null;
21
+ /** Runner version of the process. Absent for a runner before self-update,
22
+ * which does not know the restart signal (`nordhavn update` checks it). */
23
+ version?: string;
24
+ /** Chats and tasks the process is running now, so `nordhavn update` can
25
+ * refuse to install under a busy runtime. */
26
+ activeRuns?: number;
27
+ }
28
+ export declare function ensureDirs(): void;
29
+ export declare function logsDir(): string;
30
+ export declare function logPath(ref: string): string;
31
+ export declare function writeStatus(status: AgentStatus): void;
32
+ export declare function readAllStatuses(): AgentStatus[];
33
+ export declare function clearStatus(ref: string): void;
34
+ /** True if a process with this pid is currently running. */
35
+ export declare function isAlive(pid: number): boolean;
36
+ /**
37
+ * True if the process that wrote `status` is still running. A live pid alone
38
+ * is not enough: after a reboot or crash the OS hands the pid to an unrelated
39
+ * process (often a root daemon, which answers EPERM and so looks alive), and the
40
+ * agent would be reported "already running" forever. The runtime writes
41
+ * `startedAt` itself, so its process always started before that moment; a
42
+ * process with this pid that started later is someone else.
43
+ */
44
+ export declare function isStatusAlive(status: AgentStatus): boolean;
45
+ /**
46
+ * The status file for `slug`, but only when its process is still alive. A file
47
+ * whose pid is dead (or reused by another process) is pruned and null returned,
48
+ * so callers never act on a zombie entry left behind by a crashed runtime.
49
+ */
50
+ export declare function liveStatus(ref: string): AgentStatus | null;
51
+ /**
52
+ * Spawn a detached, single-agent `nordhavn up` process with stdout/stderr
53
+ * redirected to the agent's log file. The child is unref'd so the launching
54
+ * CLI process can exit immediately. Returns the child pid.
55
+ */
56
+ export declare function spawnDetachedAgent(ref: string, debug: boolean): number;
57
+ export {};
@@ -0,0 +1,159 @@
1
+ import { spawn, execFileSync } from 'node:child_process';
2
+ import { join } from 'node:path';
3
+ import { mkdirSync, readdirSync, readFileSync, writeFileSync, rmSync, openSync, closeSync, } from 'node:fs';
4
+ import { nordhavnDir } from '../paths.js';
5
+ // ─── Runtime registry ────────────────────────
6
+ //
7
+ // Every running `nordhavn up` process writes a status file per agent it drives to
8
+ // ~/.nordhavn-os/agents/<ref>.json and refreshes it on the heartbeat. The lifecycle
9
+ // commands (`ps`, `stop`, `start`, `restart`, `logs`) read this directory -
10
+ // the filesystem is the registry, so there is no IPC channel to maintain.
11
+ //
12
+ // The file name is the agent *ref* (`slug` or `slug@org`, see `agentRef` in
13
+ // config.ts), never the bare slug: two organisations can each have an `atlas`,
14
+ // and they must not share one status file, one log file, or one "already
15
+ // running" guard.
16
+ // Resolved per call so the active profile (NORDHAVN_PROFILE) decides the dir.
17
+ const agentsDir = () => join(nordhavnDir(), 'agents');
18
+ const logsDir_ = () => join(nordhavnDir(), 'logs');
19
+ export function ensureDirs() {
20
+ mkdirSync(agentsDir(), { recursive: true });
21
+ mkdirSync(logsDir_(), { recursive: true });
22
+ }
23
+ export function logsDir() { return logsDir_(); }
24
+ function statusPath(ref) { return join(agentsDir(), `${ref}.json`); }
25
+ export function logPath(ref) { return join(logsDir_(), `${ref}.log`); }
26
+ export function writeStatus(status) {
27
+ mkdirSync(agentsDir(), { recursive: true });
28
+ writeFileSync(statusPath(status.ref), JSON.stringify(status, null, 2), { mode: 0o600 });
29
+ }
30
+ function readStatus(ref) {
31
+ try {
32
+ const parsed = JSON.parse(readFileSync(statusPath(ref), 'utf-8'));
33
+ // A status file written by an older runner has no `ref`/`organisationSlug`;
34
+ // its name IS the bare slug, which is the correct ref for that install.
35
+ if (!parsed.ref)
36
+ parsed.ref = ref;
37
+ if (parsed.organisationSlug === undefined)
38
+ parsed.organisationSlug = null;
39
+ return parsed;
40
+ }
41
+ catch {
42
+ return null;
43
+ }
44
+ }
45
+ export function readAllStatuses() {
46
+ let files;
47
+ try {
48
+ files = readdirSync(agentsDir());
49
+ }
50
+ catch {
51
+ return [];
52
+ }
53
+ const out = [];
54
+ for (const file of files) {
55
+ if (!file.endsWith('.json'))
56
+ continue;
57
+ const status = readStatus(file.slice(0, -5));
58
+ if (status)
59
+ out.push(status);
60
+ }
61
+ return out;
62
+ }
63
+ export function clearStatus(ref) {
64
+ rmSync(statusPath(ref), { force: true });
65
+ }
66
+ /** True if a process with this pid is currently running. */
67
+ export function isAlive(pid) {
68
+ if (!pid || pid <= 0)
69
+ return false;
70
+ try {
71
+ process.kill(pid, 0);
72
+ return true;
73
+ }
74
+ catch (err) {
75
+ // EPERM means the process exists but is owned by another user - still alive.
76
+ return err.code === 'EPERM';
77
+ }
78
+ }
79
+ /** Seconds since `pid` started (`ps -o etime=`), or null when ps cannot tell. */
80
+ function processAgeSeconds(pid) {
81
+ try {
82
+ const out = execFileSync('ps', ['-o', 'etime=', '-p', String(pid)], {
83
+ encoding: 'utf-8', stdio: ['ignore', 'pipe', 'ignore'], timeout: 2000,
84
+ }).trim();
85
+ // [[dd-]hh:]mm:ss
86
+ const m = /^(?:(\d+)-)?(?:(\d+):)?(\d+):(\d+)$/.exec(out);
87
+ if (!m)
88
+ return null;
89
+ const [, d, h, min, sec] = m;
90
+ return ((Number(d ?? 0) * 24 + Number(h ?? 0)) * 60 + Number(min)) * 60 + Number(sec);
91
+ }
92
+ catch {
93
+ return null;
94
+ }
95
+ }
96
+ // `etime` has one-second resolution; allow for that and small clock drift.
97
+ const PID_REUSE_SLACK_MS = 5000;
98
+ /**
99
+ * True if the process that wrote `status` is still running. A live pid alone
100
+ * is not enough: after a reboot or crash the OS hands the pid to an unrelated
101
+ * process (often a root daemon, which answers EPERM and so looks alive), and the
102
+ * agent would be reported "already running" forever. The runtime writes
103
+ * `startedAt` itself, so its process always started before that moment; a
104
+ * process with this pid that started later is someone else.
105
+ */
106
+ export function isStatusAlive(status) {
107
+ if (!isAlive(status.pid))
108
+ return false;
109
+ const startedAt = Date.parse(status.startedAt);
110
+ const age = processAgeSeconds(status.pid);
111
+ if (age === null || !Number.isFinite(startedAt))
112
+ return true;
113
+ return Date.now() - age * 1000 <= startedAt + PID_REUSE_SLACK_MS;
114
+ }
115
+ /**
116
+ * The status file for `slug`, but only when its process is still alive. A file
117
+ * whose pid is dead (or reused by another process) is pruned and null returned,
118
+ * so callers never act on a zombie entry left behind by a crashed runtime.
119
+ */
120
+ export function liveStatus(ref) {
121
+ const status = readStatus(ref);
122
+ if (!status)
123
+ return null;
124
+ if (isStatusAlive(status))
125
+ return status;
126
+ clearStatus(ref);
127
+ return null;
128
+ }
129
+ /**
130
+ * Spawn a detached, single-agent `nordhavn up` process with stdout/stderr
131
+ * redirected to the agent's log file. The child is unref'd so the launching
132
+ * CLI process can exit immediately. Returns the child pid.
133
+ */
134
+ export function spawnDetachedAgent(ref, debug) {
135
+ ensureDirs();
136
+ const logFd = openSync(logPath(ref), 'a');
137
+ try {
138
+ const entry = process.argv[1];
139
+ if (!entry)
140
+ throw new Error('cannot resolve the nordhavn entry script');
141
+ // The child re-enters `up` for this one agent. It is handed the REF, not the
142
+ // slug, so a machine with two same-slugged agents starts the right one.
143
+ const args = [...process.execArgv, entry, 'up', ref];
144
+ if (debug)
145
+ args.push('-v');
146
+ const child = spawn(process.execPath, args, {
147
+ detached: true,
148
+ stdio: ['ignore', logFd, logFd],
149
+ env: { ...process.env, NORDHAVN_DETACHED: '1' },
150
+ });
151
+ child.unref();
152
+ if (!child.pid)
153
+ throw new Error('spawn returned no pid');
154
+ return child.pid;
155
+ }
156
+ finally {
157
+ closeSync(logFd);
158
+ }
159
+ }
@@ -0,0 +1,31 @@
1
+ import type { ProcStartFrame } from '@nordhavnhq/runner-runtime';
2
+ import type { Config } from '../config.js';
3
+ /**
4
+ * A dev server a person starts from the studio (`proc:start`: the Dev
5
+ * environment of a surface in the code app). It runs like one an agent starts
6
+ * with `runner_run_command` (the same sandboxed environment, the project's
7
+ * pinned Node, tracked and previewed by processes.ts), under the agent whose
8
+ * socket carried the frame, with `startedBy` naming the person.
9
+ *
10
+ * What may run is narrow: the checkout must lie inside the runner's folder
11
+ * roots, the folder inside the checkout, and the command one the code app
12
+ * proposes (`devCommandFor` in packages/os/os-shared/utils/surface-dev.ts): a
13
+ * script of the folder's package.json run by its package manager (`npm run
14
+ * dev`, `pnpm dev`, `npm start`), a composer.json script (`composer run dev`)
15
+ * or `php artisan serve` beside an `artisan` file. The whole line must be that,
16
+ * no shell metacharacters, a dev server (`isLongRunningCommand`) and none the
17
+ * shell tool blocks; anything else is refused. The runner hands it
18
+ * a free port in `PORT`; a dev server that ignores it (Vite, Astro) picks its
19
+ * own, and the port is read from its output either way.
20
+ */
21
+ /** A port nothing listens on right now, from the OS. Exported for tests. */
22
+ export declare function freePort(): Promise<number>;
23
+ /** Why `command` may not be started from the studio in `cwd`, or null when it may. Exported for tests. */
24
+ export declare function devCommandRefusal(command: string, cwd: string): string | null;
25
+ export interface DevStartAgent {
26
+ slug: string;
27
+ organisationSlug: string | null;
28
+ agentHome: string;
29
+ }
30
+ /** Start the dev server `frame` asks for; throws with the reason it may not. */
31
+ export declare function startDevServer(config: Config, frame: ProcStartFrame, agent: DevStartAgent): Promise<void>;
@@ -0,0 +1,110 @@
1
+ import { spawn } from 'node:child_process';
2
+ import { existsSync, readFileSync, statSync } from 'node:fs';
3
+ import { join } from 'node:path';
4
+ import { createServer } from 'node:net';
5
+ import { commandEnv, isBlocked, isLongRunningCommand } from '../tools/console.js';
6
+ import { checkout, inside } from './fs-checkout.js';
7
+ import { resolveProjectNode } from './project-node.js';
8
+ import { trackProcess } from './processes.js';
9
+ /**
10
+ * A dev server a person starts from the studio (`proc:start`: the Dev
11
+ * environment of a surface in the code app). It runs like one an agent starts
12
+ * with `runner_run_command` (the same sandboxed environment, the project's
13
+ * pinned Node, tracked and previewed by processes.ts), under the agent whose
14
+ * socket carried the frame, with `startedBy` naming the person.
15
+ *
16
+ * What may run is narrow: the checkout must lie inside the runner's folder
17
+ * roots, the folder inside the checkout, and the command one the code app
18
+ * proposes (`devCommandFor` in packages/os/os-shared/utils/surface-dev.ts): a
19
+ * script of the folder's package.json run by its package manager (`npm run
20
+ * dev`, `pnpm dev`, `npm start`), a composer.json script (`composer run dev`)
21
+ * or `php artisan serve` beside an `artisan` file. The whole line must be that,
22
+ * no shell metacharacters, a dev server (`isLongRunningCommand`) and none the
23
+ * shell tool blocks; anything else is refused. The runner hands it
24
+ * a free port in `PORT`; a dev server that ignores it (Vite, Astro) picks its
25
+ * own, and the port is read from its output either way.
26
+ */
27
+ /** A port nothing listens on right now, from the OS. Exported for tests. */
28
+ export function freePort() {
29
+ return new Promise((resolve, reject) => {
30
+ const server = createServer();
31
+ server.unref();
32
+ server.once('error', reject);
33
+ server.listen(0, '127.0.0.1', () => {
34
+ const address = server.address();
35
+ const port = typeof address === 'object' && address ? address.port : 0;
36
+ server.close(() => port ? resolve(port) : reject(new Error('No free port')));
37
+ });
38
+ });
39
+ }
40
+ /** A script name as package.json and composer.json use them (`dev`, `dev:web`). */
41
+ const SCRIPT = String.raw `([\w:.][\w:.-]*)`;
42
+ /** `npm run dev`, `pnpm dev`, `yarn run start`, `bun run dev`: the package manager and the script. */
43
+ const PACKAGE_SCRIPT = new RegExp(String.raw `^(npm|pnpm|yarn|bun)\s+(?:run\s+)?${SCRIPT}$`);
44
+ const COMPOSER_SCRIPT = new RegExp(String.raw `^composer\s+run\s+${SCRIPT}$`);
45
+ const ARTISAN_SERVE = /^php\s+artisan\s+serve$/;
46
+ /** The script names of the JSON manifest `file` in `cwd` (`scripts` of package.json or composer.json). */
47
+ function manifestScripts(cwd, file) {
48
+ try {
49
+ const parsed = JSON.parse(readFileSync(join(cwd, file), 'utf8'));
50
+ const scripts = parsed.scripts;
51
+ return scripts && typeof scripts === 'object' && !Array.isArray(scripts) ? new Set(Object.keys(scripts)) : new Set();
52
+ }
53
+ catch {
54
+ return new Set();
55
+ }
56
+ }
57
+ /** Why the exact shape of `line` may not run in `cwd`, or null when it is one of the accepted ones. */
58
+ function shapeRefusal(line, cwd) {
59
+ const pkg = PACKAGE_SCRIPT.exec(line);
60
+ if (pkg) {
61
+ const [, manager, script] = pkg;
62
+ // `npm <script>` is no script run; only `npm start` is (npm's own alias).
63
+ if (manager === 'npm' && !/^npm\s+run\s/.test(line) && script !== 'start')
64
+ return `Use "npm run ${script}"`;
65
+ return manifestScripts(cwd, 'package.json').has(script) ? null : `No script "${script}" in the package.json of this folder`;
66
+ }
67
+ const composer = COMPOSER_SCRIPT.exec(line);
68
+ if (composer) {
69
+ const script = composer[1];
70
+ return manifestScripts(cwd, 'composer.json').has(script) ? null : `No script "${script}" in the composer.json of this folder`;
71
+ }
72
+ if (ARTISAN_SERVE.test(line))
73
+ return existsSync(join(cwd, 'artisan')) ? null : 'No artisan file in this folder';
74
+ return `Not a dev command the studio starts (a package.json or composer.json script, or php artisan serve): ${line}`;
75
+ }
76
+ /** Why `command` may not be started from the studio in `cwd`, or null when it may. Exported for tests. */
77
+ export function devCommandRefusal(command, cwd) {
78
+ const line = command.trim();
79
+ if (!line)
80
+ return 'No command to start';
81
+ if (/[\n\r]/.test(line))
82
+ return 'A dev command is one line';
83
+ // One command, nothing chained, piped, redirected, quoted or substituted beside it.
84
+ if (/[;&|`$<>()\\'"]/.test(line))
85
+ return 'A dev command is a single command, without ; & | ` $ < > ( ) \\ or quotes';
86
+ const blocked = isBlocked(line);
87
+ if (blocked)
88
+ return blocked;
89
+ if (!isLongRunningCommand(line))
90
+ return `Not a dev server command: ${line}`;
91
+ return shapeRefusal(line, cwd);
92
+ }
93
+ /** Start the dev server `frame` asks for; throws with the reason it may not. */
94
+ export async function startDevServer(config, frame, agent) {
95
+ const root = checkout(config, frame.root);
96
+ const cwd = frame.cwd ? inside(root, frame.cwd) : root;
97
+ if (!existsSync(cwd) || !statSync(cwd).isDirectory())
98
+ throw new Error('The folder does not exist on this runner');
99
+ const refusal = devCommandRefusal(frame.command, cwd);
100
+ if (refusal)
101
+ throw new Error(refusal);
102
+ const context = { agentSlug: agent.slug, organisationSlug: agent.organisationSlug, agentHome: agent.agentHome, projectRoot: root };
103
+ const node = await resolveProjectNode(cwd, root);
104
+ const port = await freePort();
105
+ const env = { ...commandEnv(context, root, process.env, node?.binDir), PORT: String(port) };
106
+ const child = spawn('sh', ['-c', frame.command], { cwd, env, stdio: ['pipe', 'pipe', 'pipe'], detached: true });
107
+ child.stdin?.end();
108
+ child.on('error', () => { });
109
+ trackProcess(child, { command: frame.command, cwd, kind: 'server', context, id: frame.processId, startedBy: frame.startedBy });
110
+ }