MCPcopy Create free account
hub / github.com/KnockOutEZ/wigolo / syncOpencodeConfig

Function syncOpencodeConfig

src/cli/agents/opencode.ts:127–269  ·  view source on GitHub ↗
(
  options: SyncOpencodeConfigOptions = {},
)

Source from the content-addressed store, hash-verified

125}
126
127export async function syncOpencodeConfig(
128 options: SyncOpencodeConfigOptions = {},
129): Promise<SyncOpencodeConfigResult> {
130 const { command, dryRun } = options;
131 const removed: string[] = [];
132 const targetConfigPath = options.configPath ?? configPath();
133 const targetLegacyConfigPath = options.legacyConfigPath ?? legacyConfigPath();
134
135 if (command) {
136 const legacyFailure = await preflightLegacyRemoval(targetLegacyConfigPath, 'migration');
137 if (legacyFailure) return { ...legacyFailure, dryRun };
138
139 const currentExisted = existsSync(targetConfigPath);
140 const wrote = await writeJsonConfig({
141 path: targetConfigPath,
142 keyPath: [...MCP_KEY_PATH],
143 entry: buildEntry(command),
144 allowJsonc: true,
145 requireBackup: true,
146 refuseSymlink: true,
147 dryRun,
148 });
149 if (!wrote.ok) {
150 return {
151 ok: false,
152 code: wrote.code,
153 message: `OpenCode config write failed: ${wrote.message ?? wrote.code}`,
154 backupPath: wrote.backupPath,
155 removed,
156 dryRun,
157 };
158 }
159
160 const migrated = await removeJsonConfigEntry({
161 path: targetLegacyConfigPath,
162 keyPath: [...MCP_KEY_PATH],
163 dryRun,
164 allowJsonc: true,
165 requireBackup: true,
166 refuseSymlink: true,
167 });
168 if (!migrated.ok) {
169 const rollbackFailure = await rollbackConfig(
170 targetConfigPath,
171 currentExisted,
172 true,
173 wrote.backupPath,
174 wrote.writtenContentHash,
175 dryRun,
176 );
177 return {
178 ok: false,
179 code: migrated.code,
180 message: [
181 `legacy OpenCode config migration failed: ${migrated.message ?? migrated.code}`,
182 rollbackFailure,
183 ].filter(Boolean).join('; '),
184 backupPath: wrote.backupPath ?? migrated.backupPath,

Callers 4

applyOneFunction · 0.85
installMcpFunction · 0.85
uninstallFunction · 0.85
opencode.test.tsFile · 0.85

Calls 8

writeJsonConfigFunction · 0.90
removeJsonConfigEntryFunction · 0.90
configPathFunction · 0.85
legacyConfigPathFunction · 0.85
preflightLegacyRemovalFunction · 0.85
rollbackConfigFunction · 0.85
buildEntryFunction · 0.70
pushMethod · 0.65

Tested by

no test coverage detected