Skip to content

feat(core): run worktree setup scripts - #44455

Merged
Brendonovich merged 4 commits into
v2from
worktree-setup-script
Aug 25, 2026
Merged

Brendonovich merged 4 commits into
v2from
worktree-setup-script

Conversation

@opencode-agent

@opencode-agent opencode-agent Bot commented Aug 23, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • add a project update API for display metadata and workspace commands, with generated Promise and Effect clients
  • connect desktop project settings to that API so setup scripts, names, and icons can be saved for V2 projects
  • run each project's configured workspace setup script after creating and tracking a worktree
  • execute the script from the new worktree with OPENCODE_WORKTREE_BASE and OPENCODE_WORKTREE_PATH available
  • document the variables in the desktop workspace settings

Checks

  • bun test test/project.test.ts test/worktree.test.ts (packages/core): 32 passed, 1 platform skip
  • bun test test/promise.test.ts -t "project.update" (packages/client)
  • bun typecheck (packages/schema, packages/core, packages/protocol, packages/server, packages/client, packages/app)
  • bun run generate (packages/client)
  • scoped oxlint (no errors; existing warnings remain)

Related: #44151

Requested by: @Brendonovich (Brendan via Slack)

@Enough1122

Copy link
Copy Markdown

AI code review — automated review for reference, author can ignore or act on any point.

Well-rounded implementation: the clear-on-empty-string semantics in Project.update, the OPENCODE_WORKTREE_* env passthrough, and the failure-propagation via AppProcess.requireSuccess are all sensible choices, and test coverage is good. Some points to consider:

  1. Failed setup leaves an orphaned worktree — packages/core/src/worktree.ts:278-289 fails the whole create when the script exits non-zero, but by then the git worktree already exists on disk and nothing removes it, so callers end up with neither a usable worktree nor a clean state. Either roll back (call the existing remove/cleanup path) before rethrowing, or return success plus a setup-status field so the client can decide.

  2. No timeout on the setup run — proc.run(...) at packages/core/src/worktree.ts:278 blocks create until exit; a long-running command (dev server, watcher) hangs worktree creation indefinitely. A generous Effect.timeout (configurable per project) would bound the damage, especially now that failure aborts the request.

  3. icon.url is accepted but silently dropped — UpdateInput allows icon.url (packages/schema/src/project.ts:52-56), but the .set() in packages/core/src/project.ts:159-170 only writes icon_url_override / icon_color; icon_url is never updated, and fromRow will keep returning the stale URL. Either persist it or omit url from the updatable payload/schema.

  4. Catch-all error mapping — packages/server/src/handlers/project.ts:650-657 uses Effect.mapError over the entire error channel, converting any future failure into HTTP 404. Today the channel is just NotFoundError, but Effect.catchTag("Project.NotFoundError", ...) would keep unrelated errors (e.g. DB faults surfaced later) from masquerading as "not found".

Minor:

  • if (command && project) in packages/core/src/worktree.ts:274 — project is implied whenever command is set; simplify to if (command).
  • project-model.ts now relies purely on the project.updated bus event to refresh app state (packages/app/src/settings/workspaces/project-model.ts:43-50); worth confirming every connected client actually receives/publishes that event, otherwise the dialog may close while other views show stale metadata.

# Conflicts:
#	packages/client/test/promise.test.ts
#	packages/core/test/worktree.test.ts
@Brendonovich
Brendonovich merged commit ed582d1 into v2 Aug 25, 2026
6 of 11 checks passed
@Brendonovich
Brendonovich deleted the worktree-setup-script branch August 25, 2026 14:45
jinhuang712 pushed a commit to jinhuang712/opencode that referenced this pull request Sep 26, 2026
Co-authored-by: Brendonovich <[email protected]>
Co-authored-by: Brendonovich <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants