opencode-usage-insights 0.3.1 → 0.4.1

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 (57) hide show
  1. package/README.md +67 -542
  2. package/dist/core.d.ts +15 -1
  3. package/dist/gui-experimental.cjs +3 -3
  4. package/dist/index.d.ts +0 -47
  5. package/dist/index.js +1734 -1209
  6. package/dist/index.js.map +23 -16
  7. package/dist/line.d.ts +1 -0
  8. package/dist/panel-data.d.ts +9 -2
  9. package/dist/recorder.d.ts +1 -0
  10. package/dist/rpc.d.ts +4 -4
  11. package/dist/rpc.js +5 -5
  12. package/dist/rpc.js.map +3 -3
  13. package/dist/settings-client.d.ts +29 -0
  14. package/dist/settings-rpc.d.ts +746 -0
  15. package/dist/settings.d.ts +114 -0
  16. package/dist/sidebar.d.ts +3 -3
  17. package/dist/stats/aggregates.d.ts +15 -3
  18. package/dist/stats/constants.d.ts +7 -0
  19. package/dist/stats/db.d.ts +8 -128
  20. package/dist/stats/legacy.d.ts +25 -0
  21. package/dist/stats/maintenance.d.ts +1 -1
  22. package/dist/stats/migrate.d.ts +7 -0
  23. package/dist/stats/ndjson.d.ts +16 -0
  24. package/dist/stats/open.d.ts +15 -0
  25. package/dist/stats/paths.d.ts +5 -4
  26. package/dist/stats/queries.d.ts +30 -35
  27. package/dist/stats/records.d.ts +94 -0
  28. package/dist/stats/schema.d.ts +26 -0
  29. package/dist/stats-client.d.ts +9 -0
  30. package/dist/stats-worker.js +597 -367
  31. package/dist/stats-worker.js.map +17 -12
  32. package/dist/text.d.ts +2 -0
  33. package/dist/tui-settings.d.ts +18 -0
  34. package/dist/tui.d.ts +1 -57
  35. package/dist/tui.js +974 -158
  36. package/dist/tui.js.map +17 -13
  37. package/docs/cli.md +24 -0
  38. package/docs/configuration.md +108 -0
  39. package/docs/costs.md +44 -0
  40. package/docs/demo.md +94 -68
  41. package/docs/desktop.md +91 -0
  42. package/docs/images/desktop-overview-annotated.png +0 -0
  43. package/docs/images/desktop-overview.png +0 -0
  44. package/docs/images/desktop-settings.png +0 -0
  45. package/docs/images/desktop-turns-go-annotated.png +0 -0
  46. package/docs/images/desktop-turns.png +0 -0
  47. package/docs/images/line.png +0 -0
  48. package/docs/images/panel-cache.png +0 -0
  49. package/docs/images/panel-help.png +0 -0
  50. package/docs/images/panel-latency.png +0 -0
  51. package/docs/images/panel-overview.png +0 -0
  52. package/docs/images/panel-providers.png +0 -0
  53. package/docs/images/sidebar.png +0 -0
  54. package/docs/internals.md +87 -36
  55. package/docs/privacy.md +60 -0
  56. package/docs/tui.md +175 -0
  57. package/package.json +8 -7
package/dist/text.d.ts CHANGED
@@ -15,6 +15,8 @@
15
15
  */
16
16
  /** Longest value kept by default: a title, an id or a path, not a document. */
17
17
  export declare const TEXT_LIMIT = 512;
