@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,203 @@
|
|
|
1
|
+
import { isAbsolute, relative } from 'node:path';
|
|
2
|
+
// ─── Test reports, read for an agent ─────────
|
|
3
|
+
//
|
|
4
|
+
// A test run's own output is written for a person at a terminal: progress
|
|
5
|
+
// lines, colours, every passing file. What an agent needs is short: did it
|
|
6
|
+
// pass, and for each failure where it is and why. runner_test runs the suite
|
|
7
|
+
// with a machine-readable reporter (Jest-shaped JSON from vitest and jest,
|
|
8
|
+
// JUnit XML from phpunit and pest) and this file turns that report into a
|
|
9
|
+
// summary of about 3k chars. The whole output is kept in a file beside it.
|
|
10
|
+
/** Most chars the summary may take. */
|
|
11
|
+
export const TEST_SUMMARY_MAX_CHARS = 3_000;
|
|
12
|
+
/** Most chars per failure message and per diff. */
|
|
13
|
+
const MESSAGE_MAX_CHARS = 400;
|
|
14
|
+
const DIFF_MAX_LINES = 12;
|
|
15
|
+
const ANSI = /\x1b\[[0-9;]*m/g;
|
|
16
|
+
function stripAnsi(text) {
|
|
17
|
+
return text.replace(ANSI, '');
|
|
18
|
+
}
|
|
19
|
+
function relPath(file, cwd) {
|
|
20
|
+
return isAbsolute(file) ? relative(cwd, file) : file;
|
|
21
|
+
}
|
|
22
|
+
/** The message and the expected/received diff out of an assertion's text. */
|
|
23
|
+
export function splitFailureText(raw) {
|
|
24
|
+
const lines = stripAnsi(raw).split('\n');
|
|
25
|
+
const message = [];
|
|
26
|
+
const diff = [];
|
|
27
|
+
let inDiff = false;
|
|
28
|
+
for (const line of lines) {
|
|
29
|
+
const t = line.trimEnd();
|
|
30
|
+
if (/^\s+at\s|^\s*❯\s/.test(t)) {
|
|
31
|
+
if (inDiff || message.length > 0)
|
|
32
|
+
break;
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
if (/^\s*[-+] Expected|^\s*[-+] Received/.test(t))
|
|
36
|
+
inDiff = true;
|
|
37
|
+
if (inDiff) {
|
|
38
|
+
if (diff.length < DIFF_MAX_LINES)
|
|
39
|
+
diff.push(t);
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
if (t.trim() && message.length < 6)
|
|
43
|
+
message.push(t.trim());
|
|
44
|
+
}
|
|
45
|
+
const text = message.join(' ');
|
|
46
|
+
return {
|
|
47
|
+
message: text.length > MESSAGE_MAX_CHARS ? `${text.slice(0, MESSAGE_MAX_CHARS)}...` : text,
|
|
48
|
+
diff: diff.length > 0 ? diff.join('\n') : undefined,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
/** The first `file:line` of the test file itself in a stack. */
|
|
52
|
+
function lineFromStack(raw, file) {
|
|
53
|
+
const base = file.split('/').pop();
|
|
54
|
+
if (!base)
|
|
55
|
+
return undefined;
|
|
56
|
+
const escaped = base.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
57
|
+
const m = new RegExp(`${escaped}:(\\d+)(?::\\d+)?`).exec(stripAnsi(raw));
|
|
58
|
+
return m ? Number(m[1]) : undefined;
|
|
59
|
+
}
|
|
60
|
+
/** A Jest-shaped JSON report (jest --json, vitest's json reporter). */
|
|
61
|
+
export function parseJestJson(text, cwd) {
|
|
62
|
+
let json;
|
|
63
|
+
try {
|
|
64
|
+
json = JSON.parse(text);
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
if (!json || typeof json !== 'object' || !Array.isArray(json.testResults))
|
|
70
|
+
return null;
|
|
71
|
+
const failures = [];
|
|
72
|
+
const errors = [];
|
|
73
|
+
for (const file of json.testResults) {
|
|
74
|
+
const path = relPath(file.name ?? '', cwd);
|
|
75
|
+
const failedTests = (file.assertionResults ?? []).filter(a => a.status === 'failed');
|
|
76
|
+
for (const a of failedTests) {
|
|
77
|
+
const raw = (a.failureMessages ?? []).join('\n');
|
|
78
|
+
const line = a.location?.line ?? lineFromStack(raw, path);
|
|
79
|
+
failures.push({ name: a.fullName || a.title || '(unnamed test)', title: a.title, where: line ? `${path}:${line}` : path, ...splitFailureText(raw) });
|
|
80
|
+
}
|
|
81
|
+
if (file.status === 'failed' && failedTests.length === 0 && file.message) {
|
|
82
|
+
errors.push(`${path}: ${splitFailureText(file.message).message}`);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return {
|
|
86
|
+
passed: json.numPassedTests ?? 0,
|
|
87
|
+
failed: json.numFailedTests ?? failures.length,
|
|
88
|
+
skipped: (json.numPendingTests ?? 0) + (json.numTodoTests ?? 0),
|
|
89
|
+
files: json.testResults.length,
|
|
90
|
+
failures,
|
|
91
|
+
errors,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Vitest's JSON report carries a failure's message and stack but not its
|
|
96
|
+
* expected/received diff, which its console output does print, under a
|
|
97
|
+
* ` FAIL <file> > <suite> > <title>` header. Fill the missing diffs from there.
|
|
98
|
+
*/
|
|
99
|
+
export function addConsoleDiffs(report, consoleText) {
|
|
100
|
+
const missing = report.failures.filter(f => !f.diff && f.title);
|
|
101
|
+
if (missing.length === 0)
|
|
102
|
+
return;
|
|
103
|
+
const blocks = stripAnsi(consoleText).split(/^ ?FAIL\s+/m).slice(1);
|
|
104
|
+
for (const f of missing) {
|
|
105
|
+
const file = f.where?.split(':')[0]?.split('/').pop();
|
|
106
|
+
const block = blocks.find((b) => {
|
|
107
|
+
const header = b.slice(0, b.indexOf('\n'));
|
|
108
|
+
return header.endsWith(` > ${f.title}`) && (!file || header.includes(file));
|
|
109
|
+
});
|
|
110
|
+
if (!block)
|
|
111
|
+
continue;
|
|
112
|
+
const diff = splitFailureText(block.slice(block.indexOf('\n') + 1)).diff;
|
|
113
|
+
if (diff)
|
|
114
|
+
f.diff = diff;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
function attr(tag, name) {
|
|
118
|
+
const m = new RegExp(`\\s${name}="([^"]*)"`).exec(tag);
|
|
119
|
+
return m ? decodeXml(m[1]) : undefined;
|
|
120
|
+
}
|
|
121
|
+
function decodeXml(s) {
|
|
122
|
+
return s.replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"').replace(/'/g, '\'').replace(/ /g, '\n').replace(/&/g, '&');
|
|
123
|
+
}
|
|
124
|
+
/** A JUnit XML report (phpunit and pest --log-junit). */
|
|
125
|
+
export function parseJunitXml(text, cwd) {
|
|
126
|
+
if (!/<testsuites?\b/.test(text))
|
|
127
|
+
return null;
|
|
128
|
+
const failures = [];
|
|
129
|
+
let total = 0;
|
|
130
|
+
let skipped = 0;
|
|
131
|
+
const files = new Set();
|
|
132
|
+
const re = /<testcase\b([^>]*?)(?:\/>|>([\s\S]*?)<\/testcase>)/g;
|
|
133
|
+
let m;
|
|
134
|
+
while ((m = re.exec(text)) !== null) {
|
|
135
|
+
total++;
|
|
136
|
+
const tag = m[1];
|
|
137
|
+
const body = m[2] ?? '';
|
|
138
|
+
const file = attr(tag, 'file');
|
|
139
|
+
if (file)
|
|
140
|
+
files.add(file);
|
|
141
|
+
if (/<skipped\b/.test(body)) {
|
|
142
|
+
skipped++;
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
const fail = /<(failure|error)\b([^>]*?)(?:\/>|>([\s\S]*?)<\/\1>)/.exec(body);
|
|
146
|
+
if (!fail)
|
|
147
|
+
continue;
|
|
148
|
+
const raw = decodeXml(fail[3] ?? attr(fail[2], 'message') ?? '');
|
|
149
|
+
const line = attr(tag, 'line');
|
|
150
|
+
const where = file ? `${relPath(file, cwd)}${line ? `:${line}` : ''}` : undefined;
|
|
151
|
+
const cls = attr(tag, 'class') ?? attr(tag, 'classname');
|
|
152
|
+
const name = `${cls ? `${cls} > ` : ''}${attr(tag, 'name') ?? '(unnamed test)'}`;
|
|
153
|
+
failures.push({ name, where, ...splitFailureText(raw) });
|
|
154
|
+
}
|
|
155
|
+
return { passed: total - skipped - failures.length, failed: failures.length, skipped, files: files.size, failures, errors: [] };
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* The summary an agent reads: one status line, then each failure with where
|
|
159
|
+
* it is, why, and a short diff, within {@link TEST_SUMMARY_MAX_CHARS}; the
|
|
160
|
+
* failures that do not fit are named, and the rest counted.
|
|
161
|
+
*/
|
|
162
|
+
export function renderTestSummary(report, opts) {
|
|
163
|
+
const counts = `${report.failed} failed, ${report.passed} passed${report.skipped ? `, ${report.skipped} skipped` : ''} (${report.files} file(s), ${opts.seconds.toFixed(1)}s)`;
|
|
164
|
+
const ok = report.failed === 0 && report.errors.length === 0 && opts.exitCode === 0;
|
|
165
|
+
const nothingRan = report.failed + report.passed === 0 && report.errors.length === 0;
|
|
166
|
+
const status = ok && nothingRan ? 'NO TESTS RAN' : ok ? 'PASSED' : 'FAILED';
|
|
167
|
+
const head = `${status}: ${counts} [${opts.label}]`;
|
|
168
|
+
const tail = opts.fullOutputAt ? `\nFull output: ${opts.fullOutputAt}` : '';
|
|
169
|
+
const budget = TEST_SUMMARY_MAX_CHARS - head.length - tail.length - 120;
|
|
170
|
+
const blocks = [];
|
|
171
|
+
let used = 0;
|
|
172
|
+
const push = (text) => {
|
|
173
|
+
if (used + text.length + 1 > budget)
|
|
174
|
+
return false;
|
|
175
|
+
blocks.push(text);
|
|
176
|
+
used += text.length + 1;
|
|
177
|
+
return true;
|
|
178
|
+
};
|
|
179
|
+
for (const e of report.errors) {
|
|
180
|
+
if (!push(`ERROR ${e.length > MESSAGE_MAX_CHARS ? `${e.slice(0, MESSAGE_MAX_CHARS)}...` : e}`))
|
|
181
|
+
break;
|
|
182
|
+
}
|
|
183
|
+
let shown = 0;
|
|
184
|
+
for (const [i, f] of report.failures.entries()) {
|
|
185
|
+
const lines = [`${i + 1}) ${f.where ? `${f.where} ` : ''}${f.name}`];
|
|
186
|
+
if (f.message)
|
|
187
|
+
lines.push(` ${f.message}`);
|
|
188
|
+
if (f.diff)
|
|
189
|
+
lines.push(...f.diff.split('\n').map(l => ` ${l}`));
|
|
190
|
+
if (!push(lines.join('\n'))) {
|
|
191
|
+
// No room for the whole block: the name alone still says where to look.
|
|
192
|
+
if (!push(`${i + 1}) ${f.where ? `${f.where} ` : ''}${f.name}`))
|
|
193
|
+
break;
|
|
194
|
+
}
|
|
195
|
+
shown++;
|
|
196
|
+
}
|
|
197
|
+
const left = report.failures.length - shown;
|
|
198
|
+
const more = left > 0 ? `\n[... ${left} more failure(s) not shown: run them with a filter, or read the full output]` : '';
|
|
199
|
+
if (!ok && nothingRan && report.failures.length === 0 && report.errors.length === 0 && opts.exitCode !== 0) {
|
|
200
|
+
return `${head}\nThe run exited with code ${opts.exitCode} without a test result.${tail}`;
|
|
201
|
+
}
|
|
202
|
+
return `${head}${blocks.length ? `\n${blocks.join('\n')}` : ''}${more}${tail}`;
|
|
203
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { ToolContext } from './index.js';
|
|
2
|
+
/** The changed paths of the repo a command runs in, before or after it. */
|
|
3
|
+
export interface CheckoutSnapshot {
|
|
4
|
+
/** The repo's top level, canonical. */
|
|
5
|
+
top: string;
|
|
6
|
+
/** Where the top level sits in the checkout: `''` for the checkout itself. */
|
|
7
|
+
prefix: string;
|
|
8
|
+
/** Changed paths (from the top level) with a fingerprint each (size and mtime). */
|
|
9
|
+
dirty: Map<string, string>;
|
|
10
|
+
/** The command's time span, registered while it runs. */
|
|
11
|
+
span: CommandSpan;
|
|
12
|
+
}
|
|
13
|
+
/** When a command of which run ran: `end` null while it still runs. */
|
|
14
|
+
interface CommandSpan {
|
|
15
|
+
owner: string | null;
|
|
16
|
+
start: number;
|
|
17
|
+
end: number | null;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* The run a change falls to: the owner of the shortest span that holds `mtime`
|
|
21
|
+
* (for a deleted file, `mtime` null: that overlaps `mine`). Exported for tests.
|
|
22
|
+
*/
|
|
23
|
+
export declare function ownerOfChange(mtime: number | null, mine: CommandSpan, all: Iterable<CommandSpan>, now: number): string | null;
|
|
24
|
+
/**
|
|
25
|
+
* The paths of `git status --porcelain=v1 -z`, from the repo's top level. A
|
|
26
|
+
* rename or a copy names its new path; the old one follows as a field of its
|
|
27
|
+
* own, which is skipped. Exported for tests.
|
|
28
|
+
*/
|
|
29
|
+
export declare function parsePorcelainZ(stdout: string): string[];
|
|
30
|
+
/**
|
|
31
|
+
* The git status of the repo `cwd` is in, when the command runs in the
|
|
32
|
+
* project checkout (not the agent's home) and the runtime wants to know what
|
|
33
|
+
* it touched, with the command's span registered. Null otherwise, and on any
|
|
34
|
+
* failure.
|
|
35
|
+
*/
|
|
36
|
+
export declare function snapshotCheckout(cwd: string, context: ToolContext | undefined): Promise<CheckoutSnapshot | null>;
|
|
37
|
+
/**
|
|
38
|
+
* After the command: compare with `before` and hand the touched paths to the
|
|
39
|
+
* runtime (`context.touchedFiles`, keyed by the call's params), without the
|
|
40
|
+
* ones another live run claims or another run's command changed, and claim
|
|
41
|
+
* them for this run. Ends the command's span. Never throws.
|
|
42
|
+
*/
|
|
43
|
+
export declare function recordTouched(before: CheckoutSnapshot | null, cwd: string, params: Record<string, unknown>, context: ToolContext | undefined): Promise<void>;
|
|
44
|
+
export {};
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import { execFile } from 'node:child_process';
|
|
2
|
+
import { realpathSync, statSync } from 'node:fs';
|
|
3
|
+
import { isAbsolute, join, relative, resolve, sep } from 'node:path';
|
|
4
|
+
import { promisify } from 'node:util';
|
|
5
|
+
import { isInsideRoot, realpathSafe } from './_jail.js';
|
|
6
|
+
import { claimFile, claimedByOtherRun, liveClaimOwner, ownerOfContext } from '../runtime/file-claims.js';
|
|
7
|
+
// ─── Files a shell command touched ────────────
|
|
8
|
+
//
|
|
9
|
+
// A file `runner_run_command` creates or changes (codegen, a copy, a lockfile,
|
|
10
|
+
// `eslint --fix`) is the run's own, the same as a file it writes with
|
|
11
|
+
// runner_write_file (contract/own-files.ts). The command does not say which
|
|
12
|
+
// files it changed, so the repo's git status is read before and after it:
|
|
13
|
+
// every path that is newly changed, plus every path that was already changed
|
|
14
|
+
// and whose size or mtime moved, counts. A file another live run claims stays
|
|
15
|
+
// out (it changed it, not this command). Best effort: no git, a failing git or
|
|
16
|
+
// a checkout too dirty to compare gives nothing, and never fails the command.
|
|
17
|
+
//
|
|
18
|
+
// Several runs share one checkout, and their commands overlap: a typecheck of
|
|
19
|
+
// three minutes sees everything another run's script changed meanwhile. So
|
|
20
|
+
// every command keeps its time span (`spans`), and a changed file goes to the
|
|
21
|
+
// shortest span that holds its mtime (a deleted file: that overlaps this one):
|
|
22
|
+
// the 2-second script that wrote it, not the long command that only ran
|
|
23
|
+
// beside it. A file that falls to another run's command stays out. What a
|
|
24
|
+
// command keeps is claimed for its run (`claimFile`), so a command of another
|
|
25
|
+
// run that ends later leaves it out too, and a write to it is refused.
|
|
26
|
+
const execFileAsync = promisify(execFile);
|
|
27
|
+
/** Most paths one command reports: the rest is noise (a build into a folder git does not ignore). */
|
|
28
|
+
const TOUCHED_MAX = 200;
|
|
29
|
+
/** A repo with more changed paths than this is not compared at all. */
|
|
30
|
+
const SNAPSHOT_MAX = 5000;
|
|
31
|
+
const GIT_TIMEOUT_MS = 10_000;
|
|
32
|
+
/** The spans of the commands running now, and of the ended ones a running command overlaps. */
|
|
33
|
+
const spans = new Set();
|
|
34
|
+
/** Drop the ended spans no running command overlaps any more. */
|
|
35
|
+
function pruneSpans() {
|
|
36
|
+
let oldestRunning = Infinity;
|
|
37
|
+
for (const s of spans)
|
|
38
|
+
if (s.end == null)
|
|
39
|
+
oldestRunning = Math.min(oldestRunning, s.start);
|
|
40
|
+
for (const s of spans)
|
|
41
|
+
if (s.end != null && s.end < oldestRunning)
|
|
42
|
+
spans.delete(s);
|
|
43
|
+
}
|
|
44
|
+
/** The mtime of a fingerprint, null for a deleted file. */
|
|
45
|
+
function mtimeOf(print) {
|
|
46
|
+
const ms = Number(print.slice(print.indexOf(':') + 1));
|
|
47
|
+
return print === 'gone' || !Number.isFinite(ms) ? null : ms;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* The run a change falls to: the owner of the shortest span that holds `mtime`
|
|
51
|
+
* (for a deleted file, `mtime` null: that overlaps `mine`). Exported for tests.
|
|
52
|
+
*/
|
|
53
|
+
export function ownerOfChange(mtime, mine, all, now) {
|
|
54
|
+
let best = mine;
|
|
55
|
+
let bestLength = now - mine.start;
|
|
56
|
+
for (const s of all) {
|
|
57
|
+
if (s === mine)
|
|
58
|
+
continue;
|
|
59
|
+
const end = s.end ?? now;
|
|
60
|
+
const holds = mtime == null ? s.start <= now && end >= mine.start : s.start <= mtime && mtime <= end;
|
|
61
|
+
if (holds && end - s.start < bestLength) {
|
|
62
|
+
best = s;
|
|
63
|
+
bestLength = end - s.start;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return best.owner;
|
|
67
|
+
}
|
|
68
|
+
async function git(cwd, args) {
|
|
69
|
+
const { stdout } = await execFileAsync('git', args, { cwd, timeout: GIT_TIMEOUT_MS, maxBuffer: 20 * 1024 * 1024 });
|
|
70
|
+
return stdout;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* The paths of `git status --porcelain=v1 -z`, from the repo's top level. A
|
|
74
|
+
* rename or a copy names its new path; the old one follows as a field of its
|
|
75
|
+
* own, which is skipped. Exported for tests.
|
|
76
|
+
*/
|
|
77
|
+
export function parsePorcelainZ(stdout) {
|
|
78
|
+
const fields = stdout.split('\0');
|
|
79
|
+
const paths = [];
|
|
80
|
+
for (let i = 0; i < fields.length; i++) {
|
|
81
|
+
const field = fields[i] ?? '';
|
|
82
|
+
if (field.length < 4)
|
|
83
|
+
continue;
|
|
84
|
+
const xy = field.slice(0, 2);
|
|
85
|
+
paths.push(field.slice(3));
|
|
86
|
+
if (xy.includes('R') || xy.includes('C'))
|
|
87
|
+
i++;
|
|
88
|
+
}
|
|
89
|
+
return paths;
|
|
90
|
+
}
|
|
91
|
+
function fingerprint(abs) {
|
|
92
|
+
try {
|
|
93
|
+
const s = statSync(abs);
|
|
94
|
+
return `${s.size}:${s.mtimeMs}`;
|
|
95
|
+
}
|
|
96
|
+
catch {
|
|
97
|
+
return 'gone';
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
/** Where `top` sits in the checkout, or null when it lies outside it. */
|
|
101
|
+
function prefixInCheckout(projectRoot, top) {
|
|
102
|
+
const rel = relative(realpathSync(projectRoot), top);
|
|
103
|
+
if (rel === '..' || rel.startsWith(`..${sep}`) || isAbsolute(rel))
|
|
104
|
+
return null;
|
|
105
|
+
return rel.split(sep).join('/');
|
|
106
|
+
}
|
|
107
|
+
/** The changed paths of the repo `cwd` is in, inside the project checkout. Null otherwise, and on any failure. */
|
|
108
|
+
async function readStatus(cwd, context) {
|
|
109
|
+
try {
|
|
110
|
+
if (!context.projectRoot || !isInsideRoot(realpathSafe(resolve(cwd)), realpathSafe(resolve(context.projectRoot))))
|
|
111
|
+
return null;
|
|
112
|
+
const top = realpathSync((await git(cwd, ['rev-parse', '--show-toplevel'])).trim());
|
|
113
|
+
const prefix = prefixInCheckout(context.projectRoot, top);
|
|
114
|
+
if (prefix == null)
|
|
115
|
+
return null;
|
|
116
|
+
const paths = parsePorcelainZ(await git(top, ['status', '--porcelain=v1', '-z', '--untracked-files=all']));
|
|
117
|
+
if (paths.length > SNAPSHOT_MAX)
|
|
118
|
+
return null;
|
|
119
|
+
return { top, prefix, dirty: new Map(paths.map(p => [p, fingerprint(join(top, p))])) };
|
|
120
|
+
}
|
|
121
|
+
catch {
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* The git status of the repo `cwd` is in, when the command runs in the
|
|
127
|
+
* project checkout (not the agent's home) and the runtime wants to know what
|
|
128
|
+
* it touched, with the command's span registered. Null otherwise, and on any
|
|
129
|
+
* failure.
|
|
130
|
+
*/
|
|
131
|
+
export async function snapshotCheckout(cwd, context) {
|
|
132
|
+
if (!context?.touchedFiles || !context.projectRoot || context.projectRoot === context.agentHome)
|
|
133
|
+
return null;
|
|
134
|
+
const start = Date.now();
|
|
135
|
+
const status = await readStatus(cwd, context);
|
|
136
|
+
if (!status)
|
|
137
|
+
return null;
|
|
138
|
+
const span = { owner: ownerOfContext(context)?.owner ?? null, start, end: null };
|
|
139
|
+
spans.add(span);
|
|
140
|
+
return { ...status, span };
|
|
141
|
+
}
|
|
142
|
+
/** The paths that changed between two snapshots of one repo: new in `after`, or in both with another fingerprint. */
|
|
143
|
+
function touchedBetween(before, after) {
|
|
144
|
+
const touched = [];
|
|
145
|
+
for (const [rel, print] of after.dirty) {
|
|
146
|
+
if (before.dirty.get(rel) === print)
|
|
147
|
+
continue;
|
|
148
|
+
touched.push({ path: after.prefix ? `${after.prefix}/${rel}` : rel, abs: realpathSafe(join(after.top, rel)), print });
|
|
149
|
+
}
|
|
150
|
+
return touched;
|
|
151
|
+
}
|
|
152
|
+
/** Whether a touched path is this command's: claimed by its run, or falling to its span. */
|
|
153
|
+
function isOwnChange(file, mine, context, now) {
|
|
154
|
+
if (claimedByOtherRun(file.abs, context))
|
|
155
|
+
return false;
|
|
156
|
+
if (mine.owner != null && liveClaimOwner(file.abs) === mine.owner)
|
|
157
|
+
return true;
|
|
158
|
+
return ownerOfChange(mtimeOf(file.print), mine, spans, now) === mine.owner;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* After the command: compare with `before` and hand the touched paths to the
|
|
162
|
+
* runtime (`context.touchedFiles`, keyed by the call's params), without the
|
|
163
|
+
* ones another live run claims or another run's command changed, and claim
|
|
164
|
+
* them for this run. Ends the command's span. Never throws.
|
|
165
|
+
*/
|
|
166
|
+
export async function recordTouched(before, cwd, params, context) {
|
|
167
|
+
if (!before)
|
|
168
|
+
return;
|
|
169
|
+
try {
|
|
170
|
+
if (!context?.touchedFiles)
|
|
171
|
+
return;
|
|
172
|
+
const after = await readStatus(cwd, context);
|
|
173
|
+
if (!after || after.top !== before.top)
|
|
174
|
+
return;
|
|
175
|
+
const now = Date.now();
|
|
176
|
+
const kept = [];
|
|
177
|
+
for (const file of touchedBetween(before, after)) {
|
|
178
|
+
if (!isOwnChange(file, before.span, context, now))
|
|
179
|
+
continue;
|
|
180
|
+
kept.push(file.path);
|
|
181
|
+
claimFile(file.abs, context);
|
|
182
|
+
if (kept.length >= TOUCHED_MAX)
|
|
183
|
+
break;
|
|
184
|
+
}
|
|
185
|
+
if (kept.length)
|
|
186
|
+
context.touchedFiles.set(params, kept);
|
|
187
|
+
}
|
|
188
|
+
catch {
|
|
189
|
+
// What a command touched is a hint; the command's own result stands.
|
|
190
|
+
}
|
|
191
|
+
finally {
|
|
192
|
+
before.span.end = Date.now();
|
|
193
|
+
pruneSpans();
|
|
194
|
+
}
|
|
195
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { ToolContext } from './index.js';
|
|
2
|
+
/** Uploadable extensions, for building model-readable error messages. */
|
|
3
|
+
export declare const UPLOADABLE_EXTENSIONS: string[];
|
|
4
|
+
/** Resolve a filename's mime type, or null when the extension isn't uploadable. */
|
|
5
|
+
export declare function mimeFromFilename(filename: string): string | null;
|
|
6
|
+
/**
|
|
7
|
+
* Thin wrapper kept for the image/capture tools: derive an image mime from the
|
|
8
|
+
* extension (defaulting to jpeg) and delegate to {@link uploadFile}.
|
|
9
|
+
*/
|
|
10
|
+
export declare function uploadImage(imageData: Buffer, filename: string, folder: string, context: ToolContext,
|
|
11
|
+
/** Optional project file-manager folder NAME the agent picked. Forwarded
|
|
12
|
+
* as `projectFolderName`; the studio find-or-creates it. Omit to land the
|
|
13
|
+
* file at the project root (no folder). */
|
|
14
|
+
projectFolder?: string): Promise<string>;
|
|
15
|
+
/**
|
|
16
|
+
* POST a buffer to the studio's `/api/agents/upload` endpoint with the agent's
|
|
17
|
+
* Bearer token. When `context.projectSlug` is set the file lands as a permanent
|
|
18
|
+
* project file (in the `projectFolder` file-manager folder, or the project root
|
|
19
|
+
* when omitted); otherwise it is org-scoped only. Returns a JSON string with
|
|
20
|
+
* `uid` + `referenceUrl` on success, or an `Error: ...` string.
|
|
21
|
+
*/
|
|
22
|
+
export declare function uploadFile(data: Buffer, filename: string, mimeType: string, folder: string, context: ToolContext,
|
|
23
|
+
/** Optional project file-manager folder NAME the agent picked. Forwarded
|
|
24
|
+
* as `projectFolderName`; the studio find-or-creates it. Omit to land the
|
|
25
|
+
* file at the project root (no folder). */
|
|
26
|
+
projectFolder?: string): Promise<string>;
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extensions the studio's `/api/agents/upload` endpoint accepts, mapped to the
|
|
3
|
+
* mime type it expects. Kept in lockstep with the server ALLOWED_TYPES list -
|
|
4
|
+
* an unknown extension can't be uploaded, so callers should reject early with a
|
|
5
|
+
* clear message rather than send an octet-stream the server will 400.
|
|
6
|
+
*/
|
|
7
|
+
const MIME_BY_EXTENSION = {
|
|
8
|
+
// images
|
|
9
|
+
jpg: 'image/jpeg', jpeg: 'image/jpeg', png: 'image/png', webp: 'image/webp',
|
|
10
|
+
gif: 'image/gif', svg: 'image/svg+xml',
|
|
11
|
+
// documents
|
|
12
|
+
pdf: 'application/pdf',
|
|
13
|
+
txt: 'text/plain', csv: 'text/csv', md: 'text/markdown',
|
|
14
|
+
json: 'application/json',
|
|
15
|
+
doc: 'application/msword',
|
|
16
|
+
docx: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
|
17
|
+
xls: 'application/vnd.ms-excel',
|
|
18
|
+
xlsx: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
|
19
|
+
};
|
|
20
|
+
/** Uploadable extensions, for building model-readable error messages. */
|
|
21
|
+
export const UPLOADABLE_EXTENSIONS = Object.keys(MIME_BY_EXTENSION);
|
|
22
|
+
/** Resolve a filename's mime type, or null when the extension isn't uploadable. */
|
|
23
|
+
export function mimeFromFilename(filename) {
|
|
24
|
+
const ext = filename.toLowerCase().split('.').pop() ?? '';
|
|
25
|
+
return MIME_BY_EXTENSION[ext] ?? null;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Thin wrapper kept for the image/capture tools: derive an image mime from the
|
|
29
|
+
* extension (defaulting to jpeg) and delegate to {@link uploadFile}.
|
|
30
|
+
*/
|
|
31
|
+
export async function uploadImage(imageData, filename, folder, context,
|
|
32
|
+
/** Optional project file-manager folder NAME the agent picked. Forwarded
|
|
33
|
+
* as `projectFolderName`; the studio find-or-creates it. Omit to land the
|
|
34
|
+
* file at the project root (no folder). */
|
|
35
|
+
projectFolder) {
|
|
36
|
+
const ext = filename.toLowerCase().split('.').pop() ?? '';
|
|
37
|
+
const mimeType = ext === 'png' ? 'image/png' :
|
|
38
|
+
ext === 'webp' ? 'image/webp' :
|
|
39
|
+
ext === 'gif' ? 'image/gif' :
|
|
40
|
+
ext === 'svg' ? 'image/svg+xml' :
|
|
41
|
+
'image/jpeg';
|
|
42
|
+
return uploadFile(imageData, filename, mimeType, folder, context, projectFolder);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* POST a buffer to the studio's `/api/agents/upload` endpoint with the agent's
|
|
46
|
+
* Bearer token. When `context.projectSlug` is set the file lands as a permanent
|
|
47
|
+
* project file (in the `projectFolder` file-manager folder, or the project root
|
|
48
|
+
* when omitted); otherwise it is org-scoped only. Returns a JSON string with
|
|
49
|
+
* `uid` + `referenceUrl` on success, or an `Error: ...` string.
|
|
50
|
+
*/
|
|
51
|
+
export async function uploadFile(data, filename, mimeType, folder, context,
|
|
52
|
+
/** Optional project file-manager folder NAME the agent picked. Forwarded
|
|
53
|
+
* as `projectFolderName`; the studio find-or-creates it. Omit to land the
|
|
54
|
+
* file at the project root (no folder). */
|
|
55
|
+
projectFolder) {
|
|
56
|
+
if (!context.studioUrl || !context.agentToken) {
|
|
57
|
+
return 'Error: Upload configuration not available.';
|
|
58
|
+
}
|
|
59
|
+
if (data.length === 0) {
|
|
60
|
+
return 'Error: File data is empty.';
|
|
61
|
+
}
|
|
62
|
+
const boundary = `----NordhavnUpload${Date.now()}`;
|
|
63
|
+
const crlf = '\r\n';
|
|
64
|
+
const header = `--${boundary}${crlf}Content-Disposition: form-data; name="file"; filename="${filename}"${crlf}Content-Type: ${mimeType}${crlf}${crlf}`;
|
|
65
|
+
const folderPart = `${crlf}--${boundary}${crlf}Content-Disposition: form-data; name="folder"${crlf}${crlf}${folder}`;
|
|
66
|
+
// Project pin: when the dispatch tells us which project the agent is currently
|
|
67
|
+
// working in, forward the slug so the studio attaches the resulting File row
|
|
68
|
+
// to that project's file manager. Without it the file is org-scoped only.
|
|
69
|
+
// Field name mirrors what the studio's /api/agents/upload reads.
|
|
70
|
+
const projectSlug = context.projectSlug;
|
|
71
|
+
const projectPart = projectSlug
|
|
72
|
+
? `${crlf}--${boundary}${crlf}Content-Disposition: form-data; name="projectSlug"${crlf}${crlf}${projectSlug}`
|
|
73
|
+
: '';
|
|
74
|
+
// Folder pin: the agent explicitly chose a file-manager folder by name. The
|
|
75
|
+
// studio find-or-creates it; omitted means the project root.
|
|
76
|
+
const folderName = projectFolder?.trim();
|
|
77
|
+
const folderNamePart = folderName
|
|
78
|
+
? `${crlf}--${boundary}${crlf}Content-Disposition: form-data; name="projectFolderName"${crlf}${crlf}${folderName}`
|
|
79
|
+
: '';
|
|
80
|
+
const footer = `${crlf}--${boundary}--${crlf}`;
|
|
81
|
+
const body = Buffer.concat([
|
|
82
|
+
Buffer.from(header),
|
|
83
|
+
data,
|
|
84
|
+
Buffer.from(folderPart),
|
|
85
|
+
...(projectPart ? [Buffer.from(projectPart)] : []),
|
|
86
|
+
...(folderNamePart ? [Buffer.from(folderNamePart)] : []),
|
|
87
|
+
Buffer.from(footer),
|
|
88
|
+
]);
|
|
89
|
+
try {
|
|
90
|
+
const controller = new AbortController();
|
|
91
|
+
const timeout = setTimeout(() => controller.abort(), 30000);
|
|
92
|
+
const res = await fetch(`${context.studioUrl}/api/agents/upload`, {
|
|
93
|
+
method: 'POST',
|
|
94
|
+
headers: {
|
|
95
|
+
'Authorization': `Bearer ${context.agentToken}`,
|
|
96
|
+
'Content-Type': `multipart/form-data; boundary=${boundary}`,
|
|
97
|
+
},
|
|
98
|
+
body,
|
|
99
|
+
signal: controller.signal,
|
|
100
|
+
});
|
|
101
|
+
clearTimeout(timeout);
|
|
102
|
+
if (!res.ok) {
|
|
103
|
+
const err = await res.text();
|
|
104
|
+
return `Error: Upload failed (${res.status}): ${err}`;
|
|
105
|
+
}
|
|
106
|
+
const result = await res.json();
|
|
107
|
+
if (context.attachments) {
|
|
108
|
+
context.attachments.push({
|
|
109
|
+
url: result.url,
|
|
110
|
+
name: result.name,
|
|
111
|
+
type: result.mimeType,
|
|
112
|
+
size: result.size,
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
return JSON.stringify({
|
|
116
|
+
success: true,
|
|
117
|
+
uid: result.uid,
|
|
118
|
+
url: result.url,
|
|
119
|
+
// Canonical reference to embed in document/record markdown. Always use
|
|
120
|
+
// this over the raw CDN `url` (raw url = flagged unused + GC'd).
|
|
121
|
+
referenceUrl: `/api/files/${result.uid}`,
|
|
122
|
+
name: result.name,
|
|
123
|
+
size: result.size,
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
catch (err) {
|
|
127
|
+
if (err.name === 'AbortError') {
|
|
128
|
+
return `Error: Upload timed out (30s) to ${context.studioUrl}`;
|
|
129
|
+
}
|
|
130
|
+
return `Error: Upload failed - could not reach ${context.studioUrl}: ${err.message}`;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { ToolContext } from './index.js';
|
|
2
|
+
export interface WorktreeHookResult {
|
|
3
|
+
/** The command that ran, e.g. `npm run --silent worktree:setup`. */
|
|
4
|
+
command: string;
|
|
5
|
+
ok: boolean;
|
|
6
|
+
exitCode: number | null;
|
|
7
|
+
seconds: number;
|
|
8
|
+
output: string;
|
|
9
|
+
}
|
|
10
|
+
export interface WorktreeSetupResult {
|
|
11
|
+
/** False when the hook failed (linking and copying never fail the setup). */
|
|
12
|
+
ok: boolean;
|
|
13
|
+
/** Dependency folders linked from the main checkout, relative to the worktree. */
|
|
14
|
+
linked: string[];
|
|
15
|
+
/** Env files copied from the main checkout, relative to the worktree. */
|
|
16
|
+
copied: string[];
|
|
17
|
+
hook?: WorktreeHookResult;
|
|
18
|
+
/** Set when the project pins a Node the runner could not get: the hook ran on the runner's. */
|
|
19
|
+
nodeWarning?: string;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Make a new worktree of `repo` ready to work in (see above). Resolves null
|
|
23
|
+
* when there was nothing to do: no dependency folder, no env file, no hook.
|
|
24
|
+
*/
|
|
25
|
+
export declare function runWorktreeSetup(repo: string, worktree: string, context?: ToolContext): Promise<WorktreeSetupResult | null>;
|
|
26
|
+
/** The project's own setup hook, from the worktree's (the branch's) manifests. */
|
|
27
|
+
export declare function setupHookCommand(worktree: string): string | null;
|
|
28
|
+
/** The npm workspace folders of a checkout (`workspaces` as a list or `{ packages }`), `*` segments expanded. */
|
|
29
|
+
export declare function workspaceDirs(root: string): string[];
|