savant-code 0.0.16 → 0.0.19
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/.agents/skills/coding-csharp/SKILL.md +82 -0
- package/.agents/skills/coding-go/SKILL.md +76 -0
- package/.agents/skills/coding-java/SKILL.md +79 -0
- package/.agents/skills/coding-python/SKILL.md +87 -0
- package/.agents/skills/coding-rust/SKILL.md +83 -0
- package/.agents/skills/coding-typescript/SKILL.md +90 -0
- package/.agents/skills/release-workflow/SKILL.md +69 -0
- package/.bun-version +1 -0
- package/.commandcode/settings.json +11 -0
- package/.commandcode/taste/workflow/taste.md +6 -0
- package/.env.example +95 -0
- package/.gitattributes +43 -0
- package/.githooks/pre-push +35 -0
- package/.github/workflows/build-release-binaries.yml +163 -0
- package/.markdownlint.json +42 -0
- package/.markdownlintignore +21 -0
- package/.prettierignore +9 -0
- package/.prettierrc +23 -0
- package/.savantignore +3 -0
- package/AGENTS.md +97 -0
- package/ARCHITECTURE.md +241 -0
- package/CHANGELOG.md +2631 -0
- package/CONTRIBUTING.md +88 -0
- package/ECHO-freebuff.md +22 -0
- package/ECHO.md +722 -0
- package/FREEREADME.md +35 -0
- package/LEARNINGS.md +345 -0
- package/NOTICE +15 -0
- package/README.md +550 -216
- package/README.zh-CN.md +479 -0
- package/SECURITY.md +8 -0
- package/VERSION +1 -0
- package/WINDOWS.md +238 -0
- package/agents/README.md +41 -0
- package/agents/base-chat.ts +44 -0
- package/agents/basher.ts +107 -0
- package/agents/browser-use/browser-use.test.ts +211 -0
- package/agents/browser-use/browser-use.ts +259 -0
- package/agents/constants.ts +1 -0
- package/agents/context-pruner.ts +1076 -0
- package/agents/detective/detective.ts +168 -0
- package/agents/editor/best-of-n/best-of-n-selector2.ts +148 -0
- package/agents/editor/best-of-n/editor-implementor-gpt-5.ts +7 -0
- package/agents/editor/best-of-n/editor-implementor-opus.ts +7 -0
- package/agents/editor/best-of-n/editor-implementor.ts +196 -0
- package/agents/editor/best-of-n/editor-multi-prompt.ts +265 -0
- package/agents/file-explorer/directory-lister.ts +92 -0
- package/agents/file-explorer/glob-matcher.ts +96 -0
- package/agents/forge/forge.ts +146 -0
- package/agents/librarian/librarian.test.ts +289 -0
- package/agents/librarian/librarian.ts +158 -0
- package/agents/package.json +11 -0
- package/agents/recorder/recorder.ts +104 -0
- package/agents/researcher/researcher-docs.ts +32 -0
- package/agents/researcher/researcher-web.ts +40 -0
- package/agents/savant/savant-analyze.ts +11 -0
- package/agents/savant/savant-free-deepseek-flash.ts +13 -0
- package/agents/savant/savant-free-deepseek.ts +13 -0
- package/agents/savant/savant-free-evals.ts +9 -0
- package/agents/savant/savant-free-glm.ts +13 -0
- package/agents/savant/savant-free-kimi.ts +13 -0
- package/agents/savant/savant-free-mimo-pro.ts +13 -0
- package/agents/savant/savant-free-mimo.ts +13 -0
- package/agents/savant/savant-free-minimax-m3.ts +13 -0
- package/agents/savant/savant-free.ts +9 -0
- package/agents/savant/savant-scaffold.ts +15 -0
- package/agents/savant/savant.ts +706 -0
- package/agents/scout/scout.ts +305 -0
- package/agents/scribe/scribe.ts +54 -0
- package/agents/thinker/thinker-gemini.ts +26 -0
- package/agents/thinker/thinker-gpt.ts +21 -0
- package/agents/thinker/thinker-with-files-gemini.ts +66 -0
- package/agents/thinker/thinker.ts +99 -0
- package/agents/tmux-cli.ts +724 -0
- package/agents/tsconfig.json +12 -0
- package/agents/types/agent-definition.ts +1 -0
- package/agents/types/secret-agent-definition.ts +103 -0
- package/agents/types/tools.ts +465 -0
- package/agents/types/util-types.ts +167 -0
- package/agents/verifier/verifier.ts +80 -0
- package/art/savant-redesign.md +7 -0
- package/art/savant-text-graf.md +5 -0
- package/art/savant_ascii.md +88 -0
- package/assets/banner.png +0 -0
- package/bun.lock +1979 -0
- package/bunfig.toml +7 -0
- package/cli/README.md +111 -0
- package/cli/bunfig.toml +2 -0
- package/cli/cli_exit +1 -0
- package/cli/package.json +66 -0
- package/cli/release/README.md +348 -0
- package/{index.js → cli/release/index.js} +0 -0
- package/cli/release/package.json +56 -0
- package/cli/release-core/README.md +20 -0
- package/cli/release-core/package.json +4 -0
- package/cli/release-core/prepare-package.js +31 -0
- package/cli/release-staging/README.md +70 -0
- package/cli/release-staging/index.js +42 -0
- package/cli/release-staging/package.json +43 -0
- package/cli/scripts/build-binary.ts +469 -0
- package/cli/scripts/clean.ts +16 -0
- package/cli/scripts/prebuild-agents.ts +250 -0
- package/cli/scripts/release.ts +103 -0
- package/cli/scripts/smoke-binary.ts +280 -0
- package/cli/scripts/test-sdk-file-hooks.sh +87 -0
- package/cli/scripts/validate-cli-with-tmux.sh +43 -0
- package/cli/src/__tests__/README.md +256 -0
- package/cli/src/__tests__/bash-mode.test.ts +442 -0
- package/cli/src/__tests__/cli-args.test.ts +241 -0
- package/cli/src/__tests__/e2e/first-time-login.test.ts +173 -0
- package/cli/src/__tests__/e2e/logout-relogin-flow.test.ts +110 -0
- package/cli/src/__tests__/e2e/returning-user-auth.test.ts +111 -0
- package/cli/src/__tests__/e2e-cli.test.ts +185 -0
- package/cli/src/__tests__/helpers/mock-api-client.ts +64 -0
- package/cli/src/__tests__/helpers/terminal-watchdog-fixture.ts +50 -0
- package/cli/src/__tests__/home-directory-detection.test.ts +213 -0
- package/cli/src/__tests__/integration/agent-toolnames-validation.test.ts +63 -0
- package/cli/src/__tests__/integration/api-integration.test.ts +289 -0
- package/cli/src/__tests__/integration/credentials-storage.test.ts +453 -0
- package/cli/src/__tests__/integration/local-agents.test.ts +1187 -0
- package/cli/src/__tests__/integration/login-flow-instrumentation.test.ts +146 -0
- package/cli/src/__tests__/integration/login-polling-working.test.ts +287 -0
- package/cli/src/__tests__/integration/usage-refresh-on-completion.test.ts +177 -0
- package/cli/src/__tests__/integration-tmux.test.ts +186 -0
- package/cli/src/__tests__/mocks/hover-toggle-controller.ts +71 -0
- package/cli/src/__tests__/path-completion.test.ts +243 -0
- package/cli/src/__tests__/project-files-chat-id.test.ts +34 -0
- package/cli/src/__tests__/release/proxy-http-get.test.ts +670 -0
- package/cli/src/__tests__/release/wrapper-safety.test.ts +177 -0
- package/cli/src/__tests__/rerender-perf.integration.test.ts +283 -0
- package/cli/src/__tests__/terminal-reset-sequences.test.ts +36 -0
- package/cli/src/__tests__/terminal-watchdog.test.ts +114 -0
- package/cli/src/__tests__/test-utils.ts +266 -0
- package/cli/src/__tests__/tmux-poc.ts +150 -0
- package/cli/src/__tests__/unit/agent-mode-toggle.test.ts +138 -0
- package/cli/src/__tests__/unit/copy-button.test.tsx +188 -0
- package/cli/src/__tests__/unit/create-run-config.test.ts +77 -0
- package/cli/src/__tests__/unit/publish-confirmation.test.ts +70 -0
- package/cli/src/__tests__/unit/segmented-control.test.ts +167 -0
- package/cli/src/__tests__/utils/env.test.ts +210 -0
- package/cli/src/__tests__/utils/project-picker.test.ts +39 -0
- package/cli/src/agents/bundled-agents.generated.d.ts +14 -0
- package/cli/src/agents/bundled-agents.generated.ts +1962 -0
- package/cli/src/app.tsx +383 -0
- package/cli/src/chat.tsx +2008 -0
- package/cli/src/cli-args.ts +183 -0
- package/cli/src/commands/__tests__/bash-command.test.ts +449 -0
- package/cli/src/commands/__tests__/command-args.test.ts +325 -0
- package/cli/src/commands/__tests__/copy-conversation.test.ts +240 -0
- package/cli/src/commands/__tests__/dev-command.test.ts +128 -0
- package/cli/src/commands/__tests__/diagnostics-command.test.ts +35 -0
- package/cli/src/commands/__tests__/image.test.ts +99 -0
- package/cli/src/commands/__tests__/init.test.ts +479 -0
- package/cli/src/commands/__tests__/loop-command.test.ts +89 -0
- package/cli/src/commands/__tests__/new-command-rotates-chat.test.ts +87 -0
- package/cli/src/commands/__tests__/permissions-command.test.ts +93 -0
- package/cli/src/commands/__tests__/process-diagnostics.test.ts +54 -0
- package/cli/src/commands/__tests__/prompt-builders.test.ts +69 -0
- package/cli/src/commands/__tests__/registry-gating.test.ts +125 -0
- package/cli/src/commands/__tests__/rewind-command.test.ts +227 -0
- package/cli/src/commands/__tests__/router-connect-chatgpt.test.ts +72 -0
- package/cli/src/commands/__tests__/router-input.test.ts +302 -0
- package/cli/src/commands/__tests__/router-provider-setup.test.ts +180 -0
- package/cli/src/commands/__tests__/savant-free-command-aliases.test.ts +56 -0
- package/cli/src/commands/ads.ts +45 -0
- package/cli/src/commands/command-registry.ts +1112 -0
- package/cli/src/commands/copy-conversation.ts +386 -0
- package/cli/src/commands/goal.ts +87 -0
- package/cli/src/commands/health-command.ts +61 -0
- package/cli/src/commands/help.ts +13 -0
- package/cli/src/commands/image.ts +20 -0
- package/cli/src/commands/init.ts +121 -0
- package/cli/src/commands/loop.ts +182 -0
- package/cli/src/commands/process-diagnostics.ts +120 -0
- package/cli/src/commands/prompt-builders.ts +140 -0
- package/cli/src/commands/publish.ts +261 -0
- package/cli/src/commands/rewind.ts +130 -0
- package/cli/src/commands/router-utils.ts +80 -0
- package/cli/src/commands/router.ts +589 -0
- package/cli/src/commands/telemetry.ts +68 -0
- package/cli/src/commands/usage.ts +26 -0
- package/cli/src/components/__tests__/ad-banner.test.tsx +84 -0
- package/cli/src/components/__tests__/block-helpers.test.tsx +139 -0
- package/cli/src/components/__tests__/clickable.test.tsx +39 -0
- package/cli/src/components/__tests__/grid-layout.integration.test.tsx +365 -0
- package/cli/src/components/__tests__/grid-layout.test.tsx +1033 -0
- package/cli/src/components/__tests__/markdown-content.test.tsx +163 -0
- package/cli/src/components/__tests__/message-block.completion.test.tsx +104 -0
- package/cli/src/components/__tests__/message-block.streaming.test.tsx +78 -0
- package/cli/src/components/__tests__/message-with-agents.test.tsx +571 -0
- package/cli/src/components/__tests__/multiline-input.test.tsx +1129 -0
- package/cli/src/components/__tests__/selectable-list.test.ts +232 -0
- package/cli/src/components/__tests__/shimmer-text.test.tsx +32 -0
- package/cli/src/components/__tests__/status-indicator.test.tsx +184 -0
- package/cli/src/components/__tests__/user-error-banner.test.tsx +100 -0
- package/cli/src/components/ad-banner.tsx +351 -0
- package/cli/src/components/agent-checklist.tsx +385 -0
- package/cli/src/components/agent-mode-toggle.tsx +294 -0
- package/cli/src/components/ask-user/__tests__/multiple-choice-form.test.ts +432 -0
- package/cli/src/components/ask-user/__tests__/validation.test.ts +213 -0
- package/cli/src/components/ask-user/components/accordion-question.tsx +153 -0
- package/cli/src/components/ask-user/components/custom-answer-input.tsx +66 -0
- package/cli/src/components/ask-user/components/options-list.tsx +139 -0
- package/cli/src/components/ask-user/components/question-header.tsx +80 -0
- package/cli/src/components/ask-user/components/question-option.tsx +94 -0
- package/cli/src/components/ask-user/constants.ts +35 -0
- package/cli/src/components/ask-user/index.tsx +660 -0
- package/cli/src/components/ask-user/utils/validation.ts +85 -0
- package/cli/src/components/attachment-card.tsx +67 -0
- package/cli/src/components/blocks/agent-block-grid.tsx +58 -0
- package/cli/src/components/blocks/agent-branch-item.tsx +230 -0
- package/cli/src/components/blocks/agent-branch-wrapper.tsx +524 -0
- package/cli/src/components/blocks/agent-list-branch.tsx +77 -0
- package/cli/src/components/blocks/ask-user-branch.tsx +98 -0
- package/cli/src/components/blocks/block-helpers.tsx +257 -0
- package/cli/src/components/blocks/blocks-renderer.tsx +296 -0
- package/cli/src/components/blocks/content-with-markdown.tsx +34 -0
- package/cli/src/components/blocks/copy-button.tsx +106 -0
- package/cli/src/components/blocks/copyable-block.tsx +47 -0
- package/cli/src/components/blocks/image-block.tsx +128 -0
- package/cli/src/components/blocks/implementor-row.tsx +453 -0
- package/cli/src/components/blocks/markdown-content.tsx +360 -0
- package/cli/src/components/blocks/markdown-renderables.tsx +347 -0
- package/cli/src/components/blocks/single-block.tsx +210 -0
- package/cli/src/components/blocks/thinking-block.tsx +77 -0
- package/cli/src/components/blocks/tool-block-group.tsx +72 -0
- package/cli/src/components/blocks/tool-branch.tsx +196 -0
- package/cli/src/components/blocks/user-content-copy.tsx +171 -0
- package/cli/src/components/bottom-banner.tsx +145 -0
- package/cli/src/components/build-mode-buttons.tsx +110 -0
- package/cli/src/components/button.tsx +75 -0
- package/cli/src/components/chat-header.tsx +11 -0
- package/cli/src/components/chat-history-screen.tsx +417 -0
- package/cli/src/components/chat-input-bar.tsx +535 -0
- package/cli/src/components/chatgpt-connect-banner.tsx +234 -0
- package/cli/src/components/clickable.tsx +149 -0
- package/cli/src/components/collapse-button.tsx +36 -0
- package/cli/src/components/command-palette.tsx +166 -0
- package/cli/src/components/copy-button.tsx +219 -0
- package/cli/src/components/dialog.tsx +111 -0
- package/cli/src/components/elapsed-timer.tsx +56 -0
- package/cli/src/components/error-boundary.tsx +63 -0
- package/cli/src/components/feedback-container.tsx +206 -0
- package/cli/src/components/feedback-icon-button.tsx +89 -0
- package/cli/src/components/feedback-input-mode.tsx +352 -0
- package/cli/src/components/file-attachment-card.tsx +89 -0
- package/cli/src/components/grid-layout.tsx +83 -0
- package/cli/src/components/help-banner.tsx +136 -0
- package/cli/src/components/highlighted-text.tsx +52 -0
- package/cli/src/components/image-card.tsx +167 -0
- package/cli/src/components/image-thumbnail.tsx +112 -0
- package/cli/src/components/input-cursor.tsx +77 -0
- package/cli/src/components/input-mode-banner.tsx +70 -0
- package/cli/src/components/load-previous-button.tsx +48 -0
- package/cli/src/components/login-modal.tsx +450 -0
- package/cli/src/components/message-block.tsx +337 -0
- package/cli/src/components/message-footer.tsx +269 -0
- package/cli/src/components/message-with-agents.tsx +594 -0
- package/cli/src/components/mode-divider.tsx +43 -0
- package/cli/src/components/model-picker.tsx +371 -0
- package/cli/src/components/multiline-input.tsx +1276 -0
- package/cli/src/components/out-of-credits-banner.tsx +155 -0
- package/cli/src/components/pending-attachments-banner.tsx +125 -0
- package/cli/src/components/pending-bash-message.tsx +57 -0
- package/cli/src/components/progress-bar.tsx +81 -0
- package/cli/src/components/project-picker-screen.tsx +469 -0
- package/cli/src/components/provider-picker.tsx +139 -0
- package/cli/src/components/publish-confirmation.tsx +514 -0
- package/cli/src/components/publish-container.tsx +737 -0
- package/cli/src/components/raised-pill.tsx +89 -0
- package/cli/src/components/renderers/plan-box.tsx +70 -0
- package/cli/src/components/review-screen.tsx +114 -0
- package/cli/src/components/rewind-picker.tsx +276 -0
- package/cli/src/components/right-sidebar.tsx +296 -0
- package/cli/src/components/savant-free-active-session-summary.tsx +63 -0
- package/cli/src/components/savant-free-landing-screen.tsx +756 -0
- package/cli/src/components/savant-free-model-selector.tsx +815 -0
- package/cli/src/components/savant-free-referral-banner.tsx +423 -0
- package/cli/src/components/savant-free-superseded-screen.tsx +62 -0
- package/cli/src/components/savant-ui/animation/pulse.tsx +26 -0
- package/cli/src/components/savant-ui/animation/typewriter.tsx +40 -0
- package/cli/src/components/savant-ui/branding.tsx +59 -0
- package/cli/src/components/savant-ui/data-display/badge.tsx +52 -0
- package/cli/src/components/savant-ui/data-display/code-block.tsx +55 -0
- package/cli/src/components/savant-ui/data-display/key-value.tsx +34 -0
- package/cli/src/components/savant-ui/data-display/sparkline.tsx +42 -0
- package/cli/src/components/savant-ui/data-display/timeline.tsx +44 -0
- package/cli/src/components/savant-ui/data-display/tree-view.tsx +55 -0
- package/cli/src/components/savant-ui/echo/__tests__/sidebar-collapse.test.tsx +90 -0
- package/cli/src/components/savant-ui/echo/agent-stack.tsx +72 -0
- package/cli/src/components/savant-ui/echo/agent-status.tsx +66 -0
- package/cli/src/components/savant-ui/echo/fid-card.tsx +89 -0
- package/cli/src/components/savant-ui/echo/fid-list.tsx +68 -0
- package/cli/src/components/savant-ui/echo/loop-status-panel.tsx +64 -0
- package/cli/src/components/savant-ui/echo/perfection-loop.tsx +118 -0
- package/cli/src/components/savant-ui/echo/phase-indicator.tsx +68 -0
- package/cli/src/components/savant-ui/echo/phase-info.ts +72 -0
- package/cli/src/components/savant-ui/echo/token-meter.tsx +39 -0
- package/cli/src/components/savant-ui/feedback/alert.tsx +45 -0
- package/cli/src/components/savant-ui/feedback/cost-tracker.tsx +54 -0
- package/cli/src/components/savant-ui/feedback/progress-bar.tsx +71 -0
- package/cli/src/components/savant-ui/feedback/spinner.tsx +40 -0
- package/cli/src/components/savant-ui/icon-theme-keys.ts +67 -0
- package/cli/src/components/savant-ui/icon.tsx +53 -0
- package/cli/src/components/savant-ui/index.ts +75 -0
- package/cli/src/components/savant-ui/input/select.tsx +26 -0
- package/cli/src/components/savant-ui/input/toggle.tsx +28 -0
- package/cli/src/components/savant-ui/layout/grid.tsx +52 -0
- package/cli/src/components/savant-ui/layout/header.tsx +28 -0
- package/cli/src/components/savant-ui/navigation/stepper.tsx +41 -0
- package/cli/src/components/savant-ui/primitives/key-hint.tsx +45 -0
- package/cli/src/components/savant-ui/primitives/key-value-row.tsx +41 -0
- package/cli/src/components/savant-ui/primitives/panel.tsx +42 -0
- package/cli/src/components/savant-ui/primitives/separator.tsx +34 -0
- package/cli/src/components/savant-ui/primitives/sidebar-section.tsx +64 -0
- package/cli/src/components/savant-ui/primitives/spacer.tsx +13 -0
- package/cli/src/components/savant-ui/primitives/stack.tsx +35 -0
- package/cli/src/components/savant-ui/theme.ts +45 -0
- package/cli/src/components/scroll-to-bottom-button.tsx +34 -0
- package/cli/src/components/segmented-control.tsx +199 -0
- package/cli/src/components/selectable-list.tsx +249 -0
- package/cli/src/components/selected-chips.tsx +86 -0
- package/cli/src/components/separator.tsx +40 -0
- package/cli/src/components/session-ended-banner.tsx +183 -0
- package/cli/src/components/shimmer-text.tsx +254 -0
- package/cli/src/components/status-bar.tsx +279 -0
- package/cli/src/components/subscription-limit-banner.tsx +269 -0
- package/cli/src/components/suggested-prompts.tsx +184 -0
- package/cli/src/components/suggestion-menu.tsx +219 -0
- package/cli/src/components/terminal-command-display.tsx +152 -0
- package/cli/src/components/terminal-link.tsx +97 -0
- package/cli/src/components/text-attachment-card.tsx +77 -0
- package/cli/src/components/thinking.tsx +108 -0
- package/cli/src/components/toast.tsx +109 -0
- package/cli/src/components/tools/__tests__/apply-patch.test.tsx +97 -0
- package/cli/src/components/tools/__tests__/code-search.test.tsx +45 -0
- package/cli/src/components/tools/__tests__/gravity-index.test.ts +76 -0
- package/cli/src/components/tools/__tests__/render-ui.test.tsx +556 -0
- package/cli/src/components/tools/__tests__/run-terminal-command.test.ts +274 -0
- package/cli/src/components/tools/__tests__/tool-call-item.test.tsx +73 -0
- package/cli/src/components/tools/apply-patch.tsx +101 -0
- package/cli/src/components/tools/code-search.tsx +50 -0
- package/cli/src/components/tools/composio.tsx +140 -0
- package/cli/src/components/tools/diff-viewer.tsx +21 -0
- package/cli/src/components/tools/glob.tsx +66 -0
- package/cli/src/components/tools/gravity-index.tsx +80 -0
- package/cli/src/components/tools/list-directory.tsx +66 -0
- package/cli/src/components/tools/read-docs.tsx +36 -0
- package/cli/src/components/tools/read-files.tsx +97 -0
- package/cli/src/components/tools/read-subtree.tsx +40 -0
- package/cli/src/components/tools/read-url.tsx +32 -0
- package/cli/src/components/tools/registry.ts +131 -0
- package/cli/src/components/tools/render-ui.tsx +466 -0
- package/cli/src/components/tools/run-terminal-command.tsx +86 -0
- package/cli/src/components/tools/skill.tsx +26 -0
- package/cli/src/components/tools/str-replace.tsx +77 -0
- package/cli/src/components/tools/suggest-followups.tsx +373 -0
- package/cli/src/components/tools/task-completed.tsx +16 -0
- package/cli/src/components/tools/tool-call-item.tsx +163 -0
- package/cli/src/components/tools/types.ts +100 -0
- package/cli/src/components/tools/web-search.tsx +32 -0
- package/cli/src/components/tools/write-file.tsx +20 -0
- package/cli/src/components/tools/write-todos.tsx +105 -0
- package/cli/src/components/top-banner.tsx +187 -0
- package/cli/src/components/usage-banner.tsx +296 -0
- package/cli/src/components/user-error-banner.tsx +54 -0
- package/cli/src/components/validation-error-popover.tsx +191 -0
- package/cli/src/data/slash-commands.ts +306 -0
- package/cli/src/hooks/__tests__/holds-live-savant-free-slot.test.ts +49 -0
- package/cli/src/hooks/__tests__/run-outcome.test.ts +178 -0
- package/cli/src/hooks/__tests__/session-fetch-signal.test.ts +45 -0
- package/cli/src/hooks/__tests__/use-activity-query.test.ts +810 -0
- package/cli/src/hooks/__tests__/use-ask-user-bridge.test.ts +175 -0
- package/cli/src/hooks/__tests__/use-auth-query.test.ts +21 -0
- package/cli/src/hooks/__tests__/use-chat-messages-collapse.test.ts +96 -0
- package/cli/src/hooks/__tests__/use-connection-status.test.ts +112 -0
- package/cli/src/hooks/__tests__/use-directory-browser.test.ts +215 -0
- package/cli/src/hooks/__tests__/use-gravity-ad.test.ts +73 -0
- package/cli/src/hooks/__tests__/use-grid-layout.test.ts +346 -0
- package/cli/src/hooks/__tests__/use-input-history.test.ts +704 -0
- package/cli/src/hooks/__tests__/use-loop-scheduler.test.ts +247 -0
- package/cli/src/hooks/__tests__/use-path-tab-completion.test.ts +324 -0
- package/cli/src/hooks/__tests__/use-queue-controls.test.ts +68 -0
- package/cli/src/hooks/__tests__/use-searchable-list.test.ts +364 -0
- package/cli/src/hooks/__tests__/use-send-message-timer.test.ts +146 -0
- package/cli/src/hooks/__tests__/use-suggestion-engine-mention.test.ts +364 -0
- package/cli/src/hooks/__tests__/use-suggestion-engine.test.ts +485 -0
- package/cli/src/hooks/__tests__/use-terminal-focus.test.ts +66 -0
- package/cli/src/hooks/__tests__/use-terminal-layout.test.ts +675 -0
- package/cli/src/hooks/__tests__/use-timeout.test.ts +330 -0
- package/cli/src/hooks/__tests__/use-usage-query.test.ts +526 -0
- package/cli/src/hooks/__tests__/use-user-details-query.test.ts +225 -0
- package/cli/src/hooks/helpers/__tests__/send-message.test.ts +1851 -0
- package/cli/src/hooks/helpers/send-message.ts +553 -0
- package/cli/src/hooks/run-outcome.ts +64 -0
- package/cli/src/hooks/stream-state.ts +106 -0
- package/cli/src/hooks/use-activity-query.ts +696 -0
- package/cli/src/hooks/use-agent-validation.ts +80 -0
- package/cli/src/hooks/use-ask-user-bridge.ts +102 -0
- package/cli/src/hooks/use-auth-query.ts +261 -0
- package/cli/src/hooks/use-auth-state.ts +155 -0
- package/cli/src/hooks/use-chat-input.ts +87 -0
- package/cli/src/hooks/use-chat-keyboard.ts +325 -0
- package/cli/src/hooks/use-chat-messages.ts +273 -0
- package/cli/src/hooks/use-chat-state.ts +219 -0
- package/cli/src/hooks/use-chat-streaming.ts +270 -0
- package/cli/src/hooks/use-chat-ui.ts +136 -0
- package/cli/src/hooks/use-clipboard.ts +154 -0
- package/cli/src/hooks/use-connection-status.ts +156 -0
- package/cli/src/hooks/use-directory-browser.ts +88 -0
- package/cli/src/hooks/use-elapsed-time.ts +116 -0
- package/cli/src/hooks/use-event.ts +36 -0
- package/cli/src/hooks/use-exit-handler.ts +108 -0
- package/cli/src/hooks/use-fetch-login-url.ts +65 -0
- package/cli/src/hooks/use-fids.ts +48 -0
- package/cli/src/hooks/use-fingerprint.ts +64 -0
- package/cli/src/hooks/use-gravity-ad.ts +688 -0
- package/cli/src/hooks/use-grid-layout.ts +78 -0
- package/cli/src/hooks/use-input-history.ts +173 -0
- package/cli/src/hooks/use-login-keyboard-handlers.ts +74 -0
- package/cli/src/hooks/use-login-polling.ts +120 -0
- package/cli/src/hooks/use-logo.tsx +178 -0
- package/cli/src/hooks/use-loop-scheduler.ts +481 -0
- package/cli/src/hooks/use-message-queue.ts +301 -0
- package/cli/src/hooks/use-now.ts +20 -0
- package/cli/src/hooks/use-path-tab-completion.ts +88 -0
- package/cli/src/hooks/use-publish-mutation.ts +60 -0
- package/cli/src/hooks/use-queue-controls.ts +70 -0
- package/cli/src/hooks/use-queue-ui.ts +55 -0
- package/cli/src/hooks/use-savant-free-ctrl-c-exit.ts +23 -0
- package/cli/src/hooks/use-savant-free-session-progress.ts +34 -0
- package/cli/src/hooks/use-savant-free-session.ts +679 -0
- package/cli/src/hooks/use-savant-free-streak-query.ts +72 -0
- package/cli/src/hooks/use-scaffold-confirm.ts +62 -0
- package/cli/src/hooks/use-scaffold-revert-subscriber.ts +66 -0
- package/cli/src/hooks/use-scroll-management.ts +182 -0
- package/cli/src/hooks/use-searchable-list.ts +99 -0
- package/cli/src/hooks/use-send-message.ts +1038 -0
- package/cli/src/hooks/use-sheen-animation.tsx +88 -0
- package/cli/src/hooks/use-subscription-query.ts +106 -0
- package/cli/src/hooks/use-suggestion-engine.ts +793 -0
- package/cli/src/hooks/use-terminal-breakpoints.ts +77 -0
- package/cli/src/hooks/use-terminal-dimensions.ts +50 -0
- package/cli/src/hooks/use-terminal-focus.ts +146 -0
- package/cli/src/hooks/use-terminal-layout.ts +189 -0
- package/cli/src/hooks/use-theme.tsx +140 -0
- package/cli/src/hooks/use-timeout.ts +88 -0
- package/cli/src/hooks/use-toast.ts +114 -0
- package/cli/src/hooks/use-update-preference.ts +77 -0
- package/cli/src/hooks/use-usage-monitor.ts +59 -0
- package/cli/src/hooks/use-usage-query.ts +138 -0
- package/cli/src/hooks/use-user-details-query.ts +104 -0
- package/cli/src/hooks/use-why-did-you-update.ts +178 -0
- package/cli/src/index.tsx +484 -0
- package/cli/src/init/__tests__/init-direnv.test.ts +597 -0
- package/cli/src/init/init-app.ts +54 -0
- package/cli/src/init/init-direnv.ts +133 -0
- package/cli/src/login/constants.ts +71 -0
- package/cli/src/login/login-flow.ts +224 -0
- package/cli/src/login/plain-login.ts +107 -0
- package/cli/src/login/utils.ts +183 -0
- package/cli/src/native/ripgrep.ts +82 -0
- package/cli/src/polyfills/bun-strip-ansi.ts +12 -0
- package/cli/src/pre-init/load-dev-env.ts +98 -0
- package/cli/src/pre-init/tree-sitter-wasm.ts +98 -0
- package/cli/src/project-files.ts +102 -0
- package/cli/src/state/__tests__/chat-store-focus.test.ts +22 -0
- package/cli/src/state/__tests__/feedback-store.test.ts +260 -0
- package/cli/src/state/chat-history-store.ts +27 -0
- package/cli/src/state/chat-store.ts +791 -0
- package/cli/src/state/feedback-store.ts +162 -0
- package/cli/src/state/gateway-catalog-store.ts +45 -0
- package/cli/src/state/login-store.ts +150 -0
- package/cli/src/state/message-block-store.ts +143 -0
- package/cli/src/state/model-picker-store.ts +67 -0
- package/cli/src/state/provider-picker-store.ts +53 -0
- package/cli/src/state/publish-store.ts +141 -0
- package/cli/src/state/review-store.ts +24 -0
- package/cli/src/state/rewind-picker-store.ts +74 -0
- package/cli/src/state/savant-free-model-store.ts +59 -0
- package/cli/src/state/savant-free-session-store.ts +32 -0
- package/cli/src/test-setup.ts +20 -0
- package/cli/src/testing/env.ts +46 -0
- package/cli/src/types/chat-state.ts +15 -0
- package/cli/src/types/chat.ts +242 -0
- package/cli/src/types/contracts/send-message.ts +16 -0
- package/cli/src/types/env.ts +107 -0
- package/cli/src/types/function-params.ts +35 -0
- package/cli/src/types/opentui-augmentation.d.ts +11 -0
- package/cli/src/types/react19-compat.d.ts +19 -0
- package/cli/src/types/savant-free-session.ts +17 -0
- package/cli/src/types/store.ts +112 -0
- package/cli/src/types/theme-system.ts +194 -0
- package/cli/src/types/utils.ts +3 -0
- package/cli/src/utils/__tests__/activity-tracker.test.ts +440 -0
- package/cli/src/utils/__tests__/agent-display.test.ts +139 -0
- package/cli/src/utils/__tests__/analytics-client.test.ts +311 -0
- package/cli/src/utils/__tests__/anonymous-id.test.ts +74 -0
- package/cli/src/utils/__tests__/arrays.test.ts +264 -0
- package/cli/src/utils/__tests__/bash-context-processor.test.ts +38 -0
- package/cli/src/utils/__tests__/block-processor.test.ts +690 -0
- package/cli/src/utils/__tests__/chat-history.test.ts +247 -0
- package/cli/src/utils/__tests__/chat-input-key-intercept.test.ts +40 -0
- package/cli/src/utils/__tests__/chat-layout.test.ts +32 -0
- package/cli/src/utils/__tests__/chat-meta.test.ts +160 -0
- package/cli/src/utils/__tests__/chatgpt-oauth.test.ts +50 -0
- package/cli/src/utils/__tests__/clipboard.test.ts +998 -0
- package/cli/src/utils/__tests__/code-search-summary.test.ts +84 -0
- package/cli/src/utils/__tests__/collapse-helpers.test.ts +1272 -0
- package/cli/src/utils/__tests__/error-handling.test.ts +611 -0
- package/cli/src/utils/__tests__/feedback-helpers.test.ts +452 -0
- package/cli/src/utils/__tests__/feedback-submission.test.ts +26 -0
- package/cli/src/utils/__tests__/fetch-usage.test.ts +355 -0
- package/cli/src/utils/__tests__/fingerprint.test.ts +147 -0
- package/cli/src/utils/__tests__/format-elapsed-time.test.ts +103 -0
- package/cli/src/utils/__tests__/format-timeout.test.ts +87 -0
- package/cli/src/utils/__tests__/image-dimensions.test.ts +243 -0
- package/cli/src/utils/__tests__/image-processor.test.ts +250 -0
- package/cli/src/utils/__tests__/implementor-helpers.test.ts +1457 -0
- package/cli/src/utils/__tests__/keyboard-actions.test.ts +686 -0
- package/cli/src/utils/__tests__/layout-helpers.test.ts +36 -0
- package/cli/src/utils/__tests__/lazy-response-ads.test.ts +167 -0
- package/cli/src/utils/__tests__/logger-sanitize-secrets.test.ts +80 -0
- package/cli/src/utils/__tests__/markdown-renderer.test.tsx +518 -0
- package/cli/src/utils/__tests__/markdown-streaming.test.ts +64 -0
- package/cli/src/utils/__tests__/message-block-helpers.test.ts +1197 -0
- package/cli/src/utils/__tests__/message-updater.test.ts +659 -0
- package/cli/src/utils/__tests__/ollama-onboarding.test.ts +239 -0
- package/cli/src/utils/__tests__/openrouter-models.test.ts +295 -0
- package/cli/src/utils/__tests__/osc-timeout-scenarios.test.ts +172 -0
- package/cli/src/utils/__tests__/pending-attachments.test.ts +278 -0
- package/cli/src/utils/__tests__/provider-setup.test.ts +183 -0
- package/cli/src/utils/__tests__/run-state-storage.test.ts +741 -0
- package/cli/src/utils/__tests__/savant-code-api.test.ts +634 -0
- package/cli/src/utils/__tests__/savant-free-instance-owner.test.ts +69 -0
- package/cli/src/utils/__tests__/savant-free-model-navigation.test.ts +104 -0
- package/cli/src/utils/__tests__/savant-free-premium-reset.test.ts +81 -0
- package/cli/src/utils/__tests__/savant-free-referral-cache.test.ts +67 -0
- package/cli/src/utils/__tests__/savant-free-session-display.test.ts +23 -0
- package/cli/src/utils/__tests__/savant-free-streak-line.test.ts +76 -0
- package/cli/src/utils/__tests__/sdk-event-handlers.test.ts +615 -0
- package/cli/src/utils/__tests__/send-message-helpers.test.ts +1875 -0
- package/cli/src/utils/__tests__/send-message-timer.test.ts +68 -0
- package/cli/src/utils/__tests__/settings.test.ts +138 -0
- package/cli/src/utils/__tests__/strings.test.ts +210 -0
- package/cli/src/utils/__tests__/syntax-theme.test.ts +91 -0
- package/cli/src/utils/__tests__/terminal-color-detection.test.ts +425 -0
- package/cli/src/utils/__tests__/terminal-enter-detection.test.ts +77 -0
- package/cli/src/utils/__tests__/text-layout.test.ts +82 -0
- package/cli/src/utils/__tests__/think-tag-parser.test.ts +159 -0
- package/cli/src/utils/__tests__/trace-writer.test.ts +193 -0
- package/cli/src/utils/__tests__/trim-chat-logs.test.ts +79 -0
- package/cli/src/utils/__tests__/usage-banner-state.test.ts +298 -0
- package/cli/src/utils/__tests__/validation-error-formatting.test.ts +126 -0
- package/cli/src/utils/__tests__/write-file-atomic.test.ts +130 -0
- package/cli/src/utils/active-run.ts +22 -0
- package/cli/src/utils/activity-tracker.ts +66 -0
- package/cli/src/utils/agent-display.ts +87 -0
- package/cli/src/utils/agent-helpers.ts +47 -0
- package/cli/src/utils/ai-message-id.ts +12 -0
- package/cli/src/utils/analytics.ts +407 -0
- package/cli/src/utils/anonymous-id.ts +87 -0
- package/cli/src/utils/arrays.ts +117 -0
- package/cli/src/utils/auth.ts +258 -0
- package/cli/src/utils/bash-context-processor.ts +47 -0
- package/cli/src/utils/bash-messages.ts +108 -0
- package/cli/src/utils/block-margins.ts +35 -0
- package/cli/src/utils/block-operations.ts +548 -0
- package/cli/src/utils/block-processor.ts +212 -0
- package/cli/src/utils/chat-history.ts +265 -0
- package/cli/src/utils/chat-input-key-intercept.ts +52 -0
- package/cli/src/utils/chat-layout.ts +44 -0
- package/cli/src/utils/chat-meta.ts +101 -0
- package/cli/src/utils/chat-scroll-accel.ts +151 -0
- package/cli/src/utils/chatgpt-oauth.ts +350 -0
- package/cli/src/utils/clipboard-image.ts +610 -0
- package/cli/src/utils/clipboard.ts +307 -0
- package/cli/src/utils/code-search-summary.ts +69 -0
- package/cli/src/utils/collapse-helpers.ts +265 -0
- package/cli/src/utils/config-dir.ts +30 -0
- package/cli/src/utils/constants.ts +159 -0
- package/cli/src/utils/create-event-handler-state.ts +79 -0
- package/cli/src/utils/create-run-config.ts +160 -0
- package/cli/src/utils/db-storage.ts +254 -0
- package/cli/src/utils/detect-shell.ts +112 -0
- package/cli/src/utils/directory-browser.ts +74 -0
- package/cli/src/utils/engagement.ts +55 -0
- package/cli/src/utils/env.ts +109 -0
- package/cli/src/utils/error-handling.ts +246 -0
- package/cli/src/utils/error-messages.ts +84 -0
- package/cli/src/utils/feedback-helpers.ts +115 -0
- package/cli/src/utils/feedback-submission.ts +24 -0
- package/cli/src/utils/fetch-usage.ts +75 -0
- package/cli/src/utils/fid-loader.ts +135 -0
- package/cli/src/utils/fingerprint.ts +263 -0
- package/cli/src/utils/finish-logic.ts +154 -0
- package/cli/src/utils/format-elapsed-time.ts +33 -0
- package/cli/src/utils/format-session-units.ts +6 -0
- package/cli/src/utils/format-timeout.ts +28 -0
- package/cli/src/utils/format-validation-errors-for-message.ts +85 -0
- package/cli/src/utils/git.ts +17 -0
- package/cli/src/utils/glyphs.ts +188 -0
- package/cli/src/utils/helpers.ts +47 -0
- package/cli/src/utils/image-display.ts +73 -0
- package/cli/src/utils/image-handler.ts +336 -0
- package/cli/src/utils/image-processor.ts +133 -0
- package/cli/src/utils/image-thumbnail.ts +83 -0
- package/cli/src/utils/implementor-helpers.ts +817 -0
- package/cli/src/utils/input-modes.ts +196 -0
- package/cli/src/utils/keyboard-actions.ts +394 -0
- package/cli/src/utils/keypad-keys.ts +47 -0
- package/cli/src/utils/layout-helpers.ts +36 -0
- package/cli/src/utils/lazy-response-ads.ts +1 -0
- package/cli/src/utils/loading-phrases.ts +68 -0
- package/cli/src/utils/local-agent-registry.ts +611 -0
- package/cli/src/utils/log-shipper.ts +116 -0
- package/cli/src/utils/logger.ts +435 -0
- package/cli/src/utils/markdown-renderer.tsx +1315 -0
- package/cli/src/utils/math.ts +3 -0
- package/cli/src/utils/message-block-helpers.ts +667 -0
- package/cli/src/utils/message-history.ts +153 -0
- package/cli/src/utils/message-tree-utils.ts +67 -0
- package/cli/src/utils/message-updater.ts +279 -0
- package/cli/src/utils/ollama-onboarding.ts +215 -0
- package/cli/src/utils/open-file.ts +144 -0
- package/cli/src/utils/open-url.ts +63 -0
- package/cli/src/utils/openrouter-models.ts +945 -0
- package/cli/src/utils/path-completion.ts +111 -0
- package/cli/src/utils/path-helpers.ts +38 -0
- package/cli/src/utils/pending-attachments.ts +363 -0
- package/cli/src/utils/post-processing.ts +99 -0
- package/cli/src/utils/project-picker.ts +12 -0
- package/cli/src/utils/provider-setup.ts +259 -0
- package/cli/src/utils/recent-projects.ts +156 -0
- package/cli/src/utils/renderer-cleanup.ts +142 -0
- package/cli/src/utils/response-ad-positions.ts +1 -0
- package/cli/src/utils/rewind.ts +175 -0
- package/cli/src/utils/run-state-storage.ts +480 -0
- package/cli/src/utils/savant-code-api.ts +686 -0
- package/cli/src/utils/savant-code-client.ts +217 -0
- package/cli/src/utils/savant-free-agent-selection.ts +12 -0
- package/cli/src/utils/savant-free-exit.ts +24 -0
- package/cli/src/utils/savant-free-instance-owner.ts +66 -0
- package/cli/src/utils/savant-free-model-navigation.ts +46 -0
- package/cli/src/utils/savant-free-premium-reset.ts +52 -0
- package/cli/src/utils/savant-free-referral-cache.ts +35 -0
- package/cli/src/utils/savant-free-session-display.ts +21 -0
- package/cli/src/utils/savant-free-streak-line.ts +67 -0
- package/cli/src/utils/sdk-event-handlers.ts +587 -0
- package/cli/src/utils/send-message-helpers.ts +199 -0
- package/cli/src/utils/send-message-timer.ts +110 -0
- package/cli/src/utils/settings.ts +388 -0
- package/cli/src/utils/skill-registry.ts +100 -0
- package/cli/src/utils/spawn-agent-matcher.ts +56 -0
- package/cli/src/utils/status-indicator-state.ts +100 -0
- package/cli/src/utils/stream-chunk-processor.ts +65 -0
- package/cli/src/utils/strings.ts +272 -0
- package/cli/src/utils/subscription.ts +31 -0
- package/cli/src/utils/syntax-highlighter.tsx +19 -0
- package/cli/src/utils/syntax-theme.ts +131 -0
- package/cli/src/utils/terminal-color-detection.ts +472 -0
- package/cli/src/utils/terminal-enter-detection.ts +63 -0
- package/cli/src/utils/terminal-images.ts +223 -0
- package/cli/src/utils/terminal-reset-sequences.ts +33 -0
- package/cli/src/utils/terminal-title.ts +113 -0
- package/cli/src/utils/terminal-watchdog.ts +246 -0
- package/cli/src/utils/text-layout.ts +153 -0
- package/cli/src/utils/theme-config.ts +143 -0
- package/cli/src/utils/theme-system.ts +1265 -0
- package/cli/src/utils/think-tag-parser.ts +105 -0
- package/cli/src/utils/trace-writer.ts +147 -0
- package/cli/src/utils/ui-constants.ts +69 -0
- package/cli/src/utils/usage-banner-state.ts +146 -0
- package/cli/src/utils/validation-error-formatting.ts +92 -0
- package/cli/src/utils/validation-error-helpers.ts +19 -0
- package/cli/src/utils/version.ts +23 -0
- package/cli/src/utils/word-wrap-utils.ts +53 -0
- package/cli/src/utils/write-file-atomic.ts +82 -0
- package/cli/src/utils/yield-to-event-loop.ts +9 -0
- package/cli/tsconfig.json +26 -0
- package/coding-standards/csharp.md +77 -0
- package/coding-standards/go.md +71 -0
- package/coding-standards/java.md +74 -0
- package/coding-standards/python.md +82 -0
- package/coding-standards/rust.md +78 -0
- package/coding-standards/typescript.md +85 -0
- package/coding-standards/x402.md +227 -0
- package/common/README.md +41 -0
- package/common/common_exit +1 -0
- package/common/package.json +45 -0
- package/common/src/__tests__/agent-validation.test.ts +861 -0
- package/common/src/__tests__/agents.test.ts +16 -0
- package/common/src/__tests__/dynamic-agent-template-schema.test.ts +420 -0
- package/common/src/__tests__/env-ci.test.ts +167 -0
- package/common/src/__tests__/env-process.test.ts +145 -0
- package/common/src/__tests__/free-agents.test.ts +269 -0
- package/common/src/__tests__/handlesteps-parsing.test.ts +247 -0
- package/common/src/__tests__/model-config.test.ts +41 -0
- package/common/src/__tests__/project-file-tree.test.ts +82 -0
- package/common/src/__tests__/response-ad-positions.test.ts +78 -0
- package/common/src/__tests__/savant-free-models.test.ts +460 -0
- package/common/src/__tests__/savant-free-referral-tiers.test.ts +122 -0
- package/common/src/__tests__/user-state.test.ts +30 -0
- package/common/src/actions.ts +215 -0
- package/common/src/analytics-core.ts +73 -0
- package/common/src/analytics.ts +96 -0
- package/common/src/api-keys/constants.ts +26 -0
- package/common/src/browser-actions.ts +414 -0
- package/common/src/constants/agents.ts +250 -0
- package/common/src/constants/analytics-events.ts +318 -0
- package/common/src/constants/anthropic.ts +72 -0
- package/common/src/constants/byok.ts +2 -0
- package/common/src/constants/chatgpt-oauth.ts +85 -0
- package/common/src/constants/composio.ts +34 -0
- package/common/src/constants/feedback.ts +18 -0
- package/common/src/constants/free-agents.ts +347 -0
- package/common/src/constants/gemini.ts +6 -0
- package/common/src/constants/grant-priorities.ts +13 -0
- package/common/src/constants/hosts.ts +6 -0
- package/common/src/constants/images.ts +53 -0
- package/common/src/constants/index.ts +8 -0
- package/common/src/constants/knowledge.ts +46 -0
- package/common/src/constants/limits.ts +23 -0
- package/common/src/constants/model-config.ts +469 -0
- package/common/src/constants/paths.ts +69 -0
- package/common/src/constants/savant-code-config.ts +12 -0
- package/common/src/constants/savant-free-gemini-thinker.ts +30 -0
- package/common/src/constants/savant-free-models.ts +855 -0
- package/common/src/constants/savant-free-referral-tiers.ts +169 -0
- package/common/src/constants/skills.ts +60 -0
- package/common/src/constants/subscription-plans.ts +54 -0
- package/common/src/constants/ui.ts +25 -0
- package/common/src/env-ci.ts +36 -0
- package/common/src/env-process.ts +95 -0
- package/common/src/env-schema.ts +42 -0
- package/common/src/env.ts +69 -0
- package/common/src/mcp/client.ts +308 -0
- package/common/src/old-constants.ts +10 -0
- package/common/src/project-file-tree.ts +361 -0
- package/common/src/reddit-capi.ts +175 -0
- package/common/src/schemas/feedback.ts +57 -0
- package/common/src/schemas/logs.ts +66 -0
- package/common/src/templates/agent-validation.ts +436 -0
- package/common/src/templates/initial-agents-dir/LICENSE +202 -0
- package/common/src/templates/initial-agents-dir/README.md +314 -0
- package/common/src/templates/initial-agents-dir/examples/01-basic-diff-reviewer.ts +17 -0
- package/common/src/templates/initial-agents-dir/examples/02-intermediate-git-committer.ts +78 -0
- package/common/src/templates/initial-agents-dir/examples/03-advanced-file-explorer.ts +76 -0
- package/common/src/templates/initial-agents-dir/my-custom-agent.ts +40 -0
- package/common/src/templates/initial-agents-dir/package.json +6 -0
- package/common/src/templates/initial-agents-dir/skills/README.md +66 -0
- package/common/src/templates/initial-agents-dir/skills/example-skill/SKILL.md +29 -0
- package/common/src/templates/initial-agents-dir/types/agent-definition.ts +484 -0
- package/common/src/templates/initial-agents-dir/types/tools.ts +452 -0
- package/common/src/templates/initial-agents-dir/types/util-types.ts +167 -0
- package/common/src/testing/TESTING_PATTERNS.md +353 -0
- package/common/src/testing/errors.ts +33 -0
- package/common/src/testing/fixtures/agent-runtime.ts +325 -0
- package/common/src/testing/impl/agent-runtime.ts +6 -0
- package/common/src/testing/index.ts +84 -0
- package/common/src/testing/mock-modules.ts +54 -0
- package/common/src/testing/mock-types.ts +123 -0
- package/common/src/testing/mocks/analytics.ts +262 -0
- package/common/src/testing/mocks/child-process.ts +93 -0
- package/common/src/testing/mocks/crypto.ts +218 -0
- package/common/src/testing/mocks/database.ts +337 -0
- package/common/src/testing/mocks/filesystem.ts +166 -0
- package/common/src/testing/mocks/index.ts +83 -0
- package/common/src/testing/mocks/logger.ts +136 -0
- package/common/src/testing/mocks/stream.ts +314 -0
- package/common/src/testing/mocks/timers.ts +132 -0
- package/common/src/testing/mocks/tree-sitter.ts +127 -0
- package/common/src/testing/setup.ts +282 -0
- package/common/src/testing-env-ci.ts +15 -0
- package/common/src/testing-env-process.ts +78 -0
- package/common/src/tools/__tests__/compile-tool-definitions.test.ts +34 -0
- package/common/src/tools/__tests__/thought-session.test.ts +256 -0
- package/common/src/tools/compile-tool-definitions.ts +194 -0
- package/common/src/tools/constants.ts +132 -0
- package/common/src/tools/list.ts +193 -0
- package/common/src/tools/params/__tests__/coerce-to-array.test.ts +237 -0
- package/common/src/tools/params/__tests__/sequential-thinking-coercion.test.ts +98 -0
- package/common/src/tools/params/tool/add-message.ts +36 -0
- package/common/src/tools/params/tool/add-subgoal.ts +57 -0
- package/common/src/tools/params/tool/apply-patch.ts +110 -0
- package/common/src/tools/params/tool/ask-user.ts +181 -0
- package/common/src/tools/params/tool/browser-logs.ts +85 -0
- package/common/src/tools/params/tool/code-search.ts +144 -0
- package/common/src/tools/params/tool/composio.ts +131 -0
- package/common/src/tools/params/tool/create-plan.ts +80 -0
- package/common/src/tools/params/tool/end-turn.ts +54 -0
- package/common/src/tools/params/tool/find-files.ts +60 -0
- package/common/src/tools/params/tool/glob.ts +74 -0
- package/common/src/tools/params/tool/gravity-index.ts +92 -0
- package/common/src/tools/params/tool/list-directory.ts +58 -0
- package/common/src/tools/params/tool/lookup-agent-info.ts +37 -0
- package/common/src/tools/params/tool/propose-str-replace.ts +103 -0
- package/common/src/tools/params/tool/propose-write-file.ts +71 -0
- package/common/src/tools/params/tool/read-docs.ts +85 -0
- package/common/src/tools/params/tool/read-files.ts +61 -0
- package/common/src/tools/params/tool/read-subtree.ts +83 -0
- package/common/src/tools/params/tool/read-url.ts +81 -0
- package/common/src/tools/params/tool/render-ui.ts +203 -0
- package/common/src/tools/params/tool/run-file-change-hooks.ts +57 -0
- package/common/src/tools/params/tool/run-readonly-command.ts +76 -0
- package/common/src/tools/params/tool/run-terminal-command.ts +185 -0
- package/common/src/tools/params/tool/sequential-thinking.ts +110 -0
- package/common/src/tools/params/tool/set-messages.ts +42 -0
- package/common/src/tools/params/tool/set-output.ts +62 -0
- package/common/src/tools/params/tool/set-scaffold-complete.ts +51 -0
- package/common/src/tools/params/tool/skill.ts +56 -0
- package/common/src/tools/params/tool/spawn-agent-inline.ts +57 -0
- package/common/src/tools/params/tool/spawn-agents.ts +154 -0
- package/common/src/tools/params/tool/str-replace.ts +107 -0
- package/common/src/tools/params/tool/suggest-followups.ts +94 -0
- package/common/src/tools/params/tool/task-completed.ts +58 -0
- package/common/src/tools/params/tool/think-deeply.ts +53 -0
- package/common/src/tools/params/tool/transition-phase.ts +57 -0
- package/common/src/tools/params/tool/update-subgoal.ts +89 -0
- package/common/src/tools/params/tool/web-search.ts +73 -0
- package/common/src/tools/params/tool/write-file.ts +71 -0
- package/common/src/tools/params/tool/write-todos.ts +67 -0
- package/common/src/tools/params/utils.ts +152 -0
- package/common/src/tools/safety-registry.ts +274 -0
- package/common/src/tools/safety.ts +42 -0
- package/common/src/tools/sequential-thinking.ts +340 -0
- package/common/src/tools/utils.ts +25 -0
- package/common/src/types/__tests__/dynamic-agent-template.test.ts +20 -0
- package/common/src/types/agent-template.ts +223 -0
- package/common/src/types/api/agents/publish.ts +63 -0
- package/common/src/types/contracts/agent-runtime.ts +84 -0
- package/common/src/types/contracts/analytics.ts +12 -0
- package/common/src/types/contracts/bigquery.ts +55 -0
- package/common/src/types/contracts/billing.ts +46 -0
- package/common/src/types/contracts/client.ts +52 -0
- package/common/src/types/contracts/database.ts +104 -0
- package/common/src/types/contracts/env.ts +203 -0
- package/common/src/types/contracts/llm.ts +183 -0
- package/common/src/types/contracts/logger.ts +29 -0
- package/common/src/types/contracts/logs.ts +34 -0
- package/common/src/types/contracts/trace.ts +21 -0
- package/common/src/types/dynamic-agent-template.ts +290 -0
- package/common/src/types/filesystem.ts +10 -0
- package/common/src/types/function-params.ts +35 -0
- package/common/src/types/grant.ts +20 -0
- package/common/src/types/gravity-index.ts +170 -0
- package/common/src/types/json.ts +26 -0
- package/common/src/types/mcp.ts +26 -0
- package/common/src/types/messages/content-part.ts +59 -0
- package/common/src/types/messages/data-content.ts +14 -0
- package/common/src/types/messages/provider-metadata.ts +10 -0
- package/common/src/types/messages/savant-code-message.ts +55 -0
- package/common/src/types/organization.ts +118 -0
- package/common/src/types/print-mode.ts +167 -0
- package/common/src/types/publisher.ts +67 -0
- package/common/src/types/savant-free-session.ts +295 -0
- package/common/src/types/savant-free-streak.ts +6 -0
- package/common/src/types/session-state.ts +237 -0
- package/common/src/types/skill.ts +56 -0
- package/common/src/types/source.ts +11 -0
- package/common/src/types/spawn.ts +13 -0
- package/common/src/types/subscription.ts +68 -0
- package/common/src/types/usage.ts +16 -0
- package/common/src/types/util.ts +3 -0
- package/common/src/util/__tests__/analytics-dispatcher.test.ts +145 -0
- package/common/src/util/__tests__/analytics-log.test.ts +110 -0
- package/common/src/util/__tests__/analytics-sampling.test.ts +131 -0
- package/common/src/util/__tests__/axiom-only-log.test.ts +64 -0
- package/common/src/util/__tests__/engagement-tracker.test.ts +115 -0
- package/common/src/util/__tests__/error-abort.test.ts +822 -0
- package/common/src/util/__tests__/error-api-details.test.ts +190 -0
- package/common/src/util/__tests__/format-code-search.test.ts +60 -0
- package/common/src/util/__tests__/log-mirror.test.ts +31 -0
- package/common/src/util/__tests__/messages.test.ts +1118 -0
- package/common/src/util/__tests__/partial-json-delta.test.ts +505 -0
- package/common/src/util/__tests__/paths.test.ts +289 -0
- package/common/src/util/__tests__/promise.test.ts +334 -0
- package/common/src/util/__tests__/protocol-config.test.ts +119 -0
- package/common/src/util/__tests__/rate-limit.test.ts +28 -0
- package/common/src/util/__tests__/reddit-savant-free-retention.test.ts +120 -0
- package/common/src/util/__tests__/savant-free-streak.test.ts +142 -0
- package/common/src/util/__tests__/saxy.test.ts +1008 -0
- package/common/src/util/__tests__/string.test.ts +238 -0
- package/common/src/util/__tests__/zoned-time.test.ts +88 -0
- package/common/src/util/agent-file-utils.ts +110 -0
- package/common/src/util/agent-id-parsing.ts +147 -0
- package/common/src/util/agent-name-normalization.ts +39 -0
- package/common/src/util/analytics-dispatcher.ts +81 -0
- package/common/src/util/analytics-log.ts +84 -0
- package/common/src/util/analytics-sampling.ts +225 -0
- package/common/src/util/array.ts +63 -0
- package/common/src/util/axiom-only-log.ts +79 -0
- package/common/src/util/cache-debug.ts +191 -0
- package/common/src/util/credentials.ts +12 -0
- package/common/src/util/currency.ts +25 -0
- package/common/src/util/dates.ts +81 -0
- package/common/src/util/engagement-tracker.ts +133 -0
- package/common/src/util/error.ts +580 -0
- package/common/src/util/file.ts +363 -0
- package/common/src/util/format-code-search.ts +115 -0
- package/common/src/util/lazy-response-ads.ts +93 -0
- package/common/src/util/log-data.ts +57 -0
- package/common/src/util/log-mirror.ts +34 -0
- package/common/src/util/lru-cache.ts +67 -0
- package/common/src/util/messages.ts +600 -0
- package/common/src/util/model-utils.ts +25 -0
- package/common/src/util/object.ts +137 -0
- package/common/src/util/param-helpers.ts +49 -0
- package/common/src/util/partial-json-delta.ts +100 -0
- package/common/src/util/paths.ts +194 -0
- package/common/src/util/promise.ts +87 -0
- package/common/src/util/protocol-config.ts +141 -0
- package/common/src/util/random.ts +15 -0
- package/common/src/util/rate-limit.ts +56 -0
- package/common/src/util/reddit-capi-events.ts +40 -0
- package/common/src/util/reddit-savant-free-retention.ts +69 -0
- package/common/src/util/response-ad-positions.ts +54 -0
- package/common/src/util/savant-free-privacy.ts +78 -0
- package/common/src/util/savant-free-streak.ts +153 -0
- package/common/src/util/saxy.ts +739 -0
- package/common/src/util/skills.ts +32 -0
- package/common/src/util/stop-sequence.ts +60 -0
- package/common/src/util/string.ts +419 -0
- package/common/src/util/system-info.ts +51 -0
- package/common/src/util/type-narrowing.ts +125 -0
- package/common/src/util/xml.ts +17 -0
- package/common/src/util/zod-schema.ts +80 -0
- package/common/src/util/zoned-time.ts +136 -0
- package/common/src/utils/ask-user-bridge.ts +47 -0
- package/common/tsconfig.json +8 -0
- package/database.db +0 -0
- package/dev/LEARNINGS.md +309 -0
- 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 +238 -0
- package/dev/fids/archive/FID-2026-0803-001-echo-enforcement-layer-drift.md +404 -0
- package/dev/fids/archive/FID-2026-0803-002-llm-providers-database-audit.md +348 -0
- package/dev/fids/archive/FID-2026-0803-003-sdk-impl-common-util-audit.md +277 -0
- package/dev/fids/archive/FID-2026-0803-004-checkpoint-rewind.md +181 -0
- package/dev/fids/archive/FID-2026-0803-005-quality-scan-hygiene-fixes.md +265 -0
- package/dev/fids/archive/FID-2026-0803-006-code-map-audit-hygiene.md +243 -0
- package/dev/fids/archive/FID-2026-0803-007-evals-benchmark-audit-hygiene.md +296 -0
- package/dev/fids/archive/FID-2026-0803-009-echo-enforcement-doc-drift.md +112 -0
- package/dev/fids/archive/FID-2026-0803-010-database-llm-providers-low-fixes.md +255 -0
- package/dev/fids/archive/FID-2026-0803-011-build-artifact-hygiene.md +169 -0
- package/dev/fids/archive/FID-2026-0803-012-release-readiness-audit.md +162 -0
- package/dev/fids/archive/FID-2026-0803-013-agent-roster-over-reporting.md +146 -0
- package/dev/fids/archive/FID-2026-0803-014-freebuff-to-savant-rebrand-sweep.md +185 -0
- package/dev/nova/reports/2026-08-02-top-25-ai-inference-providers-competitive-intel.md +213 -0
- package/dev/nova/specs/echo-v0.1.2-freebuff.md +391 -0
- package/dev/nova/specs/goal-loop-feature-spec.md +245 -0
- package/dev/nova/specs/launch-strategy-research-prompt.md +88 -0
- package/dev/releases/README.md +50 -0
- package/dev/scratchpad/.gitkeep +0 -0
- package/dev/session-summaries/.gitkeep +0 -0
- package/dev/session-summaries/2026-07-16-1255.md +128 -0
- package/dev/session-summaries/2026-07-17-1000.md +64 -0
- package/dev/session-summaries/2026-07-19-eslint-zero-tolerance-cleanup.md +145 -0
- package/dev/session-summaries/2026-07-19-fid-026-debugging-and-rename.md +79 -0
- package/dev/session-summaries/2026-07-19-fid-026-phase-b-rebrand.md +76 -0
- package/dev/session-summaries/2026-07-19-fid-027-clean-break.md +47 -0
- package/dev/session-summaries/2026-07-19-pre-push-house-cleaning.md +100 -0
- package/dev/session-summaries/2026-07-19-v0.0.2-release-session.md +229 -0
- package/dev/session-summaries/2026-07-20-1805-fid-loop-closure.md +95 -0
- package/dev/session-summaries/2026-07-22-1800.md +52 -0
- package/dev/session-summaries/2026-07-23-fsm-optimization.md +88 -0
- package/dev/session-summaries/2026-07-25-0000.md +80 -0
- package/dev/session-summaries/2026-07-25-1200-context-compaction.md +154 -0
- package/dev/session-summaries/2026-07-25-1600-layer4-reactive-compact.md +96 -0
- package/dev/session-summaries/2026-07-25-1700-dev-folder-audit.md +161 -0
- package/dev/session-summaries/2026-07-25-2000-benchmark-v2-filters.md +147 -0
- package/dev/session-summaries/2026-07-25-2000.md +77 -0
- package/dev/session-summaries/2026-07-27-0000.md +63 -0
- package/dev/session-summaries/2026-07-28-history-capture-handoff.md +206 -0
- package/dev/session-summaries/2026-07-31-freebuff-echo-compliance-remediation.md +156 -0
- package/dev/session-summaries/2026-07-31-pre-launch-optimization-execution.md +46 -0
- package/dev/session-summaries/2026-0721-1800.md +44 -0
- package/dev/session-summaries/2026-08-01-sidebar-folded-startup.md +159 -0
- package/dev/session-summaries/2026-08-02-0.0.15-release-closeout.md +32 -0
- package/dev/session-summaries/2026-08-02-repository-hygiene.md +51 -0
- package/dev/session-summaries/2026-08-03-agent-roster-fix-and-ready-check-closeout.md +73 -0
- package/dev/session-summaries/2026-08-03-build-artifact-hygiene-closeout.md +40 -0
- package/dev/session-summaries/2026-08-03-code-map-audit-closeout.md +44 -0
- package/dev/session-summaries/2026-08-03-database-llm-providers-low-fixes-closeout.md +47 -0
- package/dev/session-summaries/2026-08-03-echo-enforcement-doc-drift-closeout.md +43 -0
- package/dev/session-summaries/2026-08-03-evals-benchmark-audit-closeout.md +50 -0
- package/dev/session-summaries/2026-08-03-quality-scan-hygiene-fixes-closeout.md +57 -0
- package/dev/session-summaries/2026-08-03-quality-session-checkpoint-rewind-closeout.md +56 -0
- package/dev/session-summaries/2026-08-03-release-readiness-audit-closeout.md +60 -0
- package/dev/test-prompts/archive/0.0.2-final-pass.md +209 -0
- package/dev/test-prompts/archive/agent-capabilities-full-test.md +361 -0
- package/dev/test-prompts/archive/agent-capabilities-test.md +471 -0
- package/dev/test-prompts/archive/comprehensive-az-system-test-v1.md +441 -0
- package/dev/test-prompts/archive/comprehensive-az-system-test-v2-report.md +377 -0
- package/dev/test-prompts/archive/comprehensive-az-system-test-v2.md +544 -0
- package/dev/test-prompts/archive/comprehensive-az-system-test.md +396 -0
- package/dev/test-prompts/archive/comprehensive-az-test-final.md +900 -0
- package/dev/test-prompts/archive/comprehensive-az-test-v11.md +141 -0
- package/dev/test-prompts/archive/comprehensive-az-test-v12.md +29 -0
- package/dev/test-prompts/archive/comprehensive-az-test-v6.md +631 -0
- package/dev/test-prompts/archive/comprehensive-az-test-v7.md +625 -0
- package/dev/test-prompts/archive/fid-007-ability-confirmation.md +248 -0
- package/dev/test-prompts/archive/fid-2026-0801-006-thinker-tool-call-boundary.md +86 -0
- package/dev/test-prompts/archive/fid-2026-0801-007-child-tool-set-fallback-cli.md +101 -0
- package/dev/test-prompts/archive/fid-2026-0801-008-provider-tool-call-accumulation-cli.md +111 -0
- package/dev/test-prompts/archive/fid-2026-0801-012-thinker-state-output-cli.md +134 -0
- package/dev/test-prompts/archive/gemini-deep-research-sidebar-highlight.md +598 -0
- package/dev/test-prompts/archive/goal-loop-cli-test.md +142 -0
- package/dev/test-prompts/archive/rebrand-qa.md +258 -0
- package/dev/test-prompts/archive/release-az-test-fid-085.md +306 -0
- package/dev/test-prompts/archive/release-az-test-fid-087.md +219 -0
- package/dev/test-prompts/archive/release-az-test-fid-2026-0726-001.md +270 -0
- package/dev/test-prompts/archive/release-az-test-fid-2026-0728-008.md +213 -0
- package/dev/test-prompts/archive/release-az-test-fid-2026-0728-launch-tracks.md +253 -0
- package/dev/test-prompts/archive/release-az-test-fid-2026-0731-pre-launch.md +102 -0
- package/docs/AI Coding Agents Market Research.md +516 -0
- package/docs/Agent Harness Feature Pairing Research.md +166 -0
- package/docs/CLI Agent Inference Backend Research.md +446 -0
- package/docs/Codebuff Rebranding And Migration Plan.md +418 -0
- package/docs/ECHO-EVOLUTION-ARCH.md +77 -0
- package/docs/Harness Engineering for Coding Agents Research.md +196 -0
- package/docs/Launch Plan Review and Optimization.md +178 -0
- package/docs/OpenTUI Sidebar Bug Fix.md +245 -0
- package/docs/SAVANT-VERSIONING.md +31 -0
- package/docs/Savant Code Launch Strategy.md +270 -0
- package/docs/Savant-Code Business And Backend Research.md +222 -0
- package/docs/agents-and-tools.md +217 -0
- package/docs/cloudflare-llms-full.md +9623 -0
- package/docs/design/OpenTUI Terminal Visualization Guide.md +471 -0
- package/docs/design/database-architecture.md +217 -0
- package/docs/design/deep-research-report.md +295 -0
- package/docs/design/thinker-sequentialthinking-regression-diagnostic.md +366 -0
- package/docs/discord-server-design.md +167 -0
- package/docs/gravity-integration-starter.md +202 -0
- package/docs/launch/hn-first-comment.md +44 -0
- package/docs/launch/hn-post.md +35 -0
- package/docs/launch/incident-response.md +88 -0
- package/docs/launch/landing/index.html +233 -0
- package/docs/launch/mastodon-thread.md +52 -0
- package/docs/launch/newsletter-pitch.md +49 -0
- package/docs/launch/twitter-thread.md +62 -0
- package/docs/privacy.md +186 -0
- package/docs/reports/Savant-Code Benchmark Specification.md +206 -0
- package/docs/reports/Thinker Agent Architecture Research.md +284 -0
- package/docs/reports/adoptable-features-2026-07-25.md +604 -0
- package/docs/reports/adoptable-features-master.md +480 -0
- package/docs/reports/codebuff-discord-feedback.md +43 -0
- package/docs/reports/feature-parity-report.md +810 -0
- package/docs/reports/repos/AionUi.md +75 -0
- package/docs/reports/repos/OpenHands.md +76 -0
- package/docs/reports/repos/SWE-agent.md +82 -0
- package/docs/reports/repos/agno.md +89 -0
- package/docs/reports/repos/aider.md +74 -0
- package/docs/reports/repos/cline.md +83 -0
- package/docs/reports/repos/codex.md +83 -0
- package/docs/reports/repos/gemini-cli.md +92 -0
- package/docs/reports/repos/goose.md +65 -0
- package/docs/reports/repos/gpt-pilot.md +52 -0
- package/docs/reports/repos/hermes-agent.md +101 -0
- package/docs/reports/repos/kilocode.md +79 -0
- package/docs/reports/repos/openclaude.md +99 -0
- package/docs/reports/repos/openclaw.md +100 -0
- package/docs/reports/repos/opencode-dev.md +78 -0
- package/docs/reports/repos/zero.md +123 -0
- package/docs/reports/savant-code-benchmark-v2-2026-08-03.md +76 -0
- package/docs/savant-code-modes.md +338 -0
- package/docs/testing.md +51 -0
- package/docs/visual-mockup-neon-slate.txt +41 -0
- package/eslint.config.js +211 -0
- package/evals/README.md +45 -0
- package/evals/benchmark/README.md +449 -0
- package/evals/benchmark/agent-runner.ts +217 -0
- package/evals/benchmark/analyze-task-scores.ts +496 -0
- package/evals/benchmark/eval-codebuff-hard.json +3343 -0
- package/evals/benchmark/eval-codebuff.json +3193 -0
- package/evals/benchmark/eval-codebuff2.json +2494 -0
- package/evals/benchmark/eval-manifold-hard.json +2525 -0
- package/evals/benchmark/eval-manifold.json +1675 -0
- package/evals/benchmark/eval-manifold2.json +1945 -0
- package/evals/benchmark/eval-plane-hard.json +4372 -0
- package/evals/benchmark/eval-plane.json +2028 -0
- package/evals/benchmark/eval-plane2.json +3517 -0
- package/evals/benchmark/eval-saleor-hard.json +6081 -0
- package/evals/benchmark/eval-saleor.json +1829 -0
- package/evals/benchmark/eval-saleor2.json +3273 -0
- package/evals/benchmark/eval-task-generator.ts +158 -0
- package/evals/benchmark/filter-supplemental-files.ts +225 -0
- package/evals/benchmark/format-output.ts +215 -0
- package/evals/benchmark/gen-evals.ts +294 -0
- package/evals/benchmark/gen-repo-eval.ts +71 -0
- package/evals/benchmark/judge.ts +308 -0
- package/evals/benchmark/lessons-extractor.ts +247 -0
- package/evals/benchmark/main-hard-tasks.ts +49 -0
- package/evals/benchmark/main-single-eval.ts +23 -0
- package/evals/benchmark/main.ts +29 -0
- package/evals/benchmark/meta-analyzer.ts +329 -0
- package/evals/benchmark/pick-commits.ts +627 -0
- package/evals/benchmark/run-benchmark.ts +657 -0
- package/evals/benchmark/runners/claude.ts +176 -0
- package/evals/benchmark/runners/codex.ts +143 -0
- package/evals/benchmark/runners/index.ts +4 -0
- package/evals/benchmark/runners/opencode.ts +253 -0
- package/evals/benchmark/runners/runner.ts +13 -0
- package/evals/benchmark/runners/savant.ts +148 -0
- package/evals/benchmark/setup-test-repo.ts +314 -0
- package/evals/benchmark/trace-analyzer.ts +257 -0
- package/evals/benchmark/trace-utils.ts +80 -0
- package/evals/benchmark/types.ts +83 -0
- package/evals/bunfig.toml +4 -0
- package/evals/logger.ts +87 -0
- package/evals/package.json +31 -0
- package/evals/subagents/test-repo-utils.ts +131 -0
- package/evals/tsconfig.json +13 -0
- package/evals/v2/README.md +149 -0
- package/evals/v2/reports/report.json +261 -0
- package/evals/v2/reports/report.md +15 -0
- package/evals/v2/schema/task.schema.json +172 -0
- package/evals/v2/src/cli.ts +216 -0
- package/evals/v2/src/golden.ts +73 -0
- package/evals/v2/src/harness.ts +293 -0
- package/evals/v2/src/metrics.ts +326 -0
- package/evals/v2/src/registry.ts +179 -0
- package/evals/v2/src/reports.ts +126 -0
- package/evals/v2/src/runner.ts +143 -0
- package/evals/v2/src/runners/savant.ts +105 -0
- package/evals/v2/src/sandbox.ts +42 -0
- package/evals/v2/src/sandboxes/docker.ts +49 -0
- package/evals/v2/src/sandboxes/tempdir.ts +120 -0
- package/evals/v2/src/schema.ts +83 -0
- package/evals/v2/src/trace.ts +186 -0
- package/evals/v2/src/verify.ts +199 -0
- package/evals/v2/tasks/error_recovery/env-fault/calculator.js +11 -0
- package/evals/v2/tasks/error_recovery/env-fault/calculator.test.js +15 -0
- package/evals/v2/tasks/error_recovery/env-fault/golden.patch +15 -0
- package/evals/v2/tasks/error_recovery/env-fault/task.yaml +20 -0
- package/evals/v2/tasks/multi_agent_orchestration/options-contract/app.js +5 -0
- package/evals/v2/tasks/multi_agent_orchestration/options-contract/app.test.js +7 -0
- package/evals/v2/tasks/multi_agent_orchestration/options-contract/golden.patch +19 -0
- package/evals/v2/tasks/multi_agent_orchestration/options-contract/greet.js +3 -0
- package/evals/v2/tasks/multi_agent_orchestration/options-contract/orchestration.test.js +30 -0
- package/evals/v2/tasks/multi_agent_orchestration/options-contract/task.yaml +29 -0
- package/evals/v2/tasks/pure_coding/add-fix/add.js +3 -0
- package/evals/v2/tasks/pure_coding/add-fix/add.test.js +11 -0
- package/evals/v2/tasks/pure_coding/add-fix/golden.patch +7 -0
- package/evals/v2/tasks/pure_coding/add-fix/task.yaml +20 -0
- package/evals/v2/tasks/pure_coding/rename-greet/app.js +5 -0
- package/evals/v2/tasks/pure_coding/rename-greet/app.test.js +32 -0
- package/evals/v2/tasks/pure_coding/rename-greet/golden.patch +19 -0
- package/evals/v2/tasks/pure_coding/rename-greet/greet.js +5 -0
- package/evals/v2/tasks/pure_coding/rename-greet/task.yaml +21 -0
- package/evals/v2/tests/golden.test.ts +104 -0
- package/evals/v2/tests/harness.test.ts +204 -0
- package/evals/v2/tests/metrics.test.ts +353 -0
- package/evals/v2/tests/registry.test.ts +210 -0
- package/evals/v2/tests/reports.test.ts +218 -0
- package/evals/v2/tests/savant-runner.test.ts +218 -0
- package/evals/v2/tests/schema.test.ts +127 -0
- package/evals/v2/tests/tempdir-sandbox.test.ts +49 -0
- package/evals/v2/tests/trace.test.ts +76 -0
- package/evals/v2/tests/verify.test.ts +224 -0
- package/license +202 -0
- package/package.json +71 -44
- package/packages/agent-runtime/README.md +46 -0
- package/packages/agent-runtime/agent_exit +1 -0
- package/packages/agent-runtime/bunfig.toml +2 -0
- package/packages/agent-runtime/package.json +34 -0
- package/packages/agent-runtime/src/__tests__/apply-patch-tool.test.ts +202 -0
- package/packages/agent-runtime/src/__tests__/cost-aggregation.test.ts +397 -0
- package/packages/agent-runtime/src/__tests__/generate-diffs-prompt.test.ts +107 -0
- package/packages/agent-runtime/src/__tests__/get-file-reading-updates.test.ts +59 -0
- package/packages/agent-runtime/src/__tests__/gravity-index-tool.test.ts +501 -0
- package/packages/agent-runtime/src/__tests__/loop-agent-steps.test.ts +1512 -0
- package/packages/agent-runtime/src/__tests__/main-prompt.test.ts +452 -0
- package/packages/agent-runtime/src/__tests__/n-parameter.test.ts +984 -0
- package/packages/agent-runtime/src/__tests__/process-file-block.test.ts +196 -0
- package/packages/agent-runtime/src/__tests__/process-str-replace.test.ts +512 -0
- package/packages/agent-runtime/src/__tests__/programmatic-tool-authorization.test.ts +219 -0
- package/packages/agent-runtime/src/__tests__/prompt-caching-subagents.test.ts +749 -0
- package/packages/agent-runtime/src/__tests__/prompts-schema-handling.test.ts +454 -0
- package/packages/agent-runtime/src/__tests__/propose-tools.test.ts +824 -0
- package/packages/agent-runtime/src/__tests__/read-docs-tool.test.ts +394 -0
- package/packages/agent-runtime/src/__tests__/run-agent-step-prefill.test.ts +161 -0
- package/packages/agent-runtime/src/__tests__/run-agent-step-tools.test.ts +612 -0
- package/packages/agent-runtime/src/__tests__/run-programmatic-step.test.ts +1743 -0
- package/packages/agent-runtime/src/__tests__/sandbox-generator.test.ts +154 -0
- package/packages/agent-runtime/src/__tests__/spawn-agents-image-content.test.ts +354 -0
- package/packages/agent-runtime/src/__tests__/spawn-agents-message-history.test.ts +280 -0
- package/packages/agent-runtime/src/__tests__/spawn-agents-permissions.test.ts +664 -0
- package/packages/agent-runtime/src/__tests__/stream-parser-abort.test.ts +250 -0
- package/packages/agent-runtime/src/__tests__/stream-parser-reasoning.test.ts +194 -0
- package/packages/agent-runtime/src/__tests__/subagent-streaming.test.ts +230 -0
- package/packages/agent-runtime/src/__tests__/test-utils.ts +96 -0
- package/packages/agent-runtime/src/__tests__/thinker-convergence-gate.test.ts +242 -0
- package/packages/agent-runtime/src/__tests__/to-token-count-input-schema.test.ts +81 -0
- package/packages/agent-runtime/src/__tests__/tool-executor-sandbox.test.ts +167 -0
- package/packages/agent-runtime/src/__tests__/tool-stream-parser.test.ts +682 -0
- package/packages/agent-runtime/src/__tests__/tool-validation-error.test.ts +1380 -0
- package/packages/agent-runtime/src/__tests__/web-search-tool.test.ts +402 -0
- package/packages/agent-runtime/src/__tests__/xml-tool-result-ordering.test.ts +264 -0
- package/packages/agent-runtime/src/constants.ts +12 -0
- package/packages/agent-runtime/src/context-compactor.ts +425 -0
- package/packages/agent-runtime/src/find-files/__tests__/request-files-prompt.test.ts +190 -0
- package/packages/agent-runtime/src/find-files/custom-file-picker-config.ts +61 -0
- package/packages/agent-runtime/src/find-files/request-files-prompt.ts +462 -0
- package/packages/agent-runtime/src/generate-diffs-prompt.ts +38 -0
- package/packages/agent-runtime/src/get-file-reading-updates.ts +27 -0
- package/packages/agent-runtime/src/llm-api/__tests__/gemini-with-fallbacks.test.ts +267 -0
- package/packages/agent-runtime/src/llm-api/__tests__/serper-api.test.ts +297 -0
- package/packages/agent-runtime/src/llm-api/claude.ts +7 -0
- package/packages/agent-runtime/src/llm-api/context7-api.ts +290 -0
- package/packages/agent-runtime/src/llm-api/gemini-with-fallbacks.ts +104 -0
- package/packages/agent-runtime/src/llm-api/savant-code-web-api.ts +370 -0
- package/packages/agent-runtime/src/llm-api/serper-api.ts +193 -0
- package/packages/agent-runtime/src/main-prompt.ts +251 -0
- package/packages/agent-runtime/src/mcp-constants.ts +12 -0
- package/packages/agent-runtime/src/mcp.ts +83 -0
- package/packages/agent-runtime/src/process-file-block.ts +118 -0
- package/packages/agent-runtime/src/process-str-replace.ts +213 -0
- package/packages/agent-runtime/src/prompt-agent-stream.ts +119 -0
- package/packages/agent-runtime/src/run-agent-step.ts +1632 -0
- package/packages/agent-runtime/src/run-programmatic-step.ts +633 -0
- package/packages/agent-runtime/src/system-prompt/prompts.ts +215 -0
- package/packages/agent-runtime/src/system-prompt/search-system-prompt.ts +89 -0
- package/packages/agent-runtime/src/system-prompt/truncate-file-tree.ts +414 -0
- package/packages/agent-runtime/src/templates/README.md +160 -0
- package/packages/agent-runtime/src/templates/__tests__/agent-registry.test.ts +489 -0
- package/packages/agent-runtime/src/templates/__tests__/strings.test.ts +465 -0
- package/packages/agent-runtime/src/templates/agent-registry.ts +122 -0
- package/packages/agent-runtime/src/templates/prompts.ts +189 -0
- package/packages/agent-runtime/src/templates/strings.ts +292 -0
- package/packages/agent-runtime/src/templates/types.ts +61 -0
- package/packages/agent-runtime/src/tool-stream-parser.ts +260 -0
- package/packages/agent-runtime/src/tools/filter-tool-set.ts +18 -0
- package/packages/agent-runtime/src/tools/handlers/__tests__/glob.test.ts +331 -0
- package/packages/agent-runtime/src/tools/handlers/__tests__/read-subtree.test.ts +346 -0
- package/packages/agent-runtime/src/tools/handlers/__tests__/run-readonly-command.test.ts +284 -0
- package/packages/agent-runtime/src/tools/handlers/handler-function-type.ts +77 -0
- package/packages/agent-runtime/src/tools/handlers/list.ts +105 -0
- package/packages/agent-runtime/src/tools/handlers/tool/__tests__/checkpoint-store.test.ts +394 -0
- package/packages/agent-runtime/src/tools/handlers/tool/__tests__/skill.test.ts +98 -0
- package/packages/agent-runtime/src/tools/handlers/tool/__tests__/write-file.test.ts +24 -0
- package/packages/agent-runtime/src/tools/handlers/tool/add-message.ts +37 -0
- package/packages/agent-runtime/src/tools/handlers/tool/add-subgoal.ts +30 -0
- package/packages/agent-runtime/src/tools/handlers/tool/apply-patch.ts +120 -0
- package/packages/agent-runtime/src/tools/handlers/tool/ask-user.ts +25 -0
- package/packages/agent-runtime/src/tools/handlers/tool/browser-logs.ts +21 -0
- package/packages/agent-runtime/src/tools/handlers/tool/checkpoint-store.ts +378 -0
- package/packages/agent-runtime/src/tools/handlers/tool/code-search.ts +21 -0
- package/packages/agent-runtime/src/tools/handlers/tool/composio.ts +52 -0
- package/packages/agent-runtime/src/tools/handlers/tool/create-plan.ts +63 -0
- package/packages/agent-runtime/src/tools/handlers/tool/end-turn.ts +15 -0
- package/packages/agent-runtime/src/tools/handlers/tool/find-files.ts +161 -0
- package/packages/agent-runtime/src/tools/handlers/tool/glob.ts +22 -0
- package/packages/agent-runtime/src/tools/handlers/tool/gravity-index.ts +230 -0
- package/packages/agent-runtime/src/tools/handlers/tool/list-directory.ts +22 -0
- package/packages/agent-runtime/src/tools/handlers/tool/lookup-agent-info.ts +105 -0
- package/packages/agent-runtime/src/tools/handlers/tool/propose-str-replace.ts +111 -0
- package/packages/agent-runtime/src/tools/handlers/tool/propose-write-file.ts +89 -0
- package/packages/agent-runtime/src/tools/handlers/tool/proposed-content-store.ts +64 -0
- package/packages/agent-runtime/src/tools/handlers/tool/read-docs.ts +160 -0
- package/packages/agent-runtime/src/tools/handlers/tool/read-files.ts +43 -0
- package/packages/agent-runtime/src/tools/handlers/tool/read-subtree.ts +198 -0
- package/packages/agent-runtime/src/tools/handlers/tool/read-url.ts +21 -0
- package/packages/agent-runtime/src/tools/handlers/tool/render-ui.ts +15 -0
- package/packages/agent-runtime/src/tools/handlers/tool/run-file-change-hooks.ts +20 -0
- package/packages/agent-runtime/src/tools/handlers/tool/run-readonly-command.ts +215 -0
- package/packages/agent-runtime/src/tools/handlers/tool/run-terminal-command.ts +33 -0
- package/packages/agent-runtime/src/tools/handlers/tool/sequential-thinking.ts +53 -0
- package/packages/agent-runtime/src/tools/handlers/tool/set-messages.ts +19 -0
- package/packages/agent-runtime/src/tools/handlers/tool/set-output.ts +104 -0
- package/packages/agent-runtime/src/tools/handlers/tool/set-scaffold-complete.ts +32 -0
- package/packages/agent-runtime/src/tools/handlers/tool/skill.ts +146 -0
- package/packages/agent-runtime/src/tools/handlers/tool/spawn-agent-inline.ts +149 -0
- package/packages/agent-runtime/src/tools/handlers/tool/spawn-agent-utils.ts +436 -0
- package/packages/agent-runtime/src/tools/handlers/tool/spawn-agents.ts +286 -0
- package/packages/agent-runtime/src/tools/handlers/tool/str-replace.ts +135 -0
- package/packages/agent-runtime/src/tools/handlers/tool/suggest-followups.ts +20 -0
- package/packages/agent-runtime/src/tools/handlers/tool/task-completed.ts +15 -0
- package/packages/agent-runtime/src/tools/handlers/tool/think-deeply.ts +25 -0
- package/packages/agent-runtime/src/tools/handlers/tool/transition-phase.ts +160 -0
- package/packages/agent-runtime/src/tools/handlers/tool/update-subgoal.ts +48 -0
- package/packages/agent-runtime/src/tools/handlers/tool/web-search.ts +151 -0
- package/packages/agent-runtime/src/tools/handlers/tool/write-file.ts +281 -0
- package/packages/agent-runtime/src/tools/handlers/tool/write-todos.ts +19 -0
- package/packages/agent-runtime/src/tools/prompts.ts +233 -0
- package/packages/agent-runtime/src/tools/sandbox/__tests__/engine.test.ts +169 -0
- package/packages/agent-runtime/src/tools/sandbox/__tests__/shell-denylist.test.ts +104 -0
- package/packages/agent-runtime/src/tools/sandbox/engine.ts +109 -0
- package/packages/agent-runtime/src/tools/sandbox/index.ts +14 -0
- package/packages/agent-runtime/src/tools/sandbox/shell-denylist.ts +119 -0
- package/packages/agent-runtime/src/tools/stream-parser.ts +407 -0
- package/packages/agent-runtime/src/tools/thinker-convergence-gate.ts +162 -0
- package/packages/agent-runtime/src/tools/thought-session-store.ts +43 -0
- package/packages/agent-runtime/src/tools/tool-executor.ts +1098 -0
- package/packages/agent-runtime/src/util/__tests__/messages.test.ts +995 -0
- package/packages/agent-runtime/src/util/__tests__/parse-tool-calls-from-text.test.ts +363 -0
- package/packages/agent-runtime/src/util/__tests__/simplify-tool-results.test.ts +382 -0
- package/packages/agent-runtime/src/util/__tests__/stream-xml-parser.test.ts +285 -0
- package/packages/agent-runtime/src/util/__tests__/think-tags.test.ts +49 -0
- package/packages/agent-runtime/src/util/__tests__/token-counter.test.ts +121 -0
- package/packages/agent-runtime/src/util/activity-tracking.ts +252 -0
- package/packages/agent-runtime/src/util/agent-output.ts +102 -0
- package/packages/agent-runtime/src/util/cache-debug.ts +330 -0
- package/packages/agent-runtime/src/util/format-value.ts +16 -0
- package/packages/agent-runtime/src/util/messages.ts +461 -0
- package/packages/agent-runtime/src/util/parse-tool-calls-from-text.ts +122 -0
- package/packages/agent-runtime/src/util/render-read-files-result.ts +18 -0
- package/packages/agent-runtime/src/util/simplify-tool-results.ts +61 -0
- package/packages/agent-runtime/src/util/stream-xml-parser.ts +259 -0
- package/packages/agent-runtime/src/util/think-tags.ts +33 -0
- package/packages/agent-runtime/src/util/token-counter.ts +136 -0
- package/packages/agent-runtime/tsconfig.json +8 -0
- package/packages/code-map/README.md +43 -0
- package/packages/code-map/__tests__/integration.test.ts +278 -0
- package/packages/code-map/__tests__/languages.test.ts +240 -0
- package/packages/code-map/__tests__/parse.test.ts +640 -0
- package/packages/code-map/__tests__/test-langs/test.c +42 -0
- package/packages/code-map/__tests__/test-langs/test.cpp +34 -0
- package/packages/code-map/__tests__/test-langs/test.cs +34 -0
- package/packages/code-map/__tests__/test-langs/test.go +27 -0
- package/packages/code-map/__tests__/test-langs/test.java +31 -0
- package/packages/code-map/__tests__/test-langs/test.js +50 -0
- package/packages/code-map/__tests__/test-langs/test.php +34 -0
- package/packages/code-map/__tests__/test-langs/test.py +25 -0
- package/packages/code-map/__tests__/test-langs/test.rb +28 -0
- package/packages/code-map/__tests__/test-langs/test.rs +28 -0
- package/packages/code-map/__tests__/test-langs/test.ts +31 -0
- package/packages/code-map/package.json +33 -0
- package/packages/code-map/src/index.ts +4 -0
- package/packages/code-map/src/init-node.ts +185 -0
- package/packages/code-map/src/languages.ts +344 -0
- package/packages/code-map/src/parse.ts +410 -0
- package/packages/code-map/src/tree-sitter-queries/readme.md +24 -0
- package/packages/code-map/src/tree-sitter-queries/tree-sitter-c-tags.scm +16 -0
- package/packages/code-map/src/tree-sitter-queries/tree-sitter-c_sharp-tags.scm +23 -0
- package/packages/code-map/src/tree-sitter-queries/tree-sitter-cpp-tags.scm +29 -0
- package/packages/code-map/src/tree-sitter-queries/tree-sitter-go-tags.scm +26 -0
- package/packages/code-map/src/tree-sitter-queries/tree-sitter-java-tags.scm +19 -0
- package/packages/code-map/src/tree-sitter-queries/tree-sitter-javascript-tags.scm +16 -0
- package/packages/code-map/src/tree-sitter-queries/tree-sitter-php-tags.scm +23 -0
- package/packages/code-map/src/tree-sitter-queries/tree-sitter-python-tags.scm +12 -0
- package/packages/code-map/src/tree-sitter-queries/tree-sitter-ruby-tags.scm +58 -0
- package/packages/code-map/src/tree-sitter-queries/tree-sitter-rust-tags.scm +26 -0
- package/packages/code-map/src/tree-sitter-queries/tree-sitter-typescript-tags.scm +22 -0
- package/packages/code-map/src/types.ts +11 -0
- package/packages/code-map/src/utils.ts +12 -0
- package/packages/code-map/tsconfig.json +10 -0
- package/packages/database/README.md +43 -0
- package/packages/database/package.json +28 -0
- package/packages/database/src/__tests__/service.test.ts +167 -0
- package/packages/database/src/index.ts +146 -0
- package/packages/database/src/service.ts +342 -0
- package/packages/database/tsconfig.json +9 -0
- package/packages/llm-providers/README.md +42 -0
- package/packages/llm-providers/package.json +42 -0
- package/packages/llm-providers/src/ollama/__tests__/detect.test.ts +59 -0
- package/packages/llm-providers/src/ollama/detect.ts +113 -0
- package/packages/llm-providers/src/ollama/index.ts +2 -0
- package/packages/llm-providers/src/openai-compatible/chat/convert-to-openai-compatible-chat-messages.test.ts +855 -0
- package/packages/llm-providers/src/openai-compatible/chat/convert-to-openai-compatible-chat-messages.ts +177 -0
- package/packages/llm-providers/src/openai-compatible/chat/get-response-metadata.ts +15 -0
- package/packages/llm-providers/src/openai-compatible/chat/map-openai-compatible-finish-reason.ts +19 -0
- package/packages/llm-providers/src/openai-compatible/chat/openai-compatible-api-types.ts +60 -0
- package/packages/llm-providers/src/openai-compatible/chat/openai-compatible-chat-language-model.test.ts +549 -0
- package/packages/llm-providers/src/openai-compatible/chat/openai-compatible-chat-language-model.ts +474 -0
- package/packages/llm-providers/src/openai-compatible/chat/openai-compatible-chat-options.ts +25 -0
- package/packages/llm-providers/src/openai-compatible/chat/openai-compatible-metadata-extractor.ts +49 -0
- package/packages/llm-providers/src/openai-compatible/chat/openai-compatible-prepare-tools.ts +162 -0
- package/packages/llm-providers/src/openai-compatible/chat/stream-transform.test.ts +106 -0
- package/packages/llm-providers/src/openai-compatible/chat/stream-transform.ts +585 -0
- package/packages/llm-providers/src/openai-compatible/completion/convert-to-openai-compatible-completion-prompt.ts +98 -0
- package/packages/llm-providers/src/openai-compatible/completion/openai-compatible-completion-language-model.test.ts +173 -0
- package/packages/llm-providers/src/openai-compatible/completion/openai-compatible-completion-language-model.ts +414 -0
- package/packages/llm-providers/src/openai-compatible/completion/openai-compatible-completion-options.ts +33 -0
- package/packages/llm-providers/src/openai-compatible/embedding/openai-compatible-embedding-model.ts +143 -0
- package/packages/llm-providers/src/openai-compatible/embedding/openai-compatible-embedding-options.ts +21 -0
- package/packages/llm-providers/src/openai-compatible/image/openai-compatible-image-model.ts +129 -0
- package/packages/llm-providers/src/openai-compatible/image/openai-compatible-image-settings.ts +1 -0
- package/packages/llm-providers/src/openai-compatible/index.ts +27 -0
- package/packages/llm-providers/src/openai-compatible/openai-compatible-error.ts +34 -0
- package/packages/llm-providers/src/openai-compatible/openai-compatible-provider.ts +174 -0
- package/packages/llm-providers/src/openai-compatible/version.ts +5 -0
- package/packages/llm-providers/tsconfig.json +9 -0
- package/protocol.config.yaml +113 -0
- package/savant-free/README.md +73 -0
- package/savant-free/SPEC.md +385 -0
- package/savant-free/cli/build.ts +49 -0
- package/savant-free/cli/release/README.md +55 -0
- package/savant-free/cli/release/index.js +37 -0
- package/savant-free/cli/release/package.json +43 -0
- package/savant-free/cli/release.ts +128 -0
- package/savant-free/cli/smoke-test.test.ts +257 -0
- package/savant-free/e2e/README.md +173 -0
- package/savant-free/e2e/agent/savant-free-tester.ts +52 -0
- package/savant-free/e2e/tests/ads-behavior.e2e.test.ts +51 -0
- package/savant-free/e2e/tests/agent-startup.e2e.test.ts +61 -0
- package/savant-free/e2e/tests/code-edit.e2e.test.ts +78 -0
- package/savant-free/e2e/tests/help-command.e2e.test.ts +97 -0
- package/savant-free/e2e/tests/knowledge-file.e2e.test.ts +66 -0
- package/savant-free/e2e/tests/slash-commands.e2e.test.ts +119 -0
- package/savant-free/e2e/tests/startup.e2e.test.ts +56 -0
- package/savant-free/e2e/tests/terminal-command.e2e.test.ts +71 -0
- package/savant-free/e2e/tests/version.e2e.test.ts +50 -0
- package/savant-free/e2e/utils/binary-helpers.ts +24 -0
- package/savant-free/e2e/utils/index.ts +17 -0
- package/savant-free/e2e/utils/savant-free-session.ts +229 -0
- package/savant-free/e2e/utils/tmux-custom-tools.ts +156 -0
- package/savant-free/e2e/utils/tmux-helpers.ts +79 -0
- package/savant-free/package.json +20 -0
- package/scripts/eslint-rules/__fixtures__/debug-ast.mjs +20 -0
- package/scripts/eslint-rules/__fixtures__/probe.mjs +41 -0
- package/scripts/eslint-rules/__fixtures__/probe2.mjs +43 -0
- package/scripts/eslint-rules/__fixtures__/rule-test.mjs +44 -0
- package/scripts/eslint-rules/__fixtures__/rule-test2.mjs +27 -0
- package/scripts/eslint-rules/__fixtures__/unknown-bad.ts +21 -0
- package/scripts/eslint-rules/__fixtures__/unknown-good.ts +35 -0
- package/scripts/eslint-rules/no-unknown-in-signatures.js +141 -0
- package/scripts/release.py +360 -0
- package/scripts/run-az-test.sh +1150 -0
- package/scripts/sync-agents.py +337 -0
- package/scripts/tmux/README.md +359 -0
- package/scripts/tmux/package.json +9 -0
- package/scripts/tmux/tmux-capture.sh +231 -0
- package/scripts/tmux/tmux-cli.sh +160 -0
- package/scripts/tmux/tmux-env.sh +34 -0
- package/scripts/tmux/tmux-send.sh +339 -0
- package/scripts/tmux/tmux-start.sh +264 -0
- package/scripts/tmux/tmux-stop.sh +157 -0
- package/scripts/tmux/tmux-viewer/README.md +254 -0
- package/scripts/tmux/tmux-viewer/components/session-viewer.tsx +556 -0
- package/scripts/tmux/tmux-viewer/components/theme.ts +54 -0
- package/scripts/tmux/tmux-viewer/gif-encoder-2.d.ts +28 -0
- package/scripts/tmux/tmux-viewer/gif-exporter.ts +278 -0
- package/scripts/tmux/tmux-viewer/index.tsx +237 -0
- package/scripts/tmux/tmux-viewer/package.json +9 -0
- package/scripts/tmux/tmux-viewer/session-loader.ts +234 -0
- package/scripts/tmux/tmux-viewer/tsconfig.json +9 -0
- package/scripts/tmux/tmux-viewer/types.ts +76 -0
- package/sdk/CHANGELOG.md +126 -0
- package/sdk/PUBLISHING.md +55 -0
- package/sdk/README.md +334 -0
- package/sdk/bunfig.toml +6 -0
- package/sdk/e2e/README.md +158 -0
- package/sdk/e2e/custom-agents/api-integration-agent.e2e.test.ts +145 -0
- package/sdk/e2e/custom-agents/apply-patch-tool.e2e.test.ts +62 -0
- package/sdk/e2e/custom-agents/database-query-agent.e2e.test.ts +135 -0
- package/sdk/e2e/custom-agents/weather-agent.e2e.test.ts +120 -0
- package/sdk/e2e/examples/code-explainer.example.ts +62 -0
- package/sdk/e2e/examples/code-reviewer.example.ts +52 -0
- package/sdk/e2e/examples/commit-message-generator.example.ts +61 -0
- package/sdk/e2e/examples/sdk-lint.example.ts +65 -0
- package/sdk/e2e/examples/sdk-refactor.example.ts +63 -0
- package/sdk/e2e/examples/sdk-test-gen.example.ts +62 -0
- package/sdk/e2e/features/knowledge-files.e2e.test.ts +82 -0
- package/sdk/e2e/features/max-agent-steps.e2e.test.ts +65 -0
- package/sdk/e2e/features/project-files.e2e.test.ts +80 -0
- package/sdk/e2e/integration/connection-check.integration.test.ts +33 -0
- package/sdk/e2e/integration/event-ordering.integration.test.ts +186 -0
- package/sdk/e2e/integration/event-types.integration.test.ts +183 -0
- package/sdk/e2e/integration/stream-chunks.integration.test.ts +191 -0
- package/sdk/e2e/streaming/concurrent-streams.e2e.test.ts +164 -0
- package/sdk/e2e/streaming/subagent-streaming.e2e.test.ts +158 -0
- package/sdk/e2e/utils/__tests__/event-collector.test.ts +297 -0
- package/sdk/e2e/utils/e2e-mocks.ts +458 -0
- package/sdk/e2e/utils/event-collector.ts +145 -0
- package/sdk/e2e/utils/get-api-key.ts +76 -0
- package/sdk/e2e/utils/index.ts +3 -0
- package/sdk/e2e/utils/test-fixtures.ts +196 -0
- package/sdk/e2e/workflows/error-recovery.e2e.test.ts +112 -0
- package/sdk/e2e/workflows/multi-turn-conversation.e2e.test.ts +132 -0
- package/sdk/examples/readme-example-1.ts +34 -0
- package/sdk/examples/readme-example-2.ts +76 -0
- package/sdk/package.json +82 -0
- package/sdk/scripts/build.ts +349 -0
- package/sdk/scripts/fetch-ripgrep.ts +172 -0
- package/sdk/scripts/publish.ts +51 -0
- package/sdk/scripts/release.js +100 -0
- package/sdk/scripts/verify.ts +204 -0
- package/sdk/sdk_exit +1 -0
- package/sdk/smoke-test-dist.ts +248 -0
- package/sdk/src/__tests__/apply-overrides-resume.test.ts +83 -0
- package/sdk/src/__tests__/apply-patch.test.ts +438 -0
- package/sdk/src/__tests__/build-file-tree.test.ts +31 -0
- package/sdk/src/__tests__/change-file.test.ts +212 -0
- package/sdk/src/__tests__/client.test.ts +142 -0
- package/sdk/src/__tests__/clone-session-state.test.ts +158 -0
- package/sdk/src/__tests__/code-search.test.ts +896 -0
- package/sdk/src/__tests__/composio.test.ts +86 -0
- package/sdk/src/__tests__/credentials.test.ts +344 -0
- package/sdk/src/__tests__/database.test.ts +153 -0
- package/sdk/src/__tests__/env.test.ts +137 -0
- package/sdk/src/__tests__/error-utils.test.ts +253 -0
- package/sdk/src/__tests__/fixtures/windows-stubborn-grandchild.ts +26 -0
- package/sdk/src/__tests__/initial-session-state.test.ts +447 -0
- package/sdk/src/__tests__/knowledge-file-selection.test.ts +335 -0
- package/sdk/src/__tests__/load-agents.test.ts +935 -0
- package/sdk/src/__tests__/load-mcp-config.test.ts +285 -0
- package/sdk/src/__tests__/load-skills.test.ts +325 -0
- package/sdk/src/__tests__/model-provider.test.ts +44 -0
- package/sdk/src/__tests__/path-utils.test.ts +66 -0
- package/sdk/src/__tests__/read-files.test.ts +573 -0
- package/sdk/src/__tests__/read-url.test.ts +371 -0
- package/sdk/src/__tests__/researcher-web.integration.test.ts +130 -0
- package/sdk/src/__tests__/run-cancellation.test.ts +1321 -0
- package/sdk/src/__tests__/run-error-preserves-history.test.ts +335 -0
- package/sdk/src/__tests__/run-event-dispatch.test.ts +80 -0
- package/sdk/src/__tests__/run-file-filter.test.ts +530 -0
- package/sdk/src/__tests__/run-handle-event.test.ts +142 -0
- package/sdk/src/__tests__/run-mcp-tool-filter.test.ts +124 -0
- package/sdk/src/__tests__/run-state-child-process.test.ts +72 -0
- package/sdk/src/__tests__/run-terminal-command.test.ts +236 -0
- package/sdk/src/__tests__/run.integration.test.ts +170 -0
- package/sdk/src/__tests__/user-knowledge-files.test.ts +361 -0
- package/sdk/src/__tests__/validate-agents.test.ts +943 -0
- package/sdk/src/agents/load-agents.ts +339 -0
- package/sdk/src/agents/load-mcp-config.ts +275 -0
- package/sdk/src/client.ts +87 -0
- package/sdk/src/composio.ts +78 -0
- package/sdk/src/constants.ts +29 -0
- package/sdk/src/credentials.ts +303 -0
- package/sdk/src/custom-tool.ts +66 -0
- package/sdk/src/env.ts +116 -0
- package/sdk/src/error-utils.ts +127 -0
- package/sdk/src/impl/__tests__/llm-chatgpt-oauth-policy.test.ts +67 -0
- package/sdk/src/impl/__tests__/llm-native-tool-call.test.ts +38 -0
- package/sdk/src/impl/__tests__/llm-stream-yielded-content.test.ts +118 -0
- package/sdk/src/impl/__tests__/model-provider-free-mode.test.ts +166 -0
- package/sdk/src/impl/__tests__/prompt-result.test.ts +210 -0
- package/sdk/src/impl/__tests__/provider-options-metadata.test.ts +67 -0
- package/sdk/src/impl/agent-runtime.ts +159 -0
- package/sdk/src/impl/chatgpt-backend-fetch.ts +588 -0
- package/sdk/src/impl/database.ts +516 -0
- package/sdk/src/impl/llm.ts +852 -0
- package/sdk/src/impl/model-provider.ts +638 -0
- package/sdk/src/impl/openrouter-key-resolver.ts +78 -0
- package/sdk/src/index.ts +133 -0
- package/sdk/src/native/ripgrep.ts +141 -0
- package/sdk/src/retry-config.ts +51 -0
- package/sdk/src/run-state.ts +897 -0
- package/sdk/src/run.ts +1222 -0
- package/sdk/src/skills/load-skills.ts +253 -0
- package/sdk/src/testing/env.ts +19 -0
- package/sdk/src/tools/apply-patch.ts +690 -0
- package/sdk/src/tools/change-file.ts +155 -0
- package/sdk/src/tools/code-search.ts +547 -0
- package/sdk/src/tools/glob.ts +58 -0
- package/sdk/src/tools/index.ts +19 -0
- package/sdk/src/tools/list-directory.ts +52 -0
- package/sdk/src/tools/path-utils.ts +101 -0
- package/sdk/src/tools/read-files.ts +110 -0
- package/sdk/src/tools/read-url.ts +469 -0
- package/sdk/src/tools/run-file-change-hooks.ts +22 -0
- package/sdk/src/tools/run-terminal-command.ts +483 -0
- package/sdk/src/tools/ssrf.ts +120 -0
- package/sdk/src/types/env.ts +40 -0
- package/sdk/src/utils/logger.ts +15 -0
- package/sdk/src/validate-agents.ts +157 -0
- package/sdk/test/cjs-compatibility/package-lock.json +423 -0
- package/sdk/test/cjs-compatibility/package.json +21 -0
- package/sdk/test/cjs-compatibility/test-imports.js +77 -0
- package/sdk/test/cjs-compatibility/test-types.ts +54 -0
- package/sdk/test/cjs-compatibility/tsconfig.json +17 -0
- package/sdk/test/esm-compatibility/package-lock.json +423 -0
- package/sdk/test/esm-compatibility/package.json +21 -0
- package/sdk/test/esm-compatibility/test-imports.js +83 -0
- package/sdk/test/esm-compatibility/test-types.ts +59 -0
- package/sdk/test/esm-compatibility/tsconfig.json +17 -0
- package/sdk/test/ripgrep-bundling/package-lock.json +423 -0
- package/sdk/test/ripgrep-bundling/package.json +21 -0
- package/sdk/test/ripgrep-bundling/test-ripgrep-types.ts +132 -0
- package/sdk/test/ripgrep-bundling/test-ripgrep.js +257 -0
- package/sdk/test/ripgrep-bundling/tsconfig.json +15 -0
- package/sdk/test/setup-env.ts +54 -0
- package/sdk/test/test-sdk.ts +25 -0
- package/sdk/test/tree-sitter-queries/package-lock.json +47 -0
- package/sdk/test/tree-sitter-queries/package.json +12 -0
- package/sdk/test/tree-sitter-queries/test-query-files.js +256 -0
- package/sdk/tsconfig.build.json +32 -0
- package/sdk/tsconfig.json +27 -0
- 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 +125 -0
- package/templates/README-TEMPLATE.md +87 -0
- package/templates/SESSION-SUMMARY.md +135 -0
- package/tsconfig.base.json +18 -0
- package/tsconfig.json +27 -0
- /package/{http.js → cli/release-core/http.js} +0 -0
- /package/{launcher.js → cli/release-core/launcher.js} +0 -0
|
@@ -0,0 +1,1851 @@
|
|
|
1
|
+
import { createPaymentRequiredError } from '@savant-code/sdk'
|
|
2
|
+
import { describe, expect, test, mock, beforeEach, afterEach } from 'bun:test'
|
|
3
|
+
|
|
4
|
+
import type { ChatMessage } from '../../../types/chat'
|
|
5
|
+
import type { SendMessageTimerController } from '../../../utils/send-message-timer'
|
|
6
|
+
import type { StreamStatus } from '../../use-message-queue'
|
|
7
|
+
import type { RunState } from '@savant-code/sdk'
|
|
8
|
+
|
|
9
|
+
// Ensure required env vars exist so logger/env parsing succeeds in tests
|
|
10
|
+
const ensureEnv = () => {
|
|
11
|
+
process.env.NEXT_PUBLIC_CB_ENVIRONMENT =
|
|
12
|
+
process.env.NEXT_PUBLIC_CB_ENVIRONMENT || 'test'
|
|
13
|
+
process.env.NEXT_PUBLIC_SAVANT_CODE_APP_URL =
|
|
14
|
+
process.env.NEXT_PUBLIC_SAVANT_CODE_APP_URL ||
|
|
15
|
+
'https://app.savant-code.test'
|
|
16
|
+
process.env.NEXT_PUBLIC_SUPPORT_EMAIL =
|
|
17
|
+
process.env.NEXT_PUBLIC_SUPPORT_EMAIL || 'support@savant-code.test'
|
|
18
|
+
process.env.NEXT_PUBLIC_POSTHOG_API_KEY =
|
|
19
|
+
process.env.NEXT_PUBLIC_POSTHOG_API_KEY || 'phc_test_key'
|
|
20
|
+
process.env.NEXT_PUBLIC_POSTHOG_HOST_URL =
|
|
21
|
+
process.env.NEXT_PUBLIC_POSTHOG_HOST_URL ||
|
|
22
|
+
'https://posthog.savant-code.test'
|
|
23
|
+
process.env.NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY =
|
|
24
|
+
process.env.NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY || 'pk_test_123'
|
|
25
|
+
process.env.NEXT_PUBLIC_STRIPE_CUSTOMER_PORTAL =
|
|
26
|
+
process.env.NEXT_PUBLIC_STRIPE_CUSTOMER_PORTAL ||
|
|
27
|
+
'https://stripe.savant-code.test'
|
|
28
|
+
process.env.NEXT_PUBLIC_WEB_PORT = process.env.NEXT_PUBLIC_WEB_PORT || '3000'
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
ensureEnv()
|
|
32
|
+
|
|
33
|
+
const { useChatStore } = await import('../../../state/chat-store')
|
|
34
|
+
const { createStreamController } = await import('../../stream-state')
|
|
35
|
+
const {
|
|
36
|
+
setupStreamingContext,
|
|
37
|
+
handleRunCompletion,
|
|
38
|
+
handleRunError,
|
|
39
|
+
finalizeQueueState,
|
|
40
|
+
resetEarlyReturnState,
|
|
41
|
+
} = await import('../send-message')
|
|
42
|
+
const { createBatchedMessageUpdater } =
|
|
43
|
+
await import('../../../utils/message-updater')
|
|
44
|
+
|
|
45
|
+
const createMockTimerController = (): SendMessageTimerController & {
|
|
46
|
+
startCalls: string[]
|
|
47
|
+
stopCalls: Array<'success' | 'error' | 'aborted'>
|
|
48
|
+
} => {
|
|
49
|
+
const startCalls: string[] = []
|
|
50
|
+
const stopCalls: Array<'success' | 'error' | 'aborted'> = []
|
|
51
|
+
|
|
52
|
+
return {
|
|
53
|
+
startCalls,
|
|
54
|
+
stopCalls,
|
|
55
|
+
start: (messageId: string) => {
|
|
56
|
+
startCalls.push(messageId)
|
|
57
|
+
},
|
|
58
|
+
stop: (outcome: 'success' | 'error' | 'aborted') => {
|
|
59
|
+
stopCalls.push(outcome)
|
|
60
|
+
return { finishedAt: Date.now(), elapsedMs: 100 }
|
|
61
|
+
},
|
|
62
|
+
pause: () => {},
|
|
63
|
+
resume: () => {},
|
|
64
|
+
isActive: () => startCalls.length > stopCalls.length,
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const createBaseMessages = (): ChatMessage[] => [
|
|
69
|
+
{
|
|
70
|
+
id: 'ai-1',
|
|
71
|
+
variant: 'ai',
|
|
72
|
+
content: 'Partial streamed content',
|
|
73
|
+
blocks: [{ type: 'text', content: 'Some text' }],
|
|
74
|
+
timestamp: 'now',
|
|
75
|
+
},
|
|
76
|
+
]
|
|
77
|
+
|
|
78
|
+
describe('setupStreamingContext', () => {
|
|
79
|
+
describe('abort flow', () => {
|
|
80
|
+
test('abort handler appends interruption notice, marks complete, and releases chain lock', () => {
|
|
81
|
+
let messages = createBaseMessages()
|
|
82
|
+
const streamRefs = createStreamController()
|
|
83
|
+
const timerController = createMockTimerController()
|
|
84
|
+
const abortControllerRef = { current: null as AbortController | null }
|
|
85
|
+
let _streamStatus: StreamStatus = 'idle'
|
|
86
|
+
let _canProcessQueue = false
|
|
87
|
+
let _chainInProgress = true
|
|
88
|
+
let isRetrying = true
|
|
89
|
+
|
|
90
|
+
const { updater, abortController } = setupStreamingContext({
|
|
91
|
+
aiMessageId: 'ai-1',
|
|
92
|
+
timerController,
|
|
93
|
+
setMessages: (fn: any) => {
|
|
94
|
+
messages = fn(messages)
|
|
95
|
+
},
|
|
96
|
+
streamRefs,
|
|
97
|
+
abortControllerRef,
|
|
98
|
+
setStreamStatus: (status: StreamStatus) => {
|
|
99
|
+
_streamStatus = status
|
|
100
|
+
},
|
|
101
|
+
setCanProcessQueue: (can: boolean) => {
|
|
102
|
+
_canProcessQueue = can
|
|
103
|
+
},
|
|
104
|
+
updateChainInProgress: (value: boolean) => {
|
|
105
|
+
_chainInProgress = value
|
|
106
|
+
},
|
|
107
|
+
setIsRetrying: (value: boolean) => {
|
|
108
|
+
isRetrying = value
|
|
109
|
+
},
|
|
110
|
+
setStreamingAgents: () => {},
|
|
111
|
+
})
|
|
112
|
+
|
|
113
|
+
// Trigger abort
|
|
114
|
+
abortController.abort()
|
|
115
|
+
|
|
116
|
+
// Verify wasAbortedByUser is set
|
|
117
|
+
expect(streamRefs.state.wasAbortedByUser).toBe(true)
|
|
118
|
+
|
|
119
|
+
// Verify stream status reset for UI feedback
|
|
120
|
+
expect(_streamStatus).toBe('idle')
|
|
121
|
+
|
|
122
|
+
// Chain lock is released immediately so new messages can be sent directly
|
|
123
|
+
expect(_chainInProgress).toBe(false)
|
|
124
|
+
expect(_canProcessQueue).toBe(true)
|
|
125
|
+
|
|
126
|
+
// Verify retrying reset
|
|
127
|
+
expect(isRetrying).toBe(false)
|
|
128
|
+
|
|
129
|
+
// Verify timer stopped with 'aborted' outcome
|
|
130
|
+
expect(timerController.stopCalls).toContain('aborted')
|
|
131
|
+
|
|
132
|
+
// Flush any pending updates to check interruption notice
|
|
133
|
+
updater.flush()
|
|
134
|
+
|
|
135
|
+
// Verify interruption notice appended (the message should have been updated)
|
|
136
|
+
const aiMessage = messages.find((m: ChatMessage) => m.id === 'ai-1')
|
|
137
|
+
expect(aiMessage).toBeDefined()
|
|
138
|
+
|
|
139
|
+
// The interruption notice should be added to blocks
|
|
140
|
+
const lastBlock = aiMessage!.blocks?.[aiMessage!.blocks.length - 1]
|
|
141
|
+
expect(lastBlock?.type).toBe('text')
|
|
142
|
+
const textBlock = lastBlock as { type: 'text'; content: string }
|
|
143
|
+
expect(textBlock?.content).toContain('[response interrupted]')
|
|
144
|
+
|
|
145
|
+
// Verify message marked complete
|
|
146
|
+
expect(aiMessage!.isComplete).toBe(true)
|
|
147
|
+
})
|
|
148
|
+
|
|
149
|
+
test('abort sets _canProcessQueue based on queue pause state', () => {
|
|
150
|
+
let messages = createBaseMessages()
|
|
151
|
+
const streamRefs = createStreamController()
|
|
152
|
+
const timerController = createMockTimerController()
|
|
153
|
+
const abortControllerRef = { current: null as AbortController | null }
|
|
154
|
+
const isQueuePausedRef = { current: true }
|
|
155
|
+
let _canProcessQueue = false
|
|
156
|
+
let _canProcessQueueCallCount = 0
|
|
157
|
+
|
|
158
|
+
const { abortController } = setupStreamingContext({
|
|
159
|
+
aiMessageId: 'ai-1',
|
|
160
|
+
timerController,
|
|
161
|
+
setMessages: (fn: any) => {
|
|
162
|
+
messages = fn(messages)
|
|
163
|
+
},
|
|
164
|
+
streamRefs,
|
|
165
|
+
abortControllerRef,
|
|
166
|
+
setStreamStatus: () => {},
|
|
167
|
+
setCanProcessQueue: (can: boolean) => {
|
|
168
|
+
_canProcessQueue = can
|
|
169
|
+
_canProcessQueueCallCount++
|
|
170
|
+
},
|
|
171
|
+
isQueuePausedRef,
|
|
172
|
+
updateChainInProgress: () => {},
|
|
173
|
+
setIsRetrying: () => {},
|
|
174
|
+
setStreamingAgents: () => {},
|
|
175
|
+
})
|
|
176
|
+
|
|
177
|
+
// Trigger abort
|
|
178
|
+
abortController.abort()
|
|
179
|
+
|
|
180
|
+
// Abort handler sets _canProcessQueue respecting queue pause state
|
|
181
|
+
expect(_canProcessQueueCallCount).toBe(1)
|
|
182
|
+
// Queue was paused, so _canProcessQueue stays false
|
|
183
|
+
expect(_canProcessQueue).toBe(false)
|
|
184
|
+
})
|
|
185
|
+
|
|
186
|
+
test('abort resets isProcessingQueueRef', () => {
|
|
187
|
+
let messages = createBaseMessages()
|
|
188
|
+
const streamRefs = createStreamController()
|
|
189
|
+
const timerController = createMockTimerController()
|
|
190
|
+
const abortControllerRef = { current: null as AbortController | null }
|
|
191
|
+
const isProcessingQueueRef = { current: true }
|
|
192
|
+
|
|
193
|
+
const { abortController } = setupStreamingContext({
|
|
194
|
+
aiMessageId: 'ai-1',
|
|
195
|
+
timerController,
|
|
196
|
+
setMessages: (fn: any) => {
|
|
197
|
+
messages = fn(messages)
|
|
198
|
+
},
|
|
199
|
+
streamRefs,
|
|
200
|
+
abortControllerRef,
|
|
201
|
+
setStreamStatus: () => {},
|
|
202
|
+
setCanProcessQueue: () => {},
|
|
203
|
+
isProcessingQueueRef,
|
|
204
|
+
updateChainInProgress: () => {},
|
|
205
|
+
setIsRetrying: () => {},
|
|
206
|
+
setStreamingAgents: () => {},
|
|
207
|
+
})
|
|
208
|
+
|
|
209
|
+
// Verify ref starts as true
|
|
210
|
+
expect(isProcessingQueueRef.current).toBe(true)
|
|
211
|
+
|
|
212
|
+
// Trigger abort
|
|
213
|
+
abortController.abort()
|
|
214
|
+
|
|
215
|
+
// isProcessingQueueRef is reset by abort handler so new messages can be sent
|
|
216
|
+
expect(isProcessingQueueRef.current).toBe(false)
|
|
217
|
+
})
|
|
218
|
+
|
|
219
|
+
test('abort releases chain lock and processing state, respects queue pause', () => {
|
|
220
|
+
let messages = createBaseMessages()
|
|
221
|
+
const streamRefs = createStreamController()
|
|
222
|
+
const timerController = createMockTimerController()
|
|
223
|
+
const abortControllerRef = { current: null as AbortController | null }
|
|
224
|
+
const isProcessingQueueRef = { current: true }
|
|
225
|
+
const isQueuePausedRef = { current: true }
|
|
226
|
+
let _streamStatus = 'streaming' as StreamStatus
|
|
227
|
+
let _canProcessQueue = true
|
|
228
|
+
let _chainInProgress = true
|
|
229
|
+
let isRetrying = true
|
|
230
|
+
|
|
231
|
+
const { abortController } = setupStreamingContext({
|
|
232
|
+
aiMessageId: 'ai-1',
|
|
233
|
+
timerController,
|
|
234
|
+
setMessages: (fn: any) => {
|
|
235
|
+
messages = fn(messages)
|
|
236
|
+
},
|
|
237
|
+
streamRefs,
|
|
238
|
+
abortControllerRef,
|
|
239
|
+
setStreamStatus: (status) => {
|
|
240
|
+
_streamStatus = status
|
|
241
|
+
},
|
|
242
|
+
setCanProcessQueue: (can) => {
|
|
243
|
+
_canProcessQueue = can
|
|
244
|
+
},
|
|
245
|
+
isQueuePausedRef,
|
|
246
|
+
isProcessingQueueRef,
|
|
247
|
+
updateChainInProgress: (value) => {
|
|
248
|
+
_chainInProgress = value
|
|
249
|
+
},
|
|
250
|
+
setIsRetrying: (value) => {
|
|
251
|
+
isRetrying = value
|
|
252
|
+
},
|
|
253
|
+
setStreamingAgents: () => {},
|
|
254
|
+
})
|
|
255
|
+
|
|
256
|
+
// Sanity check initial state
|
|
257
|
+
expect(isProcessingQueueRef.current).toBe(true)
|
|
258
|
+
expect(isQueuePausedRef.current).toBe(true)
|
|
259
|
+
expect(_streamStatus).toBe('streaming')
|
|
260
|
+
expect(_canProcessQueue).toBe(true)
|
|
261
|
+
expect(_chainInProgress).toBe(true)
|
|
262
|
+
expect(isRetrying).toBe(true)
|
|
263
|
+
|
|
264
|
+
// Trigger abort
|
|
265
|
+
abortController.abort()
|
|
266
|
+
|
|
267
|
+
// After abort, chain lock and processing lock are released immediately
|
|
268
|
+
// so new messages can be sent directly instead of being queued.
|
|
269
|
+
expect(isProcessingQueueRef.current).toBe(false)
|
|
270
|
+
expect(_canProcessQueue).toBe(false) // Respects isQueuePausedRef (true)
|
|
271
|
+
expect(_chainInProgress).toBe(false) // Released immediately
|
|
272
|
+
expect(isRetrying).toBe(false)
|
|
273
|
+
expect(_streamStatus).toBe('idle')
|
|
274
|
+
})
|
|
275
|
+
|
|
276
|
+
test('abort handler stores abortController in ref', () => {
|
|
277
|
+
let messages = createBaseMessages()
|
|
278
|
+
const streamRefs = createStreamController()
|
|
279
|
+
const timerController = createMockTimerController()
|
|
280
|
+
const abortControllerRef = { current: null as AbortController | null }
|
|
281
|
+
|
|
282
|
+
const { abortController } = setupStreamingContext({
|
|
283
|
+
aiMessageId: 'ai-1',
|
|
284
|
+
timerController,
|
|
285
|
+
setMessages: (fn: any) => {
|
|
286
|
+
messages = fn(messages)
|
|
287
|
+
},
|
|
288
|
+
streamRefs,
|
|
289
|
+
abortControllerRef,
|
|
290
|
+
setStreamStatus: () => {},
|
|
291
|
+
setCanProcessQueue: () => {},
|
|
292
|
+
updateChainInProgress: () => {},
|
|
293
|
+
setIsRetrying: () => {},
|
|
294
|
+
setStreamingAgents: () => {},
|
|
295
|
+
})
|
|
296
|
+
|
|
297
|
+
// Verify abortController is stored in ref
|
|
298
|
+
expect(abortControllerRef.current).toBe(abortController)
|
|
299
|
+
})
|
|
300
|
+
|
|
301
|
+
test('setupStreamingContext resets streamRefs and starts timer', () => {
|
|
302
|
+
let messages = createBaseMessages()
|
|
303
|
+
const streamRefs = createStreamController()
|
|
304
|
+
// Pre-populate some state
|
|
305
|
+
streamRefs.state.rootStreamBuffer = 'some old content'
|
|
306
|
+
streamRefs.state.rootStreamSeen = true
|
|
307
|
+
|
|
308
|
+
const timerController = createMockTimerController()
|
|
309
|
+
const abortControllerRef = { current: null as AbortController | null }
|
|
310
|
+
|
|
311
|
+
setupStreamingContext({
|
|
312
|
+
aiMessageId: 'ai-1',
|
|
313
|
+
timerController,
|
|
314
|
+
setMessages: (fn: any) => {
|
|
315
|
+
messages = fn(messages)
|
|
316
|
+
},
|
|
317
|
+
streamRefs,
|
|
318
|
+
abortControllerRef,
|
|
319
|
+
setStreamStatus: () => {},
|
|
320
|
+
setCanProcessQueue: () => {},
|
|
321
|
+
updateChainInProgress: () => {},
|
|
322
|
+
setIsRetrying: () => {},
|
|
323
|
+
setStreamingAgents: () => {},
|
|
324
|
+
})
|
|
325
|
+
|
|
326
|
+
// Verify streamRefs was reset
|
|
327
|
+
expect(streamRefs.state.rootStreamBuffer).toBe('')
|
|
328
|
+
expect(streamRefs.state.rootStreamSeen).toBe(false)
|
|
329
|
+
|
|
330
|
+
// Verify timer was started with correct message ID
|
|
331
|
+
expect(timerController.startCalls).toContain('ai-1')
|
|
332
|
+
})
|
|
333
|
+
})
|
|
334
|
+
})
|
|
335
|
+
|
|
336
|
+
describe('handleRunCompletion', () => {
|
|
337
|
+
describe('abort path', () => {
|
|
338
|
+
test('skips finalizeQueueState when wasAbortedByUser is true (abort handler already released locks)', () => {
|
|
339
|
+
const timerController = createMockTimerController()
|
|
340
|
+
let messages = createBaseMessages()
|
|
341
|
+
const updater = createBatchedMessageUpdater('ai-1', (fn: any) => {
|
|
342
|
+
messages = fn(messages)
|
|
343
|
+
})
|
|
344
|
+
|
|
345
|
+
// These simulate state that was already cleaned up by the abort handler
|
|
346
|
+
let _streamStatus: StreamStatus = 'idle'
|
|
347
|
+
let _canProcessQueue = true
|
|
348
|
+
let _chainInProgress = false
|
|
349
|
+
const isProcessingQueueRef = { current: false }
|
|
350
|
+
const isQueuePausedRef = { current: false }
|
|
351
|
+
let _hasReceivedPlanResponse = false
|
|
352
|
+
|
|
353
|
+
// Track if setters are called (they shouldn't be)
|
|
354
|
+
let setStreamStatusCalled = false
|
|
355
|
+
let setCanProcessQueueCalled = false
|
|
356
|
+
let updateChainInProgressCalled = false
|
|
357
|
+
|
|
358
|
+
const runState = {
|
|
359
|
+
traceSessionId: 'trace-test',
|
|
360
|
+
sessionState: undefined,
|
|
361
|
+
output: { type: 'lastMessage' as const, value: [] },
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
handleRunCompletion({
|
|
365
|
+
runState,
|
|
366
|
+
actualCredits: undefined,
|
|
367
|
+
agentMode: 'EDIT',
|
|
368
|
+
timerController,
|
|
369
|
+
updater,
|
|
370
|
+
aiMessageId: 'ai-1',
|
|
371
|
+
wasAbortedByUser: true,
|
|
372
|
+
setStreamStatus: (status: StreamStatus) => {
|
|
373
|
+
setStreamStatusCalled = true
|
|
374
|
+
_streamStatus = status
|
|
375
|
+
},
|
|
376
|
+
setCanProcessQueue: (can: boolean) => {
|
|
377
|
+
setCanProcessQueueCalled = true
|
|
378
|
+
_canProcessQueue = can
|
|
379
|
+
},
|
|
380
|
+
updateChainInProgress: (value: boolean) => {
|
|
381
|
+
updateChainInProgressCalled = true
|
|
382
|
+
_chainInProgress = value
|
|
383
|
+
},
|
|
384
|
+
setHasReceivedPlanResponse: (value: boolean) => {
|
|
385
|
+
_hasReceivedPlanResponse = value
|
|
386
|
+
},
|
|
387
|
+
isProcessingQueueRef,
|
|
388
|
+
isQueuePausedRef,
|
|
389
|
+
})
|
|
390
|
+
|
|
391
|
+
// handleRunCompletion should NOT call finalizeQueueState for aborted runs
|
|
392
|
+
// (the abort handler already released the locks)
|
|
393
|
+
expect(setStreamStatusCalled).toBe(false)
|
|
394
|
+
expect(setCanProcessQueueCalled).toBe(false)
|
|
395
|
+
expect(updateChainInProgressCalled).toBe(false)
|
|
396
|
+
})
|
|
397
|
+
|
|
398
|
+
test('does not process server response when wasAbortedByUser is true', () => {
|
|
399
|
+
const timerController = createMockTimerController()
|
|
400
|
+
let messages = createBaseMessages()
|
|
401
|
+
const updater = createBatchedMessageUpdater('ai-1', (fn: any) => {
|
|
402
|
+
messages = fn(messages)
|
|
403
|
+
})
|
|
404
|
+
|
|
405
|
+
let _hasReceivedPlanResponse = false
|
|
406
|
+
|
|
407
|
+
const runState = {
|
|
408
|
+
traceSessionId: 'trace-test',
|
|
409
|
+
sessionState: undefined,
|
|
410
|
+
output: {
|
|
411
|
+
type: 'lastMessage' as const,
|
|
412
|
+
value: [
|
|
413
|
+
{
|
|
414
|
+
role: 'assistant' as const,
|
|
415
|
+
content: [
|
|
416
|
+
{
|
|
417
|
+
type: 'text' as const,
|
|
418
|
+
text: 'Server response that should be ignored',
|
|
419
|
+
},
|
|
420
|
+
],
|
|
421
|
+
},
|
|
422
|
+
],
|
|
423
|
+
},
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
handleRunCompletion({
|
|
427
|
+
runState,
|
|
428
|
+
actualCredits: 42,
|
|
429
|
+
agentMode: 'SCAFFOLD',
|
|
430
|
+
timerController,
|
|
431
|
+
updater,
|
|
432
|
+
aiMessageId: 'ai-1',
|
|
433
|
+
wasAbortedByUser: true,
|
|
434
|
+
setStreamStatus: () => {},
|
|
435
|
+
setCanProcessQueue: () => {},
|
|
436
|
+
updateChainInProgress: () => {},
|
|
437
|
+
setHasReceivedPlanResponse: (value: boolean) => {
|
|
438
|
+
_hasReceivedPlanResponse = value
|
|
439
|
+
},
|
|
440
|
+
})
|
|
441
|
+
|
|
442
|
+
// Should NOT set plan response (abort path returns early before processing output)
|
|
443
|
+
expect(_hasReceivedPlanResponse).toBe(false)
|
|
444
|
+
|
|
445
|
+
// Timer should NOT be stopped by handleRunCompletion (abort handler already stopped it)
|
|
446
|
+
expect(timerController.stopCalls).not.toContain('success')
|
|
447
|
+
expect(timerController.stopCalls).not.toContain('error')
|
|
448
|
+
})
|
|
449
|
+
|
|
450
|
+
test('does not call resumeQueue in abort path (abort handler already released locks)', () => {
|
|
451
|
+
const timerController = createMockTimerController()
|
|
452
|
+
let messages = createBaseMessages()
|
|
453
|
+
const updater = createBatchedMessageUpdater('ai-1', (fn: any) => {
|
|
454
|
+
messages = fn(messages)
|
|
455
|
+
})
|
|
456
|
+
|
|
457
|
+
let resumeQueueCalled = false
|
|
458
|
+
let _canProcessQueueCalled = false
|
|
459
|
+
|
|
460
|
+
const runState = {
|
|
461
|
+
traceSessionId: 'trace-test',
|
|
462
|
+
sessionState: undefined,
|
|
463
|
+
output: { type: 'lastMessage' as const, value: [] },
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
handleRunCompletion({
|
|
467
|
+
runState,
|
|
468
|
+
actualCredits: undefined,
|
|
469
|
+
agentMode: 'EDIT',
|
|
470
|
+
timerController,
|
|
471
|
+
updater,
|
|
472
|
+
aiMessageId: 'ai-1',
|
|
473
|
+
wasAbortedByUser: true,
|
|
474
|
+
setStreamStatus: () => {},
|
|
475
|
+
setCanProcessQueue: () => {
|
|
476
|
+
_canProcessQueueCalled = true
|
|
477
|
+
},
|
|
478
|
+
updateChainInProgress: () => {},
|
|
479
|
+
setHasReceivedPlanResponse: () => {},
|
|
480
|
+
resumeQueue: () => {
|
|
481
|
+
resumeQueueCalled = true
|
|
482
|
+
},
|
|
483
|
+
})
|
|
484
|
+
|
|
485
|
+
// Neither should be called - abort handler already handled cleanup
|
|
486
|
+
expect(resumeQueueCalled).toBe(false)
|
|
487
|
+
expect(_canProcessQueueCalled).toBe(false)
|
|
488
|
+
})
|
|
489
|
+
})
|
|
490
|
+
})
|
|
491
|
+
|
|
492
|
+
describe('finalizeQueueState', () => {
|
|
493
|
+
test('sets stream status to idle and resets queue state', () => {
|
|
494
|
+
let _streamStatus = 'streaming' as StreamStatus
|
|
495
|
+
let _canProcessQueue = false
|
|
496
|
+
let _chainInProgress = true
|
|
497
|
+
const isProcessingQueueRef = { current: true }
|
|
498
|
+
|
|
499
|
+
finalizeQueueState({
|
|
500
|
+
setStreamStatus: (status) => {
|
|
501
|
+
_streamStatus = status
|
|
502
|
+
},
|
|
503
|
+
setCanProcessQueue: (can) => {
|
|
504
|
+
_canProcessQueue = can
|
|
505
|
+
},
|
|
506
|
+
updateChainInProgress: (value) => {
|
|
507
|
+
_chainInProgress = value
|
|
508
|
+
},
|
|
509
|
+
isProcessingQueueRef,
|
|
510
|
+
})
|
|
511
|
+
|
|
512
|
+
expect(_streamStatus).toBe('idle')
|
|
513
|
+
expect(_canProcessQueue).toBe(true)
|
|
514
|
+
expect(_chainInProgress).toBe(false)
|
|
515
|
+
expect(isProcessingQueueRef.current).toBe(false)
|
|
516
|
+
})
|
|
517
|
+
|
|
518
|
+
test('calls resumeQueue instead of setCanProcessQueue when provided', () => {
|
|
519
|
+
let _streamStatus = 'streaming' as StreamStatus
|
|
520
|
+
let _canProcessQueueCalled = false
|
|
521
|
+
let resumeQueueCalled = false
|
|
522
|
+
let _chainInProgress = true
|
|
523
|
+
|
|
524
|
+
finalizeQueueState({
|
|
525
|
+
setStreamStatus: (status) => {
|
|
526
|
+
_streamStatus = status
|
|
527
|
+
},
|
|
528
|
+
setCanProcessQueue: () => {
|
|
529
|
+
_canProcessQueueCalled = true
|
|
530
|
+
},
|
|
531
|
+
updateChainInProgress: (value) => {
|
|
532
|
+
_chainInProgress = value
|
|
533
|
+
},
|
|
534
|
+
resumeQueue: () => {
|
|
535
|
+
resumeQueueCalled = true
|
|
536
|
+
},
|
|
537
|
+
})
|
|
538
|
+
|
|
539
|
+
expect(_streamStatus).toBe('idle')
|
|
540
|
+
expect(resumeQueueCalled).toBe(true)
|
|
541
|
+
expect(_canProcessQueueCalled).toBe(false)
|
|
542
|
+
expect(_chainInProgress).toBe(false)
|
|
543
|
+
})
|
|
544
|
+
|
|
545
|
+
test('respects isQueuePausedRef when no resumeQueue provided', () => {
|
|
546
|
+
let _canProcessQueue = true
|
|
547
|
+
const isQueuePausedRef = { current: true }
|
|
548
|
+
|
|
549
|
+
finalizeQueueState({
|
|
550
|
+
setStreamStatus: () => {},
|
|
551
|
+
setCanProcessQueue: (can) => {
|
|
552
|
+
_canProcessQueue = can
|
|
553
|
+
},
|
|
554
|
+
updateChainInProgress: () => {},
|
|
555
|
+
isQueuePausedRef,
|
|
556
|
+
})
|
|
557
|
+
|
|
558
|
+
// When queue was paused before streaming, _canProcessQueue should be false
|
|
559
|
+
expect(_canProcessQueue).toBe(false)
|
|
560
|
+
})
|
|
561
|
+
})
|
|
562
|
+
|
|
563
|
+
describe('handleRunError', () => {
|
|
564
|
+
let originalGetState: typeof useChatStore.getState
|
|
565
|
+
|
|
566
|
+
beforeEach(() => {
|
|
567
|
+
originalGetState = useChatStore.getState
|
|
568
|
+
})
|
|
569
|
+
|
|
570
|
+
afterEach(() => {
|
|
571
|
+
useChatStore.getState = originalGetState
|
|
572
|
+
})
|
|
573
|
+
|
|
574
|
+
test('stores error in userError field for regular errors', () => {
|
|
575
|
+
let messages: ChatMessage[] = [
|
|
576
|
+
{
|
|
577
|
+
id: 'ai-1',
|
|
578
|
+
variant: 'ai',
|
|
579
|
+
content: 'Partial streamed content',
|
|
580
|
+
blocks: [],
|
|
581
|
+
timestamp: 'now',
|
|
582
|
+
},
|
|
583
|
+
]
|
|
584
|
+
|
|
585
|
+
const timerController = createMockTimerController()
|
|
586
|
+
const updater = createBatchedMessageUpdater('ai-1', (fn: any) => {
|
|
587
|
+
messages = fn(messages)
|
|
588
|
+
})
|
|
589
|
+
|
|
590
|
+
let _streamStatus: StreamStatus = 'idle'
|
|
591
|
+
let _canProcessQueue = false
|
|
592
|
+
let _chainInProgress = true
|
|
593
|
+
let isRetrying = true
|
|
594
|
+
|
|
595
|
+
handleRunError({
|
|
596
|
+
error: new Error('Network timeout'),
|
|
597
|
+
timerController,
|
|
598
|
+
updater,
|
|
599
|
+
setIsRetrying: (value: boolean) => {
|
|
600
|
+
isRetrying = value
|
|
601
|
+
},
|
|
602
|
+
setStreamStatus: (status: StreamStatus) => {
|
|
603
|
+
_streamStatus = status
|
|
604
|
+
},
|
|
605
|
+
setCanProcessQueue: (can: boolean) => {
|
|
606
|
+
_canProcessQueue = can
|
|
607
|
+
},
|
|
608
|
+
updateChainInProgress: (value: boolean) => {
|
|
609
|
+
_chainInProgress = value
|
|
610
|
+
},
|
|
611
|
+
})
|
|
612
|
+
|
|
613
|
+
const aiMessage = messages.find((m) => m.id === 'ai-1')
|
|
614
|
+
expect(aiMessage).toBeDefined()
|
|
615
|
+
|
|
616
|
+
// Content should be preserved, error stored in userError
|
|
617
|
+
expect(aiMessage!.content).toBe('Partial streamed content')
|
|
618
|
+
expect(aiMessage!.userError).toBe('Network timeout')
|
|
619
|
+
|
|
620
|
+
// Verify state resets
|
|
621
|
+
expect(_streamStatus).toBe('idle')
|
|
622
|
+
expect(_canProcessQueue).toBe(true)
|
|
623
|
+
expect(_chainInProgress).toBe(false)
|
|
624
|
+
expect(isRetrying).toBe(false)
|
|
625
|
+
|
|
626
|
+
// Verify timer stopped with error
|
|
627
|
+
expect(timerController.stopCalls).toContain('error')
|
|
628
|
+
|
|
629
|
+
// Verify message marked complete
|
|
630
|
+
expect(aiMessage!.isComplete).toBe(true)
|
|
631
|
+
})
|
|
632
|
+
|
|
633
|
+
test('handles empty existing content gracefully', () => {
|
|
634
|
+
let messages: ChatMessage[] = [
|
|
635
|
+
{
|
|
636
|
+
id: 'ai-1',
|
|
637
|
+
variant: 'ai',
|
|
638
|
+
content: '',
|
|
639
|
+
blocks: [],
|
|
640
|
+
timestamp: 'now',
|
|
641
|
+
},
|
|
642
|
+
]
|
|
643
|
+
|
|
644
|
+
const timerController = createMockTimerController()
|
|
645
|
+
const updater = createBatchedMessageUpdater('ai-1', (fn: any) => {
|
|
646
|
+
messages = fn(messages)
|
|
647
|
+
})
|
|
648
|
+
|
|
649
|
+
handleRunError({
|
|
650
|
+
error: new Error('Something failed'),
|
|
651
|
+
timerController,
|
|
652
|
+
updater,
|
|
653
|
+
setIsRetrying: () => {},
|
|
654
|
+
setStreamStatus: () => {},
|
|
655
|
+
setCanProcessQueue: () => {},
|
|
656
|
+
updateChainInProgress: () => {},
|
|
657
|
+
})
|
|
658
|
+
|
|
659
|
+
const aiMessage = messages.find((m) => m.id === 'ai-1')
|
|
660
|
+
// Error should be in userError field
|
|
661
|
+
expect(aiMessage!.userError).toBe('Something failed')
|
|
662
|
+
expect(aiMessage!.isComplete).toBe(true)
|
|
663
|
+
})
|
|
664
|
+
|
|
665
|
+
test('handles regular errors without switching input mode', () => {
|
|
666
|
+
let messages: ChatMessage[] = [
|
|
667
|
+
{
|
|
668
|
+
id: 'ai-1',
|
|
669
|
+
variant: 'ai',
|
|
670
|
+
content: '',
|
|
671
|
+
blocks: [],
|
|
672
|
+
timestamp: 'now',
|
|
673
|
+
},
|
|
674
|
+
]
|
|
675
|
+
|
|
676
|
+
const timerController = createMockTimerController()
|
|
677
|
+
const updater = createBatchedMessageUpdater('ai-1', (fn: any) => {
|
|
678
|
+
messages = fn(messages)
|
|
679
|
+
})
|
|
680
|
+
|
|
681
|
+
const setInputModeMock = mock(() => {})
|
|
682
|
+
useChatStore.getState = () => ({
|
|
683
|
+
...originalGetState(),
|
|
684
|
+
setInputMode: setInputModeMock,
|
|
685
|
+
})
|
|
686
|
+
|
|
687
|
+
handleRunError({
|
|
688
|
+
error: new Error('Regular error'),
|
|
689
|
+
timerController,
|
|
690
|
+
updater,
|
|
691
|
+
setIsRetrying: () => {},
|
|
692
|
+
setStreamStatus: () => {},
|
|
693
|
+
setCanProcessQueue: () => {},
|
|
694
|
+
updateChainInProgress: () => {},
|
|
695
|
+
})
|
|
696
|
+
|
|
697
|
+
// Should NOT switch input mode for regular errors
|
|
698
|
+
expect(setInputModeMock).not.toHaveBeenCalled()
|
|
699
|
+
})
|
|
700
|
+
|
|
701
|
+
test('resets isProcessingQueueRef to false on error', () => {
|
|
702
|
+
let messages: ChatMessage[] = [
|
|
703
|
+
{
|
|
704
|
+
id: 'ai-1',
|
|
705
|
+
variant: 'ai',
|
|
706
|
+
content: '',
|
|
707
|
+
blocks: [],
|
|
708
|
+
timestamp: 'now',
|
|
709
|
+
},
|
|
710
|
+
]
|
|
711
|
+
|
|
712
|
+
const timerController = createMockTimerController()
|
|
713
|
+
const updater = createBatchedMessageUpdater('ai-1', (fn: any) => {
|
|
714
|
+
messages = fn(messages)
|
|
715
|
+
})
|
|
716
|
+
const isProcessingQueueRef = { current: true }
|
|
717
|
+
|
|
718
|
+
// Verify ref starts as true
|
|
719
|
+
expect(isProcessingQueueRef.current).toBe(true)
|
|
720
|
+
|
|
721
|
+
handleRunError({
|
|
722
|
+
error: new Error('Some error'),
|
|
723
|
+
timerController,
|
|
724
|
+
updater,
|
|
725
|
+
setIsRetrying: () => {},
|
|
726
|
+
setStreamStatus: () => {},
|
|
727
|
+
setCanProcessQueue: () => {},
|
|
728
|
+
updateChainInProgress: () => {},
|
|
729
|
+
isProcessingQueueRef,
|
|
730
|
+
})
|
|
731
|
+
|
|
732
|
+
// Verify isProcessingQueueRef is reset to false
|
|
733
|
+
expect(isProcessingQueueRef.current).toBe(false)
|
|
734
|
+
})
|
|
735
|
+
|
|
736
|
+
test('respects isQueuePausedRef when setting _canProcessQueue on error', () => {
|
|
737
|
+
let messages: ChatMessage[] = [
|
|
738
|
+
{
|
|
739
|
+
id: 'ai-1',
|
|
740
|
+
variant: 'ai',
|
|
741
|
+
content: '',
|
|
742
|
+
blocks: [],
|
|
743
|
+
timestamp: 'now',
|
|
744
|
+
},
|
|
745
|
+
]
|
|
746
|
+
|
|
747
|
+
const timerController = createMockTimerController()
|
|
748
|
+
const updater = createBatchedMessageUpdater('ai-1', (fn: any) => {
|
|
749
|
+
messages = fn(messages)
|
|
750
|
+
})
|
|
751
|
+
const isQueuePausedRef = { current: true }
|
|
752
|
+
let _canProcessQueue = true
|
|
753
|
+
|
|
754
|
+
handleRunError({
|
|
755
|
+
error: new Error('Some error'),
|
|
756
|
+
timerController,
|
|
757
|
+
updater,
|
|
758
|
+
setIsRetrying: () => {},
|
|
759
|
+
setStreamStatus: () => {},
|
|
760
|
+
setCanProcessQueue: (can: boolean) => {
|
|
761
|
+
_canProcessQueue = can
|
|
762
|
+
},
|
|
763
|
+
updateChainInProgress: () => {},
|
|
764
|
+
isQueuePausedRef,
|
|
765
|
+
})
|
|
766
|
+
|
|
767
|
+
// When queue was paused before streaming, _canProcessQueue should be false
|
|
768
|
+
expect(_canProcessQueue).toBe(false)
|
|
769
|
+
})
|
|
770
|
+
|
|
771
|
+
test('context length exceeded error (AI_APICallError) stores error in userError and preserves content', () => {
|
|
772
|
+
let messages: ChatMessage[] = [
|
|
773
|
+
{
|
|
774
|
+
id: 'ai-1',
|
|
775
|
+
variant: 'ai',
|
|
776
|
+
content: 'Partial streamed content before error',
|
|
777
|
+
blocks: [{ type: 'text', content: 'some block content' }],
|
|
778
|
+
timestamp: 'now',
|
|
779
|
+
},
|
|
780
|
+
]
|
|
781
|
+
|
|
782
|
+
const timerController = createMockTimerController()
|
|
783
|
+
const updater = createBatchedMessageUpdater('ai-1', (fn: any) => {
|
|
784
|
+
messages = fn(messages)
|
|
785
|
+
})
|
|
786
|
+
|
|
787
|
+
// Create an error that matches the real AI_APICallError structure
|
|
788
|
+
const contextLengthError = Object.assign(
|
|
789
|
+
new Error(
|
|
790
|
+
'This endpoint\'s maximum context length is 200000 tokens. However, you requested about 201209 tokens (158536 of text input, 10673 of tool input, 32000 in the output). Please reduce the length of either one, or use the "middle-out" transform to compress your prompt automatically.',
|
|
791
|
+
),
|
|
792
|
+
{
|
|
793
|
+
name: 'AI_APICallError',
|
|
794
|
+
statusCode: 400,
|
|
795
|
+
},
|
|
796
|
+
)
|
|
797
|
+
|
|
798
|
+
let _streamStatus = 'streaming' as StreamStatus
|
|
799
|
+
let _canProcessQueue = false
|
|
800
|
+
let _chainInProgress = true
|
|
801
|
+
let isRetrying = true
|
|
802
|
+
|
|
803
|
+
handleRunError({
|
|
804
|
+
error: contextLengthError,
|
|
805
|
+
timerController,
|
|
806
|
+
updater,
|
|
807
|
+
setIsRetrying: (value: boolean) => {
|
|
808
|
+
isRetrying = value
|
|
809
|
+
},
|
|
810
|
+
setStreamStatus: (status: StreamStatus) => {
|
|
811
|
+
_streamStatus = status
|
|
812
|
+
},
|
|
813
|
+
setCanProcessQueue: (can: boolean) => {
|
|
814
|
+
_canProcessQueue = can
|
|
815
|
+
},
|
|
816
|
+
updateChainInProgress: (value: boolean) => {
|
|
817
|
+
_chainInProgress = value
|
|
818
|
+
},
|
|
819
|
+
})
|
|
820
|
+
|
|
821
|
+
const aiMessage = messages.find((m) => m.id === 'ai-1')
|
|
822
|
+
expect(aiMessage).toBeDefined()
|
|
823
|
+
|
|
824
|
+
// Content should be preserved
|
|
825
|
+
expect(aiMessage!.content).toBe('Partial streamed content before error')
|
|
826
|
+
|
|
827
|
+
// Blocks should be preserved
|
|
828
|
+
expect(aiMessage!.blocks).toEqual([
|
|
829
|
+
{ type: 'text', content: 'some block content' },
|
|
830
|
+
])
|
|
831
|
+
|
|
832
|
+
// Error should be stored in userError (displayed in UserErrorBanner)
|
|
833
|
+
expect(aiMessage!.userError).toContain(
|
|
834
|
+
'maximum context length is 200000 tokens',
|
|
835
|
+
)
|
|
836
|
+
expect(aiMessage!.userError).toContain('201209 tokens')
|
|
837
|
+
|
|
838
|
+
// Message should be marked complete
|
|
839
|
+
expect(aiMessage!.isComplete).toBe(true)
|
|
840
|
+
|
|
841
|
+
// State should be reset
|
|
842
|
+
expect(_streamStatus).toBe('idle')
|
|
843
|
+
expect(_canProcessQueue).toBe(true)
|
|
844
|
+
expect(_chainInProgress).toBe(false)
|
|
845
|
+
expect(isRetrying).toBe(false)
|
|
846
|
+
|
|
847
|
+
// Timer should be stopped with error
|
|
848
|
+
expect(timerController.stopCalls).toContain('error')
|
|
849
|
+
})
|
|
850
|
+
|
|
851
|
+
test('Payment required error (402) uses setError, invalidates queries, and switches input mode', () => {
|
|
852
|
+
let messages: ChatMessage[] = [
|
|
853
|
+
{
|
|
854
|
+
id: 'ai-1',
|
|
855
|
+
variant: 'ai',
|
|
856
|
+
content: 'Partial streamed content',
|
|
857
|
+
blocks: [{ type: 'text', content: 'some block' }],
|
|
858
|
+
timestamp: 'now',
|
|
859
|
+
},
|
|
860
|
+
]
|
|
861
|
+
|
|
862
|
+
const timerController = createMockTimerController()
|
|
863
|
+
const updater = createBatchedMessageUpdater('ai-1', (fn: any) => {
|
|
864
|
+
messages = fn(messages)
|
|
865
|
+
})
|
|
866
|
+
|
|
867
|
+
const setInputModeMock = mock(() => {})
|
|
868
|
+
useChatStore.getState = () => ({
|
|
869
|
+
...originalGetState(),
|
|
870
|
+
setInputMode: setInputModeMock,
|
|
871
|
+
})
|
|
872
|
+
|
|
873
|
+
const paymentError = createPaymentRequiredError('Out of credits')
|
|
874
|
+
|
|
875
|
+
handleRunError({
|
|
876
|
+
error: paymentError,
|
|
877
|
+
timerController,
|
|
878
|
+
updater,
|
|
879
|
+
setIsRetrying: () => {},
|
|
880
|
+
setStreamStatus: () => {},
|
|
881
|
+
setCanProcessQueue: () => {},
|
|
882
|
+
updateChainInProgress: () => {},
|
|
883
|
+
})
|
|
884
|
+
|
|
885
|
+
const aiMessage = messages.find((m) => m.id === 'ai-1')
|
|
886
|
+
expect(aiMessage).toBeDefined()
|
|
887
|
+
|
|
888
|
+
// For PaymentRequiredError, setError sets userError (not content)
|
|
889
|
+
// Content is preserved, error is stored in userError field
|
|
890
|
+
expect(aiMessage!.content).toBe('Partial streamed content')
|
|
891
|
+
expect(aiMessage!.userError).toContain('Out of credits')
|
|
892
|
+
|
|
893
|
+
// Blocks should be preserved for debugging context
|
|
894
|
+
expect(aiMessage!.blocks).toEqual([{ type: 'text', content: 'some block' }])
|
|
895
|
+
|
|
896
|
+
// Message should be marked complete
|
|
897
|
+
expect(aiMessage!.isComplete).toBe(true)
|
|
898
|
+
|
|
899
|
+
// Input mode should switch to outOfCredits
|
|
900
|
+
expect(setInputModeMock).toHaveBeenCalledWith('outOfCredits')
|
|
901
|
+
|
|
902
|
+
// Timer should still be stopped with error
|
|
903
|
+
expect(timerController.stopCalls).toContain('error')
|
|
904
|
+
})
|
|
905
|
+
})
|
|
906
|
+
|
|
907
|
+
/**
|
|
908
|
+
* CLI-level async race test: reproduces the exact bug scenario where aborting
|
|
909
|
+
* run A and attempting run B before A resolves would lose message history.
|
|
910
|
+
*
|
|
911
|
+
* This test simulates the full lifecycle at the helper level:
|
|
912
|
+
* 1. Start run A (setupStreamingContext)
|
|
913
|
+
* 2. Abort run A mid-stream
|
|
914
|
+
* 3. Attempt run B — verify it's blocked (chain lock held)
|
|
915
|
+
* 4. Resolve run A (handleRunCompletion with updated state)
|
|
916
|
+
* 5. Verify run B is now unblocked and can use state from A
|
|
917
|
+
*/
|
|
918
|
+
describe('CLI-level race condition: abort run A, attempt run B before A resolves', () => {
|
|
919
|
+
/**
|
|
920
|
+
* Simulates the queue-processing gate checks from useMessageQueue.processNextMessage.
|
|
921
|
+
* Returns true if a queued message would be allowed to proceed.
|
|
922
|
+
*/
|
|
923
|
+
const canQueueProcessNextMessage = (opts: {
|
|
924
|
+
isChainInProgress: boolean
|
|
925
|
+
_canProcessQueue: boolean
|
|
926
|
+
_streamStatus: StreamStatus
|
|
927
|
+
isProcessingQueue: boolean
|
|
928
|
+
isQueuePaused: boolean
|
|
929
|
+
}): boolean => {
|
|
930
|
+
if (opts.isQueuePaused) return false
|
|
931
|
+
if (!opts._canProcessQueue) return false
|
|
932
|
+
if (opts._streamStatus !== 'idle') return false
|
|
933
|
+
if (opts.isChainInProgress) return false
|
|
934
|
+
if (opts.isProcessingQueue) return false
|
|
935
|
+
return true
|
|
936
|
+
}
|
|
937
|
+
|
|
938
|
+
test('run B can proceed immediately after abort (chain lock released by abort handler)', () => {
|
|
939
|
+
// --- Shared mutable state (simulates React refs and state in the CLI) ---
|
|
940
|
+
let _streamStatus: StreamStatus = 'idle'
|
|
941
|
+
let _canProcessQueue = false
|
|
942
|
+
let _chainInProgress = true // Set true at start of sendMessage
|
|
943
|
+
const isProcessingQueueRef = { current: false }
|
|
944
|
+
const isQueuePausedRef = { current: false }
|
|
945
|
+
|
|
946
|
+
const setStreamStatus = (status: StreamStatus) => {
|
|
947
|
+
_streamStatus = status
|
|
948
|
+
}
|
|
949
|
+
const setCanProcessQueue = (can: boolean) => {
|
|
950
|
+
_canProcessQueue = can
|
|
951
|
+
}
|
|
952
|
+
const updateChainInProgress = (value: boolean) => {
|
|
953
|
+
_chainInProgress = value
|
|
954
|
+
}
|
|
955
|
+
|
|
956
|
+
// --- PHASE 1: Start run A (setupStreamingContext) ---
|
|
957
|
+
let messagesA = createBaseMessages()
|
|
958
|
+
const streamRefsA = createStreamController()
|
|
959
|
+
const timerControllerA = createMockTimerController()
|
|
960
|
+
const abortControllerRefA = { current: null as AbortController | null }
|
|
961
|
+
|
|
962
|
+
const { updater: _updaterA, abortController: abortControllerA } =
|
|
963
|
+
setupStreamingContext({
|
|
964
|
+
aiMessageId: 'ai-1',
|
|
965
|
+
timerController: timerControllerA,
|
|
966
|
+
setMessages: (fn: any) => {
|
|
967
|
+
messagesA = fn(messagesA)
|
|
968
|
+
},
|
|
969
|
+
streamRefs: streamRefsA,
|
|
970
|
+
abortControllerRef: abortControllerRefA,
|
|
971
|
+
setStreamStatus,
|
|
972
|
+
setCanProcessQueue,
|
|
973
|
+
isQueuePausedRef,
|
|
974
|
+
isProcessingQueueRef,
|
|
975
|
+
updateChainInProgress,
|
|
976
|
+
setIsRetrying: () => {},
|
|
977
|
+
setStreamingAgents: () => {},
|
|
978
|
+
})
|
|
979
|
+
|
|
980
|
+
// Simulate streaming has started
|
|
981
|
+
_streamStatus = 'streaming'
|
|
982
|
+
|
|
983
|
+
// Verify run A is actively streaming
|
|
984
|
+
expect(_streamStatus).toBe('streaming')
|
|
985
|
+
expect(_chainInProgress).toBe(true)
|
|
986
|
+
|
|
987
|
+
// --- PHASE 2: User aborts run A ---
|
|
988
|
+
abortControllerA.abort()
|
|
989
|
+
|
|
990
|
+
// Abort handler fires synchronously: UI is updated AND chain lock is released
|
|
991
|
+
expect(streamRefsA.state.wasAbortedByUser).toBe(true)
|
|
992
|
+
expect(_streamStatus as StreamStatus).toBe('idle')
|
|
993
|
+
expect(_chainInProgress).toBe(false) // Chain lock released immediately!
|
|
994
|
+
expect(_canProcessQueue).toBe(true)
|
|
995
|
+
|
|
996
|
+
// --- PHASE 3: User types run B — verify it's UNBLOCKED ---
|
|
997
|
+
const canProcessRunB = canQueueProcessNextMessage({
|
|
998
|
+
isChainInProgress: _chainInProgress,
|
|
999
|
+
_canProcessQueue,
|
|
1000
|
+
_streamStatus,
|
|
1001
|
+
isProcessingQueue: isProcessingQueueRef.current,
|
|
1002
|
+
isQueuePaused: isQueuePausedRef.current,
|
|
1003
|
+
})
|
|
1004
|
+
|
|
1005
|
+
// Run B can proceed immediately — this is the core fix.
|
|
1006
|
+
// New messages are sent directly instead of being queued.
|
|
1007
|
+
expect(canProcessRunB).toBe(true)
|
|
1008
|
+
})
|
|
1009
|
+
|
|
1010
|
+
test('handleRunCompletion does not interfere after abort (no-op for aborted runs)', () => {
|
|
1011
|
+
// After abort releases the chain lock, handleRunCompletion should be a no-op
|
|
1012
|
+
// to avoid interfering with any new run that may have started.
|
|
1013
|
+
|
|
1014
|
+
let _streamStatus: StreamStatus = 'idle'
|
|
1015
|
+
let _canProcessQueue = true
|
|
1016
|
+
let _chainInProgress = false // Already released by abort handler
|
|
1017
|
+
const isProcessingQueueRef = { current: false }
|
|
1018
|
+
const isQueuePausedRef = { current: false }
|
|
1019
|
+
|
|
1020
|
+
const timerController = createMockTimerController()
|
|
1021
|
+
let messages = createBaseMessages()
|
|
1022
|
+
const updater = createBatchedMessageUpdater('ai-1', (fn: any) => {
|
|
1023
|
+
messages = fn(messages)
|
|
1024
|
+
})
|
|
1025
|
+
|
|
1026
|
+
// Track calls
|
|
1027
|
+
let setStreamStatusCallCount = 0
|
|
1028
|
+
let updateChainInProgressCallCount = 0
|
|
1029
|
+
|
|
1030
|
+
const runState: RunState = {
|
|
1031
|
+
traceSessionId: 'trace-test',
|
|
1032
|
+
sessionState: {} as any,
|
|
1033
|
+
output: { type: 'lastMessage' as const, value: [] },
|
|
1034
|
+
}
|
|
1035
|
+
|
|
1036
|
+
handleRunCompletion({
|
|
1037
|
+
runState,
|
|
1038
|
+
actualCredits: undefined,
|
|
1039
|
+
agentMode: 'EDIT',
|
|
1040
|
+
timerController,
|
|
1041
|
+
updater,
|
|
1042
|
+
aiMessageId: 'ai-1',
|
|
1043
|
+
wasAbortedByUser: true,
|
|
1044
|
+
setStreamStatus: () => {
|
|
1045
|
+
setStreamStatusCallCount++
|
|
1046
|
+
},
|
|
1047
|
+
setCanProcessQueue: (can: boolean) => {
|
|
1048
|
+
_canProcessQueue = can
|
|
1049
|
+
},
|
|
1050
|
+
updateChainInProgress: () => {
|
|
1051
|
+
updateChainInProgressCallCount++
|
|
1052
|
+
},
|
|
1053
|
+
setHasReceivedPlanResponse: () => {},
|
|
1054
|
+
isProcessingQueueRef,
|
|
1055
|
+
isQueuePausedRef,
|
|
1056
|
+
})
|
|
1057
|
+
|
|
1058
|
+
// handleRunCompletion should be a no-op for aborted runs
|
|
1059
|
+
expect(setStreamStatusCallCount).toBe(0)
|
|
1060
|
+
expect(updateChainInProgressCallCount).toBe(0)
|
|
1061
|
+
// State should be unchanged (still in the "released" state from abort handler)
|
|
1062
|
+
expect(_chainInProgress).toBe(false)
|
|
1063
|
+
expect(_canProcessQueue).toBe(true)
|
|
1064
|
+
})
|
|
1065
|
+
|
|
1066
|
+
test('aborted run A finally block must not clear isProcessingQueueRef owned by run B', () => {
|
|
1067
|
+
// Regression test for overlap hazard: after abort releases the chain lock,
|
|
1068
|
+
// run B can start from the queue and set isProcessingQueueRef = true.
|
|
1069
|
+
// Run A's late-executing finally block must NOT clear it.
|
|
1070
|
+
//
|
|
1071
|
+
// This tests the pattern used in use-send-message.ts where the finally block
|
|
1072
|
+
// guards isProcessingQueueRef cleanup with !abortController.signal.aborted.
|
|
1073
|
+
|
|
1074
|
+
const isProcessingQueueRef = { current: false }
|
|
1075
|
+
const isQueuePausedRef = { current: false }
|
|
1076
|
+
let _chainInProgress = true
|
|
1077
|
+
let _canProcessQueue = false
|
|
1078
|
+
let _streamStatus: StreamStatus = 'idle'
|
|
1079
|
+
|
|
1080
|
+
// --- Run A setup and abort ---
|
|
1081
|
+
let messagesA = createBaseMessages()
|
|
1082
|
+
const sharedStreamRefs = createStreamController()
|
|
1083
|
+
const timerA = createMockTimerController()
|
|
1084
|
+
const abortRefA = { current: null as AbortController | null }
|
|
1085
|
+
|
|
1086
|
+
const { abortController: abortA } = setupStreamingContext({
|
|
1087
|
+
aiMessageId: 'ai-run-a',
|
|
1088
|
+
timerController: timerA,
|
|
1089
|
+
setMessages: (fn: any) => {
|
|
1090
|
+
messagesA = fn(messagesA)
|
|
1091
|
+
},
|
|
1092
|
+
streamRefs: sharedStreamRefs,
|
|
1093
|
+
abortControllerRef: abortRefA,
|
|
1094
|
+
setStreamStatus: (status: StreamStatus) => {
|
|
1095
|
+
_streamStatus = status
|
|
1096
|
+
},
|
|
1097
|
+
setCanProcessQueue: (can: boolean) => {
|
|
1098
|
+
_canProcessQueue = can
|
|
1099
|
+
},
|
|
1100
|
+
isQueuePausedRef,
|
|
1101
|
+
isProcessingQueueRef,
|
|
1102
|
+
updateChainInProgress: (value: boolean) => {
|
|
1103
|
+
_chainInProgress = value
|
|
1104
|
+
},
|
|
1105
|
+
setIsRetrying: () => {},
|
|
1106
|
+
setStreamingAgents: () => {},
|
|
1107
|
+
})
|
|
1108
|
+
|
|
1109
|
+
// Abort run A
|
|
1110
|
+
abortA.abort()
|
|
1111
|
+
expect(_chainInProgress).toBe(false)
|
|
1112
|
+
expect(isProcessingQueueRef.current).toBe(false)
|
|
1113
|
+
|
|
1114
|
+
// --- Run B starts from queue, takes ownership of isProcessingQueueRef ---
|
|
1115
|
+
isProcessingQueueRef.current = true // Queue's processNextMessage sets this
|
|
1116
|
+
_chainInProgress = true
|
|
1117
|
+
_canProcessQueue = false
|
|
1118
|
+
|
|
1119
|
+
// --- Simulate run A's finally block (late execution) ---
|
|
1120
|
+
// In use-send-message.ts, the finally block guards with !abortController.signal.aborted.
|
|
1121
|
+
// Verify abortA.signal.aborted is true so the guard would skip cleanup.
|
|
1122
|
+
expect(abortA.signal.aborted).toBe(true)
|
|
1123
|
+
|
|
1124
|
+
// The finally block pattern: only clean up if NOT aborted
|
|
1125
|
+
if (!abortA.signal.aborted) {
|
|
1126
|
+
// This should NOT execute
|
|
1127
|
+
isProcessingQueueRef.current = false
|
|
1128
|
+
}
|
|
1129
|
+
|
|
1130
|
+
// isProcessingQueueRef must still be true (owned by run B)
|
|
1131
|
+
expect(isProcessingQueueRef.current).toBe(true)
|
|
1132
|
+
// _chainInProgress must still be true (owned by run B)
|
|
1133
|
+
expect(_chainInProgress).toBe(true)
|
|
1134
|
+
})
|
|
1135
|
+
|
|
1136
|
+
test('reject-after-abort must not run handleRunError cleanup that could clobber run B', () => {
|
|
1137
|
+
// Regression test: if client.run() rejects after abort (e.g., network teardown),
|
|
1138
|
+
// handleRunError should NOT run because it would reset shared queue/stream state
|
|
1139
|
+
// that run B may have already claimed.
|
|
1140
|
+
//
|
|
1141
|
+
// This tests the pattern used in use-send-message.ts where the catch block
|
|
1142
|
+
// guards handleRunError with !abortController.signal.aborted.
|
|
1143
|
+
|
|
1144
|
+
let _streamStatus: StreamStatus = 'idle'
|
|
1145
|
+
let _canProcessQueue = true
|
|
1146
|
+
let _chainInProgress = false // Released by abort handler
|
|
1147
|
+
const isProcessingQueueRef = { current: false }
|
|
1148
|
+
const isQueuePausedRef = { current: false }
|
|
1149
|
+
|
|
1150
|
+
// --- Simulate run A was aborted ---
|
|
1151
|
+
const abortController = new AbortController()
|
|
1152
|
+
abortController.abort()
|
|
1153
|
+
expect(abortController.signal.aborted).toBe(true)
|
|
1154
|
+
|
|
1155
|
+
// --- Run B has started and claimed shared state ---
|
|
1156
|
+
_chainInProgress = true
|
|
1157
|
+
_canProcessQueue = false
|
|
1158
|
+
isProcessingQueueRef.current = true
|
|
1159
|
+
_streamStatus = 'streaming'
|
|
1160
|
+
|
|
1161
|
+
// --- Simulate what happens if client.run() rejects after abort ---
|
|
1162
|
+
// The catch block pattern: only handle error if NOT aborted
|
|
1163
|
+
const error = new Error('AbortError: The operation was aborted')
|
|
1164
|
+
|
|
1165
|
+
if (!abortController.signal.aborted) {
|
|
1166
|
+
// This should NOT execute — handleRunError would clobber run B's state
|
|
1167
|
+
handleRunError({
|
|
1168
|
+
error,
|
|
1169
|
+
timerController: createMockTimerController(),
|
|
1170
|
+
updater: createBatchedMessageUpdater('ai-1', () => {}),
|
|
1171
|
+
setIsRetrying: () => {},
|
|
1172
|
+
setStreamStatus: (status: StreamStatus) => {
|
|
1173
|
+
_streamStatus = status
|
|
1174
|
+
},
|
|
1175
|
+
setCanProcessQueue: (can: boolean) => {
|
|
1176
|
+
_canProcessQueue = can
|
|
1177
|
+
},
|
|
1178
|
+
updateChainInProgress: (value: boolean) => {
|
|
1179
|
+
_chainInProgress = value
|
|
1180
|
+
},
|
|
1181
|
+
isProcessingQueueRef,
|
|
1182
|
+
isQueuePausedRef,
|
|
1183
|
+
})
|
|
1184
|
+
}
|
|
1185
|
+
|
|
1186
|
+
// Run B's state must be untouched
|
|
1187
|
+
expect(_chainInProgress).toBe(true) // Still owned by run B
|
|
1188
|
+
expect(_canProcessQueue).toBe(false) // Still owned by run B
|
|
1189
|
+
expect(isProcessingQueueRef.current).toBe(true) // Still owned by run B
|
|
1190
|
+
expect(_streamStatus).toBe('streaming') // Still owned by run B
|
|
1191
|
+
})
|
|
1192
|
+
|
|
1193
|
+
test('handleRunError WOULD clobber run B state if called without abort guard (documents why guard is needed)', () => {
|
|
1194
|
+
// This test proves that handleRunError resets shared state, which is why
|
|
1195
|
+
// the catch block in use-send-message.ts MUST guard it with abort check.
|
|
1196
|
+
|
|
1197
|
+
let _streamStatus: StreamStatus = 'streaming'
|
|
1198
|
+
let _canProcessQueue = false
|
|
1199
|
+
let _chainInProgress = true
|
|
1200
|
+
const isProcessingQueueRef = { current: true }
|
|
1201
|
+
const isQueuePausedRef = { current: false }
|
|
1202
|
+
|
|
1203
|
+
// Call handleRunError without guard (simulates the bug scenario)
|
|
1204
|
+
handleRunError({
|
|
1205
|
+
error: new Error('AbortError'),
|
|
1206
|
+
timerController: createMockTimerController(),
|
|
1207
|
+
updater: createBatchedMessageUpdater('ai-1', (fn: any) => {}),
|
|
1208
|
+
setIsRetrying: () => {},
|
|
1209
|
+
setStreamStatus: (status: StreamStatus) => {
|
|
1210
|
+
_streamStatus = status
|
|
1211
|
+
},
|
|
1212
|
+
setCanProcessQueue: (can: boolean) => {
|
|
1213
|
+
_canProcessQueue = can
|
|
1214
|
+
},
|
|
1215
|
+
updateChainInProgress: (value: boolean) => {
|
|
1216
|
+
_chainInProgress = value
|
|
1217
|
+
},
|
|
1218
|
+
isProcessingQueueRef,
|
|
1219
|
+
isQueuePausedRef,
|
|
1220
|
+
})
|
|
1221
|
+
|
|
1222
|
+
// handleRunError resets ALL shared state — this would clobber run B
|
|
1223
|
+
expect(_chainInProgress).toBe(false) // Clobbered!
|
|
1224
|
+
expect(_canProcessQueue).toBe(true) // Clobbered!
|
|
1225
|
+
expect(isProcessingQueueRef.current).toBe(false) // Clobbered!
|
|
1226
|
+
expect(_streamStatus as StreamStatus).toBe('idle') // Clobbered!
|
|
1227
|
+
})
|
|
1228
|
+
|
|
1229
|
+
test('full two-run lifecycle with shared streamRefs: run A abort → run B starts immediately', () => {
|
|
1230
|
+
// End-to-end test: two complete runs sharing the SAME streamRefs instance
|
|
1231
|
+
// (matching production behavior where streamRefs is reused across sends).
|
|
1232
|
+
// Verifies that run B can start immediately after abort, and that run A's
|
|
1233
|
+
// late-resolving handleRunCompletion does NOT interfere with run B.
|
|
1234
|
+
|
|
1235
|
+
let _streamStatus: StreamStatus = 'idle'
|
|
1236
|
+
let _canProcessQueue = false
|
|
1237
|
+
let _chainInProgress = true
|
|
1238
|
+
const isProcessingQueueRef = { current: false }
|
|
1239
|
+
const isQueuePausedRef = { current: false }
|
|
1240
|
+
let previousRunState: RunState | null = null
|
|
1241
|
+
|
|
1242
|
+
const setStreamStatus = (status: StreamStatus) => {
|
|
1243
|
+
_streamStatus = status
|
|
1244
|
+
}
|
|
1245
|
+
const setCanProcessQueue = (can: boolean) => {
|
|
1246
|
+
_canProcessQueue = can
|
|
1247
|
+
}
|
|
1248
|
+
const updateChainInProgress = (value: boolean) => {
|
|
1249
|
+
_chainInProgress = value
|
|
1250
|
+
}
|
|
1251
|
+
|
|
1252
|
+
// CRITICAL: Use a single shared streamRefs instance, just like production.
|
|
1253
|
+
// In production, streamRefsRef is created once via useRef and reused.
|
|
1254
|
+
const sharedStreamRefs = createStreamController()
|
|
1255
|
+
|
|
1256
|
+
// === RUN A ===
|
|
1257
|
+
let messagesA = createBaseMessages()
|
|
1258
|
+
const timerA = createMockTimerController()
|
|
1259
|
+
const abortRefA = { current: null as AbortController | null }
|
|
1260
|
+
|
|
1261
|
+
const { updater: updaterA, abortController: abortA } =
|
|
1262
|
+
setupStreamingContext({
|
|
1263
|
+
aiMessageId: 'ai-run-a',
|
|
1264
|
+
timerController: timerA,
|
|
1265
|
+
setMessages: (fn: any) => {
|
|
1266
|
+
messagesA = fn(messagesA)
|
|
1267
|
+
},
|
|
1268
|
+
streamRefs: sharedStreamRefs,
|
|
1269
|
+
abortControllerRef: abortRefA,
|
|
1270
|
+
setStreamStatus,
|
|
1271
|
+
setCanProcessQueue,
|
|
1272
|
+
isQueuePausedRef,
|
|
1273
|
+
isProcessingQueueRef,
|
|
1274
|
+
updateChainInProgress,
|
|
1275
|
+
setIsRetrying: () => {},
|
|
1276
|
+
setStreamingAgents: () => {},
|
|
1277
|
+
})
|
|
1278
|
+
|
|
1279
|
+
_streamStatus = 'streaming'
|
|
1280
|
+
|
|
1281
|
+
// Abort run A
|
|
1282
|
+
abortA.abort()
|
|
1283
|
+
expect(_chainInProgress).toBe(false) // Lock released immediately!
|
|
1284
|
+
expect(_canProcessQueue).toBe(true)
|
|
1285
|
+
expect(sharedStreamRefs.state.wasAbortedByUser).toBe(true)
|
|
1286
|
+
|
|
1287
|
+
// === RUN B starts immediately (before A's client.run() resolves) ===
|
|
1288
|
+
_chainInProgress = true
|
|
1289
|
+
_canProcessQueue = false
|
|
1290
|
+
|
|
1291
|
+
let messagesB: ChatMessage[] = [
|
|
1292
|
+
{
|
|
1293
|
+
id: 'ai-run-b',
|
|
1294
|
+
variant: 'ai',
|
|
1295
|
+
content: '',
|
|
1296
|
+
blocks: [],
|
|
1297
|
+
timestamp: 'now',
|
|
1298
|
+
},
|
|
1299
|
+
]
|
|
1300
|
+
const timerB = createMockTimerController()
|
|
1301
|
+
const abortRefB = { current: null as AbortController | null }
|
|
1302
|
+
|
|
1303
|
+
// Run B's setupStreamingContext calls sharedStreamRefs.reset(),
|
|
1304
|
+
// which clears wasAbortedByUser. This is the key race condition.
|
|
1305
|
+
const { updater: updaterB, abortController: abortB } =
|
|
1306
|
+
setupStreamingContext({
|
|
1307
|
+
aiMessageId: 'ai-run-b',
|
|
1308
|
+
timerController: timerB,
|
|
1309
|
+
setMessages: (fn: any) => {
|
|
1310
|
+
messagesB = fn(messagesB)
|
|
1311
|
+
},
|
|
1312
|
+
streamRefs: sharedStreamRefs,
|
|
1313
|
+
abortControllerRef: abortRefB,
|
|
1314
|
+
setStreamStatus,
|
|
1315
|
+
setCanProcessQueue,
|
|
1316
|
+
isQueuePausedRef,
|
|
1317
|
+
isProcessingQueueRef,
|
|
1318
|
+
updateChainInProgress,
|
|
1319
|
+
setIsRetrying: () => {},
|
|
1320
|
+
setStreamingAgents: () => {},
|
|
1321
|
+
})
|
|
1322
|
+
|
|
1323
|
+
// After B starts, shared streamRefs.wasAbortedByUser is reset to false.
|
|
1324
|
+
// This is why we use per-run abortController.signal.aborted instead.
|
|
1325
|
+
expect(sharedStreamRefs.state.wasAbortedByUser).toBe(false)
|
|
1326
|
+
|
|
1327
|
+
// Now run A's client.run() resolves (after B has already started and reset shared state).
|
|
1328
|
+
// handleRunCompletion uses the per-run wasAbortedByUser boolean (from abortA.signal.aborted),
|
|
1329
|
+
// NOT the shared streamRefs, so it correctly knows A was aborted.
|
|
1330
|
+
const runStateA: RunState = {
|
|
1331
|
+
traceSessionId: 'trace-test-a',
|
|
1332
|
+
sessionState: {
|
|
1333
|
+
id: 'session-abc',
|
|
1334
|
+
messages: [
|
|
1335
|
+
{ role: 'user', content: 'first message' },
|
|
1336
|
+
{ role: 'assistant', content: 'partial response before cancel' },
|
|
1337
|
+
],
|
|
1338
|
+
} as any,
|
|
1339
|
+
output: { type: 'lastMessage' as const, value: [] },
|
|
1340
|
+
}
|
|
1341
|
+
previousRunState = runStateA
|
|
1342
|
+
|
|
1343
|
+
handleRunCompletion({
|
|
1344
|
+
runState: runStateA,
|
|
1345
|
+
actualCredits: undefined,
|
|
1346
|
+
agentMode: 'EDIT',
|
|
1347
|
+
timerController: timerA,
|
|
1348
|
+
updater: updaterA,
|
|
1349
|
+
aiMessageId: 'ai-run-a',
|
|
1350
|
+
wasAbortedByUser: abortA.signal.aborted, // per-run flag, not shared state
|
|
1351
|
+
setStreamStatus,
|
|
1352
|
+
setCanProcessQueue,
|
|
1353
|
+
updateChainInProgress,
|
|
1354
|
+
setHasReceivedPlanResponse: () => {},
|
|
1355
|
+
isProcessingQueueRef,
|
|
1356
|
+
isQueuePausedRef,
|
|
1357
|
+
})
|
|
1358
|
+
|
|
1359
|
+
// handleRunCompletion for aborted run A should be a no-op
|
|
1360
|
+
// (it should NOT interfere with run B's chain lock)
|
|
1361
|
+
expect(_chainInProgress).toBe(true) // Still true from run B!
|
|
1362
|
+
|
|
1363
|
+
// Simulate run B completing normally
|
|
1364
|
+
const runStateB: RunState = {
|
|
1365
|
+
traceSessionId: 'trace-test-b',
|
|
1366
|
+
sessionState: {
|
|
1367
|
+
id: 'session-abc',
|
|
1368
|
+
messages: [
|
|
1369
|
+
{ role: 'user', content: 'first message' },
|
|
1370
|
+
{ role: 'assistant', content: 'partial response before cancel' },
|
|
1371
|
+
{ role: 'user', content: 'second message' },
|
|
1372
|
+
{ role: 'assistant', content: 'full response to second message' },
|
|
1373
|
+
],
|
|
1374
|
+
} as any,
|
|
1375
|
+
output: {
|
|
1376
|
+
type: 'lastMessage' as const,
|
|
1377
|
+
value: [
|
|
1378
|
+
{
|
|
1379
|
+
role: 'assistant' as const,
|
|
1380
|
+
content: [{ type: 'text' as const, text: 'full response' }],
|
|
1381
|
+
},
|
|
1382
|
+
],
|
|
1383
|
+
},
|
|
1384
|
+
}
|
|
1385
|
+
previousRunState = runStateB
|
|
1386
|
+
|
|
1387
|
+
handleRunCompletion({
|
|
1388
|
+
runState: runStateB,
|
|
1389
|
+
actualCredits: 5,
|
|
1390
|
+
agentMode: 'EDIT',
|
|
1391
|
+
timerController: timerB,
|
|
1392
|
+
updater: updaterB,
|
|
1393
|
+
aiMessageId: 'ai-run-b',
|
|
1394
|
+
wasAbortedByUser: abortB.signal.aborted, // per-run flag: false (B was not aborted)
|
|
1395
|
+
setStreamStatus,
|
|
1396
|
+
setCanProcessQueue,
|
|
1397
|
+
updateChainInProgress,
|
|
1398
|
+
setHasReceivedPlanResponse: () => {},
|
|
1399
|
+
isProcessingQueueRef,
|
|
1400
|
+
isQueuePausedRef,
|
|
1401
|
+
})
|
|
1402
|
+
|
|
1403
|
+
// Final state: run B completed normally
|
|
1404
|
+
expect(previousRunState!.sessionState as any).toEqual({
|
|
1405
|
+
id: 'session-abc',
|
|
1406
|
+
messages: [
|
|
1407
|
+
{ role: 'user', content: 'first message' },
|
|
1408
|
+
{ role: 'assistant', content: 'partial response before cancel' },
|
|
1409
|
+
{ role: 'user', content: 'second message' },
|
|
1410
|
+
{ role: 'assistant', content: 'full response to second message' },
|
|
1411
|
+
],
|
|
1412
|
+
})
|
|
1413
|
+
expect(_chainInProgress).toBe(false)
|
|
1414
|
+
expect(_canProcessQueue).toBe(true)
|
|
1415
|
+
})
|
|
1416
|
+
})
|
|
1417
|
+
|
|
1418
|
+
/**
|
|
1419
|
+
* Tests for early return queue state reset in sendMessage.
|
|
1420
|
+
* These test the resetEarlyReturnState helper used across multiple early return paths:
|
|
1421
|
+
* - prepareUserMessage exception
|
|
1422
|
+
* - validation failure (success: false)
|
|
1423
|
+
* - validation exception
|
|
1424
|
+
*/
|
|
1425
|
+
describe('resetEarlyReturnState', () => {
|
|
1426
|
+
describe('prepareUserMessage exception path', () => {
|
|
1427
|
+
test('resets chain in progress to false', () => {
|
|
1428
|
+
let _chainInProgress = true
|
|
1429
|
+
|
|
1430
|
+
resetEarlyReturnState({
|
|
1431
|
+
updateChainInProgress: (value) => {
|
|
1432
|
+
_chainInProgress = value
|
|
1433
|
+
},
|
|
1434
|
+
setCanProcessQueue: () => {},
|
|
1435
|
+
})
|
|
1436
|
+
|
|
1437
|
+
expect(_chainInProgress).toBe(false)
|
|
1438
|
+
})
|
|
1439
|
+
|
|
1440
|
+
test('sets _canProcessQueue to true when queue is not paused', () => {
|
|
1441
|
+
let _canProcessQueue = false
|
|
1442
|
+
const isQueuePausedRef = { current: false }
|
|
1443
|
+
|
|
1444
|
+
resetEarlyReturnState({
|
|
1445
|
+
updateChainInProgress: () => {},
|
|
1446
|
+
setCanProcessQueue: (can) => {
|
|
1447
|
+
_canProcessQueue = can
|
|
1448
|
+
},
|
|
1449
|
+
isQueuePausedRef,
|
|
1450
|
+
})
|
|
1451
|
+
|
|
1452
|
+
expect(_canProcessQueue).toBe(true)
|
|
1453
|
+
})
|
|
1454
|
+
|
|
1455
|
+
test('sets _canProcessQueue to false when queue is paused', () => {
|
|
1456
|
+
let _canProcessQueue = true
|
|
1457
|
+
const isQueuePausedRef = { current: true }
|
|
1458
|
+
|
|
1459
|
+
resetEarlyReturnState({
|
|
1460
|
+
updateChainInProgress: () => {},
|
|
1461
|
+
setCanProcessQueue: (can) => {
|
|
1462
|
+
_canProcessQueue = can
|
|
1463
|
+
},
|
|
1464
|
+
isQueuePausedRef,
|
|
1465
|
+
})
|
|
1466
|
+
|
|
1467
|
+
expect(_canProcessQueue).toBe(false)
|
|
1468
|
+
})
|
|
1469
|
+
|
|
1470
|
+
test('resets isProcessingQueueRef to false', () => {
|
|
1471
|
+
const isProcessingQueueRef = { current: true }
|
|
1472
|
+
|
|
1473
|
+
resetEarlyReturnState({
|
|
1474
|
+
updateChainInProgress: () => {},
|
|
1475
|
+
setCanProcessQueue: () => {},
|
|
1476
|
+
isProcessingQueueRef,
|
|
1477
|
+
})
|
|
1478
|
+
|
|
1479
|
+
expect(isProcessingQueueRef.current).toBe(false)
|
|
1480
|
+
})
|
|
1481
|
+
|
|
1482
|
+
test('handles missing isProcessingQueueRef gracefully', () => {
|
|
1483
|
+
// Should not throw when isProcessingQueueRef is undefined
|
|
1484
|
+
expect(() => {
|
|
1485
|
+
resetEarlyReturnState({
|
|
1486
|
+
updateChainInProgress: () => {},
|
|
1487
|
+
setCanProcessQueue: () => {},
|
|
1488
|
+
})
|
|
1489
|
+
}).not.toThrow()
|
|
1490
|
+
})
|
|
1491
|
+
|
|
1492
|
+
test('handles missing isQueuePausedRef gracefully (defaults to _canProcessQueue=true)', () => {
|
|
1493
|
+
let _canProcessQueue = false
|
|
1494
|
+
|
|
1495
|
+
resetEarlyReturnState({
|
|
1496
|
+
updateChainInProgress: () => {},
|
|
1497
|
+
setCanProcessQueue: (can) => {
|
|
1498
|
+
_canProcessQueue = can
|
|
1499
|
+
},
|
|
1500
|
+
// No isQueuePausedRef - should default to !undefined = true
|
|
1501
|
+
})
|
|
1502
|
+
|
|
1503
|
+
expect(_canProcessQueue).toBe(true)
|
|
1504
|
+
})
|
|
1505
|
+
})
|
|
1506
|
+
|
|
1507
|
+
describe('validation failure path (success: false)', () => {
|
|
1508
|
+
test('resets all queue state correctly when processing queued message', () => {
|
|
1509
|
+
let _chainInProgress = true
|
|
1510
|
+
let _canProcessQueue = false
|
|
1511
|
+
const isProcessingQueueRef = { current: true }
|
|
1512
|
+
const isQueuePausedRef = { current: false }
|
|
1513
|
+
|
|
1514
|
+
resetEarlyReturnState({
|
|
1515
|
+
updateChainInProgress: (value) => {
|
|
1516
|
+
_chainInProgress = value
|
|
1517
|
+
},
|
|
1518
|
+
setCanProcessQueue: (can) => {
|
|
1519
|
+
_canProcessQueue = can
|
|
1520
|
+
},
|
|
1521
|
+
isProcessingQueueRef,
|
|
1522
|
+
isQueuePausedRef,
|
|
1523
|
+
})
|
|
1524
|
+
|
|
1525
|
+
expect(_chainInProgress).toBe(false)
|
|
1526
|
+
expect(_canProcessQueue).toBe(true)
|
|
1527
|
+
expect(isProcessingQueueRef.current).toBe(false)
|
|
1528
|
+
})
|
|
1529
|
+
|
|
1530
|
+
test('respects queue paused state after validation failure', () => {
|
|
1531
|
+
let _chainInProgress = true
|
|
1532
|
+
let _canProcessQueue = true
|
|
1533
|
+
const isProcessingQueueRef = { current: true }
|
|
1534
|
+
const isQueuePausedRef = { current: true }
|
|
1535
|
+
|
|
1536
|
+
resetEarlyReturnState({
|
|
1537
|
+
updateChainInProgress: (value) => {
|
|
1538
|
+
_chainInProgress = value
|
|
1539
|
+
},
|
|
1540
|
+
setCanProcessQueue: (can) => {
|
|
1541
|
+
_canProcessQueue = can
|
|
1542
|
+
},
|
|
1543
|
+
isProcessingQueueRef,
|
|
1544
|
+
isQueuePausedRef,
|
|
1545
|
+
})
|
|
1546
|
+
|
|
1547
|
+
expect(_chainInProgress).toBe(false)
|
|
1548
|
+
expect(_canProcessQueue).toBe(false) // Queue was paused, should stay paused
|
|
1549
|
+
expect(isProcessingQueueRef.current).toBe(false)
|
|
1550
|
+
})
|
|
1551
|
+
})
|
|
1552
|
+
|
|
1553
|
+
describe('validation exception path', () => {
|
|
1554
|
+
test('resets all queue state correctly when validation throws', () => {
|
|
1555
|
+
let _chainInProgress = true
|
|
1556
|
+
let _canProcessQueue = false
|
|
1557
|
+
const isProcessingQueueRef = { current: true }
|
|
1558
|
+
const isQueuePausedRef = { current: false }
|
|
1559
|
+
|
|
1560
|
+
// Simulating what happens after catching validation exception
|
|
1561
|
+
resetEarlyReturnState({
|
|
1562
|
+
updateChainInProgress: (value) => {
|
|
1563
|
+
_chainInProgress = value
|
|
1564
|
+
},
|
|
1565
|
+
setCanProcessQueue: (can) => {
|
|
1566
|
+
_canProcessQueue = can
|
|
1567
|
+
},
|
|
1568
|
+
isProcessingQueueRef,
|
|
1569
|
+
isQueuePausedRef,
|
|
1570
|
+
})
|
|
1571
|
+
|
|
1572
|
+
expect(_chainInProgress).toBe(false)
|
|
1573
|
+
expect(_canProcessQueue).toBe(true)
|
|
1574
|
+
expect(isProcessingQueueRef.current).toBe(false)
|
|
1575
|
+
})
|
|
1576
|
+
|
|
1577
|
+
test('preserves queue pause state when validation throws', () => {
|
|
1578
|
+
let _canProcessQueue = true
|
|
1579
|
+
const isQueuePausedRef = { current: true }
|
|
1580
|
+
const isProcessingQueueRef = { current: true }
|
|
1581
|
+
|
|
1582
|
+
resetEarlyReturnState({
|
|
1583
|
+
updateChainInProgress: () => {},
|
|
1584
|
+
setCanProcessQueue: (can) => {
|
|
1585
|
+
_canProcessQueue = can
|
|
1586
|
+
},
|
|
1587
|
+
isProcessingQueueRef,
|
|
1588
|
+
isQueuePausedRef,
|
|
1589
|
+
})
|
|
1590
|
+
|
|
1591
|
+
// Queue was explicitly paused before, should remain paused after error
|
|
1592
|
+
expect(_canProcessQueue).toBe(false)
|
|
1593
|
+
// But processing lock should be released to allow manual resume
|
|
1594
|
+
expect(isProcessingQueueRef.current).toBe(false)
|
|
1595
|
+
})
|
|
1596
|
+
})
|
|
1597
|
+
|
|
1598
|
+
describe('complete early return scenarios', () => {
|
|
1599
|
+
test('queue can process next message after prepareUserMessage exception', () => {
|
|
1600
|
+
// Scenario: Message was being processed from queue, prepareUserMessage throws
|
|
1601
|
+
let _chainInProgress = true
|
|
1602
|
+
let _canProcessQueue = false
|
|
1603
|
+
const isProcessingQueueRef = { current: true }
|
|
1604
|
+
const isQueuePausedRef = { current: false }
|
|
1605
|
+
|
|
1606
|
+
// After exception, reset is called
|
|
1607
|
+
resetEarlyReturnState({
|
|
1608
|
+
updateChainInProgress: (value) => {
|
|
1609
|
+
_chainInProgress = value
|
|
1610
|
+
},
|
|
1611
|
+
setCanProcessQueue: (can) => {
|
|
1612
|
+
_canProcessQueue = can
|
|
1613
|
+
},
|
|
1614
|
+
isProcessingQueueRef,
|
|
1615
|
+
isQueuePausedRef,
|
|
1616
|
+
})
|
|
1617
|
+
|
|
1618
|
+
// Queue should be able to process next message
|
|
1619
|
+
expect(_chainInProgress).toBe(false)
|
|
1620
|
+
expect(_canProcessQueue).toBe(true)
|
|
1621
|
+
expect(isProcessingQueueRef.current).toBe(false)
|
|
1622
|
+
})
|
|
1623
|
+
|
|
1624
|
+
test('queue can process next message after validation returns success=false', () => {
|
|
1625
|
+
// Scenario: Message was being processed, validation returns failure
|
|
1626
|
+
let _chainInProgress = true
|
|
1627
|
+
let _canProcessQueue = false
|
|
1628
|
+
const isProcessingQueueRef = { current: true }
|
|
1629
|
+
const isQueuePausedRef = { current: false }
|
|
1630
|
+
|
|
1631
|
+
resetEarlyReturnState({
|
|
1632
|
+
updateChainInProgress: (value) => {
|
|
1633
|
+
_chainInProgress = value
|
|
1634
|
+
},
|
|
1635
|
+
setCanProcessQueue: (can) => {
|
|
1636
|
+
_canProcessQueue = can
|
|
1637
|
+
},
|
|
1638
|
+
isProcessingQueueRef,
|
|
1639
|
+
isQueuePausedRef,
|
|
1640
|
+
})
|
|
1641
|
+
|
|
1642
|
+
// All locks released, queue can continue
|
|
1643
|
+
expect(_chainInProgress).toBe(false)
|
|
1644
|
+
expect(_canProcessQueue).toBe(true)
|
|
1645
|
+
expect(isProcessingQueueRef.current).toBe(false)
|
|
1646
|
+
})
|
|
1647
|
+
|
|
1648
|
+
test('queue can process next message after validation throws exception', () => {
|
|
1649
|
+
// Scenario: Message was being processed, validation throws
|
|
1650
|
+
let _chainInProgress = true
|
|
1651
|
+
let _canProcessQueue = false
|
|
1652
|
+
const isProcessingQueueRef = { current: true }
|
|
1653
|
+
const isQueuePausedRef = { current: false }
|
|
1654
|
+
|
|
1655
|
+
resetEarlyReturnState({
|
|
1656
|
+
updateChainInProgress: (value) => {
|
|
1657
|
+
_chainInProgress = value
|
|
1658
|
+
},
|
|
1659
|
+
setCanProcessQueue: (can) => {
|
|
1660
|
+
_canProcessQueue = can
|
|
1661
|
+
},
|
|
1662
|
+
isProcessingQueueRef,
|
|
1663
|
+
isQueuePausedRef,
|
|
1664
|
+
})
|
|
1665
|
+
|
|
1666
|
+
// All locks released, queue can continue
|
|
1667
|
+
expect(_chainInProgress).toBe(false)
|
|
1668
|
+
expect(_canProcessQueue).toBe(true)
|
|
1669
|
+
expect(isProcessingQueueRef.current).toBe(false)
|
|
1670
|
+
})
|
|
1671
|
+
|
|
1672
|
+
test('queue remains blocked after error if user had paused it', () => {
|
|
1673
|
+
// Scenario: User paused queue, then an error occurred
|
|
1674
|
+
// Queue should remain paused after error recovery
|
|
1675
|
+
let _chainInProgress = true
|
|
1676
|
+
let _canProcessQueue = true
|
|
1677
|
+
const isProcessingQueueRef = { current: true }
|
|
1678
|
+
const isQueuePausedRef = { current: true } // User explicitly paused
|
|
1679
|
+
|
|
1680
|
+
resetEarlyReturnState({
|
|
1681
|
+
updateChainInProgress: (value) => {
|
|
1682
|
+
_chainInProgress = value
|
|
1683
|
+
},
|
|
1684
|
+
setCanProcessQueue: (can) => {
|
|
1685
|
+
_canProcessQueue = can
|
|
1686
|
+
},
|
|
1687
|
+
isProcessingQueueRef,
|
|
1688
|
+
isQueuePausedRef,
|
|
1689
|
+
})
|
|
1690
|
+
|
|
1691
|
+
// Chain is no longer in progress
|
|
1692
|
+
expect(_chainInProgress).toBe(false)
|
|
1693
|
+
// But queue should remain blocked because user paused it
|
|
1694
|
+
expect(_canProcessQueue).toBe(false)
|
|
1695
|
+
// Processing lock is released though
|
|
1696
|
+
expect(isProcessingQueueRef.current).toBe(false)
|
|
1697
|
+
})
|
|
1698
|
+
})
|
|
1699
|
+
})
|
|
1700
|
+
|
|
1701
|
+
describe('savant-free gate errors', () => {
|
|
1702
|
+
const makeUpdater = (messages: ChatMessage[]) => {
|
|
1703
|
+
const updater = createBatchedMessageUpdater('ai-1', (fn: any) => {
|
|
1704
|
+
const next = fn(messages)
|
|
1705
|
+
messages.length = 0
|
|
1706
|
+
messages.push(...next)
|
|
1707
|
+
})
|
|
1708
|
+
return updater
|
|
1709
|
+
}
|
|
1710
|
+
|
|
1711
|
+
const baseMessage = (): ChatMessage[] => [
|
|
1712
|
+
{
|
|
1713
|
+
id: 'ai-1',
|
|
1714
|
+
variant: 'ai',
|
|
1715
|
+
content: '',
|
|
1716
|
+
blocks: [],
|
|
1717
|
+
timestamp: 'now',
|
|
1718
|
+
},
|
|
1719
|
+
]
|
|
1720
|
+
|
|
1721
|
+
const gateError = (kind: string, statusCode: number) => ({
|
|
1722
|
+
error: kind,
|
|
1723
|
+
statusCode,
|
|
1724
|
+
message: 'server said so',
|
|
1725
|
+
})
|
|
1726
|
+
|
|
1727
|
+
test('handleRunError maps 409 session_superseded to the restart-required message', () => {
|
|
1728
|
+
const messages = baseMessage()
|
|
1729
|
+
const updater = makeUpdater(messages)
|
|
1730
|
+
handleRunError({
|
|
1731
|
+
error: gateError('session_superseded', 409),
|
|
1732
|
+
timerController: createMockTimerController(),
|
|
1733
|
+
updater,
|
|
1734
|
+
setIsRetrying: () => {},
|
|
1735
|
+
setStreamStatus: () => {},
|
|
1736
|
+
setCanProcessQueue: () => {},
|
|
1737
|
+
updateChainInProgress: () => {},
|
|
1738
|
+
})
|
|
1739
|
+
updater.flush()
|
|
1740
|
+
expect(messages[0].userError).toContain('Another savant-free CLI took over')
|
|
1741
|
+
})
|
|
1742
|
+
|
|
1743
|
+
test('handleRunError suppresses the inline error for 410 session_expired (ended banner takes over)', () => {
|
|
1744
|
+
const messages = baseMessage()
|
|
1745
|
+
const updater = makeUpdater(messages)
|
|
1746
|
+
handleRunError({
|
|
1747
|
+
error: gateError('session_expired', 410),
|
|
1748
|
+
timerController: createMockTimerController(),
|
|
1749
|
+
updater,
|
|
1750
|
+
setIsRetrying: () => {},
|
|
1751
|
+
setStreamStatus: () => {},
|
|
1752
|
+
setCanProcessQueue: () => {},
|
|
1753
|
+
updateChainInProgress: () => {},
|
|
1754
|
+
})
|
|
1755
|
+
updater.flush()
|
|
1756
|
+
// New contract: the gate handler flips the session store into `ended`
|
|
1757
|
+
// and the session-ended banner is the user-facing signal, so we do NOT
|
|
1758
|
+
// also surface an inline userError inside the chat transcript.
|
|
1759
|
+
expect(messages[0].userError).toBeUndefined()
|
|
1760
|
+
})
|
|
1761
|
+
|
|
1762
|
+
test('handleRunError suppresses the inline error for 428 waiting_room_required (ended banner takes over)', () => {
|
|
1763
|
+
const messages = baseMessage()
|
|
1764
|
+
const updater = makeUpdater(messages)
|
|
1765
|
+
handleRunError({
|
|
1766
|
+
error: gateError('waiting_room_required', 428),
|
|
1767
|
+
timerController: createMockTimerController(),
|
|
1768
|
+
updater,
|
|
1769
|
+
setIsRetrying: () => {},
|
|
1770
|
+
setStreamStatus: () => {},
|
|
1771
|
+
setCanProcessQueue: () => {},
|
|
1772
|
+
updateChainInProgress: () => {},
|
|
1773
|
+
})
|
|
1774
|
+
updater.flush()
|
|
1775
|
+
expect(messages[0].userError).toBeUndefined()
|
|
1776
|
+
})
|
|
1777
|
+
|
|
1778
|
+
test('handleRunError maps 429 waiting_room_queued to the session-pending message', () => {
|
|
1779
|
+
const messages = baseMessage()
|
|
1780
|
+
const updater = makeUpdater(messages)
|
|
1781
|
+
handleRunError({
|
|
1782
|
+
error: gateError('waiting_room_queued', 429),
|
|
1783
|
+
timerController: createMockTimerController(),
|
|
1784
|
+
updater,
|
|
1785
|
+
setIsRetrying: () => {},
|
|
1786
|
+
setStreamStatus: () => {},
|
|
1787
|
+
setCanProcessQueue: () => {},
|
|
1788
|
+
updateChainInProgress: () => {},
|
|
1789
|
+
})
|
|
1790
|
+
updater.flush()
|
|
1791
|
+
expect(messages[0].userError).toContain('still being set up')
|
|
1792
|
+
})
|
|
1793
|
+
|
|
1794
|
+
test('handleRunError ignores gate-shaped errors with non-matching status code', () => {
|
|
1795
|
+
// An error body with error: 'session_superseded' but a 500 status should
|
|
1796
|
+
// NOT be classified as a gate error (prevents generic 5xx from mimicking
|
|
1797
|
+
// the structured gate responses).
|
|
1798
|
+
const messages = baseMessage()
|
|
1799
|
+
const updater = makeUpdater(messages)
|
|
1800
|
+
const err = Object.assign(new Error('oops'), {
|
|
1801
|
+
error: 'session_superseded',
|
|
1802
|
+
statusCode: 500,
|
|
1803
|
+
})
|
|
1804
|
+
handleRunError({
|
|
1805
|
+
error: err,
|
|
1806
|
+
timerController: createMockTimerController(),
|
|
1807
|
+
updater,
|
|
1808
|
+
setIsRetrying: () => {},
|
|
1809
|
+
setStreamStatus: () => {},
|
|
1810
|
+
setCanProcessQueue: () => {},
|
|
1811
|
+
updateChainInProgress: () => {},
|
|
1812
|
+
})
|
|
1813
|
+
updater.flush()
|
|
1814
|
+
expect(messages[0].userError).toBe('oops')
|
|
1815
|
+
expect(messages[0].userError).not.toContain('took over')
|
|
1816
|
+
})
|
|
1817
|
+
|
|
1818
|
+
test('handleRunCompletion with gate error output routes through the gate handler', () => {
|
|
1819
|
+
const messages = baseMessage()
|
|
1820
|
+
const updater = makeUpdater(messages)
|
|
1821
|
+
const runState: RunState = {
|
|
1822
|
+
traceSessionId: 'trace-test',
|
|
1823
|
+
sessionState: undefined as any,
|
|
1824
|
+
output: {
|
|
1825
|
+
type: 'error',
|
|
1826
|
+
message: 'server said so',
|
|
1827
|
+
error: 'session_expired',
|
|
1828
|
+
statusCode: 410,
|
|
1829
|
+
} as any,
|
|
1830
|
+
}
|
|
1831
|
+
handleRunCompletion({
|
|
1832
|
+
runState,
|
|
1833
|
+
actualCredits: undefined,
|
|
1834
|
+
agentMode: 'EDIT',
|
|
1835
|
+
timerController: createMockTimerController(),
|
|
1836
|
+
updater,
|
|
1837
|
+
aiMessageId: 'ai-1',
|
|
1838
|
+
wasAbortedByUser: false,
|
|
1839
|
+
setStreamStatus: () => {},
|
|
1840
|
+
setCanProcessQueue: () => {},
|
|
1841
|
+
updateChainInProgress: () => {},
|
|
1842
|
+
setHasReceivedPlanResponse: () => {},
|
|
1843
|
+
})
|
|
1844
|
+
updater.flush()
|
|
1845
|
+
// 410 is now handled by the ended banner, not an inline error. The
|
|
1846
|
+
// assertion here just confirms routing happened via the gate handler
|
|
1847
|
+
// (which swallows the userError) rather than the generic error path
|
|
1848
|
+
// (which would set a userError from the message).
|
|
1849
|
+
expect(messages[0].userError).toBeUndefined()
|
|
1850
|
+
})
|
|
1851
|
+
})
|