Repository navigation
refactor(opencode-plugin): rewrite on experimental workspace adaptor API - #4504
jamesmurdza wants to merge 12 commits into
Conversation
|
View your CI Pipeline Execution ↗ for commit fb817fb
☁️ Nx Cloud last updated this comment at |
There was a problem hiding this comment.
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.
|
@jamesmurdza can you make sure that checks pass please |
e6fdfde to
35b14fd
Compare
|
Hey @jamesmurdza , just took a look. Few questions:
|
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 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. |
|
during workspace creation, sandbox command stdout is written directly to the local tui. i saw the remote 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 Screenshot.2026-05-01.at.02.16.52.mp4 |
|
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]>
a3f7ee9 to
085b817
Compare
fb817fb to
0ec09c6
Compare
0ec09c6 to
085b817
Compare
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]>
…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]>
2c15a7f to
b40f732
Compare
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
experimental_workspace.register()API to register Daytona as a workspace type.opencode serveinside.nohupguidance for long-running servers) via theinstructionsfield inopencode.json.opencode-to namespace them from other sandboxes in the same Daytona account.OPENCODE_AUTH_CONTENT,OPENCODE_WORKSPACE_ID,OPENCODE_EXPERIMENTAL_WORKSPACES,OTEL_EXPORTER_OTLP_*) into the sandbox. Uses a localWorkspaceAdaptorWithEnvtype override because the published@opencode-ai/plugintype is missing theenvparam — tracked in anomalyco/opencode#23233; the override can be deleted once the upstream type is republished.Features removed
To do
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/