Skip to content

Add WSL OpenCode runtime bootstrap#95

Merged
Jay1 merged 12 commits into
mainfrom
jcode/document-opencode-services
Jun 12, 2026
Merged

Add WSL OpenCode runtime bootstrap#95
Jay1 merged 12 commits into
mainfrom
jcode/document-opencode-services

Conversation

@Jay1

@Jay1 Jay1 commented Jun 12, 2026

Copy link
Copy Markdown
Owner

Summary

  • add typed contracts and RPC wiring for WSL OpenCode runtime bootstrap/status/repair
  • add server-owned WSL user-systemd bootstrap for jcode-opencode.service with owner-only install/repair
  • add Settings > Providers > OpenCode controls and source-grounded docs/runbooks for the WSL lane

Test Plan

  • snip bun run --cwd packages/contracts test src/ws.test.ts src/rpc.test.ts
  • snip bun run --cwd apps/server test src/provider/openCodeRuntimeBootstrap.test.ts src/provider/openCodeRuntimeHealth.test.ts
  • snip bun run --cwd apps/web test src/wsNativeApi.test.ts
  • snip bun run --cwd apps/web test:browser:local src/components/OpenCodeRuntimeSettingsPanel.browser.tsx
  • snip bunx oxfmt@0.52.0 --check
  • GIT_MASTER=1 git diff --check origin/main...HEAD

Summary by CodeRabbit

  • New Features

    • Settings → Providers: Install or Repair OpenCode runtime with explicit “Install OpenCode runtime” / “Repair runtime” actions and status UI.
    • Runtime bootstrap status and progress shown in the settings panel; actions re-check runtime health when complete.
    • Native API/transport now supports fetching status, bootstrapping, and repairing the runtime.
  • Documentation

    • Added runbooks, architecture notes, ADR, and a design/plan for WSL OpenCode runtime bootstrap and operation.

@coderabbitai

coderabbitai Bot commented Jun 12, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

This PR implements a complete WSL-specific OpenCode runtime bootstrap system that enables Settings-driven installation and repair of a loopback jcode-opencode.service. It spans contract definitions, deterministic server-side detection and orchestration logic, WS-RPC integration with owner-only authorization, web Native API bridge and UI components, and comprehensive documentation across architecture, runbooks, and design specs.

Changes

WSL OpenCode Runtime Bootstrap

Layer / File(s) Summary
Contract and schema foundation
packages/contracts/src/providerDiscovery.ts, packages/contracts/src/ipc.ts, packages/contracts/src/ws.ts, packages/contracts/src/rpc.ts, packages/contracts/src/rpc.test.ts, packages/contracts/src/ws.test.ts
Adds bootstrap schema types (ProviderRuntimeBootstrapSnapshot, ProviderRuntimeBootstrapInput, OpenCodeRuntimeBootstrapState), native API method signatures, WebSocket RPC method constants and request/response mappings, RPC contract wrappers, and corresponding encode/decode tests.
Pure server bootstrap module
apps/server/src/provider/openCodeRuntimeBootstrap.ts, apps/server/src/provider/openCodeRuntimeBootstrap.test.ts
Implements detection of bootstrap status via probe conditions (WSL environment, systemd, port availability, service/binary presence, runtime reachability), rendering of systemd service units and start scripts with proper escaping/quoting, bootstrap path construction, runtime profile creation/upsert, message credential redaction, and orchestration entry points. Comprehensive test suite validates all exported constants, status outcomes, file rendering, profile behavior, and adapter integration with expected call ordering.
Server orchestration and RPC wiring
apps/server/src/wsRpc.ts
Extends WS-RPC layer with helper functions (execFileText, commandSucceeds, isLoopbackPortAvailable), a full WSL bootstrap adapter (binary resolution from config/PATH, smoke-test connection, systemd/service probing, runtime directory creation, file writing with chmod, systemctl operations), owner-only authorization guard, and RPC method handlers for status/bootstrap/repair with settings profile update integration.
Web native API bridge
apps/web/src/wsNativeApi.ts
Adds three native API methods that forward getRuntimeBootstrapStatus, bootstrapRuntime, and repairRuntime requests to the corresponding WebSocket RPC endpoints.
Settings panel UI integration
apps/web/src/components/OpenCodeRuntimeSettingsPanel.tsx, apps/web/src/components/OpenCodeRuntimeSettingsPanel.browser.tsx
Updates OpenCode runtime settings panel to track and display bootstrap status alongside health checks; adds install/repair/check button rendering based on bootstrap state, concurrent health/status fetching on mount, async bootstrap handlers with error toasts and forced health refresh, and comprehensive browser tests covering unsupported/not-installed/error states with expected button/API call sequences.
Architecture and invariant documentation
docs/architecture/provider-runtime.md, docs/adr/0007-parallel-windows-wsl-backend-routing.md
Clarifies provider runtime boundaries by adding the OpenCode WSL bootstrap module reference, expands invariant guidance on output source differentiation and settings vs. server ownership, introduces "Settings-Owned Actions, Server-Owned Effects" section documenting loopback-only profile behavior and narrow scope, and defines ADR scope distinction from Windows installer work.
Operational runbooks and implementation guidance
docs/runbooks/README.md, docs/runbooks/local-deploy.md, docs/runbooks/local-opencode-runtime.md, docs/runbooks/update-local-stable-jcode.md, docs/superpowers/specs/2026-06-11-wsl-opencode-runtime-bootstrap-design.md, docs/superpowers/plans/2026-06-11-wsl-opencode-runtime-bootstrap.md
Adds complete runbook documentation for local deployment separation, WSL OpenCode runtime service operation (two-service topology, settings bootstrap flow, health checks, repair/rollback, troubleshooting), stable service guidance with OpenCode upgrade risk checklist; provides implementation plan with task enumeration and acceptance criteria; includes design specification for WSL installer UX, service/profile/health wiring, RPC contract shape, and security/privacy constraints.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Suggested labels

vouch:trusted, size:XXL

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The PR title 'Add WSL OpenCode runtime bootstrap' clearly and concisely summarizes the main change: introducing WSL-specific OpenCode runtime bootstrap functionality.
Description check ✅ Passed The PR description covers all required template sections: Summary (changes listed), Why (implicit through summary), Validation (comprehensive test plan provided), and confirmation of no secrets/artifacts.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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

