@pi-kaush/pi-content-layout 0.1.13 → 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 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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-kaush/pi-content-layout",
3
- "version": "0.1.13",
3
+ "version": "0.1.15",
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,
@@ -50,15 +52,6 @@ type EditorFactory = (
50
52
  keybindings: KeybindingsManager,
51
53
  ) => EditorComponent;
52
54
 
53
- type EmbeddedStatusEditorOptions = NonNullable<
54
- ConstructorParameters<typeof CustomEditor>[3]
55
- > & { embedWorkingStatus: true };
56
-
57
- // Newer Pi consumes this option; older editors keep the transcript status row.
58
- const EMBEDDED_STATUS_EDITOR_OPTIONS: EmbeddedStatusEditorOptions = {
59
- embedWorkingStatus: true,
60
- };
61
-
62
55
  type ThemeGetter = () => Theme | undefined;
63
56
 
64
57
  type RenderRow = {
@@ -250,7 +243,8 @@ function isSystemTextChild(child: unknown): child is NativeTextRow {
250
243
  return false;
251
244
  const text = child as NativeTextRow & { constructor?: { name?: string } };
252
245
  return (
253
- text.constructor?.name === "Text" &&
246
+ (text.constructor?.name === "Text" ||
247
+ text.constructor?.name === "ThemedText") &&
254
248
  typeof text.text === "string" &&
255
249
  text.paddingX === 1 &&
256
250
  text.paddingY === 0 &&
@@ -259,6 +253,12 @@ function isSystemTextChild(child: unknown): child is NativeTextRow {
259
253
  }
260
254
 
261
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}\))?$/;
262
262
 
263
263
  let systemTextHookActive = 0;
264
264
 
@@ -291,16 +291,36 @@ function systemTextHook(
291
291
  for (const child of children) {
292
292
  if (!isSystemTextChild(child)) continue;
293
293
  const extraInset = Math.max(0, targetInset - (child.paddingX ?? 0));
294
- if (extraInset === 0) continue;
294
+ const ownRender = Object.getOwnPropertyDescriptor(child, "render");
295
295
  const originalRender = child.render;
296
- child.render = (childWidth: number): string[] =>
297
- insetLines(
298
- 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,
299
317
  childWidth,
300
318
  extraInset,
301
319
  );
320
+ };
302
321
  restores.push(() => {
303
- delete (child as Partial<NativeTextRow>).render;
322
+ if (ownRender) Object.defineProperty(child, "render", ownRender);
323
+ else delete (child as Partial<NativeTextRow>).render;
304
324
  });
305
325
  }
306
326
  if (restores.length === 0) return undefined;
@@ -539,12 +559,7 @@ export default function contentLayout(pi: ExtensionAPI): void {
539
559
  const factory: EditorFactory = (tui, editorTheme, keybindings) => {
540
560
  const editor = previous
541
561
  ? previous(tui, editorTheme, keybindings)
542
- : new CustomEditor(
543
- tui,
544
- editorTheme,
545
- keybindings,
546
- EMBEDDED_STATUS_EDITOR_OPTIONS,
547
- );
562
+ : new CustomEditor(tui, editorTheme, keybindings);
548
563
  return decorateEditor(editor);
549
564
  };
550
565
  editorRegistration = { factory, previous };