oc-flight-deck 0.19.1 → 0.20.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/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." };
@@ -685,7 +733,7 @@ function skeletonValue(field, layout) {
685
733
  case "elapsed":
686
734
  return formatDuration(0, layout.durationStyle);
687
735
  case "tps":
688
- return "0 tok/s";
736
+ return layout.tpsDisplay === "both" ? "0 rt \xB7 0 avg" : "0 tok/s";
689
737
  case "spark":
690
738
  return "\u2581".repeat(Math.max(0, Math.floor(layout.sparkWidth ?? DEFAULT_SPARK_WIDTH)));
691
739
  case "reasoning":
@@ -947,13 +995,31 @@ function statLine(field, source, layout = {}) {
947
995
  return row("elapsed", formatDuration(ms, layout.durationStyle));
948
996
  }
949
997
  case "tps": {
950
- const tps = asCount2(source.tps);
951
- if (tps === undefined)
998
+ const pair = asRecord2(source.tps);
999
+ const rt = asCount2(pair?.["rt"]);
1000
+ const avg = asCount2(pair?.["avg"]);
1001
+ const ttft = asCount2(pair?.["ttft"]);
1002
+ const display = layout.tpsDisplay ?? "avg";
1003
+ if (display === "rt") {
1004
+ const rounded = rt === undefined ? undefined : Math.round(rt);
1005
+ if (rounded === undefined || rounded <= 0)
1006
+ return;
1007
+ return row("tps", `${rounded} tok/s`);
1008
+ }
1009
+ if (display === "both") {
1010
+ if (avg !== undefined) {
1011
+ if (Math.round(avg) <= 0)
1012
+ return;
1013
+ const head = `${rt === undefined ? 0 : Math.round(rt)} rt \xB7 ${Math.round(avg)} avg`;
1014
+ return ttft === undefined ? row("tps", head) : row("tps", `${head} \xB7 ${ttft.toFixed(1)}s ttft`);
1015
+ }
1016
+ if (rt !== undefined && Math.round(rt) > 0)
1017
+ return row("tps", `${Math.round(rt)} rt`);
952
1018
  return;
953
- const rounded = Math.round(tps);
954
- if (rounded <= 0)
1019
+ }
1020
+ if (avg === undefined || Math.round(avg) <= 0)
955
1021
  return;
956
- return row("tps", `${rounded} tok/s`);
1022
+ return row("tps", `${Math.round(avg)} tok/s`);
957
1023
  }
958
1024
  case "spark": {
959
1025
  const values = Array.isArray(source.spark) ? source.spark.map((value) => asCount2(value) ?? 0) : [];
@@ -1071,6 +1137,26 @@ function mergedSpanMs(accepted) {
1071
1137
  unionMs += openEnd - openStart;
1072
1138
  return unionMs;
1073
1139
  }
1140
+ function unionSpanTotals(spans) {
1141
+ const seen = new Set;
1142
+ const accepted = [];
1143
+ let tokens = 0;
1144
+ for (const span of spans) {
1145
+ const key = asText2(span.key);
1146
+ if (key === undefined || seen.has(key))
1147
+ continue;
1148
+ const start = asCount2(span.start);
1149
+ const end = asCount2(span.end);
1150
+ if (start === undefined || end === undefined)
1151
+ continue;
1152
+ const output = asCount2(span.tokens);
1153
+ const reasoning = asCount2(span.reasoning);
1154
+ seen.add(key);
1155
+ accepted.push({ start, end: Math.max(start, end) });
1156
+ tokens += (output ?? 0) + (reasoning ?? 0);
1157
+ }
1158
+ return { tokens, unionMs: mergedSpanMs(accepted) };
1159
+ }
1074
1160
  function unionSpanMs(spans) {
1075
1161
  const seen = new Set;
1076
1162
  const accepted = [];
@@ -1108,59 +1194,262 @@ function tpsNeedsRepaint(displayed, smoothed) {
1108
1194
  return smoothed !== 0;
1109
1195
  return Math.abs(smoothed - displayed) / Math.abs(displayed) >= TPS_REPAINT_RATIO;
1110
1196
  }
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);
1197
+ function settledAverageRate(spans) {
1198
+ const { tokens, unionMs } = unionSpanTotals(spans);
1199
+ if (unionMs <= 0)
1200
+ return;
1201
+ return tokens / (unionMs / 1000);
1202
+ }
1203
+ // src/tui/realtime-tps.ts
1204
+ var RT_SAMPLE_WINDOW_MS = 5000;
1205
+ var RT_STALE_MS = 1500;
1206
+ var RT_MAX_STEPS = 100;
1207
+ var RT_MAX_SESSIONS = 50;
1208
+ function estimateDeltaTokens(delta) {
1209
+ const bytes = Buffer.byteLength(delta, "utf8");
1210
+ return bytes > 0 ? Math.max(1, Math.ceil(bytes / 5)) : 0;
1211
+ }
1212
+ function createRealtimeTps(context, opts) {
1213
+ const now = opts?.now ?? Date.now;
1214
+ const samples = new Map;
1215
+ const shown = new Map;
1216
+ const pendingStarts = new Map;
1217
+ const ttftRings = new Map;
1218
+ let disposed = false;
1219
+ let active = false;
1220
+ const releases = [];
1221
+ const remember = (sessionID, sample) => {
1222
+ const known = samples.get(sessionID);
1223
+ if (known !== undefined) {
1224
+ samples.delete(sessionID);
1225
+ known.push(sample);
1226
+ samples.set(sessionID, known);
1227
+ return;
1228
+ }
1229
+ if (samples.size >= RT_MAX_SESSIONS) {
1230
+ for (const oldest of samples.keys()) {
1231
+ samples.delete(oldest);
1232
+ break;
1233
+ }
1234
+ }
1235
+ samples.set(sessionID, [sample]);
1236
+ };
1237
+ const readDelta = (event) => {
1238
+ const record = asRecord2(event);
1239
+ const data = asRecord2(record?.["data"]);
1240
+ const sessionID = asText2(data?.["sessionID"]);
1241
+ const raw = data?.["delta"];
1242
+ const delta = typeof raw === "string" ? raw : undefined;
1243
+ if (sessionID === undefined || delta === undefined)
1244
+ return;
1245
+ const at = asCount2(record?.["created"]) ?? now();
1246
+ return { sessionID, delta, at };
1247
+ };
1248
+ const ingest = (event) => {
1249
+ if (disposed)
1250
+ return;
1251
+ const reading = readDelta(event);
1252
+ if (reading === undefined)
1253
+ return;
1254
+ remember(reading.sessionID, { at: reading.at, tokens: estimateDeltaTokens(reading.delta) });
1255
+ noteDelta(event, reading.at);
1256
+ };
1257
+ const noteDelta = (event, at) => {
1258
+ const messageID = asText2(asRecord2(asRecord2(event)?.["data"])?.["assistantMessageID"]);
1259
+ if (messageID === undefined)
1260
+ return;
1261
+ const pending = pendingStarts.get(messageID);
1262
+ if (pending === undefined)
1263
+ return;
1264
+ if (pending.earliest === undefined || at < pending.earliest)
1265
+ pending.earliest = at;
1266
+ };
1267
+ const stepStarted = (event) => {
1268
+ if (disposed)
1269
+ return;
1270
+ const data = asRecord2(asRecord2(event)?.["data"]);
1271
+ const sessionID = asText2(data?.["sessionID"]);
1272
+ const messageID = asText2(data?.["assistantMessageID"]);
1273
+ const started = asCount2(data?.["started"]);
1274
+ if (sessionID === undefined || messageID === undefined || started === undefined)
1275
+ return;
1276
+ pendingStarts.delete(messageID);
1277
+ if (pendingStarts.size >= RT_MAX_SESSIONS) {
1278
+ for (const oldest of pendingStarts.keys()) {
1279
+ pendingStarts.delete(oldest);
1280
+ break;
1281
+ }
1282
+ }
1283
+ pendingStarts.set(messageID, { sessionID, started, earliest: undefined });
1284
+ };
1285
+ const stepSettled = (event) => {
1286
+ if (disposed)
1287
+ return;
1288
+ const messageID = asText2(asRecord2(asRecord2(event)?.["data"])?.["assistantMessageID"]);
1289
+ if (messageID === undefined)
1290
+ return;
1291
+ const pending = pendingStarts.get(messageID);
1292
+ pendingStarts.delete(messageID);
1293
+ if (pending === undefined || pending.earliest === undefined)
1294
+ return;
1295
+ const value = Math.max(0, pending.earliest - pending.started);
1296
+ const ring = ttftRings.get(pending.sessionID);
1297
+ if (ring !== undefined) {
1298
+ ttftRings.delete(pending.sessionID);
1299
+ ring.push(value);
1300
+ if (ring.length > RT_MAX_STEPS)
1301
+ ring.splice(0, ring.length - RT_MAX_STEPS);
1302
+ ttftRings.set(pending.sessionID, ring);
1303
+ return;
1304
+ }
1305
+ if (ttftRings.size >= RT_MAX_SESSIONS) {
1306
+ for (const oldest of ttftRings.keys()) {
1307
+ ttftRings.delete(oldest);
1308
+ break;
1309
+ }
1310
+ }
1311
+ ttftRings.set(pending.sessionID, [value]);
1312
+ };
1313
+ try {
1314
+ const on = context.data?.on;
1315
+ if (typeof on === "function") {
1316
+ const subscribe = on;
1317
+ const track = (type, handler) => {
1318
+ try {
1319
+ releases.push(subscribe(type, handler));
1320
+ } catch {}
1321
+ };
1322
+ track("session.text.delta", ingest);
1323
+ track("session.reasoning.delta", ingest);
1324
+ track("session.step.started", stepStarted);
1325
+ track("session.step.ended", stepSettled);
1326
+ track("session.step.failed", stepSettled);
1327
+ active = releases.length > 0;
1328
+ }
1329
+ } catch {
1330
+ active = false;
1128
1331
  }
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;
1332
+ const coverageMs = (ordered, at) => {
1333
+ const first = ordered[0];
1334
+ if (first === undefined)
1144
1335
  return 0;
1336
+ if (ordered.length === 1) {
1337
+ return Math.min(Math.max(at - first.at, 250), 1000);
1338
+ }
1339
+ let duration = 0;
1340
+ for (let index = 1;index < ordered.length; index += 1) {
1341
+ duration += Math.max(0, (ordered[index]?.at ?? 0) - (ordered[index - 1]?.at ?? 0));
1145
1342
  }
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;
1343
+ duration += Math.max(0, at - (ordered[ordered.length - 1]?.at ?? at));
1344
+ return duration;
1345
+ };
1346
+ const shownOf = (displayedSessionID) => {
1347
+ const known = shown.get(displayedSessionID);
1348
+ if (known !== undefined) {
1349
+ shown.delete(displayedSessionID);
1350
+ shown.set(displayedSessionID, known);
1351
+ return known;
1352
+ }
1353
+ const fresh = { smoothed: undefined, displayed: undefined };
1354
+ if (shown.size >= RT_MAX_SESSIONS) {
1355
+ for (const oldest of shown.keys()) {
1356
+ shown.delete(oldest);
1357
+ break;
1358
+ }
1359
+ }
1360
+ shown.set(displayedSessionID, fresh);
1361
+ return fresh;
1362
+ };
1363
+ const rate = (displayedSessionID, ids) => {
1364
+ if (!active || disposed)
1152
1365
  return 0;
1366
+ const at = now();
1367
+ const seen = new Set;
1368
+ const windowed = [];
1369
+ let newest = Number.NEGATIVE_INFINITY;
1370
+ for (const id of ids) {
1371
+ if (typeof id !== "string" || seen.has(id))
1372
+ continue;
1373
+ seen.add(id);
1374
+ const ring = samples.get(id);
1375
+ if (ring === undefined)
1376
+ continue;
1377
+ const kept = ring.filter((sample) => at - sample.at <= RT_SAMPLE_WINDOW_MS);
1378
+ if (kept.length !== ring.length) {
1379
+ if (kept.length === 0)
1380
+ samples.delete(id);
1381
+ else
1382
+ samples.set(id, kept);
1383
+ }
1384
+ let idNewest = Number.NEGATIVE_INFINITY;
1385
+ for (const sample of kept) {
1386
+ if (sample.at > idNewest)
1387
+ idNewest = sample.at;
1388
+ }
1389
+ if (kept.length === 0 || at - idNewest > RT_STALE_MS)
1390
+ continue;
1391
+ for (const sample of kept) {
1392
+ windowed.push(sample);
1393
+ if (sample.at > newest)
1394
+ newest = sample.at;
1395
+ }
1153
1396
  }
1154
- prevTokens = tokens;
1155
- prevGenMs = genMs;
1156
- if (deltaMs <= 0)
1397
+ if (windowed.length === 0 || at - newest > RT_STALE_MS)
1398
+ return 0;
1399
+ windowed.sort((a, b) => a.at - b.at);
1400
+ const durationMs = coverageMs(windowed, at);
1401
+ if (!(durationMs > 0))
1402
+ return 0;
1403
+ const tokens = windowed.reduce((sum, sample) => sum + sample.tokens, 0);
1404
+ const instant = tokens / (durationMs / 1000);
1405
+ if (!Number.isFinite(instant) || instant <= 0)
1157
1406
  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;
1407
+ const state = shownOf(displayedSessionID);
1408
+ state.smoothed = smoothTpsRate(state.smoothed, instant, TPS_EWMA_ALPHA);
1409
+ if (tpsNeedsRepaint(state.displayed, state.smoothed))
1410
+ state.displayed = state.smoothed;
1411
+ return state.displayed ?? 0;
1412
+ };
1413
+ const ttft = (ids) => {
1414
+ if (!active || disposed)
1415
+ return;
1416
+ const seen = new Set;
1417
+ let totalMs = 0;
1418
+ let count = 0;
1419
+ for (const id of ids) {
1420
+ if (typeof id !== "string" || seen.has(id))
1421
+ continue;
1422
+ seen.add(id);
1423
+ const ring = ttftRings.get(id);
1424
+ if (ring === undefined)
1425
+ continue;
1426
+ for (const value of ring) {
1427
+ totalMs += value;
1428
+ count += 1;
1429
+ }
1430
+ }
1431
+ if (count === 0)
1432
+ return;
1433
+ return totalMs / count / 1000;
1163
1434
  };
1435
+ const dispose = () => {
1436
+ if (disposed)
1437
+ return;
1438
+ disposed = true;
1439
+ for (const release of releases) {
1440
+ try {
1441
+ release();
1442
+ } catch {}
1443
+ }
1444
+ releases.length = 0;
1445
+ samples.clear();
1446
+ shown.clear();
1447
+ pendingStarts.clear();
1448
+ ttftRings.clear();
1449
+ };
1450
+ return { get active() {
1451
+ return active && !disposed;
1452
+ }, rate, ttft, dispose };
1164
1453
  }
1165
1454
  // src/tui/style.ts
1166
1455
  var TextAttributes = {
@@ -1238,6 +1527,7 @@ var DEFAULT_GO_PANEL_LOOK = {
1238
1527
  blinkMs: 700
1239
1528
  };
1240
1529
  var DEFAULT_TPS_SCOPE = "family";
1530
+ var DEFAULT_TPS_DISPLAY = "avg";
1241
1531
  function cautionThresholds(config) {
1242
1532
  return {
1243
1533
  toolWatchMs: config.toolWatchSeconds * 1000,
@@ -1259,6 +1549,12 @@ var DEFAULT_GLYPHS = {
1259
1549
  caution: "\u25CF",
1260
1550
  clear: "\u25CB"
1261
1551
  };
1552
+ var DEFAULT_NOTIFICATIONS = {
1553
+ enabled: true,
1554
+ config: true,
1555
+ copy: true,
1556
+ caution: true
1557
+ };
1262
1558
  var DEFAULT_CAUTION = {
1263
1559
  enabled: false,
1264
1560
  toolWatchSeconds: 180,
@@ -1295,13 +1591,14 @@ var DEFAULT_CONFIG = {
1295
1591
  lines: DEFAULT_SIDEBAR_LINES,
1296
1592
  footer: { lines: DEFAULT_SIDEBAR_FOOTER_LINES, go: false },
1297
1593
  rows: DEFAULT_SIDEBAR_ROWS,
1298
- tps: { scope: DEFAULT_TPS_SCOPE },
1594
+ tps: { scope: DEFAULT_TPS_SCOPE, display: DEFAULT_TPS_DISPLAY },
1299
1595
  persist: true,
1300
1596
  placeholder: DEFAULT_PLACEHOLDER,
1301
1597
  maxLines: MAX_LINES
1302
1598
  },
1303
1599
  footer: { enabled: false, text: DEFAULT_FOOTER_TEXT },
1304
1600
  caution: DEFAULT_CAUTION,
1601
+ notifications: DEFAULT_NOTIFICATIONS,
1305
1602
  layout: DEFAULT_LAYOUT,
1306
1603
  format: DEFAULT_FORMAT,
1307
1604
  glyphs: DEFAULT_GLYPHS,
@@ -1491,14 +1788,22 @@ function readTpsScope(value, issues) {
1491
1788
  issues.push(`sidebar.tps.scope must be "family" or "session"; using "${DEFAULT_TPS_SCOPE}"`);
1492
1789
  return DEFAULT_TPS_SCOPE;
1493
1790
  }
1791
+ function readTpsDisplay(value, issues) {
1792
+ if (value === undefined)
1793
+ return DEFAULT_TPS_DISPLAY;
1794
+ if (value === "avg" || value === "rt" || value === "both")
1795
+ return value;
1796
+ issues.push(`sidebar.tps.display must be "avg", "rt" or "both"; using "avg"`);
1797
+ return DEFAULT_TPS_DISPLAY;
1798
+ }
1494
1799
  function readTps(section, issues) {
1495
1800
  const raw = section["tps"];
1496
1801
  if (raw !== undefined && !isRecord(raw)) {
1497
1802
  issues.push("sidebar.tps must be an object; using defaults");
1498
- return { scope: DEFAULT_TPS_SCOPE };
1803
+ return { scope: DEFAULT_TPS_SCOPE, display: DEFAULT_TPS_DISPLAY };
1499
1804
  }
1500
1805
  const tps = isRecord(raw) ? raw : {};
1501
- return { scope: readTpsScope(tps["scope"], issues) };
1806
+ return { scope: readTpsScope(tps["scope"], issues), display: readTpsDisplay(tps["display"], issues) };
1502
1807
  }
1503
1808
  function readMaxLines(value, issues) {
1504
1809
  return readNumber(value, MAX_LINES, "sidebar.maxLines", issues, 1, MAX_LINES);
@@ -1557,6 +1862,7 @@ function mergeOptions(fileOptions, hostOptions) {
1557
1862
  sidebar: mergeSection(file, host, "sidebar"),
1558
1863
  footer: mergeSection(file, host, "footer"),
1559
1864
  caution: mergeSection(file, host, "caution"),
1865
+ notifications: mergeSection(file, host, "notifications"),
1560
1866
  layout: mergeSection(file, host, "layout"),
1561
1867
  format: mergeSection(file, host, "format"),
1562
1868
  glyphs: mergeSection(file, host, "glyphs"),
@@ -1741,6 +2047,14 @@ function readToolNames(value, issues) {
1741
2047
  }
1742
2048
  return names;
1743
2049
  }
2050
+ function readNotifications(section, issues) {
2051
+ return {
2052
+ enabled: readBoolean(section["enabled"], DEFAULT_NOTIFICATIONS.enabled, "notifications.enabled", issues),
2053
+ config: readBoolean(section["config"], DEFAULT_NOTIFICATIONS.config, "notifications.config", issues),
2054
+ copy: readBoolean(section["copy"], DEFAULT_NOTIFICATIONS.copy, "notifications.copy", issues),
2055
+ caution: readBoolean(section["caution"], DEFAULT_NOTIFICATIONS.caution, "notifications.caution", issues)
2056
+ };
2057
+ }
1744
2058
  function readCaution(section, issues) {
1745
2059
  const toolWatchSeconds = readNumber(section["toolWatchSeconds"], DEFAULT_CAUTION.toolWatchSeconds, "caution.toolWatchSeconds", issues, 0);
1746
2060
  const turnWatchSeconds = readNumber(section["turnWatchSeconds"], DEFAULT_CAUTION.turnWatchSeconds, "caution.turnWatchSeconds", issues, 0);
@@ -1777,6 +2091,7 @@ function resolveConfig(options) {
1777
2091
  const rawSidebar = options.sidebar;
1778
2092
  const rawFooter = options.footer;
1779
2093
  const rawCaution = options.caution;
2094
+ const rawNotifications = options.notifications;
1780
2095
  const rawFormat = options.format;
1781
2096
  const rawStyle = options.style;
1782
2097
  if (rawSidebar !== undefined && !isRecord(rawSidebar)) {
@@ -1788,6 +2103,9 @@ function resolveConfig(options) {
1788
2103
  if (rawCaution !== undefined && !isRecord(rawCaution)) {
1789
2104
  issues.push("caution must be an object; using defaults");
1790
2105
  }
2106
+ if (rawNotifications !== undefined && !isRecord(rawNotifications)) {
2107
+ issues.push("notifications must be an object; using defaults");
2108
+ }
1791
2109
  if (rawFormat !== undefined && !isRecord(rawFormat)) {
1792
2110
  issues.push("format must be an object; using defaults");
1793
2111
  }
@@ -1797,6 +2115,7 @@ function resolveConfig(options) {
1797
2115
  const sidebar = isRecord(rawSidebar) ? rawSidebar : {};
1798
2116
  const footer = isRecord(rawFooter) ? rawFooter : {};
1799
2117
  const caution = isRecord(rawCaution) ? rawCaution : {};
2118
+ const notifications = isRecord(rawNotifications) ? rawNotifications : {};
1800
2119
  const layout = isRecord(options.layout) ? options.layout : {};
1801
2120
  const format = isRecord(rawFormat) ? rawFormat : {};
1802
2121
  const glyphs = isRecord(options.glyphs) ? options.glyphs : {};
@@ -1834,6 +2153,7 @@ function resolveConfig(options) {
1834
2153
  text: readText(footer.text, DEFAULT_CONFIG.footer.text, "footer.text", issues)
1835
2154
  },
1836
2155
  caution: readCaution(caution, issues),
2156
+ notifications: readNotifications(notifications, issues),
1837
2157
  layout: readLayout(layout, issues),
1838
2158
  format: readFormat(format, issues),
1839
2159
  glyphs: readGlyphs(glyphs, issues),
@@ -1844,6 +2164,11 @@ function resolveConfig(options) {
1844
2164
  };
1845
2165
  }
1846
2166
 
2167
+ // src/tui/notify.ts
2168
+ function shouldNotify(config, kind) {
2169
+ return config.enabled && config[kind];
2170
+ }
2171
+
1847
2172
  // src/tui/file-config.ts
1848
2173
  import { existsSync, readFileSync, statSync } from "fs";
1849
2174
  import { homedir } from "os";
@@ -1969,6 +2294,7 @@ function railLines(config, source = {}) {
1969
2294
  persist: config.sidebar.persist,
1970
2295
  placeholder: config.sidebar.placeholder,
1971
2296
  durationStyle: config.format.duration,
2297
+ tpsDisplay: config.sidebar.tps.display,
1972
2298
  hasTotalRow: config.sidebar.rows.includes("total")
1973
2299
  };
1974
2300
  const lines = config.sidebar.lines.map((text) => ({ text }));
@@ -3423,37 +3749,19 @@ function createSessionReads(context) {
3423
3749
  }
3424
3750
 
3425
3751
  // src/tui/session-tps.ts
3426
- function createTpsReader(context, live, scope = DEFAULT_TPS_SCOPE) {
3752
+ function createTpsReader(context, live, scope = DEFAULT_TPS_SCOPE, realtime) {
3427
3753
  const TPS_CACHE_MS = 1000;
3428
3754
  let hostStamps;
3429
3755
  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
- };
3756
+ const tracker = realtime ?? createRealtimeTps(context);
3449
3757
  const scanMessages = (id, now) => {
3450
3758
  let messages;
3451
3759
  try {
3452
3760
  messages = context.data.session.message.list(id) ?? [];
3453
3761
  } catch {
3454
- return { ok: false, assistant: 0, stamped: 0, spans: [] };
3762
+ return { ok: false, assistant: 0, stamped: 0, settled: [] };
3455
3763
  }
3456
- const spans = [];
3764
+ const settled = [];
3457
3765
  let assistant = 0;
3458
3766
  let stamped = 0;
3459
3767
  for (const entry of messages) {
@@ -3474,16 +3782,18 @@ function createTpsReader(context, live, scope = DEFAULT_TPS_SCOPE) {
3474
3782
  const tokens = asRecord2(message["tokens"]);
3475
3783
  const output = tokens?.["output"];
3476
3784
  const reasoning = tokens?.["reasoning"];
3477
- const settled = completed !== undefined || streamed !== undefined;
3785
+ const settledTurn = completed !== undefined || streamed !== undefined;
3478
3786
  const key = turnKey(message["id"], created, completed, output, streamed);
3479
- spans.push({
3480
- key: settled ? `${key}:${asCount2(reasoning) ?? "?"}` : key,
3787
+ const turn = {
3788
+ key: settledTurn ? `${key}:${asCount2(reasoning) ?? "?"}` : key,
3481
3789
  tokens: output,
3482
3790
  reasoning,
3483
3791
  ...span
3484
- });
3792
+ };
3793
+ if (streamed !== undefined)
3794
+ settled.push(turn);
3485
3795
  }
3486
- return { ok: true, assistant, stamped, spans };
3796
+ return { ok: true, assistant, stamped, settled };
3487
3797
  };
3488
3798
  const familyIds = (sessionID) => {
3489
3799
  const ids = [sessionID];
@@ -3500,16 +3810,16 @@ function createTpsReader(context, live, scope = DEFAULT_TPS_SCOPE) {
3500
3810
  let ok = true;
3501
3811
  let assistant = 0;
3502
3812
  let stamped = 0;
3503
- const spans = [];
3813
+ const settled = [];
3504
3814
  for (const id of ids) {
3505
3815
  const scan = scanMessages(id, now);
3506
3816
  ok = ok && scan.ok;
3507
3817
  assistant += scan.assistant;
3508
3818
  stamped += scan.stamped;
3509
- for (const span of scan.spans)
3510
- spans.push({ ...span, key: `${id} ${String(span.key)}` });
3819
+ for (const span of scan.settled)
3820
+ settled.push({ ...span, key: `${id} ${String(span.key)}` });
3511
3821
  }
3512
- return { ok, assistant, stamped, spans };
3822
+ return { ok, assistant, stamped, settled };
3513
3823
  };
3514
3824
  const recordGeneration = (session) => {
3515
3825
  const tokens = asRecord2(session?.tokens);
@@ -3529,11 +3839,11 @@ function createTpsReader(context, live, scope = DEFAULT_TPS_SCOPE) {
3529
3839
  }
3530
3840
  return { ok, generation };
3531
3841
  };
3532
- const computeTps = (sessionID, session) => {
3842
+ const computeAvg = (sessionID, session) => {
3533
3843
  const time = asRecord2(session?.time);
3534
3844
  const created = asCount2(time?.["created"]);
3535
3845
  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);
3846
+ const scan = hostStamps === false ? { ok: true, assistant: 0, stamped: 0, settled: [] } : scope === "family" ? scanScope(familyIds(sessionID), now) : scanMessages(sessionID, now);
3537
3847
  if (hostStamps === undefined) {
3538
3848
  if (scan.stamped > 0)
3539
3849
  hostStamps = true;
@@ -3542,36 +3852,47 @@ function createTpsReader(context, live, scope = DEFAULT_TPS_SCOPE) {
3542
3852
  else
3543
3853
  return;
3544
3854
  }
3545
- const tracker = trackerOf(sessionID);
3546
3855
  if (hostStamps === true) {
3547
3856
  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);
3857
+ return;
3858
+ return settledAverageRate(scan.settled);
3552
3859
  }
3553
3860
  const family = scope === "family" ? familyGeneration(sessionID, session) : undefined;
3554
3861
  if (family !== undefined && family.ok === false)
3555
- return 0;
3862
+ return;
3556
3863
  const generation = family?.generation ?? recordGeneration(session);
3557
- if (created === undefined && scope === "session")
3558
- return tracker(recordGeneration(session), 0);
3864
+ if (created === undefined && scope === "session") {
3865
+ return;
3866
+ }
3559
3867
  let genMs = 0;
3560
3868
  try {
3561
3869
  genMs = live?.elapsedMsOf?.(sessionID, now) ?? 0;
3562
3870
  } catch {
3563
3871
  genMs = 0;
3564
3872
  }
3565
- return tracker(generation, genMs);
3873
+ return genMs > 0 ? generation / (genMs / 1000) : undefined;
3566
3874
  };
3567
3875
  const sessionTps = (sessionID, session) => {
3876
+ const ids = scope === "family" ? familyIds(sessionID) : [sessionID];
3877
+ let rt = 0;
3878
+ try {
3879
+ rt = tracker.rate(sessionID, ids);
3880
+ } catch {
3881
+ rt = 0;
3882
+ }
3883
+ let ttft;
3884
+ try {
3885
+ ttft = tracker.ttft(ids);
3886
+ } catch {
3887
+ ttft = undefined;
3888
+ }
3568
3889
  const cached = tpsCache;
3569
3890
  if (cached !== undefined && cached.sessionID === sessionID && Date.now() - cached.at < TPS_CACHE_MS) {
3570
- return cached.value;
3891
+ return { rt, avg: cached.avg, ttft };
3571
3892
  }
3572
- const value = computeTps(sessionID, session) ?? 0;
3573
- tpsCache = { sessionID, at: Date.now(), value };
3574
- return value;
3893
+ const avg = computeAvg(sessionID, session);
3894
+ tpsCache = { sessionID, at: Date.now(), avg };
3895
+ return { rt, avg, ttft };
3575
3896
  };
3576
3897
  return { sessionTps };
3577
3898
  }
@@ -3589,7 +3910,7 @@ var tui_default = Plugin.define({
3589
3910
  console.warn(`[flight-deck] ${file.issue}`);
3590
3911
  }
3591
3912
  const problems = file.issue !== undefined ? [file.issue, ...issues] : issues;
3592
- if (problems.length > 0) {
3913
+ if (problems.length > 0 && shouldNotify(config.notifications, "config")) {
3593
3914
  const extra = problems.length > 1 ? ` (+${problems.length - 1} more)` : "";
3594
3915
  context.ui.toast.show({
3595
3916
  title: "Flight Deck",
@@ -3599,6 +3920,7 @@ var tui_default = Plugin.define({
3599
3920
  }
3600
3921
  const footer = footerLine(config);
3601
3922
  const releases = [];
3923
+ const realtime = createRealtimeTps(context);
3602
3924
  const themedLine = (line, copyId) => {
3603
3925
  const style = railLineStyle(config.style, line);
3604
3926
  const lineFg = themeColor(style.color, context.theme);
@@ -3621,6 +3943,8 @@ var tui_default = Plugin.define({
3621
3943
  const fb = copyFeedback(result, copyId);
3622
3944
  if (fb.ok)
3623
3945
  return;
3946
+ if (!shouldNotify(config.notifications, "copy"))
3947
+ return;
3624
3948
  context.ui.toast.show({
3625
3949
  title: "Flight Deck",
3626
3950
  message: fb.message,
@@ -3658,7 +3982,7 @@ var tui_default = Plugin.define({
3658
3982
  });
3659
3983
  const { sessionTps } = createTpsReader(context, {
3660
3984
  elapsedMsOf: (id, now) => sessionElapsed(id, now)
3661
- }, config.sidebar.tps.scope);
3985
+ }, config.sidebar.tps.scope, realtime);
3662
3986
  const sparkValues = (sessionID) => {
3663
3987
  const sizes = [];
3664
3988
  for (const entry of messagesOf(sessionID)) {
@@ -3728,7 +4052,7 @@ var tui_default = Plugin.define({
3728
4052
  let toastedKey;
3729
4053
  let watchTimer;
3730
4054
  const toastMs = Math.max(1000, config.refresh > 0 ? config.refresh : 1000);
3731
- if (config.sidebar.enabled && config.caution.enabled && config.caution.toast) {
4055
+ if (config.sidebar.enabled && config.caution.enabled && config.caution.toast && shouldNotify(config.notifications, "caution")) {
3732
4056
  watchTimer = setInterval(() => {
3733
4057
  const sessionID = watchedSession;
3734
4058
  if (sessionID === undefined)
@@ -3801,6 +4125,7 @@ var tui_default = Plugin.define({
3801
4125
  if (watchTimer !== undefined)
3802
4126
  clearInterval(watchTimer);
3803
4127
  watchTimer = undefined;
4128
+ realtime.dispose();
3804
4129
  ticker?.dispose();
3805
4130
  bridge?.dispose();
3806
4131
  goBridge?.dispose();