Skip to content
This repository was archived by the owner on Oct 3, 2026. It is now read-only.

refactor(opencode-plugin): rewrite on experimental workspace adaptor API - #4504

Draft
jamesmurdza wants to merge 12 commits into
daytonaio:mainfrom
jamesmurdza:feat/daytona-opencode-rewrite
Draft

jamesmurdza wants to merge 12 commits into
daytonaio:mainfrom
jamesmurdza:feat/daytona-opencode-rewrite

Conversation

@jamesmurdza

@jamesmurdza jamesmurdza commented Apr 18, 2026 •

Copy link
Copy Markdown
Contributor

Description

Rewrites the Daytona OpenCode plugin from a tool-based architecture to the new experimental workspace adaptor API. Simplifies from ~1500 lines (25+ files) to ~250 lines (2 files).

References

Changes

  • Uses experimental_workspace.register() API to register Daytona as a workspace type.
  • Provisions sandboxes, uploads the host repo as a tarball, installs and starts opencode serve inside.
  • Adds a Daytona-specific instructions file (preview URL format, nohup guidance for long-running servers) via the instructions field in opencode.json.
  • Prefixes sandbox names with opencode- to namespace them from other sandboxes in the same Daytona account.
  • Forwards the env vars opencode hands the adaptor (OPENCODE_AUTH_CONTENT, OPENCODE_WORKSPACE_ID, OPENCODE_EXPERIMENTAL_WORKSPACES, OTEL_EXPORTER_OTLP_*) into the sandbox. Uses a local WorkspaceAdaptorWithEnv type override because the published @opencode-ai/plugin type is missing the env param — tracked in anomalyco/opencode#23233; the override can be deleted once the upstream type is republished.

Features removed

  • Bidirectional file sync — the repo is uploaded once at creation, no ongoing sync.
  • Custom tools (file operations, git, shell) — opencode handles these via the remote-proxy target URL.
  • Session management — delegated to opencode.
  • Git branch syncing — no automatic sync between local and sandbox.

To do

  • Update guides
  • Test for durability

Documentation

  • This change requires a documentation update
  • I have made corresponding changes to the documentation

Related Issue(s)

This PR incorporates changes from both:

This allows Bun (the OpenCode runtime) to load the Daytona SDK directly from source during development.

Screenshots

My.Movie.17.-.HD.720p.online-video-cutter.com.mp4

Notes

To test locally without building Daytona, copy the plugin directory instead of symlinking:

cp -r /path/to/daytona/libs/opencode-plugin/.opencode/plugin ~/.opencode/

@claude claude 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.

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@nx-cloud

nx-cloud Bot commented Apr 18, 2026 •

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit fb817fb

Command Status Duration Result
nx e2e:cleanup daytona-e2e ✅ Succeeded <1s View ↗
nx run sdk-typescript:test:runtime ✅ Succeeded 3m 31s View ↗
nx run-many --target=test:e2e --all --nxBail=true ✅ Succeeded 7m 50s View ↗
nx e2e daytona-e2e ✅ Succeeded 1m 7s View ↗
nx run-many --target=build --projects=api,runne... ✅ Succeeded 2m 6s View ↗

☁️ Nx Cloud last updated this comment at 2026-05-13 09:36:29 UTC

@cubic-dev-ai cubic-dev-ai 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.

3 issues found across 29 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="libs/opencode-plugin/.opencode/plugin/daytona/index.ts">

<violation number="1" location="libs/opencode-plugin/.opencode/plugin/daytona/index.ts:127">
P1: `create` assumes `env` is always present, but the adaptor is registered against the published `WorkspaceAdaptor` type and the code comment says that type omits `env`. If the host invokes `create` with only the config argument, `toEnvVars(env)` will throw and workspace creation fails.</violation>

<violation number="2" location="libs/opencode-plugin/.opencode/plugin/daytona/index.ts:196">
P1: Failed workspace creation can leak a Daytona sandbox because the error path never deletes the sandbox after it has been created.</violation>

<violation number="3" location="libs/opencode-plugin/.opencode/plugin/daytona/index.ts:204">
P1: Teardown silently swallows lookup failures, masking real cleanup errors and leaving sandboxes/cache entries behind.</violation>
</file>

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

@Tpuljak

Tpuljak commented Apr 20, 2026

Copy link
Copy Markdown
Member

@jamesmurdza can you make sure that checks pass please

@jamesmurdza

jamesmurdza commented Apr 20, 2026 •

Copy link
Copy Markdown
Contributor Author

