oc-flight-deck 0.10.3 → 0.11.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.
package/CHANGELOG.md CHANGED
@@ -5,6 +5,28 @@ All notable changes to this project are documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [0.11.0] - 2026-10-08
9
+
10
+ ### Changed
11
+
12
+ - TPS now reports a delta-based instantaneous rate instead of the session-lifetime average. The display is an integer, smoothed with an EWMA, with hysteresis so the last digit does not flicker, a minimum token sample before the rate is trusted, and an idle freeze that holds the last value when no new tokens arrive.
13
+ - The `context` row now reads as an estimate (`~`), reflecting that the underlying usage figure is approximate.
14
+ - The cache hit-rate denominator is now documented as deliberate in code and docs.
15
+
16
+ ### Fixed
17
+
18
+ - `treeTotals` now wraps each per-id lookup in its own `try/catch`, so one bad id no longer blanks the cost/total rollup.
19
+ - Width-aware clipping keeps rows inside the rail instead of overflowing it.
20
+ - Per-session maps are now LRU-capped, closing a slow leak across long sessions.
21
+ - The `ses` row documents that the display is a pruned preview while click-to-copy still copies the full id.
22
+
23
+ ## [0.10.4] - 2026-10-06
24
+
25
+ ### Fixed
26
+
27
+ - The default `caution.exemptTools` list now carries the `tools.`-prefixed aliases (`tools.delegate`, `tools.delegate_many`, `tools.subagent`, `tools.task`) alongside the bare names it already exempted. Matching is by exact name, and the host reaches these delegated-work tools under both spellings, so a fresh install lit the row on ordinary delegation the bare names were meant to cover. The schema default and `flight-deck.example.jsonc` carry the same eleven names.
28
+ - The `caution` rail row draws a single-cell severity mark (`●` caution, `▲` watch) instead of `:warning:`. The bundled `string-width` tests emoji-regex before East-Asian width and charges `⚠` two cells — and Windows Terminal draws it that way — so the annunciator ran a column wider than every other row. Severity now rides a coloured run on the mark itself (`error` for a caution, `warning` for a watch) while the words keep the row's colour, and a test measures the drawn row in cells at the rail's real width.
29
+
8
30
  ## [0.10.3] - 2026-10-02
9
31
 
10
32
  ### Changed
@@ -30,6 +52,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
30
52
 
31
53
  - Opt-in `ses` sidebar row: shows the full session id (the rail wraps it), and a mouse click copies that same full id and reports the outcome - a confirmation naming the id when the copy was sent, a distinct failure message when the terminal cannot take it. Off by default, and degrades gracefully when the terminal cannot copy.
32
54
 
55
+ [0.11.0]: https://github.com/nathwn12/oc-flight-deck/compare/v0.10.4...v0.11.0
56
+ [0.10.4]: https://github.com/nathwn12/oc-flight-deck/compare/v0.10.3...v0.10.4
33
57
  [0.10.3]: https://github.com/nathwn12/oc-flight-deck/compare/v0.10.2...v0.10.3
34
58
  [0.10.2]: https://github.com/nathwn12/oc-flight-deck/compare/v0.10.1...v0.10.2
35
59
  [0.10.1]: https://github.com/nathwn12/oc-flight-deck/compare/v0.10.0...v0.10.1
package/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
  **Live session telemetry for your OpenCode terminal.**
6
6
  *The numbers where you're already looking — because your agent is spending money right now.*
7
7
 
