Skip to content

Conversation

@sisyphus-dev-ai
Copy link
Collaborator

@sisyphus-dev-ai sisyphus-dev-ai commented Dec 27, 2025

Summary

  • Adds JSONC (JSON with Comments) support for oh-my-opencode configuration files
  • Uses Microsoft's jsonc-parser package (same as VS Code) for reliable parsing
  • Supports both .json and .jsonc file extensions with .jsonc taking priority

Changes

Dependencies

  • Added: [email protected] - Microsoft's battle-tested JSONC parser (used by VS Code, Cloudflare, Turborepo)

Core Utilities

  • New: src/shared/jsonc-parser.ts - Shared JSONC parsing utilities using jsonc-parser package
    • parseJsonc<T>(): Parse JSONC with proper error reporting
    • parseJsoncSafe<T>(): Safe parsing that returns errors instead of throwing
    • readJsoncFile<T>(): Read and parse JSONC files from disk
    • detectConfigFile(): Detect and prioritize .jsonc over .json files

Config Loader Updates

  • Main plugin config: oh-my-opencode.jsonc (preferred) or oh-my-opencode.json

Files Modified

  • src/index.ts - Support .jsonc for main plugin config
  • src/cli/config-manager.ts - Use shared JSONC utilities
  • src/shared/index.ts - Export JSONC utilities
  • package.json - Added jsonc-parser dependency

