baa-conductor


baa-conductor / packages / codex-exec / src
im_wower  ·  2026-03-22

contracts.ts

  1export const CODEX_EXEC_PURPOSES = ["smoke", "simple-worker", "fallback-worker"] as const;
  2export const CODEX_EXEC_SANDBOX_MODES = [
  3  "read-only",
  4  "workspace-write",
  5  "danger-full-access"
  6] as const;
  7export const CODEX_EXEC_COLOR_MODES = ["always", "never", "auto"] as const;
  8export const CODEX_EXEC_ERROR_CODES = [
  9  "CODEX_EXEC_INVALID_INPUT",
 10  "CODEX_EXEC_SPAWN_FAILED",
 11  "CODEX_EXEC_TIMEOUT",
 12  "CODEX_EXEC_EXIT_NON_ZERO"
 13] as const;
 14export const DEFAULT_CODEX_EXEC_CLI_PATH = "codex";
 15export const DEFAULT_CODEX_EXEC_COLOR_MODE = "never" as const;
 16export const DEFAULT_CODEX_EXEC_TIMEOUT_MS = 5 * 60_000;
 17
 18export type CodexExecPurpose = (typeof CODEX_EXEC_PURPOSES)[number];
 19export type CodexExecSandboxMode = (typeof CODEX_EXEC_SANDBOX_MODES)[number];
 20export type CodexExecColorMode = (typeof CODEX_EXEC_COLOR_MODES)[number];
 21export type CodexExecErrorCode = (typeof CODEX_EXEC_ERROR_CODES)[number];
 22export type CodexExecErrorDetailValue = boolean | number | null | string;
 23export type JsonPrimitive = boolean | number | null | string;
 24export type JsonValue = JsonPrimitive | JsonValue[] | { [key: string]: JsonValue };
 25
 26export interface CodexExecError {
 27  code: CodexExecErrorCode;
 28  message: string;
 29  retryable: boolean;
 30  details?: Record<string, CodexExecErrorDetailValue>;
 31}
 32
 33export interface CodexExecRunRequest {
 34  prompt: string;
 35  purpose?: CodexExecPurpose;
 36  cwd?: string;
 37  cliPath?: string;
 38  timeoutMs?: number;
 39  model?: string;
 40  profile?: string;
 41  sandbox?: CodexExecSandboxMode;
 42  skipGitRepoCheck?: boolean;
 43  json?: boolean;
 44  ephemeral?: boolean;
 45  color?: CodexExecColorMode;
 46  config?: string[];
 47  additionalWritableDirectories?: string[];
 48  images?: string[];
 49  env?: Record<string, string | undefined>;
 50}
 51
 52export interface CodexExecInvocation {
 53  command: string;
 54  args: string[];
 55  cwd: string;
 56  prompt: string;
 57  purpose: CodexExecPurpose;
 58  timeoutMs: number;
 59  color: CodexExecColorMode;
 60  json: boolean;
 61  ephemeral: boolean;
 62  skipGitRepoCheck: boolean;
 63  model?: string;
 64  profile?: string;
 65  sandbox?: CodexExecSandboxMode;
 66  config: string[];
 67  additionalWritableDirectories: string[];
 68  images: string[];
 69}
 70
 71export interface CodexExecJsonParseError {
 72  line: number;
 73  message: string;
 74}
 75
 76export interface CodexExecRunResult {
 77  durationMs: number;
 78  exitCode: number | null;
 79  finishedAt: string;
 80  jsonEvents: JsonValue[] | null;
 81  jsonParseErrors: CodexExecJsonParseError[];
 82  lastMessage: string | null;
 83  signal: string | null;
 84  startedAt: string;
 85  stderr: string;
 86  stdout: string;
 87  timedOut: boolean;
 88}
 89
 90export interface CodexExecRunSuccess {
 91  ok: true;
 92  invocation: CodexExecInvocation;
 93  result: CodexExecRunResult;
 94}
 95
 96export interface CodexExecRunFailure {
 97  ok: false;
 98  error: CodexExecError;
 99  invocation?: CodexExecInvocation;
100  result?: CodexExecRunResult;
101}
102
103export type CodexExecRunResponse = CodexExecRunSuccess | CodexExecRunFailure;