/** * [WHO]: Provides SelfUpdateController, SelfUpdateContext — version check / update / reinstall / restart * [FROM]: Depends on @catui/tui (Container/Text/Spacer), config (VERSION/PACKAGE_NAME), * theme, components/dynamic-border, node:child_process (spawn) * [TO]: Consumed by modes/interactive/interactive-mode.ts (constructs one, delegates /update, /reinstall, startup check) * [HERE]: modes/interactive/controllers/self-update-controller.ts — P5 UI slice (UI02, 纯搬) * * Extracted from InteractiveMode (P5 self-update). Owns the npm-based update/reinstall workflow * and the startup version check — an ops flow that happens to use the TUI for prompts. Reads chat * container / render / settings / selector through a narrow SelfUpdateContext (no InteractiveMode * reference). Behavior is identical to the former InteractiveMode methods. P5 keeps it inside * modes/interactive; only a second mode consumer would justify moving it to modes/_shell/update. */ import { type Container } from "@catui/tui"; /** Narrow capability seam: the chat/render/settings/selector capabilities the updater needs. */ export interface SelfUpdateContext { /** The chat container the updater renders progress/results into. */ getChatContainer(): Container; /** Request a TUI re-render. */ requestRender(): void; getAutoUpdate(): "always" | "prompt" | "never"; getSkippedVersion(): string | undefined; setSkippedVersion(version: string | undefined): void; setAutoUpdate(mode: "always" | "prompt" | "never"): void; /** Present a selector overlay (delegates to the extension-selector UI). */ showSelector(title: string, options: string[]): Promise; } export declare class SelfUpdateController { private readonly ctx; private pollTimer; constructor(ctx: SelfUpdateContext); private get chat(); private render; checkForNewVersion(): Promise; showNewVersionNotification(newVersion: string): Promise; handleUpdateCommand(): Promise; /** * Handle /reinstall command - force clean reinstall. */ handleReinstallCommand(): void; /** * Check for updates on startup. * - "always": silently install in background, notify user when done. * - "prompt": show selector dialog asking user what to do. * - "never": no-op. */ checkAutoUpdateOnStartup(): Promise; /** * Start background polling for updates (every 30 minutes). * Only active when autoUpdate is "always". */ startBackgroundPolling(): void; /** * Stop background polling (called on shutdown). */ stopBackgroundPolling(): void; /** * Fetch the latest version from npm registry. * Returns the version string or undefined if check fails. */ private fetchLatestVersion; /** * Silently install update in background. On success, show a persistent * notification banner. No interactive prompts — user discovers it passively. */ private silentInstall; /** * Show interactive update options when a new version is available. */ private showUpdateOptions; /** * Perform the actual npm install update. */ private performUpdate; /** * Show retry options after a failed update attempt. */ private showRetryOptions; /** * Wait for a specific key press from user. * Falls back to selector UI if TTY is not available. */ private waitForKeyPress; /** * Restart Catui by spawning a new process. * Tries to detect the correct command to restart. */ private restartCatui; /** * Compare two version strings (semver style). * Returns: 1 if v1 > v2, -1 if v1 < v2, 0 if equal */ private compareVersion; }