/** * Interactive mode for the coding agent. * Handles TUI rendering and user interaction, delegating business logic to AgentSession. */ import type { SessionManager } from "@caupulican/pi-agent-core/node"; import type { AssistantMessage, ImageContent } from "@caupulican/pi-ai"; import { type LoaderIndicatorOptions } from "@caupulican/pi-tui"; import type { AgentSessionRuntime } from "../../core/agent-session-runtime.ts"; import { type LatestPiRelease } from "../../utils/version-check.ts"; import { type ActivityLaneKind } from "./components/activity-lane.ts"; import type { CountdownTimer } from "./components/countdown-timer.ts"; type UserInputSubmission = { text: string; images?: ImageContent[]; }; export declare function formatResumeCommand(sessionManager: SessionManager): string | undefined; /** * 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; /** Whether a human owns this terminal. False for unattended worker panes. */ hasHumanAudience?: boolean; } export declare class InteractiveMode { private runtimeHost; private ui; private chatContainer; private pendingMessagesContainer; private statusContainer; private defaultEditor; private editor; private autocompleteProvider; private autocompleteProviderWrappers; private fdPath; private editorContainer; private overlayHost; private footer; private footerDataProvider; private autoLearnController; private profileMenu; private authDialogs; private extensionUiHost; private keybindings; private version; private isInitialized; private readonly runtimeStatus; private onInputCallback?; private pendingUserInputs; private readonly clipboardQueue; private clipboardImageStore; private lastSigintTime; private lastEscapeTime; private changelogMarkdown; private startupNoticesShown; private anthropicSubscriptionWarningShown; private lastStatusSpacer; private lastStatusText; private liveHistoryHiddenNotice; private liveHistoryHiddenComponents; private tuiHistoryLoaded; private tuiHistoryLoadInProgress; private streamingComponent; private streamingMessage; private streamingUiUpdateTimer; private lastStreamingUiUpdateAt; private activeToolCalls; private toolOutputExpanded; private transcriptActionsExpanded; private hideThinkingBlock; private skillCommands; private unsubscribe?; private unsubscribeExtensionsChanged?; private signalCleanupHandlers; private isBashMode; private bashComponent; private pendingBashComponents; autoCompactionEscapeHandler?: () => void; retryCountdown: CountdownTimer | undefined; retryEscapeHandler?: () => void; private compactionQueuedMessages; private shutdownRequested; private widgetContainerAbove; private widgetContainerBelow; private activityLane; private readonly hasHumanAudience; private headerContainer; private builtInHeader; private options; private get session(); private get agent(); private get sessionManager(); private get settingsManager(); private get loadingAnimation(); private set loadingAnimation(value); get workingVisible(): boolean; set workingVisible(value: boolean); get workingIndicatorOptions(): LoaderIndicatorOptions | undefined; set workingIndicatorOptions(value: LoaderIndicatorOptions | undefined); constructor(runtimeHost: AgentSessionRuntime, options?: InteractiveModeOptions); private createBaseAutocompleteProvider; private setupAutocompleteProvider; private startupChecksHost; private showStartupNoticesIfNeeded; init(): Promise; private renderProjectTrustWarningIfNeeded; /** * 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; private refreshAutonomyFooterStatus; private activityLaneSnapshot; private refreshActivityLane; toolActivityKind(toolName: string): ActivityLaneKind; toolActivityLabel(toolName: string): string; toolActivityTerminalStatus(isError: boolean, details: unknown): "success" | "failure" | "neutral"; private checkForPackageUpdates; private checkTmuxKeyboardSetup; /** * Get changelog entries to display on startup. * Only shows new entries since last seen version, skips for resumed sessions. */ private getChangelogForDisplay; private getMarkdownThemeWithSettings; private getStartupExpansionState; private showLoadedResources; /** * Initialize the extension system with TUI-based UI context. */ private bindCurrentSessionExtensions; private applyRuntimeSettings; private applyEditorPresentationSettings; private refreshExtensionPresentation; private rebindCurrentSession; private subscribeToExtensionsChanged; private handleFatalRuntimeError; private handleNonFatalSessionReplacementError; private renderCurrentSessionState; /** * Get a registered tool definition by name (for custom rendering). */ private getRegisteredToolDefinition; private appendTranscriptAction; private attachToolExecutionComponent; clearActiveToolCalls(): void; private clearActiveToolCallState; private getWorkingLoaderMessage; private createWorkingLoader; private stopWorkingLoader; private setWorkingVisible; private setWorkingIndicator; private setHiddenThinkingLabel; updateRuntimeStatus(message?: AssistantMessage): void; /** * Set the extension-provided working-loader message (undefined restores the default). */ private setWorkingMessage; /** * Reset the working indicator and hidden-thinking label to their built-in defaults. */ private resetWorkingIndicators; private promptForMissingSessionCwd; private setupKeyHandlers; private keyHandlersHost; private handleClipboardImagePaste; private takeClipboardImagesForText; private buildUserInputSubmission; private setupEditorSubmitHandler; private subscribeToAgent; private handleEvent; /** Extract text content from a user message */ private getUserMessageText; private setEditorInputHistory; private populateEditorInputHistoryFromMessages; private populateEditorInputHistoryFromSession; private resetLiveTuiHistoryTrim; private clearPendingStreamingUiUpdate; private getSessionEntryCount; private showDeferredHistoryPlaceholder; private loadTuiHistoryOnDemand; private agentsOverlay; private agentsOverlayHandle; private handleAgentsOverlayRemoved; private closeAgentsOverlay; private toggleAgentsOverlay; private showTranscriptPager; private attachStreamingToolActions; applyStreamingMessageUpdate(message: AssistantMessage, options?: { force?: boolean; }): void; private trimLiveTuiHistory; private appendStatusToChat; /** * 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. */ private showStatus; private addMessageToChat; private messagesForTuiHistoryReload; /** * 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 renderGeneration; private renderQueue?; private renderSessionContext; renderInitialMessages(options?: { forceHistoryLoad?: boolean; }): Promise; getUserInput(): Promise; private rebuildChatFromMessages; private handleCtrlC; private handleCtrlD; /** * Gracefully shutdown the agent. * Stops the TUI before emitting shutdown events so extension UI cleanup cannot * repaint the final frame while the process is exiting. */ private isShuttingDown; private shutdown; private emergencyTerminalExit; private uncaughtCrash; private checkShutdownRequested; private registerSignalHandlers; private unregisterSignalHandlers; private handleCtrlZ; private handleFollowUp; private handleDequeue; private updateEditorBorderColor; private cycleThinkingLevel; private cycleModel; private toggleToolOutputExpansion; private setToolsExpanded; private setTranscriptActionsExpanded; private toggleThinkingBlockVisibility; private openExternalEditor; private openEditorForPath; clearEditor(): void; showError(errorMessage: string): void; showWarning(warningMessage: string): void; showNewVersionNotification(release: LatestPiRelease): void; showPackageUpdateNotification(packages: string[]): 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; /** Narrow seam shared by the session-picker/tree/fork and model-selector flows. */ private sessionFlowHost; private getAutoLearnModelOptions; private getAutoLearnDataDir; private getPrunedAutoLearnState; private getAutoLearnPresetForAutonomyMode; private getEffectiveAutoLearnSettings; private getCurrentAutoLearnSettings; private getAutoLearnTenantKey; private getAutoLearnTenantDataDir; private validateAutoLearnModelValue; private getCurrentCwdForSettings; private resolveSelfModificationSource; private validateSelfModificationSource; private launchAutoLearn; private isNativeReflectionEnabled; private maybeRunNativeReflection; private maybeStartAutoLearn; private maybeStartAutonomyReview; private updateAutoLearnFooter; private formatAutoLearnStatus; private applyAutonomyMode; /** * Delegates to the session rather than keeping its own instance (#27): the model router boots a * local server through AgentSession.getLocalRuntime() before a routed turn, and `/models` * commands need to see and be able to stop that SAME pi-managed process, not an unrelated one * tracked separately here. */ private get localRuntime(); private getTransformersRuntime; private getPrismLlamaCppRuntime; /** Narrow seam shared by the /models and /fitness flows. */ private localModelHost; private handleModelsCommand; private showFitnessModelSelector; private runFitnessAndAssign; private assignFitnessRole; /** Narrow seam for the /autonomy and /auto-learn command bodies. */ private autonomyHost; private handleAutonomyCommand; private handleAutoLearnCommand; /** Wide seam for the /settings selector; the hideThinkingBlock field is read+written here. */ private settingsSelectorHost; private showSettingsSelector; private handleSecretsCommand; private handleResourcesHubAction; private handleProfilesCommand; private refreshAfterProfileMutation; private handleModelCommand; private getModelCandidates; /** Update the footer's available provider count from current model candidates */ private updateAvailableProviderCount; private maybeWarnAboutAnthropicSubscriptionAuth; private showModelSelector; private showModelsSelector; private showUserMessageSelector; private handleCloneCommand; private showTreeSelector; private showTrustSelector; private showSessionSelector; private handleResumeSession; private handleReloadCommand; /** Reload and report whether the previous runtime was replaced successfully. */ private handleReloadCommandWithResult; /** * Refresh UI after extensions are loaded/unloaded live. * Performs the same refresh calls as handleReloadCommand but without the full reload. */ private refreshUIAfterExtensionsChanged; private handleExportCommand; private getPathCommandArgument; private handleImportCommand; private handleShareCommand; private handleCopyCommand; private handleNameCommand; private parseGoalContinueCommand; private handleGoalCommand; private handleTaskCommand; private handleGoalContinueCommand; private handleSessionCommand; private handleUsageCommand; private handleUsageMenuCommand; private handleChangelogCommand; /** * 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 copyResourcesRecursively; private handleInstallResourcesCommand; /** * `/curate` — skill curator (#32). With no args, lists reflection-promoted skills proposed for * archival (stale/unused) and pairs proposed for consolidation (overlapping). PROPOSE-ONLY: the user * applies actions explicitly via `/curate archive ` / `/curate restore `. Never touches * hand-authored skills; archival is restorable. */ private handleCurateCommand; private handleConfigBackupCommand; private handleConfigRestoreCommand; private handleDebugCommand; private handleArminSaysHi; private handleDementedDelves; private checkDaxnutsEasterEgg; private handleBashCommand; private handleCompactCommand; stop(): void; } export {}; //# sourceMappingURL=interactive-mode.d.ts.map