(
rootPath: string,
mcpServer: McpServerEntry,
instructions: string
)
| 34 | * @param instructions - The instruction text to write to the instructions file |
| 35 | */ |
| 36 | export function ensureOpencodeConfig( |
| 37 | rootPath: string, |
| 38 | mcpServer: McpServerEntry, |
| 39 | instructions: string |
| 40 | ): { configPath: string; instructionsPath: string } { |
| 41 | mkdirSync(rootPath, { recursive: true }); |
| 42 | |
| 43 | // Write instructions file |
| 44 | const instructionsPath = join(rootPath, INSTRUCTIONS_FILENAME); |
| 45 | writeFileSafe(instructionsPath, instructions); |
| 46 | |
| 47 | // Build opencode.json config |
| 48 | // Use absolute path for instructions since OpenCode resolves paths relative to project root |
| 49 | const config: OpencodeConfig = { |
| 50 | $schema: 'https://opencode.ai/config.json', |
| 51 | mcp: { |
| 52 | hapi: { |
| 53 | type: 'local', |
| 54 | command: [mcpServer.command, ...mcpServer.args], |
| 55 | enabled: true |
| 56 | } |
| 57 | }, |
| 58 | instructions: [instructionsPath] |
| 59 | }; |
| 60 | |
| 61 | const configPath = join(rootPath, CONFIG_FILENAME); |
| 62 | const configJson = JSON.stringify(config, null, 2); |
| 63 | writeFileSafe(configPath, configJson); |
| 64 | |
| 65 | return { configPath, instructionsPath }; |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * Write file only if content has changed. |
no test coverage detected