oc-flight-deck 0.6.3 → 0.6.6

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/README.md CHANGED
@@ -37,11 +37,11 @@ cost $0.245 · 2 subagents
37
37
  tokens 533k in · 91k out
38
38
  cache 98% hit · 32M read
39
39
  context ██░░░░░░░░ 18%
40
- elapsed 2h14m37s
40
+ elapsed 2h 14m 37s
41
41
  tps 18 tok/s
42
42
  ```
43
43
 
44
- Every row is read from the open session at render time — except `caution`, which watches a clock rather than events (a hang emits none), and the opt-in `guard` row, which is polled from the local guard RPC.
44
+ 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 a process-local tally of the busy windows this run observed rather than a value the session reports; and the opt-in `guard` row, which is polled from the local guard RPC.
45
45
 
46
46
  | Row | What it shows |
47
47
  |---|---|
@@ -57,8 +57,8 @@ Every row is read from the open session at render time — except `caution`, whi
57
57
  | `cache` | Hit rate first — the number that explains the bill — then cache reads |
58
58
  | `context` | A gauge of how full the window is |
59
59
  | `perms` | What is waiting for approval, not just how many |
60
- | `elapsed` | How long you've been at it |
61
- | `tps` | Current speed: output tokens in the last 60 s, divided by that window, subagents included. Idle longer than the window and it hides — the `status` row already says `idle`. On a host that exposes no per-message timestamps it falls back to the lifetime average, which does not hide while idle and reads lower than a peak per-turn rate. Fixed at 60 s, not configurable |
60
+ | `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 process-local and starts at zero when the plugin starts, so it measures activity observed this run, not wall-clock since the session began |
61
+ | `tps` | Average speed **while working**: output tokens divided by the time the assistant's turns actually ran, subagents included. Idle time between turns is 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 |
62
62
  | `spark` | Recent turn sizes as a shape · **off by default** |
63
63
  | `reasoning` | Reasoning tokens, when the model emits them · **off by default** |
64
64
  | `turns` | How many prompts you've sent this session · **off by default** |
@@ -106,19 +106,33 @@ The file is optional, and a missing file is normal and silent: with no file at a
106
106
 
107
107
  > **Upgrading from 0.4.0 — the config file moved.** The per-project search is gone. A `flight-deck.jsonc` in a project root or in `.opencode/` is no longer read; move it to `~/.config/opencode/flight-deck.jsonc` (or the `$XDG_CONFIG_HOME` path above) to keep your settings.
108
108
 
109
- `sidebar.rows` picks the rows and their order; `layout.labelWidth` fits your terminal. Everything else lives in the example file, documented inline — a typo is never fatal: the bad value is ignored, the default comes back, and you get a one-time toast naming the key to fix.
109
+ `sidebar.rows` picks the rows and their order; `sidebar.maxLines` caps the whole rail (fixed lines plus rows, default 24, configurable from 1 to 24); `layout.labelWidth` fits your terminal; `format.duration` switches the `elapsed` row between `spaced` (`2h 14m 37s`, the default) and `compact` (`2h14m37s`).
110
+
111
+ Optional styling lives under `style`: `style.lines` controls fixed branding/separator lines, `style.rows."*"` sets every live row, and `style.rows.cost` (or another row name) overrides one field while inheriting omitted values from the wildcard. Colors are theme roles - `default`, `subdued`, `warning`, `error`, `success`, `info` - and attributes are OpenTUI descriptors: `bold`, `dim`, `italic`, `underline`, `blink`, `inverse`, `hidden`, `strikethrough`. Defaults keep the existing theme-native look; no ANSI escapes or raw colors are needed. Invalid colors, attributes, and row names are reported and safely ignored.
112
+
113
+ Everything else lives in the example file, documented inline - a typo is never fatal: the bad value is ignored, the default comes back, and you get a one-time toast naming the key to fix.
110
114
 
