@nordhavnhq/runner 0.0.0-stage → 0.95.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +80 -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 +42 -0
- package/dist/cli/link.js +314 -0
- package/dist/cli/logs.d.ts +2 -0
- package/dist/cli/logs.js +147 -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 +81 -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 +145 -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 +1325 -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,223 @@
|
|
|
1
|
+
import { execFile } from 'node:child_process';
|
|
2
|
+
import { existsSync, readdirSync, readFileSync } from 'node:fs';
|
|
3
|
+
import { homedir, userInfo } from 'node:os';
|
|
4
|
+
import { delimiter, dirname, isAbsolute, join, relative, resolve } from 'node:path';
|
|
5
|
+
import { nordhavnDir } from '../paths.js';
|
|
6
|
+
import { matchesSpec, parseNodeVersion, pickHighest } from './node-version.js';
|
|
7
|
+
import { downloadNode } from './project-node-download.js';
|
|
8
|
+
// ─── The project's own Node ─────────────────
|
|
9
|
+
//
|
|
10
|
+
// A project pins its Node in `.node-version` or `.nvmrc`, and a strict one
|
|
11
|
+
// (`engines` + `engine-strict`) refuses `npm install` on any other. The runner
|
|
12
|
+
// itself runs on whatever node started it, so every command an agent starts
|
|
13
|
+
// (runner_run_command, runner_test, a worktree setup script) gets the pinned
|
|
14
|
+
// node's bin dir first on PATH: found among the version managers of the
|
|
15
|
+
// machine's real user (the agent's HOME is its own sandbox), or downloaded once
|
|
16
|
+
// into the runner's own cache. When that fails the command still runs, on the
|
|
17
|
+
// runner's node, and its result says so in one line.
|
|
18
|
+
const NODE_VERSION_FILES = ['.node-version', '.nvmrc'];
|
|
19
|
+
/**
|
|
20
|
+
* The nearest version file from `cwd` up to `base` (never above it, never
|
|
21
|
+
* outside it). In one folder `.node-version` comes before `.nvmrc`; a folder
|
|
22
|
+
* whose files hold only aliases ends the search without a pin.
|
|
23
|
+
*/
|
|
24
|
+
export function findNodePin(cwd, base) {
|
|
25
|
+
const root = resolve(base);
|
|
26
|
+
let dir = resolve(cwd);
|
|
27
|
+
if (!isWithin(dir, root))
|
|
28
|
+
return null;
|
|
29
|
+
for (;;) {
|
|
30
|
+
let sawFile = false;
|
|
31
|
+
for (const name of NODE_VERSION_FILES) {
|
|
32
|
+
const file = join(dir, name);
|
|
33
|
+
let text;
|
|
34
|
+
try {
|
|
35
|
+
text = readFileSync(file, 'utf-8');
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
sawFile = true;
|
|
41
|
+
const spec = parseNodeVersion(text);
|
|
42
|
+
if (spec)
|
|
43
|
+
return { spec, file };
|
|
44
|
+
}
|
|
45
|
+
if (sawFile || dir === root)
|
|
46
|
+
return null;
|
|
47
|
+
const parent = dirname(dir);
|
|
48
|
+
if (parent === dir)
|
|
49
|
+
return null;
|
|
50
|
+
dir = parent;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
function isWithin(dir, root) {
|
|
54
|
+
const rel = relative(root, dir);
|
|
55
|
+
return rel === '' || (!rel.startsWith('..') && !isAbsolute(rel));
|
|
56
|
+
}
|
|
57
|
+
/** The home of the user the runner runs as, whatever HOME says. */
|
|
58
|
+
function realUserHome() {
|
|
59
|
+
try {
|
|
60
|
+
return userInfo().homedir || homedir();
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
return homedir();
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/** Where the runner keeps the nodes it downloads: `<config dir>/node/v<x>`. */
|
|
67
|
+
function defaultNodeCacheDir() {
|
|
68
|
+
return join(nordhavnDir(), 'node');
|
|
69
|
+
}
|
|
70
|
+
/** Every place a node may be installed, the runner's cache first. */
|
|
71
|
+
function nodeStores(opts = {}) {
|
|
72
|
+
const home = opts.home ?? realUserHome();
|
|
73
|
+
const env = opts.env ?? process.env;
|
|
74
|
+
const win = (opts.platform ?? process.platform) === 'win32';
|
|
75
|
+
const bin = (folder) => (win ? folder : join(folder, 'bin'));
|
|
76
|
+
const stores = [{ dir: opts.cacheDir ?? defaultNodeCacheDir(), bin }];
|
|
77
|
+
if (win) {
|
|
78
|
+
if (env.NVM_HOME)
|
|
79
|
+
stores.push({ dir: env.NVM_HOME, bin: f => f });
|
|
80
|
+
return stores;
|
|
81
|
+
}
|
|
82
|
+
const fnm = env.FNM_DIR ? [env.FNM_DIR] : [join(home, '.local', 'share', 'fnm'), join(home, 'Library', 'Application Support', 'fnm'), join(home, '.fnm')];
|
|
83
|
+
const brew = [...new Set([env.HOMEBREW_PREFIX, '/opt/homebrew', '/usr/local'].filter((p) => !!p))];
|
|
84
|
+
stores.push({ dir: join(env.NVM_DIR || join(home, '.nvm'), 'versions', 'node'), bin });
|
|
85
|
+
for (const d of fnm)
|
|
86
|
+
stores.push({ dir: join(d, 'node-versions'), bin: f => join(f, 'installation', 'bin') });
|
|
87
|
+
stores.push({ dir: join(env.VOLTA_HOME || join(home, '.volta'), 'tools', 'image', 'node'), bin });
|
|
88
|
+
stores.push({ dir: join(env.ASDF_DATA_DIR || join(home, '.asdf'), 'installs', 'nodejs'), bin });
|
|
89
|
+
stores.push({ dir: join(home, '.local', 'share', 'mise', 'installs', 'node'), bin });
|
|
90
|
+
for (const prefix of brew) {
|
|
91
|
+
stores.push({ dir: join(prefix, 'Cellar', 'node'), bin });
|
|
92
|
+
for (const major of listDir(join(prefix, 'Cellar')).filter(n => /^node@\d+$/.test(n))) {
|
|
93
|
+
stores.push({ dir: join(prefix, 'Cellar', major), bin });
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return stores;
|
|
97
|
+
}
|
|
98
|
+
function listDir(dir) {
|
|
99
|
+
try {
|
|
100
|
+
return readdirSync(dir);
|
|
101
|
+
}
|
|
102
|
+
catch {
|
|
103
|
+
return [];
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* An installed node that satisfies `spec`: the highest match over all stores,
|
|
108
|
+
* so `26` takes the newest 26 the machine has. Only a folder with a node
|
|
109
|
+
* binary in its bin dir counts.
|
|
110
|
+
*/
|
|
111
|
+
export function findInstalledNode(spec, opts = {}) {
|
|
112
|
+
const exe = (opts.platform ?? process.platform) === 'win32' ? 'node.exe' : 'node';
|
|
113
|
+
const found = new Map();
|
|
114
|
+
for (const store of nodeStores(opts)) {
|
|
115
|
+
for (const folder of listDir(store.dir)) {
|
|
116
|
+
const version = folder.replace(/^v/, '');
|
|
117
|
+
if (found.has(version) || !matchesSpec(version, spec))
|
|
118
|
+
continue;
|
|
119
|
+
const binDir = store.bin(join(store.dir, folder));
|
|
120
|
+
if (existsSync(join(binDir, exe)))
|
|
121
|
+
found.set(version, binDir);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
const best = pickHighest([...found.keys()], spec);
|
|
125
|
+
return best ? { version: best, binDir: found.get(best) } : null;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* The child environment with `binDir` first on PATH. nvm's NVM_BIN, when it
|
|
129
|
+
* names another node, leaves PATH and the environment, so `npm` and `npx`
|
|
130
|
+
* follow the pinned node instead of the one the runner was started with.
|
|
131
|
+
*/
|
|
132
|
+
export function withNodeBin(env, binDir) {
|
|
133
|
+
const out = { ...env };
|
|
134
|
+
const stale = out.NVM_BIN && resolve(out.NVM_BIN) !== resolve(binDir) ? resolve(out.NVM_BIN) : null;
|
|
135
|
+
if (stale)
|
|
136
|
+
delete out.NVM_BIN;
|
|
137
|
+
const pathKey = Object.keys(out).find(k => k.toUpperCase() === 'PATH') ?? 'PATH';
|
|
138
|
+
const rest = (out[pathKey] ?? '').split(delimiter)
|
|
139
|
+
.filter(p => p && resolve(p) !== resolve(binDir) && (!stale || resolve(p) !== stale));
|
|
140
|
+
out[pathKey] = [binDir, ...rest].join(delimiter);
|
|
141
|
+
return out;
|
|
142
|
+
}
|
|
143
|
+
/** A failed resolution is tried again after this long (back online, version released). */
|
|
144
|
+
const FAILURE_TTL_MS = 5 * 60_000;
|
|
145
|
+
const resolutions = new Map();
|
|
146
|
+
/** Forgets every resolution (tests). */
|
|
147
|
+
export function resetProjectNodeCache() {
|
|
148
|
+
resolutions.clear();
|
|
149
|
+
}
|
|
150
|
+
/** True unless the operator turned it off (`NORDHAVN_PROJECT_NODE=off`). */
|
|
151
|
+
function enabled(env) {
|
|
152
|
+
return !/^(0|off|false|no)$/i.test(env.NORDHAVN_PROJECT_NODE ?? '');
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* The node a command in `cwd` should run on: null when the project pins none
|
|
156
|
+
* (or the feature is off). Resolved once per (base, pinned version) and kept
|
|
157
|
+
* in memory; a missing version is downloaded into the runner's cache.
|
|
158
|
+
*/
|
|
159
|
+
export async function resolveProjectNode(cwd, base, opts = {}) {
|
|
160
|
+
if (!enabled(opts.env ?? process.env))
|
|
161
|
+
return null;
|
|
162
|
+
const pin = findNodePin(cwd, base);
|
|
163
|
+
if (!pin)
|
|
164
|
+
return null;
|
|
165
|
+
const key = `${resolve(base)}\0${pin.spec}`;
|
|
166
|
+
let pending = resolutions.get(key);
|
|
167
|
+
if (pending) {
|
|
168
|
+
const done = await pending;
|
|
169
|
+
const stale = done.binDir ? !existsSync(done.binDir) : Date.now() - done.at > FAILURE_TTL_MS;
|
|
170
|
+
if (stale)
|
|
171
|
+
pending = undefined;
|
|
172
|
+
}
|
|
173
|
+
if (!pending) {
|
|
174
|
+
pending = resolvePinned(pin.spec, opts);
|
|
175
|
+
resolutions.set(key, pending);
|
|
176
|
+
}
|
|
177
|
+
const done = await pending;
|
|
178
|
+
return { pin, pinFile: relative(resolve(base), pin.file) || pin.file, binDir: done.binDir, version: done.version, reason: done.reason };
|
|
179
|
+
}
|
|
180
|
+
async function resolvePinned(spec, opts) {
|
|
181
|
+
const installed = findInstalledNode(spec, opts);
|
|
182
|
+
if (installed)
|
|
183
|
+
return { ...installed, at: Date.now() };
|
|
184
|
+
const download = opts.download ?? downloadNode;
|
|
185
|
+
try {
|
|
186
|
+
const cacheDir = opts.cacheDir ?? defaultNodeCacheDir();
|
|
187
|
+
const version = await download(spec, cacheDir, { platform: opts.platform ?? process.platform, arch: process.arch });
|
|
188
|
+
const after = findInstalledNode(version, opts);
|
|
189
|
+
if (!after)
|
|
190
|
+
return { version: null, binDir: null, reason: `downloaded ${version} but no node binary in ${cacheDir}`, at: Date.now() };
|
|
191
|
+
return { ...after, at: Date.now() };
|
|
192
|
+
}
|
|
193
|
+
catch (err) {
|
|
194
|
+
return { version: null, binDir: null, reason: err.message, at: Date.now() };
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
const pathNodeVersions = new Map();
|
|
198
|
+
/** The version of the `node` first on the runner's PATH (asked once per PATH), or the runner's own. */
|
|
199
|
+
function runnerPathNodeVersion(env = process.env) {
|
|
200
|
+
const path = env.PATH ?? '';
|
|
201
|
+
let pending = pathNodeVersions.get(path);
|
|
202
|
+
if (!pending) {
|
|
203
|
+
pending = new Promise((done) => {
|
|
204
|
+
execFile('node', ['--version'], { env: { PATH: path }, timeout: 5_000 }, (err, stdout) => {
|
|
205
|
+
const v = !err && stdout.trim().replace(/^v/, '');
|
|
206
|
+
done(v || process.version.replace(/^v/, ''));
|
|
207
|
+
});
|
|
208
|
+
});
|
|
209
|
+
pathNodeVersions.set(path, pending);
|
|
210
|
+
}
|
|
211
|
+
return pending;
|
|
212
|
+
}
|
|
213
|
+
/** The line a tool result carries when the pinned node could not be had. */
|
|
214
|
+
export async function projectNodeNote(node, opts = {}) {
|
|
215
|
+
if (!node || node.binDir)
|
|
216
|
+
return null;
|
|
217
|
+
const current = await (opts.fallbackVersion ?? (() => runnerPathNodeVersion(opts.env)))();
|
|
218
|
+
return `Project pins Node ${node.pin.spec} (${node.pinFile}); not available: ${node.reason ?? 'unknown reason'}. Running on node ${current}.`;
|
|
219
|
+
}
|
|
220
|
+
/** A short label for a result when the pinned node is in use. */
|
|
221
|
+
export function projectNodeLabel(node) {
|
|
222
|
+
return node?.binDir && node.version ? `${node.version} (from ${node.pinFile})` : null;
|
|
223
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Config } from '../config.js';
|
|
2
|
+
/**
|
|
3
|
+
* Delete every per-dispatch scratch dir older than the TTL. Walks
|
|
4
|
+
* `<home>/tmp/<slug>/<dispatchId>` two levels deep, removes any dispatch dir
|
|
5
|
+
* whose mtime is older than the cutoff, then prunes now-empty slug dirs.
|
|
6
|
+
* Best-effort: an entry the reaper can't stat/remove is skipped, never fatal
|
|
7
|
+
* (a live dispatch's dir is only ever reaped if the whole dispatch has run for
|
|
8
|
+
* longer than the TTL, which no real dispatch does). Returns the number of
|
|
9
|
+
* dispatch dirs removed.
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Count the files (recursively) currently sitting in a single dispatch's scratch
|
|
13
|
+
* dir. Used for the end-of-run heads-up that warns when an agent leaves content
|
|
14
|
+
* in scratch (which is reaped on a TTL, so it would be silently lost). Cheap,
|
|
15
|
+
* best-effort: an unreadable entry is skipped and a missing dir counts as 0.
|
|
16
|
+
* Stops early once it passes `cap` so a huge scratch tree can't stall the run's
|
|
17
|
+
* teardown - the exact number past the cap doesn't matter to the caller.
|
|
18
|
+
* Spilled tool outputs (`TOOL_OUTPUT_SPILL_DIR`) are the runner's own, not
|
|
19
|
+
* the agent's, so they are not counted.
|
|
20
|
+
*/
|
|
21
|
+
export declare function countScratchFiles(scratchRoot: string, cap?: number): number;
|
|
22
|
+
export declare function reapScratch(config: Config, ttlMs?: number): number;
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { readdirSync, statSync, rmSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { scratchBaseDir } from '../config.js';
|
|
4
|
+
import { TOOL_OUTPUT_SPILL_DIR } from './spill-tool-output.js';
|
|
5
|
+
// ─── Scratch reaper ───────────────────────────
|
|
6
|
+
//
|
|
7
|
+
// Per-dispatch scratch dirs (`<home>/tmp/<slug>/<dispatchId>`) hold the agent's
|
|
8
|
+
// throwaway files. Nothing else cleans them, so the runner sweeps them itself:
|
|
9
|
+
// once at startup (a catch-up for dirs left by an earlier run) and then hourly
|
|
10
|
+
// while it stays up. A dir is reaped once its mtime is older than the TTL.
|
|
11
|
+
const DEFAULT_TTL_HOURS = 24;
|
|
12
|
+
/**
|
|
13
|
+
* Scratch TTL in ms. Defaults to 24h; override with the
|
|
14
|
+
* `NORDHAVN_SCRATCH_TTL_HOURS` env var. Non-positive / unparseable values
|
|
15
|
+
* fall back to the default.
|
|
16
|
+
*/
|
|
17
|
+
function scratchTtlMs() {
|
|
18
|
+
const raw = Number(process.env.NORDHAVN_SCRATCH_TTL_HOURS);
|
|
19
|
+
const hours = Number.isFinite(raw) && raw > 0 ? raw : DEFAULT_TTL_HOURS;
|
|
20
|
+
return hours * 60 * 60 * 1000;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Delete every per-dispatch scratch dir older than the TTL. Walks
|
|
24
|
+
* `<home>/tmp/<slug>/<dispatchId>` two levels deep, removes any dispatch dir
|
|
25
|
+
* whose mtime is older than the cutoff, then prunes now-empty slug dirs.
|
|
26
|
+
* Best-effort: an entry the reaper can't stat/remove is skipped, never fatal
|
|
27
|
+
* (a live dispatch's dir is only ever reaped if the whole dispatch has run for
|
|
28
|
+
* longer than the TTL, which no real dispatch does). Returns the number of
|
|
29
|
+
* dispatch dirs removed.
|
|
30
|
+
*/
|
|
31
|
+
/**
|
|
32
|
+
* Count the files (recursively) currently sitting in a single dispatch's scratch
|
|
33
|
+
* dir. Used for the end-of-run heads-up that warns when an agent leaves content
|
|
34
|
+
* in scratch (which is reaped on a TTL, so it would be silently lost). Cheap,
|
|
35
|
+
* best-effort: an unreadable entry is skipped and a missing dir counts as 0.
|
|
36
|
+
* Stops early once it passes `cap` so a huge scratch tree can't stall the run's
|
|
37
|
+
* teardown - the exact number past the cap doesn't matter to the caller.
|
|
38
|
+
* Spilled tool outputs (`TOOL_OUTPUT_SPILL_DIR`) are the runner's own, not
|
|
39
|
+
* the agent's, so they are not counted.
|
|
40
|
+
*/
|
|
41
|
+
export function countScratchFiles(scratchRoot, cap = 500) {
|
|
42
|
+
let count = 0;
|
|
43
|
+
const walk = (dir) => {
|
|
44
|
+
if (count > cap)
|
|
45
|
+
return;
|
|
46
|
+
let entries;
|
|
47
|
+
try {
|
|
48
|
+
entries = readdirSync(dir, { withFileTypes: true });
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
for (const entry of entries) {
|
|
54
|
+
if (count > cap)
|
|
55
|
+
return;
|
|
56
|
+
if (entry.isDirectory()) {
|
|
57
|
+
if (dir === scratchRoot && entry.name === TOOL_OUTPUT_SPILL_DIR)
|
|
58
|
+
continue;
|
|
59
|
+
walk(join(dir, entry.name));
|
|
60
|
+
}
|
|
61
|
+
else
|
|
62
|
+
count++;
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
walk(scratchRoot);
|
|
66
|
+
return count;
|
|
67
|
+
}
|
|
68
|
+
export function reapScratch(config, ttlMs = scratchTtlMs()) {
|
|
69
|
+
const base = scratchBaseDir(config);
|
|
70
|
+
const cutoff = Date.now() - ttlMs;
|
|
71
|
+
let removed = 0;
|
|
72
|
+
let slugDirs;
|
|
73
|
+
try {
|
|
74
|
+
slugDirs = readdirSync(base);
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
return 0; // no tmp dir yet - nothing to sweep
|
|
78
|
+
}
|
|
79
|
+
for (const slug of slugDirs) {
|
|
80
|
+
const slugPath = join(base, slug);
|
|
81
|
+
let dispatchDirs;
|
|
82
|
+
try {
|
|
83
|
+
if (!statSync(slugPath).isDirectory())
|
|
84
|
+
continue;
|
|
85
|
+
dispatchDirs = readdirSync(slugPath);
|
|
86
|
+
}
|
|
87
|
+
catch {
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
for (const id of dispatchDirs) {
|
|
91
|
+
const dir = join(slugPath, id);
|
|
92
|
+
try {
|
|
93
|
+
if (statSync(dir).mtimeMs < cutoff) {
|
|
94
|
+
rmSync(dir, { recursive: true, force: true });
|
|
95
|
+
removed++;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
catch {
|
|
99
|
+
/* skip an entry we can't stat/remove */
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
// Prune the slug dir once it has no dispatch dirs left.
|
|
103
|
+
try {
|
|
104
|
+
if (readdirSync(slugPath).length === 0)
|
|
105
|
+
rmSync(slugPath, { recursive: true, force: true });
|
|
106
|
+
}
|
|
107
|
+
catch {
|
|
108
|
+
/* skip */
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return removed;
|
|
112
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** Subdirectory of a dispatch's scratch dir holding spilled outputs. Left out
|
|
2
|
+
* of the end-of-run "files left in scratch" count: the runner wrote them, not
|
|
3
|
+
* the agent. */
|
|
4
|
+
export declare const TOOL_OUTPUT_SPILL_DIR = ".tool-output";
|
|
5
|
+
/**
|
|
6
|
+
* The output as a file a person or `runner_read_file` reads by line. A JSON
|
|
7
|
+
* result (most studio tools) is laid out instead of kept as one line: a batch
|
|
8
|
+
* gets a section per result, a long string field its own raw block. Anything
|
|
9
|
+
* else, plain text and JSON that does not parse, is kept as it came.
|
|
10
|
+
*/
|
|
11
|
+
export declare function readableToolOutput(text: string): string;
|
|
12
|
+
/** Write a tool's whole output to `<scratchRoot>/.tool-output/<tool>-<callId>.txt`
|
|
13
|
+
* and return the path, or null when it is not kept. */
|
|
14
|
+
export declare function spillToolOutput(scratchRoot: string, callId: string, toolName: string, text: string): Promise<string | null>;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { mkdir, writeFile } from 'node:fs/promises';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
// ─── Spilled tool output ──────────────────────
|
|
4
|
+
//
|
|
5
|
+
// A tool result too long for the conversation is cut to its start and end as
|
|
6
|
+
// it is appended (the agent contract's `truncateToolResult`), and never touched
|
|
7
|
+
// again: the transcript stays append-only, so the prompt cache keeps reading it.
|
|
8
|
+
// The whole output is kept here first, in the dispatch's own scratch dir, so
|
|
9
|
+
// the agent can read the part it needs with runner_read_file (offset/limit) or
|
|
10
|
+
// runner_grep instead of running the call again. Reaped with the scratch dir.
|
|
11
|
+
/** Subdirectory of a dispatch's scratch dir holding spilled outputs. Left out
|
|
12
|
+
* of the end-of-run "files left in scratch" count: the runner wrote them, not
|
|
13
|
+
* the agent. */
|
|
14
|
+
export const TOOL_OUTPUT_SPILL_DIR = '.tool-output';
|
|
15
|
+
/** Tools whose output is already a file on disk: spilling a copy only adds a
|
|
16
|
+
* second place to read the same lines from. */
|
|
17
|
+
const NOT_SPILLED = new Set(['runner_read_file']);
|
|
18
|
+
function safeName(part) {
|
|
19
|
+
return part.replace(/[^A-Za-z0-9_-]/g, '_').slice(0, 80) || 'call';
|
|
20
|
+
}
|
|
21
|
+
/** A string this long, or with a line break, is written out raw: inside JSON
|
|
22
|
+
* it would be one escaped line that no line-based read can page through. */
|
|
23
|
+
const RAW_STRING_MIN_CHARS = 200;
|
|
24
|
+
function isRecord(v) {
|
|
25
|
+
return typeof v === 'object' && v !== null && !Array.isArray(v);
|
|
26
|
+
}
|
|
27
|
+
function isLongString(v) {
|
|
28
|
+
return typeof v === 'string' && (v.includes('\n') || v.length >= RAW_STRING_MIN_CHARS);
|
|
29
|
+
}
|
|
30
|
+
/** One value as lines: a long string raw, an object as indented JSON with its
|
|
31
|
+
* long strings lifted out under their key. */
|
|
32
|
+
function readableValue(value) {
|
|
33
|
+
if (typeof value === 'string')
|
|
34
|
+
return value;
|
|
35
|
+
if (!isRecord(value))
|
|
36
|
+
return JSON.stringify(value, null, 2);
|
|
37
|
+
const short = {};
|
|
38
|
+
const long = [];
|
|
39
|
+
for (const [key, v] of Object.entries(value)) {
|
|
40
|
+
if (isLongString(v))
|
|
41
|
+
long.push(`----- ${key} -----\n${v}`);
|
|
42
|
+
else
|
|
43
|
+
short[key] = v;
|
|
44
|
+
}
|
|
45
|
+
const head = Object.keys(short).length ? JSON.stringify(short, null, 2) : '';
|
|
46
|
+
return [head, ...long].filter(Boolean).join('\n');
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* The output as a file a person or `runner_read_file` reads by line. A JSON
|
|
50
|
+
* result (most studio tools) is laid out instead of kept as one line: a batch
|
|
51
|
+
* gets a section per result, a long string field its own raw block. Anything
|
|
52
|
+
* else, plain text and JSON that does not parse, is kept as it came.
|
|
53
|
+
*/
|
|
54
|
+
export function readableToolOutput(text) {
|
|
55
|
+
const trimmed = text.trimStart();
|
|
56
|
+
if (!trimmed.startsWith('{') && !trimmed.startsWith('['))
|
|
57
|
+
return text;
|
|
58
|
+
let parsed;
|
|
59
|
+
try {
|
|
60
|
+
parsed = JSON.parse(text);
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
return text;
|
|
64
|
+
}
|
|
65
|
+
if (isRecord(parsed) && Array.isArray(parsed.results)) {
|
|
66
|
+
return parsed.results.map((r, i) => {
|
|
67
|
+
const state = isRecord(r) && 'ok' in r ? (r.ok ? 'ok' : 'failed') : '';
|
|
68
|
+
const body = isRecord(r) && 'data' in r ? r.data : isRecord(r) && 'error' in r ? r.error : r;
|
|
69
|
+
return `===== results[${i}]${state ? ` (${state})` : ''} =====\n${readableValue(body)}`;
|
|
70
|
+
}).join('\n\n');
|
|
71
|
+
}
|
|
72
|
+
return readableValue(parsed);
|
|
73
|
+
}
|
|
74
|
+
/** Write a tool's whole output to `<scratchRoot>/.tool-output/<tool>-<callId>.txt`
|
|
75
|
+
* and return the path, or null when it is not kept. */
|
|
76
|
+
export async function spillToolOutput(scratchRoot, callId, toolName, text) {
|
|
77
|
+
if (NOT_SPILLED.has(toolName))
|
|
78
|
+
return null;
|
|
79
|
+
const dir = join(scratchRoot, TOOL_OUTPUT_SPILL_DIR);
|
|
80
|
+
await mkdir(dir, { recursive: true });
|
|
81
|
+
const file = join(dir, `${safeName(toolName)}-${safeName(callId)}.txt`);
|
|
82
|
+
await writeFile(file, readableToolOutput(text), 'utf8');
|
|
83
|
+
return file;
|
|
84
|
+
}
|