@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,10 @@
|
|
|
1
|
+
import type { ToolContext } from './index.js';
|
|
2
|
+
import { type WorktreeSetupResult } from './_worktree-setup.js';
|
|
3
|
+
export type RunWorktreeResult = {
|
|
4
|
+
path: string;
|
|
5
|
+
created: boolean;
|
|
6
|
+
setup: WorktreeSetupResult | null;
|
|
7
|
+
} | {
|
|
8
|
+
error: string;
|
|
9
|
+
};
|
|
10
|
+
export declare function ensureRunWorktree(repo: string, branch: string, context?: ToolContext): Promise<RunWorktreeResult>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import { runWorktreeSetup } from './_worktree-setup.js';
|
|
3
|
+
import { addWorktree, findWorktreeFor, gitErrorMessage, runGit, validateRefName, worktreePathFor } from './git.js';
|
|
4
|
+
export async function ensureRunWorktree(repo, branch, context) {
|
|
5
|
+
const invalid = validateRefName(branch);
|
|
6
|
+
if (invalid)
|
|
7
|
+
return { error: invalid };
|
|
8
|
+
const wtPath = worktreePathFor(repo, branch);
|
|
9
|
+
try {
|
|
10
|
+
// A resumed run goes on in the worktree it already has, also one made at
|
|
11
|
+
// the old place next to the checkout (<repo>-worktrees/).
|
|
12
|
+
const existing = await findWorktreeFor(repo, branch);
|
|
13
|
+
if (existing)
|
|
14
|
+
return { path: existing, created: false, setup: null };
|
|
15
|
+
if (existsSync(wtPath)) {
|
|
16
|
+
const { stdout } = await runGit(wtPath, ['branch', '--show-current']);
|
|
17
|
+
if (stdout.trim() !== branch)
|
|
18
|
+
return { error: `${wtPath} exists but is on "${stdout.trim() || 'a detached HEAD'}", not ${branch}` };
|
|
19
|
+
return { path: wtPath, created: false, setup: null };
|
|
20
|
+
}
|
|
21
|
+
await addWorktree(repo, branch, wtPath);
|
|
22
|
+
}
|
|
23
|
+
catch (err) {
|
|
24
|
+
return { error: gitErrorMessage(err) };
|
|
25
|
+
}
|
|
26
|
+
return { path: wtPath, created: true, setup: await runWorktreeSetup(repo, wtPath, context) };
|
|
27
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reading a shell line word by word, for the guards of `runner_run_command`.
|
|
3
|
+
* A tripwire, not a parser: it knows quotes, backslash escapes and the
|
|
4
|
+
* separators between simple commands, nothing about variables or expansion.
|
|
5
|
+
*/
|
|
6
|
+
/** `text` without its quotes and backslash escapes: the shell reads `"pu"sh` and `pu\sh` as `push`. */
|
|
7
|
+
export declare const unquote: (text: string) => string;
|
|
8
|
+
/**
|
|
9
|
+
* Is there an `rm` in `command` that is both recursive and forced, however its
|
|
10
|
+
* flags are written: `-rf`, `-fr`, `-Rf`, `-r -f`, `--recursive --force`,
|
|
11
|
+
* quoted or after the paths? Each simple command (split on ; & | ( ) and
|
|
12
|
+
* substitutions) is read word by word from its `rm` (also `/bin/rm`, `\rm`,
|
|
13
|
+
* `command rm`); `--` ends the flags.
|
|
14
|
+
*/
|
|
15
|
+
export declare function isForcedRecursiveRm(command: string): boolean;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reading a shell line word by word, for the guards of `runner_run_command`.
|
|
3
|
+
* A tripwire, not a parser: it knows quotes, backslash escapes and the
|
|
4
|
+
* separators between simple commands, nothing about variables or expansion.
|
|
5
|
+
*/
|
|
6
|
+
/** The separators that end one simple command in a shell line. */
|
|
7
|
+
const SHELL_SEPARATOR = /[;&|()\n\r`]|\$\(/;
|
|
8
|
+
/** `text` without its quotes and backslash escapes: the shell reads `"pu"sh` and `pu\sh` as `push`. */
|
|
9
|
+
export const unquote = (text) => text.replace(/\\(.)/g, '$1').replace(/["']/g, '');
|
|
10
|
+
/**
|
|
11
|
+
* Is there an `rm` in `command` that is both recursive and forced, however its
|
|
12
|
+
* flags are written: `-rf`, `-fr`, `-Rf`, `-r -f`, `--recursive --force`,
|
|
13
|
+
* quoted or after the paths? Each simple command (split on ; & | ( ) and
|
|
14
|
+
* substitutions) is read word by word from its `rm` (also `/bin/rm`, `\rm`,
|
|
15
|
+
* `command rm`); `--` ends the flags.
|
|
16
|
+
*/
|
|
17
|
+
export function isForcedRecursiveRm(command) {
|
|
18
|
+
for (const part of command.split(SHELL_SEPARATOR)) {
|
|
19
|
+
const words = part.trim().split(/\s+/).map(unquote);
|
|
20
|
+
const at = words.findIndex(w => w === 'rm' || w.endsWith('/rm'));
|
|
21
|
+
if (at < 0)
|
|
22
|
+
continue;
|
|
23
|
+
let recursive = false;
|
|
24
|
+
let force = false;
|
|
25
|
+
for (const word of words.slice(at + 1)) {
|
|
26
|
+
if (word === '--')
|
|
27
|
+
break;
|
|
28
|
+
if (word === '--recursive')
|
|
29
|
+
recursive = true;
|
|
30
|
+
else if (word === '--force')
|
|
31
|
+
force = true;
|
|
32
|
+
else if (/^-[a-zA-Z]+$/.test(word)) {
|
|
33
|
+
if (/[rR]/.test(word))
|
|
34
|
+
recursive = true;
|
|
35
|
+
if (word.includes('f'))
|
|
36
|
+
force = true;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
if (recursive && force)
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type ImportScan } from './imports.js';
|
|
2
|
+
import type { SonarSymbol } from './types.js';
|
|
3
|
+
/** Imports of an .astro file: frontmatter, <script> blocks and local `<script src>`. */
|
|
4
|
+
export declare function scanAstroImports(src: string): ImportScan;
|
|
5
|
+
/** Symbols of the frontmatter and scripts, plus the component the file is when its name is PascalCase. */
|
|
6
|
+
export declare function astroSymbols(path: string, src: string, lines: number): SonarSymbol[];
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { scanSymbols } from '../_symbols.js';
|
|
2
|
+
import { scanJsImports, splitSfc } from './imports.js';
|
|
3
|
+
// ─── Sonar: Astro components ────────────────
|
|
4
|
+
//
|
|
5
|
+
// An .astro file is TypeScript frontmatter between two `---` fences, then a
|
|
6
|
+
// template with optional <script> blocks. Astro has no auto-import: every
|
|
7
|
+
// component a template renders is imported in the frontmatter, so the import
|
|
8
|
+
// edges are the component edges. `<script src="./x.ts">` counts as an import.
|
|
9
|
+
/** The frontmatter and <script> code of an .astro file (everything else blanked) and its template. */
|
|
10
|
+
function splitAstro(src) {
|
|
11
|
+
const lines = src.split('\n');
|
|
12
|
+
let close = -1;
|
|
13
|
+
const open = lines.findIndex(l => l.trim() !== '');
|
|
14
|
+
if (open !== -1 && lines[open].trim() === '---') {
|
|
15
|
+
close = lines.findIndex((l, i) => i > open && l.trim() === '---');
|
|
16
|
+
}
|
|
17
|
+
const rest = lines.map((l, i) => (i <= close ? '' : l)).join('\n');
|
|
18
|
+
const { script, template } = splitSfc(rest);
|
|
19
|
+
const scriptLines = script.split('\n');
|
|
20
|
+
const code = lines.map((l, i) => (i > open && i < close ? l : scriptLines[i] ?? '')).join('\n');
|
|
21
|
+
return { code, template };
|
|
22
|
+
}
|
|
23
|
+
/** Imports of an .astro file: frontmatter, <script> blocks and local `<script src>`. */
|
|
24
|
+
export function scanAstroImports(src) {
|
|
25
|
+
const scan = scanJsImports(splitAstro(src).code);
|
|
26
|
+
const extra = [];
|
|
27
|
+
for (const m of src.matchAll(/<script\b[^>]*\bsrc\s*=\s*["']([^"'\s]+)["'][^>]*>/gi)) {
|
|
28
|
+
const spec = m[1];
|
|
29
|
+
if (!/^(?:https?:)?\/\//.test(spec) && !m[0].includes('is:inline'))
|
|
30
|
+
extra.push({ spec });
|
|
31
|
+
}
|
|
32
|
+
const known = new Set(scan.imports.map(i => i.spec));
|
|
33
|
+
return { ...scan, imports: [...scan.imports, ...extra.filter(i => !known.has(i.spec))] };
|
|
34
|
+
}
|
|
35
|
+
/** Symbols of the frontmatter and scripts, plus the component the file is when its name is PascalCase. */
|
|
36
|
+
export function astroSymbols(path, src, lines) {
|
|
37
|
+
const found = scanSymbols(`${path}.ts`, splitAstro(src).code) ?? [];
|
|
38
|
+
const symbols = found.map(s => (s.parent
|
|
39
|
+
? { name: s.name, kind: s.kind, start: s.start, end: s.end, parent: s.parent }
|
|
40
|
+
: { name: s.name, kind: s.kind, start: s.start, end: s.end }));
|
|
41
|
+
const name = path.slice(path.lastIndexOf('/') + 1, -'.astro'.length);
|
|
42
|
+
if (/^[A-Z][A-Za-z0-9]*$/.test(name))
|
|
43
|
+
symbols.unshift({ name, kind: 'component', start: 1, end: Math.max(1, lines) });
|
|
44
|
+
return symbols;
|
|
45
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { dedupeImports, scanPhpImports } from './imports.js';
|
|
2
|
+
import { BLADE_CALLS, callArgs, laravelSpec, phpString, scanCalls } from './laravel.js';
|
|
3
|
+
// ─── Sonar: Blade views ─────────────────────
|
|
4
|
+
//
|
|
5
|
+
// A .blade.php file is a template: no namespace and no classes, but it pulls
|
|
6
|
+
// in other views (@extends, @include*, @each, @component), Blade components
|
|
7
|
+
// (`<x-foo.bar>`), Livewire components (`@livewire`, `<livewire:foo>`), Vite
|
|
8
|
+
// entries (@vite) and classes (@use, @inject, inline FQCNs and aliases in its
|
|
9
|
+
// PHP). Blade comments and @verbatim blocks are blanked first; HTML comments
|
|
10
|
+
// stay, Blade still runs the directives inside them.
|
|
11
|
+
/** `{{-- --}}` comments and `@verbatim ... @endverbatim` blanked, newlines kept. */
|
|
12
|
+
function blankBlade(src) {
|
|
13
|
+
const blank = (s) => s.replace(/[^\n]/g, ' ');
|
|
14
|
+
return src.replace(/\{\{--[\s\S]*?--\}\}/g, blank).replace(/(?<![@\w])@verbatim\b[\s\S]*?@endverbatim/g, blank);
|
|
15
|
+
}
|
|
16
|
+
/** Tags that look like components but are Blade's own. */
|
|
17
|
+
const BLADE_OWN_TAGS = /^(?:slot|slot:.*|dynamic-component)$/;
|
|
18
|
+
function scanTags(code) {
|
|
19
|
+
const out = [];
|
|
20
|
+
for (const m of code.matchAll(/<x-([\w.:-]+)(?=[\s/>])/g)) {
|
|
21
|
+
if (BLADE_OWN_TAGS.test(m[1]))
|
|
22
|
+
continue;
|
|
23
|
+
const imp = laravelSpec('x', m[1]);
|
|
24
|
+
if (imp)
|
|
25
|
+
out.push(imp);
|
|
26
|
+
}
|
|
27
|
+
for (const m of code.matchAll(/<livewire:([\w.:-]+)(?=[\s/>])/g)) {
|
|
28
|
+
if (m[1] === 'styles' || m[1] === 'scripts')
|
|
29
|
+
continue;
|
|
30
|
+
const imp = laravelSpec('livewire', m[1]);
|
|
31
|
+
if (imp)
|
|
32
|
+
out.push(imp);
|
|
33
|
+
}
|
|
34
|
+
return out;
|
|
35
|
+
}
|
|
36
|
+
/** `@use('App\Models\User')` and `@inject('name', 'App\Services\X')`: classes the view imports. */
|
|
37
|
+
function scanClassDirectives(code) {
|
|
38
|
+
const out = [];
|
|
39
|
+
for (const m of code.matchAll(/(?<![@\w])@(use|inject)\s*\(/g)) {
|
|
40
|
+
const args = callArgs(code, m.index + m[0].length - 1);
|
|
41
|
+
const fq = phpString(args[m[1] === 'use' ? 0 : 1])?.replace(/^\\/, '');
|
|
42
|
+
if (fq && /^[\w\\]+$/.test(fq))
|
|
43
|
+
out.push({ spec: fq });
|
|
44
|
+
}
|
|
45
|
+
return out;
|
|
46
|
+
}
|
|
47
|
+
/** Imports of a Blade view: other views, components, Livewire, Vite entries and classes. */
|
|
48
|
+
export function scanBladeImports(src) {
|
|
49
|
+
const code = blankBlade(src);
|
|
50
|
+
const php = scanPhpImports(code, { blade: true });
|
|
51
|
+
const imports = [...php.imports, ...scanCalls(code, BLADE_CALLS), ...scanTags(code), ...scanClassDirectives(code)];
|
|
52
|
+
return { imports: dedupeImports(imports), exportsNamed: [] };
|
|
53
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { FsSonarStatus } from '@nordhavnhq/runner-runtime';
|
|
2
|
+
import { type LoadSonarOptions, type SonarIndex } from './index.js';
|
|
3
|
+
/** Failed builds of one checkout after which no build starts on its own any more (only a person's). */
|
|
4
|
+
export declare const SONAR_AUTO_ATTEMPTS = 2;
|
|
5
|
+
/** How the index of `root` (a real path) stands: never builds, refreshes or lists anything. */
|
|
6
|
+
export declare function sonarStatus(root: string, opts?: {
|
|
7
|
+
cacheDir?: string;
|
|
8
|
+
}): FsSonarStatus;
|
|
9
|
+
/**
|
|
10
|
+
* The status plus how far the files moved since the index (`stale`), for the
|
|
11
|
+
* Sonar view: lists and stats the checkout (no parse), so only when there is
|
|
12
|
+
* an index and no build runs.
|
|
13
|
+
*/
|
|
14
|
+
export declare function sonarStatusWithDrift(root: string, opts?: {
|
|
15
|
+
cacheDir?: string;
|
|
16
|
+
}): Promise<FsSonarStatus>;
|
|
17
|
+
/**
|
|
18
|
+
* Start a build of `root` (a real path) unless one runs: every file read
|
|
19
|
+
* again, the `.sonar` written anew. Returns the status as it starts; the
|
|
20
|
+
* build goes on in the background and a failure lands in the status.
|
|
21
|
+
*/
|
|
22
|
+
export declare function startSonarBuild(root: string, load?: Pick<LoadSonarOptions, 'cacheDir'>): {
|
|
23
|
+
status: FsSonarStatus;
|
|
24
|
+
done: Promise<void>;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* An index that fell behind (more changed than a load reads again) catches
|
|
28
|
+
* up: a build starts in the background, as if a person asked. Not once
|
|
29
|
+
* builds of this checkout failed SONAR_AUTO_ATTEMPTS times (no loop of
|
|
30
|
+
* failing builds: the Sonar view shows the error). True while a build runs
|
|
31
|
+
* for it, so the caller can say it is catching up.
|
|
32
|
+
*/
|
|
33
|
+
export declare function catchUpSonar(index: SonarIndex, load?: Pick<LoadSonarOptions, 'cacheDir'>): boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Make sure `root` (a real path, a coupled checkout) has a usable index: when
|
|
36
|
+
* a load finds none (no `.sonar`, one from an older runner version, a damaged
|
|
37
|
+
* one), a build starts, or the running one is joined. Waits at most
|
|
38
|
+
* `waitMs` for it; the build goes on past that. True once the index is
|
|
39
|
+
* there, false when it is not (yet), or no build may start on its own any
|
|
40
|
+
* more (SONAR_AUTO_ATTEMPTS). Never throws.
|
|
41
|
+
*/
|
|
42
|
+
export declare function ensureSonarBuilt(root: string, load?: Pick<LoadSonarOptions, 'cacheDir'> & {
|
|
43
|
+
waitMs?: number;
|
|
44
|
+
}): Promise<boolean>;
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { statSync } from 'node:fs';
|
|
2
|
+
import { log } from '../../utils/format.js';
|
|
3
|
+
import { loadSonarIndex, peekSonarIndex, SONAR_REFRESH_MAX, sonarCacheState, sonarDrift } from './index.js';
|
|
4
|
+
import { sonarCachePath } from './location.js';
|
|
5
|
+
import { rememberSonarRoot } from './roots.js';
|
|
6
|
+
// ─── Sonar: builds ──────────────────────────
|
|
7
|
+
//
|
|
8
|
+
// A coupled checkout (inside the runner's folder roots) gets its index on its
|
|
9
|
+
// own: the first one when the studio first asks for its map (`fs:sonar`, on a
|
|
10
|
+
// dispatch) or a dispatch arrives for it (ensureSonarBuilt), again when the
|
|
11
|
+
// `.sonar` is from an older runner version or damaged. A person can still
|
|
12
|
+
// (re)build from the code app's Sonar view (`fs:sonar` `build`). Once there,
|
|
13
|
+
// it keeps itself current: a load reads up to SONAR_REFRESH_MAX changed
|
|
14
|
+
// files, and an index that fell further behind (a branch switch, a big pull)
|
|
15
|
+
// catches up with a build of its own (catchUpSonar). A build that fails is
|
|
16
|
+
// tried once more on its own (SONAR_AUTO_ATTEMPTS), then only a person's
|
|
17
|
+
// build starts one. A build reads every file in the background
|
|
18
|
+
// (loadSonarIndex with `build`, in slices so the runner keeps answering), one
|
|
19
|
+
// per checkout at a time; `status` says how far it is, what the index holds,
|
|
20
|
+
// and how far the files moved since.
|
|
21
|
+
/** Failed builds of one checkout after which no build starts on its own any more (only a person's). */
|
|
22
|
+
export const SONAR_AUTO_ATTEMPTS = 2;
|
|
23
|
+
/** The builds of this process, per root and cache dir: running, or the last one that failed. */
|
|
24
|
+
const builds = new Map();
|
|
25
|
+
/** Builds of a checkout that failed in a row in this process, per root and cache dir (cleared by one that succeeds). */
|
|
26
|
+
const failures = new Map();
|
|
27
|
+
const keyOf = (root, cacheDir) => `${root}\0${cacheDir ?? ''}`;
|
|
28
|
+
function countsOf(index) {
|
|
29
|
+
let symbols = 0;
|
|
30
|
+
let edges = 0;
|
|
31
|
+
for (const f of index.files.values()) {
|
|
32
|
+
symbols += f.symbols.length;
|
|
33
|
+
edges += f.edges.length + f.componentEdges.length;
|
|
34
|
+
}
|
|
35
|
+
return { files: index.files.size, symbols, edges };
|
|
36
|
+
}
|
|
37
|
+
/** When the `.sonar` was written, for an index from before builds kept their time. */
|
|
38
|
+
function writtenAt(root, cacheDir) {
|
|
39
|
+
try {
|
|
40
|
+
return statSync(sonarCachePath(root, cacheDir)).mtime.toISOString();
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/** How the index of `root` (a real path) stands: never builds, refreshes or lists anything. */
|
|
47
|
+
export function sonarStatus(root, opts = {}) {
|
|
48
|
+
const build = builds.get(keyOf(root, opts.cacheDir));
|
|
49
|
+
const index = peekSonarIndex(root, opts);
|
|
50
|
+
const built = index ? { at: index.builtAt ?? writtenAt(root, opts.cacheDir), ...countsOf(index) } : null;
|
|
51
|
+
if (build?.running)
|
|
52
|
+
return { state: 'building', built, progress: build.progress, error: null };
|
|
53
|
+
if (build?.error)
|
|
54
|
+
return { state: 'failed', built, progress: null, error: build.error };
|
|
55
|
+
if (built)
|
|
56
|
+
return { state: 'ready', built, progress: null, error: null };
|
|
57
|
+
// A `.sonar` that is there but gives no index: from an older runner version, or broken.
|
|
58
|
+
if (writtenAt(root, opts.cacheDir) === null)
|
|
59
|
+
return { state: 'none', built: null, progress: null, error: null };
|
|
60
|
+
return sonarCacheState(root, opts) === 'outdated'
|
|
61
|
+
? { state: 'none', built: null, progress: null, error: 'Built by an older runner version: build it again', outdated: true }
|
|
62
|
+
: { state: 'none', built: null, progress: null, error: 'The .sonar cannot be read (damaged): build it again' };
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* The status plus how far the files moved since the index (`stale`), for the
|
|
66
|
+
* Sonar view: lists and stats the checkout (no parse), so only when there is
|
|
67
|
+
* an index and no build runs.
|
|
68
|
+
*/
|
|
69
|
+
export async function sonarStatusWithDrift(root, opts = {}) {
|
|
70
|
+
const status = sonarStatus(root, opts);
|
|
71
|
+
if (!status.built || status.state === 'building')
|
|
72
|
+
return status;
|
|
73
|
+
const drift = await sonarDrift(root, opts);
|
|
74
|
+
if (!drift)
|
|
75
|
+
return status;
|
|
76
|
+
return { ...status, stale: { ...drift, behind: drift.changed > SONAR_REFRESH_MAX } };
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Start a build of `root` (a real path) unless one runs: every file read
|
|
80
|
+
* again, the `.sonar` written anew. Returns the status as it starts; the
|
|
81
|
+
* build goes on in the background and a failure lands in the status.
|
|
82
|
+
*/
|
|
83
|
+
export function startSonarBuild(root, load = {}) {
|
|
84
|
+
const key = keyOf(root, load.cacheDir);
|
|
85
|
+
const current = builds.get(key);
|
|
86
|
+
if (current?.running)
|
|
87
|
+
return { status: sonarStatus(root, load), done: current.done };
|
|
88
|
+
const state = { progress: { phase: 'listing', done: 0, total: 0 }, error: null, running: true, done: Promise.resolve() };
|
|
89
|
+
builds.set(key, state);
|
|
90
|
+
log('·', 'sonar', `${root}: build started`);
|
|
91
|
+
const done = loadSonarIndex(root, { ...load, build: true, onProgress: (p) => { state.progress = p; } }).then((index) => {
|
|
92
|
+
builds.delete(key);
|
|
93
|
+
failures.delete(key);
|
|
94
|
+
if (!load.cacheDir)
|
|
95
|
+
rememberSonarRoot(root);
|
|
96
|
+
log('·', 'sonar', `${root}: built, ${index.files.size} files in ${index.stats.ms} ms`);
|
|
97
|
+
}, (err) => {
|
|
98
|
+
state.running = false;
|
|
99
|
+
state.error = err?.message ?? String(err);
|
|
100
|
+
failures.set(key, (failures.get(key) ?? 0) + 1);
|
|
101
|
+
log('✗', 'sonar', `${root}: build failed: ${state.error}`);
|
|
102
|
+
});
|
|
103
|
+
state.done = done;
|
|
104
|
+
return { status: sonarStatus(root, load), done };
|
|
105
|
+
}
|
|
106
|
+
/** True while a build may still start on its own for this checkout: fewer than SONAR_AUTO_ATTEMPTS failed in a row. */
|
|
107
|
+
const mayBuildOnItsOwn = (key) => (failures.get(key) ?? 0) < SONAR_AUTO_ATTEMPTS;
|
|
108
|
+
/**
|
|
109
|
+
* An index that fell behind (more changed than a load reads again) catches
|
|
110
|
+
* up: a build starts in the background, as if a person asked. Not once
|
|
111
|
+
* builds of this checkout failed SONAR_AUTO_ATTEMPTS times (no loop of
|
|
112
|
+
* failing builds: the Sonar view shows the error). True while a build runs
|
|
113
|
+
* for it, so the caller can say it is catching up.
|
|
114
|
+
*/
|
|
115
|
+
export function catchUpSonar(index, load = {}) {
|
|
116
|
+
const key = keyOf(index.root, load.cacheDir);
|
|
117
|
+
if (builds.get(key)?.running)
|
|
118
|
+
return true;
|
|
119
|
+
if (index.behind <= 0 || !mayBuildOnItsOwn(key))
|
|
120
|
+
return false;
|
|
121
|
+
log('·', 'sonar', `${index.root}: ${index.behind} files behind, catching up`);
|
|
122
|
+
startSonarBuild(index.root, load);
|
|
123
|
+
return true;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Make sure `root` (a real path, a coupled checkout) has a usable index: when
|
|
127
|
+
* a load finds none (no `.sonar`, one from an older runner version, a damaged
|
|
128
|
+
* one), a build starts, or the running one is joined. Waits at most
|
|
129
|
+
* `waitMs` for it; the build goes on past that. True once the index is
|
|
130
|
+
* there, false when it is not (yet), or no build may start on its own any
|
|
131
|
+
* more (SONAR_AUTO_ATTEMPTS). Never throws.
|
|
132
|
+
*/
|
|
133
|
+
export async function ensureSonarBuilt(root, load = {}) {
|
|
134
|
+
const key = keyOf(root, load.cacheDir);
|
|
135
|
+
if (peekSonarIndex(root, load))
|
|
136
|
+
return true;
|
|
137
|
+
const running = builds.get(key)?.running === true;
|
|
138
|
+
if (!running && !mayBuildOnItsOwn(key))
|
|
139
|
+
return false;
|
|
140
|
+
if (!running)
|
|
141
|
+
log('·', 'sonar', `${root}: no usable index, building one`);
|
|
142
|
+
const { done } = startSonarBuild(root, { cacheDir: load.cacheDir });
|
|
143
|
+
let timer;
|
|
144
|
+
const late = new Promise((resolve) => { timer = setTimeout(resolve, load.waitMs ?? 0); });
|
|
145
|
+
await Promise.race([done, late]).finally(() => clearTimeout(timer));
|
|
146
|
+
return peekSonarIndex(root, load) !== null;
|
|
147
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { SonarIndex } from './types.js';
|
|
2
|
+
type Status = 'modified' | 'added' | 'deleted' | 'renamed' | 'untracked';
|
|
3
|
+
interface FileDiff {
|
|
4
|
+
path: string;
|
|
5
|
+
oldPath?: string;
|
|
6
|
+
status: Status;
|
|
7
|
+
/** New-side line ranges that changed, inclusive. */
|
|
8
|
+
changed: [number, number][];
|
|
9
|
+
/** New-side ranges of hunks that only add lines. */
|
|
10
|
+
pureAdds: [number, number][];
|
|
11
|
+
/** New-side line after which lines were removed (a hunk with no new lines). */
|
|
12
|
+
removedAt: number[];
|
|
13
|
+
removedLines: string[];
|
|
14
|
+
plus: number;
|
|
15
|
+
minus: number;
|
|
16
|
+
}
|
|
17
|
+
/** `git diff --unified=0` per file: changed new-side ranges and the removed lines. */
|
|
18
|
+
export declare function parseDiff(text: string): FileDiff[];
|
|
19
|
+
/** The answer of `changed`. */
|
|
20
|
+
export declare function renderChanged(index: SonarIndex, ref: string, scope: string): Promise<string>;
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import { execFile } from 'node:child_process';
|
|
2
|
+
import { promisify } from 'node:util';
|
|
3
|
+
import { importersByDepth, inScope, isTestPath } from './graph.js';
|
|
4
|
+
import { Budget, listed } from './render.js';
|
|
5
|
+
import { callOf, coveringTests, isClose, isTestFile } from './tests.js';
|
|
6
|
+
// ─── Sonar: what changed ────────────────────
|
|
7
|
+
//
|
|
8
|
+
// `changed { query?: ref, path? }`: the diff against a ref (default HEAD:
|
|
9
|
+
// staged and unstaged work; untracked files count as new) at symbol level.
|
|
10
|
+
// Per code file the functions, classes and methods whose lines changed
|
|
11
|
+
// (added ones marked, removed definitions named), whether exports changed
|
|
12
|
+
// and how many files depend on it; then the tests that cover the changes
|
|
13
|
+
// as runner_test calls. For a review, a working copy's report or the check
|
|
14
|
+
// before a commit, without reading the diff hunk by hunk.
|
|
15
|
+
const execFileAsync = promisify(execFile);
|
|
16
|
+
/** Code files shown with their symbols; the rest are counted. */
|
|
17
|
+
const FILES_DETAILED = 25;
|
|
18
|
+
const SYMBOLS_PER_FILE = 12;
|
|
19
|
+
const TEST_CALLS = 6;
|
|
20
|
+
/** Diffs that are noise at symbol level: lock files. */
|
|
21
|
+
const LOCKS = [':(exclude,glob)**/package-lock.json', ':(exclude,glob)**/*.lock', ':(exclude,glob)**/pnpm-lock.yaml'];
|
|
22
|
+
async function git(root, args) {
|
|
23
|
+
const { stdout } = await execFileAsync('git', args, { cwd: root, maxBuffer: 32 * 1024 * 1024, timeout: 30_000 });
|
|
24
|
+
return stdout;
|
|
25
|
+
}
|
|
26
|
+
const HUNK = /^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@/;
|
|
27
|
+
const emptyDiff = (path, status, plus = 0, minus = 0) => ({ path, status, changed: [], pureAdds: [], removedAt: [], removedLines: [], plus, minus });
|
|
28
|
+
/** A header line of one file's diff (before its first hunk). */
|
|
29
|
+
function readHeader(cur, line) {
|
|
30
|
+
if (line.startsWith('new file mode'))
|
|
31
|
+
cur.status = 'added';
|
|
32
|
+
else if (line.startsWith('deleted file mode'))
|
|
33
|
+
cur.status = 'deleted';
|
|
34
|
+
else if (line.startsWith('rename from ')) {
|
|
35
|
+
cur.status = 'renamed';
|
|
36
|
+
cur.oldPath = line.slice(12);
|
|
37
|
+
}
|
|
38
|
+
else if (line.startsWith('rename to '))
|
|
39
|
+
cur.path = line.slice(10);
|
|
40
|
+
else if (line.startsWith('+++ b/'))
|
|
41
|
+
cur.path = line.slice(6);
|
|
42
|
+
else if (line.startsWith('--- a/') && cur.status === 'deleted')
|
|
43
|
+
cur.path = line.slice(6);
|
|
44
|
+
}
|
|
45
|
+
function readHunk(cur, h) {
|
|
46
|
+
const oldCount = h[2] === undefined ? 1 : Number(h[2]);
|
|
47
|
+
const start = Number(h[3]);
|
|
48
|
+
const count = h[4] === undefined ? 1 : Number(h[4]);
|
|
49
|
+
if (count === 0) {
|
|
50
|
+
cur.removedAt.push(start);
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
cur.changed.push([start, start + count - 1]);
|
|
54
|
+
if (oldCount === 0)
|
|
55
|
+
cur.pureAdds.push([start, start + count - 1]);
|
|
56
|
+
}
|
|
57
|
+
/** `git diff --unified=0` per file: changed new-side ranges and the removed lines. */
|
|
58
|
+
export function parseDiff(text) {
|
|
59
|
+
const out = [];
|
|
60
|
+
let cur = null;
|
|
61
|
+
let inHunk = false;
|
|
62
|
+
for (const line of text.split('\n')) {
|
|
63
|
+
if (line.startsWith('diff --git ')) {
|
|
64
|
+
cur = emptyDiff(/ b\/(.+)$/.exec(line)?.[1] ?? '', 'modified');
|
|
65
|
+
out.push(cur);
|
|
66
|
+
inHunk = false;
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
if (!cur)
|
|
70
|
+
continue;
|
|
71
|
+
const h = HUNK.exec(line);
|
|
72
|
+
if (h) {
|
|
73
|
+
inHunk = true;
|
|
74
|
+
readHunk(cur, h);
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
if (!inHunk) {
|
|
78
|
+
readHeader(cur, line);
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
if (line.startsWith('+'))
|
|
82
|
+
cur.plus++;
|
|
83
|
+
else if (line.startsWith('-')) {
|
|
84
|
+
cur.minus++;
|
|
85
|
+
cur.removedLines.push(line.slice(1));
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return out;
|
|
89
|
+
}
|
|
90
|
+
/** Names a removed line defined: `function x`, `class X`, `def x`, `public function x(`; a `const x` only at the top level (not a local). */
|
|
91
|
+
const DEF_LINE = /^\s*(?:export\s+)?(?:default\s+)?(?:declare\s+)?(?:abstract\s+|final\s+|static\s+|public\s+|protected\s+|private\s+|async\s+|readonly\s+)*(?:function\*?|class|interface|type|enum|def|fn|func|trait)\s+([A-Za-z_$][\w$]*)/;
|
|
92
|
+
const TOP_CONST = /^(?:export\s+)?(?:declare\s+)?(?:const|let|var)\s+([A-Za-z_$][\w$]*)/;
|
|
93
|
+
const overlaps = (s, [a, b]) => s.start <= b && a <= s.end;
|
|
94
|
+
const within = (s, [a, b]) => a <= s.start && s.end <= b;
|
|
95
|
+
/** The innermost symbols whose lines changed. */
|
|
96
|
+
function touchedSymbols(f, d) {
|
|
97
|
+
const hit = f.symbols.filter(s => d.changed.some(r => overlaps(s, r)) || d.removedAt.some(at => s.start <= at && at < s.end));
|
|
98
|
+
const innermost = hit.filter(s => !hit.some(t => t !== s && t.start >= s.start && t.end <= s.end && (t.start !== s.start || t.end !== s.end)));
|
|
99
|
+
const isNew = d.status === 'added' || d.status === 'untracked';
|
|
100
|
+
return innermost.map(symbol => ({ symbol, added: isNew || d.pureAdds.some(r => within(symbol, r)) }));
|
|
101
|
+
}
|
|
102
|
+
function removedNames(f, d) {
|
|
103
|
+
const now = new Set((f?.symbols ?? []).map(s => s.name));
|
|
104
|
+
const names = d.removedLines.map(l => (DEF_LINE.exec(l) ?? TOP_CONST.exec(l))?.[1]).filter((n) => !!n && !now.has(n));
|
|
105
|
+
return [...new Set(names)];
|
|
106
|
+
}
|
|
107
|
+
const nameOf = (s) => (s.parent ? `${s.parent}.${s.name}` : s.name);
|
|
108
|
+
function counts(d) {
|
|
109
|
+
if (d.status === 'untracked')
|
|
110
|
+
return 'new, untracked';
|
|
111
|
+
const tag = d.status === 'modified' ? '' : `${d.status}${d.oldPath ? ` from ${d.oldPath}` : ''}, `;
|
|
112
|
+
return `${tag}+${d.plus} -${d.minus}`;
|
|
113
|
+
}
|
|
114
|
+
function pushFile(out, index, f, d) {
|
|
115
|
+
const touched = touchedSymbols(f, d);
|
|
116
|
+
const exported = touched.filter(t => !t.symbol.parent && f.exportsNamed.includes(t.symbol.name)).map(t => t.symbol.name);
|
|
117
|
+
const importers = index.importers.get(f.path)?.length ?? 0;
|
|
118
|
+
const deep = importersByDepth(index, f.path, 3).reduce((n, l) => n + l.length, 0);
|
|
119
|
+
const impact = importers > 0 ? `, ${importers} importer(s), ${deep} within 3 levels` : '';
|
|
120
|
+
out.push(`${f.path} (${counts(d)}${impact})`);
|
|
121
|
+
if (d.status === 'added' || d.status === 'untracked') {
|
|
122
|
+
const own = f.symbols.filter(s => !s.parent).length;
|
|
123
|
+
out.push(` new file: ${own} top-level symbol(s)${f.exportsNamed.length > 0 ? `; exports ${listed(f.exportsNamed, 8)}` : ''}`);
|
|
124
|
+
return false;
|
|
125
|
+
}
|
|
126
|
+
pushSymbols(out, f, touched);
|
|
127
|
+
const removed = removedNames(f, d);
|
|
128
|
+
if (removed.length > 0)
|
|
129
|
+
out.push(` removed: ${listed(removed, 8)}`);
|
|
130
|
+
const changedExports = exported.filter(n => !touched.find(t => t.symbol.name === n)?.added);
|
|
131
|
+
if (changedExports.length > 0 && importers > 0)
|
|
132
|
+
out.push(` exports changed: ${listed(changedExports, 6)}: refs { query } for their callers`);
|
|
133
|
+
return removed.length > 0 || changedExports.length > 0;
|
|
134
|
+
}
|
|
135
|
+
function pushSymbols(out, f, touched) {
|
|
136
|
+
for (const t of touched.slice(0, SYMBOLS_PER_FILE)) {
|
|
137
|
+
const s = t.symbol;
|
|
138
|
+
const exp = !s.parent && f.exportsNamed.includes(s.name) ? ' exported' : '';
|
|
139
|
+
out.push(` ${s.kind} ${nameOf(s)} L${s.start}-${s.end}${t.added ? ' (new)' : ''}${exp}`);
|
|
140
|
+
}
|
|
141
|
+
if (touched.length > SYMBOLS_PER_FILE)
|
|
142
|
+
out.push(` +${touched.length - SYMBOLS_PER_FILE} more symbols`);
|
|
143
|
+
if (touched.length === 0)
|
|
144
|
+
out.push(' (outside any symbol: imports, top-level code or comments)');
|
|
145
|
+
}
|
|
146
|
+
function pushTests(out, index, files) {
|
|
147
|
+
const picked = [];
|
|
148
|
+
const add = (p) => { if (!picked.includes(p))
|
|
149
|
+
picked.push(p); };
|
|
150
|
+
for (const f of files)
|
|
151
|
+
if (isTestFile(f.path))
|
|
152
|
+
add(f.path);
|
|
153
|
+
for (const f of files) {
|
|
154
|
+
if (isTestPath(f.path))
|
|
155
|
+
continue;
|
|
156
|
+
for (const t of coveringTests(index, f).filter(isClose).slice(0, 3))
|
|
157
|
+
add(t.path);
|
|
158
|
+
}
|
|
159
|
+
if (picked.length === 0) {
|
|
160
|
+
out.push('No test file covers the changed code through the import graph or by name.');
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
out.push(`Tests (${picked.length}; changed tests first, then the best per changed file):`);
|
|
164
|
+
for (const p of picked.slice(0, TEST_CALLS))
|
|
165
|
+
out.push(` ${callOf(index.root, p)}`);
|
|
166
|
+
if (picked.length > TEST_CALLS)
|
|
167
|
+
out.push(` +${picked.length - TEST_CALLS} more: runner_sonar { action: "tests", path } per file`);
|
|
168
|
+
}
|
|
169
|
+
/** `refs/heads/x`, `HEAD~2`, `origin/main`, a sha: no options, no spaces. */
|
|
170
|
+
const SAFE_REF = /^(?!-)[\w./@^~{}-]+$/;
|
|
171
|
+
/** The diff against `ref`, plus untracked files and what only numstat shows (lock files, binaries). */
|
|
172
|
+
async function collectDiffs(root, ref, scope) {
|
|
173
|
+
const spec = [scope || '.', ...LOCKS];
|
|
174
|
+
const [diffText, numstat, untrackedText] = await Promise.all([
|
|
175
|
+
git(root, ['diff', '--no-color', '--no-ext-diff', '-M', '--unified=0', '--relative', ref, '--', ...spec]),
|
|
176
|
+
git(root, ['diff', '--numstat', '-M', '--relative', ref, '--', scope || '.']),
|
|
177
|
+
git(root, ['ls-files', '--others', '--exclude-standard', '--', scope || '.']),
|
|
178
|
+
]);
|
|
179
|
+
const diffs = parseDiff(diffText);
|
|
180
|
+
const add = (d) => { if (!diffs.some(x => x.path === d.path))
|
|
181
|
+
diffs.push(d); };
|
|
182
|
+
for (const p of untrackedText.split('\n').filter(Boolean))
|
|
183
|
+
add(emptyDiff(p, 'untracked'));
|
|
184
|
+
const stat = numstat.split('\n').filter(Boolean).map(l => l.split('\t')).filter(p => p.length >= 3);
|
|
185
|
+
for (const [plus, minus, path] of stat) {
|
|
186
|
+
const p = path.includes(' => ') ? path.replace(/\{([^}]*) => ([^}]*)\}/, '$2').replace(/^.* => /, '') : path;
|
|
187
|
+
add(emptyDiff(p, 'modified', Number(plus) || 0, Number(minus) || 0));
|
|
188
|
+
}
|
|
189
|
+
return diffs.filter(d => inScope(d.path, scope));
|
|
190
|
+
}
|
|
191
|
+
async function refError(root, ref) {
|
|
192
|
+
if (!SAFE_REF.test(ref))
|
|
193
|
+
return `Error: "${ref}" is not a git ref (a branch, tag, sha or HEAD~n).`;
|
|
194
|
+
try {
|
|
195
|
+
await git(root, ['rev-parse', '--verify', '--quiet', `${ref}^{commit}`]);
|
|
196
|
+
return null;
|
|
197
|
+
}
|
|
198
|
+
catch {
|
|
199
|
+
return `Error: "${ref}" is not a commit in this repo${ref === 'HEAD' ? ' (no commit yet?)' : ''}.`;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
/** The answer of `changed`. */
|
|
203
|
+
export async function renderChanged(index, ref, scope) {
|
|
204
|
+
const bad = await refError(index.root, ref);
|
|
205
|
+
if (bad)
|
|
206
|
+
return bad;
|
|
207
|
+
const inside = await collectDiffs(index.root, ref, scope);
|
|
208
|
+
const against = ref === 'HEAD' ? 'HEAD (staged and unstaged; untracked counted as new)' : `${ref} (the working tree against it, uncommitted work included)`;
|
|
209
|
+
if (inside.length === 0)
|
|
210
|
+
return `Nothing changed against ${against}${scope ? ` under ${scope}` : ''}.`;
|
|
211
|
+
const code = inside.filter(d => index.files.has(d.path) && d.status !== 'deleted');
|
|
212
|
+
const other = inside.filter(d => !code.includes(d));
|
|
213
|
+
const plus = inside.reduce((n, d) => n + d.plus, 0);
|
|
214
|
+
const minus = inside.reduce((n, d) => n + d.minus, 0);
|
|
215
|
+
const out = new Budget();
|
|
216
|
+
out.push(`Changed against ${against}${scope ? ` under ${scope}` : ''}: ${inside.length} file(s), +${plus} -${minus}; ${code.length} in the index.`);
|
|
217
|
+
// Source before tests, the most changed first.
|
|
218
|
+
const ordered = code.sort((a, b) => Number(isTestPath(a.path)) - Number(isTestPath(b.path)) || (b.plus + b.minus) - (a.plus + a.minus) || a.path.localeCompare(b.path));
|
|
219
|
+
let breaking = false;
|
|
220
|
+
for (const d of ordered.slice(0, FILES_DETAILED))
|
|
221
|
+
breaking = pushFile(out, index, index.files.get(d.path), d) || breaking;
|
|
222
|
+
if (ordered.length > FILES_DETAILED)
|
|
223
|
+
out.push(`+${ordered.length - FILES_DETAILED} more code files: pass \`path\` to narrow`);
|
|
224
|
+
if (other.length > 0)
|
|
225
|
+
out.push(`Other: ${listed(other.map(d => `${d.path} (${d.status === 'deleted' ? 'deleted' : counts(d)})`), 12)}`);
|
|
226
|
+
pushTests(out, index, ordered.map(d => index.files.get(d.path)));
|
|
227
|
+
if (breaking)
|
|
228
|
+
out.push('Removed or changed exports: runner_sonar { action: "impact", path } shows what else to check.');
|
|
229
|
+
return out.text('pass `path` to narrow');
|
|
230
|
+
}
|