111
115
  ```jsonc
112
116
  // ~/.config/opencode/flight-deck.jsonc
113
117
  {
114
118
  "refresh": 100,
115
119
  "sidebar": {
120
+ "maxLines": 24,
116
121
  "rows": [
117
122
  "caution", "status", "agent", "model", "branch", "cost", "project",
118
123
  "tokens", "cache", "context", "perms", "elapsed", "tps"
119
124
  ]
120
125
  },
121
- "caution": { "toast": false }
126
+ // spaced separates the units (2h 14m 37s, the default); "compact" hugs them (2h14m37s)
127
+ "format": { "duration": "spaced" },
128
+ "caution": { "toast": false },
129
+ "style": {
130
+ "lines": { "color": "default", "attributes": [] },
131
+ "rows": {
132
+ "*": { "color": "subdued", "attributes": [] },
133
+ "cost": { "color": "success", "attributes": ["bold"] }
134
+ }
135
+ }
122
136
  }
123
137
  ```
124
138
 
@@ -130,7 +144,7 @@ Flight Deck shows what OpenCode already knows.
130
144
 
131
145
  - **No network calls while the opt-in `guard` row stays off.** Nothing is fetched, nothing is sent. With `guard` enabled, the panel polls the local guard RPC — same machine, no telemetry — about every ten seconds, plus right away when the rendered session changes.
132
146
  - **No telemetry.** Nothing is collected or phoned home.
133
- - **Nothing on disk.** The one thing it normally writes is an animation counter in the host's in-memory plugin state, so the spinner and `elapsed` keep moving between turns. It is scoped to this plugin and dies with the TUI; it is never persisted, and `"refresh": 0` removes even that. With `guard` enabled there is a second in-memory write — that row's polled status — and `"refresh": 0` does not remove it; dropping `guard` from `sidebar.rows` does.
147
+ - **Nothing on disk.** The one thing it normally writes is an animation counter in the host's in-memory plugin state, so the spinner and a running `elapsed` clock keep moving between host events. It is scoped to this plugin and dies with the TUI; it is never persisted, and `"refresh": 0` removes even that. With `"refresh": 0` the rail re-reads only on host events, so a busy stretch that produces few events can undercount `elapsed` — no unobserved gap bills beyond its bound, and a longer gap banks nothing. With `guard` enabled there is a second in-memory write — that row's polled status — and `"refresh": 0` does not remove it; dropping `guard` from `sidebar.rows` does.
134
148
  - **No polling of your session while `guard` stays off.** Cost, tokens, and permissions update from the host's own events. The timer only re-reads state the host already holds in memory, so the clock-derived rows keep moving.
135
149
  - **Theme-native.** Every line uses your active theme's text tokens, so it blends with whatever look you already run.
136
150
 
@@ -46,7 +46,8 @@
46
46
  // 100 default — the spinner turns once a second, the clock stays live
47
47
  // 50 twice as lively, still negligible work per tick
48
48
  // 1000 a calm wall-clock tick, but the spinner visibly stutters
49
- // 0 no timer; `elapsed` and the spinner only move when the session does
49
+ // 0 no timer; `elapsed` and the spinner only move when the session does,
50
+ // so a busy stretch with few host events can undercount the clock
50
51
  //
51
52
  // Anything faster than 16 (one frame at 60Hz) is clamped: a tick wakes the
52
53
  // host's renderer, so a smaller value spends work without adding motion.
@@ -59,8 +60,8 @@
59
60
 
60
61
  // Fixed lines, rendered above the live rows. This is the only text Flight
61
62
  // Deck shows of its own — put your own words here, or a rule.
62
- // The first line uses your theme's primary text colour; the rest use the
63
- // subdued colour.
63
+ // Fixed lines use style.lines; live rows use their style.rows entry or the
64
+ // wildcard. With no custom style, the shipped theme-native look is kept.
64
65
  "lines": ["✈ FLIGHT DECK", "─────────────────"],
65
66
 
66
67
  // The live rows, top to bottom. Every value is read from the open session,
@@ -81,11 +82,17 @@
81
82
  // cache cache hit rate, then cache reads
82
83
  // context a gauge of how full the context window is
83
84
  // perms what is waiting for approval, not just how many
