savant-code 0.0.19 → 0.0.21
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/README.md +402 -550
- package/{cli/release/index.js → index.js} +0 -0
- package/{cli/release-core/launcher.js → launcher.js} +138 -32
- package/package.json +44 -71
- package/.agents/skills/coding-csharp/SKILL.md +0 -82
- package/.agents/skills/coding-go/SKILL.md +0 -76
- package/.agents/skills/coding-java/SKILL.md +0 -79
- package/.agents/skills/coding-python/SKILL.md +0 -87
- package/.agents/skills/coding-rust/SKILL.md +0 -83
- package/.agents/skills/coding-typescript/SKILL.md +0 -90
- package/.agents/skills/release-workflow/SKILL.md +0 -69
- package/.bun-version +0 -1
- package/.commandcode/settings.json +0 -11
- package/.commandcode/taste/workflow/taste.md +0 -6
- package/.env.example +0 -95
- package/.gitattributes +0 -43
- package/.githooks/pre-push +0 -35
- package/.github/workflows/build-release-binaries.yml +0 -163
- package/.markdownlint.json +0 -42
- package/.markdownlintignore +0 -21
- package/.prettierignore +0 -9
- package/.prettierrc +0 -23
- package/.savantignore +0 -3
- package/AGENTS.md +0 -97
- package/ARCHITECTURE.md +0 -241
- package/CHANGELOG.md +0 -2631
- package/CONTRIBUTING.md +0 -88
- package/ECHO-freebuff.md +0 -22
- package/ECHO.md +0 -722
- package/FREEREADME.md +0 -35
- package/LEARNINGS.md +0 -345
- package/NOTICE +0 -15
- package/README.zh-CN.md +0 -479
- package/SECURITY.md +0 -8
- package/VERSION +0 -1
- package/WINDOWS.md +0 -238
- package/agents/README.md +0 -41
- package/agents/base-chat.ts +0 -44
- package/agents/basher.ts +0 -107
- package/agents/browser-use/browser-use.test.ts +0 -211
- package/agents/browser-use/browser-use.ts +0 -259
- package/agents/constants.ts +0 -1
- package/agents/context-pruner.ts +0 -1076
- package/agents/detective/detective.ts +0 -168
- package/agents/editor/best-of-n/best-of-n-selector2.ts +0 -148
- package/agents/editor/best-of-n/editor-implementor-gpt-5.ts +0 -7
- package/agents/editor/best-of-n/editor-implementor-opus.ts +0 -7
- package/agents/editor/best-of-n/editor-implementor.ts +0 -196
- package/agents/editor/best-of-n/editor-multi-prompt.ts +0 -265
- package/agents/file-explorer/directory-lister.ts +0 -92
- package/agents/file-explorer/glob-matcher.ts +0 -96
- package/agents/forge/forge.ts +0 -146
- package/agents/librarian/librarian.test.ts +0 -289
- package/agents/librarian/librarian.ts +0 -158
- package/agents/package.json +0 -11
- package/agents/recorder/recorder.ts +0 -104
- package/agents/researcher/researcher-docs.ts +0 -32
- package/agents/researcher/researcher-web.ts +0 -40
- package/agents/savant/savant-analyze.ts +0 -11
- package/agents/savant/savant-free-deepseek-flash.ts +0 -13
- package/agents/savant/savant-free-deepseek.ts +0 -13
- package/agents/savant/savant-free-evals.ts +0 -9
- package/agents/savant/savant-free-glm.ts +0 -13
- package/agents/savant/savant-free-kimi.ts +0 -13
- package/agents/savant/savant-free-mimo-pro.ts +0 -13
- package/agents/savant/savant-free-mimo.ts +0 -13
- package/agents/savant/savant-free-minimax-m3.ts +0 -13
- package/agents/savant/savant-free.ts +0 -9
- package/agents/savant/savant-scaffold.ts +0 -15
- package/agents/savant/savant.ts +0 -706
- package/agents/scout/scout.ts +0 -305
- package/agents/scribe/scribe.ts +0 -54
- package/agents/thinker/thinker-gemini.ts +0 -26
- package/agents/thinker/thinker-gpt.ts +0 -21
- package/agents/thinker/thinker-with-files-gemini.ts +0 -66
- package/agents/thinker/thinker.ts +0 -99
- package/agents/tmux-cli.ts +0 -724
- package/agents/tsconfig.json +0 -12
- package/agents/types/agent-definition.ts +0 -1
- package/agents/types/secret-agent-definition.ts +0 -103
- package/agents/types/tools.ts +0 -465
- package/agents/types/util-types.ts +0 -167
- package/agents/verifier/verifier.ts +0 -80
- package/art/savant-redesign.md +0 -7
- package/art/savant-text-graf.md +0 -5
- package/art/savant_ascii.md +0 -88
- package/assets/banner.png +0 -0
- package/bun.lock +0 -1979
- package/bunfig.toml +0 -7
- package/cli/README.md +0 -111
- package/cli/bunfig.toml +0 -2
- package/cli/cli_exit +0 -1
- package/cli/package.json +0 -66
- package/cli/release/README.md +0 -348
- package/cli/release/package.json +0 -56
- package/cli/release-core/README.md +0 -20
- package/cli/release-core/package.json +0 -4
- package/cli/release-core/prepare-package.js +0 -31
- package/cli/release-staging/README.md +0 -70
- package/cli/release-staging/index.js +0 -42
- package/cli/release-staging/package.json +0 -43
- package/cli/scripts/build-binary.ts +0 -469
- package/cli/scripts/clean.ts +0 -16
- package/cli/scripts/prebuild-agents.ts +0 -250
- package/cli/scripts/release.ts +0 -103
- package/cli/scripts/smoke-binary.ts +0 -280
- package/cli/scripts/test-sdk-file-hooks.sh +0 -87
- package/cli/scripts/validate-cli-with-tmux.sh +0 -43
- package/cli/src/__tests__/README.md +0 -256
- package/cli/src/__tests__/bash-mode.test.ts +0 -442
- package/cli/src/__tests__/cli-args.test.ts +0 -241
- package/cli/src/__tests__/e2e/first-time-login.test.ts +0 -173
- package/cli/src/__tests__/e2e/logout-relogin-flow.test.ts +0 -110
- package/cli/src/__tests__/e2e/returning-user-auth.test.ts +0 -111
- package/cli/src/__tests__/e2e-cli.test.ts +0 -185
- package/cli/src/__tests__/helpers/mock-api-client.ts +0 -64
- package/cli/src/__tests__/helpers/terminal-watchdog-fixture.ts +0 -50
- package/cli/src/__tests__/home-directory-detection.test.ts +0 -213
- package/cli/src/__tests__/integration/agent-toolnames-validation.test.ts +0 -63
- package/cli/src/__tests__/integration/api-integration.test.ts +0 -289
- package/cli/src/__tests__/integration/credentials-storage.test.ts +0 -453
- package/cli/src/__tests__/integration/local-agents.test.ts +0 -1187
- package/cli/src/__tests__/integration/login-flow-instrumentation.test.ts +0 -146
- package/cli/src/__tests__/integration/login-polling-working.test.ts +0 -287
- package/cli/src/__tests__/integration/usage-refresh-on-completion.test.ts +0 -177
- package/cli/src/__tests__/integration-tmux.test.ts +0 -186
- package/cli/src/__tests__/mocks/hover-toggle-controller.ts +0 -71
- package/cli/src/__tests__/path-completion.test.ts +0 -243
- package/cli/src/__tests__/project-files-chat-id.test.ts +0 -34
- package/cli/src/__tests__/release/proxy-http-get.test.ts +0 -670
- package/cli/src/__tests__/release/wrapper-safety.test.ts +0 -177
- package/cli/src/__tests__/rerender-perf.integration.test.ts +0 -283
- package/cli/src/__tests__/terminal-reset-sequences.test.ts +0 -36
- package/cli/src/__tests__/terminal-watchdog.test.ts +0 -114
- package/cli/src/__tests__/test-utils.ts +0 -266
- package/cli/src/__tests__/tmux-poc.ts +0 -150
- package/cli/src/__tests__/unit/agent-mode-toggle.test.ts +0 -138
- package/cli/src/__tests__/unit/copy-button.test.tsx +0 -188
- package/cli/src/__tests__/unit/create-run-config.test.ts +0 -77
- package/cli/src/__tests__/unit/publish-confirmation.test.ts +0 -70
- package/cli/src/__tests__/unit/segmented-control.test.ts +0 -167
- package/cli/src/__tests__/utils/env.test.ts +0 -210
- package/cli/src/__tests__/utils/project-picker.test.ts +0 -39
- package/cli/src/agents/bundled-agents.generated.d.ts +0 -14
- package/cli/src/agents/bundled-agents.generated.ts +0 -1962
- package/cli/src/app.tsx +0 -383
- package/cli/src/chat.tsx +0 -2008
- package/cli/src/cli-args.ts +0 -183
- package/cli/src/commands/__tests__/bash-command.test.ts +0 -449
- package/cli/src/commands/__tests__/command-args.test.ts +0 -325
- package/cli/src/commands/__tests__/copy-conversation.test.ts +0 -240
- package/cli/src/commands/__tests__/dev-command.test.ts +0 -128
- package/cli/src/commands/__tests__/diagnostics-command.test.ts +0 -35
- package/cli/src/commands/__tests__/image.test.ts +0 -99
- package/cli/src/commands/__tests__/init.test.ts +0 -479
- package/cli/src/commands/__tests__/loop-command.test.ts +0 -89
- package/cli/src/commands/__tests__/new-command-rotates-chat.test.ts +0 -87
- package/cli/src/commands/__tests__/permissions-command.test.ts +0 -93
- package/cli/src/commands/__tests__/process-diagnostics.test.ts +0 -54
- package/cli/src/commands/__tests__/prompt-builders.test.ts +0 -69
- package/cli/src/commands/__tests__/registry-gating.test.ts +0 -125
- package/cli/src/commands/__tests__/rewind-command.test.ts +0 -227
- package/cli/src/commands/__tests__/router-connect-chatgpt.test.ts +0 -72
- package/cli/src/commands/__tests__/router-input.test.ts +0 -302
- package/cli/src/commands/__tests__/router-provider-setup.test.ts +0 -180
- package/cli/src/commands/__tests__/savant-free-command-aliases.test.ts +0 -56
- package/cli/src/commands/ads.ts +0 -45
- package/cli/src/commands/command-registry.ts +0 -1112
- package/cli/src/commands/copy-conversation.ts +0 -386
- package/cli/src/commands/goal.ts +0 -87
- package/cli/src/commands/health-command.ts +0 -61
- package/cli/src/commands/help.ts +0 -13
- package/cli/src/commands/image.ts +0 -20
- package/cli/src/commands/init.ts +0 -121
- package/cli/src/commands/loop.ts +0 -182
- package/cli/src/commands/process-diagnostics.ts +0 -120
- package/cli/src/commands/prompt-builders.ts +0 -140
- package/cli/src/commands/publish.ts +0 -261
- package/cli/src/commands/rewind.ts +0 -130
- package/cli/src/commands/router-utils.ts +0 -80
- package/cli/src/commands/router.ts +0 -589
- package/cli/src/commands/telemetry.ts +0 -68
- package/cli/src/commands/usage.ts +0 -26
- package/cli/src/components/__tests__/ad-banner.test.tsx +0 -84
- package/cli/src/components/__tests__/block-helpers.test.tsx +0 -139
- package/cli/src/components/__tests__/clickable.test.tsx +0 -39
- package/cli/src/components/__tests__/grid-layout.integration.test.tsx +0 -365
- package/cli/src/components/__tests__/grid-layout.test.tsx +0 -1033
- package/cli/src/components/__tests__/markdown-content.test.tsx +0 -163
- package/cli/src/components/__tests__/message-block.completion.test.tsx +0 -104
- package/cli/src/components/__tests__/message-block.streaming.test.tsx +0 -78
- package/cli/src/components/__tests__/message-with-agents.test.tsx +0 -571
- package/cli/src/components/__tests__/multiline-input.test.tsx +0 -1129
- package/cli/src/components/__tests__/selectable-list.test.ts +0 -232
- package/cli/src/components/__tests__/shimmer-text.test.tsx +0 -32
- package/cli/src/components/__tests__/status-indicator.test.tsx +0 -184
- package/cli/src/components/__tests__/user-error-banner.test.tsx +0 -100
- package/cli/src/components/ad-banner.tsx +0 -351
- package/cli/src/components/agent-checklist.tsx +0 -385
- package/cli/src/components/agent-mode-toggle.tsx +0 -294
- package/cli/src/components/ask-user/__tests__/multiple-choice-form.test.ts +0 -432
- package/cli/src/components/ask-user/__tests__/validation.test.ts +0 -213
- package/cli/src/components/ask-user/components/accordion-question.tsx +0 -153
- package/cli/src/components/ask-user/components/custom-answer-input.tsx +0 -66
- package/cli/src/components/ask-user/components/options-list.tsx +0 -139
- package/cli/src/components/ask-user/components/question-header.tsx +0 -80
- package/cli/src/components/ask-user/components/question-option.tsx +0 -94
- package/cli/src/components/ask-user/constants.ts +0 -35
- package/cli/src/components/ask-user/index.tsx +0 -660
- package/cli/src/components/ask-user/utils/validation.ts +0 -85
- package/cli/src/components/attachment-card.tsx +0 -67
- package/cli/src/components/blocks/agent-block-grid.tsx +0 -58
- package/cli/src/components/blocks/agent-branch-item.tsx +0 -230
- package/cli/src/components/blocks/agent-branch-wrapper.tsx +0 -524
- package/cli/src/components/blocks/agent-list-branch.tsx +0 -77
- package/cli/src/components/blocks/ask-user-branch.tsx +0 -98
- package/cli/src/components/blocks/block-helpers.tsx +0 -257
- package/cli/src/components/blocks/blocks-renderer.tsx +0 -296
- package/cli/src/components/blocks/content-with-markdown.tsx +0 -34
- package/cli/src/components/blocks/copy-button.tsx +0 -106
- package/cli/src/components/blocks/copyable-block.tsx +0 -47
- package/cli/src/components/blocks/image-block.tsx +0 -128
- package/cli/src/components/blocks/implementor-row.tsx +0 -453
- package/cli/src/components/blocks/markdown-content.tsx +0 -360
- package/cli/src/components/blocks/markdown-renderables.tsx +0 -347
- package/cli/src/components/blocks/single-block.tsx +0 -210
- package/cli/src/components/blocks/thinking-block.tsx +0 -77
- package/cli/src/components/blocks/tool-block-group.tsx +0 -72
- package/cli/src/components/blocks/tool-branch.tsx +0 -196
- package/cli/src/components/blocks/user-content-copy.tsx +0 -171
- package/cli/src/components/bottom-banner.tsx +0 -145
- package/cli/src/components/build-mode-buttons.tsx +0 -110
- package/cli/src/components/button.tsx +0 -75
- package/cli/src/components/chat-header.tsx +0 -11
- package/cli/src/components/chat-history-screen.tsx +0 -417
- package/cli/src/components/chat-input-bar.tsx +0 -535
- package/cli/src/components/chatgpt-connect-banner.tsx +0 -234
- package/cli/src/components/clickable.tsx +0 -149
- package/cli/src/components/collapse-button.tsx +0 -36
- package/cli/src/components/command-palette.tsx +0 -166
- package/cli/src/components/copy-button.tsx +0 -219
- package/cli/src/components/dialog.tsx +0 -111
- package/cli/src/components/elapsed-timer.tsx +0 -56
- package/cli/src/components/error-boundary.tsx +0 -63
- package/cli/src/components/feedback-container.tsx +0 -206
- package/cli/src/components/feedback-icon-button.tsx +0 -89
- package/cli/src/components/feedback-input-mode.tsx +0 -352
- package/cli/src/components/file-attachment-card.tsx +0 -89
- package/cli/src/components/grid-layout.tsx +0 -83
- package/cli/src/components/help-banner.tsx +0 -136
- package/cli/src/components/highlighted-text.tsx +0 -52
- package/cli/src/components/image-card.tsx +0 -167
- package/cli/src/components/image-thumbnail.tsx +0 -112
- package/cli/src/components/input-cursor.tsx +0 -77
- package/cli/src/components/input-mode-banner.tsx +0 -70
- package/cli/src/components/load-previous-button.tsx +0 -48
- package/cli/src/components/login-modal.tsx +0 -450
- package/cli/src/components/message-block.tsx +0 -337
- package/cli/src/components/message-footer.tsx +0 -269
- package/cli/src/components/message-with-agents.tsx +0 -594
- package/cli/src/components/mode-divider.tsx +0 -43
- package/cli/src/components/model-picker.tsx +0 -371
- package/cli/src/components/multiline-input.tsx +0 -1276
- package/cli/src/components/out-of-credits-banner.tsx +0 -155
- package/cli/src/components/pending-attachments-banner.tsx +0 -125
- package/cli/src/components/pending-bash-message.tsx +0 -57
- package/cli/src/components/progress-bar.tsx +0 -81
- package/cli/src/components/project-picker-screen.tsx +0 -469
- package/cli/src/components/provider-picker.tsx +0 -139
- package/cli/src/components/publish-confirmation.tsx +0 -514
- package/cli/src/components/publish-container.tsx +0 -737
- package/cli/src/components/raised-pill.tsx +0 -89
- package/cli/src/components/renderers/plan-box.tsx +0 -70
- package/cli/src/components/review-screen.tsx +0 -114
- package/cli/src/components/rewind-picker.tsx +0 -276
- package/cli/src/components/right-sidebar.tsx +0 -296
- package/cli/src/components/savant-free-active-session-summary.tsx +0 -63
- package/cli/src/components/savant-free-landing-screen.tsx +0 -756
- package/cli/src/components/savant-free-model-selector.tsx +0 -815
- package/cli/src/components/savant-free-referral-banner.tsx +0 -423
- package/cli/src/components/savant-free-superseded-screen.tsx +0 -62
- package/cli/src/components/savant-ui/animation/pulse.tsx +0 -26
- package/cli/src/components/savant-ui/animation/typewriter.tsx +0 -40
- package/cli/src/components/savant-ui/branding.tsx +0 -59
- package/cli/src/components/savant-ui/data-display/badge.tsx +0 -52
- package/cli/src/components/savant-ui/data-display/code-block.tsx +0 -55
- package/cli/src/components/savant-ui/data-display/key-value.tsx +0 -34
- package/cli/src/components/savant-ui/data-display/sparkline.tsx +0 -42
- package/cli/src/components/savant-ui/data-display/timeline.tsx +0 -44
- package/cli/src/components/savant-ui/data-display/tree-view.tsx +0 -55
- package/cli/src/components/savant-ui/echo/__tests__/sidebar-collapse.test.tsx +0 -90
- package/cli/src/components/savant-ui/echo/agent-stack.tsx +0 -72
- package/cli/src/components/savant-ui/echo/agent-status.tsx +0 -66
- package/cli/src/components/savant-ui/echo/fid-card.tsx +0 -89
- package/cli/src/components/savant-ui/echo/fid-list.tsx +0 -68
- package/cli/src/components/savant-ui/echo/loop-status-panel.tsx +0 -64
- package/cli/src/components/savant-ui/echo/perfection-loop.tsx +0 -118
- package/cli/src/components/savant-ui/echo/phase-indicator.tsx +0 -68
- package/cli/src/components/savant-ui/echo/phase-info.ts +0 -72
- package/cli/src/components/savant-ui/echo/token-meter.tsx +0 -39
- package/cli/src/components/savant-ui/feedback/alert.tsx +0 -45
- package/cli/src/components/savant-ui/feedback/cost-tracker.tsx +0 -54
- package/cli/src/components/savant-ui/feedback/progress-bar.tsx +0 -71
- package/cli/src/components/savant-ui/feedback/spinner.tsx +0 -40
- package/cli/src/components/savant-ui/icon-theme-keys.ts +0 -67
- package/cli/src/components/savant-ui/icon.tsx +0 -53
- package/cli/src/components/savant-ui/index.ts +0 -75
- package/cli/src/components/savant-ui/input/select.tsx +0 -26
- package/cli/src/components/savant-ui/input/toggle.tsx +0 -28
- package/cli/src/components/savant-ui/layout/grid.tsx +0 -52
- package/cli/src/components/savant-ui/layout/header.tsx +0 -28
- package/cli/src/components/savant-ui/navigation/stepper.tsx +0 -41
- package/cli/src/components/savant-ui/primitives/key-hint.tsx +0 -45
- package/cli/src/components/savant-ui/primitives/key-value-row.tsx +0 -41
- package/cli/src/components/savant-ui/primitives/panel.tsx +0 -42
- package/cli/src/components/savant-ui/primitives/separator.tsx +0 -34
- package/cli/src/components/savant-ui/primitives/sidebar-section.tsx +0 -64
- package/cli/src/components/savant-ui/primitives/spacer.tsx +0 -13
- package/cli/src/components/savant-ui/primitives/stack.tsx +0 -35
- package/cli/src/components/savant-ui/theme.ts +0 -45
- package/cli/src/components/scroll-to-bottom-button.tsx +0 -34
- package/cli/src/components/segmented-control.tsx +0 -199
- package/cli/src/components/selectable-list.tsx +0 -249
- package/cli/src/components/selected-chips.tsx +0 -86
- package/cli/src/components/separator.tsx +0 -40
- package/cli/src/components/session-ended-banner.tsx +0 -183
- package/cli/src/components/shimmer-text.tsx +0 -254
- package/cli/src/components/status-bar.tsx +0 -279
- package/cli/src/components/subscription-limit-banner.tsx +0 -269
- package/cli/src/components/suggested-prompts.tsx +0 -184
- package/cli/src/components/suggestion-menu.tsx +0 -219
- package/cli/src/components/terminal-command-display.tsx +0 -152
- package/cli/src/components/terminal-link.tsx +0 -97
- package/cli/src/components/text-attachment-card.tsx +0 -77
- package/cli/src/components/thinking.tsx +0 -108
- package/cli/src/components/toast.tsx +0 -109
- package/cli/src/components/tools/__tests__/apply-patch.test.tsx +0 -97
- package/cli/src/components/tools/__tests__/code-search.test.tsx +0 -45
- package/cli/src/components/tools/__tests__/gravity-index.test.ts +0 -76
- package/cli/src/components/tools/__tests__/render-ui.test.tsx +0 -556
- package/cli/src/components/tools/__tests__/run-terminal-command.test.ts +0 -274
- package/cli/src/components/tools/__tests__/tool-call-item.test.tsx +0 -73
- package/cli/src/components/tools/apply-patch.tsx +0 -101
- package/cli/src/components/tools/code-search.tsx +0 -50
- package/cli/src/components/tools/composio.tsx +0 -140
- package/cli/src/components/tools/diff-viewer.tsx +0 -21
- package/cli/src/components/tools/glob.tsx +0 -66
- package/cli/src/components/tools/gravity-index.tsx +0 -80
- package/cli/src/components/tools/list-directory.tsx +0 -66
- package/cli/src/components/tools/read-docs.tsx +0 -36
- package/cli/src/components/tools/read-files.tsx +0 -97
- package/cli/src/components/tools/read-subtree.tsx +0 -40
- package/cli/src/components/tools/read-url.tsx +0 -32
- package/cli/src/components/tools/registry.ts +0 -131
- package/cli/src/components/tools/render-ui.tsx +0 -466
- package/cli/src/components/tools/run-terminal-command.tsx +0 -86
- package/cli/src/components/tools/skill.tsx +0 -26
- package/cli/src/components/tools/str-replace.tsx +0 -77
- package/cli/src/components/tools/suggest-followups.tsx +0 -373
- package/cli/src/components/tools/task-completed.tsx +0 -16
- package/cli/src/components/tools/tool-call-item.tsx +0 -163
- package/cli/src/components/tools/types.ts +0 -100
- package/cli/src/components/tools/web-search.tsx +0 -32
- package/cli/src/components/tools/write-file.tsx +0 -20
- package/cli/src/components/tools/write-todos.tsx +0 -105
- package/cli/src/components/top-banner.tsx +0 -187
- package/cli/src/components/usage-banner.tsx +0 -296
- package/cli/src/components/user-error-banner.tsx +0 -54
- package/cli/src/components/validation-error-popover.tsx +0 -191
- package/cli/src/data/slash-commands.ts +0 -306
- package/cli/src/hooks/__tests__/holds-live-savant-free-slot.test.ts +0 -49
- package/cli/src/hooks/__tests__/run-outcome.test.ts +0 -178
- package/cli/src/hooks/__tests__/session-fetch-signal.test.ts +0 -45
- package/cli/src/hooks/__tests__/use-activity-query.test.ts +0 -810
- package/cli/src/hooks/__tests__/use-ask-user-bridge.test.ts +0 -175
- package/cli/src/hooks/__tests__/use-auth-query.test.ts +0 -21
- package/cli/src/hooks/__tests__/use-chat-messages-collapse.test.ts +0 -96
- package/cli/src/hooks/__tests__/use-connection-status.test.ts +0 -112
- package/cli/src/hooks/__tests__/use-directory-browser.test.ts +0 -215
- package/cli/src/hooks/__tests__/use-gravity-ad.test.ts +0 -73
- package/cli/src/hooks/__tests__/use-grid-layout.test.ts +0 -346
- package/cli/src/hooks/__tests__/use-input-history.test.ts +0 -704
- package/cli/src/hooks/__tests__/use-loop-scheduler.test.ts +0 -247
- package/cli/src/hooks/__tests__/use-path-tab-completion.test.ts +0 -324
- package/cli/src/hooks/__tests__/use-queue-controls.test.ts +0 -68
- package/cli/src/hooks/__tests__/use-searchable-list.test.ts +0 -364
- package/cli/src/hooks/__tests__/use-send-message-timer.test.ts +0 -146
- package/cli/src/hooks/__tests__/use-suggestion-engine-mention.test.ts +0 -364
- package/cli/src/hooks/__tests__/use-suggestion-engine.test.ts +0 -485
- package/cli/src/hooks/__tests__/use-terminal-focus.test.ts +0 -66
- package/cli/src/hooks/__tests__/use-terminal-layout.test.ts +0 -675
- package/cli/src/hooks/__tests__/use-timeout.test.ts +0 -330
- package/cli/src/hooks/__tests__/use-usage-query.test.ts +0 -526
- package/cli/src/hooks/__tests__/use-user-details-query.test.ts +0 -225
- package/cli/src/hooks/helpers/__tests__/send-message.test.ts +0 -1851
- package/cli/src/hooks/helpers/send-message.ts +0 -553
- package/cli/src/hooks/run-outcome.ts +0 -64
- package/cli/src/hooks/stream-state.ts +0 -106
- package/cli/src/hooks/use-activity-query.ts +0 -696
- package/cli/src/hooks/use-agent-validation.ts +0 -80
- package/cli/src/hooks/use-ask-user-bridge.ts +0 -102
- package/cli/src/hooks/use-auth-query.ts +0 -261
- package/cli/src/hooks/use-auth-state.ts +0 -155
- package/cli/src/hooks/use-chat-input.ts +0 -87
- package/cli/src/hooks/use-chat-keyboard.ts +0 -325
- package/cli/src/hooks/use-chat-messages.ts +0 -273
- package/cli/src/hooks/use-chat-state.ts +0 -219
- package/cli/src/hooks/use-chat-streaming.ts +0 -270
- package/cli/src/hooks/use-chat-ui.ts +0 -136
- package/cli/src/hooks/use-clipboard.ts +0 -154
- package/cli/src/hooks/use-connection-status.ts +0 -156
- package/cli/src/hooks/use-directory-browser.ts +0 -88
- package/cli/src/hooks/use-elapsed-time.ts +0 -116
- package/cli/src/hooks/use-event.ts +0 -36
- package/cli/src/hooks/use-exit-handler.ts +0 -108
- package/cli/src/hooks/use-fetch-login-url.ts +0 -65
- package/cli/src/hooks/use-fids.ts +0 -48
- package/cli/src/hooks/use-fingerprint.ts +0 -64
- package/cli/src/hooks/use-gravity-ad.ts +0 -688
- package/cli/src/hooks/use-grid-layout.ts +0 -78
- package/cli/src/hooks/use-input-history.ts +0 -173
- package/cli/src/hooks/use-login-keyboard-handlers.ts +0 -74
- package/cli/src/hooks/use-login-polling.ts +0 -120
- package/cli/src/hooks/use-logo.tsx +0 -178
- package/cli/src/hooks/use-loop-scheduler.ts +0 -481
- package/cli/src/hooks/use-message-queue.ts +0 -301
- package/cli/src/hooks/use-now.ts +0 -20
- package/cli/src/hooks/use-path-tab-completion.ts +0 -88
- package/cli/src/hooks/use-publish-mutation.ts +0 -60
- package/cli/src/hooks/use-queue-controls.ts +0 -70
- package/cli/src/hooks/use-queue-ui.ts +0 -55
- package/cli/src/hooks/use-savant-free-ctrl-c-exit.ts +0 -23
- package/cli/src/hooks/use-savant-free-session-progress.ts +0 -34
- package/cli/src/hooks/use-savant-free-session.ts +0 -679
- package/cli/src/hooks/use-savant-free-streak-query.ts +0 -72
- package/cli/src/hooks/use-scaffold-confirm.ts +0 -62
- package/cli/src/hooks/use-scaffold-revert-subscriber.ts +0 -66
- package/cli/src/hooks/use-scroll-management.ts +0 -182
- package/cli/src/hooks/use-searchable-list.ts +0 -99
- package/cli/src/hooks/use-send-message.ts +0 -1038
- package/cli/src/hooks/use-sheen-animation.tsx +0 -88
- package/cli/src/hooks/use-subscription-query.ts +0 -106
- package/cli/src/hooks/use-suggestion-engine.ts +0 -793
- package/cli/src/hooks/use-terminal-breakpoints.ts +0 -77
- package/cli/src/hooks/use-terminal-dimensions.ts +0 -50
- package/cli/src/hooks/use-terminal-focus.ts +0 -146
- package/cli/src/hooks/use-terminal-layout.ts +0 -189
- package/cli/src/hooks/use-theme.tsx +0 -140
- package/cli/src/hooks/use-timeout.ts +0 -88
- package/cli/src/hooks/use-toast.ts +0 -114
- package/cli/src/hooks/use-update-preference.ts +0 -77
- package/cli/src/hooks/use-usage-monitor.ts +0 -59
- package/cli/src/hooks/use-usage-query.ts +0 -138
- package/cli/src/hooks/use-user-details-query.ts +0 -104
- package/cli/src/hooks/use-why-did-you-update.ts +0 -178
- package/cli/src/index.tsx +0 -484
- package/cli/src/init/__tests__/init-direnv.test.ts +0 -597
- package/cli/src/init/init-app.ts +0 -54
- package/cli/src/init/init-direnv.ts +0 -133
- package/cli/src/login/constants.ts +0 -71
- package/cli/src/login/login-flow.ts +0 -224
- package/cli/src/login/plain-login.ts +0 -107
- package/cli/src/login/utils.ts +0 -183
- package/cli/src/native/ripgrep.ts +0 -82
- package/cli/src/polyfills/bun-strip-ansi.ts +0 -12
- package/cli/src/pre-init/load-dev-env.ts +0 -98
- package/cli/src/pre-init/tree-sitter-wasm.ts +0 -98
- package/cli/src/project-files.ts +0 -102
- package/cli/src/state/__tests__/chat-store-focus.test.ts +0 -22
- package/cli/src/state/__tests__/feedback-store.test.ts +0 -260
- package/cli/src/state/chat-history-store.ts +0 -27
- package/cli/src/state/chat-store.ts +0 -791
- package/cli/src/state/feedback-store.ts +0 -162
- package/cli/src/state/gateway-catalog-store.ts +0 -45
- package/cli/src/state/login-store.ts +0 -150
- package/cli/src/state/message-block-store.ts +0 -143
- package/cli/src/state/model-picker-store.ts +0 -67
- package/cli/src/state/provider-picker-store.ts +0 -53
- package/cli/src/state/publish-store.ts +0 -141
- package/cli/src/state/review-store.ts +0 -24
- package/cli/src/state/rewind-picker-store.ts +0 -74
- package/cli/src/state/savant-free-model-store.ts +0 -59
- package/cli/src/state/savant-free-session-store.ts +0 -32
- package/cli/src/test-setup.ts +0 -20
- package/cli/src/testing/env.ts +0 -46
- package/cli/src/types/chat-state.ts +0 -15
- package/cli/src/types/chat.ts +0 -242
- package/cli/src/types/contracts/send-message.ts +0 -16
- package/cli/src/types/env.ts +0 -107
- package/cli/src/types/function-params.ts +0 -35
- package/cli/src/types/opentui-augmentation.d.ts +0 -11
- package/cli/src/types/react19-compat.d.ts +0 -19
- package/cli/src/types/savant-free-session.ts +0 -17
- package/cli/src/types/store.ts +0 -112
- package/cli/src/types/theme-system.ts +0 -194
- package/cli/src/types/utils.ts +0 -3
- package/cli/src/utils/__tests__/activity-tracker.test.ts +0 -440
- package/cli/src/utils/__tests__/agent-display.test.ts +0 -139
- package/cli/src/utils/__tests__/analytics-client.test.ts +0 -311
- package/cli/src/utils/__tests__/anonymous-id.test.ts +0 -74
- package/cli/src/utils/__tests__/arrays.test.ts +0 -264
- package/cli/src/utils/__tests__/bash-context-processor.test.ts +0 -38
- package/cli/src/utils/__tests__/block-processor.test.ts +0 -690
- package/cli/src/utils/__tests__/chat-history.test.ts +0 -247
- package/cli/src/utils/__tests__/chat-input-key-intercept.test.ts +0 -40
- package/cli/src/utils/__tests__/chat-layout.test.ts +0 -32
- package/cli/src/utils/__tests__/chat-meta.test.ts +0 -160
- package/cli/src/utils/__tests__/chatgpt-oauth.test.ts +0 -50
- package/cli/src/utils/__tests__/clipboard.test.ts +0 -998
- package/cli/src/utils/__tests__/code-search-summary.test.ts +0 -84
- package/cli/src/utils/__tests__/collapse-helpers.test.ts +0 -1272
- package/cli/src/utils/__tests__/error-handling.test.ts +0 -611
- package/cli/src/utils/__tests__/feedback-helpers.test.ts +0 -452
- package/cli/src/utils/__tests__/feedback-submission.test.ts +0 -26
- package/cli/src/utils/__tests__/fetch-usage.test.ts +0 -355
- package/cli/src/utils/__tests__/fingerprint.test.ts +0 -147
- package/cli/src/utils/__tests__/format-elapsed-time.test.ts +0 -103
- package/cli/src/utils/__tests__/format-timeout.test.ts +0 -87
- package/cli/src/utils/__tests__/image-dimensions.test.ts +0 -243
- package/cli/src/utils/__tests__/image-processor.test.ts +0 -250
- package/cli/src/utils/__tests__/implementor-helpers.test.ts +0 -1457
- package/cli/src/utils/__tests__/keyboard-actions.test.ts +0 -686
- package/cli/src/utils/__tests__/layout-helpers.test.ts +0 -36
- package/cli/src/utils/__tests__/lazy-response-ads.test.ts +0 -167
- package/cli/src/utils/__tests__/logger-sanitize-secrets.test.ts +0 -80
- package/cli/src/utils/__tests__/markdown-renderer.test.tsx +0 -518
- package/cli/src/utils/__tests__/markdown-streaming.test.ts +0 -64
- package/cli/src/utils/__tests__/message-block-helpers.test.ts +0 -1197
- package/cli/src/utils/__tests__/message-updater.test.ts +0 -659
- package/cli/src/utils/__tests__/ollama-onboarding.test.ts +0 -239
- package/cli/src/utils/__tests__/openrouter-models.test.ts +0 -295
- package/cli/src/utils/__tests__/osc-timeout-scenarios.test.ts +0 -172
- package/cli/src/utils/__tests__/pending-attachments.test.ts +0 -278
- package/cli/src/utils/__tests__/provider-setup.test.ts +0 -183
- package/cli/src/utils/__tests__/run-state-storage.test.ts +0 -741
- package/cli/src/utils/__tests__/savant-code-api.test.ts +0 -634
- package/cli/src/utils/__tests__/savant-free-instance-owner.test.ts +0 -69
- package/cli/src/utils/__tests__/savant-free-model-navigation.test.ts +0 -104
- package/cli/src/utils/__tests__/savant-free-premium-reset.test.ts +0 -81
- package/cli/src/utils/__tests__/savant-free-referral-cache.test.ts +0 -67
- package/cli/src/utils/__tests__/savant-free-session-display.test.ts +0 -23
- package/cli/src/utils/__tests__/savant-free-streak-line.test.ts +0 -76
- package/cli/src/utils/__tests__/sdk-event-handlers.test.ts +0 -615
- package/cli/src/utils/__tests__/send-message-helpers.test.ts +0 -1875
- package/cli/src/utils/__tests__/send-message-timer.test.ts +0 -68
- package/cli/src/utils/__tests__/settings.test.ts +0 -138
- package/cli/src/utils/__tests__/strings.test.ts +0 -210
- package/cli/src/utils/__tests__/syntax-theme.test.ts +0 -91
- package/cli/src/utils/__tests__/terminal-color-detection.test.ts +0 -425
- package/cli/src/utils/__tests__/terminal-enter-detection.test.ts +0 -77
- package/cli/src/utils/__tests__/text-layout.test.ts +0 -82
- package/cli/src/utils/__tests__/think-tag-parser.test.ts +0 -159
- package/cli/src/utils/__tests__/trace-writer.test.ts +0 -193
- package/cli/src/utils/__tests__/trim-chat-logs.test.ts +0 -79
- package/cli/src/utils/__tests__/usage-banner-state.test.ts +0 -298
- package/cli/src/utils/__tests__/validation-error-formatting.test.ts +0 -126
- package/cli/src/utils/__tests__/write-file-atomic.test.ts +0 -130
- package/cli/src/utils/active-run.ts +0 -22
- package/cli/src/utils/activity-tracker.ts +0 -66
- package/cli/src/utils/agent-display.ts +0 -87
- package/cli/src/utils/agent-helpers.ts +0 -47
- package/cli/src/utils/ai-message-id.ts +0 -12
- package/cli/src/utils/analytics.ts +0 -407
- package/cli/src/utils/anonymous-id.ts +0 -87
- package/cli/src/utils/arrays.ts +0 -117
- package/cli/src/utils/auth.ts +0 -258
- package/cli/src/utils/bash-context-processor.ts +0 -47
- package/cli/src/utils/bash-messages.ts +0 -108
- package/cli/src/utils/block-margins.ts +0 -35
- package/cli/src/utils/block-operations.ts +0 -548
- package/cli/src/utils/block-processor.ts +0 -212
- package/cli/src/utils/chat-history.ts +0 -265
- package/cli/src/utils/chat-input-key-intercept.ts +0 -52
- package/cli/src/utils/chat-layout.ts +0 -44
- package/cli/src/utils/chat-meta.ts +0 -101
- package/cli/src/utils/chat-scroll-accel.ts +0 -151
- package/cli/src/utils/chatgpt-oauth.ts +0 -350
- package/cli/src/utils/clipboard-image.ts +0 -610
- package/cli/src/utils/clipboard.ts +0 -307
- package/cli/src/utils/code-search-summary.ts +0 -69
- package/cli/src/utils/collapse-helpers.ts +0 -265
- package/cli/src/utils/config-dir.ts +0 -30
- package/cli/src/utils/constants.ts +0 -159
- package/cli/src/utils/create-event-handler-state.ts +0 -79
- package/cli/src/utils/create-run-config.ts +0 -160
- package/cli/src/utils/db-storage.ts +0 -254
- package/cli/src/utils/detect-shell.ts +0 -112
- package/cli/src/utils/directory-browser.ts +0 -74
- package/cli/src/utils/engagement.ts +0 -55
- package/cli/src/utils/env.ts +0 -109
- package/cli/src/utils/error-handling.ts +0 -246
- package/cli/src/utils/error-messages.ts +0 -84
- package/cli/src/utils/feedback-helpers.ts +0 -115
- package/cli/src/utils/feedback-submission.ts +0 -24
- package/cli/src/utils/fetch-usage.ts +0 -75
- package/cli/src/utils/fid-loader.ts +0 -135
- package/cli/src/utils/fingerprint.ts +0 -263
- package/cli/src/utils/finish-logic.ts +0 -154
- package/cli/src/utils/format-elapsed-time.ts +0 -33
- package/cli/src/utils/format-session-units.ts +0 -6
- package/cli/src/utils/format-timeout.ts +0 -28
- package/cli/src/utils/format-validation-errors-for-message.ts +0 -85
- package/cli/src/utils/git.ts +0 -17
- package/cli/src/utils/glyphs.ts +0 -188
- package/cli/src/utils/helpers.ts +0 -47
- package/cli/src/utils/image-display.ts +0 -73
- package/cli/src/utils/image-handler.ts +0 -336
- package/cli/src/utils/image-processor.ts +0 -133
- package/cli/src/utils/image-thumbnail.ts +0 -83
- package/cli/src/utils/implementor-helpers.ts +0 -817
- package/cli/src/utils/input-modes.ts +0 -196
- package/cli/src/utils/keyboard-actions.ts +0 -394
- package/cli/src/utils/keypad-keys.ts +0 -47
- package/cli/src/utils/layout-helpers.ts +0 -36
- package/cli/src/utils/lazy-response-ads.ts +0 -1
- package/cli/src/utils/loading-phrases.ts +0 -68
- package/cli/src/utils/local-agent-registry.ts +0 -611
- package/cli/src/utils/log-shipper.ts +0 -116
- package/cli/src/utils/logger.ts +0 -435
- package/cli/src/utils/markdown-renderer.tsx +0 -1315
- package/cli/src/utils/math.ts +0 -3
- package/cli/src/utils/message-block-helpers.ts +0 -667
- package/cli/src/utils/message-history.ts +0 -153
- package/cli/src/utils/message-tree-utils.ts +0 -67
- package/cli/src/utils/message-updater.ts +0 -279
- package/cli/src/utils/ollama-onboarding.ts +0 -215
- package/cli/src/utils/open-file.ts +0 -144
- package/cli/src/utils/open-url.ts +0 -63
- package/cli/src/utils/openrouter-models.ts +0 -945
- package/cli/src/utils/path-completion.ts +0 -111
- package/cli/src/utils/path-helpers.ts +0 -38
- package/cli/src/utils/pending-attachments.ts +0 -363
- package/cli/src/utils/post-processing.ts +0 -99
- package/cli/src/utils/project-picker.ts +0 -12
- package/cli/src/utils/provider-setup.ts +0 -259
- package/cli/src/utils/recent-projects.ts +0 -156
- package/cli/src/utils/renderer-cleanup.ts +0 -142
- package/cli/src/utils/response-ad-positions.ts +0 -1
- package/cli/src/utils/rewind.ts +0 -175
- package/cli/src/utils/run-state-storage.ts +0 -480
- package/cli/src/utils/savant-code-api.ts +0 -686
- package/cli/src/utils/savant-code-client.ts +0 -217
- package/cli/src/utils/savant-free-agent-selection.ts +0 -12
- package/cli/src/utils/savant-free-exit.ts +0 -24
- package/cli/src/utils/savant-free-instance-owner.ts +0 -66
- package/cli/src/utils/savant-free-model-navigation.ts +0 -46
- package/cli/src/utils/savant-free-premium-reset.ts +0 -52
- package/cli/src/utils/savant-free-referral-cache.ts +0 -35
- package/cli/src/utils/savant-free-session-display.ts +0 -21
- package/cli/src/utils/savant-free-streak-line.ts +0 -67
- package/cli/src/utils/sdk-event-handlers.ts +0 -587
- package/cli/src/utils/send-message-helpers.ts +0 -199
- package/cli/src/utils/send-message-timer.ts +0 -110
- package/cli/src/utils/settings.ts +0 -388
- package/cli/src/utils/skill-registry.ts +0 -100
- package/cli/src/utils/spawn-agent-matcher.ts +0 -56
- package/cli/src/utils/status-indicator-state.ts +0 -100
- package/cli/src/utils/stream-chunk-processor.ts +0 -65
- package/cli/src/utils/strings.ts +0 -272
- package/cli/src/utils/subscription.ts +0 -31
- package/cli/src/utils/syntax-highlighter.tsx +0 -19
- package/cli/src/utils/syntax-theme.ts +0 -131
- package/cli/src/utils/terminal-color-detection.ts +0 -472
- package/cli/src/utils/terminal-enter-detection.ts +0 -63
- package/cli/src/utils/terminal-images.ts +0 -223
- package/cli/src/utils/terminal-reset-sequences.ts +0 -33
- package/cli/src/utils/terminal-title.ts +0 -113
- package/cli/src/utils/terminal-watchdog.ts +0 -246
- package/cli/src/utils/text-layout.ts +0 -153
- package/cli/src/utils/theme-config.ts +0 -143
- package/cli/src/utils/theme-system.ts +0 -1265
- package/cli/src/utils/think-tag-parser.ts +0 -105
- package/cli/src/utils/trace-writer.ts +0 -147
- package/cli/src/utils/ui-constants.ts +0 -69
- package/cli/src/utils/usage-banner-state.ts +0 -146
- package/cli/src/utils/validation-error-formatting.ts +0 -92
- package/cli/src/utils/validation-error-helpers.ts +0 -19
- package/cli/src/utils/version.ts +0 -23
- package/cli/src/utils/word-wrap-utils.ts +0 -53
- package/cli/src/utils/write-file-atomic.ts +0 -82
- package/cli/src/utils/yield-to-event-loop.ts +0 -9
- package/cli/tsconfig.json +0 -26
- package/coding-standards/csharp.md +0 -77
- package/coding-standards/go.md +0 -71
- package/coding-standards/java.md +0 -74
- package/coding-standards/python.md +0 -82
- package/coding-standards/rust.md +0 -78
- package/coding-standards/typescript.md +0 -85
- package/coding-standards/x402.md +0 -227
- package/common/README.md +0 -41
- package/common/common_exit +0 -1
- package/common/package.json +0 -45
- package/common/src/__tests__/agent-validation.test.ts +0 -861
- package/common/src/__tests__/agents.test.ts +0 -16
- package/common/src/__tests__/dynamic-agent-template-schema.test.ts +0 -420
- package/common/src/__tests__/env-ci.test.ts +0 -167
- package/common/src/__tests__/env-process.test.ts +0 -145
- package/common/src/__tests__/free-agents.test.ts +0 -269
- package/common/src/__tests__/handlesteps-parsing.test.ts +0 -247
- package/common/src/__tests__/model-config.test.ts +0 -41
- package/common/src/__tests__/project-file-tree.test.ts +0 -82
- package/common/src/__tests__/response-ad-positions.test.ts +0 -78
- package/common/src/__tests__/savant-free-models.test.ts +0 -460
- package/common/src/__tests__/savant-free-referral-tiers.test.ts +0 -122
- package/common/src/__tests__/user-state.test.ts +0 -30
- package/common/src/actions.ts +0 -215
- package/common/src/analytics-core.ts +0 -73
- package/common/src/analytics.ts +0 -96
- package/common/src/api-keys/constants.ts +0 -26
- package/common/src/browser-actions.ts +0 -414
- package/common/src/constants/agents.ts +0 -250
- package/common/src/constants/analytics-events.ts +0 -318
- package/common/src/constants/anthropic.ts +0 -72
- package/common/src/constants/byok.ts +0 -2
- package/common/src/constants/chatgpt-oauth.ts +0 -85
- package/common/src/constants/composio.ts +0 -34
- package/common/src/constants/feedback.ts +0 -18
- package/common/src/constants/free-agents.ts +0 -347
- package/common/src/constants/gemini.ts +0 -6
- package/common/src/constants/grant-priorities.ts +0 -13
- package/common/src/constants/hosts.ts +0 -6
- package/common/src/constants/images.ts +0 -53
- package/common/src/constants/index.ts +0 -8
- package/common/src/constants/knowledge.ts +0 -46
- package/common/src/constants/limits.ts +0 -23
- package/common/src/constants/model-config.ts +0 -469
- package/common/src/constants/paths.ts +0 -69
- package/common/src/constants/savant-code-config.ts +0 -12
- package/common/src/constants/savant-free-gemini-thinker.ts +0 -30
- package/common/src/constants/savant-free-models.ts +0 -855
- package/common/src/constants/savant-free-referral-tiers.ts +0 -169
- package/common/src/constants/skills.ts +0 -60
- package/common/src/constants/subscription-plans.ts +0 -54
- package/common/src/constants/ui.ts +0 -25
- package/common/src/env-ci.ts +0 -36
- package/common/src/env-process.ts +0 -95
- package/common/src/env-schema.ts +0 -42
- package/common/src/env.ts +0 -69
- package/common/src/mcp/client.ts +0 -308
- package/common/src/old-constants.ts +0 -10
- package/common/src/project-file-tree.ts +0 -361
- package/common/src/reddit-capi.ts +0 -175
- package/common/src/schemas/feedback.ts +0 -57
- package/common/src/schemas/logs.ts +0 -66
- package/common/src/templates/agent-validation.ts +0 -436
- package/common/src/templates/initial-agents-dir/LICENSE +0 -202
- package/common/src/templates/initial-agents-dir/README.md +0 -314
- package/common/src/templates/initial-agents-dir/examples/01-basic-diff-reviewer.ts +0 -17
- package/common/src/templates/initial-agents-dir/examples/02-intermediate-git-committer.ts +0 -78
- package/common/src/templates/initial-agents-dir/examples/03-advanced-file-explorer.ts +0 -76
- package/common/src/templates/initial-agents-dir/my-custom-agent.ts +0 -40
- package/common/src/templates/initial-agents-dir/package.json +0 -6
- package/common/src/templates/initial-agents-dir/skills/README.md +0 -66
- package/common/src/templates/initial-agents-dir/skills/example-skill/SKILL.md +0 -29
- package/common/src/templates/initial-agents-dir/types/agent-definition.ts +0 -484
- package/common/src/templates/initial-agents-dir/types/tools.ts +0 -452
- package/common/src/templates/initial-agents-dir/types/util-types.ts +0 -167
- package/common/src/testing/TESTING_PATTERNS.md +0 -353
- package/common/src/testing/errors.ts +0 -33
- package/common/src/testing/fixtures/agent-runtime.ts +0 -325
- package/common/src/testing/impl/agent-runtime.ts +0 -6
- package/common/src/testing/index.ts +0 -84
- package/common/src/testing/mock-modules.ts +0 -54
- package/common/src/testing/mock-types.ts +0 -123
- package/common/src/testing/mocks/analytics.ts +0 -262
- package/common/src/testing/mocks/child-process.ts +0 -93
- package/common/src/testing/mocks/crypto.ts +0 -218
- package/common/src/testing/mocks/database.ts +0 -337
- package/common/src/testing/mocks/filesystem.ts +0 -166
- package/common/src/testing/mocks/index.ts +0 -83
- package/common/src/testing/mocks/logger.ts +0 -136
- package/common/src/testing/mocks/stream.ts +0 -314
- package/common/src/testing/mocks/timers.ts +0 -132
- package/common/src/testing/mocks/tree-sitter.ts +0 -127
- package/common/src/testing/setup.ts +0 -282
- package/common/src/testing-env-ci.ts +0 -15
- package/common/src/testing-env-process.ts +0 -78
- package/common/src/tools/__tests__/compile-tool-definitions.test.ts +0 -34
- package/common/src/tools/__tests__/thought-session.test.ts +0 -256
- package/common/src/tools/compile-tool-definitions.ts +0 -194
- package/common/src/tools/constants.ts +0 -132
- package/common/src/tools/list.ts +0 -193
- package/common/src/tools/params/__tests__/coerce-to-array.test.ts +0 -237
- package/common/src/tools/params/__tests__/sequential-thinking-coercion.test.ts +0 -98
- package/common/src/tools/params/tool/add-message.ts +0 -36
- package/common/src/tools/params/tool/add-subgoal.ts +0 -57
- package/common/src/tools/params/tool/apply-patch.ts +0 -110
- package/common/src/tools/params/tool/ask-user.ts +0 -181
- package/common/src/tools/params/tool/browser-logs.ts +0 -85
- package/common/src/tools/params/tool/code-search.ts +0 -144
- package/common/src/tools/params/tool/composio.ts +0 -131
- package/common/src/tools/params/tool/create-plan.ts +0 -80
- package/common/src/tools/params/tool/end-turn.ts +0 -54
- package/common/src/tools/params/tool/find-files.ts +0 -60
- package/common/src/tools/params/tool/glob.ts +0 -74
- package/common/src/tools/params/tool/gravity-index.ts +0 -92
- package/common/src/tools/params/tool/list-directory.ts +0 -58
- package/common/src/tools/params/tool/lookup-agent-info.ts +0 -37
- package/common/src/tools/params/tool/propose-str-replace.ts +0 -103
- package/common/src/tools/params/tool/propose-write-file.ts +0 -71
- package/common/src/tools/params/tool/read-docs.ts +0 -85
- package/common/src/tools/params/tool/read-files.ts +0 -61
- package/common/src/tools/params/tool/read-subtree.ts +0 -83
- package/common/src/tools/params/tool/read-url.ts +0 -81
- package/common/src/tools/params/tool/render-ui.ts +0 -203
- package/common/src/tools/params/tool/run-file-change-hooks.ts +0 -57
- package/common/src/tools/params/tool/run-readonly-command.ts +0 -76
- package/common/src/tools/params/tool/run-terminal-command.ts +0 -185
- package/common/src/tools/params/tool/sequential-thinking.ts +0 -110
- package/common/src/tools/params/tool/set-messages.ts +0 -42
- package/common/src/tools/params/tool/set-output.ts +0 -62
- package/common/src/tools/params/tool/set-scaffold-complete.ts +0 -51
- package/common/src/tools/params/tool/skill.ts +0 -56
- package/common/src/tools/params/tool/spawn-agent-inline.ts +0 -57
- package/common/src/tools/params/tool/spawn-agents.ts +0 -154
- package/common/src/tools/params/tool/str-replace.ts +0 -107
- package/common/src/tools/params/tool/suggest-followups.ts +0 -94
- package/common/src/tools/params/tool/task-completed.ts +0 -58
- package/common/src/tools/params/tool/think-deeply.ts +0 -53
- package/common/src/tools/params/tool/transition-phase.ts +0 -57
- package/common/src/tools/params/tool/update-subgoal.ts +0 -89
- package/common/src/tools/params/tool/web-search.ts +0 -73
- package/common/src/tools/params/tool/write-file.ts +0 -71
- package/common/src/tools/params/tool/write-todos.ts +0 -67
- package/common/src/tools/params/utils.ts +0 -152
- package/common/src/tools/safety-registry.ts +0 -274
- package/common/src/tools/safety.ts +0 -42
- package/common/src/tools/sequential-thinking.ts +0 -340
- package/common/src/tools/utils.ts +0 -25
- package/common/src/types/__tests__/dynamic-agent-template.test.ts +0 -20
- package/common/src/types/agent-template.ts +0 -223
- package/common/src/types/api/agents/publish.ts +0 -63
- package/common/src/types/contracts/agent-runtime.ts +0 -84
- package/common/src/types/contracts/analytics.ts +0 -12
- package/common/src/types/contracts/bigquery.ts +0 -55
- package/common/src/types/contracts/billing.ts +0 -46
- package/common/src/types/contracts/client.ts +0 -52
- package/common/src/types/contracts/database.ts +0 -104
- package/common/src/types/contracts/env.ts +0 -203
- package/common/src/types/contracts/llm.ts +0 -183
- package/common/src/types/contracts/logger.ts +0 -29
- package/common/src/types/contracts/logs.ts +0 -34
- package/common/src/types/contracts/trace.ts +0 -21
- package/common/src/types/dynamic-agent-template.ts +0 -290
- package/common/src/types/filesystem.ts +0 -10
- package/common/src/types/function-params.ts +0 -35
- package/common/src/types/grant.ts +0 -20
- package/common/src/types/gravity-index.ts +0 -170
- package/common/src/types/json.ts +0 -26
- package/common/src/types/mcp.ts +0 -26
- package/common/src/types/messages/content-part.ts +0 -59
- package/common/src/types/messages/data-content.ts +0 -14
- package/common/src/types/messages/provider-metadata.ts +0 -10
- package/common/src/types/messages/savant-code-message.ts +0 -55
- package/common/src/types/organization.ts +0 -118
- package/common/src/types/print-mode.ts +0 -167
- package/common/src/types/publisher.ts +0 -67
- package/common/src/types/savant-free-session.ts +0 -295
- package/common/src/types/savant-free-streak.ts +0 -6
- package/common/src/types/session-state.ts +0 -237
- package/common/src/types/skill.ts +0 -56
- package/common/src/types/source.ts +0 -11
- package/common/src/types/spawn.ts +0 -13
- package/common/src/types/subscription.ts +0 -68
- package/common/src/types/usage.ts +0 -16
- package/common/src/types/util.ts +0 -3
- package/common/src/util/__tests__/analytics-dispatcher.test.ts +0 -145
- package/common/src/util/__tests__/analytics-log.test.ts +0 -110
- package/common/src/util/__tests__/analytics-sampling.test.ts +0 -131
- package/common/src/util/__tests__/axiom-only-log.test.ts +0 -64
- package/common/src/util/__tests__/engagement-tracker.test.ts +0 -115
- package/common/src/util/__tests__/error-abort.test.ts +0 -822
- package/common/src/util/__tests__/error-api-details.test.ts +0 -190
- package/common/src/util/__tests__/format-code-search.test.ts +0 -60
- package/common/src/util/__tests__/log-mirror.test.ts +0 -31
- package/common/src/util/__tests__/messages.test.ts +0 -1118
- package/common/src/util/__tests__/partial-json-delta.test.ts +0 -505
- package/common/src/util/__tests__/paths.test.ts +0 -289
- package/common/src/util/__tests__/promise.test.ts +0 -334
- package/common/src/util/__tests__/protocol-config.test.ts +0 -119
- package/common/src/util/__tests__/rate-limit.test.ts +0 -28
- package/common/src/util/__tests__/reddit-savant-free-retention.test.ts +0 -120
- package/common/src/util/__tests__/savant-free-streak.test.ts +0 -142
- package/common/src/util/__tests__/saxy.test.ts +0 -1008
- package/common/src/util/__tests__/string.test.ts +0 -238
- package/common/src/util/__tests__/zoned-time.test.ts +0 -88
- package/common/src/util/agent-file-utils.ts +0 -110
- package/common/src/util/agent-id-parsing.ts +0 -147
- package/common/src/util/agent-name-normalization.ts +0 -39
- package/common/src/util/analytics-dispatcher.ts +0 -81
- package/common/src/util/analytics-log.ts +0 -84
- package/common/src/util/analytics-sampling.ts +0 -225
- package/common/src/util/array.ts +0 -63
- package/common/src/util/axiom-only-log.ts +0 -79
- package/common/src/util/cache-debug.ts +0 -191
- package/common/src/util/credentials.ts +0 -12
- package/common/src/util/currency.ts +0 -25
- package/common/src/util/dates.ts +0 -81
- package/common/src/util/engagement-tracker.ts +0 -133
- package/common/src/util/error.ts +0 -580
- package/common/src/util/file.ts +0 -363
- package/common/src/util/format-code-search.ts +0 -115
- package/common/src/util/lazy-response-ads.ts +0 -93
- package/common/src/util/log-data.ts +0 -57
- package/common/src/util/log-mirror.ts +0 -34
- package/common/src/util/lru-cache.ts +0 -67
- package/common/src/util/messages.ts +0 -600
- package/common/src/util/model-utils.ts +0 -25
- package/common/src/util/object.ts +0 -137
- package/common/src/util/param-helpers.ts +0 -49
- package/common/src/util/partial-json-delta.ts +0 -100
- package/common/src/util/paths.ts +0 -194
- package/common/src/util/promise.ts +0 -87
- package/common/src/util/protocol-config.ts +0 -141
- package/common/src/util/random.ts +0 -15
- package/common/src/util/rate-limit.ts +0 -56
- package/common/src/util/reddit-capi-events.ts +0 -40
- package/common/src/util/reddit-savant-free-retention.ts +0 -69
- package/common/src/util/response-ad-positions.ts +0 -54
- package/common/src/util/savant-free-privacy.ts +0 -78
- package/common/src/util/savant-free-streak.ts +0 -153
- package/common/src/util/saxy.ts +0 -739
- package/common/src/util/skills.ts +0 -32
- package/common/src/util/stop-sequence.ts +0 -60
- package/common/src/util/string.ts +0 -419
- package/common/src/util/system-info.ts +0 -51
- package/common/src/util/type-narrowing.ts +0 -125
- package/common/src/util/xml.ts +0 -17
- package/common/src/util/zod-schema.ts +0 -80
- package/common/src/util/zoned-time.ts +0 -136
- package/common/src/utils/ask-user-bridge.ts +0 -47
- package/common/tsconfig.json +0 -8
- package/database.db +0 -0
- package/dev/LEARNINGS.md +0 -309
- package/dev/fids/.gitkeep +0 -0
- package/dev/fids/archive/.gitkeep +0 -0
- package/dev/fids/archive/FID-2026-0802-008-sdk-package-audit-client-run-run-state.md +0 -238
- package/dev/fids/archive/FID-2026-0803-001-echo-enforcement-layer-drift.md +0 -404
- package/dev/fids/archive/FID-2026-0803-002-llm-providers-database-audit.md +0 -348
- package/dev/fids/archive/FID-2026-0803-003-sdk-impl-common-util-audit.md +0 -277
- package/dev/fids/archive/FID-2026-0803-004-checkpoint-rewind.md +0 -181
- package/dev/fids/archive/FID-2026-0803-005-quality-scan-hygiene-fixes.md +0 -265
- package/dev/fids/archive/FID-2026-0803-006-code-map-audit-hygiene.md +0 -243
- package/dev/fids/archive/FID-2026-0803-007-evals-benchmark-audit-hygiene.md +0 -296
- package/dev/fids/archive/FID-2026-0803-009-echo-enforcement-doc-drift.md +0 -112
- package/dev/fids/archive/FID-2026-0803-010-database-llm-providers-low-fixes.md +0 -255
- package/dev/fids/archive/FID-2026-0803-011-build-artifact-hygiene.md +0 -169
- package/dev/fids/archive/FID-2026-0803-012-release-readiness-audit.md +0 -162
- package/dev/fids/archive/FID-2026-0803-013-agent-roster-over-reporting.md +0 -146
- package/dev/fids/archive/FID-2026-0803-014-freebuff-to-savant-rebrand-sweep.md +0 -185
- package/dev/nova/reports/2026-08-02-top-25-ai-inference-providers-competitive-intel.md +0 -213
- package/dev/nova/specs/echo-v0.1.2-freebuff.md +0 -391
- package/dev/nova/specs/goal-loop-feature-spec.md +0 -245
- package/dev/nova/specs/launch-strategy-research-prompt.md +0 -88
- package/dev/releases/README.md +0 -50
- package/dev/scratchpad/.gitkeep +0 -0
- package/dev/session-summaries/.gitkeep +0 -0
- package/dev/session-summaries/2026-07-16-1255.md +0 -128
- package/dev/session-summaries/2026-07-17-1000.md +0 -64
- package/dev/session-summaries/2026-07-19-eslint-zero-tolerance-cleanup.md +0 -145
- package/dev/session-summaries/2026-07-19-fid-026-debugging-and-rename.md +0 -79
- package/dev/session-summaries/2026-07-19-fid-026-phase-b-rebrand.md +0 -76
- package/dev/session-summaries/2026-07-19-fid-027-clean-break.md +0 -47
- package/dev/session-summaries/2026-07-19-pre-push-house-cleaning.md +0 -100
- package/dev/session-summaries/2026-07-19-v0.0.2-release-session.md +0 -229
- package/dev/session-summaries/2026-07-20-1805-fid-loop-closure.md +0 -95
- package/dev/session-summaries/2026-07-22-1800.md +0 -52
- package/dev/session-summaries/2026-07-23-fsm-optimization.md +0 -88
- package/dev/session-summaries/2026-07-25-0000.md +0 -80
- package/dev/session-summaries/2026-07-25-1200-context-compaction.md +0 -154
- package/dev/session-summaries/2026-07-25-1600-layer4-reactive-compact.md +0 -96
- package/dev/session-summaries/2026-07-25-1700-dev-folder-audit.md +0 -161
- package/dev/session-summaries/2026-07-25-2000-benchmark-v2-filters.md +0 -147
- package/dev/session-summaries/2026-07-25-2000.md +0 -77
- package/dev/session-summaries/2026-07-27-0000.md +0 -63
- package/dev/session-summaries/2026-07-28-history-capture-handoff.md +0 -206
- package/dev/session-summaries/2026-07-31-freebuff-echo-compliance-remediation.md +0 -156
- package/dev/session-summaries/2026-07-31-pre-launch-optimization-execution.md +0 -46
- package/dev/session-summaries/2026-0721-1800.md +0 -44
- package/dev/session-summaries/2026-08-01-sidebar-folded-startup.md +0 -159
- package/dev/session-summaries/2026-08-02-0.0.15-release-closeout.md +0 -32
- package/dev/session-summaries/2026-08-02-repository-hygiene.md +0 -51
- package/dev/session-summaries/2026-08-03-agent-roster-fix-and-ready-check-closeout.md +0 -73
- package/dev/session-summaries/2026-08-03-build-artifact-hygiene-closeout.md +0 -40
- package/dev/session-summaries/2026-08-03-code-map-audit-closeout.md +0 -44
- package/dev/session-summaries/2026-08-03-database-llm-providers-low-fixes-closeout.md +0 -47
- package/dev/session-summaries/2026-08-03-echo-enforcement-doc-drift-closeout.md +0 -43
- package/dev/session-summaries/2026-08-03-evals-benchmark-audit-closeout.md +0 -50
- package/dev/session-summaries/2026-08-03-quality-scan-hygiene-fixes-closeout.md +0 -57
- package/dev/session-summaries/2026-08-03-quality-session-checkpoint-rewind-closeout.md +0 -56
- package/dev/session-summaries/2026-08-03-release-readiness-audit-closeout.md +0 -60
- package/dev/test-prompts/archive/0.0.2-final-pass.md +0 -209
- package/dev/test-prompts/archive/agent-capabilities-full-test.md +0 -361
- package/dev/test-prompts/archive/agent-capabilities-test.md +0 -471
- package/dev/test-prompts/archive/comprehensive-az-system-test-v1.md +0 -441
- package/dev/test-prompts/archive/comprehensive-az-system-test-v2-report.md +0 -377
- package/dev/test-prompts/archive/comprehensive-az-system-test-v2.md +0 -544
- package/dev/test-prompts/archive/comprehensive-az-system-test.md +0 -396
- package/dev/test-prompts/archive/comprehensive-az-test-final.md +0 -900
- package/dev/test-prompts/archive/comprehensive-az-test-v11.md +0 -141
- package/dev/test-prompts/archive/comprehensive-az-test-v12.md +0 -29
- package/dev/test-prompts/archive/comprehensive-az-test-v6.md +0 -631
- package/dev/test-prompts/archive/comprehensive-az-test-v7.md +0 -625
- package/dev/test-prompts/archive/fid-007-ability-confirmation.md +0 -248
- package/dev/test-prompts/archive/fid-2026-0801-006-thinker-tool-call-boundary.md +0 -86
- package/dev/test-prompts/archive/fid-2026-0801-007-child-tool-set-fallback-cli.md +0 -101
- package/dev/test-prompts/archive/fid-2026-0801-008-provider-tool-call-accumulation-cli.md +0 -111
- package/dev/test-prompts/archive/fid-2026-0801-012-thinker-state-output-cli.md +0 -134
- package/dev/test-prompts/archive/gemini-deep-research-sidebar-highlight.md +0 -598
- package/dev/test-prompts/archive/goal-loop-cli-test.md +0 -142
- package/dev/test-prompts/archive/rebrand-qa.md +0 -258
- package/dev/test-prompts/archive/release-az-test-fid-085.md +0 -306
- package/dev/test-prompts/archive/release-az-test-fid-087.md +0 -219
- package/dev/test-prompts/archive/release-az-test-fid-2026-0726-001.md +0 -270
- package/dev/test-prompts/archive/release-az-test-fid-2026-0728-008.md +0 -213
- package/dev/test-prompts/archive/release-az-test-fid-2026-0728-launch-tracks.md +0 -253
- package/dev/test-prompts/archive/release-az-test-fid-2026-0731-pre-launch.md +0 -102
- package/docs/AI Coding Agents Market Research.md +0 -516
- package/docs/Agent Harness Feature Pairing Research.md +0 -166
- package/docs/CLI Agent Inference Backend Research.md +0 -446
- package/docs/Codebuff Rebranding And Migration Plan.md +0 -418
- package/docs/ECHO-EVOLUTION-ARCH.md +0 -77
- package/docs/Harness Engineering for Coding Agents Research.md +0 -196
- package/docs/Launch Plan Review and Optimization.md +0 -178
- package/docs/OpenTUI Sidebar Bug Fix.md +0 -245
- package/docs/SAVANT-VERSIONING.md +0 -31
- package/docs/Savant Code Launch Strategy.md +0 -270
- package/docs/Savant-Code Business And Backend Research.md +0 -222
- package/docs/agents-and-tools.md +0 -217
- package/docs/cloudflare-llms-full.md +0 -9623
- package/docs/design/OpenTUI Terminal Visualization Guide.md +0 -471
- package/docs/design/database-architecture.md +0 -217
- package/docs/design/deep-research-report.md +0 -295
- package/docs/design/thinker-sequentialthinking-regression-diagnostic.md +0 -366
- package/docs/discord-server-design.md +0 -167
- package/docs/gravity-integration-starter.md +0 -202
- package/docs/launch/hn-first-comment.md +0 -44
- package/docs/launch/hn-post.md +0 -35
- package/docs/launch/incident-response.md +0 -88
- package/docs/launch/landing/index.html +0 -233
- package/docs/launch/mastodon-thread.md +0 -52
- package/docs/launch/newsletter-pitch.md +0 -49
- package/docs/launch/twitter-thread.md +0 -62
- package/docs/privacy.md +0 -186
- package/docs/reports/Savant-Code Benchmark Specification.md +0 -206
- package/docs/reports/Thinker Agent Architecture Research.md +0 -284
- package/docs/reports/adoptable-features-2026-07-25.md +0 -604
- package/docs/reports/adoptable-features-master.md +0 -480
- package/docs/reports/codebuff-discord-feedback.md +0 -43
- package/docs/reports/feature-parity-report.md +0 -810
- package/docs/reports/repos/AionUi.md +0 -75
- package/docs/reports/repos/OpenHands.md +0 -76
- package/docs/reports/repos/SWE-agent.md +0 -82
- package/docs/reports/repos/agno.md +0 -89
- package/docs/reports/repos/aider.md +0 -74
- package/docs/reports/repos/cline.md +0 -83
- package/docs/reports/repos/codex.md +0 -83
- package/docs/reports/repos/gemini-cli.md +0 -92
- package/docs/reports/repos/goose.md +0 -65
- package/docs/reports/repos/gpt-pilot.md +0 -52
- package/docs/reports/repos/hermes-agent.md +0 -101
- package/docs/reports/repos/kilocode.md +0 -79
- package/docs/reports/repos/openclaude.md +0 -99
- package/docs/reports/repos/openclaw.md +0 -100
- package/docs/reports/repos/opencode-dev.md +0 -78
- package/docs/reports/repos/zero.md +0 -123
- package/docs/reports/savant-code-benchmark-v2-2026-08-03.md +0 -76
- package/docs/savant-code-modes.md +0 -338
- package/docs/testing.md +0 -51
- package/docs/visual-mockup-neon-slate.txt +0 -41
- package/eslint.config.js +0 -211
- package/evals/README.md +0 -45
- package/evals/benchmark/README.md +0 -449
- package/evals/benchmark/agent-runner.ts +0 -217
- package/evals/benchmark/analyze-task-scores.ts +0 -496
- package/evals/benchmark/eval-codebuff-hard.json +0 -3343
- package/evals/benchmark/eval-codebuff.json +0 -3193
- package/evals/benchmark/eval-codebuff2.json +0 -2494
- package/evals/benchmark/eval-manifold-hard.json +0 -2525
- package/evals/benchmark/eval-manifold.json +0 -1675
- package/evals/benchmark/eval-manifold2.json +0 -1945
- package/evals/benchmark/eval-plane-hard.json +0 -4372
- package/evals/benchmark/eval-plane.json +0 -2028
- package/evals/benchmark/eval-plane2.json +0 -3517
- package/evals/benchmark/eval-saleor-hard.json +0 -6081
- package/evals/benchmark/eval-saleor.json +0 -1829
- package/evals/benchmark/eval-saleor2.json +0 -3273
- package/evals/benchmark/eval-task-generator.ts +0 -158
- package/evals/benchmark/filter-supplemental-files.ts +0 -225
- package/evals/benchmark/format-output.ts +0 -215
- package/evals/benchmark/gen-evals.ts +0 -294
- package/evals/benchmark/gen-repo-eval.ts +0 -71
- package/evals/benchmark/judge.ts +0 -308
- package/evals/benchmark/lessons-extractor.ts +0 -247
- package/evals/benchmark/main-hard-tasks.ts +0 -49
- package/evals/benchmark/main-single-eval.ts +0 -23
- package/evals/benchmark/main.ts +0 -29
- package/evals/benchmark/meta-analyzer.ts +0 -329
- package/evals/benchmark/pick-commits.ts +0 -627
- package/evals/benchmark/run-benchmark.ts +0 -657
- package/evals/benchmark/runners/claude.ts +0 -176
- package/evals/benchmark/runners/codex.ts +0 -143
- package/evals/benchmark/runners/index.ts +0 -4
- package/evals/benchmark/runners/opencode.ts +0 -253
- package/evals/benchmark/runners/runner.ts +0 -13
- package/evals/benchmark/runners/savant.ts +0 -148
- package/evals/benchmark/setup-test-repo.ts +0 -314
- package/evals/benchmark/trace-analyzer.ts +0 -257
- package/evals/benchmark/trace-utils.ts +0 -80
- package/evals/benchmark/types.ts +0 -83
- package/evals/bunfig.toml +0 -4
- package/evals/logger.ts +0 -87
- package/evals/package.json +0 -31
- package/evals/subagents/test-repo-utils.ts +0 -131
- package/evals/tsconfig.json +0 -13
- package/evals/v2/README.md +0 -149
- package/evals/v2/reports/report.json +0 -261
- package/evals/v2/reports/report.md +0 -15
- package/evals/v2/schema/task.schema.json +0 -172
- package/evals/v2/src/cli.ts +0 -216
- package/evals/v2/src/golden.ts +0 -73
- package/evals/v2/src/harness.ts +0 -293
- package/evals/v2/src/metrics.ts +0 -326
- package/evals/v2/src/registry.ts +0 -179
- package/evals/v2/src/reports.ts +0 -126
- package/evals/v2/src/runner.ts +0 -143
- package/evals/v2/src/runners/savant.ts +0 -105
- package/evals/v2/src/sandbox.ts +0 -42
- package/evals/v2/src/sandboxes/docker.ts +0 -49
- package/evals/v2/src/sandboxes/tempdir.ts +0 -120
- package/evals/v2/src/schema.ts +0 -83
- package/evals/v2/src/trace.ts +0 -186
- package/evals/v2/src/verify.ts +0 -199
- package/evals/v2/tasks/error_recovery/env-fault/calculator.js +0 -11
- package/evals/v2/tasks/error_recovery/env-fault/calculator.test.js +0 -15
- package/evals/v2/tasks/error_recovery/env-fault/golden.patch +0 -15
- package/evals/v2/tasks/error_recovery/env-fault/task.yaml +0 -20
- package/evals/v2/tasks/multi_agent_orchestration/options-contract/app.js +0 -5
- package/evals/v2/tasks/multi_agent_orchestration/options-contract/app.test.js +0 -7
- package/evals/v2/tasks/multi_agent_orchestration/options-contract/golden.patch +0 -19
- package/evals/v2/tasks/multi_agent_orchestration/options-contract/greet.js +0 -3
- package/evals/v2/tasks/multi_agent_orchestration/options-contract/orchestration.test.js +0 -30
- package/evals/v2/tasks/multi_agent_orchestration/options-contract/task.yaml +0 -29
- package/evals/v2/tasks/pure_coding/add-fix/add.js +0 -3
- package/evals/v2/tasks/pure_coding/add-fix/add.test.js +0 -11
- package/evals/v2/tasks/pure_coding/add-fix/golden.patch +0 -7
- package/evals/v2/tasks/pure_coding/add-fix/task.yaml +0 -20
- package/evals/v2/tasks/pure_coding/rename-greet/app.js +0 -5
- package/evals/v2/tasks/pure_coding/rename-greet/app.test.js +0 -32
- package/evals/v2/tasks/pure_coding/rename-greet/golden.patch +0 -19
- package/evals/v2/tasks/pure_coding/rename-greet/greet.js +0 -5
- package/evals/v2/tasks/pure_coding/rename-greet/task.yaml +0 -21
- package/evals/v2/tests/golden.test.ts +0 -104
- package/evals/v2/tests/harness.test.ts +0 -204
- package/evals/v2/tests/metrics.test.ts +0 -353
- package/evals/v2/tests/registry.test.ts +0 -210
- package/evals/v2/tests/reports.test.ts +0 -218
- package/evals/v2/tests/savant-runner.test.ts +0 -218
- package/evals/v2/tests/schema.test.ts +0 -127
- package/evals/v2/tests/tempdir-sandbox.test.ts +0 -49
- package/evals/v2/tests/trace.test.ts +0 -76
- package/evals/v2/tests/verify.test.ts +0 -224
- package/license +0 -202
- package/packages/agent-runtime/README.md +0 -46
- package/packages/agent-runtime/agent_exit +0 -1
- package/packages/agent-runtime/bunfig.toml +0 -2
- package/packages/agent-runtime/package.json +0 -34
- package/packages/agent-runtime/src/__tests__/apply-patch-tool.test.ts +0 -202
- package/packages/agent-runtime/src/__tests__/cost-aggregation.test.ts +0 -397
- package/packages/agent-runtime/src/__tests__/generate-diffs-prompt.test.ts +0 -107
- package/packages/agent-runtime/src/__tests__/get-file-reading-updates.test.ts +0 -59
- package/packages/agent-runtime/src/__tests__/gravity-index-tool.test.ts +0 -501
- package/packages/agent-runtime/src/__tests__/loop-agent-steps.test.ts +0 -1512
- package/packages/agent-runtime/src/__tests__/main-prompt.test.ts +0 -452
- package/packages/agent-runtime/src/__tests__/n-parameter.test.ts +0 -984
- package/packages/agent-runtime/src/__tests__/process-file-block.test.ts +0 -196
- package/packages/agent-runtime/src/__tests__/process-str-replace.test.ts +0 -512
- package/packages/agent-runtime/src/__tests__/programmatic-tool-authorization.test.ts +0 -219
- package/packages/agent-runtime/src/__tests__/prompt-caching-subagents.test.ts +0 -749
- package/packages/agent-runtime/src/__tests__/prompts-schema-handling.test.ts +0 -454
- package/packages/agent-runtime/src/__tests__/propose-tools.test.ts +0 -824
- package/packages/agent-runtime/src/__tests__/read-docs-tool.test.ts +0 -394
- package/packages/agent-runtime/src/__tests__/run-agent-step-prefill.test.ts +0 -161
- package/packages/agent-runtime/src/__tests__/run-agent-step-tools.test.ts +0 -612
- package/packages/agent-runtime/src/__tests__/run-programmatic-step.test.ts +0 -1743
- package/packages/agent-runtime/src/__tests__/sandbox-generator.test.ts +0 -154
- package/packages/agent-runtime/src/__tests__/spawn-agents-image-content.test.ts +0 -354
- package/packages/agent-runtime/src/__tests__/spawn-agents-message-history.test.ts +0 -280
- package/packages/agent-runtime/src/__tests__/spawn-agents-permissions.test.ts +0 -664
- package/packages/agent-runtime/src/__tests__/stream-parser-abort.test.ts +0 -250
- package/packages/agent-runtime/src/__tests__/stream-parser-reasoning.test.ts +0 -194
- package/packages/agent-runtime/src/__tests__/subagent-streaming.test.ts +0 -230
- package/packages/agent-runtime/src/__tests__/test-utils.ts +0 -96
- package/packages/agent-runtime/src/__tests__/thinker-convergence-gate.test.ts +0 -242
- package/packages/agent-runtime/src/__tests__/to-token-count-input-schema.test.ts +0 -81
- package/packages/agent-runtime/src/__tests__/tool-executor-sandbox.test.ts +0 -167
- package/packages/agent-runtime/src/__tests__/tool-stream-parser.test.ts +0 -682
- package/packages/agent-runtime/src/__tests__/tool-validation-error.test.ts +0 -1380
- package/packages/agent-runtime/src/__tests__/web-search-tool.test.ts +0 -402
- package/packages/agent-runtime/src/__tests__/xml-tool-result-ordering.test.ts +0 -264
- package/packages/agent-runtime/src/constants.ts +0 -12
- package/packages/agent-runtime/src/context-compactor.ts +0 -425
- package/packages/agent-runtime/src/find-files/__tests__/request-files-prompt.test.ts +0 -190
- package/packages/agent-runtime/src/find-files/custom-file-picker-config.ts +0 -61
- package/packages/agent-runtime/src/find-files/request-files-prompt.ts +0 -462
- package/packages/agent-runtime/src/generate-diffs-prompt.ts +0 -38
- package/packages/agent-runtime/src/get-file-reading-updates.ts +0 -27
- package/packages/agent-runtime/src/llm-api/__tests__/gemini-with-fallbacks.test.ts +0 -267
- package/packages/agent-runtime/src/llm-api/__tests__/serper-api.test.ts +0 -297
- package/packages/agent-runtime/src/llm-api/claude.ts +0 -7
- package/packages/agent-runtime/src/llm-api/context7-api.ts +0 -290
- package/packages/agent-runtime/src/llm-api/gemini-with-fallbacks.ts +0 -104
- package/packages/agent-runtime/src/llm-api/savant-code-web-api.ts +0 -370
- package/packages/agent-runtime/src/llm-api/serper-api.ts +0 -193
- package/packages/agent-runtime/src/main-prompt.ts +0 -251
- package/packages/agent-runtime/src/mcp-constants.ts +0 -12
- package/packages/agent-runtime/src/mcp.ts +0 -83
- package/packages/agent-runtime/src/process-file-block.ts +0 -118
- package/packages/agent-runtime/src/process-str-replace.ts +0 -213
- package/packages/agent-runtime/src/prompt-agent-stream.ts +0 -119
- package/packages/agent-runtime/src/run-agent-step.ts +0 -1632
- package/packages/agent-runtime/src/run-programmatic-step.ts +0 -633
- package/packages/agent-runtime/src/system-prompt/prompts.ts +0 -215
- package/packages/agent-runtime/src/system-prompt/search-system-prompt.ts +0 -89
- package/packages/agent-runtime/src/system-prompt/truncate-file-tree.ts +0 -414
- package/packages/agent-runtime/src/templates/README.md +0 -160
- package/packages/agent-runtime/src/templates/__tests__/agent-registry.test.ts +0 -489
- package/packages/agent-runtime/src/templates/__tests__/strings.test.ts +0 -465
- package/packages/agent-runtime/src/templates/agent-registry.ts +0 -122
- package/packages/agent-runtime/src/templates/prompts.ts +0 -189
- package/packages/agent-runtime/src/templates/strings.ts +0 -292
- package/packages/agent-runtime/src/templates/types.ts +0 -61
- package/packages/agent-runtime/src/tool-stream-parser.ts +0 -260
- package/packages/agent-runtime/src/tools/filter-tool-set.ts +0 -18
- package/packages/agent-runtime/src/tools/handlers/__tests__/glob.test.ts +0 -331
- package/packages/agent-runtime/src/tools/handlers/__tests__/read-subtree.test.ts +0 -346
- package/packages/agent-runtime/src/tools/handlers/__tests__/run-readonly-command.test.ts +0 -284
- package/packages/agent-runtime/src/tools/handlers/handler-function-type.ts +0 -77
- package/packages/agent-runtime/src/tools/handlers/list.ts +0 -105
- package/packages/agent-runtime/src/tools/handlers/tool/__tests__/checkpoint-store.test.ts +0 -394
- package/packages/agent-runtime/src/tools/handlers/tool/__tests__/skill.test.ts +0 -98
- package/packages/agent-runtime/src/tools/handlers/tool/__tests__/write-file.test.ts +0 -24
- package/packages/agent-runtime/src/tools/handlers/tool/add-message.ts +0 -37
- package/packages/agent-runtime/src/tools/handlers/tool/add-subgoal.ts +0 -30
- package/packages/agent-runtime/src/tools/handlers/tool/apply-patch.ts +0 -120
- package/packages/agent-runtime/src/tools/handlers/tool/ask-user.ts +0 -25
- package/packages/agent-runtime/src/tools/handlers/tool/browser-logs.ts +0 -21
- package/packages/agent-runtime/src/tools/handlers/tool/checkpoint-store.ts +0 -378
- package/packages/agent-runtime/src/tools/handlers/tool/code-search.ts +0 -21
- package/packages/agent-runtime/src/tools/handlers/tool/composio.ts +0 -52
- package/packages/agent-runtime/src/tools/handlers/tool/create-plan.ts +0 -63
- package/packages/agent-runtime/src/tools/handlers/tool/end-turn.ts +0 -15
- package/packages/agent-runtime/src/tools/handlers/tool/find-files.ts +0 -161
- package/packages/agent-runtime/src/tools/handlers/tool/glob.ts +0 -22
- package/packages/agent-runtime/src/tools/handlers/tool/gravity-index.ts +0 -230
- package/packages/agent-runtime/src/tools/handlers/tool/list-directory.ts +0 -22
- package/packages/agent-runtime/src/tools/handlers/tool/lookup-agent-info.ts +0 -105
- package/packages/agent-runtime/src/tools/handlers/tool/propose-str-replace.ts +0 -111
- package/packages/agent-runtime/src/tools/handlers/tool/propose-write-file.ts +0 -89
- package/packages/agent-runtime/src/tools/handlers/tool/proposed-content-store.ts +0 -64
- package/packages/agent-runtime/src/tools/handlers/tool/read-docs.ts +0 -160
- package/packages/agent-runtime/src/tools/handlers/tool/read-files.ts +0 -43
- package/packages/agent-runtime/src/tools/handlers/tool/read-subtree.ts +0 -198
- package/packages/agent-runtime/src/tools/handlers/tool/read-url.ts +0 -21
- package/packages/agent-runtime/src/tools/handlers/tool/render-ui.ts +0 -15
- package/packages/agent-runtime/src/tools/handlers/tool/run-file-change-hooks.ts +0 -20
- package/packages/agent-runtime/src/tools/handlers/tool/run-readonly-command.ts +0 -215
- package/packages/agent-runtime/src/tools/handlers/tool/run-terminal-command.ts +0 -33
- package/packages/agent-runtime/src/tools/handlers/tool/sequential-thinking.ts +0 -53
- package/packages/agent-runtime/src/tools/handlers/tool/set-messages.ts +0 -19
- package/packages/agent-runtime/src/tools/handlers/tool/set-output.ts +0 -104
- package/packages/agent-runtime/src/tools/handlers/tool/set-scaffold-complete.ts +0 -32
- package/packages/agent-runtime/src/tools/handlers/tool/skill.ts +0 -146
- package/packages/agent-runtime/src/tools/handlers/tool/spawn-agent-inline.ts +0 -149
- package/packages/agent-runtime/src/tools/handlers/tool/spawn-agent-utils.ts +0 -436
- package/packages/agent-runtime/src/tools/handlers/tool/spawn-agents.ts +0 -286
- package/packages/agent-runtime/src/tools/handlers/tool/str-replace.ts +0 -135
- package/packages/agent-runtime/src/tools/handlers/tool/suggest-followups.ts +0 -20
- package/packages/agent-runtime/src/tools/handlers/tool/task-completed.ts +0 -15
- package/packages/agent-runtime/src/tools/handlers/tool/think-deeply.ts +0 -25
- package/packages/agent-runtime/src/tools/handlers/tool/transition-phase.ts +0 -160
- package/packages/agent-runtime/src/tools/handlers/tool/update-subgoal.ts +0 -48
- package/packages/agent-runtime/src/tools/handlers/tool/web-search.ts +0 -151
- package/packages/agent-runtime/src/tools/handlers/tool/write-file.ts +0 -281
- package/packages/agent-runtime/src/tools/handlers/tool/write-todos.ts +0 -19
- package/packages/agent-runtime/src/tools/prompts.ts +0 -233
- package/packages/agent-runtime/src/tools/sandbox/__tests__/engine.test.ts +0 -169
- package/packages/agent-runtime/src/tools/sandbox/__tests__/shell-denylist.test.ts +0 -104
- package/packages/agent-runtime/src/tools/sandbox/engine.ts +0 -109
- package/packages/agent-runtime/src/tools/sandbox/index.ts +0 -14
- package/packages/agent-runtime/src/tools/sandbox/shell-denylist.ts +0 -119
- package/packages/agent-runtime/src/tools/stream-parser.ts +0 -407
- package/packages/agent-runtime/src/tools/thinker-convergence-gate.ts +0 -162
- package/packages/agent-runtime/src/tools/thought-session-store.ts +0 -43
- package/packages/agent-runtime/src/tools/tool-executor.ts +0 -1098
- package/packages/agent-runtime/src/util/__tests__/messages.test.ts +0 -995
- package/packages/agent-runtime/src/util/__tests__/parse-tool-calls-from-text.test.ts +0 -363
- package/packages/agent-runtime/src/util/__tests__/simplify-tool-results.test.ts +0 -382
- package/packages/agent-runtime/src/util/__tests__/stream-xml-parser.test.ts +0 -285
- package/packages/agent-runtime/src/util/__tests__/think-tags.test.ts +0 -49
- package/packages/agent-runtime/src/util/__tests__/token-counter.test.ts +0 -121
- package/packages/agent-runtime/src/util/activity-tracking.ts +0 -252
- package/packages/agent-runtime/src/util/agent-output.ts +0 -102
- package/packages/agent-runtime/src/util/cache-debug.ts +0 -330
- package/packages/agent-runtime/src/util/format-value.ts +0 -16
- package/packages/agent-runtime/src/util/messages.ts +0 -461
- package/packages/agent-runtime/src/util/parse-tool-calls-from-text.ts +0 -122
- package/packages/agent-runtime/src/util/render-read-files-result.ts +0 -18
- package/packages/agent-runtime/src/util/simplify-tool-results.ts +0 -61
- package/packages/agent-runtime/src/util/stream-xml-parser.ts +0 -259
- package/packages/agent-runtime/src/util/think-tags.ts +0 -33
- package/packages/agent-runtime/src/util/token-counter.ts +0 -136
- package/packages/agent-runtime/tsconfig.json +0 -8
- package/packages/code-map/README.md +0 -43
- package/packages/code-map/__tests__/integration.test.ts +0 -278
- package/packages/code-map/__tests__/languages.test.ts +0 -240
- package/packages/code-map/__tests__/parse.test.ts +0 -640
- package/packages/code-map/__tests__/test-langs/test.c +0 -42
- package/packages/code-map/__tests__/test-langs/test.cpp +0 -34
- package/packages/code-map/__tests__/test-langs/test.cs +0 -34
- package/packages/code-map/__tests__/test-langs/test.go +0 -27
- package/packages/code-map/__tests__/test-langs/test.java +0 -31
- package/packages/code-map/__tests__/test-langs/test.js +0 -50
- package/packages/code-map/__tests__/test-langs/test.php +0 -34
- package/packages/code-map/__tests__/test-langs/test.py +0 -25
- package/packages/code-map/__tests__/test-langs/test.rb +0 -28
- package/packages/code-map/__tests__/test-langs/test.rs +0 -28
- package/packages/code-map/__tests__/test-langs/test.ts +0 -31
- package/packages/code-map/package.json +0 -33
- package/packages/code-map/src/index.ts +0 -4
- package/packages/code-map/src/init-node.ts +0 -185
- package/packages/code-map/src/languages.ts +0 -344
- package/packages/code-map/src/parse.ts +0 -410
- package/packages/code-map/src/tree-sitter-queries/readme.md +0 -24
- package/packages/code-map/src/tree-sitter-queries/tree-sitter-c-tags.scm +0 -16
- package/packages/code-map/src/tree-sitter-queries/tree-sitter-c_sharp-tags.scm +0 -23
- package/packages/code-map/src/tree-sitter-queries/tree-sitter-cpp-tags.scm +0 -29
- package/packages/code-map/src/tree-sitter-queries/tree-sitter-go-tags.scm +0 -26
- package/packages/code-map/src/tree-sitter-queries/tree-sitter-java-tags.scm +0 -19
- package/packages/code-map/src/tree-sitter-queries/tree-sitter-javascript-tags.scm +0 -16
- package/packages/code-map/src/tree-sitter-queries/tree-sitter-php-tags.scm +0 -23
- package/packages/code-map/src/tree-sitter-queries/tree-sitter-python-tags.scm +0 -12
- package/packages/code-map/src/tree-sitter-queries/tree-sitter-ruby-tags.scm +0 -58
- package/packages/code-map/src/tree-sitter-queries/tree-sitter-rust-tags.scm +0 -26
- package/packages/code-map/src/tree-sitter-queries/tree-sitter-typescript-tags.scm +0 -22
- package/packages/code-map/src/types.ts +0 -11
- package/packages/code-map/src/utils.ts +0 -12
- package/packages/code-map/tsconfig.json +0 -10
- package/packages/database/README.md +0 -43
- package/packages/database/package.json +0 -28
- package/packages/database/src/__tests__/service.test.ts +0 -167
- package/packages/database/src/index.ts +0 -146
- package/packages/database/src/service.ts +0 -342
- package/packages/database/tsconfig.json +0 -9
- package/packages/llm-providers/README.md +0 -42
- package/packages/llm-providers/package.json +0 -42
- package/packages/llm-providers/src/ollama/__tests__/detect.test.ts +0 -59
- package/packages/llm-providers/src/ollama/detect.ts +0 -113
- package/packages/llm-providers/src/ollama/index.ts +0 -2
- package/packages/llm-providers/src/openai-compatible/chat/convert-to-openai-compatible-chat-messages.test.ts +0 -855
- package/packages/llm-providers/src/openai-compatible/chat/convert-to-openai-compatible-chat-messages.ts +0 -177
- package/packages/llm-providers/src/openai-compatible/chat/get-response-metadata.ts +0 -15
- package/packages/llm-providers/src/openai-compatible/chat/map-openai-compatible-finish-reason.ts +0 -19
- package/packages/llm-providers/src/openai-compatible/chat/openai-compatible-api-types.ts +0 -60
- package/packages/llm-providers/src/openai-compatible/chat/openai-compatible-chat-language-model.test.ts +0 -549
- package/packages/llm-providers/src/openai-compatible/chat/openai-compatible-chat-language-model.ts +0 -474
- package/packages/llm-providers/src/openai-compatible/chat/openai-compatible-chat-options.ts +0 -25
- package/packages/llm-providers/src/openai-compatible/chat/openai-compatible-metadata-extractor.ts +0 -49
- package/packages/llm-providers/src/openai-compatible/chat/openai-compatible-prepare-tools.ts +0 -162
- package/packages/llm-providers/src/openai-compatible/chat/stream-transform.test.ts +0 -106
- package/packages/llm-providers/src/openai-compatible/chat/stream-transform.ts +0 -585
- package/packages/llm-providers/src/openai-compatible/completion/convert-to-openai-compatible-completion-prompt.ts +0 -98
- package/packages/llm-providers/src/openai-compatible/completion/openai-compatible-completion-language-model.test.ts +0 -173
- package/packages/llm-providers/src/openai-compatible/completion/openai-compatible-completion-language-model.ts +0 -414
- package/packages/llm-providers/src/openai-compatible/completion/openai-compatible-completion-options.ts +0 -33
- package/packages/llm-providers/src/openai-compatible/embedding/openai-compatible-embedding-model.ts +0 -143
- package/packages/llm-providers/src/openai-compatible/embedding/openai-compatible-embedding-options.ts +0 -21
- package/packages/llm-providers/src/openai-compatible/image/openai-compatible-image-model.ts +0 -129
- package/packages/llm-providers/src/openai-compatible/image/openai-compatible-image-settings.ts +0 -1
- package/packages/llm-providers/src/openai-compatible/index.ts +0 -27
- package/packages/llm-providers/src/openai-compatible/openai-compatible-error.ts +0 -34
- package/packages/llm-providers/src/openai-compatible/openai-compatible-provider.ts +0 -174
- package/packages/llm-providers/src/openai-compatible/version.ts +0 -5
- package/packages/llm-providers/tsconfig.json +0 -9
- package/protocol.config.yaml +0 -113
- package/savant-free/README.md +0 -73
- package/savant-free/SPEC.md +0 -385
- package/savant-free/cli/build.ts +0 -49
- package/savant-free/cli/release/README.md +0 -55
- package/savant-free/cli/release/index.js +0 -37
- package/savant-free/cli/release/package.json +0 -43
- package/savant-free/cli/release.ts +0 -128
- package/savant-free/cli/smoke-test.test.ts +0 -257
- package/savant-free/e2e/README.md +0 -173
- package/savant-free/e2e/agent/savant-free-tester.ts +0 -52
- package/savant-free/e2e/tests/ads-behavior.e2e.test.ts +0 -51
- package/savant-free/e2e/tests/agent-startup.e2e.test.ts +0 -61
- package/savant-free/e2e/tests/code-edit.e2e.test.ts +0 -78
- package/savant-free/e2e/tests/help-command.e2e.test.ts +0 -97
- package/savant-free/e2e/tests/knowledge-file.e2e.test.ts +0 -66
- package/savant-free/e2e/tests/slash-commands.e2e.test.ts +0 -119
- package/savant-free/e2e/tests/startup.e2e.test.ts +0 -56
- package/savant-free/e2e/tests/terminal-command.e2e.test.ts +0 -71
- package/savant-free/e2e/tests/version.e2e.test.ts +0 -50
- package/savant-free/e2e/utils/binary-helpers.ts +0 -24
- package/savant-free/e2e/utils/index.ts +0 -17
- package/savant-free/e2e/utils/savant-free-session.ts +0 -229
- package/savant-free/e2e/utils/tmux-custom-tools.ts +0 -156
- package/savant-free/e2e/utils/tmux-helpers.ts +0 -79
- package/savant-free/package.json +0 -20
- package/scripts/eslint-rules/__fixtures__/debug-ast.mjs +0 -20
- package/scripts/eslint-rules/__fixtures__/probe.mjs +0 -41
- package/scripts/eslint-rules/__fixtures__/probe2.mjs +0 -43
- package/scripts/eslint-rules/__fixtures__/rule-test.mjs +0 -44
- package/scripts/eslint-rules/__fixtures__/rule-test2.mjs +0 -27
- package/scripts/eslint-rules/__fixtures__/unknown-bad.ts +0 -21
- package/scripts/eslint-rules/__fixtures__/unknown-good.ts +0 -35
- package/scripts/eslint-rules/no-unknown-in-signatures.js +0 -141
- package/scripts/release.py +0 -360
- package/scripts/run-az-test.sh +0 -1150
- package/scripts/sync-agents.py +0 -337
- package/scripts/tmux/README.md +0 -359
- package/scripts/tmux/package.json +0 -9
- package/scripts/tmux/tmux-capture.sh +0 -231
- package/scripts/tmux/tmux-cli.sh +0 -160
- package/scripts/tmux/tmux-env.sh +0 -34
- package/scripts/tmux/tmux-send.sh +0 -339
- package/scripts/tmux/tmux-start.sh +0 -264
- package/scripts/tmux/tmux-stop.sh +0 -157
- package/scripts/tmux/tmux-viewer/README.md +0 -254
- package/scripts/tmux/tmux-viewer/components/session-viewer.tsx +0 -556
- package/scripts/tmux/tmux-viewer/components/theme.ts +0 -54
- package/scripts/tmux/tmux-viewer/gif-encoder-2.d.ts +0 -28
- package/scripts/tmux/tmux-viewer/gif-exporter.ts +0 -278
- package/scripts/tmux/tmux-viewer/index.tsx +0 -237
- package/scripts/tmux/tmux-viewer/package.json +0 -9
- package/scripts/tmux/tmux-viewer/session-loader.ts +0 -234
- package/scripts/tmux/tmux-viewer/tsconfig.json +0 -9
- package/scripts/tmux/tmux-viewer/types.ts +0 -76
- package/sdk/CHANGELOG.md +0 -126
- package/sdk/PUBLISHING.md +0 -55
- package/sdk/README.md +0 -334
- package/sdk/bunfig.toml +0 -6
- package/sdk/e2e/README.md +0 -158
- package/sdk/e2e/custom-agents/api-integration-agent.e2e.test.ts +0 -145
- package/sdk/e2e/custom-agents/apply-patch-tool.e2e.test.ts +0 -62
- package/sdk/e2e/custom-agents/database-query-agent.e2e.test.ts +0 -135
- package/sdk/e2e/custom-agents/weather-agent.e2e.test.ts +0 -120
- package/sdk/e2e/examples/code-explainer.example.ts +0 -62
- package/sdk/e2e/examples/code-reviewer.example.ts +0 -52
- package/sdk/e2e/examples/commit-message-generator.example.ts +0 -61
- package/sdk/e2e/examples/sdk-lint.example.ts +0 -65
- package/sdk/e2e/examples/sdk-refactor.example.ts +0 -63
- package/sdk/e2e/examples/sdk-test-gen.example.ts +0 -62
- package/sdk/e2e/features/knowledge-files.e2e.test.ts +0 -82
- package/sdk/e2e/features/max-agent-steps.e2e.test.ts +0 -65
- package/sdk/e2e/features/project-files.e2e.test.ts +0 -80
- package/sdk/e2e/integration/connection-check.integration.test.ts +0 -33
- package/sdk/e2e/integration/event-ordering.integration.test.ts +0 -186
- package/sdk/e2e/integration/event-types.integration.test.ts +0 -183
- package/sdk/e2e/integration/stream-chunks.integration.test.ts +0 -191
- package/sdk/e2e/streaming/concurrent-streams.e2e.test.ts +0 -164
- package/sdk/e2e/streaming/subagent-streaming.e2e.test.ts +0 -158
- package/sdk/e2e/utils/__tests__/event-collector.test.ts +0 -297
- package/sdk/e2e/utils/e2e-mocks.ts +0 -458
- package/sdk/e2e/utils/event-collector.ts +0 -145
- package/sdk/e2e/utils/get-api-key.ts +0 -76
- package/sdk/e2e/utils/index.ts +0 -3
- package/sdk/e2e/utils/test-fixtures.ts +0 -196
- package/sdk/e2e/workflows/error-recovery.e2e.test.ts +0 -112
- package/sdk/e2e/workflows/multi-turn-conversation.e2e.test.ts +0 -132
- package/sdk/examples/readme-example-1.ts +0 -34
- package/sdk/examples/readme-example-2.ts +0 -76
- package/sdk/package.json +0 -82
- package/sdk/scripts/build.ts +0 -349
- package/sdk/scripts/fetch-ripgrep.ts +0 -172
- package/sdk/scripts/publish.ts +0 -51
- package/sdk/scripts/release.js +0 -100
- package/sdk/scripts/verify.ts +0 -204
- package/sdk/sdk_exit +0 -1
- package/sdk/smoke-test-dist.ts +0 -248
- package/sdk/src/__tests__/apply-overrides-resume.test.ts +0 -83
- package/sdk/src/__tests__/apply-patch.test.ts +0 -438
- package/sdk/src/__tests__/build-file-tree.test.ts +0 -31
- package/sdk/src/__tests__/change-file.test.ts +0 -212
- package/sdk/src/__tests__/client.test.ts +0 -142
- package/sdk/src/__tests__/clone-session-state.test.ts +0 -158
- package/sdk/src/__tests__/code-search.test.ts +0 -896
- package/sdk/src/__tests__/composio.test.ts +0 -86
- package/sdk/src/__tests__/credentials.test.ts +0 -344
- package/sdk/src/__tests__/database.test.ts +0 -153
- package/sdk/src/__tests__/env.test.ts +0 -137
- package/sdk/src/__tests__/error-utils.test.ts +0 -253
- package/sdk/src/__tests__/fixtures/windows-stubborn-grandchild.ts +0 -26
- package/sdk/src/__tests__/initial-session-state.test.ts +0 -447
- package/sdk/src/__tests__/knowledge-file-selection.test.ts +0 -335
- package/sdk/src/__tests__/load-agents.test.ts +0 -935
- package/sdk/src/__tests__/load-mcp-config.test.ts +0 -285
- package/sdk/src/__tests__/load-skills.test.ts +0 -325
- package/sdk/src/__tests__/model-provider.test.ts +0 -44
- package/sdk/src/__tests__/path-utils.test.ts +0 -66
- package/sdk/src/__tests__/read-files.test.ts +0 -573
- package/sdk/src/__tests__/read-url.test.ts +0 -371
- package/sdk/src/__tests__/researcher-web.integration.test.ts +0 -130
- package/sdk/src/__tests__/run-cancellation.test.ts +0 -1321
- package/sdk/src/__tests__/run-error-preserves-history.test.ts +0 -335
- package/sdk/src/__tests__/run-event-dispatch.test.ts +0 -80
- package/sdk/src/__tests__/run-file-filter.test.ts +0 -530
- package/sdk/src/__tests__/run-handle-event.test.ts +0 -142
- package/sdk/src/__tests__/run-mcp-tool-filter.test.ts +0 -124
- package/sdk/src/__tests__/run-state-child-process.test.ts +0 -72
- package/sdk/src/__tests__/run-terminal-command.test.ts +0 -236
- package/sdk/src/__tests__/run.integration.test.ts +0 -170
- package/sdk/src/__tests__/user-knowledge-files.test.ts +0 -361
- package/sdk/src/__tests__/validate-agents.test.ts +0 -943
- package/sdk/src/agents/load-agents.ts +0 -339
- package/sdk/src/agents/load-mcp-config.ts +0 -275
- package/sdk/src/client.ts +0 -87
- package/sdk/src/composio.ts +0 -78
- package/sdk/src/constants.ts +0 -29
- package/sdk/src/credentials.ts +0 -303
- package/sdk/src/custom-tool.ts +0 -66
- package/sdk/src/env.ts +0 -116
- package/sdk/src/error-utils.ts +0 -127
- package/sdk/src/impl/__tests__/llm-chatgpt-oauth-policy.test.ts +0 -67
- package/sdk/src/impl/__tests__/llm-native-tool-call.test.ts +0 -38
- package/sdk/src/impl/__tests__/llm-stream-yielded-content.test.ts +0 -118
- package/sdk/src/impl/__tests__/model-provider-free-mode.test.ts +0 -166
- package/sdk/src/impl/__tests__/prompt-result.test.ts +0 -210
- package/sdk/src/impl/__tests__/provider-options-metadata.test.ts +0 -67
- package/sdk/src/impl/agent-runtime.ts +0 -159
- package/sdk/src/impl/chatgpt-backend-fetch.ts +0 -588
- package/sdk/src/impl/database.ts +0 -516
- package/sdk/src/impl/llm.ts +0 -852
- package/sdk/src/impl/model-provider.ts +0 -638
- package/sdk/src/impl/openrouter-key-resolver.ts +0 -78
- package/sdk/src/index.ts +0 -133
- package/sdk/src/native/ripgrep.ts +0 -141
- package/sdk/src/retry-config.ts +0 -51
- package/sdk/src/run-state.ts +0 -897
- package/sdk/src/run.ts +0 -1222
- package/sdk/src/skills/load-skills.ts +0 -253
- package/sdk/src/testing/env.ts +0 -19
- package/sdk/src/tools/apply-patch.ts +0 -690
- package/sdk/src/tools/change-file.ts +0 -155
- package/sdk/src/tools/code-search.ts +0 -547
- package/sdk/src/tools/glob.ts +0 -58
- package/sdk/src/tools/index.ts +0 -19
- package/sdk/src/tools/list-directory.ts +0 -52
- package/sdk/src/tools/path-utils.ts +0 -101
- package/sdk/src/tools/read-files.ts +0 -110
- package/sdk/src/tools/read-url.ts +0 -469
- package/sdk/src/tools/run-file-change-hooks.ts +0 -22
- package/sdk/src/tools/run-terminal-command.ts +0 -483
- package/sdk/src/tools/ssrf.ts +0 -120
- package/sdk/src/types/env.ts +0 -40
- package/sdk/src/utils/logger.ts +0 -15
- package/sdk/src/validate-agents.ts +0 -157
- package/sdk/test/cjs-compatibility/package-lock.json +0 -423
- package/sdk/test/cjs-compatibility/package.json +0 -21
- package/sdk/test/cjs-compatibility/test-imports.js +0 -77
- package/sdk/test/cjs-compatibility/test-types.ts +0 -54
- package/sdk/test/cjs-compatibility/tsconfig.json +0 -17
- package/sdk/test/esm-compatibility/package-lock.json +0 -423
- package/sdk/test/esm-compatibility/package.json +0 -21
- package/sdk/test/esm-compatibility/test-imports.js +0 -83
- package/sdk/test/esm-compatibility/test-types.ts +0 -59
- package/sdk/test/esm-compatibility/tsconfig.json +0 -17
- package/sdk/test/ripgrep-bundling/package-lock.json +0 -423
- package/sdk/test/ripgrep-bundling/package.json +0 -21
- package/sdk/test/ripgrep-bundling/test-ripgrep-types.ts +0 -132
- package/sdk/test/ripgrep-bundling/test-ripgrep.js +0 -257
- package/sdk/test/ripgrep-bundling/tsconfig.json +0 -15
- package/sdk/test/setup-env.ts +0 -54
- package/sdk/test/test-sdk.ts +0 -25
- package/sdk/test/tree-sitter-queries/package-lock.json +0 -47
- package/sdk/test/tree-sitter-queries/package.json +0 -12
- package/sdk/test/tree-sitter-queries/test-query-files.js +0 -256
- package/sdk/tsconfig.build.json +0 -32
- package/sdk/tsconfig.json +0 -27
- package/sdk/vendor/ripgrep/arm64-darwin/rg +0 -0
- package/sdk/vendor/ripgrep/arm64-linux/rg +0 -0
- package/sdk/vendor/ripgrep/x64-darwin/rg +0 -0
- package/sdk/vendor/ripgrep/x64-linux/rg +0 -0
- package/sdk/vendor/ripgrep/x64-win32/rg.exe +0 -0
- package/templates/FID-TEMPLATE.md +0 -125
- package/templates/README-TEMPLATE.md +0 -87
- package/templates/SESSION-SUMMARY.md +0 -135
- package/tsconfig.base.json +0 -18
- package/tsconfig.json +0 -27
- /package/{cli/release-core/http.js → http.js} +0 -0
|
@@ -1,1632 +0,0 @@
|
|
|
1
|
-
import { AnalyticsEvent } from '@savant-code/common/constants/analytics-events'
|
|
2
|
-
import { shouldUseLocalTokenCount } from '@savant-code/common/constants/free-agents'
|
|
3
|
-
import {
|
|
4
|
-
supportsAssistantPrefill,
|
|
5
|
-
supportsCacheControl,
|
|
6
|
-
} from '@savant-code/common/old-constants'
|
|
7
|
-
import { TOOLS_WHICH_WONT_FORCE_NEXT_STEP } from '@savant-code/common/tools/constants'
|
|
8
|
-
import { buildArray } from '@savant-code/common/util/array'
|
|
9
|
-
import { serializeCacheDebugCorrelation } from '@savant-code/common/util/cache-debug'
|
|
10
|
-
import {
|
|
11
|
-
AbortError,
|
|
12
|
-
FETCH_IDLE_TIMEOUT_USER_MESSAGE,
|
|
13
|
-
TRANSIENT_NETWORK_ERROR_USER_MESSAGE,
|
|
14
|
-
extractApiErrorDetails,
|
|
15
|
-
getErrorObject,
|
|
16
|
-
isAbortError,
|
|
17
|
-
isFetchIdleTimeoutError,
|
|
18
|
-
isTransientNetworkError,
|
|
19
|
-
} from '@savant-code/common/util/error'
|
|
20
|
-
import { systemMessage, userMessage } from '@savant-code/common/util/messages'
|
|
21
|
-
import { toToolInputJSONSchema } from '@savant-code/common/util/zod-schema'
|
|
22
|
-
import { type ToolSet } from 'ai'
|
|
23
|
-
import { cloneDeep, mapValues } from 'lodash'
|
|
24
|
-
|
|
25
|
-
import { CACHE_DEBUG_FULL_LOGGING } from './constants'
|
|
26
|
-
import { ContextCompactor } from './context-compactor'
|
|
27
|
-
import { callTokenCountAPI } from './llm-api/savant-code-web-api'
|
|
28
|
-
import { getMCPToolData } from './mcp'
|
|
29
|
-
import { getAgentStreamFromTemplate } from './prompt-agent-stream'
|
|
30
|
-
import {
|
|
31
|
-
clearProgrammaticRunState,
|
|
32
|
-
runProgrammaticStep,
|
|
33
|
-
} from './run-programmatic-step'
|
|
34
|
-
import { additionalSystemPrompts } from './system-prompt/prompts'
|
|
35
|
-
import { getAgentTemplate } from './templates/agent-registry'
|
|
36
|
-
import { buildAgentToolSet } from './templates/prompts'
|
|
37
|
-
import { getAgentPrompt } from './templates/strings'
|
|
38
|
-
import { filterToolSet } from './tools/filter-tool-set'
|
|
39
|
-
import { getToolSet } from './tools/prompts'
|
|
40
|
-
import { processStream } from './tools/stream-parser'
|
|
41
|
-
import {
|
|
42
|
-
resetThinkerConvergenceState,
|
|
43
|
-
runThinkerConvergenceGate,
|
|
44
|
-
} from './tools/thinker-convergence-gate'
|
|
45
|
-
import { cleanupThoughtSession } from './tools/thought-session-store'
|
|
46
|
-
import { setActivity } from './util/activity-tracking'
|
|
47
|
-
import { getAgentOutput } from './util/agent-output'
|
|
48
|
-
import {
|
|
49
|
-
createCacheDebugSnapshot,
|
|
50
|
-
enrichCacheDebugSnapshotWithProviderRequest,
|
|
51
|
-
enrichCacheDebugSnapshotWithUsage,
|
|
52
|
-
} from './util/cache-debug'
|
|
53
|
-
import {
|
|
54
|
-
withSystemInstructionTags,
|
|
55
|
-
withSystemTags as withSystemTags,
|
|
56
|
-
buildUserMessageContent,
|
|
57
|
-
expireMessages,
|
|
58
|
-
} from './util/messages'
|
|
59
|
-
import { isThinkOnlyResponse } from './util/think-tags'
|
|
60
|
-
import {
|
|
61
|
-
countTokens,
|
|
62
|
-
countTokensJson,
|
|
63
|
-
countTokensMessagesCached,
|
|
64
|
-
} from './util/token-counter'
|
|
65
|
-
|
|
66
|
-
import type { AgentTemplate } from '@savant-code/common/types/agent-template'
|
|
67
|
-
import type { TrackEventFn } from '@savant-code/common/types/contracts/analytics'
|
|
68
|
-
import type {
|
|
69
|
-
AddAgentStepFn,
|
|
70
|
-
FinishAgentRunFn,
|
|
71
|
-
StartAgentRunFn,
|
|
72
|
-
} from '@savant-code/common/types/contracts/database'
|
|
73
|
-
import type {
|
|
74
|
-
CacheDebugUsageData,
|
|
75
|
-
PromptAiSdkFn,
|
|
76
|
-
} from '@savant-code/common/types/contracts/llm'
|
|
77
|
-
import type { Logger } from '@savant-code/common/types/contracts/logger'
|
|
78
|
-
import type { TraceWriter } from '@savant-code/common/types/contracts/trace'
|
|
79
|
-
import type { ParamsExcluding } from '@savant-code/common/types/function-params'
|
|
80
|
-
import type { JSONValue } from '@savant-code/common/types/json'
|
|
81
|
-
import type {
|
|
82
|
-
TextPart,
|
|
83
|
-
ImagePart,
|
|
84
|
-
} from '@savant-code/common/types/messages/content-part'
|
|
85
|
-
import type {
|
|
86
|
-
Message,
|
|
87
|
-
ToolMessage,
|
|
88
|
-
} from '@savant-code/common/types/messages/savant-code-message'
|
|
89
|
-
import type { PrintModeEvent } from '@savant-code/common/types/print-mode'
|
|
90
|
-
import type {
|
|
91
|
-
AgentTemplateType,
|
|
92
|
-
AgentState,
|
|
93
|
-
AgentOutput,
|
|
94
|
-
} from '@savant-code/common/types/session-state'
|
|
95
|
-
import type {
|
|
96
|
-
CustomToolDefinitions,
|
|
97
|
-
ProjectFileContext,
|
|
98
|
-
} from '@savant-code/common/util/file'
|
|
99
|
-
import type z from 'zod/v4'
|
|
100
|
-
|
|
101
|
-
// Convert a tool's stored inputSchema into JSON Schema suitable for Anthropic's
|
|
102
|
-
// count_tokens API. Built-in and MCP tools store a Zod schema here; serializing
|
|
103
|
-
// it raw ships Zod internals (`def`/`shape`) instead of JSON Schema, so token
|
|
104
|
-
// counts are computed against garbage and any schema whose top-level isn't an
|
|
105
|
-
// object (e.g. a union → `anyOf`) arrives without `type`, which the API rejects
|
|
106
|
-
// with `tools.N.custom.input_schema.type: Field required`. We convert to JSON
|
|
107
|
-
// Schema and guarantee a top-level `type: 'object'`.
|
|
108
|
-
export function toTokenCountInputSchema(
|
|
109
|
-
inputSchema: JSONValue,
|
|
110
|
-
): Record<string, JSONValue> | undefined {
|
|
111
|
-
if (inputSchema == null) return undefined
|
|
112
|
-
|
|
113
|
-
let jsonSchema: Record<string, JSONValue>
|
|
114
|
-
if (
|
|
115
|
-
typeof (inputSchema as { safeParse?: unknown }).safeParse === 'function'
|
|
116
|
-
) {
|
|
117
|
-
try {
|
|
118
|
-
jsonSchema = toToolInputJSONSchema(
|
|
119
|
-
inputSchema as unknown as z.ZodType,
|
|
120
|
-
) as Record<string, JSONValue>
|
|
121
|
-
} catch {
|
|
122
|
-
jsonSchema = { type: 'object', properties: {} }
|
|
123
|
-
}
|
|
124
|
-
} else if (typeof inputSchema === 'object' && !Array.isArray(inputSchema)) {
|
|
125
|
-
// Already a plain object (e.g. a pre-serialized JSON Schema) — copy it.
|
|
126
|
-
jsonSchema = { ...(inputSchema as Record<string, JSONValue>) }
|
|
127
|
-
} else {
|
|
128
|
-
return undefined
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
// `$schema` is meaningless to count_tokens; drop it to keep the payload lean.
|
|
132
|
-
delete jsonSchema['$schema']
|
|
133
|
-
// Anthropic requires a top-level `type: 'object'`. Object schemas already
|
|
134
|
-
// carry it; union/intersection schemas (anyOf/allOf) don't — backfill it.
|
|
135
|
-
// Treat missing / null / empty-string as absent (valid JSON Schema `type` is
|
|
136
|
-
// always a non-empty string or array).
|
|
137
|
-
if (jsonSchema.type == null || jsonSchema.type === '') {
|
|
138
|
-
jsonSchema.type = 'object'
|
|
139
|
-
}
|
|
140
|
-
return jsonSchema
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
async function additionalToolDefinitions(
|
|
144
|
-
params: {
|
|
145
|
-
agentTemplate: AgentTemplate
|
|
146
|
-
fileContext: ProjectFileContext
|
|
147
|
-
} & ParamsExcluding<
|
|
148
|
-
typeof getMCPToolData,
|
|
149
|
-
'toolNames' | 'mcpServers' | 'writeTo'
|
|
150
|
-
>,
|
|
151
|
-
): Promise<CustomToolDefinitions> {
|
|
152
|
-
const { agentTemplate, fileContext } = params
|
|
153
|
-
|
|
154
|
-
const defs = cloneDeep(
|
|
155
|
-
Object.fromEntries(
|
|
156
|
-
Object.entries(fileContext.customToolDefinitions).filter(([toolName]) =>
|
|
157
|
-
agentTemplate.toolNames.includes(toolName),
|
|
158
|
-
),
|
|
159
|
-
),
|
|
160
|
-
)
|
|
161
|
-
return getMCPToolData({
|
|
162
|
-
...params,
|
|
163
|
-
toolNames: agentTemplate.toolNames,
|
|
164
|
-
mcpServers: agentTemplate.mcpServers,
|
|
165
|
-
writeTo: defs,
|
|
166
|
-
})
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
export const runAgentStep = async (
|
|
170
|
-
params: {
|
|
171
|
-
userId: string | undefined
|
|
172
|
-
userInputId: string
|
|
173
|
-
clientSessionId: string
|
|
174
|
-
fingerprintId: string
|
|
175
|
-
repoId: string | undefined
|
|
176
|
-
onResponseChunk: (chunk: string | PrintModeEvent) => void
|
|
177
|
-
|
|
178
|
-
agentType: AgentTemplateType
|
|
179
|
-
agentTemplate: AgentTemplate
|
|
180
|
-
fileContext: ProjectFileContext
|
|
181
|
-
agentState: AgentState
|
|
182
|
-
localAgentTemplates: Record<string, AgentTemplate>
|
|
183
|
-
|
|
184
|
-
prompt: string | undefined
|
|
185
|
-
spawnParams: Record<string, JSONValue> | undefined
|
|
186
|
-
system: string
|
|
187
|
-
n?: number
|
|
188
|
-
/** FID-2026-0802-005 L15: step prompt computed once per step by
|
|
189
|
-
* loopAgentSteps (token counting needs it too) and passed down — avoids
|
|
190
|
-
* a second formatPrompt pass (~13 replaceAll incl. file tree). */
|
|
191
|
-
stepPrompt?: string
|
|
192
|
-
/** FID-2026-0802-005 H8: step-built custom tool data (incl. MCP tools). */
|
|
193
|
-
customToolDefinitions?: CustomToolDefinitions
|
|
194
|
-
|
|
195
|
-
trackEvent: TrackEventFn
|
|
196
|
-
promptAiSdk: PromptAiSdkFn
|
|
197
|
-
traceWriter?: TraceWriter
|
|
198
|
-
} & ParamsExcluding<
|
|
199
|
-
typeof processStream,
|
|
200
|
-
| 'agentContext'
|
|
201
|
-
| 'agentState'
|
|
202
|
-
| 'agentStepId'
|
|
203
|
-
| 'agentTemplate'
|
|
204
|
-
| 'fullResponse'
|
|
205
|
-
| 'messages'
|
|
206
|
-
| 'onCostCalculated'
|
|
207
|
-
| 'repoId'
|
|
208
|
-
| 'stream'
|
|
209
|
-
> &
|
|
210
|
-
ParamsExcluding<
|
|
211
|
-
typeof getAgentStreamFromTemplate,
|
|
212
|
-
| 'agentId'
|
|
213
|
-
| 'includeCacheControl'
|
|
214
|
-
| 'messages'
|
|
215
|
-
| 'onCostCalculated'
|
|
216
|
-
| 'template'
|
|
217
|
-
> &
|
|
218
|
-
ParamsExcluding<typeof getAgentTemplate, 'agentId'> &
|
|
219
|
-
ParamsExcluding<
|
|
220
|
-
typeof getAgentPrompt,
|
|
221
|
-
'agentTemplate' | 'promptType' | 'agentState' | 'agentTemplates'
|
|
222
|
-
> &
|
|
223
|
-
ParamsExcluding<
|
|
224
|
-
typeof getMCPToolData,
|
|
225
|
-
'toolNames' | 'mcpServers' | 'writeTo'
|
|
226
|
-
> &
|
|
227
|
-
ParamsExcluding<
|
|
228
|
-
PromptAiSdkFn,
|
|
229
|
-
'messages' | 'model' | 'onCostCalculated' | 'n'
|
|
230
|
-
>,
|
|
231
|
-
): Promise<{
|
|
232
|
-
agentState: AgentState
|
|
233
|
-
fullResponse: string
|
|
234
|
-
shouldEndTurn: boolean
|
|
235
|
-
hasNativeIncompleteToolCall: boolean
|
|
236
|
-
messageId: string | null
|
|
237
|
-
nResponses?: string[]
|
|
238
|
-
}> => {
|
|
239
|
-
const {
|
|
240
|
-
agentType,
|
|
241
|
-
clientSessionId,
|
|
242
|
-
fileContext,
|
|
243
|
-
agentTemplate,
|
|
244
|
-
fingerprintId,
|
|
245
|
-
localAgentTemplates,
|
|
246
|
-
logger,
|
|
247
|
-
prompt,
|
|
248
|
-
repoId,
|
|
249
|
-
spawnParams,
|
|
250
|
-
system,
|
|
251
|
-
userId,
|
|
252
|
-
userInputId,
|
|
253
|
-
onResponseChunk,
|
|
254
|
-
promptAiSdk,
|
|
255
|
-
trackEvent,
|
|
256
|
-
additionalToolDefinitions,
|
|
257
|
-
} = params
|
|
258
|
-
let agentState = params.agentState
|
|
259
|
-
|
|
260
|
-
const { agentContext } = agentState
|
|
261
|
-
|
|
262
|
-
const startTime = Date.now()
|
|
263
|
-
|
|
264
|
-
// Generates a unique ID for each main prompt run (ie: a step of the agent loop)
|
|
265
|
-
// This is used to link logs within a single agent loop
|
|
266
|
-
const agentStepId = crypto.randomUUID()
|
|
267
|
-
trackEvent({
|
|
268
|
-
event: AnalyticsEvent.AGENT_STEP,
|
|
269
|
-
userId: userId ?? '',
|
|
270
|
-
properties: {
|
|
271
|
-
agentStepId,
|
|
272
|
-
clientSessionId,
|
|
273
|
-
fingerprintId,
|
|
274
|
-
userInputId,
|
|
275
|
-
userId: userId ?? null,
|
|
276
|
-
repoName: repoId ?? null,
|
|
277
|
-
},
|
|
278
|
-
logger,
|
|
279
|
-
})
|
|
280
|
-
|
|
281
|
-
if (agentState.stepsRemaining <= 0) {
|
|
282
|
-
logger.warn(
|
|
283
|
-
`Detected too many consecutive assistant messages without user prompt`,
|
|
284
|
-
)
|
|
285
|
-
|
|
286
|
-
onResponseChunk(`${STEP_WARNING_MESSAGE}\n\n`)
|
|
287
|
-
|
|
288
|
-
// Update message history to include the warning
|
|
289
|
-
agentState = {
|
|
290
|
-
...agentState,
|
|
291
|
-
messageHistory: [
|
|
292
|
-
...expireMessages(agentState.messageHistory, 'userPrompt'),
|
|
293
|
-
userMessage(
|
|
294
|
-
withSystemTags(
|
|
295
|
-
`The assistant has responded too many times in a row. The assistant's turn has automatically been ended. The maximum number of responses can be configured via maxAgentSteps.`,
|
|
296
|
-
),
|
|
297
|
-
),
|
|
298
|
-
],
|
|
299
|
-
}
|
|
300
|
-
return {
|
|
301
|
-
agentState,
|
|
302
|
-
fullResponse: STEP_WARNING_MESSAGE,
|
|
303
|
-
shouldEndTurn: true,
|
|
304
|
-
hasNativeIncompleteToolCall: false,
|
|
305
|
-
messageId: null,
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
// FID-2026-0802-005 L15: the step prompt is computed ONCE per step in
|
|
310
|
-
// loopAgentSteps (which needs it for token counting) and passed down —
|
|
311
|
-
// previously runAgentStep recomputed it for identical inputs. Callers that
|
|
312
|
-
// invoke runAgentStep directly (tests) still get the computed fallback.
|
|
313
|
-
const stepPrompt =
|
|
314
|
-
params.stepPrompt ??
|
|
315
|
-
(await getAgentPrompt({
|
|
316
|
-
...params,
|
|
317
|
-
agentTemplate,
|
|
318
|
-
promptType: { type: 'stepPrompt' },
|
|
319
|
-
fileContext,
|
|
320
|
-
agentState,
|
|
321
|
-
agentTemplates: localAgentTemplates,
|
|
322
|
-
logger,
|
|
323
|
-
additionalToolDefinitions,
|
|
324
|
-
}))
|
|
325
|
-
|
|
326
|
-
const agentMessagesUntruncated = buildArray<Message>(
|
|
327
|
-
...expireMessages(agentState.messageHistory, 'agentStep'),
|
|
328
|
-
|
|
329
|
-
stepPrompt &&
|
|
330
|
-
userMessage({
|
|
331
|
-
content: stepPrompt,
|
|
332
|
-
tags: ['STEP_PROMPT'],
|
|
333
|
-
|
|
334
|
-
// James: Deprecate the below, only use tags, which are not prescriptive.
|
|
335
|
-
timeToLive: 'agentStep' as const,
|
|
336
|
-
keepDuringTruncation: true,
|
|
337
|
-
}),
|
|
338
|
-
)
|
|
339
|
-
|
|
340
|
-
agentState.messageHistory = agentMessagesUntruncated
|
|
341
|
-
|
|
342
|
-
const { model } = agentTemplate
|
|
343
|
-
|
|
344
|
-
// A step can start with the history ending on an assistant message — e.g. a
|
|
345
|
-
// continuation after a think-only response for an agent with no stepPrompt.
|
|
346
|
-
// Claude 4.6+ rejects such requests as unsupported assistant prefill, so end
|
|
347
|
-
// the conversation with a user message instead.
|
|
348
|
-
const lastMessage =
|
|
349
|
-
agentState.messageHistory[agentState.messageHistory.length - 1]
|
|
350
|
-
if (lastMessage?.role === 'assistant' && !supportsAssistantPrefill(model)) {
|
|
351
|
-
agentState.messageHistory = [
|
|
352
|
-
...agentState.messageHistory,
|
|
353
|
-
userMessage({
|
|
354
|
-
content: withSystemTags('Continue from where you left off.'),
|
|
355
|
-
timeToLive: 'agentStep' as const,
|
|
356
|
-
keepDuringTruncation: true,
|
|
357
|
-
}),
|
|
358
|
-
]
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
let stepCreditsUsed = 0
|
|
362
|
-
|
|
363
|
-
const onCostCalculated = async (credits: number) => {
|
|
364
|
-
stepCreditsUsed += credits
|
|
365
|
-
agentState.creditsUsed += credits
|
|
366
|
-
agentState.directCreditsUsed += credits
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
const iterationNum = agentState.messageHistory.length
|
|
370
|
-
// system is a plain string; count it directly rather than JSON-stringifying
|
|
371
|
-
// it (which would add quotes and escape every newline).
|
|
372
|
-
const systemTokens = countTokens(system)
|
|
373
|
-
|
|
374
|
-
let cacheDebugCorrelation:
|
|
375
|
-
ReturnType<typeof createCacheDebugSnapshot> | undefined
|
|
376
|
-
if (CACHE_DEBUG_FULL_LOGGING) {
|
|
377
|
-
try {
|
|
378
|
-
cacheDebugCorrelation = createCacheDebugSnapshot({
|
|
379
|
-
agentType: String(agentType),
|
|
380
|
-
system,
|
|
381
|
-
toolDefinitions: (params.tools
|
|
382
|
-
? Object.fromEntries(
|
|
383
|
-
Object.entries(params.tools).map(([name, tool]) => [
|
|
384
|
-
name,
|
|
385
|
-
{
|
|
386
|
-
description: tool.description,
|
|
387
|
-
inputSchema: tool.inputSchema as unknown as Record<
|
|
388
|
-
string,
|
|
389
|
-
JSONValue
|
|
390
|
-
>,
|
|
391
|
-
},
|
|
392
|
-
]),
|
|
393
|
-
)
|
|
394
|
-
: {}) as Record<string, JSONValue>,
|
|
395
|
-
messages: [systemMessage(system), ...agentState.messageHistory],
|
|
396
|
-
logger,
|
|
397
|
-
projectRoot: fileContext.projectRoot,
|
|
398
|
-
runId: agentState.runId,
|
|
399
|
-
userInputId,
|
|
400
|
-
agentStepId,
|
|
401
|
-
model,
|
|
402
|
-
})
|
|
403
|
-
} catch (err) {
|
|
404
|
-
logger.warn({ error: err }, '[Cache Debug] Failed to create snapshot')
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
const onCacheDebugProviderRequestBuilt = cacheDebugCorrelation
|
|
409
|
-
? ({
|
|
410
|
-
provider,
|
|
411
|
-
rawBody,
|
|
412
|
-
normalizedBody,
|
|
413
|
-
}: {
|
|
414
|
-
provider: string
|
|
415
|
-
rawBody: JSONValue
|
|
416
|
-
normalizedBody?: JSONValue
|
|
417
|
-
}) => {
|
|
418
|
-
enrichCacheDebugSnapshotWithProviderRequest({
|
|
419
|
-
correlation: cacheDebugCorrelation,
|
|
420
|
-
provider,
|
|
421
|
-
rawBody,
|
|
422
|
-
normalized: normalizedBody ?? rawBody,
|
|
423
|
-
logger,
|
|
424
|
-
})
|
|
425
|
-
}
|
|
426
|
-
: undefined
|
|
427
|
-
|
|
428
|
-
const onCacheDebugUsageReceived = cacheDebugCorrelation
|
|
429
|
-
? (usage: CacheDebugUsageData) => {
|
|
430
|
-
enrichCacheDebugSnapshotWithUsage({
|
|
431
|
-
correlation: cacheDebugCorrelation,
|
|
432
|
-
usage,
|
|
433
|
-
logger,
|
|
434
|
-
})
|
|
435
|
-
}
|
|
436
|
-
: undefined
|
|
437
|
-
|
|
438
|
-
// Full message histories go to the trace writer, which appends each message
|
|
439
|
-
// exactly once (see TraceWriter).
|
|
440
|
-
params.traceWriter?.recordStep({
|
|
441
|
-
agentId: agentState.agentId,
|
|
442
|
-
agentType: String(agentType),
|
|
443
|
-
runId: agentState.runId,
|
|
444
|
-
userInputId,
|
|
445
|
-
step: iterationNum,
|
|
446
|
-
system,
|
|
447
|
-
messages: agentState.messageHistory,
|
|
448
|
-
})
|
|
449
|
-
|
|
450
|
-
// Log a summary only: the full message history, system prompt, and agent
|
|
451
|
-
// template are large and logging them every step bloats log files
|
|
452
|
-
// quadratically over the course of a chat.
|
|
453
|
-
logger.debug(
|
|
454
|
-
{
|
|
455
|
-
iteration: iterationNum,
|
|
456
|
-
runId: agentState.runId,
|
|
457
|
-
model,
|
|
458
|
-
duration: Date.now() - startTime,
|
|
459
|
-
contextTokenCount: agentState.contextTokenCount,
|
|
460
|
-
messageCount: agentState.messageHistory.length,
|
|
461
|
-
prompt,
|
|
462
|
-
params: spawnParams,
|
|
463
|
-
systemTokens,
|
|
464
|
-
agentTemplateId: agentTemplate.id,
|
|
465
|
-
toolNames: params.tools ? Object.keys(params.tools) : undefined,
|
|
466
|
-
},
|
|
467
|
-
`Start agent ${agentType} step ${iterationNum} (${userInputId}${prompt ? ` - Prompt: ${prompt.slice(0, 20)}` : ''})`,
|
|
468
|
-
)
|
|
469
|
-
|
|
470
|
-
// Handle n parameter for generating multiple responses
|
|
471
|
-
if (params.n !== undefined) {
|
|
472
|
-
const result = await promptAiSdk({
|
|
473
|
-
...params,
|
|
474
|
-
messages: agentState.messageHistory,
|
|
475
|
-
model,
|
|
476
|
-
n: params.n,
|
|
477
|
-
onCostCalculated,
|
|
478
|
-
cacheDebugCorrelation: cacheDebugCorrelation
|
|
479
|
-
? serializeCacheDebugCorrelation(cacheDebugCorrelation)
|
|
480
|
-
: undefined,
|
|
481
|
-
onCacheDebugProviderRequestBuilt,
|
|
482
|
-
onCacheDebugUsageReceived,
|
|
483
|
-
})
|
|
484
|
-
|
|
485
|
-
if (result.aborted) {
|
|
486
|
-
return {
|
|
487
|
-
agentState,
|
|
488
|
-
fullResponse: '',
|
|
489
|
-
shouldEndTurn: true,
|
|
490
|
-
hasNativeIncompleteToolCall: false,
|
|
491
|
-
messageId: null,
|
|
492
|
-
nResponses: undefined,
|
|
493
|
-
}
|
|
494
|
-
}
|
|
495
|
-
|
|
496
|
-
const responsesString = result.value
|
|
497
|
-
let nResponses: string[]
|
|
498
|
-
try {
|
|
499
|
-
nResponses = JSON.parse(responsesString) as string[]
|
|
500
|
-
if (!Array.isArray(nResponses)) {
|
|
501
|
-
if (params.n > 1) {
|
|
502
|
-
throw new Error(
|
|
503
|
-
`Expected JSON array response from LLM when n > 1, got non-array: ${responsesString.slice(0, 50)}`,
|
|
504
|
-
)
|
|
505
|
-
}
|
|
506
|
-
// If it parsed but isn't an array, treat as single response
|
|
507
|
-
nResponses = [responsesString]
|
|
508
|
-
}
|
|
509
|
-
} catch (e) {
|
|
510
|
-
if (params.n > 1) {
|
|
511
|
-
throw e
|
|
512
|
-
}
|
|
513
|
-
// If parsing fails, treat as single raw response (common for n=1)
|
|
514
|
-
nResponses = [responsesString]
|
|
515
|
-
}
|
|
516
|
-
|
|
517
|
-
return {
|
|
518
|
-
agentState,
|
|
519
|
-
fullResponse: responsesString,
|
|
520
|
-
shouldEndTurn: false,
|
|
521
|
-
hasNativeIncompleteToolCall: false,
|
|
522
|
-
messageId: null,
|
|
523
|
-
nResponses,
|
|
524
|
-
}
|
|
525
|
-
}
|
|
526
|
-
|
|
527
|
-
let fullResponse = ''
|
|
528
|
-
const toolResults: ToolMessage[] = []
|
|
529
|
-
|
|
530
|
-
// FID-2026-0718-009 M4: model stream starting — set activity to thinking.
|
|
531
|
-
setActivity(
|
|
532
|
-
agentState,
|
|
533
|
-
{ kind: 'thinking', startedAt: Date.now() },
|
|
534
|
-
onResponseChunk,
|
|
535
|
-
)
|
|
536
|
-
|
|
537
|
-
// Raw stream from AI SDK
|
|
538
|
-
const stream = getAgentStreamFromTemplate({
|
|
539
|
-
...params,
|
|
540
|
-
agentId: agentState.parentId ? agentState.agentId : undefined,
|
|
541
|
-
cacheDebugCorrelation: cacheDebugCorrelation
|
|
542
|
-
? serializeCacheDebugCorrelation(cacheDebugCorrelation)
|
|
543
|
-
: undefined,
|
|
544
|
-
includeCacheControl: supportsCacheControl(agentTemplate.model),
|
|
545
|
-
messages: [systemMessage(system), ...agentState.messageHistory],
|
|
546
|
-
onCacheDebugProviderRequestBuilt,
|
|
547
|
-
onCacheDebugUsageReceived,
|
|
548
|
-
template: agentTemplate,
|
|
549
|
-
onCostCalculated,
|
|
550
|
-
})
|
|
551
|
-
|
|
552
|
-
const {
|
|
553
|
-
fullResponse: fullResponseAfterStream,
|
|
554
|
-
hadToolCallError,
|
|
555
|
-
hasNativeIncompleteToolCall,
|
|
556
|
-
messageId,
|
|
557
|
-
toolCalls,
|
|
558
|
-
toolResults: newToolResults,
|
|
559
|
-
} = await processStream({
|
|
560
|
-
...params,
|
|
561
|
-
agentContext,
|
|
562
|
-
agentState,
|
|
563
|
-
agentStepId,
|
|
564
|
-
agentTemplate,
|
|
565
|
-
fullResponse,
|
|
566
|
-
messages: agentState.messageHistory,
|
|
567
|
-
repoId,
|
|
568
|
-
stream,
|
|
569
|
-
onCostCalculated,
|
|
570
|
-
})
|
|
571
|
-
|
|
572
|
-
toolResults.push(...newToolResults)
|
|
573
|
-
|
|
574
|
-
fullResponse = fullResponseAfterStream
|
|
575
|
-
|
|
576
|
-
// FID-2026-0718-009 M5: model stream complete — idle until next event.
|
|
577
|
-
setActivity(agentState, { kind: 'idle', since: Date.now() }, onResponseChunk)
|
|
578
|
-
|
|
579
|
-
agentState.messageHistory = expireMessages(
|
|
580
|
-
agentState.messageHistory,
|
|
581
|
-
'agentStep',
|
|
582
|
-
)
|
|
583
|
-
|
|
584
|
-
// Handle /compact command: replace message history with the summary
|
|
585
|
-
const wasCompacted =
|
|
586
|
-
prompt &&
|
|
587
|
-
(prompt.toLowerCase() === '/compact' || prompt.toLowerCase() === 'compact')
|
|
588
|
-
if (wasCompacted) {
|
|
589
|
-
agentState.messageHistory = [
|
|
590
|
-
userMessage(
|
|
591
|
-
withSystemTags(
|
|
592
|
-
`The following is a summary of the conversation between you and the user. The conversation continues after this summary:\n\n${fullResponse}`,
|
|
593
|
-
),
|
|
594
|
-
),
|
|
595
|
-
]
|
|
596
|
-
logger.debug({ summary: fullResponse }, 'Compacted messages')
|
|
597
|
-
}
|
|
598
|
-
|
|
599
|
-
const hasNoToolResults =
|
|
600
|
-
toolCalls.filter(
|
|
601
|
-
(call) => !TOOLS_WHICH_WONT_FORCE_NEXT_STEP.includes(call.toolName),
|
|
602
|
-
).length === 0 &&
|
|
603
|
-
toolResults.filter(
|
|
604
|
-
(result) => !TOOLS_WHICH_WONT_FORCE_NEXT_STEP.includes(result.toolName),
|
|
605
|
-
).length === 0 &&
|
|
606
|
-
!hadToolCallError // Tool call errors should also force another step so the agent can retry
|
|
607
|
-
|
|
608
|
-
const hasTaskCompleted = toolCalls.some(
|
|
609
|
-
(call) =>
|
|
610
|
-
call.toolName === 'task_completed' || call.toolName === 'end_turn',
|
|
611
|
-
)
|
|
612
|
-
|
|
613
|
-
// If the response is only <think>...</think> scaffolding (including orphan
|
|
614
|
-
// </think> closes that native-reasoning providers sometimes leak into
|
|
615
|
-
// content), the model was just thinking and should continue rather than end.
|
|
616
|
-
const isThinkOnly = hasNoToolResults && isThinkOnlyResponse(fullResponse)
|
|
617
|
-
|
|
618
|
-
// If the agent has the task_completed tool, it must be called to end its turn.
|
|
619
|
-
const requiresExplicitCompletion =
|
|
620
|
-
agentTemplate.toolNames.includes('task_completed')
|
|
621
|
-
|
|
622
|
-
let shouldEndTurn: boolean
|
|
623
|
-
if (requiresExplicitCompletion) {
|
|
624
|
-
// For models requiring explicit completion, only end turn when:
|
|
625
|
-
// - task_completed is called, OR
|
|
626
|
-
// - end_turn is called (backward compatibility)
|
|
627
|
-
shouldEndTurn = hasTaskCompleted
|
|
628
|
-
} else {
|
|
629
|
-
// For other models, also end turn when there are no tool calls
|
|
630
|
-
// Exception: if the response is only <think> tags, continue the turn
|
|
631
|
-
shouldEndTurn = hasTaskCompleted || (hasNoToolResults && !isThinkOnly)
|
|
632
|
-
}
|
|
633
|
-
|
|
634
|
-
// FID-2026-0725-083: Goal evaluation — if a goal condition is set and the
|
|
635
|
-
// agent called task_completed, check whether the goal is satisfied.
|
|
636
|
-
// If satisfied → keep shouldEndTurn = true (end the loop).
|
|
637
|
-
// If not satisfied → set shouldEndTurn = false (continue iterating).
|
|
638
|
-
if (shouldEndTurn && agentState.goalCondition) {
|
|
639
|
-
const goalSatisfied = /\bGOAL_SATISFIED\b/.test(fullResponse)
|
|
640
|
-
if (goalSatisfied) {
|
|
641
|
-
logger.info(
|
|
642
|
-
{ goalCondition: agentState.goalCondition },
|
|
643
|
-
'Goal evaluation: GOAL_SATISFIED — ending loop',
|
|
644
|
-
)
|
|
645
|
-
} else {
|
|
646
|
-
// Goal not satisfied or error — continue iterating
|
|
647
|
-
shouldEndTurn = false
|
|
648
|
-
const goalNotSatisfied = /\bGOAL_NOT_SATISFIED\b/.test(fullResponse)
|
|
649
|
-
const goalError = /\bGOAL_ERROR\b/.test(fullResponse)
|
|
650
|
-
const reason = goalNotSatisfied
|
|
651
|
-
? 'NOT_SATISFIED'
|
|
652
|
-
: goalError
|
|
653
|
-
? 'ERROR'
|
|
654
|
-
: 'no marker found'
|
|
655
|
-
logger.debug(
|
|
656
|
-
{ goalCondition: agentState.goalCondition, reason },
|
|
657
|
-
`Goal evaluation: ${reason} — continuing iteration`,
|
|
658
|
-
)
|
|
659
|
-
}
|
|
660
|
-
}
|
|
661
|
-
|
|
662
|
-
agentState = {
|
|
663
|
-
...agentState,
|
|
664
|
-
stepsRemaining: agentState.stepsRemaining - 1,
|
|
665
|
-
agentContext,
|
|
666
|
-
}
|
|
667
|
-
|
|
668
|
-
// Capture the assistant response and tool results added during this step
|
|
669
|
-
params.traceWriter?.recordStep({
|
|
670
|
-
agentId: agentState.agentId,
|
|
671
|
-
agentType: String(agentType),
|
|
672
|
-
runId: agentState.runId,
|
|
673
|
-
userInputId,
|
|
674
|
-
step: iterationNum,
|
|
675
|
-
system,
|
|
676
|
-
messages: agentState.messageHistory,
|
|
677
|
-
})
|
|
678
|
-
|
|
679
|
-
logger.debug(
|
|
680
|
-
{
|
|
681
|
-
iteration: iterationNum,
|
|
682
|
-
agentId: agentState.agentId,
|
|
683
|
-
model,
|
|
684
|
-
prompt,
|
|
685
|
-
shouldEndTurn,
|
|
686
|
-
duration: Date.now() - startTime,
|
|
687
|
-
fullResponse,
|
|
688
|
-
// Summarize instead of logging the full message history: logging it
|
|
689
|
-
// every step bloats log files quadratically over the course of a chat.
|
|
690
|
-
messageCount: agentState.messageHistory.length,
|
|
691
|
-
toolCalls,
|
|
692
|
-
toolResults,
|
|
693
|
-
stepCreditsUsed,
|
|
694
|
-
},
|
|
695
|
-
`End agent ${agentType} step ${iterationNum} (${userInputId}${prompt ? ` - Prompt: ${prompt.slice(0, 20)}` : ''})`,
|
|
696
|
-
)
|
|
697
|
-
|
|
698
|
-
return {
|
|
699
|
-
agentState,
|
|
700
|
-
fullResponse,
|
|
701
|
-
shouldEndTurn,
|
|
702
|
-
hasNativeIncompleteToolCall,
|
|
703
|
-
messageId,
|
|
704
|
-
nResponses: undefined,
|
|
705
|
-
}
|
|
706
|
-
}
|
|
707
|
-
|
|
708
|
-
/**
|
|
709
|
-
* Runs the agent loop.
|
|
710
|
-
*
|
|
711
|
-
* IMPORTANT: This function mutates `params.agentState` in place throughout the
|
|
712
|
-
* run (not just at return time). Fields like `messageHistory`, `systemPrompt`,
|
|
713
|
-
* `toolDefinitions`, `creditsUsed`, and `output` are updated as work progresses
|
|
714
|
-
* so that callers holding a reference to the same object (e.g. the SDK's
|
|
715
|
-
* `sessionState.mainAgentState`) see in-progress work immediately — which
|
|
716
|
-
* matters when an error is thrown mid-run and the normal return path is
|
|
717
|
-
* skipped.
|
|
718
|
-
*/
|
|
719
|
-
export async function loopAgentSteps(
|
|
720
|
-
params: {
|
|
721
|
-
addAgentStep: AddAgentStepFn
|
|
722
|
-
agentState: AgentState
|
|
723
|
-
agentType: string
|
|
724
|
-
clearUserPromptMessagesAfterResponse?: boolean
|
|
725
|
-
clientSessionId: string
|
|
726
|
-
content?: Array<TextPart | ImagePart>
|
|
727
|
-
fileContext: ProjectFileContext
|
|
728
|
-
finishAgentRun: FinishAgentRunFn
|
|
729
|
-
localAgentTemplates: Record<string, AgentTemplate>
|
|
730
|
-
logger: Logger
|
|
731
|
-
parentSystemPrompt?: string
|
|
732
|
-
parentTools?: ToolSet
|
|
733
|
-
prompt: string | undefined
|
|
734
|
-
signal: AbortSignal
|
|
735
|
-
/** Optional steering hook. Drained at each step boundary (after a step's LLM
|
|
736
|
-
* call + tools complete, before the next one). Any returned texts are appended
|
|
737
|
-
* to the message history as user prompts and keep the turn going, letting a
|
|
738
|
-
* host "steer" a running agent without aborting or losing the current step. */
|
|
739
|
-
drainSteeringMessages?: () => string[]
|
|
740
|
-
spawnParams: Record<string, JSONValue> | undefined
|
|
741
|
-
startAgentRun: StartAgentRunFn
|
|
742
|
-
userId: string | undefined
|
|
743
|
-
userInputId: string
|
|
744
|
-
agentTemplate?: AgentTemplate
|
|
745
|
-
/** FID-2026-0725-085 CTX-007: Resolved context window from OpenRouter catalog. */
|
|
746
|
-
contextWindow?: number
|
|
747
|
-
} & ParamsExcluding<typeof additionalToolDefinitions, 'agentTemplate'> &
|
|
748
|
-
ParamsExcluding<
|
|
749
|
-
typeof runProgrammaticStep,
|
|
750
|
-
| 'agentState'
|
|
751
|
-
| 'onCostCalculated'
|
|
752
|
-
| 'prompt'
|
|
753
|
-
| 'runId'
|
|
754
|
-
| 'stepNumber'
|
|
755
|
-
| 'stepsComplete'
|
|
756
|
-
| 'system'
|
|
757
|
-
| 'template'
|
|
758
|
-
| 'toolCallParams'
|
|
759
|
-
| 'tools'
|
|
760
|
-
> &
|
|
761
|
-
ParamsExcluding<typeof getAgentTemplate, 'agentId'> &
|
|
762
|
-
ParamsExcluding<
|
|
763
|
-
typeof getAgentPrompt,
|
|
764
|
-
| 'agentTemplate'
|
|
765
|
-
| 'promptType'
|
|
766
|
-
| 'agentTemplates'
|
|
767
|
-
| 'additionalToolDefinitions'
|
|
768
|
-
> &
|
|
769
|
-
ParamsExcluding<
|
|
770
|
-
typeof getMCPToolData,
|
|
771
|
-
'toolNames' | 'mcpServers' | 'writeTo'
|
|
772
|
-
> &
|
|
773
|
-
ParamsExcluding<StartAgentRunFn, 'agentId' | 'ancestorRunIds'> &
|
|
774
|
-
ParamsExcluding<
|
|
775
|
-
FinishAgentRunFn,
|
|
776
|
-
'runId' | 'status' | 'totalSteps' | 'directCredits' | 'totalCredits'
|
|
777
|
-
> &
|
|
778
|
-
ParamsExcluding<
|
|
779
|
-
typeof runAgentStep,
|
|
780
|
-
| 'additionalToolDefinitions'
|
|
781
|
-
| 'agentState'
|
|
782
|
-
| 'agentTemplate'
|
|
783
|
-
| 'prompt'
|
|
784
|
-
| 'runId'
|
|
785
|
-
| 'spawnParams'
|
|
786
|
-
| 'system'
|
|
787
|
-
| 'tools'
|
|
788
|
-
> &
|
|
789
|
-
ParamsExcluding<
|
|
790
|
-
AddAgentStepFn,
|
|
791
|
-
| 'agentRunId'
|
|
792
|
-
| 'stepNumber'
|
|
793
|
-
| 'credits'
|
|
794
|
-
| 'childRunIds'
|
|
795
|
-
| 'messageId'
|
|
796
|
-
| 'status'
|
|
797
|
-
| 'startTime'
|
|
798
|
-
>,
|
|
799
|
-
): Promise<{
|
|
800
|
-
agentState: AgentState
|
|
801
|
-
output: AgentOutput
|
|
802
|
-
}> {
|
|
803
|
-
const {
|
|
804
|
-
addAgentStep,
|
|
805
|
-
agentState: initialAgentState,
|
|
806
|
-
agentType,
|
|
807
|
-
clearUserPromptMessagesAfterResponse = true,
|
|
808
|
-
content,
|
|
809
|
-
fileContext,
|
|
810
|
-
finishAgentRun,
|
|
811
|
-
localAgentTemplates,
|
|
812
|
-
logger,
|
|
813
|
-
parentSystemPrompt,
|
|
814
|
-
parentTools,
|
|
815
|
-
prompt,
|
|
816
|
-
signal,
|
|
817
|
-
spawnParams,
|
|
818
|
-
startAgentRun,
|
|
819
|
-
clientEnv,
|
|
820
|
-
ciEnv,
|
|
821
|
-
} = params
|
|
822
|
-
|
|
823
|
-
let agentTemplate = params.agentTemplate
|
|
824
|
-
if (!agentTemplate) {
|
|
825
|
-
agentTemplate =
|
|
826
|
-
(await getAgentTemplate({
|
|
827
|
-
...params,
|
|
828
|
-
agentId: agentType,
|
|
829
|
-
})) ?? undefined
|
|
830
|
-
}
|
|
831
|
-
if (!agentTemplate) {
|
|
832
|
-
throw new Error(`Agent template not found for type: ${agentType}`)
|
|
833
|
-
}
|
|
834
|
-
|
|
835
|
-
if (signal.aborted) {
|
|
836
|
-
return {
|
|
837
|
-
agentState: initialAgentState,
|
|
838
|
-
output: {
|
|
839
|
-
type: 'error',
|
|
840
|
-
message: 'Run cancelled by user',
|
|
841
|
-
},
|
|
842
|
-
}
|
|
843
|
-
}
|
|
844
|
-
|
|
845
|
-
const runId = await startAgentRun({
|
|
846
|
-
...params,
|
|
847
|
-
agentId: agentTemplate.id,
|
|
848
|
-
ancestorRunIds: initialAgentState.ancestorRunIds,
|
|
849
|
-
})
|
|
850
|
-
if (!runId) {
|
|
851
|
-
throw new Error('Failed to start agent run')
|
|
852
|
-
}
|
|
853
|
-
initialAgentState.runId = runId
|
|
854
|
-
|
|
855
|
-
let cachedAdditionalToolDefinitions: CustomToolDefinitions | undefined
|
|
856
|
-
// Use parent's tools for prompt caching when inheritParentSystemPrompt is true
|
|
857
|
-
const useParentTools =
|
|
858
|
-
agentTemplate.inheritParentSystemPrompt && parentTools !== undefined
|
|
859
|
-
const inheritedParentTools: ToolSet = parentTools ?? {}
|
|
860
|
-
|
|
861
|
-
// Initialize message history with user prompt and instructions on first iteration
|
|
862
|
-
const instructionsPrompt = await getAgentPrompt({
|
|
863
|
-
...params,
|
|
864
|
-
agentTemplate,
|
|
865
|
-
promptType: { type: 'instructionsPrompt' },
|
|
866
|
-
agentTemplates: localAgentTemplates,
|
|
867
|
-
useParentTools,
|
|
868
|
-
additionalToolDefinitions: async () => {
|
|
869
|
-
if (!cachedAdditionalToolDefinitions) {
|
|
870
|
-
cachedAdditionalToolDefinitions = await additionalToolDefinitions({
|
|
871
|
-
...params,
|
|
872
|
-
agentTemplate,
|
|
873
|
-
})
|
|
874
|
-
}
|
|
875
|
-
return cachedAdditionalToolDefinitions
|
|
876
|
-
},
|
|
877
|
-
})
|
|
878
|
-
|
|
879
|
-
// Build the initial message history with user prompt and instructions
|
|
880
|
-
// Generate system prompt once, using parent's if inheritParentSystemPrompt is true
|
|
881
|
-
let system: string
|
|
882
|
-
if (agentTemplate.inheritParentSystemPrompt && parentSystemPrompt) {
|
|
883
|
-
system = parentSystemPrompt
|
|
884
|
-
} else {
|
|
885
|
-
const systemPrompt = await getAgentPrompt({
|
|
886
|
-
...params,
|
|
887
|
-
agentTemplate,
|
|
888
|
-
promptType: { type: 'systemPrompt' },
|
|
889
|
-
agentTemplates: localAgentTemplates,
|
|
890
|
-
additionalToolDefinitions: async () => {
|
|
891
|
-
if (!cachedAdditionalToolDefinitions) {
|
|
892
|
-
cachedAdditionalToolDefinitions = await additionalToolDefinitions({
|
|
893
|
-
...params,
|
|
894
|
-
agentTemplate,
|
|
895
|
-
})
|
|
896
|
-
}
|
|
897
|
-
return cachedAdditionalToolDefinitions
|
|
898
|
-
},
|
|
899
|
-
})
|
|
900
|
-
system = systemPrompt ?? ''
|
|
901
|
-
}
|
|
902
|
-
|
|
903
|
-
// Prompt inheritance and capability inheritance are separate concerns. A
|
|
904
|
-
// child may reuse the parent's system prompt while still needing its own
|
|
905
|
-
// tool definitions when the parent does not contain every allowed tool.
|
|
906
|
-
const parentToolKeys = new Set(Object.keys(inheritedParentTools))
|
|
907
|
-
const childToolsSubsetOfParent = agentTemplate.toolNames.every((toolName) =>
|
|
908
|
-
parentToolKeys.has(toolName),
|
|
909
|
-
)
|
|
910
|
-
const useInheritedTools = useParentTools && childToolsSubsetOfParent
|
|
911
|
-
|
|
912
|
-
// Build agent tools (agents as direct tool calls) whenever the child needs
|
|
913
|
-
// its own tool construction. This preserves spawnable child-agent tools in
|
|
914
|
-
// the same fallback path as built-in, custom, MCP, and skill tools.
|
|
915
|
-
const agentTools = useInheritedTools
|
|
916
|
-
? {}
|
|
917
|
-
: await buildAgentToolSet({
|
|
918
|
-
...params,
|
|
919
|
-
spawnableAgents: agentTemplate.spawnableAgents,
|
|
920
|
-
agentTemplates: localAgentTemplates,
|
|
921
|
-
})
|
|
922
|
-
|
|
923
|
-
const tools = useInheritedTools
|
|
924
|
-
? filterToolSet(inheritedParentTools, agentTemplate.toolNames)
|
|
925
|
-
: await getToolSet({
|
|
926
|
-
toolNames: agentTemplate.toolNames,
|
|
927
|
-
additionalToolDefinitions: async () => {
|
|
928
|
-
if (!cachedAdditionalToolDefinitions) {
|
|
929
|
-
cachedAdditionalToolDefinitions = await additionalToolDefinitions({
|
|
930
|
-
...params,
|
|
931
|
-
agentTemplate,
|
|
932
|
-
})
|
|
933
|
-
}
|
|
934
|
-
return cachedAdditionalToolDefinitions
|
|
935
|
-
},
|
|
936
|
-
agentTools,
|
|
937
|
-
skills: fileContext.skills ?? {},
|
|
938
|
-
})
|
|
939
|
-
|
|
940
|
-
const hasUserMessage = Boolean(
|
|
941
|
-
prompt ||
|
|
942
|
-
(spawnParams && Object.keys(spawnParams).length > 0) ||
|
|
943
|
-
(content && content.length > 0),
|
|
944
|
-
)
|
|
945
|
-
|
|
946
|
-
const initialMessages = buildArray<Message>(
|
|
947
|
-
...initialAgentState.messageHistory,
|
|
948
|
-
|
|
949
|
-
hasUserMessage && [
|
|
950
|
-
{
|
|
951
|
-
// Actual user message!
|
|
952
|
-
role: 'user' as const,
|
|
953
|
-
content: buildUserMessageContent(prompt, spawnParams, content),
|
|
954
|
-
tags: ['USER_PROMPT'],
|
|
955
|
-
sentAt: Date.now(),
|
|
956
|
-
|
|
957
|
-
// James: Deprecate the below, only use tags, which are not prescriptive.
|
|
958
|
-
keepDuringTruncation: true,
|
|
959
|
-
},
|
|
960
|
-
prompt &&
|
|
961
|
-
prompt in additionalSystemPrompts &&
|
|
962
|
-
userMessage(
|
|
963
|
-
withSystemInstructionTags(
|
|
964
|
-
additionalSystemPrompts[
|
|
965
|
-
prompt as keyof typeof additionalSystemPrompts
|
|
966
|
-
],
|
|
967
|
-
),
|
|
968
|
-
),
|
|
969
|
-
],
|
|
970
|
-
|
|
971
|
-
instructionsPrompt &&
|
|
972
|
-
userMessage({
|
|
973
|
-
content: instructionsPrompt,
|
|
974
|
-
tags: ['INSTRUCTIONS_PROMPT'],
|
|
975
|
-
|
|
976
|
-
// James: Deprecate the below, only use tags, which are not prescriptive.
|
|
977
|
-
keepLastTags: ['INSTRUCTIONS_PROMPT'],
|
|
978
|
-
}),
|
|
979
|
-
)
|
|
980
|
-
|
|
981
|
-
// Convert tools to a serializable format for context-pruner token counting.
|
|
982
|
-
// FID-2026-0802-005 L9: the inputSchema slot is typed as JSONValue (it feeds
|
|
983
|
-
// toTokenCountInputSchema, which handles Zod + JSON Schema + garbage); the
|
|
984
|
-
// AI SDK JSONSchema → JSONValue conversion is an honest trust-boundary
|
|
985
|
-
// assertion (tracked in the FID-029 ledger), not a cast-to-nothing.
|
|
986
|
-
const toolDefinitions: Record<
|
|
987
|
-
string,
|
|
988
|
-
{ description: string | undefined; inputSchema: JSONValue }
|
|
989
|
-
> = mapValues(tools, (tool) => ({
|
|
990
|
-
description: tool.description,
|
|
991
|
-
inputSchema: tool.inputSchema as unknown as JSONValue,
|
|
992
|
-
}))
|
|
993
|
-
|
|
994
|
-
const additionalToolDefinitionsWithCache = async () => {
|
|
995
|
-
if (!cachedAdditionalToolDefinitions) {
|
|
996
|
-
cachedAdditionalToolDefinitions = await additionalToolDefinitions({
|
|
997
|
-
...params,
|
|
998
|
-
agentTemplate,
|
|
999
|
-
})
|
|
1000
|
-
}
|
|
1001
|
-
return cachedAdditionalToolDefinitions
|
|
1002
|
-
}
|
|
1003
|
-
|
|
1004
|
-
// Mutate initialAgentState so that in-progress work propagates back to the
|
|
1005
|
-
// caller's shared reference (e.g. SDK's sessionState.mainAgentState) even if
|
|
1006
|
-
// an error is thrown before we return.
|
|
1007
|
-
initialAgentState.messageHistory = initialMessages
|
|
1008
|
-
initialAgentState.systemPrompt = system
|
|
1009
|
-
initialAgentState.toolDefinitions = toolDefinitions
|
|
1010
|
-
let currentAgentState: AgentState = initialAgentState
|
|
1011
|
-
|
|
1012
|
-
// Convert tool definitions to Anthropic format for accurate token counting.
|
|
1013
|
-
// Tool definitions are stored as { [name]: { description, inputSchema } },
|
|
1014
|
-
// where inputSchema is a Zod schema. Anthropic's count_tokens API expects
|
|
1015
|
-
// [{ name, description, input_schema }] with input_schema being real JSON
|
|
1016
|
-
// Schema (with a top-level `type: 'object'`) — see toTokenCountInputSchema.
|
|
1017
|
-
const toolsForTokenCount = Object.entries(toolDefinitions).map(
|
|
1018
|
-
([name, def]) => {
|
|
1019
|
-
const input_schema = toTokenCountInputSchema(def.inputSchema)
|
|
1020
|
-
return {
|
|
1021
|
-
name,
|
|
1022
|
-
...(def.description && { description: def.description }),
|
|
1023
|
-
...(input_schema && { input_schema }),
|
|
1024
|
-
}
|
|
1025
|
-
},
|
|
1026
|
-
)
|
|
1027
|
-
|
|
1028
|
-
let shouldEndTurn = false
|
|
1029
|
-
let hasRetriedOutputSchema = false
|
|
1030
|
-
let currentPrompt = prompt
|
|
1031
|
-
let currentParams = spawnParams
|
|
1032
|
-
let totalSteps = 0
|
|
1033
|
-
let nResponses: string[] | undefined = undefined
|
|
1034
|
-
let consecutiveNativeIncompleteSteps = 0
|
|
1035
|
-
|
|
1036
|
-
// FID-2026-0725-083: Parse goal condition from the initial message.
|
|
1037
|
-
// The /goal command sends <goal condition="..."> in the message content.
|
|
1038
|
-
// We extract it and store it in agentState.goalCondition for evaluation
|
|
1039
|
-
// after each task_completed call.
|
|
1040
|
-
if (hasUserMessage && prompt) {
|
|
1041
|
-
const goalMatch = prompt.match(/<goal condition="([^"]+)">/)
|
|
1042
|
-
if (goalMatch && !currentAgentState.goalCondition) {
|
|
1043
|
-
currentAgentState.goalCondition = goalMatch[1]
|
|
1044
|
-
logger.info(
|
|
1045
|
-
{ goalCondition: goalMatch[1] },
|
|
1046
|
-
'Goal condition detected from message — will evaluate after each task_completed',
|
|
1047
|
-
)
|
|
1048
|
-
}
|
|
1049
|
-
}
|
|
1050
|
-
|
|
1051
|
-
// FID-2026-0725-085: Initialize ContextCompactor for micro-compact before each API call.
|
|
1052
|
-
// This runs at the start of the agent loop so it's available for every iteration.
|
|
1053
|
-
// Use resolved contextWindow from CLI (CTX-007) or infer from model name (CTX-003).
|
|
1054
|
-
const contextCompactor = new ContextCompactor({
|
|
1055
|
-
logger,
|
|
1056
|
-
contextWindow: params.contextWindow,
|
|
1057
|
-
model: agentTemplate.model,
|
|
1058
|
-
})
|
|
1059
|
-
// FID-2026-0725-085 Layer 3: Wire resolved context window into agentState
|
|
1060
|
-
// so handleSteps (savant.ts) can use it for auto-compact threshold.
|
|
1061
|
-
initialAgentState.maxContextLength =
|
|
1062
|
-
contextCompactor.getThresholds().autoCompact + 30_000
|
|
1063
|
-
|
|
1064
|
-
try {
|
|
1065
|
-
while (true) {
|
|
1066
|
-
totalSteps++
|
|
1067
|
-
if (signal.aborted) {
|
|
1068
|
-
throw new AbortError()
|
|
1069
|
-
}
|
|
1070
|
-
|
|
1071
|
-
const startTime = new Date()
|
|
1072
|
-
|
|
1073
|
-
// FID-2026-0802-005 L15: computed once per step and reused by
|
|
1074
|
-
// runAgentStep. Note: this runs before the programmatic step, so a
|
|
1075
|
-
// handleSteps generator that mutates history (e.g. set_messages) could
|
|
1076
|
-
// in theory make the USER_INPUT_PROMPT placeholder stale — no bundled
|
|
1077
|
-
// agent does this; acceptable per the FID.
|
|
1078
|
-
const stepPrompt = await getAgentPrompt({
|
|
1079
|
-
...params,
|
|
1080
|
-
agentTemplate,
|
|
1081
|
-
promptType: { type: 'stepPrompt' },
|
|
1082
|
-
fileContext,
|
|
1083
|
-
agentState: currentAgentState,
|
|
1084
|
-
agentTemplates: localAgentTemplates,
|
|
1085
|
-
logger,
|
|
1086
|
-
additionalToolDefinitions: additionalToolDefinitionsWithCache,
|
|
1087
|
-
})
|
|
1088
|
-
const messagesWithStepPrompt = buildArray(
|
|
1089
|
-
...currentAgentState.messageHistory,
|
|
1090
|
-
stepPrompt &&
|
|
1091
|
-
userMessage({
|
|
1092
|
-
content: stepPrompt,
|
|
1093
|
-
}),
|
|
1094
|
-
)
|
|
1095
|
-
|
|
1096
|
-
// Count structured message content (not JSON.stringify, which inflates the
|
|
1097
|
-
// count and counts image base64 as text); system is a plain string; tool
|
|
1098
|
-
// schemas stay JSON since that's roughly how the model sees them.
|
|
1099
|
-
// FID-2026-0802-005 H2: countTokensMessagesCached memoizes per-message
|
|
1100
|
-
// counts by object identity, so the history is tokenized once over the
|
|
1101
|
-
// whole run instead of re-encoded every step (O(n²) → O(n)). The step
|
|
1102
|
-
// prompt is counted directly instead of rebuilding the array (saves the
|
|
1103
|
-
// per-step copy too).
|
|
1104
|
-
const estimateContextTokensLocally = () =>
|
|
1105
|
-
countTokensMessagesCached(currentAgentState.messageHistory) +
|
|
1106
|
-
countTokens(stepPrompt ?? '') +
|
|
1107
|
-
countTokens(system) +
|
|
1108
|
-
countTokensJson(toolsForTokenCount)
|
|
1109
|
-
|
|
1110
|
-
// Use local token estimation for external runs (OpenCode Go, BYOK,
|
|
1111
|
-
// savant-free) where the SavantCode web API is unavailable or unnecessary.
|
|
1112
|
-
// The external API ships the full message history + tools via HTTP on every
|
|
1113
|
-
// step, adding serial network overhead (30s timeout × 3 retries). Local
|
|
1114
|
-
// estimation uses gpt-tokenizer with a 1.35× fudge factor — fast and
|
|
1115
|
-
// accurate enough for context management. Only SavantCode-hosted paid runs
|
|
1116
|
-
// need the accurate API count for credit billing.
|
|
1117
|
-
const hasSavantCodeBackend = Boolean(
|
|
1118
|
-
params.apiKey ?? ciEnv.SAVANT_CODE_API_KEY,
|
|
1119
|
-
)
|
|
1120
|
-
if (
|
|
1121
|
-
shouldUseLocalTokenCount({
|
|
1122
|
-
agentId: agentTemplate.id,
|
|
1123
|
-
model: agentTemplate.model,
|
|
1124
|
-
hasSavantCodeBackend,
|
|
1125
|
-
})
|
|
1126
|
-
) {
|
|
1127
|
-
currentAgentState.contextTokenCount = estimateContextTokensLocally()
|
|
1128
|
-
} else {
|
|
1129
|
-
// SavantCode-hosted paid run: use the accurate web API count.
|
|
1130
|
-
const tokenCountResult = await callTokenCountAPI({
|
|
1131
|
-
messages: messagesWithStepPrompt as JSONValue[],
|
|
1132
|
-
system,
|
|
1133
|
-
model: agentTemplate.model,
|
|
1134
|
-
tools: toolsForTokenCount as Array<{
|
|
1135
|
-
name: string
|
|
1136
|
-
description?: string
|
|
1137
|
-
input_schema?: JSONValue
|
|
1138
|
-
}>,
|
|
1139
|
-
fetch,
|
|
1140
|
-
logger,
|
|
1141
|
-
env: { clientEnv, ciEnv },
|
|
1142
|
-
apiKey: params.apiKey,
|
|
1143
|
-
})
|
|
1144
|
-
if (tokenCountResult.inputTokens !== undefined) {
|
|
1145
|
-
currentAgentState.contextTokenCount = tokenCountResult.inputTokens
|
|
1146
|
-
} else if (tokenCountResult.error) {
|
|
1147
|
-
logger.warn(
|
|
1148
|
-
{ error: tokenCountResult.error },
|
|
1149
|
-
'Failed to get token count from web API — falling back to local estimation',
|
|
1150
|
-
)
|
|
1151
|
-
currentAgentState.contextTokenCount = estimateContextTokensLocally()
|
|
1152
|
-
}
|
|
1153
|
-
}
|
|
1154
|
-
|
|
1155
|
-
// FID-2026-0725-085: Run micro-compact before each API call to clear stale tool results.
|
|
1156
|
-
// This is zero-cost (no LLM call) and reduces context size incrementally.
|
|
1157
|
-
const thresholds = contextCompactor.getThresholds()
|
|
1158
|
-
const messagesBeforeMicroCompact = currentAgentState.messageHistory.length
|
|
1159
|
-
const microResult = contextCompactor.microCompact(
|
|
1160
|
-
currentAgentState.messageHistory,
|
|
1161
|
-
)
|
|
1162
|
-
if (microResult.tokensSaved > 0) {
|
|
1163
|
-
// FID-2026-0802-005 L8: ContextCompactor now operates on Message[]
|
|
1164
|
-
// directly — the `as unknown as CompactionMessage[]` casts are gone.
|
|
1165
|
-
currentAgentState.messageHistory = microResult.messages
|
|
1166
|
-
// FID-2026-0725-085: Log visible compaction summary.
|
|
1167
|
-
// Follows the Kilo Code / OpenClaude pattern: pause, output summary, proceed.
|
|
1168
|
-
const percentUsed = Math.round(
|
|
1169
|
-
(currentAgentState.contextTokenCount / thresholds.autoCompact) * 100,
|
|
1170
|
-
)
|
|
1171
|
-
logger.info(
|
|
1172
|
-
{
|
|
1173
|
-
messagesCleared:
|
|
1174
|
-
messagesBeforeMicroCompact - microResult.messages.length,
|
|
1175
|
-
tokensSaved: microResult.tokensSaved,
|
|
1176
|
-
percentUsed,
|
|
1177
|
-
},
|
|
1178
|
-
`⚙️ Context micro-compacted: cleared stale tool results, ~${microResult.tokensSaved.toLocaleString()} tokens saved. Context at ${percentUsed}% of auto-compact threshold.`,
|
|
1179
|
-
)
|
|
1180
|
-
}
|
|
1181
|
-
|
|
1182
|
-
// FID-2026-0725-085: Check auto-compact threshold.
|
|
1183
|
-
// If context exceeds threshold, emit warning and log for diagnostics.
|
|
1184
|
-
// Full LLM summarization is handled by handleSteps context-pruner spawn.
|
|
1185
|
-
const autoCompactCheck = contextCompactor.shouldAutoCompact(
|
|
1186
|
-
currentAgentState.messageHistory,
|
|
1187
|
-
currentAgentState.contextTokenCount,
|
|
1188
|
-
)
|
|
1189
|
-
if (autoCompactCheck.shouldCompact) {
|
|
1190
|
-
const degradationWarning = contextCompactor.getDegradationWarning()
|
|
1191
|
-
if (degradationWarning) {
|
|
1192
|
-
logger.warn(
|
|
1193
|
-
{ contextTokenCount: currentAgentState.contextTokenCount },
|
|
1194
|
-
degradationWarning,
|
|
1195
|
-
)
|
|
1196
|
-
} else {
|
|
1197
|
-
logger.warn(
|
|
1198
|
-
{
|
|
1199
|
-
contextTokenCount: currentAgentState.contextTokenCount,
|
|
1200
|
-
threshold: thresholds.autoCompact,
|
|
1201
|
-
},
|
|
1202
|
-
`⚠️ Context approaching auto-compact threshold (${currentAgentState.contextTokenCount.toLocaleString()} / ${thresholds.autoCompact.toLocaleString()} tokens). Full summarization will trigger via context-pruner.`,
|
|
1203
|
-
)
|
|
1204
|
-
}
|
|
1205
|
-
}
|
|
1206
|
-
|
|
1207
|
-
// FID-2026-0725-085 Layer 3: After step completes, check if context was compacted
|
|
1208
|
-
// and record result in ContextCompactor for circuit breaker tracking.
|
|
1209
|
-
// Detect compaction by checking if contextTokenCount dropped significantly.
|
|
1210
|
-
|
|
1211
|
-
// 1. Run programmatic step first if it exists
|
|
1212
|
-
let n: number | undefined = undefined
|
|
1213
|
-
|
|
1214
|
-
if (agentTemplate.handleSteps) {
|
|
1215
|
-
const programmaticResult = await runProgrammaticStep({
|
|
1216
|
-
...params,
|
|
1217
|
-
|
|
1218
|
-
agentState: currentAgentState,
|
|
1219
|
-
localAgentTemplates,
|
|
1220
|
-
nResponses,
|
|
1221
|
-
onCostCalculated: async (credits: number) => {
|
|
1222
|
-
currentAgentState.creditsUsed += credits
|
|
1223
|
-
currentAgentState.directCreditsUsed += credits
|
|
1224
|
-
},
|
|
1225
|
-
prompt: currentPrompt,
|
|
1226
|
-
runId,
|
|
1227
|
-
stepNumber: totalSteps,
|
|
1228
|
-
stepsComplete: shouldEndTurn,
|
|
1229
|
-
system,
|
|
1230
|
-
tools,
|
|
1231
|
-
template: agentTemplate,
|
|
1232
|
-
toolCallParams: currentParams as
|
|
1233
|
-
| Record<string, string | number | boolean | null | undefined>
|
|
1234
|
-
| undefined,
|
|
1235
|
-
})
|
|
1236
|
-
const {
|
|
1237
|
-
agentState: programmaticAgentState,
|
|
1238
|
-
endTurn,
|
|
1239
|
-
stepNumber,
|
|
1240
|
-
generateN,
|
|
1241
|
-
} = programmaticResult
|
|
1242
|
-
n = generateN
|
|
1243
|
-
|
|
1244
|
-
Object.assign(initialAgentState, programmaticAgentState)
|
|
1245
|
-
currentAgentState = initialAgentState
|
|
1246
|
-
totalSteps = stepNumber
|
|
1247
|
-
|
|
1248
|
-
shouldEndTurn = endTurn
|
|
1249
|
-
}
|
|
1250
|
-
|
|
1251
|
-
// Check if output is required but missing
|
|
1252
|
-
if (
|
|
1253
|
-
agentTemplate.outputSchema &&
|
|
1254
|
-
currentAgentState.output === undefined &&
|
|
1255
|
-
shouldEndTurn &&
|
|
1256
|
-
!hasRetriedOutputSchema
|
|
1257
|
-
) {
|
|
1258
|
-
hasRetriedOutputSchema = true
|
|
1259
|
-
logger.warn(
|
|
1260
|
-
{
|
|
1261
|
-
agentType,
|
|
1262
|
-
agentId: currentAgentState.agentId,
|
|
1263
|
-
runId,
|
|
1264
|
-
},
|
|
1265
|
-
'Agent finished without setting required output, restarting loop',
|
|
1266
|
-
)
|
|
1267
|
-
|
|
1268
|
-
// Add system message instructing to use set_output
|
|
1269
|
-
const outputSchemaMessage = withSystemTags(
|
|
1270
|
-
`You must use the "set_output" tool to provide a result that matches the output schema before ending your turn. The output schema is required for this agent.`,
|
|
1271
|
-
)
|
|
1272
|
-
|
|
1273
|
-
currentAgentState.messageHistory = [
|
|
1274
|
-
...currentAgentState.messageHistory,
|
|
1275
|
-
userMessage({
|
|
1276
|
-
content: outputSchemaMessage,
|
|
1277
|
-
keepDuringTruncation: true,
|
|
1278
|
-
}),
|
|
1279
|
-
]
|
|
1280
|
-
|
|
1281
|
-
// Reset shouldEndTurn to continue the loop
|
|
1282
|
-
shouldEndTurn = false
|
|
1283
|
-
}
|
|
1284
|
-
|
|
1285
|
-
// End turn if programmatic step ended turn, or if the previous runAgentStep ended turn
|
|
1286
|
-
if (shouldEndTurn) {
|
|
1287
|
-
break
|
|
1288
|
-
}
|
|
1289
|
-
|
|
1290
|
-
const creditsBefore = currentAgentState.directCreditsUsed
|
|
1291
|
-
const childrenBefore = currentAgentState.childRunIds.length
|
|
1292
|
-
const {
|
|
1293
|
-
agentState: newAgentState,
|
|
1294
|
-
shouldEndTurn: llmShouldEndTurn,
|
|
1295
|
-
hasNativeIncompleteToolCall,
|
|
1296
|
-
messageId,
|
|
1297
|
-
nResponses: generatedResponses,
|
|
1298
|
-
} = await runAgentStep({
|
|
1299
|
-
...params,
|
|
1300
|
-
|
|
1301
|
-
agentState: currentAgentState,
|
|
1302
|
-
agentTemplate,
|
|
1303
|
-
n,
|
|
1304
|
-
prompt: currentPrompt,
|
|
1305
|
-
runId,
|
|
1306
|
-
spawnParams: currentParams,
|
|
1307
|
-
system,
|
|
1308
|
-
tools,
|
|
1309
|
-
additionalToolDefinitions: additionalToolDefinitionsWithCache,
|
|
1310
|
-
// FID-2026-0802-005 L15/H8: reuse the step prompt already computed
|
|
1311
|
-
// above and the step-built custom tool data.
|
|
1312
|
-
stepPrompt,
|
|
1313
|
-
customToolDefinitions: cachedAdditionalToolDefinitions,
|
|
1314
|
-
})
|
|
1315
|
-
|
|
1316
|
-
Object.assign(initialAgentState, newAgentState)
|
|
1317
|
-
currentAgentState = initialAgentState
|
|
1318
|
-
nResponses = generatedResponses
|
|
1319
|
-
|
|
1320
|
-
let stepStatus: 'completed' | 'failed' = 'completed'
|
|
1321
|
-
let stepErrorMessage: string | undefined
|
|
1322
|
-
if (hasNativeIncompleteToolCall) {
|
|
1323
|
-
consecutiveNativeIncompleteSteps += 1
|
|
1324
|
-
if (consecutiveNativeIncompleteSteps >= 2) {
|
|
1325
|
-
stepStatus = 'failed'
|
|
1326
|
-
stepErrorMessage = NATIVE_TOOL_CALL_RECOVERY_EXHAUSTED_MESSAGE
|
|
1327
|
-
}
|
|
1328
|
-
shouldEndTurn = false
|
|
1329
|
-
} else {
|
|
1330
|
-
// “Consecutive” means no intervening normal text, valid tool result, or
|
|
1331
|
-
// unrelated tool error. Any non-native-incomplete step breaks recovery
|
|
1332
|
-
// streaks before the normal turn decision is applied.
|
|
1333
|
-
consecutiveNativeIncompleteSteps = 0
|
|
1334
|
-
shouldEndTurn = llmShouldEndTurn
|
|
1335
|
-
}
|
|
1336
|
-
|
|
1337
|
-
// FID-2026-0801-012: Thinker convergence gate.
|
|
1338
|
-
// Runs at the runtime boundary AFTER the native step's tool results are
|
|
1339
|
-
// committed to history, and BEFORE the loop-top `output === undefined &&
|
|
1340
|
-
// shouldEndTurn` restart check. For the Thinker it builds the
|
|
1341
|
-
// FinalArtifact from the session snapshot and sets `agentState.output`
|
|
1342
|
-
// for every terminal status — otherwise the restart branch would fire
|
|
1343
|
-
// the "You must use set_output" message and reintroduce
|
|
1344
|
-
// `structuredOutput: null` (set_output is not in the Thinker's
|
|
1345
|
-
// toolNames). Retries keep the loop going with a typed message.
|
|
1346
|
-
if (
|
|
1347
|
-
agentTemplate.outputMode === 'structured_output' &&
|
|
1348
|
-
agentTemplate.toolNames.includes('sequentialthinking')
|
|
1349
|
-
) {
|
|
1350
|
-
const gateResult = runThinkerConvergenceGate({
|
|
1351
|
-
runId,
|
|
1352
|
-
agentState: currentAgentState,
|
|
1353
|
-
shouldEndTurn,
|
|
1354
|
-
logger,
|
|
1355
|
-
})
|
|
1356
|
-
if (gateResult.retryAppended) {
|
|
1357
|
-
shouldEndTurn = false
|
|
1358
|
-
}
|
|
1359
|
-
}
|
|
1360
|
-
|
|
1361
|
-
if (newAgentState.runId) {
|
|
1362
|
-
await addAgentStep({
|
|
1363
|
-
...params,
|
|
1364
|
-
agentRunId: newAgentState.runId,
|
|
1365
|
-
stepNumber: totalSteps,
|
|
1366
|
-
credits: newAgentState.directCreditsUsed - creditsBefore,
|
|
1367
|
-
childRunIds: newAgentState.childRunIds.slice(childrenBefore),
|
|
1368
|
-
messageId,
|
|
1369
|
-
status: stepStatus,
|
|
1370
|
-
errorMessage: stepErrorMessage,
|
|
1371
|
-
startTime,
|
|
1372
|
-
})
|
|
1373
|
-
} else {
|
|
1374
|
-
logger.error('No runId found for agent state after finishing agent run')
|
|
1375
|
-
}
|
|
1376
|
-
|
|
1377
|
-
if (stepErrorMessage !== undefined) {
|
|
1378
|
-
throw new Error(stepErrorMessage)
|
|
1379
|
-
}
|
|
1380
|
-
|
|
1381
|
-
currentPrompt = undefined
|
|
1382
|
-
currentParams = undefined
|
|
1383
|
-
|
|
1384
|
-
// Steering: if the host fed user messages while this step ran, append them
|
|
1385
|
-
// now (the step's LLM call + tools have completed, so history is in a clean
|
|
1386
|
-
// state) and keep the turn going so the agent runs a second step that can
|
|
1387
|
-
// see (and act on) the new message.
|
|
1388
|
-
const steered = params.drainSteeringMessages?.()
|
|
1389
|
-
if (steered?.length) {
|
|
1390
|
-
currentAgentState.messageHistory = [
|
|
1391
|
-
...currentAgentState.messageHistory,
|
|
1392
|
-
...steered.map((text) =>
|
|
1393
|
-
userMessage({
|
|
1394
|
-
content: buildUserMessageContent(text, undefined, undefined),
|
|
1395
|
-
tags: ['USER_PROMPT'],
|
|
1396
|
-
keepDuringTruncation: true,
|
|
1397
|
-
}),
|
|
1398
|
-
),
|
|
1399
|
-
]
|
|
1400
|
-
shouldEndTurn = false
|
|
1401
|
-
}
|
|
1402
|
-
}
|
|
1403
|
-
|
|
1404
|
-
if (clearUserPromptMessagesAfterResponse) {
|
|
1405
|
-
currentAgentState.messageHistory = expireMessages(
|
|
1406
|
-
currentAgentState.messageHistory,
|
|
1407
|
-
'userPrompt',
|
|
1408
|
-
)
|
|
1409
|
-
}
|
|
1410
|
-
|
|
1411
|
-
await finishAgentRun({
|
|
1412
|
-
...params,
|
|
1413
|
-
runId,
|
|
1414
|
-
status: 'completed',
|
|
1415
|
-
totalSteps,
|
|
1416
|
-
directCredits: currentAgentState.directCreditsUsed,
|
|
1417
|
-
totalCredits: currentAgentState.creditsUsed,
|
|
1418
|
-
})
|
|
1419
|
-
|
|
1420
|
-
return {
|
|
1421
|
-
agentState: currentAgentState,
|
|
1422
|
-
output: getAgentOutput(currentAgentState, agentTemplate),
|
|
1423
|
-
}
|
|
1424
|
-
} catch (error) {
|
|
1425
|
-
// Handle user-initiated aborts separately - don't log as errors
|
|
1426
|
-
if (isAbortError(error)) {
|
|
1427
|
-
if (clearUserPromptMessagesAfterResponse) {
|
|
1428
|
-
currentAgentState.messageHistory = expireMessages(
|
|
1429
|
-
currentAgentState.messageHistory,
|
|
1430
|
-
'userPrompt',
|
|
1431
|
-
)
|
|
1432
|
-
}
|
|
1433
|
-
|
|
1434
|
-
currentAgentState.messageHistory = [
|
|
1435
|
-
...currentAgentState.messageHistory,
|
|
1436
|
-
userMessage(
|
|
1437
|
-
withSystemTags(
|
|
1438
|
-
"User interrupted the response. The assistant's previous work has been preserved.",
|
|
1439
|
-
),
|
|
1440
|
-
),
|
|
1441
|
-
]
|
|
1442
|
-
|
|
1443
|
-
logger.info(
|
|
1444
|
-
{
|
|
1445
|
-
agentType,
|
|
1446
|
-
agentId: currentAgentState.agentId,
|
|
1447
|
-
runId,
|
|
1448
|
-
totalSteps,
|
|
1449
|
-
messageHistory: currentAgentState.messageHistory,
|
|
1450
|
-
},
|
|
1451
|
-
'Agent run cancelled by user (abort error)',
|
|
1452
|
-
)
|
|
1453
|
-
|
|
1454
|
-
await finishAgentRun({
|
|
1455
|
-
...params,
|
|
1456
|
-
runId,
|
|
1457
|
-
status: 'cancelled',
|
|
1458
|
-
totalSteps,
|
|
1459
|
-
directCredits: currentAgentState.directCreditsUsed,
|
|
1460
|
-
totalCredits: currentAgentState.creditsUsed,
|
|
1461
|
-
})
|
|
1462
|
-
|
|
1463
|
-
return {
|
|
1464
|
-
agentState: currentAgentState,
|
|
1465
|
-
output: {
|
|
1466
|
-
type: 'error',
|
|
1467
|
-
message: 'Run cancelled by user',
|
|
1468
|
-
},
|
|
1469
|
-
}
|
|
1470
|
-
}
|
|
1471
|
-
|
|
1472
|
-
// FID-2026-0725-085 Layer 4: Reactive compact — catch prompt-too-long errors,
|
|
1473
|
-
// aggressively truncate, and retry once before surfacing the error.
|
|
1474
|
-
if (ContextCompactor.isPromptTooLongError(error) && !signal.aborted) {
|
|
1475
|
-
logger.warn(
|
|
1476
|
-
{ error: getErrorObject(error) },
|
|
1477
|
-
'Layer 4 reactive compact: prompt-too-long detected, attempting emergency truncation',
|
|
1478
|
-
)
|
|
1479
|
-
const reactiveResult = contextCompactor.reactiveCompact(
|
|
1480
|
-
currentAgentState.messageHistory,
|
|
1481
|
-
)
|
|
1482
|
-
if (reactiveResult.truncated) {
|
|
1483
|
-
currentAgentState.messageHistory = reactiveResult.messages
|
|
1484
|
-
logger.warn(
|
|
1485
|
-
{
|
|
1486
|
-
messagesRemoved:
|
|
1487
|
-
currentAgentState.messageHistory.length -
|
|
1488
|
-
reactiveResult.messages.length,
|
|
1489
|
-
tokensSaved: reactiveResult.tokensSaved,
|
|
1490
|
-
},
|
|
1491
|
-
`Layer 4 reactive compact: truncated ${currentAgentState.messageHistory.length - reactiveResult.messages.length} messages, saved ~${reactiveResult.tokensSaved.toLocaleString()} tokens. Retrying API call once.`,
|
|
1492
|
-
)
|
|
1493
|
-
// Retry the API call once after reactive compaction
|
|
1494
|
-
try {
|
|
1495
|
-
const retryResult = await runAgentStep({
|
|
1496
|
-
...params,
|
|
1497
|
-
agentState: currentAgentState,
|
|
1498
|
-
agentTemplate,
|
|
1499
|
-
n: undefined,
|
|
1500
|
-
prompt: currentPrompt,
|
|
1501
|
-
runId,
|
|
1502
|
-
spawnParams: currentParams,
|
|
1503
|
-
system,
|
|
1504
|
-
tools,
|
|
1505
|
-
additionalToolDefinitions: additionalToolDefinitionsWithCache,
|
|
1506
|
-
customToolDefinitions: cachedAdditionalToolDefinitions,
|
|
1507
|
-
})
|
|
1508
|
-
// Retry succeeded — use the result
|
|
1509
|
-
Object.assign(initialAgentState, retryResult.agentState)
|
|
1510
|
-
currentAgentState = initialAgentState
|
|
1511
|
-
contextCompactor.recordCompactionResult(
|
|
1512
|
-
true,
|
|
1513
|
-
currentAgentState.contextTokenCount,
|
|
1514
|
-
)
|
|
1515
|
-
await finishAgentRun({
|
|
1516
|
-
...params,
|
|
1517
|
-
runId,
|
|
1518
|
-
status: 'completed',
|
|
1519
|
-
totalSteps,
|
|
1520
|
-
directCredits: currentAgentState.directCreditsUsed,
|
|
1521
|
-
totalCredits: currentAgentState.creditsUsed,
|
|
1522
|
-
})
|
|
1523
|
-
return {
|
|
1524
|
-
agentState: currentAgentState,
|
|
1525
|
-
output: getAgentOutput(currentAgentState, agentTemplate),
|
|
1526
|
-
}
|
|
1527
|
-
} catch (retryError) {
|
|
1528
|
-
// Retry also failed — log and fall through to standard error handling
|
|
1529
|
-
contextCompactor.recordCompactionResult(false)
|
|
1530
|
-
logger.error(
|
|
1531
|
-
{ retryError: getErrorObject(retryError) },
|
|
1532
|
-
'Layer 4 reactive compact: retry also failed',
|
|
1533
|
-
)
|
|
1534
|
-
}
|
|
1535
|
-
}
|
|
1536
|
-
}
|
|
1537
|
-
|
|
1538
|
-
logger.error(
|
|
1539
|
-
{
|
|
1540
|
-
error: getErrorObject(error),
|
|
1541
|
-
agentType,
|
|
1542
|
-
agentId: currentAgentState.agentId,
|
|
1543
|
-
runId,
|
|
1544
|
-
totalSteps,
|
|
1545
|
-
directCreditsUsed: currentAgentState.directCreditsUsed,
|
|
1546
|
-
creditsUsed: currentAgentState.creditsUsed,
|
|
1547
|
-
messageHistory: currentAgentState.messageHistory,
|
|
1548
|
-
systemPrompt: system,
|
|
1549
|
-
},
|
|
1550
|
-
'Agent execution failed',
|
|
1551
|
-
)
|
|
1552
|
-
|
|
1553
|
-
const apiErrorDetails = extractApiErrorDetails(error)
|
|
1554
|
-
const isIdleTimeout = isFetchIdleTimeoutError(error)
|
|
1555
|
-
const isNetworkError = !isIdleTimeout && isTransientNetworkError(error)
|
|
1556
|
-
const hasServerMessage = apiErrorDetails.message !== undefined
|
|
1557
|
-
let fallbackMessage: string
|
|
1558
|
-
if (isIdleTimeout) {
|
|
1559
|
-
fallbackMessage = FETCH_IDLE_TIMEOUT_USER_MESSAGE
|
|
1560
|
-
} else if (isNetworkError) {
|
|
1561
|
-
fallbackMessage = TRANSIENT_NETWORK_ERROR_USER_MESSAGE
|
|
1562
|
-
} else if (error instanceof Error) {
|
|
1563
|
-
const includeStack =
|
|
1564
|
-
apiErrorDetails.statusCode === undefined && error.stack
|
|
1565
|
-
fallbackMessage =
|
|
1566
|
-
error.message + (includeStack ? `\n\n${error.stack}` : '')
|
|
1567
|
-
} else {
|
|
1568
|
-
fallbackMessage = String(error)
|
|
1569
|
-
}
|
|
1570
|
-
const errorMessage = apiErrorDetails.message ?? fallbackMessage
|
|
1571
|
-
const statusCode = apiErrorDetails.statusCode
|
|
1572
|
-
|
|
1573
|
-
const status = signal.aborted ? 'cancelled' : 'failed'
|
|
1574
|
-
await finishAgentRun({
|
|
1575
|
-
...params,
|
|
1576
|
-
runId,
|
|
1577
|
-
status,
|
|
1578
|
-
totalSteps,
|
|
1579
|
-
directCredits: currentAgentState.directCreditsUsed,
|
|
1580
|
-
totalCredits: currentAgentState.creditsUsed,
|
|
1581
|
-
errorMessage,
|
|
1582
|
-
})
|
|
1583
|
-
|
|
1584
|
-
// Payment required errors (402) should propagate
|
|
1585
|
-
if (statusCode === 402) {
|
|
1586
|
-
throw error
|
|
1587
|
-
}
|
|
1588
|
-
|
|
1589
|
-
return {
|
|
1590
|
-
agentState: currentAgentState,
|
|
1591
|
-
output: {
|
|
1592
|
-
type: 'error',
|
|
1593
|
-
message:
|
|
1594
|
-
hasServerMessage || isIdleTimeout || isNetworkError
|
|
1595
|
-
? errorMessage
|
|
1596
|
-
: 'Agent run error: ' + errorMessage,
|
|
1597
|
-
...(statusCode !== undefined && { statusCode }),
|
|
1598
|
-
...(apiErrorDetails.errorCode !== undefined && {
|
|
1599
|
-
error: apiErrorDetails.errorCode,
|
|
1600
|
-
}),
|
|
1601
|
-
...(apiErrorDetails.countryCode !== undefined && {
|
|
1602
|
-
countryCode: apiErrorDetails.countryCode,
|
|
1603
|
-
}),
|
|
1604
|
-
...(apiErrorDetails.countryBlockReason !== undefined && {
|
|
1605
|
-
countryBlockReason: apiErrorDetails.countryBlockReason,
|
|
1606
|
-
}),
|
|
1607
|
-
...(apiErrorDetails.ipPrivacySignals !== undefined && {
|
|
1608
|
-
ipPrivacySignals: apiErrorDetails.ipPrivacySignals,
|
|
1609
|
-
}),
|
|
1610
|
-
},
|
|
1611
|
-
}
|
|
1612
|
-
} finally {
|
|
1613
|
-
// The endTurn path inside runProgrammaticStep handles normal completion,
|
|
1614
|
-
// but abort/error exits (e.g. chat SSE disconnects) would otherwise leak
|
|
1615
|
-
// the run's generator, STEP_ALL flag, and proposed file content forever.
|
|
1616
|
-
clearProgrammaticRunState(runId)
|
|
1617
|
-
// FID-2026-0801-012: per-run ThoughtSession and retry counters must not
|
|
1618
|
-
// leak across abort/error exits; cleanup is idempotent and marks an
|
|
1619
|
-
// in-flight session cancelled.
|
|
1620
|
-
cleanupThoughtSession(runId)
|
|
1621
|
-
resetThinkerConvergenceState(runId)
|
|
1622
|
-
}
|
|
1623
|
-
}
|
|
1624
|
-
|
|
1625
|
-
const NATIVE_TOOL_CALL_RECOVERY_EXHAUSTED_MESSAGE =
|
|
1626
|
-
'Native tool-call recovery failed twice consecutively; ending the agent run without executing the incomplete tool call.'
|
|
1627
|
-
|
|
1628
|
-
const STEP_WARNING_MESSAGE = [
|
|
1629
|
-
"I've made quite a few responses in a row.",
|
|
1630
|
-
"Let me pause here to make sure we're still on the right track.",
|
|
1631
|
-
"Please let me know if you'd like me to continue or if you'd like to guide me in a different direction.",
|
|
1632
|
-
].join(' ')
|