mirror of
https://github.com/wu736139669/hapi.git
synced 2026-11-19 03:40:50 +00:00
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:
@@ -0,0 +1,93 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { buildMcpServerConfigArgs, buildDeveloperInstructionsArg } from './codexMcpConfig';
|
||||
|
||||
describe('codexMcpConfig', () => {
|
||||
describe('buildMcpServerConfigArgs', () => {
|
||||
it('builds config args for a single MCP server', () => {
|
||||
const mcpServers = {
|
||||
hapi: {
|
||||
command: 'hapi',
|
||||
args: ['mcp', '--url', 'http://localhost:3000']
|
||||
}
|
||||
};
|
||||
|
||||
const args = buildMcpServerConfigArgs(mcpServers);
|
||||
|
||||
expect(args).toEqual([
|
||||
'-c', 'mcp_servers.hapi.command="hapi"',
|
||||
'-c', 'mcp_servers.hapi.args=["mcp","--url","http://localhost:3000"]'
|
||||
]);
|
||||
});
|
||||
|
||||
it('builds config args for multiple MCP servers', () => {
|
||||
const mcpServers = {
|
||||
hapi: { command: 'hapi', args: ['mcp'] },
|
||||
other: { command: 'node', args: ['server.js'] }
|
||||
};
|
||||
|
||||
const args = buildMcpServerConfigArgs(mcpServers);
|
||||
|
||||
expect(args).toContain('-c');
|
||||
expect(args).toContain('mcp_servers.hapi.command="hapi"');
|
||||
expect(args).toContain('mcp_servers.other.command="node"');
|
||||
});
|
||||
|
||||
it('handles empty args array', () => {
|
||||
const mcpServers = {
|
||||
simple: { command: 'simple-server', args: [] }
|
||||
};
|
||||
|
||||
const args = buildMcpServerConfigArgs(mcpServers);
|
||||
|
||||
expect(args).toContain('mcp_servers.simple.args=[]');
|
||||
});
|
||||
|
||||
it('escapes special characters in command', () => {
|
||||
const mcpServers = {
|
||||
test: { command: 'path/to/server', args: [] }
|
||||
};
|
||||
|
||||
const args = buildMcpServerConfigArgs(mcpServers);
|
||||
|
||||
expect(args).toContain('mcp_servers.test.command="path/to/server"');
|
||||
});
|
||||
});
|
||||
|
||||
describe('buildDeveloperInstructionsArg', () => {
|
||||
it('builds developer instructions arg', () => {
|
||||
const instructions = 'Call functions.hapi__change_title to set title.';
|
||||
|
||||
const args = buildDeveloperInstructionsArg(instructions);
|
||||
|
||||
expect(args).toEqual([
|
||||
'-c',
|
||||
'developer_instructions="Call functions.hapi__change_title to set title."'
|
||||
]);
|
||||
});
|
||||
|
||||
it('escapes double quotes', () => {
|
||||
const instructions = 'Use "quotes" in text.';
|
||||
|
||||
const args = buildDeveloperInstructionsArg(instructions);
|
||||
|
||||
expect(args[1]).toContain('\\"quotes\\"');
|
||||
});
|
||||
|
||||
it('escapes newlines', () => {
|
||||
const instructions = 'Line 1\nLine 2';
|
||||
|
||||
const args = buildDeveloperInstructionsArg(instructions);
|
||||
|
||||
expect(args[1]).toContain('\\n');
|
||||
expect(args[1]).not.toContain('\n');
|
||||
});
|
||||
|
||||
it('escapes backslashes', () => {
|
||||
const instructions = 'Path: C:\\Users\\test';
|
||||
|
||||
const args = buildDeveloperInstructionsArg(instructions);
|
||||
|
||||
expect(args[1]).toContain('\\\\');
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user