84
- // elapsed wall-clock time since the session started
85
- // tps current speed: output tokens in the last 60 seconds,
86
- // subagents included. Hides while idle longer than the
87
- // window; falls back to the session's lifetime average on
88
- // hosts with no per-message timestamps
85
+ // elapsed active time: the clock runs only while this session — or a
86
+ // subagent in its tree, or one of its shells — is working, and
87
+ // freezes when everything settles. Process-local: it starts at
88
+ // zero with the plugin and counts only activity this run saw
89
+ // tps average speed while working: output tokens divided by the
90
+ // time the assistant's turns actually ran, subagents included.
91
+ // Idle between turns is never counted, so the figure freezes
92
+ // when everything settles rather than decaying or hiding; a
93
+ // turn still in flight counts up to now. On a host with no
94
+ // per-message timestamps it falls back to the lifetime
95
+ // average, which includes idle and can sag
89
96
  // spark recent turn sizes as a sparkline
90
97
  // reasoning reasoning tokens, when the model emits them
91
98
  // turns how many prompts you have sent this session
@@ -94,8 +101,8 @@
94
101
  //
95
102
  // Every named row renders persistently, so the rail keeps a stable shape:
96
103
  // a row with no data yet shows the placeholder below, in the same label
97
- // column as a live row. The fixed lines and the live rows together are
98
- // capped at 24, and anything past that is dropped.
104
+ // column as a live row. The fixed lines and live rows share the maxLines
105
+ // budget below, and anything past it is dropped.
99
106
  "rows": [
100
107
  "caution",
101
108
  "status",
@@ -118,7 +125,10 @@
118
125
  "persist": true,
119
126
 
120
127
  // Value shown for a persistent row with no data yet. Any non-empty string.
121
- "placeholder": "—"
128
+ "placeholder": "—",
129
+
130
+ // Maximum total height, including fixed lines and live rows. Defaults to 24.
131
+ "maxLines": 24
122
132
  },
123
133
 
124
134
  // ── Footer ───────────────────────────────────────────────────────────────
@@ -196,6 +206,18 @@
196
206
  "sparkWidth": 12
197
207
  },
198
208
 
209
+ // -- Format ----------------------------------------------------------------
210
+ // How values are written on the rail. Display only: nothing here changes
211
+ // what is measured, only how a number is drawn.
212
+ "format": {
213
+ // How the elapsed row joins its segments.
214
+ // "spaced" one space between units: 2h 14m 37s (the default)
215
+ // "compact" no space between units: 2h14m37s
216
+ // Zero-padding is the same either way: minutes pad when hours are present,
217
+ // seconds pad when minutes are present, so 2h 14m 07s never reads 2h 14m 7s.
218
+ "duration": "spaced"
219
+ },
220
+
199
221
  // -- Glyphs ----------------------------------------------------------------
200
222
  // The annunciator's characters. Change these if your terminal renders a
201
223
  // default as a box or at the wrong width - an ugly but readable panel beats
@@ -204,5 +226,19 @@
204
226
  "watch": "▲",
205
227
  "caution": "⚠",
206
228
  "clear": "○"
229
+ },
230
+
231
+ // -- Style -----------------------------------------------------------------
232
+ // Optional appearance, resolved through your active theme (no ANSI escapes).
233
+ // Colors are theme roles: default, subdued, warning, error, success, info.
234
+ // Attributes: bold, dim, italic, underline, blink, inverse, hidden,
235
+ // strikethrough. The values below are the defaults.
236
+ "style": {
237
+ "lines": { "color": "default", "attributes": [] },
238
+ "rows": {
239
+ "*": { "color": "subdued", "attributes": [] }
240
+ // Uncomment an override to make one row stand out:
241
+ // ,"cost": { "color": "success", "attributes": ["bold"] }
242
+ }
207
243
  }
208
244
  }
@@ -53,6 +53,13 @@
53
53
  "minLength": 1,
54
54
  "default": "—",
55
55
  "description": "Value shown for a persistent row with no data yet. Used only when `sidebar.persist` is true. Must be a non-empty string; anything else falls back to the default em dash."
56
+ },
57
+ "maxLines": {
58
+ "type": "integer",
59
+ "minimum": 1,
60
+ "maximum": 24,
61
+ "default": 24,
62
+ "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."
56
63
  }
57
64
  }
58
65
  },
@@ -157,6 +164,20 @@
157
164
  }
158
165
  },
159
166
 
