mirror of
https://github.com/wu736139669/hapi.git
synced 2026-10-09 19:29:41 +00:00
feat: add change_title MCP tool support to OpenCode
This commit is contained in:
@@ -5,6 +5,9 @@ import { Future } from '@/utils/future';
|
||||
import { getLocalLaunchExitReason } from '@/agent/localLaunchPolicy';
|
||||
import { ensureOpencodeHookPlugin } from './utils/hookPlugin';
|
||||
import { buildOpencodeEnv } from './utils/config';
|
||||
import { ensureOpencodeConfig } from './utils/opencodeConfig';
|
||||
import { TITLE_INSTRUCTION } from './utils/systemPrompt';
|
||||
import { buildHapiMcpBridge } from '@/codex/utils/buildHapiMcpBridge';
|
||||
import type { OpencodeHookEvent } from './types';
|
||||
import type { OpencodeHookServer } from './utils/startOpencodeHookServer';
|
||||
import { createOpencodeStorageScanner, type OpencodeStorageScannerHandle } from './utils/opencodeStorageScanner';
|
||||
@@ -263,6 +266,21 @@ export async function opencodeLocalLauncher(
|
||||
const opencodeConfigDir = resolveOpencodeConfigDir(session);
|
||||
ensureOpencodeHookPlugin(opencodeConfigDir, hookUrl, opts.hookServer.token);
|
||||
|
||||
// Start the hapi MCP server for change_title support (optional feature)
|
||||
let happyServer: { url: string; stop: () => void } | null = null;
|
||||
let opencodeConfigPath: string | null = null;
|
||||
try {
|
||||
const bridge = await buildHapiMcpBridge(session.client);
|
||||
happyServer = bridge.server;
|
||||
logger.debug(`[opencode-local]: Started hapi MCP server at ${happyServer.url}`);
|
||||
|
||||
// Generate opencode.json config with MCP server and instructions
|
||||
const { configPath } = ensureOpencodeConfig(opencodeConfigDir, bridge.mcpServers.hapi, TITLE_INSTRUCTION);
|
||||
opencodeConfigPath = configPath;
|
||||
} catch (error) {
|
||||
logger.debug('[opencode-local]: Failed to start hapi MCP server (change_title will be unavailable)', error);
|
||||
}
|
||||
|
||||
let storageScanner: OpencodeStorageScannerHandle | null = null;
|
||||
const messageRoles = new Map<string, string>();
|
||||
const sentTextParts = new Set<string>();
|
||||
@@ -617,6 +635,10 @@ export async function opencodeLocalLauncher(
|
||||
if (!env.OPENCODE_CONFIG_DIR) {
|
||||
env.OPENCODE_CONFIG_DIR = opencodeConfigDir;
|
||||
}
|
||||
// Set OPENCODE_CONFIG to point to our generated config file (if MCP server started)
|
||||
if (!env.OPENCODE_CONFIG && opencodeConfigPath) {
|
||||
env.OPENCODE_CONFIG = opencodeConfigPath;
|
||||
}
|
||||
|
||||
await opencodeLocal({
|
||||
path: session.path,
|
||||
@@ -659,6 +681,10 @@ export async function opencodeLocalLauncher(
|
||||
if (storageScanner) {
|
||||
await storageScanner.cleanup();
|
||||
}
|
||||
if (happyServer) {
|
||||
happyServer.stop();
|
||||
logger.debug('[opencode-local]: Stopped hapi MCP server');
|
||||
}
|
||||
}
|
||||
|
||||
return exitReason || 'exit';
|
||||
|
||||
Reference in New Issue
Block a user