MCPcopy Create free account
hub / github.com/cortexkit/magic-context / addPluginToTuiConfig

Function addPluginToTuiConfig

packages/cli/src/commands/setup-opencode.ts:90–116  ·  view source on GitHub ↗
(configPath: string, format: "json" | "jsonc" | "none")

Source from the content-addressed store, hash-verified

88}
89
90function 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
118export function findDcpPluginIndexes(plugins: unknown[]): number[] {
119 return plugins

Callers 1

runSetupFunction · 0.85

Calls 7

writeFileAtomicFunction · 0.90
matchesPluginEntryFunction · 0.90
isDevPathPluginEntryFunction · 0.90
stringifyJsoncFunction · 0.85
ensureDirFunction · 0.70
readJsoncFunction · 0.70
warnMethod · 0.65

Tested by

no test coverage detected