Changesets · Branches · Tags · Compare
| Changeset | 3f123f1d62809f34c447400fec417810fda1e2b92f82b88c30a23a5f969f0316 |
|---|---|
| Author | Dallin Romney <dallinromney@gmail.com> · 2025-09-11 19:33 -07:00 |
| Committer | Dallin Romney <dallinromney@gmail.com> · 2025-09-11 19:33 -07:00 |
| Parents | dc97a0f5f35c, 84f2ca8b9cb1 |
60 files changed
added .continue/rules/no-any-types.md +5 −0
| @@ -0,0 +1,5 @@ | ||
| 1 | +--- | |
| 2 | +globs: "**/*.{ts,tsx}" | |
| 3 | +--- | |
| 4 | + | |
| 5 | +Avoid using the `any` type wherever possible. Use unknown or find the correct type. The only acceptable place to use any is when typecasting for test mocks, and even then it's better to avoid and provide a proper mock. |
modified .github/workflows/continue-detailed-review.yaml +1 −1
| @@ -18,7 +18,7 @@ | ||
| 18 | 18 | timeout-minutes: 10 |
| 19 | 19 | steps: |
| 20 | 20 | - name: Run Detailed PR Review |
| 21 | - uses: continuedev/continue/actions/detailed-review@b3f4b82600f603ca28c65a319b80ec36c4644ed7 | |
| 21 | + uses: continuedev/continue/actions/detailed-review@5dc7a050db441934c26eb910b8433291f627db7f | |
| 22 | 22 | with: |
| 23 | 23 | continue-api-key: ${{ secrets.CONTINUE_API_KEY }} |
| 24 | 24 | continue-org: continuedev |
modified .github/workflows/continue-general-review.yaml +1 −1
| @@ -18,7 +18,7 @@ | ||
| 18 | 18 | timeout-minutes: 10 |
| 19 | 19 | steps: |
| 20 | 20 | - name: Run Continue PR Review Action |
| 21 | - uses: continuedev/continue/actions/general-review@b3f4b82600f603ca28c65a319b80ec36c4644ed7 | |
| 21 | + uses: continuedev/continue/actions/general-review@5dc7a050db441934c26eb910b8433291f627db7f | |
| 22 | 22 | with: |
| 23 | 23 | continue-api-key: ${{ secrets.CONTINUE_API_KEY }} |
| 24 | 24 | continue-org: "continuedev" |
added core/commands/slash/ruleBlockSlashCommand.ts +15 −0
| @@ -0,0 +1,15 @@ | ||
| 1 | +import { RuleWithSource, SlashCommandWithSource } from "../.."; | |
| 2 | + | |
| 3 | +export function convertRuleBlockToSlashCommand( | |
| 4 | + rule: RuleWithSource, | |
| 5 | +): SlashCommandWithSource { | |
| 6 | + return { | |
| 7 | + name: | |
| 8 | + rule.name || | |
| 9 | + (rule.rule.length > 20 ? rule.rule.substring(0, 20) + "..." : rule.rule), | |
| 10 | + description: rule.description ?? "", | |
| 11 | + prompt: rule.rule, | |
| 12 | + source: "invokable-rule", | |
| 13 | + promptFile: rule.ruleFile, | |
| 14 | + }; | |
| 15 | +} |
added core/commands/slash/ruleBlockSlashCommand.vitest.ts +93 −0
| @@ -0,0 +1,93 @@ | ||
| 1 | +import { describe, expect, it } from "vitest"; | |
| 2 | +import { RuleWithSource } from "../.."; | |
| 3 | +import { convertRuleBlockToSlashCommand } from "./ruleBlockSlashCommand"; | |
| 4 | + | |
| 5 | +describe("convertRuleBlockToSlashCommand", () => { | |
| 6 | + it("should convert a rule with all properties to a slash command", () => { | |
| 7 | + const rule: RuleWithSource = { | |
| 8 | + name: "Code Review", | |
| 9 | + rule: "Review this code for best practices", | |
| 10 | + description: "Performs a code review", | |
| 11 | + source: "rules-block", | |
| 12 | + ruleFile: "/path/to/rules.yaml", | |
| 13 | + invokable: true, | |
| 14 | + }; | |
| 15 | + | |
| 16 | + const result = convertRuleBlockToSlashCommand(rule); | |
| 17 | + | |
| 18 | + expect(result).toEqual({ | |
| 19 | + name: "Code Review", | |
| 20 | + description: "Performs a code review", | |
| 21 | + prompt: "Review this code for best practices", | |
| 22 | + source: "invokable-rule", | |
| 23 | + promptFile: "/path/to/rules.yaml", | |
| 24 | + }); | |
| 25 | + }); | |
| 26 | + | |
| 27 | + it("should handle a rule without name", () => { | |
| 28 | + const rule: RuleWithSource = { | |
| 29 | + rule: "Review this code", | |
| 30 | + source: "rules-block", | |
| 31 | + invokable: true, | |
| 32 | + }; | |
| 33 | + | |
| 34 | + const result = convertRuleBlockToSlashCommand(rule); | |
| 35 | + | |
| 36 | + expect(result.name).toBe("Review this code"); | |
| 37 | + expect(result.prompt).toBe("Review this code"); | |
| 38 | + }); | |
| 39 | + | |
| 40 | + it("should truncate long rule text when used as name", () => { | |
| 41 | + const rule: RuleWithSource = { | |
| 42 | + rule: "This is a very long rule text that should be truncated", | |
| 43 | + source: "rules-block", | |
| 44 | + invokable: true, | |
| 45 | + }; | |
| 46 | + | |
| 47 | + const result = convertRuleBlockToSlashCommand(rule); | |
| 48 | + | |
| 49 | + expect(result.name).toBe("This is a very long ..."); | |
| 50 | + expect(result.prompt).toBe( | |
| 51 | + "This is a very long rule text that should be truncated", | |
| 52 | + ); | |
| 53 | + }); | |
| 54 | + | |
| 55 | + it("should handle a rule without description", () => { | |
| 56 | + const rule: RuleWithSource = { | |
| 57 | + name: "Test Rule", | |
| 58 | + rule: "Test rule content", | |
| 59 | + source: "rules-block", | |
| 60 | + invokable: true, | |
| 61 | + }; | |
| 62 | + | |
| 63 | + const result = convertRuleBlockToSlashCommand(rule); | |
| 64 | + | |
| 65 | + expect(result.description).toBe(""); | |
| 66 | + }); | |
| 67 | + | |
| 68 | + it("should use rule text as the prompt", () => { | |
| 69 | + const rule: RuleWithSource = { | |
| 70 | + name: "Explain Code", | |
| 71 | + rule: "Explain what this code does in simple terms", | |
| 72 | + source: "rules-block", | |
| 73 | + invokable: true, | |
| 74 | + }; | |
| 75 | + | |
| 76 | + const result = convertRuleBlockToSlashCommand(rule); | |
| 77 | + | |
| 78 | + expect(result.prompt).toBe("Explain what this code does in simple terms"); | |
| 79 | + }); | |
| 80 | + | |
| 81 | + it("should always set source to 'invokable-rule'", () => { | |
| 82 | + const rule: RuleWithSource = { | |
| 83 | + name: "Test", | |
| 84 | + rule: "Test", | |
| 85 | + source: "default-chat", | |
| 86 | + invokable: true, | |
| 87 | + }; | |
| 88 | + | |
| 89 | + const result = convertRuleBlockToSlashCommand(rule); | |
| 90 | + | |
| 91 | + expect(result.source).toBe("invokable-rule"); | |
| 92 | + }); | |
| 93 | +}); |
modified core/config/types.ts +1 −0
| @@ -1061,6 +1061,7 @@ | ||
| 1061 | 1061 | filepath?: string; |
| 1062 | 1062 | fileContent?: string; |
| 1063 | 1063 | originalFileContent?: string; |
| 1064 | + autoFormattingDiff?: string; | |
| 1064 | 1065 | } |
| 1065 | 1066 | |
| 1066 | 1067 | export interface RangeInFileWithContents { |
modified core/config/yaml/loadYaml.ts +16 −1
| @@ -24,6 +24,7 @@ | ||
| 24 | 24 | |
| 25 | 25 | import { convertPromptBlockToSlashCommand } from "../../commands/slash/promptBlockSlashCommand"; |
| 26 | 26 | import { slashCommandFromPromptFile } from "../../commands/slash/promptFileSlashCommand"; |
| 27 | +import { convertRuleBlockToSlashCommand } from "../../commands/slash/ruleBlockSlashCommand"; | |
| 27 | 28 | import { getControlPlaneEnvSync } from "../../control-plane/env"; |
| 28 | 29 | import { PolicySingleton } from "../../control-plane/PolicySingleton"; |
| 29 | 30 | import { getBaseToolDefinitions } from "../../tools"; |
| @@ -208,7 +209,21 @@ | ||
| 208 | 209 | } |
| 209 | 210 | |
| 210 | 211 | for (const rule of config.rules ?? []) { |
| 211 | - continueConfig.rules.push(convertYamlRuleToContinueRule(rule)); | |
| 212 | + const convertedRule = convertYamlRuleToContinueRule(rule); | |
| 213 | + continueConfig.rules.push(convertedRule); | |
| 214 | + | |
| 215 | + // Convert invokable rules to slash commands | |
| 216 | + if (convertedRule.invokable) { | |
| 217 | + try { | |
| 218 | + const slashCommand = convertRuleBlockToSlashCommand(convertedRule); | |
| 219 | + continueConfig.slashCommands?.push(slashCommand); | |
| 220 | + } catch (e) { | |
| 221 | + localErrors.push({ | |
| 222 | + message: `Error converting invokable rule ${convertedRule.name} to slash command: ${e instanceof Error ? e.message : e}`, | |
| 223 | + fatal: false, | |
| 224 | + }); | |
| 225 | + } | |
| 226 | + } | |
| 212 | 227 | } |
| 213 | 228 | |
| 214 | 229 | continueConfig.data = config.data; |
modified core/config/yaml/yamlToContinueConfig.ts +2 −0
| @@ -13,8 +13,10 @@ | ||
| 13 | 13 | rule: rule.rule, |
| 14 | 14 | globs: rule.globs, |
| 15 | 15 | name: rule.name, |
| 16 | + description: rule.description, | |
| 16 | 17 | ruleFile: rule.sourceFile, |
| 17 | 18 | alwaysApply: rule.alwaysApply, |
| 19 | + invokable: rule.invokable, | |
| 18 | 20 | }; |
| 19 | 21 | } |
| 20 | 22 | } |
modified core/index.d.ts +2 −0
| @@ -1387,6 +1387,7 @@ | ||
| 1387 | 1387 | fileContent?: string; |
| 1388 | 1388 | originalFileContent?: string; |
| 1389 | 1389 | toolCallId?: string; |
| 1390 | + autoFormattingDiff?: string; | |
| 1390 | 1391 | } |
| 1391 | 1392 | |
| 1392 | 1393 | export interface StreamDiffLinesPayload { |
| @@ -1807,6 +1808,7 @@ | ||
| 1807 | 1808 | description?: string; |
| 1808 | 1809 | ruleFile?: string; |
| 1809 | 1810 | alwaysApply?: boolean; |
| 1811 | + invokable?: boolean; | |
| 1810 | 1812 | } |
| 1811 | 1813 | export interface CompleteOnboardingPayload { |
| 1812 | 1814 | mode: OnboardingModes; |
modified core/llm/autodetect.ts +27 −1
| @@ -1,4 +1,9 @@ | ||
| 1 | -import { ChatMessage, ModelCapability, TemplateType } from "../index.js"; | |
| 1 | +import { | |
| 2 | + ChatMessage, | |
| 3 | + ModelCapability, | |
| 4 | + ModelDescription, | |
| 5 | + TemplateType, | |
| 6 | +} from "../index.js"; | |
| 2 | 7 | import { NEXT_EDIT_MODELS } from "./constants.js"; |
| 3 | 8 | |
| 4 | 9 | import { |
| @@ -126,6 +131,26 @@ | ||
| 126 | 131 | |
| 127 | 132 | return false; |
| 128 | 133 | } |
| 134 | + | |
| 135 | +function modelSupportsReasoning( | |
| 136 | + model: ModelDescription | null | undefined, | |
| 137 | +): boolean { | |
| 138 | + if (!model) { | |
| 139 | + return false; | |
| 140 | + } | |
| 141 | + if ("anthropic" === model.underlyingProviderName) { | |
| 142 | + return true; | |
| 143 | + } | |
| 144 | + if (model.model.includes("deepseek-r")) { | |
| 145 | + return true; | |
| 146 | + } | |
| 147 | + if (model.completionOptions?.reasoning) { | |
| 148 | + // Reasoning support is forced at the config level. Model might not necessarily support it though! | |
| 149 | + return true; | |
| 150 | + } | |
| 151 | + return false; | |
| 152 | +} | |
| 153 | + | |
| 129 | 154 | const PARALLEL_PROVIDERS: string[] = [ |
| 130 | 155 | "anthropic", |
| 131 | 156 | "bedrock", |
| @@ -421,4 +446,5 @@ | ||
| 421 | 446 | llmCanGenerateInParallel, |
| 422 | 447 | modelSupportsImages, |
| 423 | 448 | modelSupportsNextEdit, |
| 449 | + modelSupportsReasoning, | |
| 424 | 450 | }; |
modified core/llm/llms/Ollama.ts +2 −1
| @@ -87,6 +87,7 @@ | ||
| 87 | 87 | tools?: OllamaTool[]; // the tools of the chat, this can be used to keep a tool memory |
| 88 | 88 | // Not supported yet - tools: tools for the model to use if supported. Requires stream to be set to false |
| 89 | 89 | // And correspondingly, tool calls in OllamaChatMessage |
| 90 | + think?: boolean; // if true the model will be prompted to think about the response before generating it | |
| 90 | 91 | } |
| 91 | 92 | |
| 92 | 93 | type OllamaBaseResponse = { |
| @@ -146,7 +147,6 @@ | ||
| 146 | 147 | private static modelsBeingInstalledMutex = new Mutex(); |
| 147 | 148 | |
| 148 | 149 | private fimSupported: boolean = false; |
| 149 | - | |
| 150 | 150 | constructor(options: LLMOptions) { |
| 151 | 151 | super(options); |
| 152 | 152 | |
| @@ -393,6 +393,7 @@ | ||
| 393 | 393 | model: this._getModel(), |
| 394 | 394 | messages: ollamaMessages, |
| 395 | 395 | options: this._getModelFileParams(options), |
| 396 | + think: options.reasoning, | |
| 396 | 397 | keep_alive: options.keepAlive ?? 60 * 30, // 30 minutes |
| 397 | 398 | stream: options.stream, |
| 398 | 399 | // format: options.format, // Not currently in base completion options |
modified core/package-lock.json +0 −0
Not shown: the file is larger than the hub shows, or this page holds as much as it shows. View the file.
modified core/tools/callTool.ts +9 −4
| @@ -1,3 +1,4 @@ | ||
| 1 | +import { CallToolResultSchema } from "@modelcontextprotocol/sdk/types.js"; | |
| 1 | 2 | import { ContextItem, Tool, ToolCall, ToolExtras } from ".."; |
| 2 | 3 | import { MCPManagerSingleton } from "../context/mcp/MCPManagerSingleton"; |
| 3 | 4 | import { canParseUrl } from "../util/url"; |
| @@ -87,10 +88,14 @@ | ||
| 87 | 88 | if (!client) { |
| 88 | 89 | throw new Error("MCP connection not found"); |
| 89 | 90 | } |
| 90 | - const response = await client.client.callTool({ | |
| 91 | - name: toolName, | |
| 92 | - arguments: args, | |
| 93 | - }); | |
| 91 | + const response = await client.client.callTool( | |
| 92 | + { | |
| 93 | + name: toolName, | |
| 94 | + arguments: args, | |
| 95 | + }, | |
| 96 | + CallToolResultSchema, | |
| 97 | + { timeout: client.options.timeout }, | |
| 98 | + ); | |
| 94 | 99 | |
| 95 | 100 | if (response.isError === true) { |
| 96 | 101 | throw new Error(JSON.stringify(response.content)); |
modified core/tools/implementations/viewDiff.ts +11 −0
| @@ -9,6 +9,17 @@ | ||
| 9 | 9 | // TODO includeUnstaged should be an option |
| 10 | 10 | |
| 11 | 11 | const combinedDiff = diffs.join("\n"); |
| 12 | + | |
| 13 | + if (!combinedDiff.trim()) { | |
| 14 | + return [ | |
| 15 | + { | |
| 16 | + name: "Diff", | |
| 17 | + description: "current Git diff", | |
| 18 | + content: "The current diff is empty", | |
| 19 | + }, | |
| 20 | + ]; | |
| 21 | + } | |
| 22 | + | |
| 12 | 23 | const diffLines = combinedDiff.split("\n"); |
| 13 | 24 | |
| 14 | 25 | let truncated = false; |
modified docs/docs.json +1 −0
| @@ -233,6 +233,7 @@ | ||
| 233 | 233 | "guides/codebase-documentation-awareness", |
| 234 | 234 | "guides/cli", |
| 235 | 235 | "guides/continuous-ai", |
| 236 | + "guides/continuous-ai-readiness-assessment", | |
| 236 | 237 | "guides/plan-mode-guide", |
| 237 | 238 | "guides/ollama-guide", |
| 238 | 239 | "guides/instinct", |
modified docs/guides/codebase-documentation-awareness.mdx +12 −4
| @@ -1,11 +1,10 @@ | ||
| 1 | 1 | --- |
| 2 | -title: How to make your agent aware of codebases and documentation | |
| 2 | +title: How to Make Your Agent Aware of Codebases and Documentation | |
| 3 | 3 | description: Learn how to give your AI agent access to codebases and documentation for more context-aware assistance |
| 4 | 4 | keywords: [agent, codebase, documentation, MCP, context, RAG, tools] |
| 5 | +sidebarTitle: Codebase and Documentation Awareness | |
| 5 | 6 | --- |
| 6 | 7 | |
| 7 | -# How to make your agent aware of codebases and documentation | |
| 8 | - | |
| 9 | 8 | AI coding agents work best when they understand the context of your project. This guide shows you how to give your agent access to codebases and documentation, making it more helpful and accurate. |
| 10 | 9 | |
| 11 | 10 | ## Make your agent aware of your open codebase |
| @@ -28,18 +27,21 @@ | ||
| 28 | 27 | # Project Architecture |
| 29 | 28 | |
| 30 | 29 | This is a React application with: |
| 30 | + | |
| 31 | 31 | - Components in `/src/components` |
| 32 | 32 | - API routes in `/src/api` |
| 33 | 33 | - State management using Redux in `/src/store` |
| 34 | 34 | |
| 35 | 35 | ## Coding Standards |
| 36 | + | |
| 36 | 37 | - Use TypeScript for all new files |
| 37 | 38 | - Follow the existing naming conventions |
| 38 | 39 | - Write tests for all new features |
| 39 | 40 | ``` |
| 40 | 41 | |
| 41 | 42 | <Tip> |
| 42 | - Place rules files at different levels of your project hierarchy to scope when they trigger | |
| 43 | + Place rules files at different levels of your project hierarchy to scope when | |
| 44 | + they trigger | |
| 43 | 45 | </Tip> |
| 44 | 46 | |
| 45 | 47 | Learn more about [rules configuration](/customize/deep-dives/rules). |
| @@ -60,6 +62,7 @@ | ||
| 60 | 62 | # External Dependencies |
| 61 | 63 | |
| 62 | 64 | Our authentication system is based on: |
| 65 | + | |
| 63 | 66 | - [Auth.js documentation](https://authjs.dev/) |
| 64 | 67 | - [Example implementation](https://github.com/nextauthjs/next-auth-example) |
| 65 | 68 | |
| @@ -76,6 +79,7 @@ | ||
| 76 | 79 | # Repository Access |
| 77 | 80 | |
| 78 | 81 | You can use the `gh` CLI to: |
| 82 | + | |
| 79 | 83 | - Search for issues: `gh issue list --repo owner/repo` |
| 80 | 84 | - View pull requests: `gh pr list --repo owner/repo` |
| 81 | 85 | - Clone repositories: `gh repo clone owner/repo` |
| @@ -86,6 +90,7 @@ | ||
| 86 | 90 | [DeepWiki MCP](https://hub.continue.dev/deepwiki/deepwiki-mcp) lets your agent explore any public GitHub repository. |
| 87 | 91 | |
| 88 | 92 | Once configured, your agent can explore repositories like: |
| 93 | + | |
| 89 | 94 | - "Explore the React repository structure" |
| 90 | 95 | - "Find how authentication is implemented in NextAuth.js" |
| 91 | 96 | |
| @@ -115,6 +120,7 @@ | ||
| 115 | 120 | # Documentation Resources |
| 116 | 121 | |
| 117 | 122 | For framework-specific questions, refer to: |
| 123 | + | |
| 118 | 124 | - React: https://react.dev/reference/react |
| 119 | 125 | - Next.js: https://nextjs.org/docs |
| 120 | 126 | - Tailwind CSS: https://tailwindcss.com/docs |
| @@ -127,6 +133,7 @@ | ||
| 127 | 133 | [Context7 MCP](https://hub.continue.dev/upstash/context7-mcp) enables your agent to search and retrieve information from public documentation: |
| 128 | 134 | |
| 129 | 135 | Your agent can then answer questions like: |
| 136 | + | |
| 130 | 137 | - "How do I use React hooks?" |
| 131 | 138 | - "What's the syntax for Tailwind CSS animations?" |
| 132 | 139 | |
| @@ -142,6 +149,7 @@ | ||
| 142 | 149 | # Internal Documentation |
| 143 | 150 | |
| 144 | 151 | Our team documentation is available at: |
| 152 | + | |
| 145 | 153 | - API Documentation: https://internal.docs/api |
| 146 | 154 | - Architecture Guide: https://internal.docs/architecture |
| 147 | 155 | - Deployment Process: https://internal.docs/deployment |
added docs/guides/continuous-ai-readiness-assessment.mdx +309 −0
| @@ -0,0 +1,309 @@ | ||
| 1 | +--- | |
| 2 | +title: Assessing Your Team's Readiness for Continuous AI | |
| 3 | +description: Complete framework to evaluate team readiness for Continuous AI adoption with maturity levels, assessment criteria, and implementation roadmap. | |
| 4 | +sidebarTitle: Continuous AI Readiness Assessment | |
| 5 | +--- | |
| 6 | + | |
| 7 | +<Info> | |
| 8 | + **TL;DR:** Use this assessment framework to determine if your team is ready to | |
| 9 | + move from individual AI tool usage to automated Continuous AI workflows. | |
| 10 | + Covers technical infrastructure, processes, culture, and organizational | |
| 11 | + support. | |
| 12 | +</Info> | |
| 13 | + | |
| 14 | +## Assessing Continuous AI Readiness | |
| 15 | + | |
| 16 | +Continuous AI can dramatically improve development velocity and code quality, but successful implementation requires careful evaluation across four key dimensions. | |
| 17 | + | |
| 18 | +<Warning> | |
| 19 | + Rushing into Continuous AI without proper foundations leads to frustration and | |
| 20 | + failed initiatives. Use this framework to identify gaps before scaling. | |
| 21 | +</Warning> | |
| 22 | + | |
| 23 | +### 1. Identify Your Current Maturity Level | |
| 24 | + | |
| 25 | +Determine where your team falls on the Continuous AI maturity spectrum: | |
| 26 | + | |
| 27 | +<CardGroup cols={1}> | |
| 28 | + <Card title="Level 1: Manual AI Assistance" icon="user"> | |
| 29 | + Developers use AI tools inconsistently with highly variable results. | |
| 30 | + | |
| 31 | + **Characteristics:** | |
| 32 | + - High rejection rates of AI-generated code (>50%) | |
| 33 | + - No shared standards or prompting rules | |
| 34 | + - AI tools lack context about your codebase | |
| 35 | + - Ad-hoc usage without team coordination | |
| 36 | + | |
| 37 | + </Card> | |
| 38 | + | |
| 39 | +<Card title="Level 2: Workflow Automation" icon="gear"> | |
| 40 | + AI is systematically integrated into team workflows and CI/CD pipelines. | |
| 41 | + | |
| 42 | +**Characteristics:** | |
| 43 | + | |
| 44 | +- Consistent adoption across 80%+ of team members | |
| 45 | +- AI integrated into code reviews and deployment processes | |
| 46 | +- Documented standards for prompts and tool usage | |
| 47 | +- Basic metrics tracking AI impact | |
| 48 | + | |
| 49 | +</Card> | |
| 50 | + | |
| 51 | + <Card title="Level 3: Zero-Intervention Workflows" icon="robot"> | |
| 52 | + Certain development processes run autonomously with minimal human oversight. | |
| 53 | + | |
| 54 | + **Characteristics:** | |
| 55 | + - Human intervention rates below 15% | |
| 56 | + - Robust monitoring and automated rollback systems | |
| 57 | + - Measurable ROI from automation initiatives | |
| 58 | + - Advanced context awareness and learning loops | |
| 59 | + | |
| 60 | + </Card> | |
| 61 | +</CardGroup> | |
| 62 | + | |
| 63 | +### 2. Evaluate Readiness Across Four Key Dimensions | |
| 64 | + | |
| 65 | +Assess your team's strengths and potential risks across these critical areas: | |
| 66 | + | |
| 67 | +<AccordionGroup> | |
| 68 | + <Accordion title="Technical Infrastructure Assessment"> | |
| 69 | + **Key Questions:** | |
| 70 | + - Do our development tools integrate reliably? | |
| 71 | + - Can we measure AI effectiveness and impact? | |
| 72 | + - Are security policies compatible with AI workflows? | |
| 73 | + | |
| 74 | + **🟢 Green Flags:** | |
| 75 | + - Stable tool integrations with >99.5% uptime | |
| 76 | + - Comprehensive monitoring and observability | |
| 77 | + - Security policies that support AI tool usage | |
| 78 | + - Automated testing and deployment pipelines | |
| 79 | + | |
| 80 | + **🔴 Red Flags:** | |
| 81 | + - Frequent integration breakdowns | |
| 82 | + - No performance tracking or metrics | |
| 83 | + - Restrictive security policies blocking AI tools | |
| 84 | + - Manual deployment processes | |
| 85 | + | |
| 86 | + </Accordion> | |
| 87 | + | |
| 88 | +<Accordion title="Process Maturity Assessment"> | |
| 89 | + **Key Questions:** | |
| 90 | + - Are our development workflows consistent and documented? | |
| 91 | + - Do we have quality gates and review processes? | |
| 92 | + - Can we reproduce builds and deployments reliably? | |
| 93 | + | |
| 94 | + **🟢 Green Flags:** | |
| 95 | + - Clear coding standards and style guides | |
| 96 | + - Automated CI/CD with quality gates | |
| 97 | + - Documented, repeatable processes | |
| 98 | + - Consistent code review practices | |
| 99 | + | |
| 100 | + **🔴 Red Flags:** | |
| 101 | + - Inconsistent code reviews | |
| 102 | + - Ad-hoc deployment processes | |
| 103 | + - "Works on my machine" culture | |
| 104 | + - Undocumented tribal knowledge | |
| 105 | + | |
| 106 | +</Accordion> | |
| 107 | + | |
| 108 | +<Accordion title="Team Culture & Skills Assessment"> | |
| 109 | + **Key Questions:** | |
| 110 | + - Are developers open to adopting new AI-powered workflows? | |
| 111 | + - How does the team handle experimentation and failure? | |
| 112 | + - Do team members collaborate effectively on new initiatives? | |
| 113 | + | |
| 114 | + **🟢 Green Flags:** | |
| 115 | + - High curiosity and willingness to experiment | |
| 116 | + - Collaborative problem-solving culture | |
| 117 | + - Constructive feedback and learning mindset | |
| 118 | + - Active knowledge sharing practices | |
| 119 | + | |
| 120 | +**🔴 Red Flags:** | |
| 121 | + | |
| 122 | +- Strong resistance to workflow changes | |
| 123 | +- Blame culture around mistakes | |
| 124 | +- Perfectionism blocking experimentation | |
| 125 | +- Siloed work with minimal collaboration | |
| 126 | + | |
| 127 | +</Accordion> | |
| 128 | + | |
| 129 | + <Accordion title="Organizational Support Assessment"> | |
| 130 | + **Key Questions:** | |
| 131 | + - Does leadership provide budget and resources for AI initiatives? | |
| 132 | + - Is there tolerance for experimentation and learning? | |
| 133 | + - Are expectations realistic for ROI timelines? | |
| 134 | + | |
| 135 | + **🟢 Green Flags:** | |
| 136 | + - Executive buy-in and strategic alignment | |
| 137 | + - Dedicated budget for training and tools | |
| 138 | + - 3-6 month ROI expectations | |
| 139 | + - Support for calculated risk-taking | |
| 140 | + | |
| 141 | + **🔴 Red Flags:** | |
| 142 | + - Pressure for immediate ROI (weeks) | |
| 143 | + - No allocated budget for AI initiatives | |
| 144 | + - High risk aversion culture | |
| 145 | + - Lack of leadership engagement | |
| 146 | + | |
| 147 | + </Accordion> | |
| 148 | +</AccordionGroup> | |
| 149 | + | |
| 150 | +### 3. Critical Warning Signs | |
| 151 | + | |
| 152 | +<Warning> | |
| 153 | + **Stop and address these issues before scaling Continuous AI:** | |
| 154 | +</Warning> | |
| 155 | + | |
| 156 | +<CardGroup cols={2}> | |
| 157 | + <Card title="Technical Red Flags" icon="triangle-exclamation"> | |
| 158 | + - Builds breaking regularly (>5% failure rate) | |
| 159 | + - Unstable deployments or rollback frequency >10% | |
| 160 | + - No monitoring or observability systems | |
| 161 | + - Critical security policy conflicts | |
| 162 | + | |
| 163 | + </Card> | |
| 164 | + | |
| 165 | +<Card title="Team & Culture Red Flags" icon="users-slash"> | |
| 166 | + - More than 30% of team opposed to AI tools | |
| 167 | + - No established feedback or learning culture | |
| 168 | + - History of failed automation initiatives | |
| 169 | + - Resistance to changing existing workflows | |
| 170 | + | |
| 171 | +</Card> | |
| 172 | + | |
| 173 | +<Card title="Process Red Flags" icon="exclamation-triangle"> | |
| 174 | + - Inconsistent development workflows | |
| 175 | + - No quality gates or review processes | |
| 176 | + - Manual deployment and testing processes | |
| 177 | + - Lack of documentation and standards | |
| 178 | + | |
| 179 | +</Card> | |
| 180 | + | |
| 181 | + <Card title="Organizational Red Flags" icon="building"> | |
| 182 | + - Leadership expecting ROI in weeks vs months | |
| 183 | + - No allocated budget for AI initiatives | |
| 184 | + - High pressure, low experimentation tolerance | |
| 185 | + - Lack of strategic alignment on AI adoption | |
| 186 | + | |
| 187 | + </Card> | |
| 188 | +</CardGroup> | |
| 189 | + | |
| 190 | +### 4. Implementation Roadmap | |
| 191 | + | |
| 192 | +Based on your assessment results, follow this step-by-step approach: | |
| 193 | + | |
| 194 | +<Steps> | |
| 195 | + <Step title="Establish Baseline Metrics"> | |
| 196 | + Document current performance across key areas: | |
| 197 | + | |
| 198 | + - Development velocity (story | |
| 199 | + points, cycle time) | |
| 200 | + - Code quality metrics (bug rates, technical debt) | |
| 201 | + - Review times and approval rates | |
| 202 | + - Developer satisfaction and productivity | |
| 203 | + scores | |
| 204 | + | |
| 205 | + </Step> | |
| 206 | + | |
| 207 | +<Step title="Select Initial Automation Target"> | |
| 208 | + Choose one high-impact, low-risk workflow to automate first: | |
| 209 | + | |
| 210 | + - **Code Review:** Automated analysis and suggestions | |
| 211 | + - **Documentation:** Auto-generated API docs and README updates | |
| 212 | + - **Testing:** Automated test generation and maintenance | |
| 213 | + - **Refactoring:** Systematic code improvement suggestions | |
| 214 | + | |
| 215 | + </Step> | |
| 216 | + | |
| 217 | +<Step title="Standardize Team AI Usage"> | |
| 218 | + Create and document consistent practices: | |
| 219 | + - AI tool selection and configuration guidelines | |
| 220 | + | |
| 221 | + - Prompting standards and best practices | |
| 222 | + | |
| 223 | + - Quality gates and review processes | |
| 224 | + | |
| 225 | + - Security and compliance requirements | |
| 226 | + | |
| 227 | + </Step> | |
| 228 | + | |
| 229 | +<Step title="Pilot and Measure Impact"> | |
| 230 | + Run controlled experiments with success criteria: | |
| 231 | + - Start with 2-3 team members for 2-4 weeks | |
| 232 | + - Track metrics against baseline performance | |
| 233 | + - Gather qualitative feedback on developer experience | |
| 234 | + - Document lessons learned and optimization opportunities | |
| 235 | + | |
| 236 | +</Step> | |
| 237 | + | |
| 238 | + <Step title="Scale Deliberately"> | |
| 239 | + Expand successful pilots across the organization: | |
| 240 | + - Roll out to additional team members gradually | |
| 241 | + - Implement monitoring and alerting systems | |
| 242 | + - Establish feedback loops for continuous improvement | |
| 243 | + - Plan next automation targets based on results | |
| 244 | + | |
| 245 | + </Step> | |
| 246 | +</Steps> | |
| 247 | + | |
| 248 | +<CardGroup cols={2}> | |
| 249 | + <Card | |
| 250 | + title="Building Async Agents with Continue CLI" | |
| 251 | + icon="blog" | |
| 252 | + href="https://blog.continue.dev/building-async-agents-with-continue-cli/" | |
| 253 | + > | |
| 254 | + Comprehensive explanation of maturity levels and organizational readiness | |
| 255 | + factors | |
| 256 | + </Card> | |
| 257 | + | |
| 258 | + <Card | |
| 259 | + title="Developer's Guide" | |
| 260 | + icon="book" | |
| 261 | + href="https://docs.continue.dev/guides/continuous-ai" | |
| 262 | + > | |
| 263 | + Technical implementation details and best practices for Continuous AI | |
| 264 | + workflows | |
| 265 | + </Card> | |
| 266 | +</CardGroup> | |
| 267 | + | |
| 268 | +## Quick Assessment Checklist | |
| 269 | + | |
| 270 | +<Tip> | |
| 271 | + **Ready to get started?** Use this quick checklist to gauge your immediate | |
| 272 | + readiness: | |
| 273 | +</Tip> | |
| 274 | + | |
| 275 | +**Technical Foundation (Score: \_\_\_/4)** | |
| 276 | + | |
| 277 | +- Stable CI/CD pipelines with \<5% failure rate | |
| 278 | +- Monitoring and observability systems in place | |
| 279 | +- Security policies support AI tool integration | |
| 280 | +- Development environment standardization | |
| 281 | + | |
| 282 | +**Process Maturity (Score: \_\_\_/4)** | |
| 283 | + | |
| 284 | +- Documented coding standards and review processes | |
| 285 | +- Consistent deployment and rollback procedures | |
| 286 | +- Quality gates and automated testing | |
| 287 | +- Regular retrospectives and process improvement | |
| 288 | + | |
| 289 | +**Team Culture (Score: \_\_\_/4)** | |
| 290 | + | |
| 291 | +- \<30% resistance to AI tool adoption | |
| 292 | +- Active experimentation and learning culture | |
| 293 | +- Collaborative problem-solving approach | |
| 294 | +- Constructive feedback and knowledge sharing | |
| 295 | + | |
| 296 | +**Organizational Support (Score: \_\_\_/4)** | |
| 297 | + | |
| 298 | +- Leadership buy-in and strategic alignment | |
| 299 | +- Dedicated budget for AI initiatives and training | |
| 300 | +- 3-6 month ROI expectations (not weeks) | |
| 301 | +- Support for calculated risk-taking | |
| 302 | + | |
| 303 | +--- | |
| 304 | + | |
| 305 | +**Overall Readiness Score: \_\_\_/16** | |
| 306 | + | |
| 307 | +- **12-16:** Ready to begin Continuous AI implementation | |
| 308 | +- **8-11:** Address gaps in 1-2 areas before scaling | |
| 309 | +- **\<8:** Focus on foundational improvements first |
modified docs/guides/overview.mdx +1 −0
| @@ -13,6 +13,7 @@ | ||
| 13 | 13 | |
| 14 | 14 | - [Continuous AI: A Developer's Guide](/guides/continuous-ai) - Integrating AI into development workflows |
| 15 | 15 | - [How to Use Continue CLI (cn)](/guides/cli) - Command-line interface for Continue |
| 16 | +- [Continuous AI Readiness Assessment](/guides/continuous-ai-readiness-assessment) - Evaluate team readiness for Continuous AI adoption | |
| 16 | 17 | |
| 17 | 18 | ## What Advanced Tutorials Are Available |
| 18 | 19 |
modified docs/guides/running-continue-without-internet.mdx +4 −4
| @@ -3,7 +3,7 @@ | ||
| 3 | 3 | description: "Learn how to set up Continue for air-gapped or offline environments using local models, including steps to disable telemetry and configure local model providers" |
| 4 | 4 | --- |
| 5 | 5 | |
| 6 | -1. Download the latest .vsix file from the [Open VSX Registry](https://open-vsx.org/extension/Continue/continue) and [install it to VS Code](https://code.visualstudio.com/docs/editor/extension-marketplace#_install-from-a-vsix). | |
| 7 | -2. Turn off "Allow Anonymous Telemetry" in the user settings. This will stop Continue from attempting requests to PostHog for [anonymous telemetry](/customize/telemetry). | |
| 8 | -3. Also in `config.json`, set the default model to a local model. You can available options [here](/customization/models#openai). | |
| 9 | -4. Restart VS Code to ensure that the changes to `config.json` or `config.yaml` take effect. | |
| 6 | +1. Download the latest .vsix file from the [GitHub Releases page](https://github.com/continuedev/continue/releases) and [install it to VS Code](https://code.visualstudio.com/docs/editor/extension-marketplace#_install-from-a-vsix). | |
| 7 | +2. Turn off "Allow Anonymous Telemetry" in the user settings. This will stop Continue from attempting requests to PostHog for [anonymous telemetry](https://docs.continue.dev/reference/telemetry). | |
| 8 | +3. In your `config.yaml` file (or through the Continue UI), set the default model to a local model. You can find available local model options [here](https://docs.continue.dev/reference/model-providers/ollama). | |
| 9 | +4. Restart VS Code to ensure that the changes to `config.yaml` take effect. |
modified docs/reference.mdx +2 −1
| @@ -219,7 +219,7 @@ | ||
| 219 | 219 | - `topP`: The cumulative probability for nucleus sampling. |
| 220 | 220 | - `topK`: Maximum number of tokens considered at each step. |
| 221 | 221 | - `stop`: An array of stop tokens that will terminate the completion. |
| 222 | - - `reasoning`: Boolean to enable thinking/reasoning for Anthropic Claude 3.7+ models. | |
| 222 | + - `reasoning`: Boolean to enable thinking/reasoning for Anthropic Claude 3.7+ and some Ollama models. | |
| 223 | 223 | - `reasoningBudgetTokens`: Budget tokens for thinking/reasoning in Anthropic Claude 3.7+ models. |
| 224 | 224 | |
| 225 | 225 | - `requestOptions`: HTTP request options specific to the model. |
| @@ -251,6 +251,7 @@ | ||
| 251 | 251 | - `modelTimeout`: Model timeout for autocomplete requests in milliseconds. |
| 252 | 252 | - `maxSuffixPercentage`: Maximum percentage of prompt allocated for suffix. |
| 253 | 253 | - `prefixPercentage`: Percentage of input allocated for prefix. |
| 254 | + - `transform`: If `false`, disables trimming of multiline completions. Defaults to `true`. Useful for models that generate better multiline completions without transformations. | |
| 254 | 255 | - `template`: Custom template for autocomplete using Mustache syntax. You can use the `{{{ prefix }}}`, `{{{ suffix }}}`, `{{{ filename }}}`, `{{{ reponame }}}`, and `{{{ language }}}` variables. |
| 255 | 256 | - `onlyMyCode`: Only includes code within the repository for context. |
| 256 | 257 | - `useCache`: If `true`, enables caching for completions. |
modified docs/reference/json-reference.mdx +1 −5
| @@ -191,7 +191,7 @@ | ||
| 191 | 191 | - `keepAlive`: For Ollama, this parameter sets the number of seconds to keep the model loaded after the last request, unloading it from memory if inactive (default: `1800` seconds, or 30 minutes). |
| 192 | 192 | - `numGpu`: For Ollama, this parameter overrides the number of gpu layers that will be used to load the model into VRAM. |
| 193 | 193 | - `useMmap`: For Ollama, this parameter allows the model to be mapped into memory. If disabled can enhance response time on low end devices but will slow down the stream. |
| 194 | -- `reasoning`: Enables thinking/reasoning for Anthropic Claude 3.7+ models. | |
| 194 | +- `reasoning`: Enables thinking/reasoning for Anthropic Claude 3.7+ and some Ollama models. | |
| 195 | 195 | - `reasoningBudgetTokens`: Sets budget tokens for thinking/reasoning in Anthropic Claude 3.7+ models. |
| 196 | 196 | |
| 197 | 197 | Example |
| @@ -485,8 +485,6 @@ | ||
| 485 | 485 | - `applyCodeBlock`: Model title for applying code blocks. |
| 486 | 486 | - `repoMapFileSelection`: Model title for repo map selections. |
| 487 | 487 | |
| 488 | - | |
| 489 | - | |
| 490 | 488 | - `modelContextProtocolServers`: See [Model Context Protocol](/customize/deep-dives/mcp) |
| 491 | 489 | |
| 492 | 490 | Example |
| @@ -540,5 +538,3 @@ | ||
| 540 | 538 | - `codeWrap` |
| 541 | 539 | - `displayRawMarkdown` |
| 542 | 540 | - `showChatScrollbar` |
| 543 | - | |
| 544 | - |
modified extensions/cli/package-lock.json +0 −0
Not shown: the file is larger than the hub shows, or this page holds as much as it shows. View the file.
modified extensions/cli/package.json +1 −0
| @@ -118,6 +118,7 @@ | ||
| 118 | 118 | "open": "^10.1.0", |
| 119 | 119 | "posthog-node": "^5.6.0", |
| 120 | 120 | "prettier": "^3.6.2", |
| 121 | + "prettier-plugin-tailwindcss": "^0.6.14", | |
| 121 | 122 | "react": "^19.1.0", |
| 122 | 123 | "readline-sync": "^1.4.10", |
| 123 | 124 | "semantic-release": "^24.2.7", |
modified extensions/cli/src/__mocks__/config.ts +1 −2
| @@ -13,5 +13,4 @@ | ||
| 13 | 13 | ) => [any, any] |
| 14 | 14 | >(); |
| 15 | 15 | export const getModel = vi.fn<(config: any, modelName: string) => any>(); |
| 16 | -export const createLlmApi = | |
| 17 | - vi.fn<(modelConfig: any, authConfig: any, orgScopeId?: string) => any>(); | |
| 16 | +export const createLlmApi = vi.fn<(model: any, authConfig: any) => any>(); |
modified extensions/cli/src/compaction.ts +3 −1
| @@ -28,6 +28,7 @@ | ||
| 28 | 28 | * @param model The model configuration |
| 29 | 29 | * @param llmApi The LLM API instance |
| 30 | 30 | * @param callbacks Optional callbacks for streaming updates |
| 31 | + * @param abortController Optional abort controller for cancellation | |
| 31 | 32 | * @returns The compacted history with compaction index |
| 32 | 33 | */ |
| 33 | 34 | export async function compactChatHistory( |
| @@ -35,6 +36,7 @@ | ||
| 35 | 36 | model: ModelConfig, |
| 36 | 37 | llmApi: BaseLlmApi, |
| 37 | 38 | callbacks?: CompactionCallbacks, |
| 39 | + abortController?: AbortController, | |
| 38 | 40 | ): Promise<CompactionResult> { |
| 39 | 41 | // Create a prompt to summarize the conversation |
| 40 | 42 | const compactionPrompt: ChatHistoryItem = { |
| @@ -81,7 +83,7 @@ | ||
| 81 | 83 | } |
| 82 | 84 | |
| 83 | 85 | // Stream the compaction response (service drives updates; this collects content locally) |
| 84 | - const controller = new AbortController(); | |
| 86 | + const controller = abortController || new AbortController(); | |
| 85 | 87 | |
| 86 | 88 | let compactionContent = ""; |
| 87 | 89 | const streamCallbacks: StreamCallbacks = { |
modified extensions/cli/src/config.ts +34 −22
| @@ -19,25 +19,14 @@ | ||
| 19 | 19 | import { env } from "./env.js"; |
| 20 | 20 | import { MCPService } from "./services/MCPService.js"; |
| 21 | 21 | |
| 22 | -export function getLlmApi( | |
| 23 | - assistant: AssistantUnrolled, | |
| 24 | - authConfig: AuthConfig, | |
| 25 | -): [BaseLlmApi, ModelConfig] { | |
| 26 | - if (!assistant.models || assistant.models.length === 0) { | |
| 27 | - throw new Error("No models found in the configured assistant"); | |
| 28 | - } | |
| 29 | - | |
| 30 | - const model = assistant.models?.find( | |
| 31 | - (model) => | |
| 32 | - model?.roles?.includes("chat") || (model && model.roles === undefined), | |
| 33 | - ); | |
| 34 | - | |
| 35 | - if (!model) { | |
| 36 | - throw new Error( | |
| 37 | - "No models with the chat role found in the configured assistant", | |
| 38 | - ); | |
| 39 | - } | |
| 40 | - | |
| 22 | +/** | |
| 23 | + * Creates an LLM API instance from a ModelConfig and auth configuration | |
| 24 | + * Handles special logic for continue-proxy provider and constructs the API | |
| 25 | + */ | |
| 26 | +export function createLlmApi( | |
| 27 | + model: ModelConfig, | |
| 28 | + authConfig: AuthConfig | null, | |
| 29 | +): BaseLlmApi | null { | |
| 41 | 30 | const accessToken = getAccessToken(authConfig); |
| 42 | 31 | const organizationId = getOrganizationId(authConfig); |
| 43 | 32 | |
| @@ -50,9 +39,10 @@ | ||
| 50 | 39 | apiKey: accessToken ?? undefined, |
| 51 | 40 | env: { |
| 52 | 41 | apiKeyLocation: (model as any).apiKeyLocation, |
| 53 | - // envSecretLocations: model.env, | |
| 54 | 42 | orgScopeId: organizationId, |
| 55 | - proxyUrl: undefined, // TODO | |
| 43 | + proxyUrl: | |
| 44 | + (model as { onPremProxyUrl: string | undefined }) | |
| 45 | + .onPremProxyUrl ?? undefined, | |
| 56 | 46 | }, |
| 57 | 47 | } |
| 58 | 48 | : { |
| @@ -63,7 +53,29 @@ | ||
| 63 | 53 | env: model.env, |
| 64 | 54 | }; |
| 65 | 55 | |
| 66 | - const llmApi = constructLlmApi(config); | |
| 56 | + return constructLlmApi(config) ?? null; | |
| 57 | +} | |
| 58 | + | |
| 59 | +export function getLlmApi( | |
| 60 | + assistant: AssistantUnrolled, | |
| 61 | + authConfig: AuthConfig, | |
| 62 | +): [BaseLlmApi, ModelConfig] { | |
| 63 | + if (!assistant.models || assistant.models.length === 0) { | |
| 64 | + throw new Error("No models found in the configured assistant"); | |
| 65 | + } | |
| 66 | + | |
| 67 | + const model = assistant.models?.find( | |
| 68 | + (model) => | |
| 69 | + model?.roles?.includes("chat") || (model && model.roles === undefined), | |
| 70 | + ); | |
| 71 | + | |
| 72 | + if (!model) { | |
| 73 | + throw new Error( | |
| 74 | + "No models with the chat role found in the configured assistant", | |
| 75 | + ); | |
| 76 | + } | |
| 77 | + | |
| 78 | + const llmApi = createLlmApi(model, authConfig); | |
| 67 | 79 | |
| 68 | 80 | if (!llmApi) { |
| 69 | 81 | throw new Error( |
modified extensions/cli/src/services/ModelService.test.ts +10 −30
| @@ -1,9 +1,7 @@ | ||
| 1 | 1 | import { AssistantUnrolled, ModelConfig } from "@continuedev/config-yaml"; |
| 2 | -import * as openaiAdapters from "@continuedev/openai-adapters"; | |
| 3 | 2 | import { describe, expect, beforeEach, vi, test } from "vitest"; |
| 4 | 3 | |
| 5 | 4 | // Mock dependencies before imports |
| 6 | -vi.mock("@continuedev/openai-adapters"); | |
| 7 | 5 | vi.mock("../config.js"); |
| 8 | 6 | vi.mock("../auth/workos.js"); |
| 9 | 7 | |
| @@ -81,9 +79,7 @@ | ||
| 81 | 79 | |
| 82 | 80 | test("should initialize with persisted model if valid", async () => { |
| 83 | 81 | vi.mocked(workos.getModelName).mockReturnValue("Claude 3"); |
| 84 | - vi.mocked(openaiAdapters.constructLlmApi).mockReturnValue( | |
| 85 | - mockLlmApi as any, | |
| 86 | - ); | |
| 82 | + vi.mocked(config.createLlmApi).mockReturnValue(mockLlmApi as any); | |
| 87 | 83 | |
| 88 | 84 | const state = await service.initialize(mockAssistant, mockAuthConfig); |
| 89 | 85 | |
| @@ -152,9 +148,7 @@ | ||
| 152 | 148 | await service.initialize(mockAssistant, mockAuthConfig); |
| 153 | 149 | |
| 154 | 150 | const newLlmApi = { complete: vi.fn(), stream: vi.fn() }; |
| 155 | - vi.mocked(openaiAdapters.constructLlmApi).mockReturnValue( | |
| 156 | - newLlmApi as any, | |
| 157 | - ); | |
| 151 | + vi.mocked(config.createLlmApi).mockReturnValue(newLlmApi as any); | |
| 158 | 152 | |
| 159 | 153 | const state = await service.switchModel(1); |
| 160 | 154 | |
| @@ -204,24 +198,14 @@ | ||
| 204 | 198 | ]); |
| 205 | 199 | await service.initialize(mockAssistant, mockAuthConfig); |
| 206 | 200 | |
| 207 | - vi.mocked(workos.getAccessToken).mockReturnValue("proxy-token"); | |
| 208 | - vi.mocked(workos.getOrganizationId).mockReturnValue("org-123"); | |
| 209 | - vi.mocked(openaiAdapters.constructLlmApi).mockReturnValue( | |
| 210 | - mockLlmApi as any, | |
| 211 | - ); | |
| 201 | + vi.mocked(config.createLlmApi).mockReturnValue(mockLlmApi as any); | |
| 212 | 202 | |
| 213 | 203 | await service.switchModel(0); |
| 214 | 204 | |
| 215 | - expect(vi.mocked(openaiAdapters.constructLlmApi)).toHaveBeenCalledWith({ | |
| 216 | - provider: "continue-proxy", | |
| 217 | - apiBase: "https://proxy.continue.dev", | |
| 218 | - apiKey: "proxy-token", | |
| 219 | - env: { | |
| 220 | - apiKeyLocation: "env.PROXY_KEY", | |
| 221 | - orgScopeId: "org-123", | |
| 222 | - proxyUrl: undefined, | |
| 223 | - }, | |
| 224 | - }); | |
| 205 | + expect(vi.mocked(config.createLlmApi)).toHaveBeenCalledWith( | |
| 206 | + proxyModel, | |
| 207 | + mockAuthConfig, | |
| 208 | + ); | |
| 225 | 209 | }); |
| 226 | 210 | }); |
| 227 | 211 | |
| @@ -292,9 +276,7 @@ | ||
| 292 | 276 | |
| 293 | 277 | expect(service.getCurrentModelIndex()).toBe(0); |
| 294 | 278 | |
| 295 | - vi.mocked(openaiAdapters.constructLlmApi).mockReturnValue( | |
| 296 | - mockLlmApi as any, | |
| 297 | - ); | |
| 279 | + vi.mocked(config.createLlmApi).mockReturnValue(mockLlmApi as any); | |
| 298 | 280 | await service.switchModel(1); |
| 299 | 281 | expect(service.getCurrentModelIndex()).toBe(1); |
| 300 | 282 | }); |
| @@ -392,9 +374,7 @@ | ||
| 392 | 374 | service.on("stateChanged", listener); |
| 393 | 375 | |
| 394 | 376 | const newLlmApi = { complete: vi.fn(), stream: vi.fn() }; |
| 395 | - vi.mocked(openaiAdapters.constructLlmApi).mockReturnValue( | |
| 396 | - newLlmApi as any, | |
| 397 | - ); | |
| 377 | + vi.mocked(config.createLlmApi).mockReturnValue(newLlmApi as any); | |
| 398 | 378 | await service.switchModel(1); |
| 399 | 379 | |
| 400 | 380 | expect(listener).toHaveBeenCalledWith( |
| @@ -419,7 +399,7 @@ | ||
| 419 | 399 | const errorListener = vi.fn(); |
| 420 | 400 | service.on("error", errorListener); |
| 421 | 401 | |
| 422 | - vi.mocked(openaiAdapters.constructLlmApi).mockReturnValue(null as any); | |
| 402 | + vi.mocked(config.createLlmApi).mockReturnValue(null as any); | |
| 423 | 403 | |
| 424 | 404 | await expect(service.switchModel(1)).rejects.toThrow( |
| 425 | 405 | "Failed to initialize LLM", |
modified extensions/cli/src/services/ModelService.ts +5 −59
| @@ -1,13 +1,7 @@ | ||
| 1 | 1 | import { AssistantUnrolled, ModelConfig } from "@continuedev/config-yaml"; |
| 2 | -import { constructLlmApi, LLMConfig } from "@continuedev/openai-adapters"; | |
| 3 | - | |
| 4 | -import { | |
| 5 | - AuthConfig, | |
| 6 | - getAccessToken, | |
| 7 | - getModelName, | |
| 8 | - getOrganizationId, | |
| 9 | -} from "../auth/workos.js"; | |
| 10 | -import { getLlmApi } from "../config.js"; | |
| 2 | + | |
| 3 | +import { AuthConfig, getModelName } from "../auth/workos.js"; | |
| 4 | +import { createLlmApi, getLlmApi } from "../config.js"; | |
| 11 | 5 | import { logger } from "../util/logger.js"; |
| 12 | 6 | |
| 13 | 7 | import { BaseService, ServiceWithDependencies } from "./BaseService.js"; |
| @@ -89,31 +83,7 @@ | ||
| 89 | 83 | name: (selectedModel as any).name || "unnamed", |
| 90 | 84 | }); |
| 91 | 85 | |
| 92 | - const accessToken = getAccessToken(authConfig); | |
| 93 | - const organizationId = getOrganizationId(authConfig); | |
| 94 | - | |
| 95 | - const config: LLMConfig = | |
| 96 | - selectedModel.provider === "continue-proxy" | |
| 97 | - ? { | |
| 98 | - provider: selectedModel.provider, | |
| 99 | - requestOptions: selectedModel.requestOptions, | |
| 100 | - apiBase: selectedModel.apiBase, | |
| 101 | - apiKey: accessToken ?? undefined, | |
| 102 | - env: { | |
| 103 | - apiKeyLocation: (selectedModel as any).apiKeyLocation, | |
| 104 | - orgScopeId: organizationId, | |
| 105 | - proxyUrl: (selectedModel as any).onPremProxyUrl ?? undefined, | |
| 106 | - }, | |
| 107 | - } | |
| 108 | - : { | |
| 109 | - provider: selectedModel.provider as any, | |
| 110 | - apiKey: selectedModel.apiKey, | |
| 111 | - apiBase: selectedModel.apiBase, | |
| 112 | - requestOptions: selectedModel.requestOptions, | |
| 113 | - env: selectedModel.env, | |
| 114 | - }; | |
| 115 | - | |
| 116 | - const llmApi = constructLlmApi(config); | |
| 86 | + const llmApi = createLlmApi(selectedModel, authConfig); | |
| 117 | 87 | |
| 118 | 88 | if (!llmApi) { |
| 119 | 89 | throw new Error("Failed to initialize LLM with persisted model"); |
| @@ -288,31 +258,7 @@ | ||
| 288 | 258 | }); |
| 289 | 259 | |
| 290 | 260 | try { |
| 291 | - const accessToken = getAccessToken(authConfig); | |
| 292 | - const organizationId = getOrganizationId(authConfig); | |
| 293 | - | |
| 294 | - const config: LLMConfig = | |
| 295 | - selectedModel.provider === "continue-proxy" | |
| 296 | - ? { | |
| 297 | - provider: selectedModel.provider, | |
| 298 | - requestOptions: selectedModel.requestOptions, | |
| 299 | - apiBase: selectedModel.apiBase, | |
| 300 | - apiKey: accessToken ?? undefined, | |
| 301 | - env: { | |
| 302 | - apiKeyLocation: (selectedModel as any).apiKeyLocation, | |
| 303 | - orgScopeId: organizationId, | |
| 304 | - proxyUrl: (selectedModel as any).onPremProxyUrl ?? undefined, | |
| 305 | - }, | |
| 306 | - } | |
| 307 | - : { | |
| 308 | - provider: selectedModel.provider as any, | |
| 309 | - apiKey: selectedModel.apiKey, | |
| 310 | - apiBase: selectedModel.apiBase, | |
| 311 | - requestOptions: selectedModel.requestOptions, | |
| 312 | - env: selectedModel.env, | |
| 313 | - }; | |
| 314 | - | |
| 315 | - const llmApi = constructLlmApi(config); | |
| 261 | + const llmApi = createLlmApi(selectedModel, authConfig); | |
| 316 | 262 | |
| 317 | 263 | if (!llmApi) { |
| 318 | 264 | throw new Error("Failed to initialize LLM with selected model"); |
added extensions/cli/src/stream/messageQueue.test.ts +62 −0
| @@ -0,0 +1,62 @@ | ||
| 1 | +import { beforeEach, describe, expect, it, vi } from "vitest"; | |
| 2 | + | |
| 3 | +vi.mock("../util/logger.js", () => ({ | |
| 4 | + logger: { | |
| 5 | + debug: vi.fn(), | |
| 6 | + info: vi.fn(), | |
| 7 | + warn: vi.fn(), | |
| 8 | + error: vi.fn(), | |
| 9 | + setLevel: vi.fn(), | |
| 10 | + configureHeadlessMode: vi.fn(), | |
| 11 | + getLogPath: vi.fn(), | |
| 12 | + getSessionId: vi.fn(), | |
| 13 | + }, | |
| 14 | +})); | |
| 15 | + | |
| 16 | +import { messageQueue } from "./messageQueue.js"; | |
| 17 | + | |
| 18 | +describe("messageQueue", () => { | |
| 19 | + beforeEach(() => { | |
| 20 | + // Drain any leftover items from previous tests | |
| 21 | + while (messageQueue.getAllQueuedMessages()) {} | |
| 22 | + }); | |
| 23 | + | |
| 24 | + it("enqueues and emits messageQueued", async () => { | |
| 25 | + const event = new Promise<any>((resolve) => | |
| 26 | + messageQueue.once("messageQueued", resolve), | |
| 27 | + ); | |
| 28 | + | |
| 29 | + const ok = await messageQueue.enqueueMessage("hello world"); | |
| 30 | + expect(ok).toBe(true); | |
| 31 | + expect(messageQueue.getQueueLength()).toBe(1); | |
| 32 | + | |
| 33 | + const queued = await event; | |
| 34 | + expect(queued.message).toBe("hello world"); | |
| 35 | + }); | |
| 36 | + | |
| 37 | + it("combines messages, merges image maps, writes history, and clears queue", async () => { | |
| 38 | + const bufA = Buffer.from("A"); | |
| 39 | + const bufB = Buffer.from("B"); | |
| 40 | + | |
| 41 | + const img1 = new Map<string, Buffer>([["a", bufA]]); | |
| 42 | + const img2 = new Map<string, Buffer>([["b", bufB]]); | |
| 43 | + | |
| 44 | + const history = { addEntry: vi.fn() } as any; | |
| 45 | + | |
| 46 | + await messageQueue.enqueueMessage("one", img1); | |
| 47 | + await messageQueue.enqueueMessage("two", img2, history); | |
| 48 | + | |
| 49 | + const combined = messageQueue.getAllQueuedMessages(); | |
| 50 | + expect(combined).toBeTruthy(); | |
| 51 | + expect(combined!.message).toBe("one\ntwo"); | |
| 52 | + expect(combined!.imageMap).toBeDefined(); | |
| 53 | + expect(combined!.imageMap!.get("a")).toEqual(bufA); | |
| 54 | + expect(combined!.imageMap!.get("b")).toEqual(bufB); | |
| 55 | + | |
| 56 | + // queue should be cleared | |
| 57 | + expect(messageQueue.getQueueLength()).toBe(0); | |
| 58 | + | |
| 59 | + // input history should receive the combined message | |
| 60 | + expect(history.addEntry).toHaveBeenCalledWith("one\ntwo"); | |
| 61 | + }); | |
| 62 | +}); |
added extensions/cli/src/stream/messageQueue.ts +94 −0
| @@ -0,0 +1,94 @@ | ||
| 1 | +import { EventEmitter } from "events"; | |
| 2 | + | |
| 3 | +import { InputHistory } from "../util/inputHistory.js"; | |
| 4 | +import { logger } from "../util/logger.js"; | |
| 5 | + | |
| 6 | +export interface QueuedMessage { | |
| 7 | + message: string; | |
| 8 | + imageMap?: Map<string, Buffer>; | |
| 9 | + timestamp: number; | |
| 10 | +} | |
| 11 | + | |
| 12 | +export interface MessageProcessor { | |
| 13 | + (message: string, imageMap?: Map<string, Buffer>): Promise<void>; | |
| 14 | +} | |
| 15 | + | |
| 16 | +/** | |
| 17 | + * A queue to store messages that need to be processed later | |
| 18 | + */ | |
| 19 | +class MessageQueue extends EventEmitter { | |
| 20 | + private queue: QueuedMessage[] = []; | |
| 21 | + private inputHistory: InputHistory | undefined; | |
| 22 | + | |
| 23 | + constructor() { | |
| 24 | + super(); | |
| 25 | + } | |
| 26 | + | |
| 27 | + async enqueueMessage( | |
| 28 | + message: string, | |
| 29 | + imageMap?: Map<string, Buffer>, | |
| 30 | + inputHistory?: InputHistory, | |
| 31 | + ): Promise<boolean> { | |
| 32 | + this.inputHistory = inputHistory; | |
| 33 | + | |
| 34 | + const queuedMessage: QueuedMessage = { | |
| 35 | + message, | |
| 36 | + imageMap, | |
| 37 | + timestamp: Date.now(), | |
| 38 | + }; | |
| 39 | + | |
| 40 | + this.queue.push(queuedMessage); | |
| 41 | + logger.debug("MessageQueue: Message queued", { | |
| 42 | + queueLength: this.queue.length, | |
| 43 | + }); | |
| 44 | + | |
| 45 | + // Emit event for UI to show the queued message | |
| 46 | + this.emit("messageQueued", queuedMessage); | |
| 47 | + | |
| 48 | + return true; | |
| 49 | + } | |
| 50 | + | |
| 51 | + public getAllQueuedMessages() { | |
| 52 | + if (this.queue.length === 0) return undefined; | |
| 53 | + | |
| 54 | + // Combine all queued messages into one | |
| 55 | + const combinedMessage = this.queue.map((msg) => msg.message).join("\n"); | |
| 56 | + const combinedImageMap = new Map<string, Buffer>(); | |
| 57 | + | |
| 58 | + // Merge all image maps | |
| 59 | + for (const queuedMsg of this.queue) { | |
| 60 | + if (queuedMsg.imageMap) { | |
| 61 | + for (const [key, value] of queuedMsg.imageMap) { | |
| 62 | + combinedImageMap.set(key, value); | |
| 63 | + } | |
| 64 | + } | |
| 65 | + } | |
| 66 | + | |
| 67 | + const result = { | |
| 68 | + message: combinedMessage, | |
| 69 | + imageMap: combinedImageMap.size > 0 ? combinedImageMap : undefined, | |
| 70 | + timestamp: Date.now(), | |
| 71 | + }; | |
| 72 | + | |
| 73 | + // Add to input history and clear the queue | |
| 74 | + this.inputHistory?.addEntry(combinedMessage); | |
| 75 | + this.queue = []; | |
| 76 | + | |
| 77 | + logger.debug("MessageQueue: All messages dequeued and combined", { | |
| 78 | + combinedLength: combinedMessage.length, | |
| 79 | + queueLength: this.queue.length, | |
| 80 | + }); | |
| 81 | + | |
| 82 | + return result; | |
| 83 | + } | |
| 84 | + | |
| 85 | + public getLatestMessage() { | |
| 86 | + return this.getAllQueuedMessages(); | |
| 87 | + } | |
| 88 | + | |
| 89 | + getQueueLength(): number { | |
| 90 | + return this.queue.length; | |
| 91 | + } | |
| 92 | +} | |
| 93 | + | |
| 94 | +export const messageQueue = new MessageQueue(); |
modified extensions/cli/src/stream/streamChatResponse.autoCompaction.test.ts +1 −1
| @@ -147,7 +147,7 @@ | ||
| 147 | 147 | "Auto-compacting...", |
| 148 | 148 | ); |
| 149 | 149 | expect(mockCallbacks.onSystemMessage).toHaveBeenCalledWith( |
| 150 | - "✓ Chat history auto-compacted successfully.", | |
| 150 | + "Chat history auto-compacted successfully.", | |
| 151 | 151 | ); |
| 152 | 152 | |
| 153 | 153 | expect(result).toEqual({ |
modified extensions/cli/src/stream/streamChatResponse.autoCompaction.ts +1 −1
| @@ -55,7 +55,7 @@ | ||
| 55 | 55 | ) { |
| 56 | 56 | if (isHeadless) return; |
| 57 | 57 | |
| 58 | - const successMessage = "✓ Chat history auto-compacted successfully."; | |
| 58 | + const successMessage = "Chat history auto-compacted successfully."; | |
| 59 | 59 | |
| 60 | 60 | if (callbacks?.onSystemMessage) { |
| 61 | 61 | callbacks.onSystemMessage(successMessage); |
modified extensions/cli/src/ui/TUIChat.tsx +22 −15
| @@ -1,4 +1,4 @@ | ||
| 1 | -import { Box, Text } from "ink"; | |
| 1 | +import { Box } from "ink"; | |
| 2 | 2 | import React, { |
| 3 | 3 | useCallback, |
| 4 | 4 | useEffect, |
| @@ -17,6 +17,7 @@ | ||
| 17 | 17 | } from "../services/types.js"; |
| 18 | 18 | import { logger } from "../util/logger.js"; |
| 19 | 19 | |
| 20 | +import { ActionStatus } from "./components/ActionStatus.js"; | |
| 20 | 21 | import { BottomStatusBar } from "./components/BottomStatusBar.js"; |
| 21 | 22 | import { ResourceDebugBar } from "./components/ResourceDebugBar.js"; |
| 22 | 23 | import { ScreenContent } from "./components/ScreenContent.js"; |
| @@ -31,8 +32,6 @@ | ||
| 31 | 32 | useLoginHandlers, |
| 32 | 33 | useSelectors, |
| 33 | 34 | } from "./hooks/useTUIChatHooks.js"; |
| 34 | -import { LoadingAnimation } from "./LoadingAnimation.js"; | |
| 35 | -import { Timer } from "./Timer.js"; | |
| 36 | 35 | |
| 37 | 36 | interface TUIChatProps { |
| 38 | 37 | // Remote mode props |
| @@ -185,9 +184,12 @@ | ||
| 185 | 184 | setChatHistory, |
| 186 | 185 | isWaitingForResponse, |
| 187 | 186 | responseStartTime, |
| 187 | + isCompacting, | |
| 188 | + compactionStartTime, | |
| 188 | 189 | inputMode, |
| 189 | 190 | activePermissionRequest, |
| 190 | 191 | wasInterrupted, |
| 192 | + queuedMessages, | |
| 191 | 193 | handleUserMessage, |
| 192 | 194 | handleInterrupt, |
| 193 | 195 | handleFileAttached, |
| @@ -282,6 +284,7 @@ | ||
| 282 | 284 | model={services.model?.model || undefined} |
| 283 | 285 | mcpService={services.mcp?.mcpService || undefined} |
| 284 | 286 | chatHistory={chatHistory} |
| 287 | + queuedMessages={queuedMessages} | |
| 285 | 288 | renderMessage={renderMessage} |
| 286 | 289 | refreshTrigger={staticRefreshTrigger} |
| 287 | 290 | /> |
| @@ -290,18 +293,21 @@ | ||
| 290 | 293 | {/* Fixed bottom section */} |
| 291 | 294 | <Box flexDirection="column" flexShrink={0}> |
| 292 | 295 | {/* Status */} |
| 293 | - {isWaitingForResponse && responseStartTime && ( | |
| 294 | - <Box paddingX={1} flexDirection="row" gap={1}> | |
| 295 | - <LoadingAnimation visible={isWaitingForResponse} /> | |
| 296 | - <Text key="loading-start" color="gray"> | |
| 297 | - ( | |
| 298 | - </Text> | |
| 299 | - <Timer startTime={responseStartTime} /> | |
| 300 | - <Text key="loading-end" color="gray"> | |
| 301 | - • esc to interrupt ) | |
| 302 | - </Text> | |
| 303 | - </Box> | |
| 304 | - )} | |
| 296 | + <ActionStatus | |
| 297 | + visible={isWaitingForResponse && !!responseStartTime} | |
| 298 | + startTime={responseStartTime || 0} | |
| 299 | + message="" | |
| 300 | + showSpinner={true} | |
| 301 | + /> | |
| 302 | + | |
| 303 | + {/* Compaction Status */} | |
| 304 | + <ActionStatus | |
| 305 | + visible={isCompacting && !!compactionStartTime} | |
| 306 | + startTime={compactionStartTime || 0} | |
| 307 | + message="Compacting history" | |
| 308 | + showSpinner={true} | |
| 309 | + loadingColor="grey" | |
| 310 | + /> | |
| 305 | 311 | |
| 306 | 312 | {/* All screen-specific content */} |
| 307 | 313 | <ScreenContent |
| @@ -318,6 +324,7 @@ | ||
| 318 | 324 | handleToolPermissionResponse={handleToolPermissionResponse} |
| 319 | 325 | handleUserMessage={handleUserMessage} |
| 320 | 326 | isWaitingForResponse={isWaitingForResponse} |
| 327 | + isCompacting={isCompacting} | |
| 321 | 328 | inputMode={inputMode} |
| 322 | 329 | handleInterrupt={handleInterrupt} |
| 323 | 330 | handleFileAttached={handleFileAttached} |
modified extensions/cli/src/ui/UserInput.tsx +20 −15
| @@ -9,6 +9,7 @@ | ||
| 9 | 9 | import type { FileIndexServiceState } from "../services/FileIndexService.js"; |
| 10 | 10 | import { SERVICE_NAMES, serviceContainer } from "../services/index.js"; |
| 11 | 11 | import { modeService } from "../services/ModeService.js"; |
| 12 | +import { messageQueue } from "../stream/messageQueue.js"; | |
| 12 | 13 | import { InputHistory } from "../util/inputHistory.js"; |
| 13 | 14 | |
| 14 | 15 | import { FileSearchUI } from "./FileSearchUI.js"; |
| @@ -94,6 +95,7 @@ | ||
| 94 | 95 | interface UserInputProps { |
| 95 | 96 | onSubmit: (message: string, imageMap?: Map<string, Buffer>) => void; |
| 96 | 97 | isWaitingForResponse: boolean; |
| 98 | + isCompacting?: boolean; | |
| 97 | 99 | inputMode: boolean; |
| 98 | 100 | onInterrupt?: () => void; |
| 99 | 101 | assistant?: AssistantConfig; |
| @@ -109,6 +111,7 @@ | ||
| 109 | 111 | const UserInput: React.FC<UserInputProps> = ({ |
| 110 | 112 | onSubmit, |
| 111 | 113 | isWaitingForResponse, |
| 114 | + isCompacting = false, | |
| 112 | 115 | inputMode, |
| 113 | 116 | onInterrupt, |
| 114 | 117 | assistant, |
| @@ -515,7 +518,7 @@ | ||
| 515 | 518 | } |
| 516 | 519 | |
| 517 | 520 | // Normal Enter behavior - submit if there's content |
| 518 | - if ((textBuffer.text.trim() || wasInterrupted) && !isWaitingForResponse) { | |
| 521 | + if (textBuffer.text.trim() || wasInterrupted) { | |
| 519 | 522 | // Get images before expanding paste blocks |
| 520 | 523 | const imageMap = textBuffer.getAllImages(); |
| 521 | 524 | |
| @@ -523,14 +526,19 @@ | ||
| 523 | 526 | textBuffer.expandAllPasteBlocks(); |
| 524 | 527 | const submittedText = textBuffer.text.trim(); |
| 525 | 528 | |
| 526 | - // Only add to history if there's actual text (not when resuming) | |
| 527 | - if (submittedText) { | |
| 529 | + if (isWaitingForResponse || isCompacting) { | |
| 530 | + // Process message later when LLM has responded or compaction is complete | |
| 531 | + void messageQueue.enqueueMessage( | |
| 532 | + submittedText, | |
| 533 | + imageMap, | |
| 534 | + inputHistory, | |
| 535 | + ); | |
| 536 | + } else { | |
| 537 | + // Submit with images | |
| 528 | 538 | inputHistory.addEntry(submittedText); |
| 539 | + onSubmit(submittedText, imageMap); | |
| 529 | 540 | } |
| 530 | 541 | |
| 531 | - // Submit with images | |
| 532 | - onSubmit(submittedText, imageMap); | |
| 533 | - | |
| 534 | 542 | textBuffer.clear(); |
| 535 | 543 | setInputText(""); |
| 536 | 544 | setCursorPosition(0); |
| @@ -570,6 +578,12 @@ | ||
| 570 | 578 | return true; |
| 571 | 579 | } |
| 572 | 580 | |
| 581 | + // Handle escape key to interrupt compaction (higher priority) | |
| 582 | + if (isCompacting && onInterrupt) { | |
| 583 | + onInterrupt(); | |
| 584 | + return true; | |
| 585 | + } | |
| 586 | + | |
| 573 | 587 | // Handle escape key to interrupt streaming |
| 574 | 588 | if (isWaitingForResponse && onInterrupt) { |
| 575 | 589 | onInterrupt(); |
| @@ -647,15 +661,6 @@ | ||
| 647 | 661 | return; |
| 648 | 662 | } |
| 649 | 663 | |
| 650 | - // Allow typing during streaming, but block submission | |
| 651 | - if (!inputMode) { | |
| 652 | - // Block only Enter key submission during streaming | |
| 653 | - if (key.return && !key.shift) { | |
| 654 | - return; | |
| 655 | - } | |
| 656 | - // Allow all other input (typing, navigation, etc.) | |
| 657 | - } | |
| 658 | - | |
| 659 | 664 | // Handle slash command navigation |
| 660 | 665 | if (showSlashCommands) { |
| 661 | 666 | if (handleSlashCommandNavigation(key)) { |
added extensions/cli/src/ui/__tests__/TUIChat.actionStatus.test.tsx +214 −0
| @@ -0,0 +1,214 @@ | ||
| 1 | +import { render } from "ink-testing-library"; | |
| 2 | +import React from "react"; | |
| 3 | +import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; | |
| 4 | + | |
| 5 | +import { createUITestContext } from "../../test-helpers/ui-test-context.js"; | |
| 6 | +import { AppRoot } from "../AppRoot.js"; | |
| 7 | + | |
| 8 | +// Mock the useChat hook to control state | |
| 9 | +const mockUseChat = vi.fn(); | |
| 10 | + | |
| 11 | +vi.mock("../hooks/useChat.js", () => ({ | |
| 12 | + useChat: () => mockUseChat(), | |
| 13 | +})); | |
| 14 | + | |
| 15 | +describe("TUIChat - ActionStatus", () => { | |
| 16 | + let context: any; | |
| 17 | + | |
| 18 | + beforeEach(() => { | |
| 19 | + context = createUITestContext({ | |
| 20 | + allServicesReady: true, | |
| 21 | + serviceState: "ready", | |
| 22 | + }); | |
| 23 | + | |
| 24 | + // Default mock return value | |
| 25 | + mockUseChat.mockReturnValue({ | |
| 26 | + chatHistory: [], | |
| 27 | + setChatHistory: vi.fn(), | |
| 28 | + isWaitingForResponse: false, | |
| 29 | + responseStartTime: null, | |
| 30 | + isCompacting: false, | |
| 31 | + compactionStartTime: null, | |
| 32 | + inputMode: true, | |
| 33 | + attachedFiles: [], | |
| 34 | + activePermissionRequest: null, | |
| 35 | + wasInterrupted: false, | |
| 36 | + handleUserMessage: vi.fn(), | |
| 37 | + handleInterrupt: vi.fn(), | |
| 38 | + handleFileAttached: vi.fn(), | |
| 39 | + resetChatHistory: vi.fn(), | |
| 40 | + handleToolPermissionResponse: vi.fn(), | |
| 41 | + }); | |
| 42 | + }); | |
| 43 | + | |
| 44 | + afterEach(() => { | |
| 45 | + context.cleanup(); | |
| 46 | + vi.clearAllMocks(); | |
| 47 | + }); | |
| 48 | + | |
| 49 | + it("shows only response status when waiting for response", () => { | |
| 50 | + const responseStartTime = Date.now(); | |
| 51 | + | |
| 52 | + mockUseChat.mockReturnValue({ | |
| 53 | + chatHistory: [], | |
| 54 | + setChatHistory: vi.fn(), | |
| 55 | + isWaitingForResponse: true, | |
| 56 | + responseStartTime, | |
| 57 | + isCompacting: false, | |
| 58 | + compactionStartTime: null, | |
| 59 | + inputMode: false, | |
| 60 | + attachedFiles: [], | |
| 61 | + activePermissionRequest: null, | |
| 62 | + wasInterrupted: false, | |
| 63 | + handleUserMessage: vi.fn(), | |
| 64 | + handleInterrupt: vi.fn(), | |
| 65 | + handleFileAttached: vi.fn(), | |
| 66 | + resetChatHistory: vi.fn(), | |
| 67 | + handleToolPermissionResponse: vi.fn(), | |
| 68 | + }); | |
| 69 | + | |
| 70 | + const { lastFrame, unmount } = render(React.createElement(AppRoot, {})); | |
| 71 | + | |
| 72 | + try { | |
| 73 | + const frame = lastFrame(); | |
| 74 | + expect(frame).toBeDefined(); | |
| 75 | + | |
| 76 | + // Should show spinner/response indicator but not compaction message | |
| 77 | + expect(frame).toContain("esc to interrupt"); | |
| 78 | + expect(frame).not.toContain("Compacting history"); | |
| 79 | + } finally { | |
| 80 | + unmount(); | |
| 81 | + } | |
| 82 | + }); | |
| 83 | + | |
| 84 | + it("shows only compaction status when compacting", () => { | |
| 85 | + const compactionStartTime = Date.now(); | |
| 86 | + | |
| 87 | + mockUseChat.mockReturnValue({ | |
| 88 | + chatHistory: [], | |
| 89 | + setChatHistory: vi.fn(), | |
| 90 | + isWaitingForResponse: false, | |
| 91 | + responseStartTime: null, | |
| 92 | + isCompacting: true, | |
| 93 | + compactionStartTime, | |
| 94 | + inputMode: true, | |
| 95 | + attachedFiles: [], | |
| 96 | + activePermissionRequest: null, | |
| 97 | + wasInterrupted: false, | |
| 98 | + handleUserMessage: vi.fn(), | |
| 99 | + handleInterrupt: vi.fn(), | |
| 100 | + handleFileAttached: vi.fn(), | |
| 101 | + resetChatHistory: vi.fn(), | |
| 102 | + handleToolPermissionResponse: vi.fn(), | |
| 103 | + }); | |
| 104 | + | |
| 105 | + const { lastFrame, unmount } = render(React.createElement(AppRoot, {})); | |
| 106 | + | |
| 107 | + try { | |
| 108 | + const frame = lastFrame(); | |
| 109 | + expect(frame).toBeDefined(); | |
| 110 | + | |
| 111 | + // Should show compaction message but not spinner | |
| 112 | + expect(frame).toContain("Compacting history"); | |
| 113 | + expect(frame).toContain("esc to interrupt"); | |
| 114 | + } finally { | |
| 115 | + unmount(); | |
| 116 | + } | |
| 117 | + }); | |
| 118 | + | |
| 119 | + it("shows neither status when both states are false", () => { | |
| 120 | + mockUseChat.mockReturnValue({ | |
| 121 | + chatHistory: [], | |
| 122 | + setChatHistory: vi.fn(), | |
| 123 | + isWaitingForResponse: false, | |
| 124 | + responseStartTime: null, | |
| 125 | + isCompacting: false, | |
| 126 | + compactionStartTime: null, | |
| 127 | + inputMode: true, | |
| 128 | + attachedFiles: [], | |
| 129 | + activePermissionRequest: null, | |
| 130 | + wasInterrupted: false, | |
| 131 | + handleUserMessage: vi.fn(), | |
| 132 | + handleInterrupt: vi.fn(), | |
| 133 | + handleFileAttached: vi.fn(), | |
| 134 | + resetChatHistory: vi.fn(), | |
| 135 | + handleToolPermissionResponse: vi.fn(), | |
| 136 | + }); | |
| 137 | + | |
| 138 | + const { lastFrame, unmount } = render(React.createElement(AppRoot, {})); | |
| 139 | + | |
| 140 | + try { | |
| 141 | + const frame = lastFrame(); | |
| 142 | + expect(frame).toBeDefined(); | |
| 143 | + | |
| 144 | + // Should not show any status messages | |
| 145 | + expect(frame).not.toContain("Compacting history"); | |
| 146 | + // The basic UI should still be there | |
| 147 | + expect(frame).toContain("Ask anything"); | |
| 148 | + } finally { | |
| 149 | + unmount(); | |
| 150 | + } | |
| 151 | + }); | |
| 152 | + | |
| 153 | + it("handles state transitions correctly", () => { | |
| 154 | + const { lastFrame, rerender, unmount } = render( | |
| 155 | + React.createElement(AppRoot, {}), | |
| 156 | + ); | |
| 157 | + | |
| 158 | + // Start with compaction | |
| 159 | + const compactionStartTime = Date.now(); | |
| 160 | + mockUseChat.mockReturnValue({ | |
| 161 | + chatHistory: [], | |
| 162 | + setChatHistory: vi.fn(), | |
| 163 | + isWaitingForResponse: false, | |
| 164 | + responseStartTime: null, | |
| 165 | + isCompacting: true, | |
| 166 | + compactionStartTime, | |
| 167 | + inputMode: true, | |
| 168 | + attachedFiles: [], | |
| 169 | + activePermissionRequest: null, | |
| 170 | + wasInterrupted: false, | |
| 171 | + handleUserMessage: vi.fn(), | |
| 172 | + handleInterrupt: vi.fn(), | |
| 173 | + handleFileAttached: vi.fn(), | |
| 174 | + resetChatHistory: vi.fn(), | |
| 175 | + handleToolPermissionResponse: vi.fn(), | |
| 176 | + }); | |
| 177 | + | |
| 178 | + try { | |
| 179 | + rerender(React.createElement(AppRoot, {})); | |
| 180 | + | |
| 181 | + let frame = lastFrame(); | |
| 182 | + expect(frame).toContain("Compacting history"); | |
| 183 | + expect(frame).not.toContain("⠀⠁⠃⠇⠏⠟⠿⣿"); // No spinner chars when only compacting | |
| 184 | + | |
| 185 | + // Transition to response waiting | |
| 186 | + const responseStartTime = Date.now(); | |
| 187 | + mockUseChat.mockReturnValue({ | |
| 188 | + chatHistory: [], | |
| 189 | + setChatHistory: vi.fn(), | |
| 190 | + isWaitingForResponse: true, | |
| 191 | + responseStartTime, | |
| 192 | + isCompacting: false, | |
| 193 | + compactionStartTime: null, | |
| 194 | + inputMode: false, | |
| 195 | + attachedFiles: [], | |
| 196 | + activePermissionRequest: null, | |
| 197 | + wasInterrupted: false, | |
| 198 | + handleUserMessage: vi.fn(), | |
| 199 | + handleInterrupt: vi.fn(), | |
| 200 | + handleFileAttached: vi.fn(), | |
| 201 | + resetChatHistory: vi.fn(), | |
| 202 | + handleToolPermissionResponse: vi.fn(), | |
| 203 | + }); | |
| 204 | + | |
| 205 | + rerender(React.createElement(AppRoot, {})); | |
| 206 | + | |
| 207 | + frame = lastFrame(); | |
| 208 | + expect(frame).not.toContain("Compacting history"); | |
| 209 | + expect(frame).toContain("esc to interrupt"); | |
| 210 | + } finally { | |
| 211 | + unmount(); | |
| 212 | + } | |
| 213 | + }); | |
| 214 | +}); |
added extensions/cli/src/ui/__tests__/TUIChat.compactionCancellation.test.tsx +141 −0
| @@ -0,0 +1,141 @@ | ||
| 1 | +import { render } from "ink-testing-library"; | |
| 2 | +import React from "react"; | |
| 3 | +import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; | |
| 4 | + | |
| 5 | +import { createUITestContext } from "../../test-helpers/ui-test-context.js"; | |
| 6 | +import { AppRoot } from "../AppRoot.js"; | |
| 7 | + | |
| 8 | +// Mock the useChat hook to control state | |
| 9 | +const mockUseChat = vi.fn(); | |
| 10 | +const mockHandleInterrupt = vi.fn(); | |
| 11 | + | |
| 12 | +vi.mock("../hooks/useChat.js", () => ({ | |
| 13 | + useChat: () => mockUseChat(), | |
| 14 | +})); | |
| 15 | + | |
| 16 | +describe("TUIChat - Compaction Cancellation", () => { | |
| 17 | + let context: any; | |
| 18 | + | |
| 19 | + beforeEach(() => { | |
| 20 | + context = createUITestContext({ | |
| 21 | + allServicesReady: true, | |
| 22 | + serviceState: "ready", | |
| 23 | + }); | |
| 24 | + | |
| 25 | + // Reset the mock | |
| 26 | + mockHandleInterrupt.mockClear(); | |
| 27 | + }); | |
| 28 | + | |
| 29 | + afterEach(() => { | |
| 30 | + context.cleanup(); | |
| 31 | + vi.clearAllMocks(); | |
| 32 | + }); | |
| 33 | + | |
| 34 | + it("calls handleInterrupt when ESC is pressed during compaction", () => { | |
| 35 | + const compactionStartTime = Date.now(); | |
| 36 | + | |
| 37 | + mockUseChat.mockReturnValue({ | |
| 38 | + chatHistory: [], | |
| 39 | + setChatHistory: vi.fn(), | |
| 40 | + isWaitingForResponse: false, | |
| 41 | + responseStartTime: null, | |
| 42 | + isCompacting: true, | |
| 43 | + compactionStartTime, | |
| 44 | + inputMode: true, // Changed to true so ESC handling is active | |
| 45 | + attachedFiles: [], | |
| 46 | + activePermissionRequest: null, | |
| 47 | + wasInterrupted: false, | |
| 48 | + handleUserMessage: vi.fn(), | |
| 49 | + handleInterrupt: mockHandleInterrupt, | |
| 50 | + handleFileAttached: vi.fn(), | |
| 51 | + resetChatHistory: vi.fn(), | |
| 52 | + handleToolPermissionResponse: vi.fn(), | |
| 53 | + }); | |
| 54 | + | |
| 55 | + const { stdin, unmount } = render(React.createElement(AppRoot, {})); | |
| 56 | + | |
| 57 | + try { | |
| 58 | + // Give some time for the component to render and set up input handling | |
| 59 | + setTimeout(() => { | |
| 60 | + // Simulate ESC key press during compaction | |
| 61 | + stdin.write("\x1b"); // ESC key | |
| 62 | + | |
| 63 | + // The handleInterrupt should be called | |
| 64 | + expect(mockHandleInterrupt).toHaveBeenCalledTimes(1); | |
| 65 | + }, 100); | |
| 66 | + } finally { | |
| 67 | + unmount(); | |
| 68 | + } | |
| 69 | + }); | |
| 70 | + | |
| 71 | + it("shows compaction status with esc to interrupt message", () => { | |
| 72 | + const compactionStartTime = Date.now(); | |
| 73 | + | |
| 74 | + mockUseChat.mockReturnValue({ | |
| 75 | + chatHistory: [], | |
| 76 | + setChatHistory: vi.fn(), | |
| 77 | + isWaitingForResponse: false, | |
| 78 | + responseStartTime: null, | |
| 79 | + isCompacting: true, | |
| 80 | + compactionStartTime, | |
| 81 | + inputMode: false, | |
| 82 | + attachedFiles: [], | |
| 83 | + activePermissionRequest: null, | |
| 84 | + wasInterrupted: false, | |
| 85 | + handleUserMessage: vi.fn(), | |
| 86 | + handleInterrupt: mockHandleInterrupt, | |
| 87 | + handleFileAttached: vi.fn(), | |
| 88 | + resetChatHistory: vi.fn(), | |
| 89 | + handleToolPermissionResponse: vi.fn(), | |
| 90 | + }); | |
| 91 | + | |
| 92 | + const { lastFrame, unmount } = render(React.createElement(AppRoot, {})); | |
| 93 | + | |
| 94 | + try { | |
| 95 | + const frame = lastFrame(); | |
| 96 | + expect(frame).toBeDefined(); | |
| 97 | + | |
| 98 | + // Should show compaction message with interrupt option | |
| 99 | + expect(frame).toContain("Compacting history"); | |
| 100 | + expect(frame).toContain("esc to interrupt"); | |
| 101 | + } finally { | |
| 102 | + unmount(); | |
| 103 | + } | |
| 104 | + }); | |
| 105 | + | |
| 106 | + it("prioritizes compaction cancellation over response cancellation", () => { | |
| 107 | + // This tests the case where both might be true (theoretical edge case) | |
| 108 | + const compactionStartTime = Date.now(); | |
| 109 | + const responseStartTime = Date.now(); | |
| 110 | + | |
| 111 | + mockUseChat.mockReturnValue({ | |
| 112 | + chatHistory: [], | |
| 113 | + setChatHistory: vi.fn(), | |
| 114 | + isWaitingForResponse: true, | |
| 115 | + responseStartTime, | |
| 116 | + isCompacting: true, | |
| 117 | + compactionStartTime, | |
| 118 | + inputMode: false, | |
| 119 | + attachedFiles: [], | |
| 120 | + activePermissionRequest: null, | |
| 121 | + wasInterrupted: false, | |
| 122 | + handleUserMessage: vi.fn(), | |
| 123 | + handleInterrupt: mockHandleInterrupt, | |
| 124 | + handleFileAttached: vi.fn(), | |
| 125 | + resetChatHistory: vi.fn(), | |
| 126 | + handleToolPermissionResponse: vi.fn(), | |
| 127 | + }); | |
| 128 | + | |
| 129 | + const { stdin, unmount } = render(React.createElement(AppRoot, {})); | |
| 130 | + | |
| 131 | + try { | |
| 132 | + // Simulate ESC key press when both states are active | |
| 133 | + stdin.write("\x1b"); // ESC key | |
| 134 | + | |
| 135 | + // Should still call handleInterrupt (which will prioritize compaction) | |
| 136 | + expect(mockHandleInterrupt).toHaveBeenCalledTimes(1); | |
| 137 | + } finally { | |
| 138 | + unmount(); | |
| 139 | + } | |
| 140 | + }); | |
| 141 | +}); |
added extensions/cli/src/ui/components/ActionStatus.tsx +37 −0
| @@ -0,0 +1,37 @@ | ||
| 1 | +import { Box, Text } from "ink"; | |
| 2 | +import React from "react"; | |
| 3 | + | |
| 4 | +import { LoadingAnimation } from "../LoadingAnimation.js"; | |
| 5 | +import { Timer } from "../Timer.js"; | |
| 6 | + | |
| 7 | +interface ActionStatusProps { | |
| 8 | + visible: boolean; | |
| 9 | + startTime: number; | |
| 10 | + message: string; | |
| 11 | + showSpinner?: boolean; | |
| 12 | + color?: string; | |
| 13 | + loadingColor?: string; | |
| 14 | +} | |
| 15 | + | |
| 16 | +const ActionStatus: React.FC<ActionStatusProps> = ({ | |
| 17 | + visible, | |
| 18 | + startTime, | |
| 19 | + message, | |
| 20 | + showSpinner = false, | |
| 21 | + color = "gray", | |
| 22 | + loadingColor = "green", | |
| 23 | +}) => { | |
| 24 | + if (!visible) return null; | |
| 25 | + | |
| 26 | + return ( | |
| 27 | + <Box paddingX={1} flexDirection="row" gap={1}> | |
| 28 | + {showSpinner && <LoadingAnimation color={loadingColor} visible={true} />} | |
| 29 | + <Text color={color}>{message}</Text> | |
| 30 | + <Text color="gray">(</Text> | |
| 31 | + <Timer startTime={startTime} /> | |
| 32 | + <Text color="gray">• esc to interrupt )</Text> | |
| 33 | + </Box> | |
| 34 | + ); | |
| 35 | +}; | |
| 36 | + | |
| 37 | +export { ActionStatus }; |
modified extensions/cli/src/ui/components/ScreenContent.tsx +3 −0
| @@ -32,6 +32,7 @@ | ||
| 32 | 32 | ) => void; |
| 33 | 33 | handleUserMessage: (message: string, imageMap?: Map<string, Buffer>) => void; |
| 34 | 34 | isWaitingForResponse: boolean; |
| 35 | + isCompacting: boolean; | |
| 35 | 36 | inputMode: boolean; |
| 36 | 37 | handleInterrupt: () => void; |
| 37 | 38 | handleFileAttached: (filePath: string, content: string) => void; |
| @@ -55,6 +56,7 @@ | ||
| 55 | 56 | handleToolPermissionResponse, |
| 56 | 57 | handleUserMessage, |
| 57 | 58 | isWaitingForResponse, |
| 59 | + isCompacting, | |
| 58 | 60 | inputMode, |
| 59 | 61 | handleInterrupt, |
| 60 | 62 | handleFileAttached, |
| @@ -149,6 +151,7 @@ | ||
| 149 | 151 | <UserInput |
| 150 | 152 | onSubmit={handleUserMessage} |
| 151 | 153 | isWaitingForResponse={isWaitingForResponse} |
| 154 | + isCompacting={isCompacting} | |
| 152 | 155 | inputMode={inputMode} |
| 153 | 156 | onInterrupt={handleInterrupt} |
| 154 | 157 | assistant={services.config?.config || undefined} |
modified extensions/cli/src/ui/components/StaticChatContent.tsx +13 −1
| @@ -1,9 +1,10 @@ | ||
| 1 | 1 | import type { AssistantUnrolled, ModelConfig } from "@continuedev/config-yaml"; |
| 2 | -import { Box, Static, useStdout } from "ink"; | |
| 2 | +import { Box, Static, Text, useStdout } from "ink"; | |
| 3 | 3 | import React, { useCallback, useEffect, useRef, useState } from "react"; |
| 4 | 4 | |
| 5 | 5 | import type { ChatHistoryItem } from "../../../../../core/index.js"; |
| 6 | 6 | import type { MCPService } from "../../services/MCPService.js"; |
| 7 | +import type { QueuedMessage } from "../../stream/messageQueue.js"; | |
| 7 | 8 | import { useTerminalSize } from "../hooks/useTerminalSize.js"; |
| 8 | 9 | import { IntroMessage } from "../IntroMessage.js"; |
| 9 | 10 | |
| @@ -13,6 +14,7 @@ | ||
| 13 | 14 | model?: ModelConfig; |
| 14 | 15 | mcpService?: MCPService; |
| 15 | 16 | chatHistory: ChatHistoryItem[]; |
| 17 | + queuedMessages?: QueuedMessage[]; | |
| 16 | 18 | renderMessage: (item: ChatHistoryItem, index: number) => React.ReactElement; |
| 17 | 19 | refreshTrigger?: number; // Add a prop to trigger refresh from parent |
| 18 | 20 | } |
| @@ -23,6 +25,7 @@ | ||
| 23 | 25 | model, |
| 24 | 26 | mcpService, |
| 25 | 27 | chatHistory, |
| 28 | + queuedMessages = [], | |
| 26 | 29 | renderMessage, |
| 27 | 30 | refreshTrigger, |
| 28 | 31 | }) => { |
| @@ -140,6 +143,15 @@ | ||
| 140 | 143 | <React.Fragment key={`pending-${index}`}>{item}</React.Fragment> |
| 141 | 144 | ))} |
| 142 | 145 | </Box> |
| 146 | + | |
| 147 | + {/* Queued messages - show at bottom with queue indicators */} | |
| 148 | + {queuedMessages.length > 0 && ( | |
| 149 | + <Box paddingLeft={2} paddingBottom={1}> | |
| 150 | + <Text color="gray" italic> | |
| 151 | + {queuedMessages.map((msg) => msg.message).join("\n")} | |
| 152 | + </Text> | |
| 153 | + </Box> | |
| 154 | + )} | |
| 143 | 155 | </Box> |
| 144 | 156 | ); |
| 145 | 157 | }; |
modified extensions/cli/src/ui/hooks/useChat.compaction.ts +79 −50
| @@ -14,6 +14,9 @@ | ||
| 14 | 14 | setCompactionIndex: React.Dispatch<React.SetStateAction<number | null>>; |
| 15 | 15 | currentSession: Session; |
| 16 | 16 | setCurrentSession: React.Dispatch<React.SetStateAction<Session>>; |
| 17 | + setIsCompacting: (value: boolean) => void; | |
| 18 | + setCompactionStartTime: (time: number | null) => void; | |
| 19 | + setCompactionAbortController: (controller: AbortController | null) => void; | |
| 17 | 20 | } |
| 18 | 21 | |
| 19 | 22 | /** |
| @@ -27,22 +30,32 @@ | ||
| 27 | 30 | setCompactionIndex, |
| 28 | 31 | currentSession, |
| 29 | 32 | setCurrentSession, |
| 33 | + setIsCompacting, | |
| 34 | + setCompactionStartTime, | |
| 35 | + setCompactionAbortController, | |
| 30 | 36 | }: HandleCompactCommandOptions): Promise<void> { |
| 31 | - // Add compacting message | |
| 32 | - setChatHistory((prev) => [ | |
| 33 | - ...prev, | |
| 34 | - { | |
| 35 | - message: { | |
| 36 | - role: "system", | |
| 37 | - content: "Compacting chat history...", | |
| 38 | - }, | |
| 39 | - contextItems: [], | |
| 40 | - }, | |
| 41 | - ]); | |
| 37 | + // Create abort controller for cancellation support | |
| 38 | + const compactionController = new AbortController(); | |
| 39 | + setCompactionAbortController(compactionController); | |
| 40 | + | |
| 41 | + // Start compaction status display | |
| 42 | + setIsCompacting(true); | |
| 43 | + setCompactionStartTime(Date.now()); | |
| 42 | 44 | |
| 43 | 45 | try { |
| 44 | - // Compact the chat history directly (already in unified format) | |
| 45 | - const result = await compactChatHistory(chatHistory, model, llmApi); | |
| 46 | + // Compact the chat history directly (already in unified format) with abort controller | |
| 47 | + const result = await compactChatHistory( | |
| 48 | + chatHistory, | |
| 49 | + model, | |
| 50 | + llmApi, | |
| 51 | + undefined, | |
| 52 | + compactionController, | |
| 53 | + ); | |
| 54 | + | |
| 55 | + // Check if operation was aborted before proceeding with success actions | |
| 56 | + if (compactionController.signal.aborted) { | |
| 57 | + return; | |
| 58 | + } | |
| 46 | 59 | |
| 47 | 60 | // Replace chat history with compacted version |
| 48 | 61 | setChatHistory(result.compactedHistory); |
| @@ -56,6 +69,7 @@ | ||
| 56 | 69 | updateSessionHistory(result.compactedHistory); |
| 57 | 70 | setCurrentSession(updatedSession); |
| 58 | 71 | |
| 72 | + // Add success message to chat | |
| 59 | 73 | setChatHistory((prev) => [ |
| 60 | 74 | ...prev, |
| 61 | 75 | { |
| @@ -67,17 +81,37 @@ | ||
| 67 | 81 | }, |
| 68 | 82 | ]); |
| 69 | 83 | } catch (error) { |
| 70 | - logger.error("Compaction failed:", error); | |
| 71 | - setChatHistory((prev) => [ | |
| 72 | - ...prev, | |
| 73 | - { | |
| 74 | - message: { | |
| 75 | - role: "system", | |
| 76 | - content: `Compaction failed: ${formatError(error)}`, | |
| 84 | + // Check if the error was due to abortion | |
| 85 | + if (compactionController.signal.aborted) { | |
| 86 | + logger.info("Manual compaction was cancelled by user"); | |
| 87 | + setChatHistory((prev) => [ | |
| 88 | + ...prev, | |
| 89 | + { | |
| 90 | + message: { | |
| 91 | + role: "system", | |
| 92 | + content: "Compaction cancelled.", | |
| 93 | + }, | |
| 94 | + contextItems: [], | |
| 77 | 95 | }, |
| 78 | - contextItems: [], | |
| 79 | - }, | |
| 80 | - ]); | |
| 96 | + ]); | |
| 97 | + } else { | |
| 98 | + logger.error("Compaction failed:", error); | |
| 99 | + setChatHistory((prev) => [ | |
| 100 | + ...prev, | |
| 101 | + { | |
| 102 | + message: { | |
| 103 | + role: "system", | |
| 104 | + content: `Compaction failed: ${formatError(error)}`, | |
| 105 | + }, | |
| 106 | + contextItems: [], | |
| 107 | + }, | |
| 108 | + ]); | |
| 109 | + } | |
| 110 | + } finally { | |
| 111 | + // Stop compaction status display | |
| 112 | + setIsCompacting(false); | |
| 113 | + setCompactionStartTime(null); | |
| 114 | + setCompactionAbortController(null); | |
| 81 | 115 | } |
| 82 | 116 | } |
| 83 | 117 | |
| @@ -88,6 +122,7 @@ | ||
| 88 | 122 | compactionIndex: number | null; |
| 89 | 123 | setChatHistory: React.Dispatch<React.SetStateAction<ChatHistoryItem[]>>; |
| 90 | 124 | setCompactionIndex: React.Dispatch<React.SetStateAction<number | null>>; |
| 125 | + abortController?: AbortController; | |
| 91 | 126 | } |
| 92 | 127 | |
| 93 | 128 | /** |
| @@ -100,6 +135,7 @@ | ||
| 100 | 135 | compactionIndex: _compactionIndex, |
| 101 | 136 | setChatHistory, |
| 102 | 137 | setCompactionIndex, |
| 138 | + abortController, | |
| 103 | 139 | }: HandleAutoCompactionOptions): Promise<{ |
| 104 | 140 | currentChatHistory: ChatHistoryItem[]; |
| 105 | 141 | currentCompactionIndex: number | null; |
| @@ -116,20 +152,14 @@ | ||
| 116 | 152 | |
| 117 | 153 | logger.info("Auto-compaction triggered for TUI mode"); |
| 118 | 154 | |
| 119 | - // Add compacting message | |
| 120 | - setChatHistory((prev) => [ | |
| 121 | - ...prev, | |
| 122 | - { | |
| 123 | - message: { | |
| 124 | - role: "system", | |
| 125 | - content: "Auto-compacting chat history...", | |
| 126 | - }, | |
| 127 | - contextItems: [], | |
| 128 | - }, | |
| 129 | - ]); | |
| 130 | - | |
| 131 | 155 | // Compact the unified history |
| 132 | - const result = await compactChatHistory(chatHistory, model, llmApi); | |
| 156 | + const result = await compactChatHistory( | |
| 157 | + chatHistory, | |
| 158 | + model, | |
| 159 | + llmApi, | |
| 160 | + undefined, | |
| 161 | + abortController, | |
| 162 | + ); | |
| 133 | 163 | |
| 134 | 164 | // Keep the system message and append the compaction summary |
| 135 | 165 | // This replaces the old messages with a summary to reduce context size |
| @@ -151,23 +181,22 @@ | ||
| 151 | 181 | ? [systemMessage, compactedMessage] |
| 152 | 182 | : [compactedMessage]; |
| 153 | 183 | |
| 154 | - setChatHistory(updatedHistory); | |
| 155 | - setCompactionIndex(updatedHistory.length - 1); | |
| 156 | - | |
| 157 | - // Add success message | |
| 158 | - setChatHistory((prev) => [ | |
| 159 | - ...prev, | |
| 160 | - { | |
| 161 | - message: { | |
| 162 | - role: "system", | |
| 163 | - content: "✓ Chat history auto-compacted successfully.", | |
| 164 | - }, | |
| 165 | - contextItems: [], | |
| 184 | + // Add success message to the history that will be returned | |
| 185 | + const successMessage: ChatHistoryItem = { | |
| 186 | + message: { | |
| 187 | + role: "system", | |
| 188 | + content: "Chat history auto-compacted successfully.", | |
| 166 | 189 | }, |
| 167 | - ]); | |
| 190 | + contextItems: [], | |
| 191 | + }; | |
| 192 | + | |
| 193 | + const finalHistory = [...updatedHistory, successMessage]; | |
| 194 | + | |
| 195 | + setChatHistory(finalHistory); | |
| 196 | + setCompactionIndex(updatedHistory.length - 1); | |
| 168 | 197 | |
| 169 | 198 | return { |
| 170 | - currentChatHistory: updatedHistory, | |
| 199 | + currentChatHistory: finalHistory, | |
| 171 | 200 | currentCompactionIndex: updatedHistory.length - 1, |
| 172 | 201 | }; |
| 173 | 202 | } catch (error) { |
modified extensions/cli/src/ui/hooks/useChat.ts +220 −45
| @@ -1,3 +1,5 @@ | ||
| 1 | +/* eslint-disable max-lines */ | |
| 2 | +/* eslint-disable max-statements */ | |
| 1 | 3 | import type { ChatHistoryItem, Session } from "core/index.js"; |
| 2 | 4 | import { useApp } from "ink"; |
| 3 | 5 | import { useEffect, useRef, useState } from "react"; |
| @@ -11,6 +13,7 @@ | ||
| 11 | 13 | updateSessionHistory, |
| 12 | 14 | } from "../../session.js"; |
| 13 | 15 | import { handleSlashCommands } from "../../slashCommands.js"; |
| 16 | +import { messageQueue, QueuedMessage } from "../../stream/messageQueue.js"; | |
| 14 | 17 | import { telemetryService } from "../../telemetry/telemetryService.js"; |
| 15 | 18 | import { formatError } from "../../util/formatError.js"; |
| 16 | 19 | import { logger } from "../../util/logger.js"; |
| @@ -138,9 +141,15 @@ | ||
| 138 | 141 | const [responseStartTime, setResponseStartTime] = useState<number | null>( |
| 139 | 142 | null, |
| 140 | 143 | ); |
| 144 | + const [isCompacting, setIsCompacting] = useState(false); | |
| 145 | + const [compactionStartTime, setCompactionStartTime] = useState<number | null>( | |
| 146 | + null, | |
| 147 | + ); | |
| 141 | 148 | const [inputMode, setInputMode] = useState(true); |
| 142 | 149 | const [abortController, setAbortController] = |
| 143 | 150 | useState<AbortController | null>(null); |
| 151 | + const [compactionAbortController, setCompactionAbortController] = | |
| 152 | + useState<AbortController | null>(null); | |
| 144 | 153 | const [isChatHistoryInitialized, setIsChatHistoryInitialized] = useState( |
| 145 | 154 | // If we're resuming and found a saved session, we're already initialized |
| 146 | 155 | // If we're forking and found a session to fork from, we're already initialized |
| @@ -166,6 +175,22 @@ | ||
| 166 | 175 | // Track interrupted state for resume functionality |
| 167 | 176 | const [wasInterrupted, setWasInterrupted] = useState(false); |
| 168 | 177 | |
| 178 | + // Track queued messages for immediate display | |
| 179 | + const [queuedMessages, setQueuedMessages] = useState<QueuedMessage[]>([]); | |
| 180 | + | |
| 181 | + // Set up message queue listeners | |
| 182 | + useEffect(() => { | |
| 183 | + const onMessageQueued = (queuedMessage: QueuedMessage) => { | |
| 184 | + setQueuedMessages((prev) => [...prev, queuedMessage]); | |
| 185 | + }; | |
| 186 | + | |
| 187 | + messageQueue.on("messageQueued", onMessageQueued); | |
| 188 | + | |
| 189 | + return () => { | |
| 190 | + messageQueue.off("messageQueued", onMessageQueued); | |
| 191 | + }; | |
| 192 | + }, []); | |
| 193 | + | |
| 169 | 194 | // Clean up abort controller on unmount |
| 170 | 195 | useEffect(() => { |
| 171 | 196 | return () => { |
| @@ -306,6 +331,23 @@ | ||
| 306 | 331 | setIsWaitingForResponse(false); |
| 307 | 332 | setResponseStartTime(null); |
| 308 | 333 | setInputMode(true); |
| 334 | + | |
| 335 | + // Check if there are queued messages and process them after a microtask delay | |
| 336 | + // This ensures the GUI state has been updated before processing the next message | |
| 337 | + const queuedMessageData = messageQueue.getLatestMessage(); | |
| 338 | + if (queuedMessageData) { | |
| 339 | + const { message: latestQueuedMessage, imageMap } = queuedMessageData; | |
| 340 | + logger.debug("processing queued message", { latestQueuedMessage }); | |
| 341 | + | |
| 342 | + // Clear queued messages from display since they're about to be processed | |
| 343 | + // Note: messageQueue.getLatestMessage() already cleared the actual queue | |
| 344 | + setQueuedMessages([]); | |
| 345 | + | |
| 346 | + await new Promise((resolve) => setTimeout(resolve, 100)); // add timeout for react to render the tui | |
| 347 | + | |
| 348 | + // Process the queued message - it will handle adding to history and compaction display | |
| 349 | + await processQueuedMessage(latestQueuedMessage, imageMap); | |
| 350 | + } | |
| 309 | 351 | } |
| 310 | 352 | }; |
| 311 | 353 | |
| @@ -362,6 +404,9 @@ | ||
| 362 | 404 | setCompactionIndex, |
| 363 | 405 | currentSession, |
| 364 | 406 | setCurrentSession, |
| 407 | + setIsCompacting, | |
| 408 | + setCompactionStartTime, | |
| 409 | + setCompactionAbortController, | |
| 365 | 410 | }); |
| 366 | 411 | return null; |
| 367 | 412 | } |
| @@ -398,20 +443,11 @@ | ||
| 398 | 443 | .join(""); |
| 399 | 444 | }; |
| 400 | 445 | |
| 401 | - const handleUserMessage = async ( | |
| 446 | + const processMessage = async ( | |
| 402 | 447 | message: string, |
| 403 | 448 | imageMap?: Map<string, Buffer>, |
| 449 | + isQueuedMessage: boolean = false, | |
| 404 | 450 | ) => { |
| 405 | - // Check if this is a resume request (empty message after interruption) | |
| 406 | - if (await handleResumeRequest(message)) { | |
| 407 | - return; | |
| 408 | - } | |
| 409 | - | |
| 410 | - // Clear interrupted state if user types a new message | |
| 411 | - if (wasInterrupted && message !== "") { | |
| 412 | - setWasInterrupted(false); | |
| 413 | - } | |
| 414 | - | |
| 415 | 451 | // Handle special commands |
| 416 | 452 | const handled = await handleSpecialCommands({ |
| 417 | 453 | message, |
| @@ -440,27 +476,9 @@ | ||
| 440 | 476 | // Track telemetry |
| 441 | 477 | trackUserMessage(message, model); |
| 442 | 478 | |
| 443 | - // Format message with attached files and images | |
| 444 | - logger.debug("Processing message with images", { | |
| 445 | - hasImages: !!(imageMap && imageMap.size > 0), | |
| 446 | - imageCount: imageMap?.size || 0, | |
| 447 | - }); | |
| 448 | - const newUserMessage = await formatMessageWithFiles( | |
| 449 | - message, | |
| 450 | - attachedFiles, | |
| 451 | - imageMap, | |
| 452 | - ); | |
| 453 | - logger.debug("Message formatted successfully"); | |
| 454 | - | |
| 455 | - if (attachedFiles.length > 0) { | |
| 456 | - setAttachedFiles([]); | |
| 457 | - } | |
| 458 | - | |
| 459 | 479 | // In remote mode, send message to server instead of processing locally |
| 460 | 480 | if (isRemoteMode && remoteUrl) { |
| 461 | - const messageContentString = convertMessageContentToString( | |
| 462 | - newUserMessage.message.content, | |
| 463 | - ); | |
| 481 | + const messageContentString = convertMessageContentToString(message); | |
| 464 | 482 | |
| 465 | 483 | await handleRemoteMessage({ |
| 466 | 484 | remoteUrl, |
| @@ -469,23 +487,161 @@ | ||
| 469 | 487 | return; |
| 470 | 488 | } |
| 471 | 489 | |
| 472 | - // Check if auto-compacting is needed BEFORE adding user message | |
| 473 | - const { currentChatHistory, currentCompactionIndex } = | |
| 474 | - await handleAutoCompaction({ | |
| 475 | - chatHistory, | |
| 476 | - model, | |
| 477 | - llmApi, | |
| 478 | - compactionIndex, | |
| 479 | - setChatHistory: setChatHistory, | |
| 480 | - setCompactionIndex, | |
| 490 | + // For non-queued messages, format and add to chat history | |
| 491 | + if (isQueuedMessage) { | |
| 492 | + // For queued messages, we need to format and add to history after compaction | |
| 493 | + // First, format the message | |
| 494 | + const formattedQueuedMessage = await formatMessageWithFiles( | |
| 495 | + message, | |
| 496 | + [], // No attached files for queued messages | |
| 497 | + imageMap, | |
| 498 | + ); | |
| 499 | + | |
| 500 | + // Check if auto-compacting is needed with current history | |
| 501 | + const compactionController = new AbortController(); | |
| 502 | + setCompactionAbortController(compactionController); | |
| 503 | + setIsCompacting(true); | |
| 504 | + setCompactionStartTime(Date.now()); | |
| 505 | + | |
| 506 | + // Add the queued message to queue display during compaction | |
| 507 | + const queuedMessageForDisplay: QueuedMessage = { | |
| 508 | + message, | |
| 509 | + imageMap, | |
| 510 | + timestamp: Date.now(), | |
| 511 | + }; | |
| 512 | + setQueuedMessages((prev) => [...prev, queuedMessageForDisplay]); | |
| 513 | + | |
| 514 | + let currentChatHistory, currentCompactionIndex; | |
| 515 | + try { | |
| 516 | + const result = await handleAutoCompaction({ | |
| 517 | + chatHistory, | |
| 518 | + model, | |
| 519 | + llmApi, | |
| 520 | + compactionIndex, | |
| 521 | + setChatHistory: setChatHistory, | |
| 522 | + setCompactionIndex, | |
| 523 | + abortController: compactionController, | |
| 524 | + }); | |
| 525 | + currentChatHistory = result.currentChatHistory; | |
| 526 | + currentCompactionIndex = result.currentCompactionIndex; | |
| 527 | + } catch (error) { | |
| 528 | + // If compaction fails, remove the queued message from display | |
| 529 | + setQueuedMessages((prev) => | |
| 530 | + prev.filter((msg) => msg !== queuedMessageForDisplay), | |
| 531 | + ); | |
| 532 | + throw error; // Re-throw to maintain error handling | |
| 533 | + } finally { | |
| 534 | + setIsCompacting(false); | |
| 535 | + setCompactionStartTime(null); | |
| 536 | + setCompactionAbortController(null); | |
| 537 | + } | |
| 538 | + | |
| 539 | + // Add the formatted queued message to history after compaction completes | |
| 540 | + const newHistory = [...currentChatHistory, formattedQueuedMessage]; | |
| 541 | + setChatHistory(newHistory); | |
| 542 | + | |
| 543 | + // Remove the queued message from display since it's now in chat history | |
| 544 | + setQueuedMessages((prev) => | |
| 545 | + prev.filter((msg) => msg !== queuedMessageForDisplay), | |
| 546 | + ); | |
| 547 | + | |
| 548 | + // Execute the streaming response with the updated history | |
| 549 | + await executeStreamingResponse(newHistory, currentCompactionIndex); | |
| 550 | + } else { | |
| 551 | + // Format message with attached files and images | |
| 552 | + logger.debug("Processing message with images", { | |
| 553 | + hasImages: !!(imageMap && imageMap.size > 0), | |
| 554 | + imageCount: imageMap?.size || 0, | |
| 481 | 555 | }); |
| 556 | + const newUserMessage = await formatMessageWithFiles( | |
| 557 | + message, | |
| 558 | + attachedFiles, | |
| 559 | + imageMap, | |
| 560 | + ); | |
| 561 | + logger.debug("Message formatted successfully"); | |
| 482 | 562 | |
| 483 | - // Add the formatted user message to history | |
| 484 | - const newHistory = [...currentChatHistory, newUserMessage]; | |
| 485 | - setChatHistory(newHistory); | |
| 563 | + if (attachedFiles.length > 0) { | |
| 564 | + setAttachedFiles([]); | |
| 565 | + } | |
| 566 | + | |
| 567 | + // Check if auto-compacting is needed BEFORE adding user message | |
| 568 | + const compactionController = new AbortController(); | |
| 569 | + setCompactionAbortController(compactionController); | |
| 570 | + setIsCompacting(true); | |
| 571 | + setCompactionStartTime(Date.now()); | |
| 572 | + | |
| 573 | + // Add the triggering message to queue display during compaction | |
| 574 | + const compactionQueuedMessage: QueuedMessage = { | |
| 575 | + message, | |
| 576 | + imageMap, | |
| 577 | + timestamp: Date.now(), | |
| 578 | + }; | |
| 579 | + setQueuedMessages((prev) => [...prev, compactionQueuedMessage]); | |
| 580 | + | |
| 581 | + let currentChatHistory, currentCompactionIndex; | |
| 582 | + try { | |
| 583 | + const result = await handleAutoCompaction({ | |
| 584 | + chatHistory, | |
| 585 | + model, | |
| 586 | + llmApi, | |
| 587 | + compactionIndex, | |
| 588 | + setChatHistory: setChatHistory, | |
| 589 | + setCompactionIndex, | |
| 590 | + abortController: compactionController, | |
| 591 | + }); | |
| 592 | + currentChatHistory = result.currentChatHistory; | |
| 593 | + currentCompactionIndex = result.currentCompactionIndex; | |
| 594 | + } catch (error) { | |
| 595 | + // If compaction fails, remove the triggering message from queue display | |
| 596 | + setQueuedMessages((prev) => | |
| 597 | + prev.filter((msg) => msg !== compactionQueuedMessage), | |
| 598 | + ); | |
| 599 | + throw error; // Re-throw to maintain error handling | |
| 600 | + } finally { | |
| 601 | + setIsCompacting(false); | |
| 602 | + setCompactionStartTime(null); | |
| 603 | + setCompactionAbortController(null); | |
| 604 | + } | |
| 605 | + | |
| 606 | + // Add the formatted user message to history | |
| 607 | + const newHistory = [...currentChatHistory, newUserMessage]; | |
| 608 | + setChatHistory(newHistory); | |
| 609 | + | |
| 610 | + // Remove the triggering message from queue display since it's now in chat history | |
| 611 | + setQueuedMessages((prev) => | |
| 612 | + prev.filter((msg) => msg !== compactionQueuedMessage), | |
| 613 | + ); | |
| 614 | + | |
| 615 | + // Execute the streaming response | |
| 616 | + await executeStreamingResponse(newHistory, currentCompactionIndex); | |
| 617 | + } | |
| 618 | + }; | |
| 619 | + | |
| 620 | + const processQueuedMessage = async ( | |
| 621 | + message: string, | |
| 622 | + imageMap?: Map<string, Buffer>, | |
| 623 | + ) => { | |
| 624 | + // For queued messages, we can reuse the core message processing logic | |
| 625 | + // by calling the internal processing function directly | |
| 626 | + await processMessage(message, imageMap, true); | |
| 627 | + }; | |
| 628 | + | |
| 629 | + const handleUserMessage = async ( | |
| 630 | + message: string, | |
| 631 | + imageMap?: Map<string, Buffer>, | |
| 632 | + ) => { | |
| 633 | + // Check if this is a resume request (empty message after interruption) | |
| 634 | + if (await handleResumeRequest(message)) { | |
| 635 | + return; | |
| 636 | + } | |
| 637 | + | |
| 638 | + // Clear interrupted state if user types a new message | |
| 639 | + if (wasInterrupted && message !== "") { | |
| 640 | + setWasInterrupted(false); | |
| 641 | + } | |
| 486 | 642 | |
| 487 | - // Execute the streaming response | |
| 488 | - await executeStreamingResponse(newHistory, currentCompactionIndex); | |
| 643 | + // Use the common message processing logic | |
| 644 | + await processMessage(message, imageMap, false); | |
| 489 | 645 | }; |
| 490 | 646 | |
| 491 | 647 | const handleInterrupt = () => { |
| @@ -504,7 +660,21 @@ | ||
| 504 | 660 | return; |
| 505 | 661 | } |
| 506 | 662 | |
| 507 | - // Local mode: abort the controller | |
| 663 | + // Local mode: abort the appropriate controller | |
| 664 | + | |
| 665 | + // If compaction is running, abort compaction | |
| 666 | + if (compactionAbortController && isCompacting) { | |
| 667 | + compactionAbortController.abort(); | |
| 668 | + setIsCompacting(false); | |
| 669 | + setCompactionStartTime(null); | |
| 670 | + setCompactionAbortController(null); | |
| 671 | + setInputMode(true); | |
| 672 | + // Clear any queued messages (including the triggering message) when compaction is interrupted | |
| 673 | + setQueuedMessages([]); | |
| 674 | + return; | |
| 675 | + } | |
| 676 | + | |
| 677 | + // If response is running, abort response | |
| 508 | 678 | if (abortController && isWaitingForResponse) { |
| 509 | 679 | abortController.abort(); |
| 510 | 680 | |
| @@ -537,6 +707,8 @@ | ||
| 537 | 707 | additionalRules, |
| 538 | 708 | ); |
| 539 | 709 | setChatHistory(newHistory); |
| 710 | + // Clear any queued messages when resetting chat | |
| 711 | + setQueuedMessages([]); | |
| 540 | 712 | }; |
| 541 | 713 | |
| 542 | 714 | const handleToolPermissionResponse = async ( |
| @@ -610,10 +782,13 @@ | ||
| 610 | 782 | setChatHistory: setChatHistory, |
| 611 | 783 | isWaitingForResponse, |
| 612 | 784 | responseStartTime, |
| 785 | + isCompacting, | |
| 786 | + compactionStartTime, | |
| 613 | 787 | inputMode, |
| 614 | 788 | attachedFiles, |
| 615 | 789 | activePermissionRequest, |
| 616 | 790 | wasInterrupted, |
| 791 | + queuedMessages, | |
| 617 | 792 | handleUserMessage, |
| 618 | 793 | handleInterrupt, |
| 619 | 794 | handleFileAttached, |
modified extensions/vscode/config_schema.json +1 −1
| @@ -78,7 +78,7 @@ | ||
| 78 | 78 | }, |
| 79 | 79 | "reasoning": { |
| 80 | 80 | "title": "Reasoning", |
| 81 | - "description": "Enable thinking/reasoning for Anthropic Claude 3.7+ models", | |
| 81 | + "description": "Enable thinking/reasoning for Anthropic Claude 3.7+ and some Ollama models", | |
| 82 | 82 | "type": "boolean" |
| 83 | 83 | }, |
| 84 | 84 | "reasoningBudgetTokens": { |
modified extensions/vscode/e2e/tests/KeyboardShortcuts.test.ts +66 −5
| @@ -4,12 +4,12 @@ | ||
| 4 | 4 | InputBox, |
| 5 | 5 | Key, |
| 6 | 6 | TextEditor, |
| 7 | + until, | |
| 7 | 8 | VSBrowser, |
| 8 | 9 | WebDriver, |
| 9 | 10 | WebElement, |
| 10 | 11 | WebView, |
| 11 | 12 | Workbench, |
| 12 | - until, | |
| 13 | 13 | } from "vscode-extension-tester"; |
| 14 | 14 | |
| 15 | 15 | import { GlobalActions } from "../actions/Global.actions"; |
| @@ -47,11 +47,31 @@ | ||
| 47 | 47 | |
| 48 | 48 | afterEach(async function () { |
| 49 | 49 | this.timeout(DEFAULT_TIMEOUT.XL * 1000); |
| 50 | + await cleanupChat(); | |
| 50 | 51 | await view.switchBack(); |
| 51 | 52 | await editor.clearText(); |
| 52 | 53 | await new EditorView().closeAllEditors(); |
| 53 | 54 | }); |
| 54 | 55 | |
| 56 | + async function cleanupChat(chatInput?: WebElement) { | |
| 57 | + try { | |
| 58 | + if (!chatInput) { | |
| 59 | + chatInput = await TestUtils.waitForSuccess(async () => { | |
| 60 | + return GUISelectors.getMessageInputFieldAtIndex(view, 0); | |
| 61 | + }); | |
| 62 | + } | |
| 63 | + if ( | |
| 64 | + chatInput && | |
| 65 | + (await chatInput.isDisplayed()) && | |
| 66 | + (await chatInput.isEnabled()) | |
| 67 | + ) { | |
| 68 | + await chatInput.clear(); | |
| 69 | + } | |
| 70 | + } catch (e) { | |
| 71 | + console.error(`Failed to clear chat: ${e}`); | |
| 72 | + } | |
| 73 | + } | |
| 74 | + | |
| 55 | 75 | it("Should correctly undo and redo using keyboard shortcuts when writing a chat message", async () => { |
| 56 | 76 | await GUIActions.executeFocusContinueInputShortcut(driver); |
| 57 | 77 | ({ view } = await GUIActions.switchToReactIframe()); |
| @@ -105,10 +125,8 @@ | ||
| 105 | 125 | ); |
| 106 | 126 | }).timeout(DEFAULT_TIMEOUT.XL); |
| 107 | 127 | |
| 108 | - it("Should not create a code block when Cmd+L is pressed without text highlighted", async () => { | |
| 109 | - const text = "Hello, world!"; | |
| 110 | - | |
| 111 | - await editor.setText(text); | |
| 128 | + it("Should not create a code block when Cmd+L is pressed on an empty document", async () => { | |
| 129 | + expect((await editor.getText()).trim()).to.equal(""); | |
| 112 | 130 | |
| 113 | 131 | await GUIActions.executeFocusContinueInputShortcut(driver); |
| 114 | 132 | |
| @@ -174,6 +192,9 @@ | ||
| 174 | 192 | |
| 175 | 193 | await driver.wait(until.elementIsNotVisible(textInput), DEFAULT_TIMEOUT.XS); |
| 176 | 194 | expect(await textInput.isDisplayed()).to.equal(false); |
| 195 | + | |
| 196 | + // Make sure the view is visible again, so it can be cleared in afterEach() | |
| 197 | + await GUIActions.executeFocusContinueInputShortcut(driver); | |
| 177 | 198 | }).timeout(DEFAULT_TIMEOUT.XL); |
| 178 | 199 | |
| 179 | 200 | it("Should create a code block when Cmd+L is pressed with text highlighted", async () => { |
| @@ -197,4 +218,44 @@ | ||
| 197 | 218 | |
| 198 | 219 | await GUIActions.executeFocusContinueInputShortcut(driver); |
| 199 | 220 | }).timeout(DEFAULT_TIMEOUT.XL); |
| 221 | + | |
| 222 | + it("Should create a code block with the whole file when Cmd+L is pressed on an empty line", async () => { | |
| 223 | + const text = "Hello,\n\n\nworld!"; | |
| 224 | + | |
| 225 | + await editor.setText(text); | |
| 226 | + await editor.moveCursor(2, 1); //Move cursor to an empty line | |
| 227 | + | |
| 228 | + await GUIActions.executeFocusContinueInputShortcut(driver); | |
| 229 | + | |
| 230 | + ({ view } = await GUIActions.switchToReactIframe()); | |
| 231 | + | |
| 232 | + const codeBlock = await TestUtils.waitForSuccess(() => | |
| 233 | + GUISelectors.getInputBoxCodeBlockAtIndex(view, 0), | |
| 234 | + ); | |
| 235 | + const codeblockContent = await codeBlock.getAttribute( | |
| 236 | + "data-codeblockcontent", | |
| 237 | + ); | |
| 238 | + | |
| 239 | + expect(codeblockContent).to.equal(text); | |
| 240 | + }); | |
| 241 | + | |
| 242 | + it("Should create a code block when Cmd+L is pressed on a non-empty line", async () => { | |
| 243 | + const text = "Hello, world!"; | |
| 244 | + | |
| 245 | + await editor.setText(text); | |
| 246 | + await editor.moveCursor(1, 7); //Move cursor to the 1st space | |
| 247 | + | |
| 248 | + await GUIActions.executeFocusContinueInputShortcut(driver); | |
| 249 | + | |
| 250 | + ({ view } = await GUIActions.switchToReactIframe()); | |
| 251 | + | |
| 252 | + const codeBlock = await TestUtils.waitForSuccess(() => | |
| 253 | + GUISelectors.getInputBoxCodeBlockAtIndex(view, 0), | |
| 254 | + ); | |
| 255 | + const codeblockContent = await codeBlock.getAttribute( | |
| 256 | + "data-codeblockcontent", | |
| 257 | + ); | |
| 258 | + | |
| 259 | + expect(codeblockContent).to.equal(text); | |
| 260 | + }).timeout(DEFAULT_TIMEOUT.XL); | |
| 200 | 261 | }); |
modified extensions/vscode/package.json +2 −3
| @@ -524,13 +524,12 @@ | ||
| 524 | 524 | "continue.continueSubMenu": [ |
| 525 | 525 | { |
| 526 | 526 | "command": "continue.focusContinueInputWithoutClear", |
| 527 | - "group": "Continue", | |
| 528 | - "when": "editorHasSelection" | |
| 527 | + "group": "Continue" | |
| 529 | 528 | }, |
| 530 | 529 | { |
| 531 | 530 | "command": "continue.focusEdit", |
| 532 | 531 | "group": "Continue", |
| 533 | - "when": "editorHasSelection && !editorReadonly" | |
| 532 | + "when": "!editorReadonly" | |
| 534 | 533 | } |
| 535 | 534 | ], |
| 536 | 535 | "explorer/context": [ |
modified extensions/vscode/src/diff/processDiff.ts +38 −5
| @@ -1,8 +1,11 @@ | ||
| 1 | 1 | import { Core } from "core/core"; |
| 2 | 2 | import { DataLogger } from "core/data/log"; |
| 3 | +import { myersDiff } from "core/diff/myers"; | |
| 4 | + | |
| 3 | 5 | import { ContinueGUIWebviewViewProvider } from "../ContinueGUIWebviewViewProvider"; |
| 4 | 6 | import { editOutcomeTracker } from "../extension/EditOutcomeTracker"; |
| 5 | 7 | import { VsCodeIde } from "../VsCodeIde"; |
| 8 | + | |
| 6 | 9 | import { VerticalDiffManager } from "./vertical/manager"; |
| 7 | 10 | |
| 8 | 11 | export async function processDiff( |
| @@ -42,7 +45,8 @@ | ||
| 42 | 45 | } |
| 43 | 46 | |
| 44 | 47 | if (streamId) { |
| 45 | - const fileContent = await ide.readFile(newOrCurrentUri); | |
| 48 | + // Capture file content before save to detect autoformatting | |
| 49 | + const preSaveContent = await ide.readFile(newOrCurrentUri); | |
| 46 | 50 | |
| 47 | 51 | // Record the edit outcome before updating the apply state |
| 48 | 52 | await editOutcomeTracker.recordEditOutcome( |
| @@ -51,16 +55,45 @@ | ||
| 51 | 55 | DataLogger.getInstance(), |
| 52 | 56 | ); |
| 53 | 57 | |
| 58 | + // Save the file | |
| 59 | + await ide.saveFile(newOrCurrentUri); | |
| 60 | + | |
| 61 | + // Capture file content after save to detect autoformatting | |
| 62 | + const postSaveContent = await ide.readFile(newOrCurrentUri); | |
| 63 | + | |
| 64 | + // Detect autoformatting by comparing normalized content | |
| 65 | + let autoFormattingDiff: string | undefined; | |
| 66 | + const normalizedPreSave = preSaveContent.trim(); | |
| 67 | + const normalizedPostSave = postSaveContent.trim(); | |
| 68 | + | |
| 69 | + if (normalizedPreSave !== normalizedPostSave) { | |
| 70 | + // Auto-formatting was applied by the editor | |
| 71 | + const diffLines = myersDiff(preSaveContent, postSaveContent); | |
| 72 | + autoFormattingDiff = diffLines | |
| 73 | + .map((line) => { | |
| 74 | + switch (line.type) { | |
| 75 | + case "old": | |
| 76 | + return `-${line.line}`; | |
| 77 | + case "new": | |
| 78 | + return `+${line.line}`; | |
| 79 | + case "same": | |
| 80 | + return ` ${line.line}`; | |
| 81 | + } | |
| 82 | + }) | |
| 83 | + .join("\n"); | |
| 84 | + } | |
| 85 | + | |
| 54 | 86 | await sidebar.webviewProtocol.request("updateApplyState", { |
| 55 | - fileContent, | |
| 87 | + fileContent: postSaveContent, // Use post-save content | |
| 56 | 88 | filepath: newOrCurrentUri, |
| 57 | 89 | streamId, |
| 58 | 90 | status: "closed", |
| 59 | 91 | numDiffs: 0, |
| 60 | 92 | toolCallId, |
| 93 | + autoFormattingDiff, // Include autoformatting diff | |
| 61 | 94 | }); |
| 95 | + } else { | |
| 96 | + // Save the file even if no streamId | |
| 97 | + await ide.saveFile(newOrCurrentUri); | |
| 62 | 98 | } |
| 63 | - | |
| 64 | - // Save the file | |
| 65 | - await ide.saveFile(newOrCurrentUri); | |
| 66 | 99 | } |
modified extensions/vscode/src/util/addCode.ts +38 −18
| @@ -36,22 +36,38 @@ | ||
| 36 | 36 | }; |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | - if (selection.isEmpty && !allowEmpty) { | |
| 39 | + if ((selection.isEmpty && !allowEmpty) || isEmptyFile(editor.document)) { | |
| 40 | 40 | return null; |
| 41 | 41 | } |
| 42 | 42 | |
| 43 | - let selectionRange = new vscode.Range(selection.start, selection.end); | |
| 44 | - const document = editor.document; | |
| 45 | - // Select the context from the beginning of the selection start line to the selection start position | |
| 46 | - const beginningOfSelectionStartLine = selection.start.with(undefined, 0); | |
| 47 | - const textBeforeSelectionStart = document.getText( | |
| 48 | - new vscode.Range(beginningOfSelectionStartLine, selection.start), | |
| 49 | - ); | |
| 50 | - // If there are only whitespace before the start of the selection, include the indentation | |
| 51 | - if (textBeforeSelectionStart.trim().length === 0) { | |
| 52 | - selectionRange = selectionRange.with({ | |
| 53 | - start: beginningOfSelectionStartLine, | |
| 54 | - }); | |
| 43 | + let selectionRange: vscode.Range | undefined; | |
| 44 | + // if the selection is empty and document is not empty, select the whole document | |
| 45 | + if (selection.isEmpty) { | |
| 46 | + selectionRange = new vscode.Range( | |
| 47 | + new vscode.Position(0, 0), | |
| 48 | + new vscode.Position( | |
| 49 | + editor.document.lineCount - 1, | |
| 50 | + editor.document.lineAt( | |
| 51 | + editor.document.lineCount - 1, | |
| 52 | + ).range.end.character, | |
| 53 | + ), | |
| 54 | + ); | |
| 55 | + } | |
| 56 | + | |
| 57 | + if (!selectionRange) { | |
| 58 | + selectionRange = new vscode.Range(selection.start, selection.end); | |
| 59 | + const document = editor.document; | |
| 60 | + // Select the context from the beginning of the selection start line to the selection start position | |
| 61 | + const beginningOfSelectionStartLine = selection.start.with(undefined, 0); | |
| 62 | + const textBeforeSelectionStart = document.getText( | |
| 63 | + new vscode.Range(beginningOfSelectionStartLine, selection.start), | |
| 64 | + ); | |
| 65 | + // If there are only whitespace before the start of the selection, include the indentation | |
| 66 | + if (textBeforeSelectionStart.trim().length === 0) { | |
| 67 | + selectionRange = selectionRange.with({ | |
| 68 | + start: beginningOfSelectionStartLine, | |
| 69 | + }); | |
| 70 | + } | |
| 55 | 71 | } |
| 56 | 72 | |
| 57 | 73 | const contents = editor.document.getText(selectionRange); |
| @@ -61,12 +77,12 @@ | ||
| 61 | 77 | contents, |
| 62 | 78 | range: { |
| 63 | 79 | start: { |
| 64 | - line: selection.start.line, | |
| 65 | - character: selection.start.character, | |
| 80 | + line: selectionRange.start.line, | |
| 81 | + character: selectionRange.start.character, | |
| 66 | 82 | }, |
| 67 | 83 | end: { |
| 68 | - line: selection.end.line, | |
| 69 | - character: selection.end.character, | |
| 84 | + line: selectionRange.end.line, | |
| 85 | + character: selectionRange.end.character, | |
| 70 | 86 | }, |
| 71 | 87 | }, |
| 72 | 88 | }; |
| @@ -78,7 +94,7 @@ | ||
| 78 | 94 | export async function addHighlightedCodeToContext( |
| 79 | 95 | webviewProtocol: VsCodeWebviewProtocol | undefined, |
| 80 | 96 | ) { |
| 81 | - const rangeInFileWithContents = getRangeInFileWithContents(); | |
| 97 | + const rangeInFileWithContents = getRangeInFileWithContents(true); | |
| 82 | 98 | if (rangeInFileWithContents) { |
| 83 | 99 | webviewProtocol?.request("highlightedCode", { |
| 84 | 100 | rangeInFileWithContents, |
| @@ -129,6 +145,10 @@ | ||
| 129 | 145 | }); |
| 130 | 146 | } |
| 131 | 147 | |
| 148 | +export function isEmptyFile(document: vscode.TextDocument) { | |
| 149 | + return document.lineCount === 1 && document.lineAt(0).range.isEmpty; | |
| 150 | +} | |
| 151 | + | |
| 132 | 152 | export function addCodeToContextFromRange( |
| 133 | 153 | range: vscode.Range, |
| 134 | 154 | webviewProtocol: VsCodeWebviewProtocol, |
modified gui/src/components/mainInput/ContextStatus.tsx +22 −0
| @@ -1,3 +1,4 @@ | ||
| 1 | +import { useMemo, useRef } from "react"; | |
| 1 | 2 | import { useAppDispatch, useAppSelector } from "../../redux/hooks"; |
| 2 | 3 | import { saveCurrentSession } from "../../redux/thunks/session"; |
| 3 | 4 | import { useCompactConversation } from "../../util/compactConversation"; |
| @@ -8,15 +9,36 @@ | ||
| 8 | 9 | const contextPercentage = useAppSelector( |
| 9 | 10 | (state) => state.session.contextPercentage, |
| 10 | 11 | ); |
| 12 | + const selectedChatModel = useAppSelector( | |
| 13 | + (state) => state.config.config.selectedModelByRole.chat?.model, | |
| 14 | + ); | |
| 15 | + const previousHistoryLength = useRef<number | null>(null); | |
| 16 | + const previousSelectedChatModel = useRef<string | null>(null); | |
| 11 | 17 | const history = useAppSelector((state) => state.session.history); |
| 12 | 18 | const percent = Math.round((contextPercentage ?? 0) * 100); |
| 13 | 19 | const isPruned = useAppSelector((state) => state.session.isPruned); |
| 14 | 20 | |
| 21 | + const isDifferentModelAndSameHistory = useMemo(() => { | |
| 22 | + if (!selectedChatModel) return false; | |
| 23 | + // only reset if history changes | |
| 24 | + if (previousHistoryLength.current !== history.length) { | |
| 25 | + previousHistoryLength.current = history.length; | |
| 26 | + previousSelectedChatModel.current = selectedChatModel; | |
| 27 | + return false; | |
| 28 | + } | |
| 29 | + return previousSelectedChatModel.current !== selectedChatModel; | |
| 30 | + }, [history.length, selectedChatModel]); | |
| 31 | + | |
| 15 | 32 | const compactConversation = useCompactConversation(); |
| 16 | 33 | if (!isPruned && percent < 60) { |
| 17 | 34 | return null; |
| 18 | 35 | } |
| 19 | 36 | |
| 37 | + // if user changed to a different model, we shouldn't show the context status until the user sends a new message | |
| 38 | + if (isDifferentModelAndSameHistory) { | |
| 39 | + return null; | |
| 40 | + } | |
| 41 | + | |
| 20 | 42 | const barColorClass = isPruned ? "bg-error" : "bg-description"; |
| 21 | 43 | |
| 22 | 44 | return ( |
modified gui/src/components/mainInput/InputToolbar.tsx +7 −2
| @@ -5,7 +5,10 @@ | ||
| 5 | 5 | } from "@heroicons/react/24/outline"; |
| 6 | 6 | import { LightBulbIcon as LightBulbIconSolid } from "@heroicons/react/24/solid"; |
| 7 | 7 | import { InputModifiers } from "core"; |
| 8 | -import { modelSupportsImages } from "core/llm/autodetect"; | |
| 8 | +import { | |
| 9 | + modelSupportsImages, | |
| 10 | + modelSupportsReasoning, | |
| 11 | +} from "core/llm/autodetect"; | |
| 9 | 12 | import { useContext, useRef } from "react"; |
| 10 | 13 | import { IdeMessengerContext } from "../../context/IdeMessenger"; |
| 11 | 14 | import { useAppDispatch, useAppSelector } from "../../redux/hooks"; |
| @@ -66,6 +69,8 @@ | ||
| 66 | 69 | defaultModel.capabilities, |
| 67 | 70 | ); |
| 68 | 71 | |
| 72 | + const supportsReasoning = modelSupportsReasoning(defaultModel); | |
| 73 | + | |
| 69 | 74 | const smallFont = useFontSize(-2); |
| 70 | 75 | const tinyFont = useFontSize(-3); |
| 71 | 76 | |
| @@ -130,7 +135,7 @@ | ||
| 130 | 135 | </HoverItem> |
| 131 | 136 | </ToolTip> |
| 132 | 137 | )} |
| 133 | - {defaultModel?.underlyingProviderName === "anthropic" && ( | |
| 138 | + {supportsReasoning && ( | |
| 134 | 139 | <HoverItem |
| 135 | 140 | onClick={() => |
| 136 | 141 | dispatch(setHasReasoningEnabled(!hasReasoningEnabled)) |
modified gui/src/hooks/ParallelListeners.tsx +8 −6
| @@ -19,6 +19,7 @@ | ||
| 19 | 19 | } from "../redux/slices/sessionSlice"; |
| 20 | 20 | import { setTTSActive } from "../redux/slices/uiSlice"; |
| 21 | 21 | |
| 22 | +import { modelSupportsReasoning } from "core/llm/autodetect"; | |
| 22 | 23 | import { cancelStream } from "../redux/thunks/cancelStream"; |
| 23 | 24 | import { handleApplyStateUpdate } from "../redux/thunks/handleApplyStateUpdate"; |
| 24 | 25 | import { refreshSessionMetadata } from "../redux/thunks/session"; |
| @@ -79,12 +80,13 @@ | ||
| 79 | 80 | document.body.style.fontSize = `${configResult.config.ui.fontSize}px`; |
| 80 | 81 | } |
| 81 | 82 | |
| 82 | - if ( | |
| 83 | - configResult.config?.selectedModelByRole.chat?.completionOptions | |
| 84 | - ?.reasoning | |
| 85 | - ) { | |
| 86 | - dispatch(setHasReasoningEnabled(true)); | |
| 87 | - } | |
| 83 | + const chatModel = configResult.config?.selectedModelByRole.chat; | |
| 84 | + const supportsReasoning = modelSupportsReasoning(chatModel); | |
| 85 | + const isReasoningDisabled = | |
| 86 | + chatModel?.completionOptions?.reasoning === false; | |
| 87 | + dispatch( | |
| 88 | + setHasReasoningEnabled(supportsReasoning && !isReasoningDisabled), | |
| 89 | + ); | |
| 88 | 90 | }, |
| 89 | 91 | [dispatch, hasDoneInitialConfigLoad], |
| 90 | 92 | ); |
modified gui/src/redux/thunks/handleApplyStateUpdate.ts +46 −1
| @@ -89,6 +89,52 @@ | ||
| 89 | 89 | toolCallId: applyState.toolCallId, |
| 90 | 90 | }), |
| 91 | 91 | ); |
| 92 | + | |
| 93 | + // Add autoformatting diff to tool output if present | |
| 94 | + if (applyState.autoFormattingDiff) { | |
| 95 | + dispatch( | |
| 96 | + updateToolCallOutput({ | |
| 97 | + toolCallId: applyState.toolCallId, | |
| 98 | + contextItems: [ | |
| 99 | + { | |
| 100 | + icon: "info", | |
| 101 | + name: "Auto-formatting Applied", | |
| 102 | + description: "Editor auto-formatting changes", | |
| 103 | + content: `Along with your edits, the editor applied the following auto-formatting:\n\n${applyState.autoFormattingDiff}\n\n(Note: Pay close attention to changes such as single quotes being converted to double quotes, semicolons being removed or added, long lines being broken into multiple lines, adjusting indentation style, adding/removing trailing commas, etc. This will help you ensure future SEARCH/REPLACE operations to this file are accurate.)`, | |
| 104 | + hidden: false, | |
| 105 | + }, | |
| 106 | + ], | |
| 107 | + }), | |
| 108 | + ); | |
| 109 | + } else { | |
| 110 | + dispatch( | |
| 111 | + updateToolCallOutput({ | |
| 112 | + toolCallId: applyState.toolCallId, | |
| 113 | + contextItems: [ | |
| 114 | + { | |
| 115 | + name: "Edit Success", | |
| 116 | + content: `Successfully edited ${applyState.filepath}`, | |
| 117 | + description: "", | |
| 118 | + hidden: true, | |
| 119 | + }, | |
| 120 | + ], | |
| 121 | + }), | |
| 122 | + ); | |
| 123 | + } | |
| 124 | + } else { | |
| 125 | + dispatch( | |
| 126 | + updateToolCallOutput({ | |
| 127 | + toolCallId: applyState.toolCallId, | |
| 128 | + contextItems: [ | |
| 129 | + { | |
| 130 | + name: "Edit Failed", | |
| 131 | + content: `Failed to edit ${applyState.filepath}. To continue working with the file, read it again to see the most up-to-date contents`, | |
| 132 | + description: "", | |
| 133 | + hidden: true, | |
| 134 | + }, | |
| 135 | + ], | |
| 136 | + }), | |
| 137 | + ); | |
| 92 | 138 | } |
| 93 | 139 | |
| 94 | 140 | void dispatch( |
| @@ -98,7 +144,6 @@ | ||
| 98 | 144 | ); |
| 99 | 145 | } |
| 100 | 146 | } |
| 101 | - // TODO return output from edit tools so the model knows the result | |
| 102 | 147 | } |
| 103 | 148 | } |
| 104 | 149 | } |
modified gui/src/redux/thunks/streamNormalInput.ts +40 −11
| @@ -1,13 +1,14 @@ | ||
| 1 | +import { ToolPolicy } from "@continuedev/terminal-security"; | |
| 1 | 2 | import { createAsyncThunk, unwrapResult } from "@reduxjs/toolkit"; |
| 2 | 3 | import { |
| 3 | - ContextItem, | |
| 4 | 4 | LLMFullCompletionOptions, |
| 5 | + ModelDescription, | |
| 5 | 6 | Tool, |
| 6 | 7 | ToolCallState, |
| 7 | 8 | } from "core"; |
| 8 | -import { ToolPolicy } from "@continuedev/terminal-security"; | |
| 9 | 9 | import { getRuleId } from "core/llm/rules/getSystemMessageWithRules"; |
| 10 | 10 | import { ToCoreProtocol } from "core/protocol"; |
| 11 | +import { IIdeMessenger } from "../../context/IdeMessenger"; | |
| 11 | 12 | import { selectActiveTools } from "../selectors/selectActiveTools"; |
| 12 | 13 | import { selectSelectedChatModel } from "../slices/configSlice"; |
| 13 | 14 | import { |
| @@ -25,7 +26,6 @@ | ||
| 25 | 26 | updateToolCallOutput, |
| 26 | 27 | } from "../slices/sessionSlice"; |
| 27 | 28 | import { AppThunkDispatch, RootState, ThunkApiType } from "../store"; |
| 28 | -import { IIdeMessenger } from "../../context/IdeMessenger"; | |
| 29 | 29 | import { constructMessages } from "../util/constructMessages"; |
| 30 | 30 | |
| 31 | 31 | import { modelSupportsNativeTools } from "core/llm/toolSupport"; |
| @@ -192,6 +192,38 @@ | ||
| 192 | 192 | return allAutoApproved; |
| 193 | 193 | } |
| 194 | 194 | |
| 195 | +/** | |
| 196 | + * Builds completion options with reasoning configuration based on session state and model capabilities. | |
| 197 | + * | |
| 198 | + * @param baseOptions - Base completion options to extend | |
| 199 | + * @param hasReasoningEnabled - Whether reasoning is enabled in the session | |
| 200 | + * @param model - The selected model with provider and completion options | |
| 201 | + * @returns Completion options with reasoning configuration | |
| 202 | + */ | |
| 203 | +function buildReasoningCompletionOptions( | |
| 204 | + baseOptions: LLMFullCompletionOptions, | |
| 205 | + hasReasoningEnabled: boolean | undefined, | |
| 206 | + model: ModelDescription, | |
| 207 | +): LLMFullCompletionOptions { | |
| 208 | + if (hasReasoningEnabled === undefined) { | |
| 209 | + return baseOptions; | |
| 210 | + } | |
| 211 | + | |
| 212 | + const reasoningOptions: LLMFullCompletionOptions = { | |
| 213 | + ...baseOptions, | |
| 214 | + reasoning: !!hasReasoningEnabled, | |
| 215 | + }; | |
| 216 | + | |
| 217 | + // Add reasoning budget tokens if reasoning is enabled and provider supports it | |
| 218 | + if (hasReasoningEnabled && model.underlyingProviderName !== "ollama") { | |
| 219 | + // Ollama doesn't support limiting reasoning tokens at this point | |
| 220 | + reasoningOptions.reasoningBudgetTokens = | |
| 221 | + model.completionOptions?.reasoningBudgetTokens ?? 2048; | |
| 222 | + } | |
| 223 | + | |
| 224 | + return reasoningOptions; | |
| 225 | +} | |
| 226 | + | |
| 195 | 227 | export const streamNormalInput = createAsyncThunk< |
| 196 | 228 | void, |
| 197 | 229 | { |
| @@ -228,14 +260,11 @@ | ||
| 228 | 260 | }; |
| 229 | 261 | } |
| 230 | 262 | |
| 231 | - if (state.session.hasReasoningEnabled) { | |
| 232 | - completionOptions = { | |
| 233 | - ...completionOptions, | |
| 234 | - reasoning: true, | |
| 235 | - reasoningBudgetTokens: | |
| 236 | - selectedChatModel.completionOptions?.reasoningBudgetTokens ?? 2048, | |
| 237 | - }; | |
| 238 | - } | |
| 263 | + completionOptions = buildReasoningCompletionOptions( | |
| 264 | + completionOptions, | |
| 265 | + state.session.hasReasoningEnabled, | |
| 266 | + selectedChatModel, | |
| 267 | + ); | |
| 239 | 268 | |
| 240 | 269 | // Construct messages (excluding system message) |
| 241 | 270 | const baseSystemMessage = getBaseSystemMessage( |
modified gui/src/redux/thunks/streamResponse.test.ts +15 −5
| @@ -435,12 +435,16 @@ | ||
| 435 | 435 | ], |
| 436 | 436 | }, |
| 437 | 437 | ], |
| 438 | - options: {}, | |
| 438 | + options: { | |
| 439 | + reasoning: false, | |
| 440 | + }, | |
| 439 | 441 | }); |
| 440 | 442 | |
| 441 | 443 | expect(mockIdeMessenger.llmStreamChat).toHaveBeenCalledWith( |
| 442 | 444 | { |
| 443 | - completionOptions: {}, | |
| 445 | + completionOptions: { | |
| 446 | + reasoning: false, | |
| 447 | + }, | |
| 444 | 448 | legacySlashCommandData: undefined, |
| 445 | 449 | messageOptions: { precompiled: true }, |
| 446 | 450 | messages: [ |
| @@ -918,7 +922,9 @@ | ||
| 918 | 922 | ], |
| 919 | 923 | }, |
| 920 | 924 | ], |
| 921 | - options: {}, | |
| 925 | + options: { | |
| 926 | + reasoning: false, | |
| 927 | + }, | |
| 922 | 928 | }, |
| 923 | 929 | ); |
| 924 | 930 | |
| @@ -1527,13 +1533,17 @@ | ||
| 1527 | 1533 | ], |
| 1528 | 1534 | }, |
| 1529 | 1535 | ], |
| 1530 | - options: {}, | |
| 1536 | + options: { | |
| 1537 | + reasoning: false, | |
| 1538 | + }, | |
| 1531 | 1539 | }, |
| 1532 | 1540 | ); |
| 1533 | 1541 | |
| 1534 | 1542 | expect(mockIdeMessengerAbort.llmStreamChat).toHaveBeenCalledWith( |
| 1535 | 1543 | { |
| 1536 | - completionOptions: {}, | |
| 1544 | + completionOptions: { | |
| 1545 | + reasoning: false, | |
| 1546 | + }, | |
| 1537 | 1547 | legacySlashCommandData: undefined, |
| 1538 | 1548 | messageOptions: { precompiled: true }, |
| 1539 | 1549 | messages: [ |
modified gui/src/redux/thunks/streamResponse_errorHandling.test.ts +6 −2
| @@ -677,7 +677,9 @@ | ||
| 677 | 677 | ], |
| 678 | 678 | }, |
| 679 | 679 | ], |
| 680 | - options: {}, | |
| 680 | + options: { | |
| 681 | + reasoning: false, | |
| 682 | + }, | |
| 681 | 683 | }); |
| 682 | 684 | expect(mockIdeMessenger.llmStreamChat).not.toHaveBeenCalled(); |
| 683 | 685 | |
| @@ -1027,7 +1029,9 @@ | ||
| 1027 | 1029 | ], |
| 1028 | 1030 | }, |
| 1029 | 1031 | ], |
| 1030 | - options: {}, | |
| 1032 | + options: { | |
| 1033 | + reasoning: false, | |
| 1034 | + }, | |
| 1031 | 1035 | }); |
| 1032 | 1036 | expect(mockIdeMessenger.llmStreamChat).not.toHaveBeenCalled(); |
| 1033 | 1037 |
modified gui/src/redux/thunks/streamResponse_toolCalls.test.ts +15 −5
| @@ -535,7 +535,9 @@ | ||
| 535 | 535 | ], |
| 536 | 536 | }, |
| 537 | 537 | ], |
| 538 | - options: {}, | |
| 538 | + options: { | |
| 539 | + reasoning: false, | |
| 540 | + }, | |
| 539 | 541 | }, |
| 540 | 542 | ); |
| 541 | 543 | |
| @@ -1217,13 +1219,17 @@ | ||
| 1217 | 1219 | ], |
| 1218 | 1220 | }, |
| 1219 | 1221 | ], |
| 1220 | - options: {}, | |
| 1222 | + options: { | |
| 1223 | + reasoning: false, | |
| 1224 | + }, | |
| 1221 | 1225 | }, |
| 1222 | 1226 | ); |
| 1223 | 1227 | |
| 1224 | 1228 | expect(mockIdeMessengerReject.llmStreamChat).toHaveBeenCalledWith( |
| 1225 | 1229 | { |
| 1226 | - completionOptions: {}, | |
| 1230 | + completionOptions: { | |
| 1231 | + reasoning: false, | |
| 1232 | + }, | |
| 1227 | 1233 | legacySlashCommandData: undefined, |
| 1228 | 1234 | messageOptions: { precompiled: true }, |
| 1229 | 1235 | messages: [ |
| @@ -1877,13 +1883,17 @@ | ||
| 1877 | 1883 | ], |
| 1878 | 1884 | }, |
| 1879 | 1885 | ], |
| 1880 | - options: {}, | |
| 1886 | + options: { | |
| 1887 | + reasoning: false, | |
| 1888 | + }, | |
| 1881 | 1889 | }, |
| 1882 | 1890 | ); |
| 1883 | 1891 | |
| 1884 | 1892 | expect(mockIdeMessengerManual.llmStreamChat).toHaveBeenCalledWith( |
| 1885 | 1893 | { |
| 1886 | - completionOptions: {}, | |
| 1894 | + completionOptions: { | |
| 1895 | + reasoning: false, | |
| 1896 | + }, | |
| 1887 | 1897 | legacySlashCommandData: undefined, |
| 1888 | 1898 | messageOptions: { precompiled: true }, |
| 1889 | 1899 | messages: [ |
modified gui/src/util/clientTools/editImpl.ts +3 −9
| @@ -17,13 +17,13 @@ | ||
| 17 | 17 | filepath = filepath.slice(2); |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | - const openFiles = await extras.ideMessenger.ide.getOpenFiles(); | |
| 21 | 20 | let firstUriMatch = await resolveRelativePathInDir( |
| 22 | 21 | filepath, |
| 23 | 22 | extras.ideMessenger.ide, |
| 24 | 23 | ); |
| 25 | 24 | |
| 26 | 25 | if (!firstUriMatch) { |
| 26 | + const openFiles = await extras.ideMessenger.ide.getOpenFiles(); | |
| 27 | 27 | for (const uri of openFiles) { |
| 28 | 28 | if (uri.endsWith(filepath)) { |
| 29 | 29 | firstUriMatch = uri; |
| @@ -46,13 +46,7 @@ | ||
| 46 | 46 | ); |
| 47 | 47 | |
| 48 | 48 | return { |
| 49 | - respondImmediately: true, | |
| 50 | - output: [ | |
| 51 | - { | |
| 52 | - name: "File edited successfully", | |
| 53 | - content: `Successfully initiated edit for ${firstUriMatch}`, | |
| 54 | - description: "File edit operation started", | |
| 55 | - }, | |
| 56 | - ], | |
| 49 | + respondImmediately: false, | |
| 50 | + output: undefined, // no immediate output - output for edit tools should be added based on apply state coming in | |
| 57 | 51 | }; |
| 58 | 52 | }; |
added packages/config-yaml/src/__tests__/test-files/invokable-rules.yaml +23 −0
| @@ -0,0 +1,23 @@ | ||
| 1 | +name: Test Invokable Rules | |
| 2 | +version: 0.0.1 | |
| 3 | +schema: v1 | |
| 4 | + | |
| 5 | +rules: | |
| 6 | + - name: "Code Review" | |
| 7 | + rule: "Review this code for best practices and potential issues" | |
| 8 | + invokable: true | |
| 9 | + description: "Performs a code review" | |
| 10 | + | |
| 11 | + - name: "Explain Code" | |
| 12 | + rule: "Explain what this code does in simple terms" | |
| 13 | + invokable: true | |
| 14 | + | |
| 15 | + - name: "Regular Rule" | |
| 16 | + rule: "This is a non-invokable rule" | |
| 17 | + invokable: false | |
| 18 | + | |
| 19 | + - name: "Default Rule" | |
| 20 | + rule: "This rule has no invokable property" | |
| 21 | + description: "Should default to non-invokable" | |
| 22 | + | |
| 23 | + - "Simple string rule" | |
| No newline at the end of the file |
modified packages/config-yaml/src/schemas/index.ts +1 −0
| @@ -57,6 +57,7 @@ | ||
| 57 | 57 | globs: z.union([z.string(), z.array(z.string())]).optional(), |
| 58 | 58 | regex: z.union([z.string(), z.array(z.string())]).optional(), |
| 59 | 59 | alwaysApply: z.boolean().optional(), |
| 60 | + invokable: z.boolean().optional(), | |
| 60 | 61 | sourceFile: z.string().optional(), //TODO refactor RuleWithSource.ruleFile to align with sourceFile |
| 61 | 62 | }); |
| 62 | 63 | const ruleSchema = z.union([z.string(), ruleObjectSchema]); |
modified packages/config-yaml/src/schemas/models.ts +1 −0
| @@ -121,6 +121,7 @@ | ||
| 121 | 121 | modelTimeout: z.number().optional(), |
| 122 | 122 | maxSuffixPercentage: z.number().optional(), |
| 123 | 123 | prefixPercentage: z.number().optional(), |
| 124 | + transform: z.boolean().optional(), | |
| 124 | 125 | template: z.string().optional(), |
| 125 | 126 | onlyMyCode: z.boolean().optional(), |
| 126 | 127 | useCache: z.boolean().optional(), |
modified packages/terminal-security/package-lock.json +9 −9
| @@ -1322,14 +1322,14 @@ | ||
| 1322 | 1322 | "license": "MIT" |
| 1323 | 1323 | }, |
| 1324 | 1324 | "node_modules/tinyglobby": { |
| 1325 | - "version": "0.2.14", | |
| 1326 | - "resolved": "https://registry.npmjs.org/tinyglobby/-/tinyglobby-0.2.14.tgz", | |
| 1327 | - "integrity": "sha512-tX5e7OM1HnYr2+a2C/4V0htOcSQcoSTH9KgJnVvNm5zm/cyEWKJ7j7YutsH9CxMdtOkkLFy2AHrMci9IM8IPZQ==", | |
| 1325 | + "version": "0.2.15", | |
| 1326 | + "resolved": "https://registry.npmjs.org/tinyglobby/-/tinyglobby-0.2.15.tgz", | |
| 1327 | + "integrity": "sha512-j2Zq4NyQYG5XMST4cbs02Ak8iJUdxRM0XI5QyxXuZOzKOINmWurp3smXu3y5wDcJrptwpSjgXHzIQxR0omXljQ==", | |
| 1328 | 1328 | "dev": true, |
| 1329 | 1329 | "license": "MIT", |
| 1330 | 1330 | "dependencies": { |
| 1331 | - "fdir": "^6.4.4", | |
| 1332 | - "picomatch": "^4.0.2" | |
| 1331 | + "fdir": "^6.5.0", | |
| 1332 | + "picomatch": "^4.0.3" | |
| 1333 | 1333 | }, |
| 1334 | 1334 | "engines": { |
| 1335 | 1335 | "node": ">=12.0.0" |
| @@ -1390,9 +1390,9 @@ | ||
| 1390 | 1390 | "license": "MIT" |
| 1391 | 1391 | }, |
| 1392 | 1392 | "node_modules/vite": { |
| 1393 | - "version": "7.1.4", | |
| 1394 | - "resolved": "https://registry.npmjs.org/vite/-/vite-7.1.4.tgz", | |
| 1395 | - "integrity": "sha512-X5QFK4SGynAeeIt+A7ZWnApdUyHYm+pzv/8/A57LqSGcI88U6R6ipOs3uCesdc6yl7nl+zNO0t8LmqAdXcQihw==", | |
| 1393 | + "version": "7.1.5", | |
| 1394 | + "resolved": "https://registry.npmjs.org/vite/-/vite-7.1.5.tgz", | |
| 1395 | + "integrity": "sha512-4cKBO9wR75r0BeIWWWId9XK9Lj6La5X846Zw9dFfzMRw38IlTk2iCcUt6hsyiDRcPidc55ZParFYDXi0nXOeLQ==", | |
| 1396 | 1396 | "dev": true, |
| 1397 | 1397 | "license": "MIT", |
| 1398 | 1398 | "dependencies": { |
| @@ -1401,7 +1401,7 @@ | ||
| 1401 | 1401 | "picomatch": "^4.0.3", |
| 1402 | 1402 | "postcss": "^8.5.6", |
| 1403 | 1403 | "rollup": "^4.43.0", |
| 1404 | - "tinyglobby": "^0.2.14" | |
| 1404 | + "tinyglobby": "^0.2.15" | |
| 1405 | 1405 | }, |
| 1406 | 1406 | "bin": { |
| 1407 | 1407 | "vite": "bin/vite.js" |
modified scripts/install-dependencies.sh +1 −1
| @@ -45,7 +45,7 @@ | ||
| 45 | 45 | pushd gui |
| 46 | 46 | npm install |
| 47 | 47 | npm link @continuedev/core |
| 48 | -npm run build | |
| 48 | +NODE_OPTIONS="--max-old-space-size=4096" npm run build | |
| 49 | 49 | popd |
| 50 | 50 | |
| 51 | 51 | # VSCode Extension (will also package GUI) |