@github-actions github-actions Bot added size:XXL vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. labels Jun 12, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 6

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@apps/server/src/provider/openCodeRuntimeBootstrap.ts`:
- Around line 284-289: The redactBootstrapMessage function currently mangles the
key name for client_secret; update its replacement so the key is preserved like
the token/password rule. In redactBootstrapMessage, change the client_secret
replace call (the regex matching (client_secret)=([^\s&]+)) to replace with the
original key and a redacted value (e.g., use the capture group to produce
"client_secret=<redacted>" or "$1=<redacted>") so the output pattern is
consistent with the token/password replacement and tests continue to remove
secrets.
- Around line 157-177: The final return that builds a "ready" snapshot is
unreachable because input.profileReachable is already handled earlier; remove
the redundant return block that constructs the "ready" snapshot (the snapshot
call referencing JCODE_OPENCODE_SERVICE_NAME, binaryPath, serverUrl, profileId
WSL_OPENCODE_PROFILE_ID and checkedAt input.now) so only the error branch and
any intended earlier ready return remain; ensure there are no leftover
references to that removed block in openCodeRuntimeBootstrap (check usages
around input.profileReachable and the snapshot helper).

In `@docs/runbooks/local-opencode-runtime.md`:
- Around line 145-162: The docs disagree on the generated helper script
location: update the design spec
(docs/superpowers/specs/2026-06-11-wsl-opencode-runtime-bootstrap-design.md) and
the implementation plan
(docs/superpowers/plans/2026-06-11-wsl-opencode-runtime-bootstrap.md) to match
the runbook canonical XDG path
(~/.local/share/jcode/runtime/opencode/jcode-opencode-start) or alternatively
change the runbook table row "OpenCode helper script" to the legacy
~/.local/bin/jcode-opencode-start—pick one canonical value and make the three
files consistent; specifically modify the string literal for the helper path in
each doc and adjust the explanatory note about legacy layouts so all three
documents (design, plan, runbook) state the same generated helper path and
rationale.

In `@docs/superpowers/plans/2026-06-11-wsl-opencode-runtime-bootstrap.md`:
- Around line 338-339: The test stub currently sets startScriptPath to the
legacy "/home/alice/.local/bin/jcode-opencode-start"; update the stub and any
related expectations to the XDG-based canonical path used by the Settings
bootstrap: "~/.local/share/jcode/runtime/opencode/jcode-opencode-start". Locate
the occurrence by searching for startScriptPath in the test stub and change its
value and any assertions that reference the old path to the new
Settings-generated path so tests align with the runbook and design spec.

In `@docs/superpowers/specs/2026-06-11-wsl-opencode-runtime-bootstrap-design.md`:
- Around line 129-133: Update the "Suggested generated artifacts" entry that
currently lists "~/.local/bin/jcode-opencode-start" so it uses the XDG-based
helper path "~/.local/share/jcode/runtime/opencode/jcode-opencode-start" and add
a brief note that this differs from older manual deployments which may have used
"~/.local/bin/jcode-opencode-start" as a legacy operator-chosen layout; make
sure the "~/.config/systemd/user/jcode-opencode.service" line remains unchanged
and that the spec text references the Settings bootstrap behavior documented
elsewhere.

In `@packages/contracts/src/providerDiscovery.ts`:
- Line 615: Replace the strict literal schema on serviceName with a more
flexible trimmed non-empty string: change the field currently declared as
serviceName: Schema.optional(Schema.Literal("jcode-opencode.service")) to use
the TrimmedNonEmptyString schema (or an equivalent Schema.String with
trim/length validation) so it no longer hardcodes the "jcode-opencode.service"
literal; update references to the symbol serviceName and keep optional
semantics, or if literal enforcement is intentional, add a comment referencing
JCODE_OPENCODE_SERVICE_NAME to document the invariant instead of changing
behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: d32458ac-cf39-4a05-824c-12cc617d45fa

📥 Commits

Reviewing files that changed from the base of the PR and between 7def666 and ea4fffa.

📒 Files selected for processing (20)
  • apps/server/src/provider/openCodeRuntimeBootstrap.test.ts
  • apps/server/src/provider/openCodeRuntimeBootstrap.ts
  • apps/server/src/wsRpc.ts
  • apps/web/src/components/OpenCodeRuntimeSettingsPanel.browser.tsx
  • apps/web/src/components/OpenCodeRuntimeSettingsPanel.tsx
  • apps/web/src/wsNativeApi.ts
  • docs/adr/0007-parallel-windows-wsl-backend-routing.md
  • docs/architecture/provider-runtime.md
  • docs/runbooks/README.md
  • docs/runbooks/local-deploy.md
  • docs/runbooks/local-opencode-runtime.md
  • docs/runbooks/update-local-stable-jcode.md
  • docs/superpowers/plans/2026-06-11-wsl-opencode-runtime-bootstrap.md
  • docs/superpowers/specs/2026-06-11-wsl-opencode-runtime-bootstrap-design.md
  • packages/contracts/src/ipc.ts
  • packages/contracts/src/providerDiscovery.ts
  • packages/contracts/src/rpc.test.ts
  • packages/contracts/src/rpc.ts
  • packages/contracts/src/ws.test.ts
  • packages/contracts/src/ws.ts

Comment thread apps/server/src/provider/openCodeRuntimeBootstrap.ts Outdated
Comment thread apps/server/src/provider/openCodeRuntimeBootstrap.ts
Comment thread docs/runbooks/local-opencode-runtime.md
Comment thread docs/superpowers/plans/2026-06-11-wsl-opencode-runtime-bootstrap.md Outdated
Comment thread packages/contracts/src/providerDiscovery.ts Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
docs/superpowers/plans/2026-06-11-wsl-opencode-runtime-bootstrap.md (1)

106-106: ⚠️ Potential issue | 🟠 Major

Document or replace the snip wrapper (and clarify GIT_MASTER=1)

  • safe-run is documented in docs/testing/strategy.md and enforced by scripts/run-vitest-browser.mjs (refuses to run browser tests without safe-run bounds unless JCODE_BROWSER_TEST_SAFE_RUN=0).
  • snip is referenced throughout this plan (e.g., the snip bun run --cwd packages/contracts test src/ws.test.ts command), but there’s no in-repo definition or documentation explaining what snip is or how to install/enable it—contributors can’t reliably execute these steps from repo docs alone.
  • GIT_MASTER=1 is mentioned in plan commands/checklists, but there’s no repo documentation describing what it does or where it’s implemented.

Either (1) add a short “How to use snip” section in the relevant dev-setup/runbooks doc, plus where snip comes from, and document GIT_MASTER, or (2) replace snip ... with standard bun run ... equivalents in this plan.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@docs/superpowers/plans/2026-06-11-wsl-opencode-runtime-bootstrap.md` at line
106, Replace or document the undocumented "snip" wrapper used in the plan and
explicitly document the GIT_MASTER=1 env var: either (A) replace occurrences
like the command string "snip bun run --cwd packages/contracts test
src/ws.test.ts" with the equivalent standard invocation ("bun run ...")
throughout the plan, or (B) add a short "How to use snip" subsection in the
dev-runbooks (referencing docs/testing/strategy.md and
scripts/run-vitest-browser.mjs) that explains where snip is provided, how to
install/enable it, and any syntax, and also add a note that documents the
purpose and expected behavior of the GIT_MASTER=1 environment variable and where
it is implemented so contributors can run the steps reliably.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@docs/superpowers/plans/2026-06-11-wsl-opencode-runtime-bootstrap.md`:
- Line 106: Replace or document the undocumented "snip" wrapper used in the plan
and explicitly document the GIT_MASTER=1 env var: either (A) replace occurrences
like the command string "snip bun run --cwd packages/contracts test
src/ws.test.ts" with the equivalent standard invocation ("bun run ...")
throughout the plan, or (B) add a short "How to use snip" subsection in the
dev-runbooks (referencing docs/testing/strategy.md and
scripts/run-vitest-browser.mjs) that explains where snip is provided, how to
install/enable it, and any syntax, and also add a note that documents the
purpose and expected behavior of the GIT_MASTER=1 environment variable and where
it is implemented so contributors can run the steps reliably.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: a1fc2f68-62a1-492a-b2bd-cd7280f237d2

📥 Commits

Reviewing files that changed from the base of the PR and between ea4fffa and 45e63a6.

📒 Files selected for processing (6)
  • apps/server/src/provider/openCodeRuntimeBootstrap.test.ts
  • apps/server/src/provider/openCodeRuntimeBootstrap.ts
  • docs/superpowers/plans/2026-06-11-wsl-opencode-runtime-bootstrap.md
  • docs/superpowers/specs/2026-06-11-wsl-opencode-runtime-bootstrap-design.md
  • packages/contracts/src/providerDiscovery.ts
  • packages/contracts/src/rpc.test.ts

@Jay1 Jay1 merged commit 91bf26a into main Jun 12, 2026
8 checks passed
@Jay1 Jay1 deleted the jcode/document-opencode-services branch June 12, 2026 01:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XXL vouch:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant