import { readFileSync } from "node:fs"; import { resolve } from "node:path"; import { normalizeMcpConfig } from "./mcp-config.js"; import { compileOpencodeModels, loadAgentModelConfig, type AgentModelConfig } from "../chat/modelConfig.js"; // A conversation Location can be outside the checkout. Load only the trusted // service assets explicitly, rather than relying on its current directory. export function serviceOpencodeConfig(input: Record, models: AgentModelConfig = loadAgentModelConfig()) { const agents = (input.agents ?? {}) as Record; const instruction = (agents.instruction ?? {}) as Record; const system = readFileSync(resolve(".opencode/agents/instruction.md"), "utf8") .replace(/^---\s*\n[\s\S]*?\n---\s*\n/, ""); return { ...input, ...compileOpencodeModels(models), snapshots: false, mcp: normalizeMcpConfig(input.mcp), plugins: ["*", ...((input.plugins ?? []) as unknown[]), resolve(".opencode/tjwater-plugin")], skills: [resolve(process.env.OPENCODE_SKILLS_ROOT_DIR ?? ".opencode/skills")], agents: { ...agents, instruction: { description: "TJWater structured data and UI agent", mode: "primary", ...instruction, model: models.default_model, system, } }, }; }