oc-flight-deck 0.19.2 → 0.20.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/dist/tui/index.js CHANGED
@@ -246,8 +246,19 @@ function formatElapsed(ms) {
246
246
  }
247
247
 
248
248
  // src/tui/host-clipboard.ts
249
+ import { createHostClipboard as createCoreHostClipboard } from "@opentui/core";
250
+ var cached;
251
+ var attempted = false;
249
252
  function createHostClipboard() {
250
- return;
253
+ if (attempted)
254
+ return cached;
255
+ attempted = true;
256
+ try {
257
+ cached = createCoreHostClipboard();
258
+ } catch {
259
+ cached = undefined;
260
+ }
261
+ return cached;
251
262
  }
252
263
 
253
264
  // src/tui/clipboard.ts
@@ -265,6 +276,40 @@ function dispatchOsc52(renderer, text) {
265
276
  return false;
266
277
  }
267
278
  }
279
+ var READ_BACK_ATTEMPTS = 5;
280
+ var READ_BACK_INTERVAL_MS = 60;
281
+ function delay(ms) {
282
+ return new Promise((resolve) => setTimeout(resolve, ms));
283
+ }
284
+ async function readBackMatches(host, text) {
285
+ const read = host?.read;
286
+ if (host === undefined || read === undefined)
287
+ return false;
288
+ for (let attempt = 0;attempt < READ_BACK_ATTEMPTS; attempt += 1) {
289
+ if (attempt > 0)
290
+ await delay(READ_BACK_INTERVAL_MS);
291
+ let current;
292
+ try {
293
+ current = await read.call(host, { preferredTypes: ["text/plain"], selection: "clipboard" });
294
+ } catch {
295
+ return false;
296
+ }
297
+ if (current.status !== "read")
298
+ continue;
299
+ const bytes = current.representation?.bytes;
300
+ if (bytes === undefined)
301
+ continue;
302
+ let decoded;
303
+ try {
304
+ decoded = new TextDecoder().decode(bytes);
305
+ } catch {
306
+ return false;
307
+ }
308
+ if (decoded === text)
309
+ return true;
310
+ }
311
+ return false;
312
+ }
268
313
  async function copyToClipboard(renderer, text, createHost = createHostClipboard) {
269
314
  let hostReached = true;
270
315
  let hostStatus = "failed";
@@ -286,8 +331,11 @@ async function copyToClipboard(renderer, text, createHost = createHostClipboard)
286
331
  }
287
332
  if (hostStatus === "written")
288
333
  return { verified: true, outcome: "written" };
289
- if (dispatchOsc52(renderer, text))
334
+ if (dispatchOsc52(renderer, text)) {
335
+ if (await readBackMatches(host, text))
336
+ return { verified: true, outcome: "osc52-confirmed" };
290
337
  return { verified: false, outcome: "osc52-dispatched" };
338
+ }
291
339
  if (!hostReached)
292
340
  return { verified: false, outcome: "no-backend" };
293
341
  const outcome = hostStatus === "unsupported" || hostStatus === "cancelled" || hostStatus === "timed-out" || hostStatus === "failed" ? hostStatus : "failed";
@@ -301,8 +349,8 @@ function copyFeedback(result, id) {
301
349
  case "osc52-dispatched":
302
350
  return {
303
351
  ok: false,
304
- variant: "error",
305
- message: "Sent the session id to the terminal, but could not confirm it was copied."
352
+ variant: "warning",
353
+ message: "Sent the session id to the terminal; the terminal does not confirm copies, so paste to verify."
306
354
  };
307
355
  case "unsupported":
308
356
  return { ok: false, variant: "error", message: "This terminal cannot copy to the clipboard." };
@@ -319,14 +367,24 @@ function copyFeedback(result, id) {
319
367
  }
320
368
 
321
369
  // src/tui/format.ts
370
+ var COUNT_UNITS = [
371
+ ["M", 1e6],
372
+ ["B", 1e9],
373
+ ["T", 1000000000000]
374
+ ];
322
375
  function formatCount(value) {
323
376
  if (value < 1000)
324
377
  return String(Math.round(value));
325
378
  const thousands = Math.round(value / 1000);
326
379
  if (thousands < 1000)
327
380
  return `${thousands}k`;
328
- const millions = (value / 1e6).toFixed(1);
329
- return `${millions.endsWith(".0") ? millions.slice(0, -2) : millions}M`;
381
+ for (const [index, [suffix, size]] of COUNT_UNITS.entries()) {
382
+ const text = (value / size).toFixed(1);
383
+ if (index === COUNT_UNITS.length - 1 || Number(text) < 1000) {
384
+ return `${text.endsWith(".0") ? text.slice(0, -2) : text}${suffix}`;
385
+ }
386
+ }
387
+ throw new Error("unreachable: T is the terminal unit");
330
388
  }
331
389
  function formatCost(value) {
332
390
  return `$${value.toFixed(value < 1 ? 3 : 2)}`;
@@ -685,7 +743,7 @@ function skeletonValue(field, layout) {
685
743
  case "elapsed":
686
744
  return formatDuration(0, layout.durationStyle);
687
745
  case "tps":
688
- return "0 tok/s";
746
+ return layout.tpsDisplay === "both" ? "0 rt \xB7 0 avg" : "0 tok/s";
689
747
  case "spark":
690
748
  return "\u2581".repeat(Math.max(0, Math.floor(layout.sparkWidth ?? DEFAULT_SPARK_WIDTH)));
691
749
  case "reasoning":
@@ -947,13 +1005,31 @@ function statLine(field, source, layout = {}) {
947
1005
  return row("elapsed", formatDuration(ms, layout.durationStyle));
948
1006
  }
949
1007
  case "tps": {
950
- const tps = asCount2(source.tps);
951
- if (tps === undefined)
1008
+ const pair = asRecord2(source.tps);
1009
+ const rt = asCount2(pair?.["rt"]);
1010
+ const avg = asCount2(pair?.["avg"]);
1011
+ const ttft = asCount2(pair?.["ttft"]);
1012
+ const display = layout.tpsDisplay ?? "avg";
1013
+ if (display === "rt") {
1014
+ const rounded = rt === undefined ? undefined : Math.round(rt);
1015
+ if (rounded === undefined || rounded <= 0)
1016
+ return;
1017
+ return row("tps", `${rounded} tok/s`);
1018
+ }
1019
+ if (display === "both") {
1020
+ if (avg !== undefined) {
1021
+ if (Math.round(avg) <= 0)
1022
+ return;
1023
+ const head = `${rt === undefined ? 0 : Math.round(rt)} rt \xB7 ${Math.round(avg)} avg`;
1024
+ return ttft === undefined ? row("tps", head) : row("tps", `${head} \xB7 ${ttft.toFixed(1)}s ttft`);
1025
+ }
1026
+ if (rt !== undefined && Math.round(rt) > 0)
1027
+ return row("tps", `${Math.round(rt)} rt`);
952
1028
  return;
953
- const rounded = Math.round(tps);
954
- if (rounded <= 0)
1029
+ }
1030
+ if (avg === undefined || Math.round(avg) <= 0)
955
1031
  return;
956
- return row("tps", `${rounded} tok/s`);
1032
+ return row("tps", `${Math.round(avg)} tok/s`);
957
1033
  }
958
1034
  case "spark": {
959
1035
  const values = Array.isArray(source.spark) ? source.spark.map((value) => asCount2(value) ?? 0) : [];
@@ -1071,6 +1147,26 @@ function mergedSpanMs(accepted) {
1071
1147
  unionMs += openEnd - openStart;
1072
1148
  return unionMs;
1073
1149
  }
1150
+ function unionSpanTotals(spans) {
1151
+ const seen = new Set;
1152
+ const accepted = [];
1153
+ let tokens = 0;
1154
+ for (const span of spans) {
1155
+ const key = asText2(span.key);
1156
+ if (key === undefined || seen.has(key))
1157
+ continue;
1158
+ const start = asCount2(span.start);
1159
+ const end = asCount2(span.end);
1160
+ if (start === undefined || end === undefined)
1161
+ continue;
1162
+ const output = asCount2(span.tokens);
1163
+ const reasoning = asCount2(span.reasoning);
1164
+ seen.add(key);
1165
+ accepted.push({ start, end: Math.max(start, end) });
1166
+ tokens += (output ?? 0) + (reasoning ?? 0);
1167
+ }
1168
+ return { tokens, unionMs: mergedSpanMs(accepted) };
1169
+ }
1074
1170
  function unionSpanMs(spans) {
1075
1171
  const seen = new Set;
1076
1172
  const accepted = [];
@@ -1108,59 +1204,262 @@ function tpsNeedsRepaint(displayed, smoothed) {
1108
1204
  return smoothed !== 0;
1109
1205
  return Math.abs(smoothed - displayed) / Math.abs(displayed) >= TPS_REPAINT_RATIO;
1110
1206
  }
1111
- function unionGenerationTotals(spans) {
1112
- const seen = new Set;
1113
- const accepted = [];
1114
- let tokens = 0;
1115
- for (const span of spans) {
1116
- const key = asText2(span.key);
1117
- if (key === undefined || seen.has(key))
1118
- continue;
1119
- const start = asCount2(span.start);
1120
- const end = asCount2(span.end);
1121
- if (start === undefined || end === undefined)
1122
- continue;
1123
- const output = asCount2(span.tokens);
1124
- const reasoning = asCount2(span.reasoning);
1125
- seen.add(key);
1126
- accepted.push({ start, end: Math.max(start, end) });
1127
- tokens += (output ?? 0) + (reasoning ?? 0);
1207
+ function settledAverageRate(spans) {
1208
+ const { tokens, unionMs } = unionSpanTotals(spans);
1209
+ if (unionMs <= 0)
1210
+ return;
1211
+ return tokens / (unionMs / 1000);
1212
+ }
1213
+ // src/tui/realtime-tps.ts
1214
+ var RT_SAMPLE_WINDOW_MS = 5000;
1215
+ var RT_STALE_MS = 1500;
1216
+ var RT_MAX_STEPS = 100;
1217
+ var RT_MAX_SESSIONS = 50;
1218
+ function estimateDeltaTokens(delta) {
1219
+ const bytes = Buffer.byteLength(delta, "utf8");
1220
+ return bytes > 0 ? Math.max(1, Math.ceil(bytes / 5)) : 0;
1221
+ }
1222
+ function createRealtimeTps(context, opts) {
1223
+ const now = opts?.now ?? Date.now;
1224
+ const samples = new Map;
1225
+ const shown = new Map;
1226
+ const pendingStarts = new Map;
1227
+ const ttftRings = new Map;
1228
+ let disposed = false;
1229
+ let active = false;
1230
+ const releases = [];
1231
+ const remember = (sessionID, sample) => {
1232
+ const known = samples.get(sessionID);
1233
+ if (known !== undefined) {
1234
+ samples.delete(sessionID);
1235
+ known.push(sample);
1236
+ samples.set(sessionID, known);
1237
+ return;
1238
+ }
1239
+ if (samples.size >= RT_MAX_SESSIONS) {
1240
+ for (const oldest of samples.keys()) {
1241
+ samples.delete(oldest);
1242
+ break;
1243
+ }
1244
+ }
1245
+ samples.set(sessionID, [sample]);
1246
+ };
1247
+ const readDelta = (event) => {
1248
+ const record = asRecord2(event);
1249
+ const data = asRecord2(record?.["data"]);
1250
+ const sessionID = asText2(data?.["sessionID"]);
1251
+ const raw = data?.["delta"];
1252
+ const delta = typeof raw === "string" ? raw : undefined;
1253
+ if (sessionID === undefined || delta === undefined)
1254
+ return;
1255
+ const at = asCount2(record?.["created"]) ?? now();
1256
+ return { sessionID, delta, at };
1257
+ };
1258
+ const ingest = (event) => {
1259
+ if (disposed)
1260
+ return;
1261
+ const reading = readDelta(event);
1262
+ if (reading === undefined)
1263
+ return;
1264
+ remember(reading.sessionID, { at: reading.at, tokens: estimateDeltaTokens(reading.delta) });
1265
+ noteDelta(event, reading.at);
1266
+ };
1267
+ const noteDelta = (event, at) => {
1268
+ const messageID = asText2(asRecord2(asRecord2(event)?.["data"])?.["assistantMessageID"]);
1269
+ if (messageID === undefined)
1270
+ return;
1271
+ const pending = pendingStarts.get(messageID);
1272
+ if (pending === undefined)
1273
+ return;
1274
+ if (pending.earliest === undefined || at < pending.earliest)
1275
+ pending.earliest = at;
1276
+ };
1277
+ const stepStarted = (event) => {
1278
+ if (disposed)
1279
+ return;
1280
+ const data = asRecord2(asRecord2(event)?.["data"]);
1281
+ const sessionID = asText2(data?.["sessionID"]);
1282
+ const messageID = asText2(data?.["assistantMessageID"]);
1283
+ const started = asCount2(data?.["started"]);
1284
+ if (sessionID === undefined || messageID === undefined || started === undefined)
1285
+ return;
1286
+ pendingStarts.delete(messageID);
1287
+ if (pendingStarts.size >= RT_MAX_SESSIONS) {
1288
+ for (const oldest of pendingStarts.keys()) {
1289
+ pendingStarts.delete(oldest);
1290
+ break;
1291
+ }
1292
+ }
1293
+ pendingStarts.set(messageID, { sessionID, started, earliest: undefined });
1294
+ };
1295
+ const stepSettled = (event) => {
1296
+ if (disposed)
1297
+ return;
1298
+ const messageID = asText2(asRecord2(asRecord2(event)?.["data"])?.["assistantMessageID"]);
1299
+ if (messageID === undefined)
1300
+ return;
1301
+ const pending = pendingStarts.get(messageID);
1302
+ pendingStarts.delete(messageID);
1303
+ if (pending === undefined || pending.earliest === undefined)
1304
+ return;
1305
+ const value = Math.max(0, pending.earliest - pending.started);
1306
+ const ring = ttftRings.get(pending.sessionID);
1307
+ if (ring !== undefined) {
1308
+ ttftRings.delete(pending.sessionID);
1309
+ ring.push(value);
1310
+ if (ring.length > RT_MAX_STEPS)
1311
+ ring.splice(0, ring.length - RT_MAX_STEPS);
1312
+ ttftRings.set(pending.sessionID, ring);
1313
+ return;
1314
+ }
1315
+ if (ttftRings.size >= RT_MAX_SESSIONS) {
1316
+ for (const oldest of ttftRings.keys()) {
1317
+ ttftRings.delete(oldest);
1318
+ break;
1319
+ }
1320
+ }
1321
+ ttftRings.set(pending.sessionID, [value]);
1322
+ };
1323
+ try {
1324
+ const on = context.data?.on;
1325
+ if (typeof on === "function") {
1326
+ const subscribe = on;
1327
+ const track = (type, handler) => {
1328
+ try {
1329
+ releases.push(subscribe(type, handler));
1330
+ } catch {}
1331
+ };
1332
+ track("session.text.delta", ingest);
1333
+ track("session.reasoning.delta", ingest);
1334
+ track("session.step.started", stepStarted);
1335
+ track("session.step.ended", stepSettled);
1336
+ track("session.step.failed", stepSettled);
1337
+ active = releases.length > 0;
1338
+ }
1339
+ } catch {
1340
+ active = false;
1128
1341
  }
1129
- return { tokens, unionMs: mergedSpanMs(accepted) };
1130
- }
1131
- function createInstantTps(alpha = TPS_EWMA_ALPHA) {
1132
- let prevTokens;
1133
- let prevGenMs;
1134
- let smoothed;
1135
- let displayed;
1136
- return function sample(totalTokens, totalGenMs) {
1137
- const tokens = asCount2(totalTokens);
1138
- const genMs = asCount2(totalGenMs);
1139
- if (tokens === undefined || genMs === undefined)
1140
- return displayed;
1141
- if (prevTokens === undefined || prevGenMs === undefined) {
1142
- prevTokens = tokens;
1143
- prevGenMs = genMs;
1342
+ const coverageMs = (ordered, at) => {
1343
+ const first = ordered[0];
1344
+ if (first === undefined)
1144
1345
  return 0;
1346
+ if (ordered.length === 1) {
1347
+ return Math.min(Math.max(at - first.at, 250), 1000);
1348
+ }
1349
+ let duration = 0;
1350
+ for (let index = 1;index < ordered.length; index += 1) {
1351
+ duration += Math.max(0, (ordered[index]?.at ?? 0) - (ordered[index - 1]?.at ?? 0));
1352
+ }
1353
+ duration += Math.max(0, at - (ordered[ordered.length - 1]?.at ?? at));
1354
+ return duration;
1355
+ };
1356
+ const shownOf = (displayedSessionID) => {
1357
+ const known = shown.get(displayedSessionID);
1358
+ if (known !== undefined) {
1359
+ shown.delete(displayedSessionID);
1360
+ shown.set(displayedSessionID, known);
1361
+ return known;
1362
+ }
1363
+ const fresh = { smoothed: undefined, displayed: undefined };
1364
+ if (shown.size >= RT_MAX_SESSIONS) {
1365
+ for (const oldest of shown.keys()) {
1366
+ shown.delete(oldest);
1367
+ break;
1368
+ }
1145
1369
  }
1146
- const deltaTokens = tokens - prevTokens;
1147
- const deltaMs = genMs - prevGenMs;
1148
- if (deltaTokens < 0 || deltaMs < 0) {
1149
- prevTokens = tokens;
1150
- prevGenMs = genMs;
1151
- smoothed = undefined;
1370
+ shown.set(displayedSessionID, fresh);
1371
+ return fresh;
1372
+ };
1373
+ const rate = (displayedSessionID, ids) => {
1374
+ if (!active || disposed)
1152
1375
  return 0;
1376
+ const at = now();
1377
+ const seen = new Set;
1378
+ const windowed = [];
1379
+ let newest = Number.NEGATIVE_INFINITY;
1380
+ for (const id of ids) {
1381
+ if (typeof id !== "string" || seen.has(id))
1382
+ continue;
1383
+ seen.add(id);
1384
+ const ring = samples.get(id);
1385
+ if (ring === undefined)
1386
+ continue;
1387
+ const kept = ring.filter((sample) => at - sample.at <= RT_SAMPLE_WINDOW_MS);
1388
+ if (kept.length !== ring.length) {
1389
+ if (kept.length === 0)
1390
+ samples.delete(id);
1391
+ else
1392
+ samples.set(id, kept);
1393
+ }
1394
+ let idNewest = Number.NEGATIVE_INFINITY;
1395
+ for (const sample of kept) {
1396
+ if (sample.at > idNewest)
1397
+ idNewest = sample.at;
1398
+ }
1399
+ if (kept.length === 0 || at - idNewest > RT_STALE_MS)
1400
+ continue;
1401
+ for (const sample of kept) {
1402
+ windowed.push(sample);
1403
+ if (sample.at > newest)
1404
+ newest = sample.at;
1405
+ }
1153
1406
  }
1154
- prevTokens = tokens;
1155
- prevGenMs = genMs;
1156
- if (deltaMs <= 0)
1407
+ if (windowed.length === 0 || at - newest > RT_STALE_MS)
1157
1408
  return 0;
1158
- const instant = deltaTokens / (deltaMs / 1000);
1159
- smoothed = smoothTpsRate(smoothed, instant, alpha);
1160
- if (tpsNeedsRepaint(displayed, smoothed))
1161
- displayed = smoothed;
1162
- return displayed;
1409
+ windowed.sort((a, b) => a.at - b.at);
1410
+ const durationMs = coverageMs(windowed, at);
1411
+ if (!(durationMs > 0))
1412
+ return 0;
1413
+ const tokens = windowed.reduce((sum, sample) => sum + sample.tokens, 0);
1414
+ const instant = tokens / (durationMs / 1000);
1415
+ if (!Number.isFinite(instant) || instant <= 0)
1416
+ return 0;
1417
+ const state = shownOf(displayedSessionID);
1418
+ state.smoothed = smoothTpsRate(state.smoothed, instant, TPS_EWMA_ALPHA);
1419
+ if (tpsNeedsRepaint(state.displayed, state.smoothed))
1420
+ state.displayed = state.smoothed;
1421
+ return state.displayed ?? 0;
1422
+ };
1423
+ const ttft = (ids) => {
1424
+ if (!active || disposed)
1425
+ return;
1426
+ const seen = new Set;
1427
+ let totalMs = 0;
1428
+ let count = 0;
1429
+ for (const id of ids) {
1430
+ if (typeof id !== "string" || seen.has(id))
1431
+ continue;
1432
+ seen.add(id);
1433
+ const ring = ttftRings.get(id);
1434
+ if (ring === undefined)
1435
+ continue;
1436
+ for (const value of ring) {
1437
+ totalMs += value;
1438
+ count += 1;
1439
+ }
1440
+ }
1441
+ if (count === 0)
1442
+ return;
1443
+ return totalMs / count / 1000;
1444
+ };
1445
+ const dispose = () => {
1446
+ if (disposed)
1447
+ return;
1448
+ disposed = true;
1449
+ for (const release of releases) {
1450
+ try {
1451
+ release();
1452
+ } catch {}
1453
+ }
1454
+ releases.length = 0;
1455
+ samples.clear();
1456
+ shown.clear();
1457
+ pendingStarts.clear();
1458
+ ttftRings.clear();
1163
1459
  };
1460
+ return { get active() {
1461
+ return active && !disposed;
1462
+ }, rate, ttft, dispose };
1164
1463
  }
1165
1464
  // src/tui/style.ts
1166
1465
  var TextAttributes = {
@@ -1238,6 +1537,7 @@ var DEFAULT_GO_PANEL_LOOK = {
1238
1537
  blinkMs: 700
1239
1538
  };
1240
1539
  var DEFAULT_TPS_SCOPE = "family";
1540
+ var DEFAULT_TPS_DISPLAY = "avg";
1241
1541
  function cautionThresholds(config) {
1242
1542
  return {
1243
1543
  toolWatchMs: config.toolWatchSeconds * 1000,
@@ -1259,6 +1559,12 @@ var DEFAULT_GLYPHS = {
1259
1559
  caution: "\u25CF",
1260
1560
  clear: "\u25CB"
1261
1561
  };
1562
+ var DEFAULT_NOTIFICATIONS = {
1563
+ enabled: true,
1564
+ config: true,
1565
+ copy: true,
1566
+ caution: true
1567
+ };
1262
1568
  var DEFAULT_CAUTION = {
1263
1569
  enabled: false,
1264
1570
  toolWatchSeconds: 180,
@@ -1295,13 +1601,14 @@ var DEFAULT_CONFIG = {
1295
1601
  lines: DEFAULT_SIDEBAR_LINES,
1296
1602
  footer: { lines: DEFAULT_SIDEBAR_FOOTER_LINES, go: false },
1297
1603
  rows: DEFAULT_SIDEBAR_ROWS,
1298
- tps: { scope: DEFAULT_TPS_SCOPE },
1604
+ tps: { scope: DEFAULT_TPS_SCOPE, display: DEFAULT_TPS_DISPLAY },
1299
1605
  persist: true,
1300
1606
  placeholder: DEFAULT_PLACEHOLDER,
1301
1607
  maxLines: MAX_LINES
1302
1608
  },
1303
1609
  footer: { enabled: false, text: DEFAULT_FOOTER_TEXT },
1304
1610
  caution: DEFAULT_CAUTION,
1611
+ notifications: DEFAULT_NOTIFICATIONS,
1305
1612
  layout: DEFAULT_LAYOUT,
1306
1613
  format: DEFAULT_FORMAT,
1307
1614
  glyphs: DEFAULT_GLYPHS,
@@ -1491,14 +1798,22 @@ function readTpsScope(value, issues) {
1491
1798
  issues.push(`sidebar.tps.scope must be "family" or "session"; using "${DEFAULT_TPS_SCOPE}"`);
1492
1799
  return DEFAULT_TPS_SCOPE;
1493
1800
  }
1801
+ function readTpsDisplay(value, issues) {
1802
+ if (value === undefined)
1803
+ return DEFAULT_TPS_DISPLAY;
1804
+ if (value === "avg" || value === "rt" || value === "both")
1805
+ return value;
1806
+ issues.push(`sidebar.tps.display must be "avg", "rt" or "both"; using "avg"`);
1807
+ return DEFAULT_TPS_DISPLAY;
1808
+ }
1494
1809
  function readTps(section, issues) {
1495
1810
  const raw = section["tps"];
1496
1811
  if (raw !== undefined && !isRecord(raw)) {
1497
1812
  issues.push("sidebar.tps must be an object; using defaults");
1498
- return { scope: DEFAULT_TPS_SCOPE };
1813
+ return { scope: DEFAULT_TPS_SCOPE, display: DEFAULT_TPS_DISPLAY };
1499
1814
  }
1500
1815
  const tps = isRecord(raw) ? raw : {};
1501
- return { scope: readTpsScope(tps["scope"], issues) };
1816
+ return { scope: readTpsScope(tps["scope"], issues), display: readTpsDisplay(tps["display"], issues) };
1502
1817
  }
1503
1818
  function readMaxLines(value, issues) {
1504
1819
  return readNumber(value, MAX_LINES, "sidebar.maxLines", issues, 1, MAX_LINES);
@@ -1557,6 +1872,7 @@ function mergeOptions(fileOptions, hostOptions) {
1557
1872
  sidebar: mergeSection(file, host, "sidebar"),
1558
1873
  footer: mergeSection(file, host, "footer"),
1559
1874
  caution: mergeSection(file, host, "caution"),
1875
+ notifications: mergeSection(file, host, "notifications"),
1560
1876
  layout: mergeSection(file, host, "layout"),
1561
1877
  format: mergeSection(file, host, "format"),
1562
1878
  glyphs: mergeSection(file, host, "glyphs"),
@@ -1741,6 +2057,14 @@ function readToolNames(value, issues) {
1741
2057
  }
1742
2058
  return names;
1743
2059
  }
2060
+ function readNotifications(section, issues) {
2061
+ return {
2062
+ enabled: readBoolean(section["enabled"], DEFAULT_NOTIFICATIONS.enabled, "notifications.enabled", issues),
2063
+ config: readBoolean(section["config"], DEFAULT_NOTIFICATIONS.config, "notifications.config", issues),
2064
+ copy: readBoolean(section["copy"], DEFAULT_NOTIFICATIONS.copy, "notifications.copy", issues),
2065
+ caution: readBoolean(section["caution"], DEFAULT_NOTIFICATIONS.caution, "notifications.caution", issues)
2066
+ };
2067
+ }
1744
2068
  function readCaution(section, issues) {
1745
2069
  const toolWatchSeconds = readNumber(section["toolWatchSeconds"], DEFAULT_CAUTION.toolWatchSeconds, "caution.toolWatchSeconds", issues, 0);
1746
2070
  const turnWatchSeconds = readNumber(section["turnWatchSeconds"], DEFAULT_CAUTION.turnWatchSeconds, "caution.turnWatchSeconds", issues, 0);
@@ -1777,6 +2101,7 @@ function resolveConfig(options) {
1777
2101
  const rawSidebar = options.sidebar;
1778
2102
  const rawFooter = options.footer;
1779
2103
  const rawCaution = options.caution;
2104
+ const rawNotifications = options.notifications;
1780
2105
  const rawFormat = options.format;
1781
2106
  const rawStyle = options.style;
1782
2107
  if (rawSidebar !== undefined && !isRecord(rawSidebar)) {
@@ -1788,6 +2113,9 @@ function resolveConfig(options) {
1788
2113
  if (rawCaution !== undefined && !isRecord(rawCaution)) {
1789
2114
  issues.push("caution must be an object; using defaults");
1790
2115
  }
2116
+ if (rawNotifications !== undefined && !isRecord(rawNotifications)) {
2117
+ issues.push("notifications must be an object; using defaults");
2118
+ }
1791
2119
  if (rawFormat !== undefined && !isRecord(rawFormat)) {
1792
2120
  issues.push("format must be an object; using defaults");
1793
2121
  }
@@ -1797,6 +2125,7 @@ function resolveConfig(options) {
1797
2125
  const sidebar = isRecord(rawSidebar) ? rawSidebar : {};
1798
2126
  const footer = isRecord(rawFooter) ? rawFooter : {};
1799
2127
  const caution = isRecord(rawCaution) ? rawCaution : {};
2128
+ const notifications = isRecord(rawNotifications) ? rawNotifications : {};
1800
2129
  const layout = isRecord(options.layout) ? options.layout : {};
1801
2130
  const format = isRecord(rawFormat) ? rawFormat : {};
1802
2131
  const glyphs = isRecord(options.glyphs) ? options.glyphs : {};
@@ -1834,6 +2163,7 @@ function resolveConfig(options) {
1834
2163
  text: readText(footer.text, DEFAULT_CONFIG.footer.text, "footer.text", issues)
1835
2164
  },
1836
2165
  caution: readCaution(caution, issues),
2166
+ notifications: readNotifications(notifications, issues),
1837
2167
  layout: readLayout(layout, issues),
1838
2168
  format: readFormat(format, issues),
1839
2169
  glyphs: readGlyphs(glyphs, issues),
@@ -1844,6 +2174,11 @@ function resolveConfig(options) {
1844
2174
  };
1845
2175
  }
1846
2176
 
2177
+ // src/tui/notify.ts
2178
+ function shouldNotify(config, kind) {
2179
+ return config.enabled && config[kind];
2180
+ }
2181
+
1847
2182
  // src/tui/file-config.ts
1848
2183
  import { existsSync, readFileSync, statSync } from "fs";
1849
2184
  import { homedir } from "os";
@@ -1969,6 +2304,7 @@ function railLines(config, source = {}) {
1969
2304
  persist: config.sidebar.persist,
1970
2305
  placeholder: config.sidebar.placeholder,
1971
2306
  durationStyle: config.format.duration,
2307
+ tpsDisplay: config.sidebar.tps.display,
1972
2308
  hasTotalRow: config.sidebar.rows.includes("total")
1973
2309
  };
1974
2310
  const lines = config.sidebar.lines.map((text) => ({ text }));
@@ -3423,37 +3759,19 @@ function createSessionReads(context) {
3423
3759
  }
3424
3760
 
3425
3761
  // src/tui/session-tps.ts
3426
- function createTpsReader(context, live, scope = DEFAULT_TPS_SCOPE) {
3762
+ function createTpsReader(context, live, scope = DEFAULT_TPS_SCOPE, realtime) {
3427
3763
  const TPS_CACHE_MS = 1000;
3428
3764
  let hostStamps;
3429
3765
  let tpsCache;
3430
- const MAX_TRACKERS = 50;
3431
- const trackers = new Map;
3432
- const trackerOf = (sessionID) => {
3433
- const known = trackers.get(sessionID);
3434
- if (known !== undefined) {
3435
- trackers.delete(sessionID);
3436
- trackers.set(sessionID, known);
3437
- return known;
3438
- }
3439
- const fresh = createInstantTps();
3440
- if (trackers.size >= MAX_TRACKERS) {
3441
- for (const oldest of trackers.keys()) {
3442
- trackers.delete(oldest);
3443
- break;
3444
- }
3445
- }
3446
- trackers.set(sessionID, fresh);
3447
- return fresh;
3448
- };
3766
+ const tracker = realtime ?? createRealtimeTps(context);
3449
3767
  const scanMessages = (id, now) => {
3450
3768
  let messages;
3451
3769
  try {
3452
3770
  messages = context.data.session.message.list(id) ?? [];
3453
3771
  } catch {
3454
- return { ok: false, assistant: 0, stamped: 0, spans: [] };
3772
+ return { ok: false, assistant: 0, stamped: 0, settled: [] };
3455
3773
  }
3456
- const spans = [];
3774
+ const settled = [];
3457
3775
  let assistant = 0;
3458
3776
  let stamped = 0;
3459
3777
  for (const entry of messages) {
@@ -3474,16 +3792,18 @@ function createTpsReader(context, live, scope = DEFAULT_TPS_SCOPE) {
3474
3792
  const tokens = asRecord2(message["tokens"]);
3475
3793
  const output = tokens?.["output"];
3476
3794
  const reasoning = tokens?.["reasoning"];
3477
- const settled = completed !== undefined || streamed !== undefined;
3795
+ const settledTurn = completed !== undefined || streamed !== undefined;
3478
3796
  const key = turnKey(message["id"], created, completed, output, streamed);
3479
- spans.push({
3480
- key: settled ? `${key}:${asCount2(reasoning) ?? "?"}` : key,
3797
+ const turn = {
3798
+ key: settledTurn ? `${key}:${asCount2(reasoning) ?? "?"}` : key,
3481
3799
  tokens: output,
3482
3800
  reasoning,
3483
3801
  ...span
3484
- });
3802
+ };
3803
+ if (streamed !== undefined)
3804
+ settled.push(turn);
3485
3805
  }
3486
- return { ok: true, assistant, stamped, spans };
3806
+ return { ok: true, assistant, stamped, settled };
3487
3807
  };
3488
3808
  const familyIds = (sessionID) => {
3489
3809
  const ids = [sessionID];
@@ -3500,16 +3820,16 @@ function createTpsReader(context, live, scope = DEFAULT_TPS_SCOPE) {
3500
3820
  let ok = true;
3501
3821
  let assistant = 0;
3502
3822
  let stamped = 0;
3503
- const spans = [];
3823
+ const settled = [];
3504
3824
  for (const id of ids) {
3505
3825
  const scan = scanMessages(id, now);
3506
3826
  ok = ok && scan.ok;
3507
3827
  assistant += scan.assistant;
3508
3828
  stamped += scan.stamped;
3509
- for (const span of scan.spans)
3510
- spans.push({ ...span, key: `${id} ${String(span.key)}` });
3829
+ for (const span of scan.settled)
3830
+ settled.push({ ...span, key: `${id} ${String(span.key)}` });
3511
3831
  }
3512
- return { ok, assistant, stamped, spans };
3832
+ return { ok, assistant, stamped, settled };
3513
3833
  };
3514
3834
  const recordGeneration = (session) => {
3515
3835
  const tokens = asRecord2(session?.tokens);
@@ -3529,11 +3849,11 @@ function createTpsReader(context, live, scope = DEFAULT_TPS_SCOPE) {
3529
3849
  }
3530
3850
  return { ok, generation };
3531
3851
  };
3532
- const computeTps = (sessionID, session) => {
3852
+ const computeAvg = (sessionID, session) => {
3533
3853
  const time = asRecord2(session?.time);
3534
3854
  const created = asCount2(time?.["created"]);
3535
3855
  const now = Date.now();
3536
- const scan = hostStamps === false ? { ok: true, assistant: 0, stamped: 0, spans: [] } : scope === "family" ? scanScope(familyIds(sessionID), now) : scanMessages(sessionID, now);
3856
+ const scan = hostStamps === false ? { ok: true, assistant: 0, stamped: 0, settled: [] } : scope === "family" ? scanScope(familyIds(sessionID), now) : scanMessages(sessionID, now);
3537
3857
  if (hostStamps === undefined) {
3538
3858
  if (scan.stamped > 0)
3539
3859
  hostStamps = true;
@@ -3542,36 +3862,47 @@ function createTpsReader(context, live, scope = DEFAULT_TPS_SCOPE) {
3542
3862
  else
3543
3863
  return;
3544
3864
  }
3545
- const tracker = trackerOf(sessionID);
3546
3865
  if (hostStamps === true) {
3547
3866
  if (scope === "family" && scan.ok === false)
3548
- return 0;
3549
- const { tokens } = unionGenerationTotals(scan.spans);
3550
- const genMs = unionSpanMs(scan.spans);
3551
- return tracker(tokens, genMs);
3867
+ return;
3868
+ return settledAverageRate(scan.settled);
3552
3869
  }
3553
3870
  const family = scope === "family" ? familyGeneration(sessionID, session) : undefined;
3554
3871
  if (family !== undefined && family.ok === false)
3555
- return 0;
3872
+ return;
3556
3873
  const generation = family?.generation ?? recordGeneration(session);
3557
- if (created === undefined && scope === "session")
3558
- return tracker(recordGeneration(session), 0);
3874
+ if (created === undefined && scope === "session") {
3875
+ return;
3876
+ }
3559
3877
  let genMs = 0;
3560
3878
  try {
3561
3879
  genMs = live?.elapsedMsOf?.(sessionID, now) ?? 0;
3562
3880
  } catch {
3563
3881
  genMs = 0;
3564
3882
  }
3565
- return tracker(generation, genMs);
3883
+ return genMs > 0 ? generation / (genMs / 1000) : undefined;
3566
3884
  };
3567
3885
  const sessionTps = (sessionID, session) => {
3886
+ const ids = scope === "family" ? familyIds(sessionID) : [sessionID];
3887
+ let rt = 0;
3888
+ try {
3889
+ rt = tracker.rate(sessionID, ids);
3890
+ } catch {
3891
+ rt = 0;
3892
+ }
3893
+ let ttft;
3894
+ try {
3895
+ ttft = tracker.ttft(ids);
3896
+ } catch {
3897
+ ttft = undefined;
3898
+ }
3568
3899
  const cached = tpsCache;
3569
3900
  if (cached !== undefined && cached.sessionID === sessionID && Date.now() - cached.at < TPS_CACHE_MS) {
3570
- return cached.value;
3901
+ return { rt, avg: cached.avg, ttft };
3571
3902
  }
3572
- const value = computeTps(sessionID, session) ?? 0;
3573
- tpsCache = { sessionID, at: Date.now(), value };
3574
- return value;
3903
+ const avg = computeAvg(sessionID, session);
3904
+ tpsCache = { sessionID, at: Date.now(), avg };
3905
+ return { rt, avg, ttft };
3575
3906
  };
3576
3907
  return { sessionTps };
3577
3908
  }
@@ -3589,7 +3920,7 @@ var tui_default = Plugin.define({
3589
3920
  console.warn(`[flight-deck] ${file.issue}`);
3590
3921
  }
3591
3922
  const problems = file.issue !== undefined ? [file.issue, ...issues] : issues;
3592
- if (problems.length > 0) {
3923
+ if (problems.length > 0 && shouldNotify(config.notifications, "config")) {
3593
3924
  const extra = problems.length > 1 ? ` (+${problems.length - 1} more)` : "";
3594
3925
  context.ui.toast.show({
3595
3926
  title: "Flight Deck",
@@ -3599,6 +3930,7 @@ var tui_default = Plugin.define({
3599
3930
  }
3600
3931
  const footer = footerLine(config);
3601
3932
  const releases = [];
3933
+ const realtime = createRealtimeTps(context);
3602
3934
  const themedLine = (line, copyId) => {
3603
3935
  const style = railLineStyle(config.style, line);
3604
3936
  const lineFg = themeColor(style.color, context.theme);
@@ -3621,6 +3953,8 @@ var tui_default = Plugin.define({
3621
3953
  const fb = copyFeedback(result, copyId);
3622
3954
  if (fb.ok)
3623
3955
  return;
3956
+ if (!shouldNotify(config.notifications, "copy"))
3957
+ return;
3624
3958
  context.ui.toast.show({
3625
3959
  title: "Flight Deck",
3626
3960
  message: fb.message,
@@ -3658,7 +3992,7 @@ var tui_default = Plugin.define({
3658
3992
  });
3659
3993
  const { sessionTps } = createTpsReader(context, {
3660
3994
  elapsedMsOf: (id, now) => sessionElapsed(id, now)
3661
- }, config.sidebar.tps.scope);
3995
+ }, config.sidebar.tps.scope, realtime);
3662
3996
  const sparkValues = (sessionID) => {
3663
3997
  const sizes = [];
3664
3998
  for (const entry of messagesOf(sessionID)) {
@@ -3728,7 +4062,7 @@ var tui_default = Plugin.define({
3728
4062
  let toastedKey;
3729
4063
  let watchTimer;
3730
4064
  const toastMs = Math.max(1000, config.refresh > 0 ? config.refresh : 1000);
3731
- if (config.sidebar.enabled && config.caution.enabled && config.caution.toast) {
4065
+ if (config.sidebar.enabled && config.caution.enabled && config.caution.toast && shouldNotify(config.notifications, "caution")) {
3732
4066
  watchTimer = setInterval(() => {
3733
4067
  const sessionID = watchedSession;
3734
4068
  if (sessionID === undefined)
@@ -3801,6 +4135,7 @@ var tui_default = Plugin.define({
3801
4135
  if (watchTimer !== undefined)
3802
4136
  clearInterval(watchTimer);
3803
4137
  watchTimer = undefined;
4138
+ realtime.dispose();
3804
4139
  ticker?.dispose();
3805
4140
  bridge?.dispose();
3806
4141
  goBridge?.dispose();