@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,22 @@
1
+ /** Whether a patch body is hunks and nothing else: every hunk exactly as
2
+ * long as its header says, so no line after it can name another file. */
3
+ export declare function isHunksOnly(lines: string[]): boolean;
4
+ /** Paths out of the index, back to what the last commit holds (out of it
5
+ * altogether before the first commit); the files on disk stay as they are. */
6
+ export declare function unstage(base: string, paths: string[]): Promise<string>;
7
+ /**
8
+ * A patch body (from its first hunk on) of the checkout's file `rel` applied:
9
+ * to the index (`cached`) or to the file on disk, `reverse` to take it back
10
+ * out. git checks every line of context, so a patch made from a diff that has
11
+ * since changed is refused rather than applied in the wrong place.
12
+ */
13
+ export declare function applyPatch(base: string, rel: string, patch: string, opts: {
14
+ cached: boolean;
15
+ reverse: boolean;
16
+ }): Promise<string>;
17
+ /** A conflicted file taken as one side wrote it and marked resolved; a side
18
+ * that deleted it deletes it. */
19
+ export declare function resolveConflict(base: string, rel: string, side: 'current' | 'incoming'): Promise<string>;
20
+ /** Conflicted files marked resolved as they are on disk, once none of them
21
+ * holds conflict markers any more. */
22
+ export declare function markResolved(base: string, paths: string[], conflicted: string[]): Promise<string>;
@@ -0,0 +1,133 @@
1
+ import { mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
2
+ import { tmpdir } from 'node:os';
3
+ import { join, relative, sep } from 'node:path';
4
+ import { exists, failure, git, said } from './fs-checkout.js';
5
+ // ─── The index, from the code app ─────────────────────────────────
6
+ //
7
+ // What a git client does with the staging area besides `add`: a path out of
8
+ // it again, part of a file's change in or out of it (the hunks and lines a
9
+ // person picked, a patch the code app writes with `buildGitPatch`), and a
10
+ // conflict settled. Paths are relative to the checkout (fs-git.ts checked
11
+ // them); a patch names one file and only that file is touched.
12
+ const HUNK = /^@@ -\d+(?:,(\d+))? \+\d+(?:,(\d+))? @@/;
13
+ /** Whether a patch body is hunks and nothing else: every hunk exactly as
14
+ * long as its header says, so no line after it can name another file. */
15
+ export function isHunksOnly(lines) {
16
+ let count = null;
17
+ for (const line of lines) {
18
+ const header = HUNK.exec(line);
19
+ if (header) {
20
+ if (count && (count.old || count.neu))
21
+ return false;
22
+ count = { old: hunkSize(header[1]), neu: hunkSize(header[2]) };
23
+ continue;
24
+ }
25
+ if (!count || !countLine(count, line))
26
+ return false;
27
+ }
28
+ return !!count && !count.old && !count.neu;
29
+ }
30
+ /** A hunk header's line count; left out, it is one line. */
31
+ function hunkSize(n) {
32
+ return n === undefined ? 1 : Number(n);
33
+ }
34
+ /** One body line counted against its hunk: false when it is no hunk line or
35
+ * runs past what the header says. */
36
+ function countLine(count, line) {
37
+ const mark = line[0];
38
+ if (mark === '\\')
39
+ return true;
40
+ if (mark === ' ') {
41
+ count.old--;
42
+ count.neu--;
43
+ }
44
+ else if (mark === '-')
45
+ count.old--;
46
+ else if (mark === '+')
47
+ count.neu--;
48
+ else
49
+ return false;
50
+ return count.old >= 0 && count.neu >= 0;
51
+ }
52
+ /** Paths out of the index, back to what the last commit holds (out of it
53
+ * altogether before the first commit); the files on disk stay as they are. */
54
+ export async function unstage(base, paths) {
55
+ if (!paths.length)
56
+ throw new Error('Nothing to unstage');
57
+ const run = await exists(base, 'HEAD')
58
+ ? await git(base, ['--literal-pathspecs', 'restore', '--staged', '--', ...paths], { timeout: 60_000 })
59
+ : await git(base, ['--literal-pathspecs', 'rm', '--cached', '-r', '-q', '--', ...paths], { timeout: 60_000 });
60
+ if (!run.ok)
61
+ throw new Error(failure(run, 'git restore failed'));
62
+ return said(run);
63
+ }
64
+ /**
65
+ * A patch body (from its first hunk on) of the checkout's file `rel` applied:
66
+ * to the index (`cached`) or to the file on disk, `reverse` to take it back
67
+ * out. git checks every line of context, so a patch made from a diff that has
68
+ * since changed is refused rather than applied in the wrong place.
69
+ */
70
+ export async function applyPatch(base, rel, patch, opts) {
71
+ const lines = patch.split('\n');
72
+ if (lines[lines.length - 1] === '')
73
+ lines.pop();
74
+ if (!isHunksOnly(lines))
75
+ throw new Error('Not a patch of one file');
76
+ // git apply reads paths from the top of the repository.
77
+ const top = (await git(base, ['rev-parse', '--show-toplevel'])).stdout.trim();
78
+ if (!top)
79
+ throw new Error('The checkout is no git repository');
80
+ const path = relative(top, join(base, rel)).split(sep).join('/');
81
+ const dir = mkdtempSync(join(tmpdir(), 'nordhavn-patch-'));
82
+ try {
83
+ const file = join(dir, 'change.patch');
84
+ writeFileSync(file, `diff --git a/${path} b/${path}\n--- a/${path}\n+++ b/${path}\n${lines.join('\n')}\n`);
85
+ const run = await git(top, ['apply', ...(opts.cached ? ['--cached'] : []), ...(opts.reverse ? ['--reverse'] : []), '--whitespace=nowarn', file]);
86
+ if (!run.ok)
87
+ throw new Error(failure(run, 'git apply failed: the file changed since, look again'));
88
+ return said(run);
89
+ }
90
+ finally {
91
+ rmSync(dir, { recursive: true, force: true });
92
+ }
93
+ }
94
+ /** A conflicted file taken as one side wrote it and marked resolved; a side
95
+ * that deleted it deletes it. */
96
+ export async function resolveConflict(base, rel, side) {
97
+ const run = await git(base, ['--literal-pathspecs', 'checkout', side === 'current' ? '--ours' : '--theirs', '--', rel]);
98
+ if (!run.ok) {
99
+ if (!/does not have (our|their) version/.test(run.stderr))
100
+ throw new Error(failure(run, 'git checkout failed'));
101
+ const removed = await git(base, ['--literal-pathspecs', 'rm', '-q', '--', rel]);
102
+ if (!removed.ok)
103
+ throw new Error(failure(removed, 'git rm failed'));
104
+ return `${rel} deleted, as the ${side} side has it`;
105
+ }
106
+ const added = await git(base, ['--literal-pathspecs', 'add', '--', rel]);
107
+ if (!added.ok)
108
+ throw new Error(failure(added, 'git add failed'));
109
+ return `${rel} taken from the ${side} side`;
110
+ }
111
+ /** Conflicted files marked resolved as they are on disk, once none of them
112
+ * holds conflict markers any more. */
113
+ export async function markResolved(base, paths, conflicted) {
114
+ if (!paths.length)
115
+ throw new Error('Nothing to mark resolved');
116
+ const stray = paths.filter(p => !conflicted.includes(p));
117
+ if (stray.length)
118
+ throw new Error(`No conflict in ${stray.join(', ')}`);
119
+ const marked = paths.filter((p) => {
120
+ try {
121
+ return /^<{7} |^>{7} /m.test(readFileSync(join(base, p), 'utf8'));
122
+ }
123
+ catch {
124
+ return false;
125
+ }
126
+ });
127
+ if (marked.length)
128
+ throw new Error(`Still conflict markers in ${marked.join(', ')}`);
129
+ const run = await git(base, ['--literal-pathspecs', 'add', '-A', '--', ...paths]);
130
+ if (!run.ok)
131
+ throw new Error(failure(run, 'git add failed'));
132
+ return `${paths.length} marked resolved`;
133
+ }
@@ -0,0 +1,16 @@
1
+ import type { FsGitAction } from '@nordhavnhq/runner-runtime';
2
+ import type { Config } from '../config.js';
3
+ /** The message a discard stashes its changes under. */
4
+ export declare const DISCARD_STASH_MESSAGE = "Discarded in Code";
5
+ /**
6
+ * Do `action` in the checkout as `by`. Returns what git said, and the commit
7
+ * when it made one. Throws what git said when it refused (a
8
+ * `MissingImportsError` for a commit that would leave an import behind).
9
+ */
10
+ export declare function checkoutGit(config: Config, root: string, action: FsGitAction, by: {
11
+ name: string;
12
+ email: string;
13
+ }): Promise<{
14
+ output: string;
15
+ sha?: string;
16
+ }>;
@@ -0,0 +1,424 @@
1
+ import { spawnSync } from 'node:child_process';
2
+ import { appendFileSync, existsSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
3
+ import { tmpdir } from 'node:os';
4
+ import { join, relative, sep } from 'node:path';
5
+ import { findMissingImports, missingFrom, MissingImportsError, repoTop, restoreIndex, snapshotIndex, stagedFiles } from '../tools/commit-guard.js';
6
+ import { commitOf, conflictsOf, exists, failure, git, inside, isPushed, operationOf, remotesOf, repo, said } from './fs-checkout.js';
7
+ import { applyPatch, markResolved, resolveConflict, unstage } from './fs-git-index.js';
8
+ // ─── What a person does with git in a checkout, from the code app ──
9
+ //
10
+ // One `fs:git` frame per action (`FsGitAction`), done in the checkout as the
11
+ // runner's own git would: its credentials, its hooks, its config. The person
12
+ // who pressed it (`by`) is the author of what it commits. Some care, because
13
+ // agents may be working in the same folder: nothing is forced past
14
+ // `--force-with-lease`, what is discarded is stashed first ("Discarded in
15
+ // Code"), a branch is only switched while nothing is changed, and a pushed
16
+ // commit is never undone. Every argument a person typed (a branch, a tag, a
17
+ // path, a commit) is checked before it reaches git, so none reads as an
18
+ // option.
19
+ /** How long a commit (its hooks), a push or a fetch may take. */
20
+ const GIT_WRITE_TIMEOUT_MS = 120_000;
21
+ /** The message a discard stashes its changes under. */
22
+ export const DISCARD_STASH_MESSAGE = 'Discarded in Code';
23
+ /** Every author line of a commit: no line breaks, no angle brackets. */
24
+ const oneLine = (text) => text.replace(/[\r\n<>]/g, ' ').trim();
25
+ /** A branch name git takes, or an error. */
26
+ function branchName(name) {
27
+ if (!name || name.startsWith('-') || spawnSync('git', ['check-ref-format', '--branch', name], { timeout: 5000 }).status !== 0) {
28
+ throw new Error(`"${name}" is not a branch name git takes`);
29
+ }
30
+ return name;
31
+ }
32
+ /** A branch to act on: a local one by its name, or a full ref of a local or
33
+ * remote one. Returns it as git takes it, or an error when it is not here. */
34
+ async function branchRef(base, ref) {
35
+ const full = ref.startsWith('refs/') ? ref : `refs/heads/${branchName(ref)}`;
36
+ if (!/^refs\/(heads|remotes)\//.test(full) || !(await exists(base, full)))
37
+ throw new Error('No such branch in the checkout');
38
+ return full;
39
+ }
40
+ /** Paths a person picked, relative to the checkout, never git's own. */
41
+ function pathsIn(base, paths) {
42
+ return paths.map((p) => {
43
+ const rel = relative(base, inside(base, p)).split(sep).join('/');
44
+ if (!rel || rel.split('/').includes('.git'))
45
+ throw new Error('Git\'s own files are not touched from here.');
46
+ return rel;
47
+ });
48
+ }
49
+ /** Whether anything in the repository is changed, untracked files included. */
50
+ async function isDirty(base) {
51
+ return !!(await git(base, ['status', '--porcelain', '--untracked-files=normal', '--', ':/'])).stdout.trim();
52
+ }
53
+ /** git that writes: a longer clock, the author for what it commits, never an
54
+ * editor (a merge, a revert take their own message). */
55
+ function write(base, args, by) {
56
+ const name = oneLine(by.name);
57
+ const email = oneLine(by.email);
58
+ return git(base, args, {
59
+ timeout: GIT_WRITE_TIMEOUT_MS,
60
+ env: { GIT_AUTHOR_NAME: name, GIT_AUTHOR_EMAIL: email, GIT_COMMITTER_NAME: name, GIT_COMMITTER_EMAIL: email, GIT_EDITOR: 'true', GIT_MERGE_AUTOEDIT: 'no' },
61
+ });
62
+ }
63
+ const done = (run, fallback) => {
64
+ if (!run.ok)
65
+ throw new Error(failure(run, fallback));
66
+ return said(run);
67
+ };
68
+ /** A step that may stop on a conflict: then it is open (the state says so)
69
+ * rather than failed. */
70
+ async function mayConflict(base, run, fallback) {
71
+ if (run.ok)
72
+ return said(run);
73
+ if (await operationOf(base))
74
+ return said(run);
75
+ throw new Error(failure(run, fallback));
76
+ }
77
+ const headSha = async (base) => (await git(base, ['rev-parse', 'HEAD'])).stdout.trim();
78
+ async function parentsOf(base, sha) {
79
+ const run = await git(base, ['rev-list', '--parents', '-n', '1', sha]);
80
+ return Math.max(0, run.stdout.trim().split(' ').length - 1);
81
+ }
82
+ /** The checked-out branch, or an error while the head is detached. */
83
+ async function currentBranch(base) {
84
+ const run = await git(base, ['symbolic-ref', '--quiet', '--short', 'HEAD']);
85
+ if (!run.ok)
86
+ throw new Error('The head is detached: there is no branch checked out');
87
+ return run.stdout.trim();
88
+ }
89
+ /** Push the current branch, and with `--follow-tags` the annotated tags on
90
+ * the commits it pushes (a tag drafted for the unpushed work goes along). */
91
+ async function push(base, force, by) {
92
+ const branch = await currentBranch(base);
93
+ const remote = (await git(base, ['config', `branch.${branch}.remote`])).stdout.trim();
94
+ const merge = (await git(base, ['config', `branch.${branch}.merge`])).stdout.trim();
95
+ const flags = [...(force ? ['--force-with-lease'] : []), '--follow-tags'];
96
+ if (remote && remote !== '.' && merge) {
97
+ return done(await write(base, ['push', '--porcelain', ...flags, remote, `refs/heads/${branch}:${merge}`], by), 'git push failed');
98
+ }
99
+ const remotes = await remotesOf(base);
100
+ const target = remotes.length === 1 ? remotes[0].name : remotes.find(r => r.name === 'origin')?.name;
101
+ if (!target)
102
+ throw new Error(remotes.length ? 'The branch follows no remote branch, and there is no origin to push to' : 'The checkout has no remote');
103
+ return done(await write(base, ['push', '--porcelain', ...flags, '--set-upstream', target, `refs/heads/${branch}:refs/heads/${branch}`], by), 'git push failed');
104
+ }
105
+ /** Switch to a branch; a remote one makes (or takes) the local branch of the
106
+ * same name that follows it. Only while nothing is changed. */
107
+ async function switchTo(base, ref, by) {
108
+ const full = await branchRef(base, ref);
109
+ if (await isDirty(base))
110
+ throw new Error('Commit or stash the changes first: a branch is only switched while nothing is changed');
111
+ if (full.startsWith('refs/heads/'))
112
+ return done(await write(base, ['switch', full.slice('refs/heads/'.length)], by), 'git switch failed');
113
+ const short = full.slice('refs/remotes/'.length);
114
+ const remote = (await remotesOf(base)).find(r => short.startsWith(`${r.name}/`));
115
+ const local = remote ? short.slice(remote.name.length + 1) : short.split('/').slice(1).join('/');
116
+ if (await exists(base, `refs/heads/${local}`))
117
+ return done(await write(base, ['switch', local], by), 'git switch failed');
118
+ return done(await write(base, ['switch', '--track', '-c', branchName(local), short], by), 'git switch failed');
119
+ }
120
+ /** Finish the merge, rebase, cherry-pick or revert that is open, once no file
121
+ * holds conflict markers any more: the files that had a conflict are taken
122
+ * as resolved. */
123
+ async function finish(base, by) {
124
+ const operation = await operationOf(base);
125
+ if (!operation)
126
+ throw new Error('Nothing is open to continue');
127
+ const conflicted = await conflictsOf(base);
128
+ const marked = conflicted.filter((p) => {
129
+ try {
130
+ return /^<{7} |^>{7} /m.test(readFileSync(join(base, p), 'utf8'));
131
+ }
132
+ catch {
133
+ return false;
134
+ }
135
+ });
136
+ if (marked.length)
137
+ throw new Error(`Still conflicts in ${marked.join(', ')}`);
138
+ if (conflicted.length)
139
+ done(await git(base, ['--literal-pathspecs', 'add', '--', ...conflicted]), 'git add failed');
140
+ if (operation === 'merge')
141
+ return done(await write(base, ['commit', '--no-edit'], by), 'git commit failed');
142
+ return mayConflict(base, await write(base, [operation, '--continue'], by), `git ${operation} --continue failed`);
143
+ }
144
+ /** Commit what is staged (`staged`), only `paths` (`git commit -- <paths>`:
145
+ * whatever else is staged stays staged and out of the commit), or all changes
146
+ * (null). Refused with a
147
+ * `MissingImportsError` (paths relative to the checkout) when a committed
148
+ * file imports an untracked file the commit leaves out (commit-guard.ts),
149
+ * unless `allowMissingImports`; what the refused commit staged is unstaged
150
+ * again. */
151
+ async function commit(base, action, by) {
152
+ await assertSomethingToCommit(base, action);
153
+ const only = !action.staged && action.paths?.length ? pathsIn(base, action.paths) : null;
154
+ const add = commitAddArgs(action, only);
155
+ const top = action.allowMissingImports ? null : await repoTop(base);
156
+ const snapshot = top ? await snapshotIndex(top) : null;
157
+ if (add)
158
+ done(await git(base, add, { timeout: 60_000 }), 'git add failed');
159
+ if (top)
160
+ await guardMissingImports(base, top, snapshot, action, only);
161
+ const output = done(await write(base, commitArgs(action, only), by), 'git commit failed');
162
+ return { output, sha: await headSha(base) };
163
+ }
164
+ /** Refuses a commit without a message, or one that would hold nothing (an
165
+ * amend may hold nothing new). */
166
+ async function assertSomethingToCommit(base, action) {
167
+ if (!action.message.trim())
168
+ throw new Error('A commit needs a message');
169
+ if (action.staged) {
170
+ const staged = await hasStaged(base);
171
+ if (!staged && !action.amend)
172
+ throw new Error('Nothing is staged');
173
+ }
174
+ else if (action.paths && !action.paths.length && !action.amend)
175
+ throw new Error('Nothing to commit');
176
+ }
177
+ /** Whether anything is staged in the repository of `base`. */
178
+ async function hasStaged(base) {
179
+ // `diff --cached --quiet` says 1 when something is staged.
180
+ const born = await exists(base, 'HEAD');
181
+ return born ? !(await git(base, ['diff', '--cached', '--quiet', 'HEAD', '--', ':/'])).ok : !!(await git(base, ['ls-files', '--', ':/'])).stdout.trim();
182
+ }
183
+ /** The `git add` a commit needs first: none for what is staged or an empty
184
+ * path list, the selected paths, or every change. */
185
+ function commitAddArgs(action, only) {
186
+ if (action.staged)
187
+ return null;
188
+ if (only)
189
+ return ['--literal-pathspecs', 'add', '-A', '--', ...only];
190
+ return action.paths ? null : ['add', '-A', '--', '.'];
191
+ }
192
+ /** Throws a `MissingImportsError` when a committed file imports an untracked
193
+ * file the commit leaves out, after putting the index back as `snapshot`
194
+ * had it. */
195
+ async function guardMissingImports(base, top, snapshot, action, only) {
196
+ const committed = await stagedFiles(top, { amend: action.amend, ...(only ? { paths: only, cwd: base } : {}) });
197
+ const missing = await findMissingImports(top, committed);
198
+ if (!missing.length)
199
+ return;
200
+ await restoreIndex(top, snapshot);
201
+ throw new MissingImportsError(await missingFrom(base, missing));
202
+ }
203
+ /** The `git commit` arguments: only the selected paths when there are any. */
204
+ function commitArgs(action, only) {
205
+ const pathspec = only ? ['--', ...only] : [];
206
+ return [...(only ? ['--literal-pathspecs'] : []), 'commit', ...(action.amend ? ['--amend'] : []), '-m', action.message, ...pathspec];
207
+ }
208
+ /**
209
+ * Do `action` in the checkout as `by`. Returns what git said, and the commit
210
+ * when it made one. Throws what git said when it refused (a
211
+ * `MissingImportsError` for a commit that would leave an import behind).
212
+ */
213
+ export async function checkoutGit(config, root, action, by) {
214
+ const base = await repo(config, root);
215
+ if (!oneLine(by.name) || !oneLine(by.email))
216
+ throw new Error('Somebody has to do it');
217
+ switch (action.kind) {
218
+ case 'commit':
219
+ return commit(base, action, by);
220
+ case 'undo-commit': {
221
+ if (!(await exists(base, 'HEAD')))
222
+ throw new Error('There is no commit to undo');
223
+ if (await isPushed(base, 'HEAD'))
224
+ throw new Error('The last commit is pushed: revert it instead');
225
+ if (await parentsOf(base, 'HEAD') === 0)
226
+ throw new Error('The first commit is not undone here');
227
+ return { output: done(await git(base, ['reset', '--soft', 'HEAD~1']), 'git reset failed') };
228
+ }
229
+ case 'push':
230
+ return { output: await push(base, action.force, by) };
231
+ case 'pull': {
232
+ if (action.rebase) {
233
+ // What is changed is set aside for the replay and put back after.
234
+ return { output: await mayConflict(base, await write(base, ['pull', '--rebase', '--autostash'], by), 'git pull failed') };
235
+ }
236
+ // Git asks how to join branches that ran apart unless the config says.
237
+ const configured = (await git(base, ['config', 'pull.rebase'])).ok;
238
+ const run = await write(base, ['pull', '--no-edit', ...(configured ? [] : ['--no-rebase'])], by);
239
+ return { output: await mayConflict(base, run, 'git pull failed') };
240
+ }
241
+ case 'stage': {
242
+ if (!action.paths.length)
243
+ throw new Error('Nothing to stage');
244
+ return { output: done(await git(base, ['--literal-pathspecs', 'add', '-A', '--', ...pathsIn(base, action.paths)], { timeout: 60_000 }), 'git add failed') };
245
+ }
246
+ case 'unstage':
247
+ return { output: await unstage(base, pathsIn(base, action.paths)) };
248
+ case 'apply-patch': {
249
+ const [rel] = pathsIn(base, [action.path]);
250
+ if (action.target === 'worktree') {
251
+ if (!action.reverse)
252
+ throw new Error('Only a discard is applied to the files on disk');
253
+ // Stashed rather than thrown away, the files on disk left as they are.
254
+ const kept = (await git(base, ['stash', 'create', DISCARD_STASH_MESSAGE])).stdout.trim();
255
+ if (kept)
256
+ done(await git(base, ['stash', 'store', '-m', DISCARD_STASH_MESSAGE, kept]), 'git stash failed');
257
+ }
258
+ return { output: await applyPatch(base, rel, action.patch, { cached: action.target === 'index', reverse: action.reverse }) };
259
+ }
260
+ case 'reset': {
261
+ const sha = await commitOf(base, action.sha);
262
+ if (action.mode === 'hard' && !(await git(base, ['diff', 'HEAD', '--quiet', '--', ':/'])).ok) {
263
+ // What a hard reset throws away is stashed first.
264
+ done(await write(base, ['stash', 'push', '-m', 'Reset in Code', '--', ':/'], by), 'git stash failed');
265
+ }
266
+ return { output: done(await git(base, ['reset', `--${action.mode}`, '-q', sha]), 'git reset failed') || `Reset to ${sha.slice(0, 7)}`, sha };
267
+ }
268
+ case 'checkout': {
269
+ const sha = await commitOf(base, action.sha);
270
+ if (await isDirty(base))
271
+ throw new Error('Commit or stash the changes first: a commit is only checked out while nothing is changed');
272
+ return { output: done(await write(base, ['switch', '--detach', sha], by), 'git switch failed'), sha };
273
+ }
274
+ case 'reword': {
275
+ if (!action.message.trim())
276
+ throw new Error('A commit needs a message');
277
+ if (!(await exists(base, 'HEAD')))
278
+ throw new Error('There is no commit to reword');
279
+ if (await isPushed(base, 'HEAD'))
280
+ throw new Error('The last commit is pushed: its message is not rewritten here');
281
+ // `--only` without paths: the message alone, whatever is staged.
282
+ const output = done(await write(base, ['commit', '--amend', '--only', '--allow-empty', '-m', action.message], by), 'git commit failed');
283
+ return { output, sha: await headSha(base) };
284
+ }
285
+ case 'rebase': {
286
+ const onto = await branchRef(base, action.ref);
287
+ await currentBranch(base);
288
+ if (await isDirty(base))
289
+ throw new Error('Commit or stash the changes first: a branch is only rebased while nothing is changed');
290
+ const run = await write(base, ['rebase', onto], by);
291
+ return { output: await mayConflict(base, run, 'git rebase failed'), sha: await headSha(base) };
292
+ }
293
+ case 'resolve': {
294
+ const [rel] = pathsIn(base, [action.path]);
295
+ if (!(await conflictsOf(base)).includes(rel))
296
+ throw new Error(`${rel} has no conflict`);
297
+ return { output: await resolveConflict(base, rel, action.side) };
298
+ }
299
+ case 'mark-resolved':
300
+ return { output: await markResolved(base, pathsIn(base, action.paths), await conflictsOf(base)) };
301
+ case 'delete-tag': {
302
+ if (!action.name || action.name.startsWith('-') || spawnSync('git', ['check-ref-format', `refs/tags/${action.name}`], { timeout: 5000 }).status !== 0) {
303
+ throw new Error(`"${action.name}" is not a tag name git takes`);
304
+ }
305
+ if (!(await exists(base, `refs/tags/${action.name}`)))
306
+ throw new Error(`No tag "${action.name}" in the checkout`);
307
+ let output = '';
308
+ if (action.remote) {
309
+ const remotes = await remotesOf(base);
310
+ const target = remotes.find(r => r.name === 'origin')?.name ?? (remotes.length === 1 ? remotes[0].name : undefined);
311
+ if (!target)
312
+ throw new Error('The checkout has no origin to delete the tag from');
313
+ output = done(await write(base, ['push', '--porcelain', target, `:refs/tags/${action.name}`], by), 'git push failed');
314
+ }
315
+ return { output: [output, done(await git(base, ['tag', '-d', action.name]), 'git tag failed')].filter(Boolean).join('\n') };
316
+ }
317
+ case 'fetch':
318
+ return { output: done(await git(base, ['fetch', '--all', '--prune'], { timeout: GIT_WRITE_TIMEOUT_MS }), 'git fetch failed') };
319
+ case 'switch':
320
+ return { output: await switchTo(base, action.ref, by) };
321
+ case 'create-branch': {
322
+ const from = action.from === null ? [] : [action.from.startsWith('refs/') ? await branchRef(base, action.from) : await commitOf(base, action.from)];
323
+ return { output: done(await write(base, ['switch', '-c', branchName(action.name), ...from], by), 'git switch failed') };
324
+ }
325
+ case 'rename-branch':
326
+ await branchRef(base, action.name);
327
+ return { output: done(await git(base, ['branch', '-m', action.name, branchName(action.to)]), 'git branch failed') };
328
+ case 'delete-branch':
329
+ await branchRef(base, action.name);
330
+ return { output: done(await git(base, ['branch', action.force ? '-D' : '-d', action.name]), 'git branch failed') };
331
+ case 'merge': {
332
+ const run = await write(base, ['merge', '--no-edit', await branchRef(base, action.ref)], by);
333
+ return { output: await mayConflict(base, run, 'git merge failed') };
334
+ }
335
+ case 'abort': {
336
+ const operation = await operationOf(base);
337
+ if (!operation)
338
+ throw new Error('Nothing is open to abort');
339
+ return { output: done(await git(base, [operation, '--abort']), `git ${operation} --abort failed`) };
340
+ }
341
+ case 'continue': {
342
+ const output = await finish(base, by);
343
+ return { output, sha: await headSha(base) };
344
+ }
345
+ case 'discard': {
346
+ // Stashed rather than thrown away: the stash list holds it. Each path
347
+ // literal by its own magic: `stash` with `--literal-pathspecs` loses
348
+ // the folder it runs in.
349
+ const paths = action.paths ? pathsIn(base, action.paths).map(p => `:(literal)${p}`) : ['.'];
350
+ if (!paths.length)
351
+ throw new Error('Nothing to discard');
352
+ return { output: done(await write(base, ['stash', 'push', '--include-untracked', '-m', DISCARD_STASH_MESSAGE, '--', ...paths], by), 'git stash failed') };
353
+ }
354
+ case 'ignore': {
355
+ const [rel] = pathsIn(base, [action.path]);
356
+ const file = join(base, '.gitignore');
357
+ const text = existsSync(file) ? readFileSync(file, 'utf8') : '';
358
+ const line = `/${rel}`;
359
+ if (!text.split('\n').includes(line))
360
+ appendFileSync(file, `${text && !text.endsWith('\n') ? '\n' : ''}${line}\n`);
361
+ return { output: `${line} added to .gitignore` };
362
+ }
363
+ case 'stash': {
364
+ const untracked = action.includeUntracked === false ? [] : ['--include-untracked'];
365
+ return { output: done(await write(base, ['stash', 'push', ...untracked, ...(action.message ? ['-m', action.message] : []), '--', '.'], by), 'git stash failed') };
366
+ }
367
+ case 'stash-apply':
368
+ case 'stash-drop': {
369
+ if (!Number.isInteger(action.index) || action.index < 0)
370
+ throw new Error('No such stash');
371
+ const verb = action.kind === 'stash-drop' ? 'drop' : action.drop ? 'pop' : 'apply';
372
+ return { output: await mayConflict(base, await write(base, ['stash', verb, `stash@{${action.index}}`], by), `git stash ${verb} failed`) };
373
+ }
374
+ case 'revert':
375
+ case 'cherry-pick': {
376
+ const sha = await commitOf(base, action.sha);
377
+ const mainline = await parentsOf(base, sha) > 1 ? ['-m', '1'] : [];
378
+ const run = await write(base, [action.kind, ...(action.kind === 'revert' ? ['--no-edit'] : []), ...mainline, sha], by);
379
+ return { output: await mayConflict(base, run, `git ${action.kind} failed`), sha: await headSha(base) };
380
+ }
381
+ case 'tag': {
382
+ const sha = await commitOf(base, action.sha);
383
+ if (!action.name || action.name.startsWith('-') || spawnSync('git', ['check-ref-format', `refs/tags/${action.name}`], { timeout: 5000 }).status !== 0) {
384
+ throw new Error(`"${action.name}" is not a tag name git takes`);
385
+ }
386
+ // A tag is never moved or overwritten.
387
+ if (await exists(base, `refs/tags/${action.name}`))
388
+ throw new Error(`The tag "${action.name}" already exists`);
389
+ if (!action.message)
390
+ return { output: done(await git(base, ['tag', action.name, sha]), 'git tag failed') };
391
+ // Annotated: the message is the release notes, the tagger is the person
392
+ // who decided (never the repo config). `whitespace` keeps the release
393
+ // notes' `###` headings, which the default cleanup strips as comments.
394
+ if (!action.tagger)
395
+ throw new Error('An annotated tag needs a tagger');
396
+ const dir = mkdtempSync(join(tmpdir(), 'nordhavn-tag-'));
397
+ try {
398
+ const file = join(dir, 'message');
399
+ writeFileSync(file, action.message);
400
+ const name = oneLine(action.tagger.name);
401
+ const email = oneLine(action.tagger.email);
402
+ const run = await git(base, ['-c', `user.name=${name}`, '-c', `user.email=${email}`, 'tag', '-a', '--cleanup=whitespace', action.name, '-F', file, sha], {
403
+ env: { GIT_COMMITTER_NAME: name, GIT_COMMITTER_EMAIL: email },
404
+ });
405
+ return { output: done(run, 'git tag failed'), sha };
406
+ }
407
+ finally {
408
+ rmSync(dir, { recursive: true, force: true });
409
+ }
410
+ }
411
+ case 'push-tag': {
412
+ if (!action.name || action.name.startsWith('-') || spawnSync('git', ['check-ref-format', `refs/tags/${action.name}`], { timeout: 5000 }).status !== 0) {
413
+ throw new Error(`"${action.name}" is not a tag name git takes`);
414
+ }
415
+ if (!(await exists(base, `refs/tags/${action.name}`)))
416
+ throw new Error(`No tag "${action.name}" in the checkout`);
417
+ const remotes = await remotesOf(base);
418
+ const target = remotes.find(r => r.name === 'origin')?.name ?? (remotes.length === 1 ? remotes[0].name : undefined);
419
+ if (!target)
420
+ throw new Error('The checkout has no origin to push the tag to');
421
+ return { output: done(await write(base, ['push', '--porcelain', target, `refs/tags/${action.name}:refs/tags/${action.name}`], by), 'git push failed') };
422
+ }
423
+ }
424
+ }
@@ -0,0 +1,46 @@
1
+ import type { GitRelayStatus, RelayPushFrame } from '@nordhavnhq/runner-runtime';
2
+ /** Largest bundle carried (bytes, decoded). */
3
+ export declare const RELAY_BUNDLE_MAX_BYTES: number;
4
+ /** Pushes per minute before the relay refuses (against a flood of dialogs). */
5
+ export declare const RELAY_PUSHES_PER_MINUTE = 6;
6
+ /** Asks the person; true only on an explicit yes. */
7
+ type Confirm = (title: string, message: string, allow: string) => Promise<boolean>;
8
+ export interface RelayDeps {
9
+ /** Where the relay keeps its state and mirrors. */
10
+ dir: string;
11
+ confirm: Confirm;
12
+ /** Whether `confirm` can ask on this machine at all. */
13
+ canConfirm: boolean;
14
+ /** The URL pushed to for a GitHub repo (tests point it elsewhere). */
15
+ remoteUrl: (owner: string, repo: string) => string;
16
+ /** Who GitHub says the key is; null when it does not authenticate. */
17
+ githubLogin: () => Promise<string | null>;
18
+ /** The machine's git identity (`user.name`, `user.email`). */
19
+ gitIdentity: () => Promise<{
20
+ name: string;
21
+ email: string;
22
+ } | null>;
23
+ }
24
+ export declare function relayStatus(deps?: RelayDeps): GitRelayStatus;
25
+ /** The person `byName` asks to pair this machine. Asks them here, tests the
26
+ * key against GitHub, keeps the result. Throws when refused or the key does
27
+ * not work. */
28
+ export declare function relayConnect(byName: string, deps?: RelayDeps): Promise<GitRelayStatus>;
29
+ /** Unpair, without asking: giving access up is never gated. */
30
+ export declare function relayDisconnect(deps?: RelayDeps): GitRelayStatus;
31
+ /** Tests only: forget the pushes of this minute. */
32
+ export declare function resetRelayLimits(): void;
33
+ /** Owner and repo of a GitHub remote URL, or an error. */
34
+ export declare function githubRepo(remote: string): {
35
+ owner: string;
36
+ repo: string;
37
+ };
38
+ /** The branch an agent may push to through the relay, or an error. */
39
+ export declare function relayBranch(branch: string): string;
40
+ /** Push what an agent committed elsewhere, after the person's click. Returns
41
+ * git's output and the pushed sha. */
42
+ export declare function relayPush(frame: Pick<RelayPushFrame, 'agent' | 'remote' | 'branch' | 'bundle'>, deps?: RelayDeps): Promise<{
43
+ output: string;
44
+ sha: string;
45
+ }>;
46
+ export {};