From ce71e5e52e3025e6f022fe6909da6072f7af3222 Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Tue, 27 May 2025 11:56:53 -0700 Subject: [PATCH 01/44] don't accept tool call if auto accepting --- gui/src/hooks/ParallelListeners.tsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/gui/src/hooks/ParallelListeners.tsx b/gui/src/hooks/ParallelListeners.tsx index 155b91e2c..bc16970d9 100644 --- a/gui/src/hooks/ParallelListeners.tsx +++ b/gui/src/hooks/ParallelListeners.tsx @@ -3,7 +3,6 @@ import { IdeMessengerContext } from "../context/IdeMessenger"; import { EDIT_MODE_STREAM_ID } from "core/edit/constants"; import { FromCoreProtocol } from "core/protocol"; -import { useMainEditor } from "../components/mainInput/TipTapEditor"; import { initializeProfilePreferences, setOrganizations, @@ -52,7 +51,7 @@ function ParallelListeners() { selectCurrentToolCallApplyState, ); - const { mainEditor } = useMainEditor(); + const config = useAppSelector((store) => store.config.config); const handleConfigUpdate = useCallback( async (isInitial: boolean, result: FromCoreProtocol["configUpdate"][0]) => { @@ -252,7 +251,8 @@ function ParallelListeners() { if ( state.status === "closed" && currentToolCallApplyState && - currentToolCallApplyState.streamId === state.streamId + currentToolCallApplyState.streamId === state.streamId && + !config.ui?.autoAcceptEditToolDiffs ) { // const output: ContextItem = { // name: "Edit tool output", @@ -273,7 +273,7 @@ function ParallelListeners() { } } }, - [currentToolCallApplyState, history], + [currentToolCallApplyState, history, config], ); useEffect(() => { From 9b12377a9a9bdf0d958a0451beda14895767ff37 Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Tue, 27 May 2025 12:44:43 -0700 Subject: [PATCH 02/44] put isActive around llm calls --- gui/src/hooks/ParallelListeners.tsx | 8 +++---- gui/src/redux/thunks/edit.ts | 3 +++ gui/src/redux/thunks/streamNormalInput.ts | 6 ++++++ .../thunks/streamResponseAfterToolCall.ts | 21 ++++++++----------- gui/src/redux/thunks/streamThunkWrapper.tsx | 2 -- gui/src/util/clientTools/editImpl.ts | 4 ---- 6 files changed, 22 insertions(+), 22 deletions(-) diff --git a/gui/src/hooks/ParallelListeners.tsx b/gui/src/hooks/ParallelListeners.tsx index bc16970d9..155b91e2c 100644 --- a/gui/src/hooks/ParallelListeners.tsx +++ b/gui/src/hooks/ParallelListeners.tsx @@ -3,6 +3,7 @@ import { IdeMessengerContext } from "../context/IdeMessenger"; import { EDIT_MODE_STREAM_ID } from "core/edit/constants"; import { FromCoreProtocol } from "core/protocol"; +import { useMainEditor } from "../components/mainInput/TipTapEditor"; import { initializeProfilePreferences, setOrganizations, @@ -51,7 +52,7 @@ function ParallelListeners() { selectCurrentToolCallApplyState, ); - const config = useAppSelector((store) => store.config.config); + const { mainEditor } = useMainEditor(); const handleConfigUpdate = useCallback( async (isInitial: boolean, result: FromCoreProtocol["configUpdate"][0]) => { @@ -251,8 +252,7 @@ function ParallelListeners() { if ( state.status === "closed" && currentToolCallApplyState && - currentToolCallApplyState.streamId === state.streamId && - !config.ui?.autoAcceptEditToolDiffs + currentToolCallApplyState.streamId === state.streamId ) { // const output: ContextItem = { // name: "Edit tool output", @@ -273,7 +273,7 @@ function ParallelListeners() { } } }, - [currentToolCallApplyState, history, config], + [currentToolCallApplyState, history], ); useEffect(() => { diff --git a/gui/src/redux/thunks/edit.ts b/gui/src/redux/thunks/edit.ts index 4471cc0b4..6d379caf9 100644 --- a/gui/src/redux/thunks/edit.ts +++ b/gui/src/redux/thunks/edit.ts @@ -17,6 +17,7 @@ import { import { newSession, setActive, + setInactive, setIsInEdit, setMainEditorContentTrigger, setMode, @@ -61,6 +62,8 @@ export const streamEditThunk = createAsyncThunk< range: codeToEdit[0] as RangeInFileWithContents, }); + dispatch(setInactive()); + if (response.status === "error") { throw new Error(response.error); } diff --git a/gui/src/redux/thunks/streamNormalInput.ts b/gui/src/redux/thunks/streamNormalInput.ts index 8776aa1a6..cf68b3340 100644 --- a/gui/src/redux/thunks/streamNormalInput.ts +++ b/gui/src/redux/thunks/streamNormalInput.ts @@ -8,6 +8,8 @@ import { selectSelectedChatModel } from "../slices/configSlice"; import { abortStream, addPromptCompletionPair, + setActive, + setInactive, setToolGenerated, streamUpdate, } from "../slices/sessionSlice"; @@ -45,6 +47,8 @@ export const streamNormalInput = createAsyncThunk< }; } + dispatch(setActive()); + // Send request const gen = extra.ideMessenger.llmStreamChat( { @@ -68,6 +72,8 @@ export const streamNormalInput = createAsyncThunk< next = await gen.next(); } + dispatch(setInactive()); + // Attach prompt log and end thinking for reasoning models if (next.done && next.value) { dispatch(addPromptCompletionPair([next.value])); diff --git a/gui/src/redux/thunks/streamResponseAfterToolCall.ts b/gui/src/redux/thunks/streamResponseAfterToolCall.ts index 990723f7a..25ce6e8c5 100644 --- a/gui/src/redux/thunks/streamResponseAfterToolCall.ts +++ b/gui/src/redux/thunks/streamResponseAfterToolCall.ts @@ -4,11 +4,7 @@ import { constructMessages } from "core/llm/constructMessages"; import { renderContextItems } from "core/util/messageContent"; import { getBaseSystemMessage } from "../../util"; import { selectSelectedChatModel } from "../slices/configSlice"; -import { - addContextItemsAtIndex, - setActive, - streamUpdate, -} from "../slices/sessionSlice"; +import { addContextItemsAtIndex, streamUpdate } from "../slices/sessionSlice"; import { ThunkApiType } from "../store"; import { findToolCall } from "../util"; import { resetStateForNewMessage } from "./resetStateForNewMessage"; @@ -63,14 +59,14 @@ export const streamResponseAfterToolCall = createAsyncThunk< }), ); - dispatch(setActive()); - - const updatedHistory = getState().session.history; - const messageMode = getState().session.mode + const messageMode = getState().session.mode; + + const baseChatOrAgentSystemMessage = getBaseSystemMessage( + selectedChatModel, + messageMode, + ); - const baseChatOrAgentSystemMessage = getBaseSystemMessage(selectedChatModel, messageMode) - const messages = constructMessages( messageMode, [...updatedHistory], @@ -78,7 +74,8 @@ export const streamResponseAfterToolCall = createAsyncThunk< state.config.config.rules, ); - unwrapResult(await dispatch(streamNormalInput({ messages }))); + const result = await dispatch(streamNormalInput({ messages })); + unwrapResult(result); }), ); }, diff --git a/gui/src/redux/thunks/streamThunkWrapper.tsx b/gui/src/redux/thunks/streamThunkWrapper.tsx index 149782416..2a6eb99b0 100644 --- a/gui/src/redux/thunks/streamThunkWrapper.tsx +++ b/gui/src/redux/thunks/streamThunkWrapper.tsx @@ -1,6 +1,5 @@ import { createAsyncThunk } from "@reduxjs/toolkit"; import StreamErrorDialog from "../../pages/gui/StreamError"; -import { setInactive } from "../slices/sessionSlice"; import { setDialogMessage, setShowDialog } from "../slices/uiSlice"; import { ThunkApiType } from "../store"; import { cancelStream } from "./cancelStream"; @@ -22,7 +21,6 @@ export const streamThunkWrapper = createAsyncThunk< }), ); } - dispatch(setInactive()); } catch (e) { dispatch(cancelStream()); dispatch(setDialogMessage()); diff --git a/gui/src/util/clientTools/editImpl.ts b/gui/src/util/clientTools/editImpl.ts index 29aa5466c..ecb1ea11f 100644 --- a/gui/src/util/clientTools/editImpl.ts +++ b/gui/src/util/clientTools/editImpl.ts @@ -35,10 +35,6 @@ export const editToolImpl: ClientToolImpl = async ( if (out.status === "error") { throw new Error(out.error); } - return { - respondImmediately: true, - output: undefined, // TODO - feed edit results back to model (also in parallel listeners) - }; } return { respondImmediately: false, From 2cba8b9d8ed2db4bcc08e98ae8f35da1f0e0a770 Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Tue, 27 May 2025 12:46:03 -0700 Subject: [PATCH 03/44] cleanup --- gui/src/redux/thunks/streamResponseAfterToolCall.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/gui/src/redux/thunks/streamResponseAfterToolCall.ts b/gui/src/redux/thunks/streamResponseAfterToolCall.ts index 25ce6e8c5..6ccd35c6f 100644 --- a/gui/src/redux/thunks/streamResponseAfterToolCall.ts +++ b/gui/src/redux/thunks/streamResponseAfterToolCall.ts @@ -74,8 +74,7 @@ export const streamResponseAfterToolCall = createAsyncThunk< state.config.config.rules, ); - const result = await dispatch(streamNormalInput({ messages })); - unwrapResult(result); + unwrapResult(await dispatch(streamNormalInput({ messages }))); }), ); }, From dd353c657166bc37f35b6c06e1b7144e672e6fc4 Mon Sep 17 00:00:00 2001 From: uinstinct <61635505+uinstinct@users.noreply.github.com> Date: Fri, 6 Jun 2025 12:11:09 +0530 Subject: [PATCH 04/44] speedup binary build - 70s to 20s --- binary/build.js | 174 ++++++++++------------------------ binary/utils/bundle-binary.js | 77 +++++++++++++++ binary/utils/copy-lancedb.js | 82 ++++++++++++++++ 3 files changed, 209 insertions(+), 124 deletions(-) create mode 100644 binary/utils/bundle-binary.js create mode 100644 binary/utils/copy-lancedb.js diff --git a/binary/build.js b/binary/build.js index b67afb94f..713ed6dc0 100644 --- a/binary/build.js +++ b/binary/build.js @@ -3,13 +3,10 @@ const fs = require("fs"); const path = require("path"); const ncp = require("ncp").ncp; const { rimrafSync } = require("rimraf"); -const { - validateFilesPresent, - execCmdSync, - autodetectPlatformAndArch, -} = require("../scripts/util"); +const { validateFilesPresent } = require("../scripts/util"); const { downloadRipgrep } = require("./utils/ripgrep"); const { ALL_TARGETS, TARGET_TO_LANCEDB } = require("./utils/targets"); +const { fork } = require("child_process"); const bin = path.join(__dirname, "bin"); const out = path.join(__dirname, "out"); @@ -29,8 +26,6 @@ function cleanSlate() { const esbuildOutputFile = "out/index.js"; let targets = [...ALL_TARGETS]; -const [currentPlatform, currentArch] = autodetectPlatformAndArch(); - const assetBackups = [ "node_modules/win-ca/lib/crypt32-ia32.node.bak", "node_modules/win-ca/lib/crypt32-x64.node.bak", @@ -78,67 +73,6 @@ async function buildWithEsbuild() { }); } -async function installNodeModuleInTempDirAndCopyToCurrent(packageName, toCopy) { - console.log(`Copying ${packageName} to ${toCopy}`); - // This is a way to install only one package without npm trying to install all the dependencies - // Create a temporary directory for installing the package - const adjustedName = packageName.replace(/@/g, "").replace("/", "-"); - const tempDir = path.join( - __dirname, - "tmp", - `continue-node_modules-${adjustedName}`, - ); - const currentDir = process.cwd(); - - // // Remove the dir we will be copying to - // rimrafSync(`node_modules/${toCopy}`); - - // // Ensure the temporary directory exists - fs.mkdirSync(tempDir, { recursive: true }); - - try { - // Move to the temporary directory - process.chdir(tempDir); - - // Initialize a new package.json and install the package - execCmdSync(`npm init -y && npm i -f ${packageName} --no-save`); - - console.log( - `Contents of: ${packageName}`, - fs.readdirSync(path.join(tempDir, "node_modules", toCopy)), - ); - - // Without this it seems the file isn't completely written to disk - await new Promise((resolve) => setTimeout(resolve, 2000)); - - // Copy the installed package back to the current directory - await new Promise((resolve, reject) => { - ncp( - path.join(tempDir, "node_modules", toCopy), - path.join(currentDir, "node_modules", toCopy), - { dereference: true }, - (error) => { - if (error) { - console.error( - `[error] Error copying ${packageName} package`, - error, - ); - reject(error); - } else { - resolve(); - } - }, - ); - }); - } finally { - // Clean up the temporary directory - // rimrafSync(tempDir); - - // Return to the original directory - process.chdir(currentDir); - } -} - /** * Downloads and installs ripgrep binaries for the specified target * @@ -181,16 +115,35 @@ async function downloadRipgrepForTarget(target, targetDir) { ), ); - console.log("[info] Downloading prebuilt lancedb..."); + const copyLanceDBPromises = []; for (const target of targets) { - if (TARGET_TO_LANCEDB[target]) { - console.log(`[info] Downloading for ${target}...`); - await installNodeModuleInTempDirAndCopyToCurrent( - TARGET_TO_LANCEDB[target], - "@lancedb", - ); + if (!TARGET_TO_LANCEDB[target]) { + continue; } + console.log(`[info] Downloading for ${target}...`); + const child = fork("./utils/copy-lancedb.js", { stdio: "inherit" }); + child.send({ + payload: { + packageName: TARGET_TO_LANCEDB[target], + toCopy: "@lancedb", + }, + }); + copyLanceDBPromises.push( + new Promise((resolve, reject) => { + child.on("message", (msg) => { + if (msg.error) { + reject(); + } + resolve(); + }); + }), + ); } + await Promise.all(copyLanceDBPromises).catch(() => { + console.error("[error] Failed to copy LanceDB"); + process.exit(1); + }); + console.log("[info] Copied all LanceDB"); // tree-sitter-wasm const treeSitterWasmsDir = path.join(out, "tree-sitter-wasms"); @@ -252,59 +205,31 @@ async function downloadRipgrepForTarget(target, targetDir) { "out/llamaTokenizerWorkerPool.mjs", ); + const buildBinaryPromises = []; console.log("[info] Building binaries with pkg..."); for (const target of targets) { - const targetDir = `bin/${target}`; - fs.mkdirSync(targetDir, { recursive: true }); - console.log(`[info] Building ${target}...`); - execCmdSync( - `npx pkg --no-bytecode --public-packages "*" --public --compress GZip pkgJson/${target} --out-path ${targetDir}`, + const child = fork("./utils/bundle-binary.js", { stdio: "inherit" }); + child.send({ + payload: { + target, + }, + }); + buildBinaryPromises.push( + new Promise((resolve, reject) => { + child.on("message", (msg) => { + if (msg.error) { + reject(); + } + resolve(); + }); + }), ); - - // Download and unzip prebuilt sqlite3 binary for the target - console.log("[info] Downloading node-sqlite3"); - - const downloadUrl = - // node-sqlite3 doesn't have a pre-built binary for win32-arm64 - target === "win32-arm64" - ? "https://continue-server-binaries.s3.us-west-1.amazonaws.com/win32-arm64/node_sqlite3.tar.gz" - : `https://github.com/TryGhost/node-sqlite3/releases/download/v5.1.7/sqlite3-v5.1.7-napi-v6-${ - target - }.tar.gz`; - - execCmdSync(`curl -L -o ${targetDir}/build.tar.gz ${downloadUrl}`); - execCmdSync(`cd ${targetDir} && tar -xvzf build.tar.gz`); - - // Copy to build directory for testing - try { - const [platform, arch] = target.split("-"); - if (platform === currentPlatform && arch === currentArch) { - fs.copyFileSync( - `${targetDir}/build/Release/node_sqlite3.node`, - `build/node_sqlite3.node`, - ); - } - } catch (error) { - console.log("[warn] Could not copy node_sqlite to build"); - console.log(error); - } - - fs.unlinkSync(`${targetDir}/build.tar.gz`); - - // copy @lancedb to bin folders - console.log("[info] Copying @lancedb files to bin"); - fs.copyFileSync( - `node_modules/${TARGET_TO_LANCEDB[target]}/index.node`, - `${targetDir}/index.node`, - ); - - // Download and install ripgrep for the target - await downloadRipgrepForTarget(target, targetDir); - - // Informs the `continue-binary` of where to look for node_sqlite3.node - // https://www.npmjs.com/package/bindings#:~:text=The%20searching%20for,file%20is%20found - fs.writeFileSync(`${targetDir}/package.json`, ""); } + await Promise.all(buildBinaryPromises).catch(() => { + console.error("[error] Failed to build binaries"); + process.exit(1); + }); + console.log("[info] All binaries built"); // Cleanup - this is needed when running locally fs.rmSync("out/package.json"); @@ -331,4 +256,5 @@ async function downloadRipgrepForTarget(target, targetDir) { validateFilesPresent(pathsToVerify); console.log("[info] Done!"); + process.exit(0); })(); diff --git a/binary/utils/bundle-binary.js b/binary/utils/bundle-binary.js new file mode 100644 index 000000000..a9ff0ead7 --- /dev/null +++ b/binary/utils/bundle-binary.js @@ -0,0 +1,77 @@ +/** + * @file Builds the binary for the specified target. It is intended to run as a child process. + */ +const { + execCmdSync, + autodetectPlatformAndArch, +} = require("../../scripts/util"); +const { downloadRipgrep } = require("./ripgrep"); +const { TARGET_TO_LANCEDB } = require("../utils/targets"); +const fs = require("fs"); + +/** + * @param {string} target the platform to build for + */ +async function bundleForBinary(target) { + const [currentPlatform, currentArch] = autodetectPlatformAndArch(); + + const targetDir = `bin/${target}`; + fs.mkdirSync(targetDir, { recursive: true }); + console.log(`[info] Building ${target}...`); + execCmdSync( + `npx pkg --no-bytecode --public-packages "*" --public --compress GZip pkgJson/${target} --out-path ${targetDir}`, + ); + + // Download and unzip prebuilt sqlite3 binary for the target + console.log("[info] Downloading node-sqlite3"); + + const downloadUrl = + // node-sqlite3 doesn't have a pre-built binary for win32-arm64 + target === "win32-arm64" + ? "https://continue-server-binaries.s3.us-west-1.amazonaws.com/win32-arm64/node_sqlite3.tar.gz" + : `https://github.com/TryGhost/node-sqlite3/releases/download/v5.1.7/sqlite3-v5.1.7-napi-v6-${ + target + }.tar.gz`; + + execCmdSync(`curl -L -o ${targetDir}/build.tar.gz ${downloadUrl}`); + execCmdSync(`cd ${targetDir} && tar -xvzf build.tar.gz`); + + // Copy to build directory for testing + try { + const [platform, arch] = target.split("-"); + if (platform === currentPlatform && arch === currentArch) { + fs.copyFileSync( + `${targetDir}/build/Release/node_sqlite3.node`, + `build/node_sqlite3.node`, + ); + } + } catch (error) { + console.log("[warn] Could not copy node_sqlite to build"); + console.log(error); + } + + fs.unlinkSync(`${targetDir}/build.tar.gz`); + + // copy @lancedb to bin folders + console.log("[info] Copying @lancedb files to bin"); + fs.copyFileSync( + `node_modules/${TARGET_TO_LANCEDB[target]}/index.node`, + `${targetDir}/index.node`, + ); + + // Download and install ripgrep for the target + await downloadRipgrep(target, targetDir); + + // Informs the `continue-binary` of where to look for node_sqlite3.node + // https://www.npmjs.com/package/bindings#:~:text=The%20searching%20for,file%20is%20found + fs.writeFileSync(`${targetDir}/package.json`, ""); +} + +process.on("message", (msg) => { + bundleForBinary(msg.payload.target) + .then(() => process.send({ done: true })) + .catch((error) => { + console.error(error); // show the error in the parent process + process.send({ error: true }); + }); +}); diff --git a/binary/utils/copy-lancedb.js b/binary/utils/copy-lancedb.js new file mode 100644 index 000000000..75c728020 --- /dev/null +++ b/binary/utils/copy-lancedb.js @@ -0,0 +1,82 @@ +/** + * @file Copy lancedb to the current directory. It is intended to run as a child process. + */ + +const fs = require("fs"); +const path = require("path"); +const ncp = require("ncp").ncp; +const { execCmdSync } = require("../../scripts/util"); + +async function installNodeModuleInTempDirAndCopyToCurrent(packageName, toCopy) { + console.log(`Copying ${packageName} to ${toCopy}`); + // This is a way to install only one package without npm trying to install all the dependencies + // Create a temporary directory for installing the package + const adjustedName = packageName.replace(/@/g, "").replace("/", "-"); + const tempDir = path.join( + __dirname, + "..", + "tmp", + `continue-node_modules-${adjustedName}`, + ); + const currentDir = process.cwd(); + + // // Remove the dir we will be copying to + // rimrafSync(`node_modules/${toCopy}`); + + // // Ensure the temporary directory exists + fs.mkdirSync(tempDir, { recursive: true }); + + try { + // Move to the temporary directory + process.chdir(tempDir); + + // Initialize a new package.json and install the package + execCmdSync(`npm init -y && npm i -f ${packageName} --no-save`); + + console.log( + `Contents of: ${packageName}`, + fs.readdirSync(path.join(tempDir, "node_modules", toCopy)), + ); + + // Without this it seems the file isn't completely written to disk + await new Promise((resolve) => setTimeout(resolve, 2000)); + + // Copy the installed package back to the current directory + await new Promise((resolve, reject) => { + ncp( + path.join(tempDir, "node_modules", toCopy), + path.join(currentDir, "node_modules", toCopy), + { dereference: true }, + (error) => { + if (error) { + console.error( + `[error] Error copying ${packageName} package`, + error, + ); + reject(error); + } else { + resolve(); + } + }, + ); + }); + } finally { + // Clean up the temporary directory + // rimrafSync(tempDir); + + // Return to the original directory + process.chdir(currentDir); + } +} + +process.on("message", (msg) => { + installNodeModuleInTempDirAndCopyToCurrent( + msg.payload.packageName, + msg.payload.toCopy, + ) + .then(() => process.send({ done: true })) + .catch((error) => { + console.error(error); // show the error in the parent process + process.send({ error: true }); + }); +}); From be9b32984c42d85b403aa7e7f5ce58bd19b37859 Mon Sep 17 00:00:00 2001 From: uinstinct <61635505+uinstinct@users.noreply.github.com> Date: Fri, 6 Jun 2025 12:29:40 +0530 Subject: [PATCH 05/44] parallel downloads for node-sqlite and ripgrep - reduction by 4 seconds --- binary/utils/bundle-binary.js | 74 +++++++++++++++++++---------------- 1 file changed, 40 insertions(+), 34 deletions(-) diff --git a/binary/utils/bundle-binary.js b/binary/utils/bundle-binary.js index a9ff0ead7..c218166cd 100644 --- a/binary/utils/bundle-binary.js +++ b/binary/utils/bundle-binary.js @@ -9,12 +9,46 @@ const { downloadRipgrep } = require("./ripgrep"); const { TARGET_TO_LANCEDB } = require("../utils/targets"); const fs = require("fs"); +async function downloadNodeSqlite(target, targetDir) { + return new Promise((resolve) => { + const [currentPlatform, currentArch] = autodetectPlatformAndArch(); + + // Download and unzip prebuilt sqlite3 binary for the target + console.log("[info] Downloading node-sqlite3"); + + const downloadUrl = + // node-sqlite3 doesn't have a pre-built binary for win32-arm64 + target === "win32-arm64" + ? "https://continue-server-binaries.s3.us-west-1.amazonaws.com/win32-arm64/node_sqlite3.tar.gz" + : `https://github.com/TryGhost/node-sqlite3/releases/download/v5.1.7/sqlite3-v5.1.7-napi-v6-${ + target + }.tar.gz`; + + execCmdSync(`curl -L -o ${targetDir}/build.tar.gz ${downloadUrl}`); + execCmdSync(`cd ${targetDir} && tar -xvzf build.tar.gz`); + + // Copy to build directory for testing + try { + const [platform, arch] = target.split("-"); + if (platform === currentPlatform && arch === currentArch) { + fs.copyFileSync( + `${targetDir}/build/Release/node_sqlite3.node`, + `build/node_sqlite3.node`, + ); + } + } catch (error) { + console.log("[warn] Could not copy node_sqlite to build"); + console.log(error); + } + fs.unlinkSync(`${targetDir}/build.tar.gz`); + resolve(); + }); +} + /** * @param {string} target the platform to build for */ async function bundleForBinary(target) { - const [currentPlatform, currentArch] = autodetectPlatformAndArch(); - const targetDir = `bin/${target}`; fs.mkdirSync(targetDir, { recursive: true }); console.log(`[info] Building ${target}...`); @@ -22,36 +56,6 @@ async function bundleForBinary(target) { `npx pkg --no-bytecode --public-packages "*" --public --compress GZip pkgJson/${target} --out-path ${targetDir}`, ); - // Download and unzip prebuilt sqlite3 binary for the target - console.log("[info] Downloading node-sqlite3"); - - const downloadUrl = - // node-sqlite3 doesn't have a pre-built binary for win32-arm64 - target === "win32-arm64" - ? "https://continue-server-binaries.s3.us-west-1.amazonaws.com/win32-arm64/node_sqlite3.tar.gz" - : `https://github.com/TryGhost/node-sqlite3/releases/download/v5.1.7/sqlite3-v5.1.7-napi-v6-${ - target - }.tar.gz`; - - execCmdSync(`curl -L -o ${targetDir}/build.tar.gz ${downloadUrl}`); - execCmdSync(`cd ${targetDir} && tar -xvzf build.tar.gz`); - - // Copy to build directory for testing - try { - const [platform, arch] = target.split("-"); - if (platform === currentPlatform && arch === currentArch) { - fs.copyFileSync( - `${targetDir}/build/Release/node_sqlite3.node`, - `build/node_sqlite3.node`, - ); - } - } catch (error) { - console.log("[warn] Could not copy node_sqlite to build"); - console.log(error); - } - - fs.unlinkSync(`${targetDir}/build.tar.gz`); - // copy @lancedb to bin folders console.log("[info] Copying @lancedb files to bin"); fs.copyFileSync( @@ -59,8 +63,10 @@ async function bundleForBinary(target) { `${targetDir}/index.node`, ); - // Download and install ripgrep for the target - await downloadRipgrep(target, targetDir); + const downloadPromises = []; + downloadPromises.push(downloadRipgrep(target, targetDir)); + downloadPromises.push(downloadNodeSqlite(target, targetDir)); + await Promise.all(downloadPromises); // Informs the `continue-binary` of where to look for node_sqlite3.node // https://www.npmjs.com/package/bindings#:~:text=The%20searching%20for,file%20is%20found From 8194ec700c0850cd8cbf61ab520da5d1cec96a1d Mon Sep 17 00:00:00 2001 From: uinstinct <61635505+uinstinct@users.noreply.github.com> Date: Fri, 6 Jun 2025 18:46:21 +0530 Subject: [PATCH 06/44] parallel npm installation of vscode and gui --- .../vscode/scripts/install-nodemodules.js | 41 +++++++++++++++ extensions/vscode/scripts/prepackage.js | 19 ++++--- extensions/vscode/scripts/utils.js | 50 ++++++++++++++----- 3 files changed, 87 insertions(+), 23 deletions(-) create mode 100644 extensions/vscode/scripts/install-nodemodules.js diff --git a/extensions/vscode/scripts/install-nodemodules.js b/extensions/vscode/scripts/install-nodemodules.js new file mode 100644 index 000000000..eb71f7223 --- /dev/null +++ b/extensions/vscode/scripts/install-nodemodules.js @@ -0,0 +1,41 @@ +/** + * @file Install node modules for the VS Code extension. This is intended to run as a child process. + */ + +const path = require("path"); + +const { execCmdSync } = require("../../../scripts/util"); + +/** + * @param {string} continueDir + */ +async function installNodeModulesInGui(continueDir) { + process.chdir(path.join(continueDir, "gui")); + execCmdSync("npm install"); + console.log("[info] npm install in gui completed"); +} + +async function installNodeModulesInVscode(continueDir) { + process.chdir(path.join(continueDir, "extensions", "vscode")); + execCmdSync("npm install"); + console.log("[info] npm install in extensions/vscode completed"); +} + +process.on("message", (msg) => { + const { continueDir, targetDir } = msg.payload; + if (targetDir === "gui") { + installNodeModulesInGui(continueDir) + .then(() => process.send({ done: true })) + .catch((error) => { + console.error(error); // show the error in the parent process + process.send({ error: true }); + }); + } else if (targetDir === "vscode") { + installNodeModulesInVscode(continueDir) + .then(() => process.send({ done: true })) + .catch((error) => { + console.error(error); // show the error in the parent process + process.send({ error: true }); + }); + } +}); diff --git a/extensions/vscode/scripts/prepackage.js b/extensions/vscode/scripts/prepackage.js index 01ef446c5..bda7833f6 100644 --- a/extensions/vscode/scripts/prepackage.js +++ b/extensions/vscode/scripts/prepackage.js @@ -14,6 +14,7 @@ const { copyConfigSchema, writeBuildTimestamp, generateConfigYamlSchema, + installNodeModules, } = require("./utils"); // Clear folders that will be packaged to ensure clean slate @@ -36,10 +37,10 @@ if (args[2] === "--target") { let os; let arch; -if (!target) { - [os, arch] = autodetectPlatformAndArch(); -} else { +if (target) { [os, arch] = target.split("-"); +} else { + [os, arch] = autodetectPlatformAndArch(); } if (os === "alpine") { @@ -82,13 +83,9 @@ void (async () => { writeBuildTimestamp(); // Install node_modules // - execCmdSync("npm install"); - console.log("[info] npm install in extensions/vscode completed"); + await installNodeModules(); - process.chdir("../../gui"); - - execCmdSync("npm install"); - console.log("[info] npm install in gui completed"); + process.chdir(path.join("__dirname", "..", "..", "..", "gui")); if (isInGitHubAction) { execCmdSync("npm run build"); @@ -465,7 +462,7 @@ void (async () => { ); // delete esbuild/bin because platform-specific @esbuild is downloaded - fs.rmdirSync(`out/node_modules/esbuild/bin`, { recursive: true }); + fs.rmSync(`out/node_modules/esbuild/bin`, { recursive: true }); console.log(`[info] Copied ${NODE_MODULES_TO_COPY.join(", ")}`); @@ -534,4 +531,6 @@ void (async () => { `out/node_modules/@lancedb/vectordb-${target}${isWinTarget ? "-msvc" : ""}${isLinuxTarget ? "-gnu" : ""}/index.node`, `out/node_modules/esbuild/lib/main.js`, ]); + + process.exit(0); })(); diff --git a/extensions/vscode/scripts/utils.js b/extensions/vscode/scripts/utils.js index 451fde407..b0b4966b1 100644 --- a/extensions/vscode/scripts/utils.js +++ b/extensions/vscode/scripts/utils.js @@ -1,7 +1,10 @@ +const { fork } = require("child_process"); const fs = require("fs"); -const ncp = require("ncp").ncp; const path = require("path"); + +const ncp = require("ncp").ncp; const { rimrafSync } = require("rimraf"); + const { validateFilesPresent, execCmdSync, @@ -77,20 +80,41 @@ function copyTokenizers() { console.log("[info] Copied llamaTokenizer"); } -function installNodeModules() { - // Make sure we are in the right directory - if (!process.cwd().endsWith("vscode")) { - process.chdir(path.join(continueDir, "extensions", "vscode")); - } +async function installNodeModules() { + const installVscodeChild = fork( + path.join(__dirname, "install-nodemodules.js"), + { + stdio: "inherit", + }, + ); + installVscodeChild.send({ payload: { continueDir, targetDir: "vscode" } }); - // Install node_modules // - execCmdSync("npm install"); - console.log("[info] npm install in extensions/vscode completed"); + const installGuiChild = fork(path.join(__dirname, "install-nodemodules.js"), { + stdio: "inherit", + }); + installGuiChild.send({ payload: { continueDir, targetDir: "gui" } }); - process.chdir(path.join(continueDir, "gui")); - - execCmdSync("npm install"); - console.log("[info] npm install in gui completed"); + await Promise.all([ + new Promise((resolve, reject) => { + installVscodeChild.on("message", (msg) => { + if (msg.error) { + reject(); + } + resolve(); + }); + }), + new Promise((resolve, reject) => { + installGuiChild.on("message", (msg) => { + if (msg.error) { + reject(); + } + resolve(); + }); + }), + ]).catch((error) => { + console.error(error); + process.exit(1); + }); } async function buildGui(isGhAction) { From c0700e1634dd96cf5d1743f8d52557cd0d1ddadb Mon Sep 17 00:00:00 2001 From: uinstinct <61635505+uinstinct@users.noreply.github.com> Date: Fri, 6 Jun 2025 19:08:53 +0530 Subject: [PATCH 07/44] parallel config yaml generation copying and installing node modules --- .../vscode/scripts/generate-copy-config.js | 83 ++++++++++++++++++ .../vscode/scripts/install-nodemodules.js | 15 ++-- extensions/vscode/scripts/prepackage.js | 20 +---- extensions/vscode/scripts/utils.js | 87 ++++++++----------- 4 files changed, 130 insertions(+), 75 deletions(-) create mode 100644 extensions/vscode/scripts/generate-copy-config.js diff --git a/extensions/vscode/scripts/generate-copy-config.js b/extensions/vscode/scripts/generate-copy-config.js new file mode 100644 index 000000000..16d8e1df6 --- /dev/null +++ b/extensions/vscode/scripts/generate-copy-config.js @@ -0,0 +1,83 @@ +/** + * @file Generate config.yaml file from template. Intended to run as a child process. + */ + +const fs = require("fs"); +const path = require("path"); + +const { execCmdSync } = require("../../../scripts/util"); + +const { continueDir } = require("./utils"); + +async function generateConfigYamlSchema() { + process.chdir(path.join(continueDir, "packages", "config-yaml")); + execCmdSync("npm install"); + execCmdSync("npm run build"); + execCmdSync("npm run generate-schema"); + fs.copyFileSync( + path.join("schema", "config-yaml-schema.json"), + path.join(continueDir, "extensions", "vscode", "config-yaml-schema.json"), + ); + console.log("[info] Generated config.yaml schema"); +} + +async function copyConfigSchema() { + process.chdir(path.join(continueDir, "extensions", "vscode")); + // Modify and copy for .continuerc.json + const schema = JSON.parse(fs.readFileSync("config_schema.json", "utf8")); + schema.$defs.SerializedContinueConfig.properties.mergeBehavior = { + type: "string", + enum: ["merge", "overwrite"], + default: "merge", + title: "Merge behavior", + markdownDescription: + "If set to 'merge', .continuerc.json will be applied on top of config.json (arrays and objects are merged). If set to 'overwrite', then every top-level property of .continuerc.json will overwrite that property from config.json.", + "x-intellij-html-description": + "

