@pi-kaush/pi-content-layout 0.1.5 → 0.1.6
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 +6 -0
- package/README.md +17 -0
- package/package.json +1 -1
- package/src/index.ts +9 -0
- package/src/intercom-message.ts +159 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
- Restyle pi-intercom's inbound `intercom_message` box onto the shared
|
|
6
|
+
transcript columns (frame border on the marker column, title and body text
|
|
7
|
+
on the text column) and drop the redundant `Ctrl+O expands` title hint.
|
|
8
|
+
Requires this package to load before `pi-intercom`; falls back to Pi's
|
|
9
|
+
default custom-message box for malformed payloads.
|
|
10
|
+
|
|
5
11
|
- Render active input with the theme's `userMessageText` foreground, restoring
|
|
6
12
|
that base color after embedded ANSI resets while preserving inline identifier
|
|
7
13
|
highlighting.
|
package/README.md
CHANGED
|
@@ -33,6 +33,23 @@ text at this package's message inset, so `pi-tool-call-markers` mirrors
|
|
|
33
33
|
`contentInset` for its bash blocks (see its `src/bash-block.ts`). Change
|
|
34
34
|
indentation in both packages together.
|
|
35
35
|
|
|
36
|
+
## pi-intercom message surface
|
|
37
|
+
|
|
38
|
+
When [`pi-intercom`](https://www.npmjs.com/package/pi-intercom) is installed,
|
|
39
|
+
this package restyles its inbound `intercom_message` box onto the shared
|
|
40
|
+
transcript columns: the frame's left border sits on the tool-marker column
|
|
41
|
+
(the outer inset), the `From:` title and body text share the text column used
|
|
42
|
+
by tool rows and Thought labels, and the redundant `Ctrl+O expands` title hint
|
|
43
|
+
is dropped (the meta line inside the box keeps `Ctrl+O to expand`). Content is
|
|
44
|
+
unchanged, and expanded view keeps pi-intercom's full body, attachment, and
|
|
45
|
+
reply sections.
|
|
46
|
+
|
|
47
|
+
Pi resolves custom message renderers in extension load order (first
|
|
48
|
+
registration wins), so list this package before `pi-intercom` in `packages`
|
|
49
|
+
for the restyle to take effect. Without pi-intercom installed the
|
|
50
|
+
registration is inert; malformed message payloads fall back to Pi's default
|
|
51
|
+
custom-message box.
|
|
52
|
+
|
|
36
53
|
## Install
|
|
37
54
|
|
|
38
55
|
```json
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
chatContainerHooks,
|
|
18
18
|
runChatContainerHooks,
|
|
19
19
|
} from "./container-hooks.ts";
|
|
20
|
+
import { renderIntercomMessage } from "./intercom-message.ts";
|
|
20
21
|
import {
|
|
21
22
|
contentInset,
|
|
22
23
|
insetLines,
|
|
@@ -381,6 +382,14 @@ function decorateEditor(
|
|
|
381
382
|
}
|
|
382
383
|
|
|
383
384
|
export default function contentLayout(pi: ExtensionAPI): void {
|
|
385
|
+
// Restyle pi-intercom's inbound message box to sit on this package's
|
|
386
|
+
// transcript columns. Pi resolves message renderers in extension load
|
|
387
|
+
// order (first registration wins), so this must load before pi-intercom
|
|
388
|
+
// to take effect; without pi-intercom installed the registration is inert.
|
|
389
|
+
pi.registerMessageRenderer("intercom_message", (message, options, theme) =>
|
|
390
|
+
renderIntercomMessage(message.details, options.expanded, theme),
|
|
391
|
+
);
|
|
392
|
+
|
|
384
393
|
const owner = {};
|
|
385
394
|
let activeTheme: Theme | undefined;
|
|
386
395
|
let assistantPatch: RenderPatchState | undefined;
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import type { Theme } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import type { Component } from "@earendil-works/pi-tui";
|
|
3
|
+
import {
|
|
4
|
+
truncateToWidth,
|
|
5
|
+
visibleWidth,
|
|
6
|
+
wrapTextWithAnsi,
|
|
7
|
+
} from "@earendil-works/pi-tui";
|
|
8
|
+
import { contentInset } from "./render.ts";
|
|
9
|
+
|
|
10
|
+
// Structural mirror of pi-intercom's `intercom_message` details payload, so
|
|
11
|
+
// this package can restyle the message without depending on pi-intercom.
|
|
12
|
+
// Malformed payloads make the renderer return undefined, which drops back to
|
|
13
|
+
// pi-intercom's own box (or Pi's default custom-message box).
|
|
14
|
+
export type IntercomMessageDetails = {
|
|
15
|
+
from?: { id?: string; name?: string; cwd?: string };
|
|
16
|
+
message?: {
|
|
17
|
+
replyTo?: string;
|
|
18
|
+
expectsReply?: boolean;
|
|
19
|
+
content?: { text?: string; attachments?: { name?: string }[] };
|
|
20
|
+
};
|
|
21
|
+
replyCommand?: string;
|
|
22
|
+
bodyText?: string;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
// Geometry contract with the rest of the transcript: the frame's left border
|
|
26
|
+
// sits on the tool-marker column (contentInset), and title/body text start
|
|
27
|
+
// two columns inside the frame, sharing the text column used by tool rows
|
|
28
|
+
// and Thought labels. A frame needs room for "│ x │", so below MIN_BOX_WIDTH
|
|
29
|
+
// the message degrades to plain truncated text instead of a broken frame.
|
|
30
|
+
const MIN_BOX_WIDTH = 8;
|
|
31
|
+
|
|
32
|
+
class IntercomMessageComponent implements Component {
|
|
33
|
+
private readonly bodyText: string;
|
|
34
|
+
private collapsedPreview?: string;
|
|
35
|
+
// Cache is keyed by frame width; a fresh component is built by Pi on every
|
|
36
|
+
// expand toggle or invalidate(), so theme styling can live inside it.
|
|
37
|
+
private wrappedBody?: { width: number; lines: string[] };
|
|
38
|
+
|
|
39
|
+
constructor(
|
|
40
|
+
private readonly details: IntercomMessageDetails,
|
|
41
|
+
private readonly expanded: boolean,
|
|
42
|
+
private readonly theme: Theme,
|
|
43
|
+
) {
|
|
44
|
+
this.bodyText = details.bodyText ?? details.message?.content?.text ?? "";
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
invalidate(): void {}
|
|
48
|
+
|
|
49
|
+
render(width: number): string[] {
|
|
50
|
+
const inset = contentInset(width);
|
|
51
|
+
const boxWidth = Math.max(1, width - inset * 2);
|
|
52
|
+
const margin = " ".repeat(inset);
|
|
53
|
+
const from = this.details.from ?? {};
|
|
54
|
+
const senderName = from.name || from.id?.slice(0, 8) || "unknown";
|
|
55
|
+
|
|
56
|
+
if (boxWidth < MIN_BOX_WIDTH) {
|
|
57
|
+
const text = truncateToWidth(`From: ${senderName}`, boxWidth, "");
|
|
58
|
+
return [margin + text + margin];
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const border = (text: string) => this.theme.fg("muted", text);
|
|
62
|
+
// Columns inside the frame: │ + space + content(innerWidth) + space + │.
|
|
63
|
+
const innerWidth = boxWidth - 4;
|
|
64
|
+
|
|
65
|
+
const frameLine = (content: string): string => {
|
|
66
|
+
const text = truncateToWidth(content, innerWidth, "");
|
|
67
|
+
const fill = " ".repeat(Math.max(0, innerWidth - visibleWidth(text)));
|
|
68
|
+
return `${margin}${border("│")} ${text}${fill} ${border("│")}${margin}`;
|
|
69
|
+
};
|
|
70
|
+
const bottomBorder = `${margin}${border(`╰${"─".repeat(boxWidth - 2)}╯`)}${margin}`;
|
|
71
|
+
|
|
72
|
+
const title = `From: ${senderName}${from.cwd ? ` (${from.cwd})` : ""}`;
|
|
73
|
+
const titleText = truncateToWidth(title, Math.max(1, innerWidth - 1), "");
|
|
74
|
+
const dashes = "─".repeat(
|
|
75
|
+
Math.max(1, innerWidth - visibleWidth(titleText)),
|
|
76
|
+
);
|
|
77
|
+
const topBorder = `${margin}${border("╭")} ${this.theme.fg("toolTitle", titleText)} ${border(dashes + "╮")}${margin}`;
|
|
78
|
+
|
|
79
|
+
const lines: string[] = [topBorder];
|
|
80
|
+
|
|
81
|
+
if (!this.expanded) {
|
|
82
|
+
this.collapsedPreview ??= this.bodyText.replace(/\s+/g, " ").trim();
|
|
83
|
+
lines.push(frameLine(this.theme.fg("text", this.collapsedPreview)));
|
|
84
|
+
|
|
85
|
+
const meta: string[] = [];
|
|
86
|
+
if (this.details.replyCommand) {
|
|
87
|
+
meta.push(`To reply: ${this.details.replyCommand}`);
|
|
88
|
+
}
|
|
89
|
+
const attachments = this.details.message?.content?.attachments;
|
|
90
|
+
if (attachments?.length) {
|
|
91
|
+
meta.push(
|
|
92
|
+
`${attachments.length} attachment${attachments.length === 1 ? "" : "s"}`,
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
const replyTo = this.details.message?.replyTo;
|
|
96
|
+
if (replyTo && !this.details.message?.expectsReply) {
|
|
97
|
+
meta.push(`Reply to ${replyTo.slice(0, 8)}`);
|
|
98
|
+
}
|
|
99
|
+
meta.push("Ctrl+O to expand");
|
|
100
|
+
lines.push(frameLine(this.theme.fg("dim", meta.join(" · "))));
|
|
101
|
+
lines.push(bottomBorder);
|
|
102
|
+
return lines;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (this.wrappedBody?.width !== innerWidth) {
|
|
106
|
+
this.wrappedBody = {
|
|
107
|
+
width: innerWidth,
|
|
108
|
+
lines: wrapTextWithAnsi(this.bodyText, innerWidth),
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
for (const line of this.wrappedBody.lines) {
|
|
112
|
+
lines.push(frameLine(this.theme.fg("text", line)));
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
if (this.details.replyCommand) {
|
|
116
|
+
lines.push(frameLine(""));
|
|
117
|
+
const replyLines = wrapTextWithAnsi(
|
|
118
|
+
this.theme.fg("dim", `To reply: ${this.details.replyCommand}`),
|
|
119
|
+
innerWidth,
|
|
120
|
+
);
|
|
121
|
+
for (const line of replyLines) {
|
|
122
|
+
lines.push(frameLine(line));
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const attachments = this.details.message?.content?.attachments;
|
|
127
|
+
if (attachments?.length) {
|
|
128
|
+
lines.push(frameLine(""));
|
|
129
|
+
for (const attachment of attachments) {
|
|
130
|
+
lines.push(
|
|
131
|
+
frameLine(this.theme.fg("dim", `Attachment: ${attachment.name}`)),
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const replyTo = this.details.message?.replyTo;
|
|
137
|
+
if (replyTo && !this.details.message?.expectsReply) {
|
|
138
|
+
lines.push(frameLine(""));
|
|
139
|
+
lines.push(
|
|
140
|
+
frameLine(this.theme.fg("dim", `Reply to ${replyTo.slice(0, 8)}`)),
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
lines.push(bottomBorder);
|
|
145
|
+
return lines;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export function renderIntercomMessage(
|
|
150
|
+
details: unknown,
|
|
151
|
+
expanded: boolean,
|
|
152
|
+
theme: Theme,
|
|
153
|
+
): Component | undefined {
|
|
154
|
+
if (!details || typeof details !== "object") return undefined;
|
|
155
|
+
const intercom = details as IntercomMessageDetails;
|
|
156
|
+
const text = intercom.bodyText ?? intercom.message?.content?.text;
|
|
157
|
+
if (typeof text !== "string") return undefined;
|
|
158
|
+
return new IntercomMessageComponent(intercom, expanded, theme);
|
|
159
|
+
}
|