167
+ "format": {
168
+ "type": "object",
169
+ "additionalProperties": false,
170
+ "description": "How values are written on the rail. Display only: these options change how a number is drawn, never what is measured.",
171
+ "properties": {
172
+ "duration": {
173
+ "type": "string",
174
+ "enum": ["spaced", "compact"],
175
+ "default": "spaced",
176
+ "description": "How the `elapsed` row joins its segments. `spaced` puts one space between them (`2h 14m 37s`, the default); `compact` runs them together (`2h14m37s`). Zero-padding is identical either way: minutes pad when hours are present, seconds pad when minutes are present (`14m 07s`, never `14m 7s`). An invalid value falls back to `spaced` and is reported."
177
+ }
178
+ }
179
+ },
180
+
160
181
  "glyphs": {
161
182
  "type": "object",
162
183
  "additionalProperties": false,
@@ -184,6 +205,61 @@
184
205
  "description": "Reserved for a future always-visible annunciator state. Not currently drawn: the row is absent when nothing is wrong."
185
206
  }
186
207
  }
208
+ },
209
+
210
+ "style": {
211
+ "type": "object",
212
+ "additionalProperties": false,
213
+ "description": "Optional per-line text styling. Colors are theme roles, not ANSI codes; attributes use OpenTUI text descriptor names. An absent style keeps the theme-native default appearance.",
214
+ "properties": {
215
+ "lines": {
216
+ "type": "object",
217
+ "additionalProperties": false,
218
+ "default": { "color": "default", "attributes": [] },
219
+ "description": "Appearance shared by the fixed branding and separator lines. Defaults to the theme's primary text color with no attributes.",
220
+ "properties": {
221
+ "color": {
222
+ "type": "string",
223
+ "enum": ["default", "subdued", "warning", "error", "success", "info"],
224
+ "default": "default",
225
+ "description": "Theme color role for fixed lines. Valid roles are default, subdued, warning, error, success, and info; default follows the active theme's primary text color."
226
+ },
227
+ "attributes": {
228
+ "type": "array",
229
+ "items": { "enum": ["bold", "dim", "italic", "underline", "blink", "inverse", "hidden", "strikethrough"] },
230
+ "default": [],
231
+ "description": "OpenTUI text attributes applied to fixed lines. Choose any combination of bold, dim, italic, underline, blink, inverse, hidden, and strikethrough; an empty list adds none."
232
+ }
233
+ }
234
+ },
235
+ "rows": {
236
+ "type": "object",
237
+ "additionalProperties": {
238
+ "type": "object",
239
+ "additionalProperties": false,
240
+ "description": "Appearance for the wildcard or one live row. Missing fields inherit the wildcard style.",
241
+ "properties": {
242
+ "color": {
243
+ "type": "string",
244
+ "enum": ["default", "subdued", "warning", "error", "success", "info"],
245
+ "default": "subdued",
246
+ "description": "Theme color role for this row. The wildcard defaults to subdued; a row override that omits color inherits the wildcard role."
247
+ },
248
+ "attributes": {
249
+ "type": "array",
250
+ "items": { "enum": ["bold", "dim", "italic", "underline", "blink", "inverse", "hidden", "strikethrough"] },
251
+ "default": [],
252
+ "description": "OpenTUI text attributes for this row. The wildcard defaults to none; a row override that omits attributes inherits the wildcard list."
253
+ }
254
+ }
255
+ },
256
+ "propertyNames": {
257
+ "enum": ["*", "caution", "status", "agent", "model", "branch", "cost", "total", "project", "tokens", "cache", "context", "perms", "elapsed", "tps", "spark", "reasoning", "turns", "guard"]
258
+ },
259
+ "default": { "*": { "color": "subdued", "attributes": [] } },
260
+ "description": "Style all live rows under `*`, then optionally override any known row name such as `cost`. A row can change one field and inherit the other from `*`; unknown row names are reported and ignored."
261
+ }
262
+ }
187
263
  }
188
264
  }
