( rawConfigJson: string | undefined, bridgedOpenCodeServerNames: readonly string[], cmEntry: CodemodeLaunchEntry, )
| 1033 | * overlay ONLY (never touching `~/.config/opencode/opencode.json`). |
| 1034 | */ |
| 1035 | export function applyOpenCodeCodemodeOverlay( |
| 1036 | rawConfigJson: string | undefined, |
| 1037 | bridgedOpenCodeServerNames: readonly string[], |
| 1038 | cmEntry: CodemodeLaunchEntry, |
| 1039 | ): string { |
| 1040 | let doc: Record<string, unknown> = {}; |
| 1041 | if (rawConfigJson) { |
| 1042 | try { |
| 1043 | const parsed = parseJsonRelaxed(rawConfigJson); |
| 1044 | if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) doc = parsed as Record<string, unknown>; |
| 1045 | } catch { /* fallback to empty */ } |
| 1046 | } |
| 1047 | const existingMcp = |
| 1048 | doc.mcp && typeof doc.mcp === "object" && !Array.isArray(doc.mcp) |
| 1049 | ? { ...(doc.mcp as Record<string, unknown>) } |
| 1050 | : {}; |
| 1051 | for (const name of bridgedOpenCodeServerNames) { |
| 1052 | existingMcp[name] = { enabled: false }; |
| 1053 | } |
| 1054 | existingMcp["caveman-codemode"] = { |
| 1055 | type: "local", |
| 1056 | command: [cmEntry.command, ...cmEntry.args], |
| 1057 | enabled: true, |
| 1058 | }; |
| 1059 | return JSON.stringify({ ...doc, mcp: existingMcp }); |
| 1060 | } |
| 1061 | |
| 1062 | /** |
| 1063 | * Injects `mcp["caveman-codemode"]` into an ephemeral `KILO_CONFIG_CONTENT` |
no test coverage detected