@bismawy/pi-arnative 0.11.1 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +49 -6
- package/README.md +16 -6
- package/extensions/arnative.ts +214 -24
- package/extensions/autocompact.ts +659 -63
- package/extensions/budget.ts +37 -10
- package/extensions/footer.ts +611 -21
- package/extensions/model-heal.ts +14 -17
- package/extensions/render-cache.ts +638 -0
- package/extensions/timestamps.ts +3 -3
- package/extensions/todos.ts +74 -4
- package/extensions/tools.ts +246 -12
- package/extensions/ui-render-tweaks.ts +273 -1
- package/extensions/usage.ts +11 -7
- package/lib/list-picker.ts +19 -3
- package/lib/model-heal.ts +38 -12
- package/lib/patch.ts +26 -1
- package/lib/preset-store.ts +6 -1
- package/lib/status-widget.ts +5 -16
- package/lib/todos.ts +7 -4
- package/package.json +3 -3
package/extensions/footer.ts
CHANGED
|
@@ -6,19 +6,23 @@
|
|
|
6
6
|
* or "Pi (system)".
|
|
7
7
|
*/
|
|
8
8
|
import type { AssistantMessage } from "@earendil-works/pi-ai";
|
|
9
|
-
import { CustomEditor, FooterComponent, type ExtensionAPI, type ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
9
|
+
import { CustomEditor, FooterComponent, InteractiveMode, type ExtensionAPI, type ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
10
10
|
import { truncateToWidth, visibleWidth, type TuiMouseEvent } from "@earendil-works/pi-tui";
|
|
11
11
|
import { execFile } from "node:child_process";
|
|
12
12
|
import { mkdirSync, mkdtempSync, readFileSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
13
13
|
import { tmpdir } from "node:os";
|
|
14
14
|
import { dirname, join, resolve } from "node:path";
|
|
15
15
|
import { softOf, softSecondaryOf, stripAnsi } from "../lib/ansi.ts";
|
|
16
|
+
import { inSpans, textSpans, type TextSpan } from "../lib/box.ts";
|
|
16
17
|
import { assert, isMain } from "../lib/check.ts";
|
|
17
18
|
import { capitalize, markedLabels, modelDisplayParts } from "../lib/format.ts";
|
|
18
19
|
import { IS_WINDOWS_LIKE, SHORTCUT_RELOAD, SHORTCUT_TOGGLE_FOOTER } from "../lib/shortcuts.ts";
|
|
19
|
-
import { markPatched, originalOf } from "../lib/patch.ts";
|
|
20
|
+
import { markPatched, originalOf, patchOnce } from "../lib/patch.ts";
|
|
20
21
|
import { estimateCost, formatTokens, loadPriceTable, TOOL_PROVIDER, type PriceTable } from "../lib/usage-store.ts";
|
|
21
22
|
import {
|
|
23
|
+
CHATBOX_DIALOG_KEY as CHATBOX_DIALOG_CONFIG_KEY,
|
|
24
|
+
CHATBOX_PRESET_KEY as CHATBOX_PRESET_CONFIG_KEY,
|
|
25
|
+
CHATBOX_PROMPT_KEY as CHATBOX_PROMPT_CONFIG_KEY,
|
|
22
26
|
FOOTER_COST_KEY as FOOTER_COST_CONFIG_KEY,
|
|
23
27
|
FOOTER_PRESET_KEY as FOOTER_PRESET_CONFIG_KEY,
|
|
24
28
|
loadChoice,
|
|
@@ -26,6 +30,7 @@ import {
|
|
|
26
30
|
saveChoice,
|
|
27
31
|
} from "../lib/preset-store.ts";
|
|
28
32
|
import { formatCost } from "./usage.ts";
|
|
33
|
+
import { isByteLimitedModel, wireBytesSnapshot } from "./autocompact.ts";
|
|
29
34
|
import { budgetLevelNow } from "./budget.ts";
|
|
30
35
|
import { EDITOR_KEY, activeSpinnerGradient, activeSpinnerPreset } from "./animations.ts";
|
|
31
36
|
import { spinnerPainter } from "../lib/spinner.ts";
|
|
@@ -39,6 +44,153 @@ import { spinnerPainter } from "../lib/spinner.ts";
|
|
|
39
44
|
// in both — pi's `setEditorComponent()` would close the picker mid-preview). The picker
|
|
40
45
|
// lives in arnative.ts, so the choice is shared through globalThis like the header preset.
|
|
41
46
|
// Listed built-in-first: the `(Full)` suffix is rendered dim, so the plain row reads cleaner on top.
|
|
47
|
+
export const CHATBOX_PRESETS = ["Pi (system)", "Arnative"] as const;
|
|
48
|
+
export type ChatboxPreset = (typeof CHATBOX_PRESETS)[number];
|
|
49
|
+
export const DEFAULT_CHATBOX_PRESET: ChatboxPreset = "Arnative";
|
|
50
|
+
const CHATBOX_PRESET_KEY = Symbol.for("pi-arnative.chatboxPreset");
|
|
51
|
+
|
|
52
|
+
export const CHATBOX_PROMPTS = ["❯", ">", "›", "▸", "→", "\uf44f", "\udb82\udf79", "\uf51b", "\udb80\udf7d", "\uf120", "\uf489", "\udb80\udd7a"] as const;
|
|
53
|
+
export type ChatboxPrompt = (typeof CHATBOX_PROMPTS)[number];
|
|
54
|
+
export const DEFAULT_CHATBOX_PROMPT: ChatboxPrompt = "❯";
|
|
55
|
+
const CHATBOX_PROMPT_KEY = Symbol.for("pi-arnative.chatboxPrompt");
|
|
56
|
+
|
|
57
|
+
export const CHATBOX_DIALOGS = ["Left", "Center", "Right", "Inside", "Outside"] as const;
|
|
58
|
+
export type ChatboxDialog = (typeof CHATBOX_DIALOGS)[number];
|
|
59
|
+
export const DEFAULT_CHATBOX_DIALOG: ChatboxDialog = "Left";
|
|
60
|
+
const CHATBOX_DIALOG_KEY = Symbol.for("pi-arnative.chatboxDialog");
|
|
61
|
+
|
|
62
|
+
export const PROMPT_IDLE_MS = 3_000;
|
|
63
|
+
const PROMPT_TYPED_AT_KEY = Symbol.for("pi-arnative.promptTypedAt");
|
|
64
|
+
const PROMPT_IDLE_TIMER_KEY = Symbol.for("pi-arnative.promptIdleTimer");
|
|
65
|
+
|
|
66
|
+
export function activeChatboxPreset(): ChatboxPreset {
|
|
67
|
+
const stored = (globalThis as Record<symbol, unknown>)[CHATBOX_PRESET_KEY] ?? loadChoice(CHATBOX_PRESET_CONFIG_KEY, CHATBOX_PRESETS);
|
|
68
|
+
return CHATBOX_PRESETS.includes(stored as ChatboxPreset) ? (stored as ChatboxPreset) : DEFAULT_CHATBOX_PRESET;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function setChatboxPreset(name: ChatboxPreset): void {
|
|
72
|
+
(globalThis as Record<symbol, unknown>)[CHATBOX_PRESET_KEY] = name;
|
|
73
|
+
saveChoice(CHATBOX_PRESET_CONFIG_KEY, name);
|
|
74
|
+
poke();
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function activeChatboxPrompt(): ChatboxPrompt {
|
|
78
|
+
const stored = (globalThis as Record<symbol, unknown>)[CHATBOX_PROMPT_KEY] ?? loadChoice(CHATBOX_PROMPT_CONFIG_KEY, CHATBOX_PROMPTS);
|
|
79
|
+
return CHATBOX_PROMPTS.includes(stored as ChatboxPrompt) ? (stored as ChatboxPrompt) : DEFAULT_CHATBOX_PROMPT;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export function setChatboxPrompt(prompt: ChatboxPrompt): void {
|
|
83
|
+
(globalThis as Record<symbol, unknown>)[CHATBOX_PROMPT_KEY] = prompt;
|
|
84
|
+
saveChoice(CHATBOX_PROMPT_CONFIG_KEY, prompt);
|
|
85
|
+
poke();
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export function nextChatboxPrompt(current: ChatboxPrompt = activeChatboxPrompt()): ChatboxPrompt {
|
|
89
|
+
const idx = CHATBOX_PROMPTS.indexOf(current);
|
|
90
|
+
return CHATBOX_PROMPTS[(idx + 1) % CHATBOX_PROMPTS.length]!;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export function activeChatboxDialog(): ChatboxDialog {
|
|
94
|
+
const stored = (globalThis as Record<symbol, unknown>)[CHATBOX_DIALOG_KEY] ?? loadChoice(CHATBOX_DIALOG_CONFIG_KEY, CHATBOX_DIALOGS);
|
|
95
|
+
return CHATBOX_DIALOGS.includes(stored as ChatboxDialog) ? (stored as ChatboxDialog) : DEFAULT_CHATBOX_DIALOG;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export function setChatboxDialog(dialog: ChatboxDialog): void {
|
|
99
|
+
(globalThis as Record<symbol, unknown>)[CHATBOX_DIALOG_KEY] = dialog;
|
|
100
|
+
saveChoice(CHATBOX_DIALOG_CONFIG_KEY, dialog);
|
|
101
|
+
poke();
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export function nextChatboxDialog(current: ChatboxDialog = activeChatboxDialog()): ChatboxDialog {
|
|
105
|
+
const idx = CHATBOX_DIALOGS.indexOf(current);
|
|
106
|
+
return CHATBOX_DIALOGS[(idx + 1) % CHATBOX_DIALOGS.length]!;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export function isPromptActive(
|
|
110
|
+
now: number = Date.now(),
|
|
111
|
+
lastTyped: number = ((globalThis as Record<symbol, unknown>)[PROMPT_TYPED_AT_KEY] as number | undefined) ?? 0,
|
|
112
|
+
): boolean {
|
|
113
|
+
return lastTyped > 0 && now - lastTyped <= PROMPT_IDLE_MS;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export function stopPromptIdle(): void {
|
|
117
|
+
const g = globalThis as Record<symbol, ReturnType<typeof setTimeout> | null | undefined>;
|
|
118
|
+
if (g[PROMPT_IDLE_TIMER_KEY]) clearTimeout(g[PROMPT_IDLE_TIMER_KEY]!);
|
|
119
|
+
g[PROMPT_IDLE_TIMER_KEY] = null;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export function markPromptTyped(now: number = Date.now()): void {
|
|
123
|
+
const g = globalThis as Record<symbol, unknown>;
|
|
124
|
+
g[PROMPT_TYPED_AT_KEY] = now;
|
|
125
|
+
stopPromptIdle();
|
|
126
|
+
const timer = setTimeout(() => {
|
|
127
|
+
g[PROMPT_IDLE_TIMER_KEY] = null;
|
|
128
|
+
poke();
|
|
129
|
+
}, PROMPT_IDLE_MS + 25);
|
|
130
|
+
timer.unref?.();
|
|
131
|
+
g[PROMPT_IDLE_TIMER_KEY] = timer;
|
|
132
|
+
poke();
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export function chatboxPrimaryPaint(
|
|
136
|
+
th: { fg?(color: string, text: string): string } | null | undefined,
|
|
137
|
+
): (text: string) => string {
|
|
138
|
+
if (!th?.fg) return (t) => t;
|
|
139
|
+
for (const token of ["mdHeading", "accent"]) {
|
|
140
|
+
try {
|
|
141
|
+
const probe = th.fg(token, "x");
|
|
142
|
+
if (typeof probe === "string" && probe.includes("x")) return (t) => th.fg!(token, t);
|
|
143
|
+
} catch {
|
|
144
|
+
// try next
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return (t) => t;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export function isWideNerdPrompt(glyph: string): boolean {
|
|
151
|
+
const cp = glyph.codePointAt(0) ?? 0;
|
|
152
|
+
return (cp >= 0xe000 && cp <= 0xf8ff) || cp >= 0xf0000;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export function paintChatboxPrompt(
|
|
156
|
+
promptGlyph: string,
|
|
157
|
+
th: { fg?(color: string, text: string): string } | null | undefined,
|
|
158
|
+
active: boolean,
|
|
159
|
+
): string {
|
|
160
|
+
const text = isWideNerdPrompt(promptGlyph) ? ` ${promptGlyph} ` : ` ${promptGlyph} `;
|
|
161
|
+
if (!th?.fg) return text;
|
|
162
|
+
try {
|
|
163
|
+
if (!active) return th.fg("dim", text);
|
|
164
|
+
return chatboxPrimaryPaint(th)(text);
|
|
165
|
+
} catch {
|
|
166
|
+
return text;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export function renderChatboxScrollBorder(
|
|
171
|
+
direction: "\u2191" | "\u2193",
|
|
172
|
+
hiddenLineCount: number,
|
|
173
|
+
width: number,
|
|
174
|
+
borderColor: (text: string) => string,
|
|
175
|
+
primaryColor: (text: string) => string,
|
|
176
|
+
): string {
|
|
177
|
+
const availableWidth = Math.max(0, width);
|
|
178
|
+
if (hiddenLineCount <= 0) return borderColor("\u2500".repeat(availableWidth));
|
|
179
|
+
const core = `${direction} ${hiddenLineCount} more`;
|
|
180
|
+
const labelWidth = visibleWidth(core) + 2;
|
|
181
|
+
if (labelWidth + 2 <= availableWidth) {
|
|
182
|
+
const leftWidth = Math.floor((availableWidth - labelWidth) / 2);
|
|
183
|
+
const rightWidth = availableWidth - leftWidth - labelWidth;
|
|
184
|
+
return `${borderColor(`${"\u2500".repeat(leftWidth)} `)}${primaryColor(core)}${borderColor(` ${"\u2500".repeat(rightWidth)}`)}`;
|
|
185
|
+
}
|
|
186
|
+
const prefix = "\u2500\u2500\u2500 ";
|
|
187
|
+
const remaining = availableWidth - visibleWidth(prefix) - visibleWidth(core) - 1;
|
|
188
|
+
if (remaining >= 0) {
|
|
189
|
+
return `${borderColor(prefix)}${primaryColor(core)}${borderColor(` ${"\u2500".repeat(remaining)}`)}`;
|
|
190
|
+
}
|
|
191
|
+
return borderColor(".".repeat(Math.min(3, availableWidth)) + "\u2500".repeat(Math.max(0, availableWidth - 3)));
|
|
192
|
+
}
|
|
193
|
+
|
|
42
194
|
export const FOOTER_PRESETS = ["Pi (system)", "Arnative (Full)", "Arnative (Minimal)"] as const;
|
|
43
195
|
export type FooterPreset = (typeof FOOTER_PRESETS)[number];
|
|
44
196
|
export const DEFAULT_FOOTER_PRESET: FooterPreset = "Arnative (Full)";
|
|
@@ -536,6 +688,19 @@ export function formatDuration(ms: number): string {
|
|
|
536
688
|
// already rendered at width - 5 (2 sides + 3 prompt) and the border is patched with
|
|
537
689
|
// dashes to match. `visible` = content line count (private `renderedVisibleLineCount`);
|
|
538
690
|
// autocomplete lines stay outside the box. JetBrainsMono NF has the round glyphs.
|
|
691
|
+
export function renderChatboxLines(
|
|
692
|
+
preset: ChatboxPreset,
|
|
693
|
+
renderInner: (w: number) => string[],
|
|
694
|
+
width: number,
|
|
695
|
+
visible: number | undefined,
|
|
696
|
+
color: (text: string) => string,
|
|
697
|
+
prompt = " > ",
|
|
698
|
+
): string[] {
|
|
699
|
+
const promptW = visibleWidth(prompt);
|
|
700
|
+
if (preset === "Pi (system)" || typeof visible !== "number" || width < promptW + 8) return renderInner(width);
|
|
701
|
+
return boxEditorLines(renderInner(width - (2 + promptW)), visible, color, prompt);
|
|
702
|
+
}
|
|
703
|
+
|
|
539
704
|
export function boxEditorLines(
|
|
540
705
|
lines: readonly string[],
|
|
541
706
|
visible: number,
|
|
@@ -555,6 +720,191 @@ export function boxEditorLines(
|
|
|
555
720
|
return out;
|
|
556
721
|
}
|
|
557
722
|
|
|
723
|
+
function formatTopBorderDialog(
|
|
724
|
+
innerW: number,
|
|
725
|
+
hiddenLineCount: number,
|
|
726
|
+
dialog: "Left" | "Center" | "Right",
|
|
727
|
+
status: string,
|
|
728
|
+
spinnerOnly: string,
|
|
729
|
+
color: (text: string) => string,
|
|
730
|
+
primaryColor: (text: string) => string = (t) => t,
|
|
731
|
+
): string {
|
|
732
|
+
const scrollCore = hiddenLineCount > 0 ? `\u2191 ${hiddenLineCount} more` : "";
|
|
733
|
+
const scrollW = scrollCore ? visibleWidth(scrollCore) + 2 : 0;
|
|
734
|
+
const scrollPainted = scrollCore ? `${color(" ")}${primaryColor(scrollCore)}${color(" ")}` : "";
|
|
735
|
+
const tryPlace = (label: string): string | null => {
|
|
736
|
+
const lw = visibleWidth(label);
|
|
737
|
+
if (lw === 0 || innerW < lw + 4) return null;
|
|
738
|
+
if (dialog === "Left") {
|
|
739
|
+
if (scrollW > 0) {
|
|
740
|
+
const centerStart = Math.floor((innerW - scrollW) / 2);
|
|
741
|
+
if (centerStart >= 4 + lw + 1) {
|
|
742
|
+
return `${color("\u2500\u2500 ")}${label}${color(` ${"\u2500".repeat(centerStart - (4 + lw))}`)}${scrollPainted}${color("\u2500".repeat(innerW - centerStart - scrollW))}`;
|
|
743
|
+
}
|
|
744
|
+
return null;
|
|
745
|
+
}
|
|
746
|
+
return color("\u2500\u2500 ") + label + color(` ${"\u2500".repeat(innerW - lw - 4)}`);
|
|
747
|
+
}
|
|
748
|
+
if (dialog === "Center") {
|
|
749
|
+
const leftD = Math.floor((innerW - lw - 2) / 2);
|
|
750
|
+
const rightD = innerW - lw - 2 - leftD;
|
|
751
|
+
if (scrollW > 0) {
|
|
752
|
+
const leftEnd = 2 + scrollW;
|
|
753
|
+
if (leftD >= leftEnd + 1) {
|
|
754
|
+
return `${color("\u2500\u2500")}${scrollPainted}${color(`${"\u2500".repeat(leftD - leftEnd)} `)}${label}${color(` ${"\u2500".repeat(rightD)}`)}`;
|
|
755
|
+
}
|
|
756
|
+
return null;
|
|
757
|
+
}
|
|
758
|
+
return color(`${"\u2500".repeat(leftD)} `) + label + color(` ${"\u2500".repeat(rightD)}`);
|
|
759
|
+
}
|
|
760
|
+
// Right
|
|
761
|
+
if (scrollW > 0) {
|
|
762
|
+
const centerStart = Math.floor((innerW - scrollW) / 2);
|
|
763
|
+
if (centerStart + scrollW + 1 <= innerW - lw - 4) {
|
|
764
|
+
return `${color("\u2500".repeat(centerStart))}${scrollPainted}${color(`${"\u2500".repeat(innerW - lw - 4 - centerStart - scrollW)} `)}${label}${color(" \u2500\u2500")}`;
|
|
765
|
+
}
|
|
766
|
+
return null;
|
|
767
|
+
}
|
|
768
|
+
return color(`${"\u2500".repeat(innerW - lw - 4)} `) + label + color(" \u2500\u2500");
|
|
769
|
+
};
|
|
770
|
+
const placed = tryPlace(status) ?? (spinnerOnly ? tryPlace(spinnerOnly) : null);
|
|
771
|
+
if (placed) return placed;
|
|
772
|
+
const fallback = spinnerOnly || status;
|
|
773
|
+
const fw = visibleWidth(fallback);
|
|
774
|
+
if (innerW >= fw + 4) {
|
|
775
|
+
if (dialog === "Right") return color(`${"\u2500".repeat(innerW - fw - 4)} `) + fallback + color(" \u2500\u2500");
|
|
776
|
+
if (dialog === "Center") {
|
|
777
|
+
const leftD = Math.floor((innerW - fw - 2) / 2);
|
|
778
|
+
return color(`${"\u2500".repeat(leftD)} `) + fallback + color(` ${"\u2500".repeat(innerW - fw - 2 - leftD)}`);
|
|
779
|
+
}
|
|
780
|
+
return color("\u2500\u2500 ") + fallback + color(` ${"\u2500".repeat(innerW - fw - 4)}`);
|
|
781
|
+
}
|
|
782
|
+
const sw = Math.min(fw, innerW);
|
|
783
|
+
const prefixW = dialog === "Right" ? Math.max(0, innerW - sw) : dialog === "Center" ? Math.max(0, Math.floor((innerW - sw) / 2)) : Math.min(2, Math.max(0, innerW - sw));
|
|
784
|
+
return color("\u2500".repeat(prefixW)) + truncateToWidth(fallback, sw, "") + color("\u2500".repeat(Math.max(0, innerW - prefixW - sw)));
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
/** Places the active working/status dialog relative to the chatbox per the user's Dialog preset. */
|
|
788
|
+
export function applyChatboxDialog(
|
|
789
|
+
lines: readonly string[],
|
|
790
|
+
boxed: boolean,
|
|
791
|
+
width: number,
|
|
792
|
+
hiddenLineCount: number,
|
|
793
|
+
dialog: ChatboxDialog,
|
|
794
|
+
status: string,
|
|
795
|
+
spinnerOnly: string,
|
|
796
|
+
color: (text: string) => string,
|
|
797
|
+
primaryColor: (text: string) => string = (t) => t,
|
|
798
|
+
): string[] {
|
|
799
|
+
const sw = visibleWidth(status);
|
|
800
|
+
if (sw === 0 || lines.length === 0) return [...lines];
|
|
801
|
+
const out = [...lines];
|
|
802
|
+
// Outside renders onto the existing above-editor widget row (no extra line added here).
|
|
803
|
+
if (dialog === "Outside") return out;
|
|
804
|
+
if (dialog === "Inside") {
|
|
805
|
+
if (out.length < 2) return out;
|
|
806
|
+
const side = boxed ? color("\u2502") : "";
|
|
807
|
+
if (boxed && (!out[1]!.startsWith(side) || !out[1]!.endsWith(side))) return out;
|
|
808
|
+
const inner = boxed ? out[1]!.slice(side.length, out[1]!.length - side.length) : out[1]!;
|
|
809
|
+
const innerW = boxed ? width - 2 : width;
|
|
810
|
+
const trimmed = inner.replace(/ +$/, "");
|
|
811
|
+
const gap = innerW - visibleWidth(trimmed);
|
|
812
|
+
if (gap >= sw + 2) {
|
|
813
|
+
out[1] = side + trimmed + " ".repeat(gap - sw - 1) + status + " " + side;
|
|
814
|
+
} else if (innerW >= sw + 6) {
|
|
815
|
+
const kept = truncateToWidth(trimmed, innerW - sw - 2, "");
|
|
816
|
+
const pad = Math.max(1, innerW - visibleWidth(kept) - sw - 1);
|
|
817
|
+
out[1] = side + kept + " ".repeat(pad) + status + " " + side;
|
|
818
|
+
}
|
|
819
|
+
return out;
|
|
820
|
+
}
|
|
821
|
+
const innerW = boxed ? Math.max(1, width - 2) : width;
|
|
822
|
+
const topInner = formatTopBorderDialog(innerW, hiddenLineCount, dialog, status, spinnerOnly, color, primaryColor);
|
|
823
|
+
out[0] = boxed ? color("\u256d") + topInner + color("\u256e") : topInner;
|
|
824
|
+
return out;
|
|
825
|
+
}
|
|
826
|
+
|
|
827
|
+
/** Left-aligns the Outside dialog status in the above-editor slot with 1 blank line
|
|
828
|
+
* above and below so it never crowds adjacent messages, Todos, or the chatbox, while
|
|
829
|
+
* keeping inline notices beside it on the same row. */
|
|
830
|
+
export function overlayOutsideDialogOnWidgetLines(lines: readonly string[], width: number, status: string): string[] {
|
|
831
|
+
const sw = visibleWidth(status);
|
|
832
|
+
if (sw === 0) return [...lines];
|
|
833
|
+
const leftRow = truncateToWidth(` ${status}`, width, "");
|
|
834
|
+
if (lines.length === 0) return ["", leftRow, ""];
|
|
835
|
+
const out = [...lines];
|
|
836
|
+
const lastIdx = out.length - 1;
|
|
837
|
+
const last = out[lastIdx]!;
|
|
838
|
+
const plainLast = stripAnsi(last).trim();
|
|
839
|
+
if (plainLast.length === 0) {
|
|
840
|
+
return ["", leftRow, ""];
|
|
841
|
+
}
|
|
842
|
+
if (!/^[╭╰│]/.test(plainLast)) {
|
|
843
|
+
const trimmed = last.replace(/ +$/, "");
|
|
844
|
+
const rest = trimmed.startsWith(" ") ? trimmed : ` ${trimmed}`;
|
|
845
|
+
out[lastIdx] = truncateToWidth(` ${status} ${rest}`, width, "");
|
|
846
|
+
if (stripAnsi(out[0]!).trim().length > 0) out.unshift("");
|
|
847
|
+
out.push("");
|
|
848
|
+
return out;
|
|
849
|
+
}
|
|
850
|
+
const boxStart = out.findIndex((line) => /^[╭╰│]/.test(stripAnsi(line).trim()));
|
|
851
|
+
const prefix = out.slice(0, boxStart).filter((line) => stripAnsi(line).trim().length > 0);
|
|
852
|
+
const boxed = out.slice(boxStart);
|
|
853
|
+
return prefix.length > 0 ? ["", leftRow, "", ...prefix, "", ...boxed] : ["", leftRow, "", ...boxed];
|
|
854
|
+
}
|
|
855
|
+
|
|
856
|
+
const OUTSIDE_HOOK_KEY = Symbol.for("pi-arnative.outsideDialogHook");
|
|
857
|
+
const ABOVE_WRAPPED_KEY = Symbol.for("pi-arnative.aboveWidgetWrapped");
|
|
858
|
+
const ABOVE_MODE_KEY = Symbol.for("pi-arnative.aboveWidgetMode");
|
|
859
|
+
|
|
860
|
+
function installAboveEditorHook(widgetContainer: { render?: (w: number) => string[] } | undefined, mode: unknown): void {
|
|
861
|
+
if (!widgetContainer || typeof widgetContainer.render !== "function") return;
|
|
862
|
+
const box = widgetContainer as Record<symbol, unknown> & { render: (w: number) => string[] };
|
|
863
|
+
box[ABOVE_MODE_KEY] = mode;
|
|
864
|
+
if (box[ABOVE_WRAPPED_KEY]) return;
|
|
865
|
+
box[ABOVE_WRAPPED_KEY] = true;
|
|
866
|
+
const ownOrig = Object.hasOwn(box, "render") ? box.render : null;
|
|
867
|
+
box.render = function (this: Record<symbol, unknown>, width: number): string[] {
|
|
868
|
+
// Delegate to the live prototype render when not overridden on the instance so `/reload`
|
|
869
|
+
// changes to Container.prototype.render still apply without touching prototype originals.
|
|
870
|
+
const baseRender = ownOrig ?? (Object.getPrototypeOf(this) as { render: (w: number) => string[] }).render;
|
|
871
|
+
const lines = baseRender.call(this, width);
|
|
872
|
+
try {
|
|
873
|
+
const hook = (globalThis as Record<symbol, ((l: string[], w: number, m: unknown) => string[]) | undefined>)[OUTSIDE_HOOK_KEY];
|
|
874
|
+
return hook ? hook(lines, width, this[ABOVE_MODE_KEY]) : lines;
|
|
875
|
+
} catch {
|
|
876
|
+
return lines;
|
|
877
|
+
}
|
|
878
|
+
};
|
|
879
|
+
}
|
|
880
|
+
|
|
881
|
+
if (InteractiveMode?.prototype) {
|
|
882
|
+
const modeProto = InteractiveMode.prototype as unknown as {
|
|
883
|
+
renderWidgetContainer?: (container: unknown, widgets: unknown, spacerWhenEmpty: boolean, leadingSpacer: boolean) => void;
|
|
884
|
+
showStatusIndicator?: (indicator: unknown) => void;
|
|
885
|
+
};
|
|
886
|
+
if (typeof modeProto.renderWidgetContainer === "function") {
|
|
887
|
+
patchOnce(modeProto, "renderWidgetContainer", (orig) => function (
|
|
888
|
+
this: any,
|
|
889
|
+
container: unknown,
|
|
890
|
+
widgets: unknown,
|
|
891
|
+
spacerWhenEmpty: boolean,
|
|
892
|
+
leadingSpacer: boolean,
|
|
893
|
+
): void {
|
|
894
|
+
if (container && container === this.widgetContainerAbove) {
|
|
895
|
+
installAboveEditorHook(container as { render?: (w: number) => string[] }, this);
|
|
896
|
+
}
|
|
897
|
+
orig.call(this, container, widgets, spacerWhenEmpty, leadingSpacer);
|
|
898
|
+
});
|
|
899
|
+
}
|
|
900
|
+
if (typeof modeProto.showStatusIndicator === "function") {
|
|
901
|
+
patchOnce(modeProto, "showStatusIndicator", (orig) => function (this: any, indicator: unknown): void {
|
|
902
|
+
installAboveEditorHook(this.widgetContainerAbove, this);
|
|
903
|
+
orig.call(this, indicator);
|
|
904
|
+
});
|
|
905
|
+
}
|
|
906
|
+
}
|
|
907
|
+
|
|
558
908
|
/**
|
|
559
909
|
* The footer as a fixed 3-row grid. Row 1 pairs the head cells (cwd line, model);
|
|
560
910
|
* rows 2-3 pair the wrapped left cells (extension status, mcp first) with the
|
|
@@ -766,7 +1116,8 @@ export const RATE_MIN_WIDTH = 80;
|
|
|
766
1116
|
* is hidden below RATE_MIN_ACTIVE_MS of active time and below RATE_MIN_WIDTH columns.
|
|
767
1117
|
* `bandPaint` paints the whole cell (icon and text) when a budget cap is near or over —
|
|
768
1118
|
* amber at `warn`, red at `over` (see `budgetLevelNow`); without it the icon keeps `acc` and
|
|
769
|
-
* the text `soft`.
|
|
1119
|
+
* the text `soft`. The rate suffix is secondary information, so it renders `dim` (or the band
|
|
1120
|
+
* paint when a cap is active, keeping the alert one colour). */
|
|
770
1121
|
export function costCell(
|
|
771
1122
|
costBilled: number,
|
|
772
1123
|
costEstimated: number,
|
|
@@ -774,24 +1125,31 @@ export function costCell(
|
|
|
774
1125
|
soft: (t: string) => string,
|
|
775
1126
|
width: number = RATE_MIN_WIDTH,
|
|
776
1127
|
bandPaint?: (t: string) => string,
|
|
1128
|
+
dim?: (t: string) => string,
|
|
777
1129
|
): string {
|
|
778
1130
|
if (!(costBilled > 0) && !(costEstimated > 0)) return "";
|
|
779
1131
|
const parts: string[] = [];
|
|
780
1132
|
if (costBilled > 0) parts.push(formatCost(costBilled));
|
|
781
1133
|
if (costEstimated > 0) parts.push(`~${formatCost(costEstimated)}`);
|
|
782
|
-
|
|
1134
|
+
const text = parts.join(" + ");
|
|
1135
|
+
let rate = "";
|
|
783
1136
|
const activeMs = clock.total();
|
|
784
1137
|
if (activeMs >= RATE_MIN_ACTIVE_MS && width >= RATE_MIN_WIDTH) {
|
|
785
|
-
const
|
|
786
|
-
|
|
1138
|
+
const perHour = (costBilled + costEstimated) / (activeMs / 3_600_000);
|
|
1139
|
+
rate = `(${costEstimated > 0 ? "~" : ""}${formatCost(perHour)}/h)`;
|
|
787
1140
|
}
|
|
788
|
-
|
|
1141
|
+
const cell = `${(bandPaint ?? acc)("\uf155")} ${(bandPaint ?? soft)(text)}`;
|
|
1142
|
+
return rate ? `${cell} ${(bandPaint ?? dim ?? soft)(rate)}` : cell;
|
|
789
1143
|
}
|
|
790
1144
|
|
|
791
1145
|
// 2s cache + branch length: the footer renders on every poke/stream tick, so
|
|
792
1146
|
// without this every frame rescans the whole branch (O(N) per frame).
|
|
793
1147
|
export function getUsage(
|
|
794
|
-
ctx: {
|
|
1148
|
+
ctx: {
|
|
1149
|
+
sessionManager: { getBranch(): readonly unknown[] };
|
|
1150
|
+
getContextUsage(): { tokens: number | null; contextWindow: number; percent: number | null } | undefined;
|
|
1151
|
+
model?: { id?: string; provider?: string };
|
|
1152
|
+
},
|
|
795
1153
|
acc: (t: string) => string,
|
|
796
1154
|
soft: (t: string) => string,
|
|
797
1155
|
/** Off by default: the cost cell is opt-in (`/arnative` → Footers → `[c]`). */
|
|
@@ -877,10 +1235,10 @@ export function getUsage(
|
|
|
877
1235
|
if (read > 0) parts.push(`${acc("\uf49b")} ${soft(formatTokens(read))}`);
|
|
878
1236
|
const u = ctx.getContextUsage();
|
|
879
1237
|
if (u && u.percent !== null && u.tokens !== null) {
|
|
880
|
-
parts.push(`${acc("\
|
|
1238
|
+
parts.push(`${acc("\ueb85")} ${soft(`${u.percent.toFixed(1)}%/${formatTokens(u.contextWindow)}`)}`);
|
|
881
1239
|
}
|
|
882
1240
|
if (showCost) {
|
|
883
|
-
const cell = costCell(costBilled, costEstimated, acc, soft, width, bandPaint);
|
|
1241
|
+
const cell = costCell(costBilled, costEstimated, acc, soft, width, bandPaint, dim);
|
|
884
1242
|
// The dollar icon opens a new group, so it takes the same divider the footer uses
|
|
885
1243
|
// between cells; the token and context parts stay a space apart.
|
|
886
1244
|
if (cell) parts.push(parts.length > 0 ? `${dim("·")} ${cell}` : cell);
|
|
@@ -888,9 +1246,12 @@ export function getUsage(
|
|
|
888
1246
|
return parts.join(" ");
|
|
889
1247
|
}
|
|
890
1248
|
|
|
1249
|
+
let editorTui: { requestRender?: () => void } | null = null;
|
|
1250
|
+
|
|
891
1251
|
function poke(): void {
|
|
892
1252
|
try {
|
|
893
|
-
rerender
|
|
1253
|
+
if (rerender) rerender();
|
|
1254
|
+
else editorTui?.requestRender?.();
|
|
894
1255
|
} catch {
|
|
895
1256
|
// ignore
|
|
896
1257
|
}
|
|
@@ -1243,6 +1604,20 @@ export default function (pi: ExtensionAPI) {
|
|
|
1243
1604
|
for (const [k, s] of statuses) {
|
|
1244
1605
|
if (k !== "mcp" && k !== "pi-cache-stats") groups.push(cleanStatus(s));
|
|
1245
1606
|
}
|
|
1607
|
+
// Payload pressure sits beside the extension statuses: the right rows
|
|
1608
|
+
// already carry speed, cache, tokens and cost. The denominator is the shed
|
|
1609
|
+
// trigger from the snapshot (900KB), not the 1MB proxy wall: showing /1MB
|
|
1610
|
+
// understated pressure by 10 points right before the trim starts.
|
|
1611
|
+
const wire = wireBytesSnapshot();
|
|
1612
|
+
if (wire && wire.bytes > 0 && isByteLimitedModel(ctx.model)) {
|
|
1613
|
+
// Under a 1 MB wall the label keeps the approved shape `0.74MB/900KB`: the
|
|
1614
|
+
// payload in MB, the ceiling in KB. A bigger wall scales both to MB so the
|
|
1615
|
+
// ceiling stays readable instead of printing 14336KB.
|
|
1616
|
+
const label = wire.limit >= 1024 * 1024
|
|
1617
|
+
? `${(wire.bytes / 1024 / 1024).toFixed(2)}MB/${(wire.limit / 1024 / 1024).toFixed(2)}MB`
|
|
1618
|
+
: `${(wire.bytes / 1024 / 1024).toFixed(2)}MB/${Math.round(wire.limit / 1024)}KB`;
|
|
1619
|
+
groups.push(`${acc("\udb80\udd93")} ${secondarySoft(label)}`);
|
|
1620
|
+
}
|
|
1246
1621
|
|
|
1247
1622
|
let usageStr = "";
|
|
1248
1623
|
try {
|
|
@@ -1310,8 +1685,14 @@ export default function (pi: ExtensionAPI) {
|
|
|
1310
1685
|
(globalThis as Record<symbol, (ctx: ExtensionContext) => void>)[FOOTER_REGISTRAR_KEY] = registerArnative;
|
|
1311
1686
|
applyFooterPreset(ctx);
|
|
1312
1687
|
class ArnativeEditor extends CustomEditor {
|
|
1688
|
+
private lastHiddenLineCount = 0;
|
|
1689
|
+
private lastBottomHiddenCount = 0;
|
|
1690
|
+
private topMoreSpans: TextSpan[] = [];
|
|
1691
|
+
private bottomMoreSpans: TextSpan[] = [];
|
|
1692
|
+
|
|
1313
1693
|
constructor(tui: any, editorTheme: any, keybindings: any, options?: any) {
|
|
1314
1694
|
super(tui, editorTheme, keybindings, { ...options, embedWorkingStatus: true });
|
|
1695
|
+
editorTui = tui;
|
|
1315
1696
|
// Published so `/arnative` → Animations can repaint the live spinner without
|
|
1316
1697
|
// waiting for the next session, and so workUI has a handle to the Loader.
|
|
1317
1698
|
(globalThis as Record<symbol, any>)[EDITOR_KEY] = this;
|
|
@@ -1344,8 +1725,91 @@ export default function (pi: ExtensionAPI) {
|
|
|
1344
1725
|
}
|
|
1345
1726
|
|
|
1346
1727
|
renderTopBorder(width: number, hiddenLineCount: number): string {
|
|
1728
|
+
this.lastHiddenLineCount = hiddenLineCount;
|
|
1347
1729
|
this.applyFixedIndicatorColors((this as any).workingStatusIndicator);
|
|
1348
|
-
|
|
1730
|
+
if (activeChatboxPreset() === "Arnative") {
|
|
1731
|
+
return renderChatboxScrollBorder(
|
|
1732
|
+
"\u2191",
|
|
1733
|
+
hiddenLineCount,
|
|
1734
|
+
width,
|
|
1735
|
+
(t) => this.borderColor(t),
|
|
1736
|
+
chatboxPrimaryPaint(this.getActiveTheme()),
|
|
1737
|
+
);
|
|
1738
|
+
}
|
|
1739
|
+
// Plain/scroll border only; render() positions the status dialog after boxing.
|
|
1740
|
+
const editorProto = Object.getPrototypeOf(CustomEditor.prototype) as {
|
|
1741
|
+
renderTopBorder?: (w: number, h: number) => string;
|
|
1742
|
+
};
|
|
1743
|
+
if (typeof editorProto?.renderTopBorder === "function") {
|
|
1744
|
+
return editorProto.renderTopBorder.call(this, width, hiddenLineCount);
|
|
1745
|
+
}
|
|
1746
|
+
return this.borderColor("\u2500".repeat(width));
|
|
1747
|
+
}
|
|
1748
|
+
|
|
1749
|
+
renderBottomBorder(width: number, hiddenLineCount: number): string {
|
|
1750
|
+
this.lastBottomHiddenCount = hiddenLineCount;
|
|
1751
|
+
if (activeChatboxPreset() === "Arnative") {
|
|
1752
|
+
return renderChatboxScrollBorder(
|
|
1753
|
+
"\u2193",
|
|
1754
|
+
hiddenLineCount,
|
|
1755
|
+
width,
|
|
1756
|
+
(t) => this.borderColor(t),
|
|
1757
|
+
chatboxPrimaryPaint(this.getActiveTheme()),
|
|
1758
|
+
);
|
|
1759
|
+
}
|
|
1760
|
+
const editorProto = Object.getPrototypeOf(CustomEditor.prototype) as {
|
|
1761
|
+
renderBottomBorder?: (w: number, h: number) => string;
|
|
1762
|
+
};
|
|
1763
|
+
if (typeof editorProto?.renderBottomBorder === "function") {
|
|
1764
|
+
return editorProto.renderBottomBorder.call(this, width, hiddenLineCount);
|
|
1765
|
+
}
|
|
1766
|
+
return this.borderColor("\u2500".repeat(width));
|
|
1767
|
+
}
|
|
1768
|
+
|
|
1769
|
+
private scrollByBorderClick(direction: -1 | 1): void {
|
|
1770
|
+
const ed = this as unknown as {
|
|
1771
|
+
lastWidth?: number;
|
|
1772
|
+
scrollOffset?: number;
|
|
1773
|
+
renderedVisibleLineCount?: number;
|
|
1774
|
+
buildVisualLineMap?(w: number): unknown[];
|
|
1775
|
+
findCurrentVisualLine?(vls: unknown[]): number;
|
|
1776
|
+
moveToVisualLine?(vls: unknown[], cur: number, target: number): void;
|
|
1777
|
+
pageScroll?(dir: number): void;
|
|
1778
|
+
};
|
|
1779
|
+
if (
|
|
1780
|
+
typeof ed.buildVisualLineMap === "function" &&
|
|
1781
|
+
typeof ed.findCurrentVisualLine === "function" &&
|
|
1782
|
+
typeof ed.moveToVisualLine === "function"
|
|
1783
|
+
) {
|
|
1784
|
+
const vls = ed.buildVisualLineMap(ed.lastWidth ?? 80);
|
|
1785
|
+
if (vls.length > 0) {
|
|
1786
|
+
const cur = ed.findCurrentVisualLine(vls);
|
|
1787
|
+
const vis = Math.max(1, ed.renderedVisibleLineCount ?? 5);
|
|
1788
|
+
const step = Math.max(1, Math.floor(vis / 2));
|
|
1789
|
+
const scrollOff = Math.max(0, ed.scrollOffset ?? 0);
|
|
1790
|
+
const target =
|
|
1791
|
+
direction < 0
|
|
1792
|
+
? Math.max(0, scrollOff - step)
|
|
1793
|
+
: Math.min(vls.length - 1, scrollOff + vis - 1 + step);
|
|
1794
|
+
ed.moveToVisualLine(vls, cur, target);
|
|
1795
|
+
return;
|
|
1796
|
+
}
|
|
1797
|
+
}
|
|
1798
|
+
ed.pageScroll?.(direction);
|
|
1799
|
+
}
|
|
1800
|
+
|
|
1801
|
+
handleMouse(event: TuiMouseEvent) {
|
|
1802
|
+
if (activeChatboxPreset() === "Arnative" && event.type === "click" && event.button === "left") {
|
|
1803
|
+
if (inSpans(this.topMoreSpans, event.y, event.x)) {
|
|
1804
|
+
this.scrollByBorderClick(-1);
|
|
1805
|
+
return { handled: true, focus: true };
|
|
1806
|
+
}
|
|
1807
|
+
if (inSpans(this.bottomMoreSpans, event.y, event.x)) {
|
|
1808
|
+
this.scrollByBorderClick(1);
|
|
1809
|
+
return { handled: true, focus: true };
|
|
1810
|
+
}
|
|
1811
|
+
}
|
|
1812
|
+
return super.handleMouse(event);
|
|
1349
1813
|
}
|
|
1350
1814
|
|
|
1351
1815
|
handleInput(data: string) {
|
|
@@ -1356,24 +1820,58 @@ export default function (pi: ExtensionAPI) {
|
|
|
1356
1820
|
}
|
|
1357
1821
|
return;
|
|
1358
1822
|
}
|
|
1823
|
+
if (!isPointerOrFocusInput(data)) markPromptTyped();
|
|
1359
1824
|
super.handleInput(data);
|
|
1360
1825
|
}
|
|
1361
1826
|
|
|
1362
1827
|
render(width: number): string[] {
|
|
1363
|
-
|
|
1828
|
+
const preset = activeChatboxPreset();
|
|
1829
|
+
const dialog = activeChatboxDialog();
|
|
1830
|
+
const indicator = (this as any).workingStatusIndicator as
|
|
1831
|
+
| { renderInBorder?(w: number): string; renderSpinnerInBorder?(w: number): string }
|
|
1832
|
+
| undefined;
|
|
1833
|
+
this.applyFixedIndicatorColors(indicator);
|
|
1834
|
+
// The box eats 5 columns: 2 sides + the 3-column prompt, so the
|
|
1364
1835
|
// content is rendered 5 columns narrower.
|
|
1365
1836
|
const visible = (this as unknown as { renderedVisibleLineCount?: number }).renderedVisibleLineCount;
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1837
|
+
const prompt = paintChatboxPrompt(activeChatboxPrompt(), this.getActiveTheme(), isPromptActive());
|
|
1838
|
+
const promptW = visibleWidth(prompt);
|
|
1839
|
+
const lines = renderChatboxLines(preset, (w) => super.render(w), width, visible, (t) => this.borderColor(t), prompt);
|
|
1840
|
+
const boxed = preset === "Arnative" && typeof visible === "number" && width >= promptW + 8 && lines.length >= visible + 2;
|
|
1841
|
+
const statusMax = Math.max(1, width - (boxed ? promptW + 4 : 5));
|
|
1842
|
+
const status = indicator?.renderInBorder?.(statusMax) ?? "";
|
|
1843
|
+
const spinnerOnly = status ? (indicator?.renderSpinnerInBorder?.(width) ?? "") : "";
|
|
1844
|
+
const primary = chatboxPrimaryPaint(this.getActiveTheme());
|
|
1845
|
+
const out = applyChatboxDialog(lines, boxed, width, this.lastHiddenLineCount, dialog, status, spinnerOnly, (t) => this.borderColor(t), primary);
|
|
1846
|
+
const visNow = (this as unknown as { renderedVisibleLineCount?: number }).renderedVisibleLineCount ?? 0;
|
|
1847
|
+
this.topMoreSpans =
|
|
1848
|
+
this.lastHiddenLineCount > 0 && out.length > 0
|
|
1849
|
+
? textSpans([out[0]!], `\u2191 ${this.lastHiddenLineCount} more`)
|
|
1850
|
+
: [];
|
|
1851
|
+
const botRow = visNow + 1;
|
|
1852
|
+
this.bottomMoreSpans =
|
|
1853
|
+
this.lastBottomHiddenCount > 0 && botRow < out.length
|
|
1854
|
+
? textSpans([out[botRow]!], `\u2193 ${this.lastBottomHiddenCount} more`).map((s) => ({ ...s, row: botRow }))
|
|
1855
|
+
: [];
|
|
1856
|
+
return out;
|
|
1374
1857
|
}
|
|
1375
1858
|
}
|
|
1376
1859
|
ctx.ui.setEditorComponent((tui, editorTheme, keybindings) => new ArnativeEditor(tui, editorTheme, keybindings));
|
|
1860
|
+
(globalThis as Record<symbol, unknown>)[OUTSIDE_HOOK_KEY] = (lines: string[], width: number, mode: any): string[] => {
|
|
1861
|
+
if (activeChatboxDialog() !== "Outside") return lines;
|
|
1862
|
+
const editor = (globalThis as Record<symbol, any>)[EDITOR_KEY] as
|
|
1863
|
+
| { workingStatusIndicator?: { renderInBorder?(w: number): string }; applyFixedIndicatorColors?: (ind: any) => void }
|
|
1864
|
+
| undefined;
|
|
1865
|
+
if (!editor || mode?.editor !== editor) return lines;
|
|
1866
|
+
const children = mode?.editorContainer?.children;
|
|
1867
|
+
if (Array.isArray(children) && !children.includes(editor)) return lines;
|
|
1868
|
+
const indicator = editor.workingStatusIndicator;
|
|
1869
|
+
if (!indicator) return lines;
|
|
1870
|
+
editor.applyFixedIndicatorColors?.(indicator);
|
|
1871
|
+
const status = indicator.renderInBorder?.(Math.max(1, width - 5)) ?? "";
|
|
1872
|
+
if (!status || visibleWidth(status) === 0) return lines;
|
|
1873
|
+
return overlayOutsideDialogOnWidgetLines(lines, width, status);
|
|
1874
|
+
};
|
|
1377
1875
|
} catch {
|
|
1378
1876
|
// fallback
|
|
1379
1877
|
}
|
|
@@ -1483,7 +1981,10 @@ export default function (pi: ExtensionAPI) {
|
|
|
1483
1981
|
usageScanLeaf = undefined;
|
|
1484
1982
|
stopWorkingClock();
|
|
1485
1983
|
stopIdleProbe();
|
|
1984
|
+
stopPromptIdle();
|
|
1486
1985
|
stopClockTick();
|
|
1986
|
+
editorTui = null;
|
|
1987
|
+
(globalThis as Record<symbol, unknown>)[OUTSIDE_HOOK_KEY] = null;
|
|
1487
1988
|
try {
|
|
1488
1989
|
ctx.ui?.setWorkingIndicator?.();
|
|
1489
1990
|
} catch {
|
|
@@ -1553,6 +2054,12 @@ if (isMain(import.meta.url)) {
|
|
|
1553
2054
|
assert(visibleWidth(boxedDim[1]!) === visibleWidth(D) + 5, "ANSI (dim) prompt does not shift the width");
|
|
1554
2055
|
assert(boxedDim[1]!.startsWith(`\u2502${dimP(" > ")}`), "dim prompt kept as-is");
|
|
1555
2056
|
|
|
2057
|
+
const widthsSeen: number[] = [];
|
|
2058
|
+
const piChatbox = renderChatboxLines("Pi (system)", (w) => (widthsSeen.push(w), [D, " hi ", D]), 16, 1, plain);
|
|
2059
|
+
assert(widthsSeen[0] === 16 && piChatbox[0] === D, "Pi (system) chatbox renders stock lines at full width");
|
|
2060
|
+
const arnativeChatbox = renderChatboxLines("Arnative", (w) => (widthsSeen.push(w), [D, " hi ", D]), 16, 1, plain);
|
|
2061
|
+
assert(widthsSeen[1] === 11 && arnativeChatbox[0]!.startsWith("\u256d"), "Arnative chatbox renders boxed lines at width - 5");
|
|
2062
|
+
|
|
1556
2063
|
// Self-check: getToolWorkingMessage
|
|
1557
2064
|
assert(getToolWorkingMessage("edit") === "Editing", "edit -> Editing");
|
|
1558
2065
|
assert(getToolWorkingMessage("write") === "Writing", "write -> Writing");
|
|
@@ -1864,6 +2371,89 @@ if (isMain(import.meta.url)) {
|
|
|
1864
2371
|
delete (globalThis as Record<symbol, unknown>)[FOOTER_PRESET_KEY];
|
|
1865
2372
|
resetPresetCache();
|
|
1866
2373
|
assert(activeFooterPreset() === "Pi (system)", "a restart reads the non-default footer preset back from disk");
|
|
2374
|
+
|
|
2375
|
+
// Chatbox presets & prompt arrows: Arnative + ❯ are the defaults; Pi (system) and prompt choice persist across restarts.
|
|
2376
|
+
assert(DEFAULT_CHATBOX_PRESET === "Arnative" && CHATBOX_PRESETS.join(" | ") === "Pi (system) | Arnative", "chatbox presets are Pi (system) then Arnative");
|
|
2377
|
+
assert(activeChatboxPreset() === "Arnative", "Arnative is the default chatbox preset");
|
|
2378
|
+
assert(DEFAULT_CHATBOX_PROMPT === "❯" && CHATBOX_PROMPTS[0] === "❯" && CHATBOX_PROMPTS.length === 12, "chatbox prompts default to ❯ with 12 choices");
|
|
2379
|
+
assert(CHATBOX_PROMPTS.every((g) => visibleWidth(g) === 1), "every chatbox prompt glyph is 1 cell wide");
|
|
2380
|
+
assert(nextChatboxPrompt("❯") === ">" && nextChatboxPrompt("\udb80\udd7a") === "❯", "nextChatboxPrompt cycles through every arrow and wraps");
|
|
2381
|
+
assert(DEFAULT_CHATBOX_DIALOG === "Left" && CHATBOX_DIALOGS.join(" | ") === "Left | Center | Right | Inside | Outside", "chatbox dialog defaults to Left with 5 positions");
|
|
2382
|
+
assert(nextChatboxDialog("Left") === "Center" && nextChatboxDialog("Outside") === "Left", "nextChatboxDialog cycles through every position and wraps");
|
|
2383
|
+
setChatboxPreset("Pi (system)");
|
|
2384
|
+
setChatboxPrompt("▸");
|
|
2385
|
+
setChatboxDialog("Outside");
|
|
2386
|
+
assert(loadChoice(CHATBOX_PRESET_CONFIG_KEY, CHATBOX_PRESETS) === "Pi (system)", "the chatbox preset is persisted to disk");
|
|
2387
|
+
assert(loadChoice(CHATBOX_PROMPT_CONFIG_KEY, CHATBOX_PROMPTS) === "▸", "the chatbox prompt is persisted to disk");
|
|
2388
|
+
assert(loadChoice(CHATBOX_DIALOG_CONFIG_KEY, CHATBOX_DIALOGS) === "Outside", "the chatbox dialog is persisted to disk");
|
|
2389
|
+
delete (globalThis as Record<symbol, unknown>)[CHATBOX_PRESET_KEY];
|
|
2390
|
+
delete (globalThis as Record<symbol, unknown>)[CHATBOX_PROMPT_KEY];
|
|
2391
|
+
delete (globalThis as Record<symbol, unknown>)[CHATBOX_DIALOG_KEY];
|
|
2392
|
+
resetPresetCache();
|
|
2393
|
+
assert(activeChatboxPreset() === "Pi (system)", "a restart reads the non-default chatbox preset back from disk");
|
|
2394
|
+
assert(activeChatboxPrompt() === "▸", "a restart reads the non-default chatbox prompt back from disk");
|
|
2395
|
+
assert(activeChatboxDialog() === "Outside", "a restart reads the non-default chatbox dialog back from disk");
|
|
2396
|
+
delete (globalThis as Record<symbol, unknown>)[CHATBOX_PRESET_KEY];
|
|
2397
|
+
delete (globalThis as Record<symbol, unknown>)[CHATBOX_PROMPT_KEY];
|
|
2398
|
+
delete (globalThis as Record<symbol, unknown>)[CHATBOX_DIALOG_KEY];
|
|
2399
|
+
|
|
2400
|
+
// Chatbox dialog placement: Left, Center, Right, Inside, and Outside keep exact box width.
|
|
2401
|
+
const dW = 36;
|
|
2402
|
+
const dBox = boxEditorLines(["\u2500".repeat(dW - 5), "hi" + " ".repeat(dW - 7), "\u2500".repeat(dW - 5)], 1, plain, " ❯ ");
|
|
2403
|
+
const dStatus = "Working (1s)";
|
|
2404
|
+
for (const pos of CHATBOX_DIALOGS) {
|
|
2405
|
+
const rendered = applyChatboxDialog(dBox, true, dW, 0, pos, dStatus, "*", plain);
|
|
2406
|
+
assert(rendered.every((r) => visibleWidth(r) <= dW), `dialog ${pos} never exceeds width`);
|
|
2407
|
+
if (pos === "Outside") {
|
|
2408
|
+
assert(rendered.length === dBox.length && rendered[0] === dBox[0], "Outside dialog leaves editor box unchanged");
|
|
2409
|
+
} else if (pos === "Inside") {
|
|
2410
|
+
assert(rendered.length === dBox.length && rendered[0] === dBox[0] && rendered[1]!.includes(dStatus) && rendered[1]!.endsWith("│"), "Inside dialog sits inside line 1 at the right corner");
|
|
2411
|
+
} else if (pos === "Left") {
|
|
2412
|
+
assert(rendered[0]!.startsWith("╭── Working (1s) ") && visibleWidth(rendered[0]!) === dW, "Left dialog sits on the left of the top border");
|
|
2413
|
+
} else if (pos === "Center") {
|
|
2414
|
+
const idx = rendered[0]!.indexOf(dStatus);
|
|
2415
|
+
assert(idx > 4 && idx < dW - dStatus.length - 4 && visibleWidth(rendered[0]!) === dW, "Center dialog sits centered on the top border");
|
|
2416
|
+
} else if (pos === "Right") {
|
|
2417
|
+
assert(rendered[0]!.endsWith(" Working (1s) ──╮") && visibleWidth(rendered[0]!) === dW, "Right dialog sits on the right of the top border");
|
|
2418
|
+
}
|
|
2419
|
+
}
|
|
2420
|
+
const outZero = overlayOutsideDialogOnWidgetLines([], dW, dStatus);
|
|
2421
|
+
assert(outZero.length === 3 && outZero[0] === "" && outZero[1] === ` ${dStatus}` && outZero[2] === "", "Outside dialog renders with 1 blank line above and below even when widgetContainerAbove is empty");
|
|
2422
|
+
const outEmpty = overlayOutsideDialogOnWidgetLines([""], dW, dStatus);
|
|
2423
|
+
assert(outEmpty.length === 3 && outEmpty[0] === "" && outEmpty[1] === ` ${dStatus}` && outEmpty[2] === "", "Outside dialog pads 1 blank line above and below when no widget is shown");
|
|
2424
|
+
const outNotice = overlayOutsideDialogOnWidgetLines(["", " \ueb1b Chatbox: Arnative."], 60, dStatus);
|
|
2425
|
+
assert(outNotice.length === 3 && outNotice[0] === "" && outNotice[1] === ` ${dStatus} \ueb1b Chatbox: Arnative.` && outNotice[2] === "", "Outside dialog sits on the left with the notice beside it and 1 blank line below");
|
|
2426
|
+
const outTodos = overlayOutsideDialogOnWidgetLines(["", "\u256d" + "\u2500".repeat(58) + "\u256e", "\u2570" + "\u2500".repeat(58) + "\u256f"], 60, dStatus);
|
|
2427
|
+
assert(outTodos.length === 5 && outTodos[0] === "" && outTodos[1] === ` ${dStatus}` && outTodos[2] === "" && outTodos[3]!.startsWith("\u256d"), "Outside dialog leaves 1 blank line above and below when Todos is visible");
|
|
2428
|
+
|
|
2429
|
+
const scrollBorder = renderChatboxScrollBorder("\u2191", 3, 24, (t) => `<bdr>${t}</bdr>`, (t) => `<pri>${t}</pri>`);
|
|
2430
|
+
assert(scrollBorder.includes("<pri>↑ 3 more</pri>") && visibleWidth(stripAnsi(scrollBorder.replace(/<\/?(bdr|pri)>/g, ""))) === 24, "chatbox scroll border paints N more in primary at exact width");
|
|
2431
|
+
const dialogWithScroll = applyChatboxDialog(dBox, true, dW, 2, "Left", dStatus, "*", (t) => `<bdr>${t}</bdr>`, (t) => `<pri>${t}</pri>`);
|
|
2432
|
+
assert(dialogWithScroll[0]!.includes("<pri>↑ 2 more</pri>"), "top border dialog keeps ↑ N more painted in primary");
|
|
2433
|
+
|
|
2434
|
+
// Prompt idle/active coloring: idle uses dim, active typing uses primary (mdHeading, accent fallback).
|
|
2435
|
+
assert(isPromptActive(10_000, 0) === false, "untyped prompt starts idle");
|
|
2436
|
+
assert(isPromptActive(10_000, 8_000) === true, "prompt stays active within 3s of typing");
|
|
2437
|
+
assert(isPromptActive(10_000, 7_000) === true, "prompt is still active at exact 3s boundary");
|
|
2438
|
+
assert(isPromptActive(10_001, 7_000) === false, "prompt turns idle past 3s without typing");
|
|
2439
|
+
const promptTheme = { fg: (c: string, t: string) => `<${c}>${t}</${c}>` };
|
|
2440
|
+
assert(paintChatboxPrompt("❯", promptTheme, false) === "<dim> ❯ </dim>", "idle prompt paints with dim");
|
|
2441
|
+
assert(paintChatboxPrompt("❯", promptTheme, true) === "<mdHeading> ❯ </mdHeading>", "active prompt paints with primary (mdHeading)");
|
|
2442
|
+
assert(paintChatboxPrompt("\udb80\udf7d", promptTheme, false) === "<dim> \udb80\udf7d </dim>", "Nerd Font PUA prompt gets 2 trailing spaces");
|
|
2443
|
+
const nerdBox = renderChatboxLines("Arnative", (w) => ["\u2500".repeat(w), "hi" + " ".repeat(w - 2), "\u2500".repeat(w)], 30, 1, (t) => t, " \udb80\udf7d ");
|
|
2444
|
+
assert(nerdBox.length === 3 && nerdBox.every((l) => visibleWidth(l) === 30) && nerdBox[1]!.startsWith("\u2502 \udb80\udf7d hi"), "4-col Nerd Font prompt preserves exact box width");
|
|
2445
|
+
const fallbackTheme = {
|
|
2446
|
+
fg: (c: string, t: string) => {
|
|
2447
|
+
if (c === "mdHeading") throw new Error("missing");
|
|
2448
|
+
return `<${c}>${t}</${c}>`;
|
|
2449
|
+
},
|
|
2450
|
+
};
|
|
2451
|
+
assert(paintChatboxPrompt("❯", fallbackTheme, true) === "<accent> ❯ </accent>", "active prompt falls back to accent when mdHeading is absent");
|
|
2452
|
+
markPromptTyped(Date.now());
|
|
2453
|
+
assert(isPromptActive() === true && (globalThis as Record<symbol, unknown>)[PROMPT_IDLE_TIMER_KEY] != null, "markPromptTyped activates prompt and arms idle timer");
|
|
2454
|
+
stopPromptIdle();
|
|
2455
|
+
assert((globalThis as Record<symbol, unknown>)[PROMPT_IDLE_TIMER_KEY] == null, "stopPromptIdle clears the prompt idle timer");
|
|
2456
|
+
delete (globalThis as Record<symbol, unknown>)[PROMPT_TYPED_AT_KEY];
|
|
1867
2457
|
rmSync(presetFixture, { recursive: true, force: true });
|
|
1868
2458
|
if (prevAgentDir === undefined) delete process.env.PI_CODING_AGENT_DIR;
|
|
1869
2459
|
else process.env.PI_CODING_AGENT_DIR = prevAgentDir;
|