feat: add MCP config and system prompt support for Codex local mode

Implements MCP server configuration and developer instructions support in
Codex local mode, bringing it to parity with remote mode.

Key additions:
- buildMcpServerConfigArgs() and buildDeveloperInstructionsArg() utilities
  to construct -c config arguments for passing MCP servers and instructions
  to the Codex CLI at runtime
- TITLE_INSTRUCTION for Codex to call hapi__change_title to update chat
  session titles dynamically
- Codex local mode now starts hapi MCP bridge server and passes both MCP
  configuration and developer instructions to Claude, enabling full feature
  parity with remote mode

Files changed:
- New: codexMcpConfig.ts (utilities), systemPrompt.ts (prompt definition),
  codexMcpConfig.test.ts (comprehensive tests)
- Updated: codexLocal.ts (accepts mcpServers, builds config args),
  codexLocalLauncher.ts (starts hapi server, passes config),
  codexStartConfig.ts (imports TITLE_INSTRUCTION)
This commit is contained in:
weishu
2026-01-05 18:38:58 +08:00
parent 45822afa49
commit c50621e85a
8 changed files with 214 additions and 7 deletions
+11
View File
@@ -1,6 +1,8 @@
import { logger } from '@/ui/logger';
import { restoreTerminalState } from '@/ui/terminalState';
import { spawnWithAbort } from '@/utils/spawnWithAbort';
import { buildMcpServerConfigArgs, buildDeveloperInstructionsArg } from './utils/codexMcpConfig';
import { codexSystemPrompt } from './utils/systemPrompt';
/**
* Filter out 'resume' subcommand which is managed internally by hapi.
@@ -29,6 +31,7 @@ export async function codexLocal(opts: {
sandbox?: 'read-only' | 'workspace-write' | 'danger-full-access';
onSessionFound: (id: string) => void;
codexArgs?: string[];
mcpServers?: Record<string, { command: string; args: string[] }>;
}): Promise<void> {
const args: string[] = [];
@@ -45,6 +48,14 @@ export async function codexLocal(opts: {
args.push('--sandbox', opts.sandbox);
}
// Add MCP server configuration
if (opts.mcpServers && Object.keys(opts.mcpServers).length > 0) {
args.push(...buildMcpServerConfigArgs(opts.mcpServers));
}
// Add developer instructions (system prompt)
args.push(...buildDeveloperInstructionsArg(codexSystemPrompt));
if (opts.codexArgs) {
const safeArgs = filterResumeSubcommand(opts.codexArgs);
args.push(...safeArgs);