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 +24 -0
- package/README.md +24 -11
- package/flight-deck.example.jsonc +2 -2
- package/flight-deck.schema.json +6 -6
- package/package.json +2 -1
- package/src/tui/active-elapsed.ts +23 -7
- package/src/tui/caution.ts +37 -10
- package/src/tui/config.ts +8 -6
- package/src/tui/format.ts +56 -8
- package/src/tui/index.tsx +17 -8
- package/src/tui/presentation.ts +3 -2
- package/src/tui/rows.ts +88 -16
- package/src/tui/session-reads.ts +35 -6
- package/src/tui/session-tps.ts +123 -72
- package/src/tui/stat-fields.ts +15 -11
- package/src/tui/stats.ts +10 -0
- package/src/tui/throughput.ts +187 -7
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
|
-
   ](https://www.npmjs.com/package/oc-flight-deck) [](./LICENSE) [](https://nodejs.org) [](https://opencode.ai) [](https://www.npmjs.com/package/oc-flight-deck) [](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
|
|
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
|
|
58
|
-
| `context` |
|
|
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` |
|
|
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` |
|
|
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
|
-
## 🔒
|
|
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
|
|
package/flight-deck.schema.json
CHANGED
|
@@ -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
|
|
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
|
|
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
|
|
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
|
|
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.
|
|
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
|
|
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
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
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;
|
package/src/tui/caution.ts
CHANGED
|
@@ -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
|
-
/**
|
|
362
|
-
|
|
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 `${
|
|
370
|
+
return `${caution.tool ?? "tool"} ${phase}${elapsed}`;
|
|
372
371
|
}
|
|
373
372
|
case "hung-shell":
|
|
374
|
-
return `${
|
|
373
|
+
return `${caution.tool ?? "shell"} running${elapsed}`;
|
|
375
374
|
case "repeat-loop":
|
|
376
|
-
return `${
|
|
375
|
+
return `${caution.tool ?? "tool"} ×${caution.repeats ?? 0} identical`;
|
|
377
376
|
case "failure-loop":
|
|
378
|
-
return `${
|
|
377
|
+
return `${caution.tool ?? "tool"} failing ×${caution.repeats ?? 0}`;
|
|
379
378
|
case "silent-turn":
|
|
380
|
-
return
|
|
379
|
+
return `no progress${elapsed}`;
|
|
381
380
|
default:
|
|
382
|
-
return
|
|
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
|
-
*
|
|
165
|
-
*
|
|
166
|
-
*
|
|
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
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
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 {
|
|
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
|
|
220
|
-
//
|
|
221
|
-
//
|
|
222
|
-
|
|
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 :
|
|
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
|
package/src/tui/presentation.ts
CHANGED
|
@@ -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 (
|
|
27
|
-
* so a caller that ignores them draws the row
|
|
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
|
}
|