MCPcopy
hub / github.com/slopus/happy / runCodex

Function runCodex

packages/happy-cli/src/codex/runCodex.ts:80–1057  ·  view source on GitHub ↗
(opts: {
    credentials: Credentials;
    startedBy?: 'daemon' | 'terminal';
    noSandbox?: boolean;
    resumeThreadId?: string;
    permissionMode?: PermissionMode;
})

Source from the content-addressed store, hash-verified

78 * Main entry point for the codex command with ink UI
79 */
80export async function runCodex(opts: {
81 credentials: Credentials;
82 startedBy?: 'daemon' | 'terminal';
83 noSandbox?: boolean;
84 resumeThreadId?: string;
85 permissionMode?: PermissionMode;
86}): Promise<void> {
87 // Early check: ensure Codex CLI is installed before proceeding
88 try {
89 execSync('codex --version', { encoding: 'utf8', stdio: 'pipe', windowsHide: true });
90 } catch {
91 console.error('\n\x1b[1m\x1b[33mCodex CLI is not installed\x1b[0m\n');
92 console.error('Please install Codex CLI using one of these methods:\n');
93 console.error('\x1b[1mOption 1 - npm (recommended):\x1b[0m');
94 console.error(' \x1b[36mnpm install -g @openai/codex\x1b[0m\n');
95 console.error('\x1b[1mOption 2 - Homebrew (macOS):\x1b[0m');
96 console.error(' \x1b[36mbrew install --cask codex\x1b[0m\n');
97 console.error('Alternatively, use Claude Code:');
98 console.error(' \x1b[36mhappy claude\x1b[0m\n');
99 process.exit(1);
100 }
101
102 type EnhancedMode = CodexEnhancedMode;
103
104 //
105 // Define session
106 //
107
108 const sessionTag = randomUUID();
109
110 // Set backend for offline warnings (before any API calls)
111 connectionState.setBackend('Codex');
112
113 const api = await ApiClient.create(opts.credentials);
114
115 // Log startup options
116 logger.debug(`[codex] Starting with options: startedBy=${opts.startedBy || 'terminal'}`);
117
118 //
119 // Machine
120 //
121
122 const settings = await readSettings();
123 let machineId = settings?.machineId;
124 const sandboxConfig = opts.noSandbox ? undefined : settings?.sandboxConfig;
125 if (!machineId) {
126 console.error(`[START] No machine ID found in settings, which is unexpected since authAndSetupMachineIfNeeded should have created it. Please report this issue on https://github.com/slopus/happy-cli/issues`);
127 process.exit(1);
128 }
129 logger.debug(`Using machineId: ${machineId}`);
130 await api.getOrCreateMachine({
131 machineId,
132 metadata: initialMachineMetadata
133 });
134
135 //
136 // Create session
137 //

Callers 1

handleCodexCommandFunction · 0.90

Calls 15

resetMethod · 0.95
addMessageMethod · 0.95
processDiffMethod · 0.95
sizeMethod · 0.95
clearMethod · 0.95
readSettingsFunction · 0.90
createSessionMetadataFunction · 0.90
decodeBase64Function · 0.90
setupOfflineReconnectionFunction · 0.90

Tested by

no test coverage detected