From a632cd82275120fac58d60bf40305a7127d78f5a Mon Sep 17 00:00:00 2001 From: "Ronny.Herrgesell" Date: Mon, 11 May 2026 07:41:13 +0200 Subject: [PATCH] prepare npm package as @sleipi/opencode-usage-stats Add main/exports/bin/files/publishConfig fields to package.json, GitHub Actions publish workflow, and update README with npm installation instructions. --- .github/workflows/publish.yml | 23 +++++++++++++++++++++++ README.md | 28 ++++++++++++++++------------ ROADMAP.md | 1 + package.json | 19 ++++++++++++++++++- 4 files changed, 58 insertions(+), 13 deletions(-) create mode 100644 .github/workflows/publish.yml diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..37a9427 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,23 @@ +name: Publish to npm + +on: + release: + types: [published] + +jobs: + publish: + runs-on: ubuntu-latest + permissions: + contents: read + steps: + - uses: actions/checkout@v4 + + - uses: oven-sh/setup-bun@v2 + with: + bun-version: latest + + - run: bun install --frozen-lockfile + + - run: npm publish --access public + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/README.md b/README.md index 16c7d9d..cc41f41 100644 --- a/README.md +++ b/README.md @@ -20,33 +20,37 @@ Tracks token usage, costs, model selection, and agent activity across sessions. ## Installation -```bash -git clone https://github.com/sleipi/opencode-usage-stats.git -cd opencode-usage-stats -bun install +Add the plugin to your `opencode.json`: + +```json +{ + "plugin": ["@sleipi/opencode-usage-stats"] +} ``` -### Symlink into OpenCode plugins +Restart OpenCode to load the plugin. The plugin starts tracking immediately. + +### Manual installation (alternative) ```bash +git clone https://github.com/sleipi/opencode-usage-stats-plugin.git +cd opencode-usage-stats-plugin +bun install ln -s "$(pwd)/src/plugin.ts" ~/.config/opencode/plugins/opencode-usage-stats.ts -ln -s "$(pwd)/src/dashboard.ts" ~/.config/opencode/plugins/usage-stats-dashboard.ts ``` -Restart OpenCode to load the plugin. The plugin starts tracking immediately. - ## Dashboard -Start the dashboard manually: +Start the dashboard: ```bash -bun run dashboard +bunx @sleipi/opencode-usage-stats ``` -Use a custom port if 3333 is already occupied by OpenCode itself: +Or with a custom port (default is 3333): ```bash -PORT=3334 bun run dashboard +PORT=3334 bunx @sleipi/opencode-usage-stats ``` Opens at [http://localhost:3333](http://localhost:3333). diff --git a/ROADMAP.md b/ROADMAP.md index 10048b0..96c9f6b 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -4,6 +4,7 @@ ## Completed +- [x] Publish as npm package (`@sleipi/opencode-usage-stats`) with bin entrypoint for dashboard - [x] Refactor dashboard into SOLID modules with DI, separated templates, services, and routes - [x] Refactor plugin hook processing into explicit interfaces and focused handlers (SOLID) - [x] Introduce Playwright end-to-end tests for dashboard rendering and stats endpoint diff --git a/package.json b/package.json index 0686d0b..ee2159c 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,25 @@ { - "name": "opencode-usage-stats", + "name": "@sleipi/opencode-usage-stats", "version": "0.1.0", "description": "Usage statistics tracking and dashboard for OpenCode", "type": "module", + "main": "./src/plugin.ts", + "exports": { + ".": "./src/plugin.ts" + }, + "bin": { + "opencode-usage-stats": "./src/dashboard.ts" + }, + "files": [ + "src/" + ], + "repository": { + "type": "git", + "url": "https://github.com/sleipi/opencode-usage-stats-plugin.git" + }, + "publishConfig": { + "access": "public" + }, "scripts": { "dashboard": "bun --watch run src/dashboard.ts", "check": "biome check .",