@pi-kaush/pi-content-layout 0.1.14 → 0.1.15
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 +2 -0
- package/README.md +12 -0
- package/package.json +1 -1
- package/src/index.ts +35 -6
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
- Align native `ThemedText` system notices with the transcript inset. Cache-miss notices gain a `✗` marker and omit `~` before the estimated cost, preserving Pi's cause labels, token counts, warning color, and detection logic.
|
|
6
|
+
|
|
5
7
|
- Restyle the `intercom_message` box even when `pi-intercom` wins Pi's first-registration-wins renderer lookup: a chat-container hook replaces the box Pi built with this package's frame, so the surface no longer depends on `packages` order. The renderer registration stays as the cheaper path when this package loads first.
|
|
6
8
|
|
|
7
9
|
- Restore Pi's native active editor border and terminal background, so its embedded status interrupts the top rule as in native Pi. Submitted user messages keep their darker railed shell. Older Pi versions keep the aligned transcript-row status fallback.
|
package/README.md
CHANGED
|
@@ -41,6 +41,18 @@ text at this package's message inset, so `pi-tool-call-markers` mirrors
|
|
|
41
41
|
`contentInset` for its bash blocks (see its `src/bash-block.ts`). Change
|
|
42
42
|
indentation in both packages together.
|
|
43
43
|
|
|
44
|
+
## Cache-miss notices
|
|
45
|
+
|
|
46
|
+
Native cache-miss notices gain a `✗` marker aligned with tool and Thought glyphs:
|
|
47
|
+
|
|
48
|
+
```text
|
|
49
|
+
✗ Cache miss: 32k tokens re-billed ($0.16)
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Pi's model-switch and idle-gap labels, token counts, warning color, and notice
|
|
53
|
+
thresholds remain unchanged. The cost is still Pi's estimate; only the `~` is
|
|
54
|
+
hidden. No cache detection or billing logic is replaced.
|
|
55
|
+
|
|
44
56
|
## Queued steering previews
|
|
45
57
|
|
|
46
58
|
Pi renders queued `Steering:` messages in the native `dim` color. This package
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -11,6 +11,8 @@ import {
|
|
|
11
11
|
type EditorComponent,
|
|
12
12
|
type EditorTheme,
|
|
13
13
|
Loader,
|
|
14
|
+
stripTerminalSequences,
|
|
15
|
+
Text,
|
|
14
16
|
TruncatedText,
|
|
15
17
|
type TUI,
|
|
16
18
|
visibleWidth,
|
|
@@ -241,7 +243,8 @@ function isSystemTextChild(child: unknown): child is NativeTextRow {
|
|
|
241
243
|
return false;
|
|
242
244
|
const text = child as NativeTextRow & { constructor?: { name?: string } };
|
|
243
245
|
return (
|
|
244
|
-
text.constructor?.name === "Text"
|
|
246
|
+
(text.constructor?.name === "Text" ||
|
|
247
|
+
text.constructor?.name === "ThemedText") &&
|
|
245
248
|
typeof text.text === "string" &&
|
|
246
249
|
text.paddingX === 1 &&
|
|
247
250
|
text.paddingY === 0 &&
|
|
@@ -250,6 +253,12 @@ function isSystemTextChild(child: unknown): child is NativeTextRow {
|
|
|
250
253
|
}
|
|
251
254
|
|
|
252
255
|
const knownChatContainers = new WeakSet<object>();
|
|
256
|
+
const systemTextPresentations = new WeakMap<
|
|
257
|
+
object,
|
|
258
|
+
{ text: string; presentation: Text | undefined }
|
|
259
|
+
>();
|
|
260
|
+
const CACHE_MISS_TEXT =
|
|
261
|
+
/^Cache miss(?: after model switch| after \d+m idle)?: \d+(?:\.\d+)?[kM]? tokens re-billed(?: \(~\$\d+\.\d{2}\))?$/;
|
|
253
262
|
|
|
254
263
|
let systemTextHookActive = 0;
|
|
255
264
|
|
|
@@ -282,16 +291,36 @@ function systemTextHook(
|
|
|
282
291
|
for (const child of children) {
|
|
283
292
|
if (!isSystemTextChild(child)) continue;
|
|
284
293
|
const extraInset = Math.max(0, targetInset - (child.paddingX ?? 0));
|
|
285
|
-
|
|
294
|
+
const ownRender = Object.getOwnPropertyDescriptor(child, "render");
|
|
286
295
|
const originalRender = child.render;
|
|
287
|
-
child.render = (childWidth: number): string[] =>
|
|
288
|
-
|
|
289
|
-
|
|
296
|
+
child.render = (childWidth: number): string[] => {
|
|
297
|
+
const innerWidth = Math.max(1, childWidth - extraInset * 2);
|
|
298
|
+
// ThemedText builds its source lazily and refreshes it on theme changes.
|
|
299
|
+
const lines = originalRender.call(child, innerWidth);
|
|
300
|
+
const text = child.text ?? "";
|
|
301
|
+
let cached = systemTextPresentations.get(child);
|
|
302
|
+
if (!cached || cached.text !== text) {
|
|
303
|
+
cached = {
|
|
304
|
+
text,
|
|
305
|
+
presentation: CACHE_MISS_TEXT.test(stripTerminalSequences(text))
|
|
306
|
+
? new Text(
|
|
307
|
+
text.replace("Cache miss", "✗ Cache miss").replace("(~$", "($"),
|
|
308
|
+
(child.paddingX ?? 0) + 2,
|
|
309
|
+
child.paddingY,
|
|
310
|
+
)
|
|
311
|
+
: undefined,
|
|
312
|
+
};
|
|
313
|
+
systemTextPresentations.set(child, cached);
|
|
314
|
+
}
|
|
315
|
+
return insetLines(
|
|
316
|
+
cached.presentation?.render(innerWidth) ?? lines,
|
|
290
317
|
childWidth,
|
|
291
318
|
extraInset,
|
|
292
319
|
);
|
|
320
|
+
};
|
|
293
321
|
restores.push(() => {
|
|
294
|
-
|
|
322
|
+
if (ownRender) Object.defineProperty(child, "render", ownRender);
|
|
323
|
+
else delete (child as Partial<NativeTextRow>).render;
|
|
295
324
|
});
|
|
296
325
|
}
|
|
297
326
|
if (restores.length === 0) return undefined;
|