oc-flight-deck 0.1.2 → 0.2.1
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 +82 -10
- package/flight-deck.example.jsonc +173 -100
- package/flight-deck.schema.json +178 -0
- package/package.json +2 -1
- package/src/tui/caution.ts +411 -0
- package/src/tui/config.ts +284 -7
- package/src/tui/index.tsx +129 -4
- package/src/tui/presentation.ts +1 -1
- package/src/tui/stats.ts +131 -19
package/src/tui/config.ts
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
// defaults below, so the rail always renders and a typo can never break the TUI.
|
|
10
10
|
|
|
11
11
|
import { isStatField, STAT_FIELDS } from "./stats.js";
|
|
12
|
+
import type { CautionThresholds } from "./caution.js";
|
|
12
13
|
|
|
13
14
|
export interface SidebarConfig {
|
|
14
15
|
/** Show the sidebar rail. Default `true`. */
|
|
@@ -32,20 +33,126 @@ export interface FooterConfig {
|
|
|
32
33
|
readonly text: string;
|
|
33
34
|
}
|
|
34
35
|
|
|
36
|
+
export interface CautionConfig {
|
|
37
|
+
/** Show the caution annunciator. Default `true`. */
|
|
38
|
+
readonly enabled: boolean;
|
|
39
|
+
/** A tool running longer than this is worth noting. Default `180`. */
|
|
40
|
+
readonly toolWatchSeconds: number;
|
|
41
|
+
/** ... and longer than this is a real caution. Default `420`. */
|
|
42
|
+
readonly toolCautionSeconds: number;
|
|
43
|
+
/** A running session quiet for this long is worth noting. Default `600`. */
|
|
44
|
+
readonly turnWatchSeconds: number;
|
|
45
|
+
/** ... and quieter than this is a real caution. Default `1200`. */
|
|
46
|
+
readonly turnCautionSeconds: number;
|
|
47
|
+
/** Identical consecutive calls before it counts as a loop. Default `3`. */
|
|
48
|
+
readonly repeatThreshold: number;
|
|
49
|
+
/**
|
|
50
|
+
* Tools that are slow by nature, so "slow" is not an anomaly for them.
|
|
51
|
+
*
|
|
52
|
+
* Calibrated against 53,672 real settled tool calls: at a 180-second watch
|
|
53
|
+
* threshold, 307 calls exceed it — and 218 of those are these tools.
|
|
54
|
+
* `subagent` alone accounts for 152, with a p99 of 14.7 minutes. A delegated
|
|
55
|
+
* agent running a quarter of an hour is working as designed, and an
|
|
56
|
+
* annunciator that lights on every delegation is one you learn to ignore.
|
|
57
|
+
* With these exempt, 0.16% of real calls cross the threshold.
|
|
58
|
+
*
|
|
59
|
+
* Matching is by exact tool name. Add your own long-running tools.
|
|
60
|
+
*/
|
|
61
|
+
readonly exemptTools: readonly string[];
|
|
62
|
+
/** Raise a toast the first time a caution appears, once per distinct problem. */
|
|
63
|
+
readonly toast: boolean;
|
|
64
|
+
}
|
|
65
|
+
|
|
35
66
|
export interface FlightDeckConfig {
|
|
36
67
|
readonly sidebar: SidebarConfig;
|
|
37
68
|
readonly footer: FooterConfig;
|
|
69
|
+
/**
|
|
70
|
+
* The annunciator: the one thing on the rail that is not session state.
|
|
71
|
+
*
|
|
72
|
+
* It exists because a hang emits no events, so nothing else here can see it.
|
|
73
|
+
* Silent when healthy, which is why it costs nothing visually.
|
|
74
|
+
*/
|
|
75
|
+
readonly caution: CautionConfig;
|
|
76
|
+
/** Geometry of a row. Every value has a sane default. */
|
|
77
|
+
readonly layout: LayoutConfig;
|
|
78
|
+
/** Glyphs for the annunciator, for terminals that render the defaults badly. */
|
|
79
|
+
readonly glyphs: GlyphConfig;
|
|
38
80
|
/**
|
|
39
81
|
* Update cadence in milliseconds for time-derived rows.
|
|
40
82
|
*
|
|
41
83
|
* Cost and tokens arrive with events, so they stay current without a timer.
|
|
42
|
-
* Anything derived from the clock — `elapsed`,
|
|
43
|
-
*
|
|
44
|
-
* off, leaving every row event-driven.
|
|
84
|
+
* Anything derived from the clock — `elapsed`, the status spinner's frames,
|
|
85
|
+
* and the annunciator's escalating thresholds — has nothing to react to, so
|
|
86
|
+
* it needs a tick. `0` turns the ticker off, leaving every row event-driven.
|
|
45
87
|
*/
|
|
46
88
|
readonly refresh: number;
|
|
47
89
|
}
|
|
48
90
|
|
|
91
|
+
/** The millisecond view the rules in ./caution.ts operate on. */
|
|
92
|
+
export function cautionThresholds(config: CautionConfig): CautionThresholds {
|
|
93
|
+
return {
|
|
94
|
+
toolWatchMs: config.toolWatchSeconds * 1_000,
|
|
95
|
+
toolCautionMs: config.toolCautionSeconds * 1_000,
|
|
96
|
+
turnWatchMs: config.turnWatchSeconds * 1_000,
|
|
97
|
+
turnCautionMs: config.turnCautionSeconds * 1_000,
|
|
98
|
+
repeatThreshold: config.repeatThreshold,
|
|
99
|
+
exemptTools: config.exemptTools,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** Pure cosmetics: the geometry of a row. */
|
|
104
|
+
export interface LayoutConfig {
|
|
105
|
+
/** Width of the row label column. Default `10`. */
|
|
106
|
+
readonly labelWidth: number;
|
|
107
|
+
/** Cells in the context gauge. Default `10`. */
|
|
108
|
+
readonly barWidth: number;
|
|
109
|
+
/** Samples drawn in the sparkline. Default `12`. */
|
|
110
|
+
readonly sparkWidth: number;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* The annunciator's glyphs.
|
|
115
|
+
*
|
|
116
|
+
* Configurable because this is the one row that has to read at a glance, and
|
|
117
|
+
* some terminals render `⚠` as a box or the wrong width. Swapping it for `!` is
|
|
118
|
+
* a worse-looking but working panel, which beats an unreadable one.
|
|
119
|
+
*/
|
|
120
|
+
export interface GlyphConfig {
|
|
121
|
+
readonly watch: string;
|
|
122
|
+
readonly caution: string;
|
|
123
|
+
readonly clear: string;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export const DEFAULT_LAYOUT: LayoutConfig = {
|
|
127
|
+
labelWidth: 10,
|
|
128
|
+
barWidth: 10,
|
|
129
|
+
sparkWidth: 12,
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
export const DEFAULT_GLYPHS: GlyphConfig = {
|
|
133
|
+
watch: "▲",
|
|
134
|
+
caution: "⚠",
|
|
135
|
+
clear: "○",
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
export const DEFAULT_CAUTION: CautionConfig = {
|
|
139
|
+
enabled: true,
|
|
140
|
+
toolWatchSeconds: 180,
|
|
141
|
+
toolCautionSeconds: 420,
|
|
142
|
+
turnWatchSeconds: 600,
|
|
143
|
+
turnCautionSeconds: 1200,
|
|
144
|
+
repeatThreshold: 3,
|
|
145
|
+
exemptTools: ["question", "task", "subagent", "agent", "delegate", "delegate_many", "delegate_task"],
|
|
146
|
+
/**
|
|
147
|
+
* Off by default. The rail is the signal; a toast is an interruption.
|
|
148
|
+
*
|
|
149
|
+
* The annunciator's job is to sit there and be ignorable until it isn't, and a
|
|
150
|
+
* notification that takes over the screen is the opposite of that. It is worth
|
|
151
|
+
* turning on if you walk away from long runs, which is why it exists at all.
|
|
152
|
+
*/
|
|
153
|
+
toast: false,
|
|
154
|
+
};
|
|
155
|
+
|
|
49
156
|
/**
|
|
50
157
|
* Fixed lines shown above the live rows — branding only.
|
|
51
158
|
*
|
|
@@ -64,12 +171,12 @@ export const DEFAULT_SIDEBAR_LINES: readonly string[] = [
|
|
|
64
171
|
* install shows real numbers with no configuration file at all.
|
|
65
172
|
*/
|
|
66
173
|
export const DEFAULT_SIDEBAR_ROWS: readonly string[] = [
|
|
174
|
+
"caution",
|
|
67
175
|
"status",
|
|
68
176
|
"agent",
|
|
69
177
|
"model",
|
|
70
178
|
"branch",
|
|
71
179
|
"cost",
|
|
72
|
-
"total",
|
|
73
180
|
"project",
|
|
74
181
|
"tokens",
|
|
75
182
|
"cache",
|
|
@@ -77,7 +184,6 @@ export const DEFAULT_SIDEBAR_ROWS: readonly string[] = [
|
|
|
77
184
|
"perms",
|
|
78
185
|
"elapsed",
|
|
79
186
|
"tps",
|
|
80
|
-
"spark",
|
|
81
187
|
];
|
|
82
188
|
|
|
83
189
|
/**
|
|
@@ -104,6 +210,9 @@ export const DEFAULT_FOOTER_TEXT = "Flight Deck";
|
|
|
104
210
|
export const DEFAULT_CONFIG: FlightDeckConfig = {
|
|
105
211
|
sidebar: { enabled: true, lines: DEFAULT_SIDEBAR_LINES, rows: DEFAULT_SIDEBAR_ROWS },
|
|
106
212
|
footer: { enabled: false, text: DEFAULT_FOOTER_TEXT },
|
|
213
|
+
caution: DEFAULT_CAUTION,
|
|
214
|
+
layout: DEFAULT_LAYOUT,
|
|
215
|
+
glyphs: DEFAULT_GLYPHS,
|
|
107
216
|
refresh: DEFAULT_REFRESH_MS,
|
|
108
217
|
};
|
|
109
218
|
|
|
@@ -230,7 +339,10 @@ function readRows(value: unknown, issues: string[]): readonly string[] {
|
|
|
230
339
|
return rows.slice(0, MAX_LINES);
|
|
231
340
|
}
|
|
232
341
|
|
|
233
|
-
|
|
342
|
+
/** Every config section that can be set from the file and overridden by the host. */
|
|
343
|
+
type SectionKey = "sidebar" | "footer" | "caution" | "layout" | "glyphs";
|
|
344
|
+
|
|
345
|
+
function sectionOf(options: Record<string, unknown>, key: SectionKey): Record<string, unknown> {
|
|
234
346
|
const value = options[key];
|
|
235
347
|
return isRecord(value) ? value : {};
|
|
236
348
|
}
|
|
@@ -259,7 +371,11 @@ function readRefresh(value: unknown, issues: string[]): number {
|
|
|
259
371
|
return value;
|
|
260
372
|
}
|
|
261
373
|
|
|
262
|
-
function mergeSection(
|
|
374
|
+
function mergeSection(
|
|
375
|
+
file: Record<string, unknown>,
|
|
376
|
+
host: Record<string, unknown>,
|
|
377
|
+
key: SectionKey,
|
|
378
|
+
): unknown {
|
|
263
379
|
const fileValue = file[key];
|
|
264
380
|
const hostValue = host[key];
|
|
265
381
|
// A malformed section from either source replaces the other and is reported
|
|
@@ -284,6 +400,157 @@ export function mergeOptions(fileOptions: unknown, hostOptions: unknown): Record
|
|
|
284
400
|
...host,
|
|
285
401
|
sidebar: mergeSection(file, host, "sidebar"),
|
|
286
402
|
footer: mergeSection(file, host, "footer"),
|
|
403
|
+
caution: mergeSection(file, host, "caution"),
|
|
404
|
+
layout: mergeSection(file, host, "layout"),
|
|
405
|
+
glyphs: mergeSection(file, host, "glyphs"),
|
|
406
|
+
};
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
/**
|
|
410
|
+
* A non-negative whole number, or the default with a reported issue.
|
|
411
|
+
*
|
|
412
|
+
* Used for both seconds and counts: the validation is identical, and the path
|
|
413
|
+
* in the message tells the reader which they are looking at.
|
|
414
|
+
*/
|
|
415
|
+
function readNumber(
|
|
416
|
+
value: unknown,
|
|
417
|
+
fallback: number,
|
|
418
|
+
path: string,
|
|
419
|
+
issues: string[],
|
|
420
|
+
min: number,
|
|
421
|
+
max: number = Number.POSITIVE_INFINITY,
|
|
422
|
+
): number {
|
|
423
|
+
if (value === undefined) return fallback;
|
|
424
|
+
if (typeof value !== "number" || !Number.isFinite(value)) {
|
|
425
|
+
issues.push(`${path} must be a number; using the default`);
|
|
426
|
+
return fallback;
|
|
427
|
+
}
|
|
428
|
+
if (value < min || value > max) {
|
|
429
|
+
const limit = max === Number.POSITIVE_INFINITY ? `at least ${min}` : `between ${min} and ${max}`;
|
|
430
|
+
issues.push(`${path} must be ${limit}; using the default`);
|
|
431
|
+
return fallback;
|
|
432
|
+
}
|
|
433
|
+
return Math.floor(value);
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
function readLayout(section: Record<string, unknown>, issues: string[]): LayoutConfig {
|
|
437
|
+
return {
|
|
438
|
+
// The label column has to fit "caution" plus a space, and must not eat the
|
|
439
|
+
// rail: six is the narrowest still legible, twenty-four is all of it.
|
|
440
|
+
labelWidth: readNumber(section["labelWidth"], DEFAULT_LAYOUT.labelWidth, "layout.labelWidth", issues, 6, 24),
|
|
441
|
+
barWidth: readNumber(section["barWidth"], DEFAULT_LAYOUT.barWidth, "layout.barWidth", issues, 1, 40),
|
|
442
|
+
sparkWidth: readNumber(section["sparkWidth"], DEFAULT_LAYOUT.sparkWidth, "layout.sparkWidth", issues, 2, 64),
|
|
443
|
+
};
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
/**
|
|
447
|
+
* One glyph, validated for width.
|
|
448
|
+
*
|
|
449
|
+
* A glyph wider than two cells pushes every row out of alignment, and a control
|
|
450
|
+
* character can break the renderer outright — so both fall back rather than
|
|
451
|
+
* being passed through.
|
|
452
|
+
*/
|
|
453
|
+
function readGlyph(value: unknown, fallback: string, path: string, issues: string[]): string {
|
|
454
|
+
if (value === undefined) return fallback;
|
|
455
|
+
if (typeof value !== "string") {
|
|
456
|
+
issues.push(`${path} must be a string; using the default`);
|
|
457
|
+
return fallback;
|
|
458
|
+
}
|
|
459
|
+
const text = value.trim();
|
|
460
|
+
if (text.length === 0 || [...text].length > 2) {
|
|
461
|
+
issues.push(`${path} must be one or two characters; using the default`);
|
|
462
|
+
return fallback;
|
|
463
|
+
}
|
|
464
|
+
if (CONTROL_CHAR.test(text)) {
|
|
465
|
+
issues.push(`${path} contained control characters; using the default`);
|
|
466
|
+
return fallback;
|
|
467
|
+
}
|
|
468
|
+
return text;
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
function readGlyphs(section: Record<string, unknown>, issues: string[]): GlyphConfig {
|
|
472
|
+
return {
|
|
473
|
+
watch: readGlyph(section["watch"], DEFAULT_GLYPHS.watch, "glyphs.watch", issues),
|
|
474
|
+
caution: readGlyph(section["caution"], DEFAULT_GLYPHS.caution, "glyphs.caution", issues),
|
|
475
|
+
clear: readGlyph(section["clear"], DEFAULT_GLYPHS.clear, "glyphs.clear", issues),
|
|
476
|
+
};
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
/** Tool names, matched exactly. A malformed list falls back whole, not partly. */
|
|
480
|
+
function readToolNames(value: unknown, issues: string[]): readonly string[] {
|
|
481
|
+
if (value === undefined) return DEFAULT_CAUTION.exemptTools;
|
|
482
|
+
if (!Array.isArray(value)) {
|
|
483
|
+
issues.push("caution.exemptTools must be an array of tool names; using the default");
|
|
484
|
+
return DEFAULT_CAUTION.exemptTools;
|
|
485
|
+
}
|
|
486
|
+
const names: string[] = [];
|
|
487
|
+
for (const entry of value) {
|
|
488
|
+
if (typeof entry !== "string" || entry.trim().length === 0) {
|
|
489
|
+
issues.push("caution.exemptTools must contain only non-empty tool names; using the default");
|
|
490
|
+
return DEFAULT_CAUTION.exemptTools;
|
|
491
|
+
}
|
|
492
|
+
names.push(entry.trim());
|
|
493
|
+
}
|
|
494
|
+
return names;
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
function readCaution(section: Record<string, unknown>, issues: string[]): CautionConfig {
|
|
498
|
+
const toolWatchSeconds = readNumber(
|
|
499
|
+
section["toolWatchSeconds"],
|
|
500
|
+
DEFAULT_CAUTION.toolWatchSeconds,
|
|
501
|
+
"caution.toolWatchSeconds",
|
|
502
|
+
issues,
|
|
503
|
+
0,
|
|
504
|
+
);
|
|
505
|
+
const turnWatchSeconds = readNumber(
|
|
506
|
+
section["turnWatchSeconds"],
|
|
507
|
+
DEFAULT_CAUTION.turnWatchSeconds,
|
|
508
|
+
"caution.turnWatchSeconds",
|
|
509
|
+
issues,
|
|
510
|
+
0,
|
|
511
|
+
);
|
|
512
|
+
|
|
513
|
+
// A caution threshold at or below its watch threshold makes the escalating
|
|
514
|
+
// state unreachable. Raise it and say so, rather than accept a config that
|
|
515
|
+
// cannot do what it claims.
|
|
516
|
+
let toolCautionSeconds = readNumber(
|
|
517
|
+
section["toolCautionSeconds"],
|
|
518
|
+
DEFAULT_CAUTION.toolCautionSeconds,
|
|
519
|
+
"caution.toolCautionSeconds",
|
|
520
|
+
issues,
|
|
521
|
+
0,
|
|
522
|
+
);
|
|
523
|
+
let turnCautionSeconds = readNumber(
|
|
524
|
+
section["turnCautionSeconds"],
|
|
525
|
+
DEFAULT_CAUTION.turnCautionSeconds,
|
|
526
|
+
"caution.turnCautionSeconds",
|
|
527
|
+
issues,
|
|
528
|
+
0,
|
|
529
|
+
);
|
|
530
|
+
if (toolCautionSeconds < toolWatchSeconds) {
|
|
531
|
+
issues.push("caution.toolCautionSeconds is below caution.toolWatchSeconds; raised to match");
|
|
532
|
+
toolCautionSeconds = toolWatchSeconds;
|
|
533
|
+
}
|
|
534
|
+
if (turnCautionSeconds < turnWatchSeconds) {
|
|
535
|
+
issues.push("caution.turnCautionSeconds is below caution.turnWatchSeconds; raised to match");
|
|
536
|
+
turnCautionSeconds = turnWatchSeconds;
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
return {
|
|
540
|
+
enabled: readBoolean(section["enabled"], DEFAULT_CAUTION.enabled, "caution.enabled", issues),
|
|
541
|
+
toolWatchSeconds,
|
|
542
|
+
toolCautionSeconds,
|
|
543
|
+
turnWatchSeconds,
|
|
544
|
+
turnCautionSeconds,
|
|
545
|
+
repeatThreshold: readNumber(
|
|
546
|
+
section["repeatThreshold"],
|
|
547
|
+
DEFAULT_CAUTION.repeatThreshold,
|
|
548
|
+
"caution.repeatThreshold",
|
|
549
|
+
issues,
|
|
550
|
+
2,
|
|
551
|
+
),
|
|
552
|
+
exemptTools: readToolNames(section["exemptTools"], issues),
|
|
553
|
+
toast: readBoolean(section["toast"], DEFAULT_CAUTION.toast, "caution.toast", issues),
|
|
287
554
|
};
|
|
288
555
|
}
|
|
289
556
|
|
|
@@ -307,15 +574,22 @@ export function resolveConfig(options: unknown): ConfigResolution {
|
|
|
307
574
|
|
|
308
575
|
const rawSidebar = options.sidebar;
|
|
309
576
|
const rawFooter = options.footer;
|
|
577
|
+
const rawCaution = options.caution;
|
|
310
578
|
if (rawSidebar !== undefined && !isRecord(rawSidebar)) {
|
|
311
579
|
issues.push("sidebar must be an object; using defaults");
|
|
312
580
|
}
|
|
313
581
|
if (rawFooter !== undefined && !isRecord(rawFooter)) {
|
|
314
582
|
issues.push("footer must be an object; using defaults");
|
|
315
583
|
}
|
|
584
|
+
if (rawCaution !== undefined && !isRecord(rawCaution)) {
|
|
585
|
+
issues.push("caution must be an object; using defaults");
|
|
586
|
+
}
|
|
316
587
|
|
|
317
588
|
const sidebar = isRecord(rawSidebar) ? rawSidebar : {};
|
|
318
589
|
const footer = isRecord(rawFooter) ? rawFooter : {};
|
|
590
|
+
const caution = isRecord(rawCaution) ? rawCaution : {};
|
|
591
|
+
const layout = isRecord(options.layout) ? options.layout : {};
|
|
592
|
+
const glyphs = isRecord(options.glyphs) ? options.glyphs : {};
|
|
319
593
|
|
|
320
594
|
// Writing any footer setting counts as asking for the footer, so the rail
|
|
321
595
|
// turns on as soon as you configure it. It is off only when you said nothing
|
|
@@ -333,6 +607,9 @@ export function resolveConfig(options: unknown): ConfigResolution {
|
|
|
333
607
|
enabled: readBoolean(footer.enabled, footerConfigured, "footer.enabled", issues),
|
|
334
608
|
text: readText(footer.text, DEFAULT_CONFIG.footer.text, "footer.text", issues),
|
|
335
609
|
},
|
|
610
|
+
caution: readCaution(caution, issues),
|
|
611
|
+
layout: readLayout(layout, issues),
|
|
612
|
+
glyphs: readGlyphs(glyphs, issues),
|
|
336
613
|
refresh: readRefresh(options.refresh, issues),
|
|
337
614
|
},
|
|
338
615
|
issues,
|
package/src/tui/index.tsx
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/** @jsxImportSource @opentui/solid */
|
|
2
2
|
import { Plugin } from "@opencode/plugin/tui";
|
|
3
|
-
import {
|
|
3
|
+
import { cautionDetail, cautionText, detectCautions, worstCaution, type Caution } from "./caution.js";
|
|
4
|
+
import { cautionThresholds, mergeOptions, resolveConfig } from "./config.js";
|
|
4
5
|
import { loadConfigFile } from "./file-config.js";
|
|
5
6
|
import { footerLine, liveRowOffset, sidebarLines } from "./presentation.js";
|
|
6
7
|
import { ANIMATED_FIELDS, type StatSource } from "./stats.js";
|
|
@@ -23,6 +24,9 @@ import { startTicker } from "./ticker.js";
|
|
|
23
24
|
// 3. the sane defaults in ./config.ts
|
|
24
25
|
// See flight-deck.example.jsonc for the commented template.
|
|
25
26
|
|
|
27
|
+
/** How many trailing messages are inspected for tool parts. */
|
|
28
|
+
const RECENT_MESSAGES = 4;
|
|
29
|
+
|
|
26
30
|
type SessionLike = { cost?: unknown; model?: unknown; time?: unknown };
|
|
27
31
|
|
|
28
32
|
function asCount(value: unknown): number | undefined {
|
|
@@ -160,9 +164,69 @@ export default Plugin.define({
|
|
|
160
164
|
}
|
|
161
165
|
};
|
|
162
166
|
|
|
163
|
-
|
|
167
|
+
// Recent tool parts, oldest first. Only the tail is inspected: a loop that is
|
|
168
|
+
// not currently happening is history, and a hang is by definition now.
|
|
169
|
+
const recentParts = (sessionID: string): readonly unknown[] => {
|
|
170
|
+
const parts: unknown[] = [];
|
|
171
|
+
for (const entry of messagesOf(sessionID).slice(-RECENT_MESSAGES)) {
|
|
172
|
+
const content = asRecord(entry)?.["content"];
|
|
173
|
+
if (Array.isArray(content)) parts.push(...content);
|
|
174
|
+
}
|
|
175
|
+
return parts;
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
// The host's own shell records, which outlive the tool call: a backgrounded
|
|
179
|
+
// command returns its result immediately, so its part settles while the
|
|
180
|
+
// process keeps running. This is the only signal that survives that.
|
|
181
|
+
const shellsOf = (sessionID: string): readonly unknown[] => {
|
|
164
182
|
try {
|
|
165
|
-
|
|
183
|
+
const shellApi = context.data.shell as unknown as
|
|
184
|
+
| { listBySession?: (id: string) => readonly unknown[] }
|
|
185
|
+
| undefined;
|
|
186
|
+
return shellApi?.listBySession?.(sessionID) ?? [];
|
|
187
|
+
} catch {
|
|
188
|
+
return [];
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
// The newest thing the host recorded for this session that is not a tool
|
|
193
|
+
// part, so the quiet-turn rule is not blind to a model that is streaming.
|
|
194
|
+
const lastActivity = (sessionID: string): number | undefined => {
|
|
195
|
+
const messages = messagesOf(sessionID);
|
|
196
|
+
for (let index = messages.length - 1; index >= 0; index -= 1) {
|
|
197
|
+
const time = asRecord(asRecord(messages[index])?.["time"]);
|
|
198
|
+
const stamp =
|
|
199
|
+
asCount(time?.["completed"]) ?? asCount(time?.["streamed"]) ?? asCount(time?.["created"]);
|
|
200
|
+
if (stamp !== undefined) return stamp;
|
|
201
|
+
}
|
|
202
|
+
return undefined;
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
const cautionThreshold = cautionThresholds(config.caution);
|
|
206
|
+
|
|
207
|
+
const cautionsOf = (sessionID: string, now: number): Caution[] =>
|
|
208
|
+
detectCautions({
|
|
209
|
+
parts: recentParts(sessionID),
|
|
210
|
+
shells: shellsOf(sessionID),
|
|
211
|
+
now,
|
|
212
|
+
sessionRunning: statusOf(sessionID) === "running",
|
|
213
|
+
lastMessageAt: lastActivity(sessionID),
|
|
214
|
+
thresholds: cautionThreshold,
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
// What is waiting, not just how many. A bare count tells you to go and look;
|
|
218
|
+
// naming the request tells you whether it is worth looking at.
|
|
219
|
+
const permsOf = (
|
|
220
|
+
sessionID: string,
|
|
221
|
+
): { count: number; action?: string; resource?: string } | undefined => {
|
|
222
|
+
try {
|
|
223
|
+
const requests = context.data.session.permission.list(sessionID);
|
|
224
|
+
if (requests === undefined || requests.length === 0) return undefined;
|
|
225
|
+
const first = asRecord(requests[0]);
|
|
226
|
+
const action = typeof first?.["action"] === "string" ? first["action"] : undefined;
|
|
227
|
+
const resources = Array.isArray(first?.["resources"]) ? first["resources"] : [];
|
|
228
|
+
const resource = typeof resources[0] === "string" ? resources[0] : undefined;
|
|
229
|
+
return { count: requests.length, action, resource };
|
|
166
230
|
} catch {
|
|
167
231
|
return undefined;
|
|
168
232
|
}
|
|
@@ -250,6 +314,19 @@ export default Plugin.define({
|
|
|
250
314
|
// Read session state inside the render so the rail stays live: cost and
|
|
251
315
|
// tokens climb as the session runs, and the branch appears once VCS
|
|
252
316
|
// resolves. Nothing here writes, requests, or leaves the process.
|
|
317
|
+
// Only the worst is ever drawn: the rail has one line for this, and two
|
|
318
|
+
// simultaneous observations is one problem with two symptoms.
|
|
319
|
+
//
|
|
320
|
+
// Returns a plain string, themed exactly like every other live row. The
|
|
321
|
+
// annunciator carries its meaning in its glyph, not in a colour of its own:
|
|
322
|
+
// a row that suddenly brightens reads as a different kind of thing rather
|
|
323
|
+
// than as the same panel telling you something.
|
|
324
|
+
const announce = (sessionID: string): string | undefined => {
|
|
325
|
+
if (!config.caution.enabled) return undefined;
|
|
326
|
+
const top = worstCaution(cautionsOf(sessionID, Date.now()));
|
|
327
|
+
return top === undefined ? undefined : cautionText(top, config.glyphs);
|
|
328
|
+
};
|
|
329
|
+
|
|
253
330
|
const snapshot = (sessionID: string): StatSource => {
|
|
254
331
|
const location = context.location ?? context.data.location.default();
|
|
255
332
|
const session = context.data.session.get(sessionID) as SessionLike | undefined;
|
|
@@ -257,6 +334,7 @@ export default Plugin.define({
|
|
|
257
334
|
|
|
258
335
|
return {
|
|
259
336
|
...session,
|
|
337
|
+
caution: announce(sessionID),
|
|
260
338
|
branch: context.data.location.vcs.info(location)?.branch?.current,
|
|
261
339
|
tree: treeTotals(sessionID, session?.cost),
|
|
262
340
|
context: contextUsage(sessionID, session?.model),
|
|
@@ -274,17 +352,62 @@ export default Plugin.define({
|
|
|
274
352
|
};
|
|
275
353
|
};
|
|
276
354
|
|
|
355
|
+
// The toast is opt-in and deliberately not the signal — the rail is. It
|
|
356
|
+
// fires on the transition into a caution, once per distinct problem, and
|
|
357
|
+
// re-arms when the session goes quiet, so a persistent hang cannot nag.
|
|
358
|
+
// Reading state on a timer rather than inside the render keeps the render a
|
|
359
|
+
// pure function of what it was given.
|
|
360
|
+
let watchedSession: string | undefined;
|
|
361
|
+
let toastedKey: string | undefined;
|
|
362
|
+
let watchTimer: ReturnType<typeof setInterval> | undefined;
|
|
363
|
+
|
|
364
|
+
if (config.caution.enabled && config.caution.toast) {
|
|
365
|
+
watchTimer = setInterval(() => {
|
|
366
|
+
const sessionID = watchedSession;
|
|
367
|
+
if (sessionID === undefined) return;
|
|
368
|
+
try {
|
|
369
|
+
const top = worstCaution(cautionsOf(sessionID, Date.now()));
|
|
370
|
+
if (top === undefined || top.severity !== "caution") {
|
|
371
|
+
toastedKey = undefined;
|
|
372
|
+
return;
|
|
373
|
+
}
|
|
374
|
+
if (top.key === toastedKey) return;
|
|
375
|
+
toastedKey = top.key;
|
|
376
|
+
context.ui.toast.show({
|
|
377
|
+
title: "Flight Deck",
|
|
378
|
+
message: cautionDetail(top),
|
|
379
|
+
variant: "warning",
|
|
380
|
+
});
|
|
381
|
+
} catch {
|
|
382
|
+
// A warning must never be able to break the panel it warns about.
|
|
383
|
+
}
|
|
384
|
+
}, config.refresh > 0 ? config.refresh : 1_000);
|
|
385
|
+
}
|
|
386
|
+
|
|
277
387
|
if (config.sidebar.enabled) {
|
|
278
388
|
releases.push(
|
|
279
389
|
context.ui.slot({
|
|
280
390
|
append: "sidebar.content",
|
|
281
391
|
render: ({ sessionID }) => {
|
|
282
|
-
|
|
392
|
+
// The annunciator is drawn from a timer, so the toast watcher needs
|
|
393
|
+
// to know which session is on screen. Reading the frame is what
|
|
394
|
+
// subscribes this render to the host's tick — without it nothing
|
|
395
|
+
// re-runs between host events, and a stall is precisely the failure
|
|
396
|
+
// that produces no host events at all.
|
|
397
|
+
watchedSession = sessionID;
|
|
398
|
+
void ticker?.frame;
|
|
399
|
+
|
|
400
|
+
const source = snapshot(sessionID);
|
|
401
|
+
const lines = sidebarLines(config, source);
|
|
283
402
|
if (lines.length === 0) return null;
|
|
284
403
|
const offset = Math.min(liveRowOffset(config), lines.length);
|
|
404
|
+
|
|
285
405
|
return (
|
|
286
406
|
// No padding here: the host already lays out and pads the sidebar,
|
|
287
407
|
// so adding our own would push the rows out of alignment with it.
|
|
408
|
+
//
|
|
409
|
+
// Every live row gets the same token, the annunciator included. It
|
|
410
|
+
// is the same panel; only the glyph changes.
|
|
288
411
|
<box flexDirection="column">
|
|
289
412
|
{lines.map((line, index) => (
|
|
290
413
|
<text fg={index < offset ? context.theme.text.default : context.theme.text.subdued}>{line}</text>
|
|
@@ -306,6 +429,8 @@ export default Plugin.define({
|
|
|
306
429
|
}
|
|
307
430
|
|
|
308
431
|
return () => {
|
|
432
|
+
if (watchTimer !== undefined) clearInterval(watchTimer);
|
|
433
|
+
watchTimer = undefined;
|
|
309
434
|
ticker?.dispose();
|
|
310
435
|
for (const release of releases) release();
|
|
311
436
|
};
|
package/src/tui/presentation.ts
CHANGED
|
@@ -18,7 +18,7 @@ import { statRows, type StatSource } from "./stats.js";
|
|
|
18
18
|
*/
|
|
19
19
|
export function sidebarLines(config: FlightDeckConfig, source: StatSource = {}): readonly string[] {
|
|
20
20
|
if (!config.sidebar.enabled) return [];
|
|
21
|
-
return [...config.sidebar.lines, ...statRows(config.sidebar.rows, source)].slice(0, MAX_LINES);
|
|
21
|
+
return [...config.sidebar.lines, ...statRows(config.sidebar.rows, source, config.layout)].slice(0, MAX_LINES);
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
/** Footer text to render, or `undefined` when the footer rail is disabled. */
|