pi-one-ui 0.1.1

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.
Files changed (101) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +106 -0
  3. package/extensions/app/config/renderer.ts +452 -0
  4. package/extensions/app/config/shell.ts +2484 -0
  5. package/extensions/app/ownership.ts +18 -0
  6. package/extensions/app/panel.ts +533 -0
  7. package/extensions/app/presets.ts +36 -0
  8. package/extensions/features/agent-summary/core.ts +194 -0
  9. package/extensions/features/agent-summary/index.ts +37 -0
  10. package/extensions/features/compact-thinking.ts +1262 -0
  11. package/extensions/features/context.ts +857 -0
  12. package/extensions/features/reference/index.ts +643 -0
  13. package/extensions/features/reference/session.ts +278 -0
  14. package/extensions/features/reference/subagent.ts +218 -0
  15. package/extensions/features/shell/aliases.ts +28 -0
  16. package/extensions/features/shell/flush-docked-bash.ts +39 -0
  17. package/extensions/features/shell/startup-header.ts +357 -0
  18. package/extensions/features/shell/working-message.ts +226 -0
  19. package/extensions/index.ts +52 -0
  20. package/extensions/shell/accent-rail-editor.ts +112 -0
  21. package/extensions/shell/accent-rail-layout-patch.ts +530 -0
  22. package/extensions/shell/completion-menu.ts +186 -0
  23. package/extensions/shell/editor-metadata-format.ts +287 -0
  24. package/extensions/shell/editor-transfer.ts +73 -0
  25. package/extensions/shell/extension-status.ts +102 -0
  26. package/extensions/shell/footer-format.ts +388 -0
  27. package/extensions/shell/footer-layout.ts +144 -0
  28. package/extensions/shell/footer.ts +1035 -0
  29. package/extensions/shell/format.ts +577 -0
  30. package/extensions/shell/git.ts +434 -0
  31. package/extensions/shell/icons.ts +261 -0
  32. package/extensions/shell/index.ts +1659 -0
  33. package/extensions/shell/interaction-summary.ts +1194 -0
  34. package/extensions/shell/live-context.ts +82 -0
  35. package/extensions/shell/minimalist-editor.ts +548 -0
  36. package/extensions/shell/package-version.ts +675 -0
  37. package/extensions/shell/project-refresh.ts +130 -0
  38. package/extensions/shell/project-state.ts +60 -0
  39. package/extensions/shell/prototype-patch-registry.ts +183 -0
  40. package/extensions/shell/runtime.ts +915 -0
  41. package/extensions/shell/selector-border.ts +109 -0
  42. package/extensions/shell/session-lifecycle.ts +60 -0
  43. package/extensions/shell/settings-command.ts +2144 -0
  44. package/extensions/shell/settings-previews.ts +137 -0
  45. package/extensions/shell/state.ts +83 -0
  46. package/extensions/shell/style.ts +480 -0
  47. package/extensions/shell/telemetry.ts +90 -0
  48. package/extensions/shell/ui.ts +1326 -0
  49. package/extensions/shell/user-message-osc.ts +279 -0
  50. package/extensions/shell/user-message-styles.ts +266 -0
  51. package/extensions/shell/user-message.ts +226 -0
  52. package/extensions/shell/working-line-messages.ts +24 -0
  53. package/extensions/shell/working-line-spinners.ts +54 -0
  54. package/extensions/shell/working-line.ts +1603 -0
  55. package/extensions/tools/ansi-color.ts +44 -0
  56. package/extensions/tools/ansi-text.ts +52 -0
  57. package/extensions/tools/component-tree.ts +37 -0
  58. package/extensions/tools/format.ts +28 -0
  59. package/extensions/tools/fullscreen-detect.ts +11 -0
  60. package/extensions/tools/patch-keys.ts +158 -0
  61. package/extensions/tools/sgr-mouse.ts +59 -0
  62. package/extensions/tools/tool-loading-icon.ts +20 -0
  63. package/extensions/tools/tool-result-sanitize.ts +27 -0
  64. package/extensions/transcript/index.ts +65 -0
  65. package/extensions/transcript/renderer/compact-mode.ts +1443 -0
  66. package/extensions/transcript/renderer/default-mode.ts +735 -0
  67. package/extensions/transcript/renderer/index.ts +286 -0
  68. package/extensions/transcript/renderer/markdown-enhance.ts +325 -0
  69. package/extensions/transcript/renderer/mouse/hover.ts +175 -0
  70. package/extensions/transcript/renderer/mouse/interaction.ts +1016 -0
  71. package/extensions/transcript/renderer/mouse/layout.ts +207 -0
  72. package/extensions/transcript/renderer/mouse/packets.ts +96 -0
  73. package/extensions/transcript/renderer/mouse/scroll.ts +211 -0
  74. package/extensions/transcript/renderer/tool/diff/ATTRIBUTION.md +28 -0
  75. package/extensions/transcript/renderer/tool/diff/ansi-utils.ts +128 -0
  76. package/extensions/transcript/renderer/tool/diff/diff-component.ts +112 -0
  77. package/extensions/transcript/renderer/tool/diff/diff-edit-render.ts +255 -0
  78. package/extensions/transcript/renderer/tool/diff/diff-header.ts +184 -0
  79. package/extensions/transcript/renderer/tool/diff/diff-highlight.ts +131 -0
  80. package/extensions/transcript/renderer/tool/diff/diff-inline.ts +350 -0
  81. package/extensions/transcript/renderer/tool/diff/diff-layout.ts +870 -0
  82. package/extensions/transcript/renderer/tool/diff/diff-limits.ts +189 -0
  83. package/extensions/transcript/renderer/tool/diff/diff-palette.ts +436 -0
  84. package/extensions/transcript/renderer/tool/diff/diff-parse.ts +536 -0
  85. package/extensions/transcript/renderer/tool/diff/diff-presentation.ts +79 -0
  86. package/extensions/transcript/renderer/tool/diff/diff-renderer.ts +29 -0
  87. package/extensions/transcript/renderer/tool/diff/diff-text.ts +57 -0
  88. package/extensions/transcript/renderer/tool/diff/diff-write-render.ts +629 -0
  89. package/extensions/transcript/renderer/tool/diff/index.ts +147 -0
  90. package/extensions/transcript/renderer/tool/diff/line-width-safety.ts +100 -0
  91. package/extensions/transcript/renderer/tool/diff/shiki-highlight.ts +104 -0
  92. package/extensions/transcript/renderer/tool/diff/write-execution.ts +124 -0
  93. package/extensions/transcript/renderer/tool/grouping.ts +619 -0
  94. package/extensions/transcript/renderer/tool/message-display.ts +183 -0
  95. package/extensions/transcript/renderer/tool/names.ts +195 -0
  96. package/extensions/transcript/renderer/tool/result.ts +842 -0
  97. package/extensions/transcript/renderer/tool/show-more-hint.ts +42 -0
  98. package/extensions/transcript/renderer/transcript-refresh.ts +79 -0
  99. package/package.json +58 -0
  100. package/themes/cc-dark.json +91 -0
  101. package/themes/cc-light.json +91 -0
