@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,131 @@
1
+ import { loadConfig } from '../config.js';
2
+ import { isAlive, spawnDetachedAgent } from '../runtime/daemon.js';
3
+ import { VERSION, bold, cyan, dim, green, red, yellow, isNewerVersion, showHelp, helpOpt } from '../utils/format.js';
4
+ import { detectInstallKind } from '../update/install-kind.js';
5
+ import { performUpdate } from '../update/install.js';
6
+ import { fetchManifest, manifestUrl } from '../update/manifest.js';
7
+ import { liveRuntimes, signalRestart } from '../update/peers.js';
8
+ import { autoUpdateOptedOut, updateHint } from '../update/policy.js';
9
+ import { wantsHelp } from './prompts.js';
10
+ /**
11
+ * `nordhavn update [--check] [--force]`: install the latest release into the
12
+ * prefix this runner lives in, then move the running runtimes onto it.
13
+ */
14
+ export async function update(ctx) {
15
+ if (wantsHelp(ctx)) {
16
+ showHelp('nordhavn update [--check] [--force]', 'Update this runner to the latest release', [
17
+ helpOpt(dim('--check'), 'Only show the installed and the latest version, change nothing'),
18
+ helpOpt(dim('--force'), 'Install even while agents are running a chat or task (they restart once idle)'),
19
+ ], ['nordhavn update --check', 'nordhavn update']);
20
+ return;
21
+ }
22
+ const check = ctx.cmdArgs.includes('--check');
23
+ const force = ctx.cmdArgs.includes('--force');
24
+ console.log('');
25
+ const config = await loadConfig();
26
+ const url = manifestUrl(config?.studioUrl);
27
+ if (!url) {
28
+ console.log(red(' Not configured. Run `nordhavn init` first.\n'));
29
+ process.exit(1);
30
+ return;
31
+ }
32
+ const kind = detectInstallKind();
33
+ let manifest;
34
+ try {
35
+ manifest = await fetchManifest(url);
36
+ }
37
+ catch (err) {
38
+ console.log(red(` Cannot read the latest release: ${err.message}\n`));
39
+ process.exit(1);
40
+ return;
41
+ }
42
+ const newer = isNewerVersion(manifest.version, VERSION);
43
+ if (check) {
44
+ const auto = kind.kind !== 'global' ? `no (${kind.reason})` : autoUpdateOptedOut(config) ? 'off' : 'on';
45
+ console.log(` ${dim('installed')} ${bold(VERSION)}`);
46
+ console.log(` ${dim('latest')} ${bold(manifest.version)}${manifest.releasedAt ? dim(` (${manifest.releasedAt})`) : ''}`);
47
+ console.log(` ${dim('install')} ${kind.kind === 'global' ? `global ${dim(kind.prefix)}` : kind.kind}`);
48
+ console.log(` ${dim('auto update')} ${auto}`);
49
+ console.log('');
50
+ console.log(newer
51
+ ? ` ${yellow('update available')}: run ${cyan(updateHint(kind.kind))}\n`
52
+ : ` ${green('up to date')}\n`);
53
+ return;
54
+ }
55
+ if (kind.kind !== 'global') {
56
+ console.log(red(` This runner is not a release install (${kind.reason}).`));
57
+ console.log(dim(` ${updateHint(kind.kind)}.\n`));
58
+ process.exit(1);
59
+ return;
60
+ }
61
+ if (!newer) {
62
+ console.log(green(` Up to date (${VERSION}).\n`));
63
+ return;
64
+ }
65
+ const runtimes = liveRuntimes();
66
+ const busy = runtimes.filter(r => r.activeRuns > 0);
67
+ if (busy.length > 0 && !force) {
68
+ const runs = busy.reduce((n, r) => n + r.activeRuns, 0);
69
+ console.log(red(` ${runs} chat(s) or task(s) are running (${busy.flatMap(r => r.refs).join(', ')}).`));
70
+ console.log(dim(' Try again once they are done, or use --force: the runtimes then restart once idle.\n'));
71
+ process.exit(1);
72
+ return;
73
+ }
74
+ try {
75
+ const result = await performUpdate({
76
+ manifest, prefix: kind.prefix, packageDir: kind.packageDir, legacy: kind.legacy,
77
+ onStep: step => console.log(dim(` ${step}`)),
78
+ });
79
+ console.log(green(result === 'installed'
80
+ ? ` ✓ updated ${VERSION} -> ${manifest.version}`
81
+ : ` ✓ ${manifest.version} is already installed`));
82
+ }
83
+ catch (err) {
84
+ console.log(red(` Update failed, ${VERSION} stays installed: ${err.message}\n`));
85
+ process.exit(1);
86
+ return;
87
+ }
88
+ await moveRuntimes(runtimes);
89
+ console.log('');
90
+ }
91
+ /**
92
+ * Running runtimes onto the new version. One that knows self-update gets the
93
+ * restart signal and restarts once idle. An older detached one is stopped and
94
+ * started again; an older foreground one can only be restarted by its operator.
95
+ */
96
+ async function moveRuntimes(runtimes) {
97
+ if (runtimes.length === 0)
98
+ return;
99
+ const signalled = new Set(signalRestart(null, runtimes));
100
+ for (const r of runtimes) {
101
+ const names = r.refs.join(', ');
102
+ if (signalled.has(r.pid)) {
103
+ console.log(dim(` ${names}: restarting on the new version${r.activeRuns > 0 ? ' once idle' : ''}`));
104
+ continue;
105
+ }
106
+ if (r.mode !== 'detached') {
107
+ console.log(yellow(` ${names} runs in the foreground (pid ${r.pid}): restart it to use the new version`));
108
+ continue;
109
+ }
110
+ try {
111
+ process.kill(r.pid, 'SIGTERM');
112
+ }
113
+ catch { /* gone */ }
114
+ const deadline = Date.now() + 5000;
115
+ while (isAlive(r.pid) && Date.now() < deadline)
116
+ await new Promise(resolve => setTimeout(resolve, 150));
117
+ if (isAlive(r.pid)) {
118
+ console.log(red(` ${names} did not stop within 5s: restart it with \`nordhavn restart\``));
119
+ continue;
120
+ }
121
+ for (const ref of r.refs) {
122
+ try {
123
+ const pid = spawnDetachedAgent(ref, false);
124
+ console.log(dim(` ${ref}: restarted on the new version (pid ${pid})`));
125
+ }
126
+ catch (err) {
127
+ console.log(red(` ${ref}: restart failed: ${err.message}`));
128
+ }
129
+ }
130
+ }
131
+ }
@@ -0,0 +1,166 @@
1
+ import type { Config, AgentConfig, HostConfig } from '@nordhavnhq/runner-runtime';
2
+ export type { Config, AgentConfig, HostConfig } from '@nordhavnhq/runner-runtime';
3
+ export declare function loadConfig(): Promise<Config | null>;
4
+ /**
5
+ * Write the config, owner-only (0600) on every write: `mode` of writeFile only
6
+ * applies when the file is created, so a config made earlier with a wider mode
7
+ * (by hand, by an old runner) is narrowed before the tokens are written into it.
8
+ */
9
+ export declare function saveConfig(config: Config): Promise<void>;
10
+ export declare function getConfigPath(): string;
11
+ /**
12
+ * How a pairing made before organisations were recorded is printed - by
13
+ * `agent ls`, by `ps`, and by the "paired with: ..." lists. Exported because it
14
+ * is also the only name an operator can type for that pairing (see
15
+ * `removePairing`): what we print has to be what we accept.
16
+ */
17
+ export declare const NAMELESS_ORG_LABEL = "unknown";
18
+ /** Stable local name for an agent: `slug` or `slug@org`. */
19
+ export declare function agentRef(config: Config, agent: AgentConfig): string;
20
+ /**
21
+ * Resolve a user-typed agent reference.
22
+ *
23
+ * An exact ref match wins outright - `atlas` and `atlas@klant-x` are the two
24
+ * names `ps` and `agent ls` print, so typing one back is unambiguous even
25
+ * though both agents are slugged `atlas`. Only when the input matches no ref
26
+ * exactly does it fall back to matching the bare slug, which is where a real
27
+ * ambiguity can appear (two agents in two *nested* organisations).
28
+ *
29
+ * That ambiguity returns the candidates rather than a pick: silently acting on
30
+ * whichever came first is exactly the class of bug this ref scheme exists to
31
+ * prevent, so the caller reports it and asks for the qualified form.
32
+ */
33
+ export declare function resolveAgentRef(config: Config, ref: string): {
34
+ agent: AgentConfig;
35
+ } | {
36
+ ambiguous: AgentConfig[];
37
+ } | {
38
+ missing: true;
39
+ };
40
+ /** The pairing an agent connects under, or null when none is configured for
41
+ * its organisation. A null-organisation agent matches the equally nameless
42
+ * legacy pairing, so the plain comparison covers that case too. */
43
+ export declare function hostForAgent(config: Config, agent: AgentConfig): HostConfig | null;
44
+ /** Why a running agent's credentials could not be re-read from a fresh config.
45
+ * Each means "stop for good" rather than "try again": there is nothing on disk
46
+ * left to connect with. */
47
+ export type CredentialsGone =
48
+ /** Its config row is gone - `agent remove`, or `unlink` of its organisation. */
49
+ 'agent'
50
+ /** The row is there but its organisation has no pairing - `unlink`. */
51
+ | 'host'
52
+ /** The row moved to another organisation while we ran. Its ref, home dir,
53
+ * status file and log file all derive from the organisation, so adopting it
54
+ * in place would be a re-key, not a token swap. A restart does it properly. */
55
+ | 'organisation-changed';
56
+ /**
57
+ * The credentials this agent would connect with *right now*, read from a config
58
+ * that was just loaded from disk.
59
+ *
60
+ * The studio rejects a connect for reasons only a human can fix (revoked host,
61
+ * rotated agent token, unlinked organisation), and fixing them - `nordhavn
62
+ * link` - writes new tokens to `config.json` from another
63
+ * process. A runner that only ever knows the credentials it started with cannot
64
+ * see that repair, so it stops on a token that has since been replaced. This is
65
+ * what lets the caller notice.
66
+ *
67
+ * The agent is looked up by its own uniqueness key (slug + organisation), with
68
+ * a fallback on the token for the window where a rename has landed on disk but
69
+ * not yet in this process. It is deliberately NOT looked up by slug alone: the
70
+ * same slug in another organisation is a different agent, and handing back its
71
+ * token is exactly the cross-organisation mix-up the ref scheme exists to stop.
72
+ */
73
+ export declare function credentialsOnDisk(fresh: Config, agent: AgentConfig): {
74
+ host: HostConfig;
75
+ agentToken: string;
76
+ } | {
77
+ gone: CredentialsGone;
78
+ };
79
+ /** The agent this runner hosts, or null before `link`. A runner hosts one. */
80
+ export declare function hostedAgent(config: Config): AgentConfig | null;
81
+ /**
82
+ * Make `agent` the one agent this runner hosts (`link`): replaces whatever is
83
+ * there and keeps only the pairing of the agent's organisation.
84
+ */
85
+ export declare function addAgent(config: Config, agent: AgentConfig): Config;
86
+ export declare function removeAgent(config: Config, agent: AgentConfig): Config;
87
+ /**
88
+ * Drop a pairing and every agent that belongs to it.
89
+ *
90
+ * `flatHomeOrg` is deliberately NOT cleared or reassigned here. The agent home
91
+ * directories of the organisation being unlinked stay on disk (as they do for
92
+ * `removeAgent`), so handing the flat layout to the next organisation would
93
+ * point its agents at someone else's files. Whether the flat layer may be
94
+ * claimed again is decided by `canClaimFlatHome`, which asks the disk rather
95
+ * than trusting this field.
96
+ *
97
+ * A pairing made before organisations were recorded has a null slug and is
98
+ * printed as `unknown`, so that label is accepted as its name. Only as a
99
+ * fallback: an organisation genuinely slugged `unknown` matches itself first.
100
+ */
101
+ export declare function removePairing(config: Config, organisation: string): {
102
+ host: HostConfig;
103
+ removedAgents: AgentConfig[];
104
+ heldFlatHome: boolean;
105
+ } | {
106
+ missing: true;
107
+ };
108
+ /**
109
+ * Whether a newly linked organisation may take the flat home layout
110
+ * (`<home>/agent_<slug>`) instead of nesting under its own directory.
111
+ *
112
+ * Three things all have to hold, and each closes a way of pointing one
113
+ * organisation's agents at another's files:
114
+ *
115
+ * - No pairing that is still present holds the layout. An organisation that
116
+ * was promised the flat layer at `link` time keeps it even before it has
117
+ * registered any agent, so a second `link` can never quietly demote it.
118
+ * (`flatHomeOrg` null means a nameless legacy pairing holds it, if one
119
+ * exists - null-organisation agents use the flat layout by definition.)
120
+ * - No configured agent uses the layout.
121
+ * - No `agent_*` directory is left on disk. This is the one that needs the
122
+ * filesystem: agent homes outlive both `agent remove` and `unlink`, so
123
+ * "no agents in config" would happily hand a fresh organisation the
124
+ * populated home directories of a departed one. A missing home dir means
125
+ * nothing has been created yet, which is free.
126
+ *
127
+ * Call it BEFORE adding the new pairing to `hosts`, so the first check sees the
128
+ * pairings that already existed.
129
+ */
130
+ export declare function canClaimFlatHome(config: Config): boolean;
131
+ /** Path to an agent's private home. `<home>/agent_<slug>` for the flat-home
132
+ * organisation, `<home>/<org>/agent_<slug>` for every other one. The agent's
133
+ * own home for things it builds for itself, always inside the tool jail. */
134
+ export declare function agentHomeDir(config: Config, agent: AgentConfig): string;
135
+ /** Base dir holding every per-dispatch scratch dir: `<home>/tmp`. Everything
136
+ * under here is throwaway and swept by the scratch reaper. */
137
+ export declare function scratchBaseDir(config: Config): string;
138
+ /** Per-dispatch throwaway scratch dir: `<home>/tmp/<agentRef>/<dispatchId>`.
139
+ * Given to the agent (jailed, and via `$NORDHAVN_SCRATCH`) for
140
+ * temp/intermediate files so it never litters the project checkout;
141
+ * auto-deleted by the reaper once older than the scratch TTL. Keyed on the
142
+ * agent ref, not the bare slug, so two same-slugged agents from different
143
+ * organisations never share a scratch tree. `dispatchId` is sanitised so a
144
+ * task/queue or conversation uid can be dropped in verbatim. */
145
+ export declare function scratchDir(config: Config, agent: AgentConfig, dispatchId: string): string;
146
+ /**
147
+ * Resolve a dispatch's project folder to a usable local root on THIS machine.
148
+ * There is NO slug auto-matching: the studio picker is the only source of the
149
+ * coupling and ships the exact `folder` on the dispatch. We only validate it's
150
+ * inside one of the runner's folders (its access scope) and exists; otherwise
151
+ * the agent falls back to its own home (no project code).
152
+ */
153
+ export declare function resolveProjectRoot(config: Config, folder: string | undefined | null, agentHome: string): string;
154
+ /**
155
+ * Resolve a dispatch's workspace folders (extra folders beside the checkout) to
156
+ * usable local roots. Same access rule as the checkout: absolute, inside one of
157
+ * the runner's folders, and an existing directory. A folder that is the
158
+ * checkout, holds it or sits in it is dropped (the checkout already covers it),
159
+ * as is a duplicate. Folders that fail are dropped silently: the agent simply
160
+ * does not get them.
161
+ */
162
+ export declare function resolveWorkspaceRoots(config: Config, folders: readonly string[] | undefined | null, projectRoot: string, agentHome: string): string[];
163
+ /** Add a folder the runner may open projects from. No-op if already present. */
164
+ export declare function addProjectsRoot(config: Config, path: string): Config;
165
+ /** Remove a search root. */
166
+ export declare function removeProjectsRoot(config: Config, path: string): Config;
package/dist/config.js ADDED
@@ -0,0 +1,383 @@
1
+ import { chmod, readFile, writeFile, mkdir } from 'node:fs/promises';
2
+ import { existsSync, statSync, readdirSync } from 'node:fs';
3
+ import { homedir } from 'node:os';
4
+ import { isAbsolute, join, resolve, sep } from 'node:path';
5
+ import { nordhavnDir, legacyDirs } from './paths.js';
6
+ // Resolved per call so the active profile (NORDHAVN_PROFILE) decides the dir.
7
+ const configDir = () => nordhavnDir();
8
+ const configFile = () => join(nordhavnDir(), 'config.json');
9
+ export async function loadConfig() {
10
+ let raw;
11
+ try {
12
+ raw = await readFile(configFile(), 'utf-8');
13
+ }
14
+ catch {
15
+ return null;
16
+ }
17
+ const parsed = JSON.parse(raw);
18
+ // Every consumer builds URLs as `${studioUrl}/api/...` (and the WS url as
19
+ // `studioUrl.replace(/^http/, 'ws') + '/_ws/agents'`). A trailing slash on
20
+ // studioUrl produces a `//api/...` double slash that the studio 302-redirects
21
+ // to the SPA, so fetches get HTML back and JSON parsing blows up. Strip it
22
+ // here so any stored/typed trailing slash self-heals on the next run.
23
+ if (typeof parsed.studioUrl === 'string')
24
+ parsed.studioUrl = parsed.studioUrl.replace(/\/+$/, '');
25
+ if (!parsed.agents)
26
+ parsed.agents = [];
27
+ if (!parsed.home)
28
+ parsed.home = join(homedir(), '.nordhavn-os', 'home');
29
+ // `home` is stored absolute, so a config written before the rename still
30
+ // points into ~/.justmade-studio (or ~/.studiolayer) even though
31
+ // `migrateLegacyDir` moved the directory. Re-root it the same way studioUrl
32
+ // self-heals above. Safe to delete alongside `migrateLegacyDir`.
33
+ for (const legacy of legacyDirs()) {
34
+ if (parsed.home === legacy || parsed.home.startsWith(legacy + sep)) {
35
+ parsed.home = nordhavnDir() + parsed.home.slice(legacy.length);
36
+ break;
37
+ }
38
+ }
39
+ // Migrate the earlier single `projectsRoot` into the `projectsRoots` array, and
40
+ // drop the retired explicit `projects` map (coupling now lives studio-side).
41
+ const legacyRoot = parsed.projectsRoot;
42
+ if (!parsed.projectsRoots)
43
+ parsed.projectsRoots = legacyRoot ? [legacyRoot] : [join(homedir(), 'projects')];
44
+ delete parsed.projectsRoot;
45
+ delete parsed.projects;
46
+ migrateToMultiOrg(parsed);
47
+ keepOneAgent(parsed);
48
+ return parsed;
49
+ }
50
+ let warnedDroppedAgents = false;
51
+ /**
52
+ * A runner hosts one agent (the studio refuses a second one with close 4009).
53
+ * A config written when a runner could host several keeps the first enabled
54
+ * one (or the first) plus the pairing of its organisation; the rest is dropped
55
+ * from memory with a warning, and from disk on the next save. A dropped agent
56
+ * runs again from its own profile: `NORDHAVN_PROFILE=<name> nordhavn init`,
57
+ * then `nordhavn link <code>`.
58
+ */
59
+ function keepOneAgent(parsed) {
60
+ if (parsed.agents.length <= 1)
61
+ return;
62
+ const kept = parsed.agents.find(a => a.enabled) ?? parsed.agents[0];
63
+ const dropped = parsed.agents.filter(a => a !== kept);
64
+ parsed.agents = [kept];
65
+ parsed.hosts = parsed.hosts.filter(h => h.organisationSlug === kept.organisationSlug);
66
+ if (warnedDroppedAgents)
67
+ return;
68
+ warnedDroppedAgents = true;
69
+ const refs = dropped.map(a => a.organisationSlug ? `${a.slug}@${a.organisationSlug}` : a.slug);
70
+ console.warn(`[nordhavn] A runner hosts one agent. Keeping "${kept.slug}", dropping: ${refs.join(', ')}.`);
71
+ console.warn('[nordhavn] Run each dropped agent in its own profile: NORDHAVN_PROFILE=<name> nordhavn init, then nordhavn link <code>.');
72
+ }
73
+ /**
74
+ * Fold the old single-organisation shape (`organisationSlug` + one `host`) into
75
+ * the `hosts[]` array, in the same self-healing spirit as the `projectsRoot`
76
+ * migration above. Invisible to anyone running a single organisation: they end
77
+ * up with a one-element array and the same home paths they had before.
78
+ *
79
+ * A config written before `organisationSlug` existed carries null there. The
80
+ * null then lands on BOTH the migrated host and its agents, so they still match
81
+ * each other - a nameless pairing serving nameless agents keeps working
82
+ * untouched, and names itself on the next `link`.
83
+ */
84
+ function migrateToMultiOrg(parsed) {
85
+ const legacy = parsed;
86
+ const legacyOrg = legacy.organisationSlug ?? null;
87
+ if (!Array.isArray(parsed.hosts)) {
88
+ // A pre-pairing config carries no usable host - the runner refuses to start
89
+ // until the pairing flow populates one.
90
+ const host = legacy.host;
91
+ parsed.hosts = host && host.token
92
+ ? [{ uuid: host.uuid, token: host.token, name: host.name, organisationSlug: legacyOrg }]
93
+ : [];
94
+ }
95
+ parsed.hosts = parsed.hosts.filter(h => h && h.token);
96
+ for (const host of parsed.hosts) {
97
+ if (host.organisationSlug === undefined)
98
+ host.organisationSlug = null;
99
+ }
100
+ for (const agent of parsed.agents) {
101
+ if (agent.organisationSlug === undefined)
102
+ agent.organisationSlug = legacyOrg;
103
+ }
104
+ // The organisation already living in the flat home layout keeps it. A config
105
+ // that was never paired leaves this null so the first `link` can claim it.
106
+ if (parsed.flatHomeOrg === undefined)
107
+ parsed.flatHomeOrg = legacyOrg;
108
+ delete legacy.organisationSlug;
109
+ delete legacy.host;
110
+ }
111
+ /**
112
+ * Write the config, owner-only (0600) on every write: `mode` of writeFile only
113
+ * applies when the file is created, so a config made earlier with a wider mode
114
+ * (by hand, by an old runner) is narrowed before the tokens are written into it.
115
+ */
116
+ export async function saveConfig(config) {
117
+ await mkdir(configDir(), { recursive: true });
118
+ const file = configFile();
119
+ await chmod(file, 0o600).catch((error) => {
120
+ if (error.code !== 'ENOENT')
121
+ throw error;
122
+ });
123
+ await writeFile(file, JSON.stringify(config, null, 2), { mode: 0o600 });
124
+ await chmod(file, 0o600);
125
+ }
126
+ export function getConfigPath() {
127
+ return configFile();
128
+ }
129
+ // ─── Agent identity ───────────────────────────
130
+ //
131
+ // An agent slug is unique only WITHIN an organisation, so on a machine paired
132
+ // with several organisations the slug alone can't name an agent. Everything
133
+ // local that needs a stable per-agent name - config lookup, status file, log
134
+ // file, scratch dir, the in-process socket maps, the detached-launch argv -
135
+ // goes through `agentRef` instead.
136
+ //
137
+ // The ref mirrors the home-dir rule: the flat-home organisation (and the
138
+ // nameless legacy one) keeps the bare slug, everything else is `slug@org`.
139
+ // That keeps every existing file name, log path and CLI invocation working
140
+ // untouched for a single-organisation install, while staying unambiguous once
141
+ // a second organisation shows up. `@` is safe in a path segment everywhere the
142
+ // runner runs.
143
+ /**
144
+ * How a pairing made before organisations were recorded is printed - by
145
+ * `agent ls`, by `ps`, and by the "paired with: ..." lists. Exported because it
146
+ * is also the only name an operator can type for that pairing (see
147
+ * `removePairing`): what we print has to be what we accept.
148
+ */
149
+ export const NAMELESS_ORG_LABEL = 'unknown';
150
+ /** True when this organisation's agents use the flat, unqualified layout. */
151
+ function isFlatOrg(config, organisationSlug) {
152
+ return organisationSlug === null || organisationSlug === config.flatHomeOrg;
153
+ }
154
+ /** Stable local name for an agent: `slug` or `slug@org`. */
155
+ export function agentRef(config, agent) {
156
+ return isFlatOrg(config, agent.organisationSlug) ? agent.slug : `${agent.slug}@${agent.organisationSlug}`;
157
+ }
158
+ /**
159
+ * Resolve a user-typed agent reference.
160
+ *
161
+ * An exact ref match wins outright - `atlas` and `atlas@klant-x` are the two
162
+ * names `ps` and `agent ls` print, so typing one back is unambiguous even
163
+ * though both agents are slugged `atlas`. Only when the input matches no ref
164
+ * exactly does it fall back to matching the bare slug, which is where a real
165
+ * ambiguity can appear (two agents in two *nested* organisations).
166
+ *
167
+ * That ambiguity returns the candidates rather than a pick: silently acting on
168
+ * whichever came first is exactly the class of bug this ref scheme exists to
169
+ * prevent, so the caller reports it and asks for the qualified form.
170
+ */
171
+ export function resolveAgentRef(config, ref) {
172
+ const exact = config.agents.filter(a => agentRef(config, a) === ref);
173
+ if (exact.length === 1)
174
+ return { agent: exact[0] };
175
+ const bySlug = config.agents.filter(a => a.slug === ref);
176
+ if (bySlug.length === 1)
177
+ return { agent: bySlug[0] };
178
+ if (bySlug.length > 1)
179
+ return { ambiguous: bySlug };
180
+ return { missing: true };
181
+ }
182
+ /** The pairing an agent connects under, or null when none is configured for
183
+ * its organisation. A null-organisation agent matches the equally nameless
184
+ * legacy pairing, so the plain comparison covers that case too. */
185
+ export function hostForAgent(config, agent) {
186
+ return config.hosts.find(h => h.organisationSlug === agent.organisationSlug) ?? null;
187
+ }
188
+ /**
189
+ * The credentials this agent would connect with *right now*, read from a config
190
+ * that was just loaded from disk.
191
+ *
192
+ * The studio rejects a connect for reasons only a human can fix (revoked host,
193
+ * rotated agent token, unlinked organisation), and fixing them - `nordhavn
194
+ * link` - writes new tokens to `config.json` from another
195
+ * process. A runner that only ever knows the credentials it started with cannot
196
+ * see that repair, so it stops on a token that has since been replaced. This is
197
+ * what lets the caller notice.
198
+ *
199
+ * The agent is looked up by its own uniqueness key (slug + organisation), with
200
+ * a fallback on the token for the window where a rename has landed on disk but
201
+ * not yet in this process. It is deliberately NOT looked up by slug alone: the
202
+ * same slug in another organisation is a different agent, and handing back its
203
+ * token is exactly the cross-organisation mix-up the ref scheme exists to stop.
204
+ */
205
+ export function credentialsOnDisk(fresh, agent) {
206
+ const row = fresh.agents.find(a => a.slug === agent.slug && a.organisationSlug === agent.organisationSlug) ?? fresh.agents.find(a => a.token === agent.token);
207
+ if (!row)
208
+ return { gone: 'agent' };
209
+ if (row.organisationSlug !== agent.organisationSlug)
210
+ return { gone: 'organisation-changed' };
211
+ const host = hostForAgent(fresh, row);
212
+ if (!host)
213
+ return { gone: 'host' };
214
+ return { host, agentToken: row.token };
215
+ }
216
+ /** The agent this runner hosts, or null before `link`. A runner hosts one. */
217
+ export function hostedAgent(config) {
218
+ return config.agents[0] ?? null;
219
+ }
220
+ /**
221
+ * Make `agent` the one agent this runner hosts (`link`): replaces whatever is
222
+ * there and keeps only the pairing of the agent's organisation.
223
+ */
224
+ export function addAgent(config, agent) {
225
+ config.agents = [agent];
226
+ config.hosts = config.hosts.filter(h => h.organisationSlug === agent.organisationSlug);
227
+ return config;
228
+ }
229
+ export function removeAgent(config, agent) {
230
+ config.agents = config.agents.filter(a => a !== agent);
231
+ return config;
232
+ }
233
+ /**
234
+ * Drop a pairing and every agent that belongs to it.
235
+ *
236
+ * `flatHomeOrg` is deliberately NOT cleared or reassigned here. The agent home
237
+ * directories of the organisation being unlinked stay on disk (as they do for
238
+ * `removeAgent`), so handing the flat layout to the next organisation would
239
+ * point its agents at someone else's files. Whether the flat layer may be
240
+ * claimed again is decided by `canClaimFlatHome`, which asks the disk rather
241
+ * than trusting this field.
242
+ *
243
+ * A pairing made before organisations were recorded has a null slug and is
244
+ * printed as `unknown`, so that label is accepted as its name. Only as a
245
+ * fallback: an organisation genuinely slugged `unknown` matches itself first.
246
+ */
247
+ export function removePairing(config, organisation) {
248
+ let index = config.hosts.findIndex(h => h.organisationSlug === organisation);
249
+ if (index === -1 && organisation === NAMELESS_ORG_LABEL) {
250
+ index = config.hosts.findIndex(h => h.organisationSlug === null);
251
+ }
252
+ if (index === -1)
253
+ return { missing: true };
254
+ const host = config.hosts[index];
255
+ const removedAgents = config.agents.filter(a => a.organisationSlug === host.organisationSlug);
256
+ const heldFlatHome = isFlatOrg(config, host.organisationSlug);
257
+ config.hosts.splice(index, 1);
258
+ config.agents = config.agents.filter(a => a.organisationSlug !== host.organisationSlug);
259
+ return { host, removedAgents, heldFlatHome };
260
+ }
261
+ /**
262
+ * Whether a newly linked organisation may take the flat home layout
263
+ * (`<home>/agent_<slug>`) instead of nesting under its own directory.
264
+ *
265
+ * Three things all have to hold, and each closes a way of pointing one
266
+ * organisation's agents at another's files:
267
+ *
268
+ * - No pairing that is still present holds the layout. An organisation that
269
+ * was promised the flat layer at `link` time keeps it even before it has
270
+ * registered any agent, so a second `link` can never quietly demote it.
271
+ * (`flatHomeOrg` null means a nameless legacy pairing holds it, if one
272
+ * exists - null-organisation agents use the flat layout by definition.)
273
+ * - No configured agent uses the layout.
274
+ * - No `agent_*` directory is left on disk. This is the one that needs the
275
+ * filesystem: agent homes outlive both `agent remove` and `unlink`, so
276
+ * "no agents in config" would happily hand a fresh organisation the
277
+ * populated home directories of a departed one. A missing home dir means
278
+ * nothing has been created yet, which is free.
279
+ *
280
+ * Call it BEFORE adding the new pairing to `hosts`, so the first check sees the
281
+ * pairings that already existed.
282
+ */
283
+ export function canClaimFlatHome(config) {
284
+ if (config.hosts.some(h => h.organisationSlug === config.flatHomeOrg))
285
+ return false;
286
+ if (config.agents.some(a => isFlatOrg(config, a.organisationSlug)))
287
+ return false;
288
+ try {
289
+ return !readdirSync(config.home).some(entry => entry.startsWith('agent_'));
290
+ }
291
+ catch {
292
+ return true;
293
+ }
294
+ }
295
+ /** Path to an agent's private home. `<home>/agent_<slug>` for the flat-home
296
+ * organisation, `<home>/<org>/agent_<slug>` for every other one. The agent's
297
+ * own home for things it builds for itself, always inside the tool jail. */
298
+ export function agentHomeDir(config, agent) {
299
+ return isFlatOrg(config, agent.organisationSlug)
300
+ ? join(config.home, `agent_${agent.slug}`)
301
+ : join(config.home, agent.organisationSlug, `agent_${agent.slug}`);
302
+ }
303
+ /** Base dir holding every per-dispatch scratch dir: `<home>/tmp`. Everything
304
+ * under here is throwaway and swept by the scratch reaper. */
305
+ export function scratchBaseDir(config) {
306
+ return join(config.home, 'tmp');
307
+ }
308
+ /** Per-dispatch throwaway scratch dir: `<home>/tmp/<agentRef>/<dispatchId>`.
309
+ * Given to the agent (jailed, and via `$NORDHAVN_SCRATCH`) for
310
+ * temp/intermediate files so it never litters the project checkout;
311
+ * auto-deleted by the reaper once older than the scratch TTL. Keyed on the
312
+ * agent ref, not the bare slug, so two same-slugged agents from different
313
+ * organisations never share a scratch tree. `dispatchId` is sanitised so a
314
+ * task/queue or conversation uid can be dropped in verbatim. */
315
+ export function scratchDir(config, agent, dispatchId) {
316
+ const safeId = dispatchId.replace(/[^a-zA-Z0-9_-]/g, '_') || 'dispatch';
317
+ return join(scratchBaseDir(config), agentRef(config, agent), safeId);
318
+ }
319
+ /**
320
+ * Resolve a dispatch's project folder to a usable local root on THIS machine.
321
+ * There is NO slug auto-matching: the studio picker is the only source of the
322
+ * coupling and ships the exact `folder` on the dispatch. We only validate it's
323
+ * inside one of the runner's folders (its access scope) and exists; otherwise
324
+ * the agent falls back to its own home (no project code).
325
+ */
326
+ export function resolveProjectRoot(config, folder, agentHome) {
327
+ if (!folder)
328
+ return agentHome;
329
+ const resolved = resolve(folder);
330
+ const inScope = (config.projectsRoots ?? []).some((root) => {
331
+ const r = resolve(root);
332
+ return resolved === r || resolved.startsWith(r + sep);
333
+ });
334
+ if (!inScope)
335
+ return agentHome;
336
+ try {
337
+ if (existsSync(resolved) && statSync(resolved).isDirectory())
338
+ return resolved;
339
+ }
340
+ catch { /* fall through */ }
341
+ return agentHome;
342
+ }
343
+ /**
344
+ * Resolve a dispatch's workspace folders (extra folders beside the checkout) to
345
+ * usable local roots. Same access rule as the checkout: absolute, inside one of
346
+ * the runner's folders, and an existing directory. A folder that is the
347
+ * checkout, holds it or sits in it is dropped (the checkout already covers it),
348
+ * as is a duplicate. Folders that fail are dropped silently: the agent simply
349
+ * does not get them.
350
+ */
351
+ export function resolveWorkspaceRoots(config, folders, projectRoot, agentHome) {
352
+ if (!folders?.length || projectRoot === agentHome)
353
+ return [];
354
+ const checkout = resolve(projectRoot);
355
+ const inside = (path, base) => path === base || path.startsWith(base + sep);
356
+ const roots = [];
357
+ for (const folder of folders) {
358
+ if (typeof folder !== 'string' || !isAbsolute(folder))
359
+ continue;
360
+ const resolved = resolveProjectRoot(config, folder, agentHome);
361
+ if (resolved === agentHome)
362
+ continue;
363
+ if (inside(resolved, checkout) || inside(checkout, resolved))
364
+ continue;
365
+ if (!roots.includes(resolved))
366
+ roots.push(resolved);
367
+ }
368
+ return roots;
369
+ }
370
+ /** Add a folder the runner may open projects from. No-op if already present. */
371
+ export function addProjectsRoot(config, path) {
372
+ if (!config.projectsRoots)
373
+ config.projectsRoots = [];
374
+ if (!config.projectsRoots.includes(path))
375
+ config.projectsRoots.push(path);
376
+ return config;
377
+ }
378
+ /** Remove a search root. */
379
+ export function removeProjectsRoot(config, path) {
380
+ if (config.projectsRoots)
381
+ config.projectsRoots = config.projectsRoots.filter(r => r !== path);
382
+ return config;
383
+ }