oc-flight-deck 0.6.1 → 0.6.3
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 +107 -214
- package/flight-deck.example.jsonc +208 -208
- package/flight-deck.schema.json +1 -1
- package/package.json +70 -70
- package/src/tui/caution.ts +14 -14
- package/src/tui/coerce.ts +25 -0
- package/src/tui/config.ts +12 -12
- package/src/tui/file-config.ts +1 -1
- package/src/tui/format.ts +82 -0
- package/src/tui/guard-tokens.ts +72 -0
- package/src/tui/guard.ts +5 -5
- package/src/tui/index.tsx +278 -679
- package/src/tui/project-totals.ts +49 -0
- package/src/tui/rows.ts +281 -0
- package/src/tui/session-reads.ts +239 -0
- package/src/tui/session-tps.ts +173 -0
- package/src/tui/stat-fields.ts +122 -0
- package/src/tui/stats.ts +12 -634
- package/src/tui/throughput.ts +85 -0
- package/src/tui/ticker.ts +2 -2
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// Coercion guards for untrusted host values.
|
|
2
|
+
//
|
|
3
|
+
// Everything the host hands the rail — session records, message lists, model
|
|
4
|
+
// catalog entries — is `unknown` and read defensively. These four guards are
|
|
5
|
+
// the only place the plugin turns a raw value into something the rail can use;
|
|
6
|
+
// every other module coerces through them rather than re-checking shapes.
|
|
7
|
+
// `SessionLike` is the minimal session shape the reads understand.
|
|
8
|
+
|
|
9
|
+
export type SessionLike = { cost?: unknown; model?: unknown; time?: unknown; tokens?: unknown };
|
|
10
|
+
|
|
11
|
+
export function asCount(value: unknown): number | undefined {
|
|
12
|
+
return typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : undefined;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function asText(value: unknown): string | undefined {
|
|
16
|
+
if (typeof value !== "string") return undefined;
|
|
17
|
+
const text = value.trim();
|
|
18
|
+
return text.length === 0 ? undefined : text;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function asRecord(value: unknown): Record<string, unknown> | undefined {
|
|
22
|
+
return typeof value === "object" && value !== null && !Array.isArray(value)
|
|
23
|
+
? (value as Record<string, unknown>)
|
|
24
|
+
: undefined;
|
|
25
|
+
}
|
package/src/tui/config.ts
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
import { DEFAULT_PLACEHOLDER, isStatField, STAT_FIELDS } from "./stats.js";
|
|
12
12
|
import type { CautionThresholds } from "./caution.js";
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
interface SidebarConfig {
|
|
15
15
|
/** Show the sidebar rail. Default `true`. */
|
|
16
16
|
readonly enabled: boolean;
|
|
17
17
|
/** Fixed lines rendered above the live rows. Default `DEFAULT_SIDEBAR_LINES`. */
|
|
@@ -27,7 +27,7 @@ export interface SidebarConfig {
|
|
|
27
27
|
readonly placeholder: string;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
|
|
30
|
+
interface FooterConfig {
|
|
31
31
|
/**
|
|
32
32
|
* Show the prompt-footer rail. Default `false`.
|
|
33
33
|
*
|
|
@@ -40,7 +40,7 @@ export interface FooterConfig {
|
|
|
40
40
|
readonly text: string;
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
|
|
43
|
+
interface CautionConfig {
|
|
44
44
|
/** Show the caution annunciator. Default `true`. */
|
|
45
45
|
readonly enabled: boolean;
|
|
46
46
|
/** A tool running longer than this is worth noting. Default `180`. */
|
|
@@ -56,12 +56,12 @@ export interface CautionConfig {
|
|
|
56
56
|
/**
|
|
57
57
|
* Tools that are slow by nature, so "slow" is not an anomaly for them.
|
|
58
58
|
*
|
|
59
|
-
* Calibrated against
|
|
60
|
-
* threshold, 307 calls exceed it — and
|
|
59
|
+
* Calibrated against 54,218 real settled tool calls: at a 180-second watch
|
|
60
|
+
* threshold, 307 calls exceed it — and 200 of those are these tools.
|
|
61
61
|
* `subagent` alone accounts for 152, with a p99 of 14.7 minutes. A delegated
|
|
62
62
|
* agent running a quarter of an hour is working as designed, and an
|
|
63
63
|
* annunciator that lights on every delegation is one you learn to ignore.
|
|
64
|
-
* With these exempt, 0.
|
|
64
|
+
* With these exempt, 0.20% of real calls cross the threshold.
|
|
65
65
|
*
|
|
66
66
|
* Matching is by exact tool name. Add your own long-running tools.
|
|
67
67
|
*/
|
|
@@ -108,7 +108,7 @@ export function cautionThresholds(config: CautionConfig): CautionThresholds {
|
|
|
108
108
|
}
|
|
109
109
|
|
|
110
110
|
/** Pure cosmetics: the geometry of a row. */
|
|
111
|
-
|
|
111
|
+
interface LayoutConfig {
|
|
112
112
|
/** Width of the row label column. Default `10`. */
|
|
113
113
|
readonly labelWidth: number;
|
|
114
114
|
/** Cells in the context gauge. Default `10`. */
|
|
@@ -124,25 +124,25 @@ export interface LayoutConfig {
|
|
|
124
124
|
* some terminals render `⚠` as a box or the wrong width. Swapping it for `!` is
|
|
125
125
|
* a worse-looking but working panel, which beats an unreadable one.
|
|
126
126
|
*/
|
|
127
|
-
|
|
127
|
+
interface GlyphConfig {
|
|
128
128
|
readonly watch: string;
|
|
129
129
|
readonly caution: string;
|
|
130
130
|
readonly clear: string;
|
|
131
131
|
}
|
|
132
132
|
|
|
133
|
-
|
|
133
|
+
const DEFAULT_LAYOUT: LayoutConfig = {
|
|
134
134
|
labelWidth: 10,
|
|
135
135
|
barWidth: 10,
|
|
136
136
|
sparkWidth: 12,
|
|
137
137
|
};
|
|
138
138
|
|
|
139
|
-
|
|
139
|
+
const DEFAULT_GLYPHS: GlyphConfig = {
|
|
140
140
|
watch: "▲",
|
|
141
141
|
caution: "⚠",
|
|
142
142
|
clear: "○",
|
|
143
143
|
};
|
|
144
144
|
|
|
145
|
-
|
|
145
|
+
const DEFAULT_CAUTION: CautionConfig = {
|
|
146
146
|
enabled: true,
|
|
147
147
|
toolWatchSeconds: 180,
|
|
148
148
|
toolCautionSeconds: 420,
|
|
@@ -244,7 +244,7 @@ function normalizeText(value: string, path: string, issues: string[]): string {
|
|
|
244
244
|
return value.replace(CONTROL_CHARS, " ").replace(/ {2,}/g, " ").trim();
|
|
245
245
|
}
|
|
246
246
|
|
|
247
|
-
|
|
247
|
+
interface ConfigResolution {
|
|
248
248
|
readonly config: FlightDeckConfig;
|
|
249
249
|
/** Human-readable problems found in the supplied options; empty when clean. */
|
|
250
250
|
readonly issues: readonly string[];
|
package/src/tui/file-config.ts
CHANGED
|
@@ -48,7 +48,7 @@ export interface FileConfig {
|
|
|
48
48
|
* Find the first config file that exists in `directory`, which defaults to the
|
|
49
49
|
* global config directory. A missing directory simply has no candidates.
|
|
50
50
|
*/
|
|
51
|
-
|
|
51
|
+
function findConfigFile(directory: string = globalConfigDirectory()): string | undefined {
|
|
52
52
|
for (const candidate of CONFIG_FILE_CANDIDATES) {
|
|
53
53
|
const path = join(directory, candidate);
|
|
54
54
|
if (existsSync(path)) return path;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
// Narrow-rail rendering: turn values into short strings and glyph strips.
|
|
2
|
+
//
|
|
3
|
+
// The sidebar is roughly thirty-odd columns wide, so every figure is shortened
|
|
4
|
+
// to something an agent can read in one glance: counts (`518k`), costs
|
|
5
|
+
// (`$0.023`), durations (`2h14m37s`), paths (clipped with an ellipsis), a
|
|
6
|
+
// ten-cell fuel gauge, and a sparkline shaped from recent turn sizes. All pure
|
|
7
|
+
// and dependency-free, so the formatting is trivial to test.
|
|
8
|
+
|
|
9
|
+
/** `518k`, `29.2M`, `32M`, `940` — short enough for a narrow rail, precise enough to read. */
|
|
10
|
+
export function formatCount(value: number): string {
|
|
11
|
+
if (value < 1_000) return String(Math.round(value));
|
|
12
|
+
// Round *before* choosing the unit. Rounding only inside the `k` branch made
|
|
13
|
+
// anything from 999,500 to 999,999 print as `1000k` — a number with two
|
|
14
|
+
// magnitudes in it, and one an agent reads as a different size entirely.
|
|
15
|
+
const thousands = Math.round(value / 1_000);
|
|
16
|
+
if (thousands < 1_000) return `${thousands}k`;
|
|
17
|
+
const millions = (value / 1_000_000).toFixed(1);
|
|
18
|
+
return `${millions.endsWith(".0") ? millions.slice(0, -2) : millions}M`;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** Sub-dollar sessions keep a third decimal so a cheap run never reads `$0.00`. */
|
|
22
|
+
export function formatCost(value: number): string {
|
|
23
|
+
return `$${value.toFixed(value < 1 ? 3 : 2)}`;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** `45s`, `14m07s`, `2h14m37s`. Seconds always show, so the row ticks every second. */
|
|
27
|
+
export function formatDuration(ms: number): string {
|
|
28
|
+
const total = Math.floor(ms / 1_000);
|
|
29
|
+
const seconds = total % 60;
|
|
30
|
+
const minutes = Math.floor(total / 60) % 60;
|
|
31
|
+
const hours = Math.floor(total / 3_600);
|
|
32
|
+
const ss = String(seconds).padStart(2, "0");
|
|
33
|
+
if (hours > 0) return `${hours}h${String(minutes).padStart(2, "0")}m${ss}s`;
|
|
34
|
+
return minutes > 0 ? `${minutes}m${ss}s` : `${seconds}s`;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Fuel-gauge width in cells when the caller does not override it. */
|
|
38
|
+
export const DEFAULT_BAR_WIDTH = 10;
|
|
39
|
+
|
|
40
|
+
/** A ten-cell gauge, so a percentage is readable at a glance rather than parsed. */
|
|
41
|
+
export function fuelBar(ratio: number, width: number = DEFAULT_BAR_WIDTH): string {
|
|
42
|
+
const cells = Math.max(1, Math.floor(width));
|
|
43
|
+
const filled = Math.max(0, Math.min(cells, Math.round(ratio * cells)));
|
|
44
|
+
return `${"█".repeat(filled)}${"░".repeat(cells - filled)}`;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const SPARK_LEVELS = ["▁", "▂", "▃", "▄", "▅", "▆", "▇", "█"] as const;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Shorten a value for a narrow rail.
|
|
51
|
+
*
|
|
52
|
+
* The sidebar is roughly thirty-odd columns wide and the label already costs
|
|
53
|
+
* ten, so a resource path has to be cut. The ellipsis is deliberate: a silently
|
|
54
|
+
* truncated path reads as a complete one.
|
|
55
|
+
*/
|
|
56
|
+
export function clip(text: string, max: number): string {
|
|
57
|
+
if (text.length <= max) return text;
|
|
58
|
+
const cut = text.slice(0, Math.max(1, max - 1));
|
|
59
|
+
// Never cut a surrogate pair in half: the orphaned half renders as a
|
|
60
|
+
// replacement character, which reads as corruption rather than as a shortened
|
|
61
|
+
// path. Losing one more column is the cheaper mistake.
|
|
62
|
+
const safe = /[\uD800-\uDBFF]$/.test(cut) ? cut.slice(0, -1) : cut;
|
|
63
|
+
return `${safe}…`;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Recent turn sizes as a shape.
|
|
68
|
+
*
|
|
69
|
+
* Scaled against the largest value in the window rather than an absolute scale,
|
|
70
|
+
* so the sparkline stays readable whether turns are tiny or enormous.
|
|
71
|
+
*/
|
|
72
|
+
export function sparkline(values: readonly number[]): string {
|
|
73
|
+
if (values.length === 0) return "";
|
|
74
|
+
const max = Math.max(...values);
|
|
75
|
+
if (!Number.isFinite(max) || max <= 0) return SPARK_LEVELS[0].repeat(values.length);
|
|
76
|
+
return values
|
|
77
|
+
.map((value) => {
|
|
78
|
+
const level = Math.floor((Math.max(0, value) / max) * (SPARK_LEVELS.length - 1));
|
|
79
|
+
return SPARK_LEVELS[Math.min(SPARK_LEVELS.length - 1, level)];
|
|
80
|
+
})
|
|
81
|
+
.join("");
|
|
82
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// Guard-token rendering for the `guard` row.
|
|
2
|
+
//
|
|
3
|
+
// The harness-guard RPC payload is untrusted: these helpers turn it into one
|
|
4
|
+
// short ASCII token, or `undefined` when there is nothing usable to show. They
|
|
5
|
+
// live here rather than in ./rows.js so the row renderer stays rendering.
|
|
6
|
+
|
|
7
|
+
import { asRecord } from "./coerce.js";
|
|
8
|
+
import { formatCount } from "./format.js";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* A guard count: a non-negative whole number, or an array counted by length.
|
|
12
|
+
*
|
|
13
|
+
* The RPC aggregates are numbers, but an array (findings, breaches) reads the
|
|
14
|
+
* same way — how many — so both count. Anything else is dropped to `undefined`
|
|
15
|
+
* so the caller can fall back to zero rather than print garbage.
|
|
16
|
+
*/
|
|
17
|
+
function asGuardCount(value: unknown): number | undefined {
|
|
18
|
+
if (typeof value === "number" && Number.isFinite(value) && value >= 0) return Math.floor(value);
|
|
19
|
+
if (Array.isArray(value)) return value.length;
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function guardCountOrZero(...candidates: readonly unknown[]): number {
|
|
24
|
+
for (const candidate of candidates) {
|
|
25
|
+
const count = asGuardCount(candidate);
|
|
26
|
+
if (count !== undefined) return count;
|
|
27
|
+
}
|
|
28
|
+
return 0;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Short harness token for the `guard` row, or `undefined` when there is no
|
|
33
|
+
* usable data (the persist layer then renders the placeholder).
|
|
34
|
+
*
|
|
35
|
+
* A section counts as usable only with an explicit boolean `available`: a
|
|
36
|
+
* present section with a missing or garbage flag is dropped, not read as
|
|
37
|
+
* either `ok` or `unknown`. Any usable section reporting `available: false`
|
|
38
|
+
* reads as `unknown` — a failed or disabled source never renders a false `ok`.
|
|
39
|
+
* Otherwise the worst signal wins: breaches, then orphans, then findings.
|
|
40
|
+
* ASCII, short, no padding.
|
|
41
|
+
*/
|
|
42
|
+
export function guardToken(value: unknown): string | undefined {
|
|
43
|
+
try {
|
|
44
|
+
const top = asRecord(value);
|
|
45
|
+
if (top === undefined) return undefined;
|
|
46
|
+
|
|
47
|
+
const air = asRecord(top.airworthiness);
|
|
48
|
+
const war = asRecord(top.warden);
|
|
49
|
+
const plan = asRecord(top.flightPlan);
|
|
50
|
+
|
|
51
|
+
const airUsable = air !== undefined && (air.available === true || air.available === false);
|
|
52
|
+
const warUsable = war !== undefined && (war.available === true || war.available === false);
|
|
53
|
+
const planUsable = plan !== undefined && (plan.available === true || plan.available === false);
|
|
54
|
+
if (!airUsable && !warUsable && !planUsable) return undefined;
|
|
55
|
+
|
|
56
|
+
if ((airUsable && air.available === false) || (warUsable && war.available === false) || (planUsable && plan.available === false)) {
|
|
57
|
+
return "unknown";
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const breaches = warUsable ? guardCountOrZero(war.breaches) : 0;
|
|
61
|
+
const orphans = warUsable ? guardCountOrZero(war.orphans) : 0;
|
|
62
|
+
const findings = airUsable ? guardCountOrZero(air.findings, air.counts) : 0;
|
|
63
|
+
|
|
64
|
+
// Abbreviated so a huge count cannot exceed the rail width; stays ASCII.
|
|
65
|
+
if (breaches > 0) return `${formatCount(breaches)} breach`;
|
|
66
|
+
if (orphans > 0) return `${formatCount(orphans)} orphan`;
|
|
67
|
+
if (findings > 0) return `${formatCount(findings)} finding`;
|
|
68
|
+
return "ok";
|
|
69
|
+
} catch {
|
|
70
|
+
return undefined;
|
|
71
|
+
}
|
|
72
|
+
}
|
package/src/tui/guard.ts
CHANGED
|
@@ -30,22 +30,22 @@
|
|
|
30
30
|
// the persist layer renders the placeholder.
|
|
31
31
|
|
|
32
32
|
/** Aggregates from guard's `status` output. Only what the row needs. */
|
|
33
|
-
|
|
33
|
+
interface GuardAirworthiness {
|
|
34
34
|
readonly available: boolean;
|
|
35
35
|
readonly findings: number;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
|
|
38
|
+
interface GuardWarden {
|
|
39
39
|
readonly available: boolean;
|
|
40
40
|
readonly breaches: number;
|
|
41
41
|
readonly orphans: number;
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
|
|
44
|
+
interface GuardFlightPlan {
|
|
45
45
|
readonly available: boolean;
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
|
|
48
|
+
interface GuardStatus {
|
|
49
49
|
readonly airworthiness?: GuardAirworthiness;
|
|
50
50
|
readonly warden?: GuardWarden;
|
|
51
51
|
readonly flightPlan?: GuardFlightPlan;
|
|
@@ -83,7 +83,7 @@ export interface GuardDeps {
|
|
|
83
83
|
readonly status: (input: { readonly sessionID: string }) => Promise<unknown>;
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
-
|
|
86
|
+
interface GuardBridge {
|
|
87
87
|
/**
|
|
88
88
|
* Current status, read from the host's store.
|
|
89
89
|
*
|