Skip to content

Conversation

@code-yeongyu
Copy link
Owner

@code-yeongyu code-yeongyu commented Jan 4, 2026

Summary

This PR adds compatibility with OpenCode v1.1.1's new permission system while maintaining backward compatibility with older versions.

Changes

  • Version Detection Utility (opencode-version.ts)

    • Detects installed OpenCode version via opencode --version
    • Provides version comparison functions (isVersionGte, isVersionLt, compareVersions)
    • Identifies whether the new permission system is supported (v1.1.1+)
    • Cached version detection to avoid repeated subprocess calls
  • Permission Compatibility Layer (permission-compat.ts)

    • Utility functions for converting between tools (boolean) and permission (allow/deny/ask) formats
    • createAgentRestrictions() helper for clean agent configuration
    • Type-safe interfaces for both old and new permission formats
  • Agent Configuration Fixes

    • oracle.ts: Fixed invalid permission: { write: "deny" }tools: { write: false }, permission: { edit: "deny" }
    • explore.ts: Fixed invalid permission: { write: "deny" }tools: { write: false }, permission: { edit: "deny" }
    • document-writer.ts: Fixed invalid permission: { background_task: "deny" }tools: { background_task: false }

Breaking Change Context (OpenCode v1.1.1)

OpenCode v1.1.1 introduced a new permission system:

  • tools config deprecated → merged into permission
  • Old: { "tools": { "bash": true } } → New: { "permission": { "bash": "allow" } }
  • SDK AgentConfig.permission only accepts specific keys: edit, bash, webfetch, doom_loop, external_directory

Our agents were incorrectly using permission with invalid keys (write, task, background_task). This fix:

  1. Uses tools for tool access control (disable specific tools)
  2. Uses permission only for valid SDK permission keys

Tests

Added 37 new tests covering:

  • Version parsing and comparison
  • Permission format conversion
  • Agent restriction creation
  • Cache behavior for version detection

Closes #487


🤖 This PR was 100% written by Sisyphus

Generated with assistance of OhMyOpenCode


Summary by cubic

Adds OpenCode v1.1.1 permission system compatibility and fixes agent configs to use the correct tools vs permission split. Keeps older versions working via version detection and a small compat layer. Closes #487.

  • New Features

    • Detects installed OpenCode version (cached) with compare helpers and a safe fallback when unknown.
    • Flags support for the new permission system (v1.1.1+) and adds conversion helpers (tools ↔ permission) plus createAgentRestrictions.
    • Adds tests for version parsing, conversions, and cache behavior.
  • Bug Fixes

    • Updates oracle, explore, and document-writer agents: move tool denials to tools { ... } and keep permission to valid keys (e.g., edit: "deny").

Written for commit 9d3c6e3. Summary will update on new commits.

…ity utilities

- Add opencode-version.ts: Detect installed OpenCode version and support API
- Add permission-compat.ts: Compatibility layer for permission system migration
- Add comprehensive tests (418 lines total)
- Export new utilities from shared/index.ts

