refactor: unify MCP bridge setup and system prompt delivery

Extract duplicate MCP bridge initialization code from codexLocalLauncher and
codexRemoteLauncher into a new buildHapiMcpBridge utility. This ensures both
modes use identical server setup logic and provides a single source of truth
for MCP configuration.

Update codexStartConfig to deliver system prompt via developer_instructions
instead of appending to the user message. This ensures consistent behavior
between local and remote modes and properly separates system guidance from
user intent.
This commit is contained in:
weishu
2026-01-05 18:38:58 +08:00
parent c50621e85a
commit 9a28e6e0a1
5 changed files with 80 additions and 28 deletions
+3 -11
View File
@@ -11,8 +11,7 @@ import { DiffProcessor } from './utils/diffProcessor';
import { logger } from '@/ui/logger';
import { CodexDisplay } from '@/ui/ink/CodexDisplay';
import type { CodexSessionConfig } from './types';
import { getHappyCliCommand } from '@/utils/spawnHappyCLI';
import { startHappyServer } from '@/claude/utils/startHappyServer';
import { buildHapiMcpBridge } from './utils/buildHapiMcpBridge';
import { emitReadyIfIdle } from './utils/emitReadyIfIdle';
import type { CodexSession } from './session';
import type { EnhancedMode } from './loop';
@@ -25,7 +24,7 @@ import {
type RemoteLauncherExitReason
} from '@/modules/common/remote/RemoteLauncherBase';
type HappyServer = Awaited<ReturnType<typeof startHappyServer>>;
type HappyServer = Awaited<ReturnType<typeof buildHapiMcpBridge>>['server'];
class CodexRemoteLauncher extends RemoteLauncherBase {
private readonly session: CodexSession;
@@ -420,15 +419,8 @@ class CodexRemoteLauncher extends RemoteLauncherBase {
}
});
const happyServer = await startHappyServer(session.client);
const { server: happyServer, mcpServers } = await buildHapiMcpBridge(session.client);
this.happyServer = happyServer;
const bridgeCommand = getHappyCliCommand(['mcp', '--url', happyServer.url]);
const mcpServers = {
hapi: {
command: bridgeCommand.command,
args: bridgeCommand.args
}
} as const;
this.setupAbortHandlers(session.client.rpcHandlerManager, {
onAbort: () => this.handleAbort(),