@pi-kaush/pi-content-layout 0.1.15 → 0.1.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/CHANGELOG.md CHANGED
@@ -2,6 +2,11 @@
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.
5
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.
6
11
 
7
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.
package/README.md CHANGED
@@ -41,12 +41,12 @@ 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
44
+ ## Warning and error notices
45
45
 
46
- Native cache-miss notices gain a `✗` marker aligned with tool and Thought glyphs:
46
+ Pi's bare `Warning: …` and `Error: …` rows, and native cache-miss notices, swap the label for a glyph on the message edge (the tool-rail column): `!` for warnings, `✗` for errors.
47
47
 
48
48
  ```text
49
- ✗ Cache miss: 32k tokens re-billed ($0.16)
49
+ ! Cache miss: 32k tokens re-billed ($0.16)
50
50
  ```
51
51
 
52
52
  Pi's model-switch and idle-gap labels, token counts, warning color, and notice
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-kaush/pi-content-layout",
3
- "version": "0.1.15",
3
+ "version": "0.1.17",
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
@@ -255,11 +255,57 @@ function isSystemTextChild(child: unknown): child is NativeTextRow {
255
255
  const knownChatContainers = new WeakSet<object>();
256
256
  const systemTextPresentations = new WeakMap<
257
257
  object,
258
- { text: string; presentation: Text | undefined }
258
+ { text: string; presentation: NoticePresentation | undefined }
259
259
  >();
260
260
  const CACHE_MISS_TEXT =
261
261
  /^Cache miss(?: after model switch| after \d+m idle)?: \d+(?:\.\d+)?[kM]? tokens re-billed(?: \(~\$\d+\.\d{2}\))?$/;
262
262
 
263
+ // Pi emits warnings and errors as bare "Warning: …" / "Error: …" rows. They
264
+ // render as a glyph on the content edge (the column tool rails use) with the
265
+ // message hanging after it: `!` for warnings, `✗` for errors.
266
+ const WARNING_GLYPH = "!";
267
+ const ERROR_GLYPH = "✗";
268
+
269
+ type NoticePresentation = { glyph: string; color: string; body: Text };
270
+
271
+ function noticePresentation(
272
+ text: string,
273
+ paddingX: number,
274
+ paddingY: number,
275
+ ): NoticePresentation | undefined {
276
+ const plain = stripTerminalSequences(text);
277
+ let glyph: string;
278
+ let body: string;
279
+ if (CACHE_MISS_TEXT.test(plain)) {
280
+ glyph = WARNING_GLYPH;
281
+ body = text.replace("(~$", "($");
282
+ } else if (plain.startsWith("Warning: ")) {
283
+ glyph = WARNING_GLYPH;
284
+ body = text.replace("Warning: ", "");
285
+ } else if (plain.startsWith("Error: ")) {
286
+ glyph = ERROR_GLYPH;
287
+ body = text.replace("Error: ", "");
288
+ } else {
289
+ return undefined;
290
+ }
291
+ const color = /^(?:\x1b\[[0-9;]*m)*/.exec(text)?.[0] ?? "";
292
+ return { glyph, color, body: new Text(body, paddingX + 2, paddingY) };
293
+ }
294
+
295
+ function renderNotice(notice: NoticePresentation, width: number): string[] {
296
+ const lines = notice.body.render(width);
297
+ const first = lines.findIndex((line) => stripTerminalSequences(line).trim());
298
+ if (first < 0) return lines;
299
+ const line = lines[first]!;
300
+ const lead = line.length - line.trimStart().length;
301
+ // Swap the two hanging-indent columns before the message for the glyph.
302
+ lines[first] =
303
+ line.slice(0, Math.max(0, lead - 2)) +
304
+ `${notice.color}${notice.glyph}\x1b[39m ` +
305
+ line.slice(lead);
306
+ return lines;
307
+ }
308
+
263
309
  let systemTextHookActive = 0;
264
310
 
265
311
  // Embedded status indicators call Loader.render() from inside the editor border.
@@ -302,18 +348,18 @@ function systemTextHook(
302
348
  if (!cached || cached.text !== text) {
303
349
  cached = {
304
350
  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,
351
+ presentation: noticePresentation(
352
+ text,
353
+ child.paddingX ?? 0,
354
+ child.paddingY ?? 0,
355
+ ),
312
356
  };
313
357
  systemTextPresentations.set(child, cached);
314
358
  }
315
359
  return insetLines(
316
- cached.presentation?.render(innerWidth) ?? lines,
360
+ cached.presentation
361
+ ? renderNotice(cached.presentation, innerWidth)
362
+ : lines,
317
363
  childWidth,
318
364
  extraInset,
319
365
  );
@@ -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;