@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,703 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The agent loop's shared rules: why a run stops, the guards that stop it,
|
|
3
|
+
* the texts it feeds back to the model, and how the context stays bounded
|
|
4
|
+
* (a tool result cut as it arrives, one fold into a summary at a ceiling).
|
|
5
|
+
*
|
|
6
|
+
* Part of the agent contract (see `version.ts`), copied verbatim into the
|
|
7
|
+
* runner. The two loops themselves (`server/utils/internal-runtime/loop.ts`
|
|
8
|
+
* and the runner's `packages/runtime/src/runtime/loop.ts`) are NOT one file:
|
|
9
|
+
* they speak different message shapes and host different tools. What has to
|
|
10
|
+
* behave the same in both lives here, so it cannot drift.
|
|
11
|
+
*/
|
|
12
|
+
// ─── Run stopped by the studio ───────────────────────────────────────────────
|
|
13
|
+
/** Marks a tool result that means the studio ended the run (a 410 or 402 from
|
|
14
|
+
* an MCP route). Both loops read it and stop with reason `stopped`. */
|
|
15
|
+
export const RUN_STOPPED_PREFIX = 'Error: [run stopped by the studio] ';
|
|
16
|
+
/** HTTP statuses an MCP route answers to end the run rather than the call:
|
|
17
|
+
* 410 (the task or mission was stopped) and 402 (the task's budget is spent). */
|
|
18
|
+
export const RUN_STOPPED_STATUSES = new Set([410, 402]);
|
|
19
|
+
export function isRunStoppedResult(result) {
|
|
20
|
+
return result.startsWith(RUN_STOPPED_PREFIX);
|
|
21
|
+
}
|
|
22
|
+
/** Why the studio refused a MODEL call with 402 (the task's budget), off the
|
|
23
|
+
* error the transport threw; null for any other error. Both loops end the
|
|
24
|
+
* run on it with stop reason `budget` and still write the handoff. */
|
|
25
|
+
export function budgetStopOf(err) {
|
|
26
|
+
if (!err || typeof err !== 'object')
|
|
27
|
+
return null;
|
|
28
|
+
const e = err;
|
|
29
|
+
if (e.status !== 402 && e.statusCode !== 402)
|
|
30
|
+
return null;
|
|
31
|
+
const text = (typeof e.message === 'string' ? e.message : '').replace(/^Inference request failed: 402[^-]*-?\s*/, '').trim();
|
|
32
|
+
// Over HTTP the studio's answer is a JSON error body: its message is the reason.
|
|
33
|
+
if (text.startsWith('{')) {
|
|
34
|
+
try {
|
|
35
|
+
const body = JSON.parse(text);
|
|
36
|
+
if (typeof body.message === 'string' && body.message)
|
|
37
|
+
return body.message;
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
// A body cut short reads as it is.
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return text || 'The task\'s budget is spent.';
|
|
44
|
+
}
|
|
45
|
+
/** What the handoff call says it is (`purpose` on the inference request): the
|
|
46
|
+
* studio lets ONE through for a run whose budget refused its next call. */
|
|
47
|
+
export const HANDOFF_CALL_PURPOSE = 'handoff';
|
|
48
|
+
// ─── Asking the user ends the turn ───────────────────────────────────────────
|
|
49
|
+
/** The tool that puts a plan to the person in a code session and ends the
|
|
50
|
+
* turn the same way: the plan waits in the chat for their approval. */
|
|
51
|
+
export const PROPOSE_PLAN_TOOL = 'studio_propose_plan';
|
|
52
|
+
/** The tool that decides a waiting plan on the person's word in the chat
|
|
53
|
+
* ("go ahead", "drop it"). A decision that went through ends the turn and
|
|
54
|
+
* says so with this prefix: the session's tools change with it (an approved
|
|
55
|
+
* plan runs on Auto), so the work goes on in a new turn the studio starts. */
|
|
56
|
+
export const APPROVE_PLAN_TOOL = 'studio_approve_plan';
|
|
57
|
+
export const PLAN_DECIDED_PREFIX = 'Plan decided; your turn ends here. ';
|
|
58
|
+
/** The one tool an agent asks a person with. In a task or mission run it opens
|
|
59
|
+
* a decision, and only a BLOCKING one ends the run, its result saying so with
|
|
60
|
+
* this prefix. In a chat the question goes on the person's screen and the
|
|
61
|
+
* turn always ends (`ASKED_IN_CHAT_PREFIX`). */
|
|
62
|
+
export const ASK_TOOL = 'studio_ask';
|
|
63
|
+
export const BLOCKING_DECISION_PREFIX = 'Asked; your run ends here. ';
|
|
64
|
+
/** The result of a `studio_ask` in a chat: the question card is on the
|
|
65
|
+
* person's screen and already is the agent's message there, so the turn ends
|
|
66
|
+
* with no reply. It starts with `BLOCKING_DECISION_PREFIX` so a runner on the
|
|
67
|
+
* older contract still stops on it. */
|
|
68
|
+
export const ASKED_IN_CHAT_PREFIX = BLOCKING_DECISION_PREFIX + 'Your question is on the person\'s screen in this chat. ';
|
|
69
|
+
export function isAskedInChat(result) {
|
|
70
|
+
return result.startsWith(ASKED_IN_CHAT_PREFIX);
|
|
71
|
+
}
|
|
72
|
+
/** The tools whose result can open a blocking decision. */
|
|
73
|
+
export const BLOCKING_DECISION_TOOLS = new Set([ASK_TOOL]);
|
|
74
|
+
/** A `studio_ask` in a chat that put its question on screen, a plan put to
|
|
75
|
+
* the person (`studio_propose_plan`), a plan decided on their word
|
|
76
|
+
* (`studio_approve_plan`), or a call that opened a blocking decision. A
|
|
77
|
+
* refusal comes back as an error or an `Error:` text, so the text decides,
|
|
78
|
+
* not only the flag. */
|
|
79
|
+
export function isQuestionAsked(toolName, outcome) {
|
|
80
|
+
if (outcome.isError || outcome.result.startsWith('Error:'))
|
|
81
|
+
return false;
|
|
82
|
+
if (toolName === PROPOSE_PLAN_TOOL)
|
|
83
|
+
return true;
|
|
84
|
+
if (toolName === APPROVE_PLAN_TOOL)
|
|
85
|
+
return outcome.result.startsWith(PLAN_DECIDED_PREFIX);
|
|
86
|
+
// Covers a chat's `studio_ask` too: `ASKED_IN_CHAT_PREFIX` starts with it.
|
|
87
|
+
return BLOCKING_DECISION_TOOLS.has(toolName) && outcome.result.startsWith(BLOCKING_DECISION_PREFIX);
|
|
88
|
+
}
|
|
89
|
+
/** What a run that stopped on a question leaves as its reply. A chat's
|
|
90
|
+
* question (`studio_ask` answered with `ASKED_IN_CHAT_PREFIX`) already is the
|
|
91
|
+
* agent's message there: nothing. A plan card likewise: nothing.
|
|
92
|
+
* A task's blocking `studio_ask` has no card where its work is followed (the
|
|
93
|
+
* task's timeline, the chat or channel it came from), so the agent speaks
|
|
94
|
+
* there in its own words: what it wrote beside the call, else the question
|
|
95
|
+
* itself. Never a canned line: that is English, the people reading it may not
|
|
96
|
+
* be, and in a channel it reads as a robot talking. */
|
|
97
|
+
export function askedRunReply(toolName, args, narration, result) {
|
|
98
|
+
if (toolName !== ASK_TOOL)
|
|
99
|
+
return '';
|
|
100
|
+
if (result && isAskedInChat(result))
|
|
101
|
+
return '';
|
|
102
|
+
const said = (narration ?? '').trim();
|
|
103
|
+
if (said)
|
|
104
|
+
return said;
|
|
105
|
+
const question = args?.question;
|
|
106
|
+
return typeof question === 'string' ? question.trim() : '';
|
|
107
|
+
}
|
|
108
|
+
// ─── A task run ended from inside ────────────────────────────────────────────
|
|
109
|
+
/** The statuses an agent may set on its OWN running task (`studio_update_task`)
|
|
110
|
+
* that end the run. `in_review` and `waiting` end it like `done`: the work is
|
|
111
|
+
* delivered, and what is left (a sign-off, an answer from outside) is not
|
|
112
|
+
* another round of the loop. */
|
|
113
|
+
export const RUN_ENDING_TASK_STATUSES = ['done', 'in_review', 'waiting', 'cancelled', 'failed'];
|
|
114
|
+
export function isRunEndingTaskStatus(status) {
|
|
115
|
+
return typeof status === 'string' && RUN_ENDING_TASK_STATUSES.includes(status);
|
|
116
|
+
}
|
|
117
|
+
/** The run-ending statuses that DELIVER work, so a structured result that fails
|
|
118
|
+
* its schema refuses them the same way. */
|
|
119
|
+
export function deliversTaskWork(status) {
|
|
120
|
+
return status === 'done' || status === 'in_review' || status === 'waiting';
|
|
121
|
+
}
|
|
122
|
+
/** The run's closing line when the agent ended it with `status` and wrote no
|
|
123
|
+
* reply of its own. */
|
|
124
|
+
export function runEndingReply(status) {
|
|
125
|
+
if (status === 'failed')
|
|
126
|
+
return 'Task failed.';
|
|
127
|
+
if (status === 'in_review')
|
|
128
|
+
return 'Task handed over for review.';
|
|
129
|
+
if (status === 'waiting')
|
|
130
|
+
return 'Task is waiting on somebody outside the team.';
|
|
131
|
+
return 'Task completed.';
|
|
132
|
+
}
|
|
133
|
+
// ─── Loop breakers ───────────────────────────────────────────────────────────
|
|
134
|
+
/** Repeat-call guard: an agent that re-runs the same (toolName, args) call
|
|
135
|
+
* over and over is almost always stuck in a re-fetch loop. After this many
|
|
136
|
+
* identical executions the tool is not run again and a directive goes back
|
|
137
|
+
* instead. Byte-identical args make legit repeats (status polling) virtually
|
|
138
|
+
* never reach it. */
|
|
139
|
+
export const MAX_IDENTICAL_TOOL_CALLS = 3;
|
|
140
|
+
/** A run whose repeat guard had to step in this often, or whose tool calls
|
|
141
|
+
* failed this many times in a row, is going in circles: it ends with stop
|
|
142
|
+
* reason `loop` instead of spending until a cap trips (a cover run once looped
|
|
143
|
+
* to 2.2M tokens). */
|
|
144
|
+
export const MAX_REPEAT_GUARD_HITS = 3;
|
|
145
|
+
export const MAX_TOOL_FAILURES_IN_A_ROW = 8;
|
|
146
|
+
export function repeatGuardKey(toolName, args) {
|
|
147
|
+
let argsKey;
|
|
148
|
+
try {
|
|
149
|
+
argsKey = JSON.stringify(args ?? null);
|
|
150
|
+
}
|
|
151
|
+
catch {
|
|
152
|
+
argsKey = '';
|
|
153
|
+
}
|
|
154
|
+
return `${toolName}|${argsKey}`;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* A task run that goes in circles gets ONE closing round before it stops:
|
|
158
|
+
* finish now, or open a blocker for a person. Only these tools run in it;
|
|
159
|
+
* any other call is answered with a refusal. Without a blocker of its own the
|
|
160
|
+
* studio opens one when the run ends (stop reason `loop`).
|
|
161
|
+
*/
|
|
162
|
+
export const LOOP_CLOSING_TOOLS = new Set([ASK_TOOL, 'studio_update_task']);
|
|
163
|
+
export function loopClosingMessage(reason) {
|
|
164
|
+
return `You are going in circles: ${reason}. This is your LAST round, and only studio_ask and studio_update_task work in it. Either finish now: write what you have as your final reply (and studio_update_task if your task asks for it). Or, when only a person can unblock you, open a blocker: studio_ask({ type: "blocker", blocking: true, question: "...", why: "..." }), in plain words for somebody who was not there, with the technical details in context.`;
|
|
165
|
+
}
|
|
166
|
+
export const LOOP_CLOSING_REFUSAL = 'Not run: in your closing round only studio_ask and studio_update_task work.';
|
|
167
|
+
/**
|
|
168
|
+
* A steer (a message the person sends while the run is busy) cuts the round
|
|
169
|
+
* short at the next tool call: the calls left in it are not run but answered
|
|
170
|
+
* with this, and the steer goes in at the start of the next round. Without it
|
|
171
|
+
* a steer waits for every tool of a batched round, which can be minutes.
|
|
172
|
+
*/
|
|
173
|
+
export const STEER_SKIPPED_RESULT = 'Not run: the person sent you a new message while this round was running, so the rest of the round was left out. Read their message first, then call this again only if it still fits.';
|
|
174
|
+
/**
|
|
175
|
+
* The result for every tool call left in a round that a loop breaker or a
|
|
176
|
+
* studio stop cut short. The provider needs a result for each call of an
|
|
177
|
+
* assistant message; without it the next inference (the closing round, the
|
|
178
|
+
* handoff) throws a missing-tool-result error.
|
|
179
|
+
*/
|
|
180
|
+
export function roundCutResult(kind) {
|
|
181
|
+
const why = kind === 'repeat-guard'
|
|
182
|
+
? 'the run kept repeating the same call after being told to stop'
|
|
183
|
+
: kind === 'failures'
|
|
184
|
+
? 'too many tool calls in a row failed'
|
|
185
|
+
: 'the studio stopped this run';
|
|
186
|
+
return `Not run: ${why}, so the rest of this round was left out.`;
|
|
187
|
+
}
|
|
188
|
+
export function repeatGuardMessage(toolName, count) {
|
|
189
|
+
return `[repeat-call guard] You have already called ${toolName} with these exact args ${count} times this run, so it was not executed again. Its earlier results are still in your context above: read them there. When a result came back cut, fetch only the part you need (offset/limit, a filter, a narrower query, or the saved full output the note names). Pin the key facts with studio_pin, then continue assembling your deliverable from what you already have.`;
|
|
190
|
+
}
|
|
191
|
+
// ─── Forced synthesis ────────────────────────────────────────────────────────
|
|
192
|
+
/** Corrective user message for the forced-synthesis retry: when a round ends
|
|
193
|
+
* with no text and no tool call, this is replayed and one more inference runs
|
|
194
|
+
* with `toolChoice: 'none'`, so the model has no option but to write text. */
|
|
195
|
+
export const FORCE_SYNTHESIS_MESSAGE = 'Your previous turn produced no message and no tool call. Write your reply to the user now, in plain text: answer their question or summarise what you did. Do not call any tools.';
|
|
196
|
+
/** How many times to re-roll the forced-synthesis inference before giving up
|
|
197
|
+
* and salvaging the last narration/reasoning. Thinking models can close a
|
|
198
|
+
* single re-roll inside their reasoning with no text; a couple of retries
|
|
199
|
+
* almost always lands a plain-text reply. */
|
|
200
|
+
export const FORCE_SYNTHESIS_MAX_ATTEMPTS = 3;
|
|
201
|
+
// ─── Tool results: cut once, when they arrive ────────────────────────────────
|
|
202
|
+
/**
|
|
203
|
+
* Two caps on one tool result, depending on whether the run can point back to
|
|
204
|
+
* the whole output. A longer result is cut to its start and end the moment it
|
|
205
|
+
* is appended, and never touched again: the transcript is append-only (see
|
|
206
|
+
* "Keeping the context bounded" below), so every later round reads it from the
|
|
207
|
+
* prompt cache.
|
|
208
|
+
*
|
|
209
|
+
* The cost reasoning (Opus 5.5): what is appended is written to the cache once
|
|
210
|
+
* (1.25x input) and read on every later round (0.05x), so a few thousand more
|
|
211
|
+
* characters kept in the history cost little per round. Running a call again
|
|
212
|
+
* to see what was cut costs a whole extra inference call, which reads the full
|
|
213
|
+
* context (easily 100k tokens). So:
|
|
214
|
+
* - a result the runtime SPILLED (kept whole in a file the agent can read in
|
|
215
|
+
* ranges) is cut hard, `SPILLED_TOOL_RESULT_MAX_CHARS`: the way back is a
|
|
216
|
+
* cheap ranged read of the copy;
|
|
217
|
+
* - a result with no copy (the studio's internal runtime, a browser or editor
|
|
218
|
+
* frontend, a host tool that is not spilled) keeps `TOOL_RESULT_MAX_CHARS`:
|
|
219
|
+
* its only way back is the re-run we want to avoid.
|
|
220
|
+
* An agent's `toolResultTruncateChars` replaces the second and can only lower
|
|
221
|
+
* the first (`toolResultCaps`). A host tool that pages on its own (a file read)
|
|
222
|
+
* keeps its output under `TOOL_RESULT_MAX_CHARS`, so it is never cut in the
|
|
223
|
+
* middle here.
|
|
224
|
+
*/
|
|
225
|
+
export const TOOL_RESULT_MAX_CHARS = 20_000;
|
|
226
|
+
export const SPILLED_TOOL_RESULT_MAX_CHARS = 8_000;
|
|
227
|
+
/** The two caps for an agent: `kept` for a result with no copy, `spilled` for
|
|
228
|
+
* one the runtime saved in full. */
|
|
229
|
+
export function toolResultCaps(override) {
|
|
230
|
+
const kept = override && override > 0 ? override : TOOL_RESULT_MAX_CHARS;
|
|
231
|
+
return { kept, spilled: Math.min(SPILLED_TOOL_RESULT_MAX_CHARS, kept) };
|
|
232
|
+
}
|
|
233
|
+
/** Share of a cut result kept from its start; the rest is its end. The end of
|
|
234
|
+
* a log is where a build or a test run says what went wrong, the start says
|
|
235
|
+
* what it was. */
|
|
236
|
+
const TOOL_RESULT_HEAD_SHARE = 0.75;
|
|
237
|
+
/** How far a cut may move back (or forward) to land on a line break, as a
|
|
238
|
+
* share of the part it shortens. */
|
|
239
|
+
const TOOL_RESULT_LINE_SNAP = 0.2;
|
|
240
|
+
/**
|
|
241
|
+
* Fit a tool result into `maxChars`: unchanged when it fits, else its start
|
|
242
|
+
* and its end around a note that says how much was cut and where the rest is.
|
|
243
|
+
* `fullOutputAt` is where the runtime kept the whole output (a file the agent
|
|
244
|
+
* can read in ranges), or null when it kept none: the note then asks for a
|
|
245
|
+
* narrower call. Pure, so both loops cut the same way.
|
|
246
|
+
*/
|
|
247
|
+
export function truncateToolResult(text, maxChars = TOOL_RESULT_MAX_CHARS, fullOutputAt) {
|
|
248
|
+
if (text.length <= maxChars)
|
|
249
|
+
return text;
|
|
250
|
+
const keep = Math.max(0, maxChars);
|
|
251
|
+
let head = text.slice(0, Math.floor(keep * TOOL_RESULT_HEAD_SHARE));
|
|
252
|
+
let tail = text.slice(text.length - (keep - head.length));
|
|
253
|
+
const headBreak = head.lastIndexOf('\n');
|
|
254
|
+
if (headBreak >= head.length * (1 - TOOL_RESULT_LINE_SNAP))
|
|
255
|
+
head = head.slice(0, headBreak);
|
|
256
|
+
const tailBreak = tail.indexOf('\n');
|
|
257
|
+
if (tailBreak >= 0 && tailBreak <= tail.length * TOOL_RESULT_LINE_SNAP)
|
|
258
|
+
tail = tail.slice(tailBreak + 1);
|
|
259
|
+
const cut = text.length - head.length - tail.length;
|
|
260
|
+
return `${head}\n\n${truncationNote(cut, text.length, fullOutputAt)}\n\n${tail}`;
|
|
261
|
+
}
|
|
262
|
+
function truncationNote(cut, total, fullOutputAt) {
|
|
263
|
+
const what = `[... ${cut} of ${total} characters cut from the middle of this output.`;
|
|
264
|
+
return fullOutputAt
|
|
265
|
+
? `${what} The full output is saved at ${fullOutputAt}: read the part you need with runner_read_file (offset/limit) or search it with runner_grep, instead of running the call again ...]`
|
|
266
|
+
: `${what} Ask for less instead of running it again whole: a filter, a smaller page (limit/offset or the tool's own paging arguments), a narrower query ...]`;
|
|
267
|
+
}
|
|
268
|
+
// ─── Keeping the context bounded ─────────────────────────────────────────────
|
|
269
|
+
//
|
|
270
|
+
// The transcript is APPEND-ONLY. Nothing that was sent is ever rewritten: a
|
|
271
|
+
// large tool result is cut once, as it is appended (`truncateToolResult`), and
|
|
272
|
+
// the run goes on reading its own history from the prompt cache. Two reasons:
|
|
273
|
+
//
|
|
274
|
+
// - Cost. A provider caches the prompt as a prefix; an edit in the middle of
|
|
275
|
+
// the transcript makes everything after it a cache WRITE again. On Opus 5.5
|
|
276
|
+
// a write costs 1.25x input and a read 0.05x, so one write costs as much as
|
|
277
|
+
// 25 reads. The old pass that compacted older tool results every ten rounds
|
|
278
|
+
// made cache writes the larger part of a task's cost.
|
|
279
|
+
// - Preserved thinking. A thinking block (Opus 5.5, Fable 5.1) is bound to the
|
|
280
|
+
// exact history it was produced with: system prompt, tools and every earlier
|
|
281
|
+
// message. An edit in the middle invalidates every later block (its
|
|
282
|
+
// reasoning is lost, or the request is refused with a 400).
|
|
283
|
+
//
|
|
284
|
+
// The one rewrite allowed is the safety net below: once a run's context passes
|
|
285
|
+
// `compactionThresholdTokens`, the WHOLE transcript is folded into one summary
|
|
286
|
+
// and the run continues on a fresh chain (system prompt, the request, the
|
|
287
|
+
// summary) that replays no earlier turn and no earlier thinking block. It runs
|
|
288
|
+
// only between rounds, never with a tool call waiting on its result.
|
|
289
|
+
/** Fallback context-window size (tokens) when the caller does not pass one. */
|
|
290
|
+
export const DEFAULT_CONTEXT_WINDOW_TOKENS = 200_000;
|
|
291
|
+
/** The context (input tokens of the last call) at which a run is folded into a
|
|
292
|
+
* summary, however large the model's window. A 1M window would otherwise let
|
|
293
|
+
* a run grow to 800k before anything happened, and every round pays for what
|
|
294
|
+
* it resends: past this size a fresh chain plus one summary call is cheaper
|
|
295
|
+
* than carrying the history on. */
|
|
296
|
+
export const COMPACTION_CEILING_TOKENS = 150_000;
|
|
297
|
+
/** For a model with a small window, the share of it at which the run folds
|
|
298
|
+
* (the lower of the two thresholds wins). */
|
|
299
|
+
export const COMPACTION_WINDOW_RATIO = 0.75;
|
|
300
|
+
/** Rounds a chain needs before it may be folded: a fresh chain whose request
|
|
301
|
+
* alone is over the threshold must not be folded round after round. */
|
|
302
|
+
export const COMPACTION_MIN_ROUNDS = 2;
|
|
303
|
+
/** Rounds to wait after a fold that failed before trying again. */
|
|
304
|
+
export const COMPACTION_RETRY_ROUNDS = 3;
|
|
305
|
+
/** The context size at which a run is folded, for a model with this window. */
|
|
306
|
+
export function compactionThresholdTokens(windowTokens) {
|
|
307
|
+
const window = windowTokens && windowTokens > 0 ? windowTokens : DEFAULT_CONTEXT_WINDOW_TOKENS;
|
|
308
|
+
return Math.min(COMPACTION_CEILING_TOKENS, Math.floor(window * COMPACTION_WINDOW_RATIO));
|
|
309
|
+
}
|
|
310
|
+
/** Marker opening the summary on a fresh chain, so the model reads it as its
|
|
311
|
+
* own work so far rather than as something the person said. */
|
|
312
|
+
export const SUMMARY_MARKER_PREFIX = '[Your work on this request so far, folded into a summary to stay within the context window. The earlier turns are gone: trust this summary, your Task context and the working set below, and continue from the next step.]';
|
|
313
|
+
/** Asked at the end of the run's own transcript when the run folds on the
|
|
314
|
+
* agent's own model: the same system prompt, tools and history as the last
|
|
315
|
+
* round, so the call is a cache read and every thinking block stays valid. */
|
|
316
|
+
export const COMPACTION_REQUEST_MESSAGE = 'Your context is about to be folded: everything above is replaced by the request you are working on and the summary you write now, so write that summary for yourself. Keep, in priority order: the goal and every constraint on it; the concrete facts you found (ids, slugs, paths, urls, names, numbers, data shapes); decisions and why; what is done (files changed, commits made, messages sent, records written); what failed or turned out to be a dead end; and the exact next step. Terse bullet points under short headings. No tool calls. Output only the summary.';
|
|
317
|
+
/** System prompt for the fold on a separate compaction model, which reads the
|
|
318
|
+
* transcript without the agent's reasoning (another model cannot read it). */
|
|
319
|
+
export const SUMMARIZE_SYSTEM_PROMPT = 'You are compacting an agent\'s working conversation because it no longer fits in its context window. Everything below is about to be replaced by your summary, so write a dense, faithful summary of what the agent needs to keep working. Preserve, in priority order: the original task and every constraint on it; concrete facts discovered (ids, slugs, paths, URLs, names, numbers, data shapes); decisions made and why; actions already completed and their outcomes; errors and dead ends already hit (so they are not repeated); and the exact next step. Drop chit-chat and reasoning that led nowhere. Use terse bullet points under short headings. Output ONLY the summary, no preamble.';
|
|
320
|
+
/** The turn that closes the transcript for the separate compaction model.
|
|
321
|
+
* Without it the transcript ends on a tool result: with tools off the model
|
|
322
|
+
* reads that as its own turn to continue, finds nothing to say and stops
|
|
323
|
+
* without text (an empty fold, the run goes on at full context). */
|
|
324
|
+
export const SUMMARIZE_REQUEST_MESSAGE = 'The conversation above is the transcript to compact. Do not continue it and do not call tools: write the summary now, as instructed.';
|
|
325
|
+
/** Tools that write a file, and the argument naming it. */
|
|
326
|
+
const FILE_WRITING_TOOLS = { runner_write_file: 'path', runner_edit_file: 'path' };
|
|
327
|
+
/** Tools that read a file (or part of one: a symbol, an outline), and the argument naming it. */
|
|
328
|
+
const FILE_READING_TOOLS = { runner_read_file: 'path', runner_outline: 'path' };
|
|
329
|
+
function filePathArg(input, key) {
|
|
330
|
+
const v = input?.[key];
|
|
331
|
+
return typeof v === 'string' && v ? v.replace(/^\.\//, '') : null;
|
|
332
|
+
}
|
|
333
|
+
/** Assistant rounds in a chain: how much work a fold would cover. */
|
|
334
|
+
export function roundsInChain(messages) {
|
|
335
|
+
return messages.filter(m => m.role === 'assistant').length;
|
|
336
|
+
}
|
|
337
|
+
/** True while the last assistant turn has a tool call without its result: a
|
|
338
|
+
* fold must never cut there (the call's thinking would go back without it). */
|
|
339
|
+
export function hasOpenToolCall(messages) {
|
|
340
|
+
let last = -1;
|
|
341
|
+
for (let i = messages.length - 1; i >= 0; i--) {
|
|
342
|
+
if (messages[i]?.role === 'assistant') {
|
|
343
|
+
last = i;
|
|
344
|
+
break;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
if (last === -1)
|
|
348
|
+
return false;
|
|
349
|
+
const content = messages[last]?.content;
|
|
350
|
+
if (!Array.isArray(content))
|
|
351
|
+
return false;
|
|
352
|
+
const open = new Set(content
|
|
353
|
+
.filter(p => p.type === 'tool-call' && typeof p.toolCallId === 'string')
|
|
354
|
+
.map(p => p.toolCallId));
|
|
355
|
+
for (const m of messages.slice(last + 1)) {
|
|
356
|
+
if (m.role !== 'tool' || !Array.isArray(m.content))
|
|
357
|
+
continue;
|
|
358
|
+
for (const p of m.content) {
|
|
359
|
+
if (p.type === 'tool-result' && typeof p.toolCallId === 'string')
|
|
360
|
+
open.delete(p.toolCallId);
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
return open.size > 0;
|
|
364
|
+
}
|
|
365
|
+
/** The transcript without its reasoning parts, for a model that did not write
|
|
366
|
+
* them. An assistant turn left with nothing is dropped. */
|
|
367
|
+
export function withoutReasoning(messages) {
|
|
368
|
+
const out = [];
|
|
369
|
+
for (const m of messages) {
|
|
370
|
+
if (m.role !== 'assistant' || !Array.isArray(m.content)) {
|
|
371
|
+
out.push(m);
|
|
372
|
+
continue;
|
|
373
|
+
}
|
|
374
|
+
const parts = m.content.filter(p => p.type !== 'reasoning' && p.type !== 'redacted-reasoning');
|
|
375
|
+
if (parts.length)
|
|
376
|
+
out.push({ ...m, content: parts });
|
|
377
|
+
}
|
|
378
|
+
return out;
|
|
379
|
+
}
|
|
380
|
+
/**
|
|
381
|
+
* What the run has worked with, read off its transcript: the files it read
|
|
382
|
+
* (with the ranges), searched and changed. A summary written by a model drops
|
|
383
|
+
* exactly these, and then the agent reads the same files again from the top.
|
|
384
|
+
* Empty when there is nothing to list.
|
|
385
|
+
*/
|
|
386
|
+
export function workingSetLedger(messages) {
|
|
387
|
+
const read = new Map();
|
|
388
|
+
const changed = new Set();
|
|
389
|
+
const searched = new Set();
|
|
390
|
+
const commands = new Set();
|
|
391
|
+
for (const m of messages) {
|
|
392
|
+
if (m.role !== 'assistant' || !Array.isArray(m.content))
|
|
393
|
+
continue;
|
|
394
|
+
for (const part of m.content) {
|
|
395
|
+
if (part.type !== 'tool-call' || !part.toolName)
|
|
396
|
+
continue;
|
|
397
|
+
const input = (part.input ?? {});
|
|
398
|
+
const writeKey = FILE_WRITING_TOOLS[part.toolName];
|
|
399
|
+
const readKey = FILE_READING_TOOLS[part.toolName];
|
|
400
|
+
if (writeKey) {
|
|
401
|
+
const path = filePathArg(input, writeKey);
|
|
402
|
+
if (path)
|
|
403
|
+
changed.add(path);
|
|
404
|
+
}
|
|
405
|
+
else if (readKey) {
|
|
406
|
+
const path = filePathArg(input, readKey);
|
|
407
|
+
if (!path)
|
|
408
|
+
continue;
|
|
409
|
+
const from = typeof input.offset === 'number' ? input.offset + 1 : 1;
|
|
410
|
+
const range = part.toolName === 'runner_outline'
|
|
411
|
+
? 'outline'
|
|
412
|
+
: typeof input.symbol === 'string' && input.symbol
|
|
413
|
+
? `symbol ${input.symbol}`
|
|
414
|
+
: typeof input.limit === 'number' ? `${from}-${from + input.limit - 1}` : from > 1 ? `${from}-` : 'whole';
|
|
415
|
+
const ranges = read.get(path) ?? new Set();
|
|
416
|
+
ranges.add(range);
|
|
417
|
+
read.set(path, ranges);
|
|
418
|
+
}
|
|
419
|
+
else if ((part.toolName === 'runner_grep' || part.toolName === 'runner_glob') && typeof input.pattern === 'string') {
|
|
420
|
+
searched.add(`${part.toolName === 'runner_grep' ? 'grep' : 'glob'} ${input.pattern}${typeof input.glob === 'string' ? ` (${input.glob})` : ''}`);
|
|
421
|
+
}
|
|
422
|
+
else if (part.toolName === 'runner_run_command' && typeof input.command === 'string') {
|
|
423
|
+
const cmd = input.command.length > 120 ? `${input.command.slice(0, 120)}...` : input.command;
|
|
424
|
+
commands.delete(cmd);
|
|
425
|
+
commands.add(cmd);
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
const lines = [];
|
|
430
|
+
if (changed.size)
|
|
431
|
+
lines.push(`Files you changed: ${[...changed].join(', ')}`);
|
|
432
|
+
if (read.size)
|
|
433
|
+
lines.push(`Files you read (lines, symbols, outlines): ${[...read].map(([p, r]) => `${p} (${[...r].join(', ')})`).join('; ')}`);
|
|
434
|
+
if (searched.size)
|
|
435
|
+
lines.push(`Searches you ran: ${[...searched].slice(-20).join('; ')}`);
|
|
436
|
+
if (commands.size)
|
|
437
|
+
lines.push(`Commands you ran (latest last): ${[...commands].slice(-15).map(c => `\`${c}\``).join('; ')}`);
|
|
438
|
+
if (!lines.length)
|
|
439
|
+
return '';
|
|
440
|
+
return `\n\nWorking set so far (re-read only the part you need, with offset/limit):\n${lines.map(l => `- ${l}`).join('\n')}`;
|
|
441
|
+
}
|
|
442
|
+
/**
|
|
443
|
+
* Fold a chain into the one message a fresh chain starts with after its system
|
|
444
|
+
* prompt: the request the run is working on (`ask`, verbatim), then the
|
|
445
|
+
* summary and the working set. Null when the fold failed (the run goes on as
|
|
446
|
+
* it was) or would cut a tool round.
|
|
447
|
+
*
|
|
448
|
+
* On the agent's own model the summary is asked at the end of the run's own
|
|
449
|
+
* transcript, with the round's own tools and tool choice: a cache read, and
|
|
450
|
+
* every thinking block in it stays valid. Only when that comes back without
|
|
451
|
+
* text (the model reached for a tool) is it asked once more with tools off.
|
|
452
|
+
* On a separate compaction model (`separateModel`) the transcript goes without
|
|
453
|
+
* the agent's reasoning under the summarizer's own system prompt: that model
|
|
454
|
+
* has no cache of this run to read anyway. It ends on an explicit request
|
|
455
|
+
* (`SUMMARIZE_REQUEST_MESSAGE`) and is asked once more when it comes back empty.
|
|
456
|
+
*
|
|
457
|
+
* `earlier` is what earlier folds already replaced, so the working set still
|
|
458
|
+
* names the files of the whole run.
|
|
459
|
+
*/
|
|
460
|
+
export async function foldTranscript(opts) {
|
|
461
|
+
const { messages, ask, separateModel, summarize } = opts;
|
|
462
|
+
if (hasOpenToolCall(messages))
|
|
463
|
+
return null;
|
|
464
|
+
let summary;
|
|
465
|
+
try {
|
|
466
|
+
if (separateModel) {
|
|
467
|
+
const request = [
|
|
468
|
+
{ role: 'system', content: SUMMARIZE_SYSTEM_PROMPT },
|
|
469
|
+
...withoutReasoning(messages.slice(1)),
|
|
470
|
+
{ role: 'user', content: SUMMARIZE_REQUEST_MESSAGE },
|
|
471
|
+
];
|
|
472
|
+
summary = ((await summarize(request, true)) ?? '').trim();
|
|
473
|
+
if (!summary)
|
|
474
|
+
summary = ((await summarize(request, true)) ?? '').trim();
|
|
475
|
+
}
|
|
476
|
+
else {
|
|
477
|
+
const request = [...messages, { role: 'user', content: COMPACTION_REQUEST_MESSAGE }];
|
|
478
|
+
summary = ((await summarize(request, false)) ?? '').trim();
|
|
479
|
+
if (!summary)
|
|
480
|
+
summary = ((await summarize(request, true)) ?? '').trim();
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
catch {
|
|
484
|
+
return null; // best-effort: a failed fold never breaks the run
|
|
485
|
+
}
|
|
486
|
+
if (!summary)
|
|
487
|
+
return null;
|
|
488
|
+
const block = `${SUMMARY_MARKER_PREFIX}\n${summary}${workingSetLedger([...(opts.earlier ?? []), ...messages])}`;
|
|
489
|
+
if (!ask)
|
|
490
|
+
return { role: 'user', content: block };
|
|
491
|
+
if (Array.isArray(ask.content))
|
|
492
|
+
return { role: 'user', content: [...ask.content, { type: 'text', text: block }] };
|
|
493
|
+
return { role: 'user', content: `${typeof ask.content === 'string' ? ask.content : ''}\n\n${block}` };
|
|
494
|
+
}
|
|
495
|
+
/** Handle an in-loop `studio_compact` call for a task run. A task has no
|
|
496
|
+
* persisted conversation to archive (its working context is the loop's
|
|
497
|
+
* in-memory transcript), so the call schedules a fold of that transcript
|
|
498
|
+
* before the next round; folding right here would cut the tool round the call
|
|
499
|
+
* itself is part of. */
|
|
500
|
+
export function scheduleInMemoryCompaction(messages) {
|
|
501
|
+
if (roundsInChain(messages) < COMPACTION_MIN_ROUNDS) {
|
|
502
|
+
return { scheduled: false, reply: 'Nothing to compact yet: the transcript is still short. A long run is folded into a summary on its own once its context gets large, so you can keep working.' };
|
|
503
|
+
}
|
|
504
|
+
return { scheduled: true, reply: 'Your working context will be folded into a summary before your next step: after that you have the system prompt (with your Task context and pins), the request and that summary, and none of the earlier turns. Pin anything you must keep word for word with studio_pin in this same step.' };
|
|
505
|
+
}
|
|
506
|
+
// ─── Handing a run over ──────────────────────────────────────────────────────
|
|
507
|
+
/** Ends after which the task is not done and the next run would start over
|
|
508
|
+
* from the brief. Not `aborted` (a person stopped it: nobody asked for more
|
|
509
|
+
* spending), not `stopped` (the task was cancelled), and not an end the agent
|
|
510
|
+
* chose itself (`hook-stop`, `reply`; a run handed for review writes the
|
|
511
|
+
* short review variant instead, `HANDOFF_REVIEW_MESSAGE`). */
|
|
512
|
+
export const HANDOFF_STOP_REASONS = new Set(['max-rounds', 'max-loop-ms', 'max-cost', 'loop', 'empty', 'awaiting-user', 'budget']);
|
|
513
|
+
/** Most the handoff notes may take on the next run's prompt. */
|
|
514
|
+
export const HANDOFF_MAX_CHARS = 6_000;
|
|
515
|
+
/** Most the notes of a run handed for review may take. */
|
|
516
|
+
export const HANDOFF_REVIEW_MAX_CHARS = 2_000;
|
|
517
|
+
/** For a run that handed its work for review: what the reviewer, and the run
|
|
518
|
+
* after their feedback, need so neither reads the whole run again. */
|
|
519
|
+
export const HANDOFF_REVIEW_MESSAGE = 'Your work goes to review now. Whoever reviews it, and the run that picks up their feedback, will NOT see this conversation, so write short notes for them: what you built or changed, the commits, the files and functions where the core of it is (path:line), how you checked it, and anything the reviewer should look at closely. At most 15 terse bullet points. No tool calls.';
|
|
520
|
+
/** The reply of a budget stop when the run wrote none of its own. */
|
|
521
|
+
export const BUDGET_STOP_REPLY = 'Stopped at the task\'s budget; the handoff notes say where the work is.';
|
|
522
|
+
/** The same request for a run that stopped on a blocking question: the next
|
|
523
|
+
* run starts once it is answered, with the question and the answer. */
|
|
524
|
+
export const HANDOFF_AWAITING_MESSAGE = 'This run ends now: you asked a question and the task waits for the answer. Whoever picks it up after the answer starts from the brief, the question and the answer, and will NOT see this conversation, so write handoff notes for them: what is done (files changed, commits made), what you established (facts, paths, ids, commands that work), what is still left and how the answer changes it. Terse bullet points under short headings. No tool calls.';
|
|
525
|
+
export const HANDOFF_REQUEST_MESSAGE = 'This run is ending now, before the task is done. Whoever picks the task up next starts from the brief and will NOT see this conversation, so write handoff notes for them: what is done (files changed, commits made), what you established (facts, paths, ids, commands that work), what is still left, and what failed or turned out to be a dead end. Terse bullet points under short headings. No tool calls.';
|
|
526
|
+
/**
|
|
527
|
+
* Handoff notes for a task run that ends without delivering: one more round
|
|
528
|
+
* on the same transcript (so it is mostly a cache read) asking the agent what
|
|
529
|
+
* the next run needs, plus the working set read off the transcript. A failed
|
|
530
|
+
* run used to hand the next one nothing but its last 30 activity lines, and the
|
|
531
|
+
* next run re-read every file from the top. `ask` makes the call, first with
|
|
532
|
+
* the chain's own tools and tool choice: anything else is another prefix (with
|
|
533
|
+
* tool use off the request carries no tools at all), and the whole run is
|
|
534
|
+
* written to the cache again for one closing call. Only when that comes back
|
|
535
|
+
* without text (the model reached for a tool anyway) is it asked once more
|
|
536
|
+
* with tool use off, like `foldTranscript`. A call that fails still leaves the
|
|
537
|
+
* working set. `earlier` is what a
|
|
538
|
+
* fold into a summary already replaced, so the working set covers the whole
|
|
539
|
+
* run. Null when the end is not one that needs a handoff, or there is nothing
|
|
540
|
+
* to say.
|
|
541
|
+
*/
|
|
542
|
+
export async function writeRunHandoff(messages, stopReason, ask, earlier = [], variant = 'handoff') {
|
|
543
|
+
if (variant === 'handoff' && !HANDOFF_STOP_REASONS.has(stopReason))
|
|
544
|
+
return null;
|
|
545
|
+
const ledger = workingSetLedger([...earlier, ...messages]);
|
|
546
|
+
let notes = '';
|
|
547
|
+
try {
|
|
548
|
+
const request = variant === 'review' ? HANDOFF_REVIEW_MESSAGE : stopReason === 'awaiting-user' ? HANDOFF_AWAITING_MESSAGE : HANDOFF_REQUEST_MESSAGE;
|
|
549
|
+
const asked = [...messages, { role: 'user', content: request }];
|
|
550
|
+
notes = ((await ask(asked, false)) ?? '').trim();
|
|
551
|
+
if (!notes)
|
|
552
|
+
notes = ((await ask(asked, true)) ?? '').trim();
|
|
553
|
+
}
|
|
554
|
+
catch {
|
|
555
|
+
// The working set alone is still worth handing over.
|
|
556
|
+
}
|
|
557
|
+
if (!notes && !ledger)
|
|
558
|
+
return null;
|
|
559
|
+
const max = variant === 'review' ? HANDOFF_REVIEW_MAX_CHARS : HANDOFF_MAX_CHARS;
|
|
560
|
+
const text = `${notes || '(The run wrote no notes of its own.)'}${ledger}`;
|
|
561
|
+
return text.length > max ? `${text.slice(0, max)}\n[... handoff cut]` : text;
|
|
562
|
+
}
|
|
563
|
+
// ─── Reading in parallel ─────────────────────────────────────────────────────
|
|
564
|
+
/** Runner tools that only read the checkout. */
|
|
565
|
+
export const READ_ONLY_RUNNER_TOOLS = [
|
|
566
|
+
'runner_read_file',
|
|
567
|
+
'runner_outline',
|
|
568
|
+
'runner_sonar',
|
|
569
|
+
'runner_grep',
|
|
570
|
+
'runner_glob',
|
|
571
|
+
'runner_list_directory',
|
|
572
|
+
'runner_git_status',
|
|
573
|
+
'runner_git_log',
|
|
574
|
+
'runner_git_diff',
|
|
575
|
+
'runner_git_tag_draft',
|
|
576
|
+
];
|
|
577
|
+
/** Studio tools that only read although their route is not a GET. */
|
|
578
|
+
export const READ_ONLY_STUDIO_TOOLS = [
|
|
579
|
+
'studio_context',
|
|
580
|
+
'studio_web_search',
|
|
581
|
+
'studio_fetch_webpage',
|
|
582
|
+
'studio_read_attachment',
|
|
583
|
+
'studio_view_image',
|
|
584
|
+
'studio_image_info',
|
|
585
|
+
];
|
|
586
|
+
/**
|
|
587
|
+
* True when a tool only reads, so the loop may run it beside the other reads
|
|
588
|
+
* of the same round: a model that asks for six files at once gets them at
|
|
589
|
+
* once, like a person opening six tabs. A studio tool behind a GET route
|
|
590
|
+
* reads by definition. Never `studio_load_toolset` (it changes the tool list)
|
|
591
|
+
* nor the tools the loop handles itself (`studio_pin`, `studio_compact`).
|
|
592
|
+
*/
|
|
593
|
+
export function isReadOnlyTool(tool) {
|
|
594
|
+
if (tool.name.startsWith('runner_'))
|
|
595
|
+
return READ_ONLY_RUNNER_TOOLS.includes(tool.name);
|
|
596
|
+
if (READ_ONLY_STUDIO_TOOLS.includes(tool.name))
|
|
597
|
+
return true;
|
|
598
|
+
return tool.name.startsWith('studio_') && tool.name !== 'studio_load_toolset' && tool.mcpMethod?.toUpperCase() === 'GET';
|
|
599
|
+
}
|
|
600
|
+
/**
|
|
601
|
+
* Which calls of a round start at once, side by side: the read-only calls
|
|
602
|
+
* before the first call that changes something (a read after an edit must
|
|
603
|
+
* see the edit), that the repeat guard would let through, and only when there
|
|
604
|
+
* are two or more. Calls the loop handles itself are stepped over. Indexes
|
|
605
|
+
* into `calls`; the loop still appends every result in order.
|
|
606
|
+
*/
|
|
607
|
+
export function earlyReadIndexes(calls, lookup, priorCounts, stopAt = calls.length) {
|
|
608
|
+
const out = [];
|
|
609
|
+
const counts = new Map(priorCounts);
|
|
610
|
+
for (let i = 0; i < Math.min(calls.length, stopAt); i++) {
|
|
611
|
+
const call = calls[i];
|
|
612
|
+
if (call.name === 'studio_pin' || call.name === 'studio_compact')
|
|
613
|
+
continue;
|
|
614
|
+
const def = lookup(call.name);
|
|
615
|
+
if (!def || !isReadOnlyTool(def))
|
|
616
|
+
break;
|
|
617
|
+
const key = repeatGuardKey(call.name, call.arguments);
|
|
618
|
+
const n = counts.get(key) ?? 0;
|
|
619
|
+
counts.set(key, n + 1);
|
|
620
|
+
if (n < MAX_IDENTICAL_TOOL_CALLS)
|
|
621
|
+
out.push(i);
|
|
622
|
+
}
|
|
623
|
+
return out.length > 1 ? out : [];
|
|
624
|
+
}
|
|
625
|
+
// ─── Pinning what you found ──────────────────────────────────────────────────
|
|
626
|
+
/** Reads in a task run without one pin, after which the run is reminded once. */
|
|
627
|
+
export const PIN_NUDGE_AFTER_READS = 8;
|
|
628
|
+
/** A step that reads the checkout or a page: what the nudge counts. */
|
|
629
|
+
export function isReadStep(name) {
|
|
630
|
+
return READ_ONLY_RUNNER_TOOLS.includes(name) || name === 'studio_fetch_webpage' || name === 'studio_read_attachment';
|
|
631
|
+
}
|
|
632
|
+
/** Appended once to a read's result in a task run that read a lot and pinned nothing. */
|
|
633
|
+
export const PIN_NUDGE_NOTE = '\n\n[Studio] You have read a lot without pinning anything. Pin what you established so far with studio_pin (path, function, what you found): pins survive a fold into a summary and carry over to the next run of this task, so nothing has to be read twice.';
|
|
634
|
+
// ─── Keeping the todo list current ───────────────────────────────────────────
|
|
635
|
+
/** Tool calls since the last `studio_manage_todos` after which a run with open todos is reminded. */
|
|
636
|
+
export const TODO_NUDGE_AFTER_CALLS = 6;
|
|
637
|
+
/** Reminders per run at most: a run that ignores them is not kept busy with them. */
|
|
638
|
+
export const MAX_TODO_NUDGES = 3;
|
|
639
|
+
/** Calls that do not count as work towards the todo reminder. */
|
|
640
|
+
export function countsForTodoNudge(name) {
|
|
641
|
+
return name !== 'studio_manage_todos' && name !== 'studio_pin' && name !== 'studio_compact';
|
|
642
|
+
}
|
|
643
|
+
/** The todos passed to a `studio_manage_todos` call, or null when the arguments hold none. */
|
|
644
|
+
export function todosFromArgs(args) {
|
|
645
|
+
const todos = args?.todos;
|
|
646
|
+
return Array.isArray(todos) ? todos.filter((t) => !!t && typeof t === 'object') : null;
|
|
647
|
+
}
|
|
648
|
+
/**
|
|
649
|
+
* The note appended to a tool result when the run's todo list still has open
|
|
650
|
+
* items and has not changed for `TODO_NUDGE_AFTER_CALLS` calls; null when
|
|
651
|
+
* every item is completed (nothing to remind of).
|
|
652
|
+
*/
|
|
653
|
+
export function todoNudgeNote(todos) {
|
|
654
|
+
const open = todos.filter(t => t.status !== 'completed');
|
|
655
|
+
if (open.length === 0)
|
|
656
|
+
return null;
|
|
657
|
+
const current = todos.find(t => t.status === 'in-progress');
|
|
658
|
+
const title = typeof current?.title === 'string' ? current.title.slice(0, 80) : null;
|
|
659
|
+
const head = title
|
|
660
|
+
? `Your todo list still shows "${title}" in progress (${open.length} of ${todos.length} open)`
|
|
661
|
+
: `Your todo list has ${open.length} of ${todos.length} items open and none in progress`;
|
|
662
|
+
return `\n\n[Studio] ${head} and has not changed for a while. Update it with studio_manage_todos in this round: tick off what is done, set the next item in progress.`;
|
|
663
|
+
}
|
|
664
|
+
/**
|
|
665
|
+
* The note that holds back a run closing (a final reply, or a task set to
|
|
666
|
+
* `done` / `in_review`) while its todo list still has open items: review the
|
|
667
|
+
* list, then either do what is left or tick it off. Null when every item is
|
|
668
|
+
* completed (or there is no list).
|
|
669
|
+
*/
|
|
670
|
+
export function openTodosAtEndNote(todos) {
|
|
671
|
+
const open = (todos ?? []).filter(t => t.status !== 'completed');
|
|
672
|
+
if (open.length === 0)
|
|
673
|
+
return null;
|
|
674
|
+
const titles = open.slice(0, 8).map(t => `- ${typeof t.title === 'string' ? t.title.slice(0, 80) : '(untitled)'}`);
|
|
675
|
+
if (open.length > 8)
|
|
676
|
+
titles.push(`- ... and ${open.length - 8} more`);
|
|
677
|
+
return `[Studio] You are closing while your todo list still has ${open.length} of ${todos.length} items open:\n${titles.join('\n')}\nReview them before you close. Is one of them still work to do? Do it now. Is it done, or no longer needed? Update the list with studio_manage_todos (tick off what is done, remove what was dropped), then close again.`;
|
|
678
|
+
}
|
|
679
|
+
/**
|
|
680
|
+
* A reply that ends by announcing a step it did not take ("Commit toch.",
|
|
681
|
+
* "I'll run the tests now."): the run would end on it and the task go to
|
|
682
|
+
* `done` with the work undone. Looks at the LAST sentence or line only.
|
|
683
|
+
* Returns that sentence, or null when the reply reads as finished.
|
|
684
|
+
*/
|
|
685
|
+
const PENDING_ACTION_RE = /^(?:(?:i(?:'ll| will| am going to|'m going to)|let me|let's|next,?|now,?|first,?|ik ga|ik zal|nu|straks|eerst|daarna)\b.*\b(?:commit|push|run|test|fix|write|create|update|add|check|try|doe|draai|maak|schrijf|werk|pas|voer)\w*|(?:commit|push|run|test|fix|write|create|update|deploy|draai|schrijf|maak|voer)\w*\b.*\b(?:toch|now|nu|next|alsnog|first|eerst)|(?:commit|push|run|deploy|draai|doe)\b.*)$/i;
|
|
686
|
+
const DONE_MARKER_RE = /\b(?:committed|pushed|done|finished|completed|gecommit|gepusht|klaar|afgerond|gedaan|green|groen)\b|\b[0-9a-f]{7,40}\b/i;
|
|
687
|
+
export function pendingActionInReply(reply) {
|
|
688
|
+
const text = reply.trim();
|
|
689
|
+
if (!text)
|
|
690
|
+
return null;
|
|
691
|
+
const lines = text.split(/\n+/).map(l => l.trim()).filter(Boolean);
|
|
692
|
+
const lastLine = lines[lines.length - 1] ?? '';
|
|
693
|
+
const sentences = lastLine.split(/(?<=[.!?])\s+/).map(s => s.trim()).filter(Boolean);
|
|
694
|
+
const last = (sentences[sentences.length - 1] ?? '').replace(/^[-*>\s]+/, '');
|
|
695
|
+
if (!last || last.length > 240)
|
|
696
|
+
return null;
|
|
697
|
+
if (DONE_MARKER_RE.test(last))
|
|
698
|
+
return null;
|
|
699
|
+
return PENDING_ACTION_RE.test(last.replace(/[.!:]+$/, '')) ? last : null;
|
|
700
|
+
}
|
|
701
|
+
export function pendingActionNudge(action) {
|
|
702
|
+
return `[Studio] Your reply ends by announcing a step ("${action}") but you called no tool. Do it now with a tool call, or say in your reply why not.`;
|
|
703
|
+
}
|