@ljw1004/opencode-trace 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.ts +20 -31
  2. package/package.json +1 -1
package/index.ts CHANGED
@@ -544,35 +544,24 @@ async function tracedFetch(
544
544
  return res
545
545
  }
546
546
 
547
- export default {
548
- id: "ljw.opencode-trace",
549
- async server(): Promise<object> {
550
- // OpenCode loads this module with dynamic import() when plugin state is initialized for
551
- // an instance/directory. In current OpenCode this module import is normally cached, so
552
- // top-level state like `orig`, `files`, and `prevs` survives repeated hook initialization.
553
- //
554
- // OpenCode then calls `server()` when it initializes this plugin's server hooks for that
555
- // instance. That can happen more than once per process across instance reload/dispose, so
556
- // the fetch patch must be guarded even though the module itself is usually only loaded once.
557
- if (!orig) {
558
- orig = globalThis.fetch.bind(globalThis)
559
- globalThis.fetch = tracedFetch
560
- }
561
- return {}
562
- },
563
- }
547
+ /* Plugin model:
548
+ * - This module is loaded with dynamic import() when plugin state is initialized for an instance/directory.
549
+ * The module import is normally cached, so our top-level state like `orig` survives repeated hook initialization
550
+ * - Opencode calls `default.server()` when it initializes this plugin's server hooks for that instance.
551
+ * This can happen more than once per process across instance reload/dispose, which is why our fetch()
552
+ * patch is guarded even though the module itself is loaded only once.
553
+ * - Opencode v1.3 has a single unified process for both TUI and server, so its plugin entrypoint `default` is just a function.
554
+ * - Opencode v1.4 has two separate entrypoints, `default.tui()` and `default.server()`
555
+ */
556
+ const main: (() => Promise<object>) & {id?: unknown, server?: unknown} = async () => {
557
+ if (!orig) {
558
+ orig = globalThis.fetch.bind(globalThis);
559
+ globalThis.fetch = tracedFetch;
560
+ }
561
+ return {};
562
+ };
564
563
 
565
- // For opencode versions prior to 1.4, it doesn't get picked up automatically from the plugins
566
- // directory so you have to add this to your ~/.config/opencode/opencode.json
567
- // "plugin": [
568
- // "file:///path/to/.config/opencode/plugins/index.ts"
569
- // ]
570
- //
571
- // And it uses a different default export:
572
- // export default async function opencodeTracePlugin() {
573
- // if (!orig) {
574
- // orig = globalThis.fetch.bind(globalThis);
575
- // globalThis.fetch = tracedFetch;
576
- // }
577
- // return {}
578
- // }
564
+ const entrypoint = main; // opencode v1.3 expects default export to be a function
565
+ entrypoint.id = "ljw1004.opencode-trace";
566
+ entrypoint.server = main; // opencode v1.4 expects default export to be an object, with server() being what executes
567
+ export default entrypoint;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ljw1004/opencode-trace",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "OpenCode plugin that saves raw json LLM request+responses as jsonl in ~/opencode-trace, with built-in HTML interactive viewer",
5
5
  "license": "MIT",
6
6
  "type": "module",