@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,35 @@
|
|
|
1
|
+
/** The scope the runner is published under, and the one it had before. */
|
|
2
|
+
export declare const PACKAGE_SCOPE = "@nordhavnhq";
|
|
3
|
+
/** Installs from before the scope rename; an update moves them to PACKAGE_SCOPE. */
|
|
4
|
+
export declare const LEGACY_PACKAGE_SCOPE = "@justmade";
|
|
5
|
+
export type InstallKind = {
|
|
6
|
+
kind: 'global';
|
|
7
|
+
/** The npm prefix the runner was installed into (`npm i -g --prefix <prefix>`). */
|
|
8
|
+
prefix: string;
|
|
9
|
+
/** `<prefix>/lib/node_modules/<scope>/runner` (real path). */
|
|
10
|
+
packageDir: string;
|
|
11
|
+
/** Installed under LEGACY_PACKAGE_SCOPE: the next update moves it. */
|
|
12
|
+
legacy: boolean;
|
|
13
|
+
} | {
|
|
14
|
+
kind: 'linked' | 'dev';
|
|
15
|
+
/** The package root the running code was loaded from, when known. */
|
|
16
|
+
packageDir: string | null;
|
|
17
|
+
/** Why this is not an updatable install, for `nordhavn update --check`. */
|
|
18
|
+
reason: string;
|
|
19
|
+
};
|
|
20
|
+
export interface DetectOptions {
|
|
21
|
+
/** The entry script, `process.argv[1]` by default. */
|
|
22
|
+
entry?: string;
|
|
23
|
+
env?: NodeJS.ProcessEnv;
|
|
24
|
+
platform?: NodeJS.Platform;
|
|
25
|
+
}
|
|
26
|
+
export declare function detectInstallKind(opts?: DetectOptions): InstallKind;
|
|
27
|
+
/**
|
|
28
|
+
* Where the runner of `packageDir` lives now: a legacy install that an update
|
|
29
|
+
* moved to PACKAGE_SCOPE is read from its new folder.
|
|
30
|
+
*/
|
|
31
|
+
export declare function currentPackageDir(packageDir: string): string;
|
|
32
|
+
/** The version of the runner package on disk (build stamp, else package.json), or null when unreadable. */
|
|
33
|
+
export declare function readPackageVersion(packageDir: string | null): string | null;
|
|
34
|
+
/** The package root of the code that is running, also for linked and dev runs. */
|
|
35
|
+
export declare function runningPackageDir(entry?: string | undefined): string | null;
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { existsSync, realpathSync } from 'node:fs';
|
|
2
|
+
import { basename, dirname, join } from 'node:path';
|
|
3
|
+
import { readRunnerVersion } from '../version.js';
|
|
4
|
+
// ─── Install kind ────────────────────────────
|
|
5
|
+
//
|
|
6
|
+
// Only a runner installed from a release tarball (`npm i -g <tgz>`) may update
|
|
7
|
+
// itself. A runner linked to a checkout (`npm link`, a workspace symlink) or run
|
|
8
|
+
// from source (`tsx src/index.ts`, the dev profile) belongs to whoever works on
|
|
9
|
+
// that checkout: replacing it with a release would throw their build away, so
|
|
10
|
+
// those only ever get a notice.
|
|
11
|
+
/** The scope the runner is published under, and the one it had before. */
|
|
12
|
+
export const PACKAGE_SCOPE = '@nordhavnhq';
|
|
13
|
+
/** Installs from before the scope rename; an update moves them to PACKAGE_SCOPE. */
|
|
14
|
+
export const LEGACY_PACKAGE_SCOPE = '@justmade';
|
|
15
|
+
export function detectInstallKind(opts = {}) {
|
|
16
|
+
const entry = opts.entry ?? process.argv[1];
|
|
17
|
+
const env = opts.env ?? process.env;
|
|
18
|
+
const platform = opts.platform ?? process.platform;
|
|
19
|
+
if ((env.NORDHAVN_PROFILE ?? '').trim().toLowerCase() === 'dev') {
|
|
20
|
+
return { kind: 'dev', packageDir: null, reason: 'the dev profile runs from source' };
|
|
21
|
+
}
|
|
22
|
+
if (!entry)
|
|
23
|
+
return { kind: 'dev', packageDir: null, reason: 'no entry script' };
|
|
24
|
+
let real;
|
|
25
|
+
try {
|
|
26
|
+
real = realpathSync(entry);
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
return { kind: 'dev', packageDir: null, reason: `cannot resolve ${entry}` };
|
|
30
|
+
}
|
|
31
|
+
if (/\.(c|m)?ts$/.test(real)) {
|
|
32
|
+
return { kind: 'dev', packageDir: dirname(dirname(real)), reason: 'running from TypeScript source' };
|
|
33
|
+
}
|
|
34
|
+
// dist/index.js -> the package root.
|
|
35
|
+
const packageDir = dirname(dirname(real));
|
|
36
|
+
if (basename(dirname(real)) !== 'dist') {
|
|
37
|
+
return { kind: 'linked', packageDir, reason: `unexpected entry ${real}` };
|
|
38
|
+
}
|
|
39
|
+
const nodeModules = dirname(dirname(packageDir));
|
|
40
|
+
const scope = runnerScope(packageDir);
|
|
41
|
+
if (!scope) {
|
|
42
|
+
// `npm link` leaves a symlink in the global node_modules; its real path is
|
|
43
|
+
// the checkout, which never has this layout.
|
|
44
|
+
return { kind: 'linked', packageDir, reason: `linked to ${packageDir}` };
|
|
45
|
+
}
|
|
46
|
+
// The global layout: <prefix>/lib/node_modules on POSIX, <prefix>/node_modules
|
|
47
|
+
// on Windows. Anything else is a project's local node_modules.
|
|
48
|
+
let prefix;
|
|
49
|
+
if (platform === 'win32') {
|
|
50
|
+
prefix = dirname(nodeModules);
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
if (basename(dirname(nodeModules)) !== 'lib') {
|
|
54
|
+
return { kind: 'linked', packageDir, reason: `installed in a project (${nodeModules}), not globally` };
|
|
55
|
+
}
|
|
56
|
+
prefix = dirname(dirname(nodeModules));
|
|
57
|
+
}
|
|
58
|
+
const checkout = findCheckout(packageDir, prefix);
|
|
59
|
+
if (checkout)
|
|
60
|
+
return { kind: 'linked', packageDir, reason: `git checkout at ${checkout}` };
|
|
61
|
+
return { kind: 'global', prefix, packageDir, legacy: scope === LEGACY_PACKAGE_SCOPE };
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* A checkout that happens to sit in a node_modules layout. Only the folders
|
|
65
|
+
* from the package up to the prefix count: a git repo higher up (a versioned
|
|
66
|
+
* home directory) says nothing about this install.
|
|
67
|
+
*/
|
|
68
|
+
function findCheckout(packageDir, prefix) {
|
|
69
|
+
for (let dir = packageDir; dir.length >= prefix.length; dir = dirname(dir)) {
|
|
70
|
+
if (existsSync(join(dir, '.git')))
|
|
71
|
+
return dir;
|
|
72
|
+
if (dir === prefix || dirname(dir) === dir)
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
/** The scope of `<node_modules>/<scope>/runner`, or null for any other layout. */
|
|
78
|
+
function runnerScope(packageDir) {
|
|
79
|
+
const scope = basename(dirname(packageDir));
|
|
80
|
+
const inNodeModules = basename(packageDir) === 'runner'
|
|
81
|
+
&& (scope === PACKAGE_SCOPE || scope === LEGACY_PACKAGE_SCOPE)
|
|
82
|
+
&& basename(dirname(dirname(packageDir))) === 'node_modules';
|
|
83
|
+
return inNodeModules ? scope : null;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Where the runner of `packageDir` lives now: a legacy install that an update
|
|
87
|
+
* moved to PACKAGE_SCOPE is read from its new folder.
|
|
88
|
+
*/
|
|
89
|
+
export function currentPackageDir(packageDir) {
|
|
90
|
+
if (basename(dirname(packageDir)) !== LEGACY_PACKAGE_SCOPE)
|
|
91
|
+
return packageDir;
|
|
92
|
+
const moved = join(dirname(dirname(packageDir)), PACKAGE_SCOPE, basename(packageDir));
|
|
93
|
+
return existsSync(moved) ? moved : packageDir;
|
|
94
|
+
}
|
|
95
|
+
/** The version of the runner package on disk (build stamp, else package.json), or null when unreadable. */
|
|
96
|
+
export function readPackageVersion(packageDir) {
|
|
97
|
+
return packageDir ? readRunnerVersion(packageDir) : null;
|
|
98
|
+
}
|
|
99
|
+
/** The package root of the code that is running, also for linked and dev runs. */
|
|
100
|
+
export function runningPackageDir(entry = process.argv[1]) {
|
|
101
|
+
if (!entry)
|
|
102
|
+
return null;
|
|
103
|
+
try {
|
|
104
|
+
return dirname(dirname(realpathSync(entry)));
|
|
105
|
+
}
|
|
106
|
+
catch {
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { type ReleaseManifest } from './manifest.js';
|
|
2
|
+
/**
|
|
3
|
+
* Takes the lock file, or returns null when a live process holds it. A lock
|
|
4
|
+
* whose owner is gone, or that is older than `staleMs`, is taken over: a
|
|
5
|
+
* crashed install must not block every later one.
|
|
6
|
+
*/
|
|
7
|
+
export declare function acquireLock(path: string, staleMs?: number): (() => void) | null;
|
|
8
|
+
/**
|
|
9
|
+
* Arguments for the global install. npm 12 blocks install scripts unless
|
|
10
|
+
* allowed; ffmpeg's platform package only marks its binary executable, which
|
|
11
|
+
* the image tools need. Older npm does not know the flag, so it is left out.
|
|
12
|
+
*/
|
|
13
|
+
export declare function npmInstallArgs(tarball: string, prefix: string, major: number, platform?: NodeJS.Platform, arch?: NodeJS.Architecture, force?: boolean): string[];
|
|
14
|
+
export interface PerformUpdateOptions {
|
|
15
|
+
manifest: ReleaseManifest;
|
|
16
|
+
prefix: string;
|
|
17
|
+
packageDir: string;
|
|
18
|
+
/** The install sits under the legacy scope: install the new one beside it, then drop it. */
|
|
19
|
+
legacy?: boolean;
|
|
20
|
+
lockPath?: string;
|
|
21
|
+
execPath?: string;
|
|
22
|
+
/** Progress lines (download, install), for the CLI. */
|
|
23
|
+
onStep?: (step: string) => void;
|
|
24
|
+
}
|
|
25
|
+
export type PerformUpdateResult = 'installed' | 'already-installed';
|
|
26
|
+
/**
|
|
27
|
+
* Installs the manifest's release unless the version on disk is already at
|
|
28
|
+
* least that new (another runtime of this machine got there first). Throws on
|
|
29
|
+
* any failure; the install on disk is then whatever npm left, which for a
|
|
30
|
+
* failed `npm i -g` is the previous version.
|
|
31
|
+
*/
|
|
32
|
+
export declare function performUpdate(opts: PerformUpdateOptions): Promise<PerformUpdateResult>;
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import { execFile, execFileSync } from 'node:child_process';
|
|
2
|
+
import { closeSync, existsSync, mkdirSync, mkdtempSync, openSync, readFileSync, realpathSync, rmSync, statSync, writeFileSync, writeSync } from 'node:fs';
|
|
3
|
+
import { tmpdir } from 'node:os';
|
|
4
|
+
import { basename, delimiter, dirname, join } from 'node:path';
|
|
5
|
+
import { isNewerVersion } from '../utils/format.js';
|
|
6
|
+
import { isAlive } from '../runtime/daemon.js';
|
|
7
|
+
import { nordhavnDir } from '../paths.js';
|
|
8
|
+
import { PACKAGE_SCOPE, readPackageVersion } from './install-kind.js';
|
|
9
|
+
import { downloadTarball } from './manifest.js';
|
|
10
|
+
// ─── Installing a release ────────────────────
|
|
11
|
+
//
|
|
12
|
+
// Download, verify, `npm i -g <tgz>` into the prefix the runner already lives
|
|
13
|
+
// in. One install at a time per machine profile (a lock file in the runner's
|
|
14
|
+
// config dir): several detached runtimes see the same new version at once.
|
|
15
|
+
const LOCK_STALE_MS = 30 * 60_000;
|
|
16
|
+
const LOCK_WAIT_MS = 15 * 60_000;
|
|
17
|
+
const INSTALL_TIMEOUT_MS = 15 * 60_000;
|
|
18
|
+
function updateLockPath() {
|
|
19
|
+
return join(nordhavnDir(), 'update.lock');
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Takes the lock file, or returns null when a live process holds it. A lock
|
|
23
|
+
* whose owner is gone, or that is older than `staleMs`, is taken over: a
|
|
24
|
+
* crashed install must not block every later one.
|
|
25
|
+
*/
|
|
26
|
+
export function acquireLock(path, staleMs = LOCK_STALE_MS) {
|
|
27
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
28
|
+
for (let attempt = 0; attempt < 2; attempt++) {
|
|
29
|
+
try {
|
|
30
|
+
const fd = openSync(path, 'wx', 0o600);
|
|
31
|
+
try {
|
|
32
|
+
writeSync(fd, JSON.stringify({ pid: process.pid, at: new Date().toISOString() }));
|
|
33
|
+
}
|
|
34
|
+
finally {
|
|
35
|
+
closeSync(fd);
|
|
36
|
+
}
|
|
37
|
+
let released = false;
|
|
38
|
+
return () => {
|
|
39
|
+
if (released)
|
|
40
|
+
return;
|
|
41
|
+
released = true;
|
|
42
|
+
rmSync(path, { force: true });
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
catch (err) {
|
|
46
|
+
if (err.code !== 'EEXIST')
|
|
47
|
+
throw err;
|
|
48
|
+
}
|
|
49
|
+
let holder = 0;
|
|
50
|
+
try {
|
|
51
|
+
holder = JSON.parse(readFileSync(path, 'utf-8')).pid ?? 0;
|
|
52
|
+
}
|
|
53
|
+
catch { /* unreadable: treat as stale */ }
|
|
54
|
+
let age = 0;
|
|
55
|
+
try {
|
|
56
|
+
age = Date.now() - statSync(path).mtimeMs;
|
|
57
|
+
}
|
|
58
|
+
catch { /* gone in between */ }
|
|
59
|
+
// This process already holds it: an install is running here.
|
|
60
|
+
if (holder === process.pid)
|
|
61
|
+
return null;
|
|
62
|
+
const ownerGone = !holder || !isAlive(holder);
|
|
63
|
+
if (!ownerGone && age < staleMs)
|
|
64
|
+
return null;
|
|
65
|
+
rmSync(path, { force: true });
|
|
66
|
+
}
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
/** Waits for the lock, polling; null after `timeoutMs`. */
|
|
70
|
+
async function waitForLock(path, timeoutMs = LOCK_WAIT_MS, pollMs = 1000) {
|
|
71
|
+
const deadline = Date.now() + timeoutMs;
|
|
72
|
+
for (;;) {
|
|
73
|
+
const release = acquireLock(path);
|
|
74
|
+
if (release)
|
|
75
|
+
return release;
|
|
76
|
+
if (Date.now() >= deadline)
|
|
77
|
+
return null;
|
|
78
|
+
await new Promise(resolve => setTimeout(resolve, pollMs));
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* The npm that belongs to the node running this process, run through that
|
|
83
|
+
* node: the npm first on PATH may belong to another node (nvm) and install
|
|
84
|
+
* into another prefix. Falls back to `npm` on PATH.
|
|
85
|
+
*/
|
|
86
|
+
function resolveNpm(execPath = process.execPath, platform = process.platform) {
|
|
87
|
+
const binDir = dirname(execPath);
|
|
88
|
+
const candidates = platform === 'win32'
|
|
89
|
+
? [join(binDir, 'node_modules', 'npm', 'bin', 'npm-cli.js')]
|
|
90
|
+
: [join(binDir, 'npm'), join(dirname(binDir), 'lib', 'node_modules', 'npm', 'bin', 'npm-cli.js')];
|
|
91
|
+
for (const candidate of candidates) {
|
|
92
|
+
try {
|
|
93
|
+
const real = realpathSync(candidate);
|
|
94
|
+
if (real.endsWith('.js'))
|
|
95
|
+
return { command: execPath, args: [real] };
|
|
96
|
+
}
|
|
97
|
+
catch { /* next */ }
|
|
98
|
+
}
|
|
99
|
+
return { command: platform === 'win32' ? 'npm.cmd' : 'npm', args: [] };
|
|
100
|
+
}
|
|
101
|
+
function npmEnv(execPath) {
|
|
102
|
+
// Lifecycle scripts call `node`: make it the same one.
|
|
103
|
+
return { ...process.env, PATH: [dirname(execPath), process.env.PATH ?? ''].join(delimiter) };
|
|
104
|
+
}
|
|
105
|
+
/** Major version of an npm, or 0 when it cannot be asked. */
|
|
106
|
+
function npmMajor(npm, execPath = process.execPath) {
|
|
107
|
+
try {
|
|
108
|
+
const out = execFileSync(npm.command, [...npm.args, '--version'], {
|
|
109
|
+
encoding: 'utf-8', timeout: 30_000, env: npmEnv(execPath), shell: npm.command.endsWith('.cmd'),
|
|
110
|
+
});
|
|
111
|
+
return parseInt(out.trim().split('.')[0] ?? '', 10) || 0;
|
|
112
|
+
}
|
|
113
|
+
catch {
|
|
114
|
+
return 0;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Arguments for the global install. npm 12 blocks install scripts unless
|
|
119
|
+
* allowed; ffmpeg's platform package only marks its binary executable, which
|
|
120
|
+
* the image tools need. Older npm does not know the flag, so it is left out.
|
|
121
|
+
*/
|
|
122
|
+
export function npmInstallArgs(tarball, prefix, major, platform = process.platform, arch = process.arch, force = false) {
|
|
123
|
+
const args = ['install', '--global', '--prefix', prefix, '--no-fund', '--no-audit', '--no-update-notifier'];
|
|
124
|
+
if (major >= 12)
|
|
125
|
+
args.push(`--allow-scripts=@ffmpeg-installer/${platform}-${arch}`);
|
|
126
|
+
// Moving off the legacy scope: the `nordhavn` bin still belongs to the old
|
|
127
|
+
// package, and npm only takes it over when forced.
|
|
128
|
+
if (force)
|
|
129
|
+
args.push('--force');
|
|
130
|
+
args.push(tarball);
|
|
131
|
+
return args;
|
|
132
|
+
}
|
|
133
|
+
function runNpm(npm, args, execPath) {
|
|
134
|
+
return new Promise((resolve, reject) => {
|
|
135
|
+
execFile(npm.command, [...npm.args, ...args], {
|
|
136
|
+
timeout: INSTALL_TIMEOUT_MS, maxBuffer: 16 * 1024 * 1024, env: npmEnv(execPath), shell: npm.command.endsWith('.cmd'),
|
|
137
|
+
}, (err, stdout, stderr) => {
|
|
138
|
+
if (!err)
|
|
139
|
+
return resolve();
|
|
140
|
+
const tail = `${stderr}\n${stdout}`.trim().split('\n').slice(-12).join('\n');
|
|
141
|
+
reject(new Error(`npm install failed: ${err.message}${tail ? `\n${tail}` : ''}`));
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Installs the manifest's release unless the version on disk is already at
|
|
147
|
+
* least that new (another runtime of this machine got there first). Throws on
|
|
148
|
+
* any failure; the install on disk is then whatever npm left, which for a
|
|
149
|
+
* failed `npm i -g` is the previous version.
|
|
150
|
+
*/
|
|
151
|
+
export async function performUpdate(opts) {
|
|
152
|
+
const execPath = opts.execPath ?? process.execPath;
|
|
153
|
+
const release = await waitForLock(opts.lockPath ?? updateLockPath());
|
|
154
|
+
if (!release)
|
|
155
|
+
throw new Error('another update holds the lock');
|
|
156
|
+
let work = null;
|
|
157
|
+
try {
|
|
158
|
+
const onDisk = readPackageVersion(opts.packageDir);
|
|
159
|
+
if (onDisk && !isNewerVersion(opts.manifest.version, onDisk))
|
|
160
|
+
return 'already-installed';
|
|
161
|
+
opts.onStep?.(`downloading ${opts.manifest.url}`);
|
|
162
|
+
const data = await downloadTarball(opts.manifest);
|
|
163
|
+
work = mkdtempSync(join(tmpdir(), 'nordhavn-update-'));
|
|
164
|
+
const tarball = join(work, `nordhavnhq-runner-${opts.manifest.version}.tgz`);
|
|
165
|
+
writeFileSync(tarball, data);
|
|
166
|
+
const npm = resolveNpm(execPath);
|
|
167
|
+
const major = npmMajor(npm, execPath);
|
|
168
|
+
opts.onStep?.(`installing into ${opts.prefix}`);
|
|
169
|
+
await runNpm(npm, npmInstallArgs(tarball, opts.prefix, major, process.platform, process.arch, opts.legacy), execPath);
|
|
170
|
+
const target = opts.legacy ? join(dirname(dirname(opts.packageDir)), PACKAGE_SCOPE, basename(opts.packageDir)) : opts.packageDir;
|
|
171
|
+
const installed = readPackageVersion(target);
|
|
172
|
+
if (installed !== opts.manifest.version) {
|
|
173
|
+
throw new Error(`npm finished but ${target} reports ${installed ?? 'no version'}, expected ${opts.manifest.version}`);
|
|
174
|
+
}
|
|
175
|
+
if (opts.legacy) {
|
|
176
|
+
// The bin now points into the new package; the old folder is dead weight.
|
|
177
|
+
opts.onStep?.(`removing the legacy install at ${opts.packageDir}`);
|
|
178
|
+
rmSync(opts.packageDir, { recursive: true, force: true });
|
|
179
|
+
}
|
|
180
|
+
return 'installed';
|
|
181
|
+
}
|
|
182
|
+
finally {
|
|
183
|
+
if (work && existsSync(work))
|
|
184
|
+
rmSync(work, { recursive: true, force: true });
|
|
185
|
+
release();
|
|
186
|
+
}
|
|
187
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export interface ReleaseManifest {
|
|
2
|
+
version: string;
|
|
3
|
+
url: string;
|
|
4
|
+
sha512: string;
|
|
5
|
+
size: number;
|
|
6
|
+
releasedAt?: string;
|
|
7
|
+
}
|
|
8
|
+
/** Where this runner reads the latest release from. NORDHAVN_UPDATE_MANIFEST_URL wins (tests, staging). */
|
|
9
|
+
export declare function manifestUrl(studioUrl: string | null | undefined, env?: NodeJS.ProcessEnv): string | null;
|
|
10
|
+
/** Validates the shape of a parsed manifest; throws with what is wrong. */
|
|
11
|
+
export declare function parseManifest(data: unknown): ReleaseManifest;
|
|
12
|
+
export declare function fetchManifest(url: string): Promise<ReleaseManifest>;
|
|
13
|
+
/** Base64 sha512 of the bytes, the manifest's format. */
|
|
14
|
+
export declare function sha512Base64(data: Uint8Array): string;
|
|
15
|
+
/** Throws unless the bytes are exactly what the manifest describes. */
|
|
16
|
+
export declare function verifyTarball(data: Uint8Array, manifest: Pick<ReleaseManifest, 'sha512' | 'size'>): void;
|
|
17
|
+
/** Downloads the release tarball and verifies it; never returns unverified bytes. */
|
|
18
|
+
export declare function downloadTarball(manifest: ReleaseManifest): Promise<Buffer>;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
const MANIFEST_PATH = '/api/releases/runner/latest.json';
|
|
3
|
+
const FETCH_TIMEOUT_MS = 30_000;
|
|
4
|
+
const DOWNLOAD_TIMEOUT_MS = 10 * 60_000;
|
|
5
|
+
/** Where this runner reads the latest release from. NORDHAVN_UPDATE_MANIFEST_URL wins (tests, staging). */
|
|
6
|
+
export function manifestUrl(studioUrl, env = process.env) {
|
|
7
|
+
const override = env.NORDHAVN_UPDATE_MANIFEST_URL?.trim();
|
|
8
|
+
if (override)
|
|
9
|
+
return override;
|
|
10
|
+
if (!studioUrl)
|
|
11
|
+
return null;
|
|
12
|
+
return studioUrl.replace(/\/+$/, '') + MANIFEST_PATH;
|
|
13
|
+
}
|
|
14
|
+
/** Plain http is only accepted for a server on this machine (a test server). */
|
|
15
|
+
function isAllowedUrl(raw) {
|
|
16
|
+
let url;
|
|
17
|
+
try {
|
|
18
|
+
url = new URL(raw);
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
if (url.protocol === 'https:')
|
|
24
|
+
return true;
|
|
25
|
+
return url.protocol === 'http:' && ['localhost', '127.0.0.1', '[::1]'].includes(url.hostname);
|
|
26
|
+
}
|
|
27
|
+
/** Validates the shape of a parsed manifest; throws with what is wrong. */
|
|
28
|
+
export function parseManifest(data) {
|
|
29
|
+
const m = data;
|
|
30
|
+
if (!m || typeof m !== 'object')
|
|
31
|
+
throw new Error('manifest is not an object');
|
|
32
|
+
if (typeof m.version !== 'string' || !/^\d+\.\d+\.\d+/.test(m.version))
|
|
33
|
+
throw new Error('manifest has no valid version');
|
|
34
|
+
if (typeof m.url !== 'string' || !isAllowedUrl(m.url))
|
|
35
|
+
throw new Error('manifest url must be https');
|
|
36
|
+
if (typeof m.sha512 !== 'string' || !m.sha512)
|
|
37
|
+
throw new Error('manifest has no sha512');
|
|
38
|
+
if (typeof m.size !== 'number' || !Number.isFinite(m.size) || m.size <= 0)
|
|
39
|
+
throw new Error('manifest has no valid size');
|
|
40
|
+
return { version: m.version, url: m.url, sha512: m.sha512, size: m.size, releasedAt: m.releasedAt };
|
|
41
|
+
}
|
|
42
|
+
export async function fetchManifest(url) {
|
|
43
|
+
if (!isAllowedUrl(url))
|
|
44
|
+
throw new Error(`refusing manifest url ${url}: https only`);
|
|
45
|
+
const res = await fetch(url, { redirect: 'follow', signal: AbortSignal.timeout(FETCH_TIMEOUT_MS), headers: { accept: 'application/json' } });
|
|
46
|
+
if (!res.ok)
|
|
47
|
+
throw new Error(`manifest ${url}: HTTP ${res.status}`);
|
|
48
|
+
return parseManifest(await res.json());
|
|
49
|
+
}
|
|
50
|
+
/** Base64 sha512 of the bytes, the manifest's format. */
|
|
51
|
+
export function sha512Base64(data) {
|
|
52
|
+
return createHash('sha512').update(data).digest('base64');
|
|
53
|
+
}
|
|
54
|
+
/** Throws unless the bytes are exactly what the manifest describes. */
|
|
55
|
+
export function verifyTarball(data, manifest) {
|
|
56
|
+
if (data.byteLength !== manifest.size) {
|
|
57
|
+
throw new Error(`tarball size ${data.byteLength} does not match the manifest (${manifest.size})`);
|
|
58
|
+
}
|
|
59
|
+
const expected = manifest.sha512.replace(/^sha512-/, '');
|
|
60
|
+
if (sha512Base64(data) !== expected)
|
|
61
|
+
throw new Error('tarball sha512 does not match the manifest');
|
|
62
|
+
}
|
|
63
|
+
/** Downloads the release tarball and verifies it; never returns unverified bytes. */
|
|
64
|
+
export async function downloadTarball(manifest) {
|
|
65
|
+
if (!isAllowedUrl(manifest.url))
|
|
66
|
+
throw new Error(`refusing tarball url ${manifest.url}: https only`);
|
|
67
|
+
const res = await fetch(manifest.url, { redirect: 'follow', signal: AbortSignal.timeout(DOWNLOAD_TIMEOUT_MS) });
|
|
68
|
+
if (!res.ok)
|
|
69
|
+
throw new Error(`tarball ${manifest.url}: HTTP ${res.status}`);
|
|
70
|
+
const data = Buffer.from(await res.arrayBuffer());
|
|
71
|
+
verifyTarball(data, manifest);
|
|
72
|
+
return data;
|
|
73
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type AgentStatus } from '../runtime/daemon.js';
|
|
2
|
+
export declare const RESTART_SIGNAL: NodeJS.Signals;
|
|
3
|
+
export interface RuntimeProcess {
|
|
4
|
+
pid: number;
|
|
5
|
+
mode: AgentStatus['mode'];
|
|
6
|
+
refs: string[];
|
|
7
|
+
version: string | null;
|
|
8
|
+
activeRuns: number;
|
|
9
|
+
}
|
|
10
|
+
/** The live runtime processes, one entry per pid (a foreground run can drive several agents). */
|
|
11
|
+
export declare function liveRuntimes(statuses?: AgentStatus[]): RuntimeProcess[];
|
|
12
|
+
/** True when the platform can deliver RESTART_SIGNAL. */
|
|
13
|
+
export declare function canSignalRestart(platform?: NodeJS.Platform): boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Tells every self-updating runtime but `exceptPid` to restart into the version
|
|
16
|
+
* on disk. Returns the pids that were signalled.
|
|
17
|
+
*/
|
|
18
|
+
export declare function signalRestart(exceptPid?: number | null, runtimes?: RuntimeProcess[]): number[];
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { readAllStatuses, isStatusAlive } from '../runtime/daemon.js';
|
|
2
|
+
// ─── Other runtimes on this machine ──────────
|
|
3
|
+
//
|
|
4
|
+
// After an install, every running runtime should move to the new version. A
|
|
5
|
+
// runtime that knows self-update (its status file carries `version`) takes
|
|
6
|
+
// RESTART_SIGNAL as "a newer version is on disk": it restarts once idle.
|
|
7
|
+
export const RESTART_SIGNAL = 'SIGUSR2';
|
|
8
|
+
/** The live runtime processes, one entry per pid (a foreground run can drive several agents). */
|
|
9
|
+
export function liveRuntimes(statuses = readAllStatuses()) {
|
|
10
|
+
const byPid = new Map();
|
|
11
|
+
for (const s of statuses) {
|
|
12
|
+
if (!isStatusAlive(s))
|
|
13
|
+
continue;
|
|
14
|
+
const entry = byPid.get(s.pid) ?? { pid: s.pid, mode: s.mode, refs: [], version: s.version ?? null, activeRuns: 0 };
|
|
15
|
+
entry.refs.push(s.ref);
|
|
16
|
+
entry.activeRuns += s.activeRuns ?? 0;
|
|
17
|
+
byPid.set(s.pid, entry);
|
|
18
|
+
}
|
|
19
|
+
return [...byPid.values()];
|
|
20
|
+
}
|
|
21
|
+
/** True when the platform can deliver RESTART_SIGNAL. */
|
|
22
|
+
export function canSignalRestart(platform = process.platform) {
|
|
23
|
+
return platform !== 'win32';
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Tells every self-updating runtime but `exceptPid` to restart into the version
|
|
27
|
+
* on disk. Returns the pids that were signalled.
|
|
28
|
+
*/
|
|
29
|
+
export function signalRestart(exceptPid = null, runtimes = liveRuntimes()) {
|
|
30
|
+
if (!canSignalRestart())
|
|
31
|
+
return [];
|
|
32
|
+
const signalled = [];
|
|
33
|
+
for (const r of runtimes) {
|
|
34
|
+
if (r.pid === exceptPid || !r.version)
|
|
35
|
+
continue;
|
|
36
|
+
try {
|
|
37
|
+
process.kill(r.pid, RESTART_SIGNAL);
|
|
38
|
+
signalled.push(r.pid);
|
|
39
|
+
}
|
|
40
|
+
catch { /* gone in between */ }
|
|
41
|
+
}
|
|
42
|
+
return signalled;
|
|
43
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Config } from '../config.js';
|
|
2
|
+
import { type InstallKind } from './install-kind.js';
|
|
3
|
+
import { Updater } from './updater.js';
|
|
4
|
+
/** True when the operator turned automatic updates off (config or env). */
|
|
5
|
+
export declare function autoUpdateOptedOut(config: Config | null, env?: NodeJS.ProcessEnv): boolean;
|
|
6
|
+
/** How the operator updates this kind of install, for notices. */
|
|
7
|
+
export declare function updateHint(kind: InstallKind['kind']): string;
|
|
8
|
+
export interface RuntimeUpdater {
|
|
9
|
+
updater: Updater;
|
|
10
|
+
kind: InstallKind;
|
|
11
|
+
/** Why it does not install by itself, or null when it does. */
|
|
12
|
+
manualReason: string | null;
|
|
13
|
+
}
|
|
14
|
+
/** The updater a running `nordhavn up` uses. */
|
|
15
|
+
export declare function createRuntimeUpdater(opts: {
|
|
16
|
+
config: Config;
|
|
17
|
+
isIdle: () => boolean;
|
|
18
|
+
restart: () => void;
|
|
19
|
+
log: (msg: string) => void;
|
|
20
|
+
}): RuntimeUpdater;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { VERSION } from '../utils/format.js';
|
|
2
|
+
import { currentPackageDir, detectInstallKind, readPackageVersion, runningPackageDir } from './install-kind.js';
|
|
3
|
+
import { performUpdate } from './install.js';
|
|
4
|
+
import { fetchManifest, manifestUrl } from './manifest.js';
|
|
5
|
+
import { signalRestart } from './peers.js';
|
|
6
|
+
import { Updater } from './updater.js';
|
|
7
|
+
/** True when the operator turned automatic updates off (config or env). */
|
|
8
|
+
export function autoUpdateOptedOut(config, env = process.env) {
|
|
9
|
+
const flag = (env.NORDHAVN_NO_AUTO_UPDATE ?? '').trim().toLowerCase();
|
|
10
|
+
if (flag === '1' || flag === 'true' || flag === 'yes')
|
|
11
|
+
return true;
|
|
12
|
+
return config?.autoUpdate === false;
|
|
13
|
+
}
|
|
14
|
+
/** How the operator updates this kind of install, for notices. */
|
|
15
|
+
export function updateHint(kind) {
|
|
16
|
+
return kind === 'global' ? 'nordhavn update' : 'git pull and rebuild the runner';
|
|
17
|
+
}
|
|
18
|
+
/** The updater a running `nordhavn up` uses. */
|
|
19
|
+
export function createRuntimeUpdater(opts) {
|
|
20
|
+
const kind = detectInstallKind();
|
|
21
|
+
const optedOut = autoUpdateOptedOut(opts.config);
|
|
22
|
+
const url = manifestUrl(opts.config.studioUrl);
|
|
23
|
+
const manualReason = kind.kind !== 'global'
|
|
24
|
+
? kind.reason
|
|
25
|
+
: optedOut ? 'automatic updates are off' : !url ? 'no studio url' : null;
|
|
26
|
+
const packageDir = kind.kind === 'global' ? kind.packageDir : runningPackageDir();
|
|
27
|
+
const updater = new Updater({
|
|
28
|
+
currentVersion: VERSION,
|
|
29
|
+
enabled: manualReason === null,
|
|
30
|
+
isIdle: opts.isIdle,
|
|
31
|
+
fetchLatest: () => {
|
|
32
|
+
if (!url)
|
|
33
|
+
return Promise.reject(new Error('no manifest url'));
|
|
34
|
+
return fetchManifest(url);
|
|
35
|
+
},
|
|
36
|
+
install: async (manifest) => {
|
|
37
|
+
if (kind.kind !== 'global')
|
|
38
|
+
throw new Error(`not a global install: ${kind.reason}`);
|
|
39
|
+
const result = await performUpdate({ manifest, prefix: kind.prefix, packageDir: kind.packageDir, legacy: kind.legacy });
|
|
40
|
+
// The other runtimes of this machine (one per detached agent) move too.
|
|
41
|
+
signalRestart(process.pid);
|
|
42
|
+
return result;
|
|
43
|
+
},
|
|
44
|
+
installedVersion: () => readPackageVersion(packageDir && currentPackageDir(packageDir)),
|
|
45
|
+
restart: opts.restart,
|
|
46
|
+
log: opts.log,
|
|
47
|
+
});
|
|
48
|
+
return { updater, kind, manualReason };
|
|
49
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/** EX_TEMPFAIL: "restart me". */
|
|
2
|
+
export declare const RESTART_EXIT_CODE = 75;
|
|
3
|
+
/** Set on the worker, so it knows a restart is its parent's job. */
|
|
4
|
+
export declare const SUPERVISED_ENV = "NORDHAVN_SUPERVISED";
|
|
5
|
+
export type WorkerExit = {
|
|
6
|
+
action: 'restart';
|
|
7
|
+
} | {
|
|
8
|
+
action: 'exit';
|
|
9
|
+
code: number;
|
|
10
|
+
};
|
|
11
|
+
/** What the supervisor does when its worker ends. */
|
|
12
|
+
export declare function decideOnExit(code: number | null, signal: NodeJS.Signals | null): WorkerExit;
|
|
13
|
+
export interface SuperviseOptions {
|
|
14
|
+
command: string;
|
|
15
|
+
args: string[];
|
|
16
|
+
env?: NodeJS.ProcessEnv;
|
|
17
|
+
/** A line for the terminal (restarts, a restart loop). */
|
|
18
|
+
log?: (msg: string) => void;
|
|
19
|
+
now?: () => number;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Runs the worker until it ends with anything but a restart; resolves with the
|
|
23
|
+
* code to exit with. Never calls process.exit itself.
|
|
24
|
+
*/
|
|
25
|
+
export declare function supervise(opts: SuperviseOptions): Promise<number>;
|