Repository navigation
opencode: find the dispatcher wherever the plugin is installed - #229
Open
Have-Purple wants to merge 1 commit into
Open
Have-Purple wants to merge 1 commit into
Have-Purple wants to merge 1 commit into
Conversation
Author
|
@microsoft-github-policy-service agree |
Aaron Li (aaron-jx-li)
requested changes
Nov 16, 2026
Aaron Li (aaron-jx-li)
left a comment
Collaborator
There was a problem hiding this comment.
Thanks for the contribution and for the clear diagnosis in #228. This PR needs a few changes before it can be merged:
plugin/opencode/tokeneconomizer.ts:72-88walks up to 16 ancestors of the plugin's directory and takes the firstscripts/te_bootstrap.pyorplugin/scripts/te_bootstrap.pyit finds, before it looks at the launcher. The walk reaches the filesystem root, so ate_bootstrap.pyin any unrelated ancestor wins over the person's own~/.tokeneconomizer/bin/te(a copy under<x>/home/u/.config/opencode/plugins/with<x>/scripts/te_bootstrap.pypresent resolves to<x>/scripts). On Windows the walk ends atC:\, where standard users can create folders by default, so another account could plantC:\scripts\te_bootstrap.pyand every hook would run it. Please check only the layouts the plugin ships in (<here>/../scripts), then the launcher, and drop the open-ended walk.- The case in #228 (a copy with nothing beside it, on a fresh install) still fails silently unless
TE_CORE_PATHorTE_PLUGIN_ROOTis set: the launcher only exists after a hook has reached the dispatcher (tokeneconomizer/plugin/controller.py:105). Neither variable is mentioned in the opencode section ofplugin/README.md, which still says to keep the plugin next toscripts/andlib/. Please add a line there for a copied plugin: setTE_CORE_PATHto the checkout, and on 2.x restart the service so it reaches the plugin. - The launcher fallback (
tokeneconomizer.ts:89-103) parses the filepaths.ensure_launcherwrites, and no test covers it. Please add one with noTE_CORE_PATHand a launcher whose target path contains a space (the quoted formshlex.quotewrites).
The plugin assumed its launchers sit at <plugin dir>/../scripts. That holds in the checkout,
but not for the copy opencode loads from ~/.config/opencode/plugins, where it resolves to
~/.config/opencode/scripts -- which does not exist. Every hook then failed to spawn, and the
fail-open path answered {}, so there was no fold, no injection, no loop guard, and no log to
notice.
Resolve instead: TE_PLUGIN_ROOT, TE_CORE_PATH (the checkout pointer the bootstrap already
reads), the layout the plugin ships in, and the state-root launcher
(~/.tokeneconomizer/bin/te -> <plugin>/scripts/te). Nothing walks up from the plugin's
directory: an unrelated ancestor would win over the dispatcher the plugin ships with, and on
Windows the walk ends at C:\, where a standard user can create folders by default, so a planted
scripts/te_bootstrap.py would run in every hook.
Tests assert dispatcher state, not hook-process count: a hook that cannot find
te_bootstrap.py still starts a Python, so counting processes would pass with the bug. The
review's cases are covered: a planted ancestor must not run, and the launcher's quoted form
(shlex.quote) must resolve when the target path holds a space.
Have-Purple
force-pushed
the
fix/opencode-dispatcher-path
branch
from
November 16, 2026 13:33
35b4e50 to
2f0fb5a
Compare
Author
|
All three items are in 2f0fb5a, rebased onto
The two Evidence: full offline suite 1167 passed, 40 skipped, 0 failed; the six non-service plugin tests pass against opencode 2.3.0 on Windows. |
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.
Fixes #228.
Problem
The opencode plugin assumed its launchers live at
<plugin dir>/../scripts:That is true in the checkout, but not for the copy opencode loads from
~/.config/opencode/plugins, where it resolves to~/.config/opencode/scripts— which does not exist. Every hook then failed to spawn its dispatcher, and the fail-open path answered{}, so there was no fold, no injection, no loop guard, and no log entry to notice. Details and repro: #228.Change
Resolve the dispatcher instead of assuming a layout, first hit wins:
TE_PLUGIN_ROOT→<root>/scriptsTE_CORE_PATH→<root>/plugin/scripts(the checkout pointer the bootstrap already documents)<here>/../scripts~/.tokeneconomizer/bin/teisexec '<plugin>/scripts/te' "$@", so its directory is the dispatcher'sNothing walks up from the plugin's directory. An unrelated ancestor would win over the dispatcher the plugin ships with, and on Windows the walk ends at
C:\, where a standard user can create folders by default — a plantedscripts/te_bootstrap.pywould run in every hook. The last-resort expression is unchanged.plugin/README.mdnow covers the copied plugin:TE_CORE_PATH(orTE_PLUGIN_ROOT) set where the 2.x service starts, plusopencode service restart. The state launcher cannot make the first hook work, since it is written once a hook has reached the dispatcher.Tests
In
tests/test_opencode_plugin.py(run by the existing opencode CI job):TE_CORE_PATHand writes dispatcher state;libbeside the plugin) still resolves withTE_CORE_PATHunset;scripts/te_bootstrap.pyplanted above the copy is not run;exectarget holds a space (theshlex.quoteform);The assertion is dispatcher state, not hook-process count: a hook that cannot find
te_bootstrap.pystill starts a Python, which would make a process-count test pass with the bug.Verification
Rebased onto
main583fff7. opencode 2.3.0 on Windows: the six plugin tests (all but the two service tests) pass. Full offline suite: 1167 passed, 40 skipped, 0 failed. Restoring the ancestor walk turns the planted-stub test red; removing the quote strip from the launcher parse turns the space-path test red.