Skip to content

fix(ocm-cli): detect the OpenCode service in ocm link - #449

Merged
chriswritescode-dev merged 1 commit into
mainfrom
fix/ocm-link-service-discovery
Oct 20, 2026
Merged

chriswritescode-dev merged 1 commit into
mainfrom
fix/ocm-link-service-discovery

Conversation

@chriswritescode-dev

@chriswritescode-dev chriswritescode-dev commented Oct 20, 2026 •

Copy link
Copy Markdown
Owner

Summary

ocm link now finds the OpenCode background service on its own instead of requiring OPENCODE_SERVER_PASSWORD=... ocm link. It reads the service registration ($XDG_STATE_HOME/opencode/service.json) first, then the opencode service config ($XDG_CONFIG_HOME/opencode/service.json), and pairs with that URL and password.

Service discovery (ocm-cli/src/link.ts)

  • discoverOpenCodeService reads the registration, then the config, and returns the base URL, password, source and loopback flag. It never throws and returns null when neither file yields a usable service.
  • A wildcard host (0.0.0.0, ::) is replaced with this machine's first non-internal IPv4 address, falling back to 127.0.0.1 when there is none.
  • loopbackOnly is classified from the final hostname, so the fallback is reported as loopback and the remote-access warning still fires.
  • An IPv6 config hostname is bracketed before it is parsed.
  • The password follows the source that was selected, so a stale registration password is no longer applied to a config URL.

Platform default port

  • The config fallback uses 45278 on Windows and 49374 elsewhere, matching the OpenCode docs.

CLI wiring (ocm-cli/bin/ocm.ts)

  • cmdLink reports which source the URL came from and warns when the service only listens on loopback, since a remote Manager cannot reach it.
  • An explicit --url or $OPENCODE_SERVER_URL still skips detection, so a discovered password is never sent to an unrelated URL; that case requires an explicit password.

Docs (ocm-cli/README.md)

  • Documents the detection order, wildcard substitution, loopback warning and the Windows default port.
  • States that an explicit URL requires --password or $OPENCODE_SERVER_PASSWORD.

Tests (ocm-cli/test/link.test.ts)

  • Discovery coverage: wildcard substitution with and without a LAN address, config fallback, IPv6 hostnames, malformed registration, loopback classification and source-matched passwords.
  • Platform default port coverage with a process.platform mock.

Known gaps

  • Non-release OpenCode channels derive their default port from a hash of the channel name; only the release default is handled here.
  • The Windows port is covered by a platform mock, not a real Windows run.

Summary by CodeRabbit

  • New Features

    • ocm link now automatically detects configured OpenCode services when no URL is provided.
    • Reuses detected service addresses and passwords, including support for registration and configuration settings.
    • Handles wildcard hosts, local network addresses, default ports, and loopback-only services.
    • Reports missing or unusable service credentials and warns when remote Manager access may be unavailable.
    • Explicit URLs or environment settings continue to bypass automatic detection.
  • Documentation

    • Updated ocm link documentation to describe service detection, defaults, credentials, and warnings.

Read the service registration then config for the base URL and password, warn when the service is loopback only, substitute LAN addresses for wildcard hosts, and use the Windows default port. Clarify that explicit URLs require explicit credentials.
@coderabbitai

coderabbitai Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Essentials
  • Run ID: e6baf0b2-d33f-436f-bf35-6881d7124fb3
📥 Commits

Reviewing files that changed from the base of the PR and between 2106722 and 4e26a19.

📒 Files selected for processing: 4
  • ocm-cli/README.md
  • ocm-cli/bin/ocm.ts
  • ocm-cli/src/link.ts
  • ocm-cli/test/link.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 5 included reviews per hour; 3 remain after this review.

📝 Walkthrough

ocm link now discovers OpenCode service URLs and passwords from registration or configuration files when no explicit URL or environment URL is set. The command reports the detected service and loopback-only status. The README documents discovery defaults and override behavior.

Changes: OpenCode service discovery

Layer / File(s) Summary
Service discovery and URL resolution
ocm-cli/src/link.ts, ocm-cli/test/link.test.ts
The link module resolves LAN IPv4 addresses and discovers service URLs and passwords from registration or configuration files. Tests cover source precedence, URL normalization, password fallback, malformed data, and platform-specific ports.
CLI integration and usage
ocm-cli/bin/ocm.ts, ocm-cli/README.md
ocm link applies URL and password precedence, retains the detected service source and loopback status, and reports detected services and loopback warnings. The README describes discovery defaults and explicit overrides.

Priority: ⬇️ Low

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  actor User
  participant OpenCodeCLI
  participant discoverOpenCodeService
  participant OpenCodeServiceRegistration
  participant OpenCodeConfig
  participant OpenCodeServer

  User->>OpenCodeCLI: Run ocm link
  alt Explicit URL or OPENCODE_SERVER_URL is set
    OpenCodeCLI->>OpenCodeCLI: Use supplied URL and skip discovery
  else No URL override
    OpenCodeCLI->>discoverOpenCodeService: Discover service settings
    discoverOpenCodeService->>OpenCodeServiceRegistration: Read registration
    alt Registration is usable
      OpenCodeServiceRegistration-->>discoverOpenCodeService: URL and registration password
    else Registration is missing or unusable
      discoverOpenCodeService->>OpenCodeConfig: Read service configuration
      OpenCodeConfig-->>discoverOpenCodeService: Configured URL and password
    end
    discoverOpenCodeService-->>OpenCodeCLI: Discovered URL and password
  end
  OpenCodeCLI->>OpenCodeServer: Probe using resolved link options
Loading
Merge Risk: ⚪ Minimal · up to 4e26a

No issue requiring a change before merge was established.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 21.05% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 19 functions across 3 files. (1 skipped: … Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely identifies the main change: detecting the OpenCode service in ocm link.
Description check Passed The description includes all required sections and provides a detailed summary of service discovery, CLI behavior, documentation, tests, and known gaps. The type-of-change and checklist boxes remain u…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description includes all required sections and provides a detailed summary of service discovery, CLI behavior, documentation, tests, and known gaps. The type-of-change and checklist boxes remain unchecked, so those confirmations are not explicitly recorded, but the description is otherwise mostly complete.

Full details: Docstring Coverage

Explanation

Docstring coverage is 21.05% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 19 functions across 3 files. (1 skipped: 1 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

  • Fix all pre-merge checks with AI
✨ Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Some tools did not complete. Review the errors below.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ocm-cli/test/link.test.ts

Parsing error: /ocm-cli/test/link.test.ts was not found by the project service. Consider either including it in the tsconfig.json or including it in allowDefaultProject.

Comment @coderabbitai help to get the list of available commands.

@chriswritescode-dev
chriswritescode-dev merged commit b00b74f into main Oct 20, 2026
2 checks passed
@chriswritescode-dev
chriswritescode-dev deleted the fix/ocm-link-service-discovery branch October 20, 2026 13:35
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.

1 participant