From 89a7d9a0c2fc2c56859af2f50c14e357caa6b2fb Mon Sep 17 00:00:00 2001 From: Fred Bricon Date: Thu, 22 May 2025 11:02:31 +0200 Subject: [PATCH] fix: open the proper config file Signed-off-by: Fred Bricon --- core/commands/slash/customSlashCommand.ts | 1 + .../commands/slash/promptBlockSlashCommand.ts | 1 + core/config/ConfigHandler.ts | 9 ++- core/config/load.ts | 1 + core/config/yaml/loadYaml.ts | 3 + core/core.ts | 5 +- core/index.d.ts | 7 +++ core/llm/index.ts | 4 ++ core/protocol/core.ts | 5 +- .../mainInput/Lump/EditBlockButton.tsx | 3 + .../Lump/sections/PromptsSection.tsx | 2 +- .../mainInput/Lump/sections/RulesSection.tsx | 1 + .../Lump/sections/docs/DocsIndexingStatus.tsx | 6 +- .../Lump/sections/mcp/MCPSection.tsx | 6 +- .../components/modelSelection/ModelSelect.tsx | 5 +- gui/src/pages/config/ModelRoleSelector.tsx | 11 +++- gui/src/pages/gui/StreamError.tsx | 1 + packages/config-types/src/index.ts | 1 + packages/config-yaml/src/load/unroll.ts | 63 +++++++++++++++++-- .../src/markdown/markdownToRule.ts | 1 + packages/config-yaml/src/schemas/index.ts | 4 ++ packages/config-yaml/src/schemas/models.ts | 1 + 22 files changed, 125 insertions(+), 16 deletions(-) diff --git a/core/commands/slash/customSlashCommand.ts b/core/commands/slash/customSlashCommand.ts index c27a41f4c..9526cbca8 100644 --- a/core/commands/slash/customSlashCommand.ts +++ b/core/commands/slash/customSlashCommand.ts @@ -11,5 +11,6 @@ export function convertCustomCommandToSlashCommand( description: customCommand.description ?? "", prompt: customCommand.prompt, source: "json-custom-command", + promptFile: customCommand.sourceFile, // TODO refactor promptFile to align with sourceFile }; } diff --git a/core/commands/slash/promptBlockSlashCommand.ts b/core/commands/slash/promptBlockSlashCommand.ts index 00530b8bd..4f3446a21 100644 --- a/core/commands/slash/promptBlockSlashCommand.ts +++ b/core/commands/slash/promptBlockSlashCommand.ts @@ -9,5 +9,6 @@ export function convertPromptBlockToSlashCommand( description: prompt.description ?? "", prompt: prompt.prompt, source: "yaml-prompt-block", + promptFile: prompt.sourceFile, // Align with the sourceFile property }; } diff --git a/core/config/ConfigHandler.ts b/core/config/ConfigHandler.ts index a50e72c24..1ca09b1e2 100644 --- a/core/config/ConfigHandler.ts +++ b/core/config/ConfigHandler.ts @@ -522,7 +522,10 @@ export class ConfigHandler { return config; } - async openConfigProfile(profileId?: string) { + async openConfigProfile( + profileId?: string, + element?: { sourceFile?: string }, + ) { let openProfileId = profileId || this.currentProfile?.profileDescription.id; if (!openProfileId) { return; @@ -530,8 +533,10 @@ export class ConfigHandler { const profile = this.currentOrg.profiles.find( (p) => p.profileDescription.id === openProfileId, ); + if (profile?.profileDescription.profileType === "local") { - await this.ide.openFile(profile.profileDescription.uri); + const configFile = element?.sourceFile ?? profile.profileDescription.uri; + await this.ide.openFile(configFile); } else { const env = await getControlPlaneEnv(this.ide.getIdeSettings()); await this.ide.openUrl(`${env.APP_URL}${openProfileId}`); diff --git a/core/config/load.ts b/core/config/load.ts index a5da010f9..5206bb8bb 100644 --- a/core/config/load.ts +++ b/core/config/load.ts @@ -652,6 +652,7 @@ function llmToSerializedModelDescription(llm: ILLM): ModelDescription { configurationStatus: llm.getConfigurationStatus(), apiKeyLocation: llm.apiKeyLocation, envSecretLocations: llm.envSecretLocations, + sourceFile: llm.sourceFile, }; } diff --git a/core/config/yaml/loadYaml.ts b/core/config/yaml/loadYaml.ts index 04c19b326..83c6384ba 100644 --- a/core/config/yaml/loadYaml.ts +++ b/core/config/yaml/loadYaml.ts @@ -56,6 +56,7 @@ function convertYamlRuleToContinueRule(rule: Rule): RuleWithSource { rule: rule.rule, globs: rule.globs, name: rule.name, + ruleFile: rule.sourceFile, }; } } @@ -237,6 +238,7 @@ async function configYamlToContinueConfig(options: { faviconUrl: doc.faviconUrl, maxDepth: doc.maxDepth, useLocalCrawling: doc.useLocalCrawling, + sourceFile: doc.sourceFile, })); config.mcpServers?.forEach((mcpServer) => { @@ -429,6 +431,7 @@ async function configYamlToContinueConfig(options: { (config.mcpServers ?? []).map((server) => ({ id: server.name, name: server.name, + sourceFile: server.sourceFile, transport: { type: "stdio", args: [], diff --git a/core/core.ts b/core/core.ts index a3fe4cab5..d8275b8ff 100644 --- a/core/core.ts +++ b/core/core.ts @@ -349,7 +349,10 @@ export class Core { }); on("config/openProfile", async (msg) => { - await this.configHandler.openConfigProfile(msg.data.profileId); + await this.configHandler.openConfigProfile( + msg.data.profileId, + msg.data?.element, + ); }); on("config/reload", async (msg) => { diff --git a/core/index.d.ts b/core/index.d.ts index c2bc7487b..50fd96534 100644 --- a/core/index.d.ts +++ b/core/index.d.ts @@ -237,6 +237,7 @@ export interface SiteIndexingConfig { maxDepth?: number; faviconUrl?: string; useLocalCrawling?: boolean; + sourceFile?: string; } export interface DocsIndexingDetails { @@ -660,6 +661,8 @@ export interface LLMOptions { deploymentId?: string; env?: Record; + + sourceFile?: string; } type RequireAtLeastOne = Pick< @@ -1035,6 +1038,7 @@ export interface CustomCommand { name: string; prompt: string; description?: string; + sourceFile?: string; } export interface Prediction { @@ -1152,6 +1156,8 @@ export interface ModelDescription { capabilities?: ModelCapability; roles?: ModelRole[]; configurationStatus?: LLMConfigurationStatuses; + + sourceFile?: string; } export interface JSONEmbedOptions { @@ -1306,6 +1312,7 @@ export interface MCPServerStatus extends MCPOptions { tools: MCPTool[]; resources: MCPResource[]; resourceTemplates: MCPResourceTemplate[]; + sourceFile?: string; } export interface ContinueUIConfig { diff --git a/core/llm/index.ts b/core/llm/index.ts index fa16b8591..0df366bbf 100644 --- a/core/llm/index.ts +++ b/core/llm/index.ts @@ -187,6 +187,9 @@ export abstract class BaseLLM implements ILLM { maxEmbeddingChunkSize: number; maxEmbeddingBatchSize: number; + //URI to local block defining this LLM + sourceFile?: string; + private _llmOptions: LLMOptions; protected openaiAdapter?: BaseLlmApi; @@ -290,6 +293,7 @@ export abstract class BaseLLM implements ILLM { this.embeddingId = `${this.constructor.name}::${this.model}::${this.maxEmbeddingChunkSize}`; this.autocompleteOptions = options.autocompleteOptions; + this.sourceFile = options.sourceFile; } getConfigurationStatus() { diff --git a/core/protocol/core.ts b/core/protocol/core.ts index 251922696..743556d15 100644 --- a/core/protocol/core.ts +++ b/core/protocol/core.ts @@ -102,7 +102,10 @@ export type ToCoreFromIdeOrWebviewProtocol = { ), void, ]; - "config/openProfile": [{ profileId: string | undefined }, void]; + "config/openProfile": [ + { profileId: string | undefined; element?: { sourceFile?: string } }, + void, + ]; "config/updateSharedConfig": [SharedConfigSchema, SharedConfigSchema]; "config/updateSelectedModel": [ { diff --git a/gui/src/components/mainInput/Lump/EditBlockButton.tsx b/gui/src/components/mainInput/Lump/EditBlockButton.tsx index 6cdcac4b0..5705deba2 100644 --- a/gui/src/components/mainInput/Lump/EditBlockButton.tsx +++ b/gui/src/components/mainInput/Lump/EditBlockButton.tsx @@ -13,6 +13,7 @@ interface EditBlockButtonProps { blockType: T; block?: NonNullable[number]; className?: string; + sourceFile?: string; } function isUsesBlock(block: any): block is { uses: string } { @@ -23,6 +24,7 @@ export default function EditBlockButton({ block, blockType, className = "", + sourceFile, }: EditBlockButtonProps) { const ideMessenger = useContext(IdeMessengerContext); const { selectedProfile } = useAuth(); @@ -37,6 +39,7 @@ export default function EditBlockButton({ if (selectedProfile?.profileType === "local") { ideMessenger.post("config/openProfile", { profileId: undefined, + element: { sourceFile }, }); } else if (block && isUsesBlock(block)) { openUrl(`${block.uses}/new-version`); diff --git a/gui/src/components/mainInput/Lump/sections/PromptsSection.tsx b/gui/src/components/mainInput/Lump/sections/PromptsSection.tsx index c277d7d92..10fb767b3 100644 --- a/gui/src/components/mainInput/Lump/sections/PromptsSection.tsx +++ b/gui/src/components/mainInput/Lump/sections/PromptsSection.tsx @@ -121,6 +121,7 @@ export function PromptsSection() { } else { ideMessenger.post("config/openProfile", { profileId: undefined, + element: { sourceFile: (prompt as any).sourceFile }, }); } }; @@ -149,7 +150,6 @@ export function PromptsSection() { index = index + 1; } } - return promptsWithSlug.sort((a, b) => { const aBookmarked = isCommandBookmarked(a.name); const bBookmarked = isCommandBookmarked(b.name); diff --git a/gui/src/components/mainInput/Lump/sections/RulesSection.tsx b/gui/src/components/mainInput/Lump/sections/RulesSection.tsx index 5f145a169..f632cb10a 100644 --- a/gui/src/components/mainInput/Lump/sections/RulesSection.tsx +++ b/gui/src/components/mainInput/Lump/sections/RulesSection.tsx @@ -60,6 +60,7 @@ const RuleCard: React.FC = ({ rule }) => { } else { ideMessenger.post("config/openProfile", { profileId: undefined, + element: { sourceFile: (rule as any).sourceFile }, }); } }; diff --git a/gui/src/components/mainInput/Lump/sections/docs/DocsIndexingStatus.tsx b/gui/src/components/mainInput/Lump/sections/docs/DocsIndexingStatus.tsx index 9189a794c..4b946a1fd 100644 --- a/gui/src/components/mainInput/Lump/sections/docs/DocsIndexingStatus.tsx +++ b/gui/src/components/mainInput/Lump/sections/docs/DocsIndexingStatus.tsx @@ -123,7 +123,11 @@ function DocsIndexingStatus({ /> )} - + {["aborted", "complete", "failed"].includes( status?.status ?? "", diff --git a/gui/src/components/mainInput/Lump/sections/mcp/MCPSection.tsx b/gui/src/components/mainInput/Lump/sections/mcp/MCPSection.tsx index 75c0f0725..76fb338e9 100644 --- a/gui/src/components/mainInput/Lump/sections/mcp/MCPSection.tsx +++ b/gui/src/components/mainInput/Lump/sections/mcp/MCPSection.tsx @@ -132,7 +132,11 @@ function MCPServerPreview({ server, serverFromYaml }: MCPServerStatusProps) { {/* Refresh button */}
- +
ideMessenger.post("config/openProfile", { profileId: undefined, + element: { sourceFile: selectedModel?.sourceFile }, }) } /> diff --git a/gui/src/pages/config/ModelRoleSelector.tsx b/gui/src/pages/config/ModelRoleSelector.tsx index 1b73751b9..5bdac5b4a 100644 --- a/gui/src/pages/config/ModelRoleSelector.tsx +++ b/gui/src/pages/config/ModelRoleSelector.tsx @@ -48,10 +48,13 @@ const ModelRoleSelector = ({ onSelect(models.find((m) => m.title === title) ?? null); } - function onClickGear(e: MouseEvent) { + function onClickGear(e: MouseEvent, model: ModelDescription) { e.stopPropagation(); e.preventDefault(); - ideMessenger.post("config/openProfile", { profileId: undefined }); + ideMessenger.post("config/openProfile", { + profileId: undefined, + element: model, + }); } function handleOptionClick( @@ -169,7 +172,9 @@ const ModelRoleSelector = ({ {hoveredIdx === idx && ( ) => + onClickGear(e, option) + } /> )} {option.title === selectedModel?.title && ( diff --git a/gui/src/pages/gui/StreamError.tsx b/gui/src/pages/gui/StreamError.tsx index 58fcaf97b..6af153338 100644 --- a/gui/src/pages/gui/StreamError.tsx +++ b/gui/src/pages/gui/StreamError.tsx @@ -77,6 +77,7 @@ const StreamErrorDialog = ({ error }: StreamErrorProps) => { onClick={() => { ideMessenger.post("config/openProfile", { profileId: undefined, + element: selectedModel ?? undefined, }); }} > diff --git a/packages/config-types/src/index.ts b/packages/config-types/src/index.ts index 8591c6b74..fbc2d45fc 100644 --- a/packages/config-types/src/index.ts +++ b/packages/config-types/src/index.ts @@ -210,6 +210,7 @@ export const siteIndexingConfigSchema = z.object({ maxDepth: z.number().optional(), faviconUrl: z.string().optional(), useLocalCrawling: z.boolean().optional(), + sourceFile: z.string().optional(), }); export const controlPlaneConfigSchema = z.object({ diff --git a/packages/config-yaml/src/load/unroll.ts b/packages/config-yaml/src/load/unroll.ts index 80403b544..adbe45324 100644 --- a/packages/config-yaml/src/load/unroll.ts +++ b/packages/config-yaml/src/load/unroll.ts @@ -452,7 +452,15 @@ export async function unrollBlocks( registry, ); - return { blockType, resolvedBlock, error: null }; + return { + blockType, + resolvedBlock, + source: + injectBlock.uriType === "file" + ? injectBlock.filePath + : undefined, + error: null, + }; } catch (err) { let msg = ""; if (injectBlock.uriType === "file") { @@ -475,7 +483,11 @@ export async function unrollBlocks( const injectedResults = await Promise.all(injectedBlockPromises); const injectedErrors: ConfigValidationError[] = []; - const injectedBlocks: { blockType: string; resolvedBlock: any }[] = []; + const injectedBlocks: { + blockType: string; + resolvedBlock: any; + source?: string; + }[] = []; for (const result of injectedResults) { if (result.error) { @@ -484,6 +496,7 @@ export async function unrollBlocks( injectedBlocks.push({ blockType: result.blockType, resolvedBlock: result.resolvedBlock, + source: result.source, }); } } @@ -521,12 +534,21 @@ export async function unrollBlocks( } // Add injected blocks - for (const { blockType, resolvedBlock } of injectedResult.injectedBlocks) { + for (const { + blockType, + resolvedBlock, + source, + } of injectedResult.injectedBlocks) { const key = blockType as BlockType; if (!unrolledAssistant[key]) { unrolledAssistant[key] = []; } - unrolledAssistant[key]?.push(...((resolvedBlock[blockType] ?? []) as any)); + const blocksWithSourceFiles = injectLocalSourceFile( + key, + resolvedBlock, + source, + ); + unrolledAssistant[key]?.push(...blocksWithSourceFiles); } const configResult: ConfigResult = { @@ -541,6 +563,39 @@ export async function unrollBlocks( return configResult; } +function injectLocalSourceFile( + blockType: BlockType, + resolvedBlock: any, + source?: string, +): (any & { source?: string })[] { + const blocks: any[] = resolvedBlock[blockType] ?? []; + if (source === undefined) { + // If no source is provided, return blocks as is + return blocks; + } + if (blockType === "rules") { + // For rules, we need to ensure they are wrapped in an object with a `source + return blocks.map((block) => { + if (typeof block === "string") { + const rule = { + sourceFile: source, + name: block, + rule: block, + } as Rule; + return rule; + } else if (typeof block === "object") { + block.sourceFile = source; + } + return block; + }); + } + // For other block types, we can directly inject the source file + return blocks.map((block) => ({ + ...block, + sourceFile: source, + })); +} + export async function resolveBlock( id: PackageIdentifier, inputs: Record | undefined, diff --git a/packages/config-yaml/src/markdown/markdownToRule.ts b/packages/config-yaml/src/markdown/markdownToRule.ts index 231b2ab4a..f584a0549 100644 --- a/packages/config-yaml/src/markdown/markdownToRule.ts +++ b/packages/config-yaml/src/markdown/markdownToRule.ts @@ -112,5 +112,6 @@ export function markdownToRule( regex: frontmatter.regex, description: frontmatter.description, alwaysApply: frontmatter.alwaysApply, + sourceFile: id.uriType === "file" ? id.filePath : undefined, }; } diff --git a/packages/config-yaml/src/schemas/index.ts b/packages/config-yaml/src/schemas/index.ts index 4ac2aa1f5..e7d56d82f 100644 --- a/packages/config-yaml/src/schemas/index.ts +++ b/packages/config-yaml/src/schemas/index.ts @@ -25,6 +25,7 @@ const mcpServerSchema = z.object({ cwd: z.string().optional(), connectionTimeout: z.number().gt(0).optional(), requestOptions: requestOptionsSchema.optional(), + sourceFile: z.string().optional(), }); export type MCPServer = z.infer; @@ -33,6 +34,7 @@ const promptSchema = z.object({ name: z.string(), description: z.string().optional(), prompt: z.string(), + sourceFile: z.string().optional(), }); export type Prompt = z.infer; @@ -44,6 +46,7 @@ const docSchema = z.object({ faviconUrl: z.string().optional(), maxDepth: z.number().optional(), useLocalCrawling: z.boolean().optional(), + sourceFile: z.string().optional(), }); export type DocsConfig = z.infer; @@ -55,6 +58,7 @@ const ruleObjectSchema = z.object({ globs: z.union([z.string(), z.array(z.string())]).optional(), regex: z.union([z.string(), z.array(z.string())]).optional(), alwaysApply: z.boolean().optional(), + sourceFile: z.string().optional(), //TODO refactor RuleWithSource.ruleFile to align with sourceFile }); const ruleSchema = z.union([z.string(), ruleObjectSchema]); diff --git a/packages/config-yaml/src/schemas/models.ts b/packages/config-yaml/src/schemas/models.ts index 8bdb6b66d..283ec6781 100644 --- a/packages/config-yaml/src/schemas/models.ts +++ b/packages/config-yaml/src/schemas/models.ts @@ -163,6 +163,7 @@ export const modelSchema = z.union([ z.object({ ...baseModelFields, provider: z.string().refine((val) => val !== "continue-proxy"), + sourceFile: z.string().optional(), }), ]);