pub fn generate_opencode_plugin(sqz_path: &str) -> StringExpand description
Generate the OpenCode TypeScript plugin content.
The plugin intercepts shell tool calls and rewrites them to pipe
output through sqz hook opencode, which compresses the output.
§Plugin shape (issue #10 comment by @itguy327)
OpenCode’s V1 plugin loader (packages/opencode/src/plugin/shared.ts,
function readV1Plugin + resolvePluginId) requires file-source
plugins to default-export { id: string, server: Plugin }. Without
an id, OpenCode’s loader throws “Path plugin … must export id”
— but the loader is lenient and falls through to the “legacy”
path (getLegacyPlugins), which iterates all exports looking for
a factory function. That fallback works but gives the plugin no
human-readable name, so OpenCode’s UI displays the raw
file:///... spec instead of “sqz”. Reported by @itguy327 on
issue #10.
The fix is a dual-export shape:
- Default export — V1 object
{ id: "sqz", server: factory }so the modern loader identifies the plugin by name. - Named export
SqzPlugin— legacy factory fallback. Old OpenCode versions that don’t know about V1 walkObject.values(mod); default export dedups against the named export viaSetidentity ingetLegacyPluginsso the factory fires exactly once either way.
Concrete verification that the dedup holds: the seen Set in
getLegacyPlugins uses identity, and we assign the same factory
reference to both. Also verified end-to-end by loading the
generated file under the V1 loader and asserting only one hook
registration.