import { type CodexAppProcessError } from "./codex-client.js"; import type { AgentAttachment, AgentEmit, AgentPermissionMode } from "./types.js"; type CodexRunOptions = { threadId?: string; cwd?: string; permissionMode?: AgentPermissionMode; appEmit?: AgentEmit; outputSchema?: Record; onStart?: () => void; onThread?: (threadId: string) => void; onTurn?: (turnId: string) => void; onFinish?: () => void; }; export type CodexRunResult = { ok: true; text: string; } | { ok: false; error: string; }; export type CodexWorkflowRunResult = { ok: true; text: string; timings: { queueWaitMs: number; threadStartMs: number; modelMs: number; }; } | { ok: false; error: string; retryable: boolean; failureKind: "contract" | "transport" | "timeout" | "turn"; timings: { queueWaitMs: number; threadStartMs: number; modelMs: number; }; }; type CodexWorkflowFailureKind = Extract["failureKind"]; export declare const FLOW_C_CODEX_MODEL = "gpt-6-astra"; export declare const FLOW_C_CODEX_REASONING_EFFORT = "low"; export declare const FLOW_C_CODEX_WORKER_CONCURRENCY: number; export declare const FLOW_C_CODEX_PROCESS_MAX_ATTEMPTS = 3; export declare function flowCCodexWorkerStatus(): { active: number; limit: number; }; export declare function boundedWorkflowProcessAttempts(value?: number): number; /** * 记录尚未确认 OS exit 的 worker 进程。worker 可以释放给队列,但在对应 * barrier 完成前只能等待/失败,绝不能启动替代 app-server。 */ export declare class WorkflowCodexLaneQuarantine { private barriers; quarantine(workerIndex: number, barrier: Promise): Promise; wait(workerIndex: number, timeoutMs: number): Promise; isQuarantined(workerIndex: number): boolean; } export { summarizeCodexThread } from "./codex-history.js"; /** 将 Codex turn 加入串行队列并等待执行完成。 */ export declare function runCodexTurn(prompt: string, emit: AgentEmit, attachments?: AgentAttachment[], options?: CodexRunOptions): Promise; /** 中断当前线程正在执行的 Codex turn。 */ export declare function interruptCodexTurn(threadId?: string): Promise; /** * Flow C 专用受控并行回合。每个 lane 独占一个 app-server,chunk 使用独立线程, * 从而不会被交互式 Codex 全局队列或另一个长脚本回合阻塞。 */ export declare function runCodexWorkflowTurn(prompt: string, emit: AgentEmit, options: CodexRunOptions & { timeoutMs: number; attachments?: AgentAttachment[]; maxProcessAttempts?: number; onWorkerStart?: () => void; onWorkerFinish?: () => void; }): Promise; /** A deadline exhausted after process recovery is terminal for this handoff wave. */ export declare function isWorkflowFailureRetryable(failureKind: CodexWorkflowFailureKind, cleanupConfirmed: boolean, processRecoveryObserved: boolean): boolean; type CodexProcessRetryOptions = { maxAttempts?: number; backoffMs?: number | ((failedAttempt: number) => number); onRetry?: (error: CodexAppProcessError, failedAttempt: number) => Promise | void; }; /** 只重试明确的 app-server 进程/stdio 故障;结构契约和普通模型失败均立即上抛。 */ export declare function runCodexProcessRetries(operation: (attempt: number) => Promise, options?: CodexProcessRetryOptions): Promise; /** * 给 Flow C 的完整 app-server 链路设置硬截止时间。超时后不再等待原 Promise * 自行结束;否则初始化或 thread/start 永不返回时会永久占住 worker lane。 */ export declare function runBoundedWorkflowOperation(operation: Promise, timeoutMs: number, onTimeout: () => Promise | void): Promise<{ timedOut: false; value: T; } | { timedOut: true; }>; /** Contract/preflight 4xx errors are deterministic and must never burn every fallback chunk size. */ export declare function isDeterministicWorkflowContractError(error: unknown): boolean; /** 强制回收失去响应的 app-server;只用于有界超时恢复。 */ export declare function restartCodexApp(message?: string): Promise; /** 回复当前 app-server 的待处理权限请求。 */ export declare function resolveCodexApproval(requestId: string, decision: string): Promise; /** 创建新的 Codex 线程并记录当前线程 ID。 */ export declare function startCodexThread(emit: AgentEmit, cwd?: string, permissionMode?: AgentPermissionMode): Promise; /** 恢复指定 Codex 线程并返回聊天历史。 */ export declare function resumeCodexThread(emit: AgentEmit, threadId: string, cwd?: string, permissionMode?: AgentPermissionMode): Promise<{ thread: import("./codex-protocol.js").CodexThread; messages: { id: string; role: "user" | "assistant" | "tool" | "error"; title?: string; text: string; detail?: unknown; streamId?: string; }[]; }>; /** 查询当前工作空间中的 Codex 线程。 */ export declare function listCodexThreads(emit: AgentEmit, options: { cwd: string; searchTerm?: string; limit?: number; }): Promise<{ data: { id: string; sessionId: string; preview: string; name: string | null; cwd: string; status: string; source: unknown; threadSource: unknown; createdAt: number; updatedAt: number; }[]; nextCursor: {} | null; backwardsCursor: {} | null; }>; /** 读取指定 Codex 线程及其聊天历史。 */ export declare function readCodexThread(emit: AgentEmit, threadId: string, cwd?: string): Promise<{ thread: { id: string; sessionId: string; preview: string; name: string | null; cwd: string; status: string; source: unknown; threadSource: unknown; createdAt: number; updatedAt: number; }; messages: { id: string; role: "user" | "assistant" | "tool" | "error"; title?: string; text: string; detail?: unknown; streamId?: string; }[]; }>; /** 确认指定 Codex 线程属于当前工作空间。 */ export declare function verifyCodexThreadWorkspace(emit: AgentEmit, threadId: string, cwd: string): Promise; /** 归档指定 Codex 线程。 */ export declare function archiveCodexThread(emit: AgentEmit, threadId: string, cwd?: string): Promise; /** 判断线程异常是否允许自动新建线程后重试。 */ export declare function isRecoverableThreadError(error: unknown): boolean;