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
+5 -1
View File
@@ -142,6 +142,10 @@ export function collectToolIdsFromMessages(messages: NormalizedMessage[]): Set<s
return ids
}
export function isChangeTitleToolName(name: string): boolean {
return name === 'mcp__hapi__change_title' || name === 'hapi__change_title'
}
export function extractTitleFromChangeTitleInput(input: unknown): string | null {
if (!input || typeof input !== 'object') return null
const title = (input as { title?: unknown }).title
@@ -154,7 +158,7 @@ export function collectTitleChanges(messages: NormalizedMessage[]): Map<string,
if (msg.role !== 'agent') continue
for (const content of msg.content) {
if (content.type !== 'tool-call') continue
if (content.name !== 'mcp__hapi__change_title') continue
if (!isChangeTitleToolName(content.name)) continue
const title = extractTitleFromChangeTitleInput(content.input)
if (!title) continue
map.set(content.id, title)