🤖 Generated with assistance of OhMyOpenCode (https://github.com/code-yeongyu/oh-my-opencode)
- Fix document-writer: change invalid 'permission: { background_task: deny }' to 'tools: { background_task: false }'
- Fix explore: split 'permission' and 'tools' config, move tool-level denials to 'tools' key
- Fix oracle: split 'permission' and 'tools' config, move tool-level denials to 'tools' key
- Align all agents with v1.1.1 permission system structure

🤖 Generated with assistance of OhMyOpenCode (https://github.com/code-yeongyu/oh-my-opencode)
@greptile-apps
Copy link

greptile-apps bot commented Jan 4, 2026

Greptile Summary

This PR successfully adds OpenCode v1.1.1 permission system compatibility while maintaining backward compatibility with older versions. The implementation correctly addresses the breaking change where OpenCode v1.1.1 deprecated the tools config and merged it into permission, with SDK restrictions on valid permission keys.

Key Changes:

  • Version detection utility: Detects OpenCode version via opencode --version, caches results, provides version comparison functions
  • Permission compatibility layer: Provides conversion utilities between tools (boolean) and permission (allow/deny/ask) formats
  • Agent configuration fixes: Fixed 3 agents (oracle.ts, explore.ts, document-writer.ts) that were incorrectly using permission with invalid keys (write, task, background_task)
  • Correct approach: Uses tools config to disable specific tools (e.g., tools: { write: false }), and permission only for valid SDK keys (edit, bash, webfetch, doom_loop, external_directory)

Test Coverage:

  • 37 new tests added (20 for version detection, 17 for permission compatibility)
  • All tests passing with comprehensive edge case coverage
  • Follows TDD principles with BDD-style comments (#given, #when, #then)

Design Quality:

  • Clean separation of concerns between version detection and permission conversion
  • Type-safe interfaces with proper TypeScript types
  • Cache mechanism prevents repeated subprocess calls
  • Graceful fallback when version detection fails (assumes newer version)

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk - well-tested compatibility layer with no breaking changes
  • Score of 5 reflects: (1) comprehensive test coverage with 37 passing tests covering all edge cases, (2) fixes critical bug where agents used invalid permission keys that would fail with OpenCode v1.1.1, (3) maintains backward compatibility without breaking existing functionality, (4) follows project conventions (TDD, BDD comments, type safety, no anti-patterns), (5) clean implementation with proper caching and error handling
  • No files require special attention

Important Files Changed

Filename Overview
src/shared/opencode-version.ts New version detection utility with caching, version parsing, and comparison functions for OpenCode v1.1.1+ detection
src/shared/permission-compat.ts Permission compatibility layer with conversion utilities between tools (boolean) and permission (allow/deny/ask) formats
src/agents/oracle.ts Fixed invalid permission config: separated tools restrictions from valid permission.edit key
src/agents/explore.ts Fixed invalid permission config: separated tools restrictions from valid permission.edit key
src/agents/document-writer.ts Fixed invalid permission.background_task to use tools.background_task instead

Sequence Diagram

sequenceDiagram
    participant Plugin as OhMyOpenCode Plugin
    participant VersionUtil as opencode-version.ts
    participant PermCompat as permission-compat.ts
    participant Agent as Agent Config (oracle/explore/document-writer)
    participant OpenCode as OpenCode SDK

    Note over Plugin,OpenCode: Plugin Initialization

    Plugin->>VersionUtil: getOpenCodeVersion()
    VersionUtil->>VersionUtil: Check cache
    alt Cache miss
        VersionUtil->>OpenCode: execSync("opencode --version")
        OpenCode-->>VersionUtil: "1.1.1" or "1.0.150"
        VersionUtil->>VersionUtil: Parse version, cache result
    end
    VersionUtil-->>Plugin: version string or null

    Plugin->>VersionUtil: supportsNewPermissionSystem()
    VersionUtil->>VersionUtil: isVersionGte(version, "1.1.1")
    VersionUtil-->>Plugin: true/false

    Note over Plugin,Agent: Agent Configuration Phase

    Plugin->>Agent: createAgent()
    Agent->>Agent: Define restrictions
    Note over Agent: OLD (pre-1.1.1): permission: { write: "deny", task: "deny" }<br/>NEW (1.1.1+): tools: { write: false, task: false }, permission: { edit: "deny" }
    
    Agent->>PermCompat: createAgentRestrictions({ denyTools, permission })
    PermCompat->>PermCompat: Build tools config (boolean)
    PermCompat->>PermCompat: Build permission config (allow/deny/ask)
    PermCompat-->>Agent: { tools: {...}, permission: {...} }

    Agent-->>Plugin: AgentConfig with correct format

    Plugin->>OpenCode: Register agent with tools + permission
    Note over OpenCode: v1.1.1+: Uses permission.edit<br/>Pre-1.1.1: Uses tools.write
    OpenCode-->>Plugin: Agent registered
Loading

Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

No issues found across 8 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

@code-yeongyu code-yeongyu merged commit 09f72e2 into dev Jan 4, 2026
4 checks passed
@code-yeongyu code-yeongyu deleted the feat/opencode-v1.1.1-compatibility branch January 4, 2026 19:26
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.

opencode v1.1.1 compatibility

2 participants