fix(plugin): stop exporting buildHiddenAgentConfig — opencode 1.17 invokes every entry export as a plugin factory - #182
Closed
iceteaSA wants to merge 1 commit into
Closed
Conversation
…encode 1.17 invokes every entry export as a plugin factory opencode 1.17 calls every exported function in a plugin's entry module (index.ts) as its own plugin factory: fn(ctx). The helper buildHiddenAgentConfig was exported from index.ts (introduced upstream in 29a49cb 'D19 resilience safe parts'), so opencode invoked it as buildHiddenAgentConfig(ctx) — passing the plugin context as `prompt` and undefined as `allowedTools` — which threw 'undefined is not an object (evaluating allowedTools)' during plugin load. Result: no hooks/tools registered, all ctx_* tools dead, empty MC runtime log, migration churn each boot. The entry module must export ONLY default (the plugin factory). Move the helper to a sibling module (hidden-agent-config.ts) where it can still be exported and unit-tested without being mis-invoked as a factory. index-refresh.test.ts now imports it from there. Verified: dist export keys = ['default']; full plugin suite green (the lone tui-config ordering flake is pre-existing on master); tsc + lint clean.
iceteaSA
force-pushed
the
fix-plugin-entry-export
branch
from
June 23, 2026 20:20
bc4adce to
d0a731f
Compare
Collaborator
|
Thanks for catching this and for the clear write-up — the root cause you identified (OpenCode's legacy loader invoking every entry-module export as a plugin factory) is exactly right. It's already resolved on master: the entry now uses the v1 plugin-object shape ( Closing as already-fixed, but the diagnosis was valuable — appreciate it. |
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.
The bug
On opencode 1.17, the magic-context plugin fails to load on every start:
Consequences: no hooks or tools registered, empty MC runtime log, migration churn each boot, all
ctx_*tools dead.Root cause
opencode 1.17 invokes every exported function in a plugin's entry module (
packages/plugin/src/index.ts) as its own plugin factory — calling itfn(ctx).The helper
buildHiddenAgentConfigis exported (introduced in29a49cb6"mason: apply D19 resilience safe parts"). So opencode calls it directly:An instrumented stack trace confirmed the caller was opencode core (an Effect frame) invoking
buildHiddenAgentConfigdirectly — not our ownconfighook. The DB (PRAGMA quick_check: ok) and the plugin cache were both empirically ruled out.The entry module must export only
default(the plugin factory). Any other exported function gets mis-invoked as a factory.The fix
Make
buildHiddenAgentConfigmodule-local (removeexport). It is only used insideindex.ts, so this is safe.Verified post-build:
…and the plugin loads cleanly under opencode 1.17 — hooks register,
ctx_*tools are live, transforms run.Scope
One line (plus an explanatory comment so it isn't re-exported by reflex).
tscclean, build clean.Need help on this PR? Tag
/codesmithwith what you need. Autofix is disabled.Summary by cubic
Move
buildHiddenAgentConfigout of the plugin entry to stop opencode 1.17 from invoking it as a plugin factory and crashing on load. The entry now exports onlydefault, restoring clean startup andctx_*tools.buildHiddenAgentConfigtopackages/plugin/src/hidden-agent-config.tsand imported it inindex.ts; entry now exports onlydefault.index-refresh.test.tsto use the new module; verified dist exports['default']and the plugin loads with hooks and tools active.Written for commit d0a731f. Summary will update on new commits.
Greptile Summary
This PR fixes a crash in opencode 1.17 where every exported function in a plugin entry module is invoked as a plugin factory. The previous code exported
buildHiddenAgentConfigfromindex.ts, causing opencode to call it with a plugin context object aspromptandundefinedasallowedTools, which threw on startup.packages/plugin/src/hidden-agent-config.ts(new):buildHiddenAgentConfigandclampHiddenAgentStepLimitare extracted into a standalone module with a JSDoc comment explaining why this helper must not live in the entry file.packages/plugin/src/index.ts: The function and itsbuildAllowOnlyPermissionimport are removed; the module now only exportsdefault, resolving the mis-invocation.packages/plugin/src/index-refresh.test.ts: Test import updated from./indexto./hidden-agent-config, keeping the existing unit tests intact.Confidence Score: 5/5
Safe to merge — the change is a minimal, surgical extraction of one helper into its own module with no logic changes.
The function body is copied verbatim into
hidden-agent-config.ts, the previously-broken test import is corrected in the same commit, andindex.tsnow carries onlyexport default plugin. The fix directly addresses the confirmed crash path and leaves no other named exports in the entry module that opencode could mis-invoke.No files require special attention.
Important Files Changed
default.Flowchart
%%{init: {'theme': 'neutral'}}%% flowchart TD A[opencode 1.17 loads plugin entry\npackages/plugin/src/index.ts] --> B{Iterates all\nexported keys} B -->|Before fix| C[Finds: default, buildHiddenAgentConfig] B -->|After fix| D[Finds: default only] C --> E[Calls buildHiddenAgentConfig as factory\nbuildHiddenAgentConfig ctx] E --> F[allowedTools = undefined\nfor...of undefined → CRASH\n'undefined is not an object'] D --> G[Calls default plugin factory\nplugin ctx] G --> H[Plugin loads successfully\nhooks + ctx_* tools registered] style F fill:#ff4444,color:#fff style H fill:#22bb44,color:#fff%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%% flowchart TD A[opencode 1.17 loads plugin entry\npackages/plugin/src/index.ts] --> B{Iterates all\nexported keys} B -->|Before fix| C[Finds: default, buildHiddenAgentConfig] B -->|After fix| D[Finds: default only] C --> E[Calls buildHiddenAgentConfig as factory\nbuildHiddenAgentConfig ctx] E --> F[allowedTools = undefined\nfor...of undefined → CRASH\n'undefined is not an object'] D --> G[Calls default plugin factory\nplugin ctx] G --> H[Plugin loads successfully\nhooks + ctx_* tools registered] style F fill:#ff4444,color:#fff style H fill:#22bb44,color:#fffReviews (2): Last reviewed commit: "fix(plugin): move buildHiddenAgentConfig..." | Re-trigger Greptile