@Tpuljak I fixed the CI checks but the plugin isn't getting recognized for me right now. Not sure if it's an OpenCode update or I made a mistake.

@Tpuljak It's working for me now! I can squash the commits to make the DCO check pass.

@jamesmurdza
jamesmurdza force-pushed the feat/daytona-opencode-rewrite branch from e6fdfde to 35b14fd Compare April 21, 2026 00:50
@mislavivanda

Copy link
Copy Markdown
Collaborator

Hey @jamesmurdza , just took a look. Few questions:

  • In the PR description it says that there is no automatic sync between local and sandbox and no ongoing sync after repo upload. Is this true or not? Should this be handled by OpenCode workspaces logic or requires our implementation inside the plugin. Also, I saw that local sync was mentioned in this X post so not sure what is the actual state of this feature. My thought about this is that if these 2 features are not supported anymore we should maybe publish this as a separate package so previous users are not affected.
  • instructions.ts is missing in the README repo structure.
  • Should we wait for them to update the PluginInputWithWorkspace and WorkspaceAdaptorWithEnv(if they haven't already) or we can add them later, just note it.
  • Should we clean the tar after uploading it to sandbox?
  • Would not recommend hardcoding preview URL domain to daytonaproxy01 inside the buildSandboxInstructions since it can change in the future. Recommended way would be to add an argument to buildSandboxInstructions which will receive a result of getPreviewLink call for some random port and figure out the up to date preview URL format.

@jamesmurdza

Copy link
Copy Markdown
Contributor Author

Hey @jamesmurdza , just took a look. Few questions:

  • In the PR description it says that there is no automatic sync between local and sandbox and no ongoing sync after repo upload. Is this true or not? Should this be handled by OpenCode workspaces logic or requires our implementation inside the plugin. Also, I saw that local sync was mentioned in this X post so not sure what is the actual state of this feature. My thought about this is that if these 2 features are not supported anymore we should maybe publish this as a separate package so previous users are not affected.
  • instructions.ts is missing in the README repo structure.
  • Should we wait for them to update the PluginInputWithWorkspace and WorkspaceAdaptorWithEnv(if they haven't already) or we can add them later, just note it.
  • Should we clean the tar after uploading it to sandbox?
  • Would not recommend hardcoding preview URL domain to daytonaproxy01 inside the buildSandboxInstructions since it can change in the future. Recommended way would be to add an argument to buildSandboxInstructions which will receive a result of getPreviewLink call for some random port and figure out the up to date preview URL format.

Thank you @mislavivanda!

I am in favor of deprecating those features in the existing plugin and instead using the effort (of maintaining those) to work with OpenCode to build a solution in their codebase.

In the old plugin, I have a solution which automatically pulls changes from Git, which works great but is very experimental and is still only a one-way sync. (Sandbox-to-desktop)

I've fixed the types in the OpenCode codebase (anomalyco/opencode#23235) and am planning to remove the fix in the plugin. (Tried yesterday but was still getting the old types.)

I'll work on those other fixes.

@mu-hashmi

Copy link
Copy Markdown
Collaborator

@jamesmurdza getting a bug where when I create a workspace on a daytona sandbox it loads, shows the opencode UI for 1 second and then my terminal just goes black. can't ctrl+c either only option is to exit that terminal window.

@jamesmurdza

Copy link
Copy Markdown
Contributor Author

@jamesmurdza getting a bug where when I create a workspace on a daytona sandbox it loads, shows the opencode UI for 1 second and then my terminal just goes black. can't ctrl+c either only option is to exit that terminal window.

@mu-hashmi Is this consistent or sporadic?

@mu-hashmi

Copy link
Copy Markdown
Collaborator

@jamesmurdza getting a bug where when I create a workspace on a daytona sandbox it loads, shows the opencode UI for 1 second and then my terminal just goes black. can't ctrl+c either only option is to exit that terminal window.

@mu-hashmi Is this consistent or sporadic?

Consistent, happened every time I created a Daytona workspace.

@381181295

381181295 commented May 1, 2026 •

Copy link
Copy Markdown

during workspace creation, sandbox command stdout is written directly to the local tui. i saw the remote opencode install banner render over the tui. in the plugin this looks like process.stdout.write(result.result) after sandbox.process.executeCommand(...). suppressing successful command stdout fixed that corruption for me

also experiencing the same blank terminal behavior, blank terminal happens after the workspace is created and healthy. i can verify the daytona sandbox started, remote opencode serve is healthy on port 3096, and the workspace appears in the session list. but selecting that workspace-backed session then blanks the terminal

Screenshot.2026-05-01.at.02.16.52.mp4

@mislavivanda

Copy link
Copy Markdown
Collaborator

@jamesmurdza See that

Hey @jamesmurdza , just took a look. Few questions:

  • In the PR description it says that there is no automatic sync between local and sandbox and no ongoing sync after repo upload. Is this true or not? Should this be handled by OpenCode workspaces logic or requires our implementation inside the plugin. Also, I saw that local sync was mentioned in this X post so not sure what is the actual state of this feature. My thought about this is that if these 2 features are not supported anymore we should maybe publish this as a separate package so previous users are not affected.
  • instructions.ts is missing in the README repo structure.
  • Should we wait for them to update the PluginInputWithWorkspace and WorkspaceAdaptorWithEnv(if they haven't already) or we can add them later, just note it.
  • Should we clean the tar after uploading it to sandbox?
  • Would not recommend hardcoding preview URL domain to daytonaproxy01 inside the buildSandboxInstructions since it can change in the future. Recommended way would be to add an argument to buildSandboxInstructions which will receive a result of getPreviewLink call for some random port and figure out the up to date preview URL format.

Thank you @mislavivanda!
I am in favor of deprecating those features in the existing plugin and instead using the effort (of maintaining those) to work with OpenCode to build a solution in their codebase.
In the old plugin, I have a solution which automatically pulls changes from Git, which works great but is very experimental and is still only a one-way sync. (Sandbox-to-desktop)
I've fixed the types in the OpenCode codebase (anomalyco/opencode#23235) and am planning to remove the fix in the plugin. (Tried yesterday but was still getting the old types.)
I'll work on those other fixes.

@jamesmurdza Okay, see that all items are implemented except the missing instructions.ts in README and preview URL domain hardcoding. Also, please rebase, fix conflicts and squash so that DCO check passes.

jamesmurdza and others added 3 commits May 12, 2026 22:49
Rewrites WithSpan/WithMetric/WithInstrumentation against the standard
ECMAScript decorator signature (value, context) instead of the legacy
TypeScript signature (target, propertyKey, descriptor). Overrides
`experimentalDecorators` and `emitDecoratorMetadata` to `false` in the
SDK's tsconfig so tsc emits standards-compliant decorator code.

Why:
- Modern decorators are the standardized form and TS's default when
  experimentalDecorators is unset. Bun, Deno, and any TS 5+ project
  without the legacy flag use this API.
- Previously the legacy-signature decorators threw at class-load time
  whenever the SDK source was consumed under the modern API (typed
  consumers via the published artifact were unaffected because tsc
  baked legacy semantics into the emitted JS).

Semantic notes:
- The class name attached to spans/metrics is now resolved from
  `this.constructor.name` at call time rather than `target.constructor.name`
  at decoration time. For inherited methods this reports the actual
  instance's class; in the SDK's current usage (no inheritance of
  decorated methods) the resulting string is identical.
- No parameter decorators, property decorators, or `reflect-metadata`
  usage exists in the SDK, so no other call sites need to change.

The rest of the monorepo keeps `experimentalDecorators: true` (NestJS
in apps/api needs it). The override is scoped to this package only.

Signed-off-by: James Murdza <[email protected]>
Splits each mixed import statement into `import type { ... }` for types
and `import { ... }` for runtime values. This is the recommended pattern
under `isolatedModules` (default in modern TS configs): per-file
transpilers like bun, esbuild, and swc can only reliably erase a symbol
when it's marked with `import type`. Without it, the type name leaks
into the emitted JS and ESM linking fails at runtime when the SDK is
consumed from source. `tsc`-compiled consumers of the published npm
artifact are unaffected because whole-program type erasure hides the
issue.

Affects imports from @daytona/api-client, @daytona/toolbox-api-client,
axios, and intra-SDK cross-file imports.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Signed-off-by: James Murdza <[email protected]>
Replaces the previous custom tools/session-manager implementation with a
workspace adaptor that runs opencode inside a Daytona sandbox. Adds a
system-prompt instructions file scoped to Daytona sessions, generates
unique opencode-prefixed sandbox names, and forwards env vars through
workspace create.

Follow-up improvements folded in:
- Drop workspace-API workarounds, import upstream types
- Clean up Daytona sandbox when create() fails partway
- Exclude host .opencode/ from sandbox repo upload
- Clean up repo tarball on sandbox after extraction
- Derive preview URL template from getPreviewLink
- Warn/error clearly when DAYTONA_API_KEY is missing
- Add integration and adapter-registration tests; fix flakiness
- Update README (troubleshooting, migration guide, instructions,
  workspace creation steps, OpenCode 1.14.x requirement, test docs)
- Add bun.lock

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Signed-off-by: James Murdza <[email protected]>
jamesmurdza and others added 2 commits June 1, 2026 13:06
macOS bsdtar embeds Apple extended attributes (e.g. com.apple.provenance)
as LIBARCHIVE.xattr.* pax headers and AppleDouble ._* entries when building
the repo upload tarball. On extraction the sandbox's GNU tar floods stdout
with "Ignoring unknown extended header keyword" warnings and litters the
repo with ._* files.

Pass --no-xattrs and COPYFILE_DISABLE=1 to suppress both. Both are no-ops on
Linux hosts (COPYFILE_DISABLE is macOS-only; --no-xattrs is GNU tar's
default), so the fix stays portable. Adds an optional env passthrough to
spawnAsync to set COPYFILE_DISABLE for the tar invocation.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Add a "Running against a local OpenCode build" subsection explaining how to
test the plugin against a from-source OpenCode checkout: run `bun dev` from
the OpenCode repo root with the test project as a trailing argument. Notes
the JSX-config (jsxImportSource) reason it must run from packages/opencode,
and the "Cannot find module 'react/jsx-dev-runtime'" failure that results
from launching the entry point inside the test project instead.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
jamesmurdza and others added 7 commits June 1, 2026 13:27
…teps

The source-parse and adaptor-registration snippets assumed different cwds
without saying so. Add the cd lines (libs/opencode-plugin and /tmp/myproject)
so each is unambiguous.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The create() run() helper wrote every sandbox command's stdout to the host
terminal, flooding it with the opencode installer's progress bar/banner, tar
output, etc. during workspace creation. Surface command output only on
failure (already captured in the thrown error) so the happy path stays quiet.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The installer's "latest release" lookup hits api.github.com, which is
rate-limited (HTTP 429) and fails with "Failed to fetch version information"
when many sandboxes install in a short window — aborting workspace creation.
Pass VERSION to skip that lookup. Also moves the env vars onto bash (right of
the pipe) where the installer actually reads them, instead of curl.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
File logger to /tmp/daytona-plugin.log tracing each create()/remove()/target()
step, so a stalled or failing step in the experimental-workspace flow is
visible without streaming to the UI.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The sandbox stops servicing new commands while opencode runs its one-time DB
migration on first start, so a health poll issued during that window hangs
indefinitely and never returns — wedging the poll loop, and thus workspace
creation, forever (the TUI shows "Creating…" with no progress) even after the
server is actually healthy.

Wrap each poll (and the final log fetch) in a 5s client-side timeout: a stuck
poll is abandoned, treated as not-ready-yet, and the loop continues. Once the
migration finishes a later poll returns and creation completes normally.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Drives the real OpenCode TUI via tmux (open -> /warp -> select Daytona ->
wait for sandbox -> send a message) against the released opencode binary.

Hard-asserts the plugin's responsibilities: the workspace provisions (sandbox
started, remote /global/health healthy, create() completes without hanging)
and the remote answers (session contains an assistant reply echoing a magic
token). Logs — but does not assert — whether the host TUI renders the reply,
since that depends on OpenCode's experimental-workspace global sync (an
intermittent upstream gap, not this plugin).

Gated on DAYTONA_API_KEY + tmux + a released opencode binary; skipped otherwise.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…them as dead

Idle Daytona sandboxes auto-stop after ~15 min. The workspace global-sync
connects to the sandbox via target() (it dials <url>/global/event), so once a
sandbox paused, that endpoint failed and the host logged a relentless
"failed to connect to global sync" (HTTP 400) storm — which destabilized the
host and broke chat rendering. The sandbox wasn't dead, just paused.

- target(): if the sandbox isn't 'started', resume it (sandbox.start()) and
  relaunch opencode serve (the server process doesn't survive a stop/start),
  then return the preview link. Cache entries carry a short verification TTL so
  bursty target() calls stay fast.
- create(): disable auto-delete (autoDeleteInterval: -1) so a timeout only
  pauses the sandbox (resumable) rather than deleting it (which orphans the
  OpenCode workspace entry and is what actually triggered the 400 storm).
- Factor the server launch + health-wait into ensureServerRunning(), shared by
  create() and target().

Verified live: create -> stop (simulated timeout) -> access resumes the sandbox,
relaunches the server, and /global/health is reachable through the proxy again.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

This branch has not been deployed

No deployments
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants