@mtayfur/opencode-cache-view 1.0.2 → 1.0.4

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 (3) hide show
  1. package/README.md +35 -55
  2. package/dist/index.js +2 -1
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # OpenCode Cache View
2
2
 
3
- `@mtayfur/opencode-cache-view` adds a compact sidebar to the OpenCode TUI for cache efficiency, estimated context usage, generation speed, and loaded skills. The latest cache-hit ratio and trend also remain visible in the prompt status row.
3
+ `@mtayfur/opencode-cache-view` adds a compact sidebar to the OpenCode TUI for cache efficiency, estimated context
4
+ usage, generation speed, and loaded skills. The latest cache-hit ratio and trend also remain visible in the prompt
5
+ status row.
4
6
 
5
7
  ```text
6
8
  Cache View
@@ -26,73 +28,51 @@ customize-opencode 3.1K tok
26
28
 
27
29
  ## Metrics
28
30
 
29
- - **Cache:** `Hit` is `cache.read / (input + cache.read + cache.write)` for the latest regular LLM step. `Session Hit` is the aggregate OpenCode session ratio, including compaction calls. `Miss` combines uncached input and cache writes.
30
- - **Estimated Tokens:** Uses one character-based estimator for the visible system, user, tool, reasoning, and output content from the latest completed compaction summary, its preserved tail, and subsequent messages loaded in the TUI. Provider system prompts, tool schemas, and media tokens are not included.
31
- - **Speed:** During streaming, `TPS` shows a `~`-prefixed estimate from visible text and reasoning deltas over the latest five seconds. Hidden reasoning with no deltas uses the previous completed turn or remains `… tok/s` when none exists. Completed tool-call steps and tool execution time are excluded. The rate remains `~`-prefixed while the turn is incomplete; the final non-tool-call assistant step replaces it with exact `(output + reasoning) / duration` throughput. `TTFT` retains the estimated delay to the first visible reasoning or text block, and `Trend` shows the latest eight completed-turn TPS values.
32
- - **Loaded Skills:** Shows active, non-compacted skill outputs and their estimated token counts. When a skill is loaded more than once, the latest load is shown.
33
-
34
- Rows and the cache-hit bar adapt to the available sidebar width. The arrow next to the hit rate compares the latest two LLM steps. Sections can be expanded or collapsed with the mouse.
35
-
36
- The prompt status indicator uses the composable `session_prompt_right` slot, so it does not replace the prompt or conflict with plugins that customize prompt behavior. It shows the same completed-step TPS as the sidebar, followed by a single separator and the cache ratio; only the cache trend is color-coded.
31
+ - **Cache:** `Hit` is `cache.read / (input + cache.read + cache.write)` for the latest regular LLM step.
32
+ `Session Hit` is the aggregate OpenCode session ratio, including compaction calls. `Miss` combines uncached input and
33
+ cache writes.
34
+ - **Estimated Tokens:** Uses one character-based estimator for the visible system, user, tool, reasoning, and output
35
+ content from the latest completed compaction summary, its preserved tail, and subsequent messages loaded in the TUI.
36
+ Provider system prompts, tool schemas, and media tokens are not included.
37
+ - **Speed:** During streaming, `TPS` shows a `~`-prefixed estimate from visible text and reasoning deltas over the
38
+ latest five seconds. Hidden reasoning with no deltas uses the previous completed turn or remains `… tok/s` when none
39
+ exists.
40
+ Completed tool-call steps and tool execution time are excluded. The rate remains `~`-prefixed while the turn is
41
+ incomplete; the final non-tool-call assistant step replaces it with exact `(output + reasoning) / duration`
42
+ throughput. `TTFT` retains the estimated delay to the first visible reasoning or text block, and `Trend` shows the
43
+ latest eight completed-turn TPS values.
44
+ - **Loaded Skills:** Shows active, non-compacted skill outputs and their estimated token counts. When a skill is loaded
45
+ more than once, the latest load is shown.
46
+
47
+ Rows and the cache-hit bar adapt to the available sidebar width. The arrow next to the hit rate compares the latest two
48
+ LLM steps. Sections can be expanded or collapsed with the mouse.
49
+
50
+ The prompt status indicator uses the composable `session_prompt_right` slot, so it does not replace the prompt or
51
+ conflict with plugins that customize prompt behavior. It shows the same completed-step TPS as the sidebar, followed by
52
+ a single separator and the cache ratio; only the cache trend is color-coded.
37
53
 
38
54
  ## Requirements
39
55
 
40
56
  - OpenCode `1.18.16` or a newer compatible 1.x release
41
- - Bun `1.3.14` or newer for local development
42
57
 
43
58
  ## Installation
44
59
 
45
- Add the package to `~/.config/opencode/tui.json`:
46
-
47
- ```json
48
- {
49
- "plugin": ["@mtayfur/opencode-cache-view"]
50
- }
51
- ```
52
-
53
- OpenCode installs package plugins automatically. Restart the TUI after changing the configuration.
54
-
55
- ### Local checkout
60
+ Install the plugin globally with OpenCode:
56
61
 
57
62
  ```sh
