Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 10 additions & 14 deletions core/config/profile/LocalProfileLoader.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ConfigResult, parseConfigYaml } from "@continuedev/config-yaml";
import { ConfigResult } from "@continuedev/config-yaml";

import { ControlPlaneClient } from "../../control-plane/client.js";
import { ContinueConfig, IDE, ILLMLogger } from "../../index.js";
Expand All @@ -13,6 +13,8 @@ import { IProfileLoader } from "./IProfileLoader.js";
export default class LocalProfileLoader implements IProfileLoader {
static ID = "local";

description: ProfileDescription;

constructor(
private ide: IDE,
private controlPlaneClient: ControlPlaneClient,
Expand All @@ -21,7 +23,7 @@ export default class LocalProfileLoader implements IProfileLoader {
| { path: string; content: string }
| undefined,
) {
const description: ProfileDescription = {
this.description = {
id: overrideAssistantFile?.path ?? LocalProfileLoader.ID,
profileType: "local",
fullSlug: {
Expand All @@ -39,19 +41,7 @@ export default class LocalProfileLoader implements IProfileLoader {
localPathToUri(getPrimaryConfigFilePath()),
rawYaml: undefined,
};
this.description = description;
if (overrideAssistantFile?.content) {
try {
const parsedAssistant = parseConfigYaml(
overrideAssistantFile?.content ?? "",
);
this.description.title = parsedAssistant.name;
} catch (e) {
console.error("Failed to parse config file: ", e);
}
}
}
description: ProfileDescription;

async doLoadConfig(): Promise<ConfigResult<ContinueConfig>> {
const result = await doLoadConfig({
Expand All @@ -72,6 +62,12 @@ export default class LocalProfileLoader implements IProfileLoader {

this.description.errors = result.errors;

// Use the config name from the loaded config (avoids duplicate file reads
// and works in environments like WSL where paths may differ)
if (result.configName) {
this.description.title = result.configName;
}

return result;
}

Expand Down
39 changes: 39 additions & 0 deletions core/config/profile/LocalProfileLoader.vitest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,43 @@ describe("LocalProfileLoader", () => {
}),
);
});

it("should update title from configName when available", async () => {
mockDoLoadConfig.mockResolvedValueOnce({
config: {},
errors: [],
configLoadInterrupted: false,
configName: "My Custom Config",
});

const loader = new LocalProfileLoader(
testIde,
controlPlaneClient,
llmLogger,
);

expect(loader.description.title).toBe("Local Config");

await loader.doLoadConfig();

expect(loader.description.title).toBe("My Custom Config");
});

it("should keep default title when configName is not set", async () => {
mockDoLoadConfig.mockResolvedValueOnce({
config: {},
errors: [],
configLoadInterrupted: false,
});

const loader = new LocalProfileLoader(
testIde,
controlPlaneClient,
llmLogger,
);

await loader.doLoadConfig();

expect(loader.description.title).toBe("Local Config");
});
});
16 changes: 14 additions & 2 deletions core/config/profile/doLoadConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ export default async function doLoadConfig(options: {
let newConfig: ContinueConfig | undefined;
let errors: ConfigValidationError[] | undefined;
let configLoadInterrupted = false;
let configName: string | undefined;

const hasPreReadContent =
packageIdentifier.uriType === "file" &&
Expand All @@ -138,6 +139,7 @@ export default async function doLoadConfig(options: {
newConfig = result.config;
errors = result.errors;
configLoadInterrupted = result.configLoadInterrupted;
configName = result.configName;
} else {
const result = await loadContinueConfigFromJson(
ide,
Expand All @@ -154,7 +156,12 @@ export default async function doLoadConfig(options: {
}

if (configLoadInterrupted || !newConfig) {
return { errors, config: newConfig, configLoadInterrupted: true };
return {
errors,
config: newConfig,
configLoadInterrupted: true,
configName,
};
}

// TODO using config result but result with non-fatal errors is an antipattern?
Expand Down Expand Up @@ -446,7 +453,12 @@ export default async function doLoadConfig(options: {
controlPlaneProxyInfo,
);

return { config: newConfig, errors, configLoadInterrupted: false };
return {
config: newConfig,
errors,
configLoadInterrupted: false,
configName,
};
}

// Pass ControlPlaneProxyInfo to objects that need it
Expand Down
2 changes: 2 additions & 0 deletions core/config/yaml/loadYaml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,7 @@ export async function loadContinueConfigFromYaml(options: {
errors: configYamlResult.errors,
config: undefined,
configLoadInterrupted: true,
configName: configYamlResult.configName,
};
}

Expand Down Expand Up @@ -495,5 +496,6 @@ export async function loadContinueConfigFromYaml(options: {
config: withShared,
errors: [...(configYamlResult.errors ?? []), ...localErrors],
configLoadInterrupted: false,
configName: configYamlResult.configName,
};
}
12 changes: 10 additions & 2 deletions packages/config-yaml/src/load/unroll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,10 +310,12 @@ export async function unrollAssistantFromContent(
});

if (!options.renderSecrets) {
const parsed = parseAssistantUnrolled(templatedYaml);
return {
config: parseAssistantUnrolled(templatedYaml),
config: parsed,
errors: [],
configLoadInterrupted: false,
configName: parsed?.name || undefined,
};
}

Expand All @@ -333,7 +335,12 @@ export async function unrollAssistantFromContent(
options.onPremProxyUrl,
);

return { config: renderedConfig, errors, configLoadInterrupted };
return {
config: renderedConfig,
errors,
configLoadInterrupted,
configName: renderedConfig?.name || undefined,
};
}

function isPackageAllowed(
Expand Down Expand Up @@ -678,6 +685,7 @@ export async function unrollBlocks(
config: undefined,
errors: undefined,
configLoadInterrupted: false,
configName: unrolledAssistant.name || undefined,
};
configResult.config = unrolledAssistant;
if (errors.length > 0) {
Expand Down
2 changes: 2 additions & 0 deletions packages/config-yaml/src/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ export interface ConfigResult<T> {
config: T | undefined;
errors: ConfigValidationError[] | undefined;
configLoadInterrupted: boolean;
/** Optional display name from config.yaml `name` field */
configName?: string;
}

function containsUnicode(str: string): boolean {
Expand Down
Loading