@@ -0,0 +1,279 @@
1
+ const ESC = "\x1b";
2
+ const BEL = "\x07";
3
+ const C1_DCS = "\x90";
4
+ const C1_SOS = "\x98";
5
+ const C1_CSI = "\x9b";
6
+ const C1_ST = "\x9c";
7
+ const C1_OSC = "\x9d";
8
+ const C1_PM = "\x9e";
9
+ const C1_APC = "\x9f";
10
+ const CAN = 0x18;
11
+ const SUB = 0x1a;
12
+
13
+ type ControlBoundary =
14
+ | {
15
+ kind: "terminator";
16
+ index: number;
17
+ length: number;
18
+ safeOsc8Terminator: boolean;
19
+ }
20
+ | { kind: "start"; index: number };
21
+
22
+ type FilterOptions = {
23
+ preserveValidOsc8: boolean;
24
+ preserveSourceWhitespace: boolean;
25
+ preserveSgr: boolean;
26
+ };
27
+
28
+ type FilterResult = {
29
+ text: string;
30
+ balancedOsc8: boolean;
31
+ };
32
+
33
+ function anyOscStartLength(text: string, index: number): number {
34
+ if (text[index] === C1_OSC) return 1;
35
+ return text[index] === ESC && text[index + 1] === "]" ? 2 : 0;
36
+ }
37
+
38
+ function findOscBoundary(
39
+ text: string,
40
+ payloadStart: number,
41
+ ): ControlBoundary | undefined {
42
+ for (let index = payloadStart; index < text.length; index += 1) {
43
+ if (anyOscStartLength(text, index) > 0) return { kind: "start", index };
44
+ if (text[index] === BEL) {
45
+ return { kind: "terminator", index, length: 1, safeOsc8Terminator: true };
46
+ }
47
+ if (text[index] === C1_ST) {
48
+ return {
49
+ kind: "terminator",
50
+ index,
51
+ length: 1,
52
+ safeOsc8Terminator: false,
53
+ };
54
+ }
55
+ if (text[index] === ESC && text[index + 1] === "\\") {
56
+ return { kind: "terminator", index, length: 2, safeOsc8Terminator: true };
57
+ }
58
+ }
59
+ return undefined;
60
+ }
61
+
62
+ const terminalControlPattern = /[\u0000-\u001f\u007f-\u009f]/;
63
+ const safeParameterKeyPattern = /^[A-Za-z0-9_.-]+$/;
64
+
65
+ export function isValidUserMessageOsc8Payload(payload: string): boolean {
66
+ if (!payload.startsWith("8;")) return false;
67
+ const uriSeparator = payload.indexOf(";", 2);
68
+ if (uriSeparator < 0) return false;
69
+
70
+ const params = payload.slice(2, uriSeparator);
71
+ const uri = payload.slice(uriSeparator + 1);
72
+ if (params === "" && uri === "") return true;
73
+ if (uri === "" || /\s/.test(uri) || terminalControlPattern.test(uri))
74
+ return false;
75
+ if (params === "") return true;
76
+
77
+ return params.split(":").every((entry) => {
78
+ const equals = entry.indexOf("=");
79
+ if (equals <= 0) return false;
80
+ const key = entry.slice(0, equals);
81
+ const value = entry.slice(equals + 1);
82
+ return (
83
+ safeParameterKeyPattern.test(key) &&
84
+ !terminalControlPattern.test(key) &&
85
+ !terminalControlPattern.test(value)
86
+ );
87
+ });
88
+ }
89
+
90
+ function incompleteOsc133PrefixLength(payload: string): number {
91
+ if (payload.length > 0 && "133".startsWith(payload)) return payload.length;
92
+ if (!payload.startsWith("133;")) return 0;
93
+
94
+ let length = 4;
95
+ if (/^[A-D]$/.test(payload[length] ?? "")) length += 1;
96
+ if (payload[length] === ";") length += 1;
97
+ return length;
98
+ }
99
+
100
+ function consumeCsi(value: string, start: number): number {
101
+ for (let index = start; index < value.length; index += 1) {
102
+ const code = value.charCodeAt(index);
103
+ if (code === CAN || code === SUB) return index + 1;
104
+ if (code >= 0x40 && code <= 0x7e) return index + 1;
105
+ }
106
+ return value.length;
107
+ }
108
+
109
+ function consumeControlString(
110
+ value: string,
111
+ start: number,
112
+ allowBel: boolean,
113
+ ): number {
114
+ for (let index = start; index < value.length; index += 1) {
115
+ const code = value.charCodeAt(index);
116
+ if (code === CAN || code === SUB) return index + 1;
117
+ if (allowBel && code === BEL.charCodeAt(0)) return index + 1;
118
+ if (code === C1_ST.charCodeAt(0)) return index + 1;
119
+ if (code === ESC.charCodeAt(0) && value[index + 1] === "\\")
120
+ return index + 2;
121
+ }
122
+ return value.length;
123
+ }
124
+
125
+ function consumeEscape(value: string, start: number): number {
126
+ if (start + 1 >= value.length) return value.length;
127
+ const next = value[start + 1];
128
+ if (next === "[") return consumeCsi(value, start + 2);
129
+ if (next === "P" || next === "X" || next === "^" || next === "_") {
130
+ return consumeControlString(value, start + 2, false);
131
+ }
132
+
133
+ let index = start + 1;
134
+ while (index < value.length) {
135
+ const code = value.charCodeAt(index);
136
+ if (code >= 0x20 && code <= 0x2f) {
137
+ index += 1;
138
+ continue;
139
+ }
140
+ return code >= 0x30 && code <= 0x7e ? index + 1 : index;
141
+ }
142
+ return value.length;
143
+ }
144
+
145
+ function isSafeSgr(sequence: string): boolean {
146
+ return /^\x1b\[[0-9:;]*m$/.test(sequence);
147
+ }
148
+
149
+ function isOsc8Close(payload: string): boolean {
150
+ return payload === "8;;";
151
+ }
152
+
153
+ function updateOsc8Balance(
154
+ payload: string,
155
+ state: { open: boolean; invalid: boolean },
156
+ ): void {
157
+ if (isOsc8Close(payload)) {
158
+ if (!state.open) state.invalid = true;
159
+ state.open = false;
160
+ return;
161
+ }
162
+ if (state.open) state.invalid = true;
163
+ state.open = true;
164
+ }
165
+
166
+ function filterUserMessageTerminalText(
167
+ text: string,
168
+ options: FilterOptions,
169
+ ): FilterResult {
170
+ let output = "";
171
+ let index = 0;
172
+ const osc8 = { open: false, invalid: false };
173
+ while (index < text.length) {
174
+ const oscStartLength = anyOscStartLength(text, index);
175
+ if (oscStartLength > 0) {
176
+ const payloadStart = index + oscStartLength;
177
+ const boundary = findOscBoundary(text, payloadStart);
178
+ if (boundary?.kind === "terminator") {
179
+ const end = boundary.index + boundary.length;
180
+ const payload = text.slice(payloadStart, boundary.index);
181
+ if (
182
+ options.preserveValidOsc8 &&
183
+ oscStartLength === 2 &&
184
+ boundary.safeOsc8Terminator &&
185
+ isValidUserMessageOsc8Payload(payload)
186
+ ) {
187
+ updateOsc8Balance(payload, osc8);
188
+ output += text.slice(index, end);
189
+ }
190
+ index = end;
191
+ continue;
192
+ }
193
+
194
+ // Removing an unterminated introducer prevents it from consuming
195
+ // Zentui's prompt markers. Preserve visible trailing payload, except
196
+ // for a recognized partial OSC 133 command prefix.
197
+ const payloadEnd = boundary?.index ?? text.length;
198
+ const payload = text.slice(payloadStart, payloadEnd);
199
+ index = payloadStart + incompleteOsc133PrefixLength(payload);
200
+ continue;
201
+ }
202
+
203
+ const code = text.charCodeAt(index);
204
+ if (code === ESC.charCodeAt(0)) {
205
+ if (text[index + 1] === "[") {
206
+ const end = consumeCsi(text, index + 2);
207
+ const sequence = text.slice(index, end);
208
+ if (options.preserveSgr && isSafeSgr(sequence)) output += sequence;
209
+ index = end;
210
+ continue;
211
+ }
212
+ index = consumeEscape(text, index);
213
+ continue;
214
+ }
215
+ if (text[index] === C1_CSI) {
216
+ index = consumeCsi(text, index + 1);
217
+ continue;
218
+ }
219
+ if (
220
+ text[index] === C1_DCS ||
221
+ text[index] === C1_SOS ||
222
+ text[index] === C1_PM ||
223
+ text[index] === C1_APC
224
+ ) {
225
+ index = consumeControlString(text, index + 1, false);
226
+ continue;
227
+ }
228
+ if (code === 0x09 || code === 0x0a) {
229
+ if (options.preserveSourceWhitespace) output += text[index];
230
+ index += 1;
231
+ continue;
232
+ }
233
+ if (code < 0x20 || (code >= 0x7f && code <= 0x9f)) {
234
+ index += 1;
235
+ continue;
236
+ }
237
+ output += text[index];
238
+ index += 1;
239
+ }
240
+ return { text: output, balancedOsc8: !osc8.open && !osc8.invalid };
241
+ }
242
+
243
+ function filterBalancedUserMessageTerminalText(
244
+ text: string,
245
+ options: FilterOptions,
246
+ ): string {
247
+ const filtered = filterUserMessageTerminalText(text, options);
248
+ if (!options.preserveValidOsc8 || filtered.balancedOsc8) return filtered.text;
249
+ return filterUserMessageTerminalText(text, {
250
+ ...options,
251
+ preserveValidOsc8: false,
252
+ }).text;
253
+ }
254
+
255
+ /** Strip every terminal control from untrusted source text before Markdown rendering. */
256
+ export function sanitizeUserMessageSourceText(text: string): string {
257
+ return filterBalancedUserMessageTerminalText(text, {
258
+ preserveValidOsc8: false,
259
+ preserveSourceWhitespace: true,
260
+ preserveSgr: false,
261
+ });
262
+ }
263
+
264
+ /**
265
+ * Sanitize a predecessor-rendered row. Pi formatting needs only SGR and
266
+ * structurally valid 7-bit OSC 8; every other terminal control is removed.
267
+ */
268
+ export function sanitizeRenderedUserMessageText(text: string): string {
269
+ return filterBalancedUserMessageTerminalText(text, {
270
+ preserveValidOsc8: true,
271
+ preserveSourceWhitespace: true,
272
+ preserveSgr: true,
273
+ });
274
+ }
275
+
276
+ /** Sanitize one predecessor output stream while retaining its row boundaries. */
277
+ export function sanitizeRenderedUserMessageLines(lines: string[]): string[] {
278
+ return sanitizeRenderedUserMessageText(lines.join("\n")).split("\n");
279
+ }
@@ -0,0 +1,266 @@
1
+ import type { Theme, ThemeColor } from "@earendil-works/pi-coding-agent";
2
+ import {
3
+ Markdown,
4
+ type MarkdownTheme,
5
+ truncateToWidth,
6
+ visibleWidth,
7
+ } from "@earendil-works/pi-tui";
8
+ import type { ZentuiConfig } from "../app/config/shell.ts";
9
+ import {
10
+ EDITOR_ACCENT_FALLBACK,
11
+ EDITOR_BORDER_FALLBACK,
12
+ renderStyleForSourceOrFallbackStrict,
13
+ } from "./style.ts";
14
+ import { sanitizeUserMessageSourceText } from "./user-message-osc.ts";
15
+
16
+ export type UserMessageStyleRenderInput = {
17
+ text: string;
18
+ width: number;
19
+ theme?: Theme;
20
+ config: ZentuiConfig;
21
+ };
22
+
23
+ function themeFg(
24
+ theme: Theme | undefined,
25
+ color: ThemeColor,
26
+ text: string,
27
+ ): string {
28
+ return theme ? theme.fg(color, text) : text;
29
+ }
30
+
31
+ function makeMarkdownTheme(theme: Theme | undefined): MarkdownTheme {
32
+ return {
33
+ heading: (text) => themeFg(theme, "mdHeading", text),
34
+ link: (text) => themeFg(theme, "mdLink", text),
35
+ linkUrl: (text) => themeFg(theme, "mdLinkUrl", text),
36
+ code: (text) => themeFg(theme, "mdCode", text),
37
+ codeBlock: (text) => themeFg(theme, "mdCodeBlock", text),
38
+ codeBlockBorder: (text) => themeFg(theme, "mdCodeBlockBorder", text),
39
+ quote: (text) => themeFg(theme, "mdQuote", text),
40
+ quoteBorder: (text) => themeFg(theme, "mdQuoteBorder", text),
41
+ hr: (text) => themeFg(theme, "mdHr", text),
42
+ listBullet: (text) => themeFg(theme, "mdListBullet", text),
43
+ bold: (text) => (theme ? theme.bold(text) : text),
44
+ italic: (text) => (theme ? theme.italic(text) : text),
45
+ underline: (text) => (theme ? theme.underline(text) : text),
46
+ strikethrough: (text) => (theme ? theme.strikethrough(text) : text),
47
+ };
48
+ }
49
+
50
+ function renderMarkdown(
51
+ text: string,
52
+ width: number,
53
+ theme: Theme | undefined,
54
+ ): string[] {
55
+ const renderer = new Markdown(text, 0, 0, makeMarkdownTheme(theme), {
56
+ color: (content) => themeFg(theme, "userMessageText", content),
57
+ });
58
+ const lines = renderer.render(Math.max(1, width));
59
+ return lines.length > 0 ? lines : [""];
60
+ }
61
+
62
+ function trimMarkdownPadding(line: string): string {
63
+ return line.replace(/ +((?:\x1b\[[0-?]*[ -/]*[@-~])*)$/, "$1");
64
+ }
65
+
66
+ function fillLine(content: string, width: number): string {
67
+ const truncated = truncateToWidth(content, Math.max(0, width), "");
68
+ return `${truncated}${" ".repeat(Math.max(0, width - visibleWidth(truncated)))}`;
69
+ }
70
+
71
+ function accent(
72
+ theme: Theme | undefined,
73
+ config: ZentuiConfig,
74
+ text: string,
75
+ ): string {
76
+ return theme
77
+ ? renderStyleForSourceOrFallbackStrict(
78
+ theme,
79
+ config.components.userMessages.colorSource,
80
+ config.colors.editorAccent,
81
+ EDITOR_ACCENT_FALLBACK,
82
+ text,
83
+ )
84
+ : text;
85
+ }
86
+
87
+ function border(
88
+ theme: Theme | undefined,
89
+ config: ZentuiConfig,
90
+ text: string,
91
+ ): string {
92
+ return theme
93
+ ? renderStyleForSourceOrFallbackStrict(
94
+ theme,
95
+ config.components.userMessages.colorSource,
96
+ config.colors.editorBorder,
97
+ EDITOR_BORDER_FALLBACK,
98
+ text,
99
+ )
100
+ : text;
101
+ }
102
+
103
+ function renderRail(theme: Theme | undefined, config: ZentuiConfig): string {
104
+ return `${accent(theme, config, config.icons.rail)} `;
105
+ }
106
+
107
+ function renderFramed({
108
+ text,
109
+ width,
110
+ theme,
111
+ config,
112
+ }: UserMessageStyleRenderInput): string[] {
113
+ if (width <= 0) return [""];
114
+ const rail = renderRail(theme, config);
115
+ const contentWidth = Math.max(1, width - visibleWidth(rail));
116
+ const body = renderMarkdown(text, contentWidth, theme);
117
+ const row = (line: string) => {
118
+ const available = Math.max(0, width - visibleWidth(rail));
119
+ return truncateToWidth(`${rail}${fillLine(line, available)}`, width, "");
120
+ };
121
+ const rule = truncateToWidth(
122
+ border(theme, config, "─".repeat(width)),
123
+ width,
124
+ "",
125
+ );
126
+ return [rule, row(""), ...body.map(row), row(""), rule];
127
+ }
128
+
129
+ function renderFramedCopyFriendly({
130
+ text,
131
+ width,
132
+ theme,
133
+ config,
134
+ }: UserMessageStyleRenderInput): string[] {
135
+ if (width <= 0) return [""];
136
+ const prefix = width > 1 ? " " : "";
137
+ const body = renderMarkdown(text, width - prefix.length, theme).map((line) =>
138
+ fillLine(`${prefix}${line}`, width),
139
+ );
140
+ const rule = truncateToWidth(
141
+ border(theme, config, "─".repeat(width)),
142
+ width,
143
+ "",
144
+ );
145
+ return [rule, "", ...body, "", rule];
146
+ }
147
+
148
+ function renderCompact({
149
+ text,
150
+ width,
151
+ theme,
152
+ config,
153
+ }: UserMessageStyleRenderInput): string[] {
154
+ if (width <= 0) return [""];
155
+ const rail = renderRail(theme, config);
156
+ const railWidth = visibleWidth(rail);
157
+ if (width <= railWidth) {
158
+ return renderMarkdown(text, width, theme).map((line) =>
159
+ truncateToWidth(trimMarkdownPadding(line), width, ""),
160
+ );
161
+ }
162
+ const contentWidth = width - railWidth;
163
+ return renderMarkdown(text, contentWidth, theme).map((line) =>
164
+ truncateToWidth(`${rail}${trimMarkdownPadding(line)}`, width, ""),
165
+ );
166
+ }
167
+
168
+ function renderLabeled({
169
+ text,
170
+ width,
171
+ theme,
172
+ config,
173
+ }: UserMessageStyleRenderInput): string[] {
174
+ if (width <= 0) return [""];
175
+ if (width <= 2) {
176
+ return renderMarkdown(text, width, theme).map((line) =>
177
+ truncateToWidth(line, width, ""),
178
+ );
179
+ }
180
+
181
+ const horizontalPadding = width >= 5 ? 1 : 0;
182
+ const contentWidth = Math.max(1, width - 2 - horizontalPadding * 2);
183
+ const body = renderMarkdown(text, contentWidth, theme);
184
+ const top =
185
+ width >= 9
186
+ ? `${border(theme, config, "╭─")}${accent(theme, config, " User ")}${border(
187
+ theme,
188
+ config,
189
+ `${"─".repeat(Math.max(0, width - 9))}╮`,
190
+ )}`
191
+ : border(theme, config, `╭${"─".repeat(Math.max(0, width - 2))}╮`);
192
+ const padding = " ".repeat(horizontalPadding);
193
+ const side = (line: string) =>
194
+ `${border(theme, config, "│")}${padding}${fillLine(line, contentWidth)}${padding}${border(
195
+ theme,
196
+ config,
197
+ "│",
198
+ )}`;
199
+ const bottom = border(
200
+ theme,
201
+ config,
202
+ `╰${"─".repeat(Math.max(0, width - 2))}╯`,
203
+ );
204
+ return [top, ...body.map(side), bottom];
205
+ }
206
+
207
+ export function userMessageStyleCacheKey(config: ZentuiConfig): string {
208
+ const messages = config.components.userMessages;
209
+ switch (messages.style) {
210
+ case "framed":
211
+ return [
212
+ "framed",
213
+ messages.colorSource,
214
+ config.colors.editorAccent ?? "",
215
+ config.colors.editorBorder ?? "",
216
+ config.icons.rail,
217
+ ].join("\0");
218
+ case "framed-copy-friendly":
219
+ return [
220
+ "framed-copy-friendly",
221
+ messages.colorSource,
222
+ config.colors.editorBorder ?? "",
223
+ ].join("\0");
224
+ case "compact":
225
+ return [
226
+ "compact",
227
+ messages.colorSource,
228
+ config.colors.editorAccent ?? "",
229
+ config.icons.rail,
230
+ ].join("\0");
231
+ case "labeled":
232
+ return [
233
+ "labeled",
234
+ messages.colorSource,
235
+ config.colors.editorAccent ?? "",
236
+ config.colors.editorBorder ?? "",
237
+ "User:v1",
238
+ ].join("\0");
239
+ }
240
+ }
241
+
242
+ function renderSelectedUserMessageStyle(
243
+ input: UserMessageStyleRenderInput,
244
+ ): string[] {
245
+ switch (input.config.components.userMessages.style) {
246
+ case "framed":
247
+ return renderFramed(input);
248
+ case "framed-copy-friendly":
249
+ return renderFramedCopyFriendly(input);
250
+ case "compact":
251
+ return renderCompact(input);
252
+ case "labeled":
253
+ return renderLabeled(input);
254
+ }
255
+ }
256
+
257
+ export function renderUserMessageStyle(
258
+ input: UserMessageStyleRenderInput,
259
+ ): string[] {
260
+ // Raw user input is a terminal trust boundary. Strip every source control,
261
+ // including OSC 8; Markdown may add its own validated links afterward.
262
+ return renderSelectedUserMessageStyle({
263
+ ...input,
264
+ text: sanitizeUserMessageSourceText(input.text),
265
+ });
266
+ }