@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,506 @@
|
|
|
1
|
+
import { readFileSync, writeFileSync, appendFileSync, readdirSync, statSync, existsSync, mkdirSync } from 'node:fs';
|
|
2
|
+
import { resolve, dirname, relative, extname } from 'node:path';
|
|
3
|
+
import { resolveInJail, resolveForRead, jailRoots, readOnlyRoots, isInsideRoot, realpathSafe, writeScopeRel } from './_jail.js';
|
|
4
|
+
import { clipLine, READ_OUTPUT_MAX_CHARS } from './_output.js';
|
|
5
|
+
import { readSymbol } from './outline.js';
|
|
6
|
+
import { toNum, toObject } from './_coerce.js';
|
|
7
|
+
import { claimedReadNote, claimFile, refuseClaimedWrite } from '../runtime/file-claims.js';
|
|
8
|
+
import { firstInRun, READ_OUTLINE_HEAD_LINES, sonarEditHint, sonarListHint, sonarRangeHint, sonarReadView, withHint } from './_sonar/hints.js';
|
|
9
|
+
import { diagnoseAfterWrite } from './_sonar/diagnose/index.js';
|
|
10
|
+
// ─── Filesystem Tools ───────────────────────
|
|
11
|
+
//
|
|
12
|
+
// Direct file operations without shell escaping. Paths are always jailed to the
|
|
13
|
+
// project root plus the agent's home (see _jail.ts) - there is no unrestricted
|
|
14
|
+
// escape hatch.
|
|
15
|
+
/** True for a file of the project checkout (not the agent's home or scratch):
|
|
16
|
+
* the only place several runs share files, so the only place claims hold. */
|
|
17
|
+
function inSharedCheckout(resolved, ctx) {
|
|
18
|
+
if (!ctx?.projectRoot || ctx.projectRoot === ctx.agentHome)
|
|
19
|
+
return false;
|
|
20
|
+
return isInsideRoot(resolved, realpathSafe(resolve(ctx.projectRoot)));
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Coerce a tool parameter that is supposed to be a string into a string.
|
|
24
|
+
*
|
|
25
|
+
* Models often pass the parsed JSON value directly when the file is JSON
|
|
26
|
+
* (e.g. `content: { plugins: {...} }` instead of `content: "{...}"`). The
|
|
27
|
+
* underlying `fs.writeFileSync` then throws a cryptic Node-level error
|
|
28
|
+
* ("data argument must be of type string"), which the model can't act on
|
|
29
|
+
* and tends to retry verbatim. Auto-stringify objects/arrays here so the
|
|
30
|
+
* call succeeds, and emit a clear actionable error for anything else
|
|
31
|
+
* (numbers, booleans, null) so the model knows exactly what to fix.
|
|
32
|
+
*
|
|
33
|
+
* Returns either the coerced string OR an Error-string ready to return
|
|
34
|
+
* straight to the model.
|
|
35
|
+
*/
|
|
36
|
+
function coerceToString(value, paramName) {
|
|
37
|
+
if (typeof value === 'string')
|
|
38
|
+
return { value };
|
|
39
|
+
if (value === null || value === undefined) {
|
|
40
|
+
return { error: `Error: '${paramName}' is required and must be a string.` };
|
|
41
|
+
}
|
|
42
|
+
if (Array.isArray(value) || (typeof value === 'object')) {
|
|
43
|
+
// Auto-stringify - this is almost always what the model meant when
|
|
44
|
+
// writing JSON config files. Pretty-print so the file is human-readable.
|
|
45
|
+
try {
|
|
46
|
+
return { value: JSON.stringify(value, null, 2) + '\n' };
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
return { error: `Error: '${paramName}' must be a string. Received an object that could not be serialised - pre-stringify it with JSON.stringify before calling this tool.` };
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
// number, boolean - coerce, but tell the model so it stops doing this
|
|
53
|
+
return { error: `Error: '${paramName}' must be a string but received a ${typeof value}. Pass file content as a string (use JSON.stringify for objects/arrays).` };
|
|
54
|
+
}
|
|
55
|
+
// ─── runner_read_file ──────────────────────────
|
|
56
|
+
const readFileDefinition = {
|
|
57
|
+
name: 'runner_read_file',
|
|
58
|
+
description: 'Read a text file, with line numbers. Returns at most ~20k chars per call: for a big file, read one function or class by name with `symbol` (runner_sonar file or runner_outline lists them), or find the lines with runner_grep and read that range with offset/limit. The first whole read of a big file the code index knows returns its outline; call again for the text. Never read a file you already have in this conversation again unless it changed.',
|
|
59
|
+
parameters: {
|
|
60
|
+
type: 'object',
|
|
61
|
+
properties: {
|
|
62
|
+
path: { type: 'string', description: 'File path. Relative paths resolve against the project root. Absolute paths must stay within the project root or the agent home.' },
|
|
63
|
+
symbol: { type: 'string', description: 'Read only this function, class, method or type (a heading in Markdown), with its doc comment: "saveTask", or "TaskStore.save" for a method. Instead of offset/limit.' },
|
|
64
|
+
offset: { type: 'number', description: 'Line to start at, 0-based (line number N in the output is offset N-1). Default: 0.' },
|
|
65
|
+
limit: { type: 'number', description: 'Max lines to return. Default: as many as fit in ~20k chars.' },
|
|
66
|
+
},
|
|
67
|
+
required: ['path'],
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
/** The JSON result of runner_write_file; a recovered (truncated) write tells the model to continue. */
|
|
71
|
+
function writeResult(path, resolved, action, recovered) {
|
|
72
|
+
const lineCount = readFileSync(resolved, 'utf-8').split('\n').length;
|
|
73
|
+
const result = { success: true, path, action, size: statSync(resolved).size, lines: lineCount };
|
|
74
|
+
if (recovered) {
|
|
75
|
+
result.partial = true;
|
|
76
|
+
result.hint = `This file was partially written (your output was truncated at ${lineCount} lines). The file content is INCOMPLETE. You MUST continue writing the rest of the file by calling runner_write_file again with append=true. Pick up exactly where the content was cut off.`;
|
|
77
|
+
}
|
|
78
|
+
return result;
|
|
79
|
+
}
|
|
80
|
+
/** A write's output with its lint report (the new problems) below it. */
|
|
81
|
+
function withDiagnostics(output, report) {
|
|
82
|
+
return report ? `${output}\n${report}` : output;
|
|
83
|
+
}
|
|
84
|
+
async function executeReadFile(params, context) {
|
|
85
|
+
const path = params.path;
|
|
86
|
+
const offset = typeof params.offset === 'number' && params.offset > 0 ? Math.floor(params.offset) : 0;
|
|
87
|
+
const limit = typeof params.limit === 'number' && params.limit > 0 ? Math.floor(params.limit) : undefined;
|
|
88
|
+
if (!path)
|
|
89
|
+
return 'Error: path is required';
|
|
90
|
+
try {
|
|
91
|
+
const resolved = resolveForRead(path, context);
|
|
92
|
+
if (!existsSync(resolved)) {
|
|
93
|
+
return `Error: File not found: ${path}`;
|
|
94
|
+
}
|
|
95
|
+
const stat = statSync(resolved);
|
|
96
|
+
if (stat.isDirectory()) {
|
|
97
|
+
return `Error: "${path}" is a directory, not a file. Use runner_list_directory or runner_glob instead.`;
|
|
98
|
+
}
|
|
99
|
+
// Reject binary files
|
|
100
|
+
const binaryExts = ['.png', '.jpg', '.jpeg', '.gif', '.webp', '.ico', '.bmp', '.mp3', '.mp4', '.mov', '.avi', '.zip', '.tar', '.gz', '.pdf', '.woff', '.woff2', '.ttf', '.otf', '.eot'];
|
|
101
|
+
if (binaryExts.includes(extname(resolved).toLowerCase())) {
|
|
102
|
+
return `Error: "${path}" appears to be a binary file (${extname(resolved)}). Cannot read binary files as text.`;
|
|
103
|
+
}
|
|
104
|
+
const content = readFileSync(resolved, 'utf-8');
|
|
105
|
+
const note = claimNote(resolved, path, context);
|
|
106
|
+
if (typeof params.symbol === 'string' && params.symbol.trim()) {
|
|
107
|
+
return withHint(note, readSymbol(path, content, params.symbol, (from, count) => renderFileSlice(path, content, from, count)));
|
|
108
|
+
}
|
|
109
|
+
if (offset === 0 && limit === undefined)
|
|
110
|
+
return withHint(note, renderWholeRead(path, resolved, content, context));
|
|
111
|
+
// A range read of a big code file: which symbols it holds, so the next read can be by symbol.
|
|
112
|
+
const to = limit === undefined ? Number.MAX_SAFE_INTEGER : offset + limit;
|
|
113
|
+
return withHint(note, withHint(sonarRangeHint(resolved, offset + 1, to, context), renderFileSlice(path, content, offset, limit)));
|
|
114
|
+
}
|
|
115
|
+
catch (err) {
|
|
116
|
+
return `Error: ${err.message}`;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Another live run is changing the file this read shows: said once per run,
|
|
121
|
+
* file and claim (a later owner says it again), only in the shared checkout.
|
|
122
|
+
*/
|
|
123
|
+
function claimNote(resolved, path, context) {
|
|
124
|
+
if (!inSharedCheckout(resolved, context))
|
|
125
|
+
return null;
|
|
126
|
+
const note = claimedReadNote(resolved, path, context);
|
|
127
|
+
return note && firstInRun(context, `claim-read\0${resolved}\0${note}`) ? note : null;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* A read from the top without a limit: the first one of a big code file the
|
|
131
|
+
* index knows is its outline and first lines (sonarReadView), any other the
|
|
132
|
+
* file, under sonar's hint line when it has one.
|
|
133
|
+
*/
|
|
134
|
+
function renderWholeRead(path, resolved, content, context) {
|
|
135
|
+
const sonar = sonarReadView(resolved, context);
|
|
136
|
+
if (sonar?.outline)
|
|
137
|
+
return `${sonar.text}\n${renderFileSlice(path, content, 0, READ_OUTLINE_HEAD_LINES)}`;
|
|
138
|
+
return withHint(sonar?.text ?? null, renderFileSlice(path, content, 0));
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* The model-facing view of a file: a one-line header, then `cat -n` style
|
|
142
|
+
* numbered lines, cut on a line boundary with the exact offset to resume from.
|
|
143
|
+
* The WHOLE result (header and footer included) stays within
|
|
144
|
+
* {@link READ_OUTPUT_MAX_CHARS}, which is at most the loop's cap for a result
|
|
145
|
+
* it cannot point back to: a file read pages here and is never cut through
|
|
146
|
+
* the middle of the code by the loop. Plain text rather than JSON, because JSON
|
|
147
|
+
* escapes every newline and quote of the source and the model pays for each.
|
|
148
|
+
* Line numbers are what let the agent come back for lines 120-180 instead of
|
|
149
|
+
* the whole file. Exported for tests.
|
|
150
|
+
*/
|
|
151
|
+
export function renderFileSlice(path, content, offset, limit) {
|
|
152
|
+
const lines = content.split('\n');
|
|
153
|
+
if (lines.length > 1 && lines[lines.length - 1] === '')
|
|
154
|
+
lines.pop();
|
|
155
|
+
const totalLines = lines.length;
|
|
156
|
+
const start = Math.min(offset, totalLines);
|
|
157
|
+
const end = limit ? Math.min(start + limit, totalLines) : totalLines;
|
|
158
|
+
const width = String(end).length;
|
|
159
|
+
// Room for the longest header and footer this file can get, so the lines
|
|
160
|
+
// fill the budget and the result as a whole still fits it.
|
|
161
|
+
const room = `${path} (lines ${totalLines}-${totalLines} of ${totalLines})\n`.length + readFooter(totalLines, totalLines).length;
|
|
162
|
+
const budget = READ_OUTPUT_MAX_CHARS - room;
|
|
163
|
+
const out = [];
|
|
164
|
+
let used = 0;
|
|
165
|
+
let shownEnd = start;
|
|
166
|
+
for (let i = start; i < end; i++) {
|
|
167
|
+
const line = `${String(i + 1).padStart(width)}\t${clipLine(lines[i])}`;
|
|
168
|
+
if (used + line.length + 1 > budget && out.length > 0)
|
|
169
|
+
break;
|
|
170
|
+
out.push(line);
|
|
171
|
+
used += line.length + 1;
|
|
172
|
+
shownEnd = i + 1;
|
|
173
|
+
}
|
|
174
|
+
const whole = start === 0 && shownEnd === totalLines;
|
|
175
|
+
const header = whole
|
|
176
|
+
? `${path} (${totalLines} lines)`
|
|
177
|
+
: `${path} (lines ${start + 1}-${shownEnd} of ${totalLines})`;
|
|
178
|
+
if (totalLines === 0 || start >= totalLines)
|
|
179
|
+
return `${header}\n(no lines in this range)`;
|
|
180
|
+
const footer = shownEnd < end ? readFooter(totalLines - shownEnd, shownEnd) : '';
|
|
181
|
+
return `${header}\n${out.join('\n')}${footer}`;
|
|
182
|
+
}
|
|
183
|
+
function readFooter(remaining, resumeAt) {
|
|
184
|
+
return `\n[... cut at ${READ_OUTPUT_MAX_CHARS} chars: this is NOT the rest of the file. ${remaining} line(s) remain. Read on with offset=${resumeAt} and a limit, or runner_grep for what you need.]`;
|
|
185
|
+
}
|
|
186
|
+
// ─── runner_write_file ─────────────────────────
|
|
187
|
+
const writeFileDefinition = {
|
|
188
|
+
name: 'runner_write_file',
|
|
189
|
+
description: 'Write content to a file. Creates parent dirs if needed. Overwrites by default. Use append=true for large files written in chunks.',
|
|
190
|
+
parameters: {
|
|
191
|
+
type: 'object',
|
|
192
|
+
properties: {
|
|
193
|
+
path: { type: 'string', description: 'File path. Relative paths resolve against the project root. Absolute paths must stay within the project root or the agent home.' },
|
|
194
|
+
content: { type: 'string', description: 'Content to write.' },
|
|
195
|
+
append: { type: 'boolean', description: 'If true, append instead of overwrite. Default: false.' },
|
|
196
|
+
},
|
|
197
|
+
required: ['path', 'content'],
|
|
198
|
+
},
|
|
199
|
+
};
|
|
200
|
+
async function executeWriteFile(params, context) {
|
|
201
|
+
const path = params.path;
|
|
202
|
+
const append = params.append === true;
|
|
203
|
+
const recovered = params._recovered === true;
|
|
204
|
+
if (!path)
|
|
205
|
+
return 'Error: path is required';
|
|
206
|
+
if (params.content === undefined || params.content === null)
|
|
207
|
+
return 'Error: content is required';
|
|
208
|
+
const coerced = coerceToString(params.content, 'content');
|
|
209
|
+
if ('error' in coerced)
|
|
210
|
+
return coerced.error;
|
|
211
|
+
const content = coerced.value;
|
|
212
|
+
try {
|
|
213
|
+
const resolved = resolveInJail(path, context);
|
|
214
|
+
const shared = inSharedCheckout(resolved, context);
|
|
215
|
+
const refused = shared ? refuseClaimedWrite(resolved, path, context) : null;
|
|
216
|
+
if (refused)
|
|
217
|
+
return refused;
|
|
218
|
+
// Create parent directories if needed
|
|
219
|
+
const dir = dirname(resolved);
|
|
220
|
+
if (!existsSync(dir)) {
|
|
221
|
+
mkdirSync(dir, { recursive: true });
|
|
222
|
+
}
|
|
223
|
+
const existed = existsSync(resolved);
|
|
224
|
+
if (append && existed) {
|
|
225
|
+
appendFileSync(resolved, content, 'utf-8');
|
|
226
|
+
}
|
|
227
|
+
else {
|
|
228
|
+
writeFileSync(resolved, content, 'utf-8');
|
|
229
|
+
}
|
|
230
|
+
if (shared)
|
|
231
|
+
claimFile(resolved, context);
|
|
232
|
+
const result = writeResult(path, resolved, append ? 'appended' : (existed ? 'overwritten' : 'created'), recovered);
|
|
233
|
+
// A partial write is not worth linting: the rest is still coming.
|
|
234
|
+
const lint = recovered ? null : await diagnoseAfterWrite(resolved, context);
|
|
235
|
+
return withDiagnostics(withHint(sonarEditHint(resolved, context), JSON.stringify(result)), lint);
|
|
236
|
+
}
|
|
237
|
+
catch (err) {
|
|
238
|
+
return `Error: ${err.message}`;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
// ─── runner_edit_file ──────────────────────────
|
|
242
|
+
const EDIT_ITEM_SCHEMA = {
|
|
243
|
+
type: 'object',
|
|
244
|
+
properties: {
|
|
245
|
+
old_text: { type: 'string', description: 'Exact text to replace. Must match once.' },
|
|
246
|
+
new_text: { type: 'string', description: 'Replacement text, or the text to insert.' },
|
|
247
|
+
insert_at: { type: 'number', description: 'Line number (0-based) to insert new_text at, instead of old_text.' },
|
|
248
|
+
},
|
|
249
|
+
required: ['new_text'],
|
|
250
|
+
};
|
|
251
|
+
const editFileDefinition = {
|
|
252
|
+
name: 'runner_edit_file',
|
|
253
|
+
description: 'Edit a file by replacing exact text (old_text -> new_text) or inserting at a line number (insert_at + new_text). Several changes to one file go in ONE call with `edits`: applied in order, all or none. old_text must match exactly once.',
|
|
254
|
+
parameters: {
|
|
255
|
+
type: 'object',
|
|
256
|
+
properties: {
|
|
257
|
+
path: { type: 'string', description: 'File path. Relative paths resolve against the project root. Absolute paths must stay within the project root or the agent home.' },
|
|
258
|
+
old_text: { type: 'string', description: 'Exact text to find and replace. Must match once. Include 3+ lines context.' },
|
|
259
|
+
new_text: { type: 'string', description: 'Replacement text or text to insert.' },
|
|
260
|
+
insert_at: { type: 'number', description: 'Line number (0-based) to insert new_text at. Use instead of old_text.' },
|
|
261
|
+
edits: { type: 'array', items: EDIT_ITEM_SCHEMA, description: 'Several edits to this file in one call, instead of old_text/new_text/insert_at. Each applies to the result of the one before; when one fails nothing is written.' },
|
|
262
|
+
},
|
|
263
|
+
required: ['path'],
|
|
264
|
+
},
|
|
265
|
+
};
|
|
266
|
+
/** Read one edit out of tool args (the call itself, or an item of `edits`). */
|
|
267
|
+
function parseEdit(raw, label) {
|
|
268
|
+
const insertAt = toNum(raw.insert_at);
|
|
269
|
+
const hasOld = raw.old_text !== undefined && raw.old_text !== null && raw.old_text !== '';
|
|
270
|
+
if (raw.new_text === undefined || raw.new_text === null)
|
|
271
|
+
return `Error: ${label}new_text is required.`;
|
|
272
|
+
if (!hasOld && insertAt === undefined)
|
|
273
|
+
return `Error: ${label}provide either old_text (for replacement) or insert_at (for insertion).`;
|
|
274
|
+
if (hasOld && insertAt !== undefined)
|
|
275
|
+
return `Error: ${label}provide old_text OR insert_at, not both.`;
|
|
276
|
+
const coercedNew = coerceToString(raw.new_text, 'new_text');
|
|
277
|
+
if ('error' in coercedNew)
|
|
278
|
+
return `${coercedNew.error}${label ? ` (${label.replace(/: $/, '')})` : ''}`;
|
|
279
|
+
if (!hasOld)
|
|
280
|
+
return { newText: coercedNew.value, insertAt };
|
|
281
|
+
const coercedOld = coerceToString(raw.old_text, 'old_text');
|
|
282
|
+
if ('error' in coercedOld)
|
|
283
|
+
return `${coercedOld.error}${label ? ` (${label.replace(/: $/, '')})` : ''}`;
|
|
284
|
+
return { oldText: coercedOld.value, newText: coercedNew.value };
|
|
285
|
+
}
|
|
286
|
+
/** The edits a call asks for: `edits`, or the single-edit form as a list of one. */
|
|
287
|
+
function parseEdits(params) {
|
|
288
|
+
let list = params.edits;
|
|
289
|
+
if (typeof list === 'string') {
|
|
290
|
+
try {
|
|
291
|
+
list = JSON.parse(list);
|
|
292
|
+
}
|
|
293
|
+
catch {
|
|
294
|
+
return 'Error: edits must be an array of { old_text, new_text } objects.';
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
if (list === undefined || list === null) {
|
|
298
|
+
const one = parseEdit(params, '');
|
|
299
|
+
return typeof one === 'string' ? one : [one];
|
|
300
|
+
}
|
|
301
|
+
if (!Array.isArray(list) || list.length === 0)
|
|
302
|
+
return 'Error: edits must be a non-empty array of { old_text, new_text } objects.';
|
|
303
|
+
if (params.old_text !== undefined || params.insert_at !== undefined)
|
|
304
|
+
return 'Error: pass either edits or a single old_text/insert_at, not both.';
|
|
305
|
+
const out = [];
|
|
306
|
+
for (let i = 0; i < list.length; i++) {
|
|
307
|
+
const item = toObject(list[i]);
|
|
308
|
+
if (!item)
|
|
309
|
+
return `Error: edit ${i + 1} of ${list.length} is not an object.`;
|
|
310
|
+
const e = parseEdit(item, `edit ${i + 1} of ${list.length}: `);
|
|
311
|
+
if (typeof e === 'string')
|
|
312
|
+
return e;
|
|
313
|
+
out.push(e);
|
|
314
|
+
}
|
|
315
|
+
return out;
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* Apply edits in order, each to the result of the one before, in memory. Any
|
|
319
|
+
* failure returns the error and nothing else, so the caller writes all or
|
|
320
|
+
* none. Exported for tests.
|
|
321
|
+
*/
|
|
322
|
+
export function applyEdits(content, edits, path) {
|
|
323
|
+
let out = content;
|
|
324
|
+
for (let i = 0; i < edits.length; i++) {
|
|
325
|
+
const e = edits[i];
|
|
326
|
+
const which = edits.length > 1 ? `edit ${i + 1} of ${edits.length}: ` : '';
|
|
327
|
+
const nothing = edits.length > 1 ? ' Nothing was written.' : '';
|
|
328
|
+
if (e.oldText !== undefined) {
|
|
329
|
+
const occurrences = out.split(e.oldText).length - 1;
|
|
330
|
+
if (occurrences === 0) {
|
|
331
|
+
const hint = out.includes(e.oldText.trim())
|
|
332
|
+
? ' The text was found with different whitespace/indentation. Make sure old_text matches exactly, including all spaces and newlines.'
|
|
333
|
+
: ` Double-check the file content with runner_read_file first.${i > 0 ? ' The edits before this one have already changed the text it is matched against.' : ''}`;
|
|
334
|
+
return { error: `Error: ${which}old_text not found in ${path}.${hint}${nothing}` };
|
|
335
|
+
}
|
|
336
|
+
if (occurrences > 1) {
|
|
337
|
+
return { error: `Error: ${which}old_text appears ${occurrences} times in ${path}. Include more surrounding context to make it unique (at least 3 lines before and after).${nothing}` };
|
|
338
|
+
}
|
|
339
|
+
// A function replacer: `$&` and friends in new_text stay literal.
|
|
340
|
+
out = out.replace(e.oldText, () => e.newText);
|
|
341
|
+
}
|
|
342
|
+
else {
|
|
343
|
+
const lines = out.split('\n');
|
|
344
|
+
lines.splice(Math.max(0, Math.min(e.insertAt, lines.length)), 0, e.newText);
|
|
345
|
+
out = lines.join('\n');
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
return { content: out };
|
|
349
|
+
}
|
|
350
|
+
async function executeEditFile(params, context) {
|
|
351
|
+
const path = params.path;
|
|
352
|
+
if (!path)
|
|
353
|
+
return 'Error: path is required';
|
|
354
|
+
const edits = parseEdits(params);
|
|
355
|
+
if (typeof edits === 'string')
|
|
356
|
+
return edits;
|
|
357
|
+
try {
|
|
358
|
+
const resolved = resolveInJail(path, context);
|
|
359
|
+
if (!existsSync(resolved)) {
|
|
360
|
+
return `Error: File not found: ${path}. Use runner_write_file to create new files.`;
|
|
361
|
+
}
|
|
362
|
+
const shared = inSharedCheckout(resolved, context);
|
|
363
|
+
const refused = shared ? refuseClaimedWrite(resolved, path, context) : null;
|
|
364
|
+
if (refused)
|
|
365
|
+
return refused;
|
|
366
|
+
const applied = applyEdits(readFileSync(resolved, 'utf-8'), edits, path);
|
|
367
|
+
if ('error' in applied)
|
|
368
|
+
return applied.error;
|
|
369
|
+
writeFileSync(resolved, applied.content, 'utf-8');
|
|
370
|
+
if (shared)
|
|
371
|
+
claimFile(resolved, context);
|
|
372
|
+
const only = edits.length === 1 ? edits[0] : null;
|
|
373
|
+
const lint = await diagnoseAfterWrite(resolved, context);
|
|
374
|
+
return withDiagnostics(withHint(sonarEditHint(resolved, context), JSON.stringify({
|
|
375
|
+
success: true,
|
|
376
|
+
path,
|
|
377
|
+
action: only ? (only.oldText !== undefined ? 'replaced' : `inserted at line ${only.insertAt}`) : `${edits.length} edits applied`,
|
|
378
|
+
size: statSync(resolved).size,
|
|
379
|
+
lines: applied.content.split('\n').length,
|
|
380
|
+
})), lint);
|
|
381
|
+
}
|
|
382
|
+
catch (err) {
|
|
383
|
+
return `Error: ${err.message}`;
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
// ─── runner_list_directory ─────────────────────
|
|
387
|
+
const listDirectoryDefinition = {
|
|
388
|
+
name: 'runner_list_directory',
|
|
389
|
+
description: 'List files and directories at a path with names, types, and sizes.',
|
|
390
|
+
parameters: {
|
|
391
|
+
type: 'object',
|
|
392
|
+
properties: {
|
|
393
|
+
path: { type: 'string', description: 'Directory path. Relative paths resolve against the project root. Absolute paths must stay within the project root or the agent home. Default: the session\'s scope folder, else the project root.' },
|
|
394
|
+
recursive: { type: 'boolean', description: 'List recursively up to 3 levels. Default: false.' },
|
|
395
|
+
},
|
|
396
|
+
required: [],
|
|
397
|
+
},
|
|
398
|
+
};
|
|
399
|
+
function listDir(dirPath, roots, depth, maxDepth) {
|
|
400
|
+
const entries = [];
|
|
401
|
+
const SKIP_DIRS = ['node_modules', '.git', '.next', '.nuxt', '.output', 'dist', '__pycache__', '.venv', 'venv', '.cache'];
|
|
402
|
+
const MAX_ENTRIES = 500;
|
|
403
|
+
let items;
|
|
404
|
+
try {
|
|
405
|
+
items = readdirSync(dirPath);
|
|
406
|
+
}
|
|
407
|
+
catch {
|
|
408
|
+
return entries;
|
|
409
|
+
}
|
|
410
|
+
for (const name of items) {
|
|
411
|
+
if (entries.length >= MAX_ENTRIES) {
|
|
412
|
+
entries.push({ name: `... (${items.length - MAX_ENTRIES} more items)`, type: 'file' });
|
|
413
|
+
break;
|
|
414
|
+
}
|
|
415
|
+
const fullPath = resolve(dirPath, name);
|
|
416
|
+
// Skip anything that escapes every allowed root.
|
|
417
|
+
if (!roots.some(r => isInsideRoot(fullPath, r)))
|
|
418
|
+
continue;
|
|
419
|
+
try {
|
|
420
|
+
const stat = statSync(fullPath);
|
|
421
|
+
if (stat.isDirectory()) {
|
|
422
|
+
const entry = { name: name + '/', type: 'directory' };
|
|
423
|
+
if (depth < maxDepth && !SKIP_DIRS.includes(name) && !name.startsWith('.')) {
|
|
424
|
+
entry.children = listDir(fullPath, roots, depth + 1, maxDepth);
|
|
425
|
+
}
|
|
426
|
+
entries.push(entry);
|
|
427
|
+
}
|
|
428
|
+
else {
|
|
429
|
+
entries.push({ name, type: 'file', size: stat.size });
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
catch {
|
|
433
|
+
// Skip inaccessible entries
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
return entries;
|
|
437
|
+
}
|
|
438
|
+
function formatTree(entries, prefix = '') {
|
|
439
|
+
const lines = [];
|
|
440
|
+
for (let i = 0; i < entries.length; i++) {
|
|
441
|
+
const entry = entries[i];
|
|
442
|
+
if (!entry)
|
|
443
|
+
continue;
|
|
444
|
+
const isLast = i === entries.length - 1;
|
|
445
|
+
const connector = isLast ? '└── ' : '├── ';
|
|
446
|
+
const sizeStr = entry.type === 'file' && entry.size !== undefined ? ` (${formatSize(entry.size)})` : '';
|
|
447
|
+
lines.push(`${prefix}${connector}${entry.name}${sizeStr}`);
|
|
448
|
+
if (entry.children && entry.children.length > 0) {
|
|
449
|
+
const childPrefix = prefix + (isLast ? ' ' : '│ ');
|
|
450
|
+
lines.push(formatTree(entry.children, childPrefix));
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
return lines.join('\n');
|
|
454
|
+
}
|
|
455
|
+
function formatSize(bytes) {
|
|
456
|
+
if (bytes < 1024)
|
|
457
|
+
return `${bytes}B`;
|
|
458
|
+
if (bytes < 1024 * 1024)
|
|
459
|
+
return `${(bytes / 1024).toFixed(1)}KB`;
|
|
460
|
+
return `${(bytes / (1024 * 1024)).toFixed(1)}MB`;
|
|
461
|
+
}
|
|
462
|
+
async function executeListDirectory(params, context) {
|
|
463
|
+
// A session's scope is the default: its folder is what the session is about.
|
|
464
|
+
const path = params.path || writeScopeRel(context) || '.';
|
|
465
|
+
const recursive = params.recursive === true;
|
|
466
|
+
try {
|
|
467
|
+
const jail = jailRoots(context);
|
|
468
|
+
if (jail.length === 0)
|
|
469
|
+
return 'Error: No project or home configured';
|
|
470
|
+
const resolved = resolveForRead(path, context);
|
|
471
|
+
// Listing is a read: a caller's scratch dir counts as a root here.
|
|
472
|
+
for (const r of readOnlyRoots(context))
|
|
473
|
+
if (!jail.includes(r))
|
|
474
|
+
jail.push(r);
|
|
475
|
+
// `resolved` is canonical (symlinks followed), so the roots and the base
|
|
476
|
+
// must be too: a project reached through a link (`/Volumes/Macintosh HD/...`
|
|
477
|
+
// on macOS is `/...`) otherwise filters out every entry and the header
|
|
478
|
+
// turns into a long `../../..` path.
|
|
479
|
+
const roots = jail.map(realpathSafe);
|
|
480
|
+
if (!existsSync(resolved)) {
|
|
481
|
+
return `Error: Directory not found: ${path}`;
|
|
482
|
+
}
|
|
483
|
+
const stat = statSync(resolved);
|
|
484
|
+
if (!stat.isDirectory()) {
|
|
485
|
+
return `Error: "${path}" is a file, not a directory. Use runner_read_file instead.`;
|
|
486
|
+
}
|
|
487
|
+
// Header/relative display anchors on the project root (first root).
|
|
488
|
+
const base = context?.projectRoot ? realpathSafe(resolve(context.projectRoot)) : roots[0] ?? resolved;
|
|
489
|
+
const maxDepth = recursive ? 3 : 0;
|
|
490
|
+
const entries = listDir(resolved, roots, 0, maxDepth);
|
|
491
|
+
const tree = formatTree(entries);
|
|
492
|
+
const relUnderBase = relative(base, resolved);
|
|
493
|
+
const header = relUnderBase || '.';
|
|
494
|
+
return withHint(sonarListHint(resolved, context), `${header}/\n${tree}`);
|
|
495
|
+
}
|
|
496
|
+
catch (err) {
|
|
497
|
+
return `Error: ${err.message}`;
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
// ─── Exports ────────────────────────────────
|
|
501
|
+
export const filesystemTools = [
|
|
502
|
+
{ definition: readFileDefinition, execute: executeReadFile },
|
|
503
|
+
{ definition: writeFileDefinition, execute: executeWriteFile },
|
|
504
|
+
{ definition: editFileDefinition, execute: executeEditFile },
|
|
505
|
+
{ definition: listDirectoryDefinition, execute: executeListDirectory },
|
|
506
|
+
];
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type ToolDefinition } from '@nordhavnhq/runner-runtime';
|
|
2
|
+
import type { ToolContext } from './index.js';
|
|
3
|
+
/** Exported for tests. */
|
|
4
|
+
export declare function executeTagDraft(params: Record<string, unknown>, context?: ToolContext): Promise<string>;
|
|
5
|
+
/** Exported for tests. */
|
|
6
|
+
export declare function executeTag(params: Record<string, unknown>, context?: ToolContext): Promise<string>;
|
|
7
|
+
export declare const gitTagTools: {
|
|
8
|
+
definition: ToolDefinition;
|
|
9
|
+
execute: typeof executeTagDraft;
|
|
10
|
+
}[];
|