oc-flight-deck 0.1.1 → 0.1.2

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
@@ -80,8 +80,9 @@ then edit. Comments and trailing commas are fine.
80
80
 
81
81
  ```jsonc
82
82
  {
83
- // Milliseconds between ticks. 0 turns the timer off entirely.
84
- "refresh": 1000,
83
+ // Tick rate in ms. The spinner has ten frames, so 100 turns it once a
84
+ // second. 0 turns the timer off entirely.
85
+ "refresh": 100,
85
86
 
86
87
  "sidebar": {
87
88
  "enabled": true,
@@ -105,16 +106,18 @@ The example file documents every row and every option inline. A typo is never
105
106
  fatal: the bad value is ignored, the default comes back, and you get a one-time
106
107
  toast naming the key to fix.
107
108
 
108
- ## It reads. It never writes.
109
+ ## It reads. It writes one number.
109
110
 
110
111
  Flight Deck shows what OpenCode already knows.
111
112
 
112
113
  - **No network calls.** Nothing is fetched, nothing is sent.
113
114
  - **No telemetry.** Nothing is collected or phoned home.
114
- - **No storage.** Nothing is written to disk.
115
- - **No polling loop** by default — cost, tokens, and permissions update from the
116
- host's own events. The ticker exists only so clock-derived rows like `elapsed`
117
- keep moving, and `"refresh": 0` removes it completely.
115
+ - **Nothing on disk.** The one thing it writes is an animation counter in the
116
+ host's in-memory plugin state, so the spinner and `elapsed` keep moving
117
+ between turns. It is scoped to this plugin and dies with the TUI; it is never
118
+ persisted, and `"refresh": 0` removes even that.
119
+ - **No polling of your session** — cost, tokens, and permissions update from the
120
+ host's own events.
118
121
  - **Theme-native.** Every line uses your active theme's text tokens, so it blends
119
122
  with whatever look you already run.
120
123
 
@@ -19,17 +19,22 @@
19
19
  // ═════════════════════════════════════════════════════════════════════════
20
20
 
21
21
  // ── Update cadence ───────────────────────────────────────────────────────
22
- // Milliseconds between refreshes.
22
+ // Milliseconds between refreshes: the tick rate of everything that has to
23
+ // animate. The status spinner has ten frames, so 100 turns it once a second.
23
24
  //
24
25
  // Cost, tokens, and permissions arrive from the host's own events, so they
25
- // stay current with no timer at all. Only clock-derived rows need one, and
26
- // `elapsed` is the reason this exists — without a tick it would sit frozen
27
- // between turns.
26
+ // stay current with no timer at all. Only clock-derived rows need one — and
27
+ // `elapsed` plus the spinner are the reason this exists. Without a tick they
28
+ // would sit frozen between turns.
28
29
  //
29
- // 1000 default — a smooth tick, negligible cost
30
- // 0 no timer; `elapsed` only moves when the session does
31
- // 5000 calmer, still live enough for a wall-clock row
32
- "refresh": 1000,
30
+ // 100 default — the spinner turns once a second, the clock stays live
31
+ // 50 twice as lively, still negligible work per tick
32
+ // 1000 a calm wall-clock tick, but the spinner visibly stutters
33
+ // 0 no timer; `elapsed` and the spinner only move when the session does
34
+ //
35
+ // Anything faster than 16 (one frame at 60Hz) is clamped: a tick wakes the
36
+ // host's renderer, so a smaller value spends work without adding motion.
37
+ "refresh": 100,
33
38
 
34
39
  // ── Sidebar ──────────────────────────────────────────────────────────────
35
40
  "sidebar": {
@@ -47,7 +52,7 @@
47
52
  // them freely — an unknown name is ignored with a one-time warning, so a
48
53
  // typo can never break the panel.
49
54
  //
50
- // status running or idle — the glyph animates while it works
55
+ // status running or idle — the glyph turns while anything is working
51
56
  // agent which agent is running (orchestrator, build, plan, ...)
52
57
  // model model id, plus the variant when there is one
53
58
  // branch current git branch
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oc-flight-deck",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
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",
package/src/tui/config.ts CHANGED
@@ -39,8 +39,9 @@ export interface FlightDeckConfig {
39
39
  * Update cadence in milliseconds for time-derived rows.
40
40
  *
41
41
  * Cost and tokens arrive with events, so they stay current without a timer.
42
- * Anything derived from the clock — `elapsed` especially — has nothing to
43
- * react to, so it needs a tick. `0` turns the ticker off entirely.
42
+ * Anything derived from the clock — `elapsed`, and the status spinner's
43
+ * frames — has nothing to react to, so it needs a tick. `0` turns the ticker
44
+ * off, leaving every row event-driven.
44
45
  */
45
46
  readonly refresh: number;
46
47
  }
@@ -79,12 +80,25 @@ export const DEFAULT_SIDEBAR_ROWS: readonly string[] = [
79
80
  "spark",
80
81
  ];
81
82
 
82
- /** One tick a second: enough for the clock-derived rows, cheap enough to ignore. */
83
- export const DEFAULT_REFRESH_MS = 1_000;
83
+ /**
84
+ * Ten ticks a second: the status spinner has ten frames, so one rotation takes a
85
+ * second and reads as motion instead of as a stuck glyph. A tick costs one
86
+ * host-store write plus a recompute measured in microseconds, and when nothing
87
+ * on the rail changed the host's renderer diffs the frame away to nothing.
88
+ * Raise it to spend less on idle sessions; `0` turns the ticker off entirely.
89
+ */
90
+ export const DEFAULT_REFRESH_MS = 100;
84
91
 
85
92
  /** A tick slower than once a minute is indistinguishable from no ticker. */
86
93
  const MAX_REFRESH_MS = 60_000;
87
94
 
95
+ /**
96
+ * A tick wakes the host's renderer, so a sub-frame interval from a config file
97
+ * is a way to wedge the TUI rather than a way to make it smoother. 16ms is one
98
+ * frame at 60Hz; below that there is nothing left to animate.
99
+ */
100
+ export const MIN_REFRESH_MS = 16;
101
+
88
102
  export const DEFAULT_FOOTER_TEXT = "Flight Deck";
89
103
 
90
104
  export const DEFAULT_CONFIG: FlightDeckConfig = {
@@ -237,6 +251,11 @@ function readRefresh(value: unknown, issues: string[]): number {
237
251
  issues.push(`refresh was longer than ${MAX_REFRESH_MS}ms; using ${MAX_REFRESH_MS}`);
238
252
  return MAX_REFRESH_MS;
239
253
  }
254
+ // `0` is "off", not "as fast as possible", so it is deliberately not clamped.
255
+ if (value > 0 && value < MIN_REFRESH_MS) {
256
+ issues.push(`refresh was faster than ${MIN_REFRESH_MS}ms; using ${MIN_REFRESH_MS}`);
257
+ return MIN_REFRESH_MS;
258
+ }
240
259
  return value;
241
260
  }
242
261
 
package/src/tui/index.tsx CHANGED
@@ -1,18 +1,21 @@
1
1
  /** @jsxImportSource @opentui/solid */
2
2
  import { Plugin } from "@opencode/plugin/tui";
3
- import { createSignal } from "solid-js";
4
3
  import { mergeOptions, resolveConfig } from "./config.js";
5
4
  import { loadConfigFile } from "./file-config.js";
6
5
  import { footerLine, liveRowOffset, sidebarLines } from "./presentation.js";
7
- import type { StatSource } from "./stats.js";
6
+ import { ANIMATED_FIELDS, type StatSource } from "./stats.js";
7
+ import { startTicker } from "./ticker.js";
8
8
 
9
9
  // Flight Deck is a read-only instrument panel for the OpenCode V2 CLI/TUI. It
10
10
  // shows the open session's agent, model, branch, cost, tokens, and cache hit
11
11
  // rate in the sidebar. It uses only the official CLI plugin boundary —
12
12
  // `@opencode/plugin/tui`, `context.ui.slot`, and theme tokens.
13
13
  //
14
- // Read-only by construction: it never writes, requests, stores, subscribes, or
15
- // polls. Everything it shows is state the host already holds in memory.
14
+ // Read-only but for one thing: the animation tick writes a single counter into
15
+ // the host's ephemeral plugin-memory store. It has to, because a timer owned by
16
+ // this plugin cannot wake the host's renderer — see ./ticker.ts for why. That
17
+ // counter is in-process, scoped to this plugin, and gone when the TUI exits.
18
+ // Everything the rail displays is state the host already holds in memory.
16
19
  //
17
20
  // Appearance comes from, in order of precedence:
18
21
  // 1. `context.options` — the host's plugin options, when the host forwards them
@@ -165,6 +168,43 @@ export default Plugin.define({
165
168
  }
166
169
  };
167
170
 
171
+ // Anything genuinely working keeps the status glyph turning: this session
172
+ // (thinking, streaming, running tools), any subagent in its tree, or a shell
173
+ // command still running. Returns `undefined` when the host has not said
174
+ // either way, so the rail can omit the row rather than invent "idle".
175
+ const busy = (sessionID: string): boolean | undefined => {
176
+ const status = statusOf(sessionID);
177
+ if (status === "running") return true;
178
+
179
+ try {
180
+ for (const id of context.data.session.family(sessionID) ?? []) {
181
+ if (id === sessionID) continue;
182
+ try {
183
+ if (context.data.session.status(id) === "running") return true;
184
+ } catch {
185
+ // One unreadable child must not hide a running sibling.
186
+ }
187
+ }
188
+ } catch {
189
+ // No subagent status on this host; the shell check below still applies.
190
+ }
191
+
192
+ try {
193
+ // `listBySession` is on the reactive client the host hands the plugin,
194
+ // but not on every published type surface, so it is reached defensively:
195
+ // a host without it still falls back to the session's own status.
196
+ const shellApi = context.data.shell as unknown as
197
+ | { listBySession?: (id: string) => readonly unknown[] }
198
+ | undefined;
199
+ const shells = shellApi?.listBySession?.(sessionID);
200
+ if (shells !== undefined && shells.some((entry) => asRecord(entry)?.status === "running")) return true;
201
+ } catch {
202
+ // Same again: unreadable shells just mean no shell signal.
203
+ }
204
+
205
+ return status === undefined ? undefined : false;
206
+ };
207
+
168
208
  // Throughput of the last completed turn. The host records when streaming
169
209
  // finished, so this is measured rather than estimated from wall-clock.
170
210
  const lastTps = (sessionID: string): number | undefined => {
@@ -199,10 +239,13 @@ export default Plugin.define({
199
239
  };
200
240
 
201
241
  // A ticker exists only for clock-derived rows; everything else updates from
202
- // the host's own events. `refresh: 0` opts out of it entirely.
203
- const [frame, setFrame] = createSignal(0);
204
- const timer =
205
- config.refresh > 0 ? setInterval(() => setFrame((value) => value + 1), config.refresh) : undefined;
242
+ // the host's own events. It is skipped entirely when nothing on the rail
243
+ // animates, and `refresh: 0` opts out regardless. The tick has to live in the
244
+ // host's reactive graph rather than ours, or it re-renders nothing at all.
245
+ const animated =
246
+ config.sidebar.enabled &&
247
+ config.sidebar.rows.some((name) => (ANIMATED_FIELDS as readonly string[]).includes(name));
248
+ const ticker = startTicker(context, animated ? config.refresh : 0);
206
249
 
207
250
  // Read session state inside the render so the rail stays live: cost and
208
251
  // tokens climb as the session runs, and the branch appears once VCS
@@ -219,13 +262,15 @@ export default Plugin.define({
219
262
  context: contextUsage(sessionID, session?.model),
220
263
  project: projectTotals(),
221
264
  status: statusOf(sessionID),
265
+ busy: busy(sessionID),
222
266
  perms: permsOf(sessionID),
223
267
  tps: lastTps(sessionID),
224
268
  spark: sparkValues(sessionID),
225
269
  elapsedMs: sessionElapsed(session),
226
270
  turns,
227
- // Read the tick so the slot re-runs each frame.
228
- frame: frame(),
271
+ // Read the tick inside the render so the host registers a dependency on
272
+ // it; that read is what makes the rail re-run on the ticker's schedule.
273
+ frame: ticker?.frame ?? 0,
229
274
  };
230
275
  };
231
276
 
@@ -261,7 +306,7 @@ export default Plugin.define({
261
306
  }
262
307
 
263
308
  return () => {
264
- if (timer !== undefined) clearInterval(timer);
309
+ ticker?.dispose();
265
310
  for (const release of releases) release();
266
311
  };
267
312
  },
package/src/tui/stats.ts CHANGED
@@ -39,6 +39,8 @@ export interface StatSource {
39
39
  readonly context?: unknown;
40
40
  readonly project?: unknown;
41
41
  readonly status?: unknown;
42
+ /** True when anything is working: this session, a subagent, or a shell. */
43
+ readonly busy?: unknown;
42
44
  readonly perms?: unknown;
43
45
  readonly tps?: unknown;
44
46
  readonly elapsedMs?: unknown;
@@ -71,6 +73,14 @@ export const STAT_FIELDS = [
71
73
 
72
74
  export type StatField = (typeof STAT_FIELDS)[number];
73
75
 
76
+ /**
77
+ * Fields whose value only ever changes on a clock tick.
78
+ *
79
+ * The ticker exists to animate these. When none of them is on screen there is
80
+ * nothing to animate, so the plugin does not start a timer at all.
81
+ */
82
+ export const ANIMATED_FIELDS = ["status", "elapsed"] as const;
83
+
74
84
  export function isStatField(value: string): value is StatField {
75
85
  return (STAT_FIELDS as readonly string[]).includes(value);
76
86
  }
@@ -162,11 +172,18 @@ export function statLine(field: string, source: StatSource): string | undefined
162
172
  switch (field) {
163
173
  case "status": {
164
174
  const status = asText(source.status);
165
- if (status === undefined) return undefined;
175
+ if (status === undefined && source.busy === undefined) return undefined;
166
176
  // The spinner lives here rather than in a row of its own: an animated
167
177
  // glyph beside "running" says the same thing without spending a line.
168
- if (status !== "running") return row("status", "○ idle");
169
- const frame = asCount(source.frame) ?? 0;
178
+ //
179
+ // `busy` folds in work the session's own status misses — a subagent
180
+ // running in its own session, or a shell command still going — so the
181
+ // glyph only stops when there is genuinely nothing happening. A host that
182
+ // does not report it falls back to the session's own status.
183
+ if (source.busy !== true && status !== "running") return row("status", "○ idle");
184
+ // Floored at the boundary: a fractional frame would index the frame list
185
+ // with a non-integer and render `undefined`.
186
+ const frame = Math.floor(asCount(source.frame) ?? 0);
170
187
  return row("status", `${SPINNER[frame % SPINNER.length]} running`);
171
188
  }
172
189
  case "agent": {
@@ -0,0 +1,130 @@
1
+ // The animation tick that drives Flight Deck's clock-derived rows.
2
+ //
3
+ // Why this is not a `createSignal`:
4
+ //
5
+ // The host's Solid is compiled into the `opencode2` binary. This plugin
6
+ // resolves its own `solid-js` from the npm cache, because the plugin packaging
7
+ // model has plugins supply their own renderer peers. Those are two module
8
+ // instances, and Solid keeps its dependency tracking in module state — so a
9
+ // signal created in one instance is invisible to an effect owned by the other.
10
+ // A `setInterval` + `createSignal` ticker therefore advanced a counter that
11
+ // nothing was listening to: `elapsed` sat frozen and the spinner never turned.
12
+ //
13
+ // `context.storage.memory` is the documented bridge. It returns a store owned
14
+ // by the *host's* Solid, so writing it from a timer notifies the host's render,
15
+ // and reading it inside the slot render registers the dependency that makes the
16
+ // rail re-run on that schedule.
17
+ //
18
+ // This is the only state the plugin writes, and it is deliberately the
19
+ // smallest, most disposable surface available: ephemeral, in-process, scoped to
20
+ // this plugin, gone when the TUI exits. Not the durable store, not a session,
21
+ // not a file, not the network.
22
+ //
23
+ // The host is a beta and its store is reached across a version boundary, so
24
+ // everything about it is validated at runtime and every failure path degrades to
25
+ // "no ticker" rather than raising into the TUI.
26
+
27
+ /** The value kept in the host's memory store. A single monotonic counter. */
28
+ interface FrameState {
29
+ frame: number;
30
+ }
31
+
32
+ /** The store the host hands back: read-only to us, reactive to the host. */
33
+ interface FrameStore {
34
+ readonly frame?: unknown;
35
+ }
36
+
37
+ /** The mutation function the host hands back. */
38
+ type FrameUpdate = (mutation: (draft: FrameState) => void) => void;
39
+
40
+ /** The one host capability the ticker needs, so it stays trivially stubbable. */
41
+ export interface TickerHost {
42
+ readonly storage?: {
43
+ /**
44
+ * Typed as `unknown` on purpose: this is the one host call reached across a
45
+ * beta version boundary, so the shape is checked at runtime instead of
46
+ * trusted from a type that may not match the binary.
47
+ */
48
+ memory(key: string, options: { readonly initial: FrameState }): unknown;
49
+ };
50
+ }
51
+
52
+ export interface Ticker {
53
+ /**
54
+ * Current frame, read from the host's store.
55
+ *
56
+ * This must be read inside the slot render, while the host's reactive scope
57
+ * is active, or it will not register as a dependency and nothing will update.
58
+ */
59
+ readonly frame: number;
60
+ /** Stops the timer. Safe to call once; the plugin calls it on cleanup. */
61
+ dispose(): void;
62
+ }
63
+
64
+ /** Namespaced so it cannot collide with another plugin's memory keys. */
65
+ export const TICKER_KEY = "flight-deck.frame";
66
+
67
+ // Untrusted store values are normalised here rather than at the render, so a
68
+ // corrupt frame can never reach the spinner's array index.
69
+ function readFrame(store: FrameStore | undefined): number {
70
+ const value = store?.frame;
71
+ return typeof value === "number" && Number.isFinite(value) && value >= 0 ? Math.floor(value) : 0;
72
+ }
73
+
74
+ // A host whose store does not match the documented shape is treated as no store
75
+ // at all: half-opening one would throw on every tick instead of degrading.
76
+ function openStore(storage: NonNullable<TickerHost["storage"]>): { store: FrameStore; update: FrameUpdate } | undefined {
77
+ let opened: unknown;
78
+ try {
79
+ opened = storage.memory(TICKER_KEY, { initial: { frame: 0 } });
80
+ } catch {
81
+ return undefined;
82
+ }
83
+
84
+ if (!Array.isArray(opened) || opened.length < 2) return undefined;
85
+ const [store, update] = opened as [unknown, unknown];
86
+ if (store === null || typeof store !== "object") return undefined;
87
+ if (typeof update !== "function") return undefined;
88
+
89
+ return { store: store as FrameStore, update: update as FrameUpdate };
90
+ }
91
+
92
+ /**
93
+ * Start the animation tick, or return `undefined` when it is switched off.
94
+ *
95
+ * A missing or unusable host store is not an error: the rail then updates only
96
+ * on host events, which is exactly how it behaved before the ticker was fixed.
97
+ * Degrading quietly keeps a cosmetic panel from ever breaking the TUI.
98
+ */
99
+ export function startTicker(host: TickerHost | undefined, intervalMs: number): Ticker | undefined {
100
+ if (!Number.isFinite(intervalMs) || intervalMs <= 0) return undefined;
101
+
102
+ const storage = host?.storage;
103
+ if (storage === undefined || typeof storage.memory !== "function") return undefined;
104
+
105
+ const opened = openStore(storage);
106
+ if (opened === undefined) return undefined;
107
+
108
+ let timer: ReturnType<typeof setInterval> | undefined = setInterval(() => {
109
+ try {
110
+ opened.update((draft) => {
111
+ draft.frame = readFrame(draft) + 1;
112
+ });
113
+ } catch {
114
+ // A store that starts failing mid-run must not raise on every tick
115
+ // forever. Put the timer down and let the rail fall back to host events.
116
+ if (timer !== undefined) clearInterval(timer);
117
+ timer = undefined;
118
+ }
119
+ }, intervalMs);
120
+
121
+ return {
122
+ get frame() {
123
+ return readFrame(opened.store);
124
+ },
125
+ dispose() {
126
+ if (timer !== undefined) clearInterval(timer);
127
+ timer = undefined;
128
+ },
129
+ };
130
+ }