diff --git a/extensions/cli/src/configLoader.ts b/extensions/cli/src/configLoader.ts index c3ccd6296..eb1c47f55 100644 --- a/extensions/cli/src/configLoader.ts +++ b/extensions/cli/src/configLoader.ts @@ -1,5 +1,6 @@ import * as fs from "fs"; import { dirname } from "node:path"; +import { fileURLToPath } from "node:url"; import * as path from "path"; import { @@ -24,6 +25,7 @@ import { } from "./auth/workos.js"; import { CLIPlatformClient } from "./CLIPlatformClient.js"; import { env } from "./env.js"; +import { logger } from "./util/logger.js"; export interface ConfigLoadResult { config: AssistantUnrolled; @@ -95,16 +97,28 @@ function determineConfigSource( return { type: "cli-flag", path: cliConfigPath }; } - // In headless, config fallback behavior isn't supported - if (isHeadless) { - return { type: "no-config" }; - } - // Priority 2: Saved config URI (only for file-based auth) if (!isEnvironmentAuthConfig(authConfig) && authConfig !== null) { const savedUri = getConfigUri(authConfig); + if (savedUri) { - return { type: "saved-uri", uri: savedUri }; + if (savedUri.startsWith("file:")) { + let exists = false; // wrote like this for nested depth linting rule lol + try { + const filepath = fileURLToPath(savedUri); + exists = fs.existsSync(filepath); + } catch (e) { + logger.warn("Invalid saved file URI " + savedUri, e); + } + if (exists) { + return { type: "saved-uri", uri: savedUri }; + } else { + logger.warn("Saved config URI does not exist: " + savedUri); + } + } else { + // slug + return { type: "saved-uri", uri: savedUri }; + } } } @@ -117,6 +131,10 @@ function determineConfigSource( } return { type: "default-agent" }; } else { + // In headless, user assistant fallback behavior isn't supported + if (isHeadless) { + return { type: "no-config" }; + } // Authenticated: try user assistants first return { type: "user-assistant", slug: "" }; // Empty slug means "first available" } diff --git a/extensions/cli/src/services/ConfigService.test.ts b/extensions/cli/src/services/ConfigService.test.ts index 6a4820553..067cc01b3 100644 --- a/extensions/cli/src/services/ConfigService.test.ts +++ b/extensions/cli/src/services/ConfigService.test.ts @@ -677,11 +677,14 @@ describe("ConfigService", () => { config, mockApiClient as any, { accessToken: "token" } as any, + true, ), - ).rejects.toThrow("No model specified and failed to load default model"); + ).rejects.toThrow( + "No model specified in headless mode (and failed to load default model)", + ); }); - test("should throw error when loaded default model is empty", async () => { + test("should throw error when loaded default model is empty in headless", async () => { const config = { name: "test-config", version: "1.0.0", @@ -704,8 +707,11 @@ describe("ConfigService", () => { config, mockApiClient as any, { accessToken: "token" } as any, + true, ), - ).rejects.toThrow("No model specified and failed to load default model"); + ).rejects.toThrow( + "No model specified in headless mode (and failed to load default model)", + ); }); test("should work with null access token", async () => { diff --git a/extensions/cli/src/services/ConfigService.ts b/extensions/cli/src/services/ConfigService.ts index 864c84cc9..555e0a3e0 100644 --- a/extensions/cli/src/services/ConfigService.ts +++ b/extensions/cli/src/services/ConfigService.ts @@ -215,6 +215,7 @@ export class ConfigService config: AssistantUnrolled, apiClient: DefaultApiInterface, authConfig: AuthConfig | undefined, + isHeadless?: boolean, ): Promise { const hasChatModel = !!config.models?.find( (m) => !!m && (!m.roles || m.roles.includes("chat")), @@ -233,8 +234,16 @@ export class ConfigService } config.models = [...(config.models || []), defaultModel]; } catch (e) { - logger.error("Failed to load default model with no model specified", e); - throw new Error("No model specified and failed to load default model"); + if (isHeadless) { + throw new Error( + "No model specified in headless mode (and failed to load default model)", + ); + } else { + logger.error( + "Failed to load default model with no model specified", + e, + ); + } } } return config; @@ -270,6 +279,7 @@ export class ConfigService merged, apiClient, authConfig, + init.isHeadless, ); // Config URI persistence is now handled by the streamlined loader diff --git a/extensions/cli/src/services/ModelService.ts b/extensions/cli/src/services/ModelService.ts index 0c36e1971..2e43062e4 100644 --- a/extensions/cli/src/services/ModelService.ts +++ b/extensions/cli/src/services/ModelService.ts @@ -64,8 +64,9 @@ export class ModelService preferredModelName = agentFileServiceState.agentFileModel?.name; modelSource = "agentFile"; } else { - preferredModelName = getModelName(authConfig); - if (preferredModelName) { + const persistedName = getModelName(authConfig); + if (persistedName) { + preferredModelName = persistedName; modelSource = "persisted"; } } diff --git a/extensions/cli/src/ui/UpdateNotification.test.tsx b/extensions/cli/src/ui/UpdateNotification.test.tsx index 5dc4c89a0..3579ac6b3 100644 --- a/extensions/cli/src/ui/UpdateNotification.test.tsx +++ b/extensions/cli/src/ui/UpdateNotification.test.tsx @@ -119,7 +119,7 @@ describe("UpdateNotification", () => { const { lastFrame } = render(); - expect(lastFrame()).toContain("◉ Updating to v1.0.1"); + expect(lastFrame()).toContain("Updating to v1.0.1"); }); it("should show updated message when update completes", () => {