@xynogen/pix-pretty 2.1.0 → 3.0.0

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 CHANGED
@@ -135,7 +135,10 @@ The package exposes its sub-modules via `exports`:
135
135
  @xynogen/pix-pretty/renderers
136
136
  @xynogen/pix-pretty/fff
137
137
  @xynogen/pix-pretty/types
138
- @xynogen/pix-pretty/utils
138
+ @xynogen/pix-pretty/utils (viewport text, terminal width, paths, JSON preview)
139
+ @xynogen/pix-pretty/frame (result frames, rules, body rows)
140
+ @xynogen/pix-pretty/render-row (call rows, collapsed rows, dim previews)
141
+ @xynogen/pix-pretty/result (tool result builders and readers)
139
142
  @xynogen/pix-pretty/text (text fade helpers for previews and widgets)
140
143
  @xynogen/pix-pretty/widget-format
141
144
  @xynogen/pix-pretty/resize
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xynogen/pix-pretty",
3
- "version": "2.1.0",
3
+ "version": "3.0.0",
4
4
  "description": "Enhanced tool output rendering with syntax highlighting, file icons, tree views, diff rendering, and FFF search",
5
5
  "type": "module",
6
6
  "main": "src/index.ts",
@@ -24,6 +24,9 @@
24
24
  "./fff": "./src/fff.ts",
25
25
  "./types": "./src/types.ts",
26
26
  "./utils": "./src/utils.ts",
27
+ "./result": "./src/result.ts",
28
+ "./frame": "./src/frame.ts",
29
+ "./render-row": "./src/render-row.ts",
27
30
  "./text": "./src/text.ts",
28
31
  "./widget-format": "./src/widget-format.ts",
29
32
  "./resize": "./src/resize.ts",
@@ -73,7 +76,7 @@
73
76
  "access": "public"
74
77
  },
75
78
  "dependencies": {
76
- "@xynogen/pix-runtime": "^0.20.0",
79
+ "@xynogen/pix-runtime": "^0.22.0",
77
80
  "chalk": "^4.1.2",
78
81
  "cli-highlight": "^2.1.11",
79
82
  "@ff-labs/fff-node": "^0.10.6",
package/src/batch.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  /** Shared batching for read/grep/find/ls — N known targets, one tool result. */
2
2
 
3
+ import { isAbortError } from "@xynogen/pix-runtime/abort";
4
+ import { getErrorMessage } from "@xynogen/pix-runtime/errors";
3
5
  import { truncateStringToBytes } from "@xynogen/pix-runtime/utf8";
4
6
 
5
7
  export const BATCH_MAX_TARGETS = 20;
@@ -34,6 +36,30 @@ export function sliceBatchTargets(targets: string[]): { targets: string[]; omitt
34
36
  };
35
37
  }
36
38
 
39
+ export type BatchOutcome<R> = { target: string; result: R } | { target: string; error: string };
40
+
41
+ /**
42
+ * Run every target in parallel. One target's failure becomes its `error` (via `describe`), so
43
+ * the rest still report; an abort rethrows, so a cancelled batch stops as a whole.
44
+ */
45
+ export function runBatch<R>(
46
+ targets: string[],
47
+ run: (target: string, index: number) => Promise<R>,
48
+ signal: AbortSignal | undefined,
49
+ describe: (error: unknown, target: string) => string | Promise<string>,
50
+ ): Promise<BatchOutcome<R>[]> {
51
+ return Promise.all(
52
+ targets.map(async (target, index) => {
53
+ try {
54
+ return { target, result: await run(target, index) };
55
+ } catch (error) {
56
+ if (signal?.aborted) throw error;
57
+ return { target, error: await describe(error, target) };
58
+ }
59
+ }),
60
+ );
61
+ }
62
+
37
63
  /** Minimal JSON-schema object shape we touch when adding a batch field. */
38
64
  export interface SchemaObject {
39
65
  properties: Record<string, unknown>;
@@ -165,3 +191,58 @@ export function formatCallTargets(ids: string[], max = 3, noun = "files"): strin
165
191
  if (ids.length <= max) return ids.join(", ");
166
192
  return `${ids.length} ${noun}`;
167
193
  }
194
+
195
+ export interface BatchToolOptions<R> {
196
+ /** Targets already resolved from the singular and plural params. */
197
+ targets: string[];
198
+ signal: AbortSignal | undefined;
199
+ nouns: readonly [string, string];
200
+ maxUnits?: number;
201
+ /** `index` is undefined for a single target, so it keeps the caller's call id. */
202
+ run: (target: string, index?: number) => Promise<R>;
203
+ /** Result when one target fails outside a batch: keeps the single-call shape. */
204
+ singleError: (target: string, message: string) => R;
205
+ /** Body and unit count of one successful target. */
206
+ section: (result: R) => { body: string; units: number };
207
+ }
208
+
209
+ export interface BatchToolResult {
210
+ /** Capped model-facing text. */
211
+ text: string;
212
+ /** Uncapped index + every body, for the expanded view. */
213
+ full: string;
214
+ targets: string[];
215
+ /** Units summed over successful targets. */
216
+ units: number;
217
+ }
218
+
219
+ /**
220
+ * Run a multi-target tool call. One target returns its own result (`R`), so the single-call
221
+ * shape stays the same. Two or more run in parallel and return capped batch text.
222
+ */
223
+ export async function runBatchTool<R>(
224
+ opts: BatchToolOptions<R>,
225
+ ): Promise<{ single: R } | { batch: BatchToolResult }> {
226
+ const { targets, omitted } = sliceBatchTargets(opts.targets);
227
+ if (targets.length === 1 && omitted === 0) {
228
+ const target = targets[0] ?? "";
229
+ try {
230
+ return { single: await opts.run(target) };
231
+ } catch (error) {
232
+ if (isAbortError(error, opts.signal)) throw error;
233
+ return { single: opts.singleError(target, getErrorMessage(error)) };
234
+ }
235
+ }
236
+ const settled = await runBatch(targets, opts.run, opts.signal, getErrorMessage);
237
+ const sections: BatchSection[] = settled.map((entry) =>
238
+ "error" in entry
239
+ ? { id: entry.target, body: "", units: 0, nouns: opts.nouns, error: entry.error }
240
+ : { id: entry.target, nouns: opts.nouns, ...opts.section(entry.result) },
241
+ );
242
+ const { text } = capSections(sections, BATCH_MAX_BYTES, opts.maxUnits, omitted);
243
+ const full = [formatBatchIndex(sections, omitted), joinSectionBodies(sections)]
244
+ .filter(Boolean)
245
+ .join("\n\n");
246
+ const units = sections.reduce((sum, s) => sum + (s.error ? 0 : s.units), 0);
247
+ return { batch: { text, full, targets, units } };
248
+ }
@@ -1,8 +1,9 @@
1
1
  import { Text, truncateToWidth, visibleWidth, wrapTextWithAnsi } from "@earendil-works/pi-tui";
2
+ import { type ExpandHintCtx, expandHint } from "./frame.ts";
2
3
  import { hlBlock } from "./highlight.ts";
4
+ import type { renderRow } from "./render-row.ts";
3
5
  import { fadePaint, fadeRowsOf, fadeText } from "./text.ts";
4
6
  import type { ThemeLike } from "./types.ts";
5
- import { type ExpandHintCtx, expandHint, type renderRow } from "./utils.ts";
6
7
 
7
8
  export function commandPreview(
8
9
  header: string,
@@ -12,9 +12,10 @@ import * as Diff from "diff";
12
12
  import { BG_BASE, BOLD, FG_DIM, FG_GREEN, FG_LNUM, FG_RED, FG_RULE, RST } from "./ansi.ts";
13
13
  import { MAX_HL_CHARS, MAX_RENDER_LINES, WORD_DIFF_MIN_SIM } from "./config.ts";
14
14
  import type { DiffLine, ParsedDiff } from "./diff.ts";
15
+ import { BODY_PAD } from "./frame.ts";
15
16
  import { hlBlock } from "./highlight.ts";
16
17
  import type { BundledLanguage, FgTheme } from "./types.ts";
17
- import { BODY_PAD, termW as utilsTermW } from "./utils.ts";
18
+ import { terminalWidth } from "./utils.ts";
18
19
 
19
20
  // ---------------------------------------------------------------------------
20
21
  // Env-overridable color/threshold helpers (mirror pi-diff)
@@ -170,7 +171,7 @@ export function diffThemeCacheKey(theme?: DiffTheme): string {
170
171
  // ---------------------------------------------------------------------------
171
172
 
172
173
  function adaptiveWrapRows(tw?: number): number {
173
- const w = tw ?? termW();
174
+ const w = tw ?? diffWidth();
174
175
  if (w >= 180) return MAX_WRAP_ROWS_WIDE;
175
176
  if (w >= 120) return MAX_WRAP_ROWS_MED;
176
177
  return MAX_WRAP_ROWS_NARROW;
@@ -184,11 +185,11 @@ function tabs(s: string): string {
184
185
  return s.replace(/\t/g, " ");
185
186
  }
186
187
 
187
- function termW(): number {
188
- // Single source of truth: utils.termW caches, falls back to tty ioctl, and
188
+ function diffWidth(): number {
189
+ // Single source of truth: utils.terminalWidth caches, falls back to tty ioctl, and
189
190
  // invalidates on resize. Diff layout needs a hard floor of 80 cols for the
190
191
  // split-view column math (no ceiling — fill the true width on ultrawide).
191
- return Math.max(80, utilsTermW());
192
+ return Math.max(80, terminalWidth());
192
193
  }
193
194
 
194
195
  /** Pad/truncate `s` to exactly `w` visible chars. ANSI-aware. */
@@ -528,7 +529,7 @@ export async function renderUnified(
528
529
  if (!diff.lines.length) return "";
529
530
 
530
531
  const vis = diff.lines.slice(0, max);
531
- const tw = termW();
532
+ const tw = diffWidth();
532
533
  const nw = Math.max(2, String(Math.max(...vis.map((l) => l.oldNum ?? l.newNum ?? 0), 0)).length);
533
534
  const gw = nw + 5;
534
535
  const cw = Math.max(20, tw - gw);
@@ -683,7 +684,7 @@ export async function renderSplit(
683
684
  max = MAX_PREVIEW_LINES,
684
685
  dc: DiffColors = DEFAULT_DIFF_COLORS,
685
686
  ): Promise<string> {
686
- const tw = termW();
687
+ const tw = diffWidth();
687
688
  if (!shouldUseSplit(diff, tw, max)) return renderUnified(diff, language, max, dc);
688
689
  if (!diff.lines.length) return "";
689
690
 
package/src/fff.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { join } from "node:path";
2
- import type { GrepCursor, GrepMatch } from "@ff-labs/fff-node";
2
+ import type { GrepCursor } from "@ff-labs/fff-node";
3
3
  import { cacheDir } from "@xynogen/pix-runtime/paths";
4
4
 
5
5
  import type { FffBackedFinder, OptionalFffModule } from "./types.ts";
@@ -62,22 +62,9 @@ export function fffDestroy(): void {
62
62
  }
63
63
 
64
64
  // ---------------------------------------------------------------------------
65
- // FFF helpers (CursorStore, grep formatting)
65
+ // FFF helpers (CursorStore)
66
66
  // ---------------------------------------------------------------------------
67
67
 
68
- function sanitizeGrepRecordContent(text: string): string {
69
- let content = text;
70
- if (content.endsWith("\r\n")) content = content.slice(0, -2);
71
- else if (content.endsWith("\r") || content.endsWith("\n")) content = content.slice(0, -1);
72
-
73
- return content.replace(/\r\n/g, "\\n").replace(/\r/g, "\\r").replace(/\n/g, "\\n");
74
- }
75
-
76
- function truncateGrepRecordContent(text: string): string {
77
- const content = sanitizeGrepRecordContent(text);
78
- return content.length > 500 ? `${content.slice(0, 500)}...` : content;
79
- }
80
-
81
68
  /**
82
69
  * Store for FFF grep pagination cursors.
83
70
  * Evicts oldest entry when exceeding maxSize.
@@ -109,42 +96,3 @@ export class CursorStore {
109
96
  return this.cursors.size;
110
97
  }
111
98
  }
112
-
113
- /**
114
- * Convert FFF GrepResult items to ripgrep-style "file:line:content" text.
115
- */
116
- export function fffFormatGrepText(items: GrepMatch[], limit: number): string {
117
- const capped = items.slice(0, limit);
118
- if (!capped.length) return "No matches found";
119
-
120
- const lines: string[] = [];
121
- let currentFile = "";
122
-
123
- for (const match of capped) {
124
- if (match.relativePath !== currentFile) {
125
- if (currentFile) lines.push("");
126
- currentFile = match.relativePath;
127
- }
128
- if (match.contextBefore?.length) {
129
- const startLine = match.lineNumber - match.contextBefore.length;
130
- for (let i = 0; i < match.contextBefore.length; i++) {
131
- lines.push(
132
- `${match.relativePath}-${startLine + i}-${truncateGrepRecordContent(match.contextBefore[i] ?? "")}`,
133
- );
134
- }
135
- }
136
- lines.push(
137
- `${match.relativePath}:${match.lineNumber}:${truncateGrepRecordContent(match.lineContent)}`,
138
- );
139
- if (match.contextAfter?.length) {
140
- const startLine = match.lineNumber + 1;
141
- for (let i = 0; i < match.contextAfter.length; i++) {
142
- lines.push(
143
- `${match.relativePath}-${startLine + i}-${truncateGrepRecordContent(match.contextAfter[i] ?? "")}`,
144
- );
145
- }
146
- }
147
- }
148
-
149
- return lines.join("\n");
150
- }
package/src/frame.ts ADDED
@@ -0,0 +1,275 @@
1
+ import { type Color, type Component, mixColors, Text, visibleWidth } from "@earendil-works/pi-tui";
2
+ import { FG_RULE, hasAnsi, RST } from "./ansi.ts";
3
+ import { MAX_PREVIEW_LINES } from "./config.ts";
4
+ import { fadeRowsOf, pluralize } from "./text.ts";
5
+ import type { TextComponentCtor, TextComponentLike } from "./types.ts";
6
+ import { terminalWidth } from "./utils.ts";
7
+
8
+ type ResultComponent = {
9
+ render(width: number): string[];
10
+ invalidate(): void;
11
+ handleInput?(data: string): void;
12
+ wantsKeyRelease?: boolean;
13
+ };
14
+ type FramableComponent = Partial<ResultComponent> & Partial<TextComponentLike>;
15
+ type ResultFrameTheme = StatusRuleTheme;
16
+
17
+ const RESULT_FRAME = Symbol("pix.resultFrame");
18
+ type FramedResultComponent = ResultComponent & {
19
+ [RESULT_FRAME]: {
20
+ component: FramableComponent;
21
+ update(theme: ResultFrameTheme, isError: boolean, section: boolean): void;
22
+ };
23
+ };
24
+
25
+ /** Paints a rule line. Callers pass `(s) => theme.fg(status, s)` so the frame
26
+ * tint follows the active theme (success/error/warning). Default = neutral FG_RULE. */
27
+ export type RulePaint = (glyphs: string) => string;
28
+
29
+ /** Render a full-width solid rule. */
30
+ export function rule(w: number, paint?: RulePaint): string {
31
+ const glyphs = "─".repeat(w);
32
+ return paint ? paint(glyphs) : `${FG_RULE}${glyphs}${RST}`;
33
+ }
34
+
35
+ /** Theme slice for {@link fadeRulePaint}. Without `colors`/`style` the rule stays flat. */
36
+ export type StatusRuleTheme = {
37
+ fg: (key: "success" | "error", text: string) => string;
38
+ colors?: Readonly<Record<string, Color | undefined>>;
39
+ style?: (text: string, style: { fg: Color }) => string;
40
+ };
41
+
42
+ /**
43
+ * Status-colored rule paint that fades in on the left and out on the right: the last
44
+ * `fadeColumns` cells at each end mix toward the tool background. Themes without color
45
+ * data get the plain `theme.fg(role, …)` rule.
46
+ */
47
+ export function fadeRulePaint(
48
+ theme: StatusRuleTheme,
49
+ role: "success" | "error",
50
+ fadeColumns = 8,
51
+ ): RulePaint {
52
+ return (glyphs) => {
53
+ const cells = [...glyphs];
54
+ const edge = Math.min(fadeColumns, Math.floor(cells.length / 2));
55
+ const fg = theme.colors?.[role];
56
+ const bg = theme.colors?.[role === "error" ? "toolErrorBg" : "toolSuccessBg"];
57
+ if (!fg || !bg || !theme.style || edge < 1) return theme.fg(role, glyphs);
58
+ // Cell i from the edge (0 = outermost) is faintest at the edge, full color past `edge`.
59
+ // Call as a method: Pi's Theme.style reads `this`.
60
+ const cell = (ch: string, i: number) =>
61
+ theme.style?.(ch, { fg: mixColors(fg, bg, 1 - (i + 1) / (edge + 1)) }) ?? ch;
62
+ const left = cells.slice(0, edge).map(cell).join("");
63
+ const right = cells
64
+ .slice(-edge)
65
+ .map((ch, i) => cell(ch, edge - 1 - i))
66
+ .join("");
67
+ return left + theme.fg(role, cells.slice(edge, -edge).join("")) + right;
68
+ };
69
+ }
70
+
71
+ /** Narrow theme for helpers that paint only `muted`. Pi's Theme and FgTheme both fit. */
72
+ type MutedTheme = { fg: (key: "muted", text: string) => string };
73
+
74
+ /** Matches an `=== label ===` separator line (a common shell/echo idiom). */
75
+ const SECTION_RE = /^\s*={2,}\s*(.+?)\s*={2,}\s*$/;
76
+
77
+ /** Fixed dash count before a left-aligned section label. */
78
+ const SECTION_RULE_LEAD = 4;
79
+
80
+ /**
81
+ * If `line` is an `=== label ===` separator, render it as a left-aligned
82
+ * section divider (`──── label ───────────`); otherwise return null. Callers
83
+ * fall back to their normal per-line rendering on null. Fills the full `width`
84
+ * so the divider aligns with the surrounding tool frame. Label and rule both
85
+ * use the muted role — theme-driven, ANSI-safe.
86
+ */
87
+ export function sectionRule(line: string, theme: MutedTheme, width: number): string | null {
88
+ const m = SECTION_RE.exec(line);
89
+ if (!m || hasAnsi(line)) return null;
90
+ const label = ` ${m[1]} `;
91
+ const trail = width - SECTION_RULE_LEAD - visibleWidth(label);
92
+ // Label fits → lead rule + trailing fill. Too long to fill → don't force a
93
+ // full-width rule; wrap it snugly with 2 dashes each side (`── long text ──`).
94
+ const [lead, tail] = trail >= 2 ? [SECTION_RULE_LEAD, trail] : [2, 2];
95
+ return theme.fg("muted", `${"─".repeat(lead)}${label}${"─".repeat(tail)}`);
96
+ }
97
+
98
+ /**
99
+ * Body indent: one tab. pi-tui renders `\t` as 3 cells, the title column after
100
+ * the 2-cell status icon + space.
101
+ */
102
+ export const BODY_PAD = "\t";
103
+
104
+ /**
105
+ * One tool-result body line, aligned under the tool title. An `=== label ===` line
106
+ * becomes a full-width section rule. Other lines go through `paint`.
107
+ */
108
+ export function bodyLine(
109
+ line: string,
110
+ theme: MutedTheme,
111
+ paint: (line: string) => string = (s) => s,
112
+ ): string {
113
+ // ponytail: 3 = pi-tui tab width. Use visibleWidth if BODY_PAD stops being one tab.
114
+ return `${BODY_PAD}${sectionRule(line, theme, terminalWidth() - 3) ?? paint(line)}`;
115
+ }
116
+
117
+ /** Renderer context slice that knows the user's expand key (Pi's `ToolRenderContext`). */
118
+ export type ExpandHintCtx = {
119
+ keyHint?: (keybinding: "app.tools.expand", description: string) => string;
120
+ /** Expanded view: renderers that take this context show every row, no hint. */
121
+ expanded?: boolean;
122
+ };
123
+
124
+ /**
125
+ * `(ctrl+o to expand)` with the user's configured key, styled like Pi's own hint.
126
+ * Without a host `keyHint` (tests, old hosts), the key falls back to `ctrl+o`.
127
+ */
128
+ export function expandHint(theme: MutedTheme, ctx?: ExpandHintCtx): string {
129
+ const hint =
130
+ ctx?.keyHint?.("app.tools.expand", "to expand") ?? theme.fg("muted", "ctrl+o to expand");
131
+ return `${theme.fg("muted", "(")}${hint}${theme.fg("muted", ")")}`;
132
+ }
133
+
134
+ /**
135
+ * Muted `… N more lines (ctrl+o to expand)` footer for a truncated tool-result body.
136
+ * Pass the renderer context so the hint shows the user's own expand key.
137
+ */
138
+ export function moreLines(count: number, theme: MutedTheme, ctx?: ExpandHintCtx): string {
139
+ return `${BODY_PAD}${theme.fg("muted", `… ${pluralize(count, "more line")} `)}${expandHint(theme, ctx)}`;
140
+ }
141
+
142
+ /** Decorate completed tool output with status-colored default chrome. */
143
+ export function frameToolResult<T extends FramableComponent & { setText(value: string): void }>(
144
+ component: T,
145
+ theme: ResultFrameTheme,
146
+ isError: boolean,
147
+ ): ResultComponent & { setText(value: string): void; getText?: () => string };
148
+ export function frameToolResult(
149
+ component: FramableComponent,
150
+ theme: ResultFrameTheme,
151
+ isError: boolean,
152
+ ): ResultComponent;
153
+ export function frameToolResult(
154
+ component: FramableComponent,
155
+ theme: ResultFrameTheme,
156
+ isError: boolean,
157
+ ): ResultComponent {
158
+ return decorateToolResult(component, theme, isError, false);
159
+ }
160
+
161
+ /** Decorate explicit expanded/detail sections with solid top and bottom rules. */
162
+ export function frameToolSection(
163
+ component: FramableComponent,
164
+ theme: ResultFrameTheme,
165
+ isError: boolean,
166
+ ): ResultComponent {
167
+ return decorateToolResult(component, theme, isError, true);
168
+ }
169
+
170
+ function decorateToolResult(
171
+ component: FramableComponent,
172
+ theme: ResultFrameTheme,
173
+ isError: boolean,
174
+ section: boolean,
175
+ ): ResultComponent & Partial<TextComponentLike> {
176
+ const existing = component as Partial<FramedResultComponent>;
177
+ if (existing[RESULT_FRAME]) {
178
+ existing[RESULT_FRAME].update(theme, isError, section);
179
+ return component as ResultComponent;
180
+ }
181
+ let frameTheme = theme;
182
+ let failed = isError;
183
+ let solid = section;
184
+ const framed: FramedResultComponent & Partial<TextComponentLike> = {
185
+ [RESULT_FRAME]: {
186
+ component,
187
+ update(nextTheme, nextError, nextSection) {
188
+ frameTheme = nextTheme;
189
+ failed = nextError;
190
+ solid = nextSection;
191
+ },
192
+ },
193
+ wantsKeyRelease: component.wantsKeyRelease,
194
+ render(width) {
195
+ const paint = fadeRulePaint(frameTheme, failed ? "error" : "success");
196
+ const lines = component.render?.(width) ?? [];
197
+ return solid ? sectionFrame(lines, [], width, paint) : ruleFrame(lines, [], width, paint);
198
+ },
199
+ invalidate() {
200
+ component.invalidate?.();
201
+ },
202
+ handleInput: component.handleInput ? (data) => component.handleInput?.(data) : undefined,
203
+ };
204
+ if (component.setText) framed.setText = (value) => component.setText?.(value);
205
+ if (component.getText) framed.getText = () => component.getText?.() ?? "";
206
+ return framed;
207
+ }
208
+
209
+ /** Remove the result frame while preserving its underlying renderer component. */
210
+ export function unframeToolResult<T extends FramableComponent>(component: T): T {
211
+ const framed = component as Partial<FramedResultComponent>;
212
+ return (framed[RESULT_FRAME]?.component ?? component) as T;
213
+ }
214
+
215
+ function isTextComponent(component: Component): component is TextComponentLike {
216
+ return typeof (component as Partial<TextComponentLike>).setText === "function";
217
+ }
218
+
219
+ /** The prior render's text component (unframed) when it has one, else a fresh one. */
220
+ export function reuseText(
221
+ last: Component | undefined,
222
+ TextComponent: TextComponentCtor = Text,
223
+ ): TextComponentLike {
224
+ const prior = last && unframeToolResult(last);
225
+ return prior && isTextComponent(prior) ? prior : new TextComponent("", 0, 0);
226
+ }
227
+
228
+ /**
229
+ * Default completed-tool chrome: unchanged body, full-width solid close, then
230
+ * footer lines. Existing callers inherit this distro-wide presentation.
231
+ */
232
+ export function ruleFrame(
233
+ bodyLines: string[],
234
+ footerLines: string[] = [],
235
+ width?: number,
236
+ paint?: RulePaint,
237
+ ): string[] {
238
+ return [...bodyLines, rule(width ?? terminalWidth(), paint), ...footerLines];
239
+ }
240
+
241
+ /**
242
+ * Command-output body: the first MAX_PREVIEW_LINES rows (all when expanded) with a
243
+ * fading tail and an "… N more" footer. Completed output closes with a status rule;
244
+ * partial output stays unframed. Returns the rows; the caller fills the background.
245
+ */
246
+ export function outputBodyRows(
247
+ lines: string[],
248
+ theme: StatusRuleTheme & MutedTheme & Parameters<typeof fadeRowsOf>[1],
249
+ ctx: ExpandHintCtx,
250
+ status: "success" | "error",
251
+ partial: boolean,
252
+ ): string[] {
253
+ const maxShow = ctx.expanded ? lines.length : MAX_PREVIEW_LINES;
254
+ const footer = lines.length > maxShow ? [moreLines(lines.length - maxShow, theme, ctx)] : [];
255
+ // Fade the last preview rows instead of a hard cut before the "… N more" row.
256
+ const body = fadeRowsOf(
257
+ lines.slice(0, maxShow + 1).map((line) => bodyLine(line, theme)),
258
+ theme,
259
+ maxShow,
260
+ );
261
+ return partial
262
+ ? [...body, ...footer]
263
+ : ruleFrame(body, footer, terminalWidth(), fadeRulePaint(theme, status));
264
+ }
265
+
266
+ /** Explicit solid top/bottom frame for sections that need stronger separation. */
267
+ export function sectionFrame(
268
+ bodyLines: string[],
269
+ footerLines: string[] = [],
270
+ width?: number,
271
+ paint?: RulePaint,
272
+ ): string[] {
273
+ const r = rule(width ?? terminalWidth(), paint);
274
+ return [r, ...bodyLines, r, ...footerLines];
275
+ }
@@ -17,6 +17,7 @@ import {
17
17
  truncateToWidth,
18
18
  visibleWidth,
19
19
  } from "@earendil-works/pi-tui";
20
+ import { getErrorMessage } from "@xynogen/pix-runtime/errors";
20
21
  import {
21
22
  frameModal,
22
23
  MIN_MODAL_HEIGHT,
@@ -25,7 +26,6 @@ import {
25
26
  modalWidth,
26
27
  terminalModalHeight,
27
28
  } from "./modal-frame.ts";
28
- import { getErrorMessage } from "./utils.ts";
29
29
 
30
30
  export interface ProviderPickerRow {
31
31
  id: string;