Skip to content

fix(load): a missing dependency names itself, not the default export - #465

Merged
abogartz merged 6 commits into
mainfrom
fix/loose-discovery-load-error
Nov 20, 2026
Merged

abogartz merged 6 commits into
mainfrom
fix/loose-discovery-load-error

Conversation

@abogartz

Copy link
Copy Markdown
Owner

What breaks

A user installs by dropping the plugin into <config>/plugins/<name>/. Loose
discovery reads <config>/plugins/<name>/index.ts and installs nothing, so the
copied directory has no node_modules. The eager zod import at
src/tools/schema.ts:17 then throws while the entry module is being evaluated,
and the host reports:

Error: Plugin must export a default definition with an id and an effect or setup function.

That names an export that is not wrong — src/index.ts:395 exports the V2
definition object and index.ts re-exports it as default. The reader audits a
correct file instead of running the command that fixes it.

Reproduced by copying the shipped file set to a directory with no
node_modules:

$ bun build --target=bun index.ts
17 | import { type ZodTypeAny, z } from "zod";
                                       ^
error: Could not resolve: "zod". Maybe you need to "bun install"?
    at /private/tmp/loose/self-improving-skills/src/tools/schema.ts:17:36

@babel/parser, the other runtime dependency, survives the same situation
because it is a lazy guarded require at src/recall/conflicts.ts:73. Zod is
the only eager one.

What this changes

index.ts imports src/index.ts inside a try. On failure it still hands the
host a valid definition — the literal id plus a setup that says nothing is
active — and logs the package it could not resolve, the directory it was loaded
from, and both fixes. The id is a literal rather than PLUGIN_ID because it
has to be correct in exactly the case where src/index.ts never evaluated, and
the host keys storage, status and diagnostics on it.

opencode-self-improvement: failed to load from D:\Ellie3\.opencode\plugins\self-improving-skills\: Could not resolve: "zod". Maybe you need to "bun install"?
opencode-self-improvement: a loose copy under <config>/plugins/ needs its runtime dependencies — run `bun install` in that directory, or install the package with `opencode plugin add opencode-self-improvement`.

The directory belongs in the line for the same reason plugin_load carries
entry=: a machine that has ever pointed a plugins entry at a checkout has
two copies of this plugin.

Docs gain the error string, which they did not have: a row in
docs/reference/troubleshooting.md, a loose-copy section in
docs/reference/install.md, and the README notes in Layout and the
troubleshooting index.

Tests

test/host/plugin-shim.test.ts copies the shipped index.ts into a temp
directory with no node_modules and evaluates it. It asserts the failure path
yields id + setup, that the log names the package, the directory and both
fixes, that setup on the unloaded definition says nothing is active, and that
a healthy src/index.ts passes through with no diagnostic. Copying the real
file rather than importing it keeps the fixture honest about what a loose copy
actually is, and proves the shim itself needs nothing installed.

Merge gate green: 1603 pass / 21 skip / 0 fail unit, 37 pass e2e against a real
opencode host, tsc clean, biome clean, comment-lint clean.

Not in this PR

The load still fails without node_modules — this makes the failure legible,
not survivable. Reported in #464, which stays open for that decision: this PR
covers its entry-guard and documentation items, not the dependency removal.
Removing zod from the plugin load path so a loose copy works
with zero runtime dependencies is the real fix and needs a decision: vendor a
bundled build, or hand-roll the bounded surface (object, string, enum,
array, boolean, coerce.number, optional, max, describe,
iso.datetime, plus z.toJSONSchema at src/tools/schema.ts:271 and
safeParse at :306). The risk to pin is drift in the safeParse message text
the model reads back. Tracked in #464.


Authored by an AI Assistant on behalf of the maintainer.

A loose copy under <config>/plugins/<name>/ installs nothing, so the eager
zod import at src/tools/schema.ts:17 throws while the entry module is being
evaluated. The host reports that as "Plugin must export a default definition
with an id and an effect or setup function", which points at an export that is
correct: src/index.ts:395 exports the V2 definition and index.ts re-exports it
as default. A reader audits the wrong file instead of running the command that
fixes it.

The root shim now imports src/index.ts inside a try and, when that fails, still
hands the host a valid definition with the literal id, and logs the package it
could not resolve, the directory it was loaded from, and both fixes: bun
install in that directory, or opencode plugin add. The id is a literal because
it has to be right in exactly the case where src/index.ts never evaluated.

test/host/plugin-shim.test.ts evaluates the shipped shim in a temp directory
with no node_modules, so it proves both that the shim needs nothing installed
and that the log names the cause. Docs gain the error string: a row in
troubleshooting.md, a loose-copy section in install.md, and the README notes.

Refs #464
@abogartz
abogartz force-pushed the fix/loose-discovery-load-error branch from b1086c3 to 616d4dc Compare November 20, 2026 20:57

@WhollyMindless WhollyMindless left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified 616d4dc on native Windows with OpenCode 2.3.2. I put the shipped files under a fresh project's .opencode/plugins/self-improving-skills/ with no node_modules and started opencode run --standalone --print-logs. Loose discovery reached the real entry. The log named the copied directory and the missing zod import in src/tools/schema.ts, printed both install remedies, and reported that no tools or hooks were active. With the same setup on main (9e7c88d), I saw the host's load warning with zod in its underlying cause, without the plugin's remediation. This verifies the CLI diagnostic on Windows; I didn't exercise the desktop error display.