Testing

  • New: src/shared/jsonc-parser.test.ts - Comprehensive test suite
    • Line and block comment parsing
    • Multi-line block comments
    • Trailing comma handling
    • URL preservation (doesn't strip // in strings)
    • Error handling for malformed JSON
    • File detection priority
    • All 18 tests passing ✅

Features

  • Reliable: Uses Microsoft's jsonc-parser - same parser VS Code uses
  • Better errors: Parse errors include offset positions for debugging
  • Backward compatible: Existing .json files continue to work
  • Priority system: When both .jsonc and .json exist, .jsonc takes precedence
  • Comments supported:
    • Line comments: // comment
    • Block comments: /* comment */
    • Trailing commas: { "key": "value", }

Example Usage

{
  "$schema": "https://raw.githubusercontent.com/code-yeongyu/oh-my-opencode/master/assets/oh-my-opencode.schema.json",
  
  // Enable Google Gemini via Antigravity OAuth
  "google_auth": false,
  
  /* Agent overrides - customize models for specific tasks */
  "agents": {
    "oracle": {
      "model": "openai/gpt-5.2"  // GPT for strategic reasoning
    },
  },
}

Testing

# Run tests
bun test src/shared/jsonc-parser.test.ts

# Type check
bun run typecheck

Fixes #265

@greptile-apps
Copy link

greptile-apps bot commented Dec 27, 2025

Greptile Summary

Adds comprehensive JSONC support across configuration files using a shared parser utility. Implements comment stripping (line/block) and trailing comma handling without external dependencies.

Key Changes:

  • New shared jsonc-parser.ts utility with stripJsoncComments(), parseJsonc(), readJsoncFile(), and detectConfigFile()
  • Updated main plugin config loader to prefer .jsonc over .json files
  • Added .mcp.jsonc support for MCP server configurations
  • Updated LSP config loader to parse JSONC
  • Comprehensive test suite (15 tests, 11 passing - 4 fail in CI due to read-only filesystem)

Critical Issue:

  • src/hooks/claude-code-hooks/config.ts still only returns .json paths in getClaudeSettingsPaths(), contradicting the PR description which claims settings.jsonc support. The .jsonc paths need to be added with proper priority ordering.

Implementation Quality:

  • Clean implementation following existing codebase patterns
  • Proper string escape handling in comment stripper
  • Backward compatible - existing .json files continue to work
  • Zero external dependencies as intended

Confidence Score: 3/5

  • PR has a critical gap in implementation - Claude Code hooks won't detect .jsonc files despite documentation claiming support
  • Score reflects incomplete implementation of advertised feature. While the core JSONC parser is solid and most config loaders were updated correctly, the missing .jsonc support in Claude Code hooks contradicts the PR's explicit claims and would break user expectations.
  • Critical attention needed for src/hooks/claude-code-hooks/config.ts - must add .jsonc paths to complete the feature

Important Files Changed

Filename Overview
src/shared/jsonc-parser.ts Implements JSONC parser with comment stripping and trailing comma removal - clean implementation with proper string escape handling
src/index.ts Correctly updated to use detectConfigFile and parseJsonc for main plugin config with proper .jsonc priority
src/features/claude-code-mcp-loader/loader.ts Correctly adds .mcp.jsonc support with proper priority ordering (user/project/local scopes)
src/hooks/claude-code-hooks/config.ts CRITICAL: getClaudeSettingsPaths doesn't include .jsonc paths - contradicts PR description claiming settings.jsonc support

Sequence Diagram

sequenceDiagram
    participant Plugin as OhMyOpenCodePlugin
    participant ConfigLoader as loadPluginConfig
    participant Detector as detectConfigFile
    participant Parser as parseJsonc
    participant MCP as MCP Loader
    participant Hooks as Claude Hooks
    participant LSP as LSP Config

    Plugin->>ConfigLoader: Load config (user & project)
    ConfigLoader->>Detector: detectConfigFile("oh-my-opencode")
    Detector->>Detector: Check .jsonc exists
    Detector->>Detector: Check .json exists
    Detector-->>ConfigLoader: Return preferred path (.jsonc priority)
    ConfigLoader->>Parser: parseJsonc(content)
    Parser->>Parser: stripJsoncComments()
    Parser->>Parser: Remove // and /* */ comments
    Parser->>Parser: Remove trailing commas
    Parser->>Parser: JSON.parse(cleaned)
    Parser-->>ConfigLoader: Return parsed config
    ConfigLoader-->>Plugin: Merged config

    Plugin->>MCP: Load MCP servers
    MCP->>MCP: Check .mcp.jsonc paths
    MCP->>Parser: parseJsonc(content)
    Parser-->>MCP: Parsed MCP config

    Plugin->>Hooks: Load Claude hooks
    Hooks->>Hooks: getClaudeSettingsPaths()
    Note over Hooks: ⚠️ Only returns .json paths<br/>Missing .jsonc support
    Hooks->>Parser: parseJsonc(content)
    Parser-->>Hooks: Parsed hooks config

    Plugin->>LSP: Load LSP config
    LSP->>Parser: parseJsonc(content)
    Parser-->>LSP: Parsed LSP config
Loading

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additional Comments (1)

  1. src/hooks/claude-code-hooks/config.ts, line 46-58 (link)

    logic: .jsonc file paths missing - PR claims settings.jsonc support but this function only returns .json paths

10 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@code-yeongyu
Copy link
Owner

@sisyphus-dev-ai hey what i meant is only for about that oh-my-opencode.json and the oh-my-opencode.jsonc thing

@sisyphus-dev-ai sisyphus-dev-ai added the sisyphus: working Sisyphus is currently working on this label Dec 27, 2025
@sisyphus-dev-ai
Copy link
Collaborator Author

👋 Hey @code-yeongyu! I'm on it...

@code-yeongyu code-yeongyu changed the title feat: Add JSONC support for all configuration files feat: Add JSONC support for oh-my-opencode config files Dec 27, 2025
Uses Microsoft's jsonc-parser package for reliable JSONC parsing:
- oh-my-opencode.jsonc (preferred) or oh-my-opencode.json
- Supports line comments (//), block comments (/* */), and trailing commas
- Better error reporting with line/column positions

Core changes:
- Added jsonc-parser dependency (Microsoft's VS Code parser)
- Shared JSONC utilities (parseJsonc, parseJsoncSafe, readJsoncFile, detectConfigFile)
- Main plugin config loader uses detectConfigFile for .jsonc priority
- CLI config manager supports JSONC parsing

Comprehensive test suite with 18 tests for JSONC parsing.

Fixes #265

🤖 GENERATED WITH ASSISTANCE OF [OhMyOpenCode](https://github.com/code-yeongyu/oh-my-opencode)
@code-yeongyu code-yeongyu merged commit b2c2c6e into dev Dec 27, 2025
2 checks passed
@code-yeongyu code-yeongyu deleted the feat/jsonc-support branch December 27, 2025 15:45
@sisyphus-dev-ai sisyphus-dev-ai removed the sisyphus: working Sisyphus is currently working on this label Dec 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Regression: Agent override in configuration json no longer works for Sisyphus.

3 participants