If set to merge, .continuerc.json will be applied on top of config.json (arrays and objects are merged). If set to overwrite, then every top-level property of .continuerc.json will overwrite that property from config.json.

", + }; + fs.writeFileSync("continue_rc_schema.json", JSON.stringify(schema, null, 2)); + + // Copy config schemas to intellij + fs.copyFileSync( + "config_schema.json", + path.join( + "..", + "intellij", + "src", + "main", + "resources", + "config_schema.json", + ), + ); + fs.copyFileSync( + "continue_rc_schema.json", + path.join( + "..", + "intellij", + "src", + "main", + "resources", + "continue_rc_schema.json", + ), + ); +} + +process.on("message", (msg) => { + const { operation } = msg.payload; + if (operation === "generate") { + generateConfigYamlSchema() + .then(() => process.send({ done: true })) + .catch((error) => { + console.error(error); // show the error in the parent process + process.send({ error: true }); + }); + } + if (operation === "copy") { + copyConfigSchema() + .then(() => process.send({ done: true })) + .catch((error) => { + console.error(error); // show the error in the parent process + process.send({ error: true }); + }); + } +}); diff --git a/extensions/vscode/scripts/install-nodemodules.js b/extensions/vscode/scripts/install-nodemodules.js index eb71f7223..cae222b39 100644 --- a/extensions/vscode/scripts/install-nodemodules.js +++ b/extensions/vscode/scripts/install-nodemodules.js @@ -6,32 +6,31 @@ const path = require("path"); const { execCmdSync } = require("../../../scripts/util"); -/** - * @param {string} continueDir - */ -async function installNodeModulesInGui(continueDir) { +const { continueDir } = require("./utils"); + +async function installNodeModulesInGui() { process.chdir(path.join(continueDir, "gui")); execCmdSync("npm install"); console.log("[info] npm install in gui completed"); } -async function installNodeModulesInVscode(continueDir) { +async function installNodeModulesInVscode() { process.chdir(path.join(continueDir, "extensions", "vscode")); execCmdSync("npm install"); console.log("[info] npm install in extensions/vscode completed"); } process.on("message", (msg) => { - const { continueDir, targetDir } = msg.payload; + const { targetDir } = msg.payload; if (targetDir === "gui") { - installNodeModulesInGui(continueDir) + installNodeModulesInGui() .then(() => process.send({ done: true })) .catch((error) => { console.error(error); // show the error in the parent process process.send({ error: true }); }); } else if (targetDir === "vscode") { - installNodeModulesInVscode(continueDir) + installNodeModulesInVscode() .then(() => process.send({ done: true })) .catch((error) => { console.error(error); // show the error in the parent process diff --git a/extensions/vscode/scripts/prepackage.js b/extensions/vscode/scripts/prepackage.js index bda7833f6..e57059261 100644 --- a/extensions/vscode/scripts/prepackage.js +++ b/extensions/vscode/scripts/prepackage.js @@ -11,10 +11,10 @@ const { } = require("../../../scripts/util/index"); const { - copyConfigSchema, writeBuildTimestamp, - generateConfigYamlSchema, installNodeModules, + continueDir, + generateAndCopyConfigYamlSchema, } = require("./utils"); // Clear folders that will be packaged to ensure clean slate @@ -68,24 +68,12 @@ const isMacTarget = target?.startsWith("darwin"); void (async () => { console.log("[info] Packaging extension for target ", target); - // Generate and copy over config-yaml-schema.json - generateConfigYamlSchema(); - - // Copy config schemas to intellij - copyConfigSchema(); - - if (!process.cwd().endsWith("vscode")) { - // This is sometimes run from root dir instead (e.g. in VS Code tasks) - process.chdir("extensions/vscode"); - } - // Make sure we have an initial timestamp file writeBuildTimestamp(); - // Install node_modules // - await installNodeModules(); + await Promise.all([generateAndCopyConfigYamlSchema(), installNodeModules()]); - process.chdir(path.join("__dirname", "..", "..", "..", "gui")); + process.chdir(path.join(continueDir, "gui")); if (isInGitHubAction) { execCmdSync("npm run build"); diff --git a/extensions/vscode/scripts/utils.js b/extensions/vscode/scripts/utils.js index b0b4966b1..422e6370b 100644 --- a/extensions/vscode/scripts/utils.js +++ b/extensions/vscode/scripts/utils.js @@ -13,57 +13,42 @@ const { const continueDir = path.join(__dirname, "..", "..", ".."); -function generateConfigYamlSchema() { - process.chdir(path.join(continueDir, "packages", "config-yaml")); - execCmdSync("npm install"); - execCmdSync("npm run build"); - execCmdSync("npm run generate-schema"); - fs.copyFileSync( - path.join("schema", "config-yaml-schema.json"), - path.join(continueDir, "extensions", "vscode", "config-yaml-schema.json"), +async function generateAndCopyConfigYamlSchema() { + // Generate and copy over config-yaml-schema.json + const generateConfigYamlChild = fork( + path.join(__dirname, "generate-copy-config.js"), + { + stdio: "inherit", + }, ); - console.log("[info] Generated config.yaml schema"); -} + generateConfigYamlChild.send({ payload: { operation: "generate" } }); -function copyConfigSchema() { - process.chdir(path.join(continueDir, "extensions", "vscode")); - // Modify and copy for .continuerc.json - const schema = JSON.parse(fs.readFileSync("config_schema.json", "utf8")); - schema.$defs.SerializedContinueConfig.properties.mergeBehavior = { - type: "string", - enum: ["merge", "overwrite"], - default: "merge", - title: "Merge behavior", - markdownDescription: - "If set to 'merge', .continuerc.json will be applied on top of config.json (arrays and objects are merged). If set to 'overwrite', then every top-level property of .continuerc.json will overwrite that property from config.json.", - "x-intellij-html-description": - "

If set to merge, .continuerc.json will be applied on top of config.json (arrays and objects are merged). If set to overwrite, then every top-level property of .continuerc.json will overwrite that property from config.json.

