/** * Copilot CLI process driver for AgentLink. * * Parallel to claude.ts but simpler: * - Each turn spawns a new `copilot --output-format json` process * - Prompt is written to stdin to avoid command-line length limits * - No persistent process, no control_request protocol * - JSONL stdout parsed and emitted as backend_event messages * - Session state stored at ~/.copilot/session-state// */ import { type ChildProcess } from 'child_process'; import type { SendFn } from './claude.js'; import type { SessionInfo } from './history.js'; import { type HistoryMessage } from './history-message-transform.js'; import { copilotCapabilities } from './backends/types.js'; export interface CopilotConversationState { conversationId: string; child: ChildProcess | null; abortController: AbortController | null; copilotSessionId: string | null; lastCopilotSessionId: string | null; workDir: string; turnActive: boolean; providerId: string; model: string | null; contextTier: CopilotContextTier | null; reasoningEffort: CopilotReasoningEffort | null; turnId: string | null; stateVersion: number; heartbeatTimer: ReturnType | null; /** True once we've sent session_started for sidebar refresh */ sessionNotified: boolean; } export type CopilotContextTier = 'default' | 'long_context'; export type CopilotReasoningEffort = 'none' | 'low' | 'medium' | 'high' | 'xhigh' | 'max'; export interface CopilotRunOptions { model?: string; context?: string; effort?: string; } interface NormalizedCopilotRunOptions { model?: string; context?: CopilotContextTier; effort?: CopilotReasoningEffort; } interface CopilotChatFile { name: string; mimeType: string; data: string; } export declare function addCopilotSendFn(fn: SendFn): () => void; export declare function getCopilotConversation(conversationId: string): CopilotConversationState | undefined; export declare function getCopilotConversations(): Map; /** * Rebind a running copilot conversation to a new conversationId. * Used when web client refreshes and generates a new UUID for the same session. * Returns true if a running conversation was found and rebound. */ export declare function rebindCopilotConversation(copilotSessionId: string, newConvId: string): boolean; export declare function createCopilotPlaceholder(conversationId: string, opts?: { providerId?: string; }): void; export declare function restartCopilotConversation(conversationId: string, opts?: { providerId?: string; model?: string; }): { wasTurnActive: boolean; copilotSessionId: string | null; }; export declare function setModel(conversationId: string | undefined, model: string): void; export interface CopilotChatOptions { resumeSessionId?: string; providerId?: string; copilotOptions?: CopilotRunOptions; } export declare function normalizeCopilotRunOptions(input?: CopilotRunOptions): { options: NormalizedCopilotRunOptions; error?: string; }; export declare function handleCopilotChat(conversationId: string, text: string, workDir: string, options?: CopilotChatOptions, files?: CopilotChatFile[]): void; export declare function cancelCopilotExecution(conversationId: string): void; export declare function cleanupAllCopilotConversations(): void; interface CopilotSessionPage { sessions: SessionInfo[]; hasMore: boolean; nextCursor?: string; } interface CopilotGlobalSessionInfo { sessionId: string; projectPath: string; projectFolder: string; stableIdentity?: string; title: string; firstPrompt: string; lastModified: number; } interface CopilotGlobalSessionPage { sessions: CopilotGlobalSessionInfo[]; hasMore: boolean; nextCursor?: string; indexState: 'ready'; } export declare function listCopilotSessions(workDir: string): SessionInfo[]; export declare function listCopilotSessionsPage(workDir: string, options?: { limit?: number; cursor?: string; }): CopilotSessionPage; export declare function readCopilotSessionMessages(_workDir: string, sessionId: string): HistoryMessage[]; export declare function getCopilotSessionWorkDir(sessionId: string): string | undefined; export declare function listAllCopilotSessions(limit?: number): Array<{ sessionId: string; projectPath: string; projectFolder: string; title: string; firstPrompt: string; lastModified: number; }>; export declare function listAllCopilotSessionsPage(options?: { limit?: number; cursor?: string; }): CopilotGlobalSessionPage; export declare function renameCopilotSession(_workDir: string, sessionId: string, newTitle: string): boolean; export declare function moveCopilotSession(_fromWorkDir: string, toWorkDir: string, sessionId: string): boolean; export declare function deleteCopilotSession(_workDir: string, sessionId: string): boolean; export { copilotCapabilities };