@different-ai/opencode-browser 4.2.3 → 4.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bin/cli.js CHANGED
@@ -289,6 +289,10 @@ Find it at ${color("cyan", "chrome://extensions")}:
289
289
  .replace(/^\s*\/\/.*$/gm, "");
290
290
  }
291
291
 
292
+ function sanitizeJson(contents) {
293
+ return stripJsoncComments(contents).replace(/,\s*(\]|\})/g, "$1");
294
+ }
295
+
292
296
  function findOpenCodeConfigPath(configDir) {
293
297
  const jsoncPath = join(configDir, "opencode.jsonc");
294
298
  if (existsSync(jsoncPath)) return jsoncPath;
@@ -338,17 +342,38 @@ Find it at ${color("cyan", "chrome://extensions")}:
338
342
 
339
343
  if (shouldUpdate) {
340
344
  try {
341
- const config = hasExistingConfig
342
- ? JSON.parse(stripJsoncComments(readFileSync(configPath, "utf-8")))
343
- : { $schema: "https://opencode.ai/config.json", plugin: [] };
344
-
345
- config.plugin = normalizePlugins(config.plugin);
346
- if (!config.plugin.includes(desiredPlugin)) config.plugin.push(desiredPlugin);
347
- if (typeof config.$schema !== "string") config.$schema = "https://opencode.ai/config.json";
348
-
349
- ensureDir(configDir);
350
- writeFileSync(configPath, JSON.stringify(config, null, 2) + "\n");
351
- success(`Updated ${configPath} with plugin`);
345
+ let config = { $schema: "https://opencode.ai/config.json", plugin: [] };
346
+ let canWriteConfig = true;
347
+
348
+ if (hasExistingConfig) {
349
+ const rawConfig = readFileSync(configPath, "utf-8");
350
+ try {
351
+ config = JSON.parse(sanitizeJson(rawConfig));
352
+ } catch (e) {
353
+ error(`Failed to parse ${configPath}: ${e.message}`);
354
+ const shouldOverwrite = await confirm("Config is invalid JSON. Back up and recreate it?");
355
+ if (shouldOverwrite) {
356
+ const backupPath = `${configPath}.bak-${Date.now()}`;
357
+ writeFileSync(backupPath, rawConfig);
358
+ warn(`Backed up invalid config to ${backupPath}`);
359
+ config = { $schema: "https://opencode.ai/config.json", plugin: [] };
360
+ } else {
361
+ canWriteConfig = false;
362
+ }
363
+ }
364
+ }
365
+
366
+ if (canWriteConfig) {
367
+ config.plugin = normalizePlugins(config.plugin);
368
+ if (!config.plugin.includes(desiredPlugin)) config.plugin.push(desiredPlugin);
369
+ if (typeof config.$schema !== "string") config.$schema = "https://opencode.ai/config.json";
370
+
371
+ ensureDir(configDir);
372
+ writeFileSync(configPath, JSON.stringify(config, null, 2) + "\n");
373
+ success(`Updated ${configPath} with plugin`);
374
+ } else {
375
+ warn(`Skipped updating ${configPath}. Fix JSON manually and rerun install.`);
376
+ }
352
377
  } catch (e) {
353
378
  error(`Failed to update ${configPath}: ${e.message}`);
354
379
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "manifest_version": 3,
3
3
  "name": "OpenCode Browser Automation",
4
- "version": "4.2.3",
4
+ "version": "4.2.4",
5
5
  "description": "Browser automation for OpenCode",
6
6
  "permissions": [
7
7
  "tabs",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@different-ai/opencode-browser",
3
- "version": "4.2.3",
3
+ "version": "4.2.4",
4
4
  "description": "Browser automation plugin for OpenCode (native messaging + per-tab ownership).",
5
5
  "type": "module",
6
6
  "bin": {