8
- ![npm](https://img.shields.io/npm/v/oc-flight-deck) ![license](https://img.shields.io/badge/license-MIT-blue) ![node](https://img.shields.io/badge/node-%E2%89%A522-green) ![downloads](https://img.shields.io/npm/dm/oc-flight-deck) ![check](https://img.shields.io/github/actions/workflow/status/nathwn12/oc-flight-deck/check.yml)
8
+ [![npm version](https://img.shields.io/npm/v/oc-flight-deck)](https://www.npmjs.com/package/oc-flight-deck) [![license: MIT](https://img.shields.io/badge/license-MIT-blue)](./LICENSE) [![node >=22](https://img.shields.io/badge/node-%E2%89%A522-green)](https://nodejs.org) [![opencode v2](https://img.shields.io/badge/opencode-v2-blueviolet)](https://opencode.ai) [![npm weekly downloads](https://img.shields.io/npm/dw/oc-flight-deck)](https://www.npmjs.com/package/oc-flight-deck) [![CI](https://github.com/nathwn12/oc-flight-deck/actions/workflows/check.yml/badge.svg)](https://github.com/nathwn12/oc-flight-deck/actions/workflows/check.yml)
9
9
 
10
10
  </div>
11
11
 
@@ -13,6 +13,13 @@
13
13
 
14
14
  ## ⚡ Quick start
15
15
 
16
+ ```text
17
+ Install the oc-flight-deck OpenCode plugin:
18
+ 1. Add "oc-flight-deck" to the "plugins" array in ~/.config/opencode/opencode.jsonc.
19
+ 2. Restart OpenCode.
20
+ 3. Verify: the panel appears beside an open session.
21
+ ```
22
+
16
23
  Add the plugin to your `opencode.jsonc`:
17
24
 
18
25
  ```jsonc
@@ -34,9 +41,9 @@ branch main
34
41
  cost $0.245 · 2 subagents
35
42
  tokens 533k in · 91k out
36
43
  cache 98% hit · 32M read
37
- context ██░░░░░░░░ 18%
44
+ context ██░░░░░░░░ ~18%
38
45
  elapsed 2h 14m 37s
39
- tps 18.0 tok/s
46
+ tps 18 tok/s
40
47
  ```
41
48
 
42
49
  Every row is read from the open session at render time — except `caution`, which watches a clock rather than events (a hang emits none); `elapsed`, which is seeded once from the session's own recorded assistant turn spans and then accumulates the busy windows this run observes, rather than a value the session reports; and the opt-in `guard` row, which is polled from the local guard RPC.
@@ -54,17 +61,17 @@ The panel's only fixed text — `▸ FLIGHT DECK` over a separator — is **opt-
54
61
  | `total` | The family total and subagent count on a row of its own · **off by default** |
55
62
  | `project` | Every session in this project, not just the one on screen |
56
63
  | `tokens` | Input and output, cumulative |
57
- | `cache` | Hit rate first — the number that explains the bill — then cache reads |
58
- | `context` | A gauge of how full the window is |
64
+ | `cache` | Hit rate first - `read / (read + input)` - then cache reads. Cache writes are excluded from the rate (creating an entry is not a lookup) but counted in `context` occupancy (a written entry still occupies the window) |
65
+ | `context` | An estimated (`~`) gauge of how full the window is - occupancy is a proxy from the last request's `input + cache.read + cache.write`, not a host-reported figure |
59
66
  | `perms` | What is waiting for approval, not just how many |
60
67
  | `elapsed` | Active time — the clock runs only while this session, a subagent in its tree, or one of its shells is working, and freezes when everything settles. It is seeded once from the assistant turn spans the host already recorded for that session, so it survives a restart instead of resetting to `—`; work observed live after that keeps counting in memory. It measures active time, not wall-clock since the session began |
61
- | `tps` | Average speed **while streaming**: output **plus reasoning** tokens divided by the time the provider was actively streaming (`streamed - created`), subagents included. Idle time between turns and the tool settlement after a turn are never counted, so the figure freezes when everything settles instead of decaying or hiding; a turn still in flight counts up to now. On a host that exposes no per-message timestamps it falls back to the lifetime average, which includes idle and can therefore sag. Not configurable |
68
+ | `tps` | Live speed **while generating**: the output-token delta between polls over the generating-time delta (streaming spans, or the busy-gated active clock), smoothed and drawn whole - no decimals. Reasoning has its own row and is out of the numerator. Idle is never divided: the figure freezes when everything settles and hides until ~2 s of generating time and ~10 tokens are on record. Not configurable |
62
69
  | `spark` | Recent turn sizes as a shape · **off by default** |
63
70
  | `reasoning` | Reasoning tokens, when the model emits them · **off by default** |
64
71
  | `turns` | How many prompts you've sent this session · **off by default** |
65
72
  | `guard` | Harness status from oc-harness-guard · **off by default** |
66
73
  | `go` | Zen Go account usage — a dial and a whole-number percent for the **5h**, **1w**, and **1m** windows, in that fixed order; a window at 90% or more turns its dial and number red, and the reset hint appears only then · **off by default** |
67
- | `ses` | The open session id, which the rail wraps; **click the row** to copy the full id to the terminal clipboard · **off by default** (requires the host's mouse) |
74
+ | `ses` | An 18-wide clipped preview of the open session id (never the full id on the rail); **click the row** to copy the full id to the terminal clipboard . **off by default** (requires the host's mouse) |
68
75
 
69
76
  `project` matches on the host's **project id**, not on a directory, so a worktree counts as part of the same project. A host that reports no project id leaves nothing to match on, and the row then totals every session that host knows about.
70
77
 
@@ -74,9 +81,7 @@ Every field named in `sidebar.rows` renders exactly one row, in order. With `sid
74
81
 
75
82
  The `guard` row only appears when oc-harness-guard is installed and answering; without it the row stays on the placeholder. Flight Deck never installs or requires the other plugin — each side works alone.
76
83
 
77
- ---
78
-
79
- ## 🚨 `caution` — calibrated, not guessed
84
+ ### 🚨 `caution` — calibrated, not guessed
80
85
 
81
86
  A hang emits no events — its only signature is *absence*. So `caution` watches a clock, stays silent on healthy sessions, and when it speaks it reports what it saw, never what it means: `shell running 8m41s`, not "stuck".
82
87
 
@@ -155,7 +160,9 @@ Everything else lives in the example file, documented inline - a typo is never f
155
160
 
156
161
  ---
157
162
 
158
- ## 🔒 It reads. It writes almost nothing.
163
+ ## 🔒 Safety
164
+
165
+ **It reads. It writes almost nothing.**
159
166
 
160
167
  Flight Deck shows what OpenCode already knows.
161
168
 
@@ -211,6 +218,12 @@ Built on the official [OpenCode V2 CLI plugin API](https://opencode.ai/v2/docs/b
211
218
 
212
219
  ---
213
220
 
221
+ ## 📄 License
222
+
223
+ MIT © 2026 nathwn12 — see [LICENSE](./LICENSE).
224
+
225
+ ---
226
+
214
227
  <div align="center">
215
228
 
216
229
  Built against `@opencode/plugin` 2.0.19 · Node ≥ 22 / Bun ≥ 1.4 · OpenCode V2
@@ -213,7 +213,7 @@
213
213
  // times, with a p99 of 14.7 minutes. Without this list the annunciator
214
214
  // lights on every delegated task - which is how an alert gets ignored.
215
215
  // Add your own long-running or orchestration tools here.
216
- "exemptTools": ["question", "task", "subagent", "agent", "delegate", "delegate_many", "delegate_task"],
216
+ "exemptTools": ["question", "task", "subagent", "agent", "delegate", "delegate_many", "delegate_task", "tools.delegate", "tools.delegate_many", "tools.subagent", "tools.task"],
217
217
 
218
218
  // Also raise a toast, once per distinct problem, re-arming when the session
219
219
  // goes quiet. Off by default: the rail is the signal, a notification is an
@@ -253,7 +253,7 @@
253
253
  // an unreadable one. One or two characters each.
254
254
  "glyphs": {
255
255
  "watch": "▲",
256
- "caution": "⚠",
256
+ "caution": "●",
257
257
  "clear": "○"
258
258
  },
259
259
 
@@ -55,7 +55,7 @@
55
55
  "items": { "enum": ["caution", "status", "agent", "model", "branch", "cost", "total", "project", "tokens", "cache", "context", "perms", "elapsed", "tps", "spark", "reasoning", "turns", "guard", "go", "ses"] },
56
56
  "default": ["status", "agent", "model", "cost", "project", "tokens", "cache", "context", "perms", "elapsed", "tps"],
57
57
  "maxItems": 24,
58
- "description": "Which live fields to draw, top to bottom. Any subset, any order - this is the single most useful thing to change. With `sidebar.persist` (the default) every named row always renders, using `sidebar.placeholder` until the host has data; with `persist: false` rows with no data are omitted entirely. Counted together with `sidebar.lines` against a 24-line cap on the whole rail. The opt-in `ses` row shows the full session id (the rail wraps it); a mouse click on that row copies the full id to the terminal clipboard."
58
+ "description": "Which live fields to draw, top to bottom. Any subset, any order - this is the single most useful thing to change. With `sidebar.persist` (the default) every named row always renders, using `sidebar.placeholder` until the host has data; with `persist: false` rows with no data are omitted entirely. Counted together with `sidebar.lines` against a 24-line cap on the whole rail. The opt-in `ses` row shows an 18-wide clipped preview of the session id; a mouse click on that row copies the full id to the terminal clipboard."
59
59
  },
60
60
  "persist": {
61
61
  "type": "boolean",
@@ -73,7 +73,7 @@
73
73
  "minimum": 1,
74
74
  "maximum": 24,
75
75
  "default": 24,
76
- "description": "Maximum height of the whole rail, including fixed lines and live rows. Defaults to 24 and may be lowered from 1 to 23; lines past the limit are dropped."
76
+ "description": "Maximum height of the whole rail, including fixed lines and live rows. Defaults to 24 and may be lowered from 1 to 24; lines past the limit are dropped."
77
77
  }
78
78
  }
79
79
  },
@@ -115,7 +115,7 @@
115
115
  "type": "integer",
116
116
  "minimum": 0,
117
117
  "default": 420,
118
- "description": "A tool running longer than this becomes a real ⚠. Raised to match toolWatchSeconds if set below it, and reported."
118
+ "description": "A tool running longer than this becomes a real ●. Raised to match toolWatchSeconds if set below it, and reported."
119
119
  },
120
120
  "turnWatchSeconds": {
121
121
  "type": "integer",
@@ -127,7 +127,7 @@
127
127
  "type": "integer",
128
128
  "minimum": 0,
129
129
  "default": 1200,
130
- "description": "A quiet session becomes a real ⚠ after this long. Raised to match turnWatchSeconds if set below it, and reported."
130
+ "description": "A quiet session becomes a real ● after this long. Raised to match turnWatchSeconds if set below it, and reported."
131
131
  },
132
132
  "repeatThreshold": {
133
133
  "type": "integer",
@@ -138,7 +138,7 @@
138
138
  "exemptTools": {
139
139
  "type": "array",
140
140
  "items": { "type": "string", "minLength": 1 },
141
- "default": ["question", "task", "subagent", "agent", "delegate", "delegate_many", "delegate_task"],
141
+ "default": ["question", "task", "subagent", "agent", "delegate", "delegate_many", "delegate_task", "tools.delegate", "tools.delegate_many", "tools.subagent", "tools.task"],
142
142
  "description": "Tools that are slow by nature, so slow is not an anomaly for them. Matched by exact name. Calibrated against 54,218 real settled tool calls: at the default threshold 307 calls exceed it and 200 of those are these tools — `subagent` alone crossed 152 times with a p99 of 14.7 minutes. Without this list the annunciator lights on every delegated task, which is how an alert gets ignored. Add your own long-running or orchestration tools here."
143
143
  },
144
144
  "toast": {
@@ -208,7 +208,7 @@
208
208
  "type": "string",
209
209
  "minLength": 1,
210
210
  "maxLength": 2,
211
- "default": "⚠",
211
+ "default": "●",
212
212
  "description": "Shown for a real caution. This is the row that has to read at a glance."
213
213
  },
214
214
  "clear": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oc-flight-deck",
3
- "version": "0.10.3",
3
+ "version": "0.11.0",
4
4
  "description": "Live OpenCode V2 session telemetry — agent, model, branch, cost, tokens, cache hit rate and context usage in your sidebar.",
5
5
  "keywords": [
6
6
  "opencode",
@@ -62,6 +62,7 @@
62
62
  "@opentui/solid": "0.5.12",
63
63
  "@types/bun": "^1.4.2",
64
64
  "solid-js": "1.9.15",
65
+ "string-width": "7.2.0",
65
66
  "typescript": "^5.9.3"
66
67
  },
67
68
  "peerDependencies": {
@@ -71,6 +71,12 @@ interface ActiveState {
71
71
  * the boundary. Undercount is acceptable, over-count is not.
72
72
  */
73
73
  export function createActiveElapsed(isBusy: BusyRead, options: ActiveElapsedOptions = {}) {
74
+ // One entry per viewed session, bounded: without eviction a TUI lifetime of
75
+ // session-hopping grows this map forever. Eviction only drops a stale tally -
76
+ // a revisit rebaselines and re-seeds from the host, exactly like a first
77
+ // sight. Recency refreshes on every read, so the watched session is always
78
+ // the last one evicted.
79
+ const MAX_STATES = 50;
74
80
  const states = new Map<string, ActiveState>();
75
81
  // The module's own contract must hold without the caller opting in; the
76
82
  // production caller still passes its own derived bound.
@@ -97,7 +103,7 @@ export function createActiveElapsed(isBusy: BusyRead, options: ActiveElapsedOpti
97
103
  if (state === undefined) {
98
104
  // First sight of this session: take the seed once, here, so the record
99
105
  // covers everything up to the moment observation begins and the
100
- // accumulator below covers everything after — no overlap, no double
106
+ // accumulator below covers everything after - no overlap, no double
101
107
  // count. Floored at zero; a non-finite or throwing read is zero.
102
108
  let seed = 0;
103
109
  if (options.seedOf !== undefined) {
@@ -109,13 +115,23 @@ export function createActiveElapsed(isBusy: BusyRead, options: ActiveElapsedOpti
109
115
  }
110
116
  }
111
117
  state = { accumulated: seed, lastAt: now, running: false };
118
+ if (states.size >= MAX_STATES) {
119
+ for (const oldest of states.keys()) {
120
+ states.delete(oldest);
121
+ break;
122
+ }
123
+ }
112
124
  states.set(sessionID, state);
113
- } else if (!boundary && state.running && busy) {
114
- // Only a window that was busy at BOTH ends and short enough to have been
115
- // observed is work. A settled gap is idle; a stalled or stepped-back
116
- // clock must never subtract; an over-long window was not watched.
117
- const delta = now - state.lastAt;
118
- if (delta > 0 && delta <= maxBankedMs) state.accumulated += delta;
125
+ } else {
126
+ states.delete(sessionID);
127
+ states.set(sessionID, state);
128
+ if (!boundary && state.running && busy) {
129
+ // Only a window that was busy at BOTH ends and short enough to have been
130
+ // observed is work. A settled gap is idle; a stalled or stepped-back
131
+ // clock must never subtract; an over-long window was not watched.
132
+ const delta = now - state.lastAt;
133
+ if (delta > 0 && delta <= maxBankedMs) state.accumulated += delta;
134
+ }
119
135
  }
120
136
 
121
137
  state.running = busy;
@@ -339,7 +339,7 @@ export function worstCaution(cautions: readonly Caution[]): Caution | undefined
339
339
  // ---------------------------------------------------------------------------
340
340
 
341
341
  export const WATCH_GLYPH = "▲";
342
- export const CAUTION_GLYPH = "⚠";
342
+ export const CAUTION_GLYPH = "●";
343
343
  const CLEAR_GLYPH = "○";
344
344
 
345
345
  /**
@@ -358,9 +358,8 @@ export function glyphFor(caution: Caution | undefined, glyphs: GlyphHint = {}):
358
358
  return caution.severity === "caution" ? (glyphs.caution ?? CAUTION_GLYPH) : (glyphs.watch ?? WATCH_GLYPH);
359
359
  }
360
360
 
361
- /** The short value beside the label. Says what was seen, not what it means. */
362
- export function cautionText(caution: Caution, glyphs: GlyphHint = {}): string {
363
- const glyph = glyphFor(caution, glyphs);
361
+ /** Everything after the mark: what was seen, with no severity and no colour. */
362
+ function cautionBody(caution: Caution): string {
364
363
  const elapsed = caution.elapsedMs === undefined ? "" : ` ${formatElapsed(caution.elapsedMs)}`;
365
364
  switch (caution.kind) {
366
365
  case "hung-tool": {
@@ -368,21 +367,49 @@ export function cautionText(caution: Caution, glyphs: GlyphHint = {}): string {
368
367
  // is a different situation from a tool that is executing and has not
369
368
  // returned. Calling both "running" would be a small lie.
370
369
  const phase = caution.status === "streaming" ? "streaming" : "running";
371
- return `${glyph} ${caution.tool ?? "tool"} ${phase}${elapsed}`;
370
+ return `${caution.tool ?? "tool"} ${phase}${elapsed}`;
372
371
  }
373
372
  case "hung-shell":
374
- return `${glyph} ${caution.tool ?? "shell"} running${elapsed}`;
373
+ return `${caution.tool ?? "shell"} running${elapsed}`;
375
374
  case "repeat-loop":
376
- return `${glyph} ${caution.tool ?? "tool"} ×${caution.repeats ?? 0} identical`;
375
+ return `${caution.tool ?? "tool"} ×${caution.repeats ?? 0} identical`;
377
376
  case "failure-loop":
378
- return `${glyph} ${caution.tool ?? "tool"} failing ×${caution.repeats ?? 0}`;
377
+ return `${caution.tool ?? "tool"} failing ×${caution.repeats ?? 0}`;
379
378
  case "silent-turn":
380
- return `${glyph} no progress${elapsed}`;
379
+ return `no progress${elapsed}`;
381
380
  default:
382
- return `${glyph} unknown`;
381
+ return "unknown";
383
382
  }
384
383
  }
385
384
 
385
+ /**
386
+ * The annunciator's mark: its one-cell glyph, the theme role its severity draws
387
+ * in, and the exact row text (`cautionText`'s value).
388
+ *
389
+ * The tone is structural on purpose, like `GlyphHint`: this module stays free
390
+ * of imports, and the caller maps the role onto a theme colour.
391
+ */
392
+ export interface CautionMark {
393
+ readonly glyph: string;
394
+ /** `error` for a caution, `warning` for a watch — the rail's own roles. */
395
+ readonly tone: "warning" | "error";
396
+ readonly text: string;
397
+ }
398
+
399
+ export function cautionMark(caution: Caution, glyphs: GlyphHint = {}): CautionMark {
400
+ const glyph = glyphFor(caution, glyphs);
401
+ return {
402
+ glyph,
403
+ tone: caution.severity === "caution" ? "error" : "warning",
404
+ text: `${glyph} ${cautionBody(caution)}`,
405
+ };
406
+ }
407
+
408
+ /** The short value beside the label. Says what was seen, not what it means. */
409
+ export function cautionText(caution: Caution, glyphs: GlyphHint = {}): string {
410
+ return cautionMark(caution, glyphs).text;
411
+ }
412
+
386
413
  /** The longer sentence, used for the toast. States the observation, then the readings. */
387
414
  export function cautionDetail(caution: Caution): string {
388
415
  const elapsed = caution.elapsedMs === undefined ? "a while" : formatElapsed(caution.elapsedMs);
package/src/tui/config.ts CHANGED
@@ -159,11 +159,13 @@ interface LayoutConfig {
159
159
  }
160
160
 
161
161
  /**
162
- * The annunciator's glyphs.
162
+ * The annunciator's glyphs: one mark per severity.
163
163
  *
164
- * Configurable because this is the one row that has to read at a glance, and
165
- * some terminals render `⚠` as a box or the wrong width. Swapping it for `!` is
166
- * a worse-looking but working panel, which beats an unreadable one.
164
+ * All three are single-cell marks — `▲` watch, `●` caution, `○` clear — so the
165
+ * annunciator row lines up with every other row on the rail regardless of how
166
+ * the terminal classifies their East Asian width. Configurable because this is
167
+ * the one row that has to read at a glance, and a terminal that draws one of
168
+ * these badly can be given a substitute without a rebuild.
167
169
  */
168
170
  interface GlyphConfig {
169
171
  readonly watch: string;
@@ -196,7 +198,7 @@ const DEFAULT_FORMAT: FormatConfig = { duration: "spaced" };
196
198
 
197
199
  const DEFAULT_GLYPHS: GlyphConfig = {
198
200
  watch: "▲",
199
- caution: "⚠",
201
+ caution: "●",
200
202
  clear: "○",
201
203
  };
202
204
 
@@ -207,7 +209,7 @@ const DEFAULT_CAUTION: CautionConfig = {
207
209
  turnWatchSeconds: 600,
208
210
  turnCautionSeconds: 1200,
209
211
  repeatThreshold: 3,
210
- exemptTools: ["question", "task", "subagent", "agent", "delegate", "delegate_many", "delegate_task"],
212
+ exemptTools: ["question", "task", "subagent", "agent", "delegate", "delegate_many", "delegate_task", "tools.delegate", "tools.delegate_many", "tools.subagent", "tools.task"],
211
213
  /**
212
214
  * Off by default. The rail is the signal; a toast is an interruption.
213
215
  *
package/src/tui/format.ts CHANGED
@@ -64,21 +64,69 @@ export function fuelBar(ratio: number, width: number = DEFAULT_BAR_WIDTH): strin
64
64
 
65
65
  const SPARK_LEVELS = ["▁", "▂", "▃", "▄", "▅", "▆", "▇", "█"] as const;
66
66
 
67
+ /**
68
+ * Terminal cell width of one code point: East Asian wide/fullwidth ranges and
69
+ * emoji take two cells, everything else one. Deliberately conservative - an
70
+ * ambiguous or unknown character counts one, so the rail may clip slightly
71
+ * early but can never overrun its column. Combines nothing: a combining mark
72
+ * counts one for the same reason, since over-counting only ever clips earlier.
73
+ */
74
+ function cellWidthOf(code: number): number {
75
+ if (
76
+ (code >= 0x1100 && code <= 0x115f) ||
77
+ code === 0x2329 ||
78
+ code === 0x232a ||
79
+ (code >= 0x2e80 && code <= 0xa4cf) ||
80
+ (code >= 0xac00 && code <= 0xd7a3) ||
81
+ (code >= 0xf900 && code <= 0xfaff) ||
82
+ (code >= 0xfe10 && code <= 0xfe19) ||
83
+ (code >= 0xfe30 && code <= 0xfe4f) ||
84
+ (code >= 0xff00 && code <= 0xff60) ||
85
+ (code >= 0xffe0 && code <= 0xffe6) ||
86
+ (code >= 0x20000 && code <= 0x3fffd) ||
87
+ (code >= 0x2600 && code <= 0x27bf) ||
88
+ (code >= 0x2b00 && code <= 0x2bff) ||
89
+ (code >= 0x1f000 && code <= 0x1faff)
90
+ ) {
91
+ return 2;
92
+ }
93
+ return 1;
94
+ }
95
+
96
+ /** The columns a string draws: its cell width, not its length. */
97
+ function cellWidth(text: string): number {
98
+ let width = 0;
99
+ for (const char of text) width += cellWidthOf(char.codePointAt(0) ?? 0);
100
+ return width;
101
+ }
102
+
67
103
  /**
68
104
  * Shorten a value for a narrow rail.
69
105
  *
70
106
  * The sidebar is roughly thirty-odd columns wide and the label already costs
71
107
  * ten, so a resource path has to be cut. The ellipsis is deliberate: a silently
72
- * truncated path reads as a complete one.
108
+ * truncated path reads as a complete one. The budget is CELLS, not characters:
109
+ * a CJK or emoji value that fits in characters can still draw twice as wide,
110
+ * so the cut keeps the longest prefix of at most `max - 1` cells and reserves
111
+ * the last cell for the ellipsis. Iterating by code point never splits a
112
+ * surrogate pair, so the orphaned-half guard the length-based cut needed is
113
+ * structurally gone.
73
114
  */
74
115
  export function clip(text: string, max: number): string {
75
- if (text.length <= max) return text;
76
- const cut = text.slice(0, Math.max(1, max - 1));
77
- // Never cut a surrogate pair in half: the orphaned half renders as a
78
- // replacement character, which reads as corruption rather than as a shortened
79
- // path. Losing one more column is the cheaper mistake.
80
- const safe = /[\uD800-\uDBFF]$/.test(cut) ? cut.slice(0, -1) : cut;
81
- return `${safe}…`;
116
+ const ellipsis = String.fromCharCode(0x2026);
117
+ if (cellWidth(text) <= max) return text;
118
+ const budget = max - 1;
119
+ let kept = "";
120
+ let width = 0;
121
+ for (const char of text) {
122
+ const next = width + cellWidthOf(char.codePointAt(0) ?? 0);
123
+ // The first character is always kept, mirroring the old floor: a budget
124
+ // below one cell still shortens rather than returning a bare ellipsis.
125
+ if (kept !== "" && next > budget) break;
126
+ kept += char;
127
+ width = next;
128
+ }
129
+ return `${kept}${ellipsis}`;
82
130
  }
83
131
 
84
132
  /**
package/src/tui/index.tsx CHANGED
@@ -1,6 +1,13 @@
1
1
  /** @jsxImportSource @opentui/solid */
2
2
  import { Plugin } from "@opencode/plugin/tui";
3
- import { cautionDetail, cautionText, detectCautions, worstCaution, type Caution } from "./caution.js";
3
+ import {
4
+ cautionDetail,
5
+ cautionMark,
6
+ detectCautions,
7
+ worstCaution,
8
+ type Caution,
9
+ type CautionMark,
10
+ } from "./caution.js";
4
11
  import { copyFeedback, copyToClipboard } from "./clipboard.js";
5
12
  import { cautionThresholds, mergeOptions, resolveConfig } from "./config.js";
6
13
  import { loadConfigFile } from "./file-config.js";
@@ -169,7 +176,10 @@ export default Plugin.define({
169
176
  thresholds: cautionThreshold,
170
177
  });
171
178
 
172
- const { sessionTps } = createTpsReader(context, isFamilyRoot);
179
+ const { sessionTps } = createTpsReader(context, isFamilyRoot, {
180
+ busyOf: busy,
181
+ elapsedMsOf: (id, now) => sessionElapsed(id, now),
182
+ });
173
183
 
174
184
  // Recent turn sizes, oldest first. Drawn from messages the host already
175
185
  // holds, so the sparkline needs no history of our own to accumulate.
@@ -216,14 +226,13 @@ export default Plugin.define({
216
226
  // Only the worst is ever drawn: the rail has one line for this, and two
217
227
  // simultaneous observations is one problem with two symptoms.
218
228
  //
219
- // Returns a plain string, themed exactly like every other live row. The
220
- // annunciator carries its meaning in its glyph, not in a colour of its own:
221
- // a row that suddenly brightens reads as a different kind of thing rather
222
- // than as the same panel telling you something.
223
- const announce = (sessionID: string): string | undefined => {
229
+ // Returns the mark itself, not just its text: severity survives to the
230
+ // renderer as the mark's own tone, so the glyph takes the rail's error or
231
+ // warning colour while the rest of the row keeps its own.
232
+ const announce = (sessionID: string): CautionMark | undefined => {
224
233
  if (!config.caution.enabled) return undefined;
225
234
  const top = worstCaution(cautionsOf(sessionID, Date.now()));
226
- return top === undefined ? undefined : cautionText(top, config.glyphs);
235
+ return top === undefined ? undefined : cautionMark(top, config.glyphs);
227
236
  };
228
237
 
229
238
  // A VCS call on a directory with no repository must not throw and take the
@@ -23,8 +23,9 @@ export interface RailLine {
23
23
  readonly field?: string;
24
24
  /**
25
25
  * The same line split into coloured runs, when a row's severity lives on part
26
- * of it (only `go` today). `text` is always the exact join of these segments,
27
- * so a caller that ignores them draws the row unchanged.
26
+ * of it (the `go` dials and the `caution` mark). `text` is always the exact
27
+ * join of these segments, so a caller that ignores them draws the row
28
+ * unchanged.
28
29
  */
29
30
  readonly segments?: readonly StatSegment[];
30
31
  }