", - }; - fs.writeFileSync("continue_rc_schema.json", JSON.stringify(schema, null, 2)); + await new Promise((resolve, reject) => { + generateConfigYamlChild.on("message", (msg) => { + if (msg.error) { + reject(); + } + resolve(); + }); + }); // Copy config schemas to intellij - fs.copyFileSync( - "config_schema.json", - path.join( - "..", - "intellij", - "src", - "main", - "resources", - "config_schema.json", - ), - ); - fs.copyFileSync( - "continue_rc_schema.json", - path.join( - "..", - "intellij", - "src", - "main", - "resources", - "continue_rc_schema.json", - ), + const copyConfigSchemaChild = fork( + path.join(__dirname, "generate-copy-config.js"), + { + stdio: "inherit", + }, ); + copyConfigSchemaChild.send({ payload: { operation: "copy" } }); + + await new Promise((resolve, reject) => { + copyConfigSchemaChild.on("message", (msg) => { + if (msg.error) { + reject(); + } + resolve(); + }); + }); } function copyTokenizers() { @@ -87,12 +72,12 @@ async function installNodeModules() { stdio: "inherit", }, ); - installVscodeChild.send({ payload: { continueDir, targetDir: "vscode" } }); + installVscodeChild.send({ payload: { targetDir: "vscode" } }); const installGuiChild = fork(path.join(__dirname, "install-nodemodules.js"), { stdio: "inherit", }); - installGuiChild.send({ payload: { continueDir, targetDir: "gui" } }); + installGuiChild.send({ payload: { targetDir: "gui" } }); await Promise.all([ new Promise((resolve, reject) => { @@ -560,14 +545,14 @@ async function copyScripts() { // in the build function writeBuildTimestamp() { fs.writeFileSync( - "src/.buildTimestamp.ts", + path.join(continueDir, "extensions/vscode", "src/.buildTimestamp.ts"), `export default "${new Date().toISOString()}";\n`, ); } module.exports = { - generateConfigYamlSchema, - copyConfigSchema, + continueDir, + generateAndCopyConfigYamlSchema, installNodeModules, buildGui, copyOnnxRuntimeFromNodeModules, From 112bdcb0ef0d068663271111cf47cbd34f30751a Mon Sep 17 00:00:00 2001 From: uinstinct <61635505+uinstinct@users.noreply.github.com> Date: Fri, 6 Jun 2025 20:29:00 +0530 Subject: [PATCH 08/44] move copy-lancedb to root scripts/util --- binary/build.js | 39 +++---------------- package.json | 1 + .../utils => scripts/util}/copy-lancedb.js | 36 +++++++++++++++-- 3 files changed, 38 insertions(+), 38 deletions(-) rename {binary/utils => scripts/util}/copy-lancedb.js (76%) diff --git a/binary/build.js b/binary/build.js index 713ed6dc0..c88ac82cc 100644 --- a/binary/build.js +++ b/binary/build.js @@ -4,9 +4,12 @@ const path = require("path"); const ncp = require("ncp").ncp; const { rimrafSync } = require("rimraf"); const { validateFilesPresent } = require("../scripts/util"); -const { downloadRipgrep } = require("./utils/ripgrep"); const { ALL_TARGETS, TARGET_TO_LANCEDB } = require("./utils/targets"); const { fork } = require("child_process"); +const { + copyLanceDBFilePath, + copyLanceDB, +} = require("../scripts/util/copy-lancedb"); const bin = path.join(__dirname, "bin"); const out = path.join(__dirname, "out"); @@ -73,24 +76,6 @@ async function buildWithEsbuild() { }); } -/** - * Downloads and installs ripgrep binaries for the specified target - * - * @param {string} target - Target platform-arch (e.g., 'darwin-x64') - * @param {string} targetDir - Directory to install ripgrep to - * @returns {Promise} - */ -async function downloadRipgrepForTarget(target, targetDir) { - console.log(`[info] Downloading ripgrep for ${target}...`); - try { - await downloadRipgrep(target, targetDir); - console.log(`[info] Successfully installed ripgrep for ${target}`); - } catch (error) { - console.error(`[error] Failed to download ripgrep for ${target}:`, error); - throw error; - } -} - (async () => { if (esbuildOnly) { await buildWithEsbuild(); @@ -121,22 +106,8 @@ async function downloadRipgrepForTarget(target, targetDir) { continue; } console.log(`[info] Downloading for ${target}...`); - const child = fork("./utils/copy-lancedb.js", { stdio: "inherit" }); - child.send({ - payload: { - packageName: TARGET_TO_LANCEDB[target], - toCopy: "@lancedb", - }, - }); copyLanceDBPromises.push( - new Promise((resolve, reject) => { - child.on("message", (msg) => { - if (msg.error) { - reject(); - } - resolve(); - }); - }), + copyLanceDB(TARGET_TO_LANCEDB[target], "@lancedb"), ); } await Promise.all(copyLanceDBPromises).catch(() => { diff --git a/package.json b/package.json index 79e522af1..9100ad0cd 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ "@typescript-eslint/parser": "^7.8.0", "concurrently": "^9.1.2", "eslint-plugin-import": "^2.29.1", + "ncp": "^2.0.0", "prettier": "^3.3.3", "prettier-plugin-tailwindcss": "^0.6.8", "typescript": "^5.6.3" diff --git a/binary/utils/copy-lancedb.js b/scripts/util/copy-lancedb.js similarity index 76% rename from binary/utils/copy-lancedb.js rename to scripts/util/copy-lancedb.js index 75c728020..dc520a483 100644 --- a/binary/utils/copy-lancedb.js +++ b/scripts/util/copy-lancedb.js @@ -5,20 +5,20 @@ const fs = require("fs"); const path = require("path"); const ncp = require("ncp").ncp; -const { execCmdSync } = require("../../scripts/util"); +const { execCmdSync } = require("."); +const { fork } = require("child_process"); async function installNodeModuleInTempDirAndCopyToCurrent(packageName, toCopy) { console.log(`Copying ${packageName} to ${toCopy}`); // This is a way to install only one package without npm trying to install all the dependencies // Create a temporary directory for installing the package const adjustedName = packageName.replace(/@/g, "").replace("/", "-"); + const currentDir = process.cwd(); const tempDir = path.join( - __dirname, - "..", + currentDir, "tmp", `continue-node_modules-${adjustedName}`, ); - const currentDir = process.cwd(); // // Remove the dir we will be copying to // rimrafSync(`node_modules/${toCopy}`); @@ -80,3 +80,31 @@ process.on("message", (msg) => { process.send({ error: true }); }); }); + +/** + * invoke a child process to install and copy lancedb into node modules + * @param {string} packageName the lancedb platform to install and copy + * @param {string} toCopy directory to copy into inside node modules + */ +async function copyLanceDB(packageName, toCopy) { + const child = fork(__filename, { stdio: "inherit", cwd: process.cwd() }); + child.send({ + payload: { + packageName, + toCopy, + }, + }); + + return new Promise((resolve, reject) => { + child.on("message", (msg) => { + if (msg.error) { + reject(); + } + resolve(); + }); + }); +} + +module.exports = { + copyLanceDB, +}; From 37139c9e11b1d2e9dfa81bf531cb2bc96e7fb975 Mon Sep 17 00:00:00 2001 From: uinstinct <61635505+uinstinct@users.noreply.github.com> Date: Fri, 6 Jun 2025 20:39:03 +0530 Subject: [PATCH 09/44] parallel node sqlite and esbuild downloads --- extensions/vscode/.gitignore | 1 + .../scripts/install-copy-sqlite-esbuild.js | 107 ++++++++++++++++++ extensions/vscode/scripts/prepackage.js | 103 ++--------------- 3 files changed, 116 insertions(+), 95 deletions(-) create mode 100644 extensions/vscode/scripts/install-copy-sqlite-esbuild.js diff --git a/extensions/vscode/.gitignore b/extensions/vscode/.gitignore index 3ba3940c3..8b752d1ad 100644 --- a/extensions/vscode/.gitignore +++ b/extensions/vscode/.gitignore @@ -9,6 +9,7 @@ src/client exe bin assets +tmp gui/** diff --git a/extensions/vscode/scripts/install-copy-sqlite-esbuild.js b/extensions/vscode/scripts/install-copy-sqlite-esbuild.js new file mode 100644 index 000000000..502001649 --- /dev/null +++ b/extensions/vscode/scripts/install-copy-sqlite-esbuild.js @@ -0,0 +1,107 @@ +const { fork, execSync } = require("child_process"); +const fs = require("fs"); + +const { rimrafSync } = require("rimraf"); + +const { execCmdSync } = require("../../../scripts/util"); + +async function installAndCopySqlite(target) { + // Replace the installed with pre-built + console.log("[info] Downloading pre-built sqlite3 binary"); + rimrafSync("../../core/node_modules/sqlite3/build"); + const downloadUrl = { + "darwin-arm64": + "https://github.com/TryGhost/node-sqlite3/releases/download/v5.1.7/sqlite3-v5.1.7-napi-v6-darwin-arm64.tar.gz", + "linux-arm64": + "https://github.com/TryGhost/node-sqlite3/releases/download/v5.1.7/sqlite3-v5.1.7-napi-v3-linux-arm64.tar.gz", + // node-sqlite3 doesn't have a pre-built binary for win32-arm64 + "win32-arm64": + "https://continue-server-binaries.s3.us-west-1.amazonaws.com/win32-arm64/node_sqlite3.tar.gz", + }[target]; + execCmdSync( + `curl -L -o ../../core/node_modules/sqlite3/build.tar.gz ${downloadUrl}`, + ); + execCmdSync("cd ../../core/node_modules/sqlite3 && tar -xvzf build.tar.gz"); + fs.unlinkSync("../../core/node_modules/sqlite3/build.tar.gz"); +} + +async function installAndCopyEsbuild(target) { + // Download and unzip esbuild + console.log("[info] Downloading pre-built esbuild binary"); + rimrafSync("node_modules/@esbuild"); + fs.mkdirSync("node_modules/@esbuild", { recursive: true }); + execCmdSync( + `curl -o node_modules/@esbuild/esbuild.zip https://continue-server-binaries.s3.us-west-1.amazonaws.com/${target}/esbuild.zip`, + ); + execCmdSync("cd node_modules/@esbuild && unzip esbuild.zip"); + fs.unlinkSync("node_modules/@esbuild/esbuild.zip"); +} + +process.on("message", (msg) => { + const { operation, target } = msg.payload; + if (operation === "sqlite") { + installAndCopySqlite(target) + .then(() => process.send({ done: true })) + .catch((error) => { + console.error(error); // show the error in the parent process + process.send({ error: true }); + }); + } + if (operation === "esbuild") { + installAndCopyEsbuild(target) + .then(() => process.send({ done: true })) + .catch((error) => { + console.error(error); // show the error in the parent process + process.send({ error: true }); + }); + } +}); + +/** + * @param {string} target the platform to build for + */ +async function copySqlite(target) { + const child = fork(__filename, { stdio: "inherit", cwd: process.cwd() }); + child.send({ + payload: { + operation: "sqlite", + target, + }, + }); + + return new Promise((resolve, reject) => { + child.on("message", (msg) => { + if (msg.error) { + reject(); + } + resolve(); + }); + }); +} + +/** + * @param {string} target the platform to build for + */ +async function copyEsbuild(target) { + const child = fork(__filename, { stdio: "inherit", cwd: process.cwd() }); + child.send({ + payload: { + operation: "esbuild", + target, + }, + }); + + return new Promise((resolve, reject) => { + child.on("message", (msg) => { + if (msg.error) { + reject(); + } + resolve(); + }); + }); +} + +module.exports = { + copySqlite, + copyEsbuild, +}; diff --git a/extensions/vscode/scripts/prepackage.js b/extensions/vscode/scripts/prepackage.js index e57059261..43fe574f0 100644 --- a/extensions/vscode/scripts/prepackage.js +++ b/extensions/vscode/scripts/prepackage.js @@ -4,12 +4,14 @@ const path = require("path"); const ncp = require("ncp").ncp; const { rimrafSync } = require("rimraf"); +const { copyLanceDB } = require("../../../scripts/util/copy-lancedb"); const { validateFilesPresent, execCmdSync, autodetectPlatformAndArch, } = require("../../../scripts/util/index"); +const { copySqlite, copyEsbuild } = require("./install-copy-sqlite-esbuild"); const { writeBuildTimestamp, installNodeModules, @@ -265,68 +267,6 @@ void (async () => { ); }); - async function installNodeModuleInTempDirAndCopyToCurrent( - packageName, - toCopy, - ) { - console.log(`Copying ${packageName} to ${toCopy}`); - // This is a way to install only one package without npm trying to install all the dependencies - // Create a temporary directory for installing the package - const adjustedName = packageName.replace(/@/g, "").replace("/", "-"); - - const tempDir = `/tmp/continue-node_modules-${adjustedName}`; - const currentDir = process.cwd(); - - // Remove the dir we will be copying to - rimrafSync(`node_modules/${toCopy}`); - - // Ensure the temporary directory exists - fs.mkdirSync(tempDir, { recursive: true }); - - try { - // Move to the temporary directory - process.chdir(tempDir); - - // Initialize a new package.json and install the package - execCmdSync(`npm init -y && npm i -f ${packageName} --no-save`); - - console.log( - `Contents of: ${packageName}`, - fs.readdirSync(path.join(tempDir, "node_modules", toCopy)), - ); - - // Without this it seems the file isn't completely written to disk - // Ideally we validate file integrity in the validation at the end - await new Promise((resolve) => setTimeout(resolve, 2000)); - - // Copy the installed package back to the current directory - await new Promise((resolve, reject) => { - ncp( - path.join(tempDir, "node_modules", toCopy), - path.join(currentDir, "node_modules", toCopy), - { dereference: true }, - (error) => { - if (error) { - console.error( - `[error] Error copying ${packageName} package`, - error, - ); - reject(error); - } else { - resolve(); - } - }, - ); - }); - } finally { - // Clean up the temporary directory - // rimrafSync(tempDir); - - // Return to the original directory - process.chdir(currentDir); - } - } - // GitHub Actions doesn't support ARM, so we need to download pre-saved binaries // 02/07/25 - the above comment is out of date, there is now support for ARM runners on GitHub Actions if (isArmTarget) { @@ -340,41 +280,14 @@ void (async () => { "[info] Downloading pre-built lancedb binary: " + packageToInstall, ); - await installNodeModuleInTempDirAndCopyToCurrent( - packageToInstall, - "@lancedb", - ); - - // Replace the installed with pre-built - console.log("[info] Downloading pre-built sqlite3 binary"); - rimrafSync("../../core/node_modules/sqlite3/build"); - const downloadUrl = { - "darwin-arm64": - "https://github.com/TryGhost/node-sqlite3/releases/download/v5.1.7/sqlite3-v5.1.7-napi-v6-darwin-arm64.tar.gz", - "linux-arm64": - "https://github.com/TryGhost/node-sqlite3/releases/download/v5.1.7/sqlite3-v5.1.7-napi-v3-linux-arm64.tar.gz", - // node-sqlite3 doesn't have a pre-built binary for win32-arm64 - "win32-arm64": - "https://continue-server-binaries.s3.us-west-1.amazonaws.com/win32-arm64/node_sqlite3.tar.gz", - }[target]; - execCmdSync( - `curl -L -o ../../core/node_modules/sqlite3/build.tar.gz ${downloadUrl}`, - ); - execCmdSync("cd ../../core/node_modules/sqlite3 && tar -xvzf build.tar.gz"); - fs.unlinkSync("../../core/node_modules/sqlite3/build.tar.gz"); - - // Download and unzip esbuild - console.log("[info] Downloading pre-built esbuild binary"); - rimrafSync("node_modules/@esbuild"); - fs.mkdirSync("node_modules/@esbuild", { recursive: true }); - execCmdSync( - `curl -o node_modules/@esbuild/esbuild.zip https://continue-server-binaries.s3.us-west-1.amazonaws.com/${target}/esbuild.zip`, - ); - execCmdSync(`cd node_modules/@esbuild && unzip esbuild.zip`); - fs.unlinkSync("node_modules/@esbuild/esbuild.zip"); + await Promise.all([ + copyLanceDB(packageToInstall, "@lancedb"), + copySqlite(target), + copyEsbuild(target), + ]); } else { // Download esbuild from npm in tmp and copy over - console.log("npm installing esbuild binary"); + console.log("[info] npm installing esbuild binary"); await installNodeModuleInTempDirAndCopyToCurrent( "esbuild@0.17.19", "@esbuild", From e98307aafa83e62c07d49ce0c6abffbff3f9fc33 Mon Sep 17 00:00:00 2001 From: uinstinct <61635505+uinstinct@users.noreply.github.com> Date: Fri, 6 Jun 2025 21:08:33 +0530 Subject: [PATCH 10/44] download using node https over curl --- .../scripts/install-copy-sqlite-esbuild.js | 85 ++++++++++++++++++- extensions/vscode/scripts/prepackage.js | 4 +- 2 files changed, 83 insertions(+), 6 deletions(-) diff --git a/extensions/vscode/scripts/install-copy-sqlite-esbuild.js b/extensions/vscode/scripts/install-copy-sqlite-esbuild.js index 502001649..370876c7f 100644 --- a/extensions/vscode/scripts/install-copy-sqlite-esbuild.js +++ b/extensions/vscode/scripts/install-copy-sqlite-esbuild.js @@ -1,10 +1,85 @@ const { fork, execSync } = require("child_process"); const fs = require("fs"); +const https = require("https"); +const path = require("path"); const { rimrafSync } = require("rimraf"); const { execCmdSync } = require("../../../scripts/util"); +/** + * download a file using nodejs http + * @param {string} url + * @param {string} outputPath + * @param {number} maxRedirects + */ +async function downloadFile(url, outputPath, maxRedirects = 5) { + return new Promise((resolve, reject) => { + const downloadWithRedirects = (currentUrl, redirectCount = 0) => { + if (redirectCount > maxRedirects) { + return reject(new Error(`Too many redirects (${maxRedirects})`)); + } + + const request = https.get(currentUrl, (response) => { + if ( + response.statusCode >= 300 && + response.statusCode < 400 && + response.headers.location + ) { + return downloadWithRedirects( + response.headers.location, + redirectCount + 1, + ); + } + + if (response.statusCode !== 200) { + return reject( + new Error(`HTTP ${response.statusCode}: ${response.statusMessage}`), + ); + } + + const outputDir = path.dirname(outputPath); + if (!fs.existsSync(outputDir)) { + fs.mkdirSync(outputDir, { recursive: true }); + } + + const writeStream = fs.createWriteStream(outputPath); + + const totalSize = parseInt(response.headers["content-length"], 10); + let downloadedSize = 0; + + response.on("data", (chunk) => { + downloadedSize += chunk.length; + if (totalSize) { + const percent = ((downloadedSize / totalSize) * 100).toFixed(1); + process.stdout.write( + `\rDownloading: ${percent}% (${downloadedSize}/${totalSize} bytes)`, + ); + } + }); + + response.pipe(writeStream); + + writeStream.on("finish", () => { + console.log(`\nDownload completed: ${outputPath}`); + resolve(outputPath); + }); + + writeStream.on("error", reject); + response.on("error", reject); + }); + + request.on("error", reject); + request.setTimeout(30000, () => { + request.destroy(); + reject(new Error("Request timeout")); + }); + }; + + downloadWithRedirects(url); + }); +} + async function installAndCopySqlite(target) { // Replace the installed with pre-built console.log("[info] Downloading pre-built sqlite3 binary"); @@ -18,8 +93,9 @@ async function installAndCopySqlite(target) { "win32-arm64": "https://continue-server-binaries.s3.us-west-1.amazonaws.com/win32-arm64/node_sqlite3.tar.gz", }[target]; - execCmdSync( - `curl -L -o ../../core/node_modules/sqlite3/build.tar.gz ${downloadUrl}`, + await downloadFile( + downloadUrl, + "../../core/node_modules/sqlite3/build.tar.gz", ); execCmdSync("cd ../../core/node_modules/sqlite3 && tar -xvzf build.tar.gz"); fs.unlinkSync("../../core/node_modules/sqlite3/build.tar.gz"); @@ -30,8 +106,9 @@ async function installAndCopyEsbuild(target) { console.log("[info] Downloading pre-built esbuild binary"); rimrafSync("node_modules/@esbuild"); fs.mkdirSync("node_modules/@esbuild", { recursive: true }); - execCmdSync( - `curl -o node_modules/@esbuild/esbuild.zip https://continue-server-binaries.s3.us-west-1.amazonaws.com/${target}/esbuild.zip`, + await downloadFile( + `https://continue-server-binaries.s3.us-west-1.amazonaws.com/${target}/esbuild.zip`, + "node_modules/@esbuild/esbuild.zip", ); execCmdSync("cd node_modules/@esbuild && unzip esbuild.zip"); fs.unlinkSync("node_modules/@esbuild/esbuild.zip"); diff --git a/extensions/vscode/scripts/prepackage.js b/extensions/vscode/scripts/prepackage.js index 43fe574f0..6e72270e7 100644 --- a/extensions/vscode/scripts/prepackage.js +++ b/extensions/vscode/scripts/prepackage.js @@ -281,9 +281,9 @@ void (async () => { ); await Promise.all([ - copyLanceDB(packageToInstall, "@lancedb"), - copySqlite(target), copyEsbuild(target), + copySqlite(target), + copyLanceDB(packageToInstall, "@lancedb"), ]); } else { // Download esbuild from npm in tmp and copy over From 8d48cefc2e8fbd5cd011da4160a76b873875b88a Mon Sep 17 00:00:00 2001 From: uinstinct <61635505+uinstinct@users.noreply.github.com> Date: Fri, 6 Jun 2025 21:20:16 +0530 Subject: [PATCH 11/44] correct to copy-nodemodule.js --- binary/build.js | 7 ++----- extensions/vscode/scripts/prepackage.js | 9 +++------ scripts/util/{copy-lancedb.js => copy-nodemodule.js} | 8 ++++---- 3 files changed, 9 insertions(+), 15 deletions(-) rename scripts/util/{copy-lancedb.js => copy-nodemodule.js} (92%) diff --git a/binary/build.js b/binary/build.js index c88ac82cc..aa5fa5ffd 100644 --- a/binary/build.js +++ b/binary/build.js @@ -6,10 +6,7 @@ const { rimrafSync } = require("rimraf"); const { validateFilesPresent } = require("../scripts/util"); const { ALL_TARGETS, TARGET_TO_LANCEDB } = require("./utils/targets"); const { fork } = require("child_process"); -const { - copyLanceDBFilePath, - copyLanceDB, -} = require("../scripts/util/copy-lancedb"); +const { copyNodeModule } = require("../scripts/util/copy-nodemodule"); const bin = path.join(__dirname, "bin"); const out = path.join(__dirname, "out"); @@ -107,7 +104,7 @@ async function buildWithEsbuild() { } console.log(`[info] Downloading for ${target}...`); copyLanceDBPromises.push( - copyLanceDB(TARGET_TO_LANCEDB[target], "@lancedb"), + copyNodeModule(TARGET_TO_LANCEDB[target], "@lancedb"), ); } await Promise.all(copyLanceDBPromises).catch(() => { diff --git a/extensions/vscode/scripts/prepackage.js b/extensions/vscode/scripts/prepackage.js index 6e72270e7..ece5d91e5 100644 --- a/extensions/vscode/scripts/prepackage.js +++ b/extensions/vscode/scripts/prepackage.js @@ -4,7 +4,7 @@ const path = require("path"); const ncp = require("ncp").ncp; const { rimrafSync } = require("rimraf"); -const { copyLanceDB } = require("../../../scripts/util/copy-lancedb"); +const { copyNodeModule } = require("../../../scripts/util/copy-nodemodule"); const { validateFilesPresent, execCmdSync, @@ -283,15 +283,12 @@ void (async () => { await Promise.all([ copyEsbuild(target), copySqlite(target), - copyLanceDB(packageToInstall, "@lancedb"), + copyNodeModule(packageToInstall, "@lancedb"), ]); } else { // Download esbuild from npm in tmp and copy over console.log("[info] npm installing esbuild binary"); - await installNodeModuleInTempDirAndCopyToCurrent( - "esbuild@0.17.19", - "@esbuild", - ); + await copyNodeModule("esbuild@0.17.19", "@esbuild"); } console.log("[info] Copying sqlite node binding from core"); diff --git a/scripts/util/copy-lancedb.js b/scripts/util/copy-nodemodule.js similarity index 92% rename from scripts/util/copy-lancedb.js rename to scripts/util/copy-nodemodule.js index dc520a483..361e2d891 100644 --- a/scripts/util/copy-lancedb.js +++ b/scripts/util/copy-nodemodule.js @@ -82,11 +82,11 @@ process.on("message", (msg) => { }); /** - * invoke a child process to install and copy lancedb into node modules - * @param {string} packageName the lancedb platform to install and copy + * invoke a child process to install a node module into temporary directory and copy it over into node modules + * @param {string} packageName the module to install and copy * @param {string} toCopy directory to copy into inside node modules */ -async function copyLanceDB(packageName, toCopy) { +async function copyNodeModule(packageName, toCopy) { const child = fork(__filename, { stdio: "inherit", cwd: process.cwd() }); child.send({ payload: { @@ -106,5 +106,5 @@ async function copyLanceDB(packageName, toCopy) { } module.exports = { - copyLanceDB, + copyNodeModule, }; From cc21abf6c236906e475efb27e79a462366d47022 Mon Sep 17 00:00:00 2001 From: uinstinct <61635505+uinstinct@users.noreply.github.com> Date: Fri, 6 Jun 2025 21:27:21 +0530 Subject: [PATCH 12/44] update root package-lock --- package-lock.json | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/package-lock.json b/package-lock.json index 06f811afa..43530562e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,6 +8,7 @@ "@typescript-eslint/parser": "^7.8.0", "concurrently": "^9.1.2", "eslint-plugin-import": "^2.29.1", + "ncp": "^2.0.0", "prettier": "^3.3.3", "prettier-plugin-tailwindcss": "^0.6.8", "typescript": "^5.6.3" @@ -2233,6 +2234,16 @@ "dev": true, "peer": true }, + "node_modules/ncp": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ncp/-/ncp-2.0.0.tgz", + "integrity": "sha512-zIdGUrPRFTUELUvr3Gmc7KZ2Sw/h1PiVM0Af/oHB6zgnV1ikqSfRk+TOufi79aHYCW3NiOXmr1BP5nWbzojLaA==", + "dev": true, + "license": "MIT", + "bin": { + "ncp": "bin/ncp" + } + }, "node_modules/object-inspect": { "version": "1.13.2", "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.2.tgz", From 6ca088fdae20e63559cbd377f4ea51b4ccc7dd58 Mon Sep 17 00:00:00 2001 From: uinstinct <61635505+uinstinct@users.noreply.github.com> Date: Fri, 6 Jun 2025 21:30:10 +0530 Subject: [PATCH 13/44] change hash to rebuild root node modules --- .github/workflows/pr_checks.yaml | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/.github/workflows/pr_checks.yaml b/.github/workflows/pr_checks.yaml index 25a1b9a1e..a61958dea 100644 --- a/.github/workflows/pr_checks.yaml +++ b/.github/workflows/pr_checks.yaml @@ -24,7 +24,7 @@ jobs: id: root-cache with: path: node_modules - key: ${{ runner.os }}-root-node-modules-${{ hashFiles('package-lock.json') }} + key: ${{ runner.os }}-root-node-modules-${{ hashFiles('package-lock.json') }}-2 - name: Install root dependencies if: steps.root-cache.outputs.cache-hit != 'true' @@ -43,7 +43,7 @@ jobs: - uses: actions/cache@v4 with: path: node_modules - key: ${{ runner.os }}-root-node-modules-${{ hashFiles('package-lock.json') }} + key: ${{ runner.os }}-root-node-modules-${{ hashFiles('package-lock.json') }}-2 - name: Check code formatting with Prettier run: npx prettier --check "**/*.{js,jsx,ts,tsx,json,css,md}" --ignore-path .gitignore --ignore-path .prettierignore @@ -61,7 +61,7 @@ jobs: - uses: actions/cache@v4 with: path: node_modules - key: ${{ runner.os }}-root-node-modules-${{ hashFiles('package-lock.json') }} + key: ${{ runner.os }}-root-node-modules-${{ hashFiles('package-lock.json') }}-2 - uses: actions/cache@v4 id: config-yaml-cache @@ -88,7 +88,7 @@ jobs: - uses: actions/cache@v4 with: path: node_modules - key: ${{ runner.os }}-root-node-modules-${{ hashFiles('package-lock.json') }} + key: ${{ runner.os }}-root-node-modules-${{ hashFiles('package-lock.json') }}-2 - uses: actions/cache@v4 id: config-yaml-cache @@ -118,7 +118,7 @@ jobs: id: root-cache with: path: node_modules - key: ${{ runner.os }}-root-node-modules-${{ hashFiles('package-lock.json') }} + key: ${{ runner.os }}-root-node-modules-${{ hashFiles('package-lock.json') }}-2 - uses: actions/cache@v4 id: core-cache @@ -146,7 +146,7 @@ jobs: id: root-cache with: path: node_modules - key: ${{ runner.os }}-root-node-modules-${{ hashFiles('package-lock.json') }} + key: ${{ runner.os }}-root-node-modules-${{ hashFiles('package-lock.json') }}-2 - uses: actions/cache@v4 id: core-cache @@ -186,7 +186,7 @@ jobs: - uses: actions/cache@v4 with: path: node_modules - key: ${{ runner.os }}-root-node-modules-${{ hashFiles('package-lock.json') }} + key: ${{ runner.os }}-root-node-modules-${{ hashFiles('package-lock.json') }}-2 - uses: actions/cache@v4 with: @@ -229,7 +229,7 @@ jobs: - uses: actions/cache@v4 with: path: node_modules - key: ${{ runner.os }}-root-node-modules-${{ hashFiles('package-lock.json') }} + key: ${{ runner.os }}-root-node-modules-${{ hashFiles('package-lock.json') }}-2 - uses: actions/cache@v4 with: @@ -272,7 +272,7 @@ jobs: - uses: actions/cache@v4 with: path: node_modules - key: ${{ runner.os }}-root-node-modules-${{ hashFiles('package-lock.json') }} + key: ${{ runner.os }}-root-node-modules-${{ hashFiles('package-lock.json') }}-2 - uses: actions/cache@v4 with: @@ -320,7 +320,7 @@ jobs: - uses: actions/cache@v4 with: path: node_modules - key: ${{ runner.os }}-root-node-modules-${{ hashFiles('package-lock.json') }} + key: ${{ runner.os }}-root-node-modules-${{ hashFiles('package-lock.json') }}-2 - uses: actions/cache@v4 with: @@ -365,7 +365,7 @@ jobs: - uses: actions/cache@v4 with: path: node_modules - key: ${{ runner.os }}-root-node-modules-${{ hashFiles('package-lock.json') }} + key: ${{ runner.os }}-root-node-modules-${{ hashFiles('package-lock.json') }}-2 - uses: actions/cache@v4 with: From 18f1c67e20086bdb68cfb51ea4b4314106f491e0 Mon Sep 17 00:00:00 2001 From: uinstinct <61635505+uinstinct@users.noreply.github.com> Date: Fri, 6 Jun 2025 21:38:08 +0530 Subject: [PATCH 14/44] Revert "change hash to rebuild root node modules" This reverts commit 6ca088fdae20e63559cbd377f4ea51b4ccc7dd58. --- .github/workflows/pr_checks.yaml | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/.github/workflows/pr_checks.yaml b/.github/workflows/pr_checks.yaml index a61958dea..25a1b9a1e 100644 --- a/.github/workflows/pr_checks.yaml +++ b/.github/workflows/pr_checks.yaml @@ -24,7 +24,7 @@ jobs: id: root-cache with: path: node_modules - key: ${{ runner.os }}-root-node-modules-${{ hashFiles('package-lock.json') }}-2 + key: ${{ runner.os }}-root-node-modules-${{ hashFiles('package-lock.json') }} - name: Install root dependencies if: steps.root-cache.outputs.cache-hit != 'true' @@ -43,7 +43,7 @@ jobs: - uses: actions/cache@v4 with: path: node_modules - key: ${{ runner.os }}-root-node-modules-${{ hashFiles('package-lock.json') }}-2 + key: ${{ runner.os }}-root-node-modules-${{ hashFiles('package-lock.json') }} - name: Check code formatting with Prettier run: npx prettier --check "**/*.{js,jsx,ts,tsx,json,css,md}" --ignore-path .gitignore --ignore-path .prettierignore @@ -61,7 +61,7 @@ jobs: - uses: actions/cache@v4 with: path: node_modules - key: ${{ runner.os }}-root-node-modules-${{ hashFiles('package-lock.json') }}-2 + key: ${{ runner.os }}-root-node-modules-${{ hashFiles('package-lock.json') }} - uses: actions/cache@v4 id: config-yaml-cache @@ -88,7 +88,7 @@ jobs: - uses: actions/cache@v4 with: path: node_modules - key: ${{ runner.os }}-root-node-modules-${{ hashFiles('package-lock.json') }}-2 + key: ${{ runner.os }}-root-node-modules-${{ hashFiles('package-lock.json') }} - uses: actions/cache@v4 id: config-yaml-cache @@ -118,7 +118,7 @@ jobs: id: root-cache with: path: node_modules - key: ${{ runner.os }}-root-node-modules-${{ hashFiles('package-lock.json') }}-2 + key: ${{ runner.os }}-root-node-modules-${{ hashFiles('package-lock.json') }} - uses: actions/cache@v4 id: core-cache @@ -146,7 +146,7 @@ jobs: id: root-cache with: path: node_modules - key: ${{ runner.os }}-root-node-modules-${{ hashFiles('package-lock.json') }}-2 + key: ${{ runner.os }}-root-node-modules-${{ hashFiles('package-lock.json') }} - uses: actions/cache@v4 id: core-cache @@ -186,7 +186,7 @@ jobs: - uses: actions/cache@v4 with: path: node_modules - key: ${{ runner.os }}-root-node-modules-${{ hashFiles('package-lock.json') }}-2 + key: ${{ runner.os }}-root-node-modules-${{ hashFiles('package-lock.json') }} - uses: actions/cache@v4 with: @@ -229,7 +229,7 @@ jobs: - uses: actions/cache@v4 with: path: node_modules - key: ${{ runner.os }}-root-node-modules-${{ hashFiles('package-lock.json') }}-2 + key: ${{ runner.os }}-root-node-modules-${{ hashFiles('package-lock.json') }} - uses: actions/cache@v4 with: @@ -272,7 +272,7 @@ jobs: - uses: actions/cache@v4 with: path: node_modules - key: ${{ runner.os }}-root-node-modules-${{ hashFiles('package-lock.json') }}-2 + key: ${{ runner.os }}-root-node-modules-${{ hashFiles('package-lock.json') }} - uses: actions/cache@v4 with: @@ -320,7 +320,7 @@ jobs: - uses: actions/cache@v4 with: path: node_modules - key: ${{ runner.os }}-root-node-modules-${{ hashFiles('package-lock.json') }}-2 + key: ${{ runner.os }}-root-node-modules-${{ hashFiles('package-lock.json') }} - uses: actions/cache@v4 with: @@ -365,7 +365,7 @@ jobs: - uses: actions/cache@v4 with: path: node_modules - key: ${{ runner.os }}-root-node-modules-${{ hashFiles('package-lock.json') }}-2 + key: ${{ runner.os }}-root-node-modules-${{ hashFiles('package-lock.json') }} - uses: actions/cache@v4 with: From 9fae1a2f05f9c88e7a68ce360127db1174ef0e52 Mon Sep 17 00:00:00 2001 From: uinstinct <61635505+uinstinct@users.noreply.github.com> Date: Fri, 6 Jun 2025 22:30:40 +0530 Subject: [PATCH 15/44] refactor utils to child process files --- binary/package-lock.json | 5 +- extensions/vscode/package-lock.json | 6 +- .../vscode/scripts/generate-copy-config.js | 43 ++++++++++ .../vscode/scripts/install-nodemodules.js | 42 ++++++++++ extensions/vscode/scripts/prepackage.js | 9 +- extensions/vscode/scripts/utils.js | 84 +------------------ gui/package-lock.json | 2 +- 7 files changed, 96 insertions(+), 95 deletions(-) diff --git a/binary/package-lock.json b/binary/package-lock.json index abb11ce8e..2d84672f0 100644 --- a/binary/package-lock.json +++ b/binary/package-lock.json @@ -52,7 +52,7 @@ "@aws-sdk/credential-providers": "^3.778.0", "@continuedev/config-types": "^1.0.13", "@continuedev/config-yaml": "file:../packages/config-yaml", - "@continuedev/fetch": "^1.0.10", + "@continuedev/fetch": "^1.0.13", "@continuedev/llm-info": "^1.0.8", "@continuedev/openai-adapters": "^1.0.25", "@modelcontextprotocol/sdk": "^1.12.0", @@ -144,7 +144,8 @@ "onnxruntime-common": "1.14.0", "onnxruntime-web": "1.14.0", "ts-jest": "^29.1.1", - "typescript": "^5.6.3" + "typescript": "^5.6.3", + "vitest": "^3.1.4" }, "engines": { "node": ">=20.19.0" diff --git a/extensions/vscode/package-lock.json b/extensions/vscode/package-lock.json index e516f171e..38efaa08a 100644 --- a/extensions/vscode/package-lock.json +++ b/extensions/vscode/package-lock.json @@ -1,12 +1,12 @@ { "name": "continue", - "version": "1.1.41", + "version": "1.1.44", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "continue", - "version": "1.1.41", + "version": "1.1.44", "license": "Apache-2.0", "dependencies": { "@continuedev/config-types": "^1.0.14", @@ -107,7 +107,7 @@ "@aws-sdk/credential-providers": "^3.778.0", "@continuedev/config-types": "^1.0.13", "@continuedev/config-yaml": "file:../packages/config-yaml", - "@continuedev/fetch": "^1.0.10", + "@continuedev/fetch": "^1.0.13", "@continuedev/llm-info": "^1.0.8", "@continuedev/openai-adapters": "^1.0.25", "@modelcontextprotocol/sdk": "^1.12.0", diff --git a/extensions/vscode/scripts/generate-copy-config.js b/extensions/vscode/scripts/generate-copy-config.js index 16d8e1df6..73fe4602d 100644 --- a/extensions/vscode/scripts/generate-copy-config.js +++ b/extensions/vscode/scripts/generate-copy-config.js @@ -2,6 +2,7 @@ * @file Generate config.yaml file from template. Intended to run as a child process. */ +const { fork } = require("child_process"); const fs = require("fs"); const path = require("path"); @@ -81,3 +82,45 @@ process.on("message", (msg) => { }); } }); + +async function generateAndCopyConfigYamlSchema() { + // Generate and copy over config-yaml-schema.json + const generateConfigYamlChild = fork( + path.join(__dirname, "generate-copy-config.js"), + { + stdio: "inherit", + }, + ); + generateConfigYamlChild.send({ payload: { operation: "generate" } }); + + await new Promise((resolve, reject) => { + generateConfigYamlChild.on("message", (msg) => { + if (msg.error) { + reject(); + } + resolve(); + }); + }); + + // Copy config schemas to intellij + const copyConfigSchemaChild = fork( + path.join(__dirname, "generate-copy-config.js"), + { + stdio: "inherit", + }, + ); + copyConfigSchemaChild.send({ payload: { operation: "copy" } }); + + await new Promise((resolve, reject) => { + copyConfigSchemaChild.on("message", (msg) => { + if (msg.error) { + reject(); + } + resolve(); + }); + }); +} + +module.exports = { + generateAndCopyConfigYamlSchema, +}; diff --git a/extensions/vscode/scripts/install-nodemodules.js b/extensions/vscode/scripts/install-nodemodules.js index cae222b39..f23de3b3b 100644 --- a/extensions/vscode/scripts/install-nodemodules.js +++ b/extensions/vscode/scripts/install-nodemodules.js @@ -2,6 +2,7 @@ * @file Install node modules for the VS Code extension. This is intended to run as a child process. */ +const { fork } = require("child_process"); const path = require("path"); const { execCmdSync } = require("../../../scripts/util"); @@ -38,3 +39,44 @@ process.on("message", (msg) => { }); } }); + +async function installNodeModules() { + const installVscodeChild = fork( + path.join(__dirname, "install-nodemodules.js"), + { + stdio: "inherit", + }, + ); + installVscodeChild.send({ payload: { targetDir: "vscode" } }); + + const installGuiChild = fork(path.join(__dirname, "install-nodemodules.js"), { + stdio: "inherit", + }); + installGuiChild.send({ payload: { targetDir: "gui" } }); + + await Promise.all([ + new Promise((resolve, reject) => { + installVscodeChild.on("message", (msg) => { + if (msg.error) { + reject(); + } + resolve(); + }); + }), + new Promise((resolve, reject) => { + installGuiChild.on("message", (msg) => { + if (msg.error) { + reject(); + } + resolve(); + }); + }), + ]).catch((error) => { + console.error(error); + process.exit(1); + }); +} + +module.exports = { + installNodeModules, +}; diff --git a/extensions/vscode/scripts/prepackage.js b/extensions/vscode/scripts/prepackage.js index ece5d91e5..622393a19 100644 --- a/extensions/vscode/scripts/prepackage.js +++ b/extensions/vscode/scripts/prepackage.js @@ -11,13 +11,10 @@ const { autodetectPlatformAndArch, } = require("../../../scripts/util/index"); +const { generateAndCopyConfigYamlSchema } = require("./generate-copy-config"); const { copySqlite, copyEsbuild } = require("./install-copy-sqlite-esbuild"); -const { - writeBuildTimestamp, - installNodeModules, - continueDir, - generateAndCopyConfigYamlSchema, -} = require("./utils"); +const { installNodeModules } = require("./install-nodemodules"); +const { writeBuildTimestamp, continueDir } = require("./utils"); // Clear folders that will be packaged to ensure clean slate rimrafSync(path.join(__dirname, "..", "bin")); diff --git a/extensions/vscode/scripts/utils.js b/extensions/vscode/scripts/utils.js index 422e6370b..cae982a97 100644 --- a/extensions/vscode/scripts/utils.js +++ b/extensions/vscode/scripts/utils.js @@ -1,56 +1,13 @@ -const { fork } = require("child_process"); const fs = require("fs"); const path = require("path"); const ncp = require("ncp").ncp; const { rimrafSync } = require("rimraf"); -const { - validateFilesPresent, - execCmdSync, - autodetectPlatformAndArch, -} = require("../../../scripts/util/index"); +const { execCmdSync } = require("../../../scripts/util/index"); const continueDir = path.join(__dirname, "..", "..", ".."); -async function generateAndCopyConfigYamlSchema() { - // Generate and copy over config-yaml-schema.json - const generateConfigYamlChild = fork( - path.join(__dirname, "generate-copy-config.js"), - { - stdio: "inherit", - }, - ); - generateConfigYamlChild.send({ payload: { operation: "generate" } }); - - await new Promise((resolve, reject) => { - generateConfigYamlChild.on("message", (msg) => { - if (msg.error) { - reject(); - } - resolve(); - }); - }); - - // Copy config schemas to intellij - const copyConfigSchemaChild = fork( - path.join(__dirname, "generate-copy-config.js"), - { - stdio: "inherit", - }, - ); - copyConfigSchemaChild.send({ payload: { operation: "copy" } }); - - await new Promise((resolve, reject) => { - copyConfigSchemaChild.on("message", (msg) => { - if (msg.error) { - reject(); - } - resolve(); - }); - }); -} - function copyTokenizers() { fs.copyFileSync( path.join(__dirname, "../../../core/llm/llamaTokenizerWorkerPool.mjs"), @@ -65,43 +22,6 @@ function copyTokenizers() { console.log("[info] Copied llamaTokenizer"); } -async function installNodeModules() { - const installVscodeChild = fork( - path.join(__dirname, "install-nodemodules.js"), - { - stdio: "inherit", - }, - ); - installVscodeChild.send({ payload: { targetDir: "vscode" } }); - - const installGuiChild = fork(path.join(__dirname, "install-nodemodules.js"), { - stdio: "inherit", - }); - installGuiChild.send({ payload: { targetDir: "gui" } }); - - await Promise.all([ - new Promise((resolve, reject) => { - installVscodeChild.on("message", (msg) => { - if (msg.error) { - reject(); - } - resolve(); - }); - }), - new Promise((resolve, reject) => { - installGuiChild.on("message", (msg) => { - if (msg.error) { - reject(); - } - resolve(); - }); - }), - ]).catch((error) => { - console.error(error); - process.exit(1); - }); -} - async function buildGui(isGhAction) { // Make sure we are in the right directory if (!process.cwd().endsWith("gui")) { @@ -552,8 +472,6 @@ function writeBuildTimestamp() { module.exports = { continueDir, - generateAndCopyConfigYamlSchema, - installNodeModules, buildGui, copyOnnxRuntimeFromNodeModules, copyTreeSitterWasms, diff --git a/gui/package-lock.json b/gui/package-lock.json index 020586519..a9d589b98 100644 --- a/gui/package-lock.json +++ b/gui/package-lock.json @@ -111,7 +111,7 @@ "@aws-sdk/credential-providers": "^3.778.0", "@continuedev/config-types": "^1.0.13", "@continuedev/config-yaml": "file:../packages/config-yaml", - "@continuedev/fetch": "^1.0.10", + "@continuedev/fetch": "^1.0.13", "@continuedev/llm-info": "^1.0.8", "@continuedev/openai-adapters": "^1.0.25", "@modelcontextprotocol/sdk": "^1.12.0", From 3722b8c4f8a3896f2410897cb8b9874a4dec2bcb Mon Sep 17 00:00:00 2001 From: uinstinct <61635505+uinstinct@users.noreply.github.com> Date: Fri, 6 Jun 2025 22:51:55 +0530 Subject: [PATCH 16/44] refactor download node-sqlite to common --- binary/utils/bundle-binary.js | 49 ++++++++----------- .../scripts/install-copy-sqlite-esbuild.js | 33 +++++++------ 2 files changed, 40 insertions(+), 42 deletions(-) diff --git a/binary/utils/bundle-binary.js b/binary/utils/bundle-binary.js index c218166cd..91d2f4593 100644 --- a/binary/utils/bundle-binary.js +++ b/binary/utils/bundle-binary.js @@ -8,41 +8,34 @@ const { const { downloadRipgrep } = require("./ripgrep"); const { TARGET_TO_LANCEDB } = require("../utils/targets"); const fs = require("fs"); +const { + downloadSqlite, +} = require("../../extensions/vscode/scripts/install-copy-sqlite-esbuild"); async function downloadNodeSqlite(target, targetDir) { - return new Promise((resolve) => { - const [currentPlatform, currentArch] = autodetectPlatformAndArch(); + const [currentPlatform, currentArch] = autodetectPlatformAndArch(); - // Download and unzip prebuilt sqlite3 binary for the target - console.log("[info] Downloading node-sqlite3"); + // Download and unzip prebuilt sqlite3 binary for the target + console.log("[info] Downloading node-sqlite3"); - const downloadUrl = - // node-sqlite3 doesn't have a pre-built binary for win32-arm64 - target === "win32-arm64" - ? "https://continue-server-binaries.s3.us-west-1.amazonaws.com/win32-arm64/node_sqlite3.tar.gz" - : `https://github.com/TryGhost/node-sqlite3/releases/download/v5.1.7/sqlite3-v5.1.7-napi-v6-${ - target - }.tar.gz`; + await downloadSqlite(target, `${targetDir}/build.tar.gz`); - execCmdSync(`curl -L -o ${targetDir}/build.tar.gz ${downloadUrl}`); - execCmdSync(`cd ${targetDir} && tar -xvzf build.tar.gz`); + execCmdSync(`cd ${targetDir} && tar -xvzf build.tar.gz`); - // Copy to build directory for testing - try { - const [platform, arch] = target.split("-"); - if (platform === currentPlatform && arch === currentArch) { - fs.copyFileSync( - `${targetDir}/build/Release/node_sqlite3.node`, - `build/node_sqlite3.node`, - ); - } - } catch (error) { - console.log("[warn] Could not copy node_sqlite to build"); - console.log(error); + // Copy to build directory for testing + try { + const [platform, arch] = target.split("-"); + if (platform === currentPlatform && arch === currentArch) { + fs.copyFileSync( + `${targetDir}/build/Release/node_sqlite3.node`, + `build/node_sqlite3.node`, + ); } - fs.unlinkSync(`${targetDir}/build.tar.gz`); - resolve(); - }); + } catch (error) { + console.log("[warn] Could not copy node_sqlite to build"); + console.log(error); + } + fs.unlinkSync(`${targetDir}/build.tar.gz`); } /** diff --git a/extensions/vscode/scripts/install-copy-sqlite-esbuild.js b/extensions/vscode/scripts/install-copy-sqlite-esbuild.js index 370876c7f..ad33b2eb6 100644 --- a/extensions/vscode/scripts/install-copy-sqlite-esbuild.js +++ b/extensions/vscode/scripts/install-copy-sqlite-esbuild.js @@ -1,4 +1,4 @@ -const { fork, execSync } = require("child_process"); +const { fork } = require("child_process"); const fs = require("fs"); const https = require("https"); const path = require("path"); @@ -80,23 +80,27 @@ async function downloadFile(url, outputPath, maxRedirects = 5) { }); } +/** + * + * @param {string} target platform specific target + * @param {string} targetDir the directory to download into + */ +async function downloadSqlite(target, targetDir) { + const downloadUrl = + // node-sqlite3 doesn't have a pre-built binary for win32-arm64 + target === "win32-arm64" + ? "https://continue-server-binaries.s3.us-west-1.amazonaws.com/win32-arm64/node_sqlite3.tar.gz" + : `https://github.com/TryGhost/node-sqlite3/releases/download/v5.1.7/sqlite3-v5.1.7-napi-v6-${ + target + }.tar.gz`; + await downloadFile(downloadUrl, targetDir); +} + async function installAndCopySqlite(target) { // Replace the installed with pre-built console.log("[info] Downloading pre-built sqlite3 binary"); rimrafSync("../../core/node_modules/sqlite3/build"); - const downloadUrl = { - "darwin-arm64": - "https://github.com/TryGhost/node-sqlite3/releases/download/v5.1.7/sqlite3-v5.1.7-napi-v6-darwin-arm64.tar.gz", - "linux-arm64": - "https://github.com/TryGhost/node-sqlite3/releases/download/v5.1.7/sqlite3-v5.1.7-napi-v3-linux-arm64.tar.gz", - // node-sqlite3 doesn't have a pre-built binary for win32-arm64 - "win32-arm64": - "https://continue-server-binaries.s3.us-west-1.amazonaws.com/win32-arm64/node_sqlite3.tar.gz", - }[target]; - await downloadFile( - downloadUrl, - "../../core/node_modules/sqlite3/build.tar.gz", - ); + await downloadSqlite(target, "../../core/node_modules/sqlite3/build.tar.gz"); execCmdSync("cd ../../core/node_modules/sqlite3 && tar -xvzf build.tar.gz"); fs.unlinkSync("../../core/node_modules/sqlite3/build.tar.gz"); } @@ -179,6 +183,7 @@ async function copyEsbuild(target) { } module.exports = { + downloadSqlite, copySqlite, copyEsbuild, }; From e8e8821134ef15043b92de83a31fa203640f6d70 Mon Sep 17 00:00:00 2001 From: uinstinct <61635505+uinstinct@users.noreply.github.com> Date: Fri, 6 Jun 2025 22:58:45 +0530 Subject: [PATCH 17/44] move install-copy-nodemodule to vscode scripts --- binary/build.js | 6 ++++-- extensions/vscode/package-lock.json | 4 ++-- .../vscode/scripts/install-copy-nodemodule.js | 12 +++++++----- extensions/vscode/scripts/prepackage.js | 6 +++--- package-lock.json | 11 ----------- package.json | 1 - 6 files changed, 16 insertions(+), 24 deletions(-) rename scripts/util/copy-nodemodule.js => extensions/vscode/scripts/install-copy-nodemodule.js (92%) diff --git a/binary/build.js b/binary/build.js index aa5fa5ffd..56c27b2bd 100644 --- a/binary/build.js +++ b/binary/build.js @@ -6,7 +6,9 @@ const { rimrafSync } = require("rimraf"); const { validateFilesPresent } = require("../scripts/util"); const { ALL_TARGETS, TARGET_TO_LANCEDB } = require("./utils/targets"); const { fork } = require("child_process"); -const { copyNodeModule } = require("../scripts/util/copy-nodemodule"); +const { + installAndCopyNodeModules, +} = require("../extensions/vscode/scripts/install-copy-nodemodule"); const bin = path.join(__dirname, "bin"); const out = path.join(__dirname, "out"); @@ -104,7 +106,7 @@ async function buildWithEsbuild() { } console.log(`[info] Downloading for ${target}...`); copyLanceDBPromises.push( - copyNodeModule(TARGET_TO_LANCEDB[target], "@lancedb"), + installAndCopyNodeModules(TARGET_TO_LANCEDB[target], "@lancedb"), ); } await Promise.all(copyLanceDBPromises).catch(() => { diff --git a/extensions/vscode/package-lock.json b/extensions/vscode/package-lock.json index 38efaa08a..349212a6a 100644 --- a/extensions/vscode/package-lock.json +++ b/extensions/vscode/package-lock.json @@ -1,12 +1,12 @@ { "name": "continue", - "version": "1.1.44", + "version": "1.1.45", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "continue", - "version": "1.1.44", + "version": "1.1.45", "license": "Apache-2.0", "dependencies": { "@continuedev/config-types": "^1.0.14", diff --git a/scripts/util/copy-nodemodule.js b/extensions/vscode/scripts/install-copy-nodemodule.js similarity index 92% rename from scripts/util/copy-nodemodule.js rename to extensions/vscode/scripts/install-copy-nodemodule.js index 361e2d891..a20d2dee4 100644 --- a/scripts/util/copy-nodemodule.js +++ b/extensions/vscode/scripts/install-copy-nodemodule.js @@ -1,12 +1,14 @@ /** - * @file Copy lancedb to the current directory. It is intended to run as a child process. + * @file Copy lancedb to the current directory. It is also intended to run as a child process. */ +const { fork } = require("child_process"); const fs = require("fs"); const path = require("path"); + const ncp = require("ncp").ncp; -const { execCmdSync } = require("."); -const { fork } = require("child_process"); + +const { execCmdSync } = require("../../../scripts/util"); async function installNodeModuleInTempDirAndCopyToCurrent(packageName, toCopy) { console.log(`Copying ${packageName} to ${toCopy}`); @@ -86,7 +88,7 @@ process.on("message", (msg) => { * @param {string} packageName the module to install and copy * @param {string} toCopy directory to copy into inside node modules */ -async function copyNodeModule(packageName, toCopy) { +async function installAndCopyNodeModules(packageName, toCopy) { const child = fork(__filename, { stdio: "inherit", cwd: process.cwd() }); child.send({ payload: { @@ -106,5 +108,5 @@ async function copyNodeModule(packageName, toCopy) { } module.exports = { - copyNodeModule, + installAndCopyNodeModules, }; diff --git a/extensions/vscode/scripts/prepackage.js b/extensions/vscode/scripts/prepackage.js index 622393a19..57fa5a52d 100644 --- a/extensions/vscode/scripts/prepackage.js +++ b/extensions/vscode/scripts/prepackage.js @@ -4,7 +4,6 @@ const path = require("path"); const ncp = require("ncp").ncp; const { rimrafSync } = require("rimraf"); -const { copyNodeModule } = require("../../../scripts/util/copy-nodemodule"); const { validateFilesPresent, execCmdSync, @@ -12,6 +11,7 @@ const { } = require("../../../scripts/util/index"); const { generateAndCopyConfigYamlSchema } = require("./generate-copy-config"); +const { installAndCopyNodeModules } = require("./install-copy-nodemodule"); const { copySqlite, copyEsbuild } = require("./install-copy-sqlite-esbuild"); const { installNodeModules } = require("./install-nodemodules"); const { writeBuildTimestamp, continueDir } = require("./utils"); @@ -280,12 +280,12 @@ void (async () => { await Promise.all([ copyEsbuild(target), copySqlite(target), - copyNodeModule(packageToInstall, "@lancedb"), + installAndCopyNodeModules(packageToInstall, "@lancedb"), ]); } else { // Download esbuild from npm in tmp and copy over console.log("[info] npm installing esbuild binary"); - await copyNodeModule("esbuild@0.17.19", "@esbuild"); + await installAndCopyNodeModules("esbuild@0.17.19", "@esbuild"); } console.log("[info] Copying sqlite node binding from core"); diff --git a/package-lock.json b/package-lock.json index 43530562e..06f811afa 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,7 +8,6 @@ "@typescript-eslint/parser": "^7.8.0", "concurrently": "^9.1.2", "eslint-plugin-import": "^2.29.1", - "ncp": "^2.0.0", "prettier": "^3.3.3", "prettier-plugin-tailwindcss": "^0.6.8", "typescript": "^5.6.3" @@ -2234,16 +2233,6 @@ "dev": true, "peer": true }, - "node_modules/ncp": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/ncp/-/ncp-2.0.0.tgz", - "integrity": "sha512-zIdGUrPRFTUELUvr3Gmc7KZ2Sw/h1PiVM0Af/oHB6zgnV1ikqSfRk+TOufi79aHYCW3NiOXmr1BP5nWbzojLaA==", - "dev": true, - "license": "MIT", - "bin": { - "ncp": "bin/ncp" - } - }, "node_modules/object-inspect": { "version": "1.13.2", "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.2.tgz", diff --git a/package.json b/package.json index 9100ad0cd..79e522af1 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,6 @@ "@typescript-eslint/parser": "^7.8.0", "concurrently": "^9.1.2", "eslint-plugin-import": "^2.29.1", - "ncp": "^2.0.0", "prettier": "^3.3.3", "prettier-plugin-tailwindcss": "^0.6.8", "typescript": "^5.6.3" From 1d4a31af2243297e1582a6ae5ed96f57a4212bfe Mon Sep 17 00:00:00 2001 From: uinstinct <61635505+uinstinct@users.noreply.github.com> Date: Fri, 6 Jun 2025 22:59:39 +0530 Subject: [PATCH 18/44] rename install-copy-sqlite-esbuild to download-copy-sqlite-esbuild --- binary/utils/bundle-binary.js | 2 +- ...l-copy-sqlite-esbuild.js => download-copy-sqlite-esbuild.js} | 0 extensions/vscode/scripts/prepackage.js | 2 +- 3 files changed, 2 insertions(+), 2 deletions(-) rename extensions/vscode/scripts/{install-copy-sqlite-esbuild.js => download-copy-sqlite-esbuild.js} (100%) diff --git a/binary/utils/bundle-binary.js b/binary/utils/bundle-binary.js index 91d2f4593..50f34f647 100644 --- a/binary/utils/bundle-binary.js +++ b/binary/utils/bundle-binary.js @@ -10,7 +10,7 @@ const { TARGET_TO_LANCEDB } = require("../utils/targets"); const fs = require("fs"); const { downloadSqlite, -} = require("../../extensions/vscode/scripts/install-copy-sqlite-esbuild"); +} = require("../../extensions/vscode/scripts/download-copy-sqlite-esbuild"); async function downloadNodeSqlite(target, targetDir) { const [currentPlatform, currentArch] = autodetectPlatformAndArch(); diff --git a/extensions/vscode/scripts/install-copy-sqlite-esbuild.js b/extensions/vscode/scripts/download-copy-sqlite-esbuild.js similarity index 100% rename from extensions/vscode/scripts/install-copy-sqlite-esbuild.js rename to extensions/vscode/scripts/download-copy-sqlite-esbuild.js diff --git a/extensions/vscode/scripts/prepackage.js b/extensions/vscode/scripts/prepackage.js index 57fa5a52d..7649e0919 100644 --- a/extensions/vscode/scripts/prepackage.js +++ b/extensions/vscode/scripts/prepackage.js @@ -10,9 +10,9 @@ const { autodetectPlatformAndArch, } = require("../../../scripts/util/index"); +const { copySqlite, copyEsbuild } = require("./download-copy-sqlite-esbuild"); const { generateAndCopyConfigYamlSchema } = require("./generate-copy-config"); const { installAndCopyNodeModules } = require("./install-copy-nodemodule"); -const { copySqlite, copyEsbuild } = require("./install-copy-sqlite-esbuild"); const { installNodeModules } = require("./install-nodemodules"); const { writeBuildTimestamp, continueDir } = require("./utils"); From a363e34f753bbf69b22d33e9c4a03f937b3fa038 Mon Sep 17 00:00:00 2001 From: uinstinct <61635505+uinstinct@users.noreply.github.com> Date: Fri, 6 Jun 2025 23:03:20 +0530 Subject: [PATCH 19/44] refactor bundle binary to modular function --- binary/build.js | 18 ++---------------- binary/utils/bundle-binary.js | 28 +++++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 17 deletions(-) diff --git a/binary/build.js b/binary/build.js index 56c27b2bd..c2431333c 100644 --- a/binary/build.js +++ b/binary/build.js @@ -9,6 +9,7 @@ const { fork } = require("child_process"); const { installAndCopyNodeModules, } = require("../extensions/vscode/scripts/install-copy-nodemodule"); +const { bundleBinary } = require("./utils/bundle-binary"); const bin = path.join(__dirname, "bin"); const out = path.join(__dirname, "out"); @@ -178,22 +179,7 @@ async function buildWithEsbuild() { const buildBinaryPromises = []; console.log("[info] Building binaries with pkg..."); for (const target of targets) { - const child = fork("./utils/bundle-binary.js", { stdio: "inherit" }); - child.send({ - payload: { - target, - }, - }); - buildBinaryPromises.push( - new Promise((resolve, reject) => { - child.on("message", (msg) => { - if (msg.error) { - reject(); - } - resolve(); - }); - }), - ); + buildBinaryPromises.push(bundleBinary(target)); } await Promise.all(buildBinaryPromises).catch(() => { console.error("[error] Failed to build binaries"); diff --git a/binary/utils/bundle-binary.js b/binary/utils/bundle-binary.js index 50f34f647..0a778f5b0 100644 --- a/binary/utils/bundle-binary.js +++ b/binary/utils/bundle-binary.js @@ -1,6 +1,7 @@ /** - * @file Builds the binary for the specified target. It is intended to run as a child process. + * @file Builds the binary for the specified target. It is also intended to run as a child process. */ + const { execCmdSync, autodetectPlatformAndArch, @@ -11,6 +12,7 @@ const fs = require("fs"); const { downloadSqlite, } = require("../../extensions/vscode/scripts/download-copy-sqlite-esbuild"); +const { fork } = require("child_process"); async function downloadNodeSqlite(target, targetDir) { const [currentPlatform, currentArch] = autodetectPlatformAndArch(); @@ -74,3 +76,27 @@ process.on("message", (msg) => { process.send({ error: true }); }); }); + +/** + * @param {string} target the platform to bundle for + */ +async function bundleBinary(target) { + const child = fork(__filename, { stdio: "inherit" }); + child.send({ + payload: { + target, + }, + }); + return new Promise((resolve, reject) => { + child.on("message", (msg) => { + if (msg.error) { + reject(); + } + resolve(); + }); + }); +} + +module.exports = { + bundleBinary, +}; From 9c087bb8b8dd80fe55dd2175b0760b4143ed298f Mon Sep 17 00:00:00 2001 From: uinstinct <61635505+uinstinct@users.noreply.github.com> Date: Fri, 6 Jun 2025 23:04:08 +0530 Subject: [PATCH 20/44] revert package-lock to main --- binary/package-lock.json | 5 ++--- extensions/vscode/package-lock.json | 4 ++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/binary/package-lock.json b/binary/package-lock.json index 2d84672f0..abb11ce8e 100644 --- a/binary/package-lock.json +++ b/binary/package-lock.json @@ -52,7 +52,7 @@ "@aws-sdk/credential-providers": "^3.778.0", "@continuedev/config-types": "^1.0.13", "@continuedev/config-yaml": "file:../packages/config-yaml", - "@continuedev/fetch": "^1.0.13", + "@continuedev/fetch": "^1.0.10", "@continuedev/llm-info": "^1.0.8", "@continuedev/openai-adapters": "^1.0.25", "@modelcontextprotocol/sdk": "^1.12.0", @@ -144,8 +144,7 @@ "onnxruntime-common": "1.14.0", "onnxruntime-web": "1.14.0", "ts-jest": "^29.1.1", - "typescript": "^5.6.3", - "vitest": "^3.1.4" + "typescript": "^5.6.3" }, "engines": { "node": ">=20.19.0" diff --git a/extensions/vscode/package-lock.json b/extensions/vscode/package-lock.json index 349212a6a..38efaa08a 100644 --- a/extensions/vscode/package-lock.json +++ b/extensions/vscode/package-lock.json @@ -1,12 +1,12 @@ { "name": "continue", - "version": "1.1.45", + "version": "1.1.44", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "continue", - "version": "1.1.45", + "version": "1.1.44", "license": "Apache-2.0", "dependencies": { "@continuedev/config-types": "^1.0.14", From 1414aec53ba347d36c1b978b4fdd04d77d0657bf Mon Sep 17 00:00:00 2001 From: uinstinct <61635505+uinstinct@users.noreply.github.com> Date: Fri, 6 Jun 2025 23:08:21 +0530 Subject: [PATCH 21/44] rename install nodemodules to npm-install --- .../vscode/scripts/generate-copy-config.js | 2 +- .../{install-nodemodules.js => npm-install.js} | 17 +++++++---------- extensions/vscode/scripts/prepackage.js | 4 ++-- 3 files changed, 10 insertions(+), 13 deletions(-) rename extensions/vscode/scripts/{install-nodemodules.js => npm-install.js} (82%) diff --git a/extensions/vscode/scripts/generate-copy-config.js b/extensions/vscode/scripts/generate-copy-config.js index 73fe4602d..21a68d999 100644 --- a/extensions/vscode/scripts/generate-copy-config.js +++ b/extensions/vscode/scripts/generate-copy-config.js @@ -1,5 +1,5 @@ /** - * @file Generate config.yaml file from template. Intended to run as a child process. + * @file Generate config.yaml file from template. Also intended to run as a child process. */ const { fork } = require("child_process"); diff --git a/extensions/vscode/scripts/install-nodemodules.js b/extensions/vscode/scripts/npm-install.js similarity index 82% rename from extensions/vscode/scripts/install-nodemodules.js rename to extensions/vscode/scripts/npm-install.js index f23de3b3b..feffdcf26 100644 --- a/extensions/vscode/scripts/install-nodemodules.js +++ b/extensions/vscode/scripts/npm-install.js @@ -1,5 +1,5 @@ /** - * @file Install node modules for the VS Code extension. This is intended to run as a child process. + * @file Install node modules for the VS Code extension and gui. This is also intended to run as a child process. */ const { fork } = require("child_process"); @@ -40,16 +40,13 @@ process.on("message", (msg) => { } }); -async function installNodeModules() { - const installVscodeChild = fork( - path.join(__dirname, "install-nodemodules.js"), - { - stdio: "inherit", - }, - ); +async function npmInstall() { + const installVscodeChild = fork(__filename, { + stdio: "inherit", + }); installVscodeChild.send({ payload: { targetDir: "vscode" } }); - const installGuiChild = fork(path.join(__dirname, "install-nodemodules.js"), { + const installGuiChild = fork(__filename, { stdio: "inherit", }); installGuiChild.send({ payload: { targetDir: "gui" } }); @@ -78,5 +75,5 @@ async function installNodeModules() { } module.exports = { - installNodeModules, + npmInstall, }; diff --git a/extensions/vscode/scripts/prepackage.js b/extensions/vscode/scripts/prepackage.js index 7649e0919..9fb0d43a4 100644 --- a/extensions/vscode/scripts/prepackage.js +++ b/extensions/vscode/scripts/prepackage.js @@ -13,7 +13,7 @@ const { const { copySqlite, copyEsbuild } = require("./download-copy-sqlite-esbuild"); const { generateAndCopyConfigYamlSchema } = require("./generate-copy-config"); const { installAndCopyNodeModules } = require("./install-copy-nodemodule"); -const { installNodeModules } = require("./install-nodemodules"); +const { npmInstall } = require("./npm-install"); const { writeBuildTimestamp, continueDir } = require("./utils"); // Clear folders that will be packaged to ensure clean slate @@ -70,7 +70,7 @@ void (async () => { // Make sure we have an initial timestamp file writeBuildTimestamp(); - await Promise.all([generateAndCopyConfigYamlSchema(), installNodeModules()]); + await Promise.all([generateAndCopyConfigYamlSchema(), npmInstall()]); process.chdir(path.join(continueDir, "gui")); From 57e329b66d61dbfd5164686160f302112bf17a95 Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Wed, 18 Jun 2025 21:33:05 -0700 Subject: [PATCH 22/44] chat test progress --- .../TipTapEditor/utils/editorConfig.ts | 3 +- gui/src/context/MockIdeMessenger.ts | 30 ++- gui/src/pages/gui/Chat.test.tsx | 190 ++++++++---------- .../gui/chat-tests/ApplyScenarios.test.tsx | 44 ++++ .../gui/chat-tests/EditToolScenarios.test.tsx | 1 + gui/src/redux/slices/profiles/slice.ts | 4 +- gui/src/util/test/config.ts | 73 +++++++ 7 files changed, 234 insertions(+), 111 deletions(-) create mode 100644 gui/src/pages/gui/chat-tests/ApplyScenarios.test.tsx create mode 100644 gui/src/pages/gui/chat-tests/EditToolScenarios.test.tsx create mode 100644 gui/src/util/test/config.ts diff --git a/gui/src/components/mainInput/TipTapEditor/utils/editorConfig.ts b/gui/src/components/mainInput/TipTapEditor/utils/editorConfig.ts index 774a95446..2d7b134bd 100644 --- a/gui/src/components/mainInput/TipTapEditor/utils/editorConfig.ts +++ b/gui/src/components/mainInput/TipTapEditor/utils/editorConfig.ts @@ -332,7 +332,8 @@ export function createEditorConfig(options: { ], editorProps: { attributes: { - class: "outline-none overflow-hidden", + "data-testid": `editor-input-${props.isMainInput ? "main" : props.inputId}`, + class: "ProseMirror outline-none overflow-hidden", style: `font-size: ${getFontSize()}px;`, }, }, diff --git a/gui/src/context/MockIdeMessenger.ts b/gui/src/context/MockIdeMessenger.ts index 0e92384f1..bc46aebc0 100644 --- a/gui/src/context/MockIdeMessenger.ts +++ b/gui/src/context/MockIdeMessenger.ts @@ -109,16 +109,34 @@ export class MockIdeMessenger implements IIdeMessenger { ); } - async *llmStreamChat( - msg: ToCoreProtocol["llm/streamChat"][0], - cancelToken: AbortSignal, - ): AsyncGenerator { - yield [ + // Ability to customize the response for llmStreamChat + chatResponse: ChatMessage[][] = [ + [ { role: "assistant", content: "This is a test", }, - ]; + ], + ]; + chatStreamDelay: number = 0; + + async *llmStreamChat( + msg: ToCoreProtocol["llm/streamChat"][0], + cancelToken: AbortSignal, + ): AsyncGenerator { + for (const response of this.chatResponse) { + if (cancelToken.aborted) { + console.log("MockIdeMessenger: Stream aborted"); + return undefined; + } + console.log("MockIdeMessenger: Yielding chunk", response); + yield response; + if (this.chatStreamDelay > 0) { + await new Promise((resolve) => + setTimeout(resolve, this.chatStreamDelay), + ); + } + } return undefined; } diff --git a/gui/src/pages/gui/Chat.test.tsx b/gui/src/pages/gui/Chat.test.tsx index 626438350..27a1fe8a1 100644 --- a/gui/src/pages/gui/Chat.test.tsx +++ b/gui/src/pages/gui/Chat.test.tsx @@ -1,109 +1,95 @@ import { screen, waitFor } from "@testing-library/dom"; import { act } from "@testing-library/react"; +import { Editor } from "@tiptap/core"; +import { addAndSelectMockLlm } from "../../util/test/config"; import { renderWithProviders } from "../../util/test/render"; import { Chat } from "./Chat"; -describe("Chat page test", () => { - it("should render input box", async () => { - await renderWithProviders(); - expect(await screen.findByTestId("continue-input-box")).toBeInTheDocument(); - }); +export async function getMainEditor(): Promise { + const editorElement = await waitFor(() => + screen.findByTestId("editor-input-main"), + ); + expect(editorElement).toBeInTheDocument(); + if ("editor" in editorElement) { + return editorElement.editor as Editor; + } else { + throw new Error("Main editor not found within editor container"); + } +} - it("should be able to toggle modes", async () => { - await renderWithProviders(); - expect(screen.getByText("Chat")).toBeInTheDocument(); - - // Simulate cmd+. keyboard shortcut to toggle modes - act(() => { - document.dispatchEvent( - new KeyboardEvent("keydown", { - key: ".", - metaKey: true, // cmd key on Mac - }), - ); - }); - - // Check that it switched to Agent mode - expect(await screen.findByText("Agent")).toBeInTheDocument(); - - act(() => { - document.dispatchEvent( - new KeyboardEvent("keydown", { - key: ".", - metaKey: true, // cmd key on Mac - }), - ); - }); - - // Check that it switched back to Chat mode - expect(await screen.findByText("Chat")).toBeInTheDocument(); - }); - - it.skip("should send a message and receive a response", async () => { - const { user, container } = await renderWithProviders(); - const inputBox = await waitFor(() => - container.querySelector(".ProseMirror")!.querySelector("p"), - ); - expect(inputBox).toBeDefined(); - - const sendButton = await screen.findByTestId("submit-input-button"); - - await act(async () => { - // Focus input box - inputBox!.focus(); - - // Type message - await user.type(inputBox!, "Hello, world!"); - - sendButton.click(); - }); - expect(await screen.findByText("Hello, world!")).toBeInTheDocument(); - }); - - it("should handle apply updates and display the accept / reject all buttons", async () => { - const { ideMessenger } = await renderWithProviders(); - - // Use queryByText which returns null when element isn't found - const acceptAllButton = screen.queryByText("Accept All"); - const rejectAllButton = screen.queryByText("Reject All"); - - // Assert that the buttons don't exist - expect(acceptAllButton).not.toBeInTheDocument(); - expect(rejectAllButton).not.toBeInTheDocument(); - - for (let i = 0; i < 5; i++) { - ideMessenger.mockMessageToWebview("updateApplyState", { - status: "streaming", - streamId: `12345`, - }); - } - - ideMessenger.mockMessageToWebview("updateApplyState", { - status: "done", - streamId: "12345", - }); - - // Wait for the buttons to appear - await waitFor(() => { - expect( - screen.getByTestId("accept-reject-all-buttons"), - ).toBeInTheDocument(); - }); - - // IDE sends back message that it is done - ideMessenger.mockMessageToWebview("updateApplyState", { - status: "closed", - streamId: "12345", - }); - - // Wait for the buttons to disappear - await waitFor(() => { - expect( - screen.queryByTestId("edit-accept-button"), - ).not.toBeInTheDocument(); - expect( - screen.queryByTestId("edit-reject-button"), - ).not.toBeInTheDocument(); - }); - }); +test("should render input box", async () => { + await renderWithProviders(); + expect(await screen.findByTestId("continue-input-box")).toBeInTheDocument(); +}); + +test("should be able to toggle modes", async () => { + await renderWithProviders(); + expect(screen.getByText("Chat")).toBeInTheDocument(); + + // Simulate cmd+. keyboard shortcut to toggle modes + act(() => { + document.dispatchEvent( + new KeyboardEvent("keydown", { + key: ".", + metaKey: true, // cmd key on Mac + }), + ); + }); + + // Check that it switched to Agent mode + expect(await screen.findByText("Agent")).toBeInTheDocument(); + + act(() => { + document.dispatchEvent( + new KeyboardEvent("keydown", { + key: ".", + metaKey: true, // cmd key on Mac + }), + ); + }); + + // Check that it switched back to Chat mode + expect(await screen.findByText("Chat")).toBeInTheDocument(); +}); + +test("should send a message and receive a response", async () => { + const { ideMessenger, store } = await renderWithProviders(); + + // First add and select the mock LLM + await act(async () => { + addAndSelectMockLlm(store, ideMessenger); + }); + + const CONTENT = "Expected response"; + const INPUT = "User input"; + + // Setup the mock response before any actions + ideMessenger.chatResponse = [[{ role: "assistant", content: CONTENT }]]; + + // Wait for the editor to be in the document + const editor = await getMainEditor(); + + // Find the submit button + const sendButton = await waitFor(() => + screen.findByTestId("submit-input-button"), + ); + expect(sendButton).toBeInTheDocument(); + + // Insert content into the editor + await act(async () => { + editor.commands.insertContent(INPUT); + }); + + // Verify the input is in the document + const input = await waitFor(() => screen.findByText(INPUT)); + expect(input).toBeInTheDocument(); + + // Click the send button + await act(async () => { + sendButton.click(); + }); + + // Increase the timeout for finding the response + const response = await waitFor(() => screen.findByText(CONTENT)); + expect(response).toBeInTheDocument(); }); diff --git a/gui/src/pages/gui/chat-tests/ApplyScenarios.test.tsx b/gui/src/pages/gui/chat-tests/ApplyScenarios.test.tsx new file mode 100644 index 000000000..c219d216e --- /dev/null +++ b/gui/src/pages/gui/chat-tests/ApplyScenarios.test.tsx @@ -0,0 +1,44 @@ +import { screen, waitFor } from "@testing-library/dom"; +import { renderWithProviders } from "../../../util/test/render"; +import { Chat } from "../Chat"; + +test("Chat apply scenarios: handle apply updates and display the accept / reject all buttons", async () => { + const { ideMessenger } = await renderWithProviders(); + + // Use queryByText which returns null when element isn't found + const acceptAllButton = screen.queryByText("Accept All"); + const rejectAllButton = screen.queryByText("Reject All"); + + // Assert that the buttons don't exist + expect(acceptAllButton).not.toBeInTheDocument(); + expect(rejectAllButton).not.toBeInTheDocument(); + + for (let i = 0; i < 5; i++) { + ideMessenger.mockMessageToWebview("updateApplyState", { + status: "streaming", + streamId: `12345`, + }); + } + + ideMessenger.mockMessageToWebview("updateApplyState", { + status: "done", + streamId: "12345", + }); + + // Wait for the buttons to appear + await waitFor(() => { + expect(screen.getByTestId("accept-reject-all-buttons")).toBeInTheDocument(); + }); + + // IDE sends back message that it is done + ideMessenger.mockMessageToWebview("updateApplyState", { + status: "closed", + streamId: "12345", + }); + + // Wait for the buttons to disappear + await waitFor(() => { + expect(screen.queryByTestId("edit-accept-button")).not.toBeInTheDocument(); + expect(screen.queryByTestId("edit-reject-button")).not.toBeInTheDocument(); + }); +}); diff --git a/gui/src/pages/gui/chat-tests/EditToolScenarios.test.tsx b/gui/src/pages/gui/chat-tests/EditToolScenarios.test.tsx new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/gui/src/pages/gui/chat-tests/EditToolScenarios.test.tsx @@ -0,0 +1 @@ + diff --git a/gui/src/redux/slices/profiles/slice.ts b/gui/src/redux/slices/profiles/slice.ts index 6f3144736..0ea3d587a 100644 --- a/gui/src/redux/slices/profiles/slice.ts +++ b/gui/src/redux/slices/profiles/slice.ts @@ -19,7 +19,7 @@ export interface ProfilesState { preferencesByProfileId: Record; } -const initialState: ProfilesState = { +export const defaultProfilesState: ProfilesState = { preferencesByProfileId: {}, selectedProfileId: null, selectedOrganizationId: null, @@ -51,7 +51,7 @@ const initialState: ProfilesState = { export const profilesSlice = createSlice({ name: "profiles", - initialState, + initialState: defaultProfilesState, reducers: { setSelectedProfile: (state, { payload }: PayloadAction) => { state.selectedProfileId = payload; diff --git a/gui/src/util/test/config.ts b/gui/src/util/test/config.ts new file mode 100644 index 000000000..4dbe4abbe --- /dev/null +++ b/gui/src/util/test/config.ts @@ -0,0 +1,73 @@ +import { EnhancedStore } from "@reduxjs/toolkit"; +import { BrowserSerializedContinueConfig, ModelDescription } from "core"; +import { SerializedOrgWithProfiles } from "core/config/ProfileLifecycleManager"; +import { MockIdeMessenger } from "../../context/MockIdeMessenger"; +import { RootState } from "../../redux/store"; + +interface TestConfigUpdateParams { + store: EnhancedStore; + messenger: MockIdeMessenger; + newProfileId?: string; + newOrgId?: string; + newOrgs?: SerializedOrgWithProfiles[]; + + configUpdates?: Partial; +} + +export function triggerConfigUpdate({ + store, + messenger, + configUpdates, + newOrgs, + newOrgId, + newProfileId, +}: TestConfigUpdateParams) { + const state = store.getState(); + messenger.mockMessageToWebview("configUpdate", { + organizations: newOrgs ?? state.profiles.organizations, + selectedOrgId: newOrgId ?? state.profiles.selectedOrganizationId, + profileId: newProfileId ?? state.profiles.selectedProfileId, + result: { + config: { + ...state.config.config, + ...configUpdates, + }, + configLoadInterrupted: false, + errors: [], + }, + }); +} + +export function addAndSelectChatModel( + store: EnhancedStore, + messenger: MockIdeMessenger, + llmDesc: ModelDescription, +) { + const state = store.getState() as RootState; + triggerConfigUpdate({ + store, + messenger, + configUpdates: { + modelsByRole: { + ...state.config.config.modelsByRole, + chat: [...state.config.config.modelsByRole.chat, llmDesc], + }, + selectedModelByRole: { + ...state.config.config.selectedModelByRole, + chat: llmDesc, + }, + }, + }); +} + +export function addAndSelectMockLlm( + store: EnhancedStore, + messenger: MockIdeMessenger, +) { + addAndSelectChatModel(store, messenger, { + model: "mock", + provider: "mock", + title: "Mock LLM", + underlyingProviderName: "mock", + }); +} From 01930c926d563b1241ed70b86b1887ed074b08cd Mon Sep 17 00:00:00 2001 From: uinstinct <61635505+uinstinct@users.noreply.github.com> Date: Thu, 19 Jun 2025 16:41:16 +0530 Subject: [PATCH 23/44] skip installations and downloads on extension run --- .vscode/tasks.json | 3 ++ extensions/vscode/scripts/prepackage.js | 50 ++++++++++++++----------- scripts/install-dependencies.sh | 2 +- 3 files changed, 32 insertions(+), 23 deletions(-) diff --git a/.vscode/tasks.json b/.vscode/tasks.json index e40d9d054..d3a4a623d 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -103,6 +103,9 @@ "clear": true }, "options": { + "env": { + "SKIP_INSTALLS": "true" + }, "cwd": "${workspaceFolder}/extensions/vscode" } }, diff --git a/extensions/vscode/scripts/prepackage.js b/extensions/vscode/scripts/prepackage.js index 9fb0d43a4..599b06062 100644 --- a/extensions/vscode/scripts/prepackage.js +++ b/extensions/vscode/scripts/prepackage.js @@ -27,6 +27,8 @@ if (!fs.existsSync(guiDist)) { fs.mkdirSync(guiDist, { recursive: true }); } +const skipInstalls = process.env.SKIP_INSTALLS === "true"; + // Get the target to package for let target = undefined; const args = process.argv; @@ -70,7 +72,9 @@ void (async () => { // Make sure we have an initial timestamp file writeBuildTimestamp(); - await Promise.all([generateAndCopyConfigYamlSchema(), npmInstall()]); + if (!skipInstalls) { + await Promise.all([generateAndCopyConfigYamlSchema(), npmInstall()]); + } process.chdir(path.join(continueDir, "gui")); @@ -264,28 +268,30 @@ void (async () => { ); }); - // GitHub Actions doesn't support ARM, so we need to download pre-saved binaries - // 02/07/25 - the above comment is out of date, there is now support for ARM runners on GitHub Actions - if (isArmTarget) { - // lancedb binary - const packageToInstall = { - "darwin-arm64": "@lancedb/vectordb-darwin-arm64", - "linux-arm64": "@lancedb/vectordb-linux-arm64-gnu", - "win32-arm64": "@lancedb/vectordb-win32-arm64-msvc", - }[target]; - console.log( - "[info] Downloading pre-built lancedb binary: " + packageToInstall, - ); + if (!skipInstalls) { + // GitHub Actions doesn't support ARM, so we need to download pre-saved binaries + // 02/07/25 - the above comment is out of date, there is now support for ARM runners on GitHub Actions + if (isArmTarget) { + // lancedb binary + const packageToInstall = { + "darwin-arm64": "@lancedb/vectordb-darwin-arm64", + "linux-arm64": "@lancedb/vectordb-linux-arm64-gnu", + "win32-arm64": "@lancedb/vectordb-win32-arm64-msvc", + }[target]; + console.log( + "[info] Downloading pre-built lancedb binary: " + packageToInstall, + ); - await Promise.all([ - copyEsbuild(target), - copySqlite(target), - installAndCopyNodeModules(packageToInstall, "@lancedb"), - ]); - } else { - // Download esbuild from npm in tmp and copy over - console.log("[info] npm installing esbuild binary"); - await installAndCopyNodeModules("esbuild@0.17.19", "@esbuild"); + await Promise.all([ + copyEsbuild(target), + copySqlite(target), + installAndCopyNodeModules(packageToInstall, "@lancedb"), + ]); + } else { + // Download esbuild from npm in tmp and copy over + console.log("[info] npm installing esbuild binary"); + await installAndCopyNodeModules("esbuild@0.17.19", "@esbuild"); + } } console.log("[info] Copying sqlite node binding from core"); diff --git a/scripts/install-dependencies.sh b/scripts/install-dependencies.sh index d92fc109d..092028b37 100755 --- a/scripts/install-dependencies.sh +++ b/scripts/install-dependencies.sh @@ -57,7 +57,7 @@ pushd extensions/vscode # This does way too many things inline but is the common denominator between many of the scripts npm install npm link @continuedev/core -npm run prepackage +# npm run prepackage # not required since npm run package has prescript of prepackage npm run package popd From 6721efc7ffeb9fd97b63a3d5ebed9e742f75e400 Mon Sep 17 00:00:00 2001 From: Nate Date: Fri, 20 Jun 2025 16:06:03 -0700 Subject: [PATCH 24/44] new rules --- .continue/rules/new-protocol-message.md | 35 +++++++++++++++++++++++++ .continue/rules/overeager.md | 5 ++++ core/rules.md | 10 +++++++ 3 files changed, 50 insertions(+) create mode 100644 .continue/rules/new-protocol-message.md create mode 100644 .continue/rules/overeager.md create mode 100644 core/rules.md diff --git a/.continue/rules/new-protocol-message.md b/.continue/rules/new-protocol-message.md new file mode 100644 index 000000000..23c6ba638 --- /dev/null +++ b/.continue/rules/new-protocol-message.md @@ -0,0 +1,35 @@ +--- +name: New protocol message +description: Create a new protocol message from core/gui/ide to core/gui/ide +--- + +Create a new protocol message by taking the following steps: + +## 1. Define the message type + +Add your new message type definition to the appropriate file in the `protocol/` directory with correct TypeScript typing. + +## 2. Check for duplicates + +Verify that no existing message type already provides the same functionality. + +## 3. Add to passThrough (if webview ↔ core) + +If your message is between webview and core, add it to `core/protocol/passThrough.ts`. + +## 4. Add to IntelliJ constants (if webview ↔ core) + +If your message is between webview and core, add it to `extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/constants/MessageTypes.kt`. + +## 5. Implement the message handler + +Implement the message in the appropriate location: + +- **Messages to core**: `core/core.ts` +- **Messages to GUI**: `useWebviewListener` hook +- **Messages to VS Code IDE**: `VsCodeMessenger.ts` +- **Messages to JetBrains IDE**: `IdeProtocolClient.kt` + +## 6. Test the implementation + +Verify that your message works correctly in both VS Code and JetBrains IDEs if applicable. diff --git a/.continue/rules/overeager.md b/.continue/rules/overeager.md new file mode 100644 index 000000000..729088aad --- /dev/null +++ b/.continue/rules/overeager.md @@ -0,0 +1,5 @@ +--- +name: Don't be overeager +--- + +Avoid over-eagerly adding new features. You should solve the problem at hand and then can propose further work. diff --git a/core/rules.md b/core/rules.md new file mode 100644 index 000000000..57c897d3f --- /dev/null +++ b/core/rules.md @@ -0,0 +1,10 @@ +# `core` rules + +Whenever a new protocol message is added to the `protocol/` directory, check the following: + +- It's type is defined correctly +- If it is a message from webview to core or vice versa: + - It has been added to `core/protocol/passThrough.ts` + - It has been added to `extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/constants/MessageTypes.kt` +- It is implemented in either `core/core.ts` (for messages to the core), in a `useWebviewListener` (for messages to the gui), or in `VsCodeMessenger.ts` for VS Code or `IdeProtocolClient.kt` for JetBriains (for messages to the IDE). +- It does not duplicate functionality from another message type that already exists. From b8af0662da16976884b61574dc4d72d01c7987e3 Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Wed, 25 Jun 2025 16:32:52 -0700 Subject: [PATCH 25/44] remove extraneous chatmessage type --- gui/src/context/MockIdeMessenger.ts | 3 +-- gui/src/pages/gui/chat-tests/EditToolScenarios | 0 gui/src/pages/gui/chat-tests/EditToolScenarios.test.tsx | 1 - gui/src/redux/store.ts | 5 ----- 4 files changed, 1 insertion(+), 8 deletions(-) create mode 100644 gui/src/pages/gui/chat-tests/EditToolScenarios delete mode 100644 gui/src/pages/gui/chat-tests/EditToolScenarios.test.tsx diff --git a/gui/src/context/MockIdeMessenger.ts b/gui/src/context/MockIdeMessenger.ts index bc46aebc0..3d9907e68 100644 --- a/gui/src/context/MockIdeMessenger.ts +++ b/gui/src/context/MockIdeMessenger.ts @@ -1,4 +1,4 @@ -import { IDE, PromptLog } from "core"; +import { ChatMessage, IDE, PromptLog } from "core"; import { AuthType } from "core/control-plane/AuthTypes"; import { FromIdeProtocol, @@ -13,7 +13,6 @@ import { GeneratorYieldType, WebviewSingleProtocolMessage, } from "core/protocol/util"; -import { ChatMessage } from "../redux/store"; import { IIdeMessenger } from "./IdeMessenger"; async function defaultMockHandleMessage( diff --git a/gui/src/pages/gui/chat-tests/EditToolScenarios b/gui/src/pages/gui/chat-tests/EditToolScenarios new file mode 100644 index 000000000..e69de29bb diff --git a/gui/src/pages/gui/chat-tests/EditToolScenarios.test.tsx b/gui/src/pages/gui/chat-tests/EditToolScenarios.test.tsx deleted file mode 100644 index 8b1378917..000000000 --- a/gui/src/pages/gui/chat-tests/EditToolScenarios.test.tsx +++ /dev/null @@ -1 +0,0 @@ - diff --git a/gui/src/redux/store.ts b/gui/src/redux/store.ts index 542ee7ffc..10ecdd2e5 100644 --- a/gui/src/redux/store.ts +++ b/gui/src/redux/store.ts @@ -23,11 +23,6 @@ import sessionReducer from "./slices/sessionSlice"; import tabsReducer from "./slices/tabsSlice"; import uiReducer from "./slices/uiSlice"; -export interface ChatMessage { - role: "system" | "user" | "assistant"; - content: string; -} - const rootReducer = combineReducers({ session: sessionReducer, ui: uiReducer, From 15c672c16fbab745b949eae9f0f2d1a8df95192c Mon Sep 17 00:00:00 2001 From: adarshramiyer Date: Wed, 25 Jun 2025 17:48:27 -0700 Subject: [PATCH 26/44] tool usage data schemas --- .../src/schemas/data/toolUsage/index.ts | 10 ++++++++ .../src/schemas/data/toolUsage/v0.2.0.ts | 25 +++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 packages/config-yaml/src/schemas/data/toolUsage/index.ts create mode 100644 packages/config-yaml/src/schemas/data/toolUsage/v0.2.0.ts diff --git a/packages/config-yaml/src/schemas/data/toolUsage/index.ts b/packages/config-yaml/src/schemas/data/toolUsage/index.ts new file mode 100644 index 000000000..25f650218 --- /dev/null +++ b/packages/config-yaml/src/schemas/data/toolUsage/index.ts @@ -0,0 +1,10 @@ +import { z } from "zod"; +import { baseDevDataAllSchema } from "../base.js"; + +export const toolUsageEventAllSchema = baseDevDataAllSchema.extend({ + toolCallId: z.string(), + functionName: z.string(), + functionArgs: z.string(), + parsedArgs: z.any(), + output: z.array(z.any()).optional(), +}); diff --git a/packages/config-yaml/src/schemas/data/toolUsage/v0.2.0.ts b/packages/config-yaml/src/schemas/data/toolUsage/v0.2.0.ts new file mode 100644 index 000000000..445a7311d --- /dev/null +++ b/packages/config-yaml/src/schemas/data/toolUsage/v0.2.0.ts @@ -0,0 +1,25 @@ +import { toolUsageEventAllSchema } from "./index.js"; + +export const toolUsageEventSchema_0_2_0 = toolUsageEventAllSchema.pick({ + // base + timestamp: true, + userId: true, + userAgent: true, + selectedProfileId: true, + eventName: true, + schema: true, + + // tool-usage-specific + toolCallId: true, + functionName: true, + functionArgs: true, + parsedArgs: true, + output: true, +}); + +export const autocompleteEventSchema_0_2_0_noCode = + toolUsageEventSchema_0_2_0.omit({ + functionArgs: true, + parsedArgs: true, + output: true, + }); From 4d47e91f671d669621a7c91df1140c74cc86d4f1 Mon Sep 17 00:00:00 2001 From: Patrick Erichsen Date: Wed, 25 Jun 2025 18:11:15 -0700 Subject: [PATCH 27/44] chore: bump package-lock.json files --- binary/package-lock.json | 6 ++---- extensions/vscode/package-lock.json | 8 ++++---- gui/package-lock.json | 11 ++++++++--- packages/config-yaml/package-lock.json | 4 ++-- 4 files changed, 16 insertions(+), 13 deletions(-) diff --git a/binary/package-lock.json b/binary/package-lock.json index ead2d8b83..aa334d30e 100644 --- a/binary/package-lock.json +++ b/binary/package-lock.json @@ -53,9 +53,9 @@ "@aws-sdk/credential-providers": "^3.778.0", "@continuedev/config-types": "^1.0.13", "@continuedev/config-yaml": "file:../packages/config-yaml", - "@continuedev/fetch": "^1.0.13", + "@continuedev/fetch": "^1.0.14", "@continuedev/llm-info": "^1.0.8", - "@continuedev/openai-adapters": "^1.0.32", + "@continuedev/openai-adapters": "1.0.42", "@modelcontextprotocol/sdk": "^1.12.0", "@mozilla/readability": "^0.5.0", "@octokit/rest": "^20.1.1", @@ -106,7 +106,6 @@ "sqlite3": "^5.1.7", "system-ca": "^1.0.3", "tar": "^7.4.3", - "tree-sitter-structured-text": "^0.0.1", "tree-sitter-wasms": "^0.1.11", "uuid": "^9.0.1", "vectordb": "^0.4.20", @@ -145,7 +144,6 @@ "myers-diff": "^2.1.0", "onnxruntime-common": "1.14.0", "onnxruntime-web": "1.14.0", - "tree-sitter-cli": "^0.22.5", "ts-jest": "^29.1.1", "typescript": "^5.6.3", "vitest": "^3.1.4" diff --git a/extensions/vscode/package-lock.json b/extensions/vscode/package-lock.json index 9ebbad2d0..29de81832 100644 --- a/extensions/vscode/package-lock.json +++ b/extensions/vscode/package-lock.json @@ -1,12 +1,12 @@ { "name": "continue", - "version": "1.1.50", + "version": "1.1.52", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "continue", - "version": "1.1.50", + "version": "1.1.52", "license": "Apache-2.0", "dependencies": { "@continuedev/config-types": "^1.0.14", @@ -108,9 +108,9 @@ "@aws-sdk/credential-providers": "^3.778.0", "@continuedev/config-types": "^1.0.13", "@continuedev/config-yaml": "file:../packages/config-yaml", - "@continuedev/fetch": "^1.0.13", + "@continuedev/fetch": "^1.0.14", "@continuedev/llm-info": "^1.0.8", - "@continuedev/openai-adapters": "file:../packages/openai-adapters", + "@continuedev/openai-adapters": "1.0.42", "@modelcontextprotocol/sdk": "^1.12.0", "@mozilla/readability": "^0.5.0", "@octokit/rest": "^20.1.1", diff --git a/gui/package-lock.json b/gui/package-lock.json index 62eea45da..5cbf9ede7 100644 --- a/gui/package-lock.json +++ b/gui/package-lock.json @@ -114,9 +114,9 @@ "@aws-sdk/credential-providers": "^3.778.0", "@continuedev/config-types": "^1.0.13", "@continuedev/config-yaml": "file:../packages/config-yaml", - "@continuedev/fetch": "^1.0.13", + "@continuedev/fetch": "^1.0.14", "@continuedev/llm-info": "^1.0.8", - "@continuedev/openai-adapters": "file:../packages/openai-adapters", + "@continuedev/openai-adapters": "1.0.42", "@modelcontextprotocol/sdk": "^1.12.0", "@mozilla/readability": "^0.5.0", "@octokit/rest": "^20.1.1", @@ -215,7 +215,7 @@ }, "../packages/config-yaml": { "name": "@continuedev/config-yaml", - "version": "1.0.94", + "version": "1.0.95", "license": "Apache-2.0", "dependencies": { "@continuedev/config-types": "^1.0.14", @@ -226,10 +226,15 @@ "config-yaml": "dist/cli.js" }, "devDependencies": { + "@semantic-release/changelog": "^6.0.3", + "@semantic-release/git": "^10.0.1", + "@semantic-release/github": "^9.2.6", + "@semantic-release/npm": "^10.0.6", "@types/jest": "^29.5.14", "@types/node": "^20.0.0", "cross-env": "^7.0.3", "jest": "^29.7.0", + "semantic-release": "^21.1.2", "ts-jest": "^29.2.3", "ts-node": "^10.9.2", "zod-to-json-schema": "^3.24.5" diff --git a/packages/config-yaml/package-lock.json b/packages/config-yaml/package-lock.json index 7f2b8b2f2..014ecac95 100644 --- a/packages/config-yaml/package-lock.json +++ b/packages/config-yaml/package-lock.json @@ -1,12 +1,12 @@ { "name": "@continuedev/config-yaml", - "version": "1.0.94", + "version": "1.0.95", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@continuedev/config-yaml", - "version": "1.0.94", + "version": "1.0.95", "license": "Apache-2.0", "dependencies": { "@continuedev/config-types": "^1.0.14", From 9b4ec0a3a4de319fa2d148146c7e852489ba55b0 Mon Sep 17 00:00:00 2001 From: adarshramiyer Date: Wed, 25 Jun 2025 18:30:26 -0700 Subject: [PATCH 28/44] finished out tool usage dev data logging --- gui/src/redux/slices/sessionSlice.ts | 23 +++++++++++++++++++ .../config-yaml/src/schemas/data/index.ts | 8 +++++++ .../src/schemas/data/toolUsage/index.ts | 1 + .../src/schemas/data/toolUsage/v0.2.0.ts | 3 ++- 4 files changed, 34 insertions(+), 1 deletion(-) diff --git a/gui/src/redux/slices/sessionSlice.ts b/gui/src/redux/slices/sessionSlice.ts index 6803947fb..50ff37320 100644 --- a/gui/src/redux/slices/sessionSlice.ts +++ b/gui/src/redux/slices/sessionSlice.ts @@ -18,7 +18,9 @@ import { RuleWithSource, Session, SessionMetadata, + ToolCallState, } from "core"; +import { safeParseToolCallArgs } from "core/tools/parseArgs"; import { NEW_SESSION_TITLE } from "core/util/constants"; import { renderChatMessage } from "core/util/messageContent"; import { findUriInDirs, getUriPathBasename } from "core/util/uri"; @@ -28,6 +30,25 @@ import { RootState } from "../store"; import { streamResponseThunk } from "../thunks/streamResponse"; import { findCurrentToolCall, findToolCall } from "../util"; +const getIdeMessenger = () => (window as any).ideMessenger; + +const logToolUsage = (toolCallState: ToolCallState, success: boolean) => { + const ideMessenger = getIdeMessenger(); + if (ideMessenger) { + ideMessenger.post("devdata/log", { + name: "toolUsage", + data: { + toolCallId: toolCallState.toolCallId, + functionName: toolCallState.toolCall.function.name, + functionArgs: toolCallState.toolCall.function.arguments, + parsedArgs: safeParseToolCallArgs(toolCallState.toolCall), + succeeded: success, + output: toolCallState.output || [], + }, + }); + } +}; + // We need this to handle reorderings (e.g. a mid-array deletion) of the messages array. // The proper fix is adding a UUID to all chat messages, but this is the temp workaround. export type ChatHistoryItemWithMessageId = ChatHistoryItem & { @@ -559,6 +580,7 @@ export const sessionSlice = createSlice({ ); if (toolCallState) { toolCallState.status = "errored"; + logToolUsage(toolCallState, false); } }, acceptToolCall: ( @@ -573,6 +595,7 @@ export const sessionSlice = createSlice({ ); if (toolCallState) { toolCallState.status = "done"; + logToolUsage(toolCallState, true); } }, setToolCallCalling: ( diff --git a/packages/config-yaml/src/schemas/data/index.ts b/packages/config-yaml/src/schemas/data/index.ts index 7251e12a7..679227c52 100644 --- a/packages/config-yaml/src/schemas/data/index.ts +++ b/packages/config-yaml/src/schemas/data/index.ts @@ -42,6 +42,11 @@ import { tokensGeneratedEventSchema_0_2_0, tokensGeneratedEventSchema_0_2_0_noCode, } from "./tokensGenerated/v0.2.0.js"; +import { toolUsageEventAllSchema } from "./toolUsage/index.js"; +import { + toolUsageEventSchema_0_2_0, + toolUsageEventSchema_0_2_0_noCode, +} from "./toolUsage/v0.2.0.js"; const semverRegex = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9A-Za-z-][0-9A-Za-z-]*)(?:\.(?:0|[1-9A-Za-z-][0-9A-Za-z-]*))*))?(?:\+([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?$/; @@ -72,6 +77,7 @@ const devEventAllVersionDataSchemas = z.object({ tokensGenerated: tokensGeneratedEventAllSchema, chatInteraction: chatInteractionEventAllSchema, editInteraction: editInteractionEventAllSchema, + toolUsage: toolUsageEventAllSchema, }); // Version and level specific schemas are organized here @@ -97,6 +103,7 @@ export const devDataVersionedSchemas = { tokensGenerated: tokensGeneratedEventSchema_0_2_0, chatInteraction: chatInteractionEventSchema_0_2_0, editInteraction: editInteractionEventSchema_0_2_0, + toolUsage: toolUsageEventSchema_0_2_0, }, noCode: { autocomplete: autocompleteEventSchema_0_2_0_noCode, @@ -104,6 +111,7 @@ export const devDataVersionedSchemas = { tokensGenerated: tokensGeneratedEventSchema_0_2_0_noCode, chatInteraction: chatInteractionEventSchema_0_2_0_noCode, editInteraction: editInteractionEventSchema_0_2_0_noCode, + toolUsage: toolUsageEventSchema_0_2_0_noCode, }, }, }; diff --git a/packages/config-yaml/src/schemas/data/toolUsage/index.ts b/packages/config-yaml/src/schemas/data/toolUsage/index.ts index 25f650218..8119366f3 100644 --- a/packages/config-yaml/src/schemas/data/toolUsage/index.ts +++ b/packages/config-yaml/src/schemas/data/toolUsage/index.ts @@ -6,5 +6,6 @@ export const toolUsageEventAllSchema = baseDevDataAllSchema.extend({ functionName: z.string(), functionArgs: z.string(), parsedArgs: z.any(), + succeeded: z.boolean(), output: z.array(z.any()).optional(), }); diff --git a/packages/config-yaml/src/schemas/data/toolUsage/v0.2.0.ts b/packages/config-yaml/src/schemas/data/toolUsage/v0.2.0.ts index 445a7311d..533e33218 100644 --- a/packages/config-yaml/src/schemas/data/toolUsage/v0.2.0.ts +++ b/packages/config-yaml/src/schemas/data/toolUsage/v0.2.0.ts @@ -14,10 +14,11 @@ export const toolUsageEventSchema_0_2_0 = toolUsageEventAllSchema.pick({ functionName: true, functionArgs: true, parsedArgs: true, + succeeded: true, output: true, }); -export const autocompleteEventSchema_0_2_0_noCode = +export const toolUsageEventSchema_0_2_0_noCode = toolUsageEventSchema_0_2_0.omit({ functionArgs: true, parsedArgs: true, From e3dc391c052cbe18112640639264d726939cce02 Mon Sep 17 00:00:00 2001 From: Nate Date: Wed, 25 Jun 2025 18:42:34 -0700 Subject: [PATCH 29/44] build.sh and build.ps1 to build packages in CI --- .github/workflows/main.yaml | 8 ++++++++ build.ps1 | 13 +++++++++++++ build.sh | 13 +++++++++++++ core/package.json | 2 +- 4 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 build.ps1 create mode 100644 build.sh diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 0c300bf17..7f8411041 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -104,6 +104,14 @@ jobs: path: gui/node_modules key: ${{ runner.os }}-node-${{ hashFiles('gui/package-lock.json') }} + - name: Build packages (Windows) + run: build.ps1 + if: matrix.os == 'windows-latest' + + - name: Build packages (Unix) + run: ./build.sh + if: matrix.os != 'windows-latest' + - name: Install extension Dependencies run: | cd extensions/vscode diff --git a/build.ps1 b/build.ps1 new file mode 100644 index 000000000..cd415b3df --- /dev/null +++ b/build.ps1 @@ -0,0 +1,13 @@ +Push-Location packages + +Push-Location "openai-adapters" +npm ci +npm run build +Pop-Location + +Push-Location "config-yaml" +npm ci +npm run build +Pop-Location + +Pop-Location \ No newline at end of file diff --git a/build.sh b/build.sh new file mode 100644 index 000000000..fa6f62731 --- /dev/null +++ b/build.sh @@ -0,0 +1,13 @@ +# Build @continuedev packages for monorepo style linking + +cd packages +cd openai-adapters + +npm ci +npm run build + +cd .. +cd config-yaml + +npm ci +npm run build diff --git a/core/package.json b/core/package.json index 26278e318..df74064a8 100644 --- a/core/package.json +++ b/core/package.json @@ -53,7 +53,7 @@ "@continuedev/config-yaml": "file:../packages/config-yaml", "@continuedev/fetch": "^1.0.14", "@continuedev/llm-info": "^1.0.8", - "@continuedev/openai-adapters": "1.0.42", + "@continuedev/openai-adapters": "file:../packages/openai-adapters", "@modelcontextprotocol/sdk": "^1.12.0", "@mozilla/readability": "^0.5.0", "@octokit/rest": "^20.1.1", From 9d5d7e40a48ed9fbc9edf8b67619f96f3c704930 Mon Sep 17 00:00:00 2001 From: Nate Date: Wed, 25 Jun 2025 18:44:42 -0700 Subject: [PATCH 30/44] i --- core/package-lock.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/package-lock.json b/core/package-lock.json index 4c7419178..6fed1b052 100644 --- a/core/package-lock.json +++ b/core/package-lock.json @@ -16,7 +16,7 @@ "@continuedev/config-yaml": "file:../packages/config-yaml", "@continuedev/fetch": "^1.0.14", "@continuedev/llm-info": "^1.0.8", - "@continuedev/openai-adapters": "1.0.42", + "@continuedev/openai-adapters": "file:../packages/openai-adapters", "@modelcontextprotocol/sdk": "^1.12.0", "@mozilla/readability": "^0.5.0", "@octokit/rest": "^20.1.1", From cc05643684d6f508e68a36e4e88016c94e005580 Mon Sep 17 00:00:00 2001 From: Patrick Erichsen Date: Wed, 25 Jun 2025 19:16:36 -0700 Subject: [PATCH 31/44] chore: update preview.yaml with package build logic --- .github/workflows/main.yaml | 4 ++-- .github/workflows/preview.yaml | 8 ++++++++ extensions/vscode/package-lock.json | 2 +- gui/package-lock.json | 2 +- build.ps1 => scripts/build-packages.ps1 | 0 build.sh => scripts/build-packages.sh | 0 6 files changed, 12 insertions(+), 4 deletions(-) rename build.ps1 => scripts/build-packages.ps1 (100%) rename build.sh => scripts/build-packages.sh (100%) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 7f8411041..ce1e59e66 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -105,11 +105,11 @@ jobs: key: ${{ runner.os }}-node-${{ hashFiles('gui/package-lock.json') }} - name: Build packages (Windows) - run: build.ps1 + run: ./scripts/build-packages.ps1 if: matrix.os == 'windows-latest' - name: Build packages (Unix) - run: ./build.sh + run: ./scripts/build-packages.sh if: matrix.os != 'windows-latest' - name: Install extension Dependencies diff --git a/.github/workflows/preview.yaml b/.github/workflows/preview.yaml index 19dafeb41..3ef4920ed 100644 --- a/.github/workflows/preview.yaml +++ b/.github/workflows/preview.yaml @@ -99,6 +99,14 @@ jobs: path: gui/node_modules key: ${{ runner.os }}-node-${{ hashFiles('gui/package-lock.json') }} + - name: Build packages (Windows) + run: ./scripts/build-packages.ps1 + if: matrix.os == 'windows-latest' + + - name: Build packages (Unix) + run: ./scripts/build-packages.sh + if: matrix.os != 'windows-latest' + - name: Install extension Dependencies run: | cd extensions/vscode diff --git a/extensions/vscode/package-lock.json b/extensions/vscode/package-lock.json index 29de81832..7e3e3ff06 100644 --- a/extensions/vscode/package-lock.json +++ b/extensions/vscode/package-lock.json @@ -110,7 +110,7 @@ "@continuedev/config-yaml": "file:../packages/config-yaml", "@continuedev/fetch": "^1.0.14", "@continuedev/llm-info": "^1.0.8", - "@continuedev/openai-adapters": "1.0.42", + "@continuedev/openai-adapters": "file:../packages/openai-adapters", "@modelcontextprotocol/sdk": "^1.12.0", "@mozilla/readability": "^0.5.0", "@octokit/rest": "^20.1.1", diff --git a/gui/package-lock.json b/gui/package-lock.json index 5cbf9ede7..873415983 100644 --- a/gui/package-lock.json +++ b/gui/package-lock.json @@ -116,7 +116,7 @@ "@continuedev/config-yaml": "file:../packages/config-yaml", "@continuedev/fetch": "^1.0.14", "@continuedev/llm-info": "^1.0.8", - "@continuedev/openai-adapters": "1.0.42", + "@continuedev/openai-adapters": "file:../packages/openai-adapters", "@modelcontextprotocol/sdk": "^1.12.0", "@mozilla/readability": "^0.5.0", "@octokit/rest": "^20.1.1", diff --git a/build.ps1 b/scripts/build-packages.ps1 similarity index 100% rename from build.ps1 rename to scripts/build-packages.ps1 diff --git a/build.sh b/scripts/build-packages.sh similarity index 100% rename from build.sh rename to scripts/build-packages.sh From 0803fe7c258f4dd27be717b473f4e864d88a7a95 Mon Sep 17 00:00:00 2001 From: Patrick Erichsen Date: Wed, 25 Jun 2025 19:19:43 -0700 Subject: [PATCH 32/44] Update package-lock.json --- binary/package-lock.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/binary/package-lock.json b/binary/package-lock.json index aa334d30e..11eaadc8a 100644 --- a/binary/package-lock.json +++ b/binary/package-lock.json @@ -55,7 +55,7 @@ "@continuedev/config-yaml": "file:../packages/config-yaml", "@continuedev/fetch": "^1.0.14", "@continuedev/llm-info": "^1.0.8", - "@continuedev/openai-adapters": "1.0.42", + "@continuedev/openai-adapters": "file:../packages/openai-adapters", "@modelcontextprotocol/sdk": "^1.12.0", "@mozilla/readability": "^0.5.0", "@octokit/rest": "^20.1.1", From f75f0d253c30641bce6e62139768e3298b3f7aba Mon Sep 17 00:00:00 2001 From: Patrick Erichsen Date: Wed, 25 Jun 2025 21:50:37 -0700 Subject: [PATCH 33/44] chore: execute permission on build scripts --- scripts/build-packages.ps1 | 0 scripts/build-packages.sh | 0 2 files changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 scripts/build-packages.ps1 mode change 100644 => 100755 scripts/build-packages.sh diff --git a/scripts/build-packages.ps1 b/scripts/build-packages.ps1 old mode 100644 new mode 100755 diff --git a/scripts/build-packages.sh b/scripts/build-packages.sh old mode 100644 new mode 100755 From 5116eb2d92557d7a890dfc1bdf05a5d5a1047d0a Mon Sep 17 00:00:00 2001 From: uinstinct <61635505+uinstinct@users.noreply.github.com> Date: Thu, 26 Jun 2025 19:15:38 +0530 Subject: [PATCH 34/44] prevent focus out on mod backspace in chat area --- gui/src/pages/gui/Chat.tsx | 10 +++++----- gui/src/util/index.ts | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/gui/src/pages/gui/Chat.tsx b/gui/src/pages/gui/Chat.tsx index 4a6d33849..6444dcb86 100644 --- a/gui/src/pages/gui/Chat.tsx +++ b/gui/src/pages/gui/Chat.tsx @@ -42,12 +42,12 @@ import { setDialogMessage, setShowDialog, } from "../../redux/slices/uiSlice"; -import { cancelStream } from "../../redux/thunks/cancelStream"; import { streamEditThunk } from "../../redux/thunks/edit"; import { loadLastSession } from "../../redux/thunks/session"; import { streamResponseThunk } from "../../redux/thunks/streamResponse"; import { isJetBrains, isMetaEquivalentKeyPressed } from "../../util"; +import { cancelStream } from "../../redux/thunks/cancelStream"; import { getLocalStorage, setLocalStorage } from "../../util/localStorage"; import { EmptyChatBody } from "./EmptyChatBody"; import { ExploreDialogWatcher } from "./ExploreDialogWatcher"; @@ -125,14 +125,14 @@ export function Chat() { useEffect(() => { // Cmd + Backspace to delete current step - const listener = (e: any) => { + const listener = (e: KeyboardEvent) => { if ( e.key === "Backspace" && (jetbrains ? e.altKey : isMetaEquivalentKeyPressed(e)) && !e.shiftKey ) { - dispatch(cancelStream()); - ideMessenger.post("rejectDiff", {}); // just always cancel, if not in applying won't matter + void dispatch(cancelStream()); + if (isInEdit) ideMessenger.post("rejectDiff", {}); } }; window.addEventListener("keydown", listener); @@ -140,7 +140,7 @@ export function Chat() { return () => { window.removeEventListener("keydown", listener); }; - }, [isStreaming, jetbrains]); + }, [isStreaming, jetbrains, isInEdit]); const { widget, highlights } = useFindWidget( stepsDivRef, diff --git a/gui/src/util/index.ts b/gui/src/util/index.ts index ccb1be1e6..dc581b51b 100644 --- a/gui/src/util/index.ts +++ b/gui/src/util/index.ts @@ -1,12 +1,12 @@ import { MessageModes, ModelDescription } from "core"; import { ProfileDescription } from "core/config/ProfileLifecycleManager"; -import _ from "lodash"; -import { KeyboardEvent } from "react"; -import { getLocalStorage } from "./localStorage"; import { - DEFAULT_CHAT_SYSTEM_MESSAGE, DEFAULT_AGENT_SYSTEM_MESSAGE, + DEFAULT_CHAT_SYSTEM_MESSAGE, } from "core/llm/constructMessages"; +import _ from "lodash"; +import { KeyboardEvent as ReactKeyboardEvent } from "react"; +import { getLocalStorage } from "./localStorage"; export type Platform = "mac" | "linux" | "windows" | "unknown"; @@ -26,7 +26,7 @@ export function getPlatform(): Platform { export function isMetaEquivalentKeyPressed({ metaKey, ctrlKey, -}: KeyboardEvent): boolean { +}: KeyboardEvent | ReactKeyboardEvent): boolean { const platform = getPlatform(); switch (platform) { case "mac": From 7c516f74689c17d0ac59d6e39c82dc7e0c659cdf Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Thu, 26 Jun 2025 10:32:50 -0700 Subject: [PATCH 35/44] chat integration tests --- extensions/vscode/package-lock.json | 6 +- gui/package-lock.json | 9 +- .../StepContainerPreToolbar/index.tsx | 1 + .../StyledMarkdownPreview/index.tsx | 23 ++- .../TipTapEditor/utils/editorConfig.ts | 4 +- gui/src/context/MockIdeMessenger.ts | 169 +++++++++------- gui/src/hooks/ParallelListeners.tsx | 69 +++++-- gui/src/pages/gui/Chat.test.tsx | 95 --------- gui/src/pages/gui/ToolCallDiv/EditFile.tsx | 27 +-- .../gui/chat-tests/ApplyScenarios.test.tsx | 50 ++--- gui/src/pages/gui/chat-tests/Chat.test.tsx | 61 ++++++ .../pages/gui/chat-tests/EditToolScenarios | 0 .../gui/chat-tests/EditToolScenarios.test.tsx | 180 ++++++++++++++++++ gui/src/pages/gui/chat-tests/utils.ts | 102 ++++++++++ gui/src/redux/slices/sessionSlice.ts | 4 +- gui/src/redux/thunks/callCurrentTool.ts | 5 +- gui/src/util/clientTools/editImpl.ts | 18 +- gui/src/util/test/config.ts | 44 ++--- gui/vite.config.ts | 13 ++ packages/config-yaml/package-lock.json | 4 +- 20 files changed, 582 insertions(+), 302 deletions(-) delete mode 100644 gui/src/pages/gui/Chat.test.tsx create mode 100644 gui/src/pages/gui/chat-tests/Chat.test.tsx delete mode 100644 gui/src/pages/gui/chat-tests/EditToolScenarios create mode 100644 gui/src/pages/gui/chat-tests/EditToolScenarios.test.tsx create mode 100644 gui/src/pages/gui/chat-tests/utils.ts diff --git a/extensions/vscode/package-lock.json b/extensions/vscode/package-lock.json index 9ebbad2d0..7c2c71f46 100644 --- a/extensions/vscode/package-lock.json +++ b/extensions/vscode/package-lock.json @@ -1,12 +1,12 @@ { "name": "continue", - "version": "1.1.50", + "version": "1.1.51", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "continue", - "version": "1.1.50", + "version": "1.1.51", "license": "Apache-2.0", "dependencies": { "@continuedev/config-types": "^1.0.14", @@ -108,7 +108,7 @@ "@aws-sdk/credential-providers": "^3.778.0", "@continuedev/config-types": "^1.0.13", "@continuedev/config-yaml": "file:../packages/config-yaml", - "@continuedev/fetch": "^1.0.13", + "@continuedev/fetch": "^1.0.14", "@continuedev/llm-info": "^1.0.8", "@continuedev/openai-adapters": "file:../packages/openai-adapters", "@modelcontextprotocol/sdk": "^1.12.0", diff --git a/gui/package-lock.json b/gui/package-lock.json index 62eea45da..873415983 100644 --- a/gui/package-lock.json +++ b/gui/package-lock.json @@ -114,7 +114,7 @@ "@aws-sdk/credential-providers": "^3.778.0", "@continuedev/config-types": "^1.0.13", "@continuedev/config-yaml": "file:../packages/config-yaml", - "@continuedev/fetch": "^1.0.13", + "@continuedev/fetch": "^1.0.14", "@continuedev/llm-info": "^1.0.8", "@continuedev/openai-adapters": "file:../packages/openai-adapters", "@modelcontextprotocol/sdk": "^1.12.0", @@ -215,7 +215,7 @@ }, "../packages/config-yaml": { "name": "@continuedev/config-yaml", - "version": "1.0.94", + "version": "1.0.95", "license": "Apache-2.0", "dependencies": { "@continuedev/config-types": "^1.0.14", @@ -226,10 +226,15 @@ "config-yaml": "dist/cli.js" }, "devDependencies": { + "@semantic-release/changelog": "^6.0.3", + "@semantic-release/git": "^10.0.1", + "@semantic-release/github": "^9.2.6", + "@semantic-release/npm": "^10.0.6", "@types/jest": "^29.5.14", "@types/node": "^20.0.0", "cross-env": "^7.0.3", "jest": "^29.7.0", + "semantic-release": "^21.1.2", "ts-jest": "^29.2.3", "ts-node": "^10.9.2", "zod-to-json-schema": "^3.24.5" diff --git a/gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/index.tsx b/gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/index.tsx index 0dd4ec7e8..a45fa18ba 100644 --- a/gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/index.tsx +++ b/gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/index.tsx @@ -293,6 +293,7 @@ export function StepContainerPreToolbar({
setIsExpanded(!isExpanded)} className={`text-lightgray h-3.5 w-3.5 flex-shrink-0 cursor-pointer hover:brightness-125 ${ isExpanded ? "rotate-0" : "-rotate-90" diff --git a/gui/src/components/StyledMarkdownPreview/index.tsx b/gui/src/components/StyledMarkdownPreview/index.tsx index 1d31852c7..bb286004f 100644 --- a/gui/src/components/StyledMarkdownPreview/index.tsx +++ b/gui/src/components/StyledMarkdownPreview/index.tsx @@ -15,6 +15,7 @@ import { import useUpdatingRef from "../../hooks/useUpdatingRef"; import { useAppSelector } from "../../redux/hooks"; import { selectUIConfig } from "../../redux/slices/configSlice"; +import { selectApplyStateByToolCallId } from "../../redux/slices/sessionSlice"; import { getContextItemsFromHistory } from "../../redux/thunks/updateFileSymbols"; import { getFontSize } from "../../util"; import { ToolTip } from "../gui/Tooltip"; @@ -126,7 +127,7 @@ interface StyledMarkdownPreviewProps { itemIndex?: number; useParentBackgroundColor?: boolean; disableManualApply?: boolean; - forceStreamId?: string; + toolCallId?: string; expandCodeblocks?: boolean; } @@ -196,11 +197,15 @@ const StyledMarkdownPreview = memo(function StyledMarkdownPreview( const itemIndexRef = useUpdatingRef(props.itemIndex); const codeblockStreamIds = useRef([]); - useEffect(() => { - if (props.forceStreamId) { - codeblockStreamIds.current = [props.forceStreamId]; - } - }, [props.forceStreamId, codeblockStreamIds]); + const toolCallApplyState = useAppSelector((state) => + selectApplyStateByToolCallId(state, props.toolCallId), + ); + const toolCallApplyStateRef = useUpdatingRef(toolCallApplyState); + // useEffect(() => { + // if (toolCallApplyState) { + // codeblockStreamIds.current = Array(1toolCallApplyState.streamId.repeat(); + // } + // }, [toolCallApplyState, codeblockStreamIds]); const [reactContent, setMarkdownSource] = useRemark({ remarkPlugins: [ @@ -294,9 +299,11 @@ const StyledMarkdownPreview = memo(function StyledMarkdownPreview( const isLastCodeblock = preChildProps["data-islastcodeblock"]; - if (codeblockStreamIds.current[codeBlockIndex] === undefined) { + if (toolCallApplyStateRef.current) { codeblockStreamIds.current[codeBlockIndex] = - props.forceStreamId ?? uuidv4(); + toolCallApplyStateRef.current.streamId; + } else { + codeblockStreamIds.current[codeBlockIndex] = uuidv4(); } return ( diff --git a/gui/src/components/mainInput/TipTapEditor/utils/editorConfig.ts b/gui/src/components/mainInput/TipTapEditor/utils/editorConfig.ts index d6ce9d2bd..be1c61dd7 100644 --- a/gui/src/components/mainInput/TipTapEditor/utils/editorConfig.ts +++ b/gui/src/components/mainInput/TipTapEditor/utils/editorConfig.ts @@ -330,7 +330,9 @@ export function createEditorConfig(options: { ], editorProps: { attributes: { - "data-testid": `editor-input-${props.isMainInput ? "main" : props.inputId}`, + "data-testid": props.isMainInput + ? "editor-input-main" + : `editor-input-${props.inputId}`, class: "ProseMirror outline-none overflow-hidden", style: `font-size: ${getFontSize()}px;`, }, diff --git a/gui/src/context/MockIdeMessenger.ts b/gui/src/context/MockIdeMessenger.ts index 3d9907e68..d79e479be 100644 --- a/gui/src/context/MockIdeMessenger.ts +++ b/gui/src/context/MockIdeMessenger.ts @@ -1,7 +1,6 @@ import { ChatMessage, IDE, PromptLog } from "core"; import { AuthType } from "core/control-plane/AuthTypes"; import { - FromIdeProtocol, FromWebviewProtocol, ToCoreProtocol, ToWebviewProtocol, @@ -15,70 +14,84 @@ import { } from "core/protocol/util"; import { IIdeMessenger } from "./IdeMessenger"; -async function defaultMockHandleMessage( - messageType: T, - data: FromWebviewProtocol[T][0], -): Promise { - function returnFor( - _: K, - value: FromWebviewProtocol[K][1], - ): FromWebviewProtocol[T][1] { - return value as unknown as FromWebviewProtocol[T][1]; - } +type MockResponses = Partial<{ + [K in keyof FromWebviewProtocol]: FromWebviewProtocol[K][1]; +}>; - switch (messageType) { - case "history/list": - return returnFor("history/list", [ - { - title: "Session 1", - sessionId: "session-1", - dateCreated: new Date().toString(), - workspaceDirectory: "/tmp", - }, - ]); - case "getControlPlaneSessionInfo": - return returnFor("getControlPlaneSessionInfo", { - AUTH_TYPE: AuthType.WorkOsStaging, - accessToken: "", - account: { - label: "", - id: "", - }, - }); - case "config/getSerializedProfileInfo": - return returnFor("config/getSerializedProfileInfo", { - organizations: [], - profileId: "test-profile", - result: { - config: undefined, - errors: [], - configLoadInterrupted: false, - }, - selectedOrgId: "local", - }); - default: - throw new Error(`Unknown message type ${messageType}`); - } -} +const DEFAULT_MOCK_CORE_RESPONSES: MockResponses = { + fileExists: true, + getCurrentFile: { + isUntitled: false, + contents: "Current file contents", + path: "file:///Users/user/workspace1/current_file.py", + }, + "controlPlane/getFreeTrialStatus": { + autocompleteLimit: 1000, + optedInToFreeTrial: false, + chatLimit: 1000, + autocompleteCount: 0, + chatCount: 0, + }, + getWorkspaceDirs: [ + "file:///Users/user/workspace1", + "file:///Users/user/workspace2", + ], + "history/list": [ + { + title: "Session 1", + sessionId: "session-1", + dateCreated: new Date().toString(), + workspaceDirectory: "/tmp", + }, + ], + "history/save": undefined, + getControlPlaneSessionInfo: { + AUTH_TYPE: AuthType.WorkOsStaging, + accessToken: "", + account: { + label: "", + id: "", + }, + }, + "config/getSerializedProfileInfo": { + organizations: [], + profileId: "test-profile", + result: { + config: undefined, + errors: [], + configLoadInterrupted: false, + }, + selectedOrgId: "local", + }, + "chatDescriber/describe": "Session summary", + applyToFile: undefined, +}; +const DEFAULT_CHAT_RESPONSE: ChatMessage[] = [ + { + role: "assistant", + content: "This is a test", + }, +]; export class MockIdeMessenger implements IIdeMessenger { ide: IDE; - private messageHandlers: Map< - keyof FromIdeProtocol, - Array<(data: any) => void> - > = new Map(); + // private messageHandlers: Map< + // keyof FromIdeProtocol, + // Array<(data: any) => void> + // > = new Map(); constructor() { this.ide = new MessageIde( - (messageType, data) => { - throw new Error("Not implemented"); + async (messageType, data) => { + const response = await this.request.bind(this)(messageType, data); + if (response.status === "error") { + throw new Error(response.error); + } else { + return response.content; + } }, (messageType, callback) => { - // Store the callback in our handlers map - if (!this.messageHandlers.has(messageType)) { - this.messageHandlers.set(messageType, []); - } - this.messageHandlers.get(messageType)?.push(callback); + return; }, ); } @@ -108,16 +121,17 @@ export class MockIdeMessenger implements IIdeMessenger { ); } - // Ability to customize the response for llmStreamChat - chatResponse: ChatMessage[][] = [ - [ + responses: MockResponses = { ...DEFAULT_MOCK_CORE_RESPONSES }; + chatResponse: ChatMessage[] = DEFAULT_CHAT_RESPONSE; + chatStreamDelay: number = 0; + setChatResponseText(text: string): void { + this.chatResponse = [ { role: "assistant", - content: "This is a test", + content: text, }, - ], - ]; - chatStreamDelay: number = 0; + ]; + } async *llmStreamChat( msg: ToCoreProtocol["llm/streamChat"][0], @@ -128,8 +142,11 @@ export class MockIdeMessenger implements IIdeMessenger { console.log("MockIdeMessenger: Stream aborted"); return undefined; } - console.log("MockIdeMessenger: Yielding chunk", response); - yield response; + console.log( + "MockIdeMessenger: Yielding chunk", + JSON.stringify(response, null, 2), + ); + yield [response]; if (this.chatStreamDelay > 0) { await new Promise((resolve) => setTimeout(resolve, this.chatStreamDelay), @@ -150,12 +167,16 @@ export class MockIdeMessenger implements IIdeMessenger { messageType: T, data: FromWebviewProtocol[T][0], ): Promise> { - const content = await defaultMockHandleMessage(messageType, data); - return { - status: "success", - content, - done: true, - }; + if (messageType in this.responses) { + const content = this.responses[messageType]; + return { + status: "success", + content, + done: true, + }; + } + console.error(messageType); + throw new Error("MockIdeMessenger: No response defined for " + messageType); } respond( @@ -174,4 +195,10 @@ export class MockIdeMessenger implements IIdeMessenger { > { return undefined; } + + resetMocks(): void { + this.responses = { ...DEFAULT_MOCK_CORE_RESPONSES }; + this.chatResponse = DEFAULT_CHAT_RESPONSE; + this.chatStreamDelay = 0; + } } diff --git a/gui/src/hooks/ParallelListeners.tsx b/gui/src/hooks/ParallelListeners.tsx index 5bf2c977a..109e6b52b 100644 --- a/gui/src/hooks/ParallelListeners.tsx +++ b/gui/src/hooks/ParallelListeners.tsx @@ -20,6 +20,8 @@ import { import { acceptToolCall, addContextItemsAtIndex, + cancelToolCall, + selectCurrentToolCall, setHasReasoningEnabled, updateApplyState, } from "../redux/slices/sessionSlice"; @@ -244,6 +246,10 @@ function ParallelListeners() { dispatch(updateIndexingStatus(data)); }); + const autoAcceptEditToolDiffs = useAppSelector( + (store) => store.config.config.ui?.autoAcceptEditToolDiffs, + ); + const currentToolCall = useAppSelector(selectCurrentToolCall); useWebviewListener( "updateApplyState", async (state) => { @@ -258,31 +264,58 @@ function ParallelListeners() { dispatch(updateApplyState(state)); // Handle apply status updates that are associated with current tool call + console.log( + "WALLAH", + currentToolCall, + currentToolCallApplyState, + state, + ); if ( - state.status === "closed" && currentToolCallApplyState && currentToolCallApplyState.streamId === state.streamId ) { - // const output: ContextItem = { - // name: "Edit tool output", - // content: "Completed edit", - // description: "", - // }; - dispatch( - acceptToolCall({ - toolCallId: currentToolCallApplyState.toolCallId!, - }), - ); - // dispatch(setToolCallOutput([])); - void dispatch( - streamResponseAfterToolCall({ - toolCallId: currentToolCallApplyState.toolCallId!, - }), - ); + if (state.status === "done" && autoAcceptEditToolDiffs) { + const out = await ideMessenger.request("acceptDiff", { + streamId: state.streamId, + filepath: state.filepath, + }); + if (out.status === "error") { + dispatch( + cancelToolCall({ + toolCallId: currentToolCallApplyState.toolCallId!, + }), + ); + } + } + if (state.status === "closed") { + if (currentToolCall?.status !== "canceled") { + dispatch( + acceptToolCall({ + toolCallId: currentToolCallApplyState.toolCallId!, + }), + ); + } + // const output: ContextItem = { + // name: "Edit tool output", + // content: "Completed edit", + // description: "", + // }; + // dispatch(setToolCallOutput([])); + void dispatch( + streamResponseAfterToolCall({ + toolCallId: currentToolCallApplyState.toolCallId!, + }), + ); + } } } }, - [currentToolCallApplyState, history], + [ + currentToolCall, + currentToolCallApplyState, + autoAcceptEditToolDiffs, + ideMessenger, + ], ); useEffect(() => { diff --git a/gui/src/pages/gui/Chat.test.tsx b/gui/src/pages/gui/Chat.test.tsx deleted file mode 100644 index 27a1fe8a1..000000000 --- a/gui/src/pages/gui/Chat.test.tsx +++ /dev/null @@ -1,95 +0,0 @@ -import { screen, waitFor } from "@testing-library/dom"; -import { act } from "@testing-library/react"; -import { Editor } from "@tiptap/core"; -import { addAndSelectMockLlm } from "../../util/test/config"; -import { renderWithProviders } from "../../util/test/render"; -import { Chat } from "./Chat"; - -export async function getMainEditor(): Promise { - const editorElement = await waitFor(() => - screen.findByTestId("editor-input-main"), - ); - expect(editorElement).toBeInTheDocument(); - if ("editor" in editorElement) { - return editorElement.editor as Editor; - } else { - throw new Error("Main editor not found within editor container"); - } -} - -test("should render input box", async () => { - await renderWithProviders(); - expect(await screen.findByTestId("continue-input-box")).toBeInTheDocument(); -}); - -test("should be able to toggle modes", async () => { - await renderWithProviders(); - expect(screen.getByText("Chat")).toBeInTheDocument(); - - // Simulate cmd+. keyboard shortcut to toggle modes - act(() => { - document.dispatchEvent( - new KeyboardEvent("keydown", { - key: ".", - metaKey: true, // cmd key on Mac - }), - ); - }); - - // Check that it switched to Agent mode - expect(await screen.findByText("Agent")).toBeInTheDocument(); - - act(() => { - document.dispatchEvent( - new KeyboardEvent("keydown", { - key: ".", - metaKey: true, // cmd key on Mac - }), - ); - }); - - // Check that it switched back to Chat mode - expect(await screen.findByText("Chat")).toBeInTheDocument(); -}); - -test("should send a message and receive a response", async () => { - const { ideMessenger, store } = await renderWithProviders(); - - // First add and select the mock LLM - await act(async () => { - addAndSelectMockLlm(store, ideMessenger); - }); - - const CONTENT = "Expected response"; - const INPUT = "User input"; - - // Setup the mock response before any actions - ideMessenger.chatResponse = [[{ role: "assistant", content: CONTENT }]]; - - // Wait for the editor to be in the document - const editor = await getMainEditor(); - - // Find the submit button - const sendButton = await waitFor(() => - screen.findByTestId("submit-input-button"), - ); - expect(sendButton).toBeInTheDocument(); - - // Insert content into the editor - await act(async () => { - editor.commands.insertContent(INPUT); - }); - - // Verify the input is in the document - const input = await waitFor(() => screen.findByText(INPUT)); - expect(input).toBeInTheDocument(); - - // Click the send button - await act(async () => { - sendButton.click(); - }); - - // Increase the timeout for finding the response - const response = await waitFor(() => screen.findByText(CONTENT)); - expect(response).toBeInTheDocument(); -}); diff --git a/gui/src/pages/gui/ToolCallDiv/EditFile.tsx b/gui/src/pages/gui/ToolCallDiv/EditFile.tsx index a4a487d42..a60113174 100644 --- a/gui/src/pages/gui/ToolCallDiv/EditFile.tsx +++ b/gui/src/pages/gui/ToolCallDiv/EditFile.tsx @@ -1,12 +1,5 @@ import { getMarkdownLanguageTagForFile } from "core/util"; -import { useEffect } from "react"; -import { v4 as uuidv4 } from "uuid"; import StyledMarkdownPreview from "../../../components/StyledMarkdownPreview"; -import { useAppDispatch, useAppSelector } from "../../../redux/hooks"; -import { - selectApplyStateByToolCallId, - updateApplyState, -} from "../../../redux/slices/sessionSlice"; type EditToolCallProps = { relativeFilePath: string; @@ -16,24 +9,6 @@ type EditToolCallProps = { }; export function EditFile(props: EditToolCallProps) { - const dispatch = useAppDispatch(); - - const applyState = useAppSelector((state) => - selectApplyStateByToolCallId(state, props.toolCallId), - ); - - useEffect(() => { - if (!applyState) { - dispatch( - updateApplyState({ - streamId: uuidv4(), - toolCallId: props.toolCallId, - status: "not-started", - }), - ); - } - }, [applyState, props.toolCallId]); - if (!props.relativeFilePath || !props.changes) { return null; } @@ -45,7 +20,7 @@ export function EditFile(props: EditToolCallProps) { isRenderingInStepContainer disableManualApply source={src} - forceStreamId={applyState?.streamId} + toolCallId={props.toolCallId} expandCodeblocks={false} itemIndex={props.historyIndex} /> diff --git a/gui/src/pages/gui/chat-tests/ApplyScenarios.test.tsx b/gui/src/pages/gui/chat-tests/ApplyScenarios.test.tsx index 909bc1ccb..06c74f080 100644 --- a/gui/src/pages/gui/chat-tests/ApplyScenarios.test.tsx +++ b/gui/src/pages/gui/chat-tests/ApplyScenarios.test.tsx @@ -1,17 +1,18 @@ -import { screen, waitFor } from "@testing-library/dom"; +import { act } from "@testing-library/react"; import { renderWithProviders } from "../../../util/test/render"; import { Chat } from "../Chat"; +import { + getElementByTestId, + verifyNotPresentByTestId, + verifyNotPresentByText, +} from "./utils"; test("Chat apply scenarios: handle apply updates and display the accept / reject all buttons", async () => { const { ideMessenger } = await renderWithProviders(); // Use queryByText which returns null when element isn't found - const acceptAllButton = screen.queryByText("Accept All"); - const rejectAllButton = screen.queryByText("Reject All"); - - // Assert that the buttons don't exist - expect(acceptAllButton).not.toBeInTheDocument(); - expect(rejectAllButton).not.toBeInTheDocument(); + await verifyNotPresentByText("Accept All"); + await verifyNotPresentByText("Reject All"); for (let i = 0; i < 5; i++) { ideMessenger.mockMessageToWebview("updateApplyState", { @@ -26,9 +27,7 @@ test("Chat apply scenarios: handle apply updates and display the accept / reject }); // Wait for the buttons to appear - await waitFor(() => { - expect(screen.getByTestId("accept-reject-all-buttons")).toBeInTheDocument(); - }); + await getElementByTestId("accept-reject-all-buttons"); // IDE sends back message that it is done ideMessenger.mockMessageToWebview("updateApplyState", { @@ -37,10 +36,8 @@ test("Chat apply scenarios: handle apply updates and display the accept / reject }); // Wait for the buttons to disappear - await waitFor(() => { - expect(screen.queryByTestId("edit-accept-button")).not.toBeInTheDocument(); - expect(screen.queryByTestId("edit-reject-button")).not.toBeInTheDocument(); - }); + await verifyNotPresentByTestId("edit-accept-button"); + await verifyNotPresentByTestId("edit-reject-button"); }); test("Chat apply scenarios: show apply cancellation", async () => { @@ -57,19 +54,15 @@ test("Chat apply scenarios: show apply cancellation", async () => { } // Wait for applying toolbar to appear - await waitFor(() => { - const cancelApplyButton = screen.getByTestId( + await getElementByTestId("notch-applying-text"); + + await act(async () => { + const cancelApplyButton = await getElementByTestId( "notch-applying-cancel-button", ); - const applyingText = screen.getByTestId("notch-applying-text"); - - expect(cancelApplyButton).toBeInTheDocument(); - expect(applyingText).toBeInTheDocument(); + cancelApplyButton.click(); }); - const cancelApplyButton = screen.getByTestId("notch-applying-cancel-button"); - cancelApplyButton.click(); - // Verify that rejectDiff message has been posted to ideMessenger expect(messengerPostSpy).toHaveBeenCalledWith("rejectDiff", {}); @@ -79,15 +72,8 @@ test("Chat apply scenarios: show apply cancellation", async () => { streamId: "12345", }); - await waitFor(() => { - const cancelApplyButton = screen.queryByTestId( - "notch-applying-cancel-button", - ); - const applyingText = screen.queryByTestId("notch-applying-text"); - - expect(cancelApplyButton).not.toBeInTheDocument(); - expect(applyingText).not.toBeInTheDocument(); - }); + await verifyNotPresentByTestId("notch-applying-text"); + await verifyNotPresentByTestId("notch-applying-cancel-button"); // Cleanup spy messengerPostSpy.mockRestore(); diff --git a/gui/src/pages/gui/chat-tests/Chat.test.tsx b/gui/src/pages/gui/chat-tests/Chat.test.tsx new file mode 100644 index 000000000..7a3d617d8 --- /dev/null +++ b/gui/src/pages/gui/chat-tests/Chat.test.tsx @@ -0,0 +1,61 @@ +import { act } from "@testing-library/react"; +import { addAndSelectMockLlm } from "../../../util/test/config"; +import { renderWithProviders } from "../../../util/test/render"; +import { Chat } from "../Chat"; +import { + getElementByTestId, + getElementByText, + sendInputWithMockedResponse, +} from "./utils"; + +test("should render input box", async () => { + await renderWithProviders(); + await getElementByTestId("continue-input-box"); +}); + +test("should be able to toggle modes", async () => { + await renderWithProviders(); + await getElementByText("Chat"); + + // Simulate cmd+. keyboard shortcut to toggle modes + act(() => { + document.dispatchEvent( + new KeyboardEvent("keydown", { + key: ".", + metaKey: true, // cmd key on Mac + }), + ); + }); + + // Check that it switched to Agent mode + await getElementByText("Agent"); + + act(() => { + document.dispatchEvent( + new KeyboardEvent("keydown", { + key: ".", + metaKey: true, // cmd key on Mac + }), + ); + }); + + await getElementByText("Chat"); +}); + +test("should send a message and receive a response", async () => { + const { ideMessenger, store } = await renderWithProviders(); + + // First add and select the mock LLM + await act(async () => { + addAndSelectMockLlm(store, ideMessenger); + }); + + const CONTENT = "Expected response"; + const INPUT = "User input"; + + await sendInputWithMockedResponse(ideMessenger, INPUT, [ + { role: "assistant", content: CONTENT }, + ]); + + await getElementByText(CONTENT); +}); diff --git a/gui/src/pages/gui/chat-tests/EditToolScenarios b/gui/src/pages/gui/chat-tests/EditToolScenarios deleted file mode 100644 index e69de29bb..000000000 diff --git a/gui/src/pages/gui/chat-tests/EditToolScenarios.test.tsx b/gui/src/pages/gui/chat-tests/EditToolScenarios.test.tsx new file mode 100644 index 000000000..f020a7513 --- /dev/null +++ b/gui/src/pages/gui/chat-tests/EditToolScenarios.test.tsx @@ -0,0 +1,180 @@ +import { BuiltInToolNames } from "core/tools/builtIn"; +import { + addAndSelectMockLlm, + triggerConfigUpdate, +} from "../../../util/test/config"; +import { renderWithProviders } from "../../../util/test/render"; +import { Chat } from "../Chat"; + +import { ChatMessage } from "core"; +import { toggleToolSetting } from "../../../redux/slices/uiSlice"; +import { + getElementByTestId, + getElementByText, + logAllTestIds, + sendInputWithMockedResponse, + verifyNotPresentByTestId, +} from "./utils"; + +const EDIT_FILEPATH = "test.txt"; +const EDIT_CHANGES = "New content"; +const EDIT_TOOL_CALL_ID = "known-id"; +const EDIT_MESSAGES: ChatMessage[] = [ + { + role: "assistant", + content: "", + toolCalls: [ + { + id: EDIT_TOOL_CALL_ID, + function: { + name: BuiltInToolNames.EditExistingFile, + arguments: JSON.stringify({ + filepath: EDIT_FILEPATH, + changes: EDIT_CHANGES, + }), + }, + }, + ], + }, +]; + +const POST_EDIT_RESPONSE = "Edit applied successfully"; +const AFTER_EDIT_MESSAGES: ChatMessage[] = [ + { + role: "assistant", + content: POST_EDIT_RESPONSE, + }, +]; +beforeEach(() => { + vi.clearAllMocks(); +}); + +test("Edit run with ask first policy and no auto apply", async () => { + const { ideMessenger, store, user } = await renderWithProviders(); + + addAndSelectMockLlm(store, ideMessenger); + + await sendInputWithMockedResponse( + ideMessenger, + "Edit this file", + EDIT_MESSAGES, + ); + + // Toggle the codeblock and make sure the changes show + + const toggleCodeblockChevron = await getElementByTestId("toggle-codeblock"); + + await user.click(toggleCodeblockChevron); + await getElementByText(EDIT_CHANGES); + + const acceptToolCallButton = await getElementByTestId( + "accept-tool-call-button", + ); + await user.click(acceptToolCallButton); + + const applyStates = store.getState().session.codeBlockApplyStates.states; + const initialToolApplyState = applyStates.find( + (s) => s.toolCallId === EDIT_TOOL_CALL_ID, + ); + + expect(initialToolApplyState).toBeDefined(); + + const streamId = initialToolApplyState!.streamId; + + ideMessenger.mockMessageToWebview("updateApplyState", { + status: "streaming", + streamId, + toolCallId: EDIT_TOOL_CALL_ID, + filepath: EDIT_FILEPATH, + }); + + await getElementByTestId("notch-applying-text"); + await getElementByTestId("notch-applying-cancel-button"); + + ideMessenger.mockMessageToWebview("updateApplyState", { + status: "done", + streamId, + toolCallId: EDIT_TOOL_CALL_ID, + filepath: EDIT_FILEPATH, + }); + + const acceptButton = await getElementByTestId("edit-accept-button"); + await getElementByTestId("edit-reject-button"); + + ideMessenger.setChatResponseText(POST_EDIT_RESPONSE); + + await user.click(acceptButton); + + ideMessenger.mockMessageToWebview("updateApplyState", { + status: "closed", + streamId, + toolCallId: EDIT_TOOL_CALL_ID, + filepath: EDIT_FILEPATH, + }); + + await getElementByText(POST_EDIT_RESPONSE); +}); + +test("Edit run with no policy and yolo mode", async () => { + const { ideMessenger, store, user } = await renderWithProviders(); + const messengerPostSpy = vi.spyOn(ideMessenger, "post"); + addAndSelectMockLlm(store, ideMessenger); + + store.dispatch(toggleToolSetting(BuiltInToolNames.EditExistingFile)); + triggerConfigUpdate({ + store, + ideMessenger, + editConfig: (current) => { + current.ui = { + ...current.ui, + autoAcceptEditToolDiffs: true, // Enable auto-accept for edit tool diffs + }; + return current; + }, + }); + expect(store.getState().config.config.ui?.autoAcceptEditToolDiffs).toBe(true); + + await sendInputWithMockedResponse( + ideMessenger, + "Edit this file", + EDIT_MESSAGES, + ); + + // Toggle the codeblock and make sure the changes show + const toggleCodeblockChevron = await getElementByTestId("toggle-codeblock"); + await user.click(toggleCodeblockChevron); + + await getElementByText(EDIT_CHANGES); + + await verifyNotPresentByTestId("accept-tool-call-button"); // Checks tool policy + + const applyStates = store.getState().session.codeBlockApplyStates.states; + const initialToolApplyState = applyStates.find( + (s) => s.toolCallId === EDIT_TOOL_CALL_ID, + ); + + expect(initialToolApplyState).toBeDefined(); + const streamId = initialToolApplyState!.streamId; + + ideMessenger.setChatResponseText(POST_EDIT_RESPONSE); + ideMessenger.mockMessageToWebview("updateApplyState", { + status: "closed", + streamId, + toolCallId: EDIT_TOOL_CALL_ID, + filepath: EDIT_FILEPATH, + }); + await getElementByText(POST_EDIT_RESPONSE); + + logAllTestIds(); // // Should be auto triggered + + // await waitFor(() => { + // expect(messengerPostSpy).toHaveBeenCalledWith("acceptDiff", {}); + // }); + + // await verifyNotPresentByTestId("edit-accept-button"); + // await verifyNotPresentByTestId("edit-reject-button"); + + // ideMessenger.setChatResponseText(POST_EDIT_RESPONSE); + + // await getElementByText(POST_EDIT_RESPONSE); +}); diff --git a/gui/src/pages/gui/chat-tests/utils.ts b/gui/src/pages/gui/chat-tests/utils.ts new file mode 100644 index 000000000..e1062bbe7 --- /dev/null +++ b/gui/src/pages/gui/chat-tests/utils.ts @@ -0,0 +1,102 @@ +import { screen, waitFor } from "@testing-library/dom"; +import { act } from "@testing-library/react"; +import { Editor } from "@tiptap/core"; +import { ChatMessage } from "core"; +import { MockIdeMessenger } from "../../../context/MockIdeMessenger"; + +function logDomText() { + const bodyText = document.body.innerHTML; + const parser = new DOMParser(); + const doc = parser.parseFromString(bodyText, "text/html"); + let cleaned = doc.body.textContent ?? ""; + cleaned = cleaned?.replace( + "No resultsAaModelsRulesDocsPromptsToolsMCPCreate your first assistant", + "", + ); + cleaned = cleaned?.replace( + "Alt⏎ Active file⏎ Enter⏎Log in to access a free trial of theModels Add-OnLog in to Continue HubOr, configure your own models", + "", + ); + cleaned = cleaned.replaceAll("Select model", ""); + cleaned = cleaned.replaceAll("Mock LLM", ""); + cleaned = cleaned.replaceAll(/^Chat|Chat$/g, ""); + console.log(cleaned || "No body content"); +} + +export function logAllTestIds() { + const elements = document.querySelectorAll("*"); + + const testIds = Array.from(elements) + .map((el) => Array.from(el.attributes)) + .flat() + .filter((a) => a.name === "data-testid") + .map((a) => a.value); + console.log("Available test ids", testIds); +} +export async function getElementByTestId(testId: string): Promise { + try { + const testIdElement = await waitFor(() => screen.findByTestId(testId)); + expect(testIdElement).toBeInTheDocument(); + return testIdElement; + } catch (e) { + logAllTestIds(); + throw new Error(`Element with testId "${testId}" not found`); + } +} + +export async function verifyNotPresentByTestId(testId: string): Promise { + const element = await waitFor(() => screen.queryByTestId(testId)); + expect(element).not.toBeInTheDocument(); +} + +export async function verifyNotPresentByText(text: string): Promise { + const element = screen.queryByText(text); + expect(element).not.toBeInTheDocument(); +} + +export async function getElementByText(text: string): Promise { + try { + const textElement = await waitFor(() => screen.findByText(text)); + expect(textElement).toBeInTheDocument(); + return textElement; + } catch (e) { + logDomText(); + throw new Error(`Element with text "${text}" not found.`); + } +} + +export async function getMainEditor(): Promise { + const editorElement = await getElementByTestId("editor-input-main"); + if ("editor" in editorElement) { + return editorElement.editor as Editor; + } else { + throw new Error("Main editor not found within editor container"); + } +} + +export async function sendInputWithMockedResponse( + ideMessenger: MockIdeMessenger, + input: string, + response: ChatMessage[], +): Promise { + // Setup the mock response before any actions + ideMessenger.chatResponse = response; + + // Wait for the editor to be in the document + const editor = await getMainEditor(); + + // Find the submit button + const sendButton = await getElementByTestId("submit-input-button"); + + // Insert content into the editor + await act(async () => { + editor.commands.insertContent(input); + }); + + await getElementByText(input); + + // Click the send button + await act(async () => { + sendButton.click(); + }); +} diff --git a/gui/src/redux/slices/sessionSlice.ts b/gui/src/redux/slices/sessionSlice.ts index 6803947fb..9c91cce73 100644 --- a/gui/src/redux/slices/sessionSlice.ts +++ b/gui/src/redux/slices/sessionSlice.ts @@ -657,7 +657,9 @@ export const selectApplyStateByToolCallId = createSelector( (state: RootState, toolCallId?: string) => toolCallId, ], (states, toolCallId) => { - return states.find((state) => state.toolCallId === toolCallId); + if (toolCallId) { + return states.find((state) => state.toolCallId === toolCallId); + } }, ); diff --git a/gui/src/redux/thunks/callCurrentTool.ts b/gui/src/redux/thunks/callCurrentTool.ts index 02137d822..a0f95a304 100644 --- a/gui/src/redux/thunks/callCurrentTool.ts +++ b/gui/src/redux/thunks/callCurrentTool.ts @@ -19,7 +19,6 @@ export const callCurrentTool = createAsyncThunk( async (_, { dispatch, extra, getState }) => { const state = getState(); const toolCallState = selectCurrentToolCall(state); - if (!toolCallState) { return; } @@ -61,7 +60,7 @@ export const callCurrentTool = createAsyncThunk( ) { // Tool is called on client side const { - output: clientToolOuput, + output: clientToolOutput, respondImmediately, errorMessage: clientToolError, } = await callClientTool(toolCallState, { @@ -73,7 +72,7 @@ export const callCurrentTool = createAsyncThunk( )?.streamId, getState, }); - output = clientToolOuput; + output = clientToolOutput; errorMessage = clientToolError; streamResponse = respondImmediately; } else { diff --git a/gui/src/util/clientTools/editImpl.ts b/gui/src/util/clientTools/editImpl.ts index ecb1ea11f..02846cc71 100644 --- a/gui/src/util/clientTools/editImpl.ts +++ b/gui/src/util/clientTools/editImpl.ts @@ -6,6 +6,7 @@ export const editToolImpl: ClientToolImpl = async ( toolCallId, extras, ) => { + console.log("EDIT TOOL IMPL", args, toolCallId, extras); if (!extras.streamId) { throw new Error("Invalid apply state"); } @@ -16,26 +17,13 @@ export const editToolImpl: ClientToolImpl = async ( if (!firstUriMatch) { throw new Error(`${args.filepath} does not exist`); } - const apply = await extras.ideMessenger.request("applyToFile", { + extras.ideMessenger.post("applyToFile", { streamId: extras.streamId, text: args.changes, toolCallId, filepath: firstUriMatch, }); - if (apply.status === "error") { - throw new Error(apply.error); - } - const state = extras.getState(); - const autoAccept = !!state.config.config.ui?.autoAcceptEditToolDiffs; - if (autoAccept) { - const out = await extras.ideMessenger.request("acceptDiff", { - streamId: extras.streamId, - filepath: firstUriMatch, - }); - if (out.status === "error") { - throw new Error(out.error); - } - } + return { respondImmediately: false, output: undefined, // No immediate output. diff --git a/gui/src/util/test/config.ts b/gui/src/util/test/config.ts index 4dbe4abbe..154ab7d24 100644 --- a/gui/src/util/test/config.ts +++ b/gui/src/util/test/config.ts @@ -1,37 +1,37 @@ import { EnhancedStore } from "@reduxjs/toolkit"; import { BrowserSerializedContinueConfig, ModelDescription } from "core"; import { SerializedOrgWithProfiles } from "core/config/ProfileLifecycleManager"; +import { copyOf } from "core/util"; import { MockIdeMessenger } from "../../context/MockIdeMessenger"; -import { RootState } from "../../redux/store"; interface TestConfigUpdateParams { store: EnhancedStore; - messenger: MockIdeMessenger; + ideMessenger: MockIdeMessenger; newProfileId?: string; newOrgId?: string; newOrgs?: SerializedOrgWithProfiles[]; - - configUpdates?: Partial; + editConfig?: ( + current: BrowserSerializedContinueConfig, + ) => BrowserSerializedContinueConfig; } export function triggerConfigUpdate({ store, - messenger, - configUpdates, + ideMessenger, + editConfig, newOrgs, newOrgId, newProfileId, }: TestConfigUpdateParams) { const state = store.getState(); - messenger.mockMessageToWebview("configUpdate", { + ideMessenger.mockMessageToWebview("configUpdate", { organizations: newOrgs ?? state.profiles.organizations, selectedOrgId: newOrgId ?? state.profiles.selectedOrganizationId, profileId: newProfileId ?? state.profiles.selectedProfileId, result: { - config: { - ...state.config.config, - ...configUpdates, - }, + config: editConfig + ? editConfig(copyOf(state.config.config)) + : state.config.config, configLoadInterrupted: false, errors: [], }, @@ -40,31 +40,25 @@ export function triggerConfigUpdate({ export function addAndSelectChatModel( store: EnhancedStore, - messenger: MockIdeMessenger, + ideMessenger: MockIdeMessenger, llmDesc: ModelDescription, ) { - const state = store.getState() as RootState; triggerConfigUpdate({ store, - messenger, - configUpdates: { - modelsByRole: { - ...state.config.config.modelsByRole, - chat: [...state.config.config.modelsByRole.chat, llmDesc], - }, - selectedModelByRole: { - ...state.config.config.selectedModelByRole, - chat: llmDesc, - }, + ideMessenger, + editConfig(current) { + current.modelsByRole.chat.push(llmDesc); + current.selectedModelByRole.chat = llmDesc; + return current; }, }); } export function addAndSelectMockLlm( store: EnhancedStore, - messenger: MockIdeMessenger, + ideMessenger: MockIdeMessenger, ) { - addAndSelectChatModel(store, messenger, { + addAndSelectChatModel(store, ideMessenger, { model: "mock", provider: "mock", title: "Mock LLM", diff --git a/gui/vite.config.ts b/gui/vite.config.ts index 957a1b0f5..cd70410f5 100644 --- a/gui/vite.config.ts +++ b/gui/vite.config.ts @@ -32,5 +32,18 @@ export default defineConfig({ globals: true, environment: "jsdom", setupFiles: "./src/util/test/setupTests.ts", + onConsoleLog(log, type) { + if (type === "stderr") { + if ( + [ + "contentEditable", + "An update to Chat inside a test was not wrapped in act", + ].some((text) => log.includes(text)) + ) { + return false; + } + } + return true; + }, }, }); diff --git a/packages/config-yaml/package-lock.json b/packages/config-yaml/package-lock.json index 7f2b8b2f2..014ecac95 100644 --- a/packages/config-yaml/package-lock.json +++ b/packages/config-yaml/package-lock.json @@ -1,12 +1,12 @@ { "name": "@continuedev/config-yaml", - "version": "1.0.94", + "version": "1.0.95", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@continuedev/config-yaml", - "version": "1.0.94", + "version": "1.0.95", "license": "Apache-2.0", "dependencies": { "@continuedev/config-types": "^1.0.14", From 11ee6fd65a5a2e5ffc938d50f824a47fc48d5b5b Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Thu, 26 Jun 2025 11:13:31 -0700 Subject: [PATCH 36/44] clean up edit tool impl and fix apply states --- extensions/intellij/rules.md | 4 +++ .../StepContainerPreToolbar/index.tsx | 34 +++++++++++-------- .../StyledMarkdownPreview/index.tsx | 18 ++-------- gui/src/util/clientTools/callClientTool.ts | 1 - gui/src/util/clientTools/editImpl.ts | 9 ++--- 5 files changed, 30 insertions(+), 36 deletions(-) diff --git a/extensions/intellij/rules.md b/extensions/intellij/rules.md index 1f95724c9..e3d749902 100644 --- a/extensions/intellij/rules.md +++ b/extensions/intellij/rules.md @@ -1,3 +1,7 @@ +--- +globs: "**/intellij**" +--- + # Continue JetBrains Extension ## Project Purpose diff --git a/gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/index.tsx b/gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/index.tsx index a45fa18ba..5087cf9db 100644 --- a/gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/index.tsx +++ b/gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/index.tsx @@ -11,8 +11,10 @@ import { IdeMessengerContext } from "../../../context/IdeMessenger"; import { useIdeMessengerRequest } from "../../../hooks/useIdeMessengerRequest"; import { useWebviewListener } from "../../../hooks/useWebviewListener"; import { useAppSelector } from "../../../redux/hooks"; -import { selectCurrentToolCallApplyState } from "../../../redux/selectors/selectCurrentToolCall"; -import { selectApplyStateByStreamId } from "../../../redux/slices/sessionSlice"; +import { + selectApplyStateByStreamId, + selectApplyStateByToolCallId, +} from "../../../redux/slices/sessionSlice"; import { getFontSize } from "../../../util"; import Spinner from "../../gui/Spinner"; import { isTerminalCodeBlock } from "../utils"; @@ -54,6 +56,7 @@ export interface StepContainerPreToolbarProps { codeBlockIndex: number; // To track which codeblock we are applying isLastCodeblock: boolean; codeBlockStreamId: string; + forceToolCallId?: string; // If this is defined, we will use this streamId instead of the one from the codeBlock range?: string; children: any; expanded?: boolean; @@ -68,6 +71,7 @@ export function StepContainerPreToolbar({ codeBlockIndex, isLastCodeblock, codeBlockStreamId, + forceToolCallId, range, children, expanded, @@ -99,10 +103,15 @@ export function StepContainerPreToolbar({ const applyState = useAppSelector((state) => selectApplyStateByStreamId(state, codeBlockStreamId), ); - const currentToolCallApplyState = useAppSelector( - selectCurrentToolCallApplyState, + const toolCallApplyState = useAppSelector((state) => + selectApplyStateByToolCallId(state, forceToolCallId), + ); + console.log( + "applyState", + applyState, + "toolCallApplyState", + toolCallApplyState, ); - /** * In the case where `relativeFilepath` is defined, this will just be `relativeFilepathUri`. * However, if no `relativeFilepath` is defined, then this will @@ -147,7 +156,7 @@ export function StepContainerPreToolbar({ setRelativeFilepathUri(resolvedUri); } }; - getRelativeFilepathUri(); + void getRelativeFilepathUri(); }, [relativeFilepath, ideMessenger.ide]); async function getFileUriToApplyTo() { @@ -173,7 +182,7 @@ export function StepContainerPreToolbar({ async function onClickApply() { const fileUri = await getFileUriToApplyTo(); if (!fileUri) { - ideMessenger.ide.showToast( + void ideMessenger.ide.showToast( "error", "Could not resolve filepath to apply changes", ); @@ -188,7 +197,7 @@ export function StepContainerPreToolbar({ }); setAppliedFileUri(fileUri); - refreshFileExists(); + void refreshFileExists(); } function onClickInsertAtCursor() { @@ -198,7 +207,7 @@ export function StepContainerPreToolbar({ async function handleDiffAction(action: "accept" | "reject") { const filepath = await getFileUriToApplyTo(); if (!filepath) { - ideMessenger.ide.showToast( + void ideMessenger.ide.showToast( "error", `Could not resolve filepath to ${action} changes`, ); @@ -233,10 +242,7 @@ export function StepContainerPreToolbar({ } const renderActionButtons = () => { - const isPendingToolCall = - currentToolCallApplyState && - currentToolCallApplyState.streamId === applyState?.streamId && - currentToolCallApplyState.status === "not-started"; + const isPendingToolCall = toolCallApplyState?.status === "not-started"; if (isGeneratingCodeBlock || isPendingToolCall) { const numLines = codeBlockContent.split("\n").length; @@ -271,7 +277,7 @@ export function StepContainerPreToolbar({ return ( handleDiffAction("accept")} onClickReject={() => handleDiffAction("reject")} diff --git a/gui/src/components/StyledMarkdownPreview/index.tsx b/gui/src/components/StyledMarkdownPreview/index.tsx index bb286004f..f648dd61b 100644 --- a/gui/src/components/StyledMarkdownPreview/index.tsx +++ b/gui/src/components/StyledMarkdownPreview/index.tsx @@ -15,7 +15,6 @@ import { import useUpdatingRef from "../../hooks/useUpdatingRef"; import { useAppSelector } from "../../redux/hooks"; import { selectUIConfig } from "../../redux/slices/configSlice"; -import { selectApplyStateByToolCallId } from "../../redux/slices/sessionSlice"; import { getContextItemsFromHistory } from "../../redux/thunks/updateFileSymbols"; import { getFontSize } from "../../util"; import { ToolTip } from "../gui/Tooltip"; @@ -197,15 +196,6 @@ const StyledMarkdownPreview = memo(function StyledMarkdownPreview( const itemIndexRef = useUpdatingRef(props.itemIndex); const codeblockStreamIds = useRef([]); - const toolCallApplyState = useAppSelector((state) => - selectApplyStateByToolCallId(state, props.toolCallId), - ); - const toolCallApplyStateRef = useUpdatingRef(toolCallApplyState); - // useEffect(() => { - // if (toolCallApplyState) { - // codeblockStreamIds.current = Array(1toolCallApplyState.streamId.repeat(); - // } - // }, [toolCallApplyState, codeblockStreamIds]); const [reactContent, setMarkdownSource] = useRemark({ remarkPlugins: [ @@ -299,10 +289,7 @@ const StyledMarkdownPreview = memo(function StyledMarkdownPreview( const isLastCodeblock = preChildProps["data-islastcodeblock"]; - if (toolCallApplyStateRef.current) { - codeblockStreamIds.current[codeBlockIndex] = - toolCallApplyStateRef.current.streamId; - } else { + if (codeblockStreamIds.current[codeBlockIndex] === undefined) { codeblockStreamIds.current[codeBlockIndex] = uuidv4(); } @@ -315,7 +302,8 @@ const StyledMarkdownPreview = memo(function StyledMarkdownPreview( relativeFilepath={relativeFilePath} isLastCodeblock={isLastCodeblock} range={range} - codeBlockStreamId={codeblockStreamIds.current[codeBlockIndex]} + codeBlockStreamId={codeblockStreamIds.current[codeBlockIndex]} // ignored if toolCallId stream state is found + forceToolCallId={props.toolCallId} expanded={props.expandCodeblocks} disableManualApply={props.disableManualApply} > diff --git a/gui/src/util/clientTools/callClientTool.ts b/gui/src/util/clientTools/callClientTool.ts index cdf6a960f..d0c1576ce 100644 --- a/gui/src/util/clientTools/callClientTool.ts +++ b/gui/src/util/clientTools/callClientTool.ts @@ -8,7 +8,6 @@ export interface ClientToolExtras { getState: () => RootState; dispatch: AppThunkDispatch; ideMessenger: IIdeMessenger; - streamId?: string; } export interface ClientToolOutput { diff --git a/gui/src/util/clientTools/editImpl.ts b/gui/src/util/clientTools/editImpl.ts index 02846cc71..6873e0512 100644 --- a/gui/src/util/clientTools/editImpl.ts +++ b/gui/src/util/clientTools/editImpl.ts @@ -1,15 +1,11 @@ import { resolveRelativePathInDir } from "core/util/ideUtils"; +import { v4 as uuid } from "uuid"; import { ClientToolImpl } from "./callClientTool"; - export const editToolImpl: ClientToolImpl = async ( args, toolCallId, extras, ) => { - console.log("EDIT TOOL IMPL", args, toolCallId, extras); - if (!extras.streamId) { - throw new Error("Invalid apply state"); - } const firstUriMatch = await resolveRelativePathInDir( args.filepath, extras.ideMessenger.ide, @@ -17,8 +13,9 @@ export const editToolImpl: ClientToolImpl = async ( if (!firstUriMatch) { throw new Error(`${args.filepath} does not exist`); } + const streamId = uuid(); extras.ideMessenger.post("applyToFile", { - streamId: extras.streamId, + streamId, text: args.changes, toolCallId, filepath: firstUriMatch, From c7709a79b5c5524bfd4590585296c30da235be31 Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Thu, 26 Jun 2025 11:17:21 -0700 Subject: [PATCH 37/44] clean up yolo mode --- .../StepContainerPreToolbar/index.tsx | 7 +------ gui/src/hooks/ParallelListeners.tsx | 6 ------ 2 files changed, 1 insertion(+), 12 deletions(-) diff --git a/gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/index.tsx b/gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/index.tsx index 5087cf9db..f5737c78e 100644 --- a/gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/index.tsx +++ b/gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/index.tsx @@ -106,12 +106,7 @@ export function StepContainerPreToolbar({ const toolCallApplyState = useAppSelector((state) => selectApplyStateByToolCallId(state, forceToolCallId), ); - console.log( - "applyState", - applyState, - "toolCallApplyState", - toolCallApplyState, - ); + /** * In the case where `relativeFilepath` is defined, this will just be `relativeFilepathUri`. * However, if no `relativeFilepath` is defined, then this will diff --git a/gui/src/hooks/ParallelListeners.tsx b/gui/src/hooks/ParallelListeners.tsx index 109e6b52b..24f68190e 100644 --- a/gui/src/hooks/ParallelListeners.tsx +++ b/gui/src/hooks/ParallelListeners.tsx @@ -264,12 +264,6 @@ function ParallelListeners() { dispatch(updateApplyState(state)); // Handle apply status updates that are associated with current tool call - console.log( - "WALLAH", - currentToolCall, - currentToolCallApplyState, - state, - ); if ( currentToolCallApplyState && currentToolCallApplyState.streamId === state.streamId From 0c94128309953cb428c45a749c68b79425ba2cf8 Mon Sep 17 00:00:00 2001 From: Patrick Erichsen Date: Thu, 26 Jun 2025 12:11:23 -0700 Subject: [PATCH 38/44] Revert "Dev data: added tool usage event" --- gui/src/redux/slices/sessionSlice.ts | 23 ---------------- .../config-yaml/src/schemas/data/index.ts | 8 ------ .../src/schemas/data/toolUsage/index.ts | 11 -------- .../src/schemas/data/toolUsage/v0.2.0.ts | 26 ------------------- 4 files changed, 68 deletions(-) delete mode 100644 packages/config-yaml/src/schemas/data/toolUsage/index.ts delete mode 100644 packages/config-yaml/src/schemas/data/toolUsage/v0.2.0.ts diff --git a/gui/src/redux/slices/sessionSlice.ts b/gui/src/redux/slices/sessionSlice.ts index 50ff37320..6803947fb 100644 --- a/gui/src/redux/slices/sessionSlice.ts +++ b/gui/src/redux/slices/sessionSlice.ts @@ -18,9 +18,7 @@ import { RuleWithSource, Session, SessionMetadata, - ToolCallState, } from "core"; -import { safeParseToolCallArgs } from "core/tools/parseArgs"; import { NEW_SESSION_TITLE } from "core/util/constants"; import { renderChatMessage } from "core/util/messageContent"; import { findUriInDirs, getUriPathBasename } from "core/util/uri"; @@ -30,25 +28,6 @@ import { RootState } from "../store"; import { streamResponseThunk } from "../thunks/streamResponse"; import { findCurrentToolCall, findToolCall } from "../util"; -const getIdeMessenger = () => (window as any).ideMessenger; - -const logToolUsage = (toolCallState: ToolCallState, success: boolean) => { - const ideMessenger = getIdeMessenger(); - if (ideMessenger) { - ideMessenger.post("devdata/log", { - name: "toolUsage", - data: { - toolCallId: toolCallState.toolCallId, - functionName: toolCallState.toolCall.function.name, - functionArgs: toolCallState.toolCall.function.arguments, - parsedArgs: safeParseToolCallArgs(toolCallState.toolCall), - succeeded: success, - output: toolCallState.output || [], - }, - }); - } -}; - // We need this to handle reorderings (e.g. a mid-array deletion) of the messages array. // The proper fix is adding a UUID to all chat messages, but this is the temp workaround. export type ChatHistoryItemWithMessageId = ChatHistoryItem & { @@ -580,7 +559,6 @@ export const sessionSlice = createSlice({ ); if (toolCallState) { toolCallState.status = "errored"; - logToolUsage(toolCallState, false); } }, acceptToolCall: ( @@ -595,7 +573,6 @@ export const sessionSlice = createSlice({ ); if (toolCallState) { toolCallState.status = "done"; - logToolUsage(toolCallState, true); } }, setToolCallCalling: ( diff --git a/packages/config-yaml/src/schemas/data/index.ts b/packages/config-yaml/src/schemas/data/index.ts index 679227c52..7251e12a7 100644 --- a/packages/config-yaml/src/schemas/data/index.ts +++ b/packages/config-yaml/src/schemas/data/index.ts @@ -42,11 +42,6 @@ import { tokensGeneratedEventSchema_0_2_0, tokensGeneratedEventSchema_0_2_0_noCode, } from "./tokensGenerated/v0.2.0.js"; -import { toolUsageEventAllSchema } from "./toolUsage/index.js"; -import { - toolUsageEventSchema_0_2_0, - toolUsageEventSchema_0_2_0_noCode, -} from "./toolUsage/v0.2.0.js"; const semverRegex = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9A-Za-z-][0-9A-Za-z-]*)(?:\.(?:0|[1-9A-Za-z-][0-9A-Za-z-]*))*))?(?:\+([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?$/; @@ -77,7 +72,6 @@ const devEventAllVersionDataSchemas = z.object({ tokensGenerated: tokensGeneratedEventAllSchema, chatInteraction: chatInteractionEventAllSchema, editInteraction: editInteractionEventAllSchema, - toolUsage: toolUsageEventAllSchema, }); // Version and level specific schemas are organized here @@ -103,7 +97,6 @@ export const devDataVersionedSchemas = { tokensGenerated: tokensGeneratedEventSchema_0_2_0, chatInteraction: chatInteractionEventSchema_0_2_0, editInteraction: editInteractionEventSchema_0_2_0, - toolUsage: toolUsageEventSchema_0_2_0, }, noCode: { autocomplete: autocompleteEventSchema_0_2_0_noCode, @@ -111,7 +104,6 @@ export const devDataVersionedSchemas = { tokensGenerated: tokensGeneratedEventSchema_0_2_0_noCode, chatInteraction: chatInteractionEventSchema_0_2_0_noCode, editInteraction: editInteractionEventSchema_0_2_0_noCode, - toolUsage: toolUsageEventSchema_0_2_0_noCode, }, }, }; diff --git a/packages/config-yaml/src/schemas/data/toolUsage/index.ts b/packages/config-yaml/src/schemas/data/toolUsage/index.ts deleted file mode 100644 index 8119366f3..000000000 --- a/packages/config-yaml/src/schemas/data/toolUsage/index.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { z } from "zod"; -import { baseDevDataAllSchema } from "../base.js"; - -export const toolUsageEventAllSchema = baseDevDataAllSchema.extend({ - toolCallId: z.string(), - functionName: z.string(), - functionArgs: z.string(), - parsedArgs: z.any(), - succeeded: z.boolean(), - output: z.array(z.any()).optional(), -}); diff --git a/packages/config-yaml/src/schemas/data/toolUsage/v0.2.0.ts b/packages/config-yaml/src/schemas/data/toolUsage/v0.2.0.ts deleted file mode 100644 index 533e33218..000000000 --- a/packages/config-yaml/src/schemas/data/toolUsage/v0.2.0.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { toolUsageEventAllSchema } from "./index.js"; - -export const toolUsageEventSchema_0_2_0 = toolUsageEventAllSchema.pick({ - // base - timestamp: true, - userId: true, - userAgent: true, - selectedProfileId: true, - eventName: true, - schema: true, - - // tool-usage-specific - toolCallId: true, - functionName: true, - functionArgs: true, - parsedArgs: true, - succeeded: true, - output: true, -}); - -export const toolUsageEventSchema_0_2_0_noCode = - toolUsageEventSchema_0_2_0.omit({ - functionArgs: true, - parsedArgs: true, - output: true, - }); From 8c520f7fade313d59a4cdd0b9125be78cce9529e Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Thu, 26 Jun 2025 12:54:19 -0700 Subject: [PATCH 39/44] clean up call tool --- core/config/sharedConfig.ts | 6 ++++- core/index.d.ts | 1 + .../vscode/src/extension/VsCodeExtension.ts | 6 +++++ gui/src/pages/config/UserSettingsForm.tsx | 10 +++++++ .../gui/chat-tests/EditToolScenarios.test.tsx | 27 +++++++++++++------ gui/src/redux/thunks/callCurrentTool.ts | 4 --- 6 files changed, 41 insertions(+), 13 deletions(-) diff --git a/core/config/sharedConfig.ts b/core/config/sharedConfig.ts index 439925188..af9dc5869 100644 --- a/core/config/sharedConfig.ts +++ b/core/config/sharedConfig.ts @@ -28,6 +28,7 @@ export const sharedConfigSchema = z displayRawMarkdown: z.boolean(), showChatScrollbar: z.boolean(), autoAcceptEditToolDiffs: z.boolean(), + useNextEdit: z.boolean(), // `tabAutocompleteOptions` in `ContinueConfig` useAutocompleteCache: z.boolean(), @@ -167,10 +168,13 @@ export function modifyAnyConfigWithSharedConfig< if (sharedConfig.readResponseTTS !== undefined) { configCopy.experimental.readResponseTTS = sharedConfig.readResponseTTS; } + if (sharedConfig.useCurrentFileAsContext !== undefined) { configCopy.experimental.useCurrentFileAsContext = sharedConfig.useCurrentFileAsContext; } - + if (sharedConfig.useNextEdit !== undefined) { + configCopy.experimental.useNextEdit = sharedConfig.useNextEdit; + } return configCopy; } diff --git a/core/index.d.ts b/core/index.d.ts index 4aea44fd4..3762d9e18 100644 --- a/core/index.d.ts +++ b/core/index.d.ts @@ -1359,6 +1359,7 @@ export interface ExperimentalConfig { /** * If enabled, will add the current file as context. */ + useNextEdit?: boolean; useCurrentFileAsContext?: boolean; } diff --git a/extensions/vscode/src/extension/VsCodeExtension.ts b/extensions/vscode/src/extension/VsCodeExtension.ts index 20bde355d..72743a03a 100644 --- a/extensions/vscode/src/extension/VsCodeExtension.ts +++ b/extensions/vscode/src/extension/VsCodeExtension.ts @@ -155,6 +155,12 @@ export class VsCodeExtension { this.configHandler.onConfigUpdate( async ({ config: newConfig, configLoadInterrupted }) => { + if (config?.experimental?.useNextEdit) { + // activate next edit + } else { + // nexteditwindowmanager.deactivates + } + if (configLoadInterrupted) { // Show error in status bar setupStatusBar(undefined, undefined, true); diff --git a/gui/src/pages/config/UserSettingsForm.tsx b/gui/src/pages/config/UserSettingsForm.tsx index 7f521b95f..3aa3b829f 100644 --- a/gui/src/pages/config/UserSettingsForm.tsx +++ b/gui/src/pages/config/UserSettingsForm.tsx @@ -78,6 +78,7 @@ export function UserSettingsForm() { const disableSessionTitles = config.disableSessionTitles ?? false; const useCurrentFileAsContext = config.experimental?.useCurrentFileAsContext ?? false; + const useNextEdit = config.experimental?.useNextEdit ?? false; const allowAnonymousTelemetry = config.allowAnonymousTelemetry ?? true; const disableIndexing = config.disableIndexing ?? false; @@ -386,6 +387,15 @@ export function UserSettingsForm() { } text="Add Current File by Default" /> + + handleUpdate({ + useNextEdit: !useNextEdit, + }) + } + text="Add Current File by Default" + />
diff --git a/gui/src/pages/gui/chat-tests/EditToolScenarios.test.tsx b/gui/src/pages/gui/chat-tests/EditToolScenarios.test.tsx index f020a7513..57853a1ec 100644 --- a/gui/src/pages/gui/chat-tests/EditToolScenarios.test.tsx +++ b/gui/src/pages/gui/chat-tests/EditToolScenarios.test.tsx @@ -6,6 +6,7 @@ import { import { renderWithProviders } from "../../../util/test/render"; import { Chat } from "../Chat"; +import { waitFor } from "@testing-library/dom"; import { ChatMessage } from "core"; import { toggleToolSetting } from "../../../redux/slices/uiSlice"; import { @@ -16,7 +17,9 @@ import { verifyNotPresentByTestId, } from "./utils"; +const EDIT_WORKSPACE_DIR = "file:///workspace"; const EDIT_FILEPATH = "test.txt"; +const EDIT_FILE_URI = `${EDIT_WORKSPACE_DIR}/${EDIT_FILEPATH}`; const EDIT_CHANGES = "New content"; const EDIT_TOOL_CALL_ID = "known-id"; const EDIT_MESSAGES: ChatMessage[] = [ @@ -52,6 +55,9 @@ beforeEach(() => { test("Edit run with ask first policy and no auto apply", async () => { const { ideMessenger, store, user } = await renderWithProviders(); + ideMessenger.responses["getWorkspaceDirs"] = [EDIT_WORKSPACE_DIR]; + const messengerPostSpy = vi.spyOn(ideMessenger, "post"); + addAndSelectMockLlm(store, ideMessenger); await sendInputWithMockedResponse( @@ -72,14 +78,19 @@ test("Edit run with ask first policy and no auto apply", async () => { ); await user.click(acceptToolCallButton); - const applyStates = store.getState().session.codeBlockApplyStates.states; - const initialToolApplyState = applyStates.find( - (s) => s.toolCallId === EDIT_TOOL_CALL_ID, - ); + await waitFor(() => { + expect(messengerPostSpy).toHaveBeenCalledWith("applyToFile", { + streamId: expect.any(String), + filepath: EDIT_FILE_URI, + text: EDIT_CHANGES, + toolCallId: EDIT_TOOL_CALL_ID, + }); + }); - expect(initialToolApplyState).toBeDefined(); - - const streamId = initialToolApplyState!.streamId; + const streamId = messengerPostSpy.mock.calls.find( + (call) => call[0] === "applyToFile", + )?.[1]?.streamId; + expect(streamId).toBeDefined(); ideMessenger.mockMessageToWebview("updateApplyState", { status: "streaming", @@ -115,7 +126,7 @@ test("Edit run with ask first policy and no auto apply", async () => { await getElementByText(POST_EDIT_RESPONSE); }); -test("Edit run with no policy and yolo mode", async () => { +test.skip("Edit run with no policy and yolo mode", async () => { const { ideMessenger, store, user } = await renderWithProviders(); const messengerPostSpy = vi.spyOn(ideMessenger, "post"); addAndSelectMockLlm(store, ideMessenger); diff --git a/gui/src/redux/thunks/callCurrentTool.ts b/gui/src/redux/thunks/callCurrentTool.ts index a0f95a304..6395a6e32 100644 --- a/gui/src/redux/thunks/callCurrentTool.ts +++ b/gui/src/redux/thunks/callCurrentTool.ts @@ -66,10 +66,6 @@ export const callCurrentTool = createAsyncThunk( } = await callClientTool(toolCallState, { dispatch, ideMessenger: extra.ideMessenger, - streamId: state.session.codeBlockApplyStates.states.find( - (state) => - state.toolCallId && state.toolCallId === toolCallState.toolCallId, - )?.streamId, getState, }); output = clientToolOutput; From 32b7bb6d71e7cbd2cfd28cac3f0d74a87c8e0c14 Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Thu, 26 Jun 2025 13:16:23 -0700 Subject: [PATCH 40/44] revert the usenextedit stuff --- core/config/sharedConfig.ts | 4 ---- core/index.d.ts | 1 - extensions/vscode/src/extension/VsCodeExtension.ts | 6 ------ gui/src/pages/config/UserSettingsForm.tsx | 10 ---------- 4 files changed, 21 deletions(-) diff --git a/core/config/sharedConfig.ts b/core/config/sharedConfig.ts index af9dc5869..cf4446b6f 100644 --- a/core/config/sharedConfig.ts +++ b/core/config/sharedConfig.ts @@ -28,7 +28,6 @@ export const sharedConfigSchema = z displayRawMarkdown: z.boolean(), showChatScrollbar: z.boolean(), autoAcceptEditToolDiffs: z.boolean(), - useNextEdit: z.boolean(), // `tabAutocompleteOptions` in `ContinueConfig` useAutocompleteCache: z.boolean(), @@ -173,8 +172,5 @@ export function modifyAnyConfigWithSharedConfig< configCopy.experimental.useCurrentFileAsContext = sharedConfig.useCurrentFileAsContext; } - if (sharedConfig.useNextEdit !== undefined) { - configCopy.experimental.useNextEdit = sharedConfig.useNextEdit; - } return configCopy; } diff --git a/core/index.d.ts b/core/index.d.ts index 3762d9e18..4aea44fd4 100644 --- a/core/index.d.ts +++ b/core/index.d.ts @@ -1359,7 +1359,6 @@ export interface ExperimentalConfig { /** * If enabled, will add the current file as context. */ - useNextEdit?: boolean; useCurrentFileAsContext?: boolean; } diff --git a/extensions/vscode/src/extension/VsCodeExtension.ts b/extensions/vscode/src/extension/VsCodeExtension.ts index 72743a03a..20bde355d 100644 --- a/extensions/vscode/src/extension/VsCodeExtension.ts +++ b/extensions/vscode/src/extension/VsCodeExtension.ts @@ -155,12 +155,6 @@ export class VsCodeExtension { this.configHandler.onConfigUpdate( async ({ config: newConfig, configLoadInterrupted }) => { - if (config?.experimental?.useNextEdit) { - // activate next edit - } else { - // nexteditwindowmanager.deactivates - } - if (configLoadInterrupted) { // Show error in status bar setupStatusBar(undefined, undefined, true); diff --git a/gui/src/pages/config/UserSettingsForm.tsx b/gui/src/pages/config/UserSettingsForm.tsx index 3aa3b829f..7f521b95f 100644 --- a/gui/src/pages/config/UserSettingsForm.tsx +++ b/gui/src/pages/config/UserSettingsForm.tsx @@ -78,7 +78,6 @@ export function UserSettingsForm() { const disableSessionTitles = config.disableSessionTitles ?? false; const useCurrentFileAsContext = config.experimental?.useCurrentFileAsContext ?? false; - const useNextEdit = config.experimental?.useNextEdit ?? false; const allowAnonymousTelemetry = config.allowAnonymousTelemetry ?? true; const disableIndexing = config.disableIndexing ?? false; @@ -387,15 +386,6 @@ export function UserSettingsForm() { } text="Add Current File by Default" /> - - handleUpdate({ - useNextEdit: !useNextEdit, - }) - } - text="Add Current File by Default" - /> From f7825aa507028319c387f00c64306c73488401dd Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Thu, 26 Jun 2025 13:51:51 -0700 Subject: [PATCH 41/44] working yolo mode test --- gui/src/context/MockIdeMessenger.ts | 1 + gui/src/hooks/ParallelListeners.tsx | 11 +- .../gui/chat-tests/EditToolScenarios.test.tsx | 112 ++++++++++++------ 3 files changed, 79 insertions(+), 45 deletions(-) diff --git a/gui/src/context/MockIdeMessenger.ts b/gui/src/context/MockIdeMessenger.ts index d79e479be..725563087 100644 --- a/gui/src/context/MockIdeMessenger.ts +++ b/gui/src/context/MockIdeMessenger.ts @@ -65,6 +65,7 @@ const DEFAULT_MOCK_CORE_RESPONSES: MockResponses = { }, "chatDescriber/describe": "Session summary", applyToFile: undefined, + acceptDiff: undefined, }; const DEFAULT_CHAT_RESPONSE: ChatMessage[] = [ diff --git a/gui/src/hooks/ParallelListeners.tsx b/gui/src/hooks/ParallelListeners.tsx index 24f68190e..693359a97 100644 --- a/gui/src/hooks/ParallelListeners.tsx +++ b/gui/src/hooks/ParallelListeners.tsx @@ -20,7 +20,6 @@ import { import { acceptToolCall, addContextItemsAtIndex, - cancelToolCall, selectCurrentToolCall, setHasReasoningEnabled, updateApplyState, @@ -269,17 +268,11 @@ function ParallelListeners() { currentToolCallApplyState.streamId === state.streamId ) { if (state.status === "done" && autoAcceptEditToolDiffs) { - const out = await ideMessenger.request("acceptDiff", { + console.log("AUTO ACCEPTED"); + ideMessenger.post("acceptDiff", { streamId: state.streamId, filepath: state.filepath, }); - if (out.status === "error") { - dispatch( - cancelToolCall({ - toolCallId: currentToolCallApplyState.toolCallId!, - }), - ); - } } if (state.status === "closed") { if (currentToolCall?.status !== "canceled") { diff --git a/gui/src/pages/gui/chat-tests/EditToolScenarios.test.tsx b/gui/src/pages/gui/chat-tests/EditToolScenarios.test.tsx index 57853a1ec..e903f8ae9 100644 --- a/gui/src/pages/gui/chat-tests/EditToolScenarios.test.tsx +++ b/gui/src/pages/gui/chat-tests/EditToolScenarios.test.tsx @@ -12,7 +12,6 @@ import { toggleToolSetting } from "../../../redux/slices/uiSlice"; import { getElementByTestId, getElementByText, - logAllTestIds, sendInputWithMockedResponse, verifyNotPresentByTestId, } from "./utils"; @@ -42,17 +41,12 @@ const EDIT_MESSAGES: ChatMessage[] = [ ]; const POST_EDIT_RESPONSE = "Edit applied successfully"; -const AFTER_EDIT_MESSAGES: ChatMessage[] = [ - { - role: "assistant", - content: POST_EDIT_RESPONSE, - }, -]; beforeEach(() => { vi.clearAllMocks(); }); test("Edit run with ask first policy and no auto apply", async () => { + // Setup const { ideMessenger, store, user } = await renderWithProviders(); ideMessenger.responses["getWorkspaceDirs"] = [EDIT_WORKSPACE_DIR]; @@ -60,6 +54,7 @@ test("Edit run with ask first policy and no auto apply", async () => { addAndSelectMockLlm(store, ideMessenger); + // Send the input that will respond with an edit tool call await sendInputWithMockedResponse( ideMessenger, "Edit this file", @@ -67,17 +62,18 @@ test("Edit run with ask first policy and no auto apply", async () => { ); // Toggle the codeblock and make sure the changes show - const toggleCodeblockChevron = await getElementByTestId("toggle-codeblock"); await user.click(toggleCodeblockChevron); await getElementByText(EDIT_CHANGES); + // Pending tool call - find and click the accept button const acceptToolCallButton = await getElementByTestId( "accept-tool-call-button", ); await user.click(acceptToolCallButton); + // Tool call, check that applyToFile was called for edit await waitFor(() => { expect(messengerPostSpy).toHaveBeenCalledWith("applyToFile", { streamId: expect.any(String), @@ -87,6 +83,7 @@ test("Edit run with ask first policy and no auto apply", async () => { }); }); + // Extract stream ID and initiate mock streaming const streamId = messengerPostSpy.mock.calls.find( (call) => call[0] === "applyToFile", )?.[1]?.streamId; @@ -96,41 +93,57 @@ test("Edit run with ask first policy and no auto apply", async () => { status: "streaming", streamId, toolCallId: EDIT_TOOL_CALL_ID, - filepath: EDIT_FILEPATH, + filepath: EDIT_FILE_URI, }); + // Mid stream, should show applying in notch await getElementByTestId("notch-applying-text"); await getElementByTestId("notch-applying-cancel-button"); + // Close the stream ideMessenger.mockMessageToWebview("updateApplyState", { status: "done", streamId, toolCallId: EDIT_TOOL_CALL_ID, - filepath: EDIT_FILEPATH, + filepath: EDIT_FILE_URI, }); + // Verify accept/reject buttons are present const acceptButton = await getElementByTestId("edit-accept-button"); await getElementByTestId("edit-reject-button"); - ideMessenger.setChatResponseText(POST_EDIT_RESPONSE); - + // Accept the changes, which should trigger a response after the tool call await user.click(acceptButton); + expect(messengerPostSpy).toHaveBeenCalledWith("acceptDiff", { + streamId, + filepath: EDIT_FILE_URI, + }); + + ideMessenger.setChatResponseText(POST_EDIT_RESPONSE); ideMessenger.mockMessageToWebview("updateApplyState", { status: "closed", streamId, toolCallId: EDIT_TOOL_CALL_ID, - filepath: EDIT_FILEPATH, + filepath: EDIT_FILE_URI, }); + await verifyNotPresentByTestId("edit-accept-button"); + await verifyNotPresentByTestId("edit-reject-button"); + await getElementByText(POST_EDIT_RESPONSE); }); -test.skip("Edit run with no policy and yolo mode", async () => { +test("Edit run with no policy and yolo mode", async () => { + // Setup const { ideMessenger, store, user } = await renderWithProviders(); + + ideMessenger.responses["getWorkspaceDirs"] = [EDIT_WORKSPACE_DIR]; const messengerPostSpy = vi.spyOn(ideMessenger, "post"); + addAndSelectMockLlm(store, ideMessenger); + // Enable automatic edit and yolo mode store.dispatch(toggleToolSetting(BuiltInToolNames.EditExistingFile)); triggerConfigUpdate({ store, @@ -145,6 +158,7 @@ test.skip("Edit run with no policy and yolo mode", async () => { }); expect(store.getState().config.config.ui?.autoAcceptEditToolDiffs).toBe(true); + // Send the input that will respond with an edit tool call await sendInputWithMockedResponse( ideMessenger, "Edit this file", @@ -153,39 +167,65 @@ test.skip("Edit run with no policy and yolo mode", async () => { // Toggle the codeblock and make sure the changes show const toggleCodeblockChevron = await getElementByTestId("toggle-codeblock"); - await user.click(toggleCodeblockChevron); + await user.click(toggleCodeblockChevron); await getElementByText(EDIT_CHANGES); - await verifyNotPresentByTestId("accept-tool-call-button"); // Checks tool policy + // Make sure there's no pending tool call + verifyNotPresentByTestId("accept-tool-call-button"); + // Tool call, check that applyToFile was called for edit + await waitFor(() => { + expect(messengerPostSpy).toHaveBeenCalledWith("applyToFile", { + streamId: expect.any(String), + filepath: EDIT_FILE_URI, + text: EDIT_CHANGES, + toolCallId: EDIT_TOOL_CALL_ID, + }); + }); - const applyStates = store.getState().session.codeBlockApplyStates.states; - const initialToolApplyState = applyStates.find( - (s) => s.toolCallId === EDIT_TOOL_CALL_ID, - ); + // Extract stream ID and initiate mock streaming + const streamId = messengerPostSpy.mock.calls.find( + (call) => call[0] === "applyToFile", + )?.[1]?.streamId; + expect(streamId).toBeDefined(); - expect(initialToolApplyState).toBeDefined(); - const streamId = initialToolApplyState!.streamId; + ideMessenger.mockMessageToWebview("updateApplyState", { + status: "streaming", + streamId, + toolCallId: EDIT_TOOL_CALL_ID, + filepath: EDIT_FILE_URI, + }); + // Mid stream, should show applying in notch + await getElementByTestId("notch-applying-text"); + await getElementByTestId("notch-applying-cancel-button"); + + // Close the stream + ideMessenger.mockMessageToWebview("updateApplyState", { + status: "done", + streamId, + toolCallId: EDIT_TOOL_CALL_ID, + filepath: EDIT_FILE_URI, + }); + + await waitFor(() => { + expect(messengerPostSpy).toHaveBeenCalledWith("acceptDiff", { + streamId, + filepath: EDIT_FILE_URI, + }); + }); + + // Close the stream, ensure response is shown and diff buttons are not present ideMessenger.setChatResponseText(POST_EDIT_RESPONSE); ideMessenger.mockMessageToWebview("updateApplyState", { status: "closed", streamId, toolCallId: EDIT_TOOL_CALL_ID, - filepath: EDIT_FILEPATH, + filepath: EDIT_FILE_URI, }); + + await verifyNotPresentByTestId("edit-accept-button"); + await verifyNotPresentByTestId("edit-reject-button"); + await getElementByText(POST_EDIT_RESPONSE); - - logAllTestIds(); // // Should be auto triggered - - // await waitFor(() => { - // expect(messengerPostSpy).toHaveBeenCalledWith("acceptDiff", {}); - // }); - - // await verifyNotPresentByTestId("edit-accept-button"); - // await verifyNotPresentByTestId("edit-reject-button"); - - // ideMessenger.setChatResponseText(POST_EDIT_RESPONSE); - - // await getElementByText(POST_EDIT_RESPONSE); }); From 51dfa72d1dc6dea1bf588e131e7567dcfee00fba Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Thu, 26 Jun 2025 13:59:48 -0700 Subject: [PATCH 42/44] move chat utils --- core/config/sharedConfig.ts | 2 +- extensions/intellij/rules.md | 4 ---- gui/src/pages/gui/chat-tests/ApplyScenarios.test.tsx | 4 ++-- gui/src/pages/gui/chat-tests/Chat.test.tsx | 4 ++-- gui/src/pages/gui/chat-tests/EditToolScenarios.test.tsx | 2 +- gui/src/redux/slices/profilesSlice.ts | 4 ++-- gui/src/{pages/gui/chat-tests => util/test}/utils.ts | 2 +- 7 files changed, 9 insertions(+), 13 deletions(-) rename gui/src/{pages/gui/chat-tests => util/test}/utils.ts (97%) diff --git a/core/config/sharedConfig.ts b/core/config/sharedConfig.ts index cf4446b6f..439925188 100644 --- a/core/config/sharedConfig.ts +++ b/core/config/sharedConfig.ts @@ -167,10 +167,10 @@ export function modifyAnyConfigWithSharedConfig< if (sharedConfig.readResponseTTS !== undefined) { configCopy.experimental.readResponseTTS = sharedConfig.readResponseTTS; } - if (sharedConfig.useCurrentFileAsContext !== undefined) { configCopy.experimental.useCurrentFileAsContext = sharedConfig.useCurrentFileAsContext; } + return configCopy; } diff --git a/extensions/intellij/rules.md b/extensions/intellij/rules.md index e3d749902..1f95724c9 100644 --- a/extensions/intellij/rules.md +++ b/extensions/intellij/rules.md @@ -1,7 +1,3 @@ ---- -globs: "**/intellij**" ---- - # Continue JetBrains Extension ## Project Purpose diff --git a/gui/src/pages/gui/chat-tests/ApplyScenarios.test.tsx b/gui/src/pages/gui/chat-tests/ApplyScenarios.test.tsx index 06c74f080..3624a5bd9 100644 --- a/gui/src/pages/gui/chat-tests/ApplyScenarios.test.tsx +++ b/gui/src/pages/gui/chat-tests/ApplyScenarios.test.tsx @@ -1,11 +1,11 @@ import { act } from "@testing-library/react"; import { renderWithProviders } from "../../../util/test/render"; -import { Chat } from "../Chat"; import { getElementByTestId, verifyNotPresentByTestId, verifyNotPresentByText, -} from "./utils"; +} from "../../../util/test/utils"; +import { Chat } from "../Chat"; test("Chat apply scenarios: handle apply updates and display the accept / reject all buttons", async () => { const { ideMessenger } = await renderWithProviders(); diff --git a/gui/src/pages/gui/chat-tests/Chat.test.tsx b/gui/src/pages/gui/chat-tests/Chat.test.tsx index 7a3d617d8..d3e6aa18b 100644 --- a/gui/src/pages/gui/chat-tests/Chat.test.tsx +++ b/gui/src/pages/gui/chat-tests/Chat.test.tsx @@ -1,12 +1,12 @@ import { act } from "@testing-library/react"; import { addAndSelectMockLlm } from "../../../util/test/config"; import { renderWithProviders } from "../../../util/test/render"; -import { Chat } from "../Chat"; import { getElementByTestId, getElementByText, sendInputWithMockedResponse, -} from "./utils"; +} from "../../../util/test/utils"; +import { Chat } from "../Chat"; test("should render input box", async () => { await renderWithProviders(); diff --git a/gui/src/pages/gui/chat-tests/EditToolScenarios.test.tsx b/gui/src/pages/gui/chat-tests/EditToolScenarios.test.tsx index e903f8ae9..157c81e9e 100644 --- a/gui/src/pages/gui/chat-tests/EditToolScenarios.test.tsx +++ b/gui/src/pages/gui/chat-tests/EditToolScenarios.test.tsx @@ -14,7 +14,7 @@ import { getElementByText, sendInputWithMockedResponse, verifyNotPresentByTestId, -} from "./utils"; +} from "../../../util/test/utils"; const EDIT_WORKSPACE_DIR = "file:///workspace"; const EDIT_FILEPATH = "test.txt"; diff --git a/gui/src/redux/slices/profilesSlice.ts b/gui/src/redux/slices/profilesSlice.ts index 0ea3d587a..6f3144736 100644 --- a/gui/src/redux/slices/profilesSlice.ts +++ b/gui/src/redux/slices/profilesSlice.ts @@ -19,7 +19,7 @@ export interface ProfilesState { preferencesByProfileId: Record; } -export const defaultProfilesState: ProfilesState = { +const initialState: ProfilesState = { preferencesByProfileId: {}, selectedProfileId: null, selectedOrganizationId: null, @@ -51,7 +51,7 @@ export const defaultProfilesState: ProfilesState = { export const profilesSlice = createSlice({ name: "profiles", - initialState: defaultProfilesState, + initialState, reducers: { setSelectedProfile: (state, { payload }: PayloadAction) => { state.selectedProfileId = payload; diff --git a/gui/src/pages/gui/chat-tests/utils.ts b/gui/src/util/test/utils.ts similarity index 97% rename from gui/src/pages/gui/chat-tests/utils.ts rename to gui/src/util/test/utils.ts index e1062bbe7..ebc4181d7 100644 --- a/gui/src/pages/gui/chat-tests/utils.ts +++ b/gui/src/util/test/utils.ts @@ -2,7 +2,7 @@ import { screen, waitFor } from "@testing-library/dom"; import { act } from "@testing-library/react"; import { Editor } from "@tiptap/core"; import { ChatMessage } from "core"; -import { MockIdeMessenger } from "../../../context/MockIdeMessenger"; +import { MockIdeMessenger } from "../../context/MockIdeMessenger"; function logDomText() { const bodyText = document.body.innerHTML; From 55ff11fc2e06511582b1ffd1e340e3b461a3f812 Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Thu, 26 Jun 2025 14:12:28 -0700 Subject: [PATCH 43/44] Clean up mock ide messenger --- gui/src/context/MockIdeMessenger.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/gui/src/context/MockIdeMessenger.ts b/gui/src/context/MockIdeMessenger.ts index 725563087..340911365 100644 --- a/gui/src/context/MockIdeMessenger.ts +++ b/gui/src/context/MockIdeMessenger.ts @@ -76,10 +76,6 @@ const DEFAULT_CHAT_RESPONSE: ChatMessage[] = [ ]; export class MockIdeMessenger implements IIdeMessenger { ide: IDE; - // private messageHandlers: Map< - // keyof FromIdeProtocol, - // Array<(data: any) => void> - // > = new Map(); constructor() { this.ide = new MessageIde( From a6dbe946eab3591ed143fb5a89cad8d7be6a243a Mon Sep 17 00:00:00 2001 From: Nate Date: Thu, 26 Jun 2025 20:54:15 -0700 Subject: [PATCH 44/44] address feedback from recurse --- binary/utils/bundle-binary.js | 3 ++- extensions/vscode/scripts/download-copy-sqlite-esbuild.js | 6 ++++-- extensions/vscode/scripts/esbuild.js | 3 ++- extensions/vscode/scripts/install-copy-nodemodule.js | 3 ++- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/binary/utils/bundle-binary.js b/binary/utils/bundle-binary.js index 0a778f5b0..f0cde0d25 100644 --- a/binary/utils/bundle-binary.js +++ b/binary/utils/bundle-binary.js @@ -91,8 +91,9 @@ async function bundleBinary(target) { child.on("message", (msg) => { if (msg.error) { reject(); + } else { + resolve(); } - resolve(); }); }); } diff --git a/extensions/vscode/scripts/download-copy-sqlite-esbuild.js b/extensions/vscode/scripts/download-copy-sqlite-esbuild.js index ad33b2eb6..ea6f8ebd9 100644 --- a/extensions/vscode/scripts/download-copy-sqlite-esbuild.js +++ b/extensions/vscode/scripts/download-copy-sqlite-esbuild.js @@ -154,8 +154,9 @@ async function copySqlite(target) { child.on("message", (msg) => { if (msg.error) { reject(); + } else { + resolve(); } - resolve(); }); }); } @@ -176,8 +177,9 @@ async function copyEsbuild(target) { child.on("message", (msg) => { if (msg.error) { reject(); + } else { + resolve(); } - resolve(); }); }); } diff --git a/extensions/vscode/scripts/esbuild.js b/extensions/vscode/scripts/esbuild.js index 9382e2b7a..e800cdfc6 100644 --- a/extensions/vscode/scripts/esbuild.js +++ b/extensions/vscode/scripts/esbuild.js @@ -1,4 +1,5 @@ const fs = require("fs"); + const { writeBuildTimestamp } = require("./utils"); const esbuild = require("esbuild"); @@ -49,7 +50,7 @@ const esbuildConfig = { ], }; -(async () => { +void (async () => { // Create .buildTimestamp.js before starting the first build writeBuildTimestamp(); // Bundles the extension into one file diff --git a/extensions/vscode/scripts/install-copy-nodemodule.js b/extensions/vscode/scripts/install-copy-nodemodule.js index a20d2dee4..1ce65327a 100644 --- a/extensions/vscode/scripts/install-copy-nodemodule.js +++ b/extensions/vscode/scripts/install-copy-nodemodule.js @@ -101,8 +101,9 @@ async function installAndCopyNodeModules(packageName, toCopy) { child.on("message", (msg) => { if (msg.error) { reject(); + } else { + resolve(); } - resolve(); }); }); }