@ftrdotdev/pi-tui 0.6.0 → 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/package.json +2 -2
- package/src/config.test.ts +63 -28
- package/src/config.ts +45 -31
- package/src/ui/footer.test.ts +2 -2
- package/src/ui/preview.test.ts +66 -0
- package/src/ui/preview.ts +15 -0
- package/src/ui/settings-command.test.ts +40 -32
- package/src/ui/settings-command.ts +37 -37
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,7 +58,7 @@
|
|
|
58
58
|
"effect": "4.0.0"
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
|
61
|
-
"@earendil-works/pi-tui": "1.0
|
|
61
|
+
"@earendil-works/pi-tui": "1.1.0",
|
|
62
62
|
"@effect/tsgo": "0.47.2",
|
|
63
63
|
"@effect/vitest": "4.0.0",
|
|
64
64
|
"@types/bun": "latest",
|
package/src/config.test.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { join } from "node:path";
|
|
|
6
6
|
import { fileURLToPath } from "node:url";
|
|
7
7
|
import { getAgentDir } from "@earendil-works/pi-coding-agent";
|
|
8
8
|
import {
|
|
9
|
-
|
|
9
|
+
adjustSmartCompactionProbability,
|
|
10
10
|
adjustMaxCandidates,
|
|
11
11
|
applyDefaults,
|
|
12
12
|
ConfigParseError,
|
|
@@ -489,8 +489,8 @@ it.effect("the shared contract fixture decodes into the smart-compaction section
|
|
|
489
489
|
const config = applyDefaults(decodeConfig(raw));
|
|
490
490
|
assert.strictEqual(config.smartCompaction.enabled, true);
|
|
491
491
|
assert.strictEqual(config.smartCompaction.classifier, "typesafe/jev-latest");
|
|
492
|
-
assert.strictEqual(config.smartCompaction.
|
|
493
|
-
assert.strictEqual(config.smartCompaction.
|
|
492
|
+
assert.strictEqual(config.smartCompaction.needsContextProbabilityThreshold, 0.5);
|
|
493
|
+
assert.strictEqual(config.smartCompaction.minAnswerConfidence, 0.5);
|
|
494
494
|
assert.strictEqual(config.smartCompaction.maxCandidates, 8);
|
|
495
495
|
}).pipe(Effect.provide(NodeFileSystem.layer)),
|
|
496
496
|
);
|
|
@@ -500,8 +500,8 @@ it("a config file without the smart-compaction section applies the smart-compact
|
|
|
500
500
|
assert.deepStrictEqual(config.smartCompaction, {
|
|
501
501
|
enabled: true,
|
|
502
502
|
classifier: null,
|
|
503
|
-
|
|
504
|
-
|
|
503
|
+
needsContextProbabilityThreshold: 0.5,
|
|
504
|
+
minAnswerConfidence: 0.5,
|
|
505
505
|
maxCandidates: 8,
|
|
506
506
|
});
|
|
507
507
|
});
|
|
@@ -513,41 +513,76 @@ it("an encoded default config carries all smart-compaction keys", () => {
|
|
|
513
513
|
assert.deepStrictEqual(encoded.smartCompaction, {
|
|
514
514
|
enabled: true,
|
|
515
515
|
classifier: null,
|
|
516
|
-
|
|
517
|
-
|
|
516
|
+
needsContextProbabilityThreshold: 0.5,
|
|
517
|
+
minAnswerConfidence: 0.5,
|
|
518
518
|
maxCandidates: 8,
|
|
519
519
|
});
|
|
520
520
|
});
|
|
521
521
|
|
|
522
|
-
it("
|
|
523
|
-
const
|
|
524
|
-
|
|
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);
|
|
525
533
|
});
|
|
526
534
|
|
|
527
|
-
it("an out-of-range
|
|
535
|
+
it("an out-of-range needs-context probability threshold falls back to the default", () => {
|
|
528
536
|
for (const invalid of [0, 1, -0.1, 1.5]) {
|
|
529
|
-
const config = applyDefaults({
|
|
530
|
-
|
|
537
|
+
const config = applyDefaults({
|
|
538
|
+
smartCompaction: { needsContextProbabilityThreshold: invalid },
|
|
539
|
+
});
|
|
540
|
+
assert.strictEqual(config.smartCompaction.needsContextProbabilityThreshold, 0.5);
|
|
531
541
|
}
|
|
532
542
|
});
|
|
533
543
|
|
|
534
|
-
it("a config file keeps a valid
|
|
535
|
-
const config = applyDefaults({ smartCompaction: {
|
|
536
|
-
assert.strictEqual(config.smartCompaction.
|
|
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);
|
|
537
547
|
});
|
|
538
548
|
|
|
539
|
-
it("an out-of-range
|
|
549
|
+
it("an out-of-range min answer confidence falls back to the default", () => {
|
|
540
550
|
for (const invalid of [0, 1, -0.1, 1.5]) {
|
|
541
|
-
const config = applyDefaults({ smartCompaction: {
|
|
542
|
-
assert.strictEqual(config.smartCompaction.
|
|
551
|
+
const config = applyDefaults({ smartCompaction: { minAnswerConfidence: invalid } });
|
|
552
|
+
assert.strictEqual(config.smartCompaction.minAnswerConfidence, 0.5);
|
|
543
553
|
}
|
|
544
554
|
});
|
|
545
555
|
|
|
546
|
-
it("
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
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);
|
|
551
586
|
});
|
|
552
587
|
|
|
553
588
|
it("a config file keeps a valid max-candidates cap", () => {
|
|
@@ -581,8 +616,8 @@ it.effect("save keeps a chosen classifier through a load round trip", () =>
|
|
|
581
616
|
smartCompaction: {
|
|
582
617
|
enabled: false,
|
|
583
618
|
classifier: "typesafe/jev-latest",
|
|
584
|
-
|
|
585
|
-
|
|
619
|
+
needsContextProbabilityThreshold: 0.8,
|
|
620
|
+
minAnswerConfidence: 0.8,
|
|
586
621
|
maxCandidates: 3,
|
|
587
622
|
},
|
|
588
623
|
});
|
|
@@ -592,8 +627,8 @@ it.effect("save keeps a chosen classifier through a load round trip", () =>
|
|
|
592
627
|
assert.deepStrictEqual(config.smartCompaction, {
|
|
593
628
|
enabled: false,
|
|
594
629
|
classifier: "typesafe/jev-latest",
|
|
595
|
-
|
|
596
|
-
|
|
630
|
+
needsContextProbabilityThreshold: 0.8,
|
|
631
|
+
minAnswerConfidence: 0.8,
|
|
597
632
|
maxCandidates: 3,
|
|
598
633
|
});
|
|
599
634
|
}),
|
package/src/config.ts
CHANGED
|
@@ -40,8 +40,8 @@ export class TuiConfig extends Schema.Class<TuiConfig>("tui/config/TuiConfig")({
|
|
|
40
40
|
smartCompaction: Schema.Struct({
|
|
41
41
|
enabled: Schema.Boolean,
|
|
42
42
|
classifier: Schema.NullOr(Schema.String),
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
needsContextProbabilityThreshold: Schema.Number,
|
|
44
|
+
minAnswerConfidence: Schema.Number,
|
|
45
45
|
maxCandidates: Schema.Number,
|
|
46
46
|
}),
|
|
47
47
|
}) {}
|
|
@@ -76,34 +76,31 @@ export const DEFAULT_CONFIG: TuiConfig = {
|
|
|
76
76
|
smartCompaction: {
|
|
77
77
|
enabled: true,
|
|
78
78
|
classifier: null,
|
|
79
|
-
|
|
80
|
-
|
|
79
|
+
needsContextProbabilityThreshold: 0.5,
|
|
80
|
+
minAnswerConfidence: 0.5,
|
|
81
81
|
maxCandidates: 8,
|
|
82
82
|
},
|
|
83
83
|
};
|
|
84
84
|
|
|
85
85
|
/**
|
|
86
|
-
* Step and bounds for the settings dialog's
|
|
87
|
-
* stay strictly inside (0, 1); the dialog clamps to this open interval so
|
|
88
|
-
* user cannot write a value the tracker would reject.
|
|
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
89
|
*/
|
|
90
|
-
export const
|
|
91
|
-
export const
|
|
92
|
-
export const
|
|
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
93
|
|
|
94
|
-
/** True when `value` is a usable
|
|
95
|
-
export const
|
|
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
96
|
|
|
97
|
-
/**
|
|
98
|
-
|
|
99
|
-
* tracker applies the same open-interval rule to both knobs.
|
|
100
|
-
*/
|
|
101
|
-
export const isKeepContextMinConfidence = isKeepContextThreshold;
|
|
102
|
-
|
|
103
|
-
/** Nudge a threshold by `delta`, rounded to two decimals and kept inside the bounds. */
|
|
104
|
-
export const adjustKeepContextThreshold = (value: number, delta: number): number => {
|
|
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 => {
|
|
105
99
|
const next = Math.round((value + delta) * 100) / 100;
|
|
106
|
-
return Math.min(
|
|
100
|
+
return Math.min(
|
|
101
|
+
SMART_COMPACTION_PROBABILITY_MAX,
|
|
102
|
+
Math.max(SMART_COMPACTION_PROBABILITY_MIN, next),
|
|
103
|
+
);
|
|
107
104
|
};
|
|
108
105
|
|
|
109
106
|
/**
|
|
@@ -168,6 +165,10 @@ const FileSchema = Schema.fromJsonString(
|
|
|
168
165
|
Schema.Struct({
|
|
169
166
|
enabled: OptionalBoolean,
|
|
170
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.
|
|
171
172
|
keepContextThreshold: Schema.optional(Schema.Finite),
|
|
172
173
|
keepContextMinConfidence: Schema.optional(Schema.Finite),
|
|
173
174
|
maxCandidates: Schema.optional(Schema.Int),
|
|
@@ -184,6 +185,19 @@ export const decodeConfig = Schema.decodeSync(FileSchema);
|
|
|
184
185
|
|
|
185
186
|
export const decodeConfigEffect = Schema.decodeEffect(FileSchema);
|
|
186
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
|
+
|
|
187
201
|
export function applyDefaults(partial: TuiConfigFile): TuiConfig {
|
|
188
202
|
return {
|
|
189
203
|
enabled: partial.enabled ?? DEFAULT_CONFIG.enabled,
|
|
@@ -217,16 +231,16 @@ export function applyDefaults(partial: TuiConfigFile): TuiConfig {
|
|
|
217
231
|
smartCompaction: {
|
|
218
232
|
enabled: partial.smartCompaction?.enabled ?? DEFAULT_CONFIG.smartCompaction.enabled,
|
|
219
233
|
classifier: partial.smartCompaction?.classifier ?? DEFAULT_CONFIG.smartCompaction.classifier,
|
|
220
|
-
|
|
221
|
-
partial.smartCompaction?.
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
partial.smartCompaction?.
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
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
|
+
),
|
|
230
244
|
maxCandidates:
|
|
231
245
|
partial.smartCompaction?.maxCandidates !== undefined &&
|
|
232
246
|
isMaxCandidates(partial.smartCompaction.maxCandidates)
|
package/src/ui/footer.test.ts
CHANGED
|
@@ -79,8 +79,8 @@ const config: TuiConfig = {
|
|
|
79
79
|
smartCompaction: {
|
|
80
80
|
enabled: true,
|
|
81
81
|
classifier: null,
|
|
82
|
-
|
|
83
|
-
|
|
82
|
+
needsContextProbabilityThreshold: 0.5,
|
|
83
|
+
minAnswerConfidence: 0.5,
|
|
84
84
|
maxCandidates: 8,
|
|
85
85
|
},
|
|
86
86
|
};
|
package/src/ui/preview.test.ts
CHANGED
|
@@ -511,6 +511,7 @@ class FakePi {
|
|
|
511
511
|
}> = [];
|
|
512
512
|
readonly entries: Array<{ type: string; data?: unknown }> = [];
|
|
513
513
|
readonly toolResultHandlers: Array<(event: any) => any> = [];
|
|
514
|
+
readonly toolExecutionEndHandlers: Array<(event: any, ctx?: any) => any> = [];
|
|
514
515
|
registerTool(tool: ToolDefinition<any, any, any>): void {
|
|
515
516
|
this.tools.push(tool);
|
|
516
517
|
}
|
|
@@ -525,6 +526,7 @@ class FakePi {
|
|
|
525
526
|
}
|
|
526
527
|
on(event: string, handler: any): void {
|
|
527
528
|
if (event === "tool_result") this.toolResultHandlers.push(handler);
|
|
529
|
+
if (event === "tool_execution_end") this.toolExecutionEndHandlers.push(handler);
|
|
528
530
|
}
|
|
529
531
|
}
|
|
530
532
|
|
|
@@ -1050,3 +1052,67 @@ it("the entry renderer draws image entries as caption box + spacer + bare kitty
|
|
|
1050
1052
|
resetCapabilitiesCache();
|
|
1051
1053
|
}
|
|
1052
1054
|
});
|
|
1055
|
+
|
|
1056
|
+
// ---------------------------------------------------------------------------
|
|
1057
|
+
// Slice 6 — nested (codemode) previews append a renderable entry
|
|
1058
|
+
// ---------------------------------------------------------------------------
|
|
1059
|
+
|
|
1060
|
+
const TEXT_RECORD: TextPreview = {
|
|
1061
|
+
kind: "text",
|
|
1062
|
+
path: "/cwd/file.md",
|
|
1063
|
+
content: "# Hi",
|
|
1064
|
+
lang: "markdown",
|
|
1065
|
+
truncated: false,
|
|
1066
|
+
};
|
|
1067
|
+
|
|
1068
|
+
const nestedEndEvent = (overrides: Record<string, unknown> = {}) => ({
|
|
1069
|
+
type: "tool_execution_end",
|
|
1070
|
+
toolCallId: "call-1/1",
|
|
1071
|
+
toolName: "preview",
|
|
1072
|
+
result: { content: [], details: TEXT_RECORD },
|
|
1073
|
+
isError: false,
|
|
1074
|
+
parentToolCallId: "call-1",
|
|
1075
|
+
...overrides,
|
|
1076
|
+
});
|
|
1077
|
+
|
|
1078
|
+
const registerEndHook = () => {
|
|
1079
|
+
const pi = new FakePi();
|
|
1080
|
+
registerPreview(pi as unknown as ExtensionAPI, makePreviewContext(makeMemFs()));
|
|
1081
|
+
return { pi, handler: pi.toolExecutionEndHandlers[0]! };
|
|
1082
|
+
};
|
|
1083
|
+
|
|
1084
|
+
it("the nested-preview hook appends the display record so the entry renderer can draw it", () => {
|
|
1085
|
+
const { pi, handler } = registerEndHook();
|
|
1086
|
+
assert.strictEqual(pi.toolExecutionEndHandlers.length, 1);
|
|
1087
|
+
handler(nestedEndEvent(), { mode: "tui" });
|
|
1088
|
+
assert.deepStrictEqual(pi.entries, [{ type: "preview", data: TEXT_RECORD }]);
|
|
1089
|
+
});
|
|
1090
|
+
|
|
1091
|
+
it("the nested-preview hook ignores model-issued (top-level) preview ends", () => {
|
|
1092
|
+
const { pi, handler } = registerEndHook();
|
|
1093
|
+
handler(nestedEndEvent({ parentToolCallId: undefined }), { mode: "tui" });
|
|
1094
|
+
assert.strictEqual(pi.entries.length, 0);
|
|
1095
|
+
});
|
|
1096
|
+
|
|
1097
|
+
it("the nested-preview hook ignores nested ends for other tools", () => {
|
|
1098
|
+
const { pi, handler } = registerEndHook();
|
|
1099
|
+
handler(nestedEndEvent({ toolName: "read" }), { mode: "tui" });
|
|
1100
|
+
assert.strictEqual(pi.entries.length, 0);
|
|
1101
|
+
});
|
|
1102
|
+
|
|
1103
|
+
it("the nested-preview hook ignores non-tui modes", () => {
|
|
1104
|
+
const { pi, handler } = registerEndHook();
|
|
1105
|
+
handler(nestedEndEvent(), { mode: "rpc" });
|
|
1106
|
+
assert.strictEqual(pi.entries.length, 0);
|
|
1107
|
+
});
|
|
1108
|
+
|
|
1109
|
+
it("the nested-preview hook ignores failed previews", () => {
|
|
1110
|
+
const { pi, handler } = registerEndHook();
|
|
1111
|
+
handler(
|
|
1112
|
+
nestedEndEvent({
|
|
1113
|
+
result: { content: [], details: { ...TEXT_RECORD, content: "", error: "boom" } },
|
|
1114
|
+
}),
|
|
1115
|
+
{ mode: "tui" },
|
|
1116
|
+
);
|
|
1117
|
+
assert.strictEqual(pi.entries.length, 0);
|
|
1118
|
+
});
|
package/src/ui/preview.ts
CHANGED
|
@@ -590,6 +590,21 @@ export function registerPreview(
|
|
|
590
590
|
});
|
|
591
591
|
});
|
|
592
592
|
|
|
593
|
+
// A preview called from inside a codemode script never gets its own tool row:
|
|
594
|
+
// pi's interactive mode ignores nested `tool_execution_*` events, and nested
|
|
595
|
+
// results never become transcript entries. The widget that `renderResult`
|
|
596
|
+
// draws for model-issued calls is therefore dropped, and codemode's renderer
|
|
597
|
+
// shows only the text call-row. Mirror the `/preview` command and append the
|
|
598
|
+
// display record as a custom entry so the entry renderer above draws it.
|
|
599
|
+
pi.on("tool_execution_end", (event, ctx) => {
|
|
600
|
+
if (!event.parentToolCallId || event.toolName !== "preview") return;
|
|
601
|
+
if (ctx.mode !== "tui") return;
|
|
602
|
+
const data = (event.result as { details?: PreviewData | PreviewDataError } | undefined)
|
|
603
|
+
?.details;
|
|
604
|
+
if (!data || "error" in data) return;
|
|
605
|
+
pi.appendEntry("preview", data);
|
|
606
|
+
});
|
|
607
|
+
|
|
593
608
|
pi.registerCommand("preview", {
|
|
594
609
|
description:
|
|
595
610
|
"Display a file in the chat for the user to read (TUI only, not sent to the model).",
|
|
@@ -258,12 +258,12 @@ const goToCompaction = (ui: SettingsUiHandle): void => {
|
|
|
258
258
|
ui.handleInput("\t");
|
|
259
259
|
};
|
|
260
260
|
|
|
261
|
-
type CompactionRow = "toggle" | "classifier" | "
|
|
261
|
+
type CompactionRow = "toggle" | "classifier" | "probability" | "answerConfidence" | "cap";
|
|
262
262
|
const ROW_OFFSET: Record<CompactionRow, number> = {
|
|
263
263
|
toggle: 0,
|
|
264
264
|
classifier: 1,
|
|
265
|
-
|
|
266
|
-
|
|
265
|
+
probability: 2,
|
|
266
|
+
answerConfidence: 3,
|
|
267
267
|
cap: 4,
|
|
268
268
|
};
|
|
269
269
|
|
|
@@ -284,18 +284,21 @@ it("the Compaction tab is hidden when the tracker extension is not loaded", () =
|
|
|
284
284
|
);
|
|
285
285
|
});
|
|
286
286
|
|
|
287
|
-
it("the Compaction tab shows the toggle, classifier,
|
|
287
|
+
it("the Compaction tab shows the toggle, classifier, two probability knobs, and cap", () => {
|
|
288
288
|
const { ui } = makeUi();
|
|
289
289
|
goToCompaction(ui);
|
|
290
290
|
const lines = rendered(ui);
|
|
291
291
|
for (const label of [
|
|
292
292
|
"Smart compaction",
|
|
293
293
|
"Compaction classifier",
|
|
294
|
-
"
|
|
295
|
-
"
|
|
294
|
+
"Needs-context probability",
|
|
295
|
+
"Answer confidence floor",
|
|
296
296
|
"Max candidates",
|
|
297
297
|
]) {
|
|
298
|
-
assert.strictEqual(
|
|
298
|
+
assert.strictEqual(
|
|
299
|
+
lines.some((line) => line.includes(label)),
|
|
300
|
+
true,
|
|
301
|
+
);
|
|
299
302
|
}
|
|
300
303
|
});
|
|
301
304
|
|
|
@@ -358,72 +361,74 @@ it("the Compaction tab adds exactly the five smart-compaction rows", () => {
|
|
|
358
361
|
assert.strictEqual(selectedShows(ui, "Smart compaction"), true);
|
|
359
362
|
});
|
|
360
363
|
|
|
361
|
-
it("the
|
|
364
|
+
it("the needs-context probability row shows the current value with two decimals", () => {
|
|
362
365
|
const { ui } = makeUi({
|
|
363
|
-
smartCompaction: { ...DEFAULT_CONFIG.smartCompaction,
|
|
366
|
+
smartCompaction: { ...DEFAULT_CONFIG.smartCompaction, needsContextProbabilityThreshold: 0.7 },
|
|
364
367
|
});
|
|
365
368
|
goToCompaction(ui);
|
|
366
369
|
assert.strictEqual(
|
|
367
|
-
rendered(ui).some(
|
|
370
|
+
rendered(ui).some(
|
|
371
|
+
(line) => line.includes("Needs-context probability") && line.includes("0.70"),
|
|
372
|
+
),
|
|
368
373
|
true,
|
|
369
374
|
);
|
|
370
375
|
});
|
|
371
376
|
|
|
372
|
-
it("Enter on the
|
|
377
|
+
it("Enter on the needs-context probability row steps the value up by 0.05", () => {
|
|
373
378
|
const { ui, changes } = makeUi();
|
|
374
|
-
selectCompactionRow(ui, "
|
|
375
|
-
assert.strictEqual(selectedShows(ui, "
|
|
379
|
+
selectCompactionRow(ui, "probability");
|
|
380
|
+
assert.strictEqual(selectedShows(ui, "Needs-context probability"), true);
|
|
376
381
|
|
|
377
382
|
ui.handleInput("\r");
|
|
378
383
|
|
|
379
384
|
assert.strictEqual(changes.length, 1);
|
|
380
|
-
assert.strictEqual(changes[0]!.smartCompaction.
|
|
385
|
+
assert.strictEqual(changes[0]!.smartCompaction.needsContextProbabilityThreshold, 0.55);
|
|
381
386
|
});
|
|
382
387
|
|
|
383
|
-
it("the +/- keys adjust the
|
|
388
|
+
it("the +/- keys adjust the needs-context probability row and clamp inside the open interval", () => {
|
|
384
389
|
const { ui, changes } = makeUi({
|
|
385
|
-
smartCompaction: { ...DEFAULT_CONFIG.smartCompaction,
|
|
390
|
+
smartCompaction: { ...DEFAULT_CONFIG.smartCompaction, needsContextProbabilityThreshold: 0.95 },
|
|
386
391
|
});
|
|
387
|
-
selectCompactionRow(ui, "
|
|
392
|
+
selectCompactionRow(ui, "probability");
|
|
388
393
|
|
|
389
394
|
ui.handleInput("+");
|
|
390
|
-
assert.strictEqual(changes.at(-1)?.smartCompaction.
|
|
395
|
+
assert.strictEqual(changes.at(-1)?.smartCompaction.needsContextProbabilityThreshold, 0.95);
|
|
391
396
|
ui.handleInput("-");
|
|
392
|
-
assert.strictEqual(changes.at(-1)?.smartCompaction.
|
|
397
|
+
assert.strictEqual(changes.at(-1)?.smartCompaction.needsContextProbabilityThreshold, 0.9);
|
|
393
398
|
});
|
|
394
399
|
|
|
395
|
-
it("the
|
|
400
|
+
it("the answer confidence floor row shows the current value with two decimals", () => {
|
|
396
401
|
const { ui } = makeUi({
|
|
397
|
-
smartCompaction: { ...DEFAULT_CONFIG.smartCompaction,
|
|
402
|
+
smartCompaction: { ...DEFAULT_CONFIG.smartCompaction, minAnswerConfidence: 0.7 },
|
|
398
403
|
});
|
|
399
404
|
goToCompaction(ui);
|
|
400
405
|
assert.strictEqual(
|
|
401
|
-
rendered(ui).some((line) => line.includes("
|
|
406
|
+
rendered(ui).some((line) => line.includes("Answer confidence floor") && line.includes("0.70")),
|
|
402
407
|
true,
|
|
403
408
|
);
|
|
404
409
|
});
|
|
405
410
|
|
|
406
|
-
it("Enter on the
|
|
411
|
+
it("Enter on the answer confidence floor row steps the value up by 0.05", () => {
|
|
407
412
|
const { ui, changes } = makeUi();
|
|
408
|
-
selectCompactionRow(ui, "
|
|
409
|
-
assert.strictEqual(selectedShows(ui, "
|
|
413
|
+
selectCompactionRow(ui, "answerConfidence");
|
|
414
|
+
assert.strictEqual(selectedShows(ui, "Answer confidence floor"), true);
|
|
410
415
|
|
|
411
416
|
ui.handleInput("\r");
|
|
412
417
|
|
|
413
418
|
assert.strictEqual(changes.length, 1);
|
|
414
|
-
assert.strictEqual(changes[0]!.smartCompaction.
|
|
419
|
+
assert.strictEqual(changes[0]!.smartCompaction.minAnswerConfidence, 0.55);
|
|
415
420
|
});
|
|
416
421
|
|
|
417
|
-
it("the +/- keys adjust the
|
|
422
|
+
it("the +/- keys adjust the answer confidence floor row and clamp inside the open interval", () => {
|
|
418
423
|
const { ui, changes } = makeUi({
|
|
419
|
-
smartCompaction: { ...DEFAULT_CONFIG.smartCompaction,
|
|
424
|
+
smartCompaction: { ...DEFAULT_CONFIG.smartCompaction, minAnswerConfidence: 0.95 },
|
|
420
425
|
});
|
|
421
|
-
selectCompactionRow(ui, "
|
|
426
|
+
selectCompactionRow(ui, "answerConfidence");
|
|
422
427
|
|
|
423
428
|
ui.handleInput("+");
|
|
424
|
-
assert.strictEqual(changes.at(-1)?.smartCompaction.
|
|
429
|
+
assert.strictEqual(changes.at(-1)?.smartCompaction.minAnswerConfidence, 0.95);
|
|
425
430
|
ui.handleInput("-");
|
|
426
|
-
assert.strictEqual(changes.at(-1)?.smartCompaction.
|
|
431
|
+
assert.strictEqual(changes.at(-1)?.smartCompaction.minAnswerConfidence, 0.9);
|
|
427
432
|
});
|
|
428
433
|
|
|
429
434
|
it("the cap row shows the integer value", () => {
|
|
@@ -486,7 +491,10 @@ it("hasTrackerExtension is true when the tracker extension command is registered
|
|
|
486
491
|
});
|
|
487
492
|
|
|
488
493
|
it("hasTrackerExtension ignores a non-extension command named tracker", () => {
|
|
489
|
-
assert.strictEqual(
|
|
494
|
+
assert.strictEqual(
|
|
495
|
+
hasTrackerExtension(probe([], [{ name: "tracker", source: "prompt" }])),
|
|
496
|
+
false,
|
|
497
|
+
);
|
|
490
498
|
});
|
|
491
499
|
|
|
492
500
|
it("hasTrackerExtension is false when the tracker is not loaded", () => {
|
|
@@ -10,9 +10,9 @@ import {
|
|
|
10
10
|
} from "@earendil-works/pi-tui";
|
|
11
11
|
import { makeBorderedBox } from "../components/bordered-box.ts";
|
|
12
12
|
import {
|
|
13
|
-
|
|
13
|
+
adjustSmartCompactionProbability,
|
|
14
14
|
adjustMaxCandidates,
|
|
15
|
-
|
|
15
|
+
SMART_COMPACTION_PROBABILITY_STEP,
|
|
16
16
|
MAX_CANDIDATES_STEP,
|
|
17
17
|
type IconMode,
|
|
18
18
|
type TuiConfig,
|
|
@@ -48,7 +48,7 @@ const COPY = {
|
|
|
48
48
|
segments: "Footer",
|
|
49
49
|
telemetry: "Telemetry",
|
|
50
50
|
},
|
|
51
|
-
hint: "Tab/Shift+Tab/←/→/h/l: tabs · ↑/↓/j/k: move · Enter/Space: change · +/−:
|
|
51
|
+
hint: "Tab/Shift+Tab/←/→/h/l: tabs · ↑/↓/j/k: move · Enter/Space: change · +/−: step value · Esc/q: close",
|
|
52
52
|
labels: {
|
|
53
53
|
enabled: "Enabled",
|
|
54
54
|
vim: "Vim mode",
|
|
@@ -69,8 +69,8 @@ const COPY = {
|
|
|
69
69
|
costRate: "Cost rate",
|
|
70
70
|
smartCompactionEnabled: "Smart compaction",
|
|
71
71
|
smartCompactionClassifier: "Compaction classifier",
|
|
72
|
-
|
|
73
|
-
|
|
72
|
+
smartCompactionNeedsContextProbability: "Needs-context probability",
|
|
73
|
+
smartCompactionMinAnswerConfidence: "Answer confidence floor",
|
|
74
74
|
smartCompactionMaxCandidates: "Max candidates",
|
|
75
75
|
},
|
|
76
76
|
values: {
|
|
@@ -130,9 +130,7 @@ export interface ClassifierDescriptor {
|
|
|
130
130
|
/** The classifier fields this dialog needs from the model registry. Structural,
|
|
131
131
|
* so `ctx.modelRegistry` satisfies it and tests pass a plain object. */
|
|
132
132
|
export interface ClassifierSource {
|
|
133
|
-
readonly getAvailableOfType: (
|
|
134
|
-
type: "classifier",
|
|
135
|
-
) => Promise<readonly ClassifierDescriptor[]>;
|
|
133
|
+
readonly getAvailableOfType: (type: "classifier") => Promise<readonly ClassifierDescriptor[]>;
|
|
136
134
|
readonly getModelsOfType: (type: "classifier") => readonly ClassifierDescriptor[];
|
|
137
135
|
}
|
|
138
136
|
|
|
@@ -210,8 +208,8 @@ function cycleClassifier(config: TuiConfig, choices: readonly ClassifierChoice[]
|
|
|
210
208
|
return { ...config, smartCompaction: { ...config.smartCompaction, classifier: next.value } };
|
|
211
209
|
}
|
|
212
210
|
|
|
213
|
-
/** Two-decimal display for the
|
|
214
|
-
const
|
|
211
|
+
/** Two-decimal display for the probability rows. */
|
|
212
|
+
const formatProbability = (value: number): string => value.toFixed(2);
|
|
215
213
|
|
|
216
214
|
function buildFeaturesItems(config: TuiConfig, copy: SettingsCopy): SettingItem[] {
|
|
217
215
|
return [
|
|
@@ -253,14 +251,14 @@ function buildCompactionItems(
|
|
|
253
251
|
currentValue: classifierLabel(choices, config.smartCompaction.classifier),
|
|
254
252
|
},
|
|
255
253
|
{
|
|
256
|
-
id: "
|
|
257
|
-
label: copy.labels.
|
|
258
|
-
currentValue:
|
|
254
|
+
id: "smartCompactionNeedsContextProbability",
|
|
255
|
+
label: copy.labels.smartCompactionNeedsContextProbability,
|
|
256
|
+
currentValue: formatProbability(config.smartCompaction.needsContextProbabilityThreshold),
|
|
259
257
|
},
|
|
260
258
|
{
|
|
261
|
-
id: "
|
|
262
|
-
label: copy.labels.
|
|
263
|
-
currentValue:
|
|
259
|
+
id: "smartCompactionMinAnswerConfidence",
|
|
260
|
+
label: copy.labels.smartCompactionMinAnswerConfidence,
|
|
261
|
+
currentValue: formatProbability(config.smartCompaction.minAnswerConfidence),
|
|
264
262
|
},
|
|
265
263
|
{
|
|
266
264
|
id: "smartCompactionMaxCandidates",
|
|
@@ -389,34 +387,34 @@ export const makeSettingsUi = (
|
|
|
389
387
|
let cachedLines: string[] | undefined;
|
|
390
388
|
let compact = false;
|
|
391
389
|
|
|
392
|
-
const
|
|
390
|
+
const adjustNeedsContextProbability = (delta: number): void => {
|
|
393
391
|
currentConfig = {
|
|
394
392
|
...currentConfig,
|
|
395
393
|
smartCompaction: {
|
|
396
394
|
...currentConfig.smartCompaction,
|
|
397
|
-
|
|
398
|
-
currentConfig.smartCompaction.
|
|
395
|
+
needsContextProbabilityThreshold: adjustSmartCompactionProbability(
|
|
396
|
+
currentConfig.smartCompaction.needsContextProbabilityThreshold,
|
|
399
397
|
delta,
|
|
400
398
|
),
|
|
401
399
|
},
|
|
402
400
|
};
|
|
403
401
|
onChange(currentConfig);
|
|
404
|
-
rebuild("
|
|
402
|
+
rebuild("smartCompactionNeedsContextProbability");
|
|
405
403
|
};
|
|
406
404
|
|
|
407
|
-
const
|
|
405
|
+
const adjustMinAnswerConfidence = (delta: number): void => {
|
|
408
406
|
currentConfig = {
|
|
409
407
|
...currentConfig,
|
|
410
408
|
smartCompaction: {
|
|
411
409
|
...currentConfig.smartCompaction,
|
|
412
|
-
|
|
413
|
-
currentConfig.smartCompaction.
|
|
410
|
+
minAnswerConfidence: adjustSmartCompactionProbability(
|
|
411
|
+
currentConfig.smartCompaction.minAnswerConfidence,
|
|
414
412
|
delta,
|
|
415
413
|
),
|
|
416
414
|
},
|
|
417
415
|
};
|
|
418
416
|
onChange(currentConfig);
|
|
419
|
-
rebuild("
|
|
417
|
+
rebuild("smartCompactionMinAnswerConfidence");
|
|
420
418
|
};
|
|
421
419
|
|
|
422
420
|
const adjustMaxCandidatesBy = (delta: number): void => {
|
|
@@ -435,12 +433,12 @@ export const makeSettingsUi = (
|
|
|
435
433
|
selectedItemByTab[tab] = itemId;
|
|
436
434
|
// The numeric rows have no enumerated value: Enter/Space steps them up, and
|
|
437
435
|
// the +/− keys step them either way.
|
|
438
|
-
if (itemId === "
|
|
439
|
-
|
|
436
|
+
if (itemId === "smartCompactionNeedsContextProbability") {
|
|
437
|
+
adjustNeedsContextProbability(SMART_COMPACTION_PROBABILITY_STEP);
|
|
440
438
|
return;
|
|
441
439
|
}
|
|
442
|
-
if (itemId === "
|
|
443
|
-
|
|
440
|
+
if (itemId === "smartCompactionMinAnswerConfidence") {
|
|
441
|
+
adjustMinAnswerConfidence(SMART_COMPACTION_PROBABILITY_STEP);
|
|
444
442
|
return;
|
|
445
443
|
}
|
|
446
444
|
if (itemId === "smartCompactionMaxCandidates") {
|
|
@@ -462,11 +460,13 @@ export const makeSettingsUi = (
|
|
|
462
460
|
const copy = COPY[currentConfig.settingsLanguage];
|
|
463
461
|
body.clear();
|
|
464
462
|
|
|
465
|
-
const tabBar = tabs
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
463
|
+
const tabBar = tabs
|
|
464
|
+
.map((tabName) => {
|
|
465
|
+
const active = tabName === tab;
|
|
466
|
+
const label = active ? `[${copy.tabs[tabName]}]` : ` ${copy.tabs[tabName]} `;
|
|
467
|
+
return active ? theme.fg("accent", label) : theme.fg("dim", label);
|
|
468
|
+
})
|
|
469
|
+
.join(" ");
|
|
470
470
|
body.addChild(new Text(tabBar, 0, 0));
|
|
471
471
|
body.addChild(new Text(theme.fg("dim", copy.hint), 0, 0));
|
|
472
472
|
|
|
@@ -556,10 +556,10 @@ export const makeSettingsUi = (
|
|
|
556
556
|
} else if (data === "+" || data === "=" || data === "-" || data === "_") {
|
|
557
557
|
const selected = selectList.getSelectedItem()?.value;
|
|
558
558
|
const sign = data === "+" || data === "=" ? 1 : -1;
|
|
559
|
-
if (selected === "
|
|
560
|
-
|
|
561
|
-
} else if (selected === "
|
|
562
|
-
|
|
559
|
+
if (selected === "smartCompactionNeedsContextProbability") {
|
|
560
|
+
adjustNeedsContextProbability(sign * SMART_COMPACTION_PROBABILITY_STEP);
|
|
561
|
+
} else if (selected === "smartCompactionMinAnswerConfidence") {
|
|
562
|
+
adjustMinAnswerConfidence(sign * SMART_COMPACTION_PROBABILITY_STEP);
|
|
563
563
|
} else if (selected === "smartCompactionMaxCandidates") {
|
|
564
564
|
adjustMaxCandidatesBy(sign * MAX_CANDIDATES_STEP);
|
|
565
565
|
} else {
|