/** * Codex CLI process driver for AgentLink. * * MVP integration: * - Each turn spawns `codex exec --json` (or `codex exec resume --json`) * - Prompt is written to stdin to avoid command-line length limits * - Codex thread_id is used as the AgentLink session id * - JSONL stdout is translated into backend_event messages * - Session history is read from ~/.codex/sessions/YYYY/MM/DD/*.jsonl */ import { type ChildProcess } from 'child_process'; import type { SendFn } from './claude.js'; import type { GlobalSessionInfo, SessionInfo } from './history.js'; import { type HistoryMessage } from './history-message-transform.js'; import { codexCapabilities } from './backends/types.js'; export interface CodexConversationState { conversationId: string; child: ChildProcess | null; abortController: AbortController | null; codexSessionId: string | null; lastCodexSessionId: string | null; workDir: string; turnActive: boolean; providerId: string; model: string | null; turnId: string | null; stateVersion: number; heartbeatTimer: ReturnType | null; sessionNotified: boolean; startedToolIds: Set; } export interface CodexRunOptions { model?: string; } interface CodexChatFile { name: string; mimeType: string; data: string; } interface CodexSessionPage { sessions: SessionInfo[]; hasMore: boolean; nextCursor?: string; } interface CodexGlobalSessionPage { sessions: GlobalSessionInfo[]; hasMore: boolean; nextCursor?: string; indexState: 'ready'; } export declare function addCodexSendFn(fn: SendFn): () => void; export declare function _resetResolvedCodexPathForTests(): void; export declare function getCodexConversation(conversationId: string): CodexConversationState | undefined; export declare function getCodexConversations(): Map; export declare function rebindCodexConversation(codexSessionId: string, newConvId: string): boolean; export declare function createCodexPlaceholder(conversationId: string, opts?: { providerId?: string; }): void; export declare function restartCodexConversation(conversationId: string, opts?: { providerId?: string; model?: string; }): { wasTurnActive: boolean; codexSessionId: string | null; }; export interface CodexChatOptions { resumeSessionId?: string; providerId?: string; codexOptions?: CodexRunOptions; } export declare function handleCodexChat(conversationId: string, text: string, workDir: string, options?: CodexChatOptions, files?: CodexChatFile[]): void; export declare function cancelCodexExecution(conversationId: string): void; export declare function cleanupAllCodexConversations(): void; export declare function evictByCodexSessionId(codexSessionId: string): boolean; export declare function listCodexSessions(workDir: string): SessionInfo[]; export declare function listCodexSessionsPage(workDir: string, options?: { limit?: number; cursor?: string; }): CodexSessionPage; export declare function listAllCodexSessions(limit?: number): GlobalSessionInfo[]; export declare function listAllCodexSessionsPage(options?: { limit?: number; cursor?: string; }): CodexGlobalSessionPage; export declare function readCodexSessionMessages(_workDir: string, sessionId: string): HistoryMessage[]; export declare function renameCodexSession(_workDir: string, sessionId: string, newTitle: string): boolean; export declare function moveCodexSession(_fromWorkDir: string, toWorkDir: string, sessionId: string): boolean; export declare function deleteCodexSession(_workDir: string, sessionId: string): boolean; export { codexCapabilities };