18
+ /** Longest title or path kept: a label on a line, not a document. */
19
+ export declare const LABEL_LIMIT: number;
18
20
  /**
19
21
  * Strip control characters and cap the length. Newlines and tabs go too: a
20
22
  * line is one line, and the renderers lay out their own spacing.
@@ -0,0 +1,18 @@
1
+ import type { Context } from "@opencode/plugin/tui/context";
2
+ import { type ServerPolicy, type UsageSettings, type UsageSettingsPatch } from "./settings";
3
+ /**
4
+ * The TUI's settings editor. The TUI SDK has no plugin settings page, so the
5
+ * editor is a command (`/insights-settings` or the command palette) that opens
6
+ * the host's native select/prompt/confirm dialogs. Every change goes through
7
+ * the shared settings RPC, so the Desktop and every other TUI follow it
8
+ * immediately.
9
+ */
10
+ export type SettingsDialogState = {
11
+ readonly settings: () => UsageSettings;
12
+ readonly policy: () => ServerPolicy;
13
+ readonly error: () => string | undefined;
14
+ refresh(): Promise<void>;
15
+ update(patch: UsageSettingsPatch): Promise<void>;
16
+ reset(): Promise<void>;
17
+ };
18
+ export declare function openUsageInsightsSettings(ctx: Context, state: SettingsDialogState): Promise<void>;
package/dist/tui.d.ts CHANGED
@@ -1,63 +1,7 @@
1
1
  /** @jsxImportSource @opentui/solid */
2
2
  import { Plugin } from "@opencode/plugin/tui";
3
- import { type LineFields, type LineLabels, type TurnStats, type TurnTotalsView } from "./core";
3
+ import { type TurnStats } from "./core";
4
4
  import { type PanelView, type RangeKey } from "./panel-data";
5
- /**
6
- * TUI side of the plugin. Two contributions:
7
- *
8
- * - `session.composer.top`: one telemetry line after every turn with the end
9
- * time, the delta since the previous prompt, the provider and model that ran
10
- * it, turn and session token totals, and cache warnings.
11
- * - `session.panel` + the `/usage-insights` slash command: the statistics
12
- * panel over the database written by the server entry. Its `go` view reads
13
- * the host's live OpenCode Go allowance; the sidebar carries the compact
14
- * forecast.
15
- *
16
- * The line is computed from the host's transcript alone; the panel, the
17
- * sidebar history and the stored list estimate come from the server's usage
18
- * RPC. The TUI never opens SQLite, so it works the same against a local or a
19
- * remote server. When the RPC is unavailable, the line still works and the
20
- * panel explains itself.
21
- */
22
- export type Options = {
23
- /** Turn the TUI side off: no line and no panel. */
24
- enabled?: boolean | undefined;
25
- /** Server-side database path override; the TUI reads it through the RPC. */
26
- db?: string | undefined;
27
- /** Allow the panel's prune, wipe, vacuum and backfill actions. Defaults to true. */
28
- maintenance?: boolean | undefined;
29
- /**
30
- * List-price estimates for steps the host reports as costing nothing.
31
- * `off` hides them on the line, in the panel and in the sidebar, and
32
- * disables the historical backfill. Defaults to `auto`.
33
- */
34
- pricing?: "auto" | "off" | undefined;
35
- /**
36
- * How the turn segment counts prompt usage: `latest` (default) shows the
37
- * prompt size the turn ended with, `sum` adds every step of the turn.
38
- */
39
- turnTotals?: TurnTotalsView | undefined;
40
- /** Telemetry line field toggles. */
41
- fields?: Partial<LineFields> | undefined;
42
- /** Telemetry line label overrides. */
43
- labels?: Partial<LineLabels> | undefined;
44
- /** Show the per-prompt history in the session sidebar (default true). */
45
- sidebar?: boolean | undefined;
46
- /** How many turns the sidebar history shows (default 8, clamped to 1–50). */
47
- sidebarTurns?: number | undefined;
48
- /**
49
- * Read the host's OpenCode Go allowance and show the `go` view and the
50
- * sidebar forecast. `off` makes no usage-limits request at all.
51
- */
52
- quota?: "auto" | "off" | undefined;
53
- /** Full subscription label; defaults to the host provider name or OpenCode Go. */
54
- quotaName?: string | undefined;
55
- /**
56
- * Show the `/usage-insights` statistics panel and its command (default
57
- * true). `false` keeps the live line and the sidebar history.
58
- */
59
- panel?: boolean | undefined;
60
- };
61
5
  export declare const __test: {
62
6
  line: ((sessionID: string) => TurnStats | undefined) | undefined;
63
7
  lineText: ((sessionID: string) => string) | undefined;