@pi-kaush/pi-content-layout 0.1.14 → 0.1.16

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 CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ - Restore the blank separator line above the `intercom_message` frame when
6
+ the chat-container hook swaps in this package's box: the swap bypassed
7
+ Pi's leading `Spacer(1)`, so the frame butted against the entry above
8
+ (most visibly a collapsed tool-call group) whenever `pi-intercom` loads
9
+ before this package.
10
+ - 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.
11
+
5
12
  - 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
13
 
7
14
  - 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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-kaush/pi-content-layout",
3
- "version": "0.1.14",
3
+ "version": "0.1.16",
4
4
  "description": "Inset Pi's conversation surface and style active and submitted prompts as matching blocks.",
5
5
  "license": "MIT",
6
6
  "author": "Kaushik Gopal",
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
- if (extraInset === 0) continue;
294
+ const ownRender = Object.getOwnPropertyDescriptor(child, "render");
286
295
  const originalRender = child.render;
287
- child.render = (childWidth: number): string[] =>
288
- insetLines(
289
- originalRender.call(child, Math.max(1, childWidth - extraInset * 2)),
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
- delete (child as Partial<NativeTextRow>).render;
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;
@@ -259,7 +259,11 @@ export function interceptIntercomMessages(
259
259
  child._expanded === true,
260
260
  theme,
261
261
  );
262
- return box ? box.render(width) : originalRender.call(child, width);
262
+ if (!box) return originalRender.call(child, width);
263
+ // Pi's CustomMessageComponent renders a Spacer(1) ahead of the box.
264
+ // The swap bypasses the host's own render, so reproduce that blank
265
+ // line to keep the frame separated from the entry above it.
266
+ return ["", ...box.render(width)];
263
267
  };
264
268
  restores.push(() => {
265
269
  delete (child as { render?: unknown }).render;