@WhollyMindless

Copy link
Copy Markdown
Contributor

I checked the Windows OpenCode Desktop 2.3.2 project settings with two fresh Git projects and loose plugin copies, both missing their dependencies. Under Project → Extensions → Plugins, main (9e7c88d) lists the loose directory path. This head (616d4dc) lists opencode-self-improvement under “Added to this project.” Neither entry shows the missing package or the install instructions in that panel.

The new diagnostic is useful in the host log. Someone looking only at Desktop can still see the plugin listed while its tools are unavailable. A short troubleshooting note pointing Desktop users from that panel to the host log would help. I couldn't reproduce the reporter's exact “Server plugin error” screen here.

A review on this PR checked the desktop app and found the plugin panel lists the
plugin under "Added to this project" and shows neither the missing package nor
the install command — on main it lists the loose directory path instead, which is
no better. The panel is therefore not where a desktop reader learns the cause, so
the two places that mention the log have to say how to open it.

`opencode run --standalone --print-logs` is the verified route: it printed the
copied directory, the unresolved `zod` import and both fixes on a Windows
checkout with no node_modules.
@abogartz

Copy link
Copy Markdown
Owner Author

Both reports are useful, and the second one changes the docs. 70a6cb7.

The desktop panel result is the important one. On this head the panel swaps a loose directory path for the plugin's own id, which is a real improvement — it is the difference between "some folder was picked up" and "this plugin loaded far enough to identify itself" — but neither version tells the reader a dependency is missing. So the panel is not where the fix gets across, and the two places in these docs that pointed at "the host log" never said how to open it. That was a dead end for exactly the reader whose panel shows nothing.

Both rows now name the verified route: opencode run --standalone --print-logs, and say the desktop Project → Extensions → Plugins panel does not report the dependency. Wording kept to what your two reports actually establish — I did not claim a desktop log file path, because nothing here shows one.

No code change: the shim already logs the package, the directory and both fixes, which is what your CLI run on Windows captured.

— identified as an AI Assistant

@WhollyMindless WhollyMindless left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One copy-paste correction for the two new docs examples in 70a6cb7. I ran opencode run --standalone --print-logs as written in the affected project on Windows with OpenCode 2.3.2 and empty stdin. It exited 1 with You must provide a message before printing the plugin diagnostic. In the same fixture, opencode run --standalone --print-logs "diagnostic" printed the missing zod package, the loose-copy directory, and both install remedies. Adding the message argument in both places would give readers the working command. My earlier review abbreviated the invocation and omitted that argument.

`opencode run` requires a message. With none it exits with "You must provide a
message" before any plugin is loaded, so the diagnostic the row exists to point
at never prints. Reproduced on 2.3.0 and reported on 2.3.2 Windows.

install.md gains a fenced command so the whole invocation is copy-pasteable.
@abogartz

Copy link
Copy Markdown
Owner Author

Confirmed on this machine too, and fixed in 07f3e65.

$ opencode run --standalone --print-logs < /dev/null
Error: You must provide a message

v2.3.0, macOS. The server starts, the error lands, and the plugin is never loaded — so the row pointed readers at a command that cannot print the thing the row is about. run --help lists message as optional, which is what led me astray; the argument is optional for the interactive route and required for this one.

Both places now carry "diagnostic", and install.md got a fenced block so the whole invocation is copy-pasteable rather than half-prose. The failure string is quoted in both, so a reader who hits it knows the docs already cover it.

— identified as an AI Assistant

@ocsi-reviewer ocsi-reviewer 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.

Approving 07f3e65.

Both review rounds on this PR were corrections to my own work and both were right. The desktop panel shows neither the missing package nor the fix on main or on this head, so pointing readers at "the host log" without saying how to open it was a dead end for exactly that reader; and the command I then added does not run — opencode run needs a message, and without one it stops with You must provide a message before any plugin loads. I reproduced that here on 2.3.0, so it is not version-specific.

The docs now carry a copy-pasteable opencode run --standalone --print-logs "diagnostic" in both places, quote the failure string, and say the desktop plugin panel reports nothing about the dependency. Wording is limited to what the two Windows reports and this machine actually establish — no invented desktop log path.

The shim itself needed no change across either round: it already hands the host a valid definition with the literal id and logs the unresolved package, the directory it loaded from, and both fixes.

Gate green locally and on CI at this head: lint, test, test-windows, smoke.

— identified as an AI Assistant

@abogartz
abogartz merged commit c6b5554 into main Nov 20, 2026
4 checks passed
@abogartz-opencode-self-improvement

Copy link
Copy Markdown

🎉 This PR is included in version 0.33.6 🎉

The release is available on:

Your semantic-release bot 📦🚀

@WhollyMindless

Copy link
Copy Markdown
Contributor

One detail for the next docs edit now that our #459 is in the release. I ran the documented command on Windows OpenCode 2.3.2 against a fresh loose copy of the merged head (f1a8164) with no node_modules. It named @lezer/markdown from src/gate/resolver.ts first and printed both install remedies. The zod example was accurate on the earlier head. Calling it an example of a missing runtime dependency in the install and troubleshooting docs would cover both diagnostics.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants