Skip to content

feat(registry): Add OCX profile preservation for worktrees#80

Open
kdcokenny wants to merge 3 commits intomainfrom
feat/ocx-aware-worktree
Open

feat(registry): Add OCX profile preservation for worktrees#80
kdcokenny wants to merge 3 commits intomainfrom
feat/ocx-aware-worktree

Conversation

@kdcokenny
Copy link
Owner

@kdcokenny kdcokenny commented Jan 22, 2026

Summary

When OpenCode is launched via ocx opencode -p <profile>, the worktree plugin now automatically preserves the profile context when spawning new worktrees.

Changes

OCX CLI (packages/cli/src/commands/opencode.ts)

  • Added resolveOcxBin() helper to find OCX binary path
  • Added environment variables when spawning OpenCode:
    • OCX_CONTEXT=1 - Marker that OCX launched this session
    • OCX_BIN=<path> - Absolute path to OCX binary
    • OCX_PROFILE=<name> - Resolved effective profile

Worktree Plugin (workers/kdco-registry/files/plugin/worktree.ts, .opencode/plugin/worktree.ts)

  • Added parseOcxContext() to detect OCX context from env vars
  • Added buildWorktreeCommand() to generate correct spawn command
  • Proper shell escaping with quoted values for paths with spaces
  • Fails loud if OCX context detected but binary missing

Documentation

  • Updated AGENTS.md with new env vars and "Worktree Profile Preservation" section
  • Updated facades/opencode-worktree/README.md with "OCX Profile Support" section

Behavior

Launch Command Worktree Spawns
opencode opencode --session <id>
ocx opencode ocx opencode --session <id>
ocx opencode -p work ocx opencode -p work --session <id>

Multiple simultaneous sessions with different profiles work independently (env vars are process-scoped).

Testing

  • Code review passed
  • Shell escaping verified (paths with spaces, injection prevention)
  • Philosophy compliance (5 Laws) verified
  • Manual testing pending

Summary by cubic

Preserves OCX profile context when spawning new worktrees. If you launched OpenCode via ocx opencode -p , worktrees now start with the same profile using the OCX binary.

  • New Features
    • Detects OCX context via env vars: OCX_CONTEXT, OCX_BIN, OCX_PROFILE.
    • Builds worktree argv and applies platform-specific shell escaping (bash, Windows batch); spawns “ocx opencode -p --session ” or “opencode --session ” when not under OCX.
    • CLI sets OCX context envs; fails loudly if OCX_BIN cannot be resolved. Documentation updated to cover profile preservation.

Written for commit a6b7c7e. Summary will update on new commits.

When OpenCode is launched via `ocx opencode -p <profile>`, the worktree
plugin now automatically preserves the profile context when spawning
new worktrees.

Changes:
- Add OCX_CONTEXT, OCX_BIN, OCX_PROFILE env vars to ocx opencode command
- Add parseOcxContext() and buildWorktreeCommand() helpers to worktree plugin
- Proper shell escaping with quoted values for safety
- Fail loud if OCX context detected but binary missing

This ensures profile settings, instructions, and configuration follow
users into worktrees when using OCX.
@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Jan 22, 2026

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
ocx a6b7c7e Jan 22 2026, 06:11 PM

@kdcokenny kdcokenny changed the title feat(worktree): add OCX profile preservation for worktrees feat(worktree): Add OCX profile preservation for worktrees Jan 22, 2026
@kdcokenny kdcokenny changed the title feat(worktree): Add OCX profile preservation for worktrees feat(registry/worktrees): Add OCX profile preservation for worktrees Jan 22, 2026
@kdcokenny kdcokenny changed the title feat(registry/worktrees): Add OCX profile preservation for worktrees feat(registry): Add OCX profile preservation for worktrees Jan 22, 2026
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.

1 issue found across 5 files

Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="workers/kdco-registry/files/plugin/worktree.ts">

<violation number="1" location="workers/kdco-registry/files/plugin/worktree.ts:84">
P2: Double-escaping issue: values are pre-escaped with `escapeBash()` and quoted here, but `terminal.ts` will escape the entire command string again. When the result is placed in a bash script in an unquoted context, the escaped quotes (`\"`) don't prevent word splitting on spaces. Paths or profile names with spaces will break.

Consider removing the escaping here and letting the terminal code handle it, or using single quotes which survive the transformation:</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

@codecov
Copy link

codecov bot commented Jan 22, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 53.60%. Comparing base (aaa67a2) to head (a6b7c7e).
⚠️ Report is 1 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##             main      #80   +/-   ##
=======================================
  Coverage   53.60%   53.60%           
=======================================
  Files          36       36           
  Lines        2722     2722           
=======================================
  Hits         1459     1459           
  Misses       1263     1263           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

- Change from command string to argv array for spawn commands
- Add argvToBashCommand() and argvToBatchCommand() with platform-specific escaping
- Fix Windows batch escaping: reject newlines, escape embedded quotes
- Add null byte validation for bash arguments
- Trim OCX_PROFILE for consistency
- Remove local .opencode/plugin/worktree.ts (registry is source of truth)
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.

1 issue found across 3 files (changes from recent commits).

Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="workers/kdco-registry/files/plugin/worktree/terminal.ts">

<violation number="1" location="workers/kdco-registry/files/plugin/worktree/terminal.ts:65">
P2: Incorrect escaping for quoted batch arguments. `escapeBatch()` is designed for unquoted contexts (adds `^&`, `^<`, etc.), but here it's applied inside double quotes where metacharacters don't need caret escaping. Only `%` needs escaping as `%%` inside quotes. This will cause arguments containing `&`, `<`, `>`, `|`, or `^` to include incorrect literal caret characters.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

escapeBatch() is for unquoted contexts and adds caret escapes.
Inside double quotes, only % and " need escaping - metacharacters
like &, <, >, |, ^ are already protected by the quotes.
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