diff --git a/README.md b/README.md index 7df6990..7eb13b4 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,20 @@ A TUI plugin for OpenCode that displays live prefill rate (PP) and generation rate (TG) from a llama.cpp-based llama-server. +There are many plugins to show tokens per second, but the reason for this one is that when running a local model I often found myself not knowing what the server was currently doing, which meant constantly switching over to a console where I could see its output. Especially during prefill/prompt processing which can take more than a minute with no feedback in the UI from other plugins I tried. + +Another motivation was to display the data of interest, but in a non-intrusive way with no UI elements jumping around. This plugin thus only shows a single numeric value, tokens per second, with an indicator as to whether the model is currently doing prompt processing or inference (token generation). + +I'm using the llama-server /slots endpoint to get the needed data, which means if you connect opencode to another provider the plugin will just display "-" since it's not getting any data to display. + +Note: As explained in further detail below the data that's displayed has to be deduced from llama-server's output. Sometimes the plugin might display PP for prompt processing while in reality the model is doing TG. If additional developments are made to the llama-server output data the plugin might be able to discern between them in a better way, but I think is as good as it gets for now. + +I made this for my own usage. If you find it useful as well I'm just happy. + +/Troed + +_thanks to Tarquinen for their [oc-tps](https://github.com/Tarquinen/oc-tps), which I used as a base although I guess most of the code has now been replaced_ + ## Display Format The plugin renders a single line in the session prompt right slot: @@ -94,4 +108,4 @@ Debug logging is controlled by the `DEBUG_ENABLED` constant in `tui.tsx`. When e ## License -Inherited from the original fork. +Creative Commons Zero (CC0 1.0 Universal) diff --git a/TUIPLUGIN.md b/TUIPLUGIN.md deleted file mode 100644 index b059181..0000000 --- a/TUIPLUGIN.md +++ /dev/null @@ -1,120 +0,0 @@ -# TUI Plugin Investigation - oc-ls-stats - -## Problem -The `@troed/oc-ls-stats` TUI plugin installs successfully via `opencode plugin` but produces no visible output in the OpenCode TUI. - -## Key Findings - -### 1. OpenCode Plugin Architecture -- **Server plugins**: Configured in `opencode.jsonc` under `plugin` array, shown in `/status` -- **TUI plugins**: Configured in `~/.config/opencode/tui.json` under `plugin` array, NOT shown in `/status` -- These are two completely separate plugin loaders - -### 2. TUI Plugin Installation -- Command: `opencode plugin "@latest" --global` -- Installs to: `~/.cache/opencode/packages/@latest/node_modules//` -- For scoped packages: `~/.cache/opencode/packages/@scope/package@latest/node_modules/@scope/package/` -- Config updated: `~/.config/opencode/tui.json` -- Peer deps installed to: `~/.config/opencode/node_modules/` - -### 3. TUI Plugin Loading -- TUI config loaded in a separate process from the main OpenCode instance -- Logs show only: `"loading tui config"` and `"applying tui config"` -- No plugin loading errors appear in logs (same as working oc-tps) -- Plugin loading happens silently - no success/error logs - -### 4. Registry Configuration -- `~/.npmrc`: - ``` - registry=https://registry.npmjs.org/ - //git.sync.wtf/api/packages/troed/npm/:_authToken=590922c3fe27e44cd5a216f14375cff575e52b5c - @troed:registry=https://git.sync.wtf/api/packages/troed/npm/ - ``` -- Public npm for `@opencode-ai/*` and other unscoped packages -- Forgejo registry for `@troed/*` scoped packages - -### 5. Package Structure (working vs non-working) -Both plugins have identical structure: -```json -{ - "name": "@troed/oc-ls-stats", - "version": "0.0.x", - "type": "module", - "exports": { "./tui": { "import": "./tui.tsx" } }, - "peerDependencies": { - "@opencode-ai/plugin": "*", - "@opentui/core": "*", - "@opentui/solid": "*", - "solid-js": "*" - } -} -``` - -Export format (identical): -```typescript -const plugin: TuiPluginModule & { id: string } = { - id: "oc-tps", - tui, -} -export default plugin -``` - -### 6. What We Tried (all failed) -- Pointing to file directly (`file:///path/to/tui.tsx`) - didn't work -- Adding `oc-plugin` field to package.json - didn't work -- Adding `main` field to package.json - didn't work -- Tuple format in tui.json - rejected by OpenCode -- Copying file to `~/.config/opencode/plugins/` - didn't work -- Publishing to Forgejo without scope - peer deps resolve from Forgejo (404) -- Publishing with scope (`@troed/`) - installs but no output -- Manual npm install to `~/.config/opencode/node_modules/` - no output -- Adding console.log - not visible (TUI runs in separate process) -- Adding early slot registration - no output -- Wrapping loadConfigUrls in try-catch - no output -- Simplified slot handler to static text - no output -- Multiple version bumps and reinstalls - no output - -### 7. Stale Cache Issues -- OpenCode caches plugins in `~/.cache/opencode/packages/` -- Stale entries from manual installs can persist -- Multiple stale directories created during debugging: - - `~/.cache/opencode/packages/oc-ls-stats@latest` (empty) - - `~/.cache/opencode/packages/@troed/oc-ls-stats:latest` (colon in name) - - `~/.cache/opencode/packages/troed/oc-ls-stats@latest` (missing @) -- Must manually clear cache before reinstalling: `rm -rf ~/.cache/opencode/packages/@troed/oc-ls-stats@latest` - -### 8. Background Dependency Install Error -- `~/.opencode/package.json` has `"@opencode-ai/plugin": "1.4.9"` as dependency -- OpenCode tries to install this from Forgejo (404) during startup -- This is a separate issue from TUI plugin loading -- The package is already installed in `~/.opencode/node_modules/` - -### 9. Working Reference: oc-tps -- Installed via: `opencode plugin oc-tps@latest --global` -- Cache location: `~/.cache/opencode/packages/oc-tps@latest/node_modules/oc-tps/` -- tui.json: `"oc-tps@latest"` (unscoped) -- Shows TPS output correctly -- NOT listed in `/status` (expected for TUI plugins) -- No log output (same as oc-ls-stats) - -### 10. Current State -- `@troed/oc-ls-stats@0.0.8` published to Forgejo -- Installed in cache with correct version -- tui.json: `["@troed/oc-ls-stats@latest"]` -- Peer deps installed in `~/.config/opencode/node_modules/` -- Slot registration added at start of tui function -- Static text output in slot handler -- **Still no visible output** - -## Conclusion -The plugin installs and appears to load (same log pattern as working oc-tps), but produces no output. The root cause is unknown. Possible causes: -1. OpenCode's TUI plugin loader has an issue with scoped packages -2. There's a runtime error that's not being logged -3. The slot registration is not being triggered for some reason -4. There's a difference in how the TUI process resolves modules for scoped vs unscoped packages - -## Next Steps -- Compare the exact module resolution path between oc-tps and oc-ls-stats -- Check if the TUI process can actually import the scoped package -- Verify the slot registration is being called (maybe via a side effect) -- Check if there's a TUI-specific debug mode or log output diff --git a/assets/demo.gif b/assets/demo.gif deleted file mode 100644 index ba4bc5d..0000000 Binary files a/assets/demo.gif and /dev/null differ diff --git a/package-lock.json b/package-lock.json index 8e7e4ee..bacafee 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "oc-tps", - "version": "0.0.66", + "version": "0.0.67", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "oc-tps", - "version": "0.0.66", + "version": "0.0.67", "engines": { "opencode": ">=1.3.14" }, diff --git a/package.json b/package.json index 921883f..7f2d173 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "$schema": "https://json.schemastore.org/package.json", "name": "@troed/oc-ls-stats", - "version": "0.0.66", + "version": "0.0.67", "type": "module", "exports": { "./tui": {