@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,739 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import { createWriteStream, mkdirSync, writeFileSync } from 'node:fs';
|
|
3
|
+
import { resolve, isAbsolute, join } from 'node:path';
|
|
4
|
+
import { homedir } from 'node:os';
|
|
5
|
+
import { activeWriteScope, hasWriteScope, isInsideRoot, isOutsideWriteScope, jailRoots, readOnlyRoots, realpathSafe, scopeWriteError } from './_jail.js';
|
|
6
|
+
import { clipCommandStreams, clipHeadTail, COMMAND_OUTPUT_MAX_CHARS } from './_output.js';
|
|
7
|
+
import { stopAllProcesses, trackProcess, waitForPreview } from '../runtime/processes.js';
|
|
8
|
+
import { projectNodeLabel, projectNodeNote, resolveProjectNode, withNodeBin } from '../runtime/project-node.js';
|
|
9
|
+
import { recordTouched, snapshotCheckout } from './_touched.js';
|
|
10
|
+
import { isForcedRecursiveRm, unquote } from './_shell-words.js';
|
|
11
|
+
// ─── Long-running / Dev Server Detection ────
|
|
12
|
+
// These patterns indicate a command that starts a persistent server
|
|
13
|
+
// and will never exit on its own (dev servers, watchers, etc.)
|
|
14
|
+
const LONG_RUNNING_PATTERNS = [
|
|
15
|
+
/\b(npm|npx|pnpm|yarn|bunx?)\s+(run\s+)?(dev|start|serve|preview|watch)\b/,
|
|
16
|
+
/\b(astro|vite|next|nuxt|gatsby|remix|svelte-kit)\s+(dev|preview|start)\b/,
|
|
17
|
+
/\bnode\s+.*server/,
|
|
18
|
+
/\blive-server\b/,
|
|
19
|
+
/\bhttp-server\b/,
|
|
20
|
+
/\bnodemon\b/,
|
|
21
|
+
/\btsc\s+--watch\b/,
|
|
22
|
+
/\bwebpack\s+serve\b/,
|
|
23
|
+
/\bng\s+serve\b/,
|
|
24
|
+
/\bphp\s+artisan\s+serve\b/,
|
|
25
|
+
/\bphp\s+-S\s/,
|
|
26
|
+
/\bcomposer\s+(run\s+)?dev\b/,
|
|
27
|
+
/\bpython3?\s+-m\s+http\.server\b/,
|
|
28
|
+
/\bmanage\.py\s+runserver\b/,
|
|
29
|
+
/\buvicorn\b/,
|
|
30
|
+
/\bflask\s+run\b/,
|
|
31
|
+
/\b(bin\/)?rails\s+(s|server)\b/,
|
|
32
|
+
/\bhugo\s+server\b/,
|
|
33
|
+
/\bwrangler\s+dev\b/,
|
|
34
|
+
/\bdeno\s+task\s+(dev|start)\b/,
|
|
35
|
+
];
|
|
36
|
+
// Patterns in output that confirm a server is ready
|
|
37
|
+
const SERVER_READY_PATTERNS = [
|
|
38
|
+
/local(host)?:\s*\d+/i,
|
|
39
|
+
/server\s+(is\s+)?running/i,
|
|
40
|
+
/listening\s+on/i,
|
|
41
|
+
/ready\s+(in|on|at)/i,
|
|
42
|
+
/started\s+(server|at|on)/i,
|
|
43
|
+
/http:\/\/\S+:\d+/,
|
|
44
|
+
/https:\/\/\S+:\d+/,
|
|
45
|
+
/preview\s+server/i,
|
|
46
|
+
/dev\s+server/i,
|
|
47
|
+
];
|
|
48
|
+
/** Is `command` a dev server or watcher (it never ends on its own)? Exported for `proc:start`. */
|
|
49
|
+
export function isLongRunningCommand(command) {
|
|
50
|
+
return LONG_RUNNING_PATTERNS.some(p => p.test(command));
|
|
51
|
+
}
|
|
52
|
+
// ─── Slow batch commands ────
|
|
53
|
+
// Finite commands that legitimately run for minutes (builds, installs, test
|
|
54
|
+
// suites, type checks). These must NOT go through the long-running/detached
|
|
55
|
+
// path above - they exit on their own - but the 60s default timeout would
|
|
56
|
+
// SIGKILL a cold build halfway. When the model didn't pass an explicit
|
|
57
|
+
// `timeout`, give these a 300s default instead.
|
|
58
|
+
const SLOW_COMMAND_PATTERNS = [
|
|
59
|
+
/\b(npm|npx|pnpm|yarn|bunx?)\s+(run\s+)?(build|check|test|ci)\b/,
|
|
60
|
+
/\b(npm|pnpm|yarn|bun)\s+(i|install|ci|add)\b/,
|
|
61
|
+
/\b(astro|vite|next|nuxt|gatsby|remix|svelte-kit)\s+(build|check|sync)\b/,
|
|
62
|
+
/\btsc\b/,
|
|
63
|
+
/\b(vitest|jest|playwright)\b/,
|
|
64
|
+
/\bprisma\s+(migrate|generate|db)\b/,
|
|
65
|
+
];
|
|
66
|
+
const DEFAULT_TIMEOUT_SEC = 60;
|
|
67
|
+
const SLOW_DEFAULT_TIMEOUT_SEC = 300;
|
|
68
|
+
const MAX_TIMEOUT_SEC = 600;
|
|
69
|
+
/** Resolve the effective timeout for a command: an explicit, valid `timeout`
|
|
70
|
+
* param wins (capped at MAX); otherwise build/install/test-like commands get
|
|
71
|
+
* the slow default and everything else the normal default. Exported for tests. */
|
|
72
|
+
export function resolveCommandTimeoutSec(command, requested) {
|
|
73
|
+
if (typeof requested === 'number' && Number.isFinite(requested) && requested > 0) {
|
|
74
|
+
return Math.min(requested, MAX_TIMEOUT_SEC);
|
|
75
|
+
}
|
|
76
|
+
return SLOW_COMMAND_PATTERNS.some(p => p.test(command)) ? SLOW_DEFAULT_TIMEOUT_SEC : DEFAULT_TIMEOUT_SEC;
|
|
77
|
+
}
|
|
78
|
+
function outputIndicatesServerReady(output) {
|
|
79
|
+
return SERVER_READY_PATTERNS.some(p => p.test(output));
|
|
80
|
+
}
|
|
81
|
+
/** How long a dev server's result waits for its preview address. */
|
|
82
|
+
const PREVIEW_WAIT_MS = 8_000;
|
|
83
|
+
/** What a dev server's result says about its preview. */
|
|
84
|
+
const previewNote = (url) => `Preview: ${url} - this is the interface of what you run: the people of the project open it in any browser, and in the studio as a dev surface of this session, until the server stops or the session ends. Give it to the person when they want to look; do not create a surface for it and do not open it for them.`;
|
|
85
|
+
// ─── Console / Shell Tools ──────────────────
|
|
86
|
+
const runCommandDefinition = {
|
|
87
|
+
name: 'runner_run_command',
|
|
88
|
+
description: 'Execute a shell command. Commands run in the project root (in the session\'s scope folder when the session has one) and are sandboxed to the project + agent home. With a scope, a cwd outside it is refused and plain writes outside it (rm, mv, cp, >, ...) are blocked, but the shell cannot be fully fenced: never change files outside the scope through a script or a build. Output is capped at 30k chars (start + end kept), so filter it yourself. Dev servers are auto-detected as long-running and started in background (the result carries a `preview` address when the studio offers previews: the interface people open, never a surface to create or open yourself); pass background=true for any other long command. Do NOT use for file read/write/search - use runner_read_file, runner_grep and runner_glob. Pushing is blocked here: runner_git_push publishes a branch, only when the user asks for it.',
|
|
89
|
+
parameters: {
|
|
90
|
+
type: 'object',
|
|
91
|
+
properties: {
|
|
92
|
+
command: { type: 'string', description: 'Shell command to execute. Can chain with && or |.' },
|
|
93
|
+
description: { type: 'string', description: 'What it does in 3 to 8 words, the title people see: "Run the inference tests".' },
|
|
94
|
+
cwd: { type: 'string', description: 'Working directory relative to the project root. Default: the session\'s scope folder, else the project root.' },
|
|
95
|
+
timeout: { type: 'number', description: 'Timeout in seconds (default: 60; build/install/test-like commands default to 300; max: 600). Ignored with background=true.' },
|
|
96
|
+
background: { type: 'boolean', description: 'Start the command and return at once with a log file to check later (tail it with this tool). For a full test suite or a long build you do not need to watch.' },
|
|
97
|
+
},
|
|
98
|
+
required: ['command'],
|
|
99
|
+
},
|
|
100
|
+
};
|
|
101
|
+
// Commands that are never allowed
|
|
102
|
+
const BLOCKED_PATTERNS = [
|
|
103
|
+
/\bsudo\b/,
|
|
104
|
+
/\bmkfs\b/,
|
|
105
|
+
/\bdd\s+/,
|
|
106
|
+
/\b:(){ :|:& };:/, // fork bomb
|
|
107
|
+
/\bchmod\s+-R\s+777/,
|
|
108
|
+
/\bcurl\b.*\|\s*(sh|bash)/, // curl pipe to shell
|
|
109
|
+
/\bwget\b.*\|\s*(sh|bash)/,
|
|
110
|
+
];
|
|
111
|
+
/**
|
|
112
|
+
* The variables of the runner's own environment a command an agent starts
|
|
113
|
+
* gets. Nothing else is handed on: the runner's environment holds its tokens,
|
|
114
|
+
* API keys and whatever the person who started it had exported, and none of
|
|
115
|
+
* that is the agent's to read. `LC_*` and the proxy variables match by prefix
|
|
116
|
+
* or in either case. Exported for tests.
|
|
117
|
+
*/
|
|
118
|
+
const COMMAND_ENV_ALLOW = [
|
|
119
|
+
'PATH', 'USER', 'LOGNAME', 'SHELL', 'LANG', 'LANGUAGE', 'TZ', 'TMPDIR', 'TEMP', 'TMP',
|
|
120
|
+
'COLORTERM', 'NO_COLOR', 'FORCE_COLOR', 'CI',
|
|
121
|
+
'HTTP_PROXY', 'HTTPS_PROXY', 'NO_PROXY', 'ALL_PROXY',
|
|
122
|
+
'NVM_DIR', 'NVM_BIN', 'VOLTA_HOME', 'PNPM_HOME', 'COREPACK_HOME', 'BUN_INSTALL',
|
|
123
|
+
'JAVA_HOME', 'GOPATH', 'GOROOT', 'CARGO_HOME', 'RUSTUP_HOME', 'PYENV_ROOT',
|
|
124
|
+
'HOMEBREW_PREFIX', 'HOMEBREW_CELLAR', 'HOMEBREW_REPOSITORY',
|
|
125
|
+
// Windows needs these to start anything at all.
|
|
126
|
+
'SYSTEMROOT', 'WINDIR', 'COMSPEC', 'PATHEXT', 'SYSTEMDRIVE', 'PROGRAMFILES', 'PROGRAMDATA',
|
|
127
|
+
];
|
|
128
|
+
/**
|
|
129
|
+
* More variable names an operator lets through, comma separated in
|
|
130
|
+
* `NORDHAVN_COMMAND_ENV_ALLOW` (for a tool that cannot do without one).
|
|
131
|
+
*/
|
|
132
|
+
const extraAllowed = () => (process.env.NORDHAVN_COMMAND_ENV_ALLOW ?? '')
|
|
133
|
+
.split(',').map(s => s.trim().toUpperCase()).filter(Boolean);
|
|
134
|
+
function envAllowed(name, allow) {
|
|
135
|
+
const upper = name.toUpperCase();
|
|
136
|
+
return allow.has(upper) || upper.startsWith('LC_');
|
|
137
|
+
}
|
|
138
|
+
/** The HOME a command's shell gets: the agent's own home, else the base dir. */
|
|
139
|
+
function shellHome(context, base) {
|
|
140
|
+
return context?.agentHome || base;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* The environment every command an agent starts runs in (the shell, a test
|
|
144
|
+
* run, a worktree setup script). It is built from `COMMAND_ENV_ALLOW`, never
|
|
145
|
+
* the runner's whole environment, so a secret the runner holds does not reach
|
|
146
|
+
* `env` or `printenv`. HOME is the agent's own home so `~` and tools stay
|
|
147
|
+
* sandboxed to its personal space; `NORDHAVN_SCRATCH` points at this
|
|
148
|
+
* dispatch's throwaway scratch dir so steps can drop temp files there
|
|
149
|
+
* (`> "$NORDHAVN_SCRATCH/out.json"`) instead of in the project checkout.
|
|
150
|
+
* `nodeBin`, the bin dir of the Node the project pins (`resolveProjectNode`),
|
|
151
|
+
* goes first on PATH.
|
|
152
|
+
*/
|
|
153
|
+
export function commandEnv(context, base, source = process.env, nodeBin) {
|
|
154
|
+
const allow = new Set([...COMMAND_ENV_ALLOW, ...extraAllowed()]);
|
|
155
|
+
const env = {};
|
|
156
|
+
for (const [name, value] of Object.entries(source)) {
|
|
157
|
+
if (value !== undefined && envAllowed(name, allow))
|
|
158
|
+
env[name] = value;
|
|
159
|
+
}
|
|
160
|
+
const out = {
|
|
161
|
+
...env,
|
|
162
|
+
TERM: 'dumb',
|
|
163
|
+
SUDO_ASKPASS: '/bin/false',
|
|
164
|
+
DEBIAN_FRONTEND: 'noninteractive',
|
|
165
|
+
HOME: shellHome(context, base),
|
|
166
|
+
// JUSTMADE_SCRATCH: the pre-rename name, for prompts and scripts that still use it.
|
|
167
|
+
...(context?.scratchRoot ? { NORDHAVN_SCRATCH: context.scratchRoot, JUSTMADE_SCRATCH: context.scratchRoot } : {}),
|
|
168
|
+
};
|
|
169
|
+
return nodeBin ? withNodeBin(out, nodeBin) : out;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* A command's result with the project's Node in it: a short `node` field when
|
|
173
|
+
* the pinned one ran it, a `nodeWarning` line when it could not be had. A
|
|
174
|
+
* result that is no JSON object gets the warning as a last line.
|
|
175
|
+
*/
|
|
176
|
+
export async function withProjectNode(result, node) {
|
|
177
|
+
const label = projectNodeLabel(node);
|
|
178
|
+
const warning = await projectNodeNote(node);
|
|
179
|
+
if (!label && !warning)
|
|
180
|
+
return result;
|
|
181
|
+
try {
|
|
182
|
+
const parsed = JSON.parse(result);
|
|
183
|
+
if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) {
|
|
184
|
+
return JSON.stringify({ ...parsed, ...(label ? { node: label } : {}), ...(warning ? { nodeWarning: warning } : {}) });
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
catch { /* plain text */ }
|
|
188
|
+
return warning ? `${result}\n${warning}` : result;
|
|
189
|
+
}
|
|
190
|
+
export function isBlocked(command) {
|
|
191
|
+
if (isForcedRecursiveRm(command))
|
|
192
|
+
return 'Blocked: a recursive forced rm (rm -rf and its spellings) is not allowed';
|
|
193
|
+
for (const pattern of BLOCKED_PATTERNS) {
|
|
194
|
+
if (pattern.test(command)) {
|
|
195
|
+
return `Blocked: command matches restricted pattern ${pattern}`;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
return null;
|
|
199
|
+
}
|
|
200
|
+
// Publishing to a remote is a human decision. Committing is not: commits are
|
|
201
|
+
// local and reversible, so the git toolset lets an agent stage and commit
|
|
202
|
+
// freely. Pushing is user-initiated, not banned: it goes through the dedicated
|
|
203
|
+
// `runner_git_push` tool (which refuses in task runs and is called only when
|
|
204
|
+
// the user asked for a push), never through this shell. Keeping the shell
|
|
205
|
+
// closed leaves exactly one gated push route instead of a promptable bypass.
|
|
206
|
+
// Also covers the gh subcommands that push a branch as a side effect of
|
|
207
|
+
// publishing (pr create/merge, repo sync, release create) - those have no tool
|
|
208
|
+
// and stay a person's job; read-only gh calls (pr list/view/diff) stay allowed.
|
|
209
|
+
//
|
|
210
|
+
// This is a best-effort guard, not a sandbox: a shell can always build the
|
|
211
|
+
// word at run time (variables, base64, a script file) and the patterns cannot
|
|
212
|
+
// see that. It closes the obvious and the accidental routes; the real boundary
|
|
213
|
+
// is the remote's credentials and the person who grants them.
|
|
214
|
+
/** The global flags that may sit between `git` and its subcommand. */
|
|
215
|
+
const GIT_FLAGS = String.raw `(?:(?:-C|-c|--git-dir|--work-tree|--exec-path|--namespace|--super-prefix|--config-env|--attr-source)(?:=|\s+)\S+\s+|--[a-z][\w-]*(?:=\S+)?\s+|-[a-zA-Z]\s+)*`;
|
|
216
|
+
const GIT_PUSH_PATTERNS = [
|
|
217
|
+
// `git push`, including the global flags that may precede a subcommand
|
|
218
|
+
// (`git -C repo push`, `git -c x=y push`, `git --git-dir=... push`), from
|
|
219
|
+
// any path (`/usr/bin/git`) and behind any wrapper (`command git`, `env A=1
|
|
220
|
+
// git`): `\bgit` matches wherever the word starts. Deliberately narrow: only
|
|
221
|
+
// real flag tokens may sit between `git` and `push`, so a commit message
|
|
222
|
+
// that merely contains the word ("git commit -m 'add push notifications'")
|
|
223
|
+
// is not caught. Matched on the unquoted line, so `git 'push'` counts.
|
|
224
|
+
new RegExp(String.raw `\bgit\s+${GIT_FLAGS}push\b`),
|
|
225
|
+
// An alias that pushes (`git -c alias.x='!git push' x`): the alias call
|
|
226
|
+
// itself no longer says push, so the definition is what gets caught.
|
|
227
|
+
/\balias\.[\w.-]+(?:\s*=\s*|\s+)!?\s*(?:git\s+)?push\b/,
|
|
228
|
+
// Any alias stored in a git config (`git config alias.p ...`, `git config
|
|
229
|
+
// --global alias.x ...`): its value can be assembled so no pattern sees a
|
|
230
|
+
// push in it, and it outlives this command, so defining one is closed.
|
|
231
|
+
new RegExp(String.raw `\bgit\s+${GIT_FLAGS}config\b[^;&|\n]*\balias\.`),
|
|
232
|
+
// Writing a git config file by hand (`>> .git/config`, `tee ~/.gitconfig`,
|
|
233
|
+
// `sed -i ... .git/config`) or an `[alias]` section anywhere: the same
|
|
234
|
+
// alias route without `git config`.
|
|
235
|
+
/(?:>>?|\btee\b[^;&|\n]*|\b(?:sed|perl)\s+[^;&|\n]*-i[^;&|\n]*|\b(?:cp|mv|ln|install)\s+[^;&|\n]*)\s*\S*(?:\.git\/config|\.gitconfig|git\/config)\b/,
|
|
236
|
+
/\[alias\]/,
|
|
237
|
+
/\bgh\s+pr\s+(?:create|merge)\b/,
|
|
238
|
+
/\bgh\s+repo\s+sync\b/,
|
|
239
|
+
/\bgh\s+release\s+create\b/,
|
|
240
|
+
];
|
|
241
|
+
/** Block any attempt to publish commits to a remote from the shell. Exported for tests. */
|
|
242
|
+
export function detectGitPush(command) {
|
|
243
|
+
// Quotes and backslash escapes split no word in the shell (`git "pu"sh`,
|
|
244
|
+
// `git pu\sh` run a push), so the patterns read the line without them.
|
|
245
|
+
const line = unquote(command);
|
|
246
|
+
for (const pattern of GIT_PUSH_PATTERNS) {
|
|
247
|
+
if (pattern.test(line)) {
|
|
248
|
+
return `Blocked: don't push from the shell. To publish a git branch, use runner_git_push - it is the only push route, called only when the user asked for a push (never offer one yourself), and it refuses in task runs where no one is present. Publishing via gh (pr create/merge, repo sync, release create) has no tool and stays a person's job. Committing is free: stage and commit with runner_git_commit as much as you like.`;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
return null;
|
|
252
|
+
}
|
|
253
|
+
// Attempts to read, print, or decrypt secret material via the shell. Secrets
|
|
254
|
+
// live AES-encrypted in the studio DB, never on this machine, so these can only
|
|
255
|
+
// be misguided exfiltration attempts (the exact failure mode where an agent,
|
|
256
|
+
// seeing a redacted secret, tries to grab the value another way). Block them and
|
|
257
|
+
// redirect to the only correct path: the ${secret:KEY} placeholder flow.
|
|
258
|
+
const SECRET_EXFIL_PATTERNS = [
|
|
259
|
+
/\bsecurity\s+find-(generic|internet)-password\b/i, // macOS keychain
|
|
260
|
+
/\b(printenv|env|set)\b[^|]*\|[^|]*\bgrep\b[^|]*\b(secret|token|api[_-]?key|apikey|password|passwd|bearer|credential)/i,
|
|
261
|
+
/\becho\s+["']?\$\{?[A-Za-z_][A-Za-z0-9_]*(SECRET|TOKEN|KEY|PASSWORD|PASSWD|APIKEY|CREDENTIAL)/i,
|
|
262
|
+
/\b(cat|less|more|head|tail|grep|strings|xxd|od)\b[^|;&]*(^|\/|\s|\.)\.?env(\.|\b)/i, // reading .env files
|
|
263
|
+
];
|
|
264
|
+
function detectSecretExfil(command) {
|
|
265
|
+
for (const pattern of SECRET_EXFIL_PATTERNS) {
|
|
266
|
+
if (pattern.test(command)) {
|
|
267
|
+
return `Blocked: this looks like an attempt to read or decrypt secret material via the shell. Secret values never live on this machine (they are encrypted server-side) and must never be fetched, printed, or decrypted by hand. To USE a secret, embed the placeholder \${secret:KEY} inside another tool's argument - e.g. an studio_mcp_call / studio_http_request header - and the studio resolves it server-side just before the call. If the secret you need does not exist, say so instead of working around it.`;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
return null;
|
|
271
|
+
}
|
|
272
|
+
/** Shell verbs that only read the path right after them. */
|
|
273
|
+
const READ_ONLY_VERBS = new Set(['cat', 'ls', 'cp', 'head', 'tail', 'less', 'more', 'find', 'grep', 'wc', 'stat', 'file']);
|
|
274
|
+
/** A `cd <dir>` in a command: where the paths after it are relative to. */
|
|
275
|
+
const CD_REGEX = /(?:^|[;&|(])\s*cd\s+["']?([^\s;|&)"']+)/g;
|
|
276
|
+
/**
|
|
277
|
+
* The directory a relative path at `index` in the command resolves from: the
|
|
278
|
+
* directory the command starts in, moved by every `cd <dir>` that ends before
|
|
279
|
+
* it, left to right (`cd apps/runner && node ../../x` reads `x` at the root).
|
|
280
|
+
* A `cd` inside a subshell is followed too: the guard is a tripwire against an
|
|
281
|
+
* agent wandering off, not a sandbox (the OS user is).
|
|
282
|
+
*/
|
|
283
|
+
function dirAt(command, index, start, home) {
|
|
284
|
+
let dir = start;
|
|
285
|
+
for (const cd of command.matchAll(CD_REGEX)) {
|
|
286
|
+
if (cd.index + cd[0].length > index)
|
|
287
|
+
break;
|
|
288
|
+
const target = cd[1];
|
|
289
|
+
if (target === '-')
|
|
290
|
+
continue;
|
|
291
|
+
dir = cdTarget(dir, target, home);
|
|
292
|
+
}
|
|
293
|
+
return dir;
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* The target of the first `cd` in the command that lands outside every root,
|
|
297
|
+
* or null. `cd .. && cat x` has no `../` to catch, and the paths after it are
|
|
298
|
+
* relative to wherever it went.
|
|
299
|
+
*/
|
|
300
|
+
function cdOutsideRoots(command, base, home, allowed) {
|
|
301
|
+
let dir = base;
|
|
302
|
+
for (const cd of command.matchAll(CD_REGEX)) {
|
|
303
|
+
const target = cd[1];
|
|
304
|
+
if (target === '-')
|
|
305
|
+
continue;
|
|
306
|
+
dir = cdTarget(dir, target, home);
|
|
307
|
+
if (!allowed(dir))
|
|
308
|
+
return target;
|
|
309
|
+
}
|
|
310
|
+
return null;
|
|
311
|
+
}
|
|
312
|
+
/** Where `cd <target>` from `dir` lands; `~` and `$HOME` are the shell's HOME (the agent's home, see `commandEnv`). */
|
|
313
|
+
function cdTarget(dir, target, home) {
|
|
314
|
+
const fromHome = target.match(/^(?:~|\$HOME|\$\{HOME\})(\/.*)?$/);
|
|
315
|
+
if (fromHome)
|
|
316
|
+
return resolve(home, `.${fromHome[1] ?? ''}`);
|
|
317
|
+
return resolve(dir, target);
|
|
318
|
+
}
|
|
319
|
+
// Detect attempts to access paths outside the agent's allowed roots (project
|
|
320
|
+
// root + agent home). `base` is the directory the command runs in (its `cwd`),
|
|
321
|
+
// which relative `../` paths resolve against, moved by any `cd` before them.
|
|
322
|
+
export function detectPathEscape(command, roots, base, readRoots = [], shellHome = homedir()) {
|
|
323
|
+
const home = homedir();
|
|
324
|
+
const allowed = (p) => roots.some(r => isInsideRoot(p, r));
|
|
325
|
+
// A read-only root (a call's caller's scratch) only opens to commands that
|
|
326
|
+
// read the path they are given: `cp` reads its first path (the source).
|
|
327
|
+
const readable = (p) => readRoots.some(r => isInsideRoot(p, r));
|
|
328
|
+
// Absolute paths outside every root (allow optional flags like -p, -r, etc. between command and path)
|
|
329
|
+
const absPathRegex = /(?:^|\s|[;|&(])\s*(cat|ls|cd|cp|mv|rm|head|tail|less|more|nano|vi|vim|open|find|grep|awk|sed|wc|stat|file|touch|mkdir|chmod|chown|ln|tar|zip|unzip|source|\.)(?:\s+-[^\s/]*)*\s+["']?(\/[^\s;|&)]*)/g;
|
|
330
|
+
let match;
|
|
331
|
+
while ((match = absPathRegex.exec(command)) !== null) {
|
|
332
|
+
const verb = match[1];
|
|
333
|
+
const path = match[2];
|
|
334
|
+
if (READ_ONLY_VERBS.has(verb) && readable(path))
|
|
335
|
+
continue;
|
|
336
|
+
if (!allowed(path) && path !== '/dev/null') {
|
|
337
|
+
return `Blocked: "${path}" is outside your allowed roots (${roots.join(', ')}). You can only access files within them.`;
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
// Detect paths traversing out of the roots with ../
|
|
341
|
+
if (/\.\.\//.test(command)) {
|
|
342
|
+
// Check common commands with .. paths
|
|
343
|
+
for (const m of command.matchAll(/["']?(?:\.\.\/)+[^\s;|&)"']*(?=[\s;|&)"]|$)/g)) {
|
|
344
|
+
const dotPath = m[0];
|
|
345
|
+
const resolved = resolve(dirAt(command, m.index, base, shellHome), dotPath.replace(/^["']|["']$/g, ''));
|
|
346
|
+
if (!allowed(resolved)) {
|
|
347
|
+
return `Blocked: "${dotPath}" resolves outside your allowed roots (${roots.join(', ')}).`;
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
const cdOut = cdOutsideRoots(command, base, shellHome, allowed);
|
|
352
|
+
if (cdOut)
|
|
353
|
+
return `Blocked: "cd ${cdOut}" leaves your allowed roots (${roots.join(', ')}).`;
|
|
354
|
+
// Block explicit references to sensitive home directories
|
|
355
|
+
const sensitivePatterns = [
|
|
356
|
+
new RegExp(`${home}/Desktop`, 'i'),
|
|
357
|
+
new RegExp(`${home}/Downloads`, 'i'),
|
|
358
|
+
new RegExp(`${home}/Documents`, 'i'),
|
|
359
|
+
new RegExp(`${home}/.ssh`, 'i'),
|
|
360
|
+
new RegExp(`${home}/.aws`, 'i'),
|
|
361
|
+
new RegExp(`${home}/.env`, 'i'),
|
|
362
|
+
new RegExp(`${home}/.gnupg`, 'i'),
|
|
363
|
+
new RegExp(`${home}/.config`, 'i'),
|
|
364
|
+
new RegExp(`${home}/Library`, 'i'),
|
|
365
|
+
];
|
|
366
|
+
for (const pattern of sensitivePatterns) {
|
|
367
|
+
if (pattern.test(command) && !roots.some(r => command.includes(r))) {
|
|
368
|
+
return `Blocked: path is outside your allowed roots (${roots.join(', ')}).`;
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
return null;
|
|
372
|
+
}
|
|
373
|
+
/** Shell verbs that change the paths they are given; `cp` and `ln` only their last one. */
|
|
374
|
+
const WRITE_VERBS = /(?:^|[;&|(])\s*(rm|rmdir|mv|cp|touch|mkdir|chmod|chown|ln|tee|truncate)((?:\s+[^\s;|&)]+)+)/g;
|
|
375
|
+
/** An output redirection and its target (`> x`, `>> x`), never `2>&1`. */
|
|
376
|
+
const REDIRECT = /(?:^|[^0-9&<>])\d?>>?\s*([^\s&;|)<>][^\s;|&)<>]*)/g;
|
|
377
|
+
/**
|
|
378
|
+
* The first path a command plainly changes outside the session's write scope
|
|
379
|
+
* (`allowedWrite` says what may change), or null. A tripwire like
|
|
380
|
+
* `detectPathEscape`, not a fence: a script, a build or `git` can still write
|
|
381
|
+
* anywhere in the checkout.
|
|
382
|
+
*/
|
|
383
|
+
export function detectScopeEscape(command, base, shellHome, outsideScope) {
|
|
384
|
+
const changed = [];
|
|
385
|
+
for (const m of command.matchAll(WRITE_VERBS)) {
|
|
386
|
+
const args = m[2].trim().split(/\s+/).filter(a => !a.startsWith('-'));
|
|
387
|
+
const targets = m[1] === 'cp' || m[1] === 'ln' ? args.slice(-1) : args;
|
|
388
|
+
for (const a of targets)
|
|
389
|
+
changed.push({ path: a, at: m.index });
|
|
390
|
+
}
|
|
391
|
+
for (const m of command.matchAll(REDIRECT))
|
|
392
|
+
changed.push({ path: m[1], at: m.index });
|
|
393
|
+
for (const { path, at } of changed) {
|
|
394
|
+
const clean = path.replace(/^["']|["']$/g, '');
|
|
395
|
+
if (!clean || clean === '/dev/null' || clean.includes('$'))
|
|
396
|
+
continue;
|
|
397
|
+
const abs = isAbsolute(clean) ? resolve(clean) : cdTarget(dirAt(command, at, base, shellHome), clean, shellHome);
|
|
398
|
+
if (outsideScope(realpathSafe(abs)))
|
|
399
|
+
return clean;
|
|
400
|
+
}
|
|
401
|
+
return null;
|
|
402
|
+
}
|
|
403
|
+
/** The cwd of a command: the session's scope by default (else the project
|
|
404
|
+
* root); an explicit one inside the allowed roots and the write scope. */
|
|
405
|
+
function commandCwd(requestedCwd, base, context) {
|
|
406
|
+
const roots = jailRoots(context);
|
|
407
|
+
if (!requestedCwd)
|
|
408
|
+
return { cwd: activeWriteScope(context) ?? base };
|
|
409
|
+
const cwd = isAbsolute(requestedCwd) ? resolve(requestedCwd) : resolve(base, requestedCwd);
|
|
410
|
+
// The resolved cwd must stay within an allowed root.
|
|
411
|
+
if (!roots.some(r => isInsideRoot(cwd, r))) {
|
|
412
|
+
return { error: `Error: Directory "${requestedCwd}" is outside the agent's allowed roots (${roots.join(', ')}).` };
|
|
413
|
+
}
|
|
414
|
+
if (isOutsideWriteScope(realpathSafe(cwd), context))
|
|
415
|
+
return { error: `Error: ${scopeWriteError(requestedCwd, context)}` };
|
|
416
|
+
return { cwd };
|
|
417
|
+
}
|
|
418
|
+
async function executeRunCommand(params, context) {
|
|
419
|
+
const command = params.command;
|
|
420
|
+
const timeoutSec = resolveCommandTimeoutSec(command, params.timeout);
|
|
421
|
+
// The project root is the default cwd (shell-`cwd` equivalent); the agent home
|
|
422
|
+
// is the second allowed root. Commands may run in either, and never outside.
|
|
423
|
+
// A session's scope moves the default cwd there; relative cwds still
|
|
424
|
+
// resolve against the project root.
|
|
425
|
+
const base = context?.projectRoot || context?.agentHome || process.env.HOME || '/';
|
|
426
|
+
const roots = jailRoots(context);
|
|
427
|
+
const at = commandCwd(params.cwd, base, context);
|
|
428
|
+
if ('error' in at)
|
|
429
|
+
return at.error;
|
|
430
|
+
const cwd = at.cwd;
|
|
431
|
+
if (!command) {
|
|
432
|
+
return 'Error: command is required.';
|
|
433
|
+
}
|
|
434
|
+
const blocked = isBlocked(command);
|
|
435
|
+
if (blocked) {
|
|
436
|
+
return blocked;
|
|
437
|
+
}
|
|
438
|
+
const gitPush = detectGitPush(command);
|
|
439
|
+
if (gitPush) {
|
|
440
|
+
return gitPush;
|
|
441
|
+
}
|
|
442
|
+
const secretExfil = detectSecretExfil(command);
|
|
443
|
+
if (secretExfil) {
|
|
444
|
+
return secretExfil;
|
|
445
|
+
}
|
|
446
|
+
{
|
|
447
|
+
const pathEscape = detectPathEscape(command, roots, cwd, readOnlyRoots(context), shellHome(context, base));
|
|
448
|
+
if (pathEscape) {
|
|
449
|
+
return pathEscape;
|
|
450
|
+
}
|
|
451
|
+
const scopeEscape = hasWriteScope(context) ? detectScopeEscape(command, cwd, shellHome(context, base), p => isOutsideWriteScope(p, context)) : null;
|
|
452
|
+
if (scopeEscape)
|
|
453
|
+
return `Blocked: ${scopeWriteError(scopeEscape, context)}`;
|
|
454
|
+
}
|
|
455
|
+
// Check if already cancelled before spawning
|
|
456
|
+
if (context?.signal?.aborted) {
|
|
457
|
+
return JSON.stringify({ success: false, error: 'Cancelled before execution.' });
|
|
458
|
+
}
|
|
459
|
+
// The Node the project pins, first on PATH (downloaded once when missing).
|
|
460
|
+
const node = await resolveProjectNode(cwd, base);
|
|
461
|
+
const childEnv = commandEnv(context, base, process.env, node?.binDir);
|
|
462
|
+
const noted = (result) => withProjectNode(result, node);
|
|
463
|
+
// A dev server asked for in the background still takes the dev server's
|
|
464
|
+
// path (it answers once ready). Any other background command gets a
|
|
465
|
+
// preview only when a line of its output announces a local address
|
|
466
|
+
// (processes.ts serverPortFromOutput).
|
|
467
|
+
if (params.background === true && !isLongRunningCommand(command)) {
|
|
468
|
+
return noted(startBackgroundCommand(command, cwd, childEnv, context));
|
|
469
|
+
}
|
|
470
|
+
// ─── Long-running command handling ───────────
|
|
471
|
+
// Dev servers, preview servers, watchers, etc. never exit.
|
|
472
|
+
// We start them in the background and return once output indicates the server is ready.
|
|
473
|
+
if (isLongRunningCommand(command)) {
|
|
474
|
+
return new Promise((resolvePromise) => {
|
|
475
|
+
const child = spawn('sh', ['-c', command], {
|
|
476
|
+
cwd,
|
|
477
|
+
env: childEnv,
|
|
478
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
479
|
+
detached: true,
|
|
480
|
+
});
|
|
481
|
+
child.stdin.end();
|
|
482
|
+
// Reported to the studio (the code app's Processes), its preview with it.
|
|
483
|
+
const processId = trackProcess(child, { command, cwd, kind: 'server', context });
|
|
484
|
+
let output = '';
|
|
485
|
+
let resolved = false;
|
|
486
|
+
let answering = false;
|
|
487
|
+
const finish = (msg) => {
|
|
488
|
+
if (resolved)
|
|
489
|
+
return;
|
|
490
|
+
resolved = true;
|
|
491
|
+
clearTimeout(readyTimer);
|
|
492
|
+
resolvePromise(msg);
|
|
493
|
+
};
|
|
494
|
+
// Answer once, with the preview's address when it gets one in time.
|
|
495
|
+
const answer = (result) => {
|
|
496
|
+
if (answering)
|
|
497
|
+
return;
|
|
498
|
+
answering = true;
|
|
499
|
+
void waitForPreview(processId, PREVIEW_WAIT_MS).then((preview) => {
|
|
500
|
+
finish(JSON.stringify({
|
|
501
|
+
...result,
|
|
502
|
+
output: clipHeadTail(output.trim(), COMMAND_OUTPUT_MAX_CHARS) || result.output,
|
|
503
|
+
...(preview ? { preview, note: `${result.note} ${previewNote(preview)}` } : {}),
|
|
504
|
+
}));
|
|
505
|
+
});
|
|
506
|
+
};
|
|
507
|
+
const collectOutput = (data) => {
|
|
508
|
+
// Past the answer the process registry keeps the output, not this.
|
|
509
|
+
if (answering)
|
|
510
|
+
return;
|
|
511
|
+
output += data.toString();
|
|
512
|
+
// Check if server appears ready
|
|
513
|
+
if (outputIndicatesServerReady(output)) {
|
|
514
|
+
answer({
|
|
515
|
+
success: true,
|
|
516
|
+
background: true,
|
|
517
|
+
pid: child.pid,
|
|
518
|
+
note: 'Server started in background. It will keep running until you cancel or the conversation ends.',
|
|
519
|
+
});
|
|
520
|
+
}
|
|
521
|
+
};
|
|
522
|
+
child.stdout.on('data', collectOutput);
|
|
523
|
+
child.stderr.on('data', collectOutput);
|
|
524
|
+
// If no ready signal within 30s, return whatever we have
|
|
525
|
+
const readyTimer = setTimeout(() => {
|
|
526
|
+
answer({
|
|
527
|
+
success: true,
|
|
528
|
+
background: true,
|
|
529
|
+
pid: child.pid,
|
|
530
|
+
output: '(server starting, no output yet)',
|
|
531
|
+
note: 'Server started in background but no ready signal detected. It may still be starting.',
|
|
532
|
+
});
|
|
533
|
+
}, 30_000);
|
|
534
|
+
// If the process exits early (crash), return the error
|
|
535
|
+
child.on('close', (code) => {
|
|
536
|
+
if (!resolved) {
|
|
537
|
+
finish(JSON.stringify({
|
|
538
|
+
success: false,
|
|
539
|
+
exitCode: code ?? 1,
|
|
540
|
+
error: clipHeadTail(output.trim(), COMMAND_OUTPUT_MAX_CHARS) || 'Server process exited unexpectedly',
|
|
541
|
+
}));
|
|
542
|
+
}
|
|
543
|
+
});
|
|
544
|
+
child.on('error', (err) => {
|
|
545
|
+
finish(JSON.stringify({ success: false, error: err.message }));
|
|
546
|
+
});
|
|
547
|
+
// Kill on abort
|
|
548
|
+
const onAbort = () => {
|
|
549
|
+
if (child.pid) {
|
|
550
|
+
try {
|
|
551
|
+
process.kill(-child.pid, 'SIGTERM');
|
|
552
|
+
}
|
|
553
|
+
catch {
|
|
554
|
+
child.kill('SIGKILL');
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
finish(JSON.stringify({ success: false, error: 'Cancelled.' }));
|
|
558
|
+
};
|
|
559
|
+
if (context?.signal) {
|
|
560
|
+
if (context.signal.aborted) {
|
|
561
|
+
onAbort();
|
|
562
|
+
return;
|
|
563
|
+
}
|
|
564
|
+
context.signal.addEventListener('abort', onAbort, { once: true });
|
|
565
|
+
}
|
|
566
|
+
// Unref so the process doesn't block the agent from exiting cleanly
|
|
567
|
+
child.unref();
|
|
568
|
+
}).then(noted);
|
|
569
|
+
}
|
|
570
|
+
// ─── Normal (short-lived) command handling ───
|
|
571
|
+
// What the command changes in the checkout becomes the run's own (_touched.ts).
|
|
572
|
+
// A background command or a dev server is still running when its step ends,
|
|
573
|
+
// so only a command that runs to its end reports what it touched.
|
|
574
|
+
const before = await snapshotCheckout(cwd, context);
|
|
575
|
+
return new Promise((resolvePromise) => {
|
|
576
|
+
// Its own process group, so a kill reaches what `sh` started too (npm,
|
|
577
|
+
// vitest, node): those hold the pipes, and `close` waits for the pipes.
|
|
578
|
+
const child = spawn('sh', ['-c', command], {
|
|
579
|
+
cwd,
|
|
580
|
+
env: childEnv,
|
|
581
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
582
|
+
detached: true,
|
|
583
|
+
});
|
|
584
|
+
const killTree = () => {
|
|
585
|
+
if (child.pid) {
|
|
586
|
+
try {
|
|
587
|
+
process.kill(-child.pid, 'SIGKILL');
|
|
588
|
+
return;
|
|
589
|
+
}
|
|
590
|
+
catch { /* group already gone */ }
|
|
591
|
+
}
|
|
592
|
+
child.kill('SIGKILL');
|
|
593
|
+
};
|
|
594
|
+
// Close stdin immediately - prevents password/interactive prompts from hanging
|
|
595
|
+
child.stdin.end();
|
|
596
|
+
let stdout = '';
|
|
597
|
+
let stderr = '';
|
|
598
|
+
let killed = false;
|
|
599
|
+
let killedReason = '';
|
|
600
|
+
// Collect output
|
|
601
|
+
child.stdout.on('data', (data) => {
|
|
602
|
+
stdout += data.toString();
|
|
603
|
+
// Enforce max buffer (1 MB)
|
|
604
|
+
if (stdout.length > 1024 * 1024) {
|
|
605
|
+
killed = true;
|
|
606
|
+
killedReason = 'Output exceeded 1MB limit';
|
|
607
|
+
killTree();
|
|
608
|
+
}
|
|
609
|
+
});
|
|
610
|
+
child.stderr.on('data', (data) => {
|
|
611
|
+
stderr += data.toString();
|
|
612
|
+
if (stderr.length > 1024 * 1024) {
|
|
613
|
+
killed = true;
|
|
614
|
+
killedReason = 'Stderr exceeded 1MB limit';
|
|
615
|
+
killTree();
|
|
616
|
+
}
|
|
617
|
+
});
|
|
618
|
+
// Timeout handler. The reason text is model-facing: tell it HOW to
|
|
619
|
+
// recover (re-run with a bigger `timeout`) so a killed build/install
|
|
620
|
+
// self-corrects in one round instead of being retried identically.
|
|
621
|
+
const timer = setTimeout(() => {
|
|
622
|
+
killed = true;
|
|
623
|
+
killedReason = `Command timed out after ${timeoutSec}s and was killed. If it legitimately needs longer (build/install/test), re-run it with a larger "timeout" parameter (max ${MAX_TIMEOUT_SEC}s), or split it into smaller steps.`;
|
|
624
|
+
killTree();
|
|
625
|
+
}, timeoutSec * 1000);
|
|
626
|
+
// Abort signal handler - kill child process immediately on cancel
|
|
627
|
+
const onAbort = () => {
|
|
628
|
+
killed = true;
|
|
629
|
+
killedReason = 'Cancelled';
|
|
630
|
+
killTree();
|
|
631
|
+
};
|
|
632
|
+
if (context?.signal) {
|
|
633
|
+
if (context.signal.aborted) {
|
|
634
|
+
// Already aborted
|
|
635
|
+
killTree();
|
|
636
|
+
clearTimeout(timer);
|
|
637
|
+
resolvePromise(JSON.stringify({ success: false, error: 'Cancelled.' }));
|
|
638
|
+
return;
|
|
639
|
+
}
|
|
640
|
+
context.signal.addEventListener('abort', onAbort, { once: true });
|
|
641
|
+
}
|
|
642
|
+
child.on('close', (code) => {
|
|
643
|
+
clearTimeout(timer);
|
|
644
|
+
context?.signal?.removeEventListener('abort', onAbort);
|
|
645
|
+
// Every branch goes through the same budget: a failing test run is the
|
|
646
|
+
// largest output a run produces and the one most likely to be resent
|
|
647
|
+
// for many rounds, so it must not be the branch that skips the cap.
|
|
648
|
+
const out = stdout.trim();
|
|
649
|
+
const err = stderr.trim();
|
|
650
|
+
if (killed) {
|
|
651
|
+
resolvePromise(JSON.stringify({
|
|
652
|
+
success: false,
|
|
653
|
+
error: killedReason,
|
|
654
|
+
output: clipHeadTail(out || err, COMMAND_OUTPUT_MAX_CHARS) || undefined,
|
|
655
|
+
}));
|
|
656
|
+
return;
|
|
657
|
+
}
|
|
658
|
+
if (code === 0) {
|
|
659
|
+
if (out.length === 0) {
|
|
660
|
+
resolvePromise(JSON.stringify({ success: true, output: '(no output)' }));
|
|
661
|
+
return;
|
|
662
|
+
}
|
|
663
|
+
const clipped = clipHeadTail(out, COMMAND_OUTPUT_MAX_CHARS);
|
|
664
|
+
resolvePromise(JSON.stringify({
|
|
665
|
+
success: true,
|
|
666
|
+
output: clipped,
|
|
667
|
+
...(clipped !== out ? { truncated: true, totalLength: out.length } : {}),
|
|
668
|
+
}));
|
|
669
|
+
}
|
|
670
|
+
else {
|
|
671
|
+
const streams = clipCommandStreams(out, err);
|
|
672
|
+
resolvePromise(JSON.stringify({
|
|
673
|
+
success: false,
|
|
674
|
+
exitCode: code ?? 1,
|
|
675
|
+
error: streams.err || 'Command failed',
|
|
676
|
+
output: streams.out || undefined,
|
|
677
|
+
...(streams.clipped ? { truncated: true } : {}),
|
|
678
|
+
}));
|
|
679
|
+
}
|
|
680
|
+
});
|
|
681
|
+
child.on('error', (error) => {
|
|
682
|
+
clearTimeout(timer);
|
|
683
|
+
context?.signal?.removeEventListener('abort', onAbort);
|
|
684
|
+
resolvePromise(JSON.stringify({
|
|
685
|
+
success: false,
|
|
686
|
+
error: error.message,
|
|
687
|
+
}));
|
|
688
|
+
});
|
|
689
|
+
}).then(async (result) => {
|
|
690
|
+
await recordTouched(before, cwd, params, context);
|
|
691
|
+
return noted(result);
|
|
692
|
+
});
|
|
693
|
+
}
|
|
694
|
+
// ─── Background commands ────
|
|
695
|
+
// A command the agent does not need to watch (a full test suite, a long build)
|
|
696
|
+
// runs detached with its output in a log file, and the call returns at once.
|
|
697
|
+
// The agent checks the log with a cheap `tail`, so neither the wait nor the
|
|
698
|
+
// whole output passes through the conversation.
|
|
699
|
+
function startBackgroundCommand(command, cwd, env, context) {
|
|
700
|
+
const dir = context?.scratchRoot || join(context?.agentHome || cwd, '.nordhavn-bg');
|
|
701
|
+
mkdirSync(dir, { recursive: true });
|
|
702
|
+
const log = join(dir, `bg-${Date.now()}.log`);
|
|
703
|
+
const exitFile = `${log}.exit`;
|
|
704
|
+
const file = createWriteStream(log, { flags: 'a' });
|
|
705
|
+
const child = spawn('sh', ['-c', command], { cwd, env, stdio: ['ignore', 'pipe', 'pipe'], detached: true });
|
|
706
|
+
// Its output goes to the log file, and to the studio as a process of its own.
|
|
707
|
+
child.stdout?.pipe(file, { end: false });
|
|
708
|
+
child.stderr?.pipe(file, { end: false });
|
|
709
|
+
trackProcess(child, { command, cwd, kind: 'background', context, log });
|
|
710
|
+
child.on('close', (code) => {
|
|
711
|
+
file.end();
|
|
712
|
+
try {
|
|
713
|
+
writeFileSync(exitFile, String(code ?? 1));
|
|
714
|
+
}
|
|
715
|
+
catch { /* the log still says what happened */ }
|
|
716
|
+
});
|
|
717
|
+
child.on('error', (err) => {
|
|
718
|
+
try {
|
|
719
|
+
writeFileSync(exitFile, `error: ${err.message}`);
|
|
720
|
+
}
|
|
721
|
+
catch { /* nothing to report it to */ }
|
|
722
|
+
});
|
|
723
|
+
child.unref();
|
|
724
|
+
return JSON.stringify({
|
|
725
|
+
success: true,
|
|
726
|
+
background: true,
|
|
727
|
+
pid: child.pid,
|
|
728
|
+
log,
|
|
729
|
+
exitFile,
|
|
730
|
+
note: `Started in background. Check it with runner_run_command: \`tail -n 40 ${log}\` for the latest output, \`cat ${exitFile}\` for the exit code (the file appears when it ends). Grep the log for what you need instead of reading it whole.`,
|
|
731
|
+
});
|
|
732
|
+
}
|
|
733
|
+
export const consoleTools = [
|
|
734
|
+
{ definition: runCommandDefinition, execute: executeRunCommand },
|
|
735
|
+
];
|
|
736
|
+
// What runs in the background stops with the runner.
|
|
737
|
+
process.on('exit', stopAllProcesses);
|
|
738
|
+
process.on('SIGINT', () => { stopAllProcesses(); process.exit(0); });
|
|
739
|
+
process.on('SIGTERM', () => { stopAllProcesses(); process.exit(0); });
|