@jaggerxtrm/pi-extensions 0.7.15 → 0.7.17
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/extensions/xtrm-ui/index.ts +76 -1
- package/package.json +1 -1
|
@@ -33,7 +33,8 @@ import {
|
|
|
33
33
|
} from "@mariozechner/pi-coding-agent";
|
|
34
34
|
import { Box, Text, truncateToWidth, visibleWidth } from "@mariozechner/pi-tui";
|
|
35
35
|
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
36
|
-
import { basename, join } from "node:path";
|
|
36
|
+
import { basename, dirname, join } from "node:path";
|
|
37
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
37
38
|
import {
|
|
38
39
|
cleanOutputLines,
|
|
39
40
|
countPrefixedItems,
|
|
@@ -66,6 +67,7 @@ export interface XtrmUiPrefs {
|
|
|
66
67
|
forceTheme: boolean; // When false, skip setTheme (allow external theme override)
|
|
67
68
|
toolRowBg: boolean; // Subtle background behind tool text rows (no padding)
|
|
68
69
|
compactExternalToolResults: boolean; // Compact extension tool results (disables full expand output)
|
|
70
|
+
hideThinkingPlaceholder: boolean; // When false, hidden thinking blocks render no placeholder text
|
|
69
71
|
}
|
|
70
72
|
|
|
71
73
|
// ============================================================================
|
|
@@ -83,6 +85,7 @@ export const DEFAULT_PREFS: XtrmUiPrefs = {
|
|
|
83
85
|
forceTheme: true,
|
|
84
86
|
toolRowBg: false,
|
|
85
87
|
compactExternalToolResults: true,
|
|
88
|
+
hideThinkingPlaceholder: false,
|
|
86
89
|
};
|
|
87
90
|
|
|
88
91
|
// ============================================================================
|
|
@@ -108,6 +111,7 @@ function normalizePrefs(input: unknown): XtrmUiPrefs {
|
|
|
108
111
|
toolRowBg: source.toolRowBg ?? DEFAULT_PREFS.toolRowBg,
|
|
109
112
|
compactExternalToolResults:
|
|
110
113
|
source.compactExternalToolResults ?? DEFAULT_PREFS.compactExternalToolResults,
|
|
114
|
+
hideThinkingPlaceholder: source.hideThinkingPlaceholder ?? DEFAULT_PREFS.hideThinkingPlaceholder,
|
|
111
115
|
};
|
|
112
116
|
}
|
|
113
117
|
|
|
@@ -125,6 +129,74 @@ function persistPrefs(pi: ExtensionAPI, prefs: XtrmUiPrefs): void {
|
|
|
125
129
|
pi.appendEntry(XTRM_UI_PREFS_ENTRY, prefs);
|
|
126
130
|
}
|
|
127
131
|
|
|
132
|
+
|
|
133
|
+
// ============================================================================
|
|
134
|
+
// Thinking Chrome
|
|
135
|
+
// ============================================================================
|
|
136
|
+
|
|
137
|
+
type AssistantMessageComponentCtor = {
|
|
138
|
+
prototype: {
|
|
139
|
+
updateContent?: (message: AssistantMessageLike) => void;
|
|
140
|
+
setExpanded?: (expanded: boolean) => void;
|
|
141
|
+
};
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
type AssistantContentBlock = { type?: string; thinking?: string };
|
|
145
|
+
type AssistantMessageLike = { content?: AssistantContentBlock[] };
|
|
146
|
+
type PatchableAssistantMessage = {
|
|
147
|
+
hideThinkingBlock?: boolean;
|
|
148
|
+
hiddenThinkingLabel?: string;
|
|
149
|
+
lastMessage?: AssistantMessageLike;
|
|
150
|
+
__xtrmThinkingExpanded?: boolean;
|
|
151
|
+
updateContent?: (message: AssistantMessageLike) => void;
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
const PATCHED_ASSISTANT_MESSAGE = "__xtrmUiSilentHiddenThinking";
|
|
155
|
+
|
|
156
|
+
async function installSilentHiddenThinkingPatch(): Promise<void> {
|
|
157
|
+
const entryPath = fileURLToPath(import.meta.resolve("@mariozechner/pi-coding-agent"));
|
|
158
|
+
const componentPath = join(dirname(entryPath), "modes", "interactive", "components", "assistant-message.js");
|
|
159
|
+
const mod = await import(pathToFileURL(componentPath).href) as {
|
|
160
|
+
AssistantMessageComponent?: AssistantMessageComponentCtor;
|
|
161
|
+
};
|
|
162
|
+
const proto = mod.AssistantMessageComponent?.prototype as
|
|
163
|
+
| (AssistantMessageComponentCtor["prototype"] & { [PATCHED_ASSISTANT_MESSAGE]?: boolean })
|
|
164
|
+
| undefined;
|
|
165
|
+
if (!proto?.updateContent || proto[PATCHED_ASSISTANT_MESSAGE]) return;
|
|
166
|
+
|
|
167
|
+
const updateContent = proto.updateContent;
|
|
168
|
+
proto.updateContent = function patchedUpdateContent(this: PatchableAssistantMessage, message: AssistantMessageLike) {
|
|
169
|
+
if (this.hiddenThinkingLabel === "" && Array.isArray(message.content)) {
|
|
170
|
+
if (!this.__xtrmThinkingExpanded) {
|
|
171
|
+
updateContent.call(this, {
|
|
172
|
+
...message,
|
|
173
|
+
content: message.content.filter((block) => block.type !== "thinking" || !block.thinking?.trim()),
|
|
174
|
+
});
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
const previousHideThinking = this.hideThinkingBlock;
|
|
179
|
+
this.hideThinkingBlock = false;
|
|
180
|
+
updateContent.call(this, message);
|
|
181
|
+
this.hideThinkingBlock = previousHideThinking;
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
updateContent.call(this, message);
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
proto.setExpanded = function setExpanded(this: PatchableAssistantMessage, expanded: boolean) {
|
|
188
|
+
this.__xtrmThinkingExpanded = expanded;
|
|
189
|
+
if (this.lastMessage) this.updateContent?.(this.lastMessage);
|
|
190
|
+
};
|
|
191
|
+
proto[PATCHED_ASSISTANT_MESSAGE] = true;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function applyThinkingChrome(ctx: ExtensionContext, prefs: XtrmUiPrefs): void {
|
|
195
|
+
(ctx.ui as { setHiddenThinkingLabel?: (label?: string) => void }).setHiddenThinkingLabel?.(
|
|
196
|
+
prefs.hideThinkingPlaceholder ? undefined : "",
|
|
197
|
+
);
|
|
198
|
+
}
|
|
199
|
+
|
|
128
200
|
// ============================================================================
|
|
129
201
|
// Chrome Application
|
|
130
202
|
// ============================================================================
|
|
@@ -1190,6 +1262,8 @@ function isXtrmTheme(name: string | undefined): boolean {
|
|
|
1190
1262
|
}
|
|
1191
1263
|
|
|
1192
1264
|
export default function xtrmUiExtension(pi: ExtensionAPI): void {
|
|
1265
|
+
void installSilentHiddenThinkingPatch().catch(() => undefined);
|
|
1266
|
+
|
|
1193
1267
|
let prefs: XtrmUiPrefs = { ...DEFAULT_PREFS };
|
|
1194
1268
|
let previousThemeName: string | null = null;
|
|
1195
1269
|
const extensionThemeDir = join(__dirname, "../../themes/xtrm-ui");
|
|
@@ -1203,6 +1277,7 @@ export default function xtrmUiExtension(pi: ExtensionAPI): void {
|
|
|
1203
1277
|
|
|
1204
1278
|
const refresh = (ctx: ExtensionContext) => {
|
|
1205
1279
|
applyXtrmChrome(ctx, prefs, getThinkingLevel);
|
|
1280
|
+
applyThinkingChrome(ctx, prefs);
|
|
1206
1281
|
};
|
|
1207
1282
|
|
|
1208
1283
|
pi.on("resources_discover", async () => ({
|