oc-flight-deck 0.4.0 → 0.6.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/README.md +24 -7
- package/flight-deck.example.jsonc +22 -6
- package/flight-deck.schema.json +1 -1
- package/package.json +70 -70
- package/src/tui/file-config.ts +35 -13
- package/src/tui/index.tsx +563 -515
- package/src/tui/presentation.ts +34 -34
- package/src/tui/stats.ts +21 -0
- package/src/tui/ticker.ts +37 -1
package/src/tui/presentation.ts
CHANGED
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
// Plain-string views of the Flight Deck rail.
|
|
2
|
-
//
|
|
3
|
-
// Keeping the text layer pure makes it trivial to test, and leaves the JSX in
|
|
4
|
-
// index.tsx to do nothing but wrap these strings in themed <text> elements.
|
|
5
|
-
// The live rows come from ./stats.ts and are read-only: nothing here mutates
|
|
6
|
-
// session state, and nothing leaves the process.
|
|
7
|
-
|
|
8
|
-
import type { FlightDeckConfig } from "./config.js";
|
|
9
|
-
import { MAX_LINES } from "./config.js";
|
|
10
|
-
import { statRows, type StatSource } from "./stats.js";
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Sidebar lines to render, or an empty list when the sidebar rail is disabled.
|
|
14
|
-
*
|
|
15
|
-
* Configured `lines` render first (branding, separators, any fixed text), then
|
|
16
|
-
* the live rows named by `sidebar.rows`. With `sidebar.persist` (the default)
|
|
17
|
-
* every named row renders exactly once, using `sidebar.placeholder` when the
|
|
18
|
-
* host has no data yet; with `persist: false` rows with no data are omitted.
|
|
19
|
-
*/
|
|
20
|
-
export function sidebarLines(config: FlightDeckConfig, source: StatSource = {}): readonly string[] {
|
|
21
|
-
if (!config.sidebar.enabled) return [];
|
|
22
|
-
const layout = { ...config.layout, persist: config.sidebar.persist, placeholder: config.sidebar.placeholder };
|
|
23
|
-
return [...config.sidebar.lines, ...statRows(config.sidebar.rows, source, layout)].slice(0, MAX_LINES);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/** Footer text to render, or `undefined` when the footer rail is disabled. */
|
|
27
|
-
export function footerLine(config: FlightDeckConfig): string | undefined {
|
|
28
|
-
return config.footer.enabled ? config.footer.text : undefined;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/** Index of the first live row, so the caller can theme branding apart from data. */
|
|
32
|
-
export function liveRowOffset(config: FlightDeckConfig): number {
|
|
33
|
-
return config.sidebar.enabled ? config.sidebar.lines.length : 0;
|
|
34
|
-
}
|
|
1
|
+
// Plain-string views of the Flight Deck rail.
|
|
2
|
+
//
|
|
3
|
+
// Keeping the text layer pure makes it trivial to test, and leaves the JSX in
|
|
4
|
+
// index.tsx to do nothing but wrap these strings in themed <text> elements.
|
|
5
|
+
// The live rows come from ./stats.ts and are read-only: nothing here mutates
|
|
6
|
+
// session state, and nothing leaves the process.
|
|
7
|
+
|
|
8
|
+
import type { FlightDeckConfig } from "./config.js";
|
|
9
|
+
import { MAX_LINES } from "./config.js";
|
|
10
|
+
import { statRows, type StatSource } from "./stats.js";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Sidebar lines to render, or an empty list when the sidebar rail is disabled.
|
|
14
|
+
*
|
|
15
|
+
* Configured `lines` render first (branding, separators, any fixed text), then
|
|
16
|
+
* the live rows named by `sidebar.rows`. With `sidebar.persist` (the default)
|
|
17
|
+
* every named row renders exactly once, using `sidebar.placeholder` when the
|
|
18
|
+
* host has no data yet; with `persist: false` rows with no data are omitted.
|
|
19
|
+
*/
|
|
20
|
+
export function sidebarLines(config: FlightDeckConfig, source: StatSource = {}): readonly string[] {
|
|
21
|
+
if (!config.sidebar.enabled) return [];
|
|
22
|
+
const layout = { ...config.layout, persist: config.sidebar.persist, placeholder: config.sidebar.placeholder };
|
|
23
|
+
return [...config.sidebar.lines, ...statRows(config.sidebar.rows, source, layout)].slice(0, MAX_LINES);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** Footer text to render, or `undefined` when the footer rail is disabled. */
|
|
27
|
+
export function footerLine(config: FlightDeckConfig): string | undefined {
|
|
28
|
+
return config.footer.enabled ? config.footer.text : undefined;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** Index of the first live row, so the caller can theme branding apart from data. */
|
|
32
|
+
export function liveRowOffset(config: FlightDeckConfig): number {
|
|
33
|
+
return config.sidebar.enabled ? config.sidebar.lines.length : 0;
|
|
34
|
+
}
|
package/src/tui/stats.ts
CHANGED
|
@@ -53,6 +53,11 @@ export interface StatSource {
|
|
|
53
53
|
/** True when anything is working: this session, a subagent, or a shell. */
|
|
54
54
|
readonly busy?: unknown;
|
|
55
55
|
readonly perms?: unknown;
|
|
56
|
+
/**
|
|
57
|
+
* Overall session throughput: output tokens over the session's lifetime,
|
|
58
|
+
* with subagents summed in. A whole-conversation average, so it reads lower
|
|
59
|
+
* than a peak per-turn rate.
|
|
60
|
+
*/
|
|
56
61
|
readonly tps?: unknown;
|
|
57
62
|
readonly elapsedMs?: unknown;
|
|
58
63
|
readonly turns?: unknown;
|
|
@@ -238,6 +243,22 @@ export function formatCost(value: number): string {
|
|
|
238
243
|
return `$${value.toFixed(value < 1 ? 3 : 2)}`;
|
|
239
244
|
}
|
|
240
245
|
|
|
246
|
+
/**
|
|
247
|
+
* Overall session throughput: output tokens over the session's lifetime.
|
|
248
|
+
*
|
|
249
|
+
* Unlike a per-turn rate, this is the whole conversation's average, so it
|
|
250
|
+
* includes every subagent and every pause. A just-started session is floored
|
|
251
|
+
* at one second so it cannot divide by a sliver of time and flash an absurd
|
|
252
|
+
* rate. Returns `undefined` when there is nothing to divide.
|
|
253
|
+
*/
|
|
254
|
+
export function sessionThroughput(outputTokens: unknown, elapsedMs: unknown): number | undefined {
|
|
255
|
+
const output = asCount(outputTokens);
|
|
256
|
+
const elapsed = asCount(elapsedMs);
|
|
257
|
+
if (output === undefined || output <= 0) return undefined;
|
|
258
|
+
if (elapsed === undefined || elapsed <= 0) return undefined;
|
|
259
|
+
return output / (Math.max(elapsed, 1_000) / 1_000);
|
|
260
|
+
}
|
|
261
|
+
|
|
241
262
|
/** `45s`, `14m`, `2h 14m`. */
|
|
242
263
|
export function formatDuration(ms: number): string {
|
|
243
264
|
const seconds = Math.floor(ms / 1_000);
|
package/src/tui/ticker.ts
CHANGED
|
@@ -20,6 +20,11 @@
|
|
|
20
20
|
// this plugin, gone when the TUI exits. Not the durable store, not a session,
|
|
21
21
|
// not a file, not the network.
|
|
22
22
|
//
|
|
23
|
+
// The tick serves the spinner first, but the spinner is only drawn while work
|
|
24
|
+
// is happening. When nothing is moving the store is written about once a second
|
|
25
|
+
// instead of on every interval — see `IDLE_REFRESH_MS` — so the host's reactive
|
|
26
|
+
// graph is woken a tenth as often for a picture that has not changed.
|
|
27
|
+
//
|
|
23
28
|
// The host is a beta and its store is reached across a version boundary, so
|
|
24
29
|
// everything about it is validated at runtime and every failure path degrades to
|
|
25
30
|
// "no ticker" rather than raising into the TUI.
|
|
@@ -64,6 +69,17 @@ export interface Ticker {
|
|
|
64
69
|
/** Namespaced so it cannot collide with another plugin's memory keys. */
|
|
65
70
|
export const TICKER_KEY = "flight-deck.frame";
|
|
66
71
|
|
|
72
|
+
/**
|
|
73
|
+
* How often the frame still advances while nothing is moving.
|
|
74
|
+
*
|
|
75
|
+
* The spinner needs ~10 frames a second, but it is only drawn while work is
|
|
76
|
+
* happening. When idle, only `elapsed` and the annunciator still need a tick,
|
|
77
|
+
* and both read in whole seconds — so the host renderer is woken once a second
|
|
78
|
+
* instead of ten times. The timer itself keeps firing (cheap); it is the store
|
|
79
|
+
* write, which wakes the host's reactive graph, that is skipped.
|
|
80
|
+
*/
|
|
81
|
+
export const IDLE_REFRESH_MS = 1_000;
|
|
82
|
+
|
|
67
83
|
// Untrusted store values are normalised here rather than at the render, so a
|
|
68
84
|
// corrupt frame can never reach the spinner's array index.
|
|
69
85
|
function readFrame(store: FrameStore | undefined): number {
|
|
@@ -96,7 +112,11 @@ function openStore(storage: NonNullable<TickerHost["storage"]>): { store: FrameS
|
|
|
96
112
|
* on host events, which is exactly how it behaved before the ticker was fixed.
|
|
97
113
|
* Degrading quietly keeps a cosmetic panel from ever breaking the TUI.
|
|
98
114
|
*/
|
|
99
|
-
export function startTicker(
|
|
115
|
+
export function startTicker(
|
|
116
|
+
host: TickerHost | undefined,
|
|
117
|
+
intervalMs: number,
|
|
118
|
+
isBusy: () => boolean = () => true,
|
|
119
|
+
): Ticker | undefined {
|
|
100
120
|
if (!Number.isFinite(intervalMs) || intervalMs <= 0) return undefined;
|
|
101
121
|
|
|
102
122
|
const storage = host?.storage;
|
|
@@ -105,7 +125,23 @@ export function startTicker(host: TickerHost | undefined, intervalMs: number): T
|
|
|
105
125
|
const opened = openStore(storage);
|
|
106
126
|
if (opened === undefined) return undefined;
|
|
107
127
|
|
|
128
|
+
const idleEvery = Math.max(1, Math.round(IDLE_REFRESH_MS / intervalMs));
|
|
129
|
+
let ticks = 0;
|
|
130
|
+
|
|
108
131
|
let timer: ReturnType<typeof setInterval> | undefined = setInterval(() => {
|
|
132
|
+
ticks += 1;
|
|
133
|
+
|
|
134
|
+
// A broken busy predicate must never freeze the spinner, so it degrades to
|
|
135
|
+
// "busy" rather than propagating.
|
|
136
|
+
let busy = true;
|
|
137
|
+
try {
|
|
138
|
+
busy = isBusy();
|
|
139
|
+
} catch {
|
|
140
|
+
busy = true;
|
|
141
|
+
}
|
|
142
|
+
// While idle, skip the store write on all but every `idleEvery`th tick.
|
|
143
|
+
if (!busy && ticks % idleEvery !== 0) return;
|
|
144
|
+
|
|
109
145
|
try {
|
|
110
146
|
opened.update((draft) => {
|
|
111
147
|
draft.frame = readFrame(draft) + 1;
|