@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,231 @@
|
|
|
1
|
+
import { readFileSync, realpathSync } from 'node:fs';
|
|
2
|
+
import { relative, sep } from 'node:path';
|
|
3
|
+
import { resolveForRead, writeScopeRel } from './_jail.js';
|
|
4
|
+
import { catchUpSonar, ensureSonarBuilt, sonarStatus } from './_sonar/build.js';
|
|
5
|
+
import { loadSonarIndex, sonarCacheProblems, SonarNotBuiltError } from './_sonar/index.js';
|
|
6
|
+
import { renderRefs } from './_sonar/refs.js';
|
|
7
|
+
import { FIND_MAX_NAMES, loadWasNotable, renderFile, renderFind, renderImpact, renderLoadStats, renderOverview, renderStale } from './_sonar/render.js';
|
|
8
|
+
import { renderChanged } from './_sonar/changed.js';
|
|
9
|
+
import { renderKeyRefs } from './_sonar/keys.js';
|
|
10
|
+
import { renderRoutes } from './_sonar/routes.js';
|
|
11
|
+
import { closePaths } from './_sonar/suggest.js';
|
|
12
|
+
import { renderTests } from './_sonar/tests.js';
|
|
13
|
+
// ─── runner_sonar ───────────────────────────
|
|
14
|
+
//
|
|
15
|
+
// A map of the checkout for an agent that lands in unknown code: layout,
|
|
16
|
+
// entry points, hubs, symbols and the import graph, from the checkout's index,
|
|
17
|
+
// refreshed on every call (only changed files are re-read). The studio only
|
|
18
|
+
// grants it to a run whose checkout has one (the first build starts when the
|
|
19
|
+
// studio asks for the map, build.ts). One that went missing or unusable
|
|
20
|
+
// since (a runner update made it outdated) is built again: the call waits up
|
|
21
|
+
// to SONAR_REBUILD_WAIT_MS, else says a build runs and the agent goes on with
|
|
22
|
+
// grep and outline. One that fell behind catches up in the background
|
|
23
|
+
// (catchUpSonar) and every answer says so meanwhile. The index lives in
|
|
24
|
+
// ./_sonar/; this file is the tool's surface.
|
|
25
|
+
const ACTIONS = ['overview', 'find', 'file', 'refs', 'impact', 'tests', 'routes', 'changed'];
|
|
26
|
+
/** Files one `file` call takes at most (`a.ts|b.ts`). */
|
|
27
|
+
const FILE_MAX_PATHS = 5;
|
|
28
|
+
const sonarDefinition = {
|
|
29
|
+
name: 'runner_sonar',
|
|
30
|
+
description: 'The code map; answers before you grep. Where is X defined: `find` (several at once: "A|B"; `read: true` adds the code, no read_file round). Who uses X: `refs` (also "env:NAME", "config:a.b" and Prisma models). What is in these files: `file` (several: "a.ts|b.ts"). What depends on this file: `impact`. Which tests cover it and how to run them: `tests`. Which file handles a URL or route: `routes`. What changed against a ref, per symbol, with its tests: `changed`. Layout, entry points, hubs: `overview`. runner_grep stays for plain text and strings.',
|
|
31
|
+
parameters: {
|
|
32
|
+
type: 'object',
|
|
33
|
+
properties: {
|
|
34
|
+
action: { type: 'string', enum: [...ACTIONS], description: 'What to ask the map.' },
|
|
35
|
+
query: { type: 'string', description: `find: symbol name(s), up to ${FIND_MAX_NAMES} split by | or , (case-insensitive; exact matches win, "name*" lists prefix and part matches too). refs: the symbol name, or "env:NAME" / "config:a.b" for where a key is set and read. impact: a folder to list only the dependents there. tests: a symbol of the file, to rank the tests that name it first. routes: a URL ("/api/tasks/ABC12"), "POST /api/tasks", or a fragment of the URI, file, route name or controller; empty for a summary. changed: the git ref to compare with (default HEAD: uncommitted work).` },
|
|
36
|
+
path: { type: 'string', description: `overview/find/routes/changed: limit to this folder (default: the session's scope folder when it has one, "." for the whole checkout). file: the file, or up to ${FILE_MAX_PATHS} split by | or ,. impact/tests: the file. refs: a folder or file to show the uses in, or the file that defines the symbol when the name is ambiguous.` },
|
|
37
|
+
read: { type: 'boolean', description: 'find: also return the code (with its doc comment) of each name that has exactly one definition. Default false.' },
|
|
38
|
+
kind: { type: 'string', description: 'find: only this symbol kind (function, class, method, interface, type, component, ...).' },
|
|
39
|
+
depth: { type: 'number', description: 'impact: levels of importers to follow. Default 3, max 6.' },
|
|
40
|
+
},
|
|
41
|
+
required: ['action'],
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
function scopeOf(raw, root, context) {
|
|
45
|
+
if (raw === undefined || raw === null || raw === '' || raw === '.')
|
|
46
|
+
return { rel: '' };
|
|
47
|
+
if (typeof raw !== 'string')
|
|
48
|
+
return 'Error: path must be a string.';
|
|
49
|
+
const abs = resolveForRead(raw, context);
|
|
50
|
+
const rel = relative(root, abs);
|
|
51
|
+
if (rel.startsWith('..') || rel.startsWith(sep) || /^[a-z]:/i.test(rel))
|
|
52
|
+
return `Error: "${raw}" is outside the project checkout.`;
|
|
53
|
+
return { rel: rel.split(sep).join('/') };
|
|
54
|
+
}
|
|
55
|
+
/** Actions whose `path` narrows a search: without one they look in the session's scope. */
|
|
56
|
+
const SCOPED_ACTIONS = new Set(['overview', 'find', 'refs', 'routes', 'changed']);
|
|
57
|
+
/** The `path` of a call: its own, else the session's scope for a narrowing action. */
|
|
58
|
+
function pathParam(action, raw, context) {
|
|
59
|
+
if (raw !== undefined && raw !== null && raw !== '')
|
|
60
|
+
return raw;
|
|
61
|
+
return SCOPED_ACTIONS.has(action) ? writeScopeRel(context) ?? raw : raw;
|
|
62
|
+
}
|
|
63
|
+
function lineReader(root) {
|
|
64
|
+
const cache = new Map();
|
|
65
|
+
return (path, line) => {
|
|
66
|
+
let lines = cache.get(path);
|
|
67
|
+
if (!lines) {
|
|
68
|
+
try {
|
|
69
|
+
lines = readFileSync(`${root}/${path}`, 'utf-8').split('\n');
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
lines = [];
|
|
73
|
+
}
|
|
74
|
+
cache.set(path, lines);
|
|
75
|
+
}
|
|
76
|
+
return lines[line - 1] ?? '';
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
function isIndexedDir(index, rel) {
|
|
80
|
+
return [...index.files.keys()].some(p => p.startsWith(`${rel}/`));
|
|
81
|
+
}
|
|
82
|
+
/** A path the index does not hold: the error, with up to 3 indexed paths it probably meant. */
|
|
83
|
+
function notIndexed(index, rel) {
|
|
84
|
+
const close = closePaths(rel, index.files.keys());
|
|
85
|
+
const hint = close.length > 0 ? ` Did you mean ${close.join(', or ')}?` : '';
|
|
86
|
+
return `Error: "${rel}" is not in the index (not a code file, ignored by git, or missing).${hint}`;
|
|
87
|
+
}
|
|
88
|
+
function needFile(index, scope, action) {
|
|
89
|
+
if (!scope.rel)
|
|
90
|
+
return `Error: ${action} needs \`path\`: the file.`;
|
|
91
|
+
if (!index.files.has(scope.rel)) {
|
|
92
|
+
return isIndexedDir(index, scope.rel)
|
|
93
|
+
? `Error: "${scope.rel}" is a folder. ${action} takes one file; runner_sonar { action: "overview", path } maps a folder.`
|
|
94
|
+
: notIndexed(index, scope.rel);
|
|
95
|
+
}
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
/** impact `query`: a repo-relative folder (or file) to narrow the dependents to; '' for all. */
|
|
99
|
+
function withinOf(raw) {
|
|
100
|
+
return typeof raw === 'string' ? raw.trim().replace(/^\.\/+/, '').replace(/\/+$/, '') : '';
|
|
101
|
+
}
|
|
102
|
+
/** impact: levels to follow, 1 to 6, default 3. */
|
|
103
|
+
function depthOf(value) {
|
|
104
|
+
const raw = typeof value === 'number' ? value : Number(value ?? 3);
|
|
105
|
+
return Number.isFinite(raw) ? Math.min(6, Math.max(1, Math.round(raw))) : 3;
|
|
106
|
+
}
|
|
107
|
+
/** Chars a `file` call of several paths shares out (one file keeps the usual cap). */
|
|
108
|
+
const FILE_MULTI_CHARS = 10_000;
|
|
109
|
+
/** The paths of a `path` param: split on `|` or `,`, trimmed, each once. */
|
|
110
|
+
function pathsOf(raw) {
|
|
111
|
+
if (typeof raw !== 'string')
|
|
112
|
+
return [];
|
|
113
|
+
return [...new Set(raw.split(/[|,]/).map(s => s.trim()).filter(Boolean))];
|
|
114
|
+
}
|
|
115
|
+
const onFile = (action, render) => (params, index, scope, query) => needFile(index, scope, action) ?? render(index, index.files.get(scope.rel), params, query);
|
|
116
|
+
/** `file` on several paths: one block each, the budget shared out; a bad path is an error line in its place. */
|
|
117
|
+
function renderFiles(index, scopes, all) {
|
|
118
|
+
const each = Math.floor(FILE_MULTI_CHARS / scopes.length);
|
|
119
|
+
const read = lineReader(index.root);
|
|
120
|
+
const blocks = scopes.map(s => {
|
|
121
|
+
if (typeof s === 'string')
|
|
122
|
+
return s;
|
|
123
|
+
return needFile(index, s, 'file') ?? renderFile(index, index.files.get(s.rel), read, each);
|
|
124
|
+
});
|
|
125
|
+
const cut = all > scopes.length ? `\n(${all - scopes.length} more path(s) left out: at most ${FILE_MAX_PATHS} per call)` : '';
|
|
126
|
+
return blocks.join('\n\n') + cut;
|
|
127
|
+
}
|
|
128
|
+
const HANDLERS = {
|
|
129
|
+
overview: (_params, index, scope, _query, notes) => renderOverview(index, scope.rel, notes),
|
|
130
|
+
find: (params, index, scope, query) => {
|
|
131
|
+
if (!query)
|
|
132
|
+
return 'Error: find needs `query`: a symbol name.';
|
|
133
|
+
const kind = typeof params.kind === 'string' && params.kind ? params.kind : undefined;
|
|
134
|
+
return renderFind(index, query, scope.rel, kind, lineReader(index.root), params.read === true || params.read === 'true');
|
|
135
|
+
},
|
|
136
|
+
refs: (_params, index, scope, query) => {
|
|
137
|
+
if (!query)
|
|
138
|
+
return 'Error: refs needs `query`: a symbol name.';
|
|
139
|
+
if (/^(env|config):/i.test(query))
|
|
140
|
+
return renderKeyRefs(index, query, scope.rel);
|
|
141
|
+
if (scope.rel && !index.files.has(scope.rel) && !isIndexedDir(index, scope.rel))
|
|
142
|
+
return notIndexed(index, scope.rel);
|
|
143
|
+
return renderRefs(index, query, scope.rel || undefined);
|
|
144
|
+
},
|
|
145
|
+
file: (params, index, scope, query, notes, scopes) => {
|
|
146
|
+
if (scopes.length > 1)
|
|
147
|
+
return renderFiles(index, scopes.slice(0, FILE_MAX_PATHS), pathsOf(params.path).length);
|
|
148
|
+
return onFile('file', (i, file) => renderFile(i, file, lineReader(i.root)))(params, index, scope, query, notes, scopes);
|
|
149
|
+
},
|
|
150
|
+
impact: onFile('impact', (index, file, params) => renderImpact(index, file, depthOf(params.depth), withinOf(params.query))),
|
|
151
|
+
tests: onFile('tests', (index, file, _params, query) => renderTests(index, file, query)),
|
|
152
|
+
routes: (_params, index, scope, query) => renderRoutes(index, query, scope.rel),
|
|
153
|
+
changed: (_params, index, scope, query) => renderChanged(index, query || 'HEAD', scope.rel),
|
|
154
|
+
};
|
|
155
|
+
async function dispatch(action, params, index, scope, notes, scopes) {
|
|
156
|
+
const query = typeof params.query === 'string' ? params.query.trim() : '';
|
|
157
|
+
return HANDLERS[action](params, index, scope, query, notes, scopes);
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* The answer with where the index came from as its first line when the load
|
|
161
|
+
* did more than a memory hit (the overview says it in its own header) and, at
|
|
162
|
+
* the end, what went wrong with the `.sonar`.
|
|
163
|
+
*/
|
|
164
|
+
function withLoadNotes(action, text, index) {
|
|
165
|
+
const quiet = action === 'overview' || text.startsWith('Error:') || !loadWasNotable(index);
|
|
166
|
+
const head = quiet ? text : `(sonar ${renderLoadStats(index)})\n${text}`;
|
|
167
|
+
const problems = sonarCacheProblems(index);
|
|
168
|
+
return problems.length > 0 ? `${head}\n${problems.join('\n')}` : head;
|
|
169
|
+
}
|
|
170
|
+
/** How long a call waits for a build of a checkout that has no usable index. */
|
|
171
|
+
const SONAR_REBUILD_WAIT_MS = 15_000;
|
|
172
|
+
/** What the tool says while the index of the checkout is still being built: the agent goes on without it for now. */
|
|
173
|
+
export const SONAR_BUILDING_ANSWER = 'Error: sonar has no usable index for this checkout yet; a build runs in the background, ask again in a minute. Meanwhile go on with runner_grep and runner_outline.';
|
|
174
|
+
/** What the tool says when the index could not be built (the Sonar view shows why). */
|
|
175
|
+
export const SONAR_BUILD_FAILED_ANSWER = 'Error: sonar could not build an index for this checkout (the Sonar view in the code app shows why). Go on with runner_grep and runner_outline.';
|
|
176
|
+
const notBuiltAnswer = (root, load) => sonarStatus(root, { cacheDir: load.cacheDir }).state === 'building' ? SONAR_BUILDING_ANSWER : SONAR_BUILD_FAILED_ANSWER;
|
|
177
|
+
/** The index of `root`, built again first when it has no usable one; throws SonarNotBuiltError when that does not finish in time or fails. */
|
|
178
|
+
async function loadOrRebuild(root, load) {
|
|
179
|
+
const opts = { cacheDir: load.cacheDir, now: load.now };
|
|
180
|
+
try {
|
|
181
|
+
return await loadSonarIndex(root, opts);
|
|
182
|
+
}
|
|
183
|
+
catch (err) {
|
|
184
|
+
if (!(err instanceof SonarNotBuiltError))
|
|
185
|
+
throw err;
|
|
186
|
+
if (!await ensureSonarBuilt(root, { cacheDir: load.cacheDir, waitMs: load.rebuildWaitMs ?? SONAR_REBUILD_WAIT_MS }))
|
|
187
|
+
throw err;
|
|
188
|
+
return loadSonarIndex(root, opts);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
/** At the end of an answer (not the overview: its header says it) from an index more files behind than a call reads again. */
|
|
192
|
+
const behindNote = (action, index, notes) => {
|
|
193
|
+
if (action === 'overview')
|
|
194
|
+
return null;
|
|
195
|
+
const stale = renderStale(index, notes);
|
|
196
|
+
return stale ? `(sonar ${stale})` : null;
|
|
197
|
+
};
|
|
198
|
+
/** The tool with a configurable index load (tests pass a temp cacheDir, and how long to wait for a build). */
|
|
199
|
+
export async function runSonar(params, context, load = {}) {
|
|
200
|
+
const action = params.action;
|
|
201
|
+
if (typeof action !== 'string' || !ACTIONS.includes(action)) {
|
|
202
|
+
return `Error: action must be one of ${ACTIONS.join(', ')}.`;
|
|
203
|
+
}
|
|
204
|
+
if (!context?.projectRoot)
|
|
205
|
+
return 'Error: runner_sonar needs a project checkout.';
|
|
206
|
+
let root = context.projectRoot;
|
|
207
|
+
try {
|
|
208
|
+
root = realpathSync(context.projectRoot);
|
|
209
|
+
const many = action === 'file' ? pathsOf(params.path) : [];
|
|
210
|
+
const scopes = many.length > 1 ? many.map(p => scopeOf(p, root, context)) : [];
|
|
211
|
+
const scope = scopes.length > 1 ? { rel: '' } : scopeOf(pathParam(action, params.path, context), root, context);
|
|
212
|
+
if (typeof scope === 'string')
|
|
213
|
+
return scope;
|
|
214
|
+
const index = await loadOrRebuild(root, load);
|
|
215
|
+
const notes = { catchingUp: catchUpSonar(index, { cacheDir: load.cacheDir }) };
|
|
216
|
+
const text = withLoadNotes(action, await dispatch(action, params, index, scope, notes, scopes), index);
|
|
217
|
+
const behind = behindNote(action, index, notes);
|
|
218
|
+
return behind ? `${text}\n${behind}` : text;
|
|
219
|
+
}
|
|
220
|
+
catch (err) {
|
|
221
|
+
if (err instanceof SonarNotBuiltError)
|
|
222
|
+
return notBuiltAnswer(root, load);
|
|
223
|
+
return `Error: ${err.message}`;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
async function executeSonar(params, context) {
|
|
227
|
+
return runSonar(params, context);
|
|
228
|
+
}
|
|
229
|
+
export const sonarTools = [
|
|
230
|
+
{ definition: sonarDefinition, execute: executeSonar },
|
|
231
|
+
];
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { ToolDefinition } from '@nordhavnhq/runner-runtime';
|
|
2
|
+
import type { ToolContext } from './index.js';
|
|
3
|
+
type TestFramework = 'vitest' | 'jest' | 'phpunit' | 'pest' | 'custom';
|
|
4
|
+
export interface TestPlan {
|
|
5
|
+
framework: TestFramework;
|
|
6
|
+
/** Program and arguments, spawned without a shell; or one shell line. */
|
|
7
|
+
command: string;
|
|
8
|
+
args: string[];
|
|
9
|
+
shell: boolean;
|
|
10
|
+
/** Where the reporter writes its report, when there is one. */
|
|
11
|
+
reportFile?: string;
|
|
12
|
+
/** How the command was found, for the answer's first line. */
|
|
13
|
+
label: string;
|
|
14
|
+
/** The body of the project's test script, for a plan that runs it: checked like any shell line. */
|
|
15
|
+
script?: string;
|
|
16
|
+
}
|
|
17
|
+
/** Single-quote a value for a POSIX shell line. */
|
|
18
|
+
export declare function shellQuote(value: string): string;
|
|
19
|
+
/**
|
|
20
|
+
* How to run this folder's tests: vitest or jest from package.json (through
|
|
21
|
+
* its own `test` script when that runs it), else pest or phpunit from
|
|
22
|
+
* composer.json, else the folder's own `test` script as it is. Returns an
|
|
23
|
+
* error the model can act on when there is no test command to find.
|
|
24
|
+
* Exported for tests.
|
|
25
|
+
*/
|
|
26
|
+
export declare function planTestRun(cwd: string, opts: {
|
|
27
|
+
filter?: string;
|
|
28
|
+
name?: string;
|
|
29
|
+
reportDir: string;
|
|
30
|
+
}): TestPlan | string;
|
|
31
|
+
declare function executeTest(params: Record<string, unknown>, context?: ToolContext): Promise<string>;
|
|
32
|
+
export declare const testTools: {
|
|
33
|
+
definition: ToolDefinition;
|
|
34
|
+
execute: typeof executeTest;
|
|
35
|
+
}[];
|
|
36
|
+
export {};
|
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import { createWriteStream, existsSync, mkdirSync, readFileSync } from 'node:fs';
|
|
3
|
+
import { tmpdir } from 'node:os';
|
|
4
|
+
import { join } from 'node:path';
|
|
5
|
+
import { activeWriteScope, resolveInCheckout } from './_jail.js';
|
|
6
|
+
import { sonarTestHint, withHint } from './_sonar/hints.js';
|
|
7
|
+
import { toNum } from './_coerce.js';
|
|
8
|
+
import { clipHeadTail } from './_output.js';
|
|
9
|
+
import { commandEnv, detectGitPush, isBlocked } from './console.js';
|
|
10
|
+
import { projectNodeNote, resolveProjectNode } from '../runtime/project-node.js';
|
|
11
|
+
import { TOOL_OUTPUT_SPILL_DIR } from '../runtime/spill-tool-output.js';
|
|
12
|
+
import { addConsoleDiffs, parseJestJson, parseJunitXml, renderTestSummary, TEST_SUMMARY_MAX_CHARS } from './_test-report.js';
|
|
13
|
+
const DEFAULT_TIMEOUT_SEC = 300;
|
|
14
|
+
const MAX_TIMEOUT_SEC = 900;
|
|
15
|
+
function sniff(text) {
|
|
16
|
+
if (/\bvitest\b/.test(text))
|
|
17
|
+
return 'vitest';
|
|
18
|
+
if (/\bjest\b/.test(text))
|
|
19
|
+
return 'jest';
|
|
20
|
+
if (/\bpest\b/.test(text))
|
|
21
|
+
return 'pest';
|
|
22
|
+
if (/\bphpunit\b/.test(text))
|
|
23
|
+
return 'phpunit';
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
function readJson(path) {
|
|
27
|
+
try {
|
|
28
|
+
return JSON.parse(readFileSync(path, 'utf-8'));
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/** Single-quote a value for a POSIX shell line. */
|
|
35
|
+
export function shellQuote(value) {
|
|
36
|
+
return /^[\w./:=@%+-]+$/.test(value) ? value : `'${value.replace(/'/g, `'\\''`)}'`;
|
|
37
|
+
}
|
|
38
|
+
/** Reporter flags plus the filter, for a framework. */
|
|
39
|
+
function frameworkArgs(fw, reportFile, filter, name) {
|
|
40
|
+
const args = [];
|
|
41
|
+
if (fw === 'vitest') {
|
|
42
|
+
args.push('--run', '--reporter=default', '--reporter=json', `--outputFile.json=${reportFile}`);
|
|
43
|
+
if (name)
|
|
44
|
+
args.push('-t', name);
|
|
45
|
+
if (filter)
|
|
46
|
+
args.push(filter);
|
|
47
|
+
}
|
|
48
|
+
else if (fw === 'jest') {
|
|
49
|
+
args.push('--ci', '--json', `--outputFile=${reportFile}`, '--testLocationInResults');
|
|
50
|
+
if (name)
|
|
51
|
+
args.push('-t', name);
|
|
52
|
+
if (filter)
|
|
53
|
+
args.push(filter);
|
|
54
|
+
}
|
|
55
|
+
else if (fw === 'phpunit' || fw === 'pest') {
|
|
56
|
+
args.push('--log-junit', reportFile);
|
|
57
|
+
if (name)
|
|
58
|
+
args.push('--filter', name);
|
|
59
|
+
if (filter) {
|
|
60
|
+
if (/[/\\]|\.php$/.test(filter))
|
|
61
|
+
args.push(filter);
|
|
62
|
+
else if (!name)
|
|
63
|
+
args.push('--filter', filter);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
else if (filter) {
|
|
67
|
+
args.push(filter);
|
|
68
|
+
}
|
|
69
|
+
return args;
|
|
70
|
+
}
|
|
71
|
+
/** npm's placeholder from `npm init`: no test command at all. */
|
|
72
|
+
const NO_TEST_SCRIPT = /no test specified/;
|
|
73
|
+
/**
|
|
74
|
+
* The project's own `test` script (package.json, else composer.json), run as
|
|
75
|
+
* is: for a project whose tests are not vitest, jest, pest or phpunit in its
|
|
76
|
+
* dependencies (a monorepo root, a test runner in a container, a shell
|
|
77
|
+
* script). The reporter is added when the script names a framework.
|
|
78
|
+
*/
|
|
79
|
+
function scriptPlan(cwd, stamp, opts) {
|
|
80
|
+
const found = testScript(cwd);
|
|
81
|
+
if (!found)
|
|
82
|
+
return null;
|
|
83
|
+
const fw = sniff(found.body) ?? 'custom';
|
|
84
|
+
const reportFile = join(opts.reportDir, `runner_test-${stamp}.${fw === 'phpunit' || fw === 'pest' ? 'xml' : 'json'}`);
|
|
85
|
+
const extra = frameworkArgs(fw, reportFile, opts.filter, opts.name);
|
|
86
|
+
return {
|
|
87
|
+
framework: fw,
|
|
88
|
+
// npm and composer pass arguments on to the script only after `--`.
|
|
89
|
+
command: `${found.runner}${extra.length > 0 ? ' --' : ''}${extra.map(a => ` ${shellQuote(a)}`).join('')}`,
|
|
90
|
+
args: [],
|
|
91
|
+
shell: true,
|
|
92
|
+
reportFile: fw === 'custom' ? undefined : reportFile,
|
|
93
|
+
label: `${fw === 'custom' ? 'custom command' : fw} via ${found.via}`,
|
|
94
|
+
script: found.body,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
/** The folder's `test` script: package.json's (not npm's placeholder), else composer.json's (a list joined with &&). */
|
|
98
|
+
function testScript(cwd) {
|
|
99
|
+
const npm = readJson(join(cwd, 'package.json'))?.scripts?.test;
|
|
100
|
+
if (typeof npm === 'string' && !NO_TEST_SCRIPT.test(npm))
|
|
101
|
+
return { body: npm, runner: 'npm run test --silent', via: 'npm run test' };
|
|
102
|
+
const composer = readJson(join(cwd, 'composer.json'))?.scripts?.test;
|
|
103
|
+
const body = Array.isArray(composer) ? composer.filter(c => typeof c === 'string').join(' && ') : composer;
|
|
104
|
+
return typeof body === 'string' && body ? { body, runner: 'composer run-script test', via: 'composer run-script test' } : null;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* How to run this folder's tests: vitest or jest from package.json (through
|
|
108
|
+
* its own `test` script when that runs it), else pest or phpunit from
|
|
109
|
+
* composer.json, else the folder's own `test` script as it is. Returns an
|
|
110
|
+
* error the model can act on when there is no test command to find.
|
|
111
|
+
* Exported for tests.
|
|
112
|
+
*/
|
|
113
|
+
export function planTestRun(cwd, opts) {
|
|
114
|
+
const stamp = `${Date.now()}`;
|
|
115
|
+
const pkg = readJson(join(cwd, 'package.json'));
|
|
116
|
+
if (pkg) {
|
|
117
|
+
const deps = { ...pkg.dependencies, ...pkg.devDependencies };
|
|
118
|
+
const fw = deps.vitest ? 'vitest' : deps.jest ? 'jest' : null;
|
|
119
|
+
if (fw) {
|
|
120
|
+
const reportFile = join(opts.reportDir, `runner_test-${stamp}.json`);
|
|
121
|
+
const extra = frameworkArgs(fw, reportFile, opts.filter, opts.name);
|
|
122
|
+
const script = pkg.scripts?.test;
|
|
123
|
+
// The project's own script first: it may load an env file or a setup the bare binary does not.
|
|
124
|
+
if (typeof script === 'string' && sniff(script) === fw) {
|
|
125
|
+
return { framework: fw, command: 'npm', args: ['run', 'test', '--silent', '--', ...extra], shell: false, reportFile, label: `${fw} via npm run test` };
|
|
126
|
+
}
|
|
127
|
+
return { framework: fw, command: 'npx', args: ['--no-install', fw, ...extra], shell: false, reportFile, label: fw };
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
const composer = readJson(join(cwd, 'composer.json'));
|
|
131
|
+
if (composer) {
|
|
132
|
+
const deps = { ...composer.require, ...composer['require-dev'] };
|
|
133
|
+
const fw = deps['pestphp/pest'] ? 'pest' : deps['phpunit/phpunit'] ? 'phpunit' : null;
|
|
134
|
+
if (fw) {
|
|
135
|
+
const reportFile = join(opts.reportDir, `runner_test-${stamp}.xml`);
|
|
136
|
+
return { framework: fw, command: join(cwd, 'vendor', 'bin', fw), args: frameworkArgs(fw, reportFile, opts.filter, opts.name), shell: false, reportFile, label: fw };
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
const script = scriptPlan(cwd, stamp, opts);
|
|
140
|
+
if (script)
|
|
141
|
+
return script;
|
|
142
|
+
return `Error: no test command found in ${cwd}: no vitest or jest in package.json, no pest or phpunit in composer.json, no "test" script in either. Give the project a "test" script, pass cwd for a package in a monorepo, or use runner_run_command.`;
|
|
143
|
+
}
|
|
144
|
+
const testDefinition = {
|
|
145
|
+
name: 'runner_test',
|
|
146
|
+
description: 'Run the project\'s tests and get back only the counts and the failures (where, why, a short diff) in ~3k chars; the whole output is saved to a file named in the answer. Finds the command itself (vitest or jest from package.json, pest or phpunit from composer.json, else the project\'s own "test" script). Pass a filter: the tests that cover your change, the full suite at most once, at the end.',
|
|
147
|
+
parameters: {
|
|
148
|
+
type: 'object',
|
|
149
|
+
properties: {
|
|
150
|
+
filter: { type: 'string', description: 'Which tests: a test file or a part of its path (vitest, jest), or a file or a --filter pattern (phpunit, pest). Without it the whole suite runs.' },
|
|
151
|
+
name: { type: 'string', description: 'Only tests whose name matches this pattern (-t for vitest/jest, --filter for phpunit/pest).' },
|
|
152
|
+
cwd: { type: 'string', description: 'Folder to run in, relative to the project root (a package in a monorepo). Default: the session\'s scope folder, else the project root.' },
|
|
153
|
+
timeout: { type: 'number', description: `Seconds before the run is stopped. Default: ${DEFAULT_TIMEOUT_SEC}, max ${MAX_TIMEOUT_SEC}.` },
|
|
154
|
+
},
|
|
155
|
+
required: [],
|
|
156
|
+
},
|
|
157
|
+
};
|
|
158
|
+
async function executeTest(params, context) {
|
|
159
|
+
const projectRoot = context?.projectRoot || context?.agentHome;
|
|
160
|
+
if (!projectRoot)
|
|
161
|
+
return 'Error: no project root for this run.';
|
|
162
|
+
let cwd;
|
|
163
|
+
try {
|
|
164
|
+
// Running tests changes nothing of the checkout: any folder of it may be
|
|
165
|
+
// the cwd, and the session's scope is only the default.
|
|
166
|
+
cwd = typeof params.cwd === 'string' && params.cwd
|
|
167
|
+
? resolveInCheckout(params.cwd, context)
|
|
168
|
+
: activeWriteScope(context) ?? resolveInCheckout('.', context);
|
|
169
|
+
}
|
|
170
|
+
catch (err) {
|
|
171
|
+
return `Error: ${err.message}`;
|
|
172
|
+
}
|
|
173
|
+
const outDir = context?.scratchRoot ? join(context.scratchRoot, TOOL_OUTPUT_SPILL_DIR) : join(tmpdir(), 'nordhavn-tests');
|
|
174
|
+
mkdirSync(outDir, { recursive: true });
|
|
175
|
+
const filter = typeof params.filter === 'string' && params.filter.trim() ? params.filter.trim() : undefined;
|
|
176
|
+
const name = typeof params.name === 'string' && params.name.trim() ? params.name.trim() : undefined;
|
|
177
|
+
const plan = planTestRun(cwd, { filter, name, reportDir: outDir });
|
|
178
|
+
if (typeof plan === 'string')
|
|
179
|
+
return plan;
|
|
180
|
+
if (plan.script) {
|
|
181
|
+
const refused = isBlocked(plan.script) ?? detectGitPush(plan.script);
|
|
182
|
+
if (refused)
|
|
183
|
+
return `${refused} (from the project's test script)`;
|
|
184
|
+
}
|
|
185
|
+
const requested = toNum(params.timeout);
|
|
186
|
+
const timeoutSec = requested && requested > 0 ? Math.min(requested, MAX_TIMEOUT_SEC) : DEFAULT_TIMEOUT_SEC;
|
|
187
|
+
const outputFile = join(outDir, `runner_test-${Date.now()}.txt`);
|
|
188
|
+
// The Node the project pins, first on PATH; a line at the end when it could not be had.
|
|
189
|
+
const node = await resolveProjectNode(cwd, projectRoot);
|
|
190
|
+
const run = await runCaptured(plan, cwd, commandEnv(context, projectRoot, process.env, node?.binDir), outputFile, timeoutSec, context?.signal);
|
|
191
|
+
const label = node?.binDir ? `${plan.label}, node ${node.version}` : plan.label;
|
|
192
|
+
const summary = summarizeRun(plan, run, { cwd, label, outputFile, timeoutSec });
|
|
193
|
+
const warning = await projectNodeNote(node);
|
|
194
|
+
return withHint(sonarTestHint(filter, context), warning ? `${summary}\n${warning}` : summary);
|
|
195
|
+
}
|
|
196
|
+
/** The answer for a finished run: counts and failures from its report, else the tail of its output. */
|
|
197
|
+
function summarizeRun(plan, run, opts) {
|
|
198
|
+
const { cwd, label, outputFile, timeoutSec } = opts;
|
|
199
|
+
if (run.timedOut) {
|
|
200
|
+
return `FAILED: stopped after ${timeoutSec}s [${label}]. Narrow it with a filter, or pass a longer timeout.\n${clipHeadTail(run.tail, 1_500)}\nFull output: ${outputFile}`;
|
|
201
|
+
}
|
|
202
|
+
if (run.aborted)
|
|
203
|
+
return `Cancelled [${label}]. Output so far: ${outputFile}`;
|
|
204
|
+
const reportText = plan.reportFile && existsSync(plan.reportFile) ? readFileSync(plan.reportFile, 'utf-8') : null;
|
|
205
|
+
const report = reportText === null
|
|
206
|
+
? null
|
|
207
|
+
: plan.framework === 'phpunit' || plan.framework === 'pest' ? parseJunitXml(reportText, cwd) : parseJestJson(reportText, cwd);
|
|
208
|
+
if (!report) {
|
|
209
|
+
// No report: a custom command, or a run that broke before any test did.
|
|
210
|
+
const status = run.exitCode === 0 ? 'PASSED' : 'FAILED';
|
|
211
|
+
const head = `${status}: exit code ${run.exitCode} after ${run.seconds.toFixed(1)}s [${label}]${plan.framework === 'custom' ? '' : ', no test report was written'}`;
|
|
212
|
+
return `${head}\n${clipHeadTail(run.tail.trim(), TEST_SUMMARY_MAX_CHARS - head.length - outputFile.length - 40, 0.1)}\nFull output: ${outputFile}`;
|
|
213
|
+
}
|
|
214
|
+
if (plan.framework === 'vitest')
|
|
215
|
+
addConsoleDiffs(report, readTail(outputFile, 2 * 1024 * 1024));
|
|
216
|
+
return renderTestSummary(report, { exitCode: run.exitCode, label, seconds: run.seconds, fullOutputAt: outputFile });
|
|
217
|
+
}
|
|
218
|
+
/** The last `maxBytes` of a file: the failure summary is at the end of a run's output. */
|
|
219
|
+
function readTail(path, maxBytes) {
|
|
220
|
+
try {
|
|
221
|
+
const buf = readFileSync(path);
|
|
222
|
+
return buf.subarray(Math.max(0, buf.length - maxBytes)).toString('utf-8');
|
|
223
|
+
}
|
|
224
|
+
catch {
|
|
225
|
+
return '';
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
/** Run the plan with stdout and stderr written to `outputFile` as they come. */
|
|
229
|
+
function runCaptured(plan, cwd, env, outputFile, timeoutSec, signal) {
|
|
230
|
+
return new Promise((resolve) => {
|
|
231
|
+
const started = Date.now();
|
|
232
|
+
const out = createWriteStream(outputFile);
|
|
233
|
+
const child = plan.shell
|
|
234
|
+
? spawn('sh', ['-c', plan.command], { cwd, env, stdio: ['ignore', 'pipe', 'pipe'], detached: true })
|
|
235
|
+
: spawn(plan.command, plan.args, { cwd, env, stdio: ['ignore', 'pipe', 'pipe'], detached: true });
|
|
236
|
+
let tail = '';
|
|
237
|
+
let timedOut = false;
|
|
238
|
+
let aborted = false;
|
|
239
|
+
const keep = (chunk) => {
|
|
240
|
+
out.write(chunk);
|
|
241
|
+
tail = (tail + chunk.toString()).slice(-20_000);
|
|
242
|
+
};
|
|
243
|
+
child.stdout?.on('data', keep);
|
|
244
|
+
child.stderr?.on('data', keep);
|
|
245
|
+
// The whole process group: a test runner starts workers of its own.
|
|
246
|
+
const stop = () => {
|
|
247
|
+
try {
|
|
248
|
+
if (child.pid)
|
|
249
|
+
process.kill(-child.pid, 'SIGKILL');
|
|
250
|
+
}
|
|
251
|
+
catch { }
|
|
252
|
+
};
|
|
253
|
+
const timer = setTimeout(() => { timedOut = true; stop(); }, timeoutSec * 1000);
|
|
254
|
+
const onAbort = () => { aborted = true; stop(); };
|
|
255
|
+
signal?.addEventListener('abort', onAbort, { once: true });
|
|
256
|
+
let done = false;
|
|
257
|
+
const finish = (exitCode, extra = '') => {
|
|
258
|
+
if (done)
|
|
259
|
+
return;
|
|
260
|
+
done = true;
|
|
261
|
+
clearTimeout(timer);
|
|
262
|
+
signal?.removeEventListener('abort', onAbort);
|
|
263
|
+
if (extra)
|
|
264
|
+
tail += extra;
|
|
265
|
+
out.end(extra, () => resolve({ exitCode, seconds: (Date.now() - started) / 1000, tail: tail.replace(/\x1b\[[0-9;]*m/g, ''), timedOut, aborted }));
|
|
266
|
+
};
|
|
267
|
+
child.on('error', err => finish(null, `\n${err.message}`));
|
|
268
|
+
child.on('close', code => finish(code));
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
export const testTools = [
|
|
272
|
+
{ definition: testDefinition, execute: executeTest },
|
|
273
|
+
];
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ToolDefinition } from '@nordhavnhq/runner-runtime';
|
|
2
|
+
import type { ToolContext } from './index.js';
|
|
3
|
+
declare function executeUploadFile(params: Record<string, unknown>, context?: ToolContext): Promise<string>;
|
|
4
|
+
export declare const uploadTools: {
|
|
5
|
+
definition: ToolDefinition;
|
|
6
|
+
execute: typeof executeUploadFile;
|
|
7
|
+
}[];
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
// MIRROR: studio apps/server/server/api/agents/upload.post.ts (MAX_SIZE)
|
|
2
|
+
import { readFileSync, existsSync, statSync } from 'node:fs';
|
|
3
|
+
import { basename } from 'node:path';
|
|
4
|
+
import { resolveForRead } from './_jail.js';
|
|
5
|
+
import { mimeFromFilename, uploadFile, UPLOADABLE_EXTENSIONS } from './_upload.js';
|
|
6
|
+
// ─── runner_upload_file ─────────────────────────
|
|
7
|
+
//
|
|
8
|
+
// Push a local file from the agent's jailed filesystem up to the studio so it
|
|
9
|
+
// becomes a permanent project file (or an org-scoped file when the dispatch
|
|
10
|
+
// isn't bound to a project). Screenshots/generated images already land via the
|
|
11
|
+
// capture/image tools' `keep:true`; this is the general path for pre-existing
|
|
12
|
+
// assets on disk (e.g. images checked into a repo) that need to reach the file
|
|
13
|
+
// manager or be referenced from a dataset image/gallery field.
|
|
14
|
+
// Mirrors the server's `/api/agents/upload` MAX_SIZE (10 MB).
|
|
15
|
+
const MAX_UPLOAD_SIZE = 10 * 1024 * 1024;
|
|
16
|
+
const uploadFileDefinition = {
|
|
17
|
+
name: 'runner_upload_file',
|
|
18
|
+
description: 'Upload local file(s) into the project file manager. Use this to get on-disk assets (images, PDFs, documents) into Files so they can be embedded in a document or referenced from a dataset image/gallery field. Pass `path` for one file or `paths` for many (uploaded in one call). Returns each file\'s `uid` and `referenceUrl`.',
|
|
19
|
+
parameters: {
|
|
20
|
+
type: 'object',
|
|
21
|
+
properties: {
|
|
22
|
+
path: {
|
|
23
|
+
type: 'string',
|
|
24
|
+
description: 'Path of a single local file to upload. Relative paths resolve against the project root; absolute paths must stay within the agent\'s allowed roots.',
|
|
25
|
+
},
|
|
26
|
+
paths: {
|
|
27
|
+
type: 'array',
|
|
28
|
+
items: { type: 'string' },
|
|
29
|
+
description: 'Paths of multiple local files to upload in one call. Use this instead of calling the tool repeatedly. Returns a `results` array (one entry per path, order preserved); a single failure does not abort the rest.',
|
|
30
|
+
},
|
|
31
|
+
folder: {
|
|
32
|
+
type: 'string',
|
|
33
|
+
description: 'Optional file-manager folder NAME to drop the file(s) into (find-or-created). Omit to save at the project root.',
|
|
34
|
+
},
|
|
35
|
+
name: {
|
|
36
|
+
type: 'string',
|
|
37
|
+
description: 'Optional filename to store the file under (single `path` only; ignored for `paths`). Defaults to the on-disk name.',
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
required: [],
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
/** Upload one jailed path, never throwing - failures come back as `{ ok:false }`
|
|
44
|
+
* so a bulk call can keep going. */
|
|
45
|
+
async function uploadOne(path, context, folder, nameOverride) {
|
|
46
|
+
try {
|
|
47
|
+
const resolved = resolveForRead(path, context);
|
|
48
|
+
if (!existsSync(resolved))
|
|
49
|
+
return { ok: false, path, error: 'File not found' };
|
|
50
|
+
const stat = statSync(resolved);
|
|
51
|
+
if (stat.isDirectory())
|
|
52
|
+
return { ok: false, path, error: 'Is a directory, not a file' };
|
|
53
|
+
if (stat.size === 0)
|
|
54
|
+
return { ok: false, path, error: 'File is empty' };
|
|
55
|
+
if (stat.size > MAX_UPLOAD_SIZE) {
|
|
56
|
+
return { ok: false, path, error: `${(stat.size / 1024 / 1024).toFixed(1)} MB, over the 10 MB limit` };
|
|
57
|
+
}
|
|
58
|
+
const filename = nameOverride ?? basename(resolved);
|
|
59
|
+
const mimeType = mimeFromFilename(filename);
|
|
60
|
+
if (!mimeType) {
|
|
61
|
+
return { ok: false, path, error: `Unsupported type. Accepted: ${UPLOADABLE_EXTENSIONS.join(', ')}` };
|
|
62
|
+
}
|
|
63
|
+
const data = readFileSync(resolved);
|
|
64
|
+
const res = await uploadFile(data, filename, mimeType, 'agent-uploads', context, folder);
|
|
65
|
+
if (res.startsWith('Error:'))
|
|
66
|
+
return { ok: false, path, error: res.slice('Error:'.length).trim() };
|
|
67
|
+
const parsed = JSON.parse(res);
|
|
68
|
+
return { ok: true, path, uid: parsed.uid, referenceUrl: parsed.referenceUrl, name: parsed.name, size: parsed.size };
|
|
69
|
+
}
|
|
70
|
+
catch (err) {
|
|
71
|
+
return { ok: false, path, error: err.message };
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
async function executeUploadFile(params, context) {
|
|
75
|
+
if (!context)
|
|
76
|
+
return 'Error: no execution context available';
|
|
77
|
+
const folder = typeof params.folder === 'string' && params.folder.trim() ? params.folder.trim() : undefined;
|
|
78
|
+
const nameOverride = typeof params.name === 'string' && params.name.trim() ? params.name.trim() : undefined;
|
|
79
|
+
const single = typeof params.path === 'string' && params.path.trim() ? params.path.trim() : undefined;
|
|
80
|
+
const many = Array.isArray(params.paths)
|
|
81
|
+
? params.paths.filter((p) => typeof p === 'string' && p.trim().length > 0).map(p => p.trim())
|
|
82
|
+
: [];
|
|
83
|
+
// Bulk mode: `paths` given (single `path`, if also present, is prepended).
|
|
84
|
+
// `name` is meaningless across many files, so it is ignored here.
|
|
85
|
+
if (many.length > 0) {
|
|
86
|
+
const targets = single ? [single, ...many] : many;
|
|
87
|
+
const results = [];
|
|
88
|
+
// Sequential: keeps peak memory to one file and stays gentle on the
|
|
89
|
+
// server's per-agent upload rate limit.
|
|
90
|
+
for (const p of targets) {
|
|
91
|
+
results.push(await uploadOne(p, context, folder, undefined));
|
|
92
|
+
}
|
|
93
|
+
const uploaded = results.filter(r => r.ok).length;
|
|
94
|
+
return JSON.stringify({ uploaded, failed: results.length - uploaded, results });
|
|
95
|
+
}
|
|
96
|
+
if (!single)
|
|
97
|
+
return 'Error: provide `path` (one file) or `paths` (a list of files).';
|
|
98
|
+
const result = await uploadOne(single, context, folder, nameOverride);
|
|
99
|
+
if (!result.ok)
|
|
100
|
+
return `Error: ${single}: ${result.error}`;
|
|
101
|
+
return JSON.stringify({ success: true, uid: result.uid, referenceUrl: result.referenceUrl, name: result.name, size: result.size });
|
|
102
|
+
}
|
|
103
|
+
// ─── Exports ────────────────────────────────
|
|
104
|
+
export const uploadTools = [
|
|
105
|
+
{ definition: uploadFileDefinition, execute: executeUploadFile },
|
|
106
|
+
];
|