diff --git a/.gitignore b/.gitignore index b24d52983..763b96238 100644 --- a/.gitignore +++ b/.gitignore @@ -169,4 +169,4 @@ extensions/.continue-debug/ *.vsix .continuerules -.continue/assistants/ \ No newline at end of file +**/.continue/assistants/ \ No newline at end of file diff --git a/core/config/ConfigHandler.ts b/core/config/ConfigHandler.ts index 8f2c6ad4c..b84349eaa 100644 --- a/core/config/ConfigHandler.ts +++ b/core/config/ConfigHandler.ts @@ -16,7 +16,7 @@ import { import Ollama from "../llm/llms/Ollama.js"; import { GlobalContext } from "../util/GlobalContext.js"; -import { getAllAssistantFiles } from "./getSystemPromptDotFile.js"; +import { getAllAssistantFiles } from "./loadLocalAssistants.js"; import { LOCAL_ONBOARDING_CHAT_MODEL, LOCAL_ONBOARDING_PROVIDER_TITLE, diff --git a/core/config/getSystemPromptDotFile.ts b/core/config/getSystemPromptDotFile.ts index 652f4285a..550144cd8 100644 --- a/core/config/getSystemPromptDotFile.ts +++ b/core/config/getSystemPromptDotFile.ts @@ -1,12 +1,4 @@ -import ignore from "ignore"; import { IDE } from ".."; -import { - DEFAULT_IGNORE_DIRS, - DEFAULT_IGNORE_FILETYPES, -} from "../indexing/ignore"; -import { walkDir } from "../indexing/walkDir"; -import { getGlobalAssistantsPath } from "../util/paths"; -import { localPathToUri } from "../util/pathToUri"; import { joinPathsToUri } from "../util/uri"; export const SYSTEM_PROMPT_DOT_FILE = ".continuerules"; @@ -32,60 +24,3 @@ export async function getSystemPromptDotFile(ide: IDE): Promise { return prompts.join("\n\n"); } - -export const ASSISTANTS_FOLDER = ".continue/assistants"; - -export async function getAssistantFilesFromDir( - ide: IDE, - dir: string, -): Promise<{ path: string; content: string }[]> { - try { - const exists = await ide.fileExists(dir); - - if (!exists) { - return []; - } - - const overrideIgnore = ignore() - .add(DEFAULT_IGNORE_FILETYPES.filter((t) => t !== "config.yaml")) - .add(DEFAULT_IGNORE_DIRS); - - const uris = await walkDir(dir, ide, { overrideIgnore }); - const assistantFilePaths = uris.filter( - (p) => p.endsWith(".yaml") || p.endsWith(".yml"), - ); - const results = assistantFilePaths.map(async (uri) => { - const content = await ide.readFile(uri); // make a try catch - return { path: uri, content }; - }); - return Promise.all(results); - } catch (e) { - console.error(e); - return []; - } -} - -export async function getAllAssistantFiles( - ide: IDE, -): Promise<{ path: string; content: string }[]> { - const workspaceDirs = await ide.getWorkspaceDirs(); - let assistantFiles: { path: string; content: string }[] = []; - - let dirsToCheck = [ASSISTANTS_FOLDER]; - const fullDirs = workspaceDirs - .map((dir) => dirsToCheck.map((d) => joinPathsToUri(dir, d))) - .flat(); - - fullDirs.push(localPathToUri(getGlobalAssistantsPath())); - - assistantFiles = ( - await Promise.all(fullDirs.map((dir) => getAssistantFilesFromDir(ide, dir))) - ).flat(); - - return await Promise.all( - assistantFiles.map(async (file) => { - const content = await ide.readFile(file.path); - return { path: file.path, content }; - }), - ); -} diff --git a/core/config/loadLocalAssistants.ts b/core/config/loadLocalAssistants.ts new file mode 100644 index 000000000..6eb6670ea --- /dev/null +++ b/core/config/loadLocalAssistants.ts @@ -0,0 +1,76 @@ +import ignore from "ignore"; +import { IDE } from ".."; +import { + DEFAULT_IGNORE_DIRS, + DEFAULT_IGNORE_FILETYPES, +} from "../indexing/ignore"; +import { walkDir } from "../indexing/walkDir"; +import { getGlobalAssistantsPath } from "../util/paths"; +import { localPathToUri } from "../util/pathToUri"; +import { joinPathsToUri } from "../util/uri"; + +export const ASSISTANTS_FOLDER = ".continue/assistants"; + +export function isLocalAssistantFile(uri: string): boolean { + if (!uri.endsWith(".yaml") && !uri.endsWith(".yml")) { + return false; + } + + const normalizedUri = uri.replace(/\\/g, "/"); + return normalizedUri.includes(`/${ASSISTANTS_FOLDER}/`); +} + +export async function getAssistantFilesFromDir( + ide: IDE, + dir: string, +): Promise<{ path: string; content: string }[]> { + try { + const exists = await ide.fileExists(dir); + + if (!exists) { + return []; + } + + const overrideIgnore = ignore() + .add(DEFAULT_IGNORE_FILETYPES.filter((t) => t !== "config.yaml")) + .add(DEFAULT_IGNORE_DIRS); + + const uris = await walkDir(dir, ide, { overrideIgnore }); + const assistantFilePaths = uris.filter( + (p) => p.endsWith(".yaml") || p.endsWith(".yml"), + ); + const results = assistantFilePaths.map(async (uri) => { + const content = await ide.readFile(uri); // make a try catch + return { path: uri, content }; + }); + return Promise.all(results); + } catch (e) { + console.error(e); + return []; + } +} + +export async function getAllAssistantFiles( + ide: IDE, +): Promise<{ path: string; content: string }[]> { + const workspaceDirs = await ide.getWorkspaceDirs(); + let assistantFiles: { path: string; content: string }[] = []; + + let dirsToCheck = [ASSISTANTS_FOLDER]; + const fullDirs = workspaceDirs + .map((dir) => dirsToCheck.map((d) => joinPathsToUri(dir, d))) + .flat(); + + fullDirs.push(localPathToUri(getGlobalAssistantsPath())); + + assistantFiles = ( + await Promise.all(fullDirs.map((dir) => getAssistantFilesFromDir(ide, dir))) + ).flat(); + + return await Promise.all( + assistantFiles.map(async (file) => { + const content = await ide.readFile(file.path); + return { path: file.path, content }; + }), + ); +} diff --git a/core/core.ts b/core/core.ts index 037bb48ce..8e14aa668 100644 --- a/core/core.ts +++ b/core/core.ts @@ -44,6 +44,7 @@ import { type IndexingProgressUpdate, } from "."; +import { isLocalAssistantFile } from "./config/loadLocalAssistants"; import { shouldIgnore } from "./indexing/shouldIgnore"; import type { FromCoreProtocol, ToCoreProtocol } from "./protocol"; import type { IMessenger, Message } from "./protocol/messenger"; @@ -926,6 +927,13 @@ export class Core { on("files/created", async ({ data }) => { if (data?.uris?.length) { void refreshIfNotIgnored(data.uris); + + // If it's a local assistant being created, we want to reload all assistants so it shows up in the list + for (const uri of data.uris) { + if (isLocalAssistantFile(uri)) { + await this.configHandler.loadAssistantsForSelectedOrg(); + } + } } }); diff --git a/extensions/vscode/package-lock.json b/extensions/vscode/package-lock.json index 5f7702aee..dc6465ddd 100644 --- a/extensions/vscode/package-lock.json +++ b/extensions/vscode/package-lock.json @@ -1,12 +1,12 @@ { "name": "continue", - "version": "1.1.7", + "version": "1.1.8", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "continue", - "version": "1.1.7", + "version": "1.1.8", "license": "Apache-2.0", "dependencies": { "@continuedev/fetch": "^1.0.3",