Skip to content

Bug: JSONC comment stripping regex breaks URLs in config files #11

@MohMaya

Description

@MohMaya

Summary

The installer fails to register the plugin when opencode.json contains URLs (e.g., MCP configurations with http:// or https://).

Root Cause

The JSONC comment stripping regex in cli.ts (line 204) and config.ts (line 38-40) incorrectly strips content after // inside string values:

const jsonContent = content.replace(/\/\/.*$/gm, "").replace(/\/\*[\s\S]*?\*\//g, "");

This regex is intended to strip single-line comments like // comment, but it naively matches ANY // on a line, including those inside quoted strings (URLs).

Example

Input (opencode.json):

{
  "plugin": ["oh-my-opencode"],
  "mcp": {
    "Figma Desktop": {
      "url": "http://127.0.0.1:3845/mcp"
    }
  },
  "$schema": "https://opencode.ai/config.json"
}

After comment stripping:

{
  "plugin": ["oh-my-opencode"],
  "mcp": {
    "Figma Desktop": {
      "url": "http:
    }
  },
  "$schema": "https:
}

The URLs are truncated, producing invalid JSON.

Symptoms

  • Installer outputs: ✗ Failed to parse config file
  • Plugin is never added to opencode.json
  • After restart, OpenCode shows "MCP not found" for supermemory
  • The /supermemory-init command exists but cannot use the supermemory tool

Affected Files

  • src/cli.ts line 204
  • src/config.ts lines 38-40

Proposed Fix

Replace the naive regex with a JSONC-aware parser that respects string boundaries. Options:

  1. Use a library like jsonc-parser (from VSCode)
  2. Implement a state-machine based comment stripper
  3. Use a more conservative regex that only matches // at the start of a line (with optional leading whitespace)

Environment

  • opencode-supermemory version: 0.1.3
  • Config file: opencode.json (not .jsonc)
  • Config contains MCP definitions with URLs

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions