@pi-kaush/pi-content-layout 0.1.11 → 0.1.12

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,8 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ - Restore Pi's native active editor border and terminal background, so its embedded status interrupts the top rule as in native Pi. Submitted user messages keep their darker railed shell. Older Pi versions keep the aligned transcript-row status fallback.
6
+
5
7
  - Roll back a chat-container hook that mutates the child list and then throws.
6
8
  Its edit used to stick, dropping those rows from every later render. The
7
9
  contract is shared by copy with pi-tool-call-markers, so both copies changed
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # pi-content-layout
2
2
 
3
- A small Pi extension that insets the main conversation, renders the active editor as a full-width dark surface, and gives submitted prompts a compact rail shell.
3
+ A small Pi extension that insets the main conversation, leaves the active editor in Pi's native style, and gives submitted prompts a compact rail shell.
4
4
 
5
5
  ### Install
6
6
 
@@ -14,10 +14,10 @@ Restart Pi or run `/reload`.
14
14
  Assistant output
15
15
  Text wraps inside the inset width.
16
16
 
17
- Active prompt
18
- ████████████████████████████████████████████████
19
- prompt text darker background
20
- ████████████████████████████████████████████████
17
+ Active prompt (native Pi border and terminal background)
18
+ ── ⠋ Working ───────────────────────────────────
19
+ prompt text
20
+ ────────────────────────────────────────────────
21
21
 
22
22
  Submitted prompt
23
23
  ▎ darker background
@@ -25,7 +25,7 @@ Submitted prompt
25
25
  ▎ darker background
26
26
  ```
27
27
 
28
- Assistant and submitted-message content keep the two-column outer inset. The active prompt intentionally ignores that inset: its darker background fills the terminal width, with no rail, one extra layout column on each side of Pi's configured editor padding, and one background-colored row above and below the content. Real scroll indicators replace the corresponding padding row when needed. The submitted prompt remains unchanged: it keeps Pi's message padding and the thin rail outside its darker body. Autocomplete stays outside the active surface.
28
+ Assistant and submitted-message content keep the two-column outer inset. The active prompt uses its editor's native border, terminal background, and padding. Pi embeds its status indicator in the top border when supported. The submitted prompt keeps Pi's message padding, with the thin rail outside its darker body.
29
29
 
30
30
  ## Scope boundary
31
31
 
@@ -90,20 +90,15 @@ If you manage Pi package sources directly, add the package to `settings.json`:
90
90
 
91
91
  ## Theme ownership
92
92
 
93
- The active editor surface and submitted message body paint with a fixed
94
- near-black `#071312` background (`PROMPT_SURFACE_BG`) so both user-input
95
- surfaces stay identical; the theme's `selectedBg` token continues to serve
96
- selections and dialogs. Active input uses the theme's `userMessageText`
97
- foreground and restores it after embedded ANSI resets without overriding
98
- inline identifier colors. The extension also consumes `accent` for the
99
- submitted-prompt rail and `muted` for editor scroll hints.
93
+ The active editor uses Pi's native terminal background (light with a light theme, dark with a dark theme). Submitted message bodies paint with the theme's `userMessageBg` token, and their rails use `borderAccent`.
100
94
 
101
- Themes control colors, while this extension controls width and component
102
- shape; a theme cannot provide the layout itself.
95
+ Themes control colors; this extension controls transcript spacing and the submitted-prompt shape.
103
96
 
104
97
  ## Composition and compatibility
105
98
 
106
- The editor factory wraps the currently configured custom editor, or creates Pi's `CustomEditor` when none exists. It decorates `render()` only; text handling, callbacks, autocomplete, history, paste, application keybindings, image paste, and extension shortcuts remain on Pi's editor.
99
+ The editor factory wraps the currently configured custom editor, or creates Pi's `CustomEditor` when none exists. It preserves the editor's native rendering and input behavior. The wrapper only prevents transcript-specific status indentation from affecting a status embedded in the editor border.
100
+
101
+ The default editor opts into Pi's `embedWorkingStatus` behavior when the host supports it, so status indicators interrupt the active prompt's top border. Older Pi versions keep the separate status row, which this package still aligns with the transcript.
107
102
 
108
103
  Pi does not currently expose public renderers for native user and assistant messages or queued steering previews. Their layout and styling use guarded adapters around Pi's exported components. The adapters restore the original renderers on shutdown and fall back to native rendering when the expected component shape changes.
109
104
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-kaush/pi-content-layout",
3
- "version": "0.1.11",
3
+ "version": "0.1.12",
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
@@ -22,7 +22,6 @@ import { renderIntercomMessage } from "./intercom-message.ts";
22
22
  import {
23
23
  contentInset,
24
24
  insetLines,
25
- renderActiveEditor,
26
25
  renderSubmittedUserLines,
27
26
  } from "./render.ts";
28
27
 
@@ -46,6 +45,15 @@ type EditorFactory = (
46
45
  keybindings: KeybindingsManager,
47
46
  ) => EditorComponent;
48
47
 
48
+ type EmbeddedStatusEditorOptions = NonNullable<
49
+ ConstructorParameters<typeof CustomEditor>[3]
50
+ > & { embedWorkingStatus: true };
51
+
52
+ // Newer Pi consumes this option; older editors keep the transcript status row.
53
+ const EMBEDDED_STATUS_EDITOR_OPTIONS: EmbeddedStatusEditorOptions = {
54
+ embedWorkingStatus: true,
55
+ };
56
+
49
57
  type ThemeGetter = () => Theme | undefined;
50
58
 
51
59
  type RenderRow = {
@@ -249,6 +257,9 @@ const knownChatContainers = new WeakSet<object>();
249
257
 
250
258
  let systemTextHookActive = 0;
251
259
 
260
+ // Embedded status indicators call Loader.render() from inside the editor border.
261
+ let embeddedStatusRenderDepth = 0;
262
+
252
263
  // The system-text inset decorates matching Text instances in place instead of
253
264
  // intercepting the container's child list. Other whole-container wrappers
254
265
  // (pi-tool-call-markers' grouping) run the shared hooks without delegating to
@@ -305,8 +316,12 @@ function statusLoaderDecorator(
305
316
  row: RenderRow,
306
317
  width: number,
307
318
  ): string[] {
308
- if (typeof (row as LoaderRow).kind !== "string")
319
+ if (
320
+ embeddedStatusRenderDepth > 0 ||
321
+ typeof (row as LoaderRow).kind !== "string"
322
+ ) {
309
323
  return original.call(row, width);
324
+ }
310
325
  const nativeInset = Math.max(0, Number((row as LoaderRow).paddingX) || 0);
311
326
  const inset = Math.max(0, contentInset(width) - nativeInset);
312
327
  if (inset === 0) return original.call(row, width);
@@ -401,22 +416,31 @@ function userDecorator(
401
416
  return decorated;
402
417
  }
403
418
 
404
- function decorateEditor(
405
- editor: EditorComponent,
406
- getTheme: ThemeGetter,
407
- ): EditorComponent {
408
- const target = editor as EditorComponent & {
409
- borderColor?: (text: string) => string;
419
+ function supportsEmbeddedWorkingStatus(editor: EditorComponent): boolean {
420
+ const candidate = editor as EditorComponent & {
421
+ embedWorkingStatus?: unknown;
422
+ setWorkingStatusIndicator?: unknown;
410
423
  };
424
+ return (
425
+ candidate.embedWorkingStatus === true &&
426
+ typeof candidate.setWorkingStatusIndicator === "function"
427
+ );
428
+ }
429
+
430
+ function decorateEditor(editor: EditorComponent): EditorComponent {
431
+ const embedsWorkingStatus = supportsEmbeddedWorkingStatus(editor);
411
432
 
412
- return new Proxy(target, {
433
+ return new Proxy(editor, {
413
434
  get(component, property) {
414
435
  if (property === "render") {
415
436
  return (width: number) => {
416
- const theme = getTheme();
417
- return theme
418
- ? renderActiveEditor(component, width, theme)
419
- : component.render(width);
437
+ if (!embedsWorkingStatus) return component.render(width);
438
+ embeddedStatusRenderDepth += 1;
439
+ try {
440
+ return component.render(width);
441
+ } finally {
442
+ embeddedStatusRenderDepth -= 1;
443
+ }
420
444
  };
421
445
  }
422
446
  const value = Reflect.get(component, property, component) as unknown;
@@ -506,8 +530,13 @@ export default function contentLayout(pi: ExtensionAPI): void {
506
530
  const factory: EditorFactory = (tui, editorTheme, keybindings) => {
507
531
  const editor = previous
508
532
  ? previous(tui, editorTheme, keybindings)
509
- : new CustomEditor(tui, editorTheme, keybindings);
510
- return decorateEditor(editor, getTheme);
533
+ : new CustomEditor(
534
+ tui,
535
+ editorTheme,
536
+ keybindings,
537
+ EMBEDDED_STATUS_EDITOR_OPTIONS,
538
+ );
539
+ return decorateEditor(editor);
511
540
  };
512
541
  editorRegistration = { factory, previous };
513
542
  ctx.ui.setEditorComponent(factory);
package/src/render.ts CHANGED
@@ -1,16 +1,13 @@
1
1
  import type { Theme, ThemeColor } from "@earendil-works/pi-coding-agent";
2
- import type { EditorComponent } from "@earendil-works/pi-tui";
3
2
  import { truncateToWidth, visibleWidth } from "@earendil-works/pi-tui";
4
3
 
5
4
  export const OUTER_INSET = 2;
6
5
  export const PROMPT_RAIL = "▎";
7
- export const ACTIVE_SIDE_PADDING = 1;
6
+ const SUBMITTED_SIDE_PADDING = 1;
8
7
 
9
- // The prompt surface (active editor block and submitted message body) paints
10
- // with the theme's userMessageBg token, so both user-input surfaces stay
11
- // identical while following the active theme. userMessageBg is a required pi
12
- // theme token; the legacy hex remains only as a fallback for theme lookalikes
13
- // that cannot resolve it (test fakes, older hosts).
8
+ // Submitted message bodies paint with the theme's userMessageBg token.
9
+ // The active editor uses Pi's native terminal background. The legacy hex
10
+ // remains only as a fallback for theme lookalikes that cannot resolve it.
14
11
  const PROMPT_SURFACE_BG_FALLBACK = "\x1b[48;2;7;19;18m"; // #071312
15
12
 
16
13
  export function promptSurfaceBg(theme: Theme): string {
@@ -21,15 +18,9 @@ export function promptSurfaceBg(theme: Theme): string {
21
18
  }
22
19
  }
23
20
 
24
- const BORDER_SENTINEL = "\x1b]133;P;pi-content-layout\x07";
25
21
  const SGR_PATTERN = /\x1b\[([0-9;]*)m/g;
26
22
  const BACKGROUND_PATTERN =
27
23
  /\x1b\[(?:4[0-8]|10[0-7]|48;5;\d{1,3}|48;2;\d{1,3};\d{1,3};\d{1,3})m/g;
28
- const DISPLAY_ANSI_PATTERN = /\x1b(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])/g;
29
-
30
- type BorderEditor = EditorComponent & {
31
- borderColor?: (text: string) => string;
32
- };
33
24
 
34
25
  export function contentInset(width: number): number {
35
26
  return width > OUTER_INSET * 2 ? OUTER_INSET : 0;
@@ -97,41 +88,6 @@ function reapplyBackgroundAfterReset(
97
88
  });
98
89
  }
99
90
 
100
- function leavesForegroundReset(rawParameters: string): boolean {
101
- const parameters =
102
- rawParameters === "" ? [0] : rawParameters.split(";").map(Number);
103
- let foregroundIsDefault = false;
104
- for (let index = 0; index < parameters.length; index++) {
105
- const parameter = parameters[index];
106
- if (parameter === 38) {
107
- foregroundIsDefault = false;
108
- const mode = parameters[index + 1];
109
- if (mode === 5) index += 2;
110
- if (mode === 2) index += 4;
111
- } else if (parameter === 0 || parameter === 39) {
112
- foregroundIsDefault = true;
113
- } else if (
114
- parameter !== undefined &&
115
- ((parameter >= 30 && parameter <= 37) ||
116
- (parameter >= 90 && parameter <= 97))
117
- ) {
118
- foregroundIsDefault = false;
119
- }
120
- }
121
- return foregroundIsDefault;
122
- }
123
-
124
- function paintForeground(text: string, foregroundAnsi: string): string {
125
- const content = text.replace(
126
- SGR_PATTERN,
127
- (sequence, rawParameters: string) =>
128
- leavesForegroundReset(rawParameters)
129
- ? `${sequence}${foregroundAnsi}`
130
- : sequence,
131
- );
132
- return `${foregroundAnsi}${content}\x1b[39m`;
133
- }
134
-
135
91
  export function paintBackground(
136
92
  line: string,
137
93
  width: number,
@@ -142,99 +98,6 @@ export function paintBackground(
142
98
  return `${backgroundAnsi}${reapplyBackgroundAfterReset(fitted, backgroundAnsi)}\x1b[49m`;
143
99
  }
144
100
 
145
- function stripDisplayAnsi(text: string): string {
146
- return text.replace(DISPLAY_ANSI_PATTERN, "");
147
- }
148
-
149
- function scrollHint(line: string): string | undefined {
150
- return stripDisplayAnsi(line).match(/[↑↓] \d+ more/)?.[0];
151
- }
152
-
153
- function activeBlockLine(
154
- line: string,
155
- isBoundary: boolean,
156
- width: number,
157
- theme: Theme,
158
- ): string {
159
- const hint = isBoundary ? scrollHint(line) : undefined;
160
- const body = hint
161
- ? theme.fg("muted", ` ${hint}`)
162
- : isBoundary
163
- ? ""
164
- : paintForeground(line, theme.getFgAnsi("userMessageText"));
165
- const innerWidth = Math.max(0, width - ACTIVE_SIDE_PADDING * 2);
166
- const padding = " ".repeat(ACTIVE_SIDE_PADDING);
167
- return paintBackground(
168
- `${padding}${fitLine(body, innerWidth)}${padding}`,
169
- width,
170
- promptSurfaceBg(theme),
171
- );
172
- }
173
-
174
- function markEditorBoundaries(editor: BorderEditor): () => void {
175
- const original = editor.borderColor;
176
- if (typeof original !== "function") return () => {};
177
- editor.borderColor = (text: string) =>
178
- `${BORDER_SENTINEL}${original(text)}${BORDER_SENTINEL}`;
179
- return () => {
180
- editor.borderColor = original;
181
- };
182
- }
183
-
184
- export function renderActiveEditor(
185
- editor: BorderEditor,
186
- width: number,
187
- theme: Theme,
188
- ): string[] {
189
- const editorWidth = width - ACTIVE_SIDE_PADDING * 2;
190
- if (editorWidth < 1 || typeof editor.borderColor !== "function") {
191
- return editor.render(width);
192
- }
193
-
194
- const restoreBorder = markEditorBoundaries(editor);
195
- let markedLines: string[];
196
- try {
197
- markedLines = editor.render(editorWidth);
198
- } finally {
199
- restoreBorder();
200
- }
201
-
202
- try {
203
- const boundaries = markedLines
204
- .map((line, index) => (line.includes(BORDER_SENTINEL) ? index : -1))
205
- .filter((index) => index >= 0);
206
- if (boundaries.length !== 2 || boundaries[0] !== 0) {
207
- return editor.render(width);
208
- }
209
-
210
- const bottomBoundary = boundaries[1];
211
- if (bottomBoundary === undefined || bottomBoundary <= 0) {
212
- return editor.render(width);
213
- }
214
-
215
- const cleanLines = markedLines.map((line) =>
216
- line.split(BORDER_SENTINEL).join(""),
217
- );
218
- const block = cleanLines
219
- .slice(0, bottomBoundary + 1)
220
- .map((line, index) =>
221
- activeBlockLine(
222
- line,
223
- index === 0 || index === bottomBoundary,
224
- width,
225
- theme,
226
- ),
227
- );
228
- const suggestions = cleanLines
229
- .slice(bottomBoundary + 1)
230
- .map((line) => fitLine(line, width));
231
-
232
- return [...block, ...suggestions];
233
- } catch {
234
- return editor.render(width);
235
- }
236
- }
237
-
238
101
  function replaceBackground(text: string, backgroundAnsi: string): string {
239
102
  return text.replace(BACKGROUND_PATTERN, backgroundAnsi);
240
103
  }
@@ -261,9 +124,9 @@ export function renderSubmittedUserLines(
261
124
  // The rail glyph (▎) fills only the left quarter of its cell, so one
262
125
  // column of left padding already reads as a two-column visual gap.
263
126
  // Give the right edge two columns so both sides of the text read equal.
264
- const leftPadding = " ".repeat(ACTIVE_SIDE_PADDING);
265
- const rightPadding = " ".repeat(ACTIVE_SIDE_PADDING + 1);
266
- const innerWidth = Math.max(1, bodyWidth - ACTIVE_SIDE_PADDING * 2 - 1);
127
+ const leftPadding = " ".repeat(SUBMITTED_SIDE_PADDING);
128
+ const rightPadding = " ".repeat(SUBMITTED_SIDE_PADDING + 1);
129
+ const innerWidth = Math.max(1, bodyWidth - SUBMITTED_SIDE_PADDING * 2 - 1);
267
130
  const body = paintBackground(
268
131
  `${leftPadding}${fitLine(recolored, innerWidth)}${rightPadding}`,
269
132
  bodyWidth,