EnsureProjectOpencode: one discover-or-launch host primitive #267
Labels
No labels
backend
bug
chore
duplication
effort:complex
effort:medium
effort:trivial
enhancement
frontend
fullstack
priority:high
ready-for-agent
refactor
security
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
dries/ocman#267
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Parent
#265 — One OpenCode per project: worktree sessions run in-app.
What to build
A new central host capability that is the only code path that
launches opencode: guarantee exactly one opencode instance per project,
rooted at the project's main checkout.
hostsvc.Host:EnsureProjectOpencode(ctx, req) (result, error). Request carries theproject directory (any path inside the repo); result carries the
discovered/launched opencode port (plus resolved repo root + tmux
session name for observability).
running opencode for that repo root; if none, launch exactly one
opencode --port 0in tmux rooted at the main checkout, seeded withOPENCODE_PERMISSION(inline JSON) containing anexternal_directoryallow rule scoped to that project's
.worktrees/<repo>/**root; waitfor the port to become discoverable; return it. Idempotent — a
second call for the same project returns the running instance and
launches nothing.
Host, or a remote'sin-process
Hostvia gRPC), following the existingHost/Router(
ForDir/ForRemote) seam. Add the remote passthrough (clientremoteHostimpl +Serverhandler) using the existingJsonReq/JsonRespenvelope — no protobuf message regeneration.external_directoryrule must be scoped to.worktrees/only;do NOT blanket-allow external directories. It must merge with, not
overwrite, any inherited permission set (composes with #101).
Acceptance criteria
EnsureProjectOpencodeonhostsvc.Host, local impl, and remotegRPC passthrough all present.
OPENCODE_PERMISSIONwith the scoped
external_directoryrule, waits for the port,returns it.
git.ErrNotARepo.seeding, and the non-repo error. Prior art:
internal/tmux/launch_test.go,internal/mcp/launchertests.go test ./... && go vet ./...green; coverage delta ≥ 0.Blocked by