pi-path-bar 0.4.1 → 0.5.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/src/minimal.ts ADDED
@@ -0,0 +1,533 @@
1
+ import { CustomEditor, type KeybindingsManager, type Theme } from "@earendil-works/pi-coding-agent";
2
+ import { sliceByColumn, truncateToWidth, visibleWidth, type EditorTheme, type TUI } from "@earendil-works/pi-tui";
3
+ import type { Config } from "./config.ts";
4
+ import { gitColor, type GitState } from "./git.ts";
5
+ import { formatPath, type PathOptions } from "./path.ts";
6
+ import { CLOCK, resolveOrder, type SlotEntry } from "./segments.ts";
7
+
8
+ export interface UsageTotals {
9
+ input: number;
10
+ output: number;
11
+ cacheRead: number;
12
+ cacheWrite: number;
13
+ cost: number;
14
+ }
15
+
16
+ export interface WorkingIndicatorLike {
17
+ readonly kind: string;
18
+ renderInBorder(width: number): string;
19
+ renderSpinnerInBorder(width: number): string;
20
+ }
21
+
22
+ export interface MinimalBorderTheme {
23
+ fg: Theme["fg"];
24
+ }
25
+
26
+ export interface MinimalTopInput {
27
+ indicator?: WorkingIndicatorLike;
28
+ totals: UsageTotals;
29
+ hitRate?: number;
30
+ subscription: boolean;
31
+ sessionName?: string;
32
+ showSession: boolean;
33
+ timeFormat: Config["timeFormat"];
34
+ now: Date;
35
+ slots: ReadonlyMap<string, SlotEntry>;
36
+ order: string[];
37
+ hidden: ReadonlySet<string>;
38
+ theme: MinimalBorderTheme;
39
+ borderColor: (text: string) => string;
40
+ }
41
+
42
+ export interface MinimalBottomInput {
43
+ displayPath: string;
44
+ aliasName?: string;
45
+ pathMode: Exclude<Config["mode"], "native">;
46
+ showIcon: boolean;
47
+ showBranch: boolean;
48
+ gitState: GitState;
49
+ fallbackBranch?: string;
50
+ modelId?: string;
51
+ reasoning?: boolean;
52
+ thinkingLevel?: string;
53
+ contextPercent?: number | null;
54
+ contextWindow: number;
55
+ theme: MinimalBorderTheme;
56
+ borderColor: (text: string) => string;
57
+ }
58
+
59
+ const clean = (value: string) => value.replace(/[\x00-\x1f\x7f-\x9f]/g, "");
60
+ const hasAnsi = (value: string) => value.includes("\x1b");
61
+ const resetIf = (value: string) => (hasAnsi(value) ? "\x1b[0m" : "");
62
+
63
+ export function compactTokens(n: number): string {
64
+ if (n < 1000) return String(Math.max(0, Math.round(n)));
65
+ if (n < 999_500) return `${Math.round(n / 1000)}k`;
66
+ return `${(n / 1e6).toFixed(1).replace(/\.0$/, "")}M`;
67
+ }
68
+
69
+ export function formatCostMinimal(cost: number, subscription: boolean): string {
70
+ if (cost <= 0) return subscription ? "sub" : "";
71
+ let text: string;
72
+ if (cost < 0.0005) text = "<$.001";
73
+ else if (cost < 0.01) text = `$.${Math.round(cost * 1000).toString().padStart(3, "0")}`;
74
+ else if (cost < 100) text = `$${cost.toFixed(2)}`;
75
+ else text = `$${Math.round(cost)}`;
76
+ return subscription ? `${text}ˢ` : text;
77
+ }
78
+
79
+ export function formatTimeMinimal(date: Date, timeFormat: "24h" | "12h"): string {
80
+ const hours = date.getHours();
81
+ const minutes = String(date.getMinutes()).padStart(2, "0");
82
+ if (timeFormat === "24h") return `${String(hours).padStart(2, "0")}:${minutes}`;
83
+ const suffix = hours >= 12 ? "p" : "a";
84
+ const h12 = hours % 12 || 12;
85
+ return `${h12}:${minutes}${suffix}`;
86
+ }
87
+
88
+ export function shortModelName(id: string | undefined, compact = false): string {
89
+ if (!id) return compact ? "?" : "no-model";
90
+ const stripped = clean(id)
91
+ .replace(/-\d{4}-\d{2}-\d{2}$/, "")
92
+ .replace(/-\d{8}$/, "")
93
+ .replace(/-\d{4}$/, "")
94
+ .replace(/-(?:latest|preview|instruct|chat)$/i, "");
95
+
96
+ let match = /^claude-(sonnet|opus|haiku)-(\d+)[.-](\d+)$/i.exec(stripped);
97
+ if (match) {
98
+ const family = match[1].toLowerCase();
99
+ return compact ? `${family[0]}${match[2]}.${match[3]}` : `${family}-${match[2]}.${match[3]}`;
100
+ }
101
+ match = /^claude-(\d+)[.-](\d+)-(sonnet|opus|haiku)$/i.exec(stripped);
102
+ if (match) {
103
+ const family = match[3].toLowerCase();
104
+ return compact ? `${family[0]}${match[1]}.${match[2]}` : `${family}-${match[1]}.${match[2]}`;
105
+ }
106
+ match = /^claude-(sonnet|opus|haiku)-(\d+)$/i.exec(stripped);
107
+ if (match) {
108
+ const family = match[1].toLowerCase();
109
+ return compact ? `${family[0]}${match[2]}` : `${family}-${match[2]}`;
110
+ }
111
+ match = /^gemini-([\d.]+)-(flash-lite|pro|flash|ultra)(?:-[a-z0-9.]+)?$/i.exec(stripped);
112
+ if (match) {
113
+ const tierMap: Record<string, string> = { "flash-lite": "fl", pro: "p", flash: "f", ultra: "u" };
114
+ const tier = tierMap[match[2].toLowerCase()] ?? match[2][0].toLowerCase();
115
+ return compact ? `g${match[1]}${tier}` : `gem-${match[1]}${tier}`;
116
+ }
117
+ match = /^gpt-([\d.]+)(?:-(codex|mini|nano|turbo))?$/i.exec(stripped);
118
+ if (match) {
119
+ const tierMap: Record<string, string> = { codex: "c", mini: "m", nano: "n", turbo: "t" };
120
+ const tier = match[2] ? tierMap[match[2].toLowerCase()] ?? "" : "";
121
+ return compact ? `g${match[1]}${tier}` : `gpt-${match[1]}${tier}`;
122
+ }
123
+ if (/^deepseek-reasoner$/i.test(stripped)) return "ds-r1";
124
+ if (/^deepseek-chat$/i.test(stripped)) return compact ? "ds-c" : "ds-chat";
125
+ match = /^deepseek-(.+)$/i.exec(stripped);
126
+ if (match) return compact ? truncateToWidth(`ds-${match[1]}`, 8, "…") : `ds-${match[1]}`;
127
+
128
+ return compact ? truncateToWidth(stripped, 8, "…") : stripped;
129
+ }
130
+
131
+ export function shortThinking(level: string | undefined): string {
132
+ if (!level || level === "off") return "";
133
+ const map: Record<string, string> = { minimal: "·m", low: "·L", medium: "·M", high: "·H", xhigh: "·X" };
134
+ return map[level] ?? `·${level[0].toUpperCase()}`;
135
+ }
136
+
137
+ export function formatContextMinimal(
138
+ percent: number | null | undefined,
139
+ contextWindow: number,
140
+ includeWindow: boolean,
141
+ theme: MinimalBorderTheme,
142
+ ): string {
143
+ const glyph = percent == null || percent <= 0 ? "○"
144
+ : percent <= 33 ? "◔"
145
+ : percent <= 66 ? "◐"
146
+ : percent < 90 ? "◕"
147
+ : "●";
148
+ const pct = percent == null ? "?" : `${Math.round(percent)}%`;
149
+ const win = includeWindow && contextWindow > 0 ? `/${compactTokens(contextWindow)}` : "";
150
+ const text = `${glyph}${pct}${win}`;
151
+ if (percent != null && percent > 90) return theme.fg("error", text);
152
+ if (percent != null && percent > 70) return theme.fg("warning", text);
153
+ return theme.fg("dim", text);
154
+ }
155
+
156
+ function shortGitOperation(operation: string): string {
157
+ const rebase = /^(?:rebase-[im]|rebase)(?:\s+(\d+\/\d+))?$/.exec(operation);
158
+ if (rebase) return rebase[1] ? `R${rebase[1]}` : "R";
159
+ if (operation.startsWith("am/rebase")) return "AR";
160
+ if (operation.startsWith("am")) return "AM";
161
+ if (operation === "merge") return "M";
162
+ if (operation === "cherry-pick") return "CP";
163
+ if (operation === "revert") return "RV";
164
+ if (operation === "bisect") return "BS";
165
+ return clean(operation);
166
+ }
167
+
168
+ export function formatGitMinimal(
169
+ state: GitState,
170
+ fallbackBranch: string | undefined,
171
+ detail: "full" | "symbols" | "branch",
172
+ ): string {
173
+ if (state.kind === "none") return "";
174
+ if (state.kind === "unknown") return fallbackBranch ? `${clean(fallbackBranch)}?` : "?";
175
+ const parts = [`${clean(state.head)}`];
176
+ if (state.operation) parts.push(shortGitOperation(state.operation));
177
+ if (detail !== "branch") {
178
+ let counts = "";
179
+ for (const [key, symbol] of [["behind", "⇣"], ["ahead", "⇡"], ["stash", "*"], ["conflicted", "~"], ["staged", "+"], ["dirty", "!"], ["untracked", "?"]] as const) {
180
+ if (state[key]) counts += detail === "full" ? `${symbol}${state[key]}` : symbol;
181
+ }
182
+ if (counts) parts.push(counts);
183
+ }
184
+ return parts.join(" ");
185
+ }
186
+
187
+ /**
188
+ * Pack right-side slots left-to-right; when overflowing, drop from the right and append `+N`.
189
+ */
190
+ export function packRightSlots(
191
+ items: ReadonlyArray<{ id: string; text: string }>,
192
+ maxWidth: number,
193
+ dim: (text: string) => string,
194
+ ): string {
195
+ if (maxWidth <= 0 || items.length === 0) return "";
196
+ const sep = dim(" ");
197
+ const join = (list: string[]) => list.join(sep);
198
+ const texts = items.map((item) => item.text);
199
+ const full = join(texts);
200
+ if (visibleWidth(full) <= maxWidth) return full;
201
+
202
+ for (let keep = texts.length - 1; keep >= 0; keep--) {
203
+ const dropped = texts.length - keep;
204
+ const badge = dim(`+${dropped}`);
205
+ const candidate = keep > 0 ? join([...texts.slice(0, keep), badge]) : badge;
206
+ if (visibleWidth(candidate) <= maxWidth) return candidate;
207
+ }
208
+ return "";
209
+ }
210
+
211
+ /**
212
+ * Overlay centered scroll indicator (` ↑ N more ` / ` ↓ N more `) onto a full-width border line.
213
+ */
214
+ export function overlayScrollLabel(
215
+ line: string,
216
+ width: number,
217
+ direction: "↑" | "↓",
218
+ hiddenLineCount: number,
219
+ borderColor: (text: string) => string,
220
+ ): string {
221
+ if (hiddenLineCount <= 0 || width <= 0) return line;
222
+ const label = ` ${direction} ${hiddenLineCount} more `;
223
+ const labelW = visibleWidth(label);
224
+ if (labelW + 2 > width) {
225
+ const fallback = `─── ${direction} ${hiddenLineCount} more `;
226
+ const remain = width - visibleWidth(fallback);
227
+ if (remain >= 0) return borderColor(fallback + "─".repeat(remain));
228
+ const ellipsis = "…".slice(0, width);
229
+ const keep = Math.max(0, width - visibleWidth(ellipsis));
230
+ return borderColor(sliceByColumn(fallback, 0, keep, true) + ellipsis);
231
+ }
232
+ const start = Math.floor((width - labelW) / 2);
233
+ const rightStart = start + labelW;
234
+ const rightTarget = width - rightStart;
235
+
236
+ const leftSlice = sliceByColumn(line, 0, start, true);
237
+ const leftPad = Math.max(0, start - visibleWidth(leftSlice));
238
+ const rightSlice = sliceByColumn(line, rightStart, rightTarget, true);
239
+ const rightPad = Math.max(0, rightTarget - visibleWidth(rightSlice));
240
+
241
+ return (
242
+ leftSlice +
243
+ resetIf(leftSlice) +
244
+ (leftPad > 0 ? borderColor("─".repeat(leftPad)) : "") +
245
+ borderColor(label) +
246
+ (rightPad > 0 ? borderColor("─".repeat(rightPad)) : "") +
247
+ rightSlice +
248
+ resetIf(rightSlice)
249
+ );
250
+ }
251
+
252
+ function fillBetween(
253
+ width: number,
254
+ left: string,
255
+ right: string,
256
+ borderColor: (text: string) => string,
257
+ ): string {
258
+ const leftW = visibleWidth(left);
259
+ const rightW = visibleWidth(right);
260
+ const gap = Math.max(0, width - leftW - rightW);
261
+ return `${left}${gap > 0 ? borderColor("─".repeat(gap)) : ""}${right}`;
262
+ }
263
+
264
+ export function renderMinimalTopBorder(input: MinimalTopInput, width: number, hiddenLineCount: number): string {
265
+ if (width <= 0) return "";
266
+ const { borderColor, theme, indicator } = input;
267
+ if (width <= 3) return borderColor("─".repeat(width));
268
+
269
+ const dim = (text: string) => theme.fg("dim", text);
270
+ const timeText = dim(formatTimeMinimal(input.now, input.timeFormat));
271
+ const rightItems = resolveOrder(input.order, input.slots.keys()).flatMap((id) => {
272
+ if (input.hidden.has(id)) return [];
273
+ const text = id === CLOCK ? timeText : input.slots.get(id)?.text ?? "";
274
+ return text ? [{ id, text }] : [];
275
+ });
276
+
277
+ const makeRightBlock = (maxSlotsWidth: number) => {
278
+ const packed = packRightSlots(rightItems, maxSlotsWidth, dim);
279
+ return packed ? `${borderColor(" ")}${packed}${borderColor(" ──")}` : "";
280
+ };
281
+
282
+ let line: string;
283
+
284
+ // Rare non-working indicators (retry / compaction / branchSummary) take over the L zone.
285
+ if (indicator && indicator.kind !== "working") {
286
+ const fullStatus = indicator.renderInBorder(Math.max(1, width - 5));
287
+ const statusW = visibleWidth(fullStatus);
288
+ if (statusW > 0 && statusW + 5 <= width) {
289
+ const leftBlock = `${borderColor("── ")}${fullStatus}${borderColor(" ")}`;
290
+ const leftW = 4 + statusW;
291
+ // Leave at least 2 fill chars + right wrapper (" " + " ──" = 4 cols) when right slots exist.
292
+ const maxRightSlots = width - leftW - 2 - 4;
293
+ const rightBlock = maxRightSlots > 0 ? makeRightBlock(maxRightSlots) : "";
294
+ line = fillBetween(width, leftBlock, rightBlock, borderColor);
295
+ } else {
296
+ const spinner = indicator.renderSpinnerInBorder(Math.max(1, width - 4));
297
+ const spinnerW = visibleWidth(spinner);
298
+ if (spinnerW > 0 && spinnerW + 4 <= width) {
299
+ const leftBlock = `${borderColor("── ")}${spinner}${borderColor(" ")}`;
300
+ const maxRightSlots = width - (4 + spinnerW) - 2 - 4;
301
+ const rightBlock = maxRightSlots > 0 ? makeRightBlock(maxRightSlots) : "";
302
+ line = fillBetween(width, leftBlock, rightBlock, borderColor);
303
+ } else {
304
+ line = borderColor("─".repeat(width));
305
+ }
306
+ }
307
+ return overlayScrollLabel(line, width, "↑", hiddenLineCount, borderColor);
308
+ }
309
+
310
+ // Scheme B: fixed 5-column W slot when working (degraded spinner) or idle with left telemetry.
311
+ const isWorking = indicator?.kind === "working";
312
+ const spinner = isWorking ? indicator.renderSpinnerInBorder(Math.max(1, width - 4)) : "";
313
+ const spinnerW = visibleWidth(spinner);
314
+ const workingPrefix = isWorking && spinnerW > 0 && spinnerW + 5 <= width
315
+ ? `${borderColor("── ")}${spinner}${borderColor(" ")}`
316
+ : "";
317
+
318
+ const tokenParts: string[] = [];
319
+ if (input.totals.input) tokenParts.push(`↑${compactTokens(input.totals.input)}`);
320
+ if (input.totals.output) tokenParts.push(`↓${compactTokens(input.totals.output)}`);
321
+ const tokensText = tokenParts.length ? dim(tokenParts.join(" ")) : "";
322
+ const cacheText = (input.totals.cacheRead || input.totals.cacheWrite) && input.hitRate !== undefined
323
+ ? dim(`c${Math.round(input.hitRate)}%`)
324
+ : "";
325
+ const costRaw = formatCostMinimal(input.totals.cost, input.subscription);
326
+ const costText = costRaw ? dim(costRaw) : "";
327
+ const sessionClean = input.showSession && input.sessionName ? clean(input.sessionName).trim() : "";
328
+ const sessionText = sessionClean ? dim(`·${truncateToWidth(sessionClean, 12, "…")}`) : "";
329
+
330
+ const telemetryTiers = [
331
+ [tokensText, cacheText, costText, sessionText],
332
+ [tokensText, cacheText, costText],
333
+ [tokensText, costText],
334
+ [costText],
335
+ [],
336
+ ].map((parts) => parts.filter(Boolean).join(dim(" ")));
337
+
338
+ const buildLeftBlock = (telemetry: string): string => {
339
+ if (workingPrefix) {
340
+ return telemetry ? `${workingPrefix}${telemetry}${borderColor(" ")}` : workingPrefix;
341
+ }
342
+ if (!telemetry) return "";
343
+ // Idle with left content uses `──── ` (5 cols) to align identically with `── ⠋ `.
344
+ return `${borderColor("──── ")}${telemetry}${borderColor(" ")}`;
345
+ };
346
+
347
+ const fullRightBlock = makeRightBlock(width);
348
+ const fullRightW = visibleWidth(fullRightBlock);
349
+ const minGap = 2;
350
+
351
+ let chosenLeft = "";
352
+ let chosenRight = "";
353
+
354
+ // First try keeping all right slots intact while progressively trimming left telemetry.
355
+ let matched = false;
356
+ for (const telemetry of telemetryTiers) {
357
+ const leftBlock = buildLeftBlock(telemetry);
358
+ if (visibleWidth(leftBlock) + minGap + fullRightW <= width) {
359
+ chosenLeft = leftBlock;
360
+ chosenRight = fullRightBlock;
361
+ matched = true;
362
+ break;
363
+ }
364
+ }
365
+
366
+ // If even empty left telemetry cannot fit full right slots, fold right slots with `+N`.
367
+ if (!matched) {
368
+ const baseLeft = buildLeftBlock("");
369
+ const baseLeftW = visibleWidth(baseLeft);
370
+ const maxRightSlots = width - baseLeftW - minGap - 4;
371
+ chosenLeft = baseLeft;
372
+ chosenRight = maxRightSlots > 0 ? makeRightBlock(maxRightSlots) : "";
373
+ // If after folding right slots there is still room for cost or tokens, re-add highest-priority telemetry.
374
+ const rightW = visibleWidth(chosenRight);
375
+ for (const telemetry of telemetryTiers) {
376
+ if (!telemetry) break;
377
+ const candidate = buildLeftBlock(telemetry);
378
+ if (visibleWidth(candidate) + minGap + rightW <= width) {
379
+ chosenLeft = candidate;
380
+ break;
381
+ }
382
+ }
383
+ }
384
+
385
+ line = fillBetween(width, chosenLeft, chosenRight, borderColor);
386
+ return overlayScrollLabel(line, width, "↑", hiddenLineCount, borderColor);
387
+ }
388
+
389
+ export function renderMinimalBottomBorder(input: MinimalBottomInput, width: number, hiddenLineCount: number): string {
390
+ if (width <= 0) return "";
391
+ const { borderColor, theme } = input;
392
+ if (width <= 5) return borderColor("─".repeat(width));
393
+
394
+ const dim = (text: string) => theme.fg("dim", text);
395
+ const thinking = input.reasoning ? shortThinking(input.thinkingLevel) : "";
396
+ const thinkingStyled = thinking ? borderColor(thinking) : "";
397
+
398
+ const makeRight = (compactModel: boolean, includeThinking: boolean, includeWindow: boolean): string => {
399
+ const model = dim(shortModelName(input.modelId, compactModel));
400
+ const ctx = formatContextMinimal(input.contextPercent, input.contextWindow, includeWindow, theme);
401
+ const modelPart = includeThinking && thinkingStyled ? `${model}${thinkingStyled}` : model;
402
+ return `${modelPart}${dim(" ")}${ctx}`;
403
+ };
404
+
405
+ const pathStyle: PathOptions["style"] = {
406
+ normal: (text) => theme.fg("dim", text),
407
+ alias: (text) => theme.fg("mdLink", text),
408
+ };
409
+
410
+ const leafName = clean(input.displayPath).split("/").filter(Boolean).pop() ?? clean(input.displayPath);
411
+ const minPathWidth = Math.min(Math.max(4, visibleWidth(leafName)), 12);
412
+ const minGap = 2;
413
+
414
+ const tiers: Array<{
415
+ pathMode: Exclude<Config["mode"], "native">;
416
+ gitDetail: "full" | "symbols" | "branch" | "none";
417
+ compactModel: boolean;
418
+ includeThinking: boolean;
419
+ includeWindow: boolean;
420
+ }> = [
421
+ { pathMode: input.pathMode, gitDetail: "full", compactModel: false, includeThinking: true, includeWindow: true },
422
+ { pathMode: "short", gitDetail: "symbols", compactModel: false, includeThinking: true, includeWindow: true },
423
+ { pathMode: "short", gitDetail: "symbols", compactModel: true, includeThinking: true, includeWindow: false },
424
+ { pathMode: "short", gitDetail: "branch", compactModel: true, includeThinking: true, includeWindow: false },
425
+ { pathMode: "short", gitDetail: "branch", compactModel: true, includeThinking: false, includeWindow: false },
426
+ { pathMode: "short", gitDetail: "none", compactModel: true, includeThinking: false, includeWindow: false },
427
+ ];
428
+
429
+ let leftBlock = "";
430
+ let rightBlock = "";
431
+
432
+ for (const tier of tiers) {
433
+ const rightContent = makeRight(tier.compactModel, tier.includeThinking, tier.includeWindow);
434
+ const rightCandidate = `${borderColor(" ")}${rightContent}${borderColor(" ──")}`;
435
+ const rightW = visibleWidth(rightCandidate);
436
+ const leftBudget = width - rightW - minGap - 4; // 4 cols = "── " (3) + trailing " " (1)
437
+
438
+ const gitRaw = input.showBranch && tier.gitDetail !== "none"
439
+ ? formatGitMinimal(input.gitState, input.fallbackBranch, tier.gitDetail)
440
+ : "";
441
+ const gitStyled = gitRaw ? theme.fg(gitColor(input.gitState), gitRaw) : "";
442
+ const gitW = visibleWidth(gitStyled);
443
+
444
+ if (leftBudget >= minPathWidth + (gitW ? gitW + 1 : 0)) {
445
+ const pathBudget = leftBudget - (gitW ? gitW + 1 : 0);
446
+ const pathStyled = formatPath(input.displayPath, pathBudget, {
447
+ mode: tier.pathMode,
448
+ icon: input.showIcon,
449
+ aliasName: input.aliasName,
450
+ style: pathStyle,
451
+ });
452
+ const leftContent = gitStyled
453
+ ? (pathStyled ? `${pathStyled}${dim(" ")}${gitStyled}` : gitStyled)
454
+ : pathStyled;
455
+ leftBlock = leftContent ? `${borderColor("── ")}${leftContent}${borderColor(" ")}` : "";
456
+ rightBlock = rightCandidate;
457
+ break;
458
+ }
459
+
460
+ // For branch-only tier, allow truncating a very long branch name before dropping git altogether.
461
+ if (tier.gitDetail === "branch" && gitRaw && leftBudget >= minPathWidth + 6) {
462
+ const maxBranch = Math.min(gitW, Math.max(5, Math.floor((leftBudget - minPathWidth - 1))));
463
+ const trimmedGit = theme.fg(gitColor(input.gitState), truncateToWidth(gitRaw, maxBranch, "…"));
464
+ const pathBudget = leftBudget - visibleWidth(trimmedGit) - 1;
465
+ const pathStyled = formatPath(input.displayPath, pathBudget, {
466
+ mode: "short",
467
+ icon: input.showIcon,
468
+ aliasName: input.aliasName,
469
+ style: pathStyle,
470
+ });
471
+ const leftContent = pathStyled ? `${pathStyled}${dim(" ")}${trimmedGit}` : trimmedGit;
472
+ leftBlock = `${borderColor("── ")}${leftContent}${borderColor(" ")}`;
473
+ rightBlock = rightCandidate;
474
+ break;
475
+ }
476
+ }
477
+
478
+ // Ultra-narrow fallback: guarantee context% survives first, then model, then leaf directory.
479
+ if (!rightBlock) {
480
+ const compactRight = makeRight(true, false, false);
481
+ const ctxOnly = formatContextMinimal(input.contextPercent, input.contextWindow, false, theme);
482
+ const chosenRightContent = visibleWidth(compactRight) + 6 <= width
483
+ ? compactRight
484
+ : visibleWidth(ctxOnly) + 6 <= width
485
+ ? ctxOnly
486
+ : truncateToWidth(ctxOnly, Math.max(0, width - 4), "");
487
+ rightBlock = chosenRightContent ? `${borderColor(" ")}${chosenRightContent}${borderColor(" ──")}` : "";
488
+ const rightW = visibleWidth(rightBlock);
489
+ const leftBudget = width - rightW - minGap - 4;
490
+ if (leftBudget >= 2) {
491
+ const pathStyled = formatPath(input.displayPath, leftBudget, {
492
+ mode: "short",
493
+ icon: false,
494
+ aliasName: input.aliasName,
495
+ style: pathStyle,
496
+ });
497
+ if (pathStyled) leftBlock = `${borderColor("── ")}${pathStyled}${borderColor(" ")}`;
498
+ }
499
+ }
500
+
501
+ const line = fillBetween(width, leftBlock, rightBlock, borderColor);
502
+ return overlayScrollLabel(line, width, "↓", hiddenLineCount, borderColor);
503
+ }
504
+
505
+ export interface MinimalEditorSource {
506
+ getTopInput(indicator: WorkingIndicatorLike | undefined, borderColor: (text: string) => string): MinimalTopInput;
507
+ getBottomInput(borderColor: (text: string) => string): MinimalBottomInput;
508
+ }
509
+
510
+ export class MinimalEditor extends CustomEditor {
511
+ private readonly source: MinimalEditorSource;
512
+ private indicator?: WorkingIndicatorLike;
513
+
514
+ constructor(tui: TUI, theme: EditorTheme, keybindings: KeybindingsManager, source: MinimalEditorSource) {
515
+ super(tui, theme, keybindings, { embedWorkingStatus: true });
516
+ this.source = source;
517
+ }
518
+
519
+ override setWorkingStatusIndicator(indicator: Parameters<CustomEditor["setWorkingStatusIndicator"]>[0]): void {
520
+ this.indicator = indicator;
521
+ super.setWorkingStatusIndicator(indicator);
522
+ }
523
+
524
+ protected override renderTopBorder(width: number, hiddenLineCount: number): string {
525
+ const borderColor = (text: string) => this.borderColor(text);
526
+ return renderMinimalTopBorder(this.source.getTopInput(this.indicator, borderColor), width, hiddenLineCount);
527
+ }
528
+
529
+ protected override renderBottomBorder(width: number, hiddenLineCount: number): string {
530
+ const borderColor = (text: string) => this.borderColor(text);
531
+ return renderMinimalBottomBorder(this.source.getBottomInput(borderColor), width, hiddenLineCount);
532
+ }
533
+ }