58
- bash ./install.sh
63
+ opencode plugin @mtayfur/opencode-cache-view --global
59
64
  ```
60
65
 
61
- The installer resolves dependencies, builds `dist/index.js`, and adds its local `file://` URL to the TUI plugin configuration. Remove the local entry with:
66
+ Restart OpenCode after installation.
62
67
 
63
- ```sh
64
- bash ./install.sh --uninstall
65
- ```
68
+ ### Manual configuration
66
69
 
67
- Restart OpenCode after either operation.
70
+ Alternatively, add the package to `~/.config/opencode/tui.json`:
68
71
 
69
- ## Architecture
70
-
71
- ```text
72
- src/
73
- ├── index.tsx Plugin entrypoint
74
- ├── cache-status.tsx Prompt status-row cache ratio
75
- ├── cache-view.tsx Solid/OpenTUI view and event subscriptions
76
- ├── format.ts Display formatting
77
- ├── token-estimator.ts Cached character-based token estimation
78
- └── metrics/
79
- ├── cache.ts Cache usage and hit ratios
80
- ├── context.ts Active context, token, and skill calculations
81
- ├── helpers.ts Shared message and part helpers
82
- ├── read.ts Metric orchestration
83
- ├── speed.ts Completed-step generation speed
84
- └── types.ts Metric data contracts
72
+ ```json
73
+ {
74
+ "plugin": ["@mtayfur/opencode-cache-view"]
75
+ }
85
76
  ```
86
77
 
87
- Metric calculations are isolated from the TUI rendering layer. `read.ts` snapshots OpenCode state and coordinates the dedicated metric modules, while `cache-view.tsx` owns reactive updates and presentation.
88
-
89
- ## Development
90
-
91
- From the repository root:
92
-
93
- ```sh
94
- bun install --frozen-lockfile
95
- bun run --filter @mtayfur/opencode-cache-view typecheck
96
- bun run --filter @mtayfur/opencode-cache-view build
97
- npm pack ./packages/cache-view --dry-run
98
- ```
78
+ Restart OpenCode after changing the configuration.
package/dist/index.js CHANGED
@@ -446,7 +446,7 @@ function createSpeedTracker(api) {
446
446
  if (!start || start.sessionID !== event.properties.sessionID)
447
447
  return;
448
448
  clearStream(value.messageID);
449
- const duration = start.firstTokenTime === undefined ? 0 : event.properties.time - start.firstTokenTime;
449
+ const duration = start.firstTokenTime === undefined || start.lastTokenTime === undefined ? 0 : start.lastTokenTime - start.firstTokenTime;
450
450
  const tokens = value.tokens.output + value.tokens.reasoning;
451
451
  if (value.reason === "tool-calls") {
452
452
  pendingToolTurns.add(start.sessionID);
@@ -467,6 +467,7 @@ function createSpeedTracker(api) {
467
467
  return;
468
468
  const now = Date.now();
469
469
  start.firstTokenTime ??= now;
470
+ start.lastTokenTime = now;
470
471
  const previous = streamParts.get(event.properties.partID) ?? {
471
472
  messageID: event.properties.messageID,
472
473
  units: 0
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
3
  "name": "@mtayfur/opencode-cache-view",
4
- "version": "1.0.2",
4
+ "version": "1.0.4",
5
5
  "description": "Minimal OpenCode TUI sidebar for cache hit, estimated tokens, and generation speed.",
6
6
  "repository": {
7
7
  "type": "git",