From bb1b30d329794932bef207aca68ec2237d861c8b Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Mon, 13 Apr 2026 15:12:21 +0100 Subject: [PATCH] perf(wizard): keep explicit skip auth path cold --- src/wizard/setup.test.ts | 1 + src/wizard/setup.ts | 105 +++++++++++++++++++++++---------------- 2 files changed, 63 insertions(+), 43 deletions(-) diff --git a/src/wizard/setup.test.ts b/src/wizard/setup.test.ts index 1b59aba655a..3d14ddd8cc9 100644 --- a/src/wizard/setup.test.ts +++ b/src/wizard/setup.test.ts @@ -346,6 +346,7 @@ describe("runSetupWizard", () => { ); expect(select).not.toHaveBeenCalled(); + expect(ensureAuthProfileStore).not.toHaveBeenCalled(); expect(setupChannels).not.toHaveBeenCalled(); expect(setupSkills).not.toHaveBeenCalled(); expect(healthCommand).not.toHaveBeenCalled(); diff --git a/src/wizard/setup.ts b/src/wizard/setup.ts index 15834e85db5..bf32f310d70 100644 --- a/src/wizard/setup.ts +++ b/src/wizard/setup.ts @@ -483,28 +483,25 @@ export async function runSetupWizard( const { applyLocalSetupWorkspaceConfig } = await import("../commands/onboard-config.js"); let nextConfig: OpenClawConfig = applyLocalSetupWorkspaceConfig(baseConfig, workspaceDir); - const { ensureAuthProfileStore } = await import("../agents/auth-profiles.runtime.js"); - const { promptAuthChoiceGrouped } = await import("../commands/auth-choice-prompt.js"); - const { promptCustomApiConfig } = await import("../commands/onboard-custom.js"); - const { applyAuthChoice, resolvePreferredProviderForAuthChoice, warnIfModelConfigLooksOff } = - await import("../commands/auth-choice.js"); - const { applyPrimaryModel, promptDefaultModel } = await import("../commands/model-picker.js"); - - const authStore = ensureAuthProfileStore(undefined, { - allowKeychainPrompt: false, - }); const authChoiceFromPrompt = opts.authChoice === undefined; - const authChoice = - opts.authChoice ?? - (await promptAuthChoiceGrouped({ + let authChoice = opts.authChoice; + if (authChoiceFromPrompt) { + const { ensureAuthProfileStore } = await import("../agents/auth-profiles.runtime.js"); + const { promptAuthChoiceGrouped } = await import("../commands/auth-choice-prompt.js"); + const authStore = ensureAuthProfileStore(undefined, { + allowKeychainPrompt: false, + }); + authChoice = await promptAuthChoiceGrouped({ prompter, store: authStore, includeSkip: true, config: nextConfig, workspaceDir, - })); + }); + } if (authChoice === "custom-api-key") { + const { promptCustomApiConfig } = await import("../commands/onboard-custom.js"); const customResult = await promptCustomApiConfig({ prompter, runtime, @@ -512,7 +509,34 @@ export async function runSetupWizard( secretInputMode: opts.secretInputMode, }); nextConfig = customResult.config; + } else if (authChoice === "skip") { + // Explicit skip should stay cold: do not bootstrap auth/profile machinery + // or run model/auth checks when the caller already chose to skip setup. + if (authChoiceFromPrompt) { + const { applyPrimaryModel, promptDefaultModel } = await import("../commands/model-picker.js"); + const modelSelection = await promptDefaultModel({ + config: nextConfig, + prompter, + allowKeep: true, + ignoreAllowlist: true, + includeProviderPluginSetups: true, + workspaceDir, + runtime, + }); + if (modelSelection.config) { + nextConfig = modelSelection.config; + } + if (modelSelection.model) { + nextConfig = applyPrimaryModel(nextConfig, modelSelection.model); + } + + const { warnIfModelConfigLooksOff } = await import("../commands/auth-choice.js"); + await warnIfModelConfigLooksOff(nextConfig, prompter); + } } else { + const { applyAuthChoice, resolvePreferredProviderForAuthChoice, warnIfModelConfigLooksOff } = + await import("../commands/auth-choice.js"); + const { applyPrimaryModel, promptDefaultModel } = await import("../commands/model-picker.js"); const authResult = await applyAuthChoice({ authChoice, config: nextConfig, @@ -525,44 +549,39 @@ export async function runSetupWizard( }, }); nextConfig = authResult.config; - if (authResult.agentModelOverride) { nextConfig = applyPrimaryModel(nextConfig, authResult.agentModelOverride); } - } - const authChoiceModelSelectionPolicy = - authChoice === "custom-api-key" - ? undefined - : await resolveAuthChoiceModelSelectionPolicy({ - authChoice, - config: nextConfig, - workspaceDir, - resolvePreferredProviderForAuthChoice, - }); - const shouldPromptModelSelection = - authChoice !== "custom-api-key" && - (authChoiceFromPrompt || authChoiceModelSelectionPolicy?.promptWhenAuthChoiceProvided === true); - if (shouldPromptModelSelection) { - const modelSelection = await promptDefaultModel({ + const authChoiceModelSelectionPolicy = await resolveAuthChoiceModelSelectionPolicy({ + authChoice, config: nextConfig, - prompter, - allowKeep: authChoiceModelSelectionPolicy?.allowKeepCurrent ?? true, - ignoreAllowlist: true, - includeProviderPluginSetups: true, - preferredProvider: authChoiceModelSelectionPolicy?.preferredProvider, workspaceDir, - runtime, + resolvePreferredProviderForAuthChoice, }); - if (modelSelection.config) { - nextConfig = modelSelection.config; + const shouldPromptModelSelection = + authChoiceFromPrompt || authChoiceModelSelectionPolicy?.promptWhenAuthChoiceProvided; + if (shouldPromptModelSelection) { + const modelSelection = await promptDefaultModel({ + config: nextConfig, + prompter, + allowKeep: authChoiceModelSelectionPolicy?.allowKeepCurrent ?? true, + ignoreAllowlist: true, + includeProviderPluginSetups: true, + preferredProvider: authChoiceModelSelectionPolicy?.preferredProvider, + workspaceDir, + runtime, + }); + if (modelSelection.config) { + nextConfig = modelSelection.config; + } + if (modelSelection.model) { + nextConfig = applyPrimaryModel(nextConfig, modelSelection.model); + } } - if (modelSelection.model) { - nextConfig = applyPrimaryModel(nextConfig, modelSelection.model); - } - } - await warnIfModelConfigLooksOff(nextConfig, prompter); + await warnIfModelConfigLooksOff(nextConfig, prompter); + } const { configureGatewayForSetup } = await import("./setup.gateway-config.js"); const gateway = await configureGatewayForSetup({