189
265
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oc-flight-deck",
3
- "version": "0.6.3",
3
+ "version": "0.6.6",
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",
@@ -0,0 +1,98 @@
1
+ // Accumulated active time for one session, measured rather than assumed.
2
+ //
3
+ // Wall-clock since `time.created` reports a session left open overnight as a
4
+ // night's work. This clock only advances while the session — or something in
5
+ // its family, or one of its shells — is actually running, and it freezes the
6
+ // instant everything settles. `busy()` decides that, so the `elapsed` and
7
+ // `status` rows can never disagree about whether work is happening.
8
+ //
9
+ // One session is watched at a time. Reading a different session means the gap
10
+ // on the previous one happened off-watch, so its next read rebaselines and
11
+ // banks nothing. A window is billed only when the session was busy at both
12
+ // ends and the window was observed within the bound — so no single unobserved
13
+ // gap is ever billed beyond the optional `maxBankedMs`, and a longer gap banks
14
+ // nothing at all.
15
+ //
16
+ // State is a per-session accumulator held in this process and keyed by the
17
+ // displayed session, so an unrelated project's session can never contribute.
18
+ // That also means the figure begins at zero when the TUI starts: it measures
19
+ // activity observed this process, not activity the host recorded. A session
20
+ // that is idle when first seen stays at zero, and an unknown busy state
21
+ // (`undefined`) freezes rather than inventing motion.
22
+
23
+ /** How the caller answers "is this session working right now?". */
24
+ export type BusyRead = (sessionID: string) => boolean | undefined;
25
+
26
+ export interface ActiveElapsedOptions {
27
+ /**
28
+ * Longest window that may be banked as work. A longer one was not observed
29
+ * — a suspended process, sparse host events — so it banks nothing.
30
+ *
31
+ * Defaults to 60_000 so the module's own contract holds even when the
32
+ * caller supplies no bound. A production caller still passes its own
33
+ * derived bound.
34
+ */
35
+ readonly maxBankedMs?: number;
36
+ }
37
+
38
+ /** One session's running tally and the last instant it was observed. */
39
+ interface ActiveState {
40
+ accumulated: number;
41
+ lastAt: number;
42
+ running: boolean;
43
+ }
44
+
45
+ /**
46
+ * Build the active clock. One session is watched at a time. A read banks the
47
+ * time since the previous read only when the session was running at BOTH ends
48
+ * of that window — so overlapping activities record one wall-clock window, not
49
+ * one per activity, and a window in which the session settled is treated as
50
+ * idle rather than billed. Reads while the tally is zero return `undefined`,
51
+ * matching the row's own "nothing to show yet" behaviour.
52
+ *
53
+ * The observation boundary is unconditional: a read of a different session than
54
+ * the one before it rebaselines and banks nothing, because the gap happened
55
+ * off-watch. The optional `maxBankedMs` is an independent cap on top of that —
56
+ * any window longer than it was unobserved and banks nothing — not a switch for
57
+ * the boundary. Undercount is acceptable, over-count is not.
58
+ */
59
+ export function createActiveElapsed(isBusy: BusyRead, options: ActiveElapsedOptions = {}) {
60
+ const states = new Map<string, ActiveState>();
61
+ // The module's own contract must hold without the caller opting in; the
62
+ // production caller still passes its own derived bound.
63
+ const maxBankedMs = options.maxBankedMs ?? 60_000;
64
+ let lastRead: string | undefined;
65
+
66
+ return function activeElapsedMs(sessionID: string, now: number): number | undefined {
67
+ if (!Number.isFinite(now)) return undefined;
68
+
69
+ // A throwing or unknown read means "not known to be busy", which freezes.
70
+ let busy = false;
71
+ try {
72
+ busy = isBusy(sessionID) === true;
73
+ } catch {
74
+ busy = false;
75
+ }
76
+
77
+ // Observation boundary: a different session on screen means this one's
78
+ // gap since the last read happened off-watch, so take a fresh baseline.
79
+ const boundary = lastRead !== undefined && lastRead !== sessionID;
80
+ lastRead = sessionID;
81
+
82
+ let state = states.get(sessionID);
83
+ if (state === undefined) {
84
+ state = { accumulated: 0, lastAt: now, running: false };
85
+ states.set(sessionID, state);
86
+ } else if (!boundary && state.running && busy) {
87
+ // Only a window that was busy at BOTH ends and short enough to have been
88
+ // observed is work. A settled gap is idle; a stalled or stepped-back
89
+ // clock must never subtract; an over-long window was not watched.
90
+ const delta = now - state.lastAt;
91
+ if (delta > 0 && delta <= maxBankedMs) state.accumulated += delta;
92
+ }
93
+
94
+ state.running = busy;
95
+ state.lastAt = now;
96
+ return state.accumulated <= 0 ? undefined : state.accumulated;
97
+ };
98
+ }