Skip to content

fix(opencode2): publish a local build's own AI SDK entry - #202

Merged
oakimov merged 1 commit into
mainfrom
fix/opencode2-local-aisdk-entry
Nov 23, 2026
Merged

oakimov merged 1 commit into
mainfrom
fix/opencode2-local-aisdk-entry

Conversation

@oakimov

@oakimov oakimov commented Nov 20, 2026

Copy link
Copy Markdown
Owner

Closes #185

@adonm, thanks for the report and the patch sketch in #185.

Problem

A plugin loaded from a local build still registered aisdk:cursor-opencode-provider unless CURSOR_OPENCODE2_DEV_ENTRY was exported before the daemon started. Our sdk hook normally supplies the model. When it does not, OpenCode's own SDK loader installs the published package and runs it against the local plugin.

Change

resolveAiSdkPackageSpec (src/opencode2/catalog.ts) picks, in order:

  1. CURSOR_OPENCODE2_DEV_ENTRY, unchanged.
  2. CURSOR_OPENCODE2_USE_LOCAL_DIST=0: the npm package.
  3. The build's own dist/index.js when it verifies: after resolving symlinks the module is outside node_modules, ../index.js is a file, and the nearest package.json is named cursor-opencode-provider and declares that file as its root entry.
  4. Otherwise aisdk:cursor-opencode-provider: registry installs, source runs and unverified layouts.

The sdk hook, credential resolution and the catalog refresh from #200 are unchanged. OpenCode 1.x is unaffected: the classic plugin already registers its own sibling index.js (MODULE_URL in src/plugin.ts). No prompt-cache surface is touched.

Docs: README environment table and troubleshooting row, the 2.x guide's local clone section (now #from-a-local-clone), the 2.x lessons, Unreleased changelog.

Test cleanup from #197

Same test-only fix as #201: the managed-spawn adapter test in test/shell-timeout.test.ts removed its temp root while the job was still finishing its writes there, which failed the TMPDIR leftover check on macOS. It now calls stopProcessesUsing(root) first. The hunk is identical in both PRs, so the second to merge merges it cleanly.

Verification

  • Resolver (test/opencode2-aisdk-package.test.ts): built checkout with spaces in its path, symlinked checkout, checkout linked into an app's node_modules, OpenCode's npm cache and a pnpm-style store, source run next to a build, manifest variants, missing and unverified entries, non-file module URLs, and both variables.
  • Native OpenCode 2.3.2 in an isolated instance (env -i, private home, XDG, config and database, a seeded model cache, HTTPS pointed at a closed local port, no credentials):
    • provider.list publishes the build's real dist/index.js when the plugin is loaded through a symlinked path with spaces. CURSOR_OPENCODE2_USE_LOCAL_DIST=0 gives aisdk:cursor-opencode-provider, and CURSOR_OPENCODE2_DEV_ENTRY wins over both.
    • With the plugin's sdk hook dropped by a harness wrapper, the host imported the instrumented fixture's dist/index.js and called its createCursor. No npm install happened, and the turn stopped at the missing credential inside the fixture's own language model.
    • With the hook in place, the host never imported dist/index.js, and the turn stopped at the integration credential check (src/opencode2/integration.ts).
  • bun run typecheck, bun run build and bun test on main at 3dc9202, macOS: 3651 pass, 9 skip, 0 fail across 134 files.

@greptile-apps

greptile-apps Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The reviewed changes appear safe to merge; no actionable issue was found.

Summary

OpenCode 2.x now publishes a verified local build's own AI SDK entry instead of the npm package.

  • Local OpenCode builds now publish their own SDK entry.
  • Managed-spawn tests stop writers before removing their temporary roots.

No actionable issues found in the supplied changes at bc3f44e9cc970220019d19a8b76c9d3da31447d3. The previous review commit is not an ancestor, so this review covered the full PR. No previous review threads were supplied. Review used source checks on Linux; tests and native OpenCode were not run.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Choose AI SDK package] --> B{Explicit dev entry?}
  B -->|Yes| C[Publish explicit file URL]
  B -->|No| D{Local dist disabled?}
  D -->|Yes| E[Publish npm package]
  D -->|No| F{Local build verified?}
  F -->|Yes| G[Publish own dist/index.js]
  F -->|No| E
Loading

Reviews (2) · Last reviewed commit: "fix(opencode2): publish a local build's ..." · Reviewed by Greptile

@codecov

codecov Bot commented Nov 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

A plugin loaded from a local build registered aisdk:cursor-opencode-provider
unless CURSOR_OPENCODE2_DEV_ENTRY was exported before the daemon started.
When our sdk hook does not supply the model, OpenCode's own SDK loader
then installed the published package and ran it against the local plugin.

resolveAiSdkPackageSpec now picks, in order: CURSOR_OPENCODE2_DEV_ENTRY;
the npm package with CURSOR_OPENCODE2_USE_LOCAL_DIST=0; the build's own
dist/index.js when the module is outside node_modules after resolving
symlinks and the nearest package.json, named cursor-opencode-provider,
declares that file as its root entry; otherwise the npm package.
Registry installs and source runs keep the npm package.

The managed-spawn adapter test now stops the job's processes before it
removes its temp root. It removed the root once `done` existed while
the job was still writing there, which left files behind on macOS.

Closes #185
@oakimov
oakimov force-pushed the fix/opencode2-local-aisdk-entry branch from a4a2bc8 to bc3f44e Compare November 20, 2026 15:19

oakimov commented Nov 20, 2026

Copy link
Copy Markdown
Owner Author

@adonm, could you retest #185 on bc3f44e with your local OpenCode 2.x setup? Rebuild the checkout, start a fresh OpenCode process with CURSOR_OPENCODE2_DEV_ENTRY and CURSOR_OPENCODE2_USE_LOCAL_DIST unset, and check opencode --standalone api provider.list. The cursor provider’s package should point to your build’s dist/index.js via an aisdk:file:// URL. With CURSOR_OPENCODE2_USE_LOCAL_DIST=0, it should report aisdk:cursor-opencode-provider. Please share your OpenCode version and which entry it selected in each case.

@oakimov
oakimov merged commit d267c6a into main Nov 23, 2026
11 checks passed
adonm added a commit to adonm/cursor-opencode-provider that referenced this pull request Nov 24, 2026
Adopt upstream's oakimov#199 pricing table, oakimov#200 in-place catalog refresh,
oakimov#201 CURSOR_PROGRESS_CONTINUATION opt-out, and oakimov#202 local AI SDK entry.
The fork's earlier ports (deb1787, 2bbab84, 9bf27b0 gate) are dropped
where upstream now covers the same ground.

Keep the fork-only pieces upstream still lacks: the seven-day conversation
snapshot default with fixed 24 h .tmp cleanup and resolver-derived test
ages, scripts/build-atomic.sh, scripts/sync-upstream.sh, the stale-dist
gate, and test/updater-build.test.ts.

Retire the last topic branch: nothing on perf/cache-ttl-and-lean-runtime
remains that upstream or this merge does not already cover, so TOPICS is
empty and the updater tests seed a synthetic topic into the copied script.
@oakimov
oakimov deleted the fix/opencode2-local-aisdk-entry branch November 29, 2026 13:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A built local checkout still publishes the npm AI SDK package unless CURSOR_OPENCODE2_DEV_ENTRY is set on the daemon

1 participant