oc-flight-deck 0.2.2 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +27 -14
- package/flight-deck.example.jsonc +19 -12
- package/flight-deck.schema.json +4 -4
- package/package.json +2 -2
- package/src/tui/caution.ts +11 -4
- package/src/tui/config.ts +14 -2
- package/src/tui/index.tsx +72 -10
- package/src/tui/stats.ts +34 -5
package/README.md
CHANGED
|
@@ -48,7 +48,7 @@ learn. The panel appears beside an open session and starts reading.
|
|
|
48
48
|
| `model` | The model *and its variant* - `high` behaves differently. |
|
|
49
49
|
| `branch` | Which branch you're about to commit to. |
|
|
50
50
|
| `cost` | This conversation, plus its subagents once any have run. |
|
|
51
|
-
| `project` | Every session in this
|
|
51
|
+
| `project` | Every session in this **project** — matched by the host's project id, so worktrees count together. |
|
|
52
52
|
| `tokens` | Input and output, cumulative. |
|
|
53
53
|
| `cache` | Hit rate first, because that's the number that explains the bill. |
|
|
54
54
|
| `context` | A gauge of how full the window is. |
|
|
@@ -56,7 +56,13 @@ learn. The panel appears beside an open session and starts reading.
|
|
|
56
56
|
| `elapsed` | How long you've been at it. |
|
|
57
57
|
| `tps` | Output tokens per second, measured from the last completed turn. |
|
|
58
58
|
| `spark` | Recent turn sizes as a shape. Available, off by default. |
|
|
59
|
-
| `
|
|
59
|
+
| `reasoning` | Reasoning tokens, when the model emits them. Available, off by default. |
|
|
60
|
+
| `turns` | How many prompts you have sent this session. Available, off by default. |
|
|
61
|
+
| `total` | The family total and subagent count on a row of its own. Adding it makes `cost` show the session figure alone. Available, off by default. |
|
|
62
|
+
|
|
63
|
+
`project` matches on the host's **project id**, not on a directory, so a worktree
|
|
64
|
+
counts as part of the same project. A host that reports no project id leaves
|
|
65
|
+
nothing to match on, and the row then totals every session that host knows about.
|
|
60
66
|
|
|
61
67
|
### `caution` is the one row that isn't session state
|
|
62
68
|
|
|
@@ -77,11 +83,14 @@ hang.
|
|
|
77
83
|
| the same call fails with identical input | caution at 3 |
|
|
78
84
|
| a running session stops producing anything | watch at 10m, caution at 20m |
|
|
79
85
|
|
|
80
|
-
The thresholds are calibrated, not guessed. Measured over **
|
|
81
|
-
calls**,
|
|
82
|
-
|
|
83
|
-
alone
|
|
84
|
-
|
|
86
|
+
The thresholds are calibrated, not guessed. Measured over **54,218 real settled
|
|
87
|
+
tool calls**, **307** (0.57%) ran longer than three minutes — and **200 of those
|
|
88
|
+
are on the exempt list**, so with it **0.20%** of calls light the row. `subagent`
|
|
89
|
+
alone accounts for 152 of them at a p99 of 14.2 minutes: a delegated agent
|
|
90
|
+
running a quarter of an hour is working as designed. Without the list the row
|
|
91
|
+
lights up on every delegation, and you would learn to ignore it.
|
|
92
|
+
|
|
93
|
+
The percentages move as that history grows; the exemption ratio is the point.
|
|
85
94
|
|
|
86
95
|
The toast is **off by default**. The rail is the signal; a notification is an
|
|
87
96
|
interruption.
|
|
@@ -148,7 +157,7 @@ then edit. Comments and trailing commas are fine.
|
|
|
148
157
|
"turnCautionSeconds": 1200,
|
|
149
158
|
"repeatThreshold": 3,
|
|
150
159
|
// Tools that are slow by nature, so slow is not an anomaly for them.
|
|
151
|
-
"exemptTools": ["question", "task", "subagent", "agent", "delegate"],
|
|
160
|
+
"exemptTools": ["question", "task", "subagent", "agent", "delegate", "delegate_many", "delegate_task"],
|
|
152
161
|
// Off by default: the rail is the signal, a toast is an interruption.
|
|
153
162
|
"toast": false
|
|
154
163
|
},
|
|
@@ -176,7 +185,8 @@ Flight Deck shows what OpenCode already knows.
|
|
|
176
185
|
between turns. It is scoped to this plugin and dies with the TUI; it is never
|
|
177
186
|
persisted, and `"refresh": 0` removes even that.
|
|
178
187
|
- **No polling of your session** — cost, tokens, and permissions update from the
|
|
179
|
-
host's own events.
|
|
188
|
+
host's own events. The timer only re-reads state the host already holds in
|
|
189
|
+
memory, and only so the clock-derived rows keep moving.
|
|
180
190
|
- **Theme-native.** Every line uses your active theme's text tokens, so it blends
|
|
181
191
|
with whatever look you already run.
|
|
182
192
|
|
|
@@ -200,17 +210,20 @@ that come out. A guard test parses the shipped example config and asserts it
|
|
|
200
210
|
still matches the real defaults, so the documentation can't drift from the code.
|
|
201
211
|
|
|
202
212
|
To load the plugin **from this checkout** while working on it, add it to the
|
|
203
|
-
|
|
213
|
+
`opencode.jsonc` of the project you run OpenCode in. A `plugins` entry is a
|
|
214
|
+
package specifier, not a file path — a bare path is ignored silently — so the
|
|
215
|
+
checkout has to be named as a git file URL:
|
|
204
216
|
|
|
205
217
|
```jsonc
|
|
206
218
|
{
|
|
207
|
-
"plugins": ["
|
|
219
|
+
"plugins": ["git+file:///absolute/path/to/oc-flight-deck"]
|
|
208
220
|
}
|
|
209
221
|
```
|
|
210
222
|
|
|
211
|
-
That
|
|
212
|
-
|
|
213
|
-
|
|
223
|
+
That installs a **copy, not a symlink**, so re-run the install after editing the
|
|
224
|
+
checkout. This file is deliberately **not** committed: if the plugin is also
|
|
225
|
+
installed globally, declaring it in both places registers the same plugin id
|
|
226
|
+
twice and the host's plugin list shows one of them as failed.
|
|
214
227
|
|
|
215
228
|
Built on the official
|
|
216
229
|
[OpenCode V2 CLI plugin API](https://opencode.ai/v2/docs/build/plugins/cli).
|
|
@@ -54,23 +54,28 @@
|
|
|
54
54
|
// them freely — an unknown name is ignored with a one-time warning, so a
|
|
55
55
|
// typo can never break the panel.
|
|
56
56
|
//
|
|
57
|
+
// caution the annunciator: silent unless something stopped moving
|
|
57
58
|
// status running or idle — the glyph turns while anything is working
|
|
58
59
|
// agent which agent is running (orchestrator, build, plan, ...)
|
|
59
60
|
// model model id, plus the variant when there is one
|
|
60
61
|
// branch current git branch
|
|
61
|
-
// cost
|
|
62
|
-
//
|
|
63
|
-
//
|
|
64
|
-
// project every session in this
|
|
62
|
+
// cost this conversation, plus its subagents when any ran; with
|
|
63
|
+
// `total` on the rail, the session figure alone
|
|
64
|
+
// total the family total and subagent count on a row of its own
|
|
65
|
+
// project every session in this project, not just the one on screen
|
|
65
66
|
// tokens this session's input and output tokens
|
|
66
67
|
// cache cache hit rate, then cache reads
|
|
67
68
|
// context a gauge of how full the context window is
|
|
68
69
|
// perms what is waiting for approval, not just how many
|
|
69
70
|
// elapsed wall-clock time since the session started
|
|
70
71
|
// tps output tokens per second on the last completed turn
|
|
71
|
-
// spark recent turn sizes as a sparkline
|
|
72
|
+
// spark recent turn sizes as a sparkline
|
|
72
73
|
// reasoning reasoning tokens, when the model emits them
|
|
73
|
-
// turns
|
|
74
|
+
// turns how many prompts you have sent this session
|
|
75
|
+
//
|
|
76
|
+
// A row appears only once the host has data for it — nothing is drawn as a
|
|
77
|
+
// placeholder. The fixed lines and the live rows together are capped at 24,
|
|
78
|
+
// and anything past that is dropped.
|
|
74
79
|
"rows": [
|
|
75
80
|
"caution",
|
|
76
81
|
"status",
|
|
@@ -135,11 +140,12 @@
|
|
|
135
140
|
// Tools that are slow by NATURE, so slow is not an anomaly for them.
|
|
136
141
|
// Matched by exact name.
|
|
137
142
|
//
|
|
138
|
-
// Calibrated against
|
|
139
|
-
//
|
|
140
|
-
//
|
|
141
|
-
//
|
|
142
|
-
//
|
|
143
|
+
// Calibrated against 54,218 real settled tool calls: at the default
|
|
144
|
+
// threshold, 307 (0.57%) exceed it and 200 of those are these tools, so
|
|
145
|
+
// with the list 0.20% of calls light the row. `subagent` alone crossed 152
|
|
146
|
+
// times, with a p99 of 14.2 minutes. Without this list the annunciator
|
|
147
|
+
// lights on every delegated task - which is how an alert gets ignored.
|
|
148
|
+
// Add your own long-running or orchestration tools here.
|
|
143
149
|
"exemptTools": ["question", "task", "subagent", "agent", "delegate", "delegate_many", "delegate_task"],
|
|
144
150
|
|
|
145
151
|
// Also raise a toast, once per distinct problem, re-arming when the session
|
|
@@ -157,7 +163,8 @@
|
|
|
157
163
|
// Cells in the `context` gauge.
|
|
158
164
|
"barWidth": 10,
|
|
159
165
|
// Samples drawn in the `spark` row. The newest turns are kept, so
|
|
160
|
-
// narrowing this keeps the recent shape rather than the oldest.
|
|
166
|
+
// narrowing this keeps the recent shape rather than the oldest. The row is
|
|
167
|
+
// this many cells wide, so a large value is a wide row.
|
|
161
168
|
"sparkWidth": 12
|
|
162
169
|
},
|
|
163
170
|
|
package/flight-deck.schema.json
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"minimum": 0,
|
|
17
17
|
"maximum": 60000,
|
|
18
18
|
"default": 100,
|
|
19
|
-
"description": "Milliseconds between ticks. Cost and tokens arrive with host events; anything derived from the clock — `elapsed`, the status spinner, and the caution thresholds — needs this timer. 100 turns the spinner once a second. 0 turns the ticker off entirely, which also freezes the annunciator (it works, but only updates on host events). Practical range 16–1000;
|
|
19
|
+
"description": "Milliseconds between ticks. Cost and tokens arrive with host events; anything derived from the clock — `elapsed`, the status spinner, and the caution thresholds — needs this timer. 100 turns the spinner once a second. 0 turns the ticker off entirely, which also freezes the annunciator (it works, but only updates on host events). Practical range 16–1000; 1–15 are treated as 16, while 0 is the deliberate off switch and is never clamped."
|
|
20
20
|
},
|
|
21
21
|
|
|
22
22
|
"sidebar": {
|
|
@@ -34,14 +34,14 @@
|
|
|
34
34
|
"items": { "type": "string" },
|
|
35
35
|
"default": ["✈ FLIGHT DECK", "─────────────────"],
|
|
36
36
|
"maxItems": 24,
|
|
37
|
-
"description": "Fixed lines rendered above the live rows, in order. Branding or a separator. These render at full brightness; the live rows below them are dimmed."
|
|
37
|
+
"description": "Fixed lines rendered above the live rows, in order. Branding or a separator. These render at full brightness; the live rows below them are dimmed. The fixed lines and the live rows together are capped at 24 — anything past that is dropped from the rail."
|
|
38
38
|
},
|
|
39
39
|
"rows": {
|
|
40
40
|
"type": "array",
|
|
41
41
|
"items": { "enum": ["caution", "status", "agent", "model", "branch", "cost", "total", "project", "tokens", "cache", "context", "perms", "elapsed", "tps", "spark", "reasoning", "turns"] },
|
|
42
42
|
"default": ["caution", "status", "agent", "model", "branch", "cost", "project", "tokens", "cache", "context", "perms", "elapsed", "tps"],
|
|
43
43
|
"maxItems": 24,
|
|
44
|
-
"description": "Which live fields to draw, top to bottom. Any subset, any order — this is the single most useful thing to change. Rows with no data are omitted entirely, so a narrow rail grows rows as a session produces them rather than showing placeholders."
|
|
44
|
+
"description": "Which live fields to draw, top to bottom. Any subset, any order — this is the single most useful thing to change. Rows with no data are omitted entirely, so a narrow rail grows rows as a session produces them rather than showing placeholders. Counted together with `sidebar.lines` against a 24-line cap on the whole rail."
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
},
|
|
@@ -141,7 +141,7 @@
|
|
|
141
141
|
"minimum": 2,
|
|
142
142
|
"maximum": 64,
|
|
143
143
|
"default": 12,
|
|
144
|
-
"description": "Samples drawn in the `spark` row. The newest turns are kept, so narrowing it keeps the recent shape rather than the oldest."
|
|
144
|
+
"description": "Samples drawn in the `spark` row. The newest turns are kept, so narrowing it keeps the recent shape rather than the oldest. The row is this many cells wide, so a large value is a wide row — mind a narrow sidebar."
|
|
145
145
|
}
|
|
146
146
|
}
|
|
147
147
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "oc-flight-deck",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"description": "Live OpenCode V2 session telemetry — agent, model, branch, cost, tokens, cache hit rate and context usage in your sidebar.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"opencode",
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
"@opentui/core": "0.5.10",
|
|
60
60
|
"@opentui/solid": "0.5.10",
|
|
61
61
|
"@types/bun": "^1.4.2",
|
|
62
|
-
"solid-js": "1.9.
|
|
62
|
+
"solid-js": "1.9.12",
|
|
63
63
|
"typescript": "^5.9.0"
|
|
64
64
|
},
|
|
65
65
|
"peerDependencies": {
|
package/src/tui/caution.ts
CHANGED
|
@@ -153,7 +153,14 @@ function sortValue(value: unknown): unknown {
|
|
|
153
153
|
|
|
154
154
|
const SEVERITY_ORDER: Record<CautionSeverity, number> = { caution: 0, watch: 1 };
|
|
155
155
|
|
|
156
|
-
|
|
156
|
+
/**
|
|
157
|
+
* Watch or caution, from the elapsed time alone.
|
|
158
|
+
*
|
|
159
|
+
* Callers reach this only after the watch threshold has already been crossed, so
|
|
160
|
+
* there is nothing left to compare against but the escalation. (The watch
|
|
161
|
+
* threshold used to be passed in and ignored, which read as if it mattered.)
|
|
162
|
+
*/
|
|
163
|
+
function severityFor(elapsed: number, cautionMs: number): CautionSeverity {
|
|
157
164
|
return elapsed >= cautionMs ? "caution" : "watch";
|
|
158
165
|
}
|
|
159
166
|
|
|
@@ -186,7 +193,7 @@ export function detectCautions(input: CautionInput): Caution[] {
|
|
|
186
193
|
|
|
187
194
|
found.push({
|
|
188
195
|
kind: "hung-tool",
|
|
189
|
-
severity: severityFor(elapsedMs, thresholds.
|
|
196
|
+
severity: severityFor(elapsedMs, thresholds.toolCautionMs),
|
|
190
197
|
tool: call.name,
|
|
191
198
|
status: call.status,
|
|
192
199
|
elapsedMs,
|
|
@@ -219,7 +226,7 @@ export function detectCautions(input: CautionInput): Caution[] {
|
|
|
219
226
|
const existing = found.findIndex((c) => c.kind === "hung-shell");
|
|
220
227
|
const caution: Caution = {
|
|
221
228
|
kind: "hung-shell",
|
|
222
|
-
severity: severityFor(elapsedMs, thresholds.
|
|
229
|
+
severity: severityFor(elapsedMs, thresholds.toolCautionMs),
|
|
223
230
|
tool: label,
|
|
224
231
|
status: "running",
|
|
225
232
|
elapsedMs,
|
|
@@ -301,7 +308,7 @@ export function detectCautions(input: CautionInput): Caution[] {
|
|
|
301
308
|
if (elapsedMs >= thresholds.turnWatchMs) {
|
|
302
309
|
found.push({
|
|
303
310
|
kind: "silent-turn",
|
|
304
|
-
severity: severityFor(elapsedMs, thresholds.
|
|
311
|
+
severity: severityFor(elapsedMs, thresholds.turnCautionMs),
|
|
305
312
|
elapsedMs,
|
|
306
313
|
key: "silent-turn",
|
|
307
314
|
});
|
package/src/tui/config.ts
CHANGED
|
@@ -596,12 +596,24 @@ export function resolveConfig(options: unknown): ConfigResolution {
|
|
|
596
596
|
// about it, and an explicit `enabled` always wins either way.
|
|
597
597
|
const footerConfigured = Object.keys(footer).length > 0;
|
|
598
598
|
|
|
599
|
+
const lines = readLines(sidebar.lines, issues);
|
|
600
|
+
const rows = readRows(sidebar.rows, issues);
|
|
601
|
+
// `sidebarLines` caps the whole rail at MAX_LINES, so the fixed lines and the
|
|
602
|
+
// live rows draw from one budget. `readLines` already reports its own cut;
|
|
603
|
+
// this is the other half, which used to be silent — a long `lines` list ate
|
|
604
|
+
// live rows off the bottom of the rail without saying so.
|
|
605
|
+
if (lines.length + rows.length > MAX_LINES) {
|
|
606
|
+
issues.push(
|
|
607
|
+
`sidebar.lines and sidebar.rows total ${lines.length + rows.length} lines; the rail draws the first ${MAX_LINES}`,
|
|
608
|
+
);
|
|
609
|
+
}
|
|
610
|
+
|
|
599
611
|
return {
|
|
600
612
|
config: {
|
|
601
613
|
sidebar: {
|
|
602
614
|
enabled: readBoolean(sidebar.enabled, DEFAULT_CONFIG.sidebar.enabled, "sidebar.enabled", issues),
|
|
603
|
-
lines
|
|
604
|
-
rows
|
|
615
|
+
lines,
|
|
616
|
+
rows,
|
|
605
617
|
},
|
|
606
618
|
footer: {
|
|
607
619
|
enabled: readBoolean(footer.enabled, footerConfigured, "footer.enabled", issues),
|
package/src/tui/index.tsx
CHANGED
|
@@ -33,6 +33,12 @@ function asCount(value: unknown): number | undefined {
|
|
|
33
33
|
return typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : undefined;
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
+
function asText(value: unknown): string | undefined {
|
|
37
|
+
if (typeof value !== "string") return undefined;
|
|
38
|
+
const text = value.trim();
|
|
39
|
+
return text.length === 0 ? undefined : text;
|
|
40
|
+
}
|
|
41
|
+
|
|
36
42
|
function asRecord(value: unknown): Record<string, unknown> | undefined {
|
|
37
43
|
return typeof value === "object" && value !== null && !Array.isArray(value)
|
|
38
44
|
? (value as Record<string, unknown>)
|
|
@@ -72,9 +78,26 @@ export default Plugin.define({
|
|
|
72
78
|
}
|
|
73
79
|
};
|
|
74
80
|
|
|
81
|
+
// A subagent session is already inside its parent's family total, and the
|
|
82
|
+
// host keys `family()` by the family ROOT — so asking from a child returns
|
|
83
|
+
// its ancestors and siblings as well. Merging that would report the whole
|
|
84
|
+
// tree as this conversation's own, under a label that promises the
|
|
85
|
+
// conversation plus *its* subagents. Only a root has a family beneath it.
|
|
86
|
+
const isFamilyRoot = (sessionID: string): boolean => {
|
|
87
|
+
try {
|
|
88
|
+
return context.data.session.root(sessionID) === sessionID;
|
|
89
|
+
} catch {
|
|
90
|
+
// A host without `root` keeps the previous behaviour rather than
|
|
91
|
+
// silently dropping everyone's subagent total.
|
|
92
|
+
return true;
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
|
|
75
96
|
// Subagent sessions are separate sessions, and the parent's `cost` does not
|
|
76
97
|
// include them, so a bare `cost` row understates a swarm. Sum the family.
|
|
77
98
|
const treeTotals = (sessionID: string, ownCost: unknown) => {
|
|
99
|
+
if (!isFamilyRoot(sessionID)) return undefined;
|
|
100
|
+
|
|
78
101
|
let ids: readonly string[];
|
|
79
102
|
try {
|
|
80
103
|
ids = context.data.session.family(sessionID) ?? [sessionID];
|
|
@@ -143,14 +166,28 @@ export default Plugin.define({
|
|
|
143
166
|
return elapsed <= 0 ? undefined : elapsed;
|
|
144
167
|
};
|
|
145
168
|
|
|
146
|
-
// Project spend: every session
|
|
147
|
-
//
|
|
148
|
-
|
|
169
|
+
// Project spend: every session in THIS project, not just the one on screen.
|
|
170
|
+
//
|
|
171
|
+
// `session.list()` is not scoped - it returns sessions across every
|
|
172
|
+
// directory the host knows about, so summing it gives "everything you have
|
|
173
|
+
// ever run" while claiming to be a project total. Filtered by `projectID`
|
|
174
|
+
// rather than by directory, because one project legitimately spans several
|
|
175
|
+
// directories (worktrees).
|
|
176
|
+
//
|
|
177
|
+
// If the host does not report a project id, the unfiltered list is used, so
|
|
178
|
+
// this degrades to the old behaviour instead of showing nothing.
|
|
179
|
+
const projectTotals = (sessionID: string) => {
|
|
149
180
|
try {
|
|
150
181
|
const sessions = context.data.session.list() ?? [];
|
|
182
|
+
const projectID = asText(asRecord(context.data.session.get(sessionID))?.["projectID"]);
|
|
183
|
+
const scoped =
|
|
184
|
+
projectID === undefined
|
|
185
|
+
? sessions
|
|
186
|
+
: sessions.filter((entry) => asText(asRecord(entry)?.["projectID"]) === projectID);
|
|
187
|
+
|
|
151
188
|
let cost = 0;
|
|
152
|
-
for (const entry of
|
|
153
|
-
return { cost, count:
|
|
189
|
+
for (const entry of scoped) cost += asCount(asRecord(entry)?.["cost"]) ?? 0;
|
|
190
|
+
return { cost, count: scoped.length };
|
|
154
191
|
} catch {
|
|
155
192
|
return undefined;
|
|
156
193
|
}
|
|
@@ -299,7 +336,9 @@ export default Plugin.define({
|
|
|
299
336
|
if (output === undefined) continue;
|
|
300
337
|
sizes.push(output);
|
|
301
338
|
}
|
|
302
|
-
|
|
339
|
+
// Windowed by the configured width, not a hardcoded one: `sparkWidth` is
|
|
340
|
+
// capped here first, so a wider setting used to be silently impossible.
|
|
341
|
+
return sizes.slice(-config.layout.sparkWidth);
|
|
303
342
|
};
|
|
304
343
|
|
|
305
344
|
// A ticker exists only for clock-derived rows; everything else updates from
|
|
@@ -327,18 +366,41 @@ export default Plugin.define({
|
|
|
327
366
|
return top === undefined ? undefined : cautionText(top, config.glyphs);
|
|
328
367
|
};
|
|
329
368
|
|
|
369
|
+
// Both of these are host lookups like any other, and the slot render must
|
|
370
|
+
// not throw: an unreachable default location, or a VCS call on a directory
|
|
371
|
+
// with no repository, would take the whole rail down with it. Each degrades
|
|
372
|
+
// to "no branch row", the same way every other missing value does.
|
|
373
|
+
const locationOf = () => {
|
|
374
|
+
try {
|
|
375
|
+
return context.location ?? context.data.location.default();
|
|
376
|
+
} catch {
|
|
377
|
+
return context.location;
|
|
378
|
+
}
|
|
379
|
+
};
|
|
380
|
+
|
|
381
|
+
const branchOf = (location: ReturnType<typeof locationOf>): string | undefined => {
|
|
382
|
+
try {
|
|
383
|
+
return context.data.location.vcs.info(location)?.branch?.current;
|
|
384
|
+
} catch {
|
|
385
|
+
return undefined;
|
|
386
|
+
}
|
|
387
|
+
};
|
|
388
|
+
|
|
330
389
|
const snapshot = (sessionID: string): StatSource => {
|
|
331
|
-
const location =
|
|
390
|
+
const location = locationOf();
|
|
332
391
|
const session = context.data.session.get(sessionID) as SessionLike | undefined;
|
|
333
|
-
|
|
392
|
+
// A "turn" is one prompt and the work it caused. The host's message list
|
|
393
|
+
// also carries system, shell and switch records, so counting records
|
|
394
|
+
// reports several times the turns actually taken.
|
|
395
|
+
const turns = messagesOf(sessionID).filter((entry) => asRecord(entry)?.["type"] === "user").length;
|
|
334
396
|
|
|
335
397
|
return {
|
|
336
398
|
...session,
|
|
337
399
|
caution: announce(sessionID),
|
|
338
|
-
branch:
|
|
400
|
+
branch: branchOf(location),
|
|
339
401
|
tree: treeTotals(sessionID, session?.cost),
|
|
340
402
|
context: contextUsage(sessionID, session?.model),
|
|
341
|
-
project: projectTotals(),
|
|
403
|
+
project: projectTotals(sessionID),
|
|
342
404
|
status: statusOf(sessionID),
|
|
343
405
|
busy: busy(sessionID),
|
|
344
406
|
perms: permsOf(sessionID),
|
package/src/tui/stats.ts
CHANGED
|
@@ -16,13 +16,16 @@ export interface StatTree {
|
|
|
16
16
|
|
|
17
17
|
/** Context-window occupancy for the most recent request. */
|
|
18
18
|
export interface StatContext {
|
|
19
|
-
/**
|
|
19
|
+
/**
|
|
20
|
+
* Prompt tokens sent on the last request: input, cache reads, and cache
|
|
21
|
+
* writes. All three occupy the window, so all three count.
|
|
22
|
+
*/
|
|
20
23
|
readonly used?: unknown;
|
|
21
24
|
/** The model's context window, when the catalog knows it. */
|
|
22
25
|
readonly limit?: unknown;
|
|
23
26
|
}
|
|
24
27
|
|
|
25
|
-
/** Whole-project spend, across every session in this
|
|
28
|
+
/** Whole-project spend, across every session in this project. */
|
|
26
29
|
export interface StatProject {
|
|
27
30
|
readonly cost?: unknown;
|
|
28
31
|
readonly count?: unknown;
|
|
@@ -142,7 +145,11 @@ function asCount(value: unknown): number | undefined {
|
|
|
142
145
|
/** `518k`, `29.2M`, `32M`, `940` — short enough for a narrow rail, precise enough to read. */
|
|
143
146
|
export function formatCount(value: number): string {
|
|
144
147
|
if (value < 1_000) return String(Math.round(value));
|
|
145
|
-
|
|
148
|
+
// Round *before* choosing the unit. Rounding only inside the `k` branch made
|
|
149
|
+
// anything from 999,500 to 999,999 print as `1000k` — a number with two
|
|
150
|
+
// magnitudes in it, and one an agent reads as a different size entirely.
|
|
151
|
+
const thousands = Math.round(value / 1_000);
|
|
152
|
+
if (thousands < 1_000) return `${thousands}k`;
|
|
146
153
|
const millions = (value / 1_000_000).toFixed(1);
|
|
147
154
|
return `${millions.endsWith(".0") ? millions.slice(0, -2) : millions}M`;
|
|
148
155
|
}
|
|
@@ -180,12 +187,34 @@ const SPARK_LEVELS = ["▁", "▂", "▃", "▄", "▅", "▆", "▇", "█"] as
|
|
|
180
187
|
* truncated path reads as a complete one.
|
|
181
188
|
*/
|
|
182
189
|
export function clip(text: string, max: number): string {
|
|
183
|
-
|
|
190
|
+
if (text.length <= max) return text;
|
|
191
|
+
const cut = text.slice(0, Math.max(1, max - 1));
|
|
192
|
+
// Never cut a surrogate pair in half: the orphaned half renders as a
|
|
193
|
+
// replacement character, which reads as corruption rather than as a shortened
|
|
194
|
+
// path. Losing one more column is the cheaper mistake.
|
|
195
|
+
const safe = /[\uD800-\uDBFF]$/.test(cut) ? cut.slice(0, -1) : cut;
|
|
196
|
+
return `${safe}…`;
|
|
184
197
|
}
|
|
185
198
|
|
|
186
199
|
/** Braille frames, advanced by the ticker, shown only while the session runs. */
|
|
187
200
|
const SPINNER = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"] as const;
|
|
188
201
|
|
|
202
|
+
/**
|
|
203
|
+
* Flatten control characters in anything about to be drawn.
|
|
204
|
+
*
|
|
205
|
+
* A rail is one line per row, so a newline or an escape sequence in a
|
|
206
|
+
* host-supplied string does not get seen — it moves the cursor. Config text is
|
|
207
|
+
* already flattened in ./config.ts, but a tool name, a permission resource or a
|
|
208
|
+
* branch name arrives straight from the host, so every row value passes through
|
|
209
|
+
* here on its way out. `replace` is unconditional rather than `test` + `replace`:
|
|
210
|
+
* a global regex used with `test` carries `lastIndex` between calls.
|
|
211
|
+
*/
|
|
212
|
+
const CONTROL_CHARS = /[\u0000-\u001F\u007F-\u009F]/g;
|
|
213
|
+
|
|
214
|
+
function plain(value: string): string {
|
|
215
|
+
return value.replace(CONTROL_CHARS, " ");
|
|
216
|
+
}
|
|
217
|
+
|
|
189
218
|
/**
|
|
190
219
|
* Recent turn sizes as a shape.
|
|
191
220
|
*
|
|
@@ -228,7 +257,7 @@ export function statLine(
|
|
|
228
257
|
// value: at labelWidth 8 the `reasoning` row rendered as "reasoning153k".
|
|
229
258
|
// The label is nine characters, which made this reachable from a config file.
|
|
230
259
|
const row = (label: string, value: string): string =>
|
|
231
|
-
`${label.padEnd(labelWidth)}${label.length >= labelWidth ? " " : ""}${value}`;
|
|
260
|
+
`${label.padEnd(labelWidth)}${label.length >= labelWidth ? " " : ""}${plain(value)}`;
|
|
232
261
|
|
|
233
262
|
switch (field) {
|
|
234
263
|
case "caution": {
|