Changesets · Branches · Tags · Compare
| Changeset | 7d35f41c7d13685e3c130005174b7252dbc370495093c928d7b4f083a6979e58 |
|---|---|
| Author | Nate <sestinj@gmail.com> · 2025-09-08 11:50 -07:00 |
| Committer | Nate <sestinj@gmail.com> · 2025-09-08 11:50 -07:00 |
| Parents | 0054f0ed575b, d96431e8a728 |
40 files changed
modified .github/workflows/cli-pr-checks.yml +1 −0
| @@ -59,6 +59,7 @@ | ||
| 59 | 59 | matrix: |
| 60 | 60 | os: [ubuntu-latest, windows-latest, macos-latest] |
| 61 | 61 | node-version: [18, 20, 22, 24] |
| 62 | + fail-fast: false | |
| 62 | 63 | runs-on: ${{ matrix.os }} |
| 63 | 64 | |
| 64 | 65 | steps: |
modified .github/workflows/compliance.yaml +1 −1
| @@ -41,7 +41,7 @@ | ||
| 41 | 41 | |
| 42 | 42 | - name: Add PR title guidance comment |
| 43 | 43 | if: always() && steps.pr-title-check.outputs.valid == 'false' |
| 44 | - uses: actions/github-script@v7 | |
| 44 | + uses: actions/github-script@v8 | |
| 45 | 45 | with: |
| 46 | 46 | script: | |
| 47 | 47 | const { data: comments } = await github.rest.issues.listComments({ |
modified .github/workflows/label-merged-prs.yml +1 −1
| @@ -44,7 +44,7 @@ | ||
| 44 | 44 | |
| 45 | 45 | - name: Determine and apply tier label |
| 46 | 46 | if: steps.check-author.outputs.should_label == 'true' |
| 47 | - uses: actions/github-script@v7 | |
| 47 | + uses: actions/github-script@v8 | |
| 48 | 48 | with: |
| 49 | 49 | script: | |
| 50 | 50 | const pr = context.payload.pull_request; |
modified .github/workflows/respond-to-cubic.yaml +46 −8
| @@ -29,7 +29,7 @@ | ||
| 29 | 29 | |
| 30 | 30 | - name: Add eyes reaction to comment |
| 31 | 31 | if: steps.check-mention.outputs.contains_mention == 'true' |
| 32 | - uses: actions/github-script@v7 | |
| 32 | + uses: actions/github-script@v8 | |
| 33 | 33 | with: |
| 34 | 34 | script: | |
| 35 | 35 | await github.rest.reactions.createForIssueComment({ |
| @@ -49,7 +49,7 @@ | ||
| 49 | 49 | - name: Get PR information |
| 50 | 50 | if: steps.check-mention.outputs.contains_mention == 'true' |
| 51 | 51 | id: pr-info |
| 52 | - uses: actions/github-script@v7 | |
| 52 | + uses: actions/github-script@v8 | |
| 53 | 53 | with: |
| 54 | 54 | script: | |
| 55 | 55 | const { data: pr } = await github.rest.pulls.get({ |
| @@ -107,7 +107,7 @@ | ||
| 107 | 107 | |
| 108 | 108 | - name: Comment with session URL |
| 109 | 109 | if: steps.check-mention.outputs.contains_mention == 'true' && steps.remote-session.outputs.session_url |
| 110 | - uses: actions/github-script@v7 | |
| 110 | + uses: actions/github-script@v8 | |
| 111 | 111 | with: |
| 112 | 112 | script: | |
| 113 | 113 | const commentBody = `I've started [a remote session](${{ steps.remote-session.outputs.session_url }}) to help with your request: |
| @@ -144,7 +144,7 @@ | ||
| 144 | 144 | |
| 145 | 145 | - name: Add eyes reaction to comment |
| 146 | 146 | if: steps.check-mention.outputs.contains_mention == 'true' |
| 147 | - uses: actions/github-script@v7 | |
| 147 | + uses: actions/github-script@v8 | |
| 148 | 148 | with: |
| 149 | 149 | script: | |
| 150 | 150 | await github.rest.reactions.createForPullRequestReviewComment({ |
| @@ -172,21 +172,59 @@ | ||
| 172 | 172 | if: steps.check-mention.outputs.contains_mention == 'true' |
| 173 | 173 | run: npm i -g @continuedev/cli |
| 174 | 174 | |
| 175 | + - name: Get review context | |
| 176 | + if: steps.check-mention.outputs.contains_mention == 'true' | |
| 177 | + id: review-context | |
| 178 | + uses: actions/github-script@v7 | |
| 179 | + with: | |
| 180 | + script: | | |
| 181 | + let reviewContext = ''; | |
| 182 | + | |
| 183 | + // Check if this comment is a reply to another review comment | |
| 184 | + if (context.payload.comment.in_reply_to_id) { | |
| 185 | + try { | |
| 186 | + const { data: originalComment } = await github.rest.pulls.getReviewComment({ | |
| 187 | + owner: context.repo.owner, | |
| 188 | + repo: context.repo.repo, | |
| 189 | + comment_id: context.payload.comment.in_reply_to_id | |
| 190 | + }); | |
| 191 | + | |
| 192 | + reviewContext = `**Original review comment by @${originalComment.user.login}:** | |
| 193 | + ${originalComment.body} | |
| 194 | + | |
| 195 | + **Reply by @${{ github.event.comment.user.login }}:** | |
| 196 | + ${{ github.event.comment.body }}`; | |
| 197 | + } catch (error) { | |
| 198 | + console.log('Could not fetch original comment, using current comment only'); | |
| 199 | + reviewContext = `**Review comment by @${{ github.event.comment.user.login }}:** | |
| 200 | + ${{ github.event.comment.body }}`; | |
| 201 | + } | |
| 202 | + } else { | |
| 203 | + reviewContext = `**Review comment by @${{ github.event.comment.user.login }}:** | |
| 204 | + ${{ github.event.comment.body }}`; | |
| 205 | + } | |
| 206 | + | |
| 207 | + core.setOutput('context', reviewContext); | |
| 208 | + | |
| 175 | 209 | - name: Start remote session |
| 176 | 210 | if: steps.check-mention.outputs.contains_mention == 'true' |
| 177 | 211 | id: remote-session |
| 178 | 212 | env: |
| 179 | 213 | CONTINUE_API_KEY: ${{ secrets.CONTINUE_API_KEY }} |
| 180 | 214 | run: | |
| 215 | + # Debug: Echo the branch we're starting the session on | |
| 216 | + echo "Starting remote session on branch: ${{ github.event.pull_request.head.ref }}" | |
| 217 | + | |
| 181 | 218 | # Create a temporary file for the prompt to handle special characters and newlines properly |
| 182 | 219 | cat > /tmp/prompt.txt << 'PROMPT_EOF' |
| 183 | - Please help with the following code review comment from @${{ github.event.comment.user.login }} on PR #${{ github.event.pull_request.number }}: | |
| 220 | + Please help with the following code review discussion from PR #${{ github.event.pull_request.number }}: | |
| 184 | 221 | |
| 185 | 222 | **File:** ${{ github.event.comment.path }} |
| 186 | 223 | **Line:** ${{ github.event.comment.line || github.event.comment.original_line || 'N/A' }} |
| 187 | - **Comment:** ${{ github.event.comment.body }} | |
| 188 | 224 | |
| 189 | - Please analyze the specific file and line mentioned, understand the review feedback, implement the necessary changes, and commit them to this branch. | |
| 225 | + ${{ steps.review-context.outputs.context }} | |
| 226 | + | |
| 227 | + Please analyze the specific file and line mentioned, understand the review feedback and any discussion context, implement the necessary changes, and commit them to this branch. | |
| 190 | 228 | PROMPT_EOF |
| 191 | 229 | |
| 192 | 230 | # Debug output |
| @@ -211,7 +249,7 @@ | ||
| 211 | 249 | |
| 212 | 250 | - name: Comment with session URL |
| 213 | 251 | if: steps.check-mention.outputs.contains_mention == 'true' && steps.remote-session.outputs.session_url |
| 214 | - uses: actions/github-script@v7 | |
| 252 | + uses: actions/github-script@v8 | |
| 215 | 253 | with: |
| 216 | 254 | script: | |
| 217 | 255 | const commentBody = `I've started [a remote session](${{ steps.remote-session.outputs.session_url }}) to help with your request: |
modified .github/workflows/similar-issues.yml +2 −2
| @@ -190,7 +190,7 @@ | ||
| 190 | 190 | echo "confidence=$CONFIDENCE" >> $GITHUB_OUTPUT |
| 191 | 191 | |
| 192 | 192 | - name: Comment with analysis |
| 193 | - uses: actions/github-script@v7 | |
| 193 | + uses: actions/github-script@v8 | |
| 194 | 194 | with: |
| 195 | 195 | script: | |
| 196 | 196 | let comment = ''; |
| @@ -307,7 +307,7 @@ | ||
| 307 | 307 | |
| 308 | 308 | - name: Add labels |
| 309 | 309 | if: github.event_name == 'issues' |
| 310 | - uses: actions/github-script@v7 | |
| 310 | + uses: actions/github-script@v8 | |
| 311 | 311 | with: |
| 312 | 312 | script: | |
| 313 | 313 | const labels = []; |
modified core/llm/index.ts +13 −11
| @@ -370,8 +370,17 @@ | ||
| 370 | 370 | }, |
| 371 | 371 | }); |
| 372 | 372 | |
| 373 | - if (error !== undefined) { | |
| 374 | - if (error === "cancel" || error.name === "AbortError") { | |
| 373 | + if (typeof error === "undefined") { | |
| 374 | + interaction?.logItem({ | |
| 375 | + kind: "success", | |
| 376 | + promptTokens, | |
| 377 | + generatedTokens, | |
| 378 | + thinkingTokens, | |
| 379 | + usage, | |
| 380 | + }); | |
| 381 | + return "success"; | |
| 382 | + } else { | |
| 383 | + if (error === "cancel" || error?.name?.includes("AbortError")) { | |
| 375 | 384 | interaction?.logItem({ |
| 376 | 385 | kind: "cancel", |
| 377 | 386 | promptTokens, |
| @@ -393,15 +402,6 @@ | ||
| 393 | 402 | }); |
| 394 | 403 | return "error"; |
| 395 | 404 | } |
| 396 | - } else { | |
| 397 | - interaction?.logItem({ | |
| 398 | - kind: "success", | |
| 399 | - promptTokens, | |
| 400 | - generatedTokens, | |
| 401 | - thinkingTokens, | |
| 402 | - usage, | |
| 403 | - }); | |
| 404 | - return "success"; | |
| 405 | 405 | } |
| 406 | 406 | } |
| 407 | 407 | |
| @@ -615,6 +615,7 @@ | ||
| 615 | 615 | kind: "chunk", |
| 616 | 616 | chunk: formattedContent, |
| 617 | 617 | }); |
| 618 | + | |
| 618 | 619 | completion += formattedContent; |
| 619 | 620 | yield content; |
| 620 | 621 | } |
| @@ -630,6 +631,7 @@ | ||
| 630 | 631 | kind: "chunk", |
| 631 | 632 | chunk, |
| 632 | 633 | }); |
| 634 | + | |
| 633 | 635 | completion += chunk; |
| 634 | 636 | yield chunk; |
| 635 | 637 | } |
modified core/tools/definitions/editFile.ts +1 −1
| @@ -8,7 +8,7 @@ | ||
| 8 | 8 | } |
| 9 | 9 | |
| 10 | 10 | export const NO_PARALLEL_TOOL_CALLING_INTSRUCTION = |
| 11 | - "Note this tool CANNOT be called in parallel with other tools."; | |
| 11 | + "This tool CANNOT be called in parallel with other tools."; | |
| 12 | 12 | |
| 13 | 13 | const CHANGES_DESCRIPTION = |
| 14 | 14 | "Any modifications to the file, showing only needed changes. Do NOT wrap this in a codeblock or write anything besides the code changes. In larger files, use brief language-appropriate placeholders for large unmodified sections, e.g. '// ... existing code ...'"; |
modified core/tools/definitions/multiEdit.ts +28 −44
| @@ -1,6 +1,7 @@ | ||
| 1 | 1 | import { Tool } from "../.."; |
| 2 | 2 | import { BUILT_IN_GROUP_NAME, BuiltInToolNames } from "../builtIn"; |
| 3 | 3 | import { NO_PARALLEL_TOOL_CALLING_INTSRUCTION } from "./editFile"; |
| 4 | +import { singleFindAndReplaceTool } from "./singleFindAndReplace"; | |
| 4 | 5 | |
| 5 | 6 | export interface EditOperation { |
| 6 | 7 | old_string: string; |
| @@ -24,60 +25,41 @@ | ||
| 24 | 25 | isInstant: false, |
| 25 | 26 | function: { |
| 26 | 27 | name: BuiltInToolNames.MultiEdit, |
| 27 | - description: `This is a tool for making multiple edits to a single file in one operation. It | |
| 28 | -is built on top of the single find and replace tool and allows you to perform multiple | |
| 29 | -find-and-replace operations efficiently. Prefer this tool over the single find and replace tool | |
| 30 | -when you need to make multiple edits to the same file. | |
| 31 | - | |
| 32 | -Before using this tool: | |
| 33 | - | |
| 34 | -1. Use the read_file tool to understand the file's contents and context | |
| 35 | -2. Verify the directory path is correct | |
| 36 | - | |
| 37 | -To make multiple file edits, provide the following: | |
| 38 | - | |
| 39 | -1. filepath: The path to the file to modify (relative to the root of the workspace) | |
| 28 | + description: `This is a tool for making multiple edits to a single file in one operation. It is built on top of the ${singleFindAndReplaceTool.function.name} and allows you to perform multiple find-and-replace operations efficiently. | |
| 29 | +Prefer this tool over the ${singleFindAndReplaceTool.function.name} tool when you need to make multiple edits to the same file. | |
| 30 | + | |
| 31 | +To make multiple edits to a file, provide the following: | |
| 32 | +1. filepath: The path to the file to modify, RELATIVE to the project/workspace root (verify the directory path is correct) | |
| 40 | 33 | 2. edits: An array of edit operations to perform, where each edit contains: |
| 41 | - - old_string: The text to replace (must match the file contents exactly, including all whitespace and indentation) | |
| 34 | + - old_string: The text to replace (must match the old file contents exactly, including all whitespace/indentation) | |
| 42 | 35 | - new_string: The edited text to replace the old_string |
| 43 | 36 | - replace_all: Replace all occurrences of old_string. This parameter is optional and defaults to false. |
| 44 | 37 | |
| 45 | 38 | IMPORTANT: |
| 46 | 39 | - All edits are applied in sequence, in the order they are provided |
| 47 | -- Each edit operates on the result of the previous edit | |
| 48 | -- All edits must be valid for the operation to succeed - if any edit fails, | |
| 49 | -none will be applied | |
| 50 | -- This tool is ideal when you need to make several changes to different parts | |
| 51 | -of the same file | |
| 40 | +- Each edit operates on the result of the previous edit, so plan your edits carefully to avoid conflicts between sequential operations | |
| 41 | +- Edits are atomic - all edits must be valid for the operation to succeed - if any edit fails, none will be applied | |
| 42 | +- This tool is ideal when you need to make several changes to different parts of the same file | |
| 52 | 43 | |
| 53 | 44 | CRITICAL REQUIREMENTS: |
| 54 | - | |
| 55 | -1. All edits follow the same requirements as the single find and replace tool | |
| 56 | -2. The edits are atomic - either all succeed or none are applied | |
| 57 | -3. Plan your edits carefully to avoid conflicts between sequential operations | |
| 58 | -4. ${NO_PARALLEL_TOOL_CALLING_INTSRUCTION} | |
| 59 | - | |
| 60 | -WARNING: | |
| 61 | - | |
| 62 | -- The tool will fail if edits.old_string doesn't match the file contents | |
| 63 | -exactly (including whitespace) | |
| 64 | -- The tool will fail if edits.old_string and edits.new_string are the same | |
| 65 | -- Since edits are applied in sequence, ensure that earlier edits don't affect | |
| 66 | -the text that later edits are trying to find | |
| 67 | - | |
| 68 | -When making edits: | |
| 69 | - | |
| 45 | +1. ALWAYS use the ${BuiltInToolNames.ReadFile} tool just before making edits, to understand the file's up-to-date contents and context. The user can also edit the file while you are working with it. | |
| 46 | +2. ${NO_PARALLEL_TOOL_CALLING_INTSRUCTION} | |
| 47 | +3. When making edits: | |
| 70 | 48 | - Ensure all edits result in idiomatic, correct code |
| 71 | 49 | - Do not leave the code in a broken state |
| 72 | -- Only use emojis if the user explicitly requests it. Avoid adding emojis to | |
| 73 | -files unless asked. | |
| 74 | -- Use replace_all for replacing and renaming strings across the file. This | |
| 75 | -parameter is useful if you want to rename a variable for instance. | |
| 50 | +- Only use emojis if the user explicitly requests it. Avoid adding emojis to files unless asked | |
| 51 | +- Use replace_all for replacing and renaming all matches for a string across the file. This parameter is useful if you want to rename a variable, for instance | |
| 76 | 52 | |
| 77 | 53 | If you want to create a new file, use: |
| 78 | -- A new file path | |
| 54 | +- A new file path, including new directory if needed | |
| 79 | 55 | - First edit: empty old_string and the new file's contents as new_string |
| 80 | -- Subsequent edits are not allowed - there is no need since you are creating`, | |
| 56 | +- Subsequent edits are not allowed - there is no need since you are creating | |
| 57 | +- ALWAYS prefer editing existing files in the codebase. NEVER write new files unless explicitly required | |
| 58 | + | |
| 59 | +WARNINGS: | |
| 60 | +- If earlier edits affect the text that later edits are trying to find, files can become mangled | |
| 61 | +- The tool will fail if edits.old_string doesn't match the file contents exactly (including whitespace) | |
| 62 | +- The tool will fail if edits.old_string and edits.new_string are the same - they MUST be different`, | |
| 81 | 63 | parameters: { |
| 82 | 64 | type: "object", |
| 83 | 65 | required: ["filepath", "edits"], |
| @@ -97,16 +79,18 @@ | ||
| 97 | 79 | properties: { |
| 98 | 80 | old_string: { |
| 99 | 81 | type: "string", |
| 100 | - description: "The text to replace", | |
| 82 | + description: | |
| 83 | + "The text to replace (exact match including whitespace/indentation)", | |
| 101 | 84 | }, |
| 102 | 85 | new_string: { |
| 103 | 86 | type: "string", |
| 104 | - description: "The text to replace it with", | |
| 87 | + description: | |
| 88 | + "The text to replace it with. MUST be different than old_string.", | |
| 105 | 89 | }, |
| 106 | 90 | replace_all: { |
| 107 | 91 | type: "boolean", |
| 108 | 92 | description: |
| 109 | - "Replace all occurrences of old_string (default false)", | |
| 93 | + "Replace all occurrences of old_string (default false) in the file", | |
| 110 | 94 | }, |
| 111 | 95 | }, |
| 112 | 96 | }, |
modified core/tools/definitions/singleFindAndReplace.ts +13 −27
| @@ -20,33 +20,18 @@ | ||
| 20 | 20 | isInstant: false, |
| 21 | 21 | function: { |
| 22 | 22 | name: BuiltInToolNames.SingleFindAndReplace, |
| 23 | - description: `Performs exact string replacements in files. | |
| 24 | - | |
| 25 | -Usage: | |
| 26 | - | |
| 27 | -- You must use your \`read_file\` tool at least once in the conversation before | |
| 28 | -editing. This tool will error if you attempt an edit without reading the file. | |
| 29 | - | |
| 30 | -- When editing text from read_file tool output, ensure you preserve the exact | |
| 31 | -indentation (tabs/spaces) as it appears AFTER the line number prefix. The line | |
| 32 | -number prefix format is: spaces + line number + tab. Everything after that tab | |
| 33 | -is the actual file content to match. Never include any part of the line number | |
| 34 | -prefix in the old_string or new_string. | |
| 35 | - | |
| 36 | -- ALWAYS prefer editing existing files in the codebase. NEVER write new files | |
| 37 | -unless explicitly required. | |
| 38 | - | |
| 39 | -- Only use emojis if the user explicitly requests it. Avoid adding emojis to | |
| 40 | -files unless asked. | |
| 23 | + description: `Performs exact string replacements in a file. | |
| 41 | 24 | |
| 25 | +IMPORTANT: | |
| 26 | +- ALWAYS use the \`${BuiltInToolNames.ReadFile}\` tool just before making edits, to understand the file's up-to-date contents and context. The user can also edit the file while you are working with it. | |
| 42 | 27 | - ${NO_PARALLEL_TOOL_CALLING_INTSRUCTION} |
| 43 | - | |
| 44 | -- The edit will FAIL if \`old_string\` is not unique in the file. Either provide | |
| 45 | -a larger string with more surrounding context to make it unique or use | |
| 46 | -\`replace_all\` to change every instance of \`old_string\`. | |
| 47 | - | |
| 48 | -- Use \`replace_all\` for replacing and renaming strings across the file. This | |
| 49 | -parameter is useful if you want to rename a variable for instance.`, | |
| 28 | +- When editing text from \`${BuiltInToolNames.ReadFile}\` tool output, ensure you preserve exact whitespace/indentation. | |
| 29 | +- Only use emojis if the user explicitly requests it. Avoid adding emojis to files unless asked. | |
| 30 | +- Use \`replace_all\` for replacing and renaming strings across the file. This parameter is useful if you want to rename a variable, for instance. | |
| 31 | + | |
| 32 | +WARNINGS: | |
| 33 | +- When not using \`replace_all\`, the edit will FAIL if \`old_string\` is not unique in the file. Either provide a larger string with more surrounding context to make it unique or use \`replace_all\` to change every instance of \`old_string\`. | |
| 34 | +- The edit will likely fail if you have not recently used the \`${BuiltInToolNames.ReadFile}\` tool to view up-to-date file contents.`, | |
| 50 | 35 | parameters: { |
| 51 | 36 | type: "object", |
| 52 | 37 | required: ["filepath", "old_string", "new_string"], |
| @@ -58,12 +43,13 @@ | ||
| 58 | 43 | }, |
| 59 | 44 | old_string: { |
| 60 | 45 | type: "string", |
| 61 | - description: "The text to replace", | |
| 46 | + description: | |
| 47 | + "The text to replace - must be exact including whitespace/indentation", | |
| 62 | 48 | }, |
| 63 | 49 | new_string: { |
| 64 | 50 | type: "string", |
| 65 | 51 | description: |
| 66 | - "The text to replace it with (must be different from old_string)", | |
| 52 | + "The text to replace it with (MUST be different from old_string)", | |
| 67 | 53 | }, |
| 68 | 54 | replace_all: { |
| 69 | 55 | type: "boolean", |
modified docs/features/autocomplete/how-to-customize.mdx +1 −1
| @@ -3,6 +3,6 @@ | ||
| 3 | 3 | description: “Learn how to customize autocomplete behavior in Continue, including user settings, configuration options, and adjustments to improve AI code suggestions in your IDE.” |
| 4 | 4 | --- |
| 5 | 5 | |
| 6 | -Continue offers a handful of settings to customize autocomplete behavior. Visit the [User Settings Page](/customize/settings) to manage these settings. | |
| 6 | +Continue offers a handful of settings to customize autocomplete behavior. Visit the User Settings Page (Gear Icon) to manage these settings. | |
| 7 | 7 | |
| 8 | 8 | For a comprehensive guide on all configuration options and their impacts, see the [Autocomplete deep dive](/customize/deep-dives/autocomplete). |
modified docs/reference/deprecated-docs.mdx +1 −1
| @@ -408,4 +408,4 @@ | ||
| 408 | 408 | </Tab> |
| 409 | 409 | </Tabs> |
| 410 | 410 | |
| 411 | -This setup could also involve enabling Chromium as a backup for local documentation through the [User Settings Page](../customize/settings). | |
| No newline at the end of the file | ||
| 411 | +This setup could also involve enabling Chromium as a backup for local documentation through the User Settings Page (Gear Icon). | |
| No newline at the end of the file |
added extensions/cli/spec/shell-mode.md +138 −0
| @@ -0,0 +1,138 @@ | ||
| 1 | +shell Mode (CLI TUI) | |
| 2 | + | |
| 3 | +Overview | |
| 4 | + | |
| 5 | +- shell mode lets users run shell commands directly from the chat input by starting their input with an exclamation mark (!). | |
| 6 | +- It is intended for quick terminal command execution without leaving the TUI. | |
| 7 | + | |
| 8 | +Activation | |
| 9 | + | |
| 10 | +- shell mode is activated when the current input (trimmed) starts with ! | |
| 11 | + - Example: "!git status" or " !ls -la" both activate shell mode. | |
| 12 | +- Visual indicator: | |
| 13 | + - Input border color changes to yellow. | |
| 14 | + - The input prompt indicator changes to a yellow "$". | |
| 15 | + - The input placeholder includes "! for shell mode". | |
| 16 | + | |
| 17 | +Deactivation / Exiting shell Mode | |
| 18 | + | |
| 19 | +- Pressing Enter to submit the input exits shell mode immediately after submission, regardless of the command result. | |
| 20 | +- Pressing Esc when the input (trimmed) is exactly ! clears the input and exits shell mode. | |
| 21 | +- Editing the input so it no longer starts with ! also exits shell mode and restores normal input behavior. | |
| 22 | + | |
| 23 | +Interaction with other input helpers | |
| 24 | + | |
| 25 | +- When in shell mode (input starts with !): | |
| 26 | + - "@" file search suggestions are disabled. | |
| 27 | + - "/" slash command UI is disabled. | |
| 28 | +- When in slash command mode (input starts with /): | |
| 29 | + - "@" file search suggestions are disabled. | |
| 30 | + | |
| 31 | +Submission behavior | |
| 32 | + | |
| 33 | +- On submit (Enter) with a shell-mode input: | |
| 34 | + - The leading ! is removed and the remainder is treated as the shell command to run. | |
| 35 | + - The TUI immediately appends an assistant message representing a shell tool call, with status set to calling, so users can see that the command is in progress. | |
| 36 | + - The shell command is executed asynchronously; when it completes, the tool call status is updated to done (or error) and the output is populated. | |
| 37 | + | |
| 38 | +Execution semantics | |
| 39 | + | |
| 40 | +- The command is executed in the same way as terminal tool commands, minus permissions | |
| 41 | + | |
| 42 | +Output handling | |
| 43 | + | |
| 44 | +- Stdout is streamed into memory; Stderr is captured and appended as a trailing "Stderr: ..." section on success. | |
| 45 | +- If the process exits non-zero and Stderr contains content, the tool call is marked as error and the error text is shown. | |
| 46 | +- Output is truncated to the first 5000 lines if exceeded. | |
| 47 | +- Timeout behavior: If no output is received for 30 seconds (configurable in tests), the process is terminated and the result includes a note like: | |
| 48 | + "[Command timed out after 30 seconds of no output]". | |
| 49 | + | |
| 50 | +Keyboard behaviors (summary) | |
| 51 | + | |
| 52 | +- Enter: submit input. If in shell mode, exits shell mode after submission and shows the pending shell tool call immediately. | |
| 53 | +- Shift+Enter: new line. | |
| 54 | +- Backslash (\) at end-of-line: inserts a new line (line continuation) as usual. | |
| 55 | +- Esc: if only ! (trimmed) is present, clears input and exits shell mode; otherwise cancels streaming or closes suggestions depending on context. | |
| 56 | + | |
| 57 | +Scope / Modes | |
| 58 | + | |
| 59 | +- shell mode applies to interactive (TUI/standard) CLI usage. It is not part of headless (-p/--print) processing. | |
| 60 | + | |
| 61 | +Error handling | |
| 62 | + | |
| 63 | +- Command execution errors are captured and surfaced in the tool call as status error with human-readable error text (including Stderr when available). | |
| 64 | + | |
| 65 | +Examples | |
| 66 | + | |
| 67 | +- "!git status" → shows a shell tool call immediately, then populates with the git status output. | |
| 68 | +- "!echo hello" → shows a shell tool call immediately, then output "hello". | |
| 69 | +- "!some-unknown-cmd" → shows a shell tool call immediately, then sets status to error with an error message. | |
| 70 | + Shell Mode (CLI TUI) | |
| 71 | + | |
| 72 | +Overview | |
| 73 | + | |
| 74 | +- Shell mode lets users run shell commands directly from the chat input by starting their input with an exclamation mark (!). | |
| 75 | +- It is intended for quick terminal command execution without leaving the TUI. | |
| 76 | + | |
| 77 | +Activation | |
| 78 | + | |
| 79 | +- Shell mode is activated when the current input (trimmed) starts with ! | |
| 80 | + - Example: "!git status" or " !ls -la" both activate Shell mode. | |
| 81 | +- Visual indicator: | |
| 82 | + - Input border color changes to yellow. | |
| 83 | + - The input prompt indicator changes to a yellow "$". | |
| 84 | + - The input placeholder includes "! for shell mode". | |
| 85 | + | |
| 86 | +Deactivation / Exiting Shell Mode | |
| 87 | + | |
| 88 | +- Pressing Enter to submit the input exits shell mode immediately after submission, regardless of the command result. | |
| 89 | +- Pressing Esc when the input (trimmed) is exactly ! clears the input and exits shell mode. | |
| 90 | +- Editing the input so it no longer starts with ! also exits shell mode and restores normal input behavior. | |
| 91 | + | |
| 92 | +Interaction with other input helpers | |
| 93 | + | |
| 94 | +- When in shell mode (input starts with !): | |
| 95 | + - "@" file search suggestions are disabled. | |
| 96 | + - "/" slash command UI is disabled. | |
| 97 | +- When in slash command mode (input starts with /): | |
| 98 | + - "@" file search suggestions are disabled. | |
| 99 | + | |
| 100 | +Submission behavior | |
| 101 | + | |
| 102 | +- On submit (Enter) with a shell-mode input: | |
| 103 | + - The leading ! is removed and the remainder is treated as the shell command to run. | |
| 104 | + - The TUI immediately appends an assistant message representing a Shell tool call, with status set to calling, so users can see that the command is in progress. | |
| 105 | + - The shell command is executed asynchronously; when it completes, the tool call status is updated to done (or error) and the output is populated. | |
| 106 | + | |
| 107 | +Execution semantics | |
| 108 | + | |
| 109 | +- The command is executed in the same way as terminal tool commands, minus permissions, and inserted into the chat history the same. | |
| 110 | + | |
| 111 | +Output handling | |
| 112 | + | |
| 113 | +- Stdout is streamed into memory; Stderr is captured and appended as a trailing "Stderr: ..." section on success. | |
| 114 | +- If the process exits non-zero and Stderr contains content, the tool call is marked as error and the error text is shown. | |
| 115 | +- Output is truncated to the first 5000 lines if exceeded. | |
| 116 | +- Timeout behavior: If no output is received for 30 seconds (configurable in tests), the process is terminated and the result includes a note like: | |
| 117 | + "[Command timed out after 30 seconds of no output]". | |
| 118 | + | |
| 119 | +Keyboard behaviors (summary) | |
| 120 | + | |
| 121 | +- Enter: submit input. If in shell mode, exits shell mode after submission and shows the pending Shell tool call immediately. | |
| 122 | +- Shift+Enter: new line. | |
| 123 | +- Backslash (\) at end-of-line: inserts a new line (line continuation) as usual. | |
| 124 | +- Esc: if only ! (trimmed) is present, clears input and exits shell mode; otherwise cancels streaming or closes suggestions depending on context. | |
| 125 | + | |
| 126 | +Scope / Modes | |
| 127 | + | |
| 128 | +- Shell mode applies to interactive (TUI/standard) CLI usage. It is not part of headless (-p/--print) processing. | |
| 129 | + | |
| 130 | +Error handling | |
| 131 | + | |
| 132 | +- Command execution errors are captured and surfaced in the tool call as status error with human-readable error text (including Stderr when available). | |
| 133 | + | |
| 134 | +Examples | |
| 135 | + | |
| 136 | +- "!git status" → shows a Shell tool call immediately, then populates with the git status output. | |
| 137 | +- "!echo hello" → shows a Shell tool call immediately, then output "hello". | |
| 138 | +- "!some-unknown-cmd" → shows a Shell tool call immediately, then sets status to error with an error message. |
modified extensions/cli/src/slashCommands.ts +3 −0
| @@ -28,6 +28,7 @@ | ||
| 28 | 28 | ` ${chalk.cyan("Enter")} Submit message`, |
| 29 | 29 | ` ${chalk.cyan("Shift+Enter")} New line`, |
| 30 | 30 | ` ${chalk.cyan("\\")} Line continuation (at end of line)`, |
| 31 | + ` ${chalk.cyan("!")} Shell mode - run shell commands`, | |
| 31 | 32 | "", |
| 32 | 33 | chalk.white("Controls:"), |
| 33 | 34 | ` ${chalk.cyan("Ctrl+C")} Clear input`, |
| @@ -39,9 +40,11 @@ | ||
| 39 | 40 | chalk.white("Special Characters:"), |
| 40 | 41 | ` ${chalk.cyan("@")} Search and attach files for context`, |
| 41 | 42 | ` ${chalk.cyan("/")} Access slash commands`, |
| 43 | + ` ${chalk.cyan("!")} Execute bash commands directly`, | |
| 42 | 44 | "", |
| 43 | 45 | chalk.white("Available Commands:"), |
| 44 | 46 | ` Type ${chalk.cyan("/")} to see available slash commands`, |
| 47 | + ` Type ${chalk.cyan("!")} followed by a command to execute bash directly`, | |
| 45 | 48 | ].join("\n"); |
| 46 | 49 | posthogService.capture("useSlashCommand", { name: "help" }); |
| 47 | 50 | return { output: helpMessage }; |
modified extensions/cli/src/tools/edit.test.ts +8 −5
| @@ -1,8 +1,9 @@ | ||
| 1 | 1 | import * as fs from "fs"; |
| 2 | 2 | |
| 3 | -import { describe, it, expect, beforeEach, afterEach, vi } from "vitest"; | |
| 3 | +import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; | |
| 4 | 4 | |
| 5 | -import { editTool, markFileAsRead, readFilesSet } from "./edit.js"; | |
| 5 | +import { editTool } from "./edit.js"; | |
| 6 | +import { markFileAsRead, readFilesSet } from "./readFile.js"; | |
| 6 | 7 | |
| 7 | 8 | // Mock the dependencies |
| 8 | 9 | vi.mock("../telemetry/telemetryService.js"); |
| @@ -21,6 +22,7 @@ | ||
| 21 | 22 | readFileSync: vi.fn(), |
| 22 | 23 | writeFileSync: vi.fn(), |
| 23 | 24 | unlinkSync: vi.fn(), |
| 25 | + realpathSync: vi.fn(), | |
| 24 | 26 | }; |
| 25 | 27 | }); |
| 26 | 28 | |
| @@ -34,6 +36,7 @@ | ||
| 34 | 36 | vi.mocked(fs.existsSync).mockReturnValue(true); |
| 35 | 37 | vi.mocked(fs.readFileSync).mockReturnValue(originalContent); |
| 36 | 38 | vi.mocked(fs.writeFileSync).mockImplementation(() => {}); |
| 39 | + vi.mocked(fs.realpathSync).mockImplementation((path) => path.toString()); | |
| 37 | 40 | }); |
| 38 | 41 | |
| 39 | 42 | afterEach(() => { |
| @@ -126,7 +129,7 @@ | ||
| 126 | 129 | const result = await editTool.preprocess!(args); |
| 127 | 130 | |
| 128 | 131 | expect(result.args).toEqual({ |
| 129 | - file_path: testFilePath, | |
| 132 | + resolvedPath: testFilePath, | |
| 130 | 133 | newContent: "Hi there\nThis is a test file\nGoodbye world", |
| 131 | 134 | oldContent: originalContent, |
| 132 | 135 | }); |
| @@ -163,7 +166,7 @@ | ||
| 163 | 166 | it("should successfully write file and return success message", async () => { |
| 164 | 167 | const newContent = "Hi there\nThis is a test file\nGoodbye world"; |
| 165 | 168 | const args = { |
| 166 | - file_path: testFilePath, | |
| 169 | + resolvedPath: testFilePath, | |
| 167 | 170 | newContent, |
| 168 | 171 | oldContent: originalContent, |
| 169 | 172 | }; |
| @@ -186,7 +189,7 @@ | ||
| 186 | 189 | }); |
| 187 | 190 | |
| 188 | 191 | const args = { |
| 189 | - file_path: testFilePath, | |
| 192 | + resolvedPath: testFilePath, | |
| 190 | 193 | newContent: "new content", |
| 191 | 194 | oldContent: originalContent, |
| 192 | 195 | }; |
modified extensions/cli/src/tools/edit.ts +38 −53
| @@ -8,6 +8,7 @@ | ||
| 8 | 8 | getLanguageFromFilePath, |
| 9 | 9 | } from "../telemetry/utils.js"; |
| 10 | 10 | |
| 11 | +import { readFilesSet, readFileTool } from "./readFile.js"; | |
| 11 | 12 | import { Tool } from "./types.js"; |
| 12 | 13 | import { generateDiff } from "./writeFile.js"; |
| 13 | 14 | |
| @@ -18,40 +19,23 @@ | ||
| 18 | 19 | replace_all?: boolean; |
| 19 | 20 | } |
| 20 | 21 | |
| 21 | -// Track files that have been read in the current session | |
| 22 | -export const readFilesSet = new Set<string>(); | |
| 23 | - | |
| 24 | 22 | export const editTool: Tool = { |
| 25 | 23 | name: "Edit", |
| 26 | 24 | displayName: "Edit", |
| 27 | 25 | readonly: false, |
| 28 | 26 | isBuiltIn: true, |
| 29 | - description: `Performs exact string replacements in files. | |
| 30 | - | |
| 31 | - | |
| 32 | -Usage: | |
| 33 | - | |
| 34 | -- You must use your \`Read\` tool at least once in the conversation before | |
| 35 | -editing. This tool will error if you attempt an edit without reading the file. | |
| 36 | - | |
| 37 | -- When editing text from Read tool output, ensure you preserve the exact | |
| 38 | -indentation (tabs/spaces) as it appears AFTER the line number prefix. The line | |
| 39 | -number prefix format is: spaces + line number + tab. Everything after that tab | |
| 40 | -is the actual file content to match. Never include any part of the line number | |
| 41 | -prefix in the old_string or new_string. | |
| 42 | - | |
| 43 | -- ALWAYS prefer editing existing files in the codebase. NEVER write new files | |
| 44 | -unless explicitly required. | |
| 45 | - | |
| 46 | -- Only use emojis if the user explicitly requests it. Avoid adding emojis to | |
| 47 | -files unless asked. | |
| 48 | - | |
| 49 | -- The edit will FAIL if \`old_string\` is not unique in the file. Either provide | |
| 50 | -a larger string with more surrounding context to make it unique or use | |
| 51 | -\`replace_all\` to change every instance of \`old_string\`. | |
| 52 | - | |
| 53 | -- Use \`replace_all\` for replacing and renaming strings across the file. This | |
| 54 | -parameter is useful if you want to rename a variable for instance.`, | |
| 27 | + description: `Performs exact string replacements in a file. | |
| 28 | + | |
| 29 | +USAGE: | |
| 30 | +- ALWAYS use the \`${readFileTool.name}\` tool just before making edits, to understand the file's up-to-date contents and context. | |
| 31 | +- When editing text from ${readFileTool.name} tool output, ensure you preserve exact whitespace/indentation. | |
| 32 | +- Always prefer editing existing files in the codebase. NEVER write new files unless explicitly required. | |
| 33 | +- Only use emojis if the user explicitly requests it. Avoid adding emojis to files unless asked. | |
| 34 | +- Use \`replace_all\` for replacing and renaming strings across the file. This parameter is useful if you want to rename a variable, for instance. | |
| 35 | + | |
| 36 | +WARNINGS: | |
| 37 | +- When not using \`replace_all\`, the edit will FAIL if \`old_string\` is not unique in the file. Either provide a larger string with more surrounding context to make it unique or use \`replace_all\` to change every instance of \`old_string\`. | |
| 38 | +- The edit will FAIL if you have not recently used the \`${readFileTool.name}\` tool to view up-to-date file contents.`, | |
| 55 | 39 | parameters: { |
| 56 | 40 | file_path: { |
| 57 | 41 | type: "string", |
| @@ -60,13 +44,14 @@ | ||
| 60 | 44 | }, |
| 61 | 45 | old_string: { |
| 62 | 46 | type: "string", |
| 63 | - description: "The text to replace", | |
| 47 | + description: | |
| 48 | + "The text to replace - must be exact including whitespace/indentation", | |
| 64 | 49 | required: true, |
| 65 | 50 | }, |
| 66 | 51 | new_string: { |
| 67 | 52 | type: "string", |
| 68 | 53 | description: |
| 69 | - "The text to replace it with (must be different from old_string)", | |
| 54 | + "The text to replace it with (MUST be different from old_string)", | |
| 70 | 55 | required: true, |
| 71 | 56 | }, |
| 72 | 57 | replace_all: { |
| @@ -82,18 +67,12 @@ | ||
| 82 | 67 | new_string, |
| 83 | 68 | replace_all = false, |
| 84 | 69 | } = args as EditArgs; |
| 85 | - throwIfFileIsSecurityConcern(file_path); | |
| 86 | - // Check if file has been read | |
| 87 | - if (!readFilesSet.has(file_path)) { | |
| 88 | - throw new Error( | |
| 89 | - `You must use the Read tool to read ${file_path} before editing it.`, | |
| 90 | - ); | |
| 91 | - } | |
| 92 | 70 | |
| 93 | 71 | // Validate arguments |
| 94 | 72 | if (!file_path) { |
| 95 | 73 | throw new Error("file_path is required"); |
| 96 | 74 | } |
| 75 | + | |
| 97 | 76 | if (!old_string) { |
| 98 | 77 | throw new Error("old_string is required"); |
| 99 | 78 | } |
| @@ -104,13 +83,24 @@ | ||
| 104 | 83 | throw new Error("old_string and new_string must be different"); |
| 105 | 84 | } |
| 106 | 85 | |
| 86 | + const resolvedPath = fs.realpathSync(file_path); | |
| 87 | + | |
| 88 | + // Check if file has been read | |
| 89 | + if (!readFilesSet.has(resolvedPath)) { | |
| 90 | + throw new Error( | |
| 91 | + `You must use the ${readFileTool.name} tool to read ${file_path} before editing it.`, | |
| 92 | + ); | |
| 93 | + } | |
| 94 | + | |
| 95 | + throwIfFileIsSecurityConcern(resolvedPath); | |
| 96 | + | |
| 107 | 97 | // Check if file exists |
| 108 | - if (!fs.existsSync(file_path)) { | |
| 98 | + if (!fs.existsSync(resolvedPath)) { | |
| 109 | 99 | throw new Error(`File ${file_path} does not exist`); |
| 110 | 100 | } |
| 111 | 101 | |
| 112 | 102 | // Read current file content |
| 113 | - const oldContent = fs.readFileSync(file_path, "utf-8"); | |
| 103 | + const oldContent = fs.readFileSync(resolvedPath, "utf-8"); | |
| 114 | 104 | |
| 115 | 105 | // Check if old_string exists in the file |
| 116 | 106 | if (!oldContent.includes(old_string)) { |
| @@ -134,11 +124,11 @@ | ||
| 134 | 124 | } |
| 135 | 125 | |
| 136 | 126 | // Generate diff for preview |
| 137 | - const diff = generateDiff(oldContent, newContent, file_path); | |
| 127 | + const diff = generateDiff(oldContent, newContent, resolvedPath); | |
| 138 | 128 | |
| 139 | 129 | return { |
| 140 | 130 | args: { |
| 141 | - file_path, | |
| 131 | + resolvedPath, | |
| 142 | 132 | newContent, |
| 143 | 133 | oldContent, |
| 144 | 134 | }, |
| @@ -155,19 +145,19 @@ | ||
| 155 | 145 | }; |
| 156 | 146 | }, |
| 157 | 147 | run: async (args: { |
| 158 | - file_path: string; | |
| 148 | + resolvedPath: string; | |
| 159 | 149 | newContent: string; |
| 160 | 150 | oldContent: string; |
| 161 | 151 | }) => { |
| 162 | 152 | try { |
| 163 | - fs.writeFileSync(args.file_path, args.newContent, "utf-8"); | |
| 153 | + fs.writeFileSync(args.resolvedPath, args.newContent, "utf-8"); | |
| 164 | 154 | |
| 165 | 155 | // Get lines for telemetry |
| 166 | 156 | const { added, removed } = calculateLinesOfCodeDiff( |
| 167 | 157 | args.oldContent, |
| 168 | 158 | args.newContent, |
| 169 | 159 | ); |
| 170 | - const language = getLanguageFromFilePath(args.file_path); | |
| 160 | + const language = getLanguageFromFilePath(args.resolvedPath); | |
| 171 | 161 | |
| 172 | 162 | if (added > 0) { |
| 173 | 163 | telemetryService.recordLinesOfCodeModified("added", added, language); |
| @@ -184,21 +174,16 @@ | ||
| 184 | 174 | const diff = generateDiff( |
| 185 | 175 | args.oldContent, |
| 186 | 176 | args.newContent, |
| 187 | - args.file_path, | |
| 177 | + args.resolvedPath, | |
| 188 | 178 | ); |
| 189 | 179 | |
| 190 | - return `Successfully edited ${args.file_path}\nDiff:\n${diff}`; | |
| 180 | + return `Successfully edited ${args.resolvedPath}\nDiff:\n${diff}`; | |
| 191 | 181 | } catch (error) { |
| 192 | 182 | throw new Error( |
| 193 | - `Error: failed to edit ${args.file_path}: ${ | |
| 183 | + `Error: failed to edit ${args.resolvedPath}: ${ | |
| 194 | 184 | error instanceof Error ? error.message : String(error) |
| 195 | 185 | }`, |
| 196 | 186 | ); |
| 197 | 187 | } |
| 198 | 188 | }, |
| 199 | 189 | }; |
| 200 | - | |
| 201 | -// Function to mark a file as read (to be called from the read tool) | |
| 202 | -export function markFileAsRead(filePath: string) { | |
| 203 | - readFilesSet.add(filePath); | |
| 204 | -} |
modified extensions/cli/src/tools/multiEdit.test.ts +5 −2
| @@ -1,9 +1,10 @@ | ||
| 1 | 1 | import * as fs from "fs"; |
| 2 | 2 | import * as path from "path"; |
| 3 | 3 | |
| 4 | -import { describe, it, expect, beforeEach, afterEach, vi } from "vitest"; | |
| 4 | +import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; | |
| 5 | 5 | |
| 6 | -import { multiEditTool, markFileAsRead } from "./multiEdit.js"; | |
| 6 | +import { multiEditTool } from "./multiEdit.js"; | |
| 7 | +import { markFileAsRead } from "./readFile.js"; | |
| 7 | 8 | |
| 8 | 9 | // Mock the dependencies |
| 9 | 10 | vi.mock("../telemetry/telemetryService.js"); |
| @@ -22,6 +23,7 @@ | ||
| 22 | 23 | readFileSync: vi.fn(), |
| 23 | 24 | writeFileSync: vi.fn(), |
| 24 | 25 | unlinkSync: vi.fn(), |
| 26 | + realpathSync: vi.fn(), | |
| 25 | 27 | }; |
| 26 | 28 | }); |
| 27 | 29 | |
| @@ -35,6 +37,7 @@ | ||
| 35 | 37 | vi.mocked(fs.existsSync).mockReturnValue(true); |
| 36 | 38 | vi.mocked(fs.readFileSync).mockReturnValue(originalContent); |
| 37 | 39 | vi.mocked(fs.writeFileSync).mockImplementation(() => {}); |
| 40 | + vi.mocked(fs.realpathSync).mockImplementation((path) => path.toString()); | |
| 38 | 41 | }); |
| 39 | 42 | |
| 40 | 43 | afterEach(() => { |
modified extensions/cli/src/tools/multiEdit.ts +41 −91
| @@ -9,12 +9,11 @@ | ||
| 9 | 9 | getLanguageFromFilePath, |
| 10 | 10 | } from "../telemetry/utils.js"; |
| 11 | 11 | |
| 12 | -import { markFileAsRead, readFilesSet } from "./edit.js"; | |
| 12 | +import { editTool } from "./edit.js"; | |
| 13 | +import { readFilesSet, readFileTool } from "./readFile.js"; | |
| 13 | 14 | import { Tool } from "./types.js"; |
| 14 | 15 | import { generateDiff } from "./writeFile.js"; |
| 15 | 16 | |
| 16 | -export { markFileAsRead }; | |
| 17 | - | |
| 18 | 17 | export interface EditOperation { |
| 19 | 18 | old_string: string; |
| 20 | 19 | new_string: string; |
| @@ -26,15 +25,10 @@ | ||
| 26 | 25 | edits: EditOperation[]; |
| 27 | 26 | } |
| 28 | 27 | |
| 29 | -// Function to check if file has been read (shared with edit tool) | |
| 30 | -function hasFileBeenRead(filePath: string): boolean { | |
| 31 | - return readFilesSet.has(filePath); | |
| 32 | -} | |
| 33 | - | |
| 34 | 28 | // Helper functions for multiEdit validation |
| 35 | 29 | function validateMultiEditArgs(args: any): { |
| 36 | 30 | original_path: string; |
| 37 | - file_path: string; | |
| 31 | + resolved_path: string; | |
| 38 | 32 | edits: EditOperation[]; |
| 39 | 33 | } { |
| 40 | 34 | const { file_path, edits } = args as MultiEditArgs; |
| @@ -53,7 +47,9 @@ | ||
| 53 | 47 | ? file_path |
| 54 | 48 | : path.resolve(process.cwd(), file_path); |
| 55 | 49 | |
| 56 | - return { original_path: file_path, file_path: absolutePath, edits }; | |
| 50 | + const resolvedPath = fs.realpathSync(absolutePath); | |
| 51 | + | |
| 52 | + return { original_path: file_path, resolved_path: resolvedPath, edits }; | |
| 57 | 53 | } |
| 58 | 54 | |
| 59 | 55 | function validateEdits(edits: EditOperation[]): void { |
| @@ -74,26 +70,25 @@ | ||
| 74 | 70 | } |
| 75 | 71 | |
| 76 | 72 | function validateFileAccess( |
| 77 | - original_path: string, | |
| 78 | - file_path: string, | |
| 73 | + resolvedPath: string, | |
| 79 | 74 | isCreatingNewFile: boolean, |
| 80 | 75 | ): void { |
| 81 | 76 | if (isCreatingNewFile) { |
| 82 | 77 | // For new file creation, check if parent directory exists |
| 83 | - const parentDir = path.dirname(file_path); | |
| 78 | + const parentDir = path.dirname(resolvedPath); | |
| 84 | 79 | if (parentDir && !fs.existsSync(parentDir)) { |
| 85 | 80 | throw new Error(`Parent directory does not exist: ${parentDir}`); |
| 86 | 81 | } |
| 87 | 82 | } else { |
| 88 | 83 | // For existing files, check if file has been read |
| 89 | 84 | // Check with the original path first, then with absolute path |
| 90 | - if (!hasFileBeenRead(original_path) && !hasFileBeenRead(file_path)) { | |
| 85 | + if (!readFilesSet.has(resolvedPath)) { | |
| 91 | 86 | throw new Error( |
| 92 | - `You must use the Read tool to read ${original_path} before editing it.`, | |
| 87 | + `You must use the ${readFileTool.name} tool to read ${resolvedPath} before editing it.`, | |
| 93 | 88 | ); |
| 94 | 89 | } |
| 95 | - if (!fs.existsSync(file_path)) { | |
| 96 | - throw new Error(`File ${file_path} does not exist`); | |
| 90 | + if (!fs.existsSync(resolvedPath)) { | |
| 91 | + throw new Error(`File ${resolvedPath} does not exist`); | |
| 97 | 92 | } |
| 98 | 93 | } |
| 99 | 94 | } |
| @@ -138,87 +133,42 @@ | ||
| 138 | 133 | displayName: "MultiEdit", |
| 139 | 134 | readonly: false, |
| 140 | 135 | isBuiltIn: true, |
| 141 | - description: `This is a tool for making multiple edits to a single file in one operation. It | |
| 142 | -is built on top of the Edit tool and allows you to perform multiple | |
| 143 | -find-and-replace operations efficiently. Prefer this tool over the Edit tool | |
| 144 | -when you need to make multiple edits to the same file. | |
| 145 | - | |
| 146 | - | |
| 147 | -Before using this tool: | |
| 148 | - | |
| 149 | - | |
| 150 | -1. Use the Read tool to understand the file's contents and context | |
| 151 | - | |
| 152 | -2. Verify the directory path is correct | |
| 153 | - | |
| 154 | - | |
| 155 | -To make multiple file edits, provide the following: | |
| 156 | - | |
| 157 | -1. file_path: The absolute path to the file to modify (must be absolute, not | |
| 158 | -relative) | |
| 159 | - | |
| 136 | + description: `This is a tool for making multiple edits to a single file in one operation. It is built on top of the ${editTool.name} tool and allows you to perform multiple find-and-replace operations efficiently. | |
| 137 | +Prefer this tool over the ${editTool.name} tool when you need to make multiple edits to the same file. | |
| 138 | + | |
| 139 | +To make multiple edits to a file, provide the following: | |
| 140 | +1. file_path: The absolute path to the file to modify (must be absolute, not relative) | |
| 160 | 141 | 2. edits: An array of edit operations to perform, where each edit contains: |
| 161 | - - old_string: The text to replace (must match the file contents exactly, including all whitespace and indentation) | |
| 142 | + - old_string: The text to replace (must match the file contents exactly, including all whitespace/indentation) | |
| 162 | 143 | - new_string: The edited text to replace the old_string |
| 163 | 144 | - replace_all: Replace all occurences of old_string. This parameter is optional and defaults to false. |
| 164 | 145 | |
| 165 | 146 | IMPORTANT: |
| 166 | - | |
| 167 | 147 | - All edits are applied in sequence, in the order they are provided |
| 168 | - | |
| 169 | -- Each edit operates on the result of the previous edit | |
| 170 | - | |
| 171 | -- All edits must be valid for the operation to succeed - if any edit fails, | |
| 172 | -none will be applied | |
| 173 | - | |
| 174 | -- This tool is ideal when you need to make several changes to different parts | |
| 175 | -of the same file | |
| 176 | - | |
| 177 | -- For Jupyter notebooks (.ipynb files), use the NotebookEdit instead | |
| 178 | - | |
| 148 | +- Each edit operates on the result of the previous edit, so plan your edits carefully to avoid conflicts between sequential operations | |
| 149 | +- Edits are atomic - all edits must be valid for the operation to succeed - if any edit fails, none will be applied | |
| 150 | +- This tool is ideal when you need to make several changes to different parts of the same file | |
| 179 | 151 | |
| 180 | 152 | CRITICAL REQUIREMENTS: |
| 181 | - | |
| 182 | -1. All edits follow the same requirements as the single Edit tool | |
| 183 | - | |
| 184 | -2. The edits are atomic - either all succeed or none are applied | |
| 185 | - | |
| 186 | -3. Plan your edits carefully to avoid conflicts between sequential operations | |
| 187 | - | |
| 188 | - | |
| 189 | -WARNING: | |
| 190 | - | |
| 191 | -- The tool will fail if edits.old_string doesn't match the file contents | |
| 192 | -exactly (including whitespace) | |
| 193 | - | |
| 194 | -- The tool will fail if edits.old_string and edits.new_string are the same | |
| 195 | - | |
| 196 | -- Since edits are applied in sequence, ensure that earlier edits don't affect | |
| 197 | -the text that later edits are trying to find | |
| 198 | - | |
| 199 | - | |
| 200 | -When making edits: | |
| 201 | - | |
| 153 | +1. ALWAYS use the ${readFileTool.name} tool just before making edits, to understand the file's up-to-date contents and context | |
| 154 | +2. When making edits: | |
| 202 | 155 | - Ensure all edits result in idiomatic, correct code |
| 203 | - | |
| 204 | 156 | - Do not leave the code in a broken state |
| 205 | - | |
| 206 | 157 | - Always use absolute file paths (starting with /) |
| 207 | - | |
| 208 | -- Only use emojis if the user explicitly requests it. Avoid adding emojis to | |
| 209 | -files unless asked. | |
| 210 | - | |
| 211 | -- Use replace_all for replacing and renaming strings across the file. This | |
| 212 | -parameter is useful if you want to rename a variable for instance. | |
| 213 | - | |
| 158 | +- Only use emojis if the user explicitly requests it. Avoid adding emojis to files unless asked. | |
| 159 | +- Use replace_all for replacing and renaming strings across the file. This parameter is useful if you want to rename a variable for instance. | |
| 214 | 160 | |
| 215 | 161 | If you want to create a new file, use: |
| 216 | - | |
| 217 | -- A new file path, including dir name if needed | |
| 218 | - | |
| 162 | +- A new file path, including new directory if needed | |
| 219 | 163 | - First edit: empty old_string and the new file's contents as new_string |
| 220 | - | |
| 221 | -- Subsequent edits: normal edit operations on the created content`, | |
| 164 | +- Subsequent edits: normal edit operations on the created content | |
| 165 | +- ALWAYS prefer editing existing files in the codebase. NEVER write new files unless explicitly required | |
| 166 | + | |
| 167 | +WARNINGS: | |
| 168 | +- If earlier edits affect the text that later edits are trying to find, files can become mangled | |
| 169 | +- The tool will fail if edits.old_string doesn't match the file contents exactly (including whitespace) | |
| 170 | +- The tool will fail if edits.old_string and edits.new_string are the same - they MUST be different | |
| 171 | +- The tool will fail if you have not used the ${readFileTool.name} tool to read the file in this session`, | |
| 222 | 172 | parameters: { |
| 223 | 173 | file_path: { |
| 224 | 174 | type: "string", |
| @@ -237,9 +187,9 @@ | ||
| 237 | 187 | }, |
| 238 | 188 | preprocess: async (args) => { |
| 239 | 189 | // Validate and extract arguments |
| 240 | - const { original_path, file_path, edits } = validateMultiEditArgs(args); | |
| 190 | + const { resolved_path, edits } = validateMultiEditArgs(args); | |
| 241 | 191 | |
| 242 | - throwIfFileIsSecurityConcern(file_path); | |
| 192 | + throwIfFileIsSecurityConcern(resolved_path); | |
| 243 | 193 | |
| 244 | 194 | // Validate each edit operation |
| 245 | 195 | validateEdits(edits); |
| @@ -248,12 +198,12 @@ | ||
| 248 | 198 | const isCreatingNewFile = edits[0].old_string === ""; |
| 249 | 199 | |
| 250 | 200 | // Validate file access |
| 251 | - validateFileAccess(original_path, file_path, isCreatingNewFile); | |
| 201 | + validateFileAccess(resolved_path, isCreatingNewFile); | |
| 252 | 202 | |
| 253 | 203 | // Read current file content (or start with empty for new files) |
| 254 | 204 | let currentContent = ""; |
| 255 | 205 | if (!isCreatingNewFile) { |
| 256 | - currentContent = fs.readFileSync(file_path, "utf-8"); | |
| 206 | + currentContent = fs.readFileSync(resolved_path, "utf-8"); | |
| 257 | 207 | } |
| 258 | 208 | |
| 259 | 209 | const originalContent = currentContent; |
| @@ -266,11 +216,11 @@ | ||
| 266 | 216 | } |
| 267 | 217 | |
| 268 | 218 | // Generate diff for preview |
| 269 | - const diff = generateDiff(originalContent, newContent, file_path); | |
| 219 | + const diff = generateDiff(originalContent, newContent, resolved_path); | |
| 270 | 220 | |
| 271 | 221 | return { |
| 272 | 222 | args: { |
| 273 | - file_path, | |
| 223 | + file_path: resolved_path, | |
| 274 | 224 | newContent, |
| 275 | 225 | originalContent, |
| 276 | 226 | isCreatingNewFile, |
| @@ -279,7 +229,7 @@ | ||
| 279 | 229 | preview: [ |
| 280 | 230 | { |
| 281 | 231 | type: "text", |
| 282 | - content: `Will apply ${edits.length} edit${edits.length === 1 ? "" : "s"} to ${isCreatingNewFile ? "create" : "modify"} ${file_path}:`, | |
| 232 | + content: `Will apply ${edits.length} edit${edits.length === 1 ? "" : "s"} to ${isCreatingNewFile ? "create" : "modify"} ${resolved_path}:`, | |
| 283 | 233 | }, |
| 284 | 234 | { |
| 285 | 235 | type: "diff", |
modified extensions/cli/src/tools/readFile.ts +9 −3
| @@ -2,10 +2,15 @@ | ||
| 2 | 2 | |
| 3 | 3 | import { throwIfFileIsSecurityConcern } from "core/indexing/ignore.js"; |
| 4 | 4 | |
| 5 | -import { markFileAsRead } from "./edit.js"; | |
| 6 | 5 | import { formatToolArgument } from "./formatters.js"; |
| 7 | 6 | import { Tool } from "./types.js"; |
| 8 | 7 | |
| 8 | +// Track files that have been read in the current session | |
| 9 | +export const readFilesSet = new Set<string>(); | |
| 10 | +export function markFileAsRead(filePath: string) { | |
| 11 | + readFilesSet.add(filePath); | |
| 12 | +} | |
| 13 | + | |
| 9 | 14 | export const readFileTool: Tool = { |
| 10 | 15 | name: "Read", |
| 11 | 16 | displayName: "Read", |
| @@ -41,9 +46,10 @@ | ||
| 41 | 46 | if (!fs.existsSync(filepath)) { |
| 42 | 47 | return `Error: File does not exist: ${filepath}`; |
| 43 | 48 | } |
| 44 | - const content = fs.readFileSync(filepath, "utf-8"); | |
| 49 | + const realPath = fs.realpathSync(filepath); | |
| 50 | + const content = fs.readFileSync(realPath, "utf-8"); | |
| 45 | 51 | // Mark this file as read for the edit tool |
| 46 | - markFileAsRead(filepath); | |
| 52 | + markFileAsRead(realPath); | |
| 47 | 53 | |
| 48 | 54 | const lines = content.split("\n"); |
| 49 | 55 | if (lines.length > 5000) { |
modified extensions/cli/src/tools/runTerminalCommand.ts +1 −1
| @@ -33,7 +33,7 @@ | ||
| 33 | 33 | displayName: "Bash", |
| 34 | 34 | description: `Executes a terminal command and returns the output |
| 35 | 35 | |
| 36 | -The command will be executed from the current working directory: ${process.cwd()} | |
| 36 | +Commands are automatically executed from the current working directory (${process.cwd()}), so there's no need to change directories with 'cd' commands. | |
| 37 | 37 | `, |
| 38 | 38 | parameters: { |
| 39 | 39 | command: { |
modified extensions/cli/src/ui/UserInput.tsx +140 −35
| @@ -20,6 +20,77 @@ | ||
| 20 | 20 | import { SlashCommandUI } from "./SlashCommandUI.js"; |
| 21 | 21 | import { TextBuffer } from "./TextBuffer.js"; |
| 22 | 22 | |
| 23 | +// Small presentational helpers to reduce cyclomatic complexity in UserInput | |
| 24 | +const InterruptedBanner: React.FC<{ wasInterrupted: boolean }> = ({ | |
| 25 | + wasInterrupted, | |
| 26 | +}) => { | |
| 27 | + if (!wasInterrupted) return null; | |
| 28 | + return ( | |
| 29 | + <Box paddingX={1} marginBottom={0}> | |
| 30 | + <Text color="yellow">⚠ Interrupted by user - Press enter to resume</Text> | |
| 31 | + </Box> | |
| 32 | + ); | |
| 33 | +}; | |
| 34 | + | |
| 35 | +const SlashCommandsMaybe: React.FC<{ | |
| 36 | + show: boolean; | |
| 37 | + inputMode: boolean; | |
| 38 | + hideNormalUI: boolean; | |
| 39 | + isRemoteMode: boolean; | |
| 40 | + assistant?: AssistantConfig; | |
| 41 | + filter: string; | |
| 42 | + selectedIndex: number; | |
| 43 | +}> = ({ | |
| 44 | + show, | |
| 45 | + inputMode, | |
| 46 | + hideNormalUI, | |
| 47 | + isRemoteMode, | |
| 48 | + assistant, | |
| 49 | + filter, | |
| 50 | + selectedIndex, | |
| 51 | +}) => { | |
| 52 | + if (!show || !inputMode || hideNormalUI || !(isRemoteMode || assistant)) | |
| 53 | + return null; | |
| 54 | + return ( | |
| 55 | + <SlashCommandUI | |
| 56 | + assistant={assistant} | |
| 57 | + filter={filter} | |
| 58 | + selectedIndex={selectedIndex} | |
| 59 | + isRemoteMode={isRemoteMode} | |
| 60 | + /> | |
| 61 | + ); | |
| 62 | +}; | |
| 63 | + | |
| 64 | +const FileSearchMaybe: React.FC<{ | |
| 65 | + show: boolean; | |
| 66 | + inputMode: boolean; | |
| 67 | + hideNormalUI: boolean; | |
| 68 | + isRemoteMode: boolean; | |
| 69 | + filter: string; | |
| 70 | + selectedIndex: number; | |
| 71 | + onSelect: (path: string) => void | Promise<void>; | |
| 72 | + onFilesUpdated: (files: Array<{ path: string; displayName: string }>) => void; | |
| 73 | +}> = ({ | |
| 74 | + show, | |
| 75 | + inputMode, | |
| 76 | + hideNormalUI, | |
| 77 | + isRemoteMode, | |
| 78 | + filter, | |
| 79 | + selectedIndex, | |
| 80 | + onSelect, | |
| 81 | + onFilesUpdated, | |
| 82 | +}) => { | |
| 83 | + if (!show || !inputMode || hideNormalUI || isRemoteMode) return null; | |
| 84 | + return ( | |
| 85 | + <FileSearchUI | |
| 86 | + filter={filter} | |
| 87 | + selectedIndex={selectedIndex} | |
| 88 | + onSelect={onSelect} | |
| 89 | + onFilesUpdated={onFilesUpdated} | |
| 90 | + /> | |
| 91 | + ); | |
| 92 | +}; | |
| 93 | + | |
| 23 | 94 | interface UserInputProps { |
| 24 | 95 | onSubmit: (message: string, imageMap?: Map<string, Buffer>) => void; |
| 25 | 96 | isWaitingForResponse: boolean; |
| @@ -78,10 +149,13 @@ | ||
| 78 | 149 | setCursorPosition(0); |
| 79 | 150 | setShowSlashCommands(false); |
| 80 | 151 | setShowFileSearch(false); |
| 152 | + setShowBashMode(false); | |
| 81 | 153 | inputHistory.resetNavigation(); |
| 82 | 154 | }, [textBuffer]); |
| 155 | + | |
| 83 | 156 | const [slashCommandFilter, setSlashCommandFilter] = useState(""); |
| 84 | 157 | const [selectedCommandIndex, setSelectedCommandIndex] = useState(0); |
| 158 | + const [showBashMode, setShowBashMode] = useState(false); | |
| 85 | 159 | const [showFileSearch, setShowFileSearch] = useState(false); |
| 86 | 160 | const [fileSearchFilter, setFileSearchFilter] = useState(""); |
| 87 | 161 | const [selectedFileIndex, setSelectedFileIndex] = useState(0); |
| @@ -131,6 +205,18 @@ | ||
| 131 | 205 | return nextMode; |
| 132 | 206 | }; |
| 133 | 207 | |
| 208 | + // Update shell mode state based on input | |
| 209 | + const updateBashModeState = (text: string) => { | |
| 210 | + const trimmed = text.trimStart(); | |
| 211 | + const isBash = trimmed.startsWith("!"); | |
| 212 | + setShowBashMode(isBash); | |
| 213 | + if (isBash) { | |
| 214 | + // Disable other helpers while in shell mode | |
| 215 | + setShowSlashCommands(false); | |
| 216 | + setShowFileSearch(false); | |
| 217 | + } | |
| 218 | + }; | |
| 219 | + | |
| 134 | 220 | // Update slash command UI state based on input |
| 135 | 221 | const updateSlashCommandState = (text: string, cursor: number) => { |
| 136 | 222 | // Only show slash commands if slash is the very first character |
| @@ -139,6 +225,9 @@ | ||
| 139 | 225 | return; |
| 140 | 226 | } |
| 141 | 227 | |
| 228 | + // When using slash commands, disable file search | |
| 229 | + setShowFileSearch(false); | |
| 230 | + | |
| 142 | 231 | const trimmedText = text.trimStart(); |
| 143 | 232 | const beforeCursor = trimmedText.slice( |
| 144 | 233 | 0, |
| @@ -196,6 +285,13 @@ | ||
| 196 | 285 | return; |
| 197 | 286 | } |
| 198 | 287 | |
| 288 | + // Disable file search if we're in shell mode or slash command mode | |
| 289 | + const trimmed = text.trimStart(); | |
| 290 | + if (trimmed.startsWith("!") || trimmed.startsWith("/")) { | |
| 291 | + setShowFileSearch(false); | |
| 292 | + return; | |
| 293 | + } | |
| 294 | + | |
| 199 | 295 | // Check if we're in a file search context |
| 200 | 296 | const beforeCursor = text.slice(0, cursor); |
| 201 | 297 | const lastAtIndex = beforeCursor.lastIndexOf("@"); |
| @@ -234,6 +330,7 @@ | ||
| 234 | 330 | setFileSearchFilter(afterAt); |
| 235 | 331 | setSelectedFileIndex(0); |
| 236 | 332 | setShowSlashCommands(false); |
| 333 | + setShowBashMode(false); | |
| 237 | 334 | } |
| 238 | 335 | } |
| 239 | 336 | }; |
| @@ -278,6 +375,7 @@ | ||
| 278 | 375 | setInputText(newText); |
| 279 | 376 | setCursorPosition(newCursorPos); |
| 280 | 377 | setShowSlashCommands(false); |
| 378 | + setShowBashMode(false); | |
| 281 | 379 | } |
| 282 | 380 | }; |
| 283 | 381 | |
| @@ -437,6 +535,7 @@ | ||
| 437 | 535 | setInputText(""); |
| 438 | 536 | setCursorPosition(0); |
| 439 | 537 | setShowSlashCommands(false); |
| 538 | + setShowBashMode(false); | |
| 440 | 539 | } |
| 441 | 540 | return true; |
| 442 | 541 | } |
| @@ -462,6 +561,15 @@ | ||
| 462 | 561 | const handleEscapeKey = (key: any): boolean => { |
| 463 | 562 | if (!key.escape) return false; |
| 464 | 563 | |
| 564 | + // If only "!" is present, clear shell mode | |
| 565 | + if (inputMode && showBashMode && inputText.trim() === "!") { | |
| 566 | + textBuffer.clear(); | |
| 567 | + setInputText(""); | |
| 568 | + setCursorPosition(0); | |
| 569 | + setShowBashMode(false); | |
| 570 | + return true; | |
| 571 | + } | |
| 572 | + | |
| 465 | 573 | // Handle escape key to interrupt streaming |
| 466 | 574 | if (isWaitingForResponse && onInterrupt) { |
| 467 | 575 | onInterrupt(); |
| @@ -491,6 +599,7 @@ | ||
| 491 | 599 | setCursorPosition(newCursor); |
| 492 | 600 | updateSlashCommandState(newText, newCursor); |
| 493 | 601 | updateFileSearchState(newText, newCursor); |
| 602 | + updateBashModeState(newText); | |
| 494 | 603 | inputHistory.resetNavigation(); |
| 495 | 604 | }; |
| 496 | 605 | |
| @@ -587,14 +696,16 @@ | ||
| 587 | 696 | setCursorPosition, |
| 588 | 697 | updateSlashCommandState, |
| 589 | 698 | updateFileSearchState, |
| 699 | + updateBashModeState, | |
| 590 | 700 | inputHistory, |
| 591 | 701 | }); |
| 592 | 702 | }); |
| 593 | 703 | |
| 594 | 704 | const renderInputText = () => { |
| 595 | 705 | const placeholderText = isRemoteMode |
| 596 | - ? "Ask anything, / for slash commands" | |
| 597 | - : placeholder || "Ask anything, @ for context, / for slash commands"; | |
| 706 | + ? "Ask anything, / for slash commands, ! for shell mode" | |
| 707 | + : placeholder || | |
| 708 | + "Ask anything, @ for context, / for slash commands, ! for shell mode"; | |
| 598 | 709 | if (inputText.length === 0) { |
| 599 | 710 | return ( |
| 600 | 711 | <> |
| @@ -677,50 +788,44 @@ | ||
| 677 | 788 | |
| 678 | 789 | return ( |
| 679 | 790 | <Box flexDirection="column"> |
| 680 | - {/* Interruption message - shown just above the input box */} | |
| 681 | - {wasInterrupted && ( | |
| 682 | - <Box paddingX={1} marginBottom={0}> | |
| 683 | - <Text color="yellow"> | |
| 684 | - ⚠ Interrupted by user - Press enter to resume | |
| 685 | - </Text> | |
| 686 | - </Box> | |
| 687 | - )} | |
| 791 | + <InterruptedBanner wasInterrupted={!!wasInterrupted} /> | |
| 688 | 792 | |
| 689 | 793 | {/* Input box */} |
| 690 | 794 | <Box |
| 691 | 795 | borderStyle="round" |
| 692 | 796 | borderTop={true} |
| 693 | 797 | paddingX={1} |
| 694 | - borderColor={isRemoteMode ? "cyan" : "gray"} | |
| 798 | + borderColor={showBashMode ? "yellow" : isRemoteMode ? "cyan" : "gray"} | |
| 695 | 799 | > |
| 696 | - <Text color={isRemoteMode ? "cyan" : "blue"} bold> | |
| 697 | - {isRemoteMode ? "◉" : "●"}{" "} | |
| 800 | + <Text | |
| 801 | + color={showBashMode ? "yellow" : isRemoteMode ? "cyan" : "blue"} | |
| 802 | + bold | |
| 803 | + > | |
| 804 | + {showBashMode ? "$" : isRemoteMode ? "◉" : "●"} | |
| 698 | 805 | </Text> |
| 699 | 806 | {renderInputText()} |
| 700 | 807 | </Box> |
| 701 | 808 | |
| 702 | - {/* Slash command UI - show in remote mode OR when assistant is available */} | |
| 703 | - {showSlashCommands && | |
| 704 | - inputMode && | |
| 705 | - !hideNormalUI && | |
| 706 | - (isRemoteMode || assistant) && ( | |
| 707 | - <SlashCommandUI | |
| 708 | - assistant={assistant} | |
| 709 | - filter={slashCommandFilter} | |
| 710 | - selectedIndex={selectedCommandIndex} | |
| 711 | - isRemoteMode={isRemoteMode} | |
| 712 | - /> | |
| 713 | - )} | |
| 714 | - | |
| 715 | - {/* File search UI - only show in local mode */} | |
| 716 | - {showFileSearch && inputMode && !hideNormalUI && !isRemoteMode && ( | |
| 717 | - <FileSearchUI | |
| 718 | - filter={fileSearchFilter} | |
| 719 | - selectedIndex={selectedFileIndex} | |
| 720 | - onSelect={selectFile} | |
| 721 | - onFilesUpdated={setCurrentFiles} | |
| 722 | - /> | |
| 723 | - )} | |
| 809 | + <SlashCommandsMaybe | |
| 810 | + show={showSlashCommands} | |
| 811 | + inputMode={inputMode} | |
| 812 | + hideNormalUI={!!hideNormalUI} | |
| 813 | + isRemoteMode={!!isRemoteMode} | |
| 814 | + assistant={assistant} | |
| 815 | + filter={slashCommandFilter} | |
| 816 | + selectedIndex={selectedCommandIndex} | |
| 817 | + /> | |
| 818 | + | |
| 819 | + <FileSearchMaybe | |
| 820 | + show={showFileSearch} | |
| 821 | + inputMode={inputMode} | |
| 822 | + hideNormalUI={!!hideNormalUI} | |
| 823 | + isRemoteMode={!!isRemoteMode} | |
| 824 | + filter={fileSearchFilter} | |
| 825 | + selectedIndex={selectedFileIndex} | |
| 826 | + onSelect={selectFile} | |
| 827 | + onFilesUpdated={setCurrentFiles} | |
| 828 | + /> | |
| 724 | 829 | </Box> |
| 725 | 830 | ); |
| 726 | 831 | }; |
modified extensions/cli/src/ui/components/StaticChatContent.tsx +15 −38
| @@ -74,14 +74,12 @@ | ||
| 74 | 74 | }, [chatHistory]); |
| 75 | 75 | |
| 76 | 76 | // Split chat history into stable and pending items |
| 77 | - // Only put items in pending if they contain tool calls with "calling" status | |
| 78 | - // Everything else goes into static content | |
| 77 | + // The last two items may have pending tool calls | |
| 79 | 78 | const { staticItems, pendingItems } = React.useMemo(() => { |
| 80 | - const items: React.ReactElement[] = []; | |
| 81 | - | |
| 82 | 79 | // Add intro message as first item if it should be shown |
| 80 | + const staticItems: React.ReactElement[] = []; | |
| 83 | 81 | if (showIntroMessage) { |
| 84 | - items.push( | |
| 82 | + staticItems.push( | |
| 85 | 83 | <IntroMessage |
| 86 | 84 | key="intro" |
| 87 | 85 | config={config} |
| @@ -91,48 +89,27 @@ | ||
| 91 | 89 | ); |
| 92 | 90 | } |
| 93 | 91 | |
| 94 | - // Helper function to check if an item has pending tool calls | |
| 95 | - const hasPendingToolCalls = (item: ChatHistoryItem): boolean => { | |
| 96 | - return !!( | |
| 97 | - item.toolCallStates && | |
| 98 | - item.toolCallStates.some( | |
| 99 | - (toolState) => | |
| 100 | - toolState.status === "calling" || | |
| 101 | - toolState.status === "generating" || | |
| 102 | - toolState.status === "generated", | |
| 103 | - ) | |
| 104 | - ); | |
| 105 | - }; | |
| 106 | - | |
| 107 | - // Find the first message with pending tool calls from the end | |
| 108 | - let pendingStartIndex = filteredChatHistory.length; | |
| 109 | - for (let i = filteredChatHistory.length - 1; i >= 0; i--) { | |
| 110 | - if (hasPendingToolCalls(filteredChatHistory[i])) { | |
| 111 | - pendingStartIndex = i; | |
| 112 | - // If there's a message after this one, include it too as it might be related | |
| 113 | - if (i + 1 < filteredChatHistory.length) { | |
| 114 | - // Keep the pending start index as is, so we include the next message | |
| 115 | - } | |
| 116 | - break; | |
| 117 | - } | |
| 118 | - } | |
| 119 | - | |
| 120 | - const stableHistory = filteredChatHistory.slice(0, pendingStartIndex); | |
| 121 | - const pendingHistory = filteredChatHistory.slice(pendingStartIndex); | |
| 92 | + const PENDING_ITEMS_COUNT = 2; | |
| 93 | + const stableCount = Math.max( | |
| 94 | + 0, | |
| 95 | + filteredChatHistory.length - PENDING_ITEMS_COUNT, | |
| 96 | + ); | |
| 97 | + const stableHistory = filteredChatHistory.slice(0, stableCount); | |
| 98 | + const pendingHistory = filteredChatHistory.slice(stableCount); | |
| 122 | 99 | |
| 123 | 100 | // Add stable messages to static items |
| 124 | 101 | stableHistory.forEach((item, index) => { |
| 125 | - items.push(renderMessage(item, index)); | |
| 102 | + staticItems.push(renderMessage(item, index)); | |
| 126 | 103 | }); |
| 127 | 104 | |
| 128 | 105 | // Pending items will be rendered dynamically outside Static |
| 129 | - const pendingElements = pendingHistory.map((item, index) => | |
| 130 | - renderMessage(item, pendingStartIndex + index), | |
| 106 | + const pendingItems = pendingHistory.map((item, index) => | |
| 107 | + renderMessage(item, stableCount + index), | |
| 131 | 108 | ); |
| 132 | 109 | |
| 133 | 110 | return { |
| 134 | - staticItems: items, | |
| 135 | - pendingItems: pendingElements, | |
| 111 | + staticItems, | |
| 112 | + pendingItems, | |
| 136 | 113 | }; |
| 137 | 114 | }, [ |
| 138 | 115 | showIntroMessage, |
added extensions/cli/src/ui/hooks/useChat.shellMode.test.ts +148 −0
| @@ -0,0 +1,148 @@ | ||
| 1 | +import { beforeEach, describe, expect, it, vi } from "vitest"; | |
| 2 | + | |
| 3 | +import { runTerminalCommandTool } from "src/tools/runTerminalCommand.js"; | |
| 4 | + | |
| 5 | +import { services } from "../../services/index.js"; | |
| 6 | + | |
| 7 | +import { handleBashModeProcessing } from "./useChat.shellMode.js"; | |
| 8 | + | |
| 9 | +// Mock the runTerminalCommandTool with the correct path for the import in shellMode.ts | |
| 10 | +vi.mock("src/tools/runTerminalCommand.js", () => ({ | |
| 11 | + runTerminalCommandTool: { | |
| 12 | + run: vi.fn(), | |
| 13 | + }, | |
| 14 | +})); | |
| 15 | + | |
| 16 | +// Mock the services | |
| 17 | +vi.mock("../../services/index.js", () => ({ | |
| 18 | + services: { | |
| 19 | + chatHistory: { | |
| 20 | + addAssistantMessage: vi.fn(), | |
| 21 | + updateToolStatus: vi.fn(), | |
| 22 | + addToolResult: vi.fn(), | |
| 23 | + }, | |
| 24 | + }, | |
| 25 | +})); | |
| 26 | + | |
| 27 | +describe("handleBashModeProcessing", () => { | |
| 28 | + beforeEach(() => { | |
| 29 | + vi.clearAllMocks(); | |
| 30 | + }); | |
| 31 | + | |
| 32 | + it("should detect bash mode when message starts with !", async () => { | |
| 33 | + const mockRun = vi.mocked(runTerminalCommandTool.run); | |
| 34 | + mockRun.mockResolvedValue( | |
| 35 | + "total 5\ndrwxr-xr-x 2 user user 4096 Jan 1 12:00 .\ndrwxr-xr-x 3 user user 4096 Jan 1 12:00 ..", | |
| 36 | + ); | |
| 37 | + | |
| 38 | + const result = await handleBashModeProcessing("!ls -la"); | |
| 39 | + | |
| 40 | + expect(result).toBe(null); // Processed, no further handling needed | |
| 41 | + expect(services.chatHistory.addAssistantMessage).toHaveBeenCalled(); | |
| 42 | + expect(services.chatHistory.updateToolStatus).toHaveBeenCalledWith( | |
| 43 | + expect.any(String), | |
| 44 | + "calling", | |
| 45 | + ); | |
| 46 | + | |
| 47 | + // Use vi.waitFor to wait for async operations in the void expression | |
| 48 | + await vi.waitFor( | |
| 49 | + () => { | |
| 50 | + expect(mockRun).toHaveBeenCalledWith({ command: "ls -la" }); | |
| 51 | + }, | |
| 52 | + { timeout: 1000 }, | |
| 53 | + ); | |
| 54 | + | |
| 55 | + await vi.waitFor( | |
| 56 | + () => { | |
| 57 | + expect(services.chatHistory.addToolResult).toHaveBeenCalledWith( | |
| 58 | + expect.any(String), | |
| 59 | + "total 5\ndrwxr-xr-x 2 user user 4096 Jan 1 12:00 .\ndrwxr-xr-x 3 user user 4096 Jan 1 12:00 ..", | |
| 60 | + "done", | |
| 61 | + ); | |
| 62 | + }, | |
| 63 | + { timeout: 1000 }, | |
| 64 | + ); | |
| 65 | + }); | |
| 66 | + | |
| 67 | + it("should handle bash command errors", async () => { | |
| 68 | + const mockRun = vi.mocked(runTerminalCommandTool.run); | |
| 69 | + mockRun.mockRejectedValue(new Error("Command not found")); | |
| 70 | + | |
| 71 | + const result = await handleBashModeProcessing("!invalidcommand"); | |
| 72 | + | |
| 73 | + expect(result).toBe(null); // Processed, no further handling needed | |
| 74 | + expect(services.chatHistory.addAssistantMessage).toHaveBeenCalled(); | |
| 75 | + expect(services.chatHistory.updateToolStatus).toHaveBeenCalledWith( | |
| 76 | + expect.any(String), | |
| 77 | + "calling", | |
| 78 | + ); | |
| 79 | + | |
| 80 | + // Use vi.waitFor to wait for async operations in the void expression | |
| 81 | + await vi.waitFor( | |
| 82 | + () => { | |
| 83 | + expect(mockRun).toHaveBeenCalledWith({ command: "invalidcommand" }); | |
| 84 | + }, | |
| 85 | + { timeout: 1000 }, | |
| 86 | + ); | |
| 87 | + | |
| 88 | + await vi.waitFor( | |
| 89 | + () => { | |
| 90 | + expect(services.chatHistory.addToolResult).toHaveBeenCalledWith( | |
| 91 | + expect.any(String), | |
| 92 | + "Bash command failed: Command not found", | |
| 93 | + "errored", | |
| 94 | + ); | |
| 95 | + }, | |
| 96 | + { timeout: 1000 }, | |
| 97 | + ); | |
| 98 | + }); | |
| 99 | + | |
| 100 | + it("should not trigger bash mode for regular messages", async () => { | |
| 101 | + const mockRun = vi.mocked(runTerminalCommandTool.run); | |
| 102 | + | |
| 103 | + const result = await handleBashModeProcessing("Hello! How are you?"); | |
| 104 | + | |
| 105 | + expect(result).toBe("Hello! How are you?"); // Pass through unchanged | |
| 106 | + expect(mockRun).not.toHaveBeenCalled(); | |
| 107 | + expect(services.chatHistory.addAssistantMessage).not.toHaveBeenCalled(); | |
| 108 | + }); | |
| 109 | + | |
| 110 | + it("should handle empty bash command", async () => { | |
| 111 | + const mockRun = vi.mocked(runTerminalCommandTool.run); | |
| 112 | + | |
| 113 | + const result = await handleBashModeProcessing("!"); | |
| 114 | + | |
| 115 | + expect(result).toBe("!"); // Pass through unchanged for empty command | |
| 116 | + expect(mockRun).not.toHaveBeenCalled(); | |
| 117 | + expect(services.chatHistory.addAssistantMessage).not.toHaveBeenCalled(); | |
| 118 | + }); | |
| 119 | + | |
| 120 | + it("should handle bash command with leading whitespace", async () => { | |
| 121 | + const mockRun = vi.mocked(runTerminalCommandTool.run); | |
| 122 | + mockRun.mockResolvedValue("echo test output"); | |
| 123 | + | |
| 124 | + const result = await handleBashModeProcessing(" !echo hello"); | |
| 125 | + | |
| 126 | + expect(result).toBe(null); // Processed, no further handling needed | |
| 127 | + expect(services.chatHistory.addAssistantMessage).toHaveBeenCalled(); | |
| 128 | + | |
| 129 | + // Use vi.waitFor to wait for async operations in the void expression | |
| 130 | + await vi.waitFor( | |
| 131 | + () => { | |
| 132 | + expect(mockRun).toHaveBeenCalledWith({ command: "echo hello" }); | |
| 133 | + }, | |
| 134 | + { timeout: 1000 }, | |
| 135 | + ); | |
| 136 | + | |
| 137 | + await vi.waitFor( | |
| 138 | + () => { | |
| 139 | + expect(services.chatHistory.addToolResult).toHaveBeenCalledWith( | |
| 140 | + expect.any(String), | |
| 141 | + "echo test output", | |
| 142 | + "done", | |
| 143 | + ); | |
| 144 | + }, | |
| 145 | + { timeout: 1000 }, | |
| 146 | + ); | |
| 147 | + }); | |
| 148 | +}); |
added extensions/cli/src/ui/hooks/useChat.shellMode.ts +51 −0
| @@ -0,0 +1,51 @@ | ||
| 1 | +import { runTerminalCommandTool } from "src/tools/runTerminalCommand.js"; | |
| 2 | +import { getErrorString } from "src/util/error.js"; | |
| 3 | + | |
| 4 | +import { services } from "../../services/index.js"; | |
| 5 | + | |
| 6 | +export const handleBashModeProcessing = async ( | |
| 7 | + message: string, | |
| 8 | +): Promise<string | null> => { | |
| 9 | + // Handle shell mode commands (starting with !) | |
| 10 | + if (!message.trimStart().startsWith("!")) { | |
| 11 | + return message; | |
| 12 | + } | |
| 13 | + | |
| 14 | + // Extract the command after the ! | |
| 15 | + const bashCommand = message.trimStart().slice(1).trim(); | |
| 16 | + | |
| 17 | + if (!bashCommand) { | |
| 18 | + return message; // No command provided, treat as regular message | |
| 19 | + } | |
| 20 | + | |
| 21 | + // Show tool call immediately, then run asynchronously and populate result | |
| 22 | + const toolCallId = `shell-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`; | |
| 23 | + const toolCall = { | |
| 24 | + id: toolCallId, | |
| 25 | + type: "function" as const, | |
| 26 | + function: { | |
| 27 | + name: "Bash", | |
| 28 | + arguments: JSON.stringify({ command: bashCommand }), | |
| 29 | + }, | |
| 30 | + }; | |
| 31 | + | |
| 32 | + // Add assistant message with tool call immediately | |
| 33 | + services.chatHistory.addAssistantMessage("", [toolCall]); | |
| 34 | + // Mark as calling for immediate UI feedback | |
| 35 | + services.chatHistory.updateToolStatus(toolCallId, "calling"); | |
| 36 | + | |
| 37 | + // Execute the bash command asynchronously - don't block UI | |
| 38 | + void runTerminalCommandTool | |
| 39 | + .run({ | |
| 40 | + command: bashCommand, | |
| 41 | + }) | |
| 42 | + .then((result) => { | |
| 43 | + services.chatHistory.addToolResult(toolCallId, result, "done"); | |
| 44 | + }) | |
| 45 | + .catch((error) => { | |
| 46 | + const errorMessage = `Bash command failed: ${getErrorString(error)}`; | |
| 47 | + services.chatHistory.addToolResult(toolCallId, errorMessage, "errored"); | |
| 48 | + }); | |
| 49 | + | |
| 50 | + return null; // Processed, no further message handling needed | |
| 51 | +}; |
modified extensions/cli/src/ui/hooks/useChat.ts +8 −0
| @@ -30,6 +30,7 @@ | ||
| 30 | 30 | handleRemoteMessage, |
| 31 | 31 | setupRemotePolling, |
| 32 | 32 | } from "./useChat.remote.helpers.js"; |
| 33 | +import { handleBashModeProcessing } from "./useChat.shellMode.js"; | |
| 33 | 34 | import { |
| 34 | 35 | createStreamCallbacks, |
| 35 | 36 | executeStreaming, |
| @@ -423,6 +424,13 @@ | ||
| 423 | 424 | |
| 424 | 425 | if (handled) return; |
| 425 | 426 | |
| 427 | + // Handle shell mode commands (before slash commands) | |
| 428 | + const bashProcessedMessage = await handleBashModeProcessing(message); | |
| 429 | + if (bashProcessedMessage === null) { | |
| 430 | + return; // Bash command was handled and no further processing needed | |
| 431 | + } | |
| 432 | + message = bashProcessedMessage; | |
| 433 | + | |
| 426 | 434 | // Handle slash commands |
| 427 | 435 | const processedMessage = await handleSlashCommandProcessing(message); |
| 428 | 436 | if (processedMessage === null) { |
modified extensions/cli/src/ui/hooks/useUserInput.ts +3 −0
| @@ -104,6 +104,7 @@ | ||
| 104 | 104 | setCursorPosition: (pos: number) => void; |
| 105 | 105 | updateSlashCommandState: (text: string, cursor: number) => void; |
| 106 | 106 | updateFileSearchState: (text: string, cursor: number) => void; |
| 107 | + updateBashModeState: (text: string) => void; | |
| 107 | 108 | inputHistory: any; |
| 108 | 109 | } |
| 109 | 110 | |
| @@ -115,6 +116,7 @@ | ||
| 115 | 116 | setCursorPosition, |
| 116 | 117 | updateSlashCommandState, |
| 117 | 118 | updateFileSearchState, |
| 119 | + updateBashModeState, | |
| 118 | 120 | inputHistory, |
| 119 | 121 | } = options; |
| 120 | 122 | |
| @@ -126,6 +128,7 @@ | ||
| 126 | 128 | setCursorPosition(newCursor); |
| 127 | 129 | updateSlashCommandState(newText, newCursor); |
| 128 | 130 | updateFileSearchState(newText, newCursor); |
| 131 | + updateBashModeState(newText); | |
| 129 | 132 | inputHistory.resetNavigation(); |
| 130 | 133 | } |
| 131 | 134 | } |
modified extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/continue/IntelliJIde.kt +3 −1
| @@ -199,7 +199,9 @@ | ||
| 199 | 199 | } |
| 200 | 200 | |
| 201 | 201 | override suspend fun openFile(path: String) = |
| 202 | - fileUtils.openFile(path) | |
| 202 | + withContext(Dispatchers.EDT) { | |
| 203 | + fileUtils.openFile(path) | |
| 204 | + } | |
| 203 | 205 | |
| 204 | 206 | override suspend fun openUrl(url: String) { |
| 205 | 207 | withContext(Dispatchers.IO) { |
modified extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/continue/process/ContinueProcessHandler.kt +8 −4
| @@ -43,10 +43,14 @@ | ||
| 43 | 43 | } |
| 44 | 44 | scope.launch(Dispatchers.IO) { |
| 45 | 45 | for (message in pendingWrites) { |
| 46 | - log.debug("Write: $message") | |
| 47 | - writer.write(message) | |
| 48 | - writer.write("\r\n") | |
| 49 | - writer.flush() | |
| 46 | + try { | |
| 47 | + log.debug("Write: $message") | |
| 48 | + writer.write(message) | |
| 49 | + writer.write("\r\n") | |
| 50 | + writer.flush() | |
| 51 | + } catch (e: IOException) { | |
| 52 | + log.warn(e) | |
| 53 | + } | |
| 50 | 54 | } |
| 51 | 55 | } |
| 52 | 56 | } |
modified extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/error/ContinueErrorSubmitter.kt +1 −0
| @@ -21,6 +21,7 @@ | ||
| 21 | 21 | consumer: Consumer<in SubmittedReportInfo> |
| 22 | 22 | ): Boolean { |
| 23 | 23 | try { |
| 24 | + // todo: IdeaReportingEvent is deprecated; migrate to IdeaLoggingEvent + figure out how to read attachments | |
| 24 | 25 | val event = events.filterIsInstance<IdeaReportingEvent>() |
| 25 | 26 | .firstOrNull() ?: return false |
| 26 | 27 | service<ContinueSentryService>().report( |
modified extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/license/AddLicenseKey.kt +12 −17
| @@ -5,22 +5,27 @@ | ||
| 5 | 5 | import com.intellij.notification.NotificationAction |
| 6 | 6 | import com.intellij.notification.NotificationGroupManager |
| 7 | 7 | import com.intellij.notification.NotificationType |
| 8 | -import com.intellij.openapi.actionSystem.ActionManager | |
| 9 | -import com.intellij.openapi.actionSystem.ActionPlaces | |
| 10 | 8 | import com.intellij.openapi.actionSystem.AnAction |
| 11 | 9 | import com.intellij.openapi.actionSystem.AnActionEvent |
| 12 | 10 | import com.intellij.openapi.application.ApplicationManager |
| 13 | 11 | import com.intellij.openapi.components.service |
| 12 | +import com.intellij.openapi.project.Project | |
| 14 | 13 | import com.intellij.openapi.ui.DialogWrapper |
| 15 | 14 | |
| 16 | 15 | class AddLicenseKey : AnAction() { |
| 17 | 16 | |
| 18 | 17 | override fun actionPerformed(e: AnActionEvent) { |
| 19 | - val dialog = AddLicenseKeyDialog(e.project) | |
| 18 | + performAddLicenseKey(e.project) | |
| 19 | + } | |
| 20 | + | |
| 21 | + private fun performAddLicenseKey(project: Project?) { | |
| 22 | + if (project == null) | |
| 23 | + return | |
| 24 | + val dialog = AddLicenseKeyDialog(project) | |
| 20 | 25 | dialog.show() |
| 21 | 26 | if (dialog.exitCode != DialogWrapper.OK_EXIT_CODE) |
| 22 | 27 | return |
| 23 | - val messenger = e.project?.service<ContinuePluginService>()?.coreMessenger | |
| 28 | + val messenger = project.service<ContinuePluginService>().coreMessenger | |
| 24 | 29 | ?: return |
| 25 | 30 | messenger.request("mdm/setLicenseKey", mapOf("licenseKey" to dialog.licenseKey), null) { response -> |
| 26 | 31 | val isValid = response.castNestedOrNull<Boolean>("content") ?: false |
| @@ -28,7 +33,7 @@ | ||
| 28 | 33 | createSuccessAction() |
| 29 | 34 | else |
| 30 | 35 | createErrorAction() |
| 31 | - notification.notify(e.project) | |
| 36 | + notification.notify(project) | |
| 32 | 37 | } |
| 33 | 38 | } |
| 34 | 39 | |
| @@ -37,7 +42,7 @@ | ||
| 37 | 42 | "License key is valid. A restart is required for it to take effect.", |
| 38 | 43 | NotificationType.INFORMATION |
| 39 | 44 | ).addAction( |
| 40 | - NotificationAction.create("Restart IDE") { event, notification -> | |
| 45 | + NotificationAction.create("Restart IDE") { _, _ -> | |
| 41 | 46 | ApplicationManager.getApplication().restart() |
| 42 | 47 | } |
| 43 | 48 | ) |
| @@ -49,17 +54,7 @@ | ||
| 49 | 54 | ).addAction( |
| 50 | 55 | NotificationAction.create("Try again") { event, notification -> |
| 51 | 56 | notification.expire() |
| 52 | - val action = this@AddLicenseKey | |
| 53 | - action.actionPerformed( | |
| 54 | - AnActionEvent( | |
| 55 | - null, | |
| 56 | - event.dataContext, | |
| 57 | - ActionPlaces.UNKNOWN, | |
| 58 | - action.templatePresentation.clone(), | |
| 59 | - ActionManager.getInstance(), | |
| 60 | - 0 | |
| 61 | - ) | |
| 62 | - ) | |
| 57 | + performAddLicenseKey(event.project) | |
| 63 | 58 | } |
| 64 | 59 | ) |
| 65 | 60 |
modified extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/license/AddLicenseKeyDialog.kt +2 −2
| @@ -3,9 +3,9 @@ | ||
| 3 | 3 | import com.intellij.openapi.project.Project |
| 4 | 4 | import com.intellij.openapi.ui.DialogWrapper |
| 5 | 5 | import com.intellij.openapi.ui.ValidationInfo |
| 6 | +import com.intellij.ui.dsl.builder.AlignX | |
| 6 | 7 | import com.intellij.ui.dsl.builder.bindText |
| 7 | 8 | import com.intellij.ui.dsl.builder.panel |
| 8 | -import com.intellij.ui.dsl.gridLayout.HorizontalAlign | |
| 9 | 9 | import javax.swing.JComponent |
| 10 | 10 | |
| 11 | 11 | class AddLicenseKeyDialog(project: Project?) : DialogWrapper(project) { |
| @@ -22,7 +22,7 @@ | ||
| 22 | 22 | panel { |
| 23 | 23 | row { |
| 24 | 24 | textField().bindText(::licenseKey) |
| 25 | - .horizontalAlign(HorizontalAlign.FILL) | |
| 25 | + .align(AlignX.FILL) | |
| 26 | 26 | .focused() |
| 27 | 27 | .validationOnApply { |
| 28 | 28 | if (it.text.isBlank()) |
modified extensions/vscode/package.json +1 −1
| @@ -2,7 +2,7 @@ | ||
| 2 | 2 | "name": "continue", |
| 3 | 3 | "icon": "media/icon.png", |
| 4 | 4 | "author": "Continue Dev, Inc", |
| 5 | - "version": "1.3.3", | |
| 5 | + "version": "1.3.4", | |
| 6 | 6 | "repository": { |
| 7 | 7 | "type": "git", |
| 8 | 8 | "url": "https://github.com/continuedev/continue" |
modified gui/src/components/gui/Switch.tsx +12 −1
| @@ -1,5 +1,7 @@ | ||
| 1 | +import { InformationCircleIcon } from "@heroicons/react/24/outline"; | |
| 1 | 2 | import React, { ReactNode } from "react"; |
| 2 | 3 | import { vscButtonBackground } from ".."; |
| 4 | +import { ToolTip } from "./Tooltip"; | |
| 3 | 5 | |
| 4 | 6 | type ToggleSwitchProps = { |
| 5 | 7 | isToggled: boolean; |
| @@ -8,6 +10,7 @@ | ||
| 8 | 10 | size?: number; |
| 9 | 11 | showIfToggled?: ReactNode; |
| 10 | 12 | disabled?: boolean; |
| 13 | + tooltip?: string; | |
| 11 | 14 | }; |
| 12 | 15 | |
| 13 | 16 | const ToggleSwitch: React.FC<ToggleSwitchProps> = ({ |
| @@ -17,12 +20,20 @@ | ||
| 17 | 20 | size = 16, |
| 18 | 21 | showIfToggled, |
| 19 | 22 | disabled = false, |
| 23 | + tooltip, | |
| 20 | 24 | }) => { |
| 21 | 25 | return ( |
| 22 | 26 | <div |
| 23 | 27 | className={`flex select-none items-center justify-between gap-3 ${disabled ? "cursor-not-allowed" : "cursor-pointer"}`} |
| 24 | 28 | > |
| 25 | - <span className="truncate-right">{text}</span> | |
| 29 | + <span className="truncate-right flex items-center gap-x-1"> | |
| 30 | + {text}{" "} | |
| 31 | + {tooltip && ( | |
| 32 | + <ToolTip content={tooltip}> | |
| 33 | + <InformationCircleIcon className="h-3 w-3" /> | |
| 34 | + </ToolTip> | |
| 35 | + )} | |
| 36 | + </span> | |
| 26 | 37 | <div className="flex flex-row items-center gap-1"> |
| 27 | 38 | {isToggled && !!showIfToggled && showIfToggled} |
| 28 | 39 | <div |
modified gui/src/pages/config/UserSettingsForm.tsx +41 −5
| @@ -2,6 +2,7 @@ | ||
| 2 | 2 | CheckIcon, |
| 3 | 3 | ChevronRightIcon, |
| 4 | 4 | ExclamationTriangleIcon, |
| 5 | + InformationCircleIcon, | |
| 5 | 6 | XMarkIcon, |
| 6 | 7 | } from "@heroicons/react/24/outline"; |
| 7 | 8 | import { |
| @@ -177,6 +178,7 @@ | ||
| 177 | 178 | }) |
| 178 | 179 | } |
| 179 | 180 | text="Show Session Tabs" |
| 181 | + tooltip="If on, displays tabs above the chat as an alternative way to organize and access your sessions." | |
| 180 | 182 | /> |
| 181 | 183 | <ToggleSwitch |
| 182 | 184 | isToggled={codeWrap} |
| @@ -186,6 +188,7 @@ | ||
| 186 | 188 | }) |
| 187 | 189 | } |
| 188 | 190 | text="Wrap Codeblocks" |
| 191 | + tooltip="If on, displays tabs above the chat as an alternative way to organize and access your sessions." | |
| 189 | 192 | /> |
| 190 | 193 | |
| 191 | 194 | <ToggleSwitch |
| @@ -196,6 +199,7 @@ | ||
| 196 | 199 | }) |
| 197 | 200 | } |
| 198 | 201 | text="Show Chat Scrollbar" |
| 202 | + tooltip="If on, enables a scrollbar in the chat window." | |
| 199 | 203 | /> |
| 200 | 204 | <ToggleSwitch |
| 201 | 205 | isToggled={readResponseTTS} |
| @@ -205,6 +209,7 @@ | ||
| 205 | 209 | }) |
| 206 | 210 | } |
| 207 | 211 | text="Text-to-Speech Output" |
| 212 | + tooltip="If on, reads LLM responses aloud with TTS." | |
| 208 | 213 | /> |
| 209 | 214 | {/* <ToggleSwitch |
| 210 | 215 | isToggled={useChromiumForDocsCrawling} |
| @@ -223,6 +228,7 @@ | ||
| 223 | 228 | }) |
| 224 | 229 | } |
| 225 | 230 | text="Enable Session Titles" |
| 231 | + tooltip="If on, generates summary titles for each chat session after the first message, using the current Chat model." | |
| 226 | 232 | /> |
| 227 | 233 | <ToggleSwitch |
| 228 | 234 | isToggled={!displayRawMarkdown} |
| @@ -232,6 +238,7 @@ | ||
| 232 | 238 | }) |
| 233 | 239 | } |
| 234 | 240 | text="Format Markdown" |
| 241 | + tooltip="If off, shows responses as raw text." | |
| 235 | 242 | /> |
| 236 | 243 | |
| 237 | 244 | <ToggleSwitch |
| @@ -243,6 +250,7 @@ | ||
| 243 | 250 | }) |
| 244 | 251 | } |
| 245 | 252 | text="Allow Anonymous Telemetry" |
| 253 | + tooltip="If on, allows Continue to send anonymous telemetry." | |
| 246 | 254 | /> |
| 247 | 255 | |
| 248 | 256 | <ToggleSwitch |
| @@ -267,7 +275,12 @@ | ||
| 267 | 275 | /> */} |
| 268 | 276 | |
| 269 | 277 | <label className="flex items-center justify-between gap-3"> |
| 270 | - <span className="text-left">Font Size</span> | |
| 278 | + <span className="flex items-center gap-x-1 text-left"> | |
| 279 | + Font Size{" "} | |
| 280 | + <ToolTip content="Specifies base font size for UI elements"> | |
| 281 | + <InformationCircleIcon className="h-3 w-3" /> | |
| 282 | + </ToolTip> | |
| 283 | + </span> | |
| 271 | 284 | <NumberInput |
| 272 | 285 | value={fontSize} |
| 273 | 286 | onChange={(val) => { |
| @@ -281,8 +294,11 @@ | ||
| 281 | 294 | /> |
| 282 | 295 | </label> |
| 283 | 296 | <label className="flex items-center justify-between gap-3"> |
| 284 | - <span className="lines lines-1 text-left"> | |
| 297 | + <span className="lines lines-1 flex items-center gap-x-1 text-left"> | |
| 285 | 298 | Multiline Autocompletions |
| 299 | + <ToolTip content="Controls multiline completions for autocomplete."> | |
| 300 | + <InformationCircleIcon className="h-3 w-3" /> | |
| 301 | + </ToolTip> | |
| 286 | 302 | </span> |
| 287 | 303 | <Select |
| 288 | 304 | value={useAutocompleteMultilineCompletions} |
| @@ -301,7 +317,12 @@ | ||
| 301 | 317 | </Select> |
| 302 | 318 | </label> |
| 303 | 319 | <label className="flex items-center justify-between gap-3"> |
| 304 | - <span className="text-left">Autocomplete Timeout (ms)</span> | |
| 320 | + <span className="flex items-center gap-x-1 text-left"> | |
| 321 | + Autocomplete Timeout (ms) | |
| 322 | + <ToolTip content="Maximum time in milliseconds for autocomplete request/retrieval."> | |
| 323 | + <InformationCircleIcon className="h-3 w-3" /> | |
| 324 | + </ToolTip> | |
| 325 | + </span> | |
| 305 | 326 | <NumberInput |
| 306 | 327 | value={modelTimeout} |
| 307 | 328 | onChange={(val) => |
| @@ -314,7 +335,12 @@ | ||
| 314 | 335 | /> |
| 315 | 336 | </label> |
| 316 | 337 | <label className="flex items-center justify-between gap-3"> |
| 317 | - <span className="text-left">Autocomplete Debounce (ms)</span> | |
| 338 | + <span className="flex items-center gap-x-1 text-left"> | |
| 339 | + Autocomplete Debounce (ms) | |
| 340 | + <ToolTip content="Minimum time in milliseconds to trigger an autocomplete request after a change."> | |
| 341 | + <InformationCircleIcon className="h-3 w-3" /> | |
| 342 | + </ToolTip> | |
| 343 | + </span> | |
| 318 | 344 | <NumberInput |
| 319 | 345 | value={debounceDelay} |
| 320 | 346 | onChange={(val) => |
| @@ -334,7 +360,12 @@ | ||
| 334 | 360 | }} |
| 335 | 361 | > |
| 336 | 362 | <div className="flex items-center justify-between"> |
| 337 | - <span>Disable autocomplete in files</span> | |
| 363 | + <span className="flex items-center gap-x-1"> | |
| 364 | + Disable autocomplete in files | |
| 365 | + <ToolTip content="List of comma-separated glob pattern to disable autocomplete in matching files. E.g., **/*.{txt,md}"> | |
| 366 | + <InformationCircleIcon className="h-3 w-3" /> | |
| 367 | + </ToolTip> | |
| 368 | + </span> | |
| 338 | 369 | <div className="flex items-center gap-2"> |
| 339 | 370 | <Input |
| 340 | 371 | value={formDisableAutocomplete} |
| @@ -401,6 +432,8 @@ | ||
| 401 | 432 | }) |
| 402 | 433 | } |
| 403 | 434 | text="Auto-Accept Agent Edits" |
| 435 | + tooltip="If on, diffs generated by the edit tool are | |
| 436 | + automatically accepted and Agent proceeds with the next conversational turn." | |
| 404 | 437 | showIfToggled={ |
| 405 | 438 | <> |
| 406 | 439 | <ToolTip |
| @@ -420,6 +453,7 @@ | ||
| 420 | 453 | }) |
| 421 | 454 | } |
| 422 | 455 | text="Add Current File by Default" |
| 456 | + tooltip="If on, the currently open file is added as context in every new conversation." | |
| 423 | 457 | /> |
| 424 | 458 | |
| 425 | 459 | <ToggleSwitch |
| @@ -439,6 +473,7 @@ | ||
| 439 | 473 | onlyUseSystemMessageTools: !onlyUseSystemMessageTools, |
| 440 | 474 | }) |
| 441 | 475 | } |
| 476 | + tooltip="If on, Continue will not attempt to use native tool calling and will only use system message tools." | |
| 442 | 477 | text="Only use system message tools" |
| 443 | 478 | /> |
| 444 | 479 | |
| @@ -460,6 +495,7 @@ | ||
| 460 | 495 | }) |
| 461 | 496 | } |
| 462 | 497 | text="Stream after tool rejection" |
| 498 | + tooltip="If on, streaming will continue after the tool call is rejected." | |
| 463 | 499 | /> |
| 464 | 500 | |
| 465 | 501 | {hasContinueEmail && ( |
modified gui/src/pages/gui/ToolCallDiv/FindAndReplace.tsx +78 −53
| @@ -14,6 +14,7 @@ | ||
| 14 | 14 | selectToolCallById, |
| 15 | 15 | } from "../../../redux/selectors/selectToolCalls"; |
| 16 | 16 | import { performFindAndReplace } from "../../../util/clientTools/findAndReplaceUtils"; |
| 17 | +import { cn } from "../../../util/cn"; | |
| 17 | 18 | import { getStatusIcon } from "./utils"; |
| 18 | 19 | |
| 19 | 20 | interface FindAndReplaceDisplayProps { |
| @@ -25,6 +26,48 @@ | ||
| 25 | 26 | historyIndex: number; |
| 26 | 27 | } |
| 27 | 28 | |
| 29 | +const MAX_SAME_LINES = 2; | |
| 30 | + | |
| 31 | +function EllipsisLine() { | |
| 32 | + return ( | |
| 33 | + <div className="text-description-muted px-3 py-1 text-center font-mono"> | |
| 34 | + ⋯ | |
| 35 | + </div> | |
| 36 | + ); | |
| 37 | +} | |
| 38 | + | |
| 39 | +function DiffLines({ | |
| 40 | + lines, | |
| 41 | + className = "", | |
| 42 | + diffChar = " ", | |
| 43 | + diffCharClass = "text-description-muted", | |
| 44 | +}: { | |
| 45 | + lines: string[]; | |
| 46 | + diffChar?: string; | |
| 47 | + diffCharClass?: string; | |
| 48 | + className?: string; | |
| 49 | +}) { | |
| 50 | + return ( | |
| 51 | + <> | |
| 52 | + {lines.map((line, lineIndex) => { | |
| 53 | + const isLastPartLine = lineIndex === lines.length - 1; | |
| 54 | + if (line === "" && isLastPartLine) return null; | |
| 55 | + return ( | |
| 56 | + <div | |
| 57 | + key={lineIndex} | |
| 58 | + className={cn("text-foreground px-3 py-px font-mono", className)} | |
| 59 | + > | |
| 60 | + <span className={cn("mr-2 select-none", diffCharClass)}> | |
| 61 | + {diffChar} | |
| 62 | + </span> | |
| 63 | + {line} | |
| 64 | + </div> | |
| 65 | + ); | |
| 66 | + })} | |
| 67 | + </> | |
| 68 | + ); | |
| 69 | +} | |
| 70 | + | |
| 28 | 71 | export function FindAndReplaceDisplay({ |
| 29 | 72 | fileUri, |
| 30 | 73 | relativeFilePath, |
| @@ -200,70 +243,52 @@ | ||
| 200 | 243 | <pre |
| 201 | 244 | className={`bg-editor m-0 w-full text-xs leading-tight ${config?.ui?.codeWrap ? "whitespace-pre-wrap" : "whitespace-pre"}`} |
| 202 | 245 | > |
| 203 | - {diffResult.diff.map((part, index) => { | |
| 246 | + {diffResult.diff?.map((part, index) => { | |
| 204 | 247 | if (part.removed) { |
| 205 | 248 | return ( |
| 206 | - <div | |
| 249 | + <DiffLines | |
| 207 | 250 | key={index} |
| 208 | - className="text-foreground border-l-4 border-red-900 bg-red-900/30" | |
| 209 | - > | |
| 210 | - {part.value.split("\n").map((line, lineIndex) => { | |
| 211 | - if ( | |
| 212 | - line === "" && | |
| 213 | - lineIndex === part.value.split("\n").length - 1 | |
| 214 | - ) | |
| 215 | - return null; | |
| 216 | - return ( | |
| 217 | - <div key={lineIndex} className="px-3 py-px font-mono"> | |
| 218 | - <span className="mr-2 select-none text-red-600">-</span> | |
| 219 | - {line} | |
| 220 | - </div> | |
| 221 | - ); | |
| 222 | - })} | |
| 223 | - </div> | |
| 251 | + lines={part.value.split("\n")} | |
| 252 | + className="border-l-4 border-red-900 bg-red-900/30" | |
| 253 | + diffCharClass="text-red-600" | |
| 254 | + diffChar="-" | |
| 255 | + /> | |
| 224 | 256 | ); |
| 225 | 257 | } else if (part.added) { |
| 226 | 258 | return ( |
| 227 | - <div | |
| 259 | + <DiffLines | |
| 228 | 260 | key={index} |
| 229 | - className="text-foreground border-l-4 border-green-600 bg-green-600/20" | |
| 230 | - > | |
| 231 | - {part.value.split("\n").map((line, lineIndex) => { | |
| 232 | - if ( | |
| 233 | - line === "" && | |
| 234 | - lineIndex === part.value.split("\n").length - 1 | |
| 235 | - ) | |
| 236 | - return null; | |
| 237 | - return ( | |
| 238 | - <div key={lineIndex} className="px-3 py-px font-mono"> | |
| 239 | - <span className="mr-2 select-none text-green-600">+</span> | |
| 240 | - {line} | |
| 241 | - </div> | |
| 242 | - ); | |
| 243 | - })} | |
| 244 | - </div> | |
| 261 | + lines={part.value.split("\n")} | |
| 262 | + diffCharClass="text-green-600" | |
| 263 | + className="border-l-4 border-green-600 bg-green-600/20" | |
| 264 | + diffChar="+" | |
| 265 | + /> | |
| 245 | 266 | ); |
| 246 | 267 | } else { |
| 268 | + const isFirst = index === 0; | |
| 269 | + const isLast = index === diffResult.diff.length - 1; | |
| 270 | + const lines = part.value.split("\n"); | |
| 271 | + const showStartEllipsis = isFirst && lines.length > MAX_SAME_LINES; | |
| 272 | + const showEndEllipsis = isLast && lines.length > MAX_SAME_LINES; | |
| 273 | + const showMiddleEllipses = | |
| 274 | + !isFirst && !isLast && lines.length > MAX_SAME_LINES * 2 + 1; | |
| 275 | + | |
| 276 | + const startLines = showStartEllipsis | |
| 277 | + ? lines.slice(-MAX_SAME_LINES) | |
| 278 | + : showMiddleEllipses || showEndEllipsis | |
| 279 | + ? lines.slice(0, MAX_SAME_LINES) | |
| 280 | + : lines; | |
| 281 | + const endLines = showMiddleEllipses | |
| 282 | + ? lines.slice(-MAX_SAME_LINES) | |
| 283 | + : []; | |
| 284 | + | |
| 247 | 285 | return ( |
| 248 | 286 | <div key={index}> |
| 249 | - {part.value.split("\n").map((line, lineIndex) => { | |
| 250 | - if ( | |
| 251 | - line === "" && | |
| 252 | - lineIndex === part.value.split("\n").length - 1 | |
| 253 | - ) | |
| 254 | - return null; | |
| 255 | - return ( | |
| 256 | - <div | |
| 257 | - key={lineIndex} | |
| 258 | - className="text-foreground px-3 py-px font-mono" | |
| 259 | - > | |
| 260 | - <span className="text-description-muted mr-2 select-none"> | |
| 261 | - {" "} | |
| 262 | - </span> | |
| 263 | - {line} | |
| 264 | - </div> | |
| 265 | - ); | |
| 266 | - })} | |
| 287 | + {showStartEllipsis && <EllipsisLine />} | |
| 288 | + <DiffLines lines={startLines} /> | |
| 289 | + {showMiddleEllipses && <EllipsisLine />} | |
| 290 | + <DiffLines lines={endLines} /> | |
| 291 | + {showEndEllipsis && <EllipsisLine />} | |
| 267 | 292 | </div> |
| 268 | 293 | ); |
| 269 | 294 | } |
modified packages/openai-adapters/src/apis/Gemini.ts +33 −2
| @@ -10,6 +10,7 @@ | ||
| 10 | 10 | Completion, |
| 11 | 11 | CompletionCreateParamsNonStreaming, |
| 12 | 12 | CompletionCreateParamsStreaming, |
| 13 | + CompletionUsage, | |
| 13 | 14 | CreateEmbeddingResponse, |
| 14 | 15 | EmbeddingCreateParams, |
| 15 | 16 | Model, |
| @@ -22,6 +23,7 @@ | ||
| 22 | 23 | chatChunkFromDelta, |
| 23 | 24 | customFetch, |
| 24 | 25 | embedding, |
| 26 | + usageChatChunk, | |
| 25 | 27 | } from "../util.js"; |
| 26 | 28 | import { |
| 27 | 29 | convertOpenAIToolToGeminiFunction, |
| @@ -37,6 +39,11 @@ | ||
| 37 | 39 | RerankCreateParams, |
| 38 | 40 | } from "./base.js"; |
| 39 | 41 | |
| 42 | +type UsageInfo = Pick< | |
| 43 | + CompletionUsage, | |
| 44 | + "total_tokens" | "completion_tokens" | "prompt_tokens" | |
| 45 | +>; | |
| 46 | + | |
| 40 | 47 | export class GeminiApi implements BaseLlmApi { |
| 41 | 48 | apiBase: string = "https://generativelanguage.googleapis.com/v1beta/"; |
| 42 | 49 | |
| @@ -240,6 +247,7 @@ | ||
| 240 | 247 | signal: AbortSignal, |
| 241 | 248 | ): Promise<ChatCompletion> { |
| 242 | 249 | let completion = ""; |
| 250 | + let usage: UsageInfo | undefined = undefined; | |
| 243 | 251 | for await (const chunk of this.chatCompletionStream( |
| 244 | 252 | { |
| 245 | 253 | ...body, |
| @@ -247,7 +255,12 @@ | ||
| 247 | 255 | }, |
| 248 | 256 | signal, |
| 249 | 257 | )) { |
| 250 | - completion += chunk.choices[0].delta.content; | |
| 258 | + if (chunk.choices.length > 0) { | |
| 259 | + completion += chunk.choices[0].delta.content || ""; | |
| 260 | + } | |
| 261 | + if (chunk.usage) { | |
| 262 | + usage = chunk.usage; | |
| 263 | + } | |
| 251 | 264 | } |
| 252 | 265 | return { |
| 253 | 266 | id: "", |
| @@ -266,12 +279,13 @@ | ||
| 266 | 279 | }, |
| 267 | 280 | }, |
| 268 | 281 | ], |
| 269 | - usage: undefined, | |
| 282 | + usage, | |
| 270 | 283 | }; |
| 271 | 284 | } |
| 272 | 285 | |
| 273 | 286 | async *handleStreamResponse(response: any, model: string) { |
| 274 | 287 | let buffer = ""; |
| 288 | + let usage: UsageInfo | undefined = undefined; | |
| 275 | 289 | for await (const chunk of streamResponse(response as any)) { |
| 276 | 290 | buffer += chunk; |
| 277 | 291 | if (buffer.startsWith("[")) { |
| @@ -300,6 +314,15 @@ | ||
| 300 | 314 | throw new Error(data.error.message); |
| 301 | 315 | } |
| 302 | 316 | |
| 317 | + // Check for usage metadata | |
| 318 | + if (data.usageMetadata) { | |
| 319 | + usage = { | |
| 320 | + prompt_tokens: data.usageMetadata.promptTokenCount || 0, | |
| 321 | + completion_tokens: data.usageMetadata.candidatesTokenCount || 0, | |
| 322 | + total_tokens: data.usageMetadata.totalTokenCount || 0, | |
| 323 | + }; | |
| 324 | + } | |
| 325 | + | |
| 303 | 326 | // In case of max tokens reached, gemini will sometimes return content with no parts, even though that doesn't match the API spec |
| 304 | 327 | const contentParts = data?.candidates?.[0]?.content?.parts; |
| 305 | 328 | if (contentParts) { |
| @@ -338,6 +361,14 @@ | ||
| 338 | 361 | buffer = ""; |
| 339 | 362 | } |
| 340 | 363 | } |
| 364 | + | |
| 365 | + // Emit usage at the end if we have it | |
| 366 | + if (usage) { | |
| 367 | + yield usageChatChunk({ | |
| 368 | + model, | |
| 369 | + usage, | |
| 370 | + }); | |
| 371 | + } | |
| 341 | 372 | } |
| 342 | 373 | |
| 343 | 374 | async *chatCompletionStream( |
modified packages/openai-adapters/src/apis/OpenAI.ts +5 −0
| @@ -35,6 +35,11 @@ | ||
| 35 | 35 | }); |
| 36 | 36 | } |
| 37 | 37 | modifyChatBody<T extends ChatCompletionCreateParams>(body: T): T { |
| 38 | + // Add stream_options to include usage in streaming responses | |
| 39 | + if (body.stream) { | |
| 40 | + (body as any).stream_options = { include_usage: true }; | |
| 41 | + } | |
| 42 | + | |
| 38 | 43 | // o-series models - only apply for official OpenAI API |
| 39 | 44 | const isOfficialOpenAIAPI = this.apiBase === "https://api.openai.com/v1/"; |
| 40 | 45 | if (isOfficialOpenAIAPI) { |
modified packages/openai-adapters/src/apis/Relace.ts +29 −2
| @@ -2,6 +2,7 @@ | ||
| 2 | 2 | Completion, |
| 3 | 3 | CompletionCreateParamsNonStreaming, |
| 4 | 4 | CompletionCreateParamsStreaming, |
| 5 | + CompletionUsage, | |
| 5 | 6 | } from "openai/resources/completions.mjs"; |
| 6 | 7 | import { |
| 7 | 8 | CreateEmbeddingResponse, |
| @@ -16,7 +17,12 @@ | ||
| 16 | 17 | import { Model } from "openai/resources/models.mjs"; |
| 17 | 18 | import { z } from "zod"; |
| 18 | 19 | import { OpenAIConfigSchema } from "../types.js"; |
| 19 | -import { chatChunk, chatCompletion, customFetch } from "../util.js"; | |
| 20 | +import { | |
| 21 | + chatChunk, | |
| 22 | + chatCompletion, | |
| 23 | + customFetch, | |
| 24 | + usageChatChunk, | |
| 25 | +} from "../util.js"; | |
| 20 | 26 | import { |
| 21 | 27 | BaseLlmApi, |
| 22 | 28 | CreateRerankResponse, |
| @@ -24,6 +30,11 @@ | ||
| 24 | 30 | RerankCreateParams, |
| 25 | 31 | } from "./base.js"; |
| 26 | 32 | |
| 33 | +type UsageInfo = Pick< | |
| 34 | + CompletionUsage, | |
| 35 | + "total_tokens" | "completion_tokens" | "prompt_tokens" | |
| 36 | +>; | |
| 37 | + | |
| 27 | 38 | // Relace only supports apply through a /v1/apply endpoint |
| 28 | 39 | export class RelaceApi implements BaseLlmApi { |
| 29 | 40 | private apiBase = "https://instantapply.endpoint.relace.run/v1/"; |
| @@ -41,6 +52,7 @@ | ||
| 41 | 52 | signal: AbortSignal, |
| 42 | 53 | ): Promise<ChatCompletion> { |
| 43 | 54 | let content = ""; |
| 55 | + let usage: UsageInfo | undefined = undefined; | |
| 44 | 56 | |
| 45 | 57 | // Convert the non-streaming params to streaming params |
| 46 | 58 | const streamingBody: ChatCompletionCreateParamsStreaming = { |
| @@ -52,12 +64,18 @@ | ||
| 52 | 64 | streamingBody, |
| 53 | 65 | signal, |
| 54 | 66 | )) { |
| 55 | - content += chunk.choices[0]?.delta?.content || ""; | |
| 67 | + if (chunk.choices.length > 0) { | |
| 68 | + content += chunk.choices[0]?.delta?.content || ""; | |
| 69 | + } | |
| 70 | + if (chunk.usage) { | |
| 71 | + usage = chunk.usage; | |
| 72 | + } | |
| 56 | 73 | } |
| 57 | 74 | |
| 58 | 75 | return chatCompletion({ |
| 59 | 76 | content, |
| 60 | 77 | model: body.model, |
| 78 | + usage, | |
| 61 | 79 | }); |
| 62 | 80 | } |
| 63 | 81 | |
| @@ -115,6 +133,15 @@ | ||
| 115 | 133 | content: mergedCode, |
| 116 | 134 | model: body.model, |
| 117 | 135 | }); |
| 136 | + | |
| 137 | + yield usageChatChunk({ | |
| 138 | + model: body.model, | |
| 139 | + usage: { | |
| 140 | + prompt_tokens: result.usage.prompt_tokens || 0, | |
| 141 | + completion_tokens: result.usage.completion_tokens || 0, | |
| 142 | + total_tokens: result.usage.total_tokens, | |
| 143 | + }, | |
| 144 | + }); | |
| 118 | 145 | } |
| 119 | 146 | |
| 120 | 147 | completionNonStream( |
modified packages/openai-adapters/src/test/adapter-test-utils.ts +1 −0
| @@ -258,6 +258,7 @@ | ||
| 258 | 258 | model: "gpt-4", |
| 259 | 259 | messages: [{ role: "user", content: "hello" }], |
| 260 | 260 | stream: true, |
| 261 | + stream_options: { include_usage: true }, | |
| 261 | 262 | ...testConfig.customBodyOptions, |
| 262 | 263 | }, |
| 263 | 264 | }, |
modified packages/openai-adapters/src/test/main.test.ts +58 −7
| @@ -51,6 +51,20 @@ | ||
| 51 | 51 | model: "gpt-4o", |
| 52 | 52 | apiKey: process.env.OPENAI_API_KEY!, |
| 53 | 53 | roles: ["chat"], |
| 54 | + options: { | |
| 55 | + skipTools: false, | |
| 56 | + expectUsage: true, | |
| 57 | + }, | |
| 58 | + }, | |
| 59 | + { | |
| 60 | + provider: "openai", | |
| 61 | + model: "gpt-4o-mini", | |
| 62 | + apiKey: process.env.OPENAI_API_KEY!, | |
| 63 | + roles: ["chat"], | |
| 64 | + options: { | |
| 65 | + skipTools: false, | |
| 66 | + expectUsage: true, | |
| 67 | + }, | |
| 54 | 68 | }, |
| 55 | 69 | { |
| 56 | 70 | provider: "anthropic", |
| @@ -67,15 +81,32 @@ | ||
| 67 | 81 | model: "gemini-1.5-flash-latest", |
| 68 | 82 | apiKey: process.env.GEMINI_API_KEY!, |
| 69 | 83 | roles: ["chat"], |
| 84 | + options: { | |
| 85 | + skipTools: false, | |
| 86 | + expectUsage: true, | |
| 87 | + }, | |
| 88 | + }, | |
| 89 | + { | |
| 90 | + provider: "gemini", | |
| 91 | + model: "gemini-2.5-flash", | |
| 92 | + apiKey: process.env.GEMINI_API_KEY!, | |
| 93 | + roles: ["chat"], | |
| 94 | + options: { | |
| 95 | + skipTools: false, | |
| 96 | + expectUsage: true, | |
| 97 | + }, | |
| 98 | + }, | |
| 99 | + { | |
| 100 | + provider: "mistral", | |
| 101 | + model: "codestral", | |
| 102 | + apiKey: process.env.MISTRAL_API_KEY!, | |
| 103 | + roles: ["chat"], | |
| 104 | + options: { | |
| 105 | + skipTools: false, | |
| 106 | + expectUsage: true, | |
| 107 | + }, | |
| 70 | 108 | }, |
| 71 | 109 | // { |
| 72 | - // provider: "mistral", | |
| 73 | - // model: "codestral-latest", | |
| 74 | - // apiKey: process.env.MISTRAL_API_KEY!, | |
| 75 | - // apiBase: "https://api.mistral.ai/v1", | |
| 76 | - // roles: ["autocomplete"], | |
| 77 | - // }, | |
| 78 | - // { | |
| 79 | 110 | // provider: "deepseek", |
| 80 | 111 | // model: "deepseek-coder", |
| 81 | 112 | // apiKey: process.env.DEEPSEEK_API_KEY!, |
| @@ -111,6 +142,26 @@ | ||
| 111 | 142 | apiKey: process.env.VOYAGE_API_KEY!, |
| 112 | 143 | roles: ["rerank"], |
| 113 | 144 | }, |
| 145 | + { | |
| 146 | + provider: "relace", | |
| 147 | + model: "instant-apply", | |
| 148 | + apiKey: process.env.RELACE_API_KEY!, | |
| 149 | + roles: ["chat"], | |
| 150 | + options: { | |
| 151 | + skipTools: true, | |
| 152 | + expectUsage: true, | |
| 153 | + }, | |
| 154 | + }, | |
| 155 | + { | |
| 156 | + provider: "inception", | |
| 157 | + model: "mercury-coder", | |
| 158 | + apiKey: process.env.INCEPTION_API_KEY!, | |
| 159 | + roles: ["chat"], | |
| 160 | + options: { | |
| 161 | + skipTools: false, | |
| 162 | + expectUsage: true, | |
| 163 | + }, | |
| 164 | + }, | |
| 114 | 165 | // { |
| 115 | 166 | // provider: "cohere", |
| 116 | 167 | // model: "rerank-v3.5", |
modified packages/openai-adapters/src/test/util.ts +11 −3
| @@ -106,9 +106,17 @@ | ||
| 106 | 106 | expect(usage).toBeDefined(); |
| 107 | 107 | expect(usage!.completion_tokens).toBeGreaterThan(0); |
| 108 | 108 | expect(usage!.prompt_tokens).toBeGreaterThan(0); |
| 109 | - expect(usage!.total_tokens).toEqual( | |
| 110 | - usage!.prompt_tokens + usage!.completion_tokens, | |
| 111 | - ); | |
| 109 | + // Gemini 2.5 models have thinking tokens, so total_tokens >= prompt + completion | |
| 110 | + // Other models should have total_tokens = prompt + completion | |
| 111 | + if (model.includes("gemini-2.5") || model.includes("gemini-2.0")) { | |
| 112 | + expect(usage!.total_tokens).toBeGreaterThanOrEqual( | |
| 113 | + usage!.prompt_tokens + usage!.completion_tokens, | |
| 114 | + ); | |
| 115 | + } else { | |
| 116 | + expect(usage!.total_tokens).toEqual( | |
| 117 | + usage!.prompt_tokens + usage!.completion_tokens, | |
| 118 | + ); | |
| 119 | + } | |
| 112 | 120 | } |
| 113 | 121 | }); |
| 114 | 122 |