@ftrdotdev/pi-tui 0.5.2 → 0.7.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 +166 -0
- package/src/config.ts +97 -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 +151 -17
- package/src/ui/preview.ts +27 -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 +351 -7
- package/src/ui/settings-command.ts +276 -20
- 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/README.md
CHANGED
|
@@ -60,4 +60,4 @@ no `this` and survive any hand-off.
|
|
|
60
60
|
| `bun test` | Run the test suite (vitest + @effect/vitest) |
|
|
61
61
|
| `bun test:watch` | Run the test suite in watch mode |
|
|
62
62
|
| `bunx tsc --noEmit` | Type check |
|
|
63
|
-
| `bun lint` | Lint with oxlint |
|
|
63
|
+
| `bun lint` | Lint with oxlint |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ftrdotdev/pi-tui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "House TUI components and the pi interface extension: themed boxes, a pure box-frame model, and the header/footer/editor/settings/preview chrome",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"components",
|
|
@@ -58,6 +58,7 @@
|
|
|
58
58
|
"effect": "4.0.0"
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
|
61
|
+
"@earendil-works/pi-tui": "1.1.0",
|
|
61
62
|
"@effect/tsgo": "0.47.2",
|
|
62
63
|
"@effect/vitest": "4.0.0",
|
|
63
64
|
"@types/bun": "latest",
|
package/src/activity.test.ts
CHANGED
|
@@ -144,7 +144,10 @@ it("keeps inference plus tool plus wait at or below total active time at every i
|
|
|
144
144
|
assert.deepStrictEqual(observed, expected);
|
|
145
145
|
for (const b of observed) {
|
|
146
146
|
assert.ok(b.inference + b.tool + b.wait <= b.total);
|
|
147
|
-
assert.strictEqual(
|
|
147
|
+
assert.strictEqual(
|
|
148
|
+
b.inference + b.tool + b.wait,
|
|
149
|
+
b.total - (b.total - b.inference - b.tool - b.wait),
|
|
150
|
+
);
|
|
148
151
|
}
|
|
149
152
|
});
|
|
150
153
|
|
|
@@ -235,20 +238,18 @@ it("parity: waitingMs reports the open wait span and 0 when no prompt is open",
|
|
|
235
238
|
|
|
236
239
|
it("toTrackerEvent maps pi message roles and tool calls onto tracker descriptors", () => {
|
|
237
240
|
// Assistant message_start opens an inference span.
|
|
238
|
-
assert.deepStrictEqual(
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
241
|
+
assert.deepStrictEqual(toTrackerEvent({ kind: "message_start", role: "assistant", now: 1000 }), {
|
|
242
|
+
type: "message_start",
|
|
243
|
+
role: "assistant",
|
|
244
|
+
now: 1000,
|
|
245
|
+
});
|
|
242
246
|
// toolResult message_end never maps to an assistant span.
|
|
243
247
|
assert.strictEqual(
|
|
244
248
|
toTrackerEvent({ kind: "message_end", role: "toolResult", now: 2000 }),
|
|
245
249
|
undefined,
|
|
246
250
|
);
|
|
247
251
|
// User messages never map either.
|
|
248
|
-
assert.strictEqual(
|
|
249
|
-
toTrackerEvent({ kind: "message_start", role: "user", now: 2000 }),
|
|
250
|
-
undefined,
|
|
251
|
-
);
|
|
252
|
+
assert.strictEqual(toTrackerEvent({ kind: "message_start", role: "user", now: 2000 }), undefined);
|
|
252
253
|
// Tool executions carry their call id through.
|
|
253
254
|
assert.deepStrictEqual(
|
|
254
255
|
toTrackerEvent({ kind: "tool_execution_start", toolCallId: "call_1", now: 3000 }),
|
|
@@ -278,4 +279,4 @@ it("toTrackerEvent feeds the tracker a live inference/tool script", () => {
|
|
|
278
279
|
const breakdown = tracker.breakdown(6000);
|
|
279
280
|
// tool 2000..4000 = 2s; inference 1000..2000 + 4000..5000 = 2s.
|
|
280
281
|
assert.deepStrictEqual(breakdown, { inference: 2000, tool: 2000, wait: 0, total: 5000 });
|
|
281
|
-
});
|
|
282
|
+
});
|
package/src/activity.ts
CHANGED
|
@@ -14,6 +14,7 @@ const plainTheme = {
|
|
|
14
14
|
fg: (_color: string, text: string) => text,
|
|
15
15
|
bg: (_color: string, text: string) => text,
|
|
16
16
|
bold: (text: string) => text,
|
|
17
|
+
style: (text: string) => text,
|
|
17
18
|
} as unknown as Theme;
|
|
18
19
|
|
|
19
20
|
// Marker theme for color and background assertions.
|
|
@@ -21,6 +22,12 @@ const markerTheme = {
|
|
|
21
22
|
fg: (color: string, text: string) => `<${color}>${text}</${color}>`,
|
|
22
23
|
bg: (color: string, text: string) => `[${color}]${text}[/${color}]`,
|
|
23
24
|
bold: (text: string) => text,
|
|
25
|
+
style: (text: string, options: { fg?: string; bg?: string }) => {
|
|
26
|
+
let out = text;
|
|
27
|
+
if (options.fg) out = `<${options.fg}>${out}</${options.fg}>`;
|
|
28
|
+
if (options.bg) out = `[${options.bg}]${out}[/${options.bg}]`;
|
|
29
|
+
return out;
|
|
30
|
+
},
|
|
24
31
|
} as unknown as Theme;
|
|
25
32
|
|
|
26
33
|
it("renders top and bottom borders with the content rail-wrapped between them", () => {
|
|
@@ -48,9 +55,8 @@ it("truncates long body lines to the content width", () => {
|
|
|
48
55
|
assert.deepStrictEqual(out, ["╭──────╮", "│ abcd\x1b[0m │", "╰──────╯"]);
|
|
49
56
|
});
|
|
50
57
|
|
|
51
|
-
it("applies the background
|
|
52
|
-
const
|
|
53
|
-
const out = makeBorderedBox(lines(["hi"]), markerTheme, { bg }).render(12);
|
|
58
|
+
it("applies the background token to every rendered line", () => {
|
|
59
|
+
const out = makeBorderedBox(lines(["hi"]), markerTheme, { bg: "customMessageBg" }).render(12);
|
|
54
60
|
assert.strictEqual(out.length, 3);
|
|
55
61
|
for (const line of out) {
|
|
56
62
|
assert.strictEqual(line.startsWith("[customMessageBg]"), true);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { Theme, ThemeColor } from "@earendil-works/pi-coding-agent";
|
|
2
|
-
import type { Component } from "@earendil-works/pi-tui";
|
|
1
|
+
import type { Theme, ThemeBg, ThemeColor } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import type { Color, Component } from "@earendil-works/pi-tui";
|
|
3
3
|
import { composeBorderLine, buildBoxFrame } from "../frame/box-frame.ts";
|
|
4
4
|
import { padRight, visibleWidth } from "../utils.ts";
|
|
5
5
|
import { defineComponent } from "./define-component.ts";
|
|
@@ -12,16 +12,19 @@ export interface BorderedBoxOptions {
|
|
|
12
12
|
* follow theme changes. When the box is too narrow the label is omitted.
|
|
13
13
|
*/
|
|
14
14
|
readonly label?: string | ((theme: Theme) => string);
|
|
15
|
-
/** Border color token
|
|
16
|
-
readonly color?: ThemeColor;
|
|
15
|
+
/** Border color: a theme token, or a concrete derived `Color`. Defaults to "accent". */
|
|
16
|
+
readonly color?: ThemeColor | Color;
|
|
17
17
|
/**
|
|
18
18
|
* Decorative dash run after the label. Defaults to " ─────". Pass a
|
|
19
19
|
* different tail (e.g. a single space for a scroll hint) when the label
|
|
20
20
|
* should not trail with the full dash run.
|
|
21
21
|
*/
|
|
22
22
|
readonly labelSuffix?: string;
|
|
23
|
-
/**
|
|
24
|
-
|
|
23
|
+
/**
|
|
24
|
+
* Background token applied to every rendered line, including the embedded
|
|
25
|
+
* label. Painted through `theme.style()`, not a caller-supplied wrapper.
|
|
26
|
+
*/
|
|
27
|
+
readonly bg?: ThemeBg;
|
|
25
28
|
/** Horizontal padding between the rails and the content. Defaults to 1. */
|
|
26
29
|
readonly paddingX?: number;
|
|
27
30
|
/**
|
|
@@ -69,8 +72,15 @@ export const makeBorderedBox = (
|
|
|
69
72
|
});
|
|
70
73
|
if (!frame) return [];
|
|
71
74
|
|
|
72
|
-
|
|
73
|
-
|
|
75
|
+
// Border chrome carries the foreground token and the background in one
|
|
76
|
+
// `theme.style()` call. Body content styles itself, so it only needs the
|
|
77
|
+
// background wrapper; the wrapper also covers the embedded label, which
|
|
78
|
+
// `composeBorderLine` passes through raw (already pre-themed by callers).
|
|
79
|
+
const paint = (s: string) => theme.style(s, { fg: options.color ?? "accent", bg: options.bg });
|
|
80
|
+
const bg =
|
|
81
|
+
options.bg === undefined
|
|
82
|
+
? (s: string) => s
|
|
83
|
+
: (s: string) => theme.style(s, { bg: options.bg });
|
|
74
84
|
const pad = frame.padLeft;
|
|
75
85
|
|
|
76
86
|
const top = bg(composeBorderLine(frame, "top", paint));
|
package/src/components/index.ts
CHANGED
|
@@ -25,6 +25,9 @@ export {
|
|
|
25
25
|
type BoxTopBorder,
|
|
26
26
|
} from "../frame/box-frame.ts";
|
|
27
27
|
export { VimRouter, type NavigationIntent } from "../vim/vim-router.ts";
|
|
28
|
+
// Derived theme colors: mix concrete token colors when a component needs a
|
|
29
|
+
// shade that is not a theme token.
|
|
30
|
+
export { emphasize, isDark, mixThemeTokens, recede } from "../ui/theme-color.ts";
|
|
28
31
|
// Editor customization: a generic Effect service other extensions can import
|
|
29
32
|
// and `.configure` to inject/override the editor's border tint.
|
|
30
33
|
export {
|
package/src/config.test.ts
CHANGED
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
import { assert, it } from "@effect/vitest";
|
|
2
2
|
import { Effect, PlatformError, Schema } from "effect";
|
|
3
3
|
import * as FileSystem from "effect/FileSystem";
|
|
4
|
+
import * as NodeFileSystem from "@effect/platform-node/NodeFileSystem";
|
|
4
5
|
import { join } from "node:path";
|
|
6
|
+
import { fileURLToPath } from "node:url";
|
|
5
7
|
import { getAgentDir } from "@earendil-works/pi-coding-agent";
|
|
6
8
|
import {
|
|
9
|
+
adjustSmartCompactionProbability,
|
|
10
|
+
adjustMaxCandidates,
|
|
7
11
|
applyDefaults,
|
|
8
12
|
ConfigParseError,
|
|
9
13
|
ConfigWriteError,
|
|
10
14
|
DEFAULT_CONFIG,
|
|
15
|
+
decodeConfig,
|
|
11
16
|
encodeConfig,
|
|
12
17
|
getConfigPath,
|
|
13
18
|
TuiConfig,
|
|
@@ -467,3 +472,164 @@ it("ConfigWriteError carries the expected tag", () => {
|
|
|
467
472
|
assert.strictEqual(err._tag, "ConfigWriteError");
|
|
468
473
|
assert.instanceOf(err, ConfigWriteError);
|
|
469
474
|
});
|
|
475
|
+
|
|
476
|
+
// ---------------------------------------------------------------------------
|
|
477
|
+
// Smart compaction: shared with the tracker reader
|
|
478
|
+
// ---------------------------------------------------------------------------
|
|
479
|
+
|
|
480
|
+
const CONTRACT_FIXTURE = new URL(
|
|
481
|
+
"../../tracker/test-fixtures/tui-config.contract.json",
|
|
482
|
+
import.meta.url,
|
|
483
|
+
);
|
|
484
|
+
|
|
485
|
+
it.effect("the shared contract fixture decodes into the smart-compaction section", () =>
|
|
486
|
+
Effect.gen(function* () {
|
|
487
|
+
const fs = yield* FileSystem.FileSystem;
|
|
488
|
+
const raw = yield* fs.readFileString(fileURLToPath(CONTRACT_FIXTURE));
|
|
489
|
+
const config = applyDefaults(decodeConfig(raw));
|
|
490
|
+
assert.strictEqual(config.smartCompaction.enabled, true);
|
|
491
|
+
assert.strictEqual(config.smartCompaction.classifier, "typesafe/jev-latest");
|
|
492
|
+
assert.strictEqual(config.smartCompaction.needsContextProbabilityThreshold, 0.5);
|
|
493
|
+
assert.strictEqual(config.smartCompaction.minAnswerConfidence, 0.5);
|
|
494
|
+
assert.strictEqual(config.smartCompaction.maxCandidates, 8);
|
|
495
|
+
}).pipe(Effect.provide(NodeFileSystem.layer)),
|
|
496
|
+
);
|
|
497
|
+
|
|
498
|
+
it("a config file without the smart-compaction section applies the smart-compaction defaults", () => {
|
|
499
|
+
const config = applyDefaults({ enabled: false });
|
|
500
|
+
assert.deepStrictEqual(config.smartCompaction, {
|
|
501
|
+
enabled: true,
|
|
502
|
+
classifier: null,
|
|
503
|
+
needsContextProbabilityThreshold: 0.5,
|
|
504
|
+
minAnswerConfidence: 0.5,
|
|
505
|
+
maxCandidates: 8,
|
|
506
|
+
});
|
|
507
|
+
});
|
|
508
|
+
|
|
509
|
+
it("an encoded default config carries all smart-compaction keys", () => {
|
|
510
|
+
const encoded = JSON.parse(encodeConfig(DEFAULT_CONFIG)) as {
|
|
511
|
+
smartCompaction: unknown;
|
|
512
|
+
};
|
|
513
|
+
assert.deepStrictEqual(encoded.smartCompaction, {
|
|
514
|
+
enabled: true,
|
|
515
|
+
classifier: null,
|
|
516
|
+
needsContextProbabilityThreshold: 0.5,
|
|
517
|
+
minAnswerConfidence: 0.5,
|
|
518
|
+
maxCandidates: 8,
|
|
519
|
+
});
|
|
520
|
+
});
|
|
521
|
+
|
|
522
|
+
it("an encoded default config omits the legacy probability aliases", () => {
|
|
523
|
+
const encoded = JSON.parse(encodeConfig(DEFAULT_CONFIG)) as {
|
|
524
|
+
smartCompaction: Record<string, unknown>;
|
|
525
|
+
};
|
|
526
|
+
assert.strictEqual("keepContextThreshold" in encoded.smartCompaction, false);
|
|
527
|
+
assert.strictEqual("keepContextMinConfidence" in encoded.smartCompaction, false);
|
|
528
|
+
});
|
|
529
|
+
|
|
530
|
+
it("a config file keeps a valid needs-context probability threshold", () => {
|
|
531
|
+
const config = applyDefaults({ smartCompaction: { needsContextProbabilityThreshold: 0.72 } });
|
|
532
|
+
assert.strictEqual(config.smartCompaction.needsContextProbabilityThreshold, 0.72);
|
|
533
|
+
});
|
|
534
|
+
|
|
535
|
+
it("an out-of-range needs-context probability threshold falls back to the default", () => {
|
|
536
|
+
for (const invalid of [0, 1, -0.1, 1.5]) {
|
|
537
|
+
const config = applyDefaults({
|
|
538
|
+
smartCompaction: { needsContextProbabilityThreshold: invalid },
|
|
539
|
+
});
|
|
540
|
+
assert.strictEqual(config.smartCompaction.needsContextProbabilityThreshold, 0.5);
|
|
541
|
+
}
|
|
542
|
+
});
|
|
543
|
+
|
|
544
|
+
it("a config file keeps a valid min answer confidence", () => {
|
|
545
|
+
const config = applyDefaults({ smartCompaction: { minAnswerConfidence: 0.72 } });
|
|
546
|
+
assert.strictEqual(config.smartCompaction.minAnswerConfidence, 0.72);
|
|
547
|
+
});
|
|
548
|
+
|
|
549
|
+
it("an out-of-range min answer confidence falls back to the default", () => {
|
|
550
|
+
for (const invalid of [0, 1, -0.1, 1.5]) {
|
|
551
|
+
const config = applyDefaults({ smartCompaction: { minAnswerConfidence: invalid } });
|
|
552
|
+
assert.strictEqual(config.smartCompaction.minAnswerConfidence, 0.5);
|
|
553
|
+
}
|
|
554
|
+
});
|
|
555
|
+
|
|
556
|
+
it("a config file with only the legacy probability keys decodes and resolves", () => {
|
|
557
|
+
const config = applyDefaults(
|
|
558
|
+
decodeConfig(
|
|
559
|
+
JSON.stringify({
|
|
560
|
+
smartCompaction: { keepContextThreshold: 0.72, keepContextMinConfidence: 0.31 },
|
|
561
|
+
}),
|
|
562
|
+
),
|
|
563
|
+
);
|
|
564
|
+
assert.strictEqual(config.smartCompaction.needsContextProbabilityThreshold, 0.72);
|
|
565
|
+
assert.strictEqual(config.smartCompaction.minAnswerConfidence, 0.31);
|
|
566
|
+
});
|
|
567
|
+
|
|
568
|
+
it("the current probability keys win over their legacy aliases", () => {
|
|
569
|
+
const config = applyDefaults({
|
|
570
|
+
smartCompaction: {
|
|
571
|
+
needsContextProbabilityThreshold: 0.72,
|
|
572
|
+
keepContextThreshold: 0.31,
|
|
573
|
+
minAnswerConfidence: 0.41,
|
|
574
|
+
keepContextMinConfidence: 0.21,
|
|
575
|
+
},
|
|
576
|
+
});
|
|
577
|
+
assert.strictEqual(config.smartCompaction.needsContextProbabilityThreshold, 0.72);
|
|
578
|
+
assert.strictEqual(config.smartCompaction.minAnswerConfidence, 0.41);
|
|
579
|
+
});
|
|
580
|
+
|
|
581
|
+
it("adjustSmartCompactionProbability steps by 0.05 and clamps inside the open interval", () => {
|
|
582
|
+
assert.strictEqual(adjustSmartCompactionProbability(0.5, 0.05), 0.55);
|
|
583
|
+
assert.strictEqual(adjustSmartCompactionProbability(0.5, -0.05), 0.45);
|
|
584
|
+
assert.strictEqual(adjustSmartCompactionProbability(0.95, 0.05), 0.95);
|
|
585
|
+
assert.strictEqual(adjustSmartCompactionProbability(0.05, -0.05), 0.05);
|
|
586
|
+
});
|
|
587
|
+
|
|
588
|
+
it("a config file keeps a valid max-candidates cap", () => {
|
|
589
|
+
const config = applyDefaults({ smartCompaction: { maxCandidates: 3 } });
|
|
590
|
+
assert.strictEqual(config.smartCompaction.maxCandidates, 3);
|
|
591
|
+
});
|
|
592
|
+
|
|
593
|
+
it("a cap that is not an integer in range falls back to the default", () => {
|
|
594
|
+
for (const invalid of [0, 21, 5.5, -1]) {
|
|
595
|
+
const config = applyDefaults({ smartCompaction: { maxCandidates: invalid } });
|
|
596
|
+
assert.strictEqual(config.smartCompaction.maxCandidates, 8);
|
|
597
|
+
}
|
|
598
|
+
});
|
|
599
|
+
|
|
600
|
+
it("adjustMaxCandidates steps by one and clamps to the bounds", () => {
|
|
601
|
+
assert.strictEqual(adjustMaxCandidates(8, 1), 9);
|
|
602
|
+
assert.strictEqual(adjustMaxCandidates(8, -1), 7);
|
|
603
|
+
assert.strictEqual(adjustMaxCandidates(20, 1), 20);
|
|
604
|
+
assert.strictEqual(adjustMaxCandidates(1, -1), 1);
|
|
605
|
+
});
|
|
606
|
+
|
|
607
|
+
it.effect("save keeps a chosen classifier through a load round trip", () =>
|
|
608
|
+
Effect.gen(function* () {
|
|
609
|
+
const mem = makeMemFs();
|
|
610
|
+
const config = yield* runWithMem(
|
|
611
|
+
mem,
|
|
612
|
+
Effect.gen(function* () {
|
|
613
|
+
const svc = yield* TuiConfigService;
|
|
614
|
+
yield* svc.save({
|
|
615
|
+
...DEFAULT_CONFIG,
|
|
616
|
+
smartCompaction: {
|
|
617
|
+
enabled: false,
|
|
618
|
+
classifier: "typesafe/jev-latest",
|
|
619
|
+
needsContextProbabilityThreshold: 0.8,
|
|
620
|
+
minAnswerConfidence: 0.8,
|
|
621
|
+
maxCandidates: 3,
|
|
622
|
+
},
|
|
623
|
+
});
|
|
624
|
+
return yield* svc.load;
|
|
625
|
+
}),
|
|
626
|
+
);
|
|
627
|
+
assert.deepStrictEqual(config.smartCompaction, {
|
|
628
|
+
enabled: false,
|
|
629
|
+
classifier: "typesafe/jev-latest",
|
|
630
|
+
needsContextProbabilityThreshold: 0.8,
|
|
631
|
+
minAnswerConfidence: 0.8,
|
|
632
|
+
maxCandidates: 3,
|
|
633
|
+
});
|
|
634
|
+
}),
|
|
635
|
+
);
|
package/src/config.ts
CHANGED
|
@@ -37,6 +37,13 @@ export class TuiConfig extends Schema.Class<TuiConfig>("tui/config/TuiConfig")({
|
|
|
37
37
|
stalls: Schema.Boolean,
|
|
38
38
|
cost: Schema.Boolean,
|
|
39
39
|
}),
|
|
40
|
+
smartCompaction: Schema.Struct({
|
|
41
|
+
enabled: Schema.Boolean,
|
|
42
|
+
classifier: Schema.NullOr(Schema.String),
|
|
43
|
+
needsContextProbabilityThreshold: Schema.Number,
|
|
44
|
+
minAnswerConfidence: Schema.Number,
|
|
45
|
+
maxCandidates: Schema.Number,
|
|
46
|
+
}),
|
|
40
47
|
}) {}
|
|
41
48
|
|
|
42
49
|
export type TelemetryConfig = TuiConfig["telemetry"];
|
|
@@ -66,8 +73,53 @@ export const DEFAULT_CONFIG: TuiConfig = {
|
|
|
66
73
|
stalls: true,
|
|
67
74
|
cost: true,
|
|
68
75
|
},
|
|
76
|
+
smartCompaction: {
|
|
77
|
+
enabled: true,
|
|
78
|
+
classifier: null,
|
|
79
|
+
needsContextProbabilityThreshold: 0.5,
|
|
80
|
+
minAnswerConfidence: 0.5,
|
|
81
|
+
maxCandidates: 8,
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Step and bounds for the settings dialog's two probability editors. The value
|
|
87
|
+
* must stay strictly inside (0, 1); the dialog clamps to this open interval so
|
|
88
|
+
* a user cannot write a value the tracker would reject.
|
|
89
|
+
*/
|
|
90
|
+
export const SMART_COMPACTION_PROBABILITY_STEP = 0.05;
|
|
91
|
+
export const SMART_COMPACTION_PROBABILITY_MIN = 0.05;
|
|
92
|
+
export const SMART_COMPACTION_PROBABILITY_MAX = 0.95;
|
|
93
|
+
|
|
94
|
+
/** True when `value` is a usable probability knob: strictly inside (0, 1). */
|
|
95
|
+
export const isSmartCompactionProbability = (value: number): boolean => value > 0 && value < 1;
|
|
96
|
+
|
|
97
|
+
/** Nudge a probability knob by `delta`, rounded to two decimals and kept inside the bounds. */
|
|
98
|
+
export const adjustSmartCompactionProbability = (value: number, delta: number): number => {
|
|
99
|
+
const next = Math.round((value + delta) * 100) / 100;
|
|
100
|
+
return Math.min(
|
|
101
|
+
SMART_COMPACTION_PROBABILITY_MAX,
|
|
102
|
+
Math.max(SMART_COMPACTION_PROBABILITY_MIN, next),
|
|
103
|
+
);
|
|
69
104
|
};
|
|
70
105
|
|
|
106
|
+
/**
|
|
107
|
+
* Step and bounds for the settings dialog's max-candidates editor. The tracker
|
|
108
|
+
* accepts an integer in [1, 20]; the dialog clamps to this interval.
|
|
109
|
+
*/
|
|
110
|
+
export const MAX_CANDIDATES_STEP = 1;
|
|
111
|
+
export const MAX_CANDIDATES_MIN = 1;
|
|
112
|
+
export const MAX_CANDIDATES_MAX = 20;
|
|
113
|
+
export const DEFAULT_MAX_CANDIDATES = 8;
|
|
114
|
+
|
|
115
|
+
/** True when `value` is a usable cap: an integer in [1, 20]. */
|
|
116
|
+
export const isMaxCandidates = (value: number): boolean =>
|
|
117
|
+
Number.isInteger(value) && value >= MAX_CANDIDATES_MIN && value <= MAX_CANDIDATES_MAX;
|
|
118
|
+
|
|
119
|
+
/** Nudge a cap by `delta`, clamped to the bounds. */
|
|
120
|
+
export const adjustMaxCandidates = (value: number, delta: number): number =>
|
|
121
|
+
Math.min(MAX_CANDIDATES_MAX, Math.max(MAX_CANDIDATES_MIN, Math.round(value + delta)));
|
|
122
|
+
|
|
71
123
|
export function getConfigPath(): string {
|
|
72
124
|
return join(getAgentDir(), CONFIG_FILE_NAME);
|
|
73
125
|
}
|
|
@@ -109,6 +161,19 @@ const FileSchema = Schema.fromJsonString(
|
|
|
109
161
|
cost: OptionalBoolean,
|
|
110
162
|
}),
|
|
111
163
|
),
|
|
164
|
+
smartCompaction: Schema.optional(
|
|
165
|
+
Schema.Struct({
|
|
166
|
+
enabled: OptionalBoolean,
|
|
167
|
+
classifier: Schema.optional(Schema.NullOr(Schema.String)),
|
|
168
|
+
needsContextProbabilityThreshold: Schema.optional(Schema.Finite),
|
|
169
|
+
minAnswerConfidence: Schema.optional(Schema.Finite),
|
|
170
|
+
// Pre-rename names. They stay declared and read as aliases, so an
|
|
171
|
+
// existing tui.json keeps working.
|
|
172
|
+
keepContextThreshold: Schema.optional(Schema.Finite),
|
|
173
|
+
keepContextMinConfidence: Schema.optional(Schema.Finite),
|
|
174
|
+
maxCandidates: Schema.optional(Schema.Int),
|
|
175
|
+
}),
|
|
176
|
+
),
|
|
112
177
|
}),
|
|
113
178
|
{ space: 2 },
|
|
114
179
|
);
|
|
@@ -120,6 +185,19 @@ export const decodeConfig = Schema.decodeSync(FileSchema);
|
|
|
120
185
|
|
|
121
186
|
export const decodeConfigEffect = Schema.decodeEffect(FileSchema);
|
|
122
187
|
|
|
188
|
+
/**
|
|
189
|
+
* Resolve one probability knob: the current key, then its legacy alias, then the
|
|
190
|
+
* default. The current key wins when present; a value outside (0, 1) is ignored.
|
|
191
|
+
*/
|
|
192
|
+
const probabilityValue = (
|
|
193
|
+
current: number | undefined,
|
|
194
|
+
legacy: number | undefined,
|
|
195
|
+
fallback: number,
|
|
196
|
+
): number => {
|
|
197
|
+
const raw = current ?? legacy;
|
|
198
|
+
return raw !== undefined && isSmartCompactionProbability(raw) ? raw : fallback;
|
|
199
|
+
};
|
|
200
|
+
|
|
123
201
|
export function applyDefaults(partial: TuiConfigFile): TuiConfig {
|
|
124
202
|
return {
|
|
125
203
|
enabled: partial.enabled ?? DEFAULT_CONFIG.enabled,
|
|
@@ -150,6 +228,25 @@ export function applyDefaults(partial: TuiConfigFile): TuiConfig {
|
|
|
150
228
|
stalls: partial.telemetry?.stalls ?? DEFAULT_CONFIG.telemetry.stalls,
|
|
151
229
|
cost: partial.telemetry?.cost ?? DEFAULT_CONFIG.telemetry.cost,
|
|
152
230
|
},
|
|
231
|
+
smartCompaction: {
|
|
232
|
+
enabled: partial.smartCompaction?.enabled ?? DEFAULT_CONFIG.smartCompaction.enabled,
|
|
233
|
+
classifier: partial.smartCompaction?.classifier ?? DEFAULT_CONFIG.smartCompaction.classifier,
|
|
234
|
+
needsContextProbabilityThreshold: probabilityValue(
|
|
235
|
+
partial.smartCompaction?.needsContextProbabilityThreshold,
|
|
236
|
+
partial.smartCompaction?.keepContextThreshold,
|
|
237
|
+
DEFAULT_CONFIG.smartCompaction.needsContextProbabilityThreshold,
|
|
238
|
+
),
|
|
239
|
+
minAnswerConfidence: probabilityValue(
|
|
240
|
+
partial.smartCompaction?.minAnswerConfidence,
|
|
241
|
+
partial.smartCompaction?.keepContextMinConfidence,
|
|
242
|
+
DEFAULT_CONFIG.smartCompaction.minAnswerConfidence,
|
|
243
|
+
),
|
|
244
|
+
maxCandidates:
|
|
245
|
+
partial.smartCompaction?.maxCandidates !== undefined &&
|
|
246
|
+
isMaxCandidates(partial.smartCompaction.maxCandidates)
|
|
247
|
+
? partial.smartCompaction.maxCandidates
|
|
248
|
+
: DEFAULT_CONFIG.smartCompaction.maxCandidates,
|
|
249
|
+
},
|
|
153
250
|
};
|
|
154
251
|
}
|
|
155
252
|
|
|
@@ -259,48 +356,3 @@ export class TuiConfigService extends Context.Service<
|
|
|
259
356
|
): Layer.Layer<TuiConfigService> =>
|
|
260
357
|
TuiConfigService.make(path).pipe(Layer.provide(FileSystem.layerNoop(fileSystem)));
|
|
261
358
|
}
|
|
262
|
-
|
|
263
|
-
// // ------------------------------------------------------------------
|
|
264
|
-
// // Temporary imperative wrappers for backwards compatibility.
|
|
265
|
-
// // TODO: remove these once src/index.ts is wired to TuiConfigService.
|
|
266
|
-
// // ------------------------------------------------------------------
|
|
267
|
-
//
|
|
268
|
-
// export function ensureConfigExists(): void {
|
|
269
|
-
// const path = getConfigPath();
|
|
270
|
-
// if (existsSync(path)) return;
|
|
271
|
-
// try {
|
|
272
|
-
// const agentDir = getAgentDir();
|
|
273
|
-
// if (!existsSync(agentDir)) mkdirSync(agentDir, { recursive: true });
|
|
274
|
-
// writeFileSync(path, JSON.stringify(DEFAULT_CONFIG, null, 2) + "\n", "utf8");
|
|
275
|
-
// } catch {}
|
|
276
|
-
// }
|
|
277
|
-
//
|
|
278
|
-
// export function loadConfig(notify?: (msg: string, level: "warning" | "info") => void): TuiConfig {
|
|
279
|
-
// const path = getConfigPath();
|
|
280
|
-
// if (!existsSync(path)) {
|
|
281
|
-
// ensureConfigExists();
|
|
282
|
-
// return applyDefaults({});
|
|
283
|
-
// }
|
|
284
|
-
//
|
|
285
|
-
// try {
|
|
286
|
-
// const raw = readFileSync(path, "utf8");
|
|
287
|
-
// const parsed: unknown = JSON.parse(raw);
|
|
288
|
-
// const partial = Schema.decodeUnknownSync(FileSchema, { onExcessProperty: "ignore" })(parsed);
|
|
289
|
-
// return applyDefaults(partial);
|
|
290
|
-
// } catch (err) {
|
|
291
|
-
// notify?.(
|
|
292
|
-
// `tui config parse error: ${err instanceof Error ? err.message : String(err)}`,
|
|
293
|
-
// "warning",
|
|
294
|
-
// );
|
|
295
|
-
// return applyDefaults({});
|
|
296
|
-
// }
|
|
297
|
-
// }
|
|
298
|
-
//
|
|
299
|
-
// export function saveConfig(config: TuiConfig): void {
|
|
300
|
-
// const path = getConfigPath();
|
|
301
|
-
// try {
|
|
302
|
-
// const agentDir = getAgentDir();
|
|
303
|
-
// if (!existsSync(agentDir)) mkdirSync(agentDir, { recursive: true });
|
|
304
|
-
// writeFileSync(path, JSON.stringify(config, null, 2) + "\n", "utf8");
|
|
305
|
-
// } catch {}
|
|
306
|
-
// }
|
package/src/index.ts
CHANGED
|
@@ -27,32 +27,6 @@ import * as NodeChildProcessSpawner from "@effect/platform-node/NodeChildProcess
|
|
|
27
27
|
import { VimRouter } from "./vim/vim-router.ts";
|
|
28
28
|
import { EditorTintService } from "./ui/editor-tint.ts";
|
|
29
29
|
|
|
30
|
-
function isInteractiveLaunch(): boolean {
|
|
31
|
-
if (!process.stdout.isTTY) return false;
|
|
32
|
-
const args = process.argv.slice(2);
|
|
33
|
-
const nonInteractiveFlags = [
|
|
34
|
-
"-p",
|
|
35
|
-
"--print",
|
|
36
|
-
"--help",
|
|
37
|
-
"-h",
|
|
38
|
-
"--version",
|
|
39
|
-
"-v",
|
|
40
|
-
"--list-models",
|
|
41
|
-
"--export",
|
|
42
|
-
];
|
|
43
|
-
for (const arg of args) {
|
|
44
|
-
if (nonInteractiveFlags.includes(arg)) return false;
|
|
45
|
-
if (arg.startsWith("--mode")) return false;
|
|
46
|
-
}
|
|
47
|
-
return true;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function clearVisibleScreen(): void {
|
|
51
|
-
if (process.stdout.isTTY) {
|
|
52
|
-
process.stdout.write("\x1b[2J\x1b[H");
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
30
|
function isTuiContext(ctx: ExtensionContext): boolean {
|
|
57
31
|
try {
|
|
58
32
|
const mode = (ctx as ExtensionContext & { mode?: string }).mode;
|
|
@@ -79,7 +53,6 @@ const main = Effect.fn("tui/main")(function* (pi: ExtensionAPI) {
|
|
|
79
53
|
let lastCtx: ExtensionContext | undefined;
|
|
80
54
|
let requestFooterRender: (() => void) | undefined;
|
|
81
55
|
let workingTimer: ReturnType<typeof setInterval> | undefined;
|
|
82
|
-
// TODO: configure
|
|
83
56
|
let cleanupHeader: (() => void) | undefined;
|
|
84
57
|
let cleanupFooter: (() => void) | undefined;
|
|
85
58
|
let cleanupEditor: (() => void) | undefined;
|
|
@@ -183,7 +156,10 @@ const main = Effect.fn("tui/main")(function* (pi: ExtensionAPI) {
|
|
|
183
156
|
requestFooterRender?.();
|
|
184
157
|
};
|
|
185
158
|
tick();
|
|
186
|
-
|
|
159
|
+
// The footer timer renders whole seconds (`formatDuration`), so a 1s
|
|
160
|
+
// cadence keeps the display exact and avoids 3 wasted full-layout
|
|
161
|
+
// re-renders per second.
|
|
162
|
+
workingTimer = setInterval(tick, 1000);
|
|
187
163
|
workingTimer.unref?.();
|
|
188
164
|
};
|
|
189
165
|
|
|
@@ -206,10 +182,6 @@ const main = Effect.fn("tui/main")(function* (pi: ExtensionAPI) {
|
|
|
206
182
|
|
|
207
183
|
config = yield* conf.load.pipe(Effect.mapError((e) => ctx.ui.notify(e.message, "error")));
|
|
208
184
|
|
|
209
|
-
if (isInteractiveLaunch() && config.enabled) {
|
|
210
|
-
clearVisibleScreen();
|
|
211
|
-
}
|
|
212
|
-
|
|
213
185
|
applyUi(ctx);
|
|
214
186
|
|
|
215
187
|
refreshInteractiveState(ctx, true);
|