@ftrdotdev/pi-tui 0.5.2 → 0.6.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/README.md +1 -1
- package/package.json +2 -1
- package/src/activity.test.ts +11 -10
- package/src/activity.ts +1 -1
- package/src/components/bordered-box.test.ts +9 -3
- package/src/components/bordered-box.ts +18 -8
- package/src/components/index.ts +3 -0
- package/src/config.test.ts +131 -0
- package/src/config.ts +83 -45
- package/src/index.ts +4 -32
- package/src/runtime.test.ts +87 -0
- package/src/runtime.ts +25 -28
- package/src/session-lifecycle.ts +0 -18
- package/src/state.test.ts +1 -1
- package/src/state.ts +2 -2
- package/src/ui/editor-tint.test.ts +1 -1
- package/src/ui/editor-tint.ts +3 -2
- package/src/ui/editor.ts +64 -18
- package/src/ui/footer.test.ts +8 -1
- package/src/ui/header.test.ts +50 -3
- package/src/ui/header.ts +38 -1
- package/src/ui/preview.test.ts +85 -17
- package/src/ui/preview.ts +12 -12
- package/src/ui/render-helpers.test.ts +25 -0
- package/src/ui/render-helpers.ts +14 -9
- package/src/ui/settings-command.test.ts +343 -7
- package/src/ui/settings-command.ts +272 -16
- package/src/ui/theme-color.test.ts +39 -0
- package/src/ui/theme-color.ts +38 -0
- package/src/utils.test.ts +152 -0
- package/src/vim/editor-close-autocomplete.ts +1 -3
- package/src/vim/editor-host.test.ts +34 -0
package/src/ui/preview.ts
CHANGED
|
@@ -431,13 +431,13 @@ function makePreviewComponent(data: PreviewData, expanded: boolean, theme: Theme
|
|
|
431
431
|
? `${data.path} (${data.dimensions.widthPx}x${data.dimensions.heightPx})`
|
|
432
432
|
: data.path;
|
|
433
433
|
return makeBorderedBox(new Text(theme.fg("accent", caption), 0, 0), theme, {
|
|
434
|
-
label: theme.
|
|
435
|
-
bg:
|
|
434
|
+
label: theme.style("preview", { fg: "accent", bold: true }),
|
|
435
|
+
bg: "customMessageBg",
|
|
436
436
|
});
|
|
437
437
|
}
|
|
438
438
|
return makeBorderedBox(renderBodyComponent(data, expanded, theme), theme, {
|
|
439
|
-
label: theme.
|
|
440
|
-
bg:
|
|
439
|
+
label: theme.style("preview", { fg: "accent", bold: true }),
|
|
440
|
+
bg: "customMessageBg",
|
|
441
441
|
});
|
|
442
442
|
}
|
|
443
443
|
|
|
@@ -527,8 +527,8 @@ export function registerPreview(
|
|
|
527
527
|
|
|
528
528
|
renderCall(args, theme) {
|
|
529
529
|
return makeBorderedBox(new Text(args.path, 0, 0), theme, {
|
|
530
|
-
label: theme.
|
|
531
|
-
bg:
|
|
530
|
+
label: theme.style("preview", { fg: "toolTitle", bold: true }),
|
|
531
|
+
bg: "customMessageBg",
|
|
532
532
|
});
|
|
533
533
|
},
|
|
534
534
|
|
|
@@ -538,9 +538,9 @@ export function registerPreview(
|
|
|
538
538
|
if (!data) return context.lastComponent ?? new Text("", 0, 0);
|
|
539
539
|
if (data.error) {
|
|
540
540
|
return makeBorderedBox(new Text(`preview failed: ${data.error}`, 0, 0), theme, {
|
|
541
|
-
label: theme.
|
|
541
|
+
label: theme.style("preview", { fg: "warning", bold: true }),
|
|
542
542
|
color: "warning",
|
|
543
|
-
bg:
|
|
543
|
+
bg: "customMessageBg",
|
|
544
544
|
});
|
|
545
545
|
}
|
|
546
546
|
return makePreviewComponent(data, options.expanded, theme);
|
|
@@ -556,9 +556,9 @@ export function registerPreview(
|
|
|
556
556
|
const noData = new Container();
|
|
557
557
|
noData.addChild(new Text(theme.fg("warning", "[preview] no data"), 0, 0));
|
|
558
558
|
return makeBorderedBox(noData, theme, {
|
|
559
|
-
label: theme.
|
|
559
|
+
label: theme.style("preview", { fg: "warning", bold: true }),
|
|
560
560
|
color: "warning",
|
|
561
|
-
bg:
|
|
561
|
+
bg: "customMessageBg",
|
|
562
562
|
});
|
|
563
563
|
}
|
|
564
564
|
// Image entries mirror pi's native tool-image layout exactly: the bordered
|
|
@@ -585,8 +585,8 @@ export function registerPreview(
|
|
|
585
585
|
body.addChild(new Text(theme.fg("accent", data.path), 0, 0));
|
|
586
586
|
body.addChild(renderBodyComponent(data, expanded, theme));
|
|
587
587
|
return makeBorderedBox(body, theme, {
|
|
588
|
-
label: theme.
|
|
589
|
-
bg:
|
|
588
|
+
label: theme.style("preview", { fg: "accent", bold: true }),
|
|
589
|
+
bg: "customMessageBg",
|
|
590
590
|
});
|
|
591
591
|
});
|
|
592
592
|
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { assert, it } from "@effect/vitest";
|
|
2
|
+
import type { Theme } from "@earendil-works/pi-coding-agent";
|
|
3
|
+
import { renderBar, renderRuntimeSegment } from "./render-helpers.ts";
|
|
4
|
+
|
|
5
|
+
// Identity theme: styling is a no-op so assertions read the plain text.
|
|
6
|
+
const theme = {
|
|
7
|
+
fg: (_color: string, text: string) => text,
|
|
8
|
+
bg: (_color: string, text: string) => text,
|
|
9
|
+
bold: (text: string) => text,
|
|
10
|
+
} as unknown as Theme;
|
|
11
|
+
|
|
12
|
+
it("renderBar fills by rounded percentage in ascii and unicode", () => {
|
|
13
|
+
assert.strictEqual(renderBar(theme, 50, 10, true), "[#####-----]");
|
|
14
|
+
assert.strictEqual(renderBar(theme, 0, 4, false), "[░░░░]");
|
|
15
|
+
assert.strictEqual(renderBar(theme, 100, 4, true), "[####]");
|
|
16
|
+
assert.strictEqual(renderBar(theme, 150, 4, true), "[####]");
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it("renderRuntimeSegment joins every runtime with a dim separator", () => {
|
|
20
|
+
assert.strictEqual(renderRuntimeSegment(theme, [], "ascii"), "");
|
|
21
|
+
assert.strictEqual(
|
|
22
|
+
renderRuntimeSegment(theme, [{ name: "nodejs", version: "1.2.3" }, { name: "rust" }], "ascii"),
|
|
23
|
+
"node 1.2.3 · rs",
|
|
24
|
+
);
|
|
25
|
+
});
|
package/src/ui/render-helpers.ts
CHANGED
|
@@ -159,19 +159,22 @@ export function renderGitSegment(
|
|
|
159
159
|
}
|
|
160
160
|
|
|
161
161
|
/**
|
|
162
|
-
* The runtime footer segment:
|
|
163
|
-
*
|
|
162
|
+
* The runtime footer segment: one symbol (ascii or nerd per the icon mode)
|
|
163
|
+
* per matching runtime, each with its version when known. Multiple runtimes
|
|
164
|
+
* are joined with a dim separator. Returns `""` for no runtime.
|
|
164
165
|
*/
|
|
165
166
|
export function renderRuntimeSegment(
|
|
166
167
|
theme: Theme,
|
|
167
|
-
|
|
168
|
+
runtimes: readonly RuntimeInfo[],
|
|
168
169
|
iconMode: TuiConfig["icons"]["mode"],
|
|
169
170
|
): string {
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
171
|
+
return runtimes
|
|
172
|
+
.map((runtime) => {
|
|
173
|
+
const symbol = theme.fg("success", runtimeSymbol(runtime.name, iconMode));
|
|
174
|
+
const version = runtime.version ? theme.fg("muted", runtime.version) : "";
|
|
175
|
+
return [symbol, version].filter(Boolean).join(" ");
|
|
176
|
+
})
|
|
177
|
+
.join(theme.fg("dim", " · "));
|
|
175
178
|
}
|
|
176
179
|
|
|
177
180
|
/**
|
|
@@ -189,7 +192,9 @@ export interface TimerSegmentParts {
|
|
|
189
192
|
function renderSplit(theme: Theme, glyphs: IconGlyphs, inference: number, tool: number): string {
|
|
190
193
|
const buckets: string[] = [];
|
|
191
194
|
if (inference > 0) {
|
|
192
|
-
buckets.push(
|
|
195
|
+
buckets.push(
|
|
196
|
+
`${theme.fg("dim", glyphs.inference)} ${theme.fg("accent", formatDuration(inference))}`,
|
|
197
|
+
);
|
|
193
198
|
}
|
|
194
199
|
if (tool > 0) {
|
|
195
200
|
buckets.push(`${theme.fg("dim", glyphs.tool)} ${theme.fg("accent", formatDuration(tool))}`);
|
|
@@ -3,7 +3,15 @@ import { Effect } from "effect";
|
|
|
3
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
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
hasTrackerExtension,
|
|
8
|
+
loadClassifierChoices,
|
|
9
|
+
makeSettingsUi,
|
|
10
|
+
type ClassifierChoice,
|
|
11
|
+
type ClassifierDescriptor,
|
|
12
|
+
type ClassifierSource,
|
|
13
|
+
type SettingsUiHandle,
|
|
14
|
+
} from "./settings-command.ts";
|
|
7
15
|
|
|
8
16
|
// Pass-through theme: selections and the active tab are detected via
|
|
9
17
|
// plain-text markers ("→ " prefix, "[Tab]" brackets) in the render output.
|
|
@@ -11,6 +19,7 @@ const theme = {
|
|
|
11
19
|
fg: (_color: string, text: string) => text,
|
|
12
20
|
bg: (_color: string, text: string) => text,
|
|
13
21
|
bold: (text: string) => text,
|
|
22
|
+
style: (text: string) => text,
|
|
14
23
|
} as unknown as Theme;
|
|
15
24
|
|
|
16
25
|
const RENDER_WIDTH = 120;
|
|
@@ -28,11 +37,23 @@ interface UiSpy {
|
|
|
28
37
|
closes: number;
|
|
29
38
|
}
|
|
30
39
|
|
|
31
|
-
const
|
|
40
|
+
const defaultChoices: ClassifierChoice[] = [
|
|
41
|
+
{ value: null, label: "Automatic (prefer Clef Flash, then Jev)" },
|
|
42
|
+
{ value: "typesafe/jev-latest", label: "Safe" },
|
|
43
|
+
{ value: "cloudflare-workers-ai/@cf/cloudflare/clef-flash", label: "Fast" },
|
|
44
|
+
];
|
|
45
|
+
|
|
46
|
+
const makeUi = (
|
|
47
|
+
overrides: Partial<TuiConfig> = {},
|
|
48
|
+
choices: readonly ClassifierChoice[] = defaultChoices,
|
|
49
|
+
hasTracker = true,
|
|
50
|
+
): UiSpy => {
|
|
32
51
|
const spy: UiSpy = { ui: undefined!, changes: [], closes: 0 };
|
|
33
52
|
spy.ui = makeSettingsUi(
|
|
34
53
|
theme,
|
|
35
54
|
{ ...structuredClone(DEFAULT_CONFIG), ...overrides },
|
|
55
|
+
choices,
|
|
56
|
+
hasTracker,
|
|
36
57
|
(config) => {
|
|
37
58
|
spy.changes.push(config);
|
|
38
59
|
},
|
|
@@ -52,7 +73,7 @@ const selectedShows = (ui: SettingsUiHandle, label: string): boolean =>
|
|
|
52
73
|
const activeTab = (ui: SettingsUiHandle): string | undefined => {
|
|
53
74
|
const line = rendered(ui).find((l) => l.includes("["));
|
|
54
75
|
if (!line) return undefined;
|
|
55
|
-
for (const tab of ["General", "Icons", "Footer", "Telemetry"] as const) {
|
|
76
|
+
for (const tab of ["General", "Compaction", "Icons", "Footer", "Telemetry"] as const) {
|
|
56
77
|
if (line.includes(`[${tab}]`)) return tab;
|
|
57
78
|
}
|
|
58
79
|
return undefined;
|
|
@@ -72,7 +93,10 @@ it("starts with the first item of the features tab selected", () => {
|
|
|
72
93
|
it("renders the Vim mode item on the features tab showing Off by default", () => {
|
|
73
94
|
const { ui } = makeUi();
|
|
74
95
|
const lines = rendered(ui);
|
|
75
|
-
assert.strictEqual(
|
|
96
|
+
assert.strictEqual(
|
|
97
|
+
lines.some((line) => line.includes("Vim mode") && line.includes("Off")),
|
|
98
|
+
true,
|
|
99
|
+
);
|
|
76
100
|
});
|
|
77
101
|
|
|
78
102
|
it("Space toggles vim on and reports the change", () => {
|
|
@@ -82,7 +106,10 @@ it("Space toggles vim on and reports the change", () => {
|
|
|
82
106
|
assert.strictEqual(changes.length, 1);
|
|
83
107
|
assert.strictEqual(changes[0]!.vim, true);
|
|
84
108
|
assert.strictEqual(changes[0]!.enabled, true); // other fields untouched
|
|
85
|
-
assert.strictEqual(
|
|
109
|
+
assert.strictEqual(
|
|
110
|
+
rendered(ui).some((line) => line.includes("Vim mode") && line.includes("On")),
|
|
111
|
+
true,
|
|
112
|
+
);
|
|
86
113
|
});
|
|
87
114
|
|
|
88
115
|
it("j moves the selection down and wraps to the first item at the end", () => {
|
|
@@ -132,6 +159,8 @@ it("j moves the selection with vim off (settings gate is unconditional)", () =>
|
|
|
132
159
|
it("l switches to the next tab and wraps from the last tab to the first", () => {
|
|
133
160
|
const { ui } = makeUi();
|
|
134
161
|
ui.handleInput("l");
|
|
162
|
+
assert.strictEqual(activeTab(ui), "Compaction");
|
|
163
|
+
ui.handleInput("l");
|
|
135
164
|
assert.strictEqual(activeTab(ui), "Icons");
|
|
136
165
|
ui.handleInput("l");
|
|
137
166
|
assert.strictEqual(activeTab(ui), "Footer");
|
|
@@ -150,6 +179,8 @@ it("h switches to the previous tab and wraps from the first tab to the last", ()
|
|
|
150
179
|
ui.handleInput("h");
|
|
151
180
|
assert.strictEqual(activeTab(ui), "Icons");
|
|
152
181
|
ui.handleInput("h");
|
|
182
|
+
assert.strictEqual(activeTab(ui), "Compaction");
|
|
183
|
+
ui.handleInput("h");
|
|
153
184
|
assert.strictEqual(activeTab(ui), "General");
|
|
154
185
|
});
|
|
155
186
|
|
|
@@ -157,7 +188,7 @@ it("remembers the selected item per tab when navigating with h/l", () => {
|
|
|
157
188
|
const { ui } = makeUi();
|
|
158
189
|
ui.handleInput("j"); // features: Vim mode
|
|
159
190
|
ui.handleInput("j"); // features: Language
|
|
160
|
-
ui.handleInput("l"); // →
|
|
191
|
+
ui.handleInput("l"); // → Compaction
|
|
161
192
|
ui.handleInput("h"); // → back to features
|
|
162
193
|
assert.strictEqual(selectedShows(ui, "Language"), true);
|
|
163
194
|
});
|
|
@@ -177,7 +208,7 @@ it("the arrow keys still move the selection", () => {
|
|
|
177
208
|
it("Tab and Shift+Tab still switch tabs", () => {
|
|
178
209
|
const { ui } = makeUi();
|
|
179
210
|
ui.handleInput("\t");
|
|
180
|
-
assert.strictEqual(activeTab(ui), "
|
|
211
|
+
assert.strictEqual(activeTab(ui), "Compaction");
|
|
181
212
|
ui.handleInput("\x1b[Z");
|
|
182
213
|
assert.strictEqual(activeTab(ui), "General");
|
|
183
214
|
});
|
|
@@ -185,6 +216,7 @@ it("Tab and Shift+Tab still switch tabs", () => {
|
|
|
185
216
|
it("j and k work on tabs with more items than fit the visible list", () => {
|
|
186
217
|
const { ui } = makeUi();
|
|
187
218
|
ui.handleInput("l");
|
|
219
|
+
ui.handleInput("l");
|
|
188
220
|
ui.handleInput("l"); // → Footer (9 items)
|
|
189
221
|
ui.handleInput("k"); // wrap to the bottom of the segments list
|
|
190
222
|
assert.strictEqual(selectedShows(ui, "Extension status line"), true);
|
|
@@ -216,3 +248,307 @@ it("unrelated letters are ignored", () => {
|
|
|
216
248
|
assert.strictEqual(closes, 0);
|
|
217
249
|
assert.strictEqual(selectedShows(ui, "Enabled"), true);
|
|
218
250
|
});
|
|
251
|
+
|
|
252
|
+
// ---------------------------------------------------------------------------
|
|
253
|
+
// Compaction tab: gated on the tracker extension, five rows
|
|
254
|
+
// ---------------------------------------------------------------------------
|
|
255
|
+
|
|
256
|
+
/** Switch from the General tab to the Compaction tab. */
|
|
257
|
+
const goToCompaction = (ui: SettingsUiHandle): void => {
|
|
258
|
+
ui.handleInput("\t");
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
type CompactionRow = "toggle" | "classifier" | "threshold" | "minConfidence" | "cap";
|
|
262
|
+
const ROW_OFFSET: Record<CompactionRow, number> = {
|
|
263
|
+
toggle: 0,
|
|
264
|
+
classifier: 1,
|
|
265
|
+
threshold: 2,
|
|
266
|
+
minConfidence: 3,
|
|
267
|
+
cap: 4,
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
/** Switch to the Compaction tab and move to the named row. */
|
|
271
|
+
const selectCompactionRow = (ui: SettingsUiHandle, row: CompactionRow): void => {
|
|
272
|
+
goToCompaction(ui);
|
|
273
|
+
for (let step = 0; step < ROW_OFFSET[row]; step += 1) ui.handleInput("j");
|
|
274
|
+
};
|
|
275
|
+
|
|
276
|
+
it("the Compaction tab is hidden when the tracker extension is not loaded", () => {
|
|
277
|
+
const { ui } = makeUi({}, defaultChoices, false);
|
|
278
|
+
assert.strictEqual(activeTab(ui), "General");
|
|
279
|
+
ui.handleInput("l");
|
|
280
|
+
assert.strictEqual(activeTab(ui), "Icons");
|
|
281
|
+
assert.strictEqual(
|
|
282
|
+
rendered(ui).some((line) => line.includes("Smart compaction")),
|
|
283
|
+
false,
|
|
284
|
+
);
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
it("the Compaction tab shows the toggle, classifier, threshold, min confidence, and cap", () => {
|
|
288
|
+
const { ui } = makeUi();
|
|
289
|
+
goToCompaction(ui);
|
|
290
|
+
const lines = rendered(ui);
|
|
291
|
+
for (const label of [
|
|
292
|
+
"Smart compaction",
|
|
293
|
+
"Compaction classifier",
|
|
294
|
+
"Keep-context confidence",
|
|
295
|
+
"Min confidence",
|
|
296
|
+
"Max candidates",
|
|
297
|
+
]) {
|
|
298
|
+
assert.strictEqual(lines.some((line) => line.includes(label)), true);
|
|
299
|
+
}
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
it("pressing enter toggles smart compaction On -> Off -> On", () => {
|
|
303
|
+
const { ui, changes } = makeUi();
|
|
304
|
+
selectCompactionRow(ui, "toggle");
|
|
305
|
+
assert.strictEqual(selectedShows(ui, "Smart compaction"), true);
|
|
306
|
+
|
|
307
|
+
ui.handleInput("\r");
|
|
308
|
+
assert.strictEqual(changes.at(-1)?.smartCompaction.enabled, false);
|
|
309
|
+
ui.handleInput("\r");
|
|
310
|
+
assert.strictEqual(changes.at(-1)?.smartCompaction.enabled, true);
|
|
311
|
+
assert.deepStrictEqual(
|
|
312
|
+
changes.map((config) => config.smartCompaction.enabled),
|
|
313
|
+
[false, true],
|
|
314
|
+
);
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
it("cycling the classifier row advances to the next enumerated choice", () => {
|
|
318
|
+
const { ui, changes } = makeUi();
|
|
319
|
+
selectCompactionRow(ui, "classifier");
|
|
320
|
+
|
|
321
|
+
ui.handleInput("\r");
|
|
322
|
+
|
|
323
|
+
assert.strictEqual(changes.length, 1);
|
|
324
|
+
assert.strictEqual(changes[0]!.smartCompaction.classifier, "typesafe/jev-latest");
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
it("cycling past the last classifier choice returns to Automatic", () => {
|
|
328
|
+
const { ui, changes } = makeUi({
|
|
329
|
+
smartCompaction: {
|
|
330
|
+
...DEFAULT_CONFIG.smartCompaction,
|
|
331
|
+
classifier: "cloudflare-workers-ai/@cf/cloudflare/clef-flash",
|
|
332
|
+
},
|
|
333
|
+
});
|
|
334
|
+
selectCompactionRow(ui, "classifier");
|
|
335
|
+
|
|
336
|
+
ui.handleInput("\r");
|
|
337
|
+
|
|
338
|
+
assert.strictEqual(changes.at(-1)?.smartCompaction.classifier, null);
|
|
339
|
+
});
|
|
340
|
+
|
|
341
|
+
it("the classifier row shows the label of the chosen model", () => {
|
|
342
|
+
const { ui } = makeUi({
|
|
343
|
+
smartCompaction: { ...DEFAULT_CONFIG.smartCompaction, classifier: "typesafe/jev-latest" },
|
|
344
|
+
});
|
|
345
|
+
selectCompactionRow(ui, "classifier");
|
|
346
|
+
const lines = rendered(ui);
|
|
347
|
+
assert.strictEqual(
|
|
348
|
+
lines.some((line) => line.includes("Compaction classifier") && line.includes("Safe")),
|
|
349
|
+
true,
|
|
350
|
+
);
|
|
351
|
+
});
|
|
352
|
+
|
|
353
|
+
it("the Compaction tab adds exactly the five smart-compaction rows", () => {
|
|
354
|
+
const { ui } = makeUi();
|
|
355
|
+
selectCompactionRow(ui, "cap");
|
|
356
|
+
assert.strictEqual(selectedShows(ui, "Max candidates"), true);
|
|
357
|
+
ui.handleInput("j"); // wraps to the first item, proving no extra row follows
|
|
358
|
+
assert.strictEqual(selectedShows(ui, "Smart compaction"), true);
|
|
359
|
+
});
|
|
360
|
+
|
|
361
|
+
it("the threshold row shows the current value with two decimals", () => {
|
|
362
|
+
const { ui } = makeUi({
|
|
363
|
+
smartCompaction: { ...DEFAULT_CONFIG.smartCompaction, keepContextThreshold: 0.7 },
|
|
364
|
+
});
|
|
365
|
+
goToCompaction(ui);
|
|
366
|
+
assert.strictEqual(
|
|
367
|
+
rendered(ui).some((line) => line.includes("Keep-context confidence") && line.includes("0.70")),
|
|
368
|
+
true,
|
|
369
|
+
);
|
|
370
|
+
});
|
|
371
|
+
|
|
372
|
+
it("Enter on the threshold row steps the value up by 0.05", () => {
|
|
373
|
+
const { ui, changes } = makeUi();
|
|
374
|
+
selectCompactionRow(ui, "threshold");
|
|
375
|
+
assert.strictEqual(selectedShows(ui, "Keep-context confidence"), true);
|
|
376
|
+
|
|
377
|
+
ui.handleInput("\r");
|
|
378
|
+
|
|
379
|
+
assert.strictEqual(changes.length, 1);
|
|
380
|
+
assert.strictEqual(changes[0]!.smartCompaction.keepContextThreshold, 0.55);
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
it("the +/- keys adjust the threshold row and clamp inside the open interval", () => {
|
|
384
|
+
const { ui, changes } = makeUi({
|
|
385
|
+
smartCompaction: { ...DEFAULT_CONFIG.smartCompaction, keepContextThreshold: 0.95 },
|
|
386
|
+
});
|
|
387
|
+
selectCompactionRow(ui, "threshold");
|
|
388
|
+
|
|
389
|
+
ui.handleInput("+");
|
|
390
|
+
assert.strictEqual(changes.at(-1)?.smartCompaction.keepContextThreshold, 0.95);
|
|
391
|
+
ui.handleInput("-");
|
|
392
|
+
assert.strictEqual(changes.at(-1)?.smartCompaction.keepContextThreshold, 0.9);
|
|
393
|
+
});
|
|
394
|
+
|
|
395
|
+
it("the min-confidence row shows the current value with two decimals", () => {
|
|
396
|
+
const { ui } = makeUi({
|
|
397
|
+
smartCompaction: { ...DEFAULT_CONFIG.smartCompaction, keepContextMinConfidence: 0.7 },
|
|
398
|
+
});
|
|
399
|
+
goToCompaction(ui);
|
|
400
|
+
assert.strictEqual(
|
|
401
|
+
rendered(ui).some((line) => line.includes("Min confidence") && line.includes("0.70")),
|
|
402
|
+
true,
|
|
403
|
+
);
|
|
404
|
+
});
|
|
405
|
+
|
|
406
|
+
it("Enter on the min-confidence row steps the value up by 0.05", () => {
|
|
407
|
+
const { ui, changes } = makeUi();
|
|
408
|
+
selectCompactionRow(ui, "minConfidence");
|
|
409
|
+
assert.strictEqual(selectedShows(ui, "Min confidence"), true);
|
|
410
|
+
|
|
411
|
+
ui.handleInput("\r");
|
|
412
|
+
|
|
413
|
+
assert.strictEqual(changes.length, 1);
|
|
414
|
+
assert.strictEqual(changes[0]!.smartCompaction.keepContextMinConfidence, 0.55);
|
|
415
|
+
});
|
|
416
|
+
|
|
417
|
+
it("the +/- keys adjust the min-confidence row and clamp inside the open interval", () => {
|
|
418
|
+
const { ui, changes } = makeUi({
|
|
419
|
+
smartCompaction: { ...DEFAULT_CONFIG.smartCompaction, keepContextMinConfidence: 0.95 },
|
|
420
|
+
});
|
|
421
|
+
selectCompactionRow(ui, "minConfidence");
|
|
422
|
+
|
|
423
|
+
ui.handleInput("+");
|
|
424
|
+
assert.strictEqual(changes.at(-1)?.smartCompaction.keepContextMinConfidence, 0.95);
|
|
425
|
+
ui.handleInput("-");
|
|
426
|
+
assert.strictEqual(changes.at(-1)?.smartCompaction.keepContextMinConfidence, 0.9);
|
|
427
|
+
});
|
|
428
|
+
|
|
429
|
+
it("the cap row shows the integer value", () => {
|
|
430
|
+
const { ui } = makeUi({
|
|
431
|
+
smartCompaction: { ...DEFAULT_CONFIG.smartCompaction, maxCandidates: 3 },
|
|
432
|
+
});
|
|
433
|
+
goToCompaction(ui);
|
|
434
|
+
assert.strictEqual(
|
|
435
|
+
rendered(ui).some((line) => line.includes("Max candidates") && line.includes("3")),
|
|
436
|
+
true,
|
|
437
|
+
);
|
|
438
|
+
});
|
|
439
|
+
|
|
440
|
+
it("Enter on the cap row steps the value up by one", () => {
|
|
441
|
+
const { ui, changes } = makeUi();
|
|
442
|
+
selectCompactionRow(ui, "cap");
|
|
443
|
+
|
|
444
|
+
ui.handleInput("\r");
|
|
445
|
+
|
|
446
|
+
assert.strictEqual(changes.length, 1);
|
|
447
|
+
assert.strictEqual(changes[0]!.smartCompaction.maxCandidates, 9);
|
|
448
|
+
});
|
|
449
|
+
|
|
450
|
+
it("the +/- keys adjust the cap row and clamp to the bounds", () => {
|
|
451
|
+
const { ui, changes } = makeUi({
|
|
452
|
+
smartCompaction: { ...DEFAULT_CONFIG.smartCompaction, maxCandidates: 20 },
|
|
453
|
+
});
|
|
454
|
+
selectCompactionRow(ui, "cap");
|
|
455
|
+
|
|
456
|
+
ui.handleInput("+");
|
|
457
|
+
assert.strictEqual(changes.at(-1)?.smartCompaction.maxCandidates, 20);
|
|
458
|
+
ui.handleInput("-");
|
|
459
|
+
assert.strictEqual(changes.at(-1)?.smartCompaction.maxCandidates, 19);
|
|
460
|
+
});
|
|
461
|
+
|
|
462
|
+
// ---------------------------------------------------------------------------
|
|
463
|
+
// hasTrackerExtension: the gate itself
|
|
464
|
+
// ---------------------------------------------------------------------------
|
|
465
|
+
|
|
466
|
+
const probe = (
|
|
467
|
+
tools: readonly string[],
|
|
468
|
+
commands: readonly { name: string; source: string }[],
|
|
469
|
+
): {
|
|
470
|
+
getAllTools: () => readonly { name: string }[];
|
|
471
|
+
getCommands: () => readonly { name: string; source: string }[];
|
|
472
|
+
} => ({
|
|
473
|
+
getAllTools: () => tools.map((name) => ({ name })),
|
|
474
|
+
getCommands: () => commands,
|
|
475
|
+
});
|
|
476
|
+
|
|
477
|
+
it("hasTrackerExtension is true when the tracker tool is registered", () => {
|
|
478
|
+
assert.strictEqual(hasTrackerExtension(probe(["read", "tracker"], [])), true);
|
|
479
|
+
});
|
|
480
|
+
|
|
481
|
+
it("hasTrackerExtension is true when the tracker extension command is registered", () => {
|
|
482
|
+
assert.strictEqual(
|
|
483
|
+
hasTrackerExtension(probe([], [{ name: "tracker", source: "extension" }])),
|
|
484
|
+
true,
|
|
485
|
+
);
|
|
486
|
+
});
|
|
487
|
+
|
|
488
|
+
it("hasTrackerExtension ignores a non-extension command named tracker", () => {
|
|
489
|
+
assert.strictEqual(hasTrackerExtension(probe([], [{ name: "tracker", source: "prompt" }])), false);
|
|
490
|
+
});
|
|
491
|
+
|
|
492
|
+
it("hasTrackerExtension is false when the tracker is not loaded", () => {
|
|
493
|
+
assert.strictEqual(
|
|
494
|
+
hasTrackerExtension(probe(["read", "bash"], [{ name: "tui", source: "extension" }])),
|
|
495
|
+
false,
|
|
496
|
+
);
|
|
497
|
+
});
|
|
498
|
+
|
|
499
|
+
// ---------------------------------------------------------------------------
|
|
500
|
+
// loadClassifierChoices: credential-available models, else the catalog
|
|
501
|
+
// ---------------------------------------------------------------------------
|
|
502
|
+
|
|
503
|
+
const descriptor = (provider: string, id: string, name: string): ClassifierDescriptor => ({
|
|
504
|
+
provider,
|
|
505
|
+
id,
|
|
506
|
+
name,
|
|
507
|
+
});
|
|
508
|
+
|
|
509
|
+
const catalogModels: readonly ClassifierDescriptor[] = [
|
|
510
|
+
descriptor("cloudflare-workers-ai", "@cf/cloudflare/clef-flash", "Clef Flash"),
|
|
511
|
+
descriptor("typesafe", "jev-latest", "Jev"),
|
|
512
|
+
descriptor("other", "alpha", "Alpha"),
|
|
513
|
+
descriptor("other", "beta", "Beta"),
|
|
514
|
+
];
|
|
515
|
+
|
|
516
|
+
const source = (available: readonly ClassifierDescriptor[]): ClassifierSource => ({
|
|
517
|
+
getAvailableOfType: async () => available,
|
|
518
|
+
getModelsOfType: () => catalogModels,
|
|
519
|
+
});
|
|
520
|
+
|
|
521
|
+
it("loadClassifierChoices prefers credential-available classifiers", async () => {
|
|
522
|
+
const choices = await loadClassifierChoices(source([catalogModels[0]!, catalogModels[1]!]));
|
|
523
|
+
assert.deepStrictEqual(
|
|
524
|
+
choices.map((choice) => choice.value),
|
|
525
|
+
[null, "cloudflare-workers-ai/@cf/cloudflare/clef-flash", "typesafe/jev-latest"],
|
|
526
|
+
);
|
|
527
|
+
assert.strictEqual(choices[0]!.label, "Automatic (prefer Clef Flash, then Jev)");
|
|
528
|
+
});
|
|
529
|
+
|
|
530
|
+
it("loadClassifierChoices falls back to the full catalog when none are available", async () => {
|
|
531
|
+
const choices = await loadClassifierChoices(source([]));
|
|
532
|
+
assert.strictEqual(choices.length, catalogModels.length + 1);
|
|
533
|
+
assert.deepStrictEqual(
|
|
534
|
+
choices.map((choice) => choice.value),
|
|
535
|
+
[
|
|
536
|
+
null,
|
|
537
|
+
"cloudflare-workers-ai/@cf/cloudflare/clef-flash",
|
|
538
|
+
"typesafe/jev-latest",
|
|
539
|
+
"other/alpha",
|
|
540
|
+
"other/beta",
|
|
541
|
+
],
|
|
542
|
+
);
|
|
543
|
+
});
|
|
544
|
+
|
|
545
|
+
it("loadClassifierChoices survives a discovery failure", async () => {
|
|
546
|
+
const failing: ClassifierSource = {
|
|
547
|
+
getAvailableOfType: async () => {
|
|
548
|
+
throw new Error("no credentials");
|
|
549
|
+
},
|
|
550
|
+
getModelsOfType: () => catalogModels,
|
|
551
|
+
};
|
|
552
|
+
const choices = await loadClassifierChoices(failing);
|
|
553
|
+
assert.strictEqual(choices.length, catalogModels.length + 1);
|
|
554
|
+
});
|