@pi-kaush/pi-content-layout 0.1.16 → 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/README.md +3 -3
- package/package.json +1 -1
- package/src/index.ts +55 -9
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,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:
|
|
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:
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
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
|
|
360
|
+
cached.presentation
|
|
361
|
+
? renderNotice(cached.presentation, innerWidth)
|
|
362
|
+
: lines,
|
|
317
363
|
childWidth,
|
|
318
364
|
extraInset,
|
|
319
365
|
);
|