Repository navigation
fix(opencode2): publish a local build's own AI SDK entry - #202
Conversation
[Medium impact] The reviewed changes appear safe to merge; no actionable issue was found. SummaryOpenCode 2.x now publishes a verified local build's own AI SDK entry instead of the npm package.
No actionable issues found in the supplied changes at
|
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
a4a2bc8 to
bc3f44e
Compare
|
@adonm, could you retest #185 on |
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.
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-providerunlessCURSOR_OPENCODE2_DEV_ENTRYwas exported before the daemon started. Oursdkhook 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:CURSOR_OPENCODE2_DEV_ENTRY, unchanged.CURSOR_OPENCODE2_USE_LOCAL_DIST=0: the npm package.dist/index.jswhen it verifies: after resolving symlinks the module is outsidenode_modules,../index.jsis a file, and the nearestpackage.jsonis namedcursor-opencode-providerand declares that file as its root entry.aisdk:cursor-opencode-provider: registry installs, source runs and unverified layouts.The
sdkhook, credential resolution and the catalog refresh from #200 are unchanged. OpenCode 1.x is unaffected: the classic plugin already registers its own siblingindex.js(MODULE_URLinsrc/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.tsremoved its temp root while the job was still finishing its writes there, which failed the TMPDIR leftover check on macOS. It now callsstopProcessesUsing(root)first. The hunk is identical in both PRs, so the second to merge merges it cleanly.Verification
test/opencode2-aisdk-package.test.ts): built checkout with spaces in its path, symlinked checkout, checkout linked into an app'snode_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.env -i, private home, XDG, config and database, a seeded model cache, HTTPS pointed at a closed local port, no credentials):provider.listpublishes the build's realdist/index.jswhen the plugin is loaded through a symlinked path with spaces.CURSOR_OPENCODE2_USE_LOCAL_DIST=0givesaisdk:cursor-opencode-provider, andCURSOR_OPENCODE2_DEV_ENTRYwins over both.sdkhook dropped by a harness wrapper, the host imported the instrumented fixture'sdist/index.jsand called itscreateCursor. No npm install happened, and the turn stopped at the missing credential inside the fixture's own language model.dist/index.js, and the turn stopped at the integration credential check (src/opencode2/integration.ts).bun run typecheck,bun run buildandbun testonmainat 3dc9202, macOS: 3651 pass, 9 skip, 0 fail across 134 files.