@oh-my-pi/pi-tui 18.8.8 → 18.8.9
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 +25 -23
- package/dist/types/charts/chart-plan.d.ts +11 -5
- package/dist/types/charts/chart-svg.d.ts +11 -7
- package/dist/types/charts/table-data.d.ts +6 -1
- package/dist/types/kitty-graphics.d.ts +2 -2
- package/dist/types/multiplexers/cmux.d.ts +16 -0
- package/dist/types/multiplexers/herdr.d.ts +26 -0
- package/dist/types/multiplexers/notify.d.ts +13 -0
- package/dist/types/multiplexers/orca.d.ts +12 -0
- package/dist/types/multiplexers/screen.d.ts +9 -0
- package/dist/types/multiplexers/tmux.d.ts +29 -0
- package/dist/types/multiplexers/types.d.ts +100 -0
- package/dist/types/multiplexers/wmux.d.ts +12 -0
- package/dist/types/multiplexers/zellij.d.ts +12 -0
- package/dist/types/status-line/types.d.ts +2 -2
- package/dist/types/terminal-capabilities.d.ts +24 -32
- package/dist/types/terminal-multiplexer.d.ts +127 -14
- package/dist/types/terminal.d.ts +5 -4
- package/dist/types/tmux.d.ts +1 -4
- package/package.json +9 -9
- package/src/charts/chart-plan.ts +152 -12
- package/src/charts/chart-svg.ts +479 -126
- package/src/charts/table-data.ts +43 -8
- package/src/chat/svg-figure.ts +45 -8
- package/src/kitty-graphics.ts +4 -4
- package/src/multiplexers/cmux.ts +29 -0
- package/src/multiplexers/herdr.ts +64 -0
- package/src/multiplexers/notify.ts +24 -0
- package/src/multiplexers/orca.ts +16 -0
- package/src/multiplexers/screen.ts +15 -0
- package/src/multiplexers/tmux.ts +40 -0
- package/src/multiplexers/types.ts +110 -0
- package/src/multiplexers/wmux.ts +16 -0
- package/src/multiplexers/zellij.ts +24 -0
- package/src/status-line/component.ts +12 -8
- package/src/status-line/segments.ts +7 -11
- package/src/status-line/types.ts +2 -2
- package/src/terminal-capabilities.ts +65 -181
- package/src/terminal-multiplexer.ts +112 -33
- package/src/terminal.ts +34 -28
- package/src/theme/session-color.ts +1 -7
- package/src/theme/theme.ts +7 -4
- package/src/tmux.ts +4 -11
- package/src/tui.ts +18 -12
package/src/charts/table-data.ts
CHANGED
|
@@ -45,7 +45,10 @@ export interface NumberCell {
|
|
|
45
45
|
readonly toFigure?: string;
|
|
46
46
|
/** `a–b`: `b`, in the same base units. */
|
|
47
47
|
readonly upper?: number;
|
|
48
|
-
/**
|
|
48
|
+
/**
|
|
49
|
+
* `a/b`: `b`. {@link analyzeTable} reads a score (`12/12`, `154/160`) as the
|
|
50
|
+
* percent of `b` reached; a pair (`85 / 147` under `Edit / read calls`) keeps `a`.
|
|
51
|
+
*/
|
|
49
52
|
readonly denominator?: number;
|
|
50
53
|
}
|
|
51
54
|
|
|
@@ -77,6 +80,8 @@ export interface TableColumn {
|
|
|
77
80
|
readonly unit: string;
|
|
78
81
|
/** Numeric cells disagree on dimension (a metric-per-row table). */
|
|
79
82
|
readonly mixed: boolean;
|
|
83
|
+
/** Numeric cells are mostly scores out of a total (`12/12`), read as percent of it. */
|
|
84
|
+
readonly scores: boolean;
|
|
80
85
|
/** Every numeric data cell holds the same value: an echoed setting, not a measure. */
|
|
81
86
|
readonly constant: boolean;
|
|
82
87
|
/** Share of numeric cells written with an explicit sign. */
|
|
@@ -220,7 +225,7 @@ export function parseCell(markdown: string): Cell {
|
|
|
220
225
|
const text = plain.text.replace(MARKS, "").replace(/\s+/g, " ").trim();
|
|
221
226
|
const emphasis = plain.emphasis;
|
|
222
227
|
const other = (kind: OtherCell["kind"]): OtherCell => ({ kind, text: plain.text, emphasis });
|
|
223
|
-
if (MISSING
|
|
228
|
+
if (Object.hasOwn(MISSING, text.toLowerCase())) return other("missing");
|
|
224
229
|
if (DATE.test(text)) return other("date");
|
|
225
230
|
if (TIME.test(text)) return other("time");
|
|
226
231
|
if (VERSION.test(text)) return other("version");
|
|
@@ -257,7 +262,7 @@ export function parseCell(markdown: string): Cell {
|
|
|
257
262
|
let dim: Dimension = groups.cur ? "currency" : "count";
|
|
258
263
|
let factor = 1;
|
|
259
264
|
if (unit) {
|
|
260
|
-
const known =
|
|
265
|
+
const known = knownUnit(unit);
|
|
261
266
|
if (known) {
|
|
262
267
|
[dim, factor] = known;
|
|
263
268
|
} else if (unit.includes("/")) {
|
|
@@ -274,7 +279,7 @@ export function parseCell(markdown: string): Cell {
|
|
|
274
279
|
if (groups.cur) unit = groups.cur;
|
|
275
280
|
// `24–72 h`: the unit after the range's end applies to its start too.
|
|
276
281
|
const range = RANGE_TAIL.exec(rest);
|
|
277
|
-
const rangeUnit = range?.[2] ? (
|
|
282
|
+
const rangeUnit = range?.[2] ? knownUnit(range[2]) : undefined;
|
|
278
283
|
if (!unit && rangeUnit) {
|
|
279
284
|
[dim, factor] = rangeUnit;
|
|
280
285
|
unit = range![2]!;
|
|
@@ -314,14 +319,26 @@ function toNumber(written: string): number {
|
|
|
314
319
|
/** Factor of a unit written after the second number of a range or transition; the first number's when absent. */
|
|
315
320
|
function tailFactor(unit: string | undefined, fallback: number): number {
|
|
316
321
|
if (!unit) return fallback;
|
|
317
|
-
|
|
318
|
-
|
|
322
|
+
return knownUnit(unit)?.[1] ?? fallback;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
/** Dimension and base factor of `unit`, cased spellings first; own keys only, so `constructor` is no unit. */
|
|
326
|
+
function knownUnit(unit: string): readonly [Dimension, number] | undefined {
|
|
327
|
+
if (Object.hasOwn(CASED_UNITS, unit)) return CASED_UNITS[unit];
|
|
328
|
+
const lower = unit.toLowerCase();
|
|
329
|
+
return Object.hasOwn(UNITS, lower) ? UNITS[lower] : undefined;
|
|
319
330
|
}
|
|
320
331
|
|
|
321
332
|
/** Read a table's columns and rows for charting. Cells are the raw Markdown of each cell. */
|
|
322
333
|
export function analyzeTable(header: readonly string[], rows: readonly (readonly string[])[]): TableAnalysis {
|
|
323
|
-
const
|
|
324
|
-
const
|
|
334
|
+
const headers = header.map(cell => plainCell(cell).text);
|
|
335
|
+
const parsed = rows.map(row => {
|
|
336
|
+
const cells = headers.map((_, index) => parseCell(row[index] ?? ""));
|
|
337
|
+
// `Edit / read calls | 85 / 147`: a spaced slash in the row's name pairs two values.
|
|
338
|
+
const paired = cells.some(cell => cell.kind === "text" && PAIR_SLASH.test(cell.text));
|
|
339
|
+
return cells.map((cell, index) => (paired || PAIR_SLASH.test(headers[index]!) ? cell : asScore(cell)));
|
|
340
|
+
});
|
|
341
|
+
const draft = headers.map((text, index) => readColumn(index, text, parsed));
|
|
325
342
|
const labels = draft.filter(column => column.role === "label" || column.role === "temporal");
|
|
326
343
|
const label =
|
|
327
344
|
labels[0] ?? draft.find(column => column.role === "sequence") ?? draft.find(column => column.role === "index");
|
|
@@ -338,6 +355,22 @@ export function analyzeTable(header: readonly string[], rows: readonly (readonly
|
|
|
338
355
|
|
|
339
356
|
type DraftColumn = Omit<TableColumn, "constant">;
|
|
340
357
|
|
|
358
|
+
/** A spaced slash naming two values (`p50 / p95`, `median / max`) rather than a path or a score. */
|
|
359
|
+
const PAIR_SLASH = /\S \/ \S/;
|
|
360
|
+
|
|
361
|
+
/**
|
|
362
|
+
* A whole-number `a/b` with `a ≤ b` as the percent of `b` it reached; any
|
|
363
|
+
* other cell unchanged, a list like `327 / 333 / 339` included.
|
|
364
|
+
*/
|
|
365
|
+
function asScore(cell: Cell): Cell {
|
|
366
|
+
if (!isNumber(cell) || cell.dim !== "fraction" || !cell.denominator) return cell;
|
|
367
|
+
const { value, denominator } = cell;
|
|
368
|
+
if (!Number.isInteger(value) || !Number.isInteger(denominator) || value > denominator) return cell;
|
|
369
|
+
const after = cell.text.indexOf(cell.figure);
|
|
370
|
+
if (after < 0 || /^\s*\//.test(cell.text.slice(after + cell.figure.length))) return cell;
|
|
371
|
+
return { ...cell, dim: "percent", value: (100 * value) / denominator };
|
|
372
|
+
}
|
|
373
|
+
|
|
341
374
|
function readColumn(index: number, header: string, parsed: readonly (readonly Cell[])[]): DraftColumn {
|
|
342
375
|
const cells = resolveMinutes(parsed.map(row => row[index]!));
|
|
343
376
|
const present = cells.filter(cell => cell.kind !== "missing");
|
|
@@ -358,6 +391,7 @@ function readColumn(index: number, header: string, parsed: readonly (readonly Ce
|
|
|
358
391
|
for (const group of dims.values()) if (group.length > dominant.length) dominant = group;
|
|
359
392
|
const dim = dominant[0]?.dim;
|
|
360
393
|
const mixed = numbers.length > 0 && dominant.length / numbers.length < 0.8;
|
|
394
|
+
const scored = numbers.filter(cell => cell.dim === "percent" && cell.denominator !== undefined).length;
|
|
361
395
|
const unit = dim === "currency" || dim === "rate" ? (dominant[0]?.unit ?? "") : "";
|
|
362
396
|
|
|
363
397
|
const trimmed = header.trim();
|
|
@@ -385,6 +419,7 @@ function readColumn(index: number, header: string, parsed: readonly (readonly Ce
|
|
|
385
419
|
dim,
|
|
386
420
|
unit,
|
|
387
421
|
mixed,
|
|
422
|
+
scores: numbers.length > 0 && scored / numbers.length >= 0.8,
|
|
388
423
|
signedShare: numbers.length ? numbers.filter(cell => cell.signed).length / numbers.length : 0,
|
|
389
424
|
arrowShare: numbers.length ? numbers.filter(cell => cell.to !== undefined).length / numbers.length : 0,
|
|
390
425
|
};
|
package/src/chat/svg-figure.ts
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* places it 1:1: any resampling, even 0.99×, blurs every glyph edge.
|
|
14
14
|
*/
|
|
15
15
|
import { rasterizeSvg } from "@oh-my-pi/pi-natives";
|
|
16
|
-
import { logger } from "@oh-my-pi/pi-utils";
|
|
16
|
+
import { hexToOklch, hueDistance, logger, oklchCusp, oklchToHex } from "@oh-my-pi/pi-utils";
|
|
17
17
|
import { Image, type ImageBudget, imageMaxColumns } from "../components/image";
|
|
18
18
|
import { fencedCode, type Markdown } from "../components/markdown";
|
|
19
19
|
import { type CellDimensions, getCellDimensions, getImageDimensions } from "../terminal-capabilities";
|
|
@@ -30,7 +30,10 @@ const MAX_EDGE_PX = 4096;
|
|
|
30
30
|
/** Share of the terminal's rows one figure may fill, so it fits on screen whole. */
|
|
31
31
|
const MAX_VIEWPORT_SHARE = 0.8;
|
|
32
32
|
|
|
33
|
-
/**
|
|
33
|
+
/**
|
|
34
|
+
* Foreground theme colors behind the figure tokens (`var(--name)`); `surface`
|
|
35
|
+
* is the selection background and `c1`…`c6` come from {@link seriesColors}.
|
|
36
|
+
*/
|
|
34
37
|
const PALETTE: Readonly<Record<string, ThemeColor>> = {
|
|
35
38
|
fg: "text",
|
|
36
39
|
muted: "muted",
|
|
@@ -39,21 +42,55 @@ const PALETTE: Readonly<Record<string, ThemeColor>> = {
|
|
|
39
42
|
success: "success",
|
|
40
43
|
warning: "warning",
|
|
41
44
|
error: "error",
|
|
42
|
-
c1: "syntaxKeyword",
|
|
43
|
-
c2: "syntaxString",
|
|
44
|
-
c3: "syntaxFunction",
|
|
45
|
-
c4: "syntaxType",
|
|
46
|
-
c5: "syntaxNumber",
|
|
47
|
-
c6: "syntaxVariable",
|
|
48
45
|
};
|
|
49
46
|
|
|
47
|
+
/** Hue families (OKLCH degrees) the series colors draw from: blue, orange, green, purple, pink, teal. */
|
|
48
|
+
const SERIES_HUES = [255, 55, 145, 305, 0, 200];
|
|
49
|
+
/** Gold, for a sixth series when the accent's hue crowds out two families. */
|
|
50
|
+
const RESERVE_HUE = 90;
|
|
51
|
+
/** Least hue distance between a family and the accent's hue for both to lead series. */
|
|
52
|
+
const MIN_SERIES_HUE_GAP = 30;
|
|
53
|
+
/** Chroma below which the accent reads as gray and blue leads instead. */
|
|
54
|
+
const MIN_ACCENT_CHROMA = 0.04;
|
|
55
|
+
/** Lightness band of series colors: deep enough for labels on light surfaces, bright enough on dark ones. */
|
|
56
|
+
const SERIES_LIGHTNESS = { light: [0.52, 0.66], dark: [0.68, 0.82] } as const;
|
|
57
|
+
/** Chroma ceiling: vivid, not neon. */
|
|
58
|
+
const SERIES_CHROMA = 0.19;
|
|
59
|
+
|
|
50
60
|
/** The active theme's color per figure token, for resolving a figure with `prepareSvg`. */
|
|
51
61
|
export function svgFigurePalette(): Record<string, string> {
|
|
52
62
|
const palette: Record<string, string> = { surface: theme.getBgHex("selectedBg") };
|
|
53
63
|
for (const token in PALETTE) palette[token] = theme.getColorHex(PALETTE[token]!);
|
|
64
|
+
seriesColors(palette.accent!, theme.isLight).forEach((color, at) => {
|
|
65
|
+
palette[`c${at + 1}`] = color;
|
|
66
|
+
});
|
|
54
67
|
return palette;
|
|
55
68
|
}
|
|
56
69
|
|
|
70
|
+
/**
|
|
71
|
+
* Six series colors of even visual weight, in the manner of Apple's system
|
|
72
|
+
* palette: led by the theme accent's hue (blue when the accent is gray), each
|
|
73
|
+
* next hue the family farthest from those already taken. Every hue sits at
|
|
74
|
+
* its gamut cusp clamped into the theme's {@link SERIES_LIGHTNESS} band, so
|
|
75
|
+
* orange stays orange and blue stays deep.
|
|
76
|
+
*/
|
|
77
|
+
function seriesColors(accent: string, light: boolean): string[] {
|
|
78
|
+
const { c, h } = hexToOklch(accent);
|
|
79
|
+
const lead = c >= MIN_ACCENT_CHROMA ? h : SERIES_HUES[0]!;
|
|
80
|
+
const hues = [lead];
|
|
81
|
+
const pool = SERIES_HUES.filter(hue => hueDistance(hue, lead) >= MIN_SERIES_HUE_GAP);
|
|
82
|
+
while (pool.length > 0) {
|
|
83
|
+
const gaps = pool.map(hue => Math.min(...hues.map(taken => hueDistance(hue, taken))));
|
|
84
|
+
hues.push(pool.splice(gaps.indexOf(Math.max(...gaps)), 1)[0]!);
|
|
85
|
+
}
|
|
86
|
+
if (hues.length < 6) hues.push(RESERVE_HUE);
|
|
87
|
+
const [low, high] = SERIES_LIGHTNESS[light ? "light" : "dark"];
|
|
88
|
+
return hues.slice(0, 6).map(hue => {
|
|
89
|
+
const cusp = oklchCusp(hue);
|
|
90
|
+
return oklchToHex({ l: Math.min(high, Math.max(low, cusp.l)), c: Math.min(SERIES_CHROMA, cusp.c), h: hue });
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
|
|
57
94
|
let figuresEnabled = true;
|
|
58
95
|
|
|
59
96
|
/** Turn lifting ```svg fences into images on or off (the host's `tui.renderSvg`); the host rebuilds the transcript after. */
|
package/src/kitty-graphics.ts
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
* forms. Protocol gating (`imageProtocol === Kitty`) lives in the caller.
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
|
-
import {
|
|
18
|
+
import { isInsideTerminalMultiplexer, terminalMultiplexerSessions } from "./terminal-multiplexer";
|
|
19
19
|
import { wrapTmuxPassthroughIfNeeded } from "./tmux";
|
|
20
20
|
|
|
21
21
|
/** Kitty Unicode placeholder base character (U+10EEEE, Plane 16 PUA). */
|
|
@@ -67,8 +67,8 @@ export interface KittyGraphicsFeatures {
|
|
|
67
67
|
* cannot use cursor-positioned placements because the outer terminal does not
|
|
68
68
|
* know pane scroll/reflow state. An explicit `PI_FORCE_IMAGE_PROTOCOL=kitty`
|
|
69
69
|
* opts into placeholders under any multiplexer — matching `timg -pk`.
|
|
70
|
-
* Automatic
|
|
71
|
-
* that
|
|
70
|
+
* Automatic fallback stays off inside multiplexers whose pane marker does not
|
|
71
|
+
* prove that a Kitty renderer is enabled (Herdr's is experimental).
|
|
72
72
|
*
|
|
73
73
|
* `PI_NO_KITTY_PLACEHOLDERS=1` and `PI_KITTY_PLACEHOLDERS=0` remain hard
|
|
74
74
|
* opt-outs; `PI_KITTY_PLACEHOLDERS=1` explicitly opts in anywhere else.
|
|
@@ -81,7 +81,7 @@ export function detectKittyUnicodePlaceholdersSupport(terminalId: string, env: N
|
|
|
81
81
|
if (force === "0" || force === "false" || force === "off" || force === "no" || force === "n") return false;
|
|
82
82
|
const insideMultiplexer = isInsideTerminalMultiplexer(env);
|
|
83
83
|
if (insideMultiplexer && env.PI_FORCE_IMAGE_PROTOCOL?.trim().toLowerCase() === "kitty") return true;
|
|
84
|
-
if (
|
|
84
|
+
if (terminalMultiplexerSessions(env).some(multiplexer => multiplexer.imagesRequireOverride)) return false;
|
|
85
85
|
return (
|
|
86
86
|
terminalId === "kitty" ||
|
|
87
87
|
terminalId === "ghostty" ||
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { notificationTitleAndBody, spawnNotifier } from "./notify";
|
|
2
|
+
import type { TerminalMultiplexerModule } from "./types";
|
|
3
|
+
|
|
4
|
+
const CMUX_SURFACE_ID_PATTERN = /^[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/iu;
|
|
5
|
+
|
|
6
|
+
export const cmuxMultiplexer = {
|
|
7
|
+
id: "cmux",
|
|
8
|
+
precedence: "session",
|
|
9
|
+
// CMUX_SOCKET_PATH is a CLI socket override and can be set outside a CMUX terminal.
|
|
10
|
+
sessionEnvKeys: ["CMUX_WORKSPACE_ID", "CMUX_SURFACE_ID", "CMUX_REMOTE_TRANSPORT"],
|
|
11
|
+
ownsScreenGrid: true,
|
|
12
|
+
isInside(env: NodeJS.ProcessEnv = Bun.env): boolean {
|
|
13
|
+
return Boolean(env.CMUX_WORKSPACE_ID || env.CMUX_SURFACE_ID || env.CMUX_REMOTE_TRANSPORT);
|
|
14
|
+
},
|
|
15
|
+
/**
|
|
16
|
+
* Workspace/socket state alone is not enough: only the injected surface UUID
|
|
17
|
+
* identifies the pane that should receive the notification. Without a valid
|
|
18
|
+
* surface, or without the binary, delivery falls through unchanged.
|
|
19
|
+
*/
|
|
20
|
+
notifier: {
|
|
21
|
+
tier: "surface",
|
|
22
|
+
send({ message, env }) {
|
|
23
|
+
const surfaceId = env.CMUX_SURFACE_ID?.trim();
|
|
24
|
+
if (!surfaceId || !CMUX_SURFACE_ID_PATTERN.test(surfaceId)) return false;
|
|
25
|
+
const { title, body } = notificationTitleAndBody(message);
|
|
26
|
+
return spawnNotifier(["cmux", "notify", "--surface", surfaceId, "--title", title, "--body", body]);
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
} as const satisfies TerminalMultiplexerModule;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { DEFAULT_NOTIFICATION_TITLE, notificationTitleAndBody, spawnNotifier } from "./notify";
|
|
2
|
+
import type { TerminalMultiplexerModule } from "./types";
|
|
3
|
+
|
|
4
|
+
const HERDR_PANE_ID_PATTERN = /^[0-9A-Za-z:_-]{1,64}$/u;
|
|
5
|
+
/**
|
|
6
|
+
* `herdr notification show` takes the title as its first positional and reads
|
|
7
|
+
* exactly these three values there as a help request; it has no `--`
|
|
8
|
+
* terminator. Any other text, including one starting with `-`, is a title.
|
|
9
|
+
*/
|
|
10
|
+
const HERDR_USAGE_TOKENS: Record<string, true> = { help: true, "--help": true, "-h": true };
|
|
11
|
+
|
|
12
|
+
export const herdrMultiplexer = {
|
|
13
|
+
id: "herdr",
|
|
14
|
+
precedence: "session",
|
|
15
|
+
sessionEnvKeys: ["HERDR_ENV", "HERDR_PANE_ID", "HERDR_TAB_ID", "HERDR_WORKSPACE_ID"],
|
|
16
|
+
ownsScreenGrid: true,
|
|
17
|
+
isInside(env: NodeJS.ProcessEnv = Bun.env): boolean {
|
|
18
|
+
// Identity vars survive env-sanitizing launchers that drop HERDR_ENV.
|
|
19
|
+
// Client-only socket, binary, session, and config overrides are not proof
|
|
20
|
+
// that this process runs inside a pane.
|
|
21
|
+
return env.HERDR_ENV === "1" || Boolean(env.HERDR_PANE_ID || env.HERDR_TAB_ID || env.HERDR_WORKSPACE_ID);
|
|
22
|
+
},
|
|
23
|
+
/**
|
|
24
|
+
* Herdr multiplexes panes like tmux but swallows bare OSC 9 / OSC 99 and has
|
|
25
|
+
* no DCS passthrough envelope, and its bell relay does not flag a
|
|
26
|
+
* backgrounded tab — so without its CLI a backgrounded pane gets no signal
|
|
27
|
+
* at all that the agent finished or is waiting for input.
|
|
28
|
+
*
|
|
29
|
+
* `sound` maps the notification kind onto what Herdr offers: a question
|
|
30
|
+
* waiting on the user and a turn that stopped with an error both need the
|
|
31
|
+
* human and ring `request`, a settled turn rings `done`, anything else stays
|
|
32
|
+
* silent. The exact pane ID addresses the CLI call; without a valid one, or
|
|
33
|
+
* without the binary, delivery falls through.
|
|
34
|
+
*/
|
|
35
|
+
notifier: {
|
|
36
|
+
tier: "pane",
|
|
37
|
+
send({ message, env }) {
|
|
38
|
+
const paneId = env.HERDR_PANE_ID?.trim();
|
|
39
|
+
if (!paneId || !HERDR_PANE_ID_PATTERN.test(paneId)) return false;
|
|
40
|
+
|
|
41
|
+
const parsed = notificationTitleAndBody(message);
|
|
42
|
+
const title = Object.hasOwn(HERDR_USAGE_TOKENS, parsed.title) ? DEFAULT_NOTIFICATION_TITLE : parsed.title;
|
|
43
|
+
const kinds = typeof message === "string" ? [] : [message.type ?? []].flat();
|
|
44
|
+
const sound =
|
|
45
|
+
kinds.includes("ask") || kinds.includes("error")
|
|
46
|
+
? "request"
|
|
47
|
+
: kinds.includes("completion")
|
|
48
|
+
? "done"
|
|
49
|
+
: "none";
|
|
50
|
+
return spawnNotifier(["herdr", "notification", "show", title, "--body", parsed.body, "--sound", sound]);
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
// Herdr hides the outer terminal (`TERM=xterm-256color`, no `TERM_PROGRAM`),
|
|
54
|
+
// but renders OSC 8 in its own grid and opens links itself on Ctrl+click.
|
|
55
|
+
hyperlinks: "render",
|
|
56
|
+
// The pane VTE is libghostty and suppresses compositing while DEC 2026 is
|
|
57
|
+
// set. Without sync, CUP-diff paints and split write(2) chunks composite as
|
|
58
|
+
// dirty-row patches: the live viewport tears, its top frozen while only the
|
|
59
|
+
// bottom refreshes.
|
|
60
|
+
honorsSynchronizedOutput: true,
|
|
61
|
+
// The pane marker does not prove the client enabled Herdr's experimental
|
|
62
|
+
// Kitty renderer, and leaked outer-terminal identities cannot either.
|
|
63
|
+
imagesRequireOverride: true,
|
|
64
|
+
} as const satisfies TerminalMultiplexerModule;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { TerminalNotification } from "../terminal-capabilities";
|
|
2
|
+
|
|
3
|
+
/** Title for out-of-band multiplexer notifications that carry none of their own. */
|
|
4
|
+
export const DEFAULT_NOTIFICATION_TITLE = "omp";
|
|
5
|
+
|
|
6
|
+
/** Title and body for an out-of-band multiplexer notification (cmux, Herdr). */
|
|
7
|
+
export function notificationTitleAndBody(message: string | TerminalNotification): { title: string; body: string } {
|
|
8
|
+
if (typeof message === "string") return { title: DEFAULT_NOTIFICATION_TITLE, body: message };
|
|
9
|
+
return { title: message.title?.trim() || DEFAULT_NOTIFICATION_TITLE, body: message.body ?? "" };
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Start a notifier CLI without waiting for or pinning it. Returns false when
|
|
14
|
+
* the binary cannot be spawned, which leaves delivery to the terminal fallback.
|
|
15
|
+
*/
|
|
16
|
+
export function spawnNotifier(cmd: string[]): boolean {
|
|
17
|
+
try {
|
|
18
|
+
const child = Bun.spawn({ cmd, stdin: "ignore", stdout: "ignore", stderr: "ignore" });
|
|
19
|
+
child.unref();
|
|
20
|
+
} catch {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { TerminalMultiplexerModule } from "./types";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Orca is an xterm.js-based IDE whose terminals expose paired pane/worktree IDs.
|
|
5
|
+
* It is recognized for launches, but it ranks below nested multiplexers and keeps
|
|
6
|
+
* the direct-terminal render path it used before it was recognized.
|
|
7
|
+
*/
|
|
8
|
+
export const orcaMultiplexer = {
|
|
9
|
+
id: "orca",
|
|
10
|
+
precedence: "outerApp",
|
|
11
|
+
sessionEnvKeys: ["ORCA_PANE_KEY", "ORCA_WORKTREE_ID"],
|
|
12
|
+
ownsScreenGrid: false,
|
|
13
|
+
isInside(env: NodeJS.ProcessEnv = Bun.env): boolean {
|
|
14
|
+
return Boolean(env.ORCA_PANE_KEY?.trim() && env.ORCA_WORKTREE_ID?.trim());
|
|
15
|
+
},
|
|
16
|
+
} as const satisfies TerminalMultiplexerModule;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { TerminalMultiplexerModule } from "./types";
|
|
2
|
+
|
|
3
|
+
export const screenMultiplexer = {
|
|
4
|
+
id: "screen",
|
|
5
|
+
precedence: "session",
|
|
6
|
+
sessionEnvKeys: ["STY"],
|
|
7
|
+
termPrefix: "screen",
|
|
8
|
+
ownsScreenGrid: true,
|
|
9
|
+
isInside(env: NodeJS.ProcessEnv = Bun.env): boolean {
|
|
10
|
+
return Boolean(env.STY);
|
|
11
|
+
},
|
|
12
|
+
// GNU screen never gained OSC 8 support, so a screen layer anywhere in the
|
|
13
|
+
// path vetoes hyperlinks, even under a nested tmux.
|
|
14
|
+
hyperlinks: "drop",
|
|
15
|
+
} as const satisfies TerminalMultiplexerModule;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { TerminalMultiplexerModule } from "./types";
|
|
2
|
+
|
|
3
|
+
/** Wrap a control sequence in tmux's DCS passthrough envelope. */
|
|
4
|
+
export function wrapTmuxPassthrough(payload: string): string {
|
|
5
|
+
return `\x1bPtmux;${payload.replaceAll("\x1b", "\x1b\x1b")}\x1b\\`;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export const tmuxMultiplexer = {
|
|
9
|
+
id: "tmux",
|
|
10
|
+
precedence: "session",
|
|
11
|
+
sessionEnvKeys: ["TMUX"],
|
|
12
|
+
termPrefix: "tmux",
|
|
13
|
+
ownsScreenGrid: true,
|
|
14
|
+
isInside(env: NodeJS.ProcessEnv = Bun.env): boolean {
|
|
15
|
+
return Boolean(env.TMUX);
|
|
16
|
+
},
|
|
17
|
+
notifier: {
|
|
18
|
+
tier: "inBand",
|
|
19
|
+
// tmux swallows bare OSCs; passthrough preserves the toast and BEL flags
|
|
20
|
+
// the pane. Bell notifications already provide that signal. One write
|
|
21
|
+
// keeps a concurrent renderer from interleaving between the two.
|
|
22
|
+
send({ sequence, write }) {
|
|
23
|
+
if (sequence === null) return false;
|
|
24
|
+
write(`${wrapTmuxPassthrough(sequence)}\x07`);
|
|
25
|
+
return true;
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
// tmux 3.4 stores OSC 8 as a cell attribute and forwards it to outer
|
|
29
|
+
// terminals whose `terminal-features` include `hyperlinks`; it self-reports
|
|
30
|
+
// via TERM_PROGRAM/TERM_PROGRAM_VERSION since 3.2a.
|
|
31
|
+
hyperlinks: { forward: { termProgram: "tmux", major: 3, minor: 4 } },
|
|
32
|
+
// An explicit appearance refresh passes OSC 11 to the outer terminal, then
|
|
33
|
+
// re-reads tmux's cache once it has consumed the reply.
|
|
34
|
+
backgroundColorCache: { passthrough: wrapTmuxPassthrough, settleMs: 100 },
|
|
35
|
+
expandsRepPadding: true,
|
|
36
|
+
// tmux expires synchronized output after one second.
|
|
37
|
+
expiresSynchronizedOutput: true,
|
|
38
|
+
altRestoreEndsSynchronizedOutput: true,
|
|
39
|
+
growsBeforeSigwinch: true,
|
|
40
|
+
} as const satisfies TerminalMultiplexerModule;
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import type { TerminalNotification } from "../terminal-capabilities";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Classification tier. `session` markers outrank the TERM fallback; `outerApp`
|
|
5
|
+
* hosts rank below it so a multiplexer nested inside them still wins.
|
|
6
|
+
*/
|
|
7
|
+
export type TerminalMultiplexerPrecedence = "session" | "outerApp";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Notification delivery tier, tried in this order so the innermost target wins:
|
|
11
|
+
* a `pane` notifier addresses the exact pane through the multiplexer's CLI, a
|
|
12
|
+
* `surface` notifier addresses the containing app surface, and an `inBand`
|
|
13
|
+
* notifier rewrites the terminal's own notification sequence.
|
|
14
|
+
*/
|
|
15
|
+
export type TerminalMultiplexerNotificationTier = "pane" | "surface" | "inBand";
|
|
16
|
+
|
|
17
|
+
/** One notification offered to a multiplexer notifier. */
|
|
18
|
+
export interface TerminalMultiplexerNotificationRequest {
|
|
19
|
+
readonly message: string | TerminalNotification;
|
|
20
|
+
readonly env: NodeJS.ProcessEnv;
|
|
21
|
+
/** The host terminal's formatted OSC notification, or `null` when it notifies with a bare BEL. */
|
|
22
|
+
readonly sequence: string | null;
|
|
23
|
+
/** Write a sequence through the active terminal. */
|
|
24
|
+
write(data: string): void;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface TerminalMultiplexerNotifier {
|
|
28
|
+
readonly tier: TerminalMultiplexerNotificationTier;
|
|
29
|
+
/** Deliver the notification. `false` leaves it to the next notifier and then the terminal fallback. */
|
|
30
|
+
send(request: TerminalMultiplexerNotificationRequest): boolean;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* OSC 8 handling inside a multiplexer session:
|
|
35
|
+
* - `render`: the multiplexer draws and opens links itself, so links work
|
|
36
|
+
* whatever the outer terminal supports, unless another session with a
|
|
37
|
+
* hyperlink policy sits in the path.
|
|
38
|
+
* - `drop`: never forwards OSC 8; its session anywhere in the path disables links.
|
|
39
|
+
* - `forward`: forwards OSC 8 once it self-reports (`TERM_PROGRAM`/`TERM_PROGRAM_VERSION`)
|
|
40
|
+
* at least `major.minor`; older or unreported versions stay off.
|
|
41
|
+
*/
|
|
42
|
+
export type TerminalMultiplexerHyperlinks =
|
|
43
|
+
| "render"
|
|
44
|
+
| "drop"
|
|
45
|
+
| {
|
|
46
|
+
readonly forward: {
|
|
47
|
+
/** Lowercase `TERM_PROGRAM` the multiplexer sets inside its panes. */
|
|
48
|
+
readonly termProgram: string;
|
|
49
|
+
readonly major: number;
|
|
50
|
+
readonly minor: number;
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
/** A multiplexer that answers OSC 11 from a cached copy of the outer terminal's background color. */
|
|
55
|
+
export interface TerminalMultiplexerBackgroundColorCache {
|
|
56
|
+
/** Wrap a query so it reaches the outer terminal and refreshes the cache. */
|
|
57
|
+
passthrough(query: string): string;
|
|
58
|
+
/** How long the multiplexer needs to store the outer reply before the cache is re-read. */
|
|
59
|
+
readonly settleMs: number;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** Everything omp needs to recognize one terminal multiplexer and adapt to it. */
|
|
63
|
+
export interface TerminalMultiplexerModule<Id extends string = string> {
|
|
64
|
+
readonly id: Id;
|
|
65
|
+
readonly precedence: TerminalMultiplexerPrecedence;
|
|
66
|
+
/** Every environment variable `isInside()` reads. */
|
|
67
|
+
readonly sessionEnvKeys: readonly string[];
|
|
68
|
+
/** Lowercase TERM prefix that identifies the multiplexer when its session markers were stripped. */
|
|
69
|
+
readonly termPrefix?: string;
|
|
70
|
+
/**
|
|
71
|
+
* Whether the multiplexer owns the screen grid. When true, rendering takes the
|
|
72
|
+
* multiplexer path (no scrollback rebuild, anchored resize, skipped probes).
|
|
73
|
+
*/
|
|
74
|
+
readonly ownsScreenGrid: boolean;
|
|
75
|
+
isInside(env?: NodeJS.ProcessEnv): boolean;
|
|
76
|
+
/** Routes notifications the multiplexer would otherwise swallow. */
|
|
77
|
+
readonly notifier?: TerminalMultiplexerNotifier;
|
|
78
|
+
/** OSC 8 policy inside a session; unset defers to the outer terminal. */
|
|
79
|
+
readonly hyperlinks?: TerminalMultiplexerHyperlinks;
|
|
80
|
+
/**
|
|
81
|
+
* The pane's VTE honors DEC 2026 even when DECRQM is unanswered or reports
|
|
82
|
+
* the mode unrecognized (status 0): synchronized output starts on inside a
|
|
83
|
+
* session, and an unrecognized report does not turn it off.
|
|
84
|
+
*/
|
|
85
|
+
readonly honorsSynchronizedOutput?: boolean;
|
|
86
|
+
/**
|
|
87
|
+
* The session does not reveal whether its client renders graphics while
|
|
88
|
+
* outer-terminal identity variables leak in, so images and Kitty
|
|
89
|
+
* placeholders stay off unless the user forces them.
|
|
90
|
+
*/
|
|
91
|
+
readonly imagesRequireOverride?: boolean;
|
|
92
|
+
/** Platforms where the multiplexer breaks OSC 11 passthrough, so host appearance is used instead. */
|
|
93
|
+
readonly backgroundQueryBrokenOn?: readonly NodeJS.Platform[];
|
|
94
|
+
/** Present when OSC 11 replies come from a cache an explicit refresh must update first. */
|
|
95
|
+
readonly backgroundColorCache?: TerminalMultiplexerBackgroundColorCache;
|
|
96
|
+
/** Expands REP into identical styled cells, so destructive replays REP-encode their padding. */
|
|
97
|
+
readonly expandsRepPadding?: boolean;
|
|
98
|
+
/** Expires a synchronized update after a deadline, so large rebuild replays renew DEC 2026 as they stream. */
|
|
99
|
+
readonly expiresSynchronizedOutput?: boolean;
|
|
100
|
+
/**
|
|
101
|
+
* Restoring the alternate buffer schedules a redraw that ends a synchronized
|
|
102
|
+
* update early, so a synchronized resize rebuild stays on the main buffer.
|
|
103
|
+
*/
|
|
104
|
+
readonly altRestoreEndsSynchronizedOutput?: boolean;
|
|
105
|
+
/**
|
|
106
|
+
* May grow its grid before SIGWINCH reaches the app, so a rebuild-mode grow
|
|
107
|
+
* whose full viewport no longer reaches the bottom replays history.
|
|
108
|
+
*/
|
|
109
|
+
readonly growsBeforeSigwinch?: boolean;
|
|
110
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { TerminalMultiplexerModule } from "./types";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* wmux is a Windows multiplexer (Electron + xterm.js) modeled on cmux/herdr that
|
|
5
|
+
* repaints its pane in place. WMUX_CLI / WMUX_PIPE are CLI path overrides and can
|
|
6
|
+
* be set outside a wmux terminal.
|
|
7
|
+
*/
|
|
8
|
+
export const wmuxMultiplexer = {
|
|
9
|
+
id: "wmux",
|
|
10
|
+
precedence: "session",
|
|
11
|
+
sessionEnvKeys: ["WMUX", "WMUX_SURFACE_ID"],
|
|
12
|
+
ownsScreenGrid: true,
|
|
13
|
+
isInside(env: NodeJS.ProcessEnv = Bun.env): boolean {
|
|
14
|
+
return env.WMUX === "1" || Boolean(env.WMUX_SURFACE_ID);
|
|
15
|
+
},
|
|
16
|
+
} as const satisfies TerminalMultiplexerModule;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { TerminalMultiplexerModule } from "./types";
|
|
2
|
+
|
|
3
|
+
export const zellijMultiplexer = {
|
|
4
|
+
id: "zellij",
|
|
5
|
+
precedence: "session",
|
|
6
|
+
sessionEnvKeys: ["ZELLIJ"],
|
|
7
|
+
ownsScreenGrid: true,
|
|
8
|
+
isInside(env: NodeJS.ProcessEnv = Bun.env): boolean {
|
|
9
|
+
return Boolean(env.ZELLIJ);
|
|
10
|
+
},
|
|
11
|
+
notifier: {
|
|
12
|
+
tier: "inBand",
|
|
13
|
+
// Zellij drops OSCs and has no DCS passthrough; a bare BEL raises its bell
|
|
14
|
+
// flag. Bell notifications already provide that signal.
|
|
15
|
+
send({ sequence, write }) {
|
|
16
|
+
if (sequence === null) return false;
|
|
17
|
+
write(`${sequence}\x07`);
|
|
18
|
+
return true;
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
// Zellij currently breaks OSC 11 passthrough on macOS, so terminal-derived
|
|
22
|
+
// appearance cannot be trusted there.
|
|
23
|
+
backgroundQueryBrokenOn: ["darwin"],
|
|
24
|
+
} as const satisfies TerminalMultiplexerModule;
|
|
@@ -83,9 +83,9 @@ const PINNED_NATIVE_PRIORITY = 1000;
|
|
|
83
83
|
/**
|
|
84
84
|
* Segments a TSP terminal shows outside the composer's facts: the model chip,
|
|
85
85
|
* the context hairline and usage text (context, cost), Tern's pane header
|
|
86
|
-
* (path
|
|
87
|
-
*
|
|
88
|
-
*
|
|
86
|
+
* (path), the tab title (session name, PR), the HUD pills (subagents), the
|
|
87
|
+
* editor (vim) and the brand (`pi`; while focus-proxied, the viewed agent is
|
|
88
|
+
* the composer's viewing header).
|
|
89
89
|
*/
|
|
90
90
|
const COMPOSER_HOMED_SEGMENTS: Partial<Record<StatusLineSegmentId, true>> = {
|
|
91
91
|
pi: true,
|
|
@@ -94,7 +94,6 @@ const COMPOSER_HOMED_SEGMENTS: Partial<Record<StatusLineSegmentId, true>> = {
|
|
|
94
94
|
context_total: true,
|
|
95
95
|
cost: true,
|
|
96
96
|
path: true,
|
|
97
|
-
git: true,
|
|
98
97
|
pr: true,
|
|
99
98
|
session_name: true,
|
|
100
99
|
subagents: true,
|
|
@@ -3519,13 +3518,14 @@ export class StatusLineComponent<TSession extends StatusLineSession = StatusLine
|
|
|
3519
3518
|
#buildComposerFacts(effectiveSettings: EffectiveStatusLineSettings, nowMs: number): ComposerFacts {
|
|
3520
3519
|
const { leftSegments, rightSegments } = effectiveSettings;
|
|
3521
3520
|
const segments = [...leftSegments, ...rightSegments];
|
|
3522
|
-
// Tern's pane header shows the path
|
|
3521
|
+
// Tern's pane header shows the path from the pane's cwd; the branch sits by the model chip.
|
|
3522
|
+
const gitEnabled = this.#gitEnabled();
|
|
3523
3523
|
const ctx = this.#buildSegmentContext(
|
|
3524
3524
|
0,
|
|
3525
3525
|
effectiveSettings.segmentOptions,
|
|
3526
3526
|
false,
|
|
3527
|
-
|
|
3528
|
-
|
|
3527
|
+
gitEnabled && hasGitSegment(segments),
|
|
3528
|
+
gitEnabled && hasPrSegment(segments),
|
|
3529
3529
|
nowMs,
|
|
3530
3530
|
);
|
|
3531
3531
|
const pr = ctx.git.pr ?? undefined;
|
|
@@ -3543,8 +3543,12 @@ export class StatusLineComponent<TSession extends StatusLineSession = StatusLine
|
|
|
3543
3543
|
if (!view) return;
|
|
3544
3544
|
const props: TspProps<"seg"> = {
|
|
3545
3545
|
role: "omp.composer.fact",
|
|
3546
|
-
priority:
|
|
3546
|
+
priority:
|
|
3547
|
+
(PINNED_NATIVE_SEGMENTS[id] === true ? PINNED_NATIVE_PRIORITY : 0) +
|
|
3548
|
+
statusSegmentPriority(side, index, ids.length),
|
|
3547
3549
|
};
|
|
3550
|
+
const action = NATIVE_SEGMENT_ACTIONS[id];
|
|
3551
|
+
if (action) props.actions = { click: action };
|
|
3548
3552
|
facts.push(describeSeg(id, props, view, dim));
|
|
3549
3553
|
});
|
|
3550
3554
|
};
|
|
@@ -678,19 +678,15 @@ const gitSegment: StatusLineSegment = {
|
|
|
678
678
|
const showBranch = opts.showBranch !== false;
|
|
679
679
|
const spans: TspSpan[] = [];
|
|
680
680
|
if (showBranch && branch) spans.push(span(branch, colorName));
|
|
681
|
-
const indicators: TspSpan[] = [];
|
|
682
681
|
if (status) {
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
}
|
|
689
|
-
if (opts.showUntracked !== false && status.untracked > 0) {
|
|
690
|
-
indicators.push(span(`?${status.untracked}`, "statusLineUntracked"));
|
|
691
|
-
}
|
|
682
|
+
// Spans join as one text: each count after the branch or a previous count leads with a space.
|
|
683
|
+
const push = (text: string, token: string): void => {
|
|
684
|
+
spans.push(span(spans.length > 0 ? ` ${text}` : text, token));
|
|
685
|
+
};
|
|
686
|
+
if (opts.showUnstaged !== false && status.unstaged > 0) push(`*${status.unstaged}`, "statusLineDirty");
|
|
687
|
+
if (opts.showStaged !== false && status.staged > 0) push(`+${status.staged}`, "statusLineStaged");
|
|
688
|
+
if (opts.showUntracked !== false && status.untracked > 0) push(`?${status.untracked}`, "statusLineUntracked");
|
|
692
689
|
}
|
|
693
|
-
spans.push(...indicators);
|
|
694
690
|
if (spans.length === 0) return null;
|
|
695
691
|
return segView(spans, showBranch && branch ? "branch" : "git", isDirty ? "warning" : undefined);
|
|
696
692
|
},
|