@ftrdotdev/pi-tui 0.8.0 → 0.9.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 +225 -0
- package/README.md +5 -0
- package/package.json +18 -15
- package/src/activity-service.test.ts +97 -0
- package/src/activity.test.ts +1 -1
- package/src/activity.ts +38 -0
- package/src/chrome/budget.test.ts +345 -0
- package/src/chrome/budget.ts +220 -0
- package/src/chrome/declarations.ts +303 -0
- package/src/chrome/facts.test.ts +165 -0
- package/src/chrome/facts.ts +267 -0
- package/src/chrome/frame.ts +45 -0
- package/src/chrome/laws.test.ts +231 -0
- package/src/chrome/port.test.ts +164 -0
- package/src/chrome/port.ts +67 -0
- package/src/chrome/service-provider.test.ts +383 -0
- package/src/chrome/service-provider.ts +55 -0
- package/src/commands/git-execution.test.ts +5 -2
- package/src/commands/git-execution.ts +27 -15
- package/src/commands/git-status.test.ts +47 -15
- package/src/commands/git-status.ts +83 -31
- package/src/components/bordered-box.test.ts +12 -15
- package/src/components/bordered-box.ts +11 -7
- package/src/components/define-component.ts +1 -1
- package/src/components/index.ts +7 -0
- package/src/components/row-list.test.ts +310 -0
- package/src/components/row-list.ts +272 -0
- package/src/config.test.ts +118 -3
- package/src/config.ts +46 -40
- package/src/frame/box-frame.test.ts +53 -7
- package/src/harness-policy.test.ts +47 -0
- package/src/icons.test.ts +19 -0
- package/src/icons.ts +50 -31
- package/src/index.test.ts +135 -0
- package/src/index.ts +118 -119
- package/src/layers.test.ts +94 -0
- package/src/layers.ts +92 -0
- package/src/runtime-service.test.ts +218 -0
- package/src/runtime-service.ts +103 -0
- package/src/runtime.test.ts +165 -66
- package/src/runtime.ts +127 -93
- package/src/session-lifecycle-service.test.ts +95 -0
- package/src/session-lifecycle.test.ts +77 -0
- package/src/session-lifecycle.ts +21 -0
- package/src/state.test.ts +132 -3
- package/src/state.ts +43 -13
- package/src/telemetry-service.test.ts +250 -0
- package/src/telemetry.test.ts +322 -0
- package/src/telemetry.ts +130 -23
- package/src/ui/editor-tint.test.ts +58 -45
- package/src/ui/editor-tint.ts +1 -1
- package/src/ui/editor.ts +117 -53
- package/src/ui/footer.test.ts +349 -120
- package/src/ui/footer.ts +147 -124
- package/src/ui/header.test.ts +203 -223
- package/src/ui/header.ts +32 -96
- package/src/ui/preview.test.ts +73 -70
- package/src/ui/preview.ts +48 -33
- package/src/ui/render-helpers.test.ts +82 -13
- package/src/ui/render-helpers.ts +110 -122
- package/src/ui/settings-command.test.ts +70 -11
- package/src/ui/settings-command.ts +30 -45
- package/src/ui/theme-color.test.ts +4 -3
- package/src/usage-totals-service.test.ts +230 -0
- package/src/usage-totals-service.ts +59 -0
- package/src/utils.test.ts +46 -50
- package/src/utils.ts +41 -239
- package/src/vim/editor-host.test.ts +201 -75
- package/src/vim/editor-state.ts +2 -2
- package/src/vim/mode-indicator.test.ts +6 -5
- package/src/vim/mode-indicator.ts +13 -9
- package/src/vim/selection-render.ts +8 -4
- package/src/vim/text-model.test.ts +52 -14
- package/src/vim/text-model.ts +1 -1
- package/src/vim/vim-router.test.ts +3 -0
- package/src/vim/vim-router.ts +1 -1
package/src/ui/render-helpers.ts
CHANGED
|
@@ -6,23 +6,23 @@
|
|
|
6
6
|
// so a moved-but-changed helper cannot ship.
|
|
7
7
|
|
|
8
8
|
import type { ExtensionContext, Theme, ThemeColor } from "@earendil-works/pi-coding-agent";
|
|
9
|
-
import {
|
|
9
|
+
import { wrapTextWithAnsi } from "@earendil-works/pi-tui";
|
|
10
10
|
import type { TuiConfig } from "../config.ts";
|
|
11
11
|
import type { IconGlyphs } from "../icons.ts";
|
|
12
|
-
import {
|
|
12
|
+
import { resolveBarCells, runtimeSymbol } from "../icons.ts";
|
|
13
13
|
import type { GitStatus } from "../commands/git-status.ts";
|
|
14
14
|
import type { RuntimeInfo } from "../runtime.ts";
|
|
15
|
+
import type { ActivityTracker } from "../activity.ts";
|
|
15
16
|
import {
|
|
16
|
-
cacheHitColor,
|
|
17
17
|
fmtTokens,
|
|
18
18
|
formatCost,
|
|
19
19
|
formatDuration,
|
|
20
|
-
|
|
20
|
+
isNonEmptyString,
|
|
21
21
|
sanitizeStatus,
|
|
22
22
|
stressColor,
|
|
23
23
|
truncatePath,
|
|
24
24
|
} from "../utils.ts";
|
|
25
|
-
import type {
|
|
25
|
+
import type { UsageTotals } from "../state.ts";
|
|
26
26
|
|
|
27
27
|
// ---------------------------------------------------------------------------
|
|
28
28
|
// Header leaves (relocated verbatim from header.ts, Slice 1)
|
|
@@ -63,99 +63,98 @@ export function renderLogo(paint: (text: string) => string): string[] {
|
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
/**
|
|
66
|
-
*
|
|
67
|
-
* column separator, and the right cell padded to `rightWidth` (with `…`
|
|
68
|
-
* when the right cell overflows).
|
|
69
|
-
*/
|
|
70
|
-
export function twoColumn(
|
|
71
|
-
left: string,
|
|
72
|
-
right: string,
|
|
73
|
-
leftWidth: number,
|
|
74
|
-
rightWidth: number,
|
|
75
|
-
paint: (text: string) => string,
|
|
76
|
-
): string {
|
|
77
|
-
return `${padRight(left, leftWidth)} ${paint("│")} ${padRight(right, rightWidth, "…")}`;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
// ---------------------------------------------------------------------------
|
|
81
|
-
// Footer leaves (relocated verbatim from footer.ts, Slice 3)
|
|
82
|
-
// ---------------------------------------------------------------------------
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* A context-usage bar segment: `[####----]` (ascii) or `[████░░░░]`
|
|
66
|
+
* A context-usage bar segment: `[▮▮▮▮▯▯▯▯]` (ascii) or `[████░░░░]`
|
|
86
67
|
* (nerd) with the filled fraction colored by `stressColor`, framed by
|
|
87
|
-
* dim brackets.
|
|
68
|
+
* dim brackets. The cells come from the icon table so a mode change is one
|
|
69
|
+
* edit and the one-column law covers them.
|
|
88
70
|
*/
|
|
89
|
-
export function renderBar(
|
|
71
|
+
export function renderBar(
|
|
72
|
+
theme: Theme,
|
|
73
|
+
pct: number,
|
|
74
|
+
barWidth: number,
|
|
75
|
+
mode: TuiConfig["icons"]["mode"],
|
|
76
|
+
): string {
|
|
90
77
|
const filled = Math.max(0, Math.min(barWidth, Math.round((pct / 100) * barWidth)));
|
|
91
78
|
const empty = barWidth - filled;
|
|
92
79
|
const color = stressColor(pct);
|
|
93
|
-
const
|
|
94
|
-
const emptyCell = ascii ? "-" : "░";
|
|
80
|
+
const cells = resolveBarCells(mode);
|
|
95
81
|
return (
|
|
96
82
|
theme.fg("dim", "[") +
|
|
97
|
-
theme.fg(color,
|
|
98
|
-
theme.fg("dim",
|
|
83
|
+
theme.fg(color, cells.filled.repeat(filled)) +
|
|
84
|
+
theme.fg("dim", cells.empty.repeat(empty)) +
|
|
99
85
|
theme.fg("dim", "]")
|
|
100
86
|
);
|
|
101
87
|
}
|
|
102
88
|
|
|
103
89
|
/**
|
|
104
|
-
* The git
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
* `""` so the caller drops the segment.
|
|
90
|
+
* The git branch segment: branch (or detached HEAD) and, when enabled, the
|
|
91
|
+
* commit's untracked part. Each fact is its own leaf so the footer's
|
|
92
|
+
* declarations can fit and drop them independently.
|
|
108
93
|
*/
|
|
109
|
-
export function
|
|
94
|
+
export function renderGitBranchSegment(
|
|
110
95
|
theme: Theme,
|
|
111
96
|
git: GitStatus,
|
|
112
97
|
glyphs: IconGlyphs,
|
|
113
98
|
segments: TuiConfig["footerSegments"],
|
|
114
99
|
maxBranchLen = 20,
|
|
115
100
|
): string {
|
|
116
|
-
|
|
117
|
-
if (
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
parts.push(theme.fg("warning", glyphs.git));
|
|
123
|
-
parts.push(theme.fg("warning", "HEAD"));
|
|
124
|
-
if (git.commit.oid) {
|
|
125
|
-
const shortHash = git.commit.oid.slice(0, 7);
|
|
126
|
-
const tag = git.commit.tag ? ` ${git.commit.tag}` : "";
|
|
127
|
-
parts.push(theme.fg("dim", `${shortHash}${tag}`));
|
|
128
|
-
}
|
|
129
|
-
}
|
|
101
|
+
if (!segments.gitBranch) return "";
|
|
102
|
+
if (isNonEmptyString(git.branch)) {
|
|
103
|
+
return `${theme.fg("mdLink", glyphs.git)} ${theme.fg("mdLink", truncatePath(git.branch, maxBranchLen))}`;
|
|
104
|
+
}
|
|
105
|
+
if (git.commit?.detached ?? false) {
|
|
106
|
+
return `${theme.fg("warning", glyphs.git)} ${theme.fg("warning", "HEAD")}`;
|
|
130
107
|
}
|
|
108
|
+
return "";
|
|
109
|
+
}
|
|
131
110
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
111
|
+
/** The detached commit's short hash and tag, or `""` when not detached. */
|
|
112
|
+
export function renderGitCommitSegment(
|
|
113
|
+
theme: Theme,
|
|
114
|
+
git: GitStatus,
|
|
115
|
+
segments: TuiConfig["footerSegments"],
|
|
116
|
+
): string {
|
|
117
|
+
if (!segments.gitCommit || git.commit === null) return "";
|
|
118
|
+
if (!(git.commit.detached ?? false) || git.commit.oid === null || git.commit.oid === "")
|
|
119
|
+
return "";
|
|
120
|
+
const shortHash = git.commit.oid.slice(0, 7);
|
|
121
|
+
const tag = git.commit.tag !== null && git.commit.tag !== "" ? ` ${git.commit.tag}` : "";
|
|
122
|
+
return theme.fg("dim", `${shortHash}${tag}`);
|
|
123
|
+
}
|
|
144
124
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
125
|
+
/**
|
|
126
|
+
* The git status block: the bracketed counts (`[!3 A2 ?1 S1 ^v2/1]`), each
|
|
127
|
+
* count gated by its `footerSegments` flag. Returns `""` when empty.
|
|
128
|
+
*/
|
|
129
|
+
export function renderGitStatusSegment(
|
|
130
|
+
theme: Theme,
|
|
131
|
+
git: GitStatus,
|
|
132
|
+
glyphs: IconGlyphs,
|
|
133
|
+
segments: TuiConfig["footerSegments"],
|
|
134
|
+
): string {
|
|
135
|
+
if (!segments.gitStatus) return "";
|
|
136
|
+
const statusIcons: string[] = [];
|
|
137
|
+
const addStatus = (count: number, glyph: string, color: ThemeColor) => {
|
|
138
|
+
if (count > 0) statusIcons.push(theme.fg(color, `${glyph}${count}`));
|
|
139
|
+
};
|
|
140
|
+
addStatus(git.conflicted, glyphs.conflicted, "error");
|
|
141
|
+
addStatus(git.deleted, glyphs.deleted, "error");
|
|
142
|
+
addStatus(git.modified, glyphs.modified, "warning");
|
|
143
|
+
addStatus(git.renamed, glyphs.renamed, "warning");
|
|
144
|
+
addStatus(git.staged, glyphs.staged, "success");
|
|
145
|
+
addStatus(git.untracked, glyphs.untracked, "muted");
|
|
146
|
+
addStatus(git.stashed, glyphs.stashed, "muted");
|
|
151
147
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
}
|
|
148
|
+
if (git.ahead > 0 && git.behind > 0) {
|
|
149
|
+
statusIcons.push(theme.fg("warning", `${glyphs.diverged}${git.ahead}/${git.behind}`));
|
|
150
|
+
} else if (git.ahead > 0) {
|
|
151
|
+
statusIcons.push(theme.fg("success", `${glyphs.ahead}${git.ahead}`));
|
|
152
|
+
statusIcons.push(theme.fg("warning", `${glyphs.behind}${git.behind}`));
|
|
156
153
|
}
|
|
157
154
|
|
|
158
|
-
|
|
155
|
+
const statusBlock = statusIcons.join(" ");
|
|
156
|
+
if (statusBlock === "") return "";
|
|
157
|
+
return `${theme.fg("dim", "[")}${statusBlock}${theme.fg("dim", "]")}`;
|
|
159
158
|
}
|
|
160
159
|
|
|
161
160
|
/**
|
|
@@ -171,7 +170,7 @@ export function renderRuntimeSegment(
|
|
|
171
170
|
return runtimes
|
|
172
171
|
.map((runtime) => {
|
|
173
172
|
const symbol = theme.fg("success", runtimeSymbol(runtime.name, iconMode));
|
|
174
|
-
const version = runtime.version ? theme.fg("muted", runtime.version) : "";
|
|
173
|
+
const version = isNonEmptyString(runtime.version) ? theme.fg("muted", runtime.version) : "";
|
|
175
174
|
return [symbol, version].filter(Boolean).join(" ");
|
|
176
175
|
})
|
|
177
176
|
.join(theme.fg("dim", " · "));
|
|
@@ -216,27 +215,28 @@ function renderSplit(theme: Theme, glyphs: IconGlyphs, inference: number, tool:
|
|
|
216
215
|
*/
|
|
217
216
|
export function renderTimerSegment(
|
|
218
217
|
theme: Theme,
|
|
219
|
-
|
|
218
|
+
tracker: ActivityTracker,
|
|
219
|
+
lastDoneIn: number | undefined,
|
|
220
220
|
glyphs: IconGlyphs,
|
|
221
221
|
now: number = Date.now(),
|
|
222
222
|
): TimerSegmentParts | undefined {
|
|
223
|
-
if (
|
|
224
|
-
if (
|
|
223
|
+
if (tracker.isRunOpen()) {
|
|
224
|
+
if (tracker.isWaiting()) {
|
|
225
225
|
return {
|
|
226
|
-
total: `${theme.fg("warning", glyphs.working)} ${theme.fg("warning",
|
|
226
|
+
total: `${theme.fg("warning", glyphs.working)} ${theme.fg("warning", formatDuration(tracker.waitingMs(now)))}`,
|
|
227
227
|
split: "",
|
|
228
228
|
};
|
|
229
229
|
}
|
|
230
|
-
const active =
|
|
230
|
+
const active = tracker.breakdown(now);
|
|
231
231
|
return {
|
|
232
|
-
total: `${theme.fg("accent", glyphs.working)} ${theme.fg("
|
|
232
|
+
total: `${theme.fg("accent", glyphs.working)} ${theme.fg("accent", formatDuration(active.total - active.wait))}`,
|
|
233
233
|
split: renderSplit(theme, glyphs, active.inference, active.tool),
|
|
234
234
|
};
|
|
235
235
|
}
|
|
236
|
-
if (
|
|
237
|
-
const done =
|
|
236
|
+
if (lastDoneIn !== undefined) {
|
|
237
|
+
const done = tracker.breakdown(now);
|
|
238
238
|
return {
|
|
239
|
-
total: `${theme.fg("success", glyphs.done)} ${theme.fg("
|
|
239
|
+
total: `${theme.fg("success", glyphs.done)} ${theme.fg("text", formatDuration(lastDoneIn))}`,
|
|
240
240
|
split: renderSplit(theme, glyphs, done.inference, done.tool),
|
|
241
241
|
};
|
|
242
242
|
}
|
|
@@ -244,67 +244,55 @@ export function renderTimerSegment(
|
|
|
244
244
|
}
|
|
245
245
|
|
|
246
246
|
/**
|
|
247
|
-
* The context-usage footer segment:
|
|
248
|
-
*
|
|
249
|
-
*
|
|
247
|
+
* The context-usage footer segment: the context glyph and `tokens/window`.
|
|
248
|
+
* Returns `""` when the window is unknown (empty session) so the caller drops
|
|
249
|
+
* it. The percentage and bar are deliberately omitted: the ratio is the fact.
|
|
250
250
|
*/
|
|
251
251
|
export function renderContextBar(
|
|
252
252
|
theme: Theme,
|
|
253
|
-
|
|
254
|
-
width: number,
|
|
253
|
+
contextUsage: ReturnType<ExtensionContext["getContextUsage"]>,
|
|
255
254
|
glyphs: IconGlyphs,
|
|
256
|
-
iconMode: TuiConfig["icons"]["mode"],
|
|
257
255
|
): string {
|
|
258
|
-
const
|
|
259
|
-
const
|
|
260
|
-
const contextTokens = contextUsage?.tokens ?? 0;
|
|
256
|
+
const contextWindow = contextUsage?.contextWindow ?? 0;
|
|
257
|
+
const contextTokens = contextUsage?.tokens;
|
|
261
258
|
const contextPct = contextUsage?.percent ?? 0;
|
|
262
259
|
|
|
263
260
|
// populated instead of collapsing everything left in an empty session.
|
|
264
261
|
if (contextWindow <= 0) return "";
|
|
265
262
|
|
|
266
|
-
const
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
const reserved =
|
|
270
|
-
visibleWidth(contextIcon) + visibleWidth(pctText) + visibleWidth(ctxText) + 5 + 2;
|
|
271
|
-
const barWidth = Math.max(4, Math.min(12, width - reserved));
|
|
272
|
-
return `${contextIcon} ${renderBar(theme, contextPct, barWidth, resolveIconMode(iconMode) === "ascii")} ${pctText} ${theme.fg("dim", "·")} ${ctxText}`;
|
|
263
|
+
const tokenText =
|
|
264
|
+
contextTokens === null || contextTokens === undefined ? "—" : fmtTokens(contextTokens);
|
|
265
|
+
return `${theme.fg(stressColor(contextPct), glyphs.context)} ${theme.fg("text", tokenText)}${theme.fg("dim", "/")}${theme.fg("text", fmtTokens(contextWindow))}`;
|
|
273
266
|
}
|
|
274
267
|
|
|
275
268
|
/**
|
|
276
|
-
* Token
|
|
277
|
-
* `footerSegments` flag and joined with dim pipes. The cache-hit % is
|
|
278
|
-
* shown only when the provider reports cache tokens.
|
|
269
|
+
* Token totals (`↑ 2.4k | ↓ 800`), gated by the `tokens` flag. `""` when off.
|
|
279
270
|
*/
|
|
280
|
-
export function
|
|
271
|
+
export function renderTokenCountsSegment(
|
|
281
272
|
theme: Theme,
|
|
282
273
|
totals: UsageTotals,
|
|
283
274
|
glyphs: IconGlyphs,
|
|
284
275
|
segments: TuiConfig["footerSegments"],
|
|
285
276
|
): string {
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
const hasCacheTokens = totals.cacheRead > 0 || totals.cacheWrite > 0;
|
|
292
|
-
if (hasCacheTokens && totals.latestCacheHitRate !== undefined) {
|
|
293
|
-
stats.push(
|
|
294
|
-
theme.fg(
|
|
295
|
-
cacheHitColor(totals.latestCacheHitRate),
|
|
296
|
-
`${glyphs.cacheHit} ${totals.latestCacheHitRate.toFixed(1)}%`,
|
|
297
|
-
),
|
|
298
|
-
);
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
if (segments.cost) {
|
|
302
|
-
stats.push(theme.fg("warning", formatCost(glyphs.cost, totals.cost)));
|
|
303
|
-
}
|
|
304
|
-
|
|
277
|
+
if (!segments.tokens) return "";
|
|
278
|
+
const stats = [
|
|
279
|
+
theme.fg("accent", `${glyphs.input} ${fmtTokens(totals.input)}`),
|
|
280
|
+
theme.fg("success", `${glyphs.output} ${fmtTokens(totals.output)}`),
|
|
281
|
+
];
|
|
305
282
|
return stats.join(` ${theme.fg("dim", "|")} `);
|
|
306
283
|
}
|
|
307
284
|
|
|
285
|
+
/** The session cost (`$ 0.084`), gated by the `cost` flag. `""` when off. */
|
|
286
|
+
export function renderCostSegment(
|
|
287
|
+
theme: Theme,
|
|
288
|
+
totals: UsageTotals,
|
|
289
|
+
glyphs: IconGlyphs,
|
|
290
|
+
segments: TuiConfig["footerSegments"],
|
|
291
|
+
): string {
|
|
292
|
+
if (!segments.cost) return "";
|
|
293
|
+
return theme.fg("warning", formatCost(glyphs.cost, totals.cost));
|
|
294
|
+
}
|
|
295
|
+
|
|
308
296
|
/**
|
|
309
297
|
* Extension status lines (sorted by key, sanitized, wrapped to `width`),
|
|
310
298
|
* prefixed with the extensions glyph. Returns `[]` when there are no
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { assert, it } from "@effect/vitest";
|
|
2
|
+
import { themeDouble } from "@ftrdotdev/pi-test-kit";
|
|
2
3
|
import { Effect } from "effect";
|
|
3
|
-
import type { Theme } from "@earendil-works/pi-coding-agent";
|
|
4
4
|
import { DEFAULT_CONFIG, type TuiConfig } from "../config.ts";
|
|
5
5
|
import { VimRouter } from "../vim/vim-router.ts";
|
|
6
6
|
import {
|
|
@@ -15,20 +15,16 @@ import {
|
|
|
15
15
|
|
|
16
16
|
// Pass-through theme: selections and the active tab are detected via
|
|
17
17
|
// plain-text markers ("→ " prefix, "[Tab]" brackets) in the render output.
|
|
18
|
-
const theme =
|
|
19
|
-
fg: (_color: string, text: string) => text,
|
|
20
|
-
bg: (_color: string, text: string) => text,
|
|
21
|
-
bold: (text: string) => text,
|
|
22
|
-
style: (text: string) => text,
|
|
23
|
-
} as unknown as Theme;
|
|
18
|
+
const theme = themeDouble();
|
|
24
19
|
|
|
25
20
|
const RENDER_WIDTH = 120;
|
|
26
21
|
|
|
27
22
|
// The settings UI injects an always-true gate for its own router instance
|
|
28
23
|
// (per-consumer gate injection), so its h/j/k/l stay unconditional regardless
|
|
29
24
|
// of the vim toggle.
|
|
30
|
-
const settingsRouter = Effect.
|
|
31
|
-
Effect.
|
|
25
|
+
const settingsRouter = await Effect.service(VimRouter).pipe(
|
|
26
|
+
Effect.provide(VimRouter.make(() => true)),
|
|
27
|
+
Effect.runPromise,
|
|
32
28
|
);
|
|
33
29
|
|
|
34
30
|
interface UiSpy {
|
|
@@ -65,14 +61,14 @@ const makeUi = (
|
|
|
65
61
|
return spy;
|
|
66
62
|
};
|
|
67
63
|
|
|
68
|
-
const rendered = (ui: SettingsUiHandle): string[] => ui.render(RENDER_WIDTH);
|
|
64
|
+
const rendered = (ui: SettingsUiHandle): readonly string[] => ui.render(RENDER_WIDTH);
|
|
69
65
|
|
|
70
66
|
const selectedShows = (ui: SettingsUiHandle, label: string): boolean =>
|
|
71
67
|
rendered(ui).some((line) => line.includes(`→ ${label}`));
|
|
72
68
|
|
|
73
69
|
const activeTab = (ui: SettingsUiHandle): string | undefined => {
|
|
74
70
|
const line = rendered(ui).find((l) => l.includes("["));
|
|
75
|
-
if (
|
|
71
|
+
if (line === undefined || line === "") return undefined;
|
|
76
72
|
for (const tab of ["General", "Compaction", "Icons", "Footer", "Telemetry"] as const) {
|
|
77
73
|
if (line.includes(`[${tab}]`)) return tab;
|
|
78
74
|
}
|
|
@@ -224,6 +220,69 @@ it("j and k work on tabs with more items than fit the visible list", () => {
|
|
|
224
220
|
assert.strictEqual(selectedShows(ui, "CWD"), true);
|
|
225
221
|
});
|
|
226
222
|
|
|
223
|
+
const FOOTER_LABELS = [
|
|
224
|
+
"CWD",
|
|
225
|
+
"Git branch",
|
|
226
|
+
"Git status",
|
|
227
|
+
"Git commit (detached)",
|
|
228
|
+
"Runtime",
|
|
229
|
+
"Context usage",
|
|
230
|
+
"Tokens",
|
|
231
|
+
"Cost",
|
|
232
|
+
"Extension status line",
|
|
233
|
+
] as const;
|
|
234
|
+
|
|
235
|
+
const TELEMETRY_LABELS = [
|
|
236
|
+
"Enabled",
|
|
237
|
+
"TPS",
|
|
238
|
+
"TTFT",
|
|
239
|
+
"Total duration",
|
|
240
|
+
"Token counts",
|
|
241
|
+
"Stall details",
|
|
242
|
+
"Cost rate",
|
|
243
|
+
] as const;
|
|
244
|
+
|
|
245
|
+
/** Switch to a tab by pressing `l` `times` times. */
|
|
246
|
+
const goToTab = (ui: SettingsUiHandle, times: number): void => {
|
|
247
|
+
for (let i = 0; i < times; i++) ui.handleInput("l");
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
/** Walk the current tab's rows and assert the labels appear in this order. */
|
|
251
|
+
const assertLabelOrder = (ui: SettingsUiHandle, labels: readonly string[]): void => {
|
|
252
|
+
labels.forEach((label, index) => {
|
|
253
|
+
if (index > 0) ui.handleInput("j");
|
|
254
|
+
assert.strictEqual(selectedShows(ui, label), true, `${label} at position ${index}`);
|
|
255
|
+
});
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
it("the Footer rows come from the registry, with unchanged labels", () => {
|
|
259
|
+
const { ui } = makeUi();
|
|
260
|
+
goToTab(ui, 3);
|
|
261
|
+
assert.strictEqual(activeTab(ui), "Footer");
|
|
262
|
+
assertLabelOrder(ui, FOOTER_LABELS);
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
it("the Telemetry rows come from the registry, with unchanged labels", () => {
|
|
266
|
+
const { ui } = makeUi();
|
|
267
|
+
goToTab(ui, 4);
|
|
268
|
+
assert.strictEqual(activeTab(ui), "Telemetry");
|
|
269
|
+
assertLabelOrder(ui, TELEMETRY_LABELS);
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
it("/tui toggles a fact-scoped key from the new default", () => {
|
|
273
|
+
const { ui, changes } = makeUi();
|
|
274
|
+
goToTab(ui, 3);
|
|
275
|
+
for (let i = 0; i < 4; i++) ui.handleInput("j"); // CWD → Runtime
|
|
276
|
+
assert.strictEqual(selectedShows(ui, "Runtime"), true);
|
|
277
|
+
ui.handleInput(" ");
|
|
278
|
+
assert.strictEqual(changes.length, 1);
|
|
279
|
+
assert.strictEqual(changes[0]!.footerSegments.runtime, true);
|
|
280
|
+
assert.deepStrictEqual(
|
|
281
|
+
{ ...changes[0]!.footerSegments, runtime: false },
|
|
282
|
+
DEFAULT_CONFIG.footerSegments,
|
|
283
|
+
);
|
|
284
|
+
});
|
|
285
|
+
|
|
227
286
|
it("q and Escape close the settings UI", () => {
|
|
228
287
|
const spy = makeUi();
|
|
229
288
|
spy.ui.handleInput("q");
|
|
@@ -19,6 +19,7 @@ import {
|
|
|
19
19
|
type SettingsLanguage,
|
|
20
20
|
} from "../config.ts";
|
|
21
21
|
import { VimRouter } from "../vim/vim-router.ts";
|
|
22
|
+
import { factsFor, flagOf } from "../chrome/facts.ts";
|
|
22
23
|
|
|
23
24
|
interface SettingItem {
|
|
24
25
|
id: string;
|
|
@@ -54,19 +55,6 @@ const COPY = {
|
|
|
54
55
|
vim: "Vim mode",
|
|
55
56
|
language: "Language",
|
|
56
57
|
iconMode: "Icon mode",
|
|
57
|
-
cwd: "CWD",
|
|
58
|
-
gitBranch: "Git branch",
|
|
59
|
-
gitStatus: "Git status",
|
|
60
|
-
gitCommit: "Git commit (detached)",
|
|
61
|
-
runtime: "Runtime",
|
|
62
|
-
context: "Context bar",
|
|
63
|
-
tokens: "Tokens",
|
|
64
|
-
cost: "Cost",
|
|
65
|
-
extensionStatuses: "Extension status line",
|
|
66
|
-
totalDuration: "Total duration",
|
|
67
|
-
tokenCounts: "Token counts",
|
|
68
|
-
stallDetails: "Stall details",
|
|
69
|
-
costRate: "Cost rate",
|
|
70
58
|
smartCompactionEnabled: "Smart compaction",
|
|
71
59
|
smartCompactionClassifier: "Compaction classifier",
|
|
72
60
|
smartCompactionNeedsContextProbability: "Needs-context probability",
|
|
@@ -275,39 +263,34 @@ function buildIconsItems(config: TuiConfig, copy: SettingsCopy): SettingItem[] {
|
|
|
275
263
|
}
|
|
276
264
|
|
|
277
265
|
function buildSegmentsItems(config: TuiConfig, copy: SettingsCopy): SettingItem[] {
|
|
278
|
-
|
|
279
|
-
const flag = (value: boolean) => (value ? copy.values.on : copy.values.off);
|
|
280
|
-
return [
|
|
281
|
-
{ id: "cwd", label: copy.labels.cwd, currentValue: flag(segs.cwd) },
|
|
282
|
-
{ id: "gitBranch", label: copy.labels.gitBranch, currentValue: flag(segs.gitBranch) },
|
|
283
|
-
{ id: "gitStatus", label: copy.labels.gitStatus, currentValue: flag(segs.gitStatus) },
|
|
284
|
-
{ id: "gitCommit", label: copy.labels.gitCommit, currentValue: flag(segs.gitCommit) },
|
|
285
|
-
{ id: "runtime", label: copy.labels.runtime, currentValue: flag(segs.runtime) },
|
|
286
|
-
{ id: "context", label: copy.labels.context, currentValue: flag(segs.context) },
|
|
287
|
-
{ id: "tokens", label: copy.labels.tokens, currentValue: flag(segs.tokens) },
|
|
288
|
-
{ id: "cost", label: copy.labels.cost, currentValue: flag(segs.cost) },
|
|
289
|
-
{
|
|
290
|
-
id: "extensionStatuses",
|
|
291
|
-
label: copy.labels.extensionStatuses,
|
|
292
|
-
currentValue: flag(segs.extensionStatuses),
|
|
293
|
-
},
|
|
294
|
-
];
|
|
266
|
+
return buildFactItems("footer", config, copy);
|
|
295
267
|
}
|
|
296
268
|
|
|
297
269
|
function buildTelemetryItems(config: TuiConfig, copy: SettingsCopy): SettingItem[] {
|
|
298
|
-
const telemetry = config.telemetry;
|
|
299
270
|
const flag = (value: boolean) => (value ? copy.values.on : copy.values.off);
|
|
300
271
|
return [
|
|
301
|
-
{ id: "enabled", label: copy.labels.enabled, currentValue: flag(telemetry.enabled) },
|
|
302
|
-
|
|
303
|
-
{ id: "ttft", label: "TTFT", currentValue: flag(telemetry.ttft) },
|
|
304
|
-
{ id: "duration", label: copy.labels.totalDuration, currentValue: flag(telemetry.duration) },
|
|
305
|
-
{ id: "tokens", label: copy.labels.tokenCounts, currentValue: flag(telemetry.tokens) },
|
|
306
|
-
{ id: "stalls", label: copy.labels.stallDetails, currentValue: flag(telemetry.stalls) },
|
|
307
|
-
{ id: "cost", label: copy.labels.costRate, currentValue: flag(telemetry.cost) },
|
|
272
|
+
{ id: "enabled", label: copy.labels.enabled, currentValue: flag(config.telemetry.enabled) },
|
|
273
|
+
...buildFactItems("notify", config, copy),
|
|
308
274
|
];
|
|
309
275
|
}
|
|
310
276
|
|
|
277
|
+
/** The registry's keyed facts for one surface, in registry order. */
|
|
278
|
+
function buildFactItems(
|
|
279
|
+
surface: "footer" | "notify",
|
|
280
|
+
config: TuiConfig,
|
|
281
|
+
copy: SettingsCopy,
|
|
282
|
+
): SettingItem[] {
|
|
283
|
+
const section: Record<string, boolean> =
|
|
284
|
+
surface === "footer" ? config.footerSegments : config.telemetry;
|
|
285
|
+
const flag = (value: boolean) => (value ? copy.values.on : copy.values.off);
|
|
286
|
+
return factsFor(surface).flatMap((fact) => {
|
|
287
|
+
const key = fact.key;
|
|
288
|
+
if (key === undefined || fact.label === undefined) return [];
|
|
289
|
+
const id = flagOf(key);
|
|
290
|
+
return [{ id, label: fact.label, currentValue: flag(section[id] ?? false) }];
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
|
|
311
294
|
function buildItems(
|
|
312
295
|
tab: Tab,
|
|
313
296
|
config: TuiConfig,
|
|
@@ -354,7 +337,7 @@ function handleSettingChange(
|
|
|
354
337
|
}
|
|
355
338
|
|
|
356
339
|
export interface SettingsUiHandle {
|
|
357
|
-
render: (width: number) => string[];
|
|
340
|
+
render: (width: number) => readonly string[];
|
|
358
341
|
invalidate: () => void;
|
|
359
342
|
handleInput: (data: string) => void;
|
|
360
343
|
}
|
|
@@ -384,7 +367,7 @@ export const makeSettingsUi = (
|
|
|
384
367
|
const selectedItemByTab: Partial<Record<Tab, string>> = {};
|
|
385
368
|
const body = new Container();
|
|
386
369
|
let cachedWidth: number | undefined;
|
|
387
|
-
let cachedLines: string[] | undefined;
|
|
370
|
+
let cachedLines: readonly string[] | undefined;
|
|
388
371
|
let compact = false;
|
|
389
372
|
|
|
390
373
|
const adjustNeedsContextProbability = (delta: number): void => {
|
|
@@ -489,7 +472,9 @@ export const makeSettingsUi = (
|
|
|
489
472
|
if (selectedIndex >= 0) {
|
|
490
473
|
selectList.setSelectedIndex(selectedIndex);
|
|
491
474
|
}
|
|
492
|
-
|
|
475
|
+
const selectedValue = selectList.getSelectedItem()?.value;
|
|
476
|
+
if (selectedValue === undefined) delete selectedItemByTab[tab];
|
|
477
|
+
else selectedItemByTab[tab] = selectedValue;
|
|
493
478
|
selectList.onSelectionChange = (item) => {
|
|
494
479
|
selectedItemByTab[tab] = item.value;
|
|
495
480
|
};
|
|
@@ -523,7 +508,7 @@ export const makeSettingsUi = (
|
|
|
523
508
|
const nextIndex = (currentIndex + offset + items.length) % items.length;
|
|
524
509
|
selectList.setSelectedIndex(nextIndex);
|
|
525
510
|
const item = items[nextIndex];
|
|
526
|
-
if (item) selectedItemByTab[tab] = item.id;
|
|
511
|
+
if (item !== undefined) selectedItemByTab[tab] = item.id;
|
|
527
512
|
};
|
|
528
513
|
|
|
529
514
|
const handleInput = (data: string): void => {
|
|
@@ -552,7 +537,7 @@ export const makeSettingsUi = (
|
|
|
552
537
|
}
|
|
553
538
|
if (matchesKey(data, Key.space) || data === " ") {
|
|
554
539
|
const selected = selectList.getSelectedItem();
|
|
555
|
-
if (selected) applySetting(selected.value);
|
|
540
|
+
if (selected !== null) applySetting(selected.value);
|
|
556
541
|
} else if (data === "+" || data === "=" || data === "-" || data === "_") {
|
|
557
542
|
const selected = selectList.getSelectedItem()?.value;
|
|
558
543
|
const sign = data === "+" || data === "=" ? 1 : -1;
|
|
@@ -571,7 +556,7 @@ export const makeSettingsUi = (
|
|
|
571
556
|
invalidate();
|
|
572
557
|
};
|
|
573
558
|
|
|
574
|
-
const render = (width: number): string[] => {
|
|
559
|
+
const render = (width: number): readonly string[] => {
|
|
575
560
|
// The body renders at contentWidth = width - 4 (2 rails + 2×paddingX),
|
|
576
561
|
// mirroring makeBorderedBox's default paddingX of 1.
|
|
577
562
|
const widthCompact = Math.max(1, width - 4) <= 60;
|
|
@@ -579,7 +564,7 @@ export const makeSettingsUi = (
|
|
|
579
564
|
compact = widthCompact;
|
|
580
565
|
rebuild();
|
|
581
566
|
}
|
|
582
|
-
if (cachedLines && cachedWidth === width) return cachedLines;
|
|
567
|
+
if (cachedLines !== undefined && cachedWidth === width) return cachedLines;
|
|
583
568
|
cachedWidth = width;
|
|
584
569
|
cachedLines = bordered.render(width);
|
|
585
570
|
return cachedLines;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { assert, it } from "@effect/vitest";
|
|
2
|
-
import
|
|
2
|
+
import { themeDouble } from "@ftrdotdev/pi-test-kit";
|
|
3
|
+
import type { ThemeToken } from "@earendil-works/pi-coding-agent";
|
|
3
4
|
import { type Color, mixColors, rgbColor } from "@earendil-works/pi-tui";
|
|
4
5
|
import { emphasize, isDark, mixThemeTokens, recede } from "./theme-color.ts";
|
|
5
6
|
|
|
@@ -9,8 +10,8 @@ const colors = {
|
|
|
9
10
|
text: rgbColor(230, 230, 230),
|
|
10
11
|
userMessageBg: rgbColor(30, 30, 30),
|
|
11
12
|
} as unknown as Readonly<Record<ThemeToken, Color>>;
|
|
12
|
-
const darkTheme = { colors, appearance: "dark" }
|
|
13
|
-
const lightTheme = { colors, appearance: "light" }
|
|
13
|
+
const darkTheme = themeDouble({ colors, appearance: "dark" });
|
|
14
|
+
const lightTheme = themeDouble({ colors, appearance: "light" });
|
|
14
15
|
|
|
15
16
|
it("mixThemeTokens mixes the two tokens in OKLCH", () => {
|
|
16
17
|
assert.deepStrictEqual(
|