fix(onboarding): auto-install shell completion in QuickStart

This commit is contained in:
Peter Steinberger
2026-02-09 12:56:06 -06:00
parent 512b2053c5
commit 394d60c1fb
4 changed files with 179 additions and 50 deletions

View File

@@ -6,9 +6,7 @@ import type { RuntimeEnv } from "../runtime.js";
import type { GatewayWizardSettings, WizardFlow } from "./onboarding.types.js";
import type { WizardPrompter } from "./prompts.js";
import { DEFAULT_BOOTSTRAP_FILENAME } from "../agents/workspace.js";
import { resolveCliName } from "../cli/cli-name.js";
import { formatCliCommand } from "../cli/command-format.js";
import { installCompletion } from "../cli/completion-cli.js";
import {
buildGatewayInstallPlan,
gatewayInstallErrorHint,
@@ -17,10 +15,6 @@ import {
DEFAULT_GATEWAY_DAEMON_RUNTIME,
GATEWAY_DAEMON_RUNTIME_OPTIONS,
} from "../commands/daemon-runtime.js";
import {
checkShellCompletionStatus,
ensureCompletionCacheExists,
} from "../commands/doctor-completion.js";
import { formatHealthCheckFailure } from "../commands/health-format.js";
import { healthCommand } from "../commands/health.js";
import {
@@ -37,6 +31,7 @@ import { ensureControlUiAssetsBuilt } from "../infra/control-ui-assets.js";
import { restoreTerminalState } from "../terminal/restore.js";
import { runTui } from "../tui/tui.js";
import { resolveUserPath } from "../utils.js";
import { setupOnboardingShellCompletion } from "./onboarding.completion.js";
type FinalizeOnboardingOptions = {
flow: WizardFlow;
@@ -397,50 +392,7 @@ export async function finalizeOnboardingWizard(
"Security",
);
// Shell completion setup
const cliName = resolveCliName();
const completionStatus = await checkShellCompletionStatus(cliName);
if (completionStatus.usesSlowPattern) {
// Case 1: Profile uses slow dynamic pattern - silently upgrade to cached version
const cacheGenerated = await ensureCompletionCacheExists(cliName);
if (cacheGenerated) {
await installCompletion(completionStatus.shell, true, cliName);
}
} else if (completionStatus.profileInstalled && !completionStatus.cacheExists) {
// Case 2: Profile has completion but no cache - auto-fix silently
await ensureCompletionCacheExists(cliName);
} else if (!completionStatus.profileInstalled) {
// Case 3: No completion at all - prompt to install
const installShellCompletion = await prompter.confirm({
message: `Enable ${completionStatus.shell} shell completion for ${cliName}?`,
initialValue: true,
});
if (installShellCompletion) {
// Generate cache first (required for fast shell startup)
const cacheGenerated = await ensureCompletionCacheExists(cliName);
if (cacheGenerated) {
// Install to shell profile
await installCompletion(completionStatus.shell, true, cliName);
const profileHint =
completionStatus.shell === "zsh"
? "~/.zshrc"
: completionStatus.shell === "bash"
? "~/.bashrc"
: "~/.config/fish/config.fish";
await prompter.note(
`Shell completion installed. Restart your shell or run: source ${profileHint}`,
"Shell completion",
);
} else {
await prompter.note(
`Failed to generate completion cache. Run \`${cliName} completion --install\` later.`,
"Shell completion",
);
}
}
}
// Case 4: Both profile and cache exist (using cached version) - all good, nothing to do
await setupOnboardingShellCompletion({ flow, prompter });
const shouldOpenControlUi =
!opts.skipUi &&