/** * Main entry point for the coding agent CLI. * * This file handles CLI argument parsing and translates them into * createAgentSession() options. The SDK does the heavy lifting. */ import type { ImageContent } from "@gajae-code/ai/core"; import type { Args } from "./cli/args"; import { ModelRegistry } from "./config/model-registry"; import { Settings } from "./config/settings"; import type { ExtensionUIContext } from "./extensibility/extensions/types"; import type { AcpStartupOptions } from "./modes/acp/startup-options"; import type { SessionSelectionResult } from "./modes/components/session-selector"; import type { InteractiveMode } from "./modes/interactive-mode"; import type { PrintModeOptions } from "./modes/print-mode"; import { initTheme } from "./modes/theme/theme"; import type { SubmittedUserInput } from "./modes/types"; import type { MCPManager } from "./runtime-mcp"; import { type CreateAgentSessionOptions, type CreateAgentSessionResult, createAgentSession, discoverAuthStorage } from "./sdk"; import type { AgentSession } from "./session/agent-session"; import { type ResumeSessionIdentity, type SessionDestination, type SessionDirectoryMigrationPolicy, type SessionInfo, SessionManager, type StrictSessionOpenResult } from "./session/session-manager"; import { runStartupCredentialAutoImportIfNeeded } from "./setup/credential-auto-import"; import type { LspStartupServerInfo } from "./tools"; import type { EventBus } from "./utils/event-bus"; export type StartupUpdateRoute = "interactive" | "print" | "text" | "json" | "acp"; export declare function classifyStartupUpdateRoute(parsed: Pick, autoPrint: boolean): StartupUpdateRoute; /** Coordinates the non-blocking update check around the interactive UI lifecycle. */ export declare class StartupUpdateOrchestrator { #private; constructor(route: StartupUpdateRoute, enabled: () => boolean, check: () => Promise); startBeforeInteractiveInitialization(): void; attachAfterInteractiveInitialization(notify: (version: string) => void): void; } export interface StartupUpdateInteractiveMode { init: () => Promise; showNewVersionNotification: (version: string) => void; } export declare function initializeInteractiveModeWithStartupUpdate(mode: StartupUpdateInteractiveMode, startupUpdate: StartupUpdateOrchestrator): Promise; /** * Translate only ACP startup settings with a canonical SDK control carrier. * Every other local-session flag is rejected so the broker-backed ACP host * never appears to accept options it cannot apply to its remote session. */ export declare function resolveAcpStartupOptions(parsed: Pick, sessionOptions: Pick): AcpStartupOptions; declare function readPipedInput(): Promise; export interface InteractiveModeNotify { kind: "warn" | "error" | "info"; message: string; } export declare function submitInteractiveInput(mode: Pick, session: Pick, input: SubmittedUserInput): Promise; type StartupModelProfileArgs = { session: AgentSession; settings: Settings; modelRegistry: ModelRegistry; parsedArgs: Pick; startupModel?: CreateAgentSessionOptions["model"]; startupThinkingLevel?: CreateAgentSessionOptions["thinkingLevel"]; preferCachedModels?: boolean; }; export declare function applyStartupModelProfiles(args: StartupModelProfileArgs): Promise; export declare function applyStartupModelProfilesOrExit(args: StartupModelProfileArgs): Promise; export declare function isStartupModelProfileCredentialRecoveryEligible(options: { isInteractive: boolean; hasInteractiveTerminal: boolean; initialMessage: string | undefined; initialMessages: readonly string[]; resumeAction: "continue-tail" | "open-idle" | undefined; }): boolean; export declare function applyStartupModelProfilesForRoot(args: StartupModelProfileArgs & { isInteractive: boolean; hasInteractiveTerminal: boolean; initialMessage: string | undefined; initialMessages: readonly string[]; resumeAction: "continue-tail" | "open-idle" | undefined; }): Promise<{ recoverableErrors: string[]; }>; type DeferredModelProfileStartup = () => Promise<{ recoverableErrors: string[]; }>; interface InteractiveModeFactoryOptions { session: AgentSession; version: string; changelogMarkdown: string | undefined; setExtensionUIContext: (uiContext: ExtensionUIContext, hasUI: boolean) => void; lspServers: LspStartupServerInfo[] | undefined; mcpManager: MCPManager | undefined; eventBus?: EventBus; } type CreateInteractiveMode = (options: InteractiveModeFactoryOptions) => InteractiveMode; type ResumePickerTerminalCheck = () => boolean; type ListForResumePickerReadOnly = (cwd: string, sessionDir?: string, storage?: undefined) => Promise; type ListManagedForResumePickerReadOnly = (cwd: string, managedAgentDir?: string, storage?: undefined) => Promise; type ResolveManagedAgentDirForScope = (cwd: string) => string; type SelectResumeSession = (sessions: SessionInfo[]) => Promise; type OpenExistingSessionStrict = (identity: ResumeSessionIdentity, destination: SessionDestination, storage?: undefined, migrationPolicy?: SessionDirectoryMigrationPolicy) => Promise; export declare const BARE_RESUME_CONFLICT_ERROR = "--resume without a session cannot be combined with --continue, --fork, or --no-session."; export declare const BARE_RESUME_INTERACTIVE_ERROR = "--resume requires an interactive terminal; use --resume ."; /** Resolves only the managed agent root needed for pre-consent picker inventory. */ export declare function resolveManagedAgentDirForScope(_cwd: string): string; export declare const BARE_RESUME_OPEN_ERROR = "Could not open the selected session. Use --resume ."; export declare function runInteractiveMode(session: AgentSession, version: string, changelogMarkdown: string | undefined, notifs: (InteractiveModeNotify | null)[], startupUpdate: StartupUpdateOrchestrator, initialMessages: string[], setExtensionUIContext: (uiContext: ExtensionUIContext, hasUI: boolean) => void, lspServers: LspStartupServerInfo[] | undefined, mcpManager: MCPManager | undefined, eventBus?: EventBus, initialMessage?: string, initialImages?: ImageContent[], createInteractiveMode?: CreateInteractiveMode, resumeAction?: "continue-tail" | "open-idle", startDeferredMcpConfig?: CreateAgentSessionResult["startDeferredMcpConfig"], startDeferredModelProfiles?: DeferredModelProfileStartup): Promise; export declare function getChangelogForDisplay(parsed: Args): Promise; export declare function createSessionManager(parsed: Args, cwd: string, activeSettings?: Settings): Promise; type RunPrintMode = (session: AgentSession, options: PrintModeOptions) => Promise; export interface RunRootCommandDependencies { createAgentSession?: typeof createAgentSession; createSessionManager?: typeof createSessionManager; discoverAuthStorage?: typeof discoverAuthStorage; runAcpMode?: (options?: { agentDir?: string; }) => Promise; settings?: Settings; suppressProcessExit?: boolean; startupUpdate?: { check: () => Promise; }; initTheme?: typeof initTheme; readPipedInput?: typeof readPipedInput; stdinIsTTY?: boolean; runStartupCredentialAutoImportIfNeeded?: typeof runStartupCredentialAutoImportIfNeeded; getChangelogForDisplay?: typeof getChangelogForDisplay; createInteractiveMode?: CreateInteractiveMode; runPrintMode?: RunPrintMode; quit?: (code: number) => Promise; isResumePickerTerminal?: ResumePickerTerminalCheck; listForResumePickerReadOnly?: ListForResumePickerReadOnly; listManagedForResumePickerReadOnly?: ListManagedForResumePickerReadOnly; resolveManagedAgentDirForScope?: ResolveManagedAgentDirForScope; selectResumeSession?: SelectResumeSession; openExistingSessionStrict?: OpenExistingSessionStrict; initializeSettings?: typeof Settings.init; loadSettingsForScope?: typeof Settings.loadForScope; } export interface ModelRoleOverrides { smol?: string; slow?: string; plan?: string; } /** * Resolve the ephemeral `smol`/`slow`/`plan` model-role overrides. * * Precedence per role is CLI flag > documented `GJC_*_MODEL` > legacy * `PI_*_MODEL`, matching the repo-wide GJC-first/PI-fallback convention. * Resolution reads the process environment via `$pickenv`, which trims values * and treats empty/whitespace as unset; it is deliberately kept separate from * credential env resolution (`$credentialEnv`/`$pickCredentialEnv`). The * function is pure and stateless, so it reads fresh each call and a later * invocation never inherits an earlier one's values. */ export declare function resolveModelRoleOverrides(parsed: Pick): ModelRoleOverrides; /** * Apply the `--no-pty` / `--no-title` terminal-control flags to the environment. * * Sets the canonical `GJC_*` name (so an explicit flag wins over a user-set * `GJC_*` value under the GJC-first resolver — CLI authority) and the legacy * `PI_*` name for backward compatibility. `--acp` mode implies `--no-title`. */ export declare function applyTerminalControlFlagsToEnv(parsed: Pick, env?: NodeJS.ProcessEnv): void; export declare function runRootCommand(parsed: Args, rawArgs: string[], deps?: RunRootCommandDependencies): Promise; export declare function main(args: string[]): Promise; export {};