@bismawy/pi-arnative 0.16.1 → 0.18.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 +25 -16
- package/extensions/index.ts +41 -0
- package/lib/active-clock.ts +91 -0
- package/lib/ansi.ts +40 -78
- package/lib/box.ts +49 -68
- package/lib/chatbox.ts +371 -0
- package/lib/color.ts +3 -31
- package/lib/compat.ts +0 -60
- package/lib/edit-diff.ts +199 -0
- package/{extensions → lib/features}/arnative.ts +96 -423
- package/{extensions/autocompact.ts → lib/features/auto-compact.ts} +30 -327
- package/{extensions → lib/features}/budget.ts +17 -242
- package/lib/features/footer.ts +2232 -0
- package/{extensions/section-headers.ts → lib/features/headers.ts} +38 -49
- package/{extensions → lib/features}/model-heal.ts +5 -28
- package/lib/features/progress-group.ts +1557 -0
- package/{extensions → lib/features}/render-cache.ts +113 -161
- package/{extensions → lib/features}/timestamps.ts +18 -94
- package/{extensions → lib/features}/todos.ts +44 -158
- package/lib/features/tools.ts +1202 -0
- package/lib/features/ui-render-tweaks.ts +606 -0
- package/lib/features/usage.ts +786 -0
- package/lib/format.ts +22 -4
- package/lib/git-status.ts +164 -0
- package/lib/list-picker.ts +1 -127
- package/lib/model-heal.ts +70 -162
- package/lib/patch.ts +0 -63
- package/lib/preset-store.ts +17 -133
- package/lib/provider-store.ts +573 -0
- package/lib/provider.ts +52 -851
- package/lib/runtime.ts +209 -0
- package/lib/shortcuts.ts +8 -58
- package/lib/spinner.ts +88 -162
- package/lib/status-widget.ts +4 -30
- package/lib/todos.ts +20 -143
- package/lib/usage-pricing.ts +143 -0
- package/lib/usage-store.ts +44 -378
- package/package.json +5 -6
- package/themes/arnative-blossom.json +0 -0
- package/themes/arnative-crimson.json +0 -0
- package/themes/arnative-cyberpunk.json +0 -0
- package/themes/arnative-dracula.json +0 -0
- package/themes/arnative-earthy.json +0 -0
- package/themes/arnative-garden.json +0 -0
- package/themes/arnative-gruvbox.json +0 -0
- package/themes/arnative-lemonade.json +0 -0
- package/themes/arnative-magical.json +0 -0
- package/themes/arnative-matrix.json +0 -0
- package/themes/arnative-neutral.json +0 -0
- package/themes/arnative-nord.json +0 -0
- package/themes/arnative-zinc.json +0 -0
- package/themes/arnative.json +0 -0
- package/CHANGELOG.md +0 -683
- package/extensions/animations.ts +0 -242
- package/extensions/footer.ts +0 -2617
- package/extensions/tools.ts +0 -2231
- package/extensions/ui-render-tweaks.ts +0 -1005
- package/extensions/usage-export.ts +0 -283
- package/extensions/usage.ts +0 -1406
- package/lib/check.ts +0 -21
- package/themes/gen-themes.mjs +0 -715
|
@@ -1,1005 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Six small patches to pi's fullscreen renderer (render layer only, session data
|
|
3
|
-
* untouched):
|
|
4
|
-
* 1. Hide pi's built-in "Reloading keybindings, extensions, skills..." box
|
|
5
|
-
* (hardcoded in handleReloadCommand, no auto-hide).
|
|
6
|
-
* 2. Drag selection: pi wraps it in reverse video (\x1b[7m), unreadable in some
|
|
7
|
-
* terminals/themes -> explicit colors (bg selectedBg + fg text).
|
|
8
|
-
* 3. Compaction message: pi's 3 lines (label, blank, text) squeezed into one:
|
|
9
|
-
* `[compaction] Compacted from N tokens (ctrl+o to expand)`.
|
|
10
|
-
* 4. Custom `pi-jev-eye-review` message: pi adds a label + blank line inside a purple
|
|
11
|
-
* box; our renderer shows the content as-is.
|
|
12
|
-
* 5. `↓ Jump to latest message` pill (fullscreen): bg selectedBg (grey) -> accent,
|
|
13
|
-
* text darkened (theme canvas) so contrast stays high (9.6:1).
|
|
14
|
-
* 6. `ctx.ui.select` rows: pi paints the whole selected row accent -> keep accent on
|
|
15
|
-
* the `❯` marker and `·` separators, selected text in soft.
|
|
16
|
-
*/
|
|
17
|
-
import {
|
|
18
|
-
AssistantMessageComponent,
|
|
19
|
-
CompactionSummaryMessageComponent,
|
|
20
|
-
ExtensionSelectorComponent,
|
|
21
|
-
getMarkdownTheme,
|
|
22
|
-
initTheme,
|
|
23
|
-
InteractiveMode,
|
|
24
|
-
Theme,
|
|
25
|
-
UserMessageComponent,
|
|
26
|
-
type ExtensionAPI,
|
|
27
|
-
} from "@earendil-works/pi-coding-agent";
|
|
28
|
-
import {
|
|
29
|
-
Container,
|
|
30
|
-
Markdown,
|
|
31
|
-
MouseRegion,
|
|
32
|
-
Spacer,
|
|
33
|
-
Text,
|
|
34
|
-
TuiAltScreen,
|
|
35
|
-
visibleWidth,
|
|
36
|
-
type Component,
|
|
37
|
-
type TuiMouseEvent,
|
|
38
|
-
type TuiMouseEventResult,
|
|
39
|
-
} from "@earendil-works/pi-tui";
|
|
40
|
-
import { readdirSync, readFileSync } from "node:fs";
|
|
41
|
-
import { renderBoxLines } from "../lib/box.ts";
|
|
42
|
-
import { statusRows } from "../lib/status-widget.ts";
|
|
43
|
-
import { ansiBgOpen, getActiveTheme, setActiveTheme, stripAnsi, themeOf, softOf } from "../lib/ansi.ts";
|
|
44
|
-
import { assert, isMain } from "../lib/check.ts";
|
|
45
|
-
import { contrast, hexToRgb, oklchToRgb, parseOklch, rgbToAnsi256, toHex } from "../lib/color.ts";
|
|
46
|
-
import { expandKeyName } from "../lib/format.ts";
|
|
47
|
-
import { patchOnce } from "../lib/patch.ts";
|
|
48
|
-
|
|
49
|
-
type ActiveTheme = { fg(color: string, text: string): string; bg?(color: string, text: string): string; italic?(text: string): string } | null;
|
|
50
|
-
const activeTheme = () => getActiveTheme<Exclude<ActiveTheme, null>>();
|
|
51
|
-
|
|
52
|
-
// Hide pi's built-in "Reloading keybindings, extensions, skills..." box
|
|
53
|
-
// (hardcoded in handleReloadCommand, no auto-hide). Patches Container.render
|
|
54
|
-
// through the prototype chain (Container is not exported) and drops the whole box on match.
|
|
55
|
-
const RELOAD_TEXT = "Reloading keybindings, extensions, skills, prompts, themes, and context files...";
|
|
56
|
-
/** The reload box is a fixed 5-child container (2 borders, 2 spacers, one 78-char line), so it
|
|
57
|
-
* renders at most ~9 rows even wrapped. Anything larger cannot be the box, and this predicate
|
|
58
|
-
* runs per frame on every plain Container — including a transcript of tens of thousands of
|
|
59
|
-
* lines, where the substring scan is the single most expensive arnative render patch. */
|
|
60
|
-
const RELOAD_BOX_MAX_LINES = 64;
|
|
61
|
-
/**
|
|
62
|
-
* True only for the box itself: border rows, blank spacers and (possibly wrapped) copy of the
|
|
63
|
-
* message. The patch sits on every plain Container, so a bare substring test would blank a
|
|
64
|
-
* whole chat the moment a transcript line mentioned the phrase. Containers larger than
|
|
65
|
-
* {@link RELOAD_BOX_MAX_LINES} are refused before any scanning starts.
|
|
66
|
-
*/
|
|
67
|
-
export function shouldHideReloadBox(lines: readonly string[]): boolean {
|
|
68
|
-
if (lines.length > RELOAD_BOX_MAX_LINES) return false;
|
|
69
|
-
if (!lines.some((l) => l.includes("Reloading keybindings"))) return false;
|
|
70
|
-
const rows = lines.map((l) => stripAnsi(l).trim());
|
|
71
|
-
return rows.every((r) => r === "" || /^[─-]+$/.test(r) || RELOAD_TEXT.includes(r));
|
|
72
|
-
}
|
|
73
|
-
// Every patch below reinstalls on each load (lib/patch.ts): `/reload` re-evaluates the
|
|
74
|
-
// module in the same process, so a `globalThis` guard would freeze the first load.
|
|
75
|
-
if (UserMessageComponent?.prototype) {
|
|
76
|
-
const containerProto = Object.getPrototypeOf(UserMessageComponent.prototype) as { render?: (width: number) => string[] };
|
|
77
|
-
if (typeof containerProto?.render === "function") {
|
|
78
|
-
patchOnce(containerProto, "render", (orig) => function (this: any, width: number): string[] {
|
|
79
|
-
const lines = orig.call(this, width);
|
|
80
|
-
return shouldHideReloadBox(lines) ? [] : lines;
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
// bg open code (no closing reset) -> lib/ansi.ts (single definition).
|
|
86
|
-
|
|
87
|
-
// Drag selection in pi fullscreen: pi only wraps the selection in reverse video
|
|
88
|
-
// (\x1b[7m), unreadable in some terminals/themes. Replaced with explicit colors
|
|
89
|
-
// (bg selectedBg + fg text) so text always stays visible.
|
|
90
|
-
|
|
91
|
-
export function recolorSelection(highlighted: string, fgOpen: string, bgOpen: string): string {
|
|
92
|
-
return highlighted.split("\x1b[7m").join(fgOpen + bgOpen).split("\x1b[27m").join("\x1b[39m\x1b[49m");
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
export function ansiFgOpen(th: { fg?(c: string, t: string): string } | null, color = "text"): string {
|
|
96
|
-
if (!th?.fg) return "";
|
|
97
|
-
try {
|
|
98
|
-
const probe = th.fg(color, "");
|
|
99
|
-
const reset = "\x1b[39m";
|
|
100
|
-
return probe.endsWith(reset) ? probe.slice(0, -reset.length) : probe;
|
|
101
|
-
} catch {
|
|
102
|
-
return "";
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
// `↓ Jump to latest message` pill (fullscreen): pi colors it with bg `selectedBg`
|
|
107
|
-
// (grey) -> accent bg + darkened canvas text (contrast 9.6:1, WCAG AA). pi has no bg
|
|
108
|
-
// token for `accent` (7 exist, see PILL_INK), so the SGR escapes are swapped;
|
|
109
|
-
// `bg("accent")` would throw "Unknown theme background color" and stay unchanged.
|
|
110
|
-
const PILL_MARK = "↓ Jump to latest message";
|
|
111
|
-
const PILL_INK = "toolPendingBg";
|
|
112
|
-
|
|
113
|
-
const asBg = (seq: string) => seq.replace(/\x1b\[38;/g, "\x1b[48;");
|
|
114
|
-
const asFg = (seq: string) => seq.replace(/\x1b\[48;/g, "\x1b[38;");
|
|
115
|
-
|
|
116
|
-
export function accentPill(
|
|
117
|
-
text: string,
|
|
118
|
-
th: { fg?(c: string, t: string): string; bg?(c: string, t: string): string } | null,
|
|
119
|
-
): string {
|
|
120
|
-
if (!text.includes(PILL_MARK) || !th?.fg || !th?.bg) return text;
|
|
121
|
-
const accentBg = asBg(ansiFgOpen(th, "accent"));
|
|
122
|
-
const inkFg = asFg(ansiBgOpen(th, PILL_INK));
|
|
123
|
-
if (!accentBg || !inkFg) return text; // token missing from the theme -> leave pi's default
|
|
124
|
-
return `${accentBg}${inkFg}${stripAnsi(text)}\x1b[39m\x1b[49m`;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
// TuiAltScreen builds the pill via the per-instance `scrollToEndIndicator` callback
|
|
128
|
-
// (an instance field, so the prototype cannot be patched). Swap in our callback
|
|
129
|
-
// only while the composite runs, then restore the original.
|
|
130
|
-
export function withAccentPill<T>(
|
|
131
|
-
host: { scrollToEndIndicator?: (() => string) | undefined },
|
|
132
|
-
fn: () => T,
|
|
133
|
-
th: { fg?(c: string, t: string): string; bg?(c: string, t: string): string } | null,
|
|
134
|
-
): T {
|
|
135
|
-
const orig = host.scrollToEndIndicator;
|
|
136
|
-
if (typeof orig !== "function") return fn();
|
|
137
|
-
host.scrollToEndIndicator = () => accentPill(orig(), th);
|
|
138
|
-
try {
|
|
139
|
-
return fn();
|
|
140
|
-
} finally {
|
|
141
|
-
host.scrollToEndIndicator = orig;
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
if (TuiAltScreen?.prototype) {
|
|
146
|
-
const proto = TuiAltScreen.prototype as any;
|
|
147
|
-
if (typeof proto.applySelectionHighlight === "function") {
|
|
148
|
-
patchOnce(proto, "applySelectionHighlight", (orig) => function (this: any, text: string): string {
|
|
149
|
-
const highlighted = orig.call(this, text);
|
|
150
|
-
const fgOpen = ansiFgOpen(activeTheme());
|
|
151
|
-
const bgOpen = ansiBgOpen(activeTheme(), "selectedBg");
|
|
152
|
-
return fgOpen && bgOpen ? recolorSelection(highlighted, fgOpen, bgOpen) : highlighted;
|
|
153
|
-
});
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
if (TuiAltScreen?.prototype) {
|
|
158
|
-
const proto = TuiAltScreen.prototype as unknown as {
|
|
159
|
-
compositeScrollToEndIndicator?: (screen: string[], layout: unknown, width: number) => string[];
|
|
160
|
-
};
|
|
161
|
-
if (typeof proto.compositeScrollToEndIndicator === "function") {
|
|
162
|
-
patchOnce(proto, "compositeScrollToEndIndicator", (origComposite) => function (
|
|
163
|
-
this: { scrollToEndIndicator?: (() => string) | undefined },
|
|
164
|
-
screen: string[],
|
|
165
|
-
layout: unknown,
|
|
166
|
-
width: number,
|
|
167
|
-
) {
|
|
168
|
-
return withAccentPill(this, () => origComposite.call(this, screen, layout, width), activeTheme());
|
|
169
|
-
});
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
// 6. Select menus (ctx.ui.select -> ExtensionSelectorComponent.updateList): pi colors the
|
|
174
|
-
// whole selected row accent. Arnative keeps accent on the `❯` marker and `·` separators
|
|
175
|
-
// and moves the selected text to soft (accent on themes without the token).
|
|
176
|
-
|
|
177
|
-
/** Selected row body: `·` separators accent, the text around them soft. */
|
|
178
|
-
export function selectRowText(row: string, th: { fg(c: string, t: string): string }): string {
|
|
179
|
-
const soft = softOf(th);
|
|
180
|
-
return row
|
|
181
|
-
.split("·")
|
|
182
|
-
.map((part) => soft(part))
|
|
183
|
-
.join(th.fg("accent", "·"));
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
if (ExtensionSelectorComponent?.prototype) {
|
|
187
|
-
const proto = ExtensionSelectorComponent.prototype as unknown as {
|
|
188
|
-
options: string[];
|
|
189
|
-
selectedIndex: number;
|
|
190
|
-
listContainer: { clear(): void; addChild(c: unknown): void };
|
|
191
|
-
updateList(): void;
|
|
192
|
-
};
|
|
193
|
-
patchOnce(proto, "updateList", (origUpdateList) => function (this: typeof proto) {
|
|
194
|
-
const th = activeTheme();
|
|
195
|
-
if (!th) return origUpdateList.call(this); // no theme yet -> pi's default
|
|
196
|
-
this.listContainer.clear();
|
|
197
|
-
for (let i = 0; i < this.options.length; i++) {
|
|
198
|
-
const text =
|
|
199
|
-
i === this.selectedIndex
|
|
200
|
-
? th.fg("accent", "❯ ") + selectRowText(this.options[i]!, th)
|
|
201
|
-
: ` ${th.fg("text", this.options[i]!)}`;
|
|
202
|
-
this.listContainer.addChild(new Text(text, 1, 0));
|
|
203
|
-
}
|
|
204
|
-
});
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
export default function uiRenderTweaks(pi: ExtensionAPI) {
|
|
208
|
-
// The active theme is re-read per session (ctx.ui.theme); render reads it lazily.
|
|
209
|
-
pi.on("session_start", async (_event, ctx) => {
|
|
210
|
-
const th = themeOf<Exclude<ActiveTheme, null>>(ctx);
|
|
211
|
-
if (th) setActiveTheme(th);
|
|
212
|
-
clearThinkingTicker();
|
|
213
|
-
});
|
|
214
|
-
|
|
215
|
-
pi.on("agent_end", async () => {
|
|
216
|
-
clearThinkingTicker();
|
|
217
|
-
});
|
|
218
|
-
|
|
219
|
-
pi.on("session_shutdown", async () => {
|
|
220
|
-
clearThinkingTicker();
|
|
221
|
-
});
|
|
222
|
-
|
|
223
|
-
// 4. `pi-jev-eye-review` contract message: use our own border box.
|
|
224
|
-
// Collapsed by default: [pi-jev-eye] Reviewed turn contract. [click to expand]
|
|
225
|
-
// On click: the full contract content appears inside the box.
|
|
226
|
-
pi.registerMessageRenderer("pi-jev-eye-review", (message, { expanded }, th) => {
|
|
227
|
-
const raw = customMessageText(message.content);
|
|
228
|
-
return new JevReviewBoxComponent(raw, Boolean(expanded), th);
|
|
229
|
-
});
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
// "Package Updates Available" notification: pi wraps the text in a DynamicBorder
|
|
233
|
-
// (full lines, not a box). Replaced with an arnative box (╭─╮ │ ╰─╯) through an
|
|
234
|
-
// InteractiveMode prototype patch; the yellow (warning) title and border stay, the
|
|
235
|
-
// body text is unchanged.
|
|
236
|
-
export class PackageUpdateBoxComponent implements Component {
|
|
237
|
-
private packages: string[];
|
|
238
|
-
private th: { fg(c: string, t: string): string } | null;
|
|
239
|
-
|
|
240
|
-
constructor(packages: string[], th: { fg(c: string, t: string): string } | null) {
|
|
241
|
-
this.packages = packages;
|
|
242
|
-
this.th = th;
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
invalidate(): void {}
|
|
246
|
-
|
|
247
|
-
render(width: number): string[] {
|
|
248
|
-
const th = this.th;
|
|
249
|
-
const fg = (color: string, text: string) => (th ? th.fg(color, text) : text);
|
|
250
|
-
const rows = [
|
|
251
|
-
fg("warning", "\x1b[1m\uf449 Package Updates Available\x1b[22m"),
|
|
252
|
-
`${fg("muted", "Package updates are available. Run ")}${fg("accent", "pi update --extensions")}`,
|
|
253
|
-
fg("muted", "Packages:"),
|
|
254
|
-
...this.packages.map((pkg) => `- ${pkg}`),
|
|
255
|
-
];
|
|
256
|
-
return renderBoxLines(th, width, rows, undefined, "warning");
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
if (InteractiveMode?.prototype) {
|
|
261
|
-
const proto = InteractiveMode.prototype as unknown as {
|
|
262
|
-
showPackageUpdateNotification(packages: string[]): void;
|
|
263
|
-
};
|
|
264
|
-
patchOnce(proto, "showPackageUpdateNotification", () => function (this: typeof proto, packages: string[]) {
|
|
265
|
-
const self = this as unknown as {
|
|
266
|
-
chatContainer: { addChild(c: unknown): void };
|
|
267
|
-
ui: { requestRender(): void };
|
|
268
|
-
};
|
|
269
|
-
self.chatContainer.addChild(new Spacer(1));
|
|
270
|
-
self.chatContainer.addChild(new PackageUpdateBoxComponent(packages, activeTheme()));
|
|
271
|
-
self.ui.requestRender();
|
|
272
|
-
});
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
// arnative box border helper -> lib/box.ts (one definition for every box)
|
|
276
|
-
|
|
277
|
-
// 7. Status rows above the chat column (pi's `aboveEditor` widget slot). pi turns a string
|
|
278
|
-
// array into unstyled `Text`, so an extension's status line ignores the theme and lands in
|
|
279
|
-
// the default foreground. Every such array is handed to a component factory instead, which
|
|
280
|
-
// receives the live theme: the arnative mark leads the block and every row is `dim`.
|
|
281
|
-
if (InteractiveMode?.prototype) {
|
|
282
|
-
const proto = InteractiveMode.prototype as unknown as {
|
|
283
|
-
setExtensionWidget(key: string, content: unknown, options?: { placement?: string }): void;
|
|
284
|
-
renderWidgets?(): void;
|
|
285
|
-
};
|
|
286
|
-
patchOnce(proto, "setExtensionWidget", (origSetWidget) => function (
|
|
287
|
-
this: typeof proto,
|
|
288
|
-
key: string,
|
|
289
|
-
content: unknown,
|
|
290
|
-
options?: { placement?: string },
|
|
291
|
-
) {
|
|
292
|
-
const ui = (this as unknown as { ui?: { requestRender(): void } }).ui;
|
|
293
|
-
if (ui) thinkingState.ui = ui;
|
|
294
|
-
if (Array.isArray(content) && content.every((line) => typeof line === "string")) {
|
|
295
|
-
const rows = content as string[];
|
|
296
|
-
content = (_tui: unknown, th: Parameters<typeof statusRows>[0]) => ({
|
|
297
|
-
dispose() {
|
|
298
|
-
/* no listeners, no timers */
|
|
299
|
-
},
|
|
300
|
-
invalidate() {
|
|
301
|
-
/* the rows are fixed at set time */
|
|
302
|
-
},
|
|
303
|
-
render(width: number): string[] {
|
|
304
|
-
return statusRows(th ?? activeTheme(), rows, width);
|
|
305
|
-
},
|
|
306
|
-
});
|
|
307
|
-
}
|
|
308
|
-
return origSetWidget.call(this, key, content, options);
|
|
309
|
-
});
|
|
310
|
-
if (typeof proto.renderWidgets === "function") {
|
|
311
|
-
patchOnce(proto, "renderWidgets", (origRenderWidgets) => function (this: typeof proto) {
|
|
312
|
-
const ui = (this as unknown as { ui?: { requestRender(): void } }).ui;
|
|
313
|
-
if (ui) thinkingState.ui = ui;
|
|
314
|
-
return origRenderWidgets.call(this);
|
|
315
|
-
});
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
export class JevReviewBoxComponent implements Component {
|
|
320
|
-
private text: string;
|
|
321
|
-
private th: { fg(c: string, t: string): string; bg?(c: string, t: string): string };
|
|
322
|
-
public isExpanded: boolean;
|
|
323
|
-
|
|
324
|
-
constructor(text: string, isExpanded: boolean, th: { fg(c: string, t: string): string; bg?(c: string, t: string): string }) {
|
|
325
|
-
this.text = text;
|
|
326
|
-
this.isExpanded = isExpanded;
|
|
327
|
-
this.th = th;
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
render(width: number): string[] {
|
|
331
|
-
const tag = this.th.fg("customMessageLabel", "\x1b[1m[pi-jev-eye]\x1b[22m");
|
|
332
|
-
if (!this.isExpanded) {
|
|
333
|
-
const title = this.th.fg("customMessageText", "Reviewed turn contract.");
|
|
334
|
-
const hint = this.th.fg("dim", "[click to expand]");
|
|
335
|
-
return renderBoxLines(this.th, width, [`${tag} ${title} ${hint}`]);
|
|
336
|
-
}
|
|
337
|
-
// Expanded: show every content line
|
|
338
|
-
const lines = this.text.split("\n");
|
|
339
|
-
const formattedRows = lines.map((line, idx) => {
|
|
340
|
-
if (idx === 0 && line.startsWith("[pi-jev-eye]")) {
|
|
341
|
-
const rest = line.slice("[pi-jev-eye]".length).trim();
|
|
342
|
-
return `${tag} ${this.th.fg("customMessageText", rest)}`;
|
|
343
|
-
}
|
|
344
|
-
return this.th.fg("customMessageText", line);
|
|
345
|
-
});
|
|
346
|
-
return renderBoxLines(this.th, width, formattedRows);
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
handleMouse(event: TuiMouseEvent): TuiMouseEventResult | undefined {
|
|
350
|
-
if (event.type === "click" && event.button === "left") {
|
|
351
|
-
this.isExpanded = !this.isExpanded;
|
|
352
|
-
return { handled: true };
|
|
353
|
-
}
|
|
354
|
-
return undefined;
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
invalidate(): void {}
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
// 3. Compaction message: one line instead of three (label, spacer, text).
|
|
361
|
-
// The theme is used so colors match pi's own box; before the session starts (no
|
|
362
|
-
// proxy yet) the built-in renderer keeps working.
|
|
363
|
-
export function compactionLine(th: { fg(c: string, t: string): string }, tokenStr: string): string {
|
|
364
|
-
const label = th.fg("customMessageLabel", "\x1b[1m[compaction]\x1b[22m");
|
|
365
|
-
return `${label} ${th.fg("customMessageText", `Compacted from ${tokenStr} tokens (`)}${th.fg("dim", expandKeyName())}${th.fg(
|
|
366
|
-
"customMessageText",
|
|
367
|
-
" to expand)",
|
|
368
|
-
)}`;
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
// Custom message content: a plain string, or concatenated text blocks (image blocks dropped).
|
|
372
|
-
export function customMessageText(content: unknown): string {
|
|
373
|
-
if (typeof content === "string") return content;
|
|
374
|
-
if (Array.isArray(content))
|
|
375
|
-
return content
|
|
376
|
-
.filter((c) => (c as { type?: string })?.type === "text")
|
|
377
|
-
.map((c) => (c as { text?: string }).text ?? "")
|
|
378
|
-
.join("\n");
|
|
379
|
-
return "";
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
if (CompactionSummaryMessageComponent?.prototype) {
|
|
383
|
-
const proto = CompactionSummaryMessageComponent.prototype as any;
|
|
384
|
-
patchOnce(proto, "updateDisplay", (origUpdateDisplay) => function (this: any): void {
|
|
385
|
-
const th = activeTheme();
|
|
386
|
-
if (!th) return origUpdateDisplay.call(this);
|
|
387
|
-
const message = this.message as { tokensBefore?: number; summary?: string } | undefined;
|
|
388
|
-
const tokenStr = Number(message?.tokensBefore ?? 0).toLocaleString();
|
|
389
|
-
this.clear();
|
|
390
|
-
const content = new Container();
|
|
391
|
-
if (this.expanded) {
|
|
392
|
-
content.addChild(new Text(th.fg("customMessageLabel", "\x1b[1m[compaction]\x1b[22m"), 0, 0));
|
|
393
|
-
content.addChild(new Spacer(1));
|
|
394
|
-
content.addChild(
|
|
395
|
-
new Markdown(
|
|
396
|
-
`**Compacted from ${tokenStr} tokens**\n\n${message?.summary ?? ""}`,
|
|
397
|
-
0,
|
|
398
|
-
0,
|
|
399
|
-
this.markdownTheme ?? getMarkdownTheme(),
|
|
400
|
-
{ color: (t: string) => th.fg("customMessageText", t) },
|
|
401
|
-
),
|
|
402
|
-
);
|
|
403
|
-
} else {
|
|
404
|
-
content.addChild(new Text(compactionLine(th, tokenStr), 0, 0));
|
|
405
|
-
}
|
|
406
|
-
this.addChild(
|
|
407
|
-
new MouseRegion(content, (event: any) => {
|
|
408
|
-
if (event.type !== "click" || event.button !== "left") return undefined;
|
|
409
|
-
this.setExpanded(!this.expanded);
|
|
410
|
-
return { handled: true };
|
|
411
|
-
}),
|
|
412
|
-
);
|
|
413
|
-
});
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
// 8. Hidden thinking label (`AssistantMessageComponent`): pi renders plain `Thinking...`
|
|
417
|
-
// in `thinkingText`. Arnative replaces pi's default `"Thinking..."` label with `\uec21`
|
|
418
|
-
// in `accent`, `Thinking...` in `dim`, and animates `.` -> `..` -> `...` while that
|
|
419
|
-
// thinking run is actively streaming. Finished or non-default labels stay static.
|
|
420
|
-
export const THINKING_ICON = "\uec21";
|
|
421
|
-
export const THINKING_DOTS = [".", "..", "..."] as const;
|
|
422
|
-
export const THINKING_DOT_MS = 400;
|
|
423
|
-
|
|
424
|
-
const THINKING_STATE_KEY = Symbol.for("pi-arnative.thinkingLabelState");
|
|
425
|
-
type ThinkingState = {
|
|
426
|
-
ui: { requestRender(): void } | null;
|
|
427
|
-
active: Set<object>;
|
|
428
|
-
starts: WeakMap<object, number[]>;
|
|
429
|
-
finished: WeakMap<object, Array<string | undefined>>;
|
|
430
|
-
timer: ReturnType<typeof setInterval> | null;
|
|
431
|
-
};
|
|
432
|
-
const thinkingState = ((globalThis as Record<symbol, unknown>)[THINKING_STATE_KEY] ??= {
|
|
433
|
-
ui: null,
|
|
434
|
-
active: new Set<object>(),
|
|
435
|
-
starts: new WeakMap<object, number[]>(),
|
|
436
|
-
finished: new WeakMap<object, Array<string | undefined>>(),
|
|
437
|
-
timer: null,
|
|
438
|
-
}) as ThinkingState;
|
|
439
|
-
|
|
440
|
-
function stopThinkingTicker(): void {
|
|
441
|
-
if (thinkingState.timer) {
|
|
442
|
-
clearInterval(thinkingState.timer);
|
|
443
|
-
thinkingState.timer = null;
|
|
444
|
-
}
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
export function clearThinkingTicker(): void {
|
|
448
|
-
thinkingState.active.clear();
|
|
449
|
-
thinkingState.starts = new WeakMap<object, number[]>();
|
|
450
|
-
thinkingState.finished = new WeakMap<object, Array<string | undefined>>();
|
|
451
|
-
stopThinkingTicker();
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
// Clear any leftover timer on module reload so old closures never keep ticking.
|
|
455
|
-
clearThinkingTicker();
|
|
456
|
-
|
|
457
|
-
function syncThinkingTicker(): void {
|
|
458
|
-
if (thinkingState.active.size === 0) {
|
|
459
|
-
stopThinkingTicker();
|
|
460
|
-
return;
|
|
461
|
-
}
|
|
462
|
-
if (thinkingState.timer) return;
|
|
463
|
-
thinkingState.timer = setInterval(() => {
|
|
464
|
-
if (thinkingState.active.size === 0) {
|
|
465
|
-
stopThinkingTicker();
|
|
466
|
-
return;
|
|
467
|
-
}
|
|
468
|
-
thinkingState.ui?.requestRender?.();
|
|
469
|
-
}, THINKING_DOT_MS);
|
|
470
|
-
thinkingState.timer.unref?.();
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
export function thinkingDotsAt(now: number, startMs: number): string {
|
|
474
|
-
const elapsed = Math.max(0, now - startMs);
|
|
475
|
-
const step = Math.floor(elapsed / THINKING_DOT_MS) % THINKING_DOTS.length;
|
|
476
|
-
return THINKING_DOTS[step]!;
|
|
477
|
-
}
|
|
478
|
-
|
|
479
|
-
// A finished run states what it did and how long it took, so the collapsed block stops
|
|
480
|
-
// claiming to be thinking once the answer has started. Seconds below a minute, then
|
|
481
|
-
// `Xm Ys`; a run always lasts at least one second, never `0s`.
|
|
482
|
-
export function formatThinkingElapsed(ms: number): string {
|
|
483
|
-
const total = Math.max(1, Math.round(ms / 1000));
|
|
484
|
-
if (total < 60) return `${total}s`;
|
|
485
|
-
const minutes = Math.floor(total / 60);
|
|
486
|
-
const seconds = total % 60;
|
|
487
|
-
return seconds === 0 ? `${minutes}m` : `${minutes}m ${seconds}s`;
|
|
488
|
-
}
|
|
489
|
-
|
|
490
|
-
export function formatThinkingLabel(
|
|
491
|
-
th: { fg(color: string, text: string): string; italic?(text: string): string } | null,
|
|
492
|
-
dots = "...",
|
|
493
|
-
finished?: string,
|
|
494
|
-
): string {
|
|
495
|
-
const icon = th ? th.fg("dim", THINKING_ICON) : THINKING_ICON;
|
|
496
|
-
const label = finished ?? `Thinking${dots}`;
|
|
497
|
-
const styledLabel = th ? (th.italic ? th.italic(th.fg("dim", label)) : th.fg("dim", label)) : label;
|
|
498
|
-
return `${icon} ${styledLabel}`;
|
|
499
|
-
}
|
|
500
|
-
|
|
501
|
-
export function activeThinkingRunIndex(
|
|
502
|
-
message: { content?: Array<{ type?: string; text?: string; thinking?: string }> } | undefined,
|
|
503
|
-
isStreaming: boolean,
|
|
504
|
-
): number | null {
|
|
505
|
-
if (!isStreaming || !Array.isArray(message?.content)) return null;
|
|
506
|
-
let runIdx = -1;
|
|
507
|
-
let lastVisibleKind: "thinking" | "other" | null = null;
|
|
508
|
-
for (let i = 0; i < message.content.length; i++) {
|
|
509
|
-
const block = message.content[i];
|
|
510
|
-
if (!block) continue;
|
|
511
|
-
if (block.type === "thinking") {
|
|
512
|
-
let hasText = false;
|
|
513
|
-
for (; i < message.content.length; i++) {
|
|
514
|
-
const b = message.content[i];
|
|
515
|
-
if (b?.type !== "thinking") break;
|
|
516
|
-
if (typeof b.thinking === "string" && b.thinking.trim()) hasText = true;
|
|
517
|
-
}
|
|
518
|
-
i--;
|
|
519
|
-
if (hasText) {
|
|
520
|
-
runIdx++;
|
|
521
|
-
lastVisibleKind = "thinking";
|
|
522
|
-
}
|
|
523
|
-
} else if ((block.type === "text" && typeof block.text === "string" && block.text.trim()) || block.type === "toolCall") {
|
|
524
|
-
lastVisibleKind = "other";
|
|
525
|
-
}
|
|
526
|
-
}
|
|
527
|
-
return lastVisibleKind === "thinking" && runIdx >= 0 ? runIdx : null;
|
|
528
|
-
}
|
|
529
|
-
|
|
530
|
-
export class ThinkingLabelComponent implements Component {
|
|
531
|
-
private inner: Text;
|
|
532
|
-
private isActive: boolean;
|
|
533
|
-
private startMs: number | undefined;
|
|
534
|
-
private finished: string | undefined;
|
|
535
|
-
private getTheme: () => ActiveTheme;
|
|
536
|
-
|
|
537
|
-
constructor(
|
|
538
|
-
padX: number,
|
|
539
|
-
isActive: boolean,
|
|
540
|
-
startMs: number | undefined,
|
|
541
|
-
getTheme: () => ActiveTheme,
|
|
542
|
-
finished?: string,
|
|
543
|
-
) {
|
|
544
|
-
this.isActive = isActive;
|
|
545
|
-
this.startMs = startMs;
|
|
546
|
-
this.finished = finished;
|
|
547
|
-
this.getTheme = getTheme;
|
|
548
|
-
this.inner = new Text(this.labelText(), padX, 0);
|
|
549
|
-
}
|
|
550
|
-
|
|
551
|
-
private labelText(): string {
|
|
552
|
-
const dots = this.isActive ? thinkingDotsAt(Date.now(), this.startMs ?? Date.now()) : "...";
|
|
553
|
-
return formatThinkingLabel(this.getTheme(), dots, this.isActive ? undefined : this.finished);
|
|
554
|
-
}
|
|
555
|
-
|
|
556
|
-
invalidate(): void {
|
|
557
|
-
this.inner.invalidate();
|
|
558
|
-
}
|
|
559
|
-
|
|
560
|
-
render(width: number): string[] {
|
|
561
|
-
this.inner.setText(this.labelText());
|
|
562
|
-
return this.inner.render(width);
|
|
563
|
-
}
|
|
564
|
-
}
|
|
565
|
-
|
|
566
|
-
function isPlainTextComponent(c: unknown): boolean {
|
|
567
|
-
if (!c || typeof c !== "object") return false;
|
|
568
|
-
const ctorName = (c as { constructor?: { name?: string } }).constructor?.name;
|
|
569
|
-
if (ctorName === "Text") return true;
|
|
570
|
-
return "text" in c && typeof (c as { text?: unknown }).text === "string" && !("theme" in c);
|
|
571
|
-
}
|
|
572
|
-
|
|
573
|
-
export function patchThinkingInAssistantMessage(comp: {
|
|
574
|
-
contentContainer?: { children?: unknown[] };
|
|
575
|
-
lastMessage?: { content?: Array<{ type?: string; text?: string; thinking?: string }> };
|
|
576
|
-
isStreaming?: boolean;
|
|
577
|
-
hiddenThinkingLabel?: string;
|
|
578
|
-
outputPad?: number;
|
|
579
|
-
}): boolean {
|
|
580
|
-
const th = activeTheme();
|
|
581
|
-
if (!th || (comp.hiddenThinkingLabel ?? "Thinking...") !== "Thinking...") {
|
|
582
|
-
thinkingState.active.delete(comp);
|
|
583
|
-
syncThinkingTicker();
|
|
584
|
-
return false;
|
|
585
|
-
}
|
|
586
|
-
const activeRunIdx = activeThinkingRunIndex(comp.lastMessage, Boolean(comp.isStreaming));
|
|
587
|
-
const children = comp.contentContainer?.children ?? [];
|
|
588
|
-
const starts = thinkingState.starts.get(comp) ?? [];
|
|
589
|
-
const finished = thinkingState.finished.get(comp) ?? [];
|
|
590
|
-
let runIdx = 0;
|
|
591
|
-
let anyActive = false;
|
|
592
|
-
let anyReplaced = false;
|
|
593
|
-
for (const child of children) {
|
|
594
|
-
if (!child || typeof child !== "object" || !("child" in child) || !("onMouse" in child)) continue;
|
|
595
|
-
const region = child as { child: unknown };
|
|
596
|
-
if (isPlainTextComponent(region.child)) {
|
|
597
|
-
const isActive = activeRunIdx === runIdx;
|
|
598
|
-
if (isActive) {
|
|
599
|
-
anyActive = true;
|
|
600
|
-
starts[runIdx] ??= Date.now();
|
|
601
|
-
} else if (starts[runIdx] !== undefined && finished[runIdx] === undefined) {
|
|
602
|
-
// The run just ended: keep how long it took, so the settled label reads
|
|
603
|
-
// `Thought for 3s` instead of claiming to still think.
|
|
604
|
-
finished[runIdx] = `Thought for ${formatThinkingElapsed(Date.now() - starts[runIdx]!)}`;
|
|
605
|
-
}
|
|
606
|
-
region.child = new ThinkingLabelComponent(
|
|
607
|
-
comp.outputPad ?? 1,
|
|
608
|
-
isActive,
|
|
609
|
-
starts[runIdx],
|
|
610
|
-
activeTheme,
|
|
611
|
-
finished[runIdx],
|
|
612
|
-
);
|
|
613
|
-
anyReplaced = true;
|
|
614
|
-
}
|
|
615
|
-
runIdx++;
|
|
616
|
-
}
|
|
617
|
-
thinkingState.starts.set(comp, starts);
|
|
618
|
-
thinkingState.finished.set(comp, finished);
|
|
619
|
-
if (anyActive) thinkingState.active.add(comp);
|
|
620
|
-
else thinkingState.active.delete(comp);
|
|
621
|
-
syncThinkingTicker();
|
|
622
|
-
return anyReplaced;
|
|
623
|
-
}
|
|
624
|
-
|
|
625
|
-
if (AssistantMessageComponent?.prototype?.updateContent) {
|
|
626
|
-
const proto = AssistantMessageComponent.prototype as any;
|
|
627
|
-
patchOnce(proto, "updateContent", (origUpdateContent) => function (this: any, message: unknown, isStreaming?: boolean) {
|
|
628
|
-
const res = origUpdateContent.call(this, message, isStreaming);
|
|
629
|
-
patchThinkingInAssistantMessage(this);
|
|
630
|
-
return res;
|
|
631
|
-
});
|
|
632
|
-
}
|
|
633
|
-
|
|
634
|
-
// Self-check: `node extensions/ui-render-tweaks.ts`
|
|
635
|
-
if (isMain(import.meta.url)) {
|
|
636
|
-
// reload box fully hidden (not line by line)
|
|
637
|
-
assert(shouldHideReloadBox(["────", "", " Reloading keybindings, extensions, skills, prompts, themes, and context files... ", "", "────"]) === true, "reload box detected");
|
|
638
|
-
assert(shouldHideReloadBox(["────", "", " Reloading keybindings, extensions,", " skills, prompts, themes, and context files...", "", "────"]) === true, "wrapped reload box detected");
|
|
639
|
-
assert(shouldHideReloadBox(["hello", "the log says Reloading keybindings", "world"]) === false, "chat lines that mention the phrase stay visible");
|
|
640
|
-
assert(shouldHideReloadBox(["hello", "world"]) === false, "normal lines pass through");
|
|
641
|
-
assert(
|
|
642
|
-
shouldHideReloadBox([...Array(RELOAD_BOX_MAX_LINES + 1).fill(""), " Reloading keybindings, extensions, skills, prompts, themes, and context files... "]) === false,
|
|
643
|
-
"a container larger than any reload box is refused before scanning",
|
|
644
|
-
);
|
|
645
|
-
|
|
646
|
-
// selection: reverse video replaced with explicit colors (bg selectedBg + fg text)
|
|
647
|
-
assert(
|
|
648
|
-
recolorSelection("\x1b[7mhi\x1b[27m", "<F>", "<B>") === "<F><B>hi\x1b[39m\x1b[49m",
|
|
649
|
-
"recolorSelection: open with fg+bg, close with fg+bg reset",
|
|
650
|
-
);
|
|
651
|
-
assert(recolorSelection("plain", "<F>", "<B>") === "plain", "no reverse video: unchanged");
|
|
652
|
-
assert(ansiFgOpen(null) === "", "no theme: empty fgOpen");
|
|
653
|
-
assert(ansiFgOpen({ fg: (_c, t) => `\x1b[38;2;1;2;3m${t}\x1b[39m` }) === "\x1b[38;2;1;2;3m", "fgOpen taken from the theme probe");
|
|
654
|
-
assert(ansiBgOpen({ bg: (_c, t) => `\x1b[48;2;9;9;9m${t}\x1b[49m` }, "selectedBg") === "\x1b[48;2;9;9;9m", "bgOpen selectedBg taken");
|
|
655
|
-
|
|
656
|
-
// "Jump to latest message" pill: accent bg + canvas text (not grey selectedBg).
|
|
657
|
-
// Use the REAL theme: the permissive stub would let `bg("accent")` through,
|
|
658
|
-
// which pi throws on.
|
|
659
|
-
const themeJson = JSON.parse(readFileSync(new URL("../themes/arnative.json", import.meta.url), "utf8")) as {
|
|
660
|
-
vars: Record<string, string>;
|
|
661
|
-
colors: Record<string, string>;
|
|
662
|
-
};
|
|
663
|
-
// Themes store OKLCH; the Theme class shipped in node_modules (0.87.1) only parses
|
|
664
|
-
// hex, so resolve every token through lib/color before constructing it.
|
|
665
|
-
const resolve = (value: string) => toHex(themeJson.vars[value] ?? value);
|
|
666
|
-
const hex = (tok: string) => resolve(themeJson.colors[tok] ?? tok);
|
|
667
|
-
// Mirrors `soften()` (themes/gen-themes.mjs) and `softenColor` (lib/ansi.ts): the soft
|
|
668
|
-
// tier is the base color at L 0.82 with a fifth of its chroma. Both sides read the
|
|
669
|
-
// declared OKLCH string (not the 8-bit hex), so the comparison is not rounded twice.
|
|
670
|
-
const softenToHex = (base: string, scale = 0.35, l = 0.90) => {
|
|
671
|
-
const o = parseOklch(base);
|
|
672
|
-
assert(o !== null, `cannot soften a non-oklch color: ${base}`);
|
|
673
|
-
return toHex(`oklch(${+(l * 100).toFixed(1)}% ${oklchToRgb(l, o.C * scale, o.H).chroma} ${o.H})`);
|
|
674
|
-
};
|
|
675
|
-
// The built-in theme adds fallbacks (scrollbarTrack<-muted, thinkingMax<-thinkingXhigh),
|
|
676
|
-
// so the fg map must be complete; take the whole palette like pi's loader does.
|
|
677
|
-
const fgPalette = Object.fromEntries(
|
|
678
|
-
Object.entries(themeJson.colors)
|
|
679
|
-
.filter(([k]) => k !== "accentSoft")
|
|
680
|
-
.map(([k, v]) => [k, resolve(v)]),
|
|
681
|
-
);
|
|
682
|
-
const thPill = new Theme(fgPalette, { toolPendingBg: hex("toolPendingBg"), selectedBg: hex("selectedBg") }, "truecolor");
|
|
683
|
-
const pillOriginal = thPill.bg("selectedBg", thPill.fg("text", " ↓ Jump to latest message · End "));
|
|
684
|
-
const rgb = (h: string) => [1, 3, 5].map((i) => parseInt(h.slice(i, i + 2), 16)).join(";");
|
|
685
|
-
assert(
|
|
686
|
-
accentPill(pillOriginal, thPill) ===
|
|
687
|
-
`\x1b[48;2;${rgb(hex("accent"))}m\x1b[38;2;${rgb(hex("toolPendingBg"))}m ↓ Jump to latest message · End \x1b[39m\x1b[49m`,
|
|
688
|
-
"pill: accent bg + canvas text, old ANSI dropped",
|
|
689
|
-
);
|
|
690
|
-
let rejected = false;
|
|
691
|
-
try {
|
|
692
|
-
thPill.bg("accent", "x");
|
|
693
|
-
} catch {
|
|
694
|
-
rejected = true;
|
|
695
|
-
}
|
|
696
|
-
assert(rejected, "pi really rejects bg('accent') -> the SGR direction must be swapped");
|
|
697
|
-
assert(accentPill("other text", thPill) === "other text", "pill: non-pill text untouched");
|
|
698
|
-
assert(accentPill(pillOriginal, null) === pillOriginal, "pill: no theme -> passed through");
|
|
699
|
-
|
|
700
|
-
// select rows: `❯` + `·` stay accent, selected text moves to accentSoft
|
|
701
|
-
const tagFg = { fg: (c: string, t: string) => `<${c}>${t}</${c}>` };
|
|
702
|
-
assert(
|
|
703
|
-
selectRowText("Routing · off", tagFg) === "<accentSoft>Routing </accentSoft><accent>·</accent><accentSoft> off</accentSoft>",
|
|
704
|
-
"select row: separators accent, text accentSoft",
|
|
705
|
-
);
|
|
706
|
-
assert(selectRowText("plain", tagFg) === "<accentSoft>plain</accentSoft>", "select row without separators: all accentSoft");
|
|
707
|
-
|
|
708
|
-
// Theme variants: every themes/*.json must be valid — name = file name, all
|
|
709
|
-
// required colors present, valid hex, and contrast measured against that theme's
|
|
710
|
-
// own canvas (userMessageBg): content >= 3.0, secondary text >= 2.0, thinking
|
|
711
|
-
// ramp 1.3-4.0, accent pill >= 4.5 — the thresholds that already pass in the
|
|
712
|
-
// base `arnative` (not invented numbers).
|
|
713
|
-
const themesDir = new URL("../themes/", import.meta.url);
|
|
714
|
-
const required = Object.keys(themeJson.colors);
|
|
715
|
-
// Non-text keys (backgrounds/borders/scrollbar) — contrast is not measured.
|
|
716
|
-
const nonText = new Set([
|
|
717
|
-
"selectedBg", "userMessageBg", "customMessageBg", "toolPendingBg", "toolSuccessBg", "toolErrorBg",
|
|
718
|
-
"searchMatchBg", "border", "borderAccent", "borderMuted", "mdCodeBlockBorder", "mdQuoteBorder", "mdHr",
|
|
719
|
-
"scrollbarTrack", "scrollbarThumb",
|
|
720
|
-
]);
|
|
721
|
-
// Every background a box or a highlight paints. These carry no text contrast
|
|
722
|
-
// requirement, but each must still be *visible*: a box the same color as the
|
|
723
|
-
// terminal canvas is not a box.
|
|
724
|
-
const BOX_TOKENS = [
|
|
725
|
-
"userMessageBg", "customMessageBg", "toolPendingBg", "toolSuccessBg", "toolErrorBg",
|
|
726
|
-
"selectedBg", "searchMatchBg",
|
|
727
|
-
];
|
|
728
|
-
const secondary = new Set(["muted", "dim", "mdQuote", "mdLinkUrl", "toolOutput", "toolDiffContext", "thinkingText", "syntaxComment"]);
|
|
729
|
-
// Thinking ramp: the higher the more readable; thinkingMax = accent (measured on the pill path).
|
|
730
|
-
const ramp: Record<string, number> = {
|
|
731
|
-
thinkingOff: 1.3, thinkingMinimal: 1.3, thinkingLow: 2.0,
|
|
732
|
-
thinkingMedium: 2.7, thinkingHigh: 3.6, thinkingXhigh: 4.0,
|
|
733
|
-
};
|
|
734
|
-
const isColor = (v: string) => /^#[0-9a-f]{6}$/i.test(v) || parseOklch(v) !== null;
|
|
735
|
-
// The tokens pi's published theme schema allows as keys in `colors`. Pi 1.2.0 validates
|
|
736
|
-
// with `additionalProperties: false`, so ANY other key (arnative's `accentSoft` was the
|
|
737
|
-
// offender) fails the whole theme at startup with "must not have additional properties"
|
|
738
|
-
// and "Theme not found". Arnative's own colors belong in `vars`, referenced from these.
|
|
739
|
-
const SCHEMA_TOKENS = new Set([
|
|
740
|
-
"accent", "border", "borderAccent", "borderMuted", "success", "error", "warning",
|
|
741
|
-
"muted", "dim", "text", "thinkingText", "scrollbarTrack", "scrollbarThumb",
|
|
742
|
-
"selectedBg", "searchMatchBg", "searchMatchText", "userMessageBg", "userMessageText",
|
|
743
|
-
"customMessageBg", "customMessageText", "customMessageLabel", "toolPendingBg",
|
|
744
|
-
"toolSuccessBg", "toolErrorBg", "toolTitle", "toolOutput", "mdHeading", "mdLink",
|
|
745
|
-
"mdLinkUrl", "mdCode", "mdCodeBlock", "mdCodeBlockBorder", "mdQuote", "mdQuoteBorder",
|
|
746
|
-
"mdHr", "mdListBullet", "toolDiffAdded", "toolDiffRemoved", "toolDiffContext",
|
|
747
|
-
"syntaxComment", "syntaxKeyword", "syntaxFunction", "syntaxVariable", "syntaxString",
|
|
748
|
-
"syntaxNumber", "syntaxType", "syntaxOperator", "syntaxPunctuation", "thinkingOff",
|
|
749
|
-
"thinkingMinimal", "thinkingLow", "thinkingMedium", "thinkingHigh", "thinkingXhigh",
|
|
750
|
-
"thinkingMax", "bashMode",
|
|
751
|
-
]);
|
|
752
|
-
for (const f of readdirSync(themesDir).filter((n) => n.endsWith(".json")).sort()) {
|
|
753
|
-
const d = JSON.parse(readFileSync(new URL(f, themesDir), "utf8")) as {
|
|
754
|
-
$schema?: string;
|
|
755
|
-
name: string;
|
|
756
|
-
vars: Record<string, string>;
|
|
757
|
-
colors: Record<string, string>;
|
|
758
|
-
};
|
|
759
|
-
assert(d.name === f.replace(/\.json$/, ""), `theme ${f}: name = file name`);
|
|
760
|
-
// Pi 1.2.0 validates `colors` strictly; an extra key rejects the theme at startup.
|
|
761
|
-
const rogue = Object.keys(d.colors).filter((k) => !SCHEMA_TOKENS.has(k));
|
|
762
|
-
assert(rogue.length === 0, `theme ${f}: colors has non-schema keys [${rogue.join(", ")}] — move them to vars`);
|
|
763
|
-
assert(
|
|
764
|
-
d.$schema === "https://pi.dev/schemas/theme.schema.json",
|
|
765
|
-
`theme ${f}: $schema must be the published pi.dev theme schema (got ${d.$schema})`,
|
|
766
|
-
);
|
|
767
|
-
const missing = required.filter((k) => !(k in d.colors));
|
|
768
|
-
assert(missing.length === 0, `theme ${f}: required colors complete (missing ${missing.join(",")})`);
|
|
769
|
-
// colors values may only be: hex, oklch, 256-index, empty, or a REAL variable name —
|
|
770
|
-
// a bare color name (e.g. "muted") makes pi reject the theme with no clear reason.
|
|
771
|
-
for (const [tok, value] of Object.entries(d.colors)) {
|
|
772
|
-
if (typeof value !== "string") continue;
|
|
773
|
-
if (value === "" || isColor(value) || value in d.vars) continue;
|
|
774
|
-
assert(false, `theme ${f}: colors.${tok} = "${value}" is not hex/oklch/var`);
|
|
775
|
-
}
|
|
776
|
-
// Every var must itself be a real color, and no two vars may resolve to the
|
|
777
|
-
// same value — near-identical hand-written hex was the original problem.
|
|
778
|
-
for (const [name, value] of Object.entries(d.vars)) {
|
|
779
|
-
assert(isColor(value), `theme ${f}: vars.${name} is a color (${value})`);
|
|
780
|
-
}
|
|
781
|
-
const seenVar = new Map<string, string>();
|
|
782
|
-
for (const [name, value] of Object.entries(d.vars)) {
|
|
783
|
-
const h = toHex(value);
|
|
784
|
-
assert(!seenVar.has(h), `theme ${f}: vars.${name} duplicates vars.${seenVar.get(h)} (${h})`);
|
|
785
|
-
seenVar.set(h, name);
|
|
786
|
-
}
|
|
787
|
-
const hex = (tok: string) => toHex(d.vars[d.colors[tok] ?? tok] ?? d.colors[tok]!);
|
|
788
|
-
for (const tok of ["accent", "text", "selectedBg", "toolPendingBg"]) {
|
|
789
|
-
assert(isColor(d.vars[d.colors[tok] ?? tok] ?? d.colors[tok]!), `theme ${f}: ${tok} is a color (${hex(tok)})`);
|
|
790
|
-
}
|
|
791
|
-
// Accent pill: accent bg + toolPendingBg colored text.
|
|
792
|
-
assert(contrast(hex("accent"), hex("toolPendingBg")) >= 4.5, `theme ${f}: accent vs toolPendingBg contrast >= 4.5`);
|
|
793
|
-
assert(isColor(d.vars.accentSoft ?? ""), `theme ${f}: vars.accentSoft is a color`);
|
|
794
|
-
assert(isColor(d.vars.secondarySoft ?? ""), `theme ${f}: vars.secondarySoft is a color`);
|
|
795
|
-
assert(isColor(d.vars.primary ?? ""), `theme ${f}: vars.primary is a color`);
|
|
796
|
-
assert(isColor(d.vars.secondary ?? ""), `theme ${f}: vars.secondary is a color`);
|
|
797
|
-
// The declared soft vars must equal what the extensions derive at runtime, or the
|
|
798
|
-
// footer label colour drifts from the theme file. `softenToHex` mirrors
|
|
799
|
-
// `soften()` in gen-themes.mjs and `softenColor` in lib/ansi.ts.
|
|
800
|
-
for (const [softName, baseName] of [["accentSoft", "accent"], ["secondarySoft", "secondary"]] as const) {
|
|
801
|
-
const base = d.vars[d.colors[baseName] ?? baseName]!;
|
|
802
|
-
const declared = toHex(d.vars[softName]!);
|
|
803
|
-
const derived = softenToHex(base);
|
|
804
|
-
assert(declared === derived, `theme ${f}: vars.${softName} ${declared} != runtime ${derived} (derived from ${baseName})`);
|
|
805
|
-
}
|
|
806
|
-
const canvas = hex("userMessageBg");
|
|
807
|
-
for (const tok of Object.keys(d.colors)) {
|
|
808
|
-
if (nonText.has(tok) || tok === "thinkingMax") continue;
|
|
809
|
-
const color = hex(tok);
|
|
810
|
-
const limit = ramp[tok] ?? (secondary.has(tok) ? 2.0 : 3.0);
|
|
811
|
-
const c = contrast(color, canvas);
|
|
812
|
-
assert(c >= limit, `theme ${f}: ${tok} vs canvas contrast ${c.toFixed(2)} < ${limit}`);
|
|
813
|
-
}
|
|
814
|
-
// Thinking ramp must rise monotonically (Off < Minimal < … < Xhigh).
|
|
815
|
-
const rampKeys = ["thinkingOff", "thinkingMinimal", "thinkingLow", "thinkingMedium", "thinkingHigh", "thinkingXhigh"];
|
|
816
|
-
for (let i = 1; i < rampKeys.length; i++) {
|
|
817
|
-
const [lo, hi] = [hex(rampKeys[i - 1]!), hex(rampKeys[i]!)];
|
|
818
|
-
assert(contrast(lo, canvas) < contrast(hi, canvas), `theme ${f}: ${rampKeys[i]} is brighter than ${rampKeys[i - 1]}`);
|
|
819
|
-
}
|
|
820
|
-
// Tool box text must be readable on the success background AND in errors, and
|
|
821
|
-
// the error text in the error box — three pairs that used to pass (3.48-4.46)
|
|
822
|
-
// without being caught.
|
|
823
|
-
for (const [fg, bg] of [
|
|
824
|
-
["toolOutput", "toolSuccessBg"], ["toolOutput", "toolErrorBg"],
|
|
825
|
-
["error", "toolErrorBg"], ["toolDiffRemoved", "toolErrorBg"],
|
|
826
|
-
] as const) {
|
|
827
|
-
const c = contrast(hex(fg), hex(bg));
|
|
828
|
-
assert(c >= 4.5, `theme ${f}: ${fg} on ${bg} contrast ${c.toFixed(2)} < 4.5`);
|
|
829
|
-
}
|
|
830
|
-
// The error box must not be heavier than the success box (matching background luminance).
|
|
831
|
-
const [lErr, lOk] = [hex("toolErrorBg"), hex("toolSuccessBg")].map((h) => {
|
|
832
|
-
const ch = [1, 3, 5].map((i) => parseInt(h.slice(i, i + 2), 16) / 255).map((c) =>
|
|
833
|
-
c <= 0.03928 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4,
|
|
834
|
-
);
|
|
835
|
-
return 0.2126 * ch[0]! + 0.7152 * ch[1]! + 0.0722 * ch[2]!;
|
|
836
|
-
});
|
|
837
|
-
assert(Math.abs(lErr! - lOk!) / Math.max(lErr!, lOk!) <= 0.25, `theme ${f}: toolErrorBg vs toolSuccessBg weight (${lErr!.toFixed(3)} vs ${lOk!.toFixed(3)})`);
|
|
838
|
-
// Scrollbar thumb & highlight must be distinguishable from track/selection (they used to be identical).
|
|
839
|
-
assert(hex("scrollbarThumb") !== hex("scrollbarTrack"), `theme ${f}: scrollbarThumb still equals scrollbarTrack`);
|
|
840
|
-
assert(hex("searchMatchBg") !== hex("selectedBg"), `theme ${f}: searchMatchBg still equals selectedBg`);
|
|
841
|
-
// Every box must be visible on a pure-black terminal AND survive 256-color
|
|
842
|
-
// quantization. At L 0.19 the panel was `#001817` (1.14:1 on black) and every
|
|
843
|
-
// theme's boxes quantized to cube black (index 16) — invisible in both modes.
|
|
844
|
-
for (const tok of BOX_TOKENS) {
|
|
845
|
-
const color = hex(tok);
|
|
846
|
-
assert(contrast(color, "#000000") >= 1.4, `theme ${f}: ${tok} ${color} is invisible on a black terminal`);
|
|
847
|
-
const quantized = rgbToAnsi256(hexToRgb(color));
|
|
848
|
-
assert(quantized !== 16, `theme ${f}: ${tok} ${color} quantizes to index 16 (pure black) in 256-color mode`);
|
|
849
|
-
}
|
|
850
|
-
}
|
|
851
|
-
// Only `muted`, `text` and `selectedBg` exist. pi's Theme constructor maps whatever
|
|
852
|
-
// it gets — including the thinkingMax <- thinkingXhigh fallback — so these probe
|
|
853
|
-
// values must already be hex: the bundled parser (0.87.1) rejects OKLCH, which is
|
|
854
|
-
// exactly why the real theme self-check resolves through lib/color first.
|
|
855
|
-
const tokenGapTheme = new Theme(
|
|
856
|
-
{ muted: "#808080", text: "#d4d4d4", thinkingXhigh: "#20caee" },
|
|
857
|
-
{ selectedBg: "#3a3a4a" },
|
|
858
|
-
"truecolor",
|
|
859
|
-
);
|
|
860
|
-
assert(accentPill(pillOriginal, tokenGapTheme) === pillOriginal, "pill: token absent -> passed through");
|
|
861
|
-
const hostPil: { scrollToEndIndicator?: () => string } = { scrollToEndIndicator: () => pillOriginal };
|
|
862
|
-
const inPill = withAccentPill(hostPil, () => hostPil.scrollToEndIndicator?.(), thPill);
|
|
863
|
-
assert(inPill.includes(`\x1b[48;2;${rgb(hex("accent"))}m`), "pill: instance callback injected with accent bg");
|
|
864
|
-
assert(hostPil.scrollToEndIndicator?.() === pillOriginal, "pill: original callback restored after render");
|
|
865
|
-
|
|
866
|
-
// compaction: pi's three lines -> one
|
|
867
|
-
assert(
|
|
868
|
-
stripAnsi(compactionLine({ fg: (_c, t) => t }, "112,247")) ===
|
|
869
|
-
"[compaction] Compacted from 112,247 tokens (ctrl+o to expand)",
|
|
870
|
-
"compaction: label + text + expand hint on one line (no blank line)",
|
|
871
|
-
);
|
|
872
|
-
|
|
873
|
-
// custom message: content as-is, no extra label/lines
|
|
874
|
-
assert(
|
|
875
|
-
customMessageText("[pi-jev-eye] Reviewed turn contract:\n- Language follows the user") ===
|
|
876
|
-
"[pi-jev-eye] Reviewed turn contract:\n- Language follows the user",
|
|
877
|
-
"custom message content intact",
|
|
878
|
-
);
|
|
879
|
-
assert(
|
|
880
|
-
customMessageText([
|
|
881
|
-
{ type: "text", text: "a" },
|
|
882
|
-
{ type: "image", data: "x" },
|
|
883
|
-
{ type: "text", text: "b" },
|
|
884
|
-
]) === "a\nb",
|
|
885
|
-
"non-text blocks dropped",
|
|
886
|
-
);
|
|
887
|
-
|
|
888
|
-
// Integration: run the factory like pi, then call updateDisplay / the original renderer
|
|
889
|
-
const fakePi = {
|
|
890
|
-
handlers: [] as any[],
|
|
891
|
-
renderers: {} as Record<string, any>,
|
|
892
|
-
on(_e: string, h: any) {
|
|
893
|
-
this.handlers.push(h);
|
|
894
|
-
return () => {};
|
|
895
|
-
},
|
|
896
|
-
registerMessageRenderer(t: string, r: any) {
|
|
897
|
-
this.renderers[t] = r;
|
|
898
|
-
},
|
|
899
|
-
};
|
|
900
|
-
initTheme(); // markdown + pi's internal theme (already active in a real session)
|
|
901
|
-
uiRenderTweaks(fakePi as any);
|
|
902
|
-
await fakePi.handlers[0]({}, { ui: { theme: { fg: (_c: string, t: string) => t } } });
|
|
903
|
-
|
|
904
|
-
const kids: any[] = [];
|
|
905
|
-
const fake = {
|
|
906
|
-
expanded: false,
|
|
907
|
-
message: { tokensBefore: 112247, summary: "**Summary** long\n\n- one" },
|
|
908
|
-
clear() {
|
|
909
|
-
kids.length = 0;
|
|
910
|
-
},
|
|
911
|
-
addChild(c: any) {
|
|
912
|
-
kids.push(c);
|
|
913
|
-
},
|
|
914
|
-
};
|
|
915
|
-
CompactionSummaryMessageComponent.prototype.updateDisplay.call(fake as any);
|
|
916
|
-
const collapsed = kids[0].render(120);
|
|
917
|
-
assert(
|
|
918
|
-
collapsed.length === 1 && collapsed[0].trimEnd().endsWith("Compacted from 112,247 tokens (ctrl+o to expand)"),
|
|
919
|
-
"compaction collapsed: exactly one line",
|
|
920
|
-
);
|
|
921
|
-
|
|
922
|
-
fake.expanded = true;
|
|
923
|
-
CompactionSummaryMessageComponent.prototype.updateDisplay.call(fake as any);
|
|
924
|
-
const expanded = kids[0].render(120);
|
|
925
|
-
assert(
|
|
926
|
-
expanded.length > 1 && expanded.some((l: string) => l.includes("[compaction]")) && expanded.join(" ").includes("Summary"),
|
|
927
|
-
"compaction expanded: label + markdown summary still there",
|
|
928
|
-
);
|
|
929
|
-
|
|
930
|
-
const contractCollapsed = fakePi.renderers["pi-jev-eye-review"](
|
|
931
|
-
{ customType: "pi-jev-eye-review", content: "[pi-jev-eye] Reviewed turn contract:\n- Language follows the user" },
|
|
932
|
-
{ expanded: false, outputPad: 1 },
|
|
933
|
-
{ fg: (_c: string, t: string) => t },
|
|
934
|
-
);
|
|
935
|
-
const cLines = contractCollapsed.render(120).map((l: string) => l.trimEnd());
|
|
936
|
-
assert(
|
|
937
|
-
cLines[0].startsWith("╭") && cLines[cLines.length - 1].startsWith("╰") && cLines[1].includes("[click to expand]"),
|
|
938
|
-
"contract message collapsed: border box with [click to expand]",
|
|
939
|
-
);
|
|
940
|
-
|
|
941
|
-
// Package update notification: arnative box, body and yellow kept
|
|
942
|
-
const upd = new PackageUpdateBoxComponent(["github.com/bismawy/pi-arnative", "pkg-two"], {
|
|
943
|
-
fg: (c: string, t: string) => (c === "warning" ? `\x1b[33m${t}\x1b[39m` : t),
|
|
944
|
-
}).render(60);
|
|
945
|
-
assert(upd[0]!.includes("\x1b[33m") && upd[0]!.includes("╭"), "update box: round frame + warning color");
|
|
946
|
-
assert(upd[upd.length - 1]!.includes("╰"), "update box: bottom frame");
|
|
947
|
-
assert(upd[1]!.includes("Package Updates Available"), "update title inside the box");
|
|
948
|
-
assert(upd[1]!.includes("\uf449"), "\uf449 icon on the update title");
|
|
949
|
-
assert(upd.some((l: string) => l.includes("- github.com/bismawy/pi-arnative")), "package list inside the box");
|
|
950
|
-
assert(upd.every((l: string) => visibleWidth(l) === 60), "update box is 60 wide");
|
|
951
|
-
|
|
952
|
-
// Test invalidate and the handleMouse click toggle
|
|
953
|
-
contractCollapsed.invalidate();
|
|
954
|
-
const mouseRes = contractCollapsed.handleMouse({ type: "click", button: "left" });
|
|
955
|
-
assert(mouseRes?.handled === true, "left click handled");
|
|
956
|
-
assert(contractCollapsed.isExpanded === true, "left click toggles expanded");
|
|
957
|
-
const toggledLines = contractCollapsed.render(120).map((l: string) => l.trimEnd());
|
|
958
|
-
assert(toggledLines.some((l: string) => l.includes("Language follows the user")), "after the click: full content shown");
|
|
959
|
-
|
|
960
|
-
const contractExpanded = fakePi.renderers["pi-jev-eye-review"](
|
|
961
|
-
{ customType: "pi-jev-eye-review", content: "[pi-jev-eye] Reviewed turn contract:\n- Language follows the user" },
|
|
962
|
-
{ expanded: true, outputPad: 1 },
|
|
963
|
-
{ fg: (_c: string, t: string) => t },
|
|
964
|
-
);
|
|
965
|
-
const expLines = contractExpanded.render(120).map((l: string) => l.trimEnd());
|
|
966
|
-
assert(
|
|
967
|
-
expLines[0].startsWith("╭") && expLines[expLines.length - 1].startsWith("╰") && expLines.some((l: string) => l.includes("Language follows the user")),
|
|
968
|
-
"contract message expanded: border box with the full content",
|
|
969
|
-
);
|
|
970
|
-
|
|
971
|
-
// Thinking label: accent \uec21 + dim Thinking... + animated . -> .. -> ... while active streaming
|
|
972
|
-
assert(thinkingDotsAt(0, 0) === "." && thinkingDotsAt(400, 0) === ".." && thinkingDotsAt(800, 0) === "..." && thinkingDotsAt(1200, 0) === ".", "thinking dots loop . -> .. -> ...");
|
|
973
|
-
const tLabel = formatThinkingLabel(
|
|
974
|
-
{ fg: (c, t) => `[${c}]${t}[/${c}]`, italic: (t) => `<i>${t}</i>` },
|
|
975
|
-
"..",
|
|
976
|
-
);
|
|
977
|
-
assert(tLabel === "[dim]\uec21[/dim] <i>[dim]Thinking..[/dim]</i>", "thinking label paints icon dim and label dim italic");
|
|
978
|
-
const doneLabel = formatThinkingLabel(
|
|
979
|
-
{ fg: (c, t) => `[${c}]${t}[/${c}]`, italic: (t) => `<i>${t}</i>` },
|
|
980
|
-
"...",
|
|
981
|
-
"Thought for 3s",
|
|
982
|
-
);
|
|
983
|
-
assert(doneLabel === "[dim]\uec21[/dim] <i>[dim]Thought for 3s[/dim]</i>", "a finished run states Thought for Ns, same dim italic paint");
|
|
984
|
-
assert(formatThinkingElapsed(0) === "1s" && formatThinkingElapsed(2999) === "3s", "a short run counts in whole seconds, never 0s");
|
|
985
|
-
assert(formatThinkingElapsed(60_000) === "1m" && formatThinkingElapsed(83_000) === "1m 23s", "a long run adds minutes");
|
|
986
|
-
|
|
987
|
-
const fakeThinkingMsg = { role: "assistant", content: [{ type: "thinking", thinking: "pondering" }], stopReason: "stop", usage: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, totalTokens: 0, cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 } }, api: "openai-completions", provider: "test", model: "test", timestamp: 0 };
|
|
988
|
-
const activeComp = new AssistantMessageComponent(undefined, true, getMarkdownTheme(), "Thinking...", 1);
|
|
989
|
-
activeComp.updateContent(fakeThinkingMsg as any, true);
|
|
990
|
-
const stripOsc = (s: string) => stripAnsi(s.replace(/\x1b\][^\x07]*\x07/g, "")).trim();
|
|
991
|
-
const activeLines = activeComp.render(60).map(stripOsc);
|
|
992
|
-
assert(activeLines.some((l) => l.startsWith("\uec21 Thinking.")), "streaming hidden thinking renders \\uec21 Thinking.(. / .. / ...)");
|
|
993
|
-
assert(activeThinkingRunIndex(fakeThinkingMsg, true) === 0, "active thinking run is detected while streaming");
|
|
994
|
-
assert(activeThinkingRunIndex({ content: [{ type: "thinking", thinking: "x" }, { type: "text", text: "done" }] }, true) === null, "thinking stops animating once answer text begins");
|
|
995
|
-
|
|
996
|
-
activeComp.updateContent(fakeThinkingMsg as any, false);
|
|
997
|
-
const doneLines = activeComp.render(60).map(stripOsc);
|
|
998
|
-
assert(
|
|
999
|
-
doneLines.some((l) => l.startsWith("\uec21 Thought for ")),
|
|
1000
|
-
"a finished hidden thinking run settles on \uec21 Thought for Ns, not Thinking...",
|
|
1001
|
-
);
|
|
1002
|
-
clearThinkingTicker();
|
|
1003
|
-
|
|
1004
|
-
console.log("ui-render-tweaks.ts self-check OK");
|
|
1005
|
-
}
|