(configPath: string, format: "json" | "jsonc" | "none")
| 88 | } |
| 89 | |
| 90 | function addPluginToTuiConfig(configPath: string, format: "json" | "jsonc" | "none"): void { |
| 91 | ensureDir(dirname(configPath)); |
| 92 | |
| 93 | if (format === "none") { |
| 94 | writeFileAtomic(configPath, `${stringifyJsonc({ plugin: [PLUGIN_ENTRY] }, null, 2)}\n`); |
| 95 | return; |
| 96 | } |
| 97 | |
| 98 | const existing = readJsonc(configPath); |
| 99 | if (!existing) { |
| 100 | log.warn(`Could not parse ${configPath} — skipping to avoid data loss`); |
| 101 | return; |
| 102 | } |
| 103 | |
| 104 | // Same rules as the main opencode config — preserve tuple entries and |
| 105 | // never replace dev-path entries. |
| 106 | const rawPlugins: unknown[] = Array.isArray(existing.plugin) ? existing.plugin : []; |
| 107 | const hasNpmEntry = rawPlugins.some((p) => matchesPluginEntry(p, PLUGIN_NAME)); |
| 108 | const hasDevEntry = rawPlugins.some((p) => isDevPathPluginEntry(p)); |
| 109 | |
| 110 | if (!hasNpmEntry && !hasDevEntry) { |
| 111 | rawPlugins.push(PLUGIN_ENTRY); |
| 112 | } |
| 113 | |
| 114 | existing.plugin = rawPlugins; |
| 115 | writeFileAtomic(configPath, `${stringifyJsonc(existing, null, 2)}\n`); |
| 116 | } |
| 117 | |
| 118 | export function findDcpPluginIndexes(plugins: unknown[]): number[] { |
| 119 | return plugins |
no test coverage detected