/** * Shared types for the @agenticmail/codex package. * * Kept in one file so install/uninstall/status/dispatcher can import a single * source of truth without circular deps. */ /** An AgenticMail account as returned by `GET /api/agenticmail/accounts`. */ interface AgenticMailAccount { id: string; name: string; email: string; apiKey: string; role?: string; metadata?: Record; /** Per-agent wake preference. When false, the dispatcher * drops wakes where this agent was on Cc/Bcc but not To, * regardless of the sender's wake list. Defaults to true. */ wakeOnCc?: boolean; /** Soft-stop flag. When true, the dispatcher refuses to wake * this agent for any reason. Mail still lands in the mailbox * so the thread's audit trail is preserved. Toggle via the * stop_agent / resume_agent MCP tools or the * POST /accounts/:id/stop / POST /accounts/:id/resume API. */ stopped?: boolean; } /** Resolved configuration for everything the package does. */ interface CodexIntegrationConfig { /** AgenticMail master API URL. */ apiUrl: string; /** AgenticMail master key (mk_…). */ masterKey: string; /** Codex's home dir (CODEX_HOME env or ~/.codex). */ codexHome: string; /** Path to ~/.codex/config.toml — MCP servers, feature flags. */ codexConfigPath: string; /** Path to ~/.codex/hooks.json — lifecycle hooks (separate file from config.toml). */ codexHooksPath: string; /** Directory where per-agent Codex agent .toml files live (~/.codex/agents). */ agentsDir: string; /** Key under [mcp_servers.*] in config.toml. */ mcpServerName: string; /** Name of the dedicated AgenticMail account that represents this Codex install. */ bridgeAgentName: string; /** Prefix for generated agent names — produces e.g. `agenticmail-vesper`. */ subagentPrefix: string; /** * Command used to invoke the AgenticMail MCP server. * Defaults to `npx -y @agenticmail/mcp` for portability. */ mcpCommand: string; mcpArgs: string[]; } /** Snapshot of the installation state — used by `status`. */ interface InstallStatus { state: 'installed' | 'not_installed' | 'partial'; /** Whether the MCP server block is present in ~/.codex/config.toml. */ mcpInstalled: boolean; /** Whether the multi_agent_v2 feature flag is enabled (so `spawn_agent` is available). */ multiAgentEnabled: boolean; /** Bridge agent (Codex's identity inside AgenticMail) exists. */ bridgeAgentExists: boolean; /** Codex agent .toml files currently present, keyed by AgenticMail agent name. */ subagents: string[]; /** Path to Codex config.toml (so the user knows what we touched). */ codexConfigPath: string; /** Path to Codex hooks.json. */ codexHooksPath: string; /** Directory used for agent .toml files. */ agentsDir: string; /** Free-form notes for the user (e.g. "API unreachable"). */ notes: string[]; /** Dispatcher PM2 status (null when PM2 isn't installed or entry absent). */ dispatcher: { running: boolean; pid?: number; restartCount?: number; uptimeMs?: number; } | null; } /** Result returned by `install`. */ interface InstallResult { /** AgenticMail agents that were turned into Codex subagents. */ registeredAgents: AgenticMailAccount[]; /** Where the MCP server block was written. */ codexConfigPath: string; /** Where the hook entries were written. */ codexHooksPath: string; /** Where the agent .toml files were written. */ agentsDir: string; /** The bridge agent (Codex's identity inside AgenticMail). */ bridgeAgent: AgenticMailAccount; /** True if the install changed any files (false on no-op re-runs). */ changed: boolean; /** Dispatcher daemon launch status (best-effort; reason populated on failure). */ dispatcher?: { started: boolean; reason?: string; }; } /** Result returned by `uninstall`. */ interface UninstallResult { /** Whether anything was actually removed. */ changed: boolean; /** Removed agent .toml files. */ removedSubagents: string[]; /** Whether the MCP server block was removed from config.toml. */ mcpBlockRemoved: boolean; /** Whether the hooks block was removed from hooks.json. */ hooksRemoved: boolean; /** Whether the bridge agent was deleted (only if `--purge-bridge` was set). */ bridgeAgentDeleted: boolean; /** Whether the dispatcher PM2 entry was stopped. */ dispatcherStopped: boolean; } /** * Resolves a fully-populated CodexIntegrationConfig from defaults + overrides * + the on-disk AgenticMail config (~/.agenticmail/config.json). * * Reading the master key from disk lives here (not in install.ts) so tests * can supply config inline without touching the filesystem. * * # Codex vs Claude Code paths * * Claude Code keeps its global config at `~/.claude.json` (one JSON file) * and its hooks + settings at `~/.claude/settings.json`. Codex CLI is * structured differently: * * ~/.codex/config.toml — global config, including `[mcp_servers.*]` * and `features.multi_agent_v2.enabled` * ~/.codex/hooks.json — lifecycle hooks (separate file, not nested) * ~/.codex/agents/.toml — one TOML file per custom subagent * ~/.codex/sessions/ — Codex's own thread rollouts (resumeThread) * * `CODEX_HOME` env var overrides `~/.codex`. We honour it the same way the * Codex CLI itself does in `codex-rs/core/src/config/mod.rs::resolve_codex_home`. */ /** Public options for resolveConfig — everything is optional and overrides defaults. */ interface ResolveConfigOptions { apiUrl?: string; masterKey?: string; /** Override CODEX_HOME (defaults to env var or ~/.codex). */ codexHome?: string; /** Override the agents directory inside CODEX_HOME (defaults to `/agents`). */ agentsDir?: string; /** MCP server entry name in [mcp_servers.*]. Default: 'agenticmail'. */ mcpServerName?: string; /** Name of the dedicated AgenticMail account that represents this Codex install. */ bridgeAgentName?: string; /** Prefix for generated Codex subagent names. */ subagentPrefix?: string; /** MCP server command + args (defaults to npx-fallback). */ mcpCommand?: string; mcpArgs?: string[]; /** Override path to AgenticMail's config.json (defaults to ~/.agenticmail/config.json). Tests use this. */ agenticmailConfigPath?: string; } /** * Resolve the Codex home directory the same way the CLI does: * 1. Explicit override. * 2. $CODEX_HOME env var. * 3. ~/.codex. */ declare function resolveCodexHome(override?: string): string; declare function resolveConfig(opts?: ResolveConfigOptions): CodexIntegrationConfig; export { type AgenticMailAccount as A, type CodexIntegrationConfig as C, type InstallResult as I, type ResolveConfigOptions as R, type UninstallResult as U, type InstallStatus as a, resolveConfig as b, resolveCodexHome as r };