pi-tui-prompt-box 0.1.0 → 0.1.1
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 +6 -0
- package/package.json +1 -1
- package/src/index.ts +15 -3
- package/src/routed-model.ts +57 -0
- package/src/ui/padded-footer.ts +16 -5
- package/src/ui/prompt-box-editor.ts +37 -2
- package/src/ui/status-line.ts +47 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.1.1] - 12.11.2026
|
|
4
|
+
|
|
5
|
+
### New
|
|
6
|
+
* `[ui]` Show the routed model of a virtual model in the status line, not in the footer.
|
|
7
|
+
* `[ui]` Color the routed thinking level and the busy indicator with that level's color.
|
|
8
|
+
|
|
3
9
|
## [0.1.0] - 11.11.2026
|
|
4
10
|
|
|
5
11
|
### New
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -7,13 +7,14 @@
|
|
|
7
7
|
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
8
8
|
import type { RgbColor, TUI } from "@earendil-works/pi-tui";
|
|
9
9
|
|
|
10
|
+
import { findRoutedModel } from "./routed-model.ts";
|
|
10
11
|
import { watchTerminalBackground } from "./terminal-background.ts";
|
|
11
12
|
import { computeBoxColors, type ReadBoxColors } from "./ui/colors.ts";
|
|
12
13
|
import { padPiContainers } from "./ui/padded-containers.ts";
|
|
13
14
|
import { findBuiltInFooter, PaddedFooter } from "./ui/padded-footer.ts";
|
|
14
15
|
import { PromptBoxEditor, type RenderStatus } from "./ui/prompt-box-editor.ts";
|
|
15
16
|
import { readScrollbarPadding } from "./ui/scrollbar-padding.ts";
|
|
16
|
-
import { formatStatus } from "./ui/status-line.ts";
|
|
17
|
+
import { formatStatus, readRoutedLevelColor } from "./ui/status-line.ts";
|
|
17
18
|
|
|
18
19
|
/**
|
|
19
20
|
* Registers the prompt box editor for every session.
|
|
@@ -31,6 +32,7 @@ export default function promptBox(pi: ExtensionAPI): void {
|
|
|
31
32
|
model: ctx.model,
|
|
32
33
|
getProviderName: (provider) => ctx.modelRegistry.getProviderDisplayName(provider),
|
|
33
34
|
thinkingLevel: pi.getThinkingLevel(),
|
|
35
|
+
routedModel: findRoutedModel(ctx),
|
|
34
36
|
});
|
|
35
37
|
|
|
36
38
|
let terminalBackground: RgbColor | undefined;
|
|
@@ -42,7 +44,13 @@ export default function promptBox(pi: ExtensionAPI): void {
|
|
|
42
44
|
ctx.ui.setEditorComponent((tui, theme, keybindings) => {
|
|
43
45
|
editorTui = tui;
|
|
44
46
|
const readRightPadding = () => readScrollbarPadding(tui);
|
|
45
|
-
|
|
47
|
+
const readBusyColor = () => readRoutedLevelColor(ctx.ui.theme, findRoutedModel(ctx));
|
|
48
|
+
editor = new PromptBoxEditor(tui, theme, keybindings,
|
|
49
|
+
renderStatus,
|
|
50
|
+
readBoxColors,
|
|
51
|
+
readRightPadding,
|
|
52
|
+
readBusyColor,
|
|
53
|
+
);
|
|
46
54
|
return editor;
|
|
47
55
|
});
|
|
48
56
|
|
|
@@ -62,7 +70,11 @@ export default function promptBox(pi: ExtensionAPI): void {
|
|
|
62
70
|
if (!builtInFooter)
|
|
63
71
|
return;
|
|
64
72
|
|
|
65
|
-
const readModelState = () => ({
|
|
73
|
+
const readModelState = () => ({
|
|
74
|
+
model: ctx.model,
|
|
75
|
+
thinkingLevel: pi.getThinkingLevel(),
|
|
76
|
+
routedModel: findRoutedModel(ctx),
|
|
77
|
+
});
|
|
66
78
|
ctx.ui.setFooter((tui) => new PaddedFooter(builtInFooter, readModelState, () => readScrollbarPadding(tui)));
|
|
67
79
|
});
|
|
68
80
|
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Routed model: the physical model a virtual model picked for the latest successful response.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { ExtensionContext, Theme } from "@earendil-works/pi-coding-agent";
|
|
6
|
+
|
|
7
|
+
// API id of Pi's virtual models; Pi does not export its own constant
|
|
8
|
+
const VIRTUAL_MODEL_API = "pi-virtual";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Physical model that answered, with the thinking level the router picked for it.
|
|
12
|
+
*/
|
|
13
|
+
export interface RoutedModel {
|
|
14
|
+
model: NonNullable<ExtensionContext["model"]>;
|
|
15
|
+
thinkingLevel?: Parameters<Theme["getThinkingBorderColor"]>[0];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Parts of the extension context the routed model is read from.
|
|
20
|
+
*/
|
|
21
|
+
export interface RoutedModelSource {
|
|
22
|
+
model: ExtensionContext["model"];
|
|
23
|
+
sessionManager: Pick<ExtensionContext["sessionManager"], "getLeafEntry" | "getEntry">;
|
|
24
|
+
modelRegistry: Pick<ExtensionContext["modelRegistry"], "find">;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Finds the routed model of the latest successful response on the current session branch.
|
|
29
|
+
*
|
|
30
|
+
* Pi gives extensions no access to the `routedModel` of its session, so this follows the same rules:
|
|
31
|
+
* only under a virtual selection, and failed or aborted responses are skipped. Returns `undefined`
|
|
32
|
+
* without such a response, or when its model is no longer in the registry.
|
|
33
|
+
*/
|
|
34
|
+
export function findRoutedModel(source: RoutedModelSource): RoutedModel | undefined {
|
|
35
|
+
const { model, sessionManager, modelRegistry } = source;
|
|
36
|
+
if (model?.api !== VIRTUAL_MODEL_API)
|
|
37
|
+
return undefined;
|
|
38
|
+
|
|
39
|
+
// The answer is usually near the leaf, so walk up from it instead of building the whole branch
|
|
40
|
+
let entry = sessionManager.getLeafEntry();
|
|
41
|
+
while (entry) {
|
|
42
|
+
if (entry.type === "message" && entry.message.role === "assistant") {
|
|
43
|
+
const { stopReason, provider, model: modelId, thinkingLevel } = entry.message;
|
|
44
|
+
if (stopReason !== "error" && stopReason !== "aborted") {
|
|
45
|
+
const routedModel = modelRegistry.find(provider, modelId);
|
|
46
|
+
if (!routedModel || routedModel.api === VIRTUAL_MODEL_API)
|
|
47
|
+
return undefined;
|
|
48
|
+
|
|
49
|
+
return { model: routedModel, thinkingLevel };
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
entry = entry.parentId ? sessionManager.getEntry(entry.parentId) : undefined;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
package/src/ui/padded-footer.ts
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
6
6
|
import { type Component, stripTerminalSequences, truncateToWidth, visibleWidth } from "@earendil-works/pi-tui";
|
|
7
7
|
|
|
8
|
+
import type { RoutedModel } from "../routed-model.ts";
|
|
8
9
|
import { LEFT_MARGIN, RIGHT_MARGIN } from "./prompt-box-editor.ts";
|
|
9
10
|
import type { ReadRightPadding } from "./scrollbar-padding.ts";
|
|
10
11
|
|
|
@@ -20,6 +21,8 @@ const MIN_MODEL_GAP = 2;
|
|
|
20
21
|
export interface FooterModelState {
|
|
21
22
|
model: ExtensionContext["model"];
|
|
22
23
|
thinkingLevel: string;
|
|
24
|
+
/** Model a virtual `model` routed the latest response to; Pi's footer adds it after `→`. */
|
|
25
|
+
routedModel?: RoutedModel;
|
|
23
26
|
}
|
|
24
27
|
|
|
25
28
|
/**
|
|
@@ -45,14 +48,14 @@ export function findBuiltInFooter(root: Component): Component | undefined {
|
|
|
45
48
|
}
|
|
46
49
|
|
|
47
50
|
/**
|
|
48
|
-
* Removes the model part that Pi's built-in footer right-aligns on its stats line: `(provider) model • level
|
|
51
|
+
* Removes the model part that Pi's built-in footer right-aligns on its stats line: `(provider) model • level`,
|
|
52
|
+
* with ` → model • level` after it for a routed model.
|
|
49
53
|
*
|
|
50
54
|
* The prompt box status line already shows it. The line is changed only when it ends with exactly the text
|
|
51
|
-
* Pi builds from `state`; otherwise, for example when Pi truncated it
|
|
52
|
-
* returned unchanged.
|
|
55
|
+
* Pi builds from `state`; otherwise, for example when Pi truncated it, it is returned unchanged.
|
|
53
56
|
*/
|
|
54
57
|
export function removeModelPart(line: string, state: FooterModelState): string {
|
|
55
|
-
const { model, thinkingLevel } = state;
|
|
58
|
+
const { model, thinkingLevel, routedModel } = state;
|
|
56
59
|
if (!model)
|
|
57
60
|
return line;
|
|
58
61
|
|
|
@@ -60,9 +63,17 @@ export function removeModelPart(line: string, state: FooterModelState): string {
|
|
|
60
63
|
if (model.reasoning)
|
|
61
64
|
modelPart += thinkingLevel === "off" ? " • thinking off" : ` • ${thinkingLevel}`;
|
|
62
65
|
|
|
66
|
+
// Pi may show no routed model where the status line still does, for example after compaction
|
|
67
|
+
const modelParts = [modelPart];
|
|
68
|
+
if (routedModel) {
|
|
69
|
+
const routedLevel = routedModel.thinkingLevel ? ` • ${routedModel.thinkingLevel}` : "";
|
|
70
|
+
modelParts.unshift(`${modelPart} → ${routedModel.model.id}${routedLevel}`);
|
|
71
|
+
}
|
|
72
|
+
|
|
63
73
|
const plainLine = stripTerminalSequences(line);
|
|
64
74
|
const gap = " ".repeat(MIN_MODEL_GAP);
|
|
65
|
-
|
|
75
|
+
const candidates = modelParts.flatMap((part) => [`(${model.provider}) ${part}`, part]);
|
|
76
|
+
for (const candidate of candidates) {
|
|
66
77
|
if (!plainLine.endsWith(gap + candidate))
|
|
67
78
|
continue;
|
|
68
79
|
|
|
@@ -57,6 +57,12 @@ const BOTTOM_BORDER_MARKER = "\x00prompt-box-bottom-border\x00";
|
|
|
57
57
|
*/
|
|
58
58
|
export type RenderStatus = (barColor: (text: string) => string, bashMode: BashMode) => string;
|
|
59
59
|
|
|
60
|
+
/**
|
|
61
|
+
* Returns the color of Pi's busy indicator when it differs from the accent bar: the routed thinking level
|
|
62
|
+
* color. Returns `undefined` to use the accent bar color.
|
|
63
|
+
*/
|
|
64
|
+
export type ReadBusyColor = () => ((text: string) => string) | undefined;
|
|
65
|
+
|
|
60
66
|
// Pi does not export the StatusIndicator type
|
|
61
67
|
type StatusIndicator = NonNullable<Parameters<CustomEditor["setWorkingStatusIndicator"]>[0]>;
|
|
62
68
|
|
|
@@ -92,7 +98,9 @@ interface BoxStyle {
|
|
|
92
98
|
* The base editor renders the text lines; this class replaces its borders and
|
|
93
99
|
* wraps every line in the box background. `renderStatus` is called on every
|
|
94
100
|
* render, so the status line always shows the current state. The accent bar
|
|
95
|
-
* uses `borderColor
|
|
101
|
+
* uses the `borderColor` Pi sets from the thinking level and bash mode.
|
|
102
|
+
* Pi colors its working and compaction indicators with the `borderColor` it reads back, so reading it
|
|
103
|
+
* returns `readBusyColor()` when set, except in bash mode; the bar keeps the color Pi set.
|
|
96
104
|
* With `embedWorkingStatus`, Pi passes its busy indicators (working, retry,
|
|
97
105
|
* compaction, branch summary) to the editor, which shows them in the status line.
|
|
98
106
|
* `readBoxColors` is called on every render, so the box follows the terminal background.
|
|
@@ -109,6 +117,9 @@ export class PromptBoxEditor extends CustomEditor {
|
|
|
109
117
|
private readonly editorTheme: EditorTheme;
|
|
110
118
|
private readonly readBoxColors: ReadBoxColors;
|
|
111
119
|
private readonly readRightPadding: ReadRightPadding;
|
|
120
|
+
private readonly readBusyColor: ReadBusyColor;
|
|
121
|
+
// The borderColor Pi set; the `borderColor` property itself returns the busy indicator color
|
|
122
|
+
private barColor: (text: string) => string;
|
|
112
123
|
private statusIndicator: StatusIndicator | undefined;
|
|
113
124
|
// Pi's editor paddingX setting; the base editor keeps 0, so its text indent inside the box stays the same
|
|
114
125
|
private boxPaddingX = 0;
|
|
@@ -127,12 +138,25 @@ export class PromptBoxEditor extends CustomEditor {
|
|
|
127
138
|
renderStatus: RenderStatus,
|
|
128
139
|
readBoxColors: ReadBoxColors,
|
|
129
140
|
readRightPadding: ReadRightPadding = () => 0,
|
|
141
|
+
readBusyColor: ReadBusyColor = () => undefined,
|
|
130
142
|
) {
|
|
131
143
|
super(tui, theme, keybindings, { paddingX: 0, embedWorkingStatus: true });
|
|
132
144
|
this.renderStatus = renderStatus;
|
|
133
145
|
this.editorTheme = theme;
|
|
134
146
|
this.readBoxColors = readBoxColors;
|
|
135
147
|
this.readRightPadding = readRightPadding;
|
|
148
|
+
this.readBusyColor = readBusyColor;
|
|
149
|
+
|
|
150
|
+
// The base class declares borderColor as a field, so the accessor is defined on the instance
|
|
151
|
+
this.barColor = this.borderColor;
|
|
152
|
+
Object.defineProperty(this, "borderColor", {
|
|
153
|
+
configurable: true,
|
|
154
|
+
enumerable: true,
|
|
155
|
+
get: () => this.readIndicatorColor(),
|
|
156
|
+
set: (color: (text: string) => string) => {
|
|
157
|
+
this.barColor = color;
|
|
158
|
+
},
|
|
159
|
+
});
|
|
136
160
|
}
|
|
137
161
|
|
|
138
162
|
// The base class keeps the indicator private, so keep a copy for the status line
|
|
@@ -191,7 +215,7 @@ export class PromptBoxEditor extends CustomEditor {
|
|
|
191
215
|
this.boxLayout = { leftMargin: margins.left, textWidth, textLineCount: textLines.length };
|
|
192
216
|
|
|
193
217
|
const boxWidth = width - margins.left - margins.right - BAR_WIDTH;
|
|
194
|
-
const barColor = this.
|
|
218
|
+
const barColor = this.barColor;
|
|
195
219
|
const colors = this.readBoxColors();
|
|
196
220
|
const status = this.renderStatusLine(textWidth, barColor);
|
|
197
221
|
|
|
@@ -236,6 +260,17 @@ export class PromptBoxEditor extends CustomEditor {
|
|
|
236
260
|
return super.handleMouse({ ...baseEvent, x: event.x - textIndent, y });
|
|
237
261
|
}
|
|
238
262
|
|
|
263
|
+
/**
|
|
264
|
+
* Returns the color Pi's busy indicator gets when it reads `borderColor`. In bash mode, and for the base
|
|
265
|
+
* editor borders of the fallback layout, it is the accent bar color.
|
|
266
|
+
*/
|
|
267
|
+
private readIndicatorColor(): (text: string) => string {
|
|
268
|
+
if (this.renderingFallback || detectBashMode(this.getText()) !== "off")
|
|
269
|
+
return this.barColor;
|
|
270
|
+
|
|
271
|
+
return this.readBusyColor() ?? this.barColor;
|
|
272
|
+
}
|
|
273
|
+
|
|
239
274
|
/**
|
|
240
275
|
* Renders the base editor layout with Pi's borders, for widths below the box minimum.
|
|
241
276
|
*/
|
package/src/ui/status-line.ts
CHANGED
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
|
|
5
5
|
import type { ExtensionContext, Theme } from "@earendil-works/pi-coding-agent";
|
|
6
6
|
|
|
7
|
+
import type { RoutedModel } from "../routed-model.ts";
|
|
8
|
+
|
|
7
9
|
/**
|
|
8
10
|
* Bash mode of the input:
|
|
9
11
|
* off a normal prompt
|
|
@@ -24,25 +26,64 @@ export interface StatusLineOptions {
|
|
|
24
26
|
/** Returns the display name of a provider id, like Pi's model registry: `opencode` → `OpenCode Zen`. */
|
|
25
27
|
getProviderName: (provider: string) => string;
|
|
26
28
|
thinkingLevel: string;
|
|
29
|
+
/** Model a virtual `model` routed the latest response to; shown after `→`. */
|
|
30
|
+
routedModel?: RoutedModel;
|
|
27
31
|
}
|
|
28
32
|
|
|
29
33
|
/**
|
|
30
|
-
*
|
|
34
|
+
* Returns the theme color of the routed thinking level, or `undefined` when the status line shows no routed
|
|
35
|
+
* level: without a routed model, without its level, or for a routed model without reasoning support.
|
|
36
|
+
*/
|
|
37
|
+
export function readRoutedLevelColor(
|
|
38
|
+
theme: Theme,
|
|
39
|
+
routedModel: RoutedModel | undefined,
|
|
40
|
+
): ((text: string) => string) | undefined {
|
|
41
|
+
if (!routedModel?.model.reasoning || !routedModel.thinkingLevel)
|
|
42
|
+
return undefined;
|
|
43
|
+
|
|
44
|
+
return theme.getThinkingBorderColor(routedModel.thinkingLevel);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Builds the status line text: model, provider and thinking level, then the routed model in the same format.
|
|
31
49
|
* Like Pi's footer, the level shows only for models with reasoning support, and level `off` shows as `thinking off`.
|
|
32
50
|
* In bash mode, `Bash` replaces them. Pi's busy indicator is added by the editor.
|
|
33
51
|
*/
|
|
34
52
|
export function formatStatus(options: StatusLineOptions): string {
|
|
35
|
-
const { theme, levelColor, bashMode, model,
|
|
53
|
+
const { theme, levelColor, bashMode, model, thinkingLevel, routedModel } = options;
|
|
36
54
|
if (bashMode === "context")
|
|
37
55
|
return levelColor("Bash");
|
|
38
56
|
|
|
39
57
|
if (bashMode === "no-context")
|
|
40
58
|
return `${levelColor("Bash")}${theme.fg("dim", " (no context)")}`;
|
|
41
59
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
60
|
+
if (!model)
|
|
61
|
+
return theme.fg("dim", "no model");
|
|
62
|
+
|
|
63
|
+
const selectedText = formatModel(options, model, thinkingLevel, levelColor);
|
|
64
|
+
if (!routedModel)
|
|
65
|
+
return selectedText;
|
|
66
|
+
|
|
67
|
+
// The routed level has the color of its own level, which can differ from the accent bar
|
|
68
|
+
const routedLevelColor = readRoutedLevelColor(theme, routedModel) ?? levelColor;
|
|
69
|
+
const routedText = formatModel(options, routedModel.model, routedModel.thinkingLevel, routedLevelColor);
|
|
70
|
+
|
|
71
|
+
return `${selectedText}${theme.fg("dim", " → ")}${routedText}`;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Formats one model as `name provider · level`; the level is left out for models without reasoning support
|
|
76
|
+
* and when it is unknown.
|
|
77
|
+
*/
|
|
78
|
+
function formatModel(
|
|
79
|
+
options: StatusLineOptions,
|
|
80
|
+
model: NonNullable<ExtensionContext["model"]>,
|
|
81
|
+
thinkingLevel: string | undefined,
|
|
82
|
+
levelColor: (text: string) => string,
|
|
83
|
+
): string {
|
|
84
|
+
const { theme, getProviderName } = options;
|
|
85
|
+
const modelText = `${theme.fg("text", model.name)} ${theme.fg("dim", getProviderName(model.provider))}`;
|
|
86
|
+
if (!model.reasoning || !thinkingLevel)
|
|
46
87
|
return modelText;
|
|
47
88
|
|
|
48
89
|
const separator = theme.fg("dim", " · ");
|