CreateSession: send the session directory to OpenCode #266

Closed
opened 2026-07-09 10:20:16 +02:00 by dries · 0 comments
Owner

Parent

#265 — One OpenCode per project: worktree sessions run in-app.

What to build

opencode.Adapter.CreateSession must actually send the session's
directory to OpenCode so a single project instance can create a
session rooted at a worktree (an external directory). Today it uses
req.Directory only for port discovery and POSTs /session with a
literal {} body, so a session's directory always equals the process's
launch cwd.

  • POST /session carries the directory via the x-opencode-directory
    header (URL-encoded) or ?directory= query param. (Verified on
    OpenCode 1.17.10: a single instance created a session rooted at
    /private/tmp this way, and the returned session reported the correct
    directory.)
  • The caller can supply the already-known port (from the project
    instance) so CreateSession does not re-run an lsof scan for worktree
    sessions. Keep the platforms.CreateSessionRequest change minimal —
    thread the known port rather than adding a second discovery.
  • Existing same-directory behaviour is unchanged when no explicit port /
    external directory is provided.

Acceptance criteria

  • CreateSession sends the requested directory to OpenCode on
    POST /session (query or header).
  • A session can be created rooted at a directory other than the
    opencode process launch cwd, and the returned session reports that
    directory.
  • When a known port is provided, CreateSession does not trigger a
    fresh lsof scan.
  • Adapter-level tests against a fake OpenCode HTTP server cover the
    directory-sending branch and the provided-port branch. Prior art:
    TestCreateSessionPinsReturnedSessionPort,
    TestCreateSession_TitleIsSetAfterCreation.
  • go test ./... && go vet ./... green; coverage delta ≥ 0.

Blocked by

  • None — can start immediately.
## Parent #265 — One OpenCode per project: worktree sessions run in-app. ## What to build `opencode.Adapter.CreateSession` must actually send the session's `directory` to OpenCode so a single project instance can create a session rooted at a worktree (an external directory). Today it uses `req.Directory` **only for port discovery** and POSTs `/session` with a literal `{}` body, so a session's directory always equals the process's launch cwd. - `POST /session` carries the directory via the `x-opencode-directory` header (URL-encoded) or `?directory=` query param. (Verified on OpenCode 1.17.10: a single instance created a session rooted at `/private/tmp` this way, and the returned session reported the correct `directory`.) - The caller can supply the already-known port (from the project instance) so `CreateSession` does not re-run an lsof scan for worktree sessions. Keep the `platforms.CreateSessionRequest` change minimal — thread the known port rather than adding a second discovery. - Existing same-directory behaviour is unchanged when no explicit port / external directory is provided. ## Acceptance criteria - [ ] `CreateSession` sends the requested directory to OpenCode on `POST /session` (query or header). - [ ] A session can be created rooted at a directory *other* than the opencode process launch cwd, and the returned session reports that directory. - [ ] When a known port is provided, `CreateSession` does not trigger a fresh lsof scan. - [ ] Adapter-level tests against a fake OpenCode HTTP server cover the directory-sending branch and the provided-port branch. Prior art: `TestCreateSessionPinsReturnedSessionPort`, `TestCreateSession_TitleIsSetAfterCreation`. - [ ] `go test ./... && go vet ./...` green; coverage delta ≥ 0. ## Blocked by - None — can start immediately.
dries closed this issue 2026-07-09 14:29:36 +02:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
dries/ocman#266
No description provided.