opencode-usage-insights 0.1.3 → 0.3.0

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.
@@ -0,0 +1,97 @@
1
+ # Contributing to opencode-usage-insights
2
+
3
+ Thank you for considering contributing to opencode-usage-insights! Before diving in, please read these guidelines carefully.
4
+
5
+ ## Before You Write Any Code
6
+
7
+ **Open an issue first.** For anything beyond a small bug fix, typo, or documentation improvement, please open an issue and wait for a response before writing code. This can save you hours of work on something that won't be merged.
8
+
9
+ If an issue already exists, comment on it to signal your intent so work isn't duplicated.
10
+
11
+ ## Pull Request Size
12
+
13
+ **Keep PRs small and focused on a single concern.**
14
+
15
+ - **Target under ~300 lines changed** (excluding lock files and generated code)
16
+ - **One PR = one thing.** Don't bundle a bug fix with a refactor with a new feature
17
+ - If your change is naturally large, break it into a chain of smaller PRs
18
+
19
+ PRs that are too large to review efficiently will be asked to be split.
20
+
21
+ ## Prerequisites
22
+
23
+ - **Bun** (installed globally) — see [bun.sh](https://bun.sh)
24
+
25
+ ## Getting Started
26
+
27
+ 1. **Fork the repository** on GitHub
28
+ 2. **Clone your fork** locally:
29
+ ```bash
30
+ git clone https://github.com/YOUR_USERNAME/opencode-usage-insights.git
31
+ ```
32
+ 3. **Create a branch** with a descriptive name:
33
+ ```bash
34
+ git checkout -b fix/description-of-fix
35
+ # or
36
+ git checkout -b feat/description-of-feature
37
+ ```
38
+ 4. Install dependencies:
39
+ ```bash
40
+ bun install
41
+ ```
42
+ 5. **Make your changes** and validate before pushing:
43
+ ```bash
44
+ bun run typecheck && bun run build && bun test && bun run check:package
45
+ ```
46
+ 6. **Push and open a PR** against the `main` branch, filling in the PR template completely.
47
+
48
+ ## Ground Rules for This Plugin
49
+
50
+ - `src/core.ts`, `src/line.ts`, `src/panel-data.ts`, `src/pricing.ts`,
51
+ `src/stats/` and `src/text.ts` must stay free of host imports
52
+ (`@opencode/*`, `@opentui/*`, `solid-js`) so they remain unit-testable
53
+ without a TUI runtime.
54
+ - `src/gui/**` is browser code: no `bun:*`, no `node:*`, no `bun:sqlite` and no
55
+ `@opencode/ui`/`@opencode/session-ui`. It may import `effect`, `solid-js`,
56
+ `@opencode/plugin/gui`, `@opencode/plugin/rpc` and `@opencode/client`, which
57
+ the Desktop provides. Render controls with `ctx.ui` and the app's v2 CSS
58
+ tokens; `scripts/check-package.ts` fails on a forbidden module in the bundle.
59
+ - The usage RPC (`src/rpc.ts`) is a security boundary. A new method needs a
60
+ closed JSON Schema, a bounded input, a server-side clamp, and a test for the
61
+ read-only and maintenance paths. Do not add SQL, a filesystem path or an
62
+ import/export operation to the RPC.
63
+ - The worker is the only reader for the panel and the turn history. Server
64
+ request handlers must not query SQLite directly; go through `src/service.ts`
65
+ and `src/stats-client.ts`, and keep the worker read-only for queries.
66
+ - Every view or line change needs a test at the level it lives at: pure text for
67
+ the view models, the shared harness (`test/harness.ts`) for slots, commands
68
+ and the line, and a render test for anything that changes JSX.
69
+ - A render test must **drive a reactive update** and assert the new output
70
+ (see `test/plugin.test.ts`): render-once smoke tests cannot catch content that
71
+ is appended on every update. Assertions read the renderable tree (`treeText`),
72
+ because the headless renderer paints a single frame. `test/preload.ts` (wired
73
+ in `bunfig.toml`) resolves `solid-js` to the client build for the same reason;
74
+ without it the tests would pass without any reactivity.
75
+ - A line or panel contribution is a *single* renderable filled through its
76
+ `content` property. Passing a `StyledText` as a JSX child accumulates a copy
77
+ of the content per update in the current OpenTUI build.
78
+ - Recording must stay observational: never rewrite prompts, requests or
79
+ responses, and never let a telemetry failure surface as a session error.
80
+ - A database write must be idempotent (upsert by message id) — replayed events
81
+ and restarts are normal.
82
+ - The identity of a step is the provider the model ran through and the model
83
+ itself, both taken from the event stream. Never infer who ran a request from
84
+ anything else: a gateway's upstream is not observable, and a guess would
85
+ label the telemetry with a name no evidence supports.
86
+ - Changes that touch the queries, the panel assembly or the line should keep
87
+ `bun run bench` green; changes to paths, the database or maintenance should
88
+ keep `bun run check:platform` green. CI runs the suite on Linux, so run that
89
+ check on macOS or Windows when you touch those.
90
+
91
+ ## Response Time Expectations
92
+
93
+ Reviews may take a few days depending on availability. A PR sitting without a response is not a rejection. Please feel free to leave a polite ping after a week if there's been no activity.
94
+
95
+ ## Thank You
96
+
97
+ Every contribution makes a real difference. Thank you for taking the time to improve opencode-usage-insights.