@oh-my-pi/pi-tui 16.5.1 → 16.5.2

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,17 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
+ ## [16.5.2] - 2026-07-14
6
+
7
+ ### Fixed
8
+
9
+ - Fixed animated Loader ANSI updates causing unnecessary text layout invalidation and re-wrapping on shimmer-only frames (#5230).
10
+ - Fixed Ctrl+W (delete word backward) stopping at underscores in snake_case identifiers, treating them as single words (#4776).
11
+ - Fixed automatic file completion incorrectly treating punctuation, trailing spaces, and slash-command text as paths, and improved autocomplete dismissal behavior (#5376).
12
+ - Fixed Kitty graphics rendering under tmux, ensuring images correctly follow pane scrolling and reflow (#5381).
13
+ - Fixed tmux sessions becoming unresponsive after terminal capability replies by falling back to legacy keyboard input mode when the Kitty protocol is unavailable (#5378).
14
+ - Fixed PageUp and PageDown keys on an empty prompt editor incorrectly navigating prompt history instead of scrolling the editor viewport (#4754).
15
+
5
16
  ## [16.5.1] - 2026-07-14
6
17
 
7
18
  ### Fixed
@@ -1,9 +1,14 @@
1
1
  import type { TUI } from "../tui.js";
2
2
  import { Text } from "./text.js";
3
3
  type ColorFn = (str: string) => string;
4
+ /**
5
+ * Styles Loader message fragments without changing their visible text or width.
6
+ * Set `animated` for colorizers whose ANSI output changes over time.
7
+ */
4
8
  export type LoaderMessageColorFn = ColorFn & {
5
9
  readonly animated?: true;
6
10
  };
11
+ /** Animates a spinner and colorized message while asynchronous work is pending. */
7
12
  export declare class Loader extends Text {
8
13
  #private;
9
14
  private spinnerColorFn;
@@ -26,18 +26,15 @@ export interface KittyGraphicsFeatures {
26
26
  * Whether the detected terminal renders Kitty Unicode placeholders (`U=1` +
27
27
  * U+10EEEE with row/column diacritics).
28
28
  *
29
- * Only `kitty` (the protocol's origin) and `ghostty` ship a working
30
- * implementation; WezTerm advertises Kitty graphics but treats placeholder
31
- * cells as literal PUA glyphs (see wezterm/wezterm#986, "placeholder support"
32
- * still unchecked), and the tmux/screen fallback can land on any outer
33
- * terminal. Enabling placeholders on those paths emits a `columns × rows`
34
- * grid of U+10EEEE per image per frame; the cells render as boxed fallback
35
- * glyphs and re-emit on every repaint, which is exactly the
36
- * "stuck/laggy scrolling + ASCII artifact" symptom reported in #1877.
29
+ * Kitty and Ghostty advertise placeholder support directly. A tmux session
30
+ * cannot use cursor-positioned placements because the outer terminal does not
31
+ * know pane scroll/reflow state, so an explicit `PI_FORCE_IMAGE_PROTOCOL=kitty`
32
+ * also opts into placeholders there matching `timg -pk`. Automatic tmux
33
+ * fallback stays off because the unknown outer terminal may render U+10EEEE as
34
+ * literal PUA boxes (#1877).
37
35
  *
38
- * `PI_NO_KITTY_PLACEHOLDERS=1` forces off (e.g. for tmux passthrough to a
39
- * non-supporting outer terminal); `PI_KITTY_PLACEHOLDERS=1` forces on (e.g.
40
- * for a wezterm nightly that has merged placeholder support).
36
+ * `PI_NO_KITTY_PLACEHOLDERS=1` and `PI_KITTY_PLACEHOLDERS=0` remain hard
37
+ * opt-outs; `PI_KITTY_PLACEHOLDERS=1` explicitly opts in anywhere else.
41
38
  */
42
39
  export declare function detectKittyUnicodePlaceholdersSupport(terminalId: string, env?: NodeJS.ProcessEnv): boolean;
43
40
  export declare function getKittyGraphics(): Readonly<KittyGraphicsFeatures>;
@@ -1,3 +1,4 @@
1
+ export { isInsideTmux, wrapTmuxPassthrough } from "./tmux.js";
1
2
  export declare enum ImageProtocol {
2
3
  Kitty = "\u001B_G",
3
4
  Iterm2 = "\u001B]1337;File=",
@@ -34,12 +35,6 @@ export declare class TerminalInfo {
34
35
  formatNotification(message: string | TerminalNotification): string;
35
36
  sendNotification(message: string | TerminalNotification): void;
36
37
  }
37
- /**
38
- * Whether the agent process is running inside a tmux session. Read fresh on
39
- * each call so tests can toggle `Bun.env.TMUX` per case without re-importing
40
- * the module and so a tmux session attached/detached mid-run is observed.
41
- */
42
- export declare function isInsideTmux(env?: NodeJS.ProcessEnv): boolean;
43
38
  /** Detect terminal multiplexers where scrollback clearing and height-change redraws are hostile. */
44
39
  export declare function isInsideTerminalMultiplexer(env?: NodeJS.ProcessEnv): boolean;
45
40
  /**
@@ -48,19 +43,6 @@ export declare function isInsideTerminalMultiplexer(env?: NodeJS.ProcessEnv): bo
48
43
  * is observed and tests can toggle `Bun.env.ZELLIJ` per case.
49
44
  */
50
45
  export declare function isInsideZellij(env?: NodeJS.ProcessEnv): boolean;
51
- /**
52
- * Wrap a control-sequence payload in tmux's DCS passthrough envelope. Each
53
- * ESC byte inside `payload` is doubled per tmux's escape rules. tmux strips
54
- * the envelope and forwards the unwrapped payload to the outer terminal only
55
- * when the user opts in with `set -g allow-passthrough on`; otherwise tmux
56
- * silently consumes the envelope, which is identical to the pre-wrap baseline
57
- * (tmux already swallowed the bare OSC).
58
- *
59
- * Used by `TerminalInfo.sendNotification` and the OSC 99 capability probe in
60
- * `terminal.ts` to keep notifications alive for terminals that understand
61
- * OSC 9 / OSC 99 (kitty, ghostty, wezterm, iterm2) when running under tmux.
62
- */
63
- export declare function wrapTmuxPassthrough(payload: string): string;
64
46
  export declare function isNotificationSuppressed(): boolean;
65
47
  /**
66
48
  * Returns true when running in Windows Terminal with known SIXEL support.
@@ -0,0 +1,6 @@
1
+ /** Whether the process is running inside a tmux session. */
2
+ export declare function isInsideTmux(env?: NodeJS.ProcessEnv): boolean;
3
+ /** Wrap a control sequence in tmux's DCS passthrough envelope. */
4
+ export declare function wrapTmuxPassthrough(payload: string): string;
5
+ /** Pass a control sequence through tmux, leaving direct-terminal output unchanged. */
6
+ export declare function wrapTmuxPassthroughIfNeeded(payload: string, env?: NodeJS.ProcessEnv): string;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "@oh-my-pi/pi-tui",
4
- "version": "16.5.1",
4
+ "version": "16.5.2",
5
5
  "description": "Terminal User Interface library with differential rendering for efficient text-based applications",
6
6
  "homepage": "https://omp.sh",
7
7
  "author": "Can Boluk",
@@ -37,8 +37,8 @@
37
37
  "fmt": "biome format --write ."
38
38
  },
39
39
  "dependencies": {
40
- "@oh-my-pi/pi-natives": "16.5.1",
41
- "@oh-my-pi/pi-utils": "16.5.1",
40
+ "@oh-my-pi/pi-natives": "16.5.2",
41
+ "@oh-my-pi/pi-utils": "16.5.2",
42
42
  "lru-cache": "11.5.2",
43
43
  "marked": "^18.0.6"
44
44
  },
@@ -456,6 +456,10 @@ export class CombinedAutocompleteProvider implements AutocompleteProvider {
456
456
  prefix: isMidPromptSkillLookup ? commandText : textBeforeCursor,
457
457
  };
458
458
  }
459
+ if (!isMidPromptSkillLookup && slashStart === leadingSlashStart && !commandText.slice(1).includes("/")) {
460
+ return null;
461
+ }
462
+
459
463
  // A slash token with no matching command may still be an absolute
460
464
  // path (`/tmp/fo` at prompt start, `see /tmp` mid-prompt); fall
461
465
  // through to file-path completion.
@@ -679,15 +683,14 @@ export class CombinedAutocompleteProvider implements AutocompleteProvider {
679
683
  return pathPrefix;
680
684
  }
681
685
 
682
- // For natural triggers, return if it looks like a path, ends with /, starts with ~/, .
683
- // Only return empty string if the text looks like it's starting a path context
684
- if (pathPrefix.includes("/") || pathPrefix.startsWith(".") || pathPrefix.startsWith("~/")) {
685
- return pathPrefix;
686
- }
687
-
688
- // Return empty string only after a space (not for completely empty text)
689
- // Empty text should not trigger file suggestions - that's for forced Tab completion
690
- if (pathPrefix === "" && text.endsWith(" ")) {
686
+ // Automatic updates complete only unambiguous path syntax. Bare relative
687
+ // tokens remain available through explicit Tab completion.
688
+ if (
689
+ pathPrefix.startsWith("/") ||
690
+ pathPrefix.startsWith("./") ||
691
+ pathPrefix.startsWith("../") ||
692
+ pathPrefix.startsWith("~/")
693
+ ) {
691
694
  return pathPrefix;
692
695
  }
693
696
 
@@ -1364,21 +1364,14 @@ export class Editor implements Component, Focusable {
1364
1364
  } else if (kb.matches(data, "tui.editor.cursorLineEnd")) {
1365
1365
  this.#moveToLineEnd();
1366
1366
  }
1367
- // Page navigation (PageUp/PageDown)
1367
+ // Page navigation (PageUp/PageDown): page the editor viewport only. On a
1368
+ // short draft this is a no-op — it never steps prompt history (that stays
1369
+ // on Up/Down), so an idle empty editor swallows the keys instead of
1370
+ // surprising the user by loading the previous prompt (#4754).
1368
1371
  else if (kb.matches(data, "tui.editor.pageUp")) {
1369
- if (this.#isEditorEmpty()) {
1370
- this.#navigateHistory(-1);
1371
- } else if (this.#historyIndex > -1 && this.#isOnFirstVisualLine()) {
1372
- this.#navigateHistory(-1);
1373
- } else {
1374
- this.#pageScroll(-1);
1375
- }
1372
+ this.#pageScroll(-1);
1376
1373
  } else if (kb.matches(data, "tui.editor.pageDown")) {
1377
- if (this.#historyIndex > -1 && this.#isOnLastVisualLine()) {
1378
- this.#navigateHistory(1);
1379
- } else {
1380
- this.#pageScroll(1);
1381
- }
1374
+ this.#pageScroll(1);
1382
1375
  }
1383
1376
  // Forward delete (Fn+Backspace or Delete key, including Shift+Delete)
1384
1377
  else if (kb.matches(data, "tui.editor.deleteCharForward") || matchesKey(data, "shift+delete")) {
@@ -2077,15 +2070,13 @@ export class Editor implements Component, Focusable {
2077
2070
  this.#resetKillSequence();
2078
2071
  this.#recordUndoState();
2079
2072
 
2080
- let removedMidPromptSlashTrigger = false;
2073
+ let removedSlashTrigger = false;
2081
2074
 
2082
2075
  if (this.#state.cursorCol > 0) {
2083
2076
  const line = this.#state.lines[this.#state.cursorLine] || "";
2084
2077
  const textBeforeCursor = line.slice(0, this.#state.cursorCol);
2085
2078
  const trailingSlashStart = findTrailingSlashCommandStart(textBeforeCursor);
2086
- removedMidPromptSlashTrigger =
2087
- trailingSlashStart === this.#state.cursorCol - 1 &&
2088
- (!this.#hasOnlyWhitespaceBeforeCursorLine() || textBeforeCursor.slice(0, trailingSlashStart).trim() !== "");
2079
+ removedSlashTrigger = trailingSlashStart === this.#state.cursorCol - 1;
2089
2080
  // An atomic placeholder token (image/paste marker) deletes as a unit, so a single
2090
2081
  // backspace never leaves a half-eaten `[Paste #1, +30 lines` behind as stray text.
2091
2082
  const token = this.#atomicTokenAt(line, this.#state.cursorCol - 1);
@@ -2125,7 +2116,7 @@ export class Editor implements Component, Focusable {
2125
2116
 
2126
2117
  // Update or re-trigger autocomplete after backspace
2127
2118
  if (this.#autocompleteState) {
2128
- if (removedMidPromptSlashTrigger) {
2119
+ if (removedSlashTrigger) {
2129
2120
  this.#cancelAutocomplete();
2130
2121
  this.onAutocompleteUpdate?.();
2131
2122
  } else {
@@ -3046,17 +3037,17 @@ export class Editor implements Component, Focusable {
3046
3037
  } else if (this.#isInMidPromptSkillSlashContext()) {
3047
3038
  await this.#handleSlashCommandCompletion();
3048
3039
  if (!this.#autocompleteState) {
3049
- await this.#forceFileAutocomplete(true);
3040
+ await this.#forceFileAutocomplete();
3050
3041
  }
3051
3042
  } else {
3052
- await this.#forceFileAutocomplete(true);
3043
+ await this.#forceFileAutocomplete();
3053
3044
  }
3054
3045
  }
3055
3046
  async #handleSlashCommandCompletion(): Promise<void> {
3056
3047
  await this.#tryTriggerAutocomplete();
3057
3048
  }
3058
3049
 
3059
- async #forceFileAutocomplete(explicitTab: boolean = false): Promise<void> {
3050
+ async #forceFileAutocomplete(): Promise<void> {
3060
3051
  if (!this.#autocompleteProvider) return;
3061
3052
 
3062
3053
  // File-aware providers expose getForceFileSuggestions; slash-only ones fall back to regular completion.
@@ -3076,27 +3067,6 @@ export class Editor implements Component, Focusable {
3076
3067
  if (requestId !== this.#autocompleteRequestId) return;
3077
3068
 
3078
3069
  if (suggestions && Array.isArray(suggestions.items) && suggestions.items.length > 0) {
3079
- // If there's exactly one suggestion and this was an explicit Tab press, apply it immediately
3080
- if (explicitTab && suggestions.items.length === 1) {
3081
- const item = suggestions.items[0]!;
3082
- const result = this.#autocompleteProvider.applyCompletion(
3083
- this.#state.lines,
3084
- this.#state.cursorLine,
3085
- this.#state.cursorCol,
3086
- item,
3087
- suggestions.prefix,
3088
- );
3089
-
3090
- this.#state.lines = result.lines;
3091
- this.#state.cursorLine = result.cursorLine;
3092
- this.#setCursorCol(result.cursorCol);
3093
-
3094
- if (this.onChange) {
3095
- this.onChange(this.getText());
3096
- }
3097
- return;
3098
- }
3099
-
3100
3070
  this.#autocompletePrefix = suggestions.prefix;
3101
3071
  this.#autocompleteList = this.#createAutocompleteList(suggestions.prefix, suggestions.items);
3102
3072
  this.#autocompleteState = "force";
@@ -1,28 +1,29 @@
1
1
  import type { TUI } from "../tui";
2
- import { sliceByColumn, visibleWidth } from "../utils";
2
+ import { getPaddingX, sliceByColumn, visibleWidth } from "../utils";
3
3
  import { Text } from "./text";
4
4
 
5
- /**
6
- * Loader component. Spinner frames advance at `SPINNER_ADVANCE_MS`.
7
- *
8
- * Message colorizers that are time-dependent can opt into 30fps redraws by
9
- * setting `animated` to `true` on the function object.
10
- */
11
5
  const RENDER_INTERVAL_MS = 1000 / 30;
12
6
  const SPINNER_ADVANCE_MS = 80;
13
7
 
14
8
  type ColorFn = (str: string) => string;
15
9
 
10
+ /**
11
+ * Styles Loader message fragments without changing their visible text or width.
12
+ * Set `animated` for colorizers whose ANSI output changes over time.
13
+ */
16
14
  export type LoaderMessageColorFn = ColorFn & {
17
15
  readonly animated?: true;
18
16
  };
19
17
 
18
+ /** Animates a spinner and colorized message while asynchronous work is pending. */
20
19
  export class Loader extends Text {
21
20
  #frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"];
22
21
  #currentFrame = 0;
23
22
  #intervalId?: NodeJS.Timeout;
24
23
  #ui: TUI | null = null;
25
24
  #lastSpinnerTick = 0;
25
+ #layoutSource?: readonly string[];
26
+ #layout?: readonly { leading: string; content: string; trailing: string }[];
26
27
 
27
28
  constructor(
28
29
  ui: TUI,
@@ -40,11 +41,36 @@ export class Loader extends Text {
40
41
  }
41
42
 
42
43
  render(width: number): readonly string[] {
43
- const lines = ["", ...super.render(width)];
44
- for (let i = 0; i < lines.length; i++) {
45
- const line = lines[i];
46
- if (visibleWidth(line) > width) {
47
- lines[i] = sliceByColumn(line, 0, width, true);
44
+ const source = super.render(width);
45
+ if (source !== this.#layoutSource) {
46
+ const paddingX = getPaddingX(1);
47
+ this.#layoutSource = source;
48
+ this.#layout = source.map(line => {
49
+ const clamped = visibleWidth(line) > width ? sliceByColumn(line, 0, width, true) : line;
50
+ const body = clamped.slice(paddingX);
51
+ const content = body.trimEnd();
52
+ return {
53
+ leading: clamped.slice(0, paddingX),
54
+ content,
55
+ trailing: body.slice(content.length),
56
+ };
57
+ });
58
+ }
59
+
60
+ const frame = this.#frames[this.#currentFrame];
61
+ const lines = [""];
62
+ const layout = this.#layout ?? [];
63
+ for (let i = 0; i < layout.length; i++) {
64
+ const { leading, content, trailing } = layout[i];
65
+ if (i === 0 && content.startsWith(frame)) {
66
+ const remainder = content.slice(frame.length);
67
+ const separator = remainder.startsWith(" ") ? " " : "";
68
+ const message = remainder.slice(separator.length);
69
+ lines.push(
70
+ `${leading}${this.spinnerColorFn(frame)}${separator}${message ? this.messageColorFn(message) : ""}${trailing}`,
71
+ );
72
+ } else {
73
+ lines.push(`${leading}${content ? this.messageColorFn(content) : ""}${trailing}`);
48
74
  }
49
75
  }
50
76
  return lines;
@@ -91,8 +117,8 @@ export class Loader extends Text {
91
117
 
92
118
  #updateDisplay() {
93
119
  const frame = this.#frames[this.#currentFrame];
94
- const text = `${this.spinnerColorFn(frame)} ${this.messageColorFn(this.message)}`;
95
- if (this.setText(text) && this.#ui) {
120
+ const textChanged = this.setText(`${frame} ${this.message}`);
121
+ if ((textChanged || this.messageColorFn.animated === true) && this.#ui) {
96
122
  // Direct write: a loader tick changes only this component, so the TUI
97
123
  // can update the already-positioned rows without driving the full
98
124
  // compose/prepare/diff pipeline. Lightweight test stubs may not carry
@@ -15,6 +15,8 @@
15
15
  * forms. Protocol gating (`imageProtocol === Kitty`) lives in the caller.
16
16
  */
17
17
 
18
+ import { wrapTmuxPassthroughIfNeeded } from "./tmux";
19
+
18
20
  /** Kitty Unicode placeholder base character (U+10EEEE, Plane 16 PUA). */
19
21
  export const KITTY_PLACEHOLDER = "\u{10eeee}";
20
22
 
@@ -60,18 +62,15 @@ export interface KittyGraphicsFeatures {
60
62
  * Whether the detected terminal renders Kitty Unicode placeholders (`U=1` +
61
63
  * U+10EEEE with row/column diacritics).
62
64
  *
63
- * Only `kitty` (the protocol's origin) and `ghostty` ship a working
64
- * implementation; WezTerm advertises Kitty graphics but treats placeholder
65
- * cells as literal PUA glyphs (see wezterm/wezterm#986, "placeholder support"
66
- * still unchecked), and the tmux/screen fallback can land on any outer
67
- * terminal. Enabling placeholders on those paths emits a `columns × rows`
68
- * grid of U+10EEEE per image per frame; the cells render as boxed fallback
69
- * glyphs and re-emit on every repaint, which is exactly the
70
- * "stuck/laggy scrolling + ASCII artifact" symptom reported in #1877.
65
+ * Kitty and Ghostty advertise placeholder support directly. A tmux session
66
+ * cannot use cursor-positioned placements because the outer terminal does not
67
+ * know pane scroll/reflow state, so an explicit `PI_FORCE_IMAGE_PROTOCOL=kitty`
68
+ * also opts into placeholders there matching `timg -pk`. Automatic tmux
69
+ * fallback stays off because the unknown outer terminal may render U+10EEEE as
70
+ * literal PUA boxes (#1877).
71
71
  *
72
- * `PI_NO_KITTY_PLACEHOLDERS=1` forces off (e.g. for tmux passthrough to a
73
- * non-supporting outer terminal); `PI_KITTY_PLACEHOLDERS=1` forces on (e.g.
74
- * for a wezterm nightly that has merged placeholder support).
72
+ * `PI_NO_KITTY_PLACEHOLDERS=1` and `PI_KITTY_PLACEHOLDERS=0` remain hard
73
+ * opt-outs; `PI_KITTY_PLACEHOLDERS=1` explicitly opts in anywhere else.
75
74
  */
76
75
  export function detectKittyUnicodePlaceholdersSupport(terminalId: string, env: NodeJS.ProcessEnv = Bun.env): boolean {
77
76
  const offRaw = env.PI_NO_KITTY_PLACEHOLDERS?.trim().toLowerCase();
@@ -79,6 +78,7 @@ export function detectKittyUnicodePlaceholdersSupport(terminalId: string, env: N
79
78
  const force = env.PI_KITTY_PLACEHOLDERS?.trim().toLowerCase();
80
79
  if (force === "1" || force === "true" || force === "on" || force === "yes" || force === "y") return true;
81
80
  if (force === "0" || force === "false" || force === "off" || force === "no" || force === "n") return false;
81
+ if (env.TMUX && env.PI_FORCE_IMAGE_PROTOCOL?.trim().toLowerCase() === "kitty") return true;
82
82
  return terminalId === "kitty" || terminalId === "ghostty";
83
83
  }
84
84
 
@@ -120,7 +120,7 @@ export function encodeKittyVirtualPlacement(opts: {
120
120
  const params = ["a=p", "U=1", "q=2", `i=${opts.imageId}`];
121
121
  if (opts.placementId) params.push(`p=${opts.placementId}`);
122
122
  params.push(`c=${opts.columns}`, `r=${opts.rows}`);
123
- return `\x1b_G${params.join(",")}\x1b\\`;
123
+ return wrapTmuxPassthroughIfNeeded(`\x1b_G${params.join(",")}\x1b\\`);
124
124
  }
125
125
 
126
126
  /**
@@ -9,6 +9,9 @@ import {
9
9
  renderKittyPlaceholderLines,
10
10
  setKittyGraphics,
11
11
  } from "./kitty-graphics";
12
+ import { isInsideTmux, wrapTmuxPassthrough, wrapTmuxPassthroughIfNeeded } from "./tmux";
13
+
14
+ export { isInsideTmux, wrapTmuxPassthrough } from "./tmux";
12
15
 
13
16
  export enum ImageProtocol {
14
17
  Kitty = "\x1b_G",
@@ -142,15 +145,6 @@ export class TerminalInfo {
142
145
  }
143
146
  }
144
147
 
145
- /**
146
- * Whether the agent process is running inside a tmux session. Read fresh on
147
- * each call so tests can toggle `Bun.env.TMUX` per case without re-importing
148
- * the module and so a tmux session attached/detached mid-run is observed.
149
- */
150
- export function isInsideTmux(env: NodeJS.ProcessEnv = Bun.env): boolean {
151
- return Boolean(env.TMUX);
152
- }
153
-
154
148
  /** Detect terminal multiplexers where scrollback clearing and height-change redraws are hostile. */
155
149
  export function isInsideTerminalMultiplexer(env: NodeJS.ProcessEnv = Bun.env): boolean {
156
150
  // TMUX/STY/ZELLIJ/CMUX workspace+surface ids are authoritative session
@@ -172,22 +166,6 @@ export function isInsideZellij(env: NodeJS.ProcessEnv = Bun.env): boolean {
172
166
  return Boolean(env.ZELLIJ);
173
167
  }
174
168
 
175
- /**
176
- * Wrap a control-sequence payload in tmux's DCS passthrough envelope. Each
177
- * ESC byte inside `payload` is doubled per tmux's escape rules. tmux strips
178
- * the envelope and forwards the unwrapped payload to the outer terminal only
179
- * when the user opts in with `set -g allow-passthrough on`; otherwise tmux
180
- * silently consumes the envelope, which is identical to the pre-wrap baseline
181
- * (tmux already swallowed the bare OSC).
182
- *
183
- * Used by `TerminalInfo.sendNotification` and the OSC 99 capability probe in
184
- * `terminal.ts` to keep notifications alive for terminals that understand
185
- * OSC 9 / OSC 99 (kitty, ghostty, wezterm, iterm2) when running under tmux.
186
- */
187
- export function wrapTmuxPassthrough(payload: string): string {
188
- return `\x1bPtmux;${payload.replaceAll("\x1b", "\x1b\x1b")}\x1b\\`;
189
- }
190
-
191
169
  export function isNotificationSuppressed(): boolean {
192
170
  const value = $env.PI_NOTIFICATIONS;
193
171
  if (!value) return false;
@@ -628,7 +606,7 @@ export function setCellDimensions(dims: CellDimensions): void {
628
606
  function chunkKittyApc(leadParams: string, base64Data: string): string {
629
607
  const CHUNK_SIZE = 4096;
630
608
  if (base64Data.length <= CHUNK_SIZE) {
631
- return `\x1b_G${leadParams};${base64Data}\x1b\\`;
609
+ return wrapTmuxPassthroughIfNeeded(`\x1b_G${leadParams};${base64Data}\x1b\\`);
632
610
  }
633
611
 
634
612
  const chunks: string[] = [];
@@ -640,12 +618,12 @@ function chunkKittyApc(leadParams: string, base64Data: string): string {
640
618
  const isLast = offset + CHUNK_SIZE >= base64Data.length;
641
619
 
642
620
  if (isFirst) {
643
- chunks.push(`\x1b_G${leadParams},m=1;${chunk}\x1b\\`);
621
+ chunks.push(wrapTmuxPassthroughIfNeeded(`\x1b_G${leadParams},m=1;${chunk}\x1b\\`));
644
622
  isFirst = false;
645
623
  } else if (isLast) {
646
- chunks.push(`\x1b_Gm=0;${chunk}\x1b\\`);
624
+ chunks.push(wrapTmuxPassthroughIfNeeded(`\x1b_Gq=2,m=0;${chunk}\x1b\\`));
647
625
  } else {
648
- chunks.push(`\x1b_Gm=1;${chunk}\x1b\\`);
626
+ chunks.push(wrapTmuxPassthroughIfNeeded(`\x1b_Gq=2,m=1;${chunk}\x1b\\`));
649
627
  }
650
628
 
651
629
  offset += CHUNK_SIZE;
@@ -699,7 +677,7 @@ export function encodeKittyPlacement(options: {
699
677
  if (options.placementId) params.push(`p=${options.placementId}`);
700
678
  if (options.columns) params.push(`c=${options.columns}`);
701
679
  if (options.rows) params.push(`r=${options.rows}`);
702
- return `\x1b_G${params.join(",")}\x1b\\`;
680
+ return wrapTmuxPassthroughIfNeeded(`\x1b_G${params.join(",")}\x1b\\`);
703
681
  }
704
682
 
705
683
  /**
@@ -710,7 +688,7 @@ export function encodeKittyPlacement(options: {
710
688
  * this is the only way to actually purge a placed image.
711
689
  */
712
690
  export function encodeKittyDeleteImage(imageId: number): string {
713
- return `\x1b_Ga=d,d=I,i=${imageId},q=2\x1b\\`;
691
+ return wrapTmuxPassthroughIfNeeded(`\x1b_Ga=d,d=I,i=${imageId},q=2\x1b\\`);
714
692
  }
715
693
 
716
694
  export function encodeITerm2(
package/src/terminal.ts CHANGED
@@ -45,6 +45,7 @@ export function resolveHangulCompatibilityJamoWidthFromTerminalIdentity(
45
45
  }
46
46
 
47
47
  function shouldEnableModifyOtherKeysFallback(env: NodeJS.ProcessEnv = Bun.env): boolean {
48
+ if (isInsideTmux(env)) return false;
48
49
  if (!env.SSH_CONNECTION && !env.SSH_TTY && !env.SSH_CLIENT) return true;
49
50
  return TERMINAL.id !== "base" && TERMINAL.id !== "trueColor";
50
51
  }
package/src/tmux.ts ADDED
@@ -0,0 +1,14 @@
1
+ /** Whether the process is running inside a tmux session. */
2
+ export function isInsideTmux(env: NodeJS.ProcessEnv = Bun.env): boolean {
3
+ return Boolean(env.TMUX);
4
+ }
5
+
6
+ /** Wrap a control sequence in tmux's DCS passthrough envelope. */
7
+ export function wrapTmuxPassthrough(payload: string): string {
8
+ return `\x1bPtmux;${payload.replaceAll("\x1b", "\x1b\x1b")}\x1b\\`;
9
+ }
10
+
11
+ /** Pass a control sequence through tmux, leaving direct-terminal output unchanged. */
12
+ export function wrapTmuxPassthroughIfNeeded(payload: string, env: NodeJS.ProcessEnv = Bun.env): string {
13
+ return isInsideTmux(env) ? wrapTmuxPassthrough(payload) : payload;
14
+ }
package/src/utils.ts CHANGED
@@ -394,6 +394,7 @@ export function getWordNavKind(grapheme: string): WordNavKind {
394
394
  const ch = firstCodePointChar(grapheme);
395
395
  if (!ch) return "other";
396
396
  if (WORD_NAV_RE_WHITESPACE.test(ch)) return "whitespace";
397
+ if (ch === "_") return "word";
397
398
  if (WORD_NAV_RE_PUNCT.test(ch) || WORD_NAV_RE_SYMBOL.test(ch)) return "delimiter";
398
399
  if (
399
400
  WORD_NAV_RE_HAN.test(ch) ||
@@ -403,7 +404,7 @@ export function getWordNavKind(grapheme: string): WordNavKind {
403
404
  ) {
404
405
  return "cjk";
405
406
  }
406
- if (ch === "_" || WORD_NAV_RE_LETTER.test(ch) || WORD_NAV_RE_NUMBER.test(ch)) return "word";
407
+ if (WORD_NAV_RE_LETTER.test(ch) || WORD_NAV_RE_NUMBER.test(ch)) return "word";
407
408
  return "other";
408
409
  }
409
410