import type { ImageContent } from "@catui/ai/types"; import { type AgentSession } from "../../core/runtime/agent-session.js"; /** * Options for InteractiveMode initialization. */ export interface InteractiveModeOptions { /** Providers that were migrated to auth.json (shows warning) */ migratedProviders?: string[]; /** Warning message if session model couldn't be restored */ modelFallbackMessage?: string; /** Initial message to send on startup (can include @file content) */ initialMessage?: string; /** Images to attach to the initial message */ initialImages?: ImageContent[]; /** Additional messages to send after the initial message */ initialMessages?: string[]; /** Force verbose startup (overrides quietStartup setting) */ verbose?: boolean; } export declare class InteractiveMode { private options; private session; private ui; private chatContainer; private pendingMessagesContainer; private statusContainer; private defaultEditor; private editor; private autocompleteProvider; private fdPath; private startupToolsPrewarmed; private editorContainer; private footer; private buddyPet; private buddyPetSpecies; private buddyPetResetTimer; private footerDataProvider; private keybindings; private version; private isInitialized; private onInputCallback?; private readonly catWorkingMessages; private catMessageIndex; private catMessageLastSwitch; /** Consolidated render/turn UI state (streaming, tools, loaders, run timers, status, queues). */ private readonly state; private skillCommands; private unsubscribe?; private isBashMode; private bashComponent; private pendingBashComponents; private shutdownRequested; private statusTimers; private notificationQueue; private extensionTerminalInputUnsubscribers; private widgetContainerAbove; private widgetContainerBelow; /** Pet column next to the input (right side, compact coding-agent style). */ private buddySlot; private editorBuddyLayout; private headerContainer; private builtInHeader; private attachmentsContainer; private imagePipeline; private selfUpdate; private authProviderConfig; private modelOverlay; private treeOverlay; private settingsOverlay; private slashDispatcher; private inputSubmit; private interrupt; private streamRender; private surfaces; private promptHost; private customOverlay; private editorAdapter; private get agent(); private get sessionManager(); private get settingsManager(); constructor(session: AgentSession, options?: InteractiveModeOptions); private setupAutocomplete; private prewarmStartupTools; init(): Promise; /** * 同步构建 header + layout。把这段从 init() 抽出,让 init() * 的主体只剩"装配与启动",阅读性更好。 */ private buildHeaderAndLayout; /** * Update terminal title with session name and cwd. */ private updateTerminalTitle; /** * Run the interactive mode. This is the main entry point. * Initializes the UI, shows warnings, processes initial messages, and starts the interactive loop. */ run(): Promise; /** * Check npm registry for a newer version. */ private getMarkdownThemeWithSettings; private formatDisplayPath; /** * Get a short path relative to the package root for display. */ private getShortPath; private getDisplaySourceInfo; private getScopeGroup; private isPackageSource; private buildScopeGroups; private formatScopeGroups; /** * Find metadata for a path, checking parent directories if exact match fails. * Package manager stores metadata for directories, but we display file paths. */ private findMetadata; /** * Format a path with its source/scope info from metadata. */ private formatPathWithSource; /** * Format resource diagnostics with nice collision display using metadata. */ private formatDiagnostics; private showLoadedResources; /** * Initialize the extension system with TUI-based UI context. */ private initExtensions; /** * Get a registered tool definition by name (for custom rendering). */ private getRegisteredToolDefinition; /** * Set up keyboard shortcuts registered by extensions. */ private setupExtensionShortcuts; private formatElapsedSeconds; private getNextCatMessage; private buildWorkingMessage; private updateWorkingMessage; private stopAgentRunTimer; private stopWelcomeBannerTimer; private startAgentRunTimer; private resetExtensionUI; private clearBuddyPetResetTimer; private syncBuddyPet; /** * Restore attachments bar (if any) + editor row with optional buddy column. */ private remountEditorShell; private setBuddyPetState; private addExtensionTerminalInputListener; private clearExtensionTerminalInputListeners; /** * Create the ExtensionUIContext for extensions. */ private createExtensionUIContext; /** * Show a notification for extensions. */ private showExtensionNotify; private shouldRenderToolTrace; /** * Show an extension error in the UI. */ private showExtensionError; private setupKeyHandlers; private setupEditorSubmitHandler; private subscribeToAgent; private addSessionNavigationBanner; private handleEvent; /** Extract text content from a user message */ private getUserMessageText; /** * Show a status message in the chat. * * If multiple status messages are emitted back-to-back (without anything else being added to the chat), * we update the previous status line instead of appending new ones to avoid log spam. * Auto-dismisses after 5 seconds. */ private showStatus; private addMessageToChat; /** * Render session context to chat. Used for initial load and rebuild after compaction. * @param sessionContext Session context to render * @param options.updateFooter Update footer state * @param options.populateHistory Add user messages to editor history */ private renderSessionContext; renderInitialMessages(options?: { requestRender?: boolean; }): void; getUserInput(): Promise; private rebuildChatFromMessages; /** * Gracefully shutdown the agent. * Emits shutdown event to extensions (with timeout guard), then exits. */ private isShuttingDown; private shutdown; /** * Check if shutdown was requested and perform shutdown if so. */ private checkShutdownRequested; /** TUI suspend mechanic (Ctrl-Z): stop the TUI, SIGTSTP the group, restore on SIGCONT. */ private suspend; private handleFollowUp; private handleDequeue; private promptAfterRender; private updateEditorBorderColor; private handleAgentLoopCommand; private toggleToolOutputExpansion; private setToolsExpanded; private toggleThinkingBlockVisibility; private openExternalEditor; private openExistingFileInExternalEditor; clearEditor(): void; showError(errorMessage: string): void; showWarning(warningMessage: string): void; /** * Schedule auto-removal of a status/warning message after 5 seconds. */ private scheduleStatusDismiss; /** * Cancel all pending status dismiss timers (e.g., on /clear). */ private clearStatusTimers; /** * Show a priority notification (floating, auto-dismiss, dedup by key). */ notify(message: string, options?: { key?: string; priority?: "immediate" | "high" | "medium" | "low"; type?: "info" | "warning" | "error"; duration?: number; }): void; /** * Get all queued messages (read-only). * Combines session queue and compaction queue. */ private getAllQueuedMessages; /** * Clear all queued messages and return their contents. * Clears both session queue and compaction queue. */ private clearAllQueues; private updatePendingMessagesDisplay; private restoreQueuedMessagesToEditor; private queueCompactionMessage; private isExtensionCommand; private flushCompactionQueue; /** Move pending bash components from pending area to chat */ private flushPendingBashComponents; /** * Shows a selector component in place of the editor. * @param create Factory that receives a `done` callback and returns the component and focus target */ private showSelector; private handleReloadCommand; private handleExportCommand; private handleShareCommand; private handleCopyCommand; /** * Handle /status command - show agent status card (Codex-style) */ private handleStatusCommand; /** * Handle /usage command - show token usage statistics */ private handleUsageCommand; private handleNameCommand; private handleSessionCommand; private handleChangelogCommand; /** * Capitalize keybinding for display (e.g., "ctrl+c" -> "Ctrl+C"). */ private capitalizeKey; /** * Get capitalized display string for an app keybinding action. */ private getAppKeyDisplay; /** * Get capitalized display string for an editor keybinding action. */ private getEditorKeyDisplay; private handleHotkeysCommand; private handleClearCommand; private handleRenderDebugCommand; private handleArminSaysHi; private handleShowResourcesCommand; private handleDaxnuts; private handleBashCommand; private handleCompactCommand; private executeCompaction; stop(): void; /** * If session is tagged with a persona, apply it to env + active persona file, * then reload session runtime so Catui/Soul/NanoMem/Skills/MCP can be re-wired. */ private applyPersonaFromSessionIfAny; private handleSoulCommand; private handlePersonaCommand; private switchPersona; private handleMemoryCommand; private getAvailablePersonaIds; private handleBrowserOptInCommand; private handleMcpCommand; private handleLanguageCommand; }