@pi-kaush/pi-content-layout 0.1.16 → 0.1.18
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 -1
- package/README.md +3 -3
- package/package.json +1 -1
- package/src/index.ts +56 -9
package/CHANGELOG.md
CHANGED
|
@@ -7,7 +7,8 @@
|
|
|
7
7
|
Pi's leading `Spacer(1)`, so the frame butted against the entry above
|
|
8
8
|
(most visibly a collapsed tool-call group) whenever `pi-intercom` loads
|
|
9
9
|
before this package.
|
|
10
|
-
-
|
|
10
|
+
- Show Pi's bare `Warning: …` and `Error: …` rows, and native cache-miss notices, as a glyph on the message edge (the tool-rail column) with a hanging indent: `!` for warnings, `✗` for errors. The label is dropped, the estimated cost loses its `~`, and Pi's text and theme color (bronze warnings, red errors) are preserved. Cache-miss notices now use `!` and sit on the edge instead of indented with `✗`.
|
|
11
|
+
- Fix a stacking glyph: Pi's `Text` returns the same cached line array on every render, and the notice rewrite edited that array in place, so each repaint prepended another `!` or `✗` and shoved the row out of its inset. The rewrite now edits a copy, with a regression test that renders repeatedly.
|
|
11
12
|
|
|
12
13
|
- 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.
|
|
13
14
|
|
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
|
-
##
|
|
44
|
+
## Warning and error notices
|
|
45
45
|
|
|
46
|
-
|
|
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
|
-
|
|
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
package/src/index.ts
CHANGED
|
@@ -255,11 +255,58 @@ 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:
|
|
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
|
+
// Text caches and returns its own array; copy before editing a line.
|
|
297
|
+
const lines = [...notice.body.render(width)];
|
|
298
|
+
const first = lines.findIndex((line) => stripTerminalSequences(line).trim());
|
|
299
|
+
if (first < 0) return lines;
|
|
300
|
+
const line = lines[first]!;
|
|
301
|
+
const lead = line.length - line.trimStart().length;
|
|
302
|
+
// Swap the two hanging-indent columns before the message for the glyph.
|
|
303
|
+
lines[first] =
|
|
304
|
+
line.slice(0, Math.max(0, lead - 2)) +
|
|
305
|
+
`${notice.color}${notice.glyph}\x1b[39m ` +
|
|
306
|
+
line.slice(lead);
|
|
307
|
+
return lines;
|
|
308
|
+
}
|
|
309
|
+
|
|
263
310
|
let systemTextHookActive = 0;
|
|
264
311
|
|
|
265
312
|
// Embedded status indicators call Loader.render() from inside the editor border.
|
|
@@ -302,18 +349,18 @@ function systemTextHook(
|
|
|
302
349
|
if (!cached || cached.text !== text) {
|
|
303
350
|
cached = {
|
|
304
351
|
text,
|
|
305
|
-
presentation:
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
)
|
|
311
|
-
: undefined,
|
|
352
|
+
presentation: noticePresentation(
|
|
353
|
+
text,
|
|
354
|
+
child.paddingX ?? 0,
|
|
355
|
+
child.paddingY ?? 0,
|
|
356
|
+
),
|
|
312
357
|
};
|
|
313
358
|
systemTextPresentations.set(child, cached);
|
|
314
359
|
}
|
|
315
360
|
return insetLines(
|
|
316
|
-
cached.presentation
|
|
361
|
+
cached.presentation
|
|
362
|
+
? renderNotice(cached.presentation, innerWidth)
|
|
363
|
+
: lines,
|
|
317
364
|
childWidth,
|
|
318
365
|
extraInset,
|
|
319
366
|
);
|