oc-flight-deck 0.24.0 → 0.25.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/CHANGELOG.md +11 -0
- package/README.md +42 -24
- package/dist/tui/index.js +229 -103
- package/docs/GUIDE.md +10 -7
- package/flight-deck.example.jsonc +43 -27
- package/flight-deck.schema.json +27 -10
- package/package.json +6 -6
- package/src/tui/config.ts +115 -6
- package/src/tui/go-panel.ts +5 -3
- package/src/tui/index.tsx +38 -3
- package/src/tui/lifetime-totals.ts +92 -0
- package/src/tui/presentation.ts +11 -5
- package/src/tui/rows.ts +73 -71
- package/src/tui/stat-fields.ts +55 -22
package/dist/tui/index.js
CHANGED
|
@@ -722,8 +722,8 @@ var STAT_FIELDS = [
|
|
|
722
722
|
"agent",
|
|
723
723
|
"model",
|
|
724
724
|
"branch",
|
|
725
|
-
"
|
|
726
|
-
"
|
|
725
|
+
"spend",
|
|
726
|
+
"lifetime",
|
|
727
727
|
"project",
|
|
728
728
|
"tokens",
|
|
729
729
|
"cache",
|
|
@@ -742,10 +742,16 @@ var STAT_FIELDS = [
|
|
|
742
742
|
];
|
|
743
743
|
var ANIMATED_FIELDS = ["caution", "status", "elapsed", "tps"];
|
|
744
744
|
function isStatField(value) {
|
|
745
|
-
return value === "session" || STAT_FIELDS.some((field) => field === value);
|
|
745
|
+
return value === "session" || value === "cost" || value === "total" || STAT_FIELDS.some((field) => field === value);
|
|
746
746
|
}
|
|
747
747
|
function canonicalField(name) {
|
|
748
|
-
|
|
748
|
+
if (name === "session")
|
|
749
|
+
return "ses";
|
|
750
|
+
if (name === "cost")
|
|
751
|
+
return "spend";
|
|
752
|
+
if (name === "total")
|
|
753
|
+
return "lifetime";
|
|
754
|
+
return name;
|
|
749
755
|
}
|
|
750
756
|
function fieldLabel(field, labels) {
|
|
751
757
|
const override = labels?.[canonicalField(field)];
|
|
@@ -753,13 +759,13 @@ function fieldLabel(field, labels) {
|
|
|
753
759
|
return override;
|
|
754
760
|
return field === "ses" ? "session" : field;
|
|
755
761
|
}
|
|
756
|
-
var DEFAULT_PLACEHOLDER = "
|
|
762
|
+
var DEFAULT_PLACEHOLDER = "0";
|
|
757
763
|
var DEFAULT_LABEL_WIDTH = 10;
|
|
758
764
|
var DEFAULT_SPARK_WIDTH = 12;
|
|
759
765
|
function skeletonValue(field, layout) {
|
|
760
766
|
switch (canonicalField(field)) {
|
|
761
|
-
case "
|
|
762
|
-
case "
|
|
767
|
+
case "spend":
|
|
768
|
+
case "lifetime":
|
|
763
769
|
case "project":
|
|
764
770
|
return formatCost(0);
|
|
765
771
|
case "tokens":
|
|
@@ -772,8 +778,10 @@ function skeletonValue(field, layout) {
|
|
|
772
778
|
return "0 waiting";
|
|
773
779
|
case "elapsed":
|
|
774
780
|
return formatDuration(0, layout.durationStyle);
|
|
775
|
-
case "tps":
|
|
776
|
-
|
|
781
|
+
case "tps": {
|
|
782
|
+
const label = layout.tpsLabel ?? "tok/s";
|
|
783
|
+
return layout.tpsDisplay === "both" ? `0 rt \xB7 0 avg` : `0 ${label}`;
|
|
784
|
+
}
|
|
777
785
|
case "spark":
|
|
778
786
|
return "\u2581".repeat(Math.max(0, Math.floor(layout.sparkWidth ?? DEFAULT_SPARK_WIDTH)));
|
|
779
787
|
case "reasoning":
|
|
@@ -962,37 +970,30 @@ function statLine(field, source, layout = {}) {
|
|
|
962
970
|
const branch = asText2(source.branch);
|
|
963
971
|
return branch === undefined ? undefined : row("branch", branch);
|
|
964
972
|
}
|
|
965
|
-
case "
|
|
973
|
+
case "spend": {
|
|
966
974
|
const cost = asCount2(source.cost);
|
|
967
975
|
const tree = asRecord2(source.tree);
|
|
968
976
|
const treeCost = asCount2(tree?.cost);
|
|
969
977
|
const count = asCount2(tree?.count);
|
|
970
978
|
const family = count !== undefined && count > 0 ? count : 0;
|
|
971
|
-
const merge = layout.
|
|
979
|
+
const merge = layout.hasLifetimeRow !== true && cost !== undefined && treeCost !== undefined && family > 0 && treeCost > cost;
|
|
972
980
|
if (!merge) {
|
|
973
|
-
|
|
974
|
-
return;
|
|
975
|
-
return row("cost", `${feeMark(source.costKind)}${formatCost(cost)}`);
|
|
981
|
+
return row(field, `${feeMark(source.costKind)}${formatCost(cost ?? 0)}`);
|
|
976
982
|
}
|
|
977
983
|
const plural = family === 1 ? "subagent" : "subagents";
|
|
978
|
-
return row(
|
|
984
|
+
return row(field, `${feeMark(tree?.kind)}${formatCost(treeCost)} \xB7 ${family} ${plural}`);
|
|
979
985
|
}
|
|
980
|
-
case "
|
|
981
|
-
const
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
const
|
|
985
|
-
if (cost === undefined)
|
|
986
|
-
return;
|
|
987
|
-
const count = asCount2(tree.count) ?? 0;
|
|
986
|
+
case "lifetime": {
|
|
987
|
+
const live = asRecord2(source.tree);
|
|
988
|
+
const durable = asRecord2(source.lifetime);
|
|
989
|
+
const cost = asCount2(durable?.cost) ?? asCount2(live?.cost) ?? 0;
|
|
990
|
+
const count = asCount2(live?.count) ?? 0;
|
|
988
991
|
const plural = count === 1 ? "subagent" : "subagents";
|
|
989
|
-
return row(
|
|
992
|
+
return row(field, `${feeMark(durable?.kind ?? live?.kind)}${formatCost(cost)} \xB7 ${count} ${plural}`);
|
|
990
993
|
}
|
|
991
994
|
case "project": {
|
|
992
995
|
const project = asRecord2(source.project);
|
|
993
|
-
const cost = asCount2(project?.cost);
|
|
994
|
-
if (cost === undefined)
|
|
995
|
-
return;
|
|
996
|
+
const cost = asCount2(project?.cost) ?? 0;
|
|
996
997
|
const count = asCount2(project?.count);
|
|
997
998
|
return row("project", `${formatCost(cost)}${count !== undefined && count > 1 ? ` \xB7 ${count} sessions` : ""}`);
|
|
998
999
|
}
|
|
@@ -1000,18 +1001,12 @@ function statLine(field, source, layout = {}) {
|
|
|
1000
1001
|
const tokens = asRecord2(source.tokens);
|
|
1001
1002
|
const input = asCount2(tokens?.input);
|
|
1002
1003
|
const output = asCount2(tokens?.output);
|
|
1003
|
-
if (input === undefined && output === undefined)
|
|
1004
|
-
return;
|
|
1005
1004
|
return row("tokens", `${formatCount(input ?? 0)} in \xB7 ${formatCount(output ?? 0)} out`);
|
|
1006
1005
|
}
|
|
1007
1006
|
case "cache": {
|
|
1008
1007
|
const tokens = asRecord2(source.tokens);
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
const cache = asRecord2(tokens.cache);
|
|
1012
|
-
const read = asCount2(cache?.read);
|
|
1013
|
-
if (read === undefined)
|
|
1014
|
-
return;
|
|
1008
|
+
const cache = asRecord2(tokens?.cache);
|
|
1009
|
+
const read = asCount2(cache?.read) ?? 0;
|
|
1015
1010
|
const input = asCount2(tokens?.input);
|
|
1016
1011
|
const total = input === undefined ? undefined : read + input;
|
|
1017
1012
|
if (read === 0) {
|
|
@@ -1023,9 +1018,9 @@ function statLine(field, source, layout = {}) {
|
|
|
1023
1018
|
case "context": {
|
|
1024
1019
|
const context = asRecord2(source.context);
|
|
1025
1020
|
const used = asCount2(context?.used);
|
|
1026
|
-
if (used === undefined || used === 0)
|
|
1027
|
-
return;
|
|
1028
1021
|
const limit = asCount2(context?.limit);
|
|
1022
|
+
if (used === undefined || used === 0)
|
|
1023
|
+
return row("context", "~0 used");
|
|
1029
1024
|
if (limit === undefined || limit === 0)
|
|
1030
1025
|
return row("context", `~${formatCount(used)} used`);
|
|
1031
1026
|
const ratio = used / limit;
|
|
@@ -1046,9 +1041,7 @@ function statLine(field, source, layout = {}) {
|
|
|
1046
1041
|
return row("perms", resource === undefined ? action : `${action} \xB7 ${clip(resource, 18)}`);
|
|
1047
1042
|
}
|
|
1048
1043
|
case "elapsed": {
|
|
1049
|
-
const ms = asCount2(source.elapsedMs);
|
|
1050
|
-
if (ms === undefined || ms <= 0)
|
|
1051
|
-
return;
|
|
1044
|
+
const ms = asCount2(source.elapsedMs) ?? 0;
|
|
1052
1045
|
return row("elapsed", formatDuration(ms, layout.durationStyle));
|
|
1053
1046
|
}
|
|
1054
1047
|
case "updated": {
|
|
@@ -1063,29 +1056,24 @@ function statLine(field, source, layout = {}) {
|
|
|
1063
1056
|
const rt = asCount2(pair?.["rt"]);
|
|
1064
1057
|
const avg = asCount2(pair?.["avg"]);
|
|
1065
1058
|
const ttft = asCount2(pair?.["ttft"]);
|
|
1059
|
+
const shownTtft = layout.tpsTtft ?? true ? ttft : undefined;
|
|
1066
1060
|
const display = layout.tpsDisplay ?? "rt";
|
|
1061
|
+
const label = layout.tpsLabel ?? "tok/s";
|
|
1062
|
+
const rounded = (value) => {
|
|
1063
|
+
const value_ = value === undefined ? 0 : Math.round(value);
|
|
1064
|
+
return value_ > 0 ? value_ : 0;
|
|
1065
|
+
};
|
|
1066
|
+
const current = rounded(rt);
|
|
1067
|
+
const settled = rounded(avg);
|
|
1068
|
+
const suffix = shownTtft === undefined ? "" : ` \xB7 ${shownTtft.toFixed(1)}s ttft`;
|
|
1067
1069
|
if (display === "rt") {
|
|
1068
|
-
|
|
1069
|
-
if (rounded === undefined || rounded <= 0) {
|
|
1070
|
-
return ttft === undefined ? undefined : row("tps", `${ttft.toFixed(1)}s ttft`);
|
|
1071
|
-
}
|
|
1072
|
-
const rate = `${rounded} tok/s`;
|
|
1073
|
-
return row("tps", ttft === undefined ? rate : `${rate} \xB7 ${ttft.toFixed(1)}s ttft`);
|
|
1070
|
+
return row("tps", current > 0 ? `${current} ${label}${suffix}` : `0 ${label}`);
|
|
1074
1071
|
}
|
|
1075
1072
|
if (display === "both") {
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
return;
|
|
1079
|
-
const head = `${rt === undefined ? 0 : Math.round(rt)} rt \xB7 ${Math.round(avg)} avg`;
|
|
1080
|
-
return ttft === undefined ? row("tps", head) : row("tps", `${head} \xB7 ${ttft.toFixed(1)}s ttft`);
|
|
1081
|
-
}
|
|
1082
|
-
if (rt !== undefined && Math.round(rt) > 0)
|
|
1083
|
-
return row("tps", `${Math.round(rt)} rt`);
|
|
1084
|
-
return;
|
|
1073
|
+
const head = `${current} rt \xB7 ${settled} avg`;
|
|
1074
|
+
return row("tps", settled > 0 ? head + suffix : head);
|
|
1085
1075
|
}
|
|
1086
|
-
|
|
1087
|
-
return;
|
|
1088
|
-
return row("tps", `${Math.round(avg)} tok/s`);
|
|
1076
|
+
return row("tps", `${settled} ${label}`);
|
|
1089
1077
|
}
|
|
1090
1078
|
case "spark": {
|
|
1091
1079
|
const values = Array.isArray(source.spark) ? source.spark.map((value) => asCount2(value) ?? 0) : [];
|
|
@@ -1095,9 +1083,7 @@ function statLine(field, source, layout = {}) {
|
|
|
1095
1083
|
return row("spark", sparkline(windowed));
|
|
1096
1084
|
}
|
|
1097
1085
|
case "reasoning": {
|
|
1098
|
-
const reasoning = asCount2(asRecord2(source.tokens)?.reasoning);
|
|
1099
|
-
if (reasoning === undefined || reasoning === 0)
|
|
1100
|
-
return;
|
|
1086
|
+
const reasoning = asCount2(asRecord2(source.tokens)?.reasoning) ?? 0;
|
|
1101
1087
|
return row("reasoning", formatCount(reasoning));
|
|
1102
1088
|
}
|
|
1103
1089
|
case "turns": {
|
|
@@ -1146,14 +1132,17 @@ function statSegments(field, source, layout = {}) {
|
|
|
1146
1132
|
return [{ text: labelPrefix(fieldLabel(name, layout.labels), layout.labelWidth ?? DEFAULT_LABEL_WIDTH) }, ...value];
|
|
1147
1133
|
}
|
|
1148
1134
|
function statRows(fields, source, layout = {}) {
|
|
1149
|
-
const hint = {
|
|
1135
|
+
const hint = {
|
|
1136
|
+
...layout,
|
|
1137
|
+
hasLifetimeRow: fields.some((field) => canonicalField(field) === "lifetime")
|
|
1138
|
+
};
|
|
1150
1139
|
const persist = hint.persist === true;
|
|
1151
1140
|
const placeholder = hint.placeholder ?? DEFAULT_PLACEHOLDER;
|
|
1152
1141
|
const labelWidth = hint.labelWidth ?? DEFAULT_LABEL_WIDTH;
|
|
1153
1142
|
const rows = [];
|
|
1154
1143
|
for (const field of fields) {
|
|
1155
1144
|
const name = canonicalField(field);
|
|
1156
|
-
const line = statLine(
|
|
1145
|
+
const line = statLine(field, source, hint);
|
|
1157
1146
|
if (line !== undefined) {
|
|
1158
1147
|
rows.push(line);
|
|
1159
1148
|
continue;
|
|
@@ -1521,6 +1510,63 @@ function createRealtimeTps(context, opts) {
|
|
|
1521
1510
|
return active && !disposed;
|
|
1522
1511
|
}, rate, ttft, dispose };
|
|
1523
1512
|
}
|
|
1513
|
+
// src/tui/lifetime-totals.ts
|
|
1514
|
+
import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from "fs";
|
|
1515
|
+
import { homedir } from "os";
|
|
1516
|
+
import { dirname, join } from "path";
|
|
1517
|
+
function defaultLifetimeTotalsPath() {
|
|
1518
|
+
return join(homedir(), ".local", "share", "opencode", "flight-deck", "totals.json");
|
|
1519
|
+
}
|
|
1520
|
+
function createLifetimeTotals(options = {}) {
|
|
1521
|
+
const path = options.path ?? defaultLifetimeTotalsPath();
|
|
1522
|
+
const held = new Map;
|
|
1523
|
+
const storedValues = () => {
|
|
1524
|
+
try {
|
|
1525
|
+
if (!existsSync(path))
|
|
1526
|
+
return {};
|
|
1527
|
+
const parsed = JSON.parse(readFileSync(path, "utf8"));
|
|
1528
|
+
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed))
|
|
1529
|
+
return {};
|
|
1530
|
+
const values = {};
|
|
1531
|
+
for (const [id, value] of Object.entries(parsed)) {
|
|
1532
|
+
if (typeof value === "number" && Number.isFinite(value) && value > 0)
|
|
1533
|
+
values[id] = value;
|
|
1534
|
+
}
|
|
1535
|
+
return values;
|
|
1536
|
+
} catch {
|
|
1537
|
+
return {};
|
|
1538
|
+
}
|
|
1539
|
+
};
|
|
1540
|
+
const writeAll = (values) => {
|
|
1541
|
+
try {
|
|
1542
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
1543
|
+
const temporary = `${path}.${process.pid}.tmp`;
|
|
1544
|
+
writeFileSync(temporary, JSON.stringify(values));
|
|
1545
|
+
renameSync(temporary, path);
|
|
1546
|
+
} catch {}
|
|
1547
|
+
};
|
|
1548
|
+
return {
|
|
1549
|
+
read(id) {
|
|
1550
|
+
const stored = storedValues()[id];
|
|
1551
|
+
const memory = held.get(id);
|
|
1552
|
+
if (stored === undefined && memory === undefined)
|
|
1553
|
+
return;
|
|
1554
|
+
return Math.max(stored ?? 0, memory ?? 0);
|
|
1555
|
+
},
|
|
1556
|
+
record(id, value) {
|
|
1557
|
+
if (!Number.isFinite(value) || value <= 0)
|
|
1558
|
+
return;
|
|
1559
|
+
const previous = Math.max(held.get(id) ?? 0, storedValues()[id] ?? 0);
|
|
1560
|
+
if (value <= previous)
|
|
1561
|
+
return;
|
|
1562
|
+
held.set(id, value);
|
|
1563
|
+
const values = storedValues();
|
|
1564
|
+
values[id] = value;
|
|
1565
|
+
writeAll(values);
|
|
1566
|
+
}
|
|
1567
|
+
};
|
|
1568
|
+
}
|
|
1569
|
+
|
|
1524
1570
|
// src/tui/style.ts
|
|
1525
1571
|
var TextAttributes = {
|
|
1526
1572
|
NONE: 0,
|
|
@@ -1598,6 +1644,8 @@ var DEFAULT_GO_PANEL_LOOK = {
|
|
|
1598
1644
|
};
|
|
1599
1645
|
var DEFAULT_TPS_SCOPE = "family";
|
|
1600
1646
|
var DEFAULT_TPS_DISPLAY = "rt";
|
|
1647
|
+
var DEFAULT_TPS_TTFT = true;
|
|
1648
|
+
var DEFAULT_TPS_LABEL = "tok/s";
|
|
1601
1649
|
function cautionThresholds(config) {
|
|
1602
1650
|
return {
|
|
1603
1651
|
toolWatchMs: config.toolWatchSeconds * 1000,
|
|
@@ -1645,7 +1693,7 @@ var DEFAULT_SIDEBAR_ROWS = [
|
|
|
1645
1693
|
"status",
|
|
1646
1694
|
"agent",
|
|
1647
1695
|
"model",
|
|
1648
|
-
"
|
|
1696
|
+
"spend",
|
|
1649
1697
|
"project",
|
|
1650
1698
|
"tokens",
|
|
1651
1699
|
"cache",
|
|
@@ -1665,7 +1713,12 @@ var DEFAULT_CONFIG = {
|
|
|
1665
1713
|
lines: DEFAULT_SIDEBAR_LINES,
|
|
1666
1714
|
footer: { lines: DEFAULT_SIDEBAR_FOOTER_LINES, go: false },
|
|
1667
1715
|
rows: DEFAULT_SIDEBAR_ROWS,
|
|
1668
|
-
tps: {
|
|
1716
|
+
tps: {
|
|
1717
|
+
scope: DEFAULT_TPS_SCOPE,
|
|
1718
|
+
display: DEFAULT_TPS_DISPLAY,
|
|
1719
|
+
label: DEFAULT_TPS_LABEL,
|
|
1720
|
+
ttft: DEFAULT_TPS_TTFT
|
|
1721
|
+
},
|
|
1669
1722
|
persist: true,
|
|
1670
1723
|
placeholder: DEFAULT_PLACEHOLDER,
|
|
1671
1724
|
maxLines: MAX_LINES
|
|
@@ -1677,7 +1730,8 @@ var DEFAULT_CONFIG = {
|
|
|
1677
1730
|
format: DEFAULT_FORMAT,
|
|
1678
1731
|
glyphs: DEFAULT_GLYPHS,
|
|
1679
1732
|
style: DEFAULT_STYLE,
|
|
1680
|
-
refresh: DEFAULT_REFRESH_MS
|
|
1733
|
+
refresh: DEFAULT_REFRESH_MS,
|
|
1734
|
+
lifetimeTotalsPath: defaultLifetimeTotalsPath()
|
|
1681
1735
|
};
|
|
1682
1736
|
var MAX_LINE_LENGTH = 120;
|
|
1683
1737
|
var CONTROL_CHAR = /[\u0000-\u001F\u007F-\u009F]/;
|
|
@@ -1846,7 +1900,13 @@ function readRows(value, issues, maxLines) {
|
|
|
1846
1900
|
issues.push(`${path} is not a known field (${STAT_FIELDS.join(", ")}); skipping it`);
|
|
1847
1901
|
return;
|
|
1848
1902
|
}
|
|
1849
|
-
|
|
1903
|
+
const canonical = canonicalField(name);
|
|
1904
|
+
const duplicateOf = rows.find((entry) => canonicalField(entry) === canonical);
|
|
1905
|
+
if (duplicateOf !== undefined) {
|
|
1906
|
+
issues.push(`${path} duplicates ${duplicateOf}; rendering the row once`);
|
|
1907
|
+
return;
|
|
1908
|
+
}
|
|
1909
|
+
rows.push(name === "session" ? "ses" : name);
|
|
1850
1910
|
});
|
|
1851
1911
|
if (rows.length === 0) {
|
|
1852
1912
|
issues.push("sidebar.rows had no usable entries; using the default rows");
|
|
@@ -1870,14 +1930,46 @@ function readTpsDisplay(value, issues) {
|
|
|
1870
1930
|
issues.push(`sidebar.tps.display must be "avg", "rt" or "both"; using "${DEFAULT_TPS_DISPLAY}"`);
|
|
1871
1931
|
return DEFAULT_TPS_DISPLAY;
|
|
1872
1932
|
}
|
|
1933
|
+
function readTpsTtft(value, issues) {
|
|
1934
|
+
return readBoolean(value, DEFAULT_TPS_TTFT, "sidebar.tps.ttft", issues);
|
|
1935
|
+
}
|
|
1936
|
+
var TPS_LABEL_MAX_LENGTH = 16;
|
|
1937
|
+
function readTpsLabel(value, issues) {
|
|
1938
|
+
if (value === undefined)
|
|
1939
|
+
return DEFAULT_TPS_LABEL;
|
|
1940
|
+
if (typeof value !== "string") {
|
|
1941
|
+
issues.push("sidebar.tps.label must be a string; using the default");
|
|
1942
|
+
return DEFAULT_TPS_LABEL;
|
|
1943
|
+
}
|
|
1944
|
+
const text = normalizeText(value, "sidebar.tps.label", issues);
|
|
1945
|
+
if (text.length === 0) {
|
|
1946
|
+
issues.push("sidebar.tps.label must not be empty; using the default");
|
|
1947
|
+
return DEFAULT_TPS_LABEL;
|
|
1948
|
+
}
|
|
1949
|
+
if (text.length > TPS_LABEL_MAX_LENGTH) {
|
|
1950
|
+
issues.push(`sidebar.tps.label was longer than ${TPS_LABEL_MAX_LENGTH} characters; using the default`);
|
|
1951
|
+
return DEFAULT_TPS_LABEL;
|
|
1952
|
+
}
|
|
1953
|
+
return text;
|
|
1954
|
+
}
|
|
1873
1955
|
function readTps(section, issues) {
|
|
1874
1956
|
const raw = section["tps"];
|
|
1875
1957
|
if (raw !== undefined && !isRecord(raw)) {
|
|
1876
1958
|
issues.push("sidebar.tps must be an object; using defaults");
|
|
1877
|
-
return {
|
|
1959
|
+
return {
|
|
1960
|
+
scope: DEFAULT_TPS_SCOPE,
|
|
1961
|
+
display: DEFAULT_TPS_DISPLAY,
|
|
1962
|
+
label: DEFAULT_TPS_LABEL,
|
|
1963
|
+
ttft: DEFAULT_TPS_TTFT
|
|
1964
|
+
};
|
|
1878
1965
|
}
|
|
1879
1966
|
const tps = isRecord(raw) ? raw : {};
|
|
1880
|
-
return {
|
|
1967
|
+
return {
|
|
1968
|
+
scope: readTpsScope(tps["scope"], issues),
|
|
1969
|
+
display: readTpsDisplay(tps["display"], issues),
|
|
1970
|
+
label: readTpsLabel(tps["label"], issues),
|
|
1971
|
+
ttft: readTpsTtft(tps["ttft"], issues)
|
|
1972
|
+
};
|
|
1881
1973
|
}
|
|
1882
1974
|
function readMaxLines(value, issues) {
|
|
1883
1975
|
return readNumber(value, MAX_LINES, "sidebar.maxLines", issues, 1, MAX_LINES);
|
|
@@ -1886,6 +1978,15 @@ function sectionOf(options, key) {
|
|
|
1886
1978
|
const value = options[key];
|
|
1887
1979
|
return isRecord(value) ? value : {};
|
|
1888
1980
|
}
|
|
1981
|
+
function readLifetimeTotalsPath(value, issues) {
|
|
1982
|
+
if (value === undefined)
|
|
1983
|
+
return DEFAULT_CONFIG.lifetimeTotalsPath;
|
|
1984
|
+
if (typeof value !== "string" || value.trim().length === 0) {
|
|
1985
|
+
issues.push("lifetimeTotalsPath must be a non-empty string; using the default path");
|
|
1986
|
+
return DEFAULT_CONFIG.lifetimeTotalsPath;
|
|
1987
|
+
}
|
|
1988
|
+
return value.trim();
|
|
1989
|
+
}
|
|
1889
1990
|
function readRefresh(value, issues) {
|
|
1890
1991
|
if (value === undefined)
|
|
1891
1992
|
return DEFAULT_REFRESH_MS;
|
|
@@ -2330,7 +2431,8 @@ function resolveConfig(options) {
|
|
|
2330
2431
|
format: readFormat(format, issues),
|
|
2331
2432
|
glyphs: readGlyphs(glyphs, issues),
|
|
2332
2433
|
style: readStyle(style, issues),
|
|
2333
|
-
refresh: readRefresh(options.refresh, issues)
|
|
2434
|
+
refresh: readRefresh(options.refresh, issues),
|
|
2435
|
+
lifetimeTotalsPath: readLifetimeTotalsPath(options.lifetimeTotalsPath, issues)
|
|
2334
2436
|
},
|
|
2335
2437
|
issues
|
|
2336
2438
|
};
|
|
@@ -2342,19 +2444,19 @@ function shouldNotify(config, kind) {
|
|
|
2342
2444
|
}
|
|
2343
2445
|
|
|
2344
2446
|
// src/tui/file-config.ts
|
|
2345
|
-
import { existsSync, readFileSync, statSync } from "fs";
|
|
2346
|
-
import { homedir } from "os";
|
|
2347
|
-
import { isAbsolute, join } from "path";
|
|
2447
|
+
import { existsSync as existsSync2, readFileSync as readFileSync2, statSync } from "fs";
|
|
2448
|
+
import { homedir as homedir2 } from "os";
|
|
2449
|
+
import { isAbsolute, join as join2 } from "path";
|
|
2348
2450
|
var CONFIG_FILE_CANDIDATES = ["flight-deck.jsonc", "flight-deck.json"];
|
|
2349
2451
|
function globalConfigDirectory() {
|
|
2350
2452
|
const xdg = process.env["XDG_CONFIG_HOME"]?.trim();
|
|
2351
|
-
return xdg !== undefined && xdg.length > 0 && isAbsolute(xdg) ?
|
|
2453
|
+
return xdg !== undefined && xdg.length > 0 && isAbsolute(xdg) ? join2(xdg, "opencode") : join2(homedir2(), ".config", "opencode");
|
|
2352
2454
|
}
|
|
2353
2455
|
var MAX_CONFIG_BYTES = 64 * 1024;
|
|
2354
2456
|
function findConfigFile(directory = globalConfigDirectory()) {
|
|
2355
2457
|
for (const candidate of CONFIG_FILE_CANDIDATES) {
|
|
2356
|
-
const path =
|
|
2357
|
-
if (
|
|
2458
|
+
const path = join2(directory, candidate);
|
|
2459
|
+
if (existsSync2(path))
|
|
2358
2460
|
return path;
|
|
2359
2461
|
}
|
|
2360
2462
|
return;
|
|
@@ -2378,7 +2480,7 @@ function loadConfigFile(directory = globalConfigDirectory()) {
|
|
|
2378
2480
|
const limit = Math.floor(MAX_CONFIG_BYTES / 1024);
|
|
2379
2481
|
return { options: undefined, source, issue: `${source} is larger than ${limit} KiB; using defaults` };
|
|
2380
2482
|
}
|
|
2381
|
-
const text =
|
|
2483
|
+
const text = readFileSync2(source, "utf8");
|
|
2382
2484
|
if (text.trim().length === 0) {
|
|
2383
2485
|
return { options: undefined, source, issue: `${source} is empty; using defaults` };
|
|
2384
2486
|
}
|
|
@@ -2394,12 +2496,12 @@ function loadConfigFile(directory = globalConfigDirectory()) {
|
|
|
2394
2496
|
}
|
|
2395
2497
|
|
|
2396
2498
|
// src/tui/go-look.ts
|
|
2397
|
-
import { existsSync as
|
|
2398
|
-
import { join as
|
|
2499
|
+
import { existsSync as existsSync3, statSync as statSync2 } from "fs";
|
|
2500
|
+
import { join as join3 } from "path";
|
|
2399
2501
|
function findCandidate(directory) {
|
|
2400
2502
|
for (const candidate of CONFIG_FILE_CANDIDATES) {
|
|
2401
|
-
const path =
|
|
2402
|
-
if (
|
|
2503
|
+
const path = join3(directory, candidate);
|
|
2504
|
+
if (existsSync3(path))
|
|
2403
2505
|
return path;
|
|
2404
2506
|
}
|
|
2405
2507
|
return;
|
|
@@ -2468,7 +2570,9 @@ function railLines(config, source = {}) {
|
|
|
2468
2570
|
durationStyle: config.format.duration,
|
|
2469
2571
|
timestamp: config.format.timestamp,
|
|
2470
2572
|
tpsDisplay: config.sidebar.tps.display,
|
|
2471
|
-
|
|
2573
|
+
tpsLabel: config.sidebar.tps.label,
|
|
2574
|
+
tpsTtft: config.sidebar.tps.ttft,
|
|
2575
|
+
hasLifetimeRow: config.sidebar.rows.some((field) => canonicalField(field) === "lifetime")
|
|
2472
2576
|
};
|
|
2473
2577
|
const lines = config.sidebar.lines.map((text) => ({ text }));
|
|
2474
2578
|
for (const field of config.sidebar.rows) {
|
|
@@ -2497,7 +2601,9 @@ function railLineSpans(line, style) {
|
|
|
2497
2601
|
function footerLine(config) {
|
|
2498
2602
|
return config.footer.enabled ? config.footer.text : undefined;
|
|
2499
2603
|
}
|
|
2604
|
+
|
|
2500
2605
|
// src/tui/go-panel.ts
|
|
2606
|
+
var NO_READING = "\u2014";
|
|
2501
2607
|
var PANEL_WINDOWS = ["5h", "1w", "1m"];
|
|
2502
2608
|
var PANEL_DEFAULT_LABELS = {
|
|
2503
2609
|
rolling: "rolling",
|
|
@@ -2699,7 +2805,7 @@ function restingLine(label, look, reason, nowMs, isFirst) {
|
|
|
2699
2805
|
segments.push({ text: `${reason} `, tone: "subdued" });
|
|
2700
2806
|
trackCells = Math.max(0, cells - reason.length - 1);
|
|
2701
2807
|
}
|
|
2702
|
-
const tail = CELL.repeat(trackCells) + (look.showPercent ? ` ${alignCell(
|
|
2808
|
+
const tail = CELL.repeat(trackCells) + (look.showPercent ? ` ${alignCell(NO_READING, PANEL_PERCENT_WIDTH, look.align)}` : "");
|
|
2703
2809
|
segments.push({ text: tail, tone: "subdued" });
|
|
2704
2810
|
return { field: "go", text: segments.map((segment) => segment.text).join(""), segments };
|
|
2705
2811
|
}
|
|
@@ -2718,7 +2824,7 @@ function valueLine(label, look, window, nowMs, frame, isFirst) {
|
|
|
2718
2824
|
appendRun(runs, CELL, "subdued");
|
|
2719
2825
|
}
|
|
2720
2826
|
if (look.showPercent) {
|
|
2721
|
-
const percent = ratio === undefined ?
|
|
2827
|
+
const percent = ratio === undefined ? NO_READING : `${Math.round(ratio * 100)}%`;
|
|
2722
2828
|
appendRun(runs, ` ${alignCell(percent, PANEL_PERCENT_WIDTH, look.align)}`, tone);
|
|
2723
2829
|
}
|
|
2724
2830
|
const segments = [];
|
|
@@ -3000,9 +3106,9 @@ function startGuardBridge(host, deps, intervalMs = GUARD_POLL_MS) {
|
|
|
3000
3106
|
}
|
|
3001
3107
|
|
|
3002
3108
|
// src/tui/go.ts
|
|
3003
|
-
import { appendFileSync, existsSync as
|
|
3109
|
+
import { appendFileSync, existsSync as existsSync4, mkdirSync as mkdirSync2, readFileSync as readFileSync3, writeFileSync as writeFileSync2 } from "fs";
|
|
3004
3110
|
import { tmpdir } from "os";
|
|
3005
|
-
import { join as
|
|
3111
|
+
import { join as join4 } from "path";
|
|
3006
3112
|
var GO_KEY = "flight-deck.go";
|
|
3007
3113
|
var GO_POLL_MS = 60000;
|
|
3008
3114
|
var GO_USAGE_URL = "https://opencode.ai/zen/go/v1/usage";
|
|
@@ -3368,22 +3474,22 @@ function logPoll(entry) {
|
|
|
3368
3474
|
if (!goLogEnabled())
|
|
3369
3475
|
return;
|
|
3370
3476
|
try {
|
|
3371
|
-
const directory =
|
|
3372
|
-
const path =
|
|
3477
|
+
const directory = join4(tmpdir(), GO_LOG_DIR);
|
|
3478
|
+
const path = join4(directory, GO_LOG_FILE);
|
|
3373
3479
|
const line = `ts=${new Date().toISOString()} src=${entry.src} key=${entry.key ? "yes" : "no"} http=${entry.http} parse=${entry.parse} reason=${entry.reason}
|
|
3374
3480
|
`;
|
|
3375
3481
|
let prior = "";
|
|
3376
3482
|
try {
|
|
3377
|
-
if (
|
|
3378
|
-
prior =
|
|
3483
|
+
if (existsSync4(path))
|
|
3484
|
+
prior = readFileSync3(path, "utf8");
|
|
3379
3485
|
} catch {
|
|
3380
3486
|
prior = "";
|
|
3381
3487
|
}
|
|
3382
3488
|
const lines = prior.length === 0 ? 0 : prior.split(`
|
|
3383
3489
|
`).filter((row) => row.length > 0).length;
|
|
3384
|
-
|
|
3490
|
+
mkdirSync2(directory, { recursive: true });
|
|
3385
3491
|
if (lines >= GO_LOG_MAX_LINES)
|
|
3386
|
-
|
|
3492
|
+
writeFileSync2(path, line);
|
|
3387
3493
|
else
|
|
3388
3494
|
appendFileSync(path, line);
|
|
3389
3495
|
} catch {}
|
|
@@ -3526,12 +3632,12 @@ function startGoBridge(host, deps, intervalMs = GO_POLL_MS) {
|
|
|
3526
3632
|
|
|
3527
3633
|
// src/tui/codex-quota.ts
|
|
3528
3634
|
import { spawn } from "child_process";
|
|
3529
|
-
import { existsSync as
|
|
3530
|
-
import { isAbsolute as isAbsolute2, join as
|
|
3635
|
+
import { existsSync as existsSync5, readFileSync as readFileSync4 } from "fs";
|
|
3636
|
+
import { isAbsolute as isAbsolute2, join as join6 } from "path";
|
|
3531
3637
|
import { createInterface } from "readline";
|
|
3532
3638
|
|
|
3533
3639
|
// src/tui/owned-process.ts
|
|
3534
|
-
import { join as
|
|
3640
|
+
import { join as join5 } from "path";
|
|
3535
3641
|
var supervisor = String.raw`
|
|
3536
3642
|
using System;
|
|
3537
3643
|
using System.ComponentModel;
|
|
@@ -3651,7 +3757,7 @@ ${supervisor}
|
|
|
3651
3757
|
$argsList=${decode(JSON.stringify(args))}|ConvertFrom-Json
|
|
3652
3758
|
` + `exit [FlightDeckOwned]::Run($command,[string[]]$argsList,${ownerPid})`;
|
|
3653
3759
|
return {
|
|
3654
|
-
command:
|
|
3760
|
+
command: join5(process.env.SystemRoot ?? "C:\\Windows", "System32", "WindowsPowerShell", "v1.0", "powershell.exe"),
|
|
3655
3761
|
args: ["-NoLogo", "-NoProfile", "-NonInteractive", "-EncodedCommand", Buffer.from(script, "utf16le").toString("base64")]
|
|
3656
3762
|
};
|
|
3657
3763
|
}
|
|
@@ -3683,15 +3789,15 @@ function executable(pathValue = process.env.PATH ?? "") {
|
|
|
3683
3789
|
for (const directory of pathValue.split(process.platform === "win32" ? ";" : ":")) {
|
|
3684
3790
|
if (!isAbsolute2(directory))
|
|
3685
3791
|
continue;
|
|
3686
|
-
const path =
|
|
3687
|
-
if (!
|
|
3792
|
+
const path = join6(directory, process.platform === "win32" ? "codex.exe" : "codex");
|
|
3793
|
+
if (!existsSync5(path))
|
|
3688
3794
|
continue;
|
|
3689
3795
|
if (process.platform === "win32") {
|
|
3690
3796
|
const shim = path.replace(/\.exe$/i, ".shim");
|
|
3691
|
-
if (
|
|
3797
|
+
if (existsSync5(shim)) {
|
|
3692
3798
|
try {
|
|
3693
|
-
const target = /^path\s*=\s*"([^"\r\n]+)"\s*$/m.exec(
|
|
3694
|
-
if (target && isAbsolute2(target) && /[\\/]codex\.exe$/i.test(target) &&
|
|
3799
|
+
const target = /^path\s*=\s*"([^"\r\n]+)"\s*$/m.exec(readFileSync4(shim, "utf8"))?.[1];
|
|
3800
|
+
if (target && isAbsolute2(target) && /[\\/]codex\.exe$/i.test(target) && existsSync5(target))
|
|
3695
3801
|
return target;
|
|
3696
3802
|
} catch {}
|
|
3697
3803
|
return;
|
|
@@ -4568,7 +4674,7 @@ var tui_default = Plugin.define({
|
|
|
4568
4674
|
setup(context) {
|
|
4569
4675
|
const file = loadConfigFile();
|
|
4570
4676
|
const { config, issues } = resolveConfig(mergeOptions(file.options, context.options));
|
|
4571
|
-
const rows = config.sidebar.enabled ? new Set(config.sidebar.rows) : new Set;
|
|
4677
|
+
const rows = config.sidebar.enabled ? new Set(config.sidebar.rows.map(canonicalField)) : new Set;
|
|
4572
4678
|
const wants = (name) => rows.has(name);
|
|
4573
4679
|
if (file.issue !== undefined && file.source !== undefined) {
|
|
4574
4680
|
console.warn(`[flight-deck] ${file.issue}`);
|
|
@@ -4636,6 +4742,7 @@ var tui_default = Plugin.define({
|
|
|
4636
4742
|
busy
|
|
4637
4743
|
} = reads;
|
|
4638
4744
|
const { projectTotals } = createProjectTotals(context);
|
|
4745
|
+
const lifetimeTotals = createLifetimeTotals({ path: config.lifetimeTotalsPath });
|
|
4639
4746
|
const cautionThreshold = cautionThresholds(config.caution);
|
|
4640
4747
|
const cautionsOf = (sessionID, now) => detectCautions({
|
|
4641
4748
|
parts: recentParts(sessionID),
|
|
@@ -4693,9 +4800,27 @@ var tui_default = Plugin.define({
|
|
|
4693
4800
|
const isBusy = busy(sessionID);
|
|
4694
4801
|
spinnerNeeded = wants("status") && isBusy === true;
|
|
4695
4802
|
const turns = wants("turns") ? messagesOf(sessionID).filter((entry) => asRecord2(entry)?.["type"] === "user").length : undefined;
|
|
4696
|
-
const wantsUsage = wants("
|
|
4803
|
+
const wantsUsage = wants("spend") || wants("lifetime") || wants("tokens") || wants("cache") || wants("reasoning");
|
|
4697
4804
|
const ownCost = wantsUsage ? sessionCost(sessionID, session) : undefined;
|
|
4698
4805
|
const tree = wantsUsage ? treeTotals(sessionID) : undefined;
|
|
4806
|
+
let lifetime;
|
|
4807
|
+
if (wantsUsage) {
|
|
4808
|
+
let root = sessionID;
|
|
4809
|
+
try {
|
|
4810
|
+
root = context.data.session.root(sessionID) ?? sessionID;
|
|
4811
|
+
} catch {
|
|
4812
|
+
root = sessionID;
|
|
4813
|
+
}
|
|
4814
|
+
const stored = lifetimeTotals.read(root);
|
|
4815
|
+
const live = tree?.cost;
|
|
4816
|
+
if (live !== undefined && (stored === undefined || live > stored)) {
|
|
4817
|
+
lifetimeTotals.record(root, live);
|
|
4818
|
+
}
|
|
4819
|
+
const high = Math.max(live ?? 0, stored ?? 0);
|
|
4820
|
+
if (live !== undefined || stored !== undefined) {
|
|
4821
|
+
lifetime = { cost: high, count: tree?.count ?? 0, kind: tree?.kind ?? "bounded" };
|
|
4822
|
+
}
|
|
4823
|
+
}
|
|
4699
4824
|
return {
|
|
4700
4825
|
...session,
|
|
4701
4826
|
cost: ownCost?.cost,
|
|
@@ -4704,6 +4829,7 @@ var tui_default = Plugin.define({
|
|
|
4704
4829
|
caution: wants("caution") ? announce(sessionID) : undefined,
|
|
4705
4830
|
branch: wants("branch") ? branchOf(location) : undefined,
|
|
4706
4831
|
tree,
|
|
4832
|
+
lifetime,
|
|
4707
4833
|
context: wants("context") ? contextUsage(sessionID, session?.model) : undefined,
|
|
4708
4834
|
project: wants("project") ? projectTotals(sessionID) : undefined,
|
|
4709
4835
|
status: wants("status") ? statusOf(sessionID) : undefined,
|