Repository navigation
fix: an opencode session outside lich starts again - #16
Merged
Merged
Conversation
Running opencode outside lich with the plugin installed failed at startup with `Error: Unexpected server error`, and the server log named the cause twice: `plugin config hook failed` on `null is not an object (evaluating 'N.config')`, then the same on the session.created listener. opencode loads every export of a plugin module as a plugin, not just the one that looks like one. It called `lichTools` with the plugin input, which made `$` the input object and left `helper` undefined, and outside lich the LICH_PORT/LICH_TOKEN/LICH_SESSION_ID guard returned `null` — so opencode went looking for hook keys on `null` and died. Inside lich the same call returned the tools object, whose unknown keys opencode ignores, which is why only a bare terminal ever saw it. The export existed for one reason: the suite has to inject the tool package, because opencode resolves it from its own plugin dependencies and a checkout of this repository has none. That seam moves onto `LichPlugin`'s second argument instead. opencode calls a plugin with a single argument, so the parameter is invisible to it, and the module is back to one export. The regression test loads the module the way opencode does: with no lich environment, it calls every export with a plugin input and asserts each one hands back a hooks object whose keys can be read. It fails on the export this commit removes.
Moves the [Unreleased] entry under a v0.9.2 heading, refreshes the compare links, and aligns the version in both manifests with the tag. The release is what carries the fix: lich installs opencode's client by fetching the module at the latest release's tag, so every opencode session started outside lich keeps dying at startup until this one exists.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Running
opencodein a plain terminal with the plugin installed died atstartup:
The server log named the cause twice:
Root cause
opencode loads every export of a plugin module as a plugin, not just the one
that looks like one.
opencode/lich.jsexportedlichToolsbesideLichPlugin, so opencode called it with the plugin input too —$got theinput object,
helperwasundefined— and outside lich theLICH_PORT/LICH_TOKEN/LICH_SESSION_IDguard returnednull. opencode thenread hook keys off that
null.Inside lich it went unnoticed: the same call returned the tools object, whose
unknown keys opencode ignores. Only a bare terminal ever saw it.
Fix
The export existed for one reason — the suite has to inject the tool package,
because opencode resolves it from its own plugin dependencies and a checkout of
this repository has none. That seam moves onto
LichPlugin's second argument,which opencode never passes. The module is back to one export.
Test plan
node --test tests/*.test.mjs— 127 passevery export called with a plugin input, each result asserted to be a
hooks object whose keys can be read. It fails on the export this PR
removes (verified by re-adding the keyword).
XDG_CONFIG_HOME/XDG_DATA_HOME, opencode 1.18.16):reproduced upstream by @mellow-badger — only the
exportkeyword differsbetween the crashing and the working run.
Also cuts the release:
[Unreleased]moves underv0.9.2and both manifestsalign with the tag. lich installs the module at the latest release's tag, so
the fix only reaches sessions once that release exists — tag and release to
follow the merge.