@nordhavnhq/runner 0.0.0-stage → 0.96.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/cliclick +0 -0
- package/dist/brand.d.ts +5 -0
- package/dist/brand.js +18 -0
- package/dist/cli/agent.d.ts +9 -0
- package/dist/cli/agent.js +39 -0
- package/dist/cli/folder.d.ts +2 -0
- package/dist/cli/folder.js +103 -0
- package/dist/cli/init.d.ts +2 -0
- package/dist/cli/init.js +67 -0
- package/dist/cli/lifecycle.d.ts +3 -0
- package/dist/cli/lifecycle.js +149 -0
- package/dist/cli/link.d.ts +20 -0
- package/dist/cli/link.js +312 -0
- package/dist/cli/logs.d.ts +2 -0
- package/dist/cli/logs.js +144 -0
- package/dist/cli/prompts.d.ts +7 -0
- package/dist/cli/prompts.js +13 -0
- package/dist/cli/ps.d.ts +2 -0
- package/dist/cli/ps.js +80 -0
- package/dist/cli/relay.d.ts +4 -0
- package/dist/cli/relay.js +29 -0
- package/dist/cli/update.d.ts +6 -0
- package/dist/cli/update.js +131 -0
- package/dist/config.d.ts +166 -0
- package/dist/config.js +383 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +135 -0
- package/dist/legacy-env.d.ts +4 -0
- package/dist/legacy-env.js +32 -0
- package/dist/paths.d.ts +37 -0
- package/dist/paths.js +92 -0
- package/dist/runtime/daemon.d.ts +57 -0
- package/dist/runtime/daemon.js +159 -0
- package/dist/runtime/dev-start.d.ts +31 -0
- package/dist/runtime/dev-start.js +110 -0
- package/dist/runtime/file-claims.d.ts +58 -0
- package/dist/runtime/file-claims.js +174 -0
- package/dist/runtime/fs-browse.d.ts +18 -0
- package/dist/runtime/fs-browse.js +104 -0
- package/dist/runtime/fs-checkout.d.ts +154 -0
- package/dist/runtime/fs-checkout.js +1049 -0
- package/dist/runtime/fs-git-index.d.ts +22 -0
- package/dist/runtime/fs-git-index.js +133 -0
- package/dist/runtime/fs-git.d.ts +16 -0
- package/dist/runtime/fs-git.js +424 -0
- package/dist/runtime/git-relay.d.ts +46 -0
- package/dist/runtime/git-relay.js +259 -0
- package/dist/runtime/git-unpushed.d.ts +36 -0
- package/dist/runtime/git-unpushed.js +93 -0
- package/dist/runtime/node-version.d.ts +12 -0
- package/dist/runtime/node-version.js +39 -0
- package/dist/runtime/preview-tunnel.d.ts +16 -0
- package/dist/runtime/preview-tunnel.js +135 -0
- package/dist/runtime/processes.d.ts +61 -0
- package/dist/runtime/processes.js +408 -0
- package/dist/runtime/project-node-download.d.ts +17 -0
- package/dist/runtime/project-node-download.js +137 -0
- package/dist/runtime/project-node.d.ts +65 -0
- package/dist/runtime/project-node.js +223 -0
- package/dist/runtime/reap-scratch.d.ts +22 -0
- package/dist/runtime/reap-scratch.js +112 -0
- package/dist/runtime/spill-tool-output.d.ts +14 -0
- package/dist/runtime/spill-tool-output.js +84 -0
- package/dist/runtime/up.d.ts +6 -0
- package/dist/runtime/up.js +1324 -0
- package/dist/tools/_coerce.d.ts +2 -0
- package/dist/tools/_coerce.js +26 -0
- package/dist/tools/_commit-scope.d.ts +14 -0
- package/dist/tools/_commit-scope.js +70 -0
- package/dist/tools/_jail.d.ts +68 -0
- package/dist/tools/_jail.js +209 -0
- package/dist/tools/_output.d.ts +24 -0
- package/dist/tools/_output.js +48 -0
- package/dist/tools/_ripgrep.d.ts +46 -0
- package/dist/tools/_ripgrep.js +148 -0
- package/dist/tools/_run-worktree.d.ts +10 -0
- package/dist/tools/_run-worktree.js +27 -0
- package/dist/tools/_shell-words.d.ts +15 -0
- package/dist/tools/_shell-words.js +43 -0
- package/dist/tools/_sonar/astro.d.ts +6 -0
- package/dist/tools/_sonar/astro.js +45 -0
- package/dist/tools/_sonar/blade.d.ts +3 -0
- package/dist/tools/_sonar/blade.js +53 -0
- package/dist/tools/_sonar/build.d.ts +44 -0
- package/dist/tools/_sonar/build.js +147 -0
- package/dist/tools/_sonar/changed.d.ts +21 -0
- package/dist/tools/_sonar/changed.js +230 -0
- package/dist/tools/_sonar/diagnose/delta.d.ts +27 -0
- package/dist/tools/_sonar/diagnose/delta.js +64 -0
- package/dist/tools/_sonar/diagnose/detect.d.ts +39 -0
- package/dist/tools/_sonar/diagnose/detect.js +117 -0
- package/dist/tools/_sonar/diagnose/index.d.ts +13 -0
- package/dist/tools/_sonar/diagnose/index.js +217 -0
- package/dist/tools/_sonar/diagnose/lint-worker.d.ts +1 -0
- package/dist/tools/_sonar/diagnose/lint-worker.js +48 -0
- package/dist/tools/_sonar/diagnose/pool.d.ts +22 -0
- package/dist/tools/_sonar/diagnose/pool.js +149 -0
- package/dist/tools/_sonar/diagnose/rules.d.ts +23 -0
- package/dist/tools/_sonar/diagnose/rules.js +131 -0
- package/dist/tools/_sonar/diagnose/types-worker.d.ts +1 -0
- package/dist/tools/_sonar/diagnose/types-worker.js +183 -0
- package/dist/tools/_sonar/files.d.ts +14 -0
- package/dist/tools/_sonar/files.js +121 -0
- package/dist/tools/_sonar/graph.d.ts +34 -0
- package/dist/tools/_sonar/graph.js +164 -0
- package/dist/tools/_sonar/hints.d.ts +116 -0
- package/dist/tools/_sonar/hints.js +545 -0
- package/dist/tools/_sonar/imports.d.ts +38 -0
- package/dist/tools/_sonar/imports.js +275 -0
- package/dist/tools/_sonar/index.d.ts +79 -0
- package/dist/tools/_sonar/index.js +462 -0
- package/dist/tools/_sonar/keys.d.ts +5 -0
- package/dist/tools/_sonar/keys.js +248 -0
- package/dist/tools/_sonar/laravel-routes.d.ts +15 -0
- package/dist/tools/_sonar/laravel-routes.js +263 -0
- package/dist/tools/_sonar/laravel.d.ts +64 -0
- package/dist/tools/_sonar/laravel.js +326 -0
- package/dist/tools/_sonar/location.d.ts +33 -0
- package/dist/tools/_sonar/location.js +137 -0
- package/dist/tools/_sonar/map.d.ts +43 -0
- package/dist/tools/_sonar/map.js +212 -0
- package/dist/tools/_sonar/parse.d.ts +3 -0
- package/dist/tools/_sonar/parse.js +76 -0
- package/dist/tools/_sonar/prewarm.d.ts +9 -0
- package/dist/tools/_sonar/prewarm.js +96 -0
- package/dist/tools/_sonar/prisma.d.ts +9 -0
- package/dist/tools/_sonar/prisma.js +51 -0
- package/dist/tools/_sonar/refs.d.ts +7 -0
- package/dist/tools/_sonar/refs.js +273 -0
- package/dist/tools/_sonar/render.d.ts +66 -0
- package/dist/tools/_sonar/render.js +498 -0
- package/dist/tools/_sonar/resolve.d.ts +63 -0
- package/dist/tools/_sonar/resolve.js +402 -0
- package/dist/tools/_sonar/roots.d.ts +4 -0
- package/dist/tools/_sonar/roots.js +42 -0
- package/dist/tools/_sonar/routes.d.ts +5 -0
- package/dist/tools/_sonar/routes.js +247 -0
- package/dist/tools/_sonar/serve.d.ts +12 -0
- package/dist/tools/_sonar/serve.js +104 -0
- package/dist/tools/_sonar/suggest.d.ts +23 -0
- package/dist/tools/_sonar/suggest.js +114 -0
- package/dist/tools/_sonar/tests.d.ts +21 -0
- package/dist/tools/_sonar/tests.js +134 -0
- package/dist/tools/_sonar/tsconfig.d.ts +34 -0
- package/dist/tools/_sonar/tsconfig.js +188 -0
- package/dist/tools/_sonar/types.d.ts +81 -0
- package/dist/tools/_sonar/types.js +6 -0
- package/dist/tools/_symbols.d.ts +27 -0
- package/dist/tools/_symbols.js +461 -0
- package/dist/tools/_test-report.d.ts +47 -0
- package/dist/tools/_test-report.js +203 -0
- package/dist/tools/_touched.d.ts +44 -0
- package/dist/tools/_touched.js +195 -0
- package/dist/tools/_upload.d.ts +26 -0
- package/dist/tools/_upload.js +132 -0
- package/dist/tools/_worktree-setup.d.ts +29 -0
- package/dist/tools/_worktree-setup.js +204 -0
- package/dist/tools/browser.d.ts +2 -0
- package/dist/tools/browser.js +8 -0
- package/dist/tools/commit-guard.d.ts +44 -0
- package/dist/tools/commit-guard.js +165 -0
- package/dist/tools/computer.d.ts +13 -0
- package/dist/tools/computer.js +952 -0
- package/dist/tools/console.d.ts +44 -0
- package/dist/tools/console.js +739 -0
- package/dist/tools/database.d.ts +28 -0
- package/dist/tools/database.js +152 -0
- package/dist/tools/filesystem.d.ts +36 -0
- package/dist/tools/filesystem.js +506 -0
- package/dist/tools/git-tag.d.ts +10 -0
- package/dist/tools/git-tag.js +164 -0
- package/dist/tools/git.d.ts +52 -0
- package/dist/tools/git.js +1272 -0
- package/dist/tools/http.d.ts +12 -0
- package/dist/tools/http.js +119 -0
- package/dist/tools/image.d.ts +8 -0
- package/dist/tools/image.js +551 -0
- package/dist/tools/index.d.ts +13 -0
- package/dist/tools/index.js +58 -0
- package/dist/tools/outline.d.ts +20 -0
- package/dist/tools/outline.js +98 -0
- package/dist/tools/search.d.ts +17 -0
- package/dist/tools/search.js +391 -0
- package/dist/tools/sonar.d.ts +17 -0
- package/dist/tools/sonar.js +231 -0
- package/dist/tools/testing.d.ts +36 -0
- package/dist/tools/testing.js +273 -0
- package/dist/tools/upload.d.ts +8 -0
- package/dist/tools/upload.js +106 -0
- package/dist/tools/webcam.d.ts +28 -0
- package/dist/tools/webcam.js +967 -0
- package/dist/update/install-kind.d.ts +35 -0
- package/dist/update/install-kind.js +109 -0
- package/dist/update/install.d.ts +32 -0
- package/dist/update/install.js +187 -0
- package/dist/update/manifest.d.ts +18 -0
- package/dist/update/manifest.js +73 -0
- package/dist/update/peers.d.ts +18 -0
- package/dist/update/peers.js +43 -0
- package/dist/update/policy.d.ts +20 -0
- package/dist/update/policy.js +49 -0
- package/dist/update/supervisor.d.ts +25 -0
- package/dist/update/supervisor.js +83 -0
- package/dist/update/updater.d.ts +44 -0
- package/dist/update/updater.js +116 -0
- package/dist/utils/format.d.ts +50 -0
- package/dist/utils/format.js +190 -0
- package/dist/version.d.ts +17 -0
- package/dist/version.js +63 -0
- package/dist/version.json +5 -0
- package/node_modules/@nordhavnhq/runner-browser/dist/act-tools.d.ts +15 -0
- package/node_modules/@nordhavnhq/runner-browser/dist/act-tools.js +541 -0
- package/node_modules/@nordhavnhq/runner-browser/dist/cast-hub.d.ts +25 -0
- package/node_modules/@nordhavnhq/runner-browser/dist/cast-hub.js +137 -0
- package/node_modules/@nordhavnhq/runner-browser/dist/guard.d.ts +21 -0
- package/node_modules/@nordhavnhq/runner-browser/dist/guard.js +104 -0
- package/node_modules/@nordhavnhq/runner-browser/dist/host-protocol.d.ts +47 -0
- package/node_modules/@nordhavnhq/runner-browser/dist/host-protocol.js +41 -0
- package/node_modules/@nordhavnhq/runner-browser/dist/host.d.ts +18 -0
- package/node_modules/@nordhavnhq/runner-browser/dist/host.js +15 -0
- package/node_modules/@nordhavnhq/runner-browser/dist/index.d.ts +13 -0
- package/node_modules/@nordhavnhq/runner-browser/dist/index.js +28 -0
- package/node_modules/@nordhavnhq/runner-browser/dist/live-input.d.ts +74 -0
- package/node_modules/@nordhavnhq/runner-browser/dist/live-input.js +93 -0
- package/node_modules/@nordhavnhq/runner-browser/dist/live-open.d.ts +4 -0
- package/node_modules/@nordhavnhq/runner-browser/dist/live-open.js +57 -0
- package/node_modules/@nordhavnhq/runner-browser/dist/live.d.ts +148 -0
- package/node_modules/@nordhavnhq/runner-browser/dist/live.js +179 -0
- package/node_modules/@nordhavnhq/runner-browser/dist/local-live.d.ts +31 -0
- package/node_modules/@nordhavnhq/runner-browser/dist/local-live.js +262 -0
- package/node_modules/@nordhavnhq/runner-browser/dist/marks.d.ts +36 -0
- package/node_modules/@nordhavnhq/runner-browser/dist/marks.js +173 -0
- package/node_modules/@nordhavnhq/runner-browser/dist/page-events.d.ts +27 -0
- package/node_modules/@nordhavnhq/runner-browser/dist/page-events.js +82 -0
- package/node_modules/@nordhavnhq/runner-browser/dist/page-tools.d.ts +13 -0
- package/node_modules/@nordhavnhq/runner-browser/dist/page-tools.js +526 -0
- package/node_modules/@nordhavnhq/runner-browser/dist/params.d.ts +12 -0
- package/node_modules/@nordhavnhq/runner-browser/dist/params.js +32 -0
- package/node_modules/@nordhavnhq/runner-browser/dist/pick.d.ts +24 -0
- package/node_modules/@nordhavnhq/runner-browser/dist/pick.js +76 -0
- package/node_modules/@nordhavnhq/runner-browser/dist/session.d.ts +225 -0
- package/node_modules/@nordhavnhq/runner-browser/dist/session.js +507 -0
- package/node_modules/@nordhavnhq/runner-browser/dist/shots.d.ts +11 -0
- package/node_modules/@nordhavnhq/runner-browser/dist/shots.js +103 -0
- package/node_modules/@nordhavnhq/runner-browser/dist/show.d.ts +10 -0
- package/node_modules/@nordhavnhq/runner-browser/dist/show.js +190 -0
- package/node_modules/@nordhavnhq/runner-browser/dist/target.d.ts +37 -0
- package/node_modules/@nordhavnhq/runner-browser/dist/target.js +82 -0
- package/node_modules/@nordhavnhq/runner-browser/dist/tour.d.ts +19 -0
- package/node_modules/@nordhavnhq/runner-browser/dist/tour.js +178 -0
- package/node_modules/@nordhavnhq/runner-browser/package.json +18 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/config.d.ts +96 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/config.js +25 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/connection.d.ts +276 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/connection.js +507 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/constants.d.ts +48 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/constants.js +95 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/contract/batch.d.ts +94 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/contract/batch.js +219 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/contract/calls.d.ts +136 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/contract/calls.js +214 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/contract/fs.d.ts +735 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/contract/fs.js +40 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/contract/loop.d.ts +362 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/contract/loop.js +703 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/contract/own-files.d.ts +105 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/contract/own-files.js +202 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/contract/phases.d.ts +204 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/contract/phases.js +497 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/contract/pins.d.ts +45 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/contract/pins.js +176 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/contract/processes.d.ts +74 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/contract/processes.js +72 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/contract/release-tag.d.ts +59 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/contract/release-tag.js +117 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/contract/replay.d.ts +62 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/contract/replay.js +84 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/contract/tool-names.d.ts +27 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/contract/tool-names.js +80 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/contract/version.d.ts +22 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/contract/version.js +22 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/contract/wire.d.ts +595 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/contract/wire.js +85 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/index.d.ts +43 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/index.js +50 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/inference.d.ts +135 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/inference.js +945 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/mcp.d.ts +67 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/mcp.js +47 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/platform.d.ts +21 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/platform.js +25 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/auto-load.d.ts +39 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/auto-load.js +67 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/background-commands.d.ts +61 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/background-commands.js +58 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/chat-run-ends.d.ts +23 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/chat-run-ends.js +42 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/duration.d.ts +6 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/duration.js +12 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/events.d.ts +150 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/events.js +36 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/extract-json.d.ts +14 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/extract-json.js +49 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/handle-chat.d.ts +109 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/handle-chat.js +894 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/handle-task.d.ts +73 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/handle-task.js +765 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/loop.d.ts +246 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/loop.js +621 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/messages.d.ts +88 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/messages.js +188 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/pending-steers.d.ts +15 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/pending-steers.js +10 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/phased-loop.d.ts +16 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/phased-loop.js +97 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/project-instructions.d.ts +22 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/project-instructions.js +47 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/run-tools.d.ts +26 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/run-tools.js +48 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/scratch-prompt.d.ts +8 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/scratch-prompt.js +19 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/side-question.d.ts +76 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/side-question.js +155 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/task-validation.d.ts +43 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/task-validation.js +37 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/unload-toolset.d.ts +49 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/unload-toolset.js +104 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/write-scope.d.ts +16 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/runtime/write-scope.js +6 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/tools/delegate.d.ts +86 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/tools/delegate.js +141 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/tools/index.d.ts +179 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/tools/index.js +35 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/tools/mcp.d.ts +21 -0
- package/node_modules/@nordhavnhq/runner-runtime/dist/tools/mcp.js +179 -0
- package/node_modules/@nordhavnhq/runner-runtime/package.json +18 -0
- package/package.json +33 -4
- package/README.md +0 -3
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
import { execFile } from 'node:child_process';
|
|
2
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync, rmSync } from 'node:fs';
|
|
3
|
+
import { hostname } from 'node:os';
|
|
4
|
+
import { join } from 'node:path';
|
|
5
|
+
import { promisify } from 'node:util';
|
|
6
|
+
import { nordhavnDir } from '../paths.js';
|
|
7
|
+
const run = promisify(execFile);
|
|
8
|
+
// ─── The git relay: pushing for a person, with their key, from here ──
|
|
9
|
+
//
|
|
10
|
+
// A person pairs this machine (`relay:connect`, confirmed in a dialog the
|
|
11
|
+
// runner shows itself). From then on, what an agent on ANOTHER runner commits
|
|
12
|
+
// in a session that person started can be pushed in their name: the studio
|
|
13
|
+
// hands this runner a git bundle, this runner shows what the bundle holds,
|
|
14
|
+
// and pushes it with the machine's own ssh key and git config after a click.
|
|
15
|
+
// The key never leaves the machine and nothing is pushed without that click.
|
|
16
|
+
//
|
|
17
|
+
// What is checked here, never trusted from the frame: the branch (an agent's
|
|
18
|
+
// own, `feat/` and the like, never main or master), the remote (GitHub only,
|
|
19
|
+
// rewritten to its ssh URL), what the bundle really holds (its one ref, its
|
|
20
|
+
// commits and their authors, read from git), its size. The push runs from a
|
|
21
|
+
// mirror of its own under the runner's folder, never a person's checkout, and
|
|
22
|
+
// never forced. Opt-in, kept in a file on this machine; the studio keeps
|
|
23
|
+
// nothing. Disconnecting is never gated.
|
|
24
|
+
/** How long the dialog waits for a click before it says no (seconds). */
|
|
25
|
+
const RELAY_DIALOG_SECONDS = 120;
|
|
26
|
+
/** Largest bundle carried (bytes, decoded). */
|
|
27
|
+
export const RELAY_BUNDLE_MAX_BYTES = 25 * 1024 * 1024;
|
|
28
|
+
/** Pushes per minute before the relay refuses (against a flood of dialogs). */
|
|
29
|
+
export const RELAY_PUSHES_PER_MINUTE = 6;
|
|
30
|
+
/** Branches the relay pushes: an agent's own, never main or master. */
|
|
31
|
+
const RELAY_BRANCH = /^(feat|fix|chore|test|task)\/[A-Za-z0-9][A-Za-z0-9._/-]*$/;
|
|
32
|
+
const PROTECTED = new Set(['main', 'master', 'develop', 'production', 'release']);
|
|
33
|
+
const GIT_TIMEOUT_MS = 120_000;
|
|
34
|
+
function defaultRelayDeps() {
|
|
35
|
+
return {
|
|
36
|
+
dir: join(nordhavnDir(), 'git-relay'),
|
|
37
|
+
confirm: confirmDialog,
|
|
38
|
+
canConfirm: process.platform === 'darwin',
|
|
39
|
+
remoteUrl: (owner, repo) => `git@github.com:${owner}/${repo}.git`,
|
|
40
|
+
githubLogin: sshGithubLogin,
|
|
41
|
+
gitIdentity: globalGitIdentity,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
// ─── State ───────────────────────────────────
|
|
45
|
+
function stateFile(deps) {
|
|
46
|
+
return join(deps.dir, 'relay.json');
|
|
47
|
+
}
|
|
48
|
+
function readState(deps) {
|
|
49
|
+
try {
|
|
50
|
+
const raw = JSON.parse(readFileSync(stateFile(deps), 'utf8'));
|
|
51
|
+
return {
|
|
52
|
+
enabled: raw.enabled === true,
|
|
53
|
+
githubLogin: raw.githubLogin ?? null,
|
|
54
|
+
gitName: raw.gitName ?? null,
|
|
55
|
+
gitEmail: raw.gitEmail ?? null,
|
|
56
|
+
connectedAt: raw.connectedAt ?? null,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
return { enabled: false, githubLogin: null, gitName: null, gitEmail: null, connectedAt: null };
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
function writeState(deps, state) {
|
|
64
|
+
mkdirSync(deps.dir, { recursive: true, mode: 0o700 });
|
|
65
|
+
writeFileSync(stateFile(deps), JSON.stringify(state, null, 2) + '\n', { mode: 0o600 });
|
|
66
|
+
}
|
|
67
|
+
export function relayStatus(deps = defaultRelayDeps()) {
|
|
68
|
+
const state = readState(deps);
|
|
69
|
+
return { ...state, host: hostname(), dialog: deps.canConfirm };
|
|
70
|
+
}
|
|
71
|
+
// ─── Connect / disconnect ────────────────────
|
|
72
|
+
let busy = false;
|
|
73
|
+
/** One dialog at a time: a second request while one is open is refused. */
|
|
74
|
+
async function exclusive(work) {
|
|
75
|
+
if (busy)
|
|
76
|
+
throw new Error('the relay is already asking something on this machine');
|
|
77
|
+
busy = true;
|
|
78
|
+
try {
|
|
79
|
+
return await work();
|
|
80
|
+
}
|
|
81
|
+
finally {
|
|
82
|
+
busy = false;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
async function gitConfig(key) {
|
|
86
|
+
try {
|
|
87
|
+
const { stdout } = await run('git', ['config', '--global', '--get', key], { timeout: 5000 });
|
|
88
|
+
return stdout.trim() || null;
|
|
89
|
+
}
|
|
90
|
+
catch {
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
async function globalGitIdentity() {
|
|
95
|
+
const [name, email] = await Promise.all([gitConfig('user.name'), gitConfig('user.email')]);
|
|
96
|
+
return name && email ? { name, email } : null;
|
|
97
|
+
}
|
|
98
|
+
/** The person `byName` asks to pair this machine. Asks them here, tests the
|
|
99
|
+
* key against GitHub, keeps the result. Throws when refused or the key does
|
|
100
|
+
* not work. */
|
|
101
|
+
export function relayConnect(byName, deps = defaultRelayDeps()) {
|
|
102
|
+
return exclusive(async () => {
|
|
103
|
+
if (!deps.canConfirm)
|
|
104
|
+
throw new Error('this machine cannot show the confirmation dialog (macOS only for now)');
|
|
105
|
+
const ok = await deps.confirm('Nordhavn git relay', `${oneLine(byName)} wants to connect this machine's GitHub key to the studio.\n\n`
|
|
106
|
+
+ 'Agents working elsewhere can then push in your name, through this machine. '
|
|
107
|
+
+ 'Every push asks you here first. The key never leaves this machine.', 'Connect');
|
|
108
|
+
if (!ok)
|
|
109
|
+
throw new Error('refused on the machine');
|
|
110
|
+
const login = await deps.githubLogin();
|
|
111
|
+
if (!login)
|
|
112
|
+
throw new Error('the ssh key on this machine does not authenticate with GitHub (ssh -T git@github.com)');
|
|
113
|
+
const who = await deps.gitIdentity();
|
|
114
|
+
if (!who)
|
|
115
|
+
throw new Error('git has no user.name or user.email on this machine (git config --global)');
|
|
116
|
+
writeState(deps, { enabled: true, githubLogin: login, gitName: who.name, gitEmail: who.email, connectedAt: new Date().toISOString() });
|
|
117
|
+
return relayStatus(deps);
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
/** Unpair, without asking: giving access up is never gated. */
|
|
121
|
+
export function relayDisconnect(deps = defaultRelayDeps()) {
|
|
122
|
+
const state = readState(deps);
|
|
123
|
+
writeState(deps, { ...state, enabled: false });
|
|
124
|
+
return relayStatus(deps);
|
|
125
|
+
}
|
|
126
|
+
// ─── Push ────────────────────────────────────
|
|
127
|
+
const recentPushes = [];
|
|
128
|
+
/** Tests only: forget the pushes of this minute. */
|
|
129
|
+
export function resetRelayLimits() {
|
|
130
|
+
recentPushes.length = 0;
|
|
131
|
+
}
|
|
132
|
+
function rateLimit() {
|
|
133
|
+
const now = Date.now();
|
|
134
|
+
while (recentPushes.length && now - recentPushes[0] > 60_000)
|
|
135
|
+
recentPushes.shift();
|
|
136
|
+
if (recentPushes.length >= RELAY_PUSHES_PER_MINUTE)
|
|
137
|
+
throw new Error('too many pushes through the relay this minute');
|
|
138
|
+
recentPushes.push(now);
|
|
139
|
+
}
|
|
140
|
+
/** Owner and repo of a GitHub remote URL, or an error. */
|
|
141
|
+
export function githubRepo(remote) {
|
|
142
|
+
const m = /^(?:git@github\.com:|ssh:\/\/git@github\.com\/|https:\/\/github\.com\/)([A-Za-z0-9-]{1,39})\/([A-Za-z0-9._-]{1,100}?)(?:\.git)?\/?$/.exec(remote.trim());
|
|
143
|
+
if (!m || m[2] === '.' || m[2] === '..')
|
|
144
|
+
throw new Error('the relay pushes to GitHub repos only');
|
|
145
|
+
return { owner: m[1], repo: m[2] };
|
|
146
|
+
}
|
|
147
|
+
/** The branch an agent may push to through the relay, or an error. */
|
|
148
|
+
export function relayBranch(branch) {
|
|
149
|
+
const name = branch.replace(/^refs\/heads\//, '');
|
|
150
|
+
if (PROTECTED.has(name) || !RELAY_BRANCH.test(name) || name.includes('..') || name.endsWith('.lock') || name.endsWith('/')) {
|
|
151
|
+
throw new Error(`the relay only pushes an agent's own branch (feat/, fix/, chore/, test/, task/), not "${name}"`);
|
|
152
|
+
}
|
|
153
|
+
return name;
|
|
154
|
+
}
|
|
155
|
+
async function git(cwd, args) {
|
|
156
|
+
const env = { ...process.env, GIT_TERMINAL_PROMPT: '0' };
|
|
157
|
+
try {
|
|
158
|
+
const { stdout, stderr } = await run('git', args, { cwd, timeout: GIT_TIMEOUT_MS, env, maxBuffer: 16 * 1024 * 1024 });
|
|
159
|
+
return (stdout + stderr).trim();
|
|
160
|
+
}
|
|
161
|
+
catch (err) {
|
|
162
|
+
const e = err;
|
|
163
|
+
throw new Error((e.stderr || e.message).trim().split('\n').slice(-3).join('\n'), { cause: err });
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
/** Push what an agent committed elsewhere, after the person's click. Returns
|
|
167
|
+
* git's output and the pushed sha. */
|
|
168
|
+
export async function relayPush(frame, deps = defaultRelayDeps()) {
|
|
169
|
+
const state = readState(deps);
|
|
170
|
+
if (!state.enabled)
|
|
171
|
+
throw new Error('the git relay on this machine is not connected');
|
|
172
|
+
if (!deps.canConfirm)
|
|
173
|
+
throw new Error('this machine cannot show the confirmation dialog');
|
|
174
|
+
const branch = relayBranch(frame.branch);
|
|
175
|
+
const { owner, repo } = githubRepo(frame.remote);
|
|
176
|
+
const bytes = Buffer.from(frame.bundle, 'base64');
|
|
177
|
+
if (bytes.length === 0)
|
|
178
|
+
throw new Error('empty bundle');
|
|
179
|
+
if (bytes.length > RELAY_BUNDLE_MAX_BYTES)
|
|
180
|
+
throw new Error('the bundle is too big for the relay');
|
|
181
|
+
rateLimit();
|
|
182
|
+
return exclusive(async () => {
|
|
183
|
+
// A bare mirror per repo, of the relay's own.
|
|
184
|
+
const mirror = join(deps.dir, 'mirrors', owner, `${repo}.git`);
|
|
185
|
+
const url = deps.remoteUrl(owner, repo);
|
|
186
|
+
if (!existsSync(join(mirror, 'HEAD'))) {
|
|
187
|
+
mkdirSync(mirror, { recursive: true, mode: 0o700 });
|
|
188
|
+
await git(mirror, ['init', '--bare', '--quiet']);
|
|
189
|
+
await git(mirror, ['remote', 'add', 'origin', url]);
|
|
190
|
+
}
|
|
191
|
+
else {
|
|
192
|
+
await git(mirror, ['remote', 'set-url', 'origin', url]);
|
|
193
|
+
}
|
|
194
|
+
const file = join(deps.dir, `incoming-${process.pid}-${Date.now()}.bundle`);
|
|
195
|
+
writeFileSync(file, bytes, { mode: 0o600 });
|
|
196
|
+
try {
|
|
197
|
+
// What the bundle holds, read by git: exactly the one branch.
|
|
198
|
+
const heads = (await git(mirror, ['bundle', 'list-heads', file])).split('\n').filter(Boolean);
|
|
199
|
+
const want = `refs/heads/${branch}`;
|
|
200
|
+
const head = heads.map(l => l.split(' ')).find(([, ref]) => ref === want);
|
|
201
|
+
if (heads.length !== 1 || !head || !/^[0-9a-f]{40,64}$/.test(head[0])) {
|
|
202
|
+
throw new Error(`the bundle must hold exactly ${want}`);
|
|
203
|
+
}
|
|
204
|
+
const sha = head[0];
|
|
205
|
+
// Its base is on GitHub: fetch that (a read, with the key the person
|
|
206
|
+
// connected), then the bundle on top.
|
|
207
|
+
await git(mirror, ['fetch', '--quiet', '--prune', 'origin', '+refs/heads/*:refs/remotes/origin/*']);
|
|
208
|
+
await git(mirror, ['bundle', 'verify', '--quiet', file]);
|
|
209
|
+
await git(mirror, ['fetch', '--quiet', file, `+${want}:refs/relay/incoming`]);
|
|
210
|
+
const authors = (await git(mirror, ['log', '--format=%an <%ae>', sha, '--not', '--remotes=origin'])).split('\n').filter(Boolean);
|
|
211
|
+
const subjects = (await git(mirror, ['log', '--format=%s', '-n', '5', sha, '--not', '--remotes=origin'])).split('\n').filter(Boolean);
|
|
212
|
+
if (authors.length === 0)
|
|
213
|
+
throw new Error('nothing to push: every commit is already on GitHub');
|
|
214
|
+
const uniqueAuthors = [...new Set(authors)];
|
|
215
|
+
const ok = await deps.confirm('Nordhavn git relay', `${oneLine(frame.agent.name)} wants to push to ${branch} on ${owner}/${repo}.\n\n`
|
|
216
|
+
+ `${authors.length} commit${authors.length === 1 ? '' : 's'} (${sha.slice(0, 8)}), by ${uniqueAuthors.slice(0, 3).map(oneLine).join(', ')}${uniqueAuthors.length > 3 ? ', ...' : ''}\n`
|
|
217
|
+
+ subjects.map(s => ` - ${oneLine(s).slice(0, 80)}`).join('\n')
|
|
218
|
+
+ (authors.length > subjects.length ? '\n - ...' : ''), 'Push');
|
|
219
|
+
if (!ok)
|
|
220
|
+
throw new Error('refused on the machine');
|
|
221
|
+
const output = await git(mirror, ['push', '--porcelain', 'origin', `${sha}:${want}`]);
|
|
222
|
+
return { output, sha };
|
|
223
|
+
}
|
|
224
|
+
finally {
|
|
225
|
+
rmSync(file, { force: true });
|
|
226
|
+
await git(mirror, ['update-ref', '-d', 'refs/relay/incoming']).catch(() => undefined);
|
|
227
|
+
}
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
// ─── macOS ───────────────────────────────────
|
|
231
|
+
/** No line breaks, quotes or angle brackets from outside in a dialog line. */
|
|
232
|
+
function oneLine(text) {
|
|
233
|
+
return text.replace(/[\r\n<>"]/g, ' ').trim().slice(0, 200);
|
|
234
|
+
}
|
|
235
|
+
/** A native dialog. The text goes in as an argument, never into the script. */
|
|
236
|
+
async function confirmDialog(title, message, allow) {
|
|
237
|
+
const script = [
|
|
238
|
+
'on run argv',
|
|
239
|
+
`display dialog (item 2 of argv) with title (item 1 of argv) buttons {"Refuse", (item 3 of argv)} default button "Refuse" cancel button "Refuse" with icon caution giving up after ${RELAY_DIALOG_SECONDS}`,
|
|
240
|
+
'return (button returned of result) & "|" & (gave up of result)',
|
|
241
|
+
'end run',
|
|
242
|
+
];
|
|
243
|
+
try {
|
|
244
|
+
const { stdout } = await run('osascript', [...script.flatMap(l => ['-e', l]), title, message, allow], { timeout: (RELAY_DIALOG_SECONDS + 10) * 1000 });
|
|
245
|
+
const [button, gaveUp] = stdout.trim().split('|');
|
|
246
|
+
return button === allow && gaveUp !== 'true';
|
|
247
|
+
}
|
|
248
|
+
catch {
|
|
249
|
+
return false;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
/** `ssh -T git@github.com` answers "Hi <login>!" (and exits 1) when the key
|
|
253
|
+
* works. Never prompts. */
|
|
254
|
+
async function sshGithubLogin() {
|
|
255
|
+
const args = ['-T', '-o', 'BatchMode=yes', '-o', 'StrictHostKeyChecking=accept-new', '-o', 'ConnectTimeout=10', 'git@github.com'];
|
|
256
|
+
const said = await run('ssh', args, { timeout: 20_000 }).then(r => r.stdout + r.stderr, (err) => (err.stdout ?? '') + (err.stderr ?? ''));
|
|
257
|
+
const m = /Hi ([A-Za-z0-9-]{1,39})!/.exec(said);
|
|
258
|
+
return m ? m[1] : null;
|
|
259
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/** The nearest tag behind HEAD and how many commits came after it; null
|
|
2
|
+
* without one. Tag names may hold `-`, so the suffix is taken off the end. */
|
|
3
|
+
export declare function nearestTag(cwd: string): Promise<{
|
|
4
|
+
name: string;
|
|
5
|
+
distance: number;
|
|
6
|
+
} | null>;
|
|
7
|
+
/**
|
|
8
|
+
* The annotated tags on commits of `rev` that no remote branch holds (of
|
|
9
|
+
* `remote` only, when given): what `--follow-tags` takes along with a push of
|
|
10
|
+
* it. Approximate: a tag that is on the remote already while its commit is
|
|
11
|
+
* not is listed too.
|
|
12
|
+
*/
|
|
13
|
+
export declare function unpushedAnnotatedTags(cwd: string, rev?: string, remote?: string): Promise<string[]>;
|
|
14
|
+
/** One commit that is not pushed yet, with its message body and the size of its change. */
|
|
15
|
+
export interface UnpushedCommit {
|
|
16
|
+
sha: string;
|
|
17
|
+
parents: string[];
|
|
18
|
+
subject: string;
|
|
19
|
+
author: string;
|
|
20
|
+
date: string;
|
|
21
|
+
/** git's full decoration (`%D` with `--decorate=full`). */
|
|
22
|
+
decorated: string;
|
|
23
|
+
body: string;
|
|
24
|
+
stat: {
|
|
25
|
+
files: number;
|
|
26
|
+
additions: number;
|
|
27
|
+
deletions: number;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* The commits on HEAD that no remote branch holds, newest first, at most
|
|
32
|
+
* `TAG_DRAFT_COMMITS_MAX`, each with its body and stat: one git call. The
|
|
33
|
+
* whole repo, whatever folder the checkout is: a tag covers all of it. None
|
|
34
|
+
* when HEAD has no commit.
|
|
35
|
+
*/
|
|
36
|
+
export declare function unpushedCommits(cwd: string, max?: number): Promise<UnpushedCommit[]>;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { execFile } from 'node:child_process';
|
|
2
|
+
import { TAG_DRAFT_COMMITS_MAX } from '@nordhavnhq/runner-runtime';
|
|
3
|
+
function run(cwd, args) {
|
|
4
|
+
return new Promise((done) => {
|
|
5
|
+
execFile('git', ['-C', cwd, '-c', 'core.quotePath=false', ...args], {
|
|
6
|
+
encoding: 'utf8',
|
|
7
|
+
timeout: 30_000,
|
|
8
|
+
maxBuffer: 32 * 1024 * 1024,
|
|
9
|
+
env: { ...process.env, GIT_TERMINAL_PROMPT: '0' },
|
|
10
|
+
}, (err, stdout) => done({ ok: !err, stdout: String(stdout) }));
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
/** The revisions of "not pushed yet": `rev` minus every remote branch (of `remote` only, when given). */
|
|
14
|
+
function unpushedRange(rev, remote) {
|
|
15
|
+
return [rev, '--not', remote ? `--remotes=${remote}` : '--remotes'];
|
|
16
|
+
}
|
|
17
|
+
/** The nearest tag behind HEAD and how many commits came after it; null
|
|
18
|
+
* without one. Tag names may hold `-`, so the suffix is taken off the end. */
|
|
19
|
+
export async function nearestTag(cwd) {
|
|
20
|
+
const described = await run(cwd, ['describe', '--tags', '--long', 'HEAD']);
|
|
21
|
+
if (!described.ok)
|
|
22
|
+
return null;
|
|
23
|
+
const m = /^(.*)-(\d+)-g[0-9a-f]+$/.exec(described.stdout.trim());
|
|
24
|
+
return m ? { name: m[1], distance: Number(m[2]) } : null;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* The annotated tags on commits of `rev` that no remote branch holds (of
|
|
28
|
+
* `remote` only, when given): what `--follow-tags` takes along with a push of
|
|
29
|
+
* it. Approximate: a tag that is on the remote already while its commit is
|
|
30
|
+
* not is listed too.
|
|
31
|
+
*/
|
|
32
|
+
export async function unpushedAnnotatedTags(cwd, rev = 'HEAD', remote) {
|
|
33
|
+
const [tagged, tags] = await Promise.all([
|
|
34
|
+
run(cwd, ['log', '--simplify-by-decoration', '--decorate-refs=refs/tags/', '--format=%H', ...unpushedRange(rev, remote), '--']),
|
|
35
|
+
run(cwd, ['for-each-ref', '--format=%(refname:short)%00%(objecttype)%00%(*objectname)', 'refs/tags']),
|
|
36
|
+
]);
|
|
37
|
+
if (!tagged.ok || !tags.ok)
|
|
38
|
+
return [];
|
|
39
|
+
const commits = new Set(tagged.stdout.split('\n').filter(Boolean));
|
|
40
|
+
return tags.stdout.split('\n').flatMap((line) => {
|
|
41
|
+
const [name, type, peeled] = line.split('\0');
|
|
42
|
+
return name && type === 'tag' && peeled && commits.has(peeled) ? [name] : [];
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
/** One record of `unpushedCommits`'s log: the header up to \x1d, then its numstat lines. */
|
|
46
|
+
function parseRecord(record) {
|
|
47
|
+
const end = record.indexOf('\x1d');
|
|
48
|
+
if (end < 0)
|
|
49
|
+
return null;
|
|
50
|
+
const [sha, parents, subject, author, date, decorated, ...body] = record.slice(0, end).split('\x1f');
|
|
51
|
+
if (!sha)
|
|
52
|
+
return null;
|
|
53
|
+
const stat = { files: 0, additions: 0, deletions: 0 };
|
|
54
|
+
for (const line of record.slice(end + 1).split('\n')) {
|
|
55
|
+
const m = /^(\d+|-)\t(\d+|-)\t/.exec(line);
|
|
56
|
+
if (!m)
|
|
57
|
+
continue;
|
|
58
|
+
stat.files++;
|
|
59
|
+
if (m[1] !== '-')
|
|
60
|
+
stat.additions += Number(m[1]);
|
|
61
|
+
if (m[2] !== '-')
|
|
62
|
+
stat.deletions += Number(m[2]);
|
|
63
|
+
}
|
|
64
|
+
return {
|
|
65
|
+
sha: sha.trim(),
|
|
66
|
+
parents: (parents ?? '').split(' ').filter(Boolean),
|
|
67
|
+
subject: subject ?? '',
|
|
68
|
+
author: author ?? '',
|
|
69
|
+
date: date ?? '',
|
|
70
|
+
decorated: decorated ?? '',
|
|
71
|
+
body: body.join('\x1f').trim(),
|
|
72
|
+
stat,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* The commits on HEAD that no remote branch holds, newest first, at most
|
|
77
|
+
* `TAG_DRAFT_COMMITS_MAX`, each with its body and stat: one git call. The
|
|
78
|
+
* whole repo, whatever folder the checkout is: a tag covers all of it. None
|
|
79
|
+
* when HEAD has no commit.
|
|
80
|
+
*/
|
|
81
|
+
export async function unpushedCommits(cwd, max = TAG_DRAFT_COMMITS_MAX) {
|
|
82
|
+
const log = await run(cwd, [
|
|
83
|
+
'log', '--date-order', '--decorate=full', '--numstat', `--max-count=${max}`,
|
|
84
|
+
'--format=%x1e%H%x1f%P%x1f%s%x1f%an%x1f%cI%x1f%D%x1f%b%x1d',
|
|
85
|
+
...unpushedRange('HEAD'), '--',
|
|
86
|
+
]);
|
|
87
|
+
if (!log.ok)
|
|
88
|
+
return [];
|
|
89
|
+
return log.stdout.split('\x1e').flatMap((record) => {
|
|
90
|
+
const commit = parseRecord(record);
|
|
91
|
+
return commit ? [commit] : [];
|
|
92
|
+
});
|
|
93
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The version in a `.node-version` or `.nvmrc`: its first line without
|
|
3
|
+
* comments, `v` optional. Null for an alias (`lts/*`, `node`, `stable`): no
|
|
4
|
+
* pin the runner can honour.
|
|
5
|
+
*/
|
|
6
|
+
export declare function parseNodeVersion(text: string): string | null;
|
|
7
|
+
/** True when `version` (x.y.z, `v` optional) satisfies `spec` (x, x.y or x.y.z). */
|
|
8
|
+
export declare function matchesSpec(version: string, spec: string): boolean;
|
|
9
|
+
/** The highest of `versions` that satisfies `spec`, without `v`. */
|
|
10
|
+
export declare function pickHighest(versions: string[], spec: string): string | null;
|
|
11
|
+
/** True for a full x.y.z version. */
|
|
12
|
+
export declare function isExactVersion(spec: string): boolean;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// ─── Node version specs ─────────────────────
|
|
2
|
+
//
|
|
3
|
+
// What a project pins (`26.13.0`, `26.13`, `26`) and which installed or
|
|
4
|
+
// released versions satisfy it. Pure: no file system, no network.
|
|
5
|
+
/**
|
|
6
|
+
* The version in a `.node-version` or `.nvmrc`: its first line without
|
|
7
|
+
* comments, `v` optional. Null for an alias (`lts/*`, `node`, `stable`): no
|
|
8
|
+
* pin the runner can honour.
|
|
9
|
+
*/
|
|
10
|
+
export function parseNodeVersion(text) {
|
|
11
|
+
const line = text.split(/\r?\n/).map(l => l.replace(/#.*/, '').trim()).find(Boolean);
|
|
12
|
+
const match = line?.match(/^v?(\d+(?:\.\d+){0,2})$/);
|
|
13
|
+
return match ? match[1] : null;
|
|
14
|
+
}
|
|
15
|
+
function parseTriple(name) {
|
|
16
|
+
const m = name.replace(/^v/, '').match(/^(\d+)\.(\d+)\.(\d+)$/);
|
|
17
|
+
return m ? [Number(m[1]), Number(m[2]), Number(m[3])] : null;
|
|
18
|
+
}
|
|
19
|
+
/** True when `version` (x.y.z, `v` optional) satisfies `spec` (x, x.y or x.y.z). */
|
|
20
|
+
export function matchesSpec(version, spec) {
|
|
21
|
+
const v = parseTriple(version);
|
|
22
|
+
if (!v)
|
|
23
|
+
return false;
|
|
24
|
+
return spec.split('.').every((part, i) => Number(part) === v[i]);
|
|
25
|
+
}
|
|
26
|
+
/** The highest of `versions` that satisfies `spec`, without `v`. */
|
|
27
|
+
export function pickHighest(versions, spec) {
|
|
28
|
+
const ok = versions.filter(v => matchesSpec(v, spec)).map(v => v.replace(/^v/, ''));
|
|
29
|
+
ok.sort((a, b) => {
|
|
30
|
+
const x = parseTriple(a);
|
|
31
|
+
const y = parseTriple(b);
|
|
32
|
+
return x[0] - y[0] || x[1] - y[1] || x[2] - y[2];
|
|
33
|
+
});
|
|
34
|
+
return ok.at(-1) ?? null;
|
|
35
|
+
}
|
|
36
|
+
/** True for a full x.y.z version. */
|
|
37
|
+
export function isExactVersion(spec) {
|
|
38
|
+
return parseTriple(spec) !== null;
|
|
39
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The runner's end of a preview's tunnel (framing in the agent contract's
|
|
3
|
+
* processes.ts): every stream the studio opens is a request to
|
|
4
|
+
* `localhost:<port>`, answered back over the same socket, or a raw socket
|
|
5
|
+
* for a WebSocket upgrade (a dev server's hot reload). The studio already
|
|
6
|
+
* set `Host` and the rest; this end only carries bytes.
|
|
7
|
+
*/
|
|
8
|
+
export interface PreviewTunnel {
|
|
9
|
+
close(): void;
|
|
10
|
+
}
|
|
11
|
+
export declare function openPreviewTunnel(opts: {
|
|
12
|
+
url: string;
|
|
13
|
+
port: number;
|
|
14
|
+
onReady: () => void;
|
|
15
|
+
onClose: (code: number) => void;
|
|
16
|
+
}): PreviewTunnel;
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import http from 'node:http';
|
|
2
|
+
import net from 'node:net';
|
|
3
|
+
import { WebSocket } from 'ws';
|
|
4
|
+
import { PREVIEW_OP, decodePreviewFrame, encodePreviewFrame, previewPayloadJson, previewPayloadText, } from '@nordhavnhq/runner-runtime';
|
|
5
|
+
/** Response headers a hop sets for itself; the studio's answer makes its own. */
|
|
6
|
+
const HOP_HEADERS = new Set(['connection', 'keep-alive', 'transfer-encoding', 'proxy-connection']);
|
|
7
|
+
export function openPreviewTunnel(opts) {
|
|
8
|
+
const ws = new WebSocket(opts.url);
|
|
9
|
+
const streams = new Map();
|
|
10
|
+
let ready = false;
|
|
11
|
+
let closedByUs = false;
|
|
12
|
+
const send = (op, stream, payload) => {
|
|
13
|
+
if (ws.readyState !== WebSocket.OPEN)
|
|
14
|
+
return;
|
|
15
|
+
try {
|
|
16
|
+
ws.send(encodePreviewFrame(op, stream, payload));
|
|
17
|
+
}
|
|
18
|
+
catch { /* closing */ }
|
|
19
|
+
};
|
|
20
|
+
const drop = (id) => {
|
|
21
|
+
const stream = streams.get(id);
|
|
22
|
+
streams.delete(id);
|
|
23
|
+
if (stream?.kind === 'http')
|
|
24
|
+
stream.req.destroy();
|
|
25
|
+
if (stream?.kind === 'raw')
|
|
26
|
+
stream.socket.destroy();
|
|
27
|
+
};
|
|
28
|
+
const openRequest = (id, head) => {
|
|
29
|
+
const req = http.request({ host: 'localhost', port: opts.port, method: head.method, path: head.path, headers: head.headers }, (res) => {
|
|
30
|
+
const headers = {};
|
|
31
|
+
for (const [name, value] of Object.entries(res.headers)) {
|
|
32
|
+
if (value !== undefined && !HOP_HEADERS.has(name))
|
|
33
|
+
headers[name] = value;
|
|
34
|
+
}
|
|
35
|
+
send(PREVIEW_OP.response, id, { status: res.statusCode ?? 502, headers });
|
|
36
|
+
res.on('data', (chunk) => send(PREVIEW_OP.data, id, chunk));
|
|
37
|
+
res.on('end', () => {
|
|
38
|
+
if (!streams.has(id))
|
|
39
|
+
return;
|
|
40
|
+
streams.delete(id);
|
|
41
|
+
send(PREVIEW_OP.end, id);
|
|
42
|
+
});
|
|
43
|
+
res.on('error', (err) => {
|
|
44
|
+
if (!streams.has(id))
|
|
45
|
+
return;
|
|
46
|
+
streams.delete(id);
|
|
47
|
+
send(PREVIEW_OP.reset, id, err.message);
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
req.on('error', (err) => {
|
|
51
|
+
if (!streams.has(id))
|
|
52
|
+
return;
|
|
53
|
+
streams.delete(id);
|
|
54
|
+
send(PREVIEW_OP.reset, id, `localhost:${opts.port}: ${err.message}`);
|
|
55
|
+
});
|
|
56
|
+
streams.set(id, { kind: 'http', req });
|
|
57
|
+
};
|
|
58
|
+
const openRaw = (id, head) => {
|
|
59
|
+
const socket = net.connect({ host: 'localhost', port: opts.port }, () => socket.write(head));
|
|
60
|
+
socket.on('data', (chunk) => send(PREVIEW_OP.data, id, chunk));
|
|
61
|
+
const done = () => {
|
|
62
|
+
if (!streams.has(id))
|
|
63
|
+
return;
|
|
64
|
+
streams.delete(id);
|
|
65
|
+
send(PREVIEW_OP.end, id);
|
|
66
|
+
};
|
|
67
|
+
socket.on('end', done);
|
|
68
|
+
socket.on('close', done);
|
|
69
|
+
socket.on('error', done);
|
|
70
|
+
streams.set(id, { kind: 'raw', socket });
|
|
71
|
+
};
|
|
72
|
+
ws.on('message', (raw, isBinary) => {
|
|
73
|
+
if (!isBinary) {
|
|
74
|
+
const text = raw.toString();
|
|
75
|
+
if (!ready && text.includes('"ready"')) {
|
|
76
|
+
ready = true;
|
|
77
|
+
opts.onReady();
|
|
78
|
+
}
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
const bytes = Array.isArray(raw) ? Buffer.concat(raw) : Buffer.from(raw);
|
|
82
|
+
const frame = decodePreviewFrame(bytes);
|
|
83
|
+
if (!frame)
|
|
84
|
+
return;
|
|
85
|
+
const stream = streams.get(frame.stream);
|
|
86
|
+
switch (frame.op) {
|
|
87
|
+
case PREVIEW_OP.request: {
|
|
88
|
+
const head = previewPayloadJson(frame.payload);
|
|
89
|
+
if (head)
|
|
90
|
+
openRequest(frame.stream, head);
|
|
91
|
+
else
|
|
92
|
+
send(PREVIEW_OP.reset, frame.stream, 'Unreadable request');
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
case PREVIEW_OP.upgrade:
|
|
96
|
+
openRaw(frame.stream, Buffer.from(frame.payload));
|
|
97
|
+
return;
|
|
98
|
+
case PREVIEW_OP.data:
|
|
99
|
+
if (stream?.kind === 'http')
|
|
100
|
+
stream.req.write(Buffer.from(frame.payload));
|
|
101
|
+
else if (stream?.kind === 'raw')
|
|
102
|
+
stream.socket.write(Buffer.from(frame.payload));
|
|
103
|
+
return;
|
|
104
|
+
case PREVIEW_OP.end:
|
|
105
|
+
if (stream?.kind === 'http')
|
|
106
|
+
stream.req.end();
|
|
107
|
+
else if (stream?.kind === 'raw') {
|
|
108
|
+
streams.delete(frame.stream);
|
|
109
|
+
stream.socket.end();
|
|
110
|
+
}
|
|
111
|
+
return;
|
|
112
|
+
case PREVIEW_OP.reset:
|
|
113
|
+
void previewPayloadText(frame.payload);
|
|
114
|
+
drop(frame.stream);
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
ws.on('error', () => { });
|
|
118
|
+
ws.on('close', (code) => {
|
|
119
|
+
for (const id of [...streams.keys()])
|
|
120
|
+
drop(id);
|
|
121
|
+
if (!closedByUs)
|
|
122
|
+
opts.onClose(code);
|
|
123
|
+
});
|
|
124
|
+
return {
|
|
125
|
+
close() {
|
|
126
|
+
closedByUs = true;
|
|
127
|
+
for (const id of [...streams.keys()])
|
|
128
|
+
drop(id);
|
|
129
|
+
try {
|
|
130
|
+
ws.close(1000);
|
|
131
|
+
}
|
|
132
|
+
catch { /* already closed */ }
|
|
133
|
+
},
|
|
134
|
+
};
|
|
135
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { EventEmitter } from 'node:events';
|
|
2
|
+
import type { ChildProcess } from 'node:child_process';
|
|
3
|
+
import { type BackgroundCommandsWait, type PreviewOpenFrame, type ProcessInfo, type ToolContext, type WaitForBackgroundCommandsOptions } from '@nordhavnhq/runner-runtime';
|
|
4
|
+
export declare const processEvents: EventEmitter<any>;
|
|
5
|
+
/** The port a dev server says it listens on, from what it printed. Exported for tests. */
|
|
6
|
+
export declare function portFromOutput(output: string): number | null;
|
|
7
|
+
/**
|
|
8
|
+
* The port a background command announces it serves on: a line with a local
|
|
9
|
+
* (or `http://<ip>:`) address and a word that says it serves there (`Local:`,
|
|
10
|
+
* `listening`, `running on`, `Serving`). Stricter than `portFromOutput`, so a
|
|
11
|
+
* test suite or a build that mentions a port does not get a preview.
|
|
12
|
+
* Exported for tests.
|
|
13
|
+
*/
|
|
14
|
+
export declare function serverPortFromOutput(output: string): number | null;
|
|
15
|
+
/**
|
|
16
|
+
* Is anything left in the process group `pgid` leads? Every tracked command
|
|
17
|
+
* is spawned detached, so it leads its own group, and what it starts in the
|
|
18
|
+
* background (`server &`) stays in it after the command itself has ended.
|
|
19
|
+
* Exported for tests.
|
|
20
|
+
*/
|
|
21
|
+
export declare function groupAlive(pgid: number): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Track a process `runner_run_command` started. Its stdout and stderr must be
|
|
24
|
+
* pipes: the output is read here (and handed on through `onOutput` to the
|
|
25
|
+
* caller that still waits on it).
|
|
26
|
+
*/
|
|
27
|
+
export declare function trackProcess(child: ChildProcess, opts: {
|
|
28
|
+
command: string;
|
|
29
|
+
cwd: string;
|
|
30
|
+
kind: ProcessInfo['kind'];
|
|
31
|
+
context?: ToolContext;
|
|
32
|
+
log?: string;
|
|
33
|
+
id?: string;
|
|
34
|
+
startedBy?: string;
|
|
35
|
+
}): string;
|
|
36
|
+
/**
|
|
37
|
+
* The end of a task run (`HandleTaskDeps.waitForBackgroundCommands`): wait for
|
|
38
|
+
* the background commands dispatch `queueUid` started, within `timeoutMs`, and
|
|
39
|
+
* say how each stands. Dev servers are never waited for, nothing is stopped,
|
|
40
|
+
* and the run's list is forgotten once collected.
|
|
41
|
+
*/
|
|
42
|
+
export declare function waitForBackgroundCommands(queueUid: string, opts: WaitForBackgroundCommandsOptions): Promise<BackgroundCommandsWait>;
|
|
43
|
+
/** Every process of one agent, with the end of its output: what `proc:sync` sends. */
|
|
44
|
+
export declare function listProcesses(agentSlug: string, organisationSlug: string | null): (ProcessInfo & {
|
|
45
|
+
tail: string;
|
|
46
|
+
})[];
|
|
47
|
+
/** End a process and everything it started (its group), harder after a grace. */
|
|
48
|
+
export declare function stopProcess(id: string, agentSlug: string, organisationSlug: string | null): boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Wait for the preview of a process: its address once the tunnel is up, or
|
|
51
|
+
* null when there is none within `timeoutMs` (no port, refused, previews off).
|
|
52
|
+
*/
|
|
53
|
+
export declare function waitForPreview(id: string, timeoutMs: number): Promise<string | null>;
|
|
54
|
+
/** The studio opened a preview (ours, or one a person asked for): hold its tunnel. */
|
|
55
|
+
export declare function onPreviewOpen(frame: PreviewOpenFrame, studioUrl: string, agentSlug: string, organisationSlug: string | null): void;
|
|
56
|
+
/** The studio closed a preview: drop its tunnel for good. */
|
|
57
|
+
export declare function onPreviewClose(previewId: string): void;
|
|
58
|
+
/** No preview for our request: whoever waits hears none, a dropped one tries again later. */
|
|
59
|
+
export declare function onPreviewRefused(requestId: string): void;
|
|
60
|
+
/** Every process still running is stopped with the runner. */
|
|
61
|
+
export declare function stopAllProcesses(): void;
|