@linxiraos/pi-tui 1.4.13 → 1.5.1

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.
Files changed (94) hide show
  1. package/CHANGELOG.md +33 -34
  2. package/dist/types/chat/messages.d.ts +2 -0
  3. package/dist/types/chat/spotlight.d.ts +8 -3
  4. package/dist/types/chat/transcript-render-helpers.d.ts +5 -0
  5. package/dist/types/components/editor.d.ts +4 -1
  6. package/dist/types/html-form/data.d.ts +56 -0
  7. package/dist/types/html-form/dialog.d.ts +51 -0
  8. package/dist/types/html-form/media.d.ts +28 -0
  9. package/dist/types/html-form/paginate.d.ts +43 -0
  10. package/dist/types/html-form/parse.d.ts +99 -0
  11. package/dist/types/overlays/ask-dialog.d.ts +11 -6
  12. package/dist/types/overlays/copy-targets.d.ts +8 -6
  13. package/dist/types/overlays/directory-picker.d.ts +62 -0
  14. package/dist/types/overlays/hook-editor.d.ts +3 -1
  15. package/dist/types/overlays/hub-frame.d.ts +2 -0
  16. package/dist/types/overlays/model-hub.d.ts +2 -0
  17. package/dist/types/overlays/team-hub.d.ts +150 -0
  18. package/dist/types/render/row-moves.d.ts +41 -0
  19. package/dist/types/status-line/component.d.ts +5 -0
  20. package/dist/types/status-line/host.d.ts +2 -2
  21. package/dist/types/status-line/schema.d.ts +1 -1
  22. package/dist/types/status-line/types.d.ts +8 -0
  23. package/dist/types/tools/ask.d.ts +11 -49
  24. package/dist/types/tools/autoresearch.d.ts +2 -2
  25. package/dist/types/tools/eval.d.ts +4 -0
  26. package/dist/types/tools/grouped-file-output.d.ts +2 -0
  27. package/dist/types/tools/shell-viz.d.ts +6 -2
  28. package/dist/types/tools/xd-url.d.ts +6 -0
  29. package/dist/types/windows-input-mode.d.ts +8 -0
  30. package/package.json +9 -9
  31. package/src/charts/table-data.ts +18 -5
  32. package/src/chat/chat-transcript-builder.ts +27 -10
  33. package/src/chat/image-loading.ts +55 -0
  34. package/src/chat/messages.d.ts +2 -0
  35. package/src/chat/messages.ts +3 -0
  36. package/src/chat/spotlight.d.ts +8 -3
  37. package/src/chat/spotlight.ts +23 -11
  38. package/src/chat/tool-execution.ts +5 -0
  39. package/src/chat/transcript-render-helpers.d.ts +5 -0
  40. package/src/chat/transcript-render-helpers.ts +13 -0
  41. package/src/chrome/transcript-container.ts +1 -1
  42. package/src/components/editor.d.ts +4 -1
  43. package/src/components/editor.ts +3 -2
  44. package/src/components/markdown.ts +70 -12
  45. package/src/html-form/data.d.ts +56 -0
  46. package/src/html-form/data.ts +177 -0
  47. package/src/html-form/dialog.ts +1450 -0
  48. package/src/html-form/media.ts +105 -0
  49. package/src/html-form/paginate.ts +99 -0
  50. package/src/html-form/parse.d.ts +99 -0
  51. package/src/html-form/parse.ts +568 -0
  52. package/src/lang-from-path.ts +1 -0
  53. package/src/latex-block.ts +3 -3
  54. package/src/latex-to-unicode.ts +18 -5
  55. package/src/overlays/ask-dialog.ts +69 -52
  56. package/src/overlays/copy-targets.d.ts +8 -6
  57. package/src/overlays/copy-targets.ts +25 -46
  58. package/src/overlays/directory-picker.ts +387 -0
  59. package/src/overlays/hook-editor.ts +16 -15
  60. package/src/overlays/hub-frame.ts +8 -1
  61. package/src/overlays/model-hub.ts +12 -2
  62. package/src/overlays/spotlight-sheet.ts +18 -18
  63. package/src/overlays/team-hub.ts +901 -0
  64. package/src/render/row-moves.d.ts +41 -0
  65. package/src/render/row-moves.ts +109 -0
  66. package/src/setup/wizard-overlay.ts +7 -3
  67. package/src/status-line/component.ts +19 -0
  68. package/src/status-line/footer.ts +2 -2
  69. package/src/status-line/host.ts +2 -2
  70. package/src/status-line/presets.ts +6 -6
  71. package/src/status-line/schema.ts +2 -1
  72. package/src/status-line/segments.ts +31 -4
  73. package/src/status-line/startup.ts +1 -1
  74. package/src/status-line/types.ts +8 -0
  75. package/src/stdin-buffer.ts +15 -1
  76. package/src/terminal-capabilities.ts +12 -3
  77. package/src/terminal.ts +41 -3
  78. package/src/tools/ask.d.ts +11 -49
  79. package/src/tools/ask.ts +201 -606
  80. package/src/tools/autoresearch.ts +2 -2
  81. package/src/tools/debug.ts +31 -38
  82. package/src/tools/eval.d.ts +4 -0
  83. package/src/tools/eval.ts +4 -0
  84. package/src/tools/grep.ts +38 -16
  85. package/src/tools/grouped-file-output.d.ts +2 -0
  86. package/src/tools/grouped-file-output.ts +5 -0
  87. package/src/tools/shell-viz-render.ts +37 -6
  88. package/src/tools/shell-viz.d.ts +6 -2
  89. package/src/tools/shell-viz.ts +19 -6
  90. package/src/tools/xd-url.d.ts +6 -0
  91. package/src/tools/xd-url.ts +19 -1
  92. package/src/tui.ts +129 -1
  93. package/src/windows-input-mode.d.ts +8 -0
  94. package/src/windows-input-mode.ts +13 -0
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Row-move planning for paints a terminal may present half-applied.
3
+ *
4
+ * Without synchronized output (DEC 2026) a terminal can show any prefix of a
5
+ * frame's bytes. Repainting a viewport whose content shifted row by row,
6
+ * top-down, then exposes rows already rewritten above rows that have not moved
7
+ * yet, and the seam shows the shifted rows twice. Moving the surviving rows
8
+ * with delete-line/insert-line first keeps every intermediate screen a
9
+ * coherent, shifted copy of the previous frame, and leaves only the rows that
10
+ * really changed to rewrite.
11
+ *
12
+ * Rows are integer keys: {@link BLANK_ROW} for an empty row,
13
+ * {@link UNKNOWN_ROW} for committed history the planner does not model (never
14
+ * matched, never moved), and any other value for one distinct line.
15
+ */
16
+ /** Key of an empty row. */
17
+ export declare const BLANK_ROW = 0;
18
+ /** Key of a row whose content is not modeled; it matches nothing. */
19
+ export declare const UNKNOWN_ROW = -1;
20
+ /** `count` rows starting at screen row `from` move to start at `to`; the rows they vacate turn blank. */
21
+ export interface RowMove {
22
+ readonly from: number;
23
+ readonly to: number;
24
+ readonly count: number;
25
+ }
26
+ /**
27
+ * The band move that turns the most rows of `screen` into `target`, or
28
+ * `undefined` when no move saves a row rewrite. Only rows at or below `base`
29
+ * are moved or vacated. An upward move never lands on row 0: it deletes lines
30
+ * at its destination, and Terminal.app archives lines deleted from the top row
31
+ * into scrollback.
32
+ */
33
+ export declare function findRowMove(screen: readonly number[], target: readonly number[], base: number): RowMove | undefined;
34
+ /** Apply `move` to a screen model, as {@link rowMoveSequence} applies it to the terminal. */
35
+ export declare function applyRowMove(screen: number[], move: RowMove): void;
36
+ /**
37
+ * Terminal bytes performing `move` on a `height`-row screen with default
38
+ * margins: rows outside the band and its vacated rows keep their place. Lines
39
+ * inserted or deleted take the current background, so callers reset SGR first.
40
+ */
41
+ export declare function rowMoveSequence(move: RowMove, height: number): string;
@@ -0,0 +1,109 @@
1
+ /**
2
+ * Row-move planning for paints a terminal may present half-applied.
3
+ *
4
+ * Without synchronized output (DEC 2026) a terminal can show any prefix of a
5
+ * frame's bytes. Repainting a viewport whose content shifted row by row,
6
+ * top-down, then exposes rows already rewritten above rows that have not moved
7
+ * yet, and the seam shows the shifted rows twice. Moving the surviving rows
8
+ * with delete-line/insert-line first keeps every intermediate screen a
9
+ * coherent, shifted copy of the previous frame, and leaves only the rows that
10
+ * really changed to rewrite.
11
+ *
12
+ * Rows are integer keys: {@link BLANK_ROW} for an empty row,
13
+ * {@link UNKNOWN_ROW} for committed history the planner does not model (never
14
+ * matched, never moved), and any other value for one distinct line.
15
+ */
16
+
17
+ /** Key of an empty row. */
18
+ export const BLANK_ROW = 0;
19
+ /** Key of a row whose content is not modeled; it matches nothing. */
20
+ export const UNKNOWN_ROW = -1;
21
+
22
+ /** `count` rows starting at screen row `from` move to start at `to`; the rows they vacate turn blank. */
23
+ export interface RowMove {
24
+ readonly from: number;
25
+ readonly to: number;
26
+ readonly count: number;
27
+ }
28
+
29
+ /**
30
+ * The band move that turns the most rows of `screen` into `target`, or
31
+ * `undefined` when no move saves a row rewrite. Only rows at or below `base`
32
+ * are moved or vacated. An upward move never lands on row 0: it deletes lines
33
+ * at its destination, and Terminal.app archives lines deleted from the top row
34
+ * into scrollback.
35
+ */
36
+ export function findRowMove(screen: readonly number[], target: readonly number[], base: number): RowMove | undefined {
37
+ const height = screen.length;
38
+ // hits[r]: rows above r already matching in place; blanks[r]: rows above r
39
+ // whose target is blank (a vacated row then matches).
40
+ const hits = new Int32Array(height + 1);
41
+ const blanks = new Int32Array(height + 1);
42
+ for (let r = 0; r < height; r++) {
43
+ hits[r + 1] = hits[r]! + (target[r] !== UNKNOWN_ROW && screen[r] === target[r] ? 1 : 0);
44
+ blanks[r + 1] = blanks[r]! + (target[r] === BLANK_ROW ? 1 : 0);
45
+ }
46
+ let best: RowMove | undefined;
47
+ let bestGain = 0;
48
+ // Nearer shifts first, so a tie keeps the smaller move.
49
+ for (let distance = 1; distance < height - base; distance++) {
50
+ for (let sign = 1; sign >= -1; sign -= 2) {
51
+ const shift = sign * distance;
52
+ const first = shift > 0 ? Math.max(base, 1) : base + distance;
53
+ const last = shift > 0 ? height - distance : height;
54
+ let start = -1;
55
+ let content = false;
56
+ for (let r = first; r <= last; r++) {
57
+ if (r < last && target[r] !== UNKNOWN_ROW && screen[r + shift] === target[r]) {
58
+ if (start < 0) start = r;
59
+ if (target[r] !== BLANK_ROW) content = true;
60
+ continue;
61
+ }
62
+ if (start >= 0 && content) {
63
+ const count = r - start;
64
+ // Rows the move rewrites: its destination plus the band it vacates.
65
+ const vacatedStart = shift > 0 ? r : start + shift;
66
+ const vacatedEnd = shift > 0 ? r + shift : start;
67
+ const gain =
68
+ count -
69
+ (hits[r]! - hits[start]!) +
70
+ (blanks[vacatedEnd]! - blanks[vacatedStart]!) -
71
+ (hits[vacatedEnd]! - hits[vacatedStart]!);
72
+ if (gain > bestGain) {
73
+ best = { from: start + shift, to: start, count };
74
+ bestGain = gain;
75
+ }
76
+ }
77
+ start = -1;
78
+ content = false;
79
+ }
80
+ }
81
+ }
82
+ return best;
83
+ }
84
+
85
+ /** Apply `move` to a screen model, as {@link rowMoveSequence} applies it to the terminal. */
86
+ export function applyRowMove(screen: number[], move: RowMove): void {
87
+ const { from, to, count } = move;
88
+ const band = screen.slice(from, from + count);
89
+ if (from < to) screen.fill(BLANK_ROW, from, to);
90
+ else screen.fill(BLANK_ROW, to + count, from + count);
91
+ for (let i = 0; i < count; i++) screen[to + i] = band[i]!;
92
+ }
93
+
94
+ /**
95
+ * Terminal bytes performing `move` on a `height`-row screen with default
96
+ * margins: rows outside the band and its vacated rows keep their place. Lines
97
+ * inserted or deleted take the current background, so callers reset SGR first.
98
+ */
99
+ export function rowMoveSequence(move: RowMove, height: number): string {
100
+ const { from, to, count } = move;
101
+ if (to < from) {
102
+ const shift = from - to;
103
+ const up = `\x1b[${to + 1};1H\x1b[${shift}M`;
104
+ return from + count < height ? `${up}\x1b[${to + count + 1};1H\x1b[${shift}L` : up;
105
+ }
106
+ const shift = to - from;
107
+ const down = `\x1b[${from + 1};1H\x1b[${shift}L`;
108
+ return to + count < height ? `\x1b[${from + count + 1};1H\x1b[${shift}M${down}` : down;
109
+ }
@@ -444,9 +444,9 @@ export class SetupWizardComponent implements Component, OverlayFocusOwner {
444
444
  }
445
445
 
446
446
  /**
447
- * ANSI: repaint every tick and advance timed phases from it. Native: no
448
- * repaint loop; a one-shot fires when the current timed phase ends (none
449
- * while a scene is up). Call again whenever the phase changes.
447
+ * ANSI: repaint during timed phases only. Native: schedule a one-shot at
448
+ * each phase deadline; its renderer clocks the animation. Neither path
449
+ * needs a timer while a scene waits for input.
450
450
  */
451
451
  #startTimer(): void {
452
452
  if (isNativeRendering()) {
@@ -462,6 +462,10 @@ export class SetupWizardComponent implements Component, OverlayFocusOwner {
462
462
  this.#deadline = setTimeout(() => this.#tick(), Math.max(0, remaining));
463
463
  return;
464
464
  }
465
+ if (PHASE_LIMIT_MS[this.#phase] === undefined) {
466
+ this.#stopTimer();
467
+ return;
468
+ }
465
469
  if (this.#timer) return;
466
470
  this.#timer = setInterval(() => this.#tick(), SETUP_TICK_MS);
467
471
  }
@@ -792,6 +792,8 @@ export class StatusLineComponent<TSession extends StatusLineSession = StatusLine
792
792
  #loopModeStatus: SegmentContext["loopMode"] = null;
793
793
  #goalModeStatus: { enabled: boolean; paused: boolean } | null = null;
794
794
  #vibeModeStatus: { enabled: boolean } | null = null;
795
+ #leadModeStatus: { enabled: boolean } | null = null;
796
+ #teamBreadcrumb: SegmentContext["team"] = null;
795
797
  #vimStatus: SegmentContext["vim"] = null;
796
798
  /**
797
799
  * Injected aggregator that returns the aggregate tok/s of this session's
@@ -1225,6 +1227,21 @@ export class StatusLineComponent<TSession extends StatusLineSession = StatusLine
1225
1227
  this.#invalidateStatusLineRenderCache();
1226
1228
  }
1227
1229
 
1230
+ setLeadModeStatus(status: { enabled: boolean } | undefined): void {
1231
+ const next = status ?? null;
1232
+ if (this.#leadModeStatus === next || this.#leadModeStatus?.enabled === next?.enabled) return;
1233
+ this.#leadModeStatus = next;
1234
+ this.#invalidateStatusLineRenderCache();
1235
+ }
1236
+
1237
+ /** Team breadcrumb; `undefined` hides the segment (outside a Team, or a plain subdirectory). */
1238
+ setTeamBreadcrumb(label: string | undefined): void {
1239
+ const next = label ? { label } : null;
1240
+ if (this.#teamBreadcrumb?.label === next?.label) return;
1241
+ this.#teamBreadcrumb = next;
1242
+ this.#invalidateStatusLineRenderCache();
1243
+ }
1244
+
1228
1245
  /** Mirror of the editor's modal state; `undefined` clears it (Vim mode off). */
1229
1246
  setVimStatus(status: NonNullable<SegmentContext["vim"]> | undefined): void {
1230
1247
  const next = status ?? null;
@@ -2720,6 +2737,8 @@ export class StatusLineComponent<TSession extends StatusLineSession = StatusLine
2720
2737
  goalMode: this.#goalModeStatus,
2721
2738
  goalStatusInFooter: this.#goalModeStatus ? this.host.goalStatusInFooter(this.session) : false,
2722
2739
  vibeMode: this.#vibeModeStatus,
2740
+ leadMode: this.#leadModeStatus,
2741
+ team: this.#teamBreadcrumb,
2723
2742
  vim: this.#vimStatus,
2724
2743
  stream: this.#streamStatus,
2725
2744
  recording: this.#recording,
@@ -198,7 +198,7 @@ export class FooterComponent implements Component {
198
198
  for (const [key, glyph, amount] of counters) {
199
199
  if (amount) seg(key, { side: "left", priority: 1, spans: [span(`${glyph}${formatNumber(amount)}`, "dim")] });
200
200
  }
201
- const usingSubscription = state.model ? this.session.modelRegistry.isUsingOAuth(state.model) : false;
201
+ const usingSubscription = state.model ? this.session.modelRegistry.isUsingSubscription(state.model) : false;
202
202
  const billing = formatBillingSummary({ cost, usingSubscription, premiumRequests, fractionDigits: 3 }, theme);
203
203
  if (billing) seg("cost", { side: "left", priority: 3, spans: [span(billing, "dim")] });
204
204
  const contextUsage = this.session.getContextUsage();
@@ -304,7 +304,7 @@ export class FooterComponent implements Component {
304
304
  }
305
305
 
306
306
  // Show billing summary with subscription and premium-request indicators
307
- const usingSubscription = state.model ? this.session.modelRegistry.isUsingOAuth(state.model) : false;
307
+ const usingSubscription = state.model ? this.session.modelRegistry.isUsingSubscription(state.model) : false;
308
308
  const { auto: autoIcon } = theme.icon;
309
309
  const billing = formatBillingSummary(
310
310
  { cost: totalCost, usingSubscription, premiumRequests: totalPremiumRequests, fractionDigits: 3 },
@@ -97,7 +97,7 @@ export interface StatusLineSession {
97
97
  };
98
98
  };
99
99
  modelRegistry: {
100
- isUsingOAuth(model: Model): boolean;
100
+ isUsingSubscription(model: Model): boolean;
101
101
  };
102
102
  getContextUsage(): { tokens: number; contextWindow: number; percent: number | null } | undefined;
103
103
  autoResolvedThinkingLevel(): string | undefined;
@@ -124,7 +124,7 @@ export interface FooterSession {
124
124
  isAutoThinking: boolean;
125
125
  autoResolvedThinkingLevel(): string | undefined;
126
126
  getContextUsage: StatusLineSession["getContextUsage"];
127
- modelRegistry: Pick<StatusLineSession["modelRegistry"], "isUsingOAuth">;
127
+ modelRegistry: Pick<StatusLineSession["modelRegistry"], "isUsingSubscription">;
128
128
  /**
129
129
  * Cumulative session rollup. Unlike the active-window stats it spans every
130
130
  * entry in the session, so compaction does not reset the counters, and it
@@ -3,7 +3,7 @@ import type { PresetDef, StatusLinePreset } from "./types";
3
3
 
4
4
  export const STATUS_LINE_PRESETS: Record<StatusLinePreset, PresetDef> = {
5
5
  default: {
6
- leftSegments: ["pi", "vim", "model", "mode", "stream", "path", "git", "pr", "context_pct", "cost"],
6
+ leftSegments: ["pi", "vim", "model", "mode", "team", "stream", "path", "git", "pr", "context_pct", "cost"],
7
7
  rightSegments: ["session_name"],
8
8
  separator: "powerline-thin",
9
9
  segmentOptions: {
@@ -14,7 +14,7 @@ export const STATUS_LINE_PRESETS: Record<StatusLinePreset, PresetDef> = {
14
14
  },
15
15
 
16
16
  minimal: {
17
- leftSegments: ["vim", "path", "git"],
17
+ leftSegments: ["vim", "team", "path", "git"],
18
18
  rightSegments: ["session_name", "mode", "context_pct"],
19
19
  separator: "slash",
20
20
  segmentOptions: {
@@ -24,7 +24,7 @@ export const STATUS_LINE_PRESETS: Record<StatusLinePreset, PresetDef> = {
24
24
  },
25
25
 
26
26
  compact: {
27
- leftSegments: ["vim", "model", "mode", "git", "pr"],
27
+ leftSegments: ["vim", "model", "mode", "team", "git", "pr"],
28
28
  rightSegments: ["session_name", "cost", "context_pct"],
29
29
  separator: "powerline-thin",
30
30
  segmentOptions: {
@@ -34,7 +34,7 @@ export const STATUS_LINE_PRESETS: Record<StatusLinePreset, PresetDef> = {
34
34
  },
35
35
 
36
36
  full: {
37
- leftSegments: ["pi", "vim", "hostname", "model", "mode", "path", "git", "pr", "subagents"],
37
+ leftSegments: ["pi", "vim", "hostname", "model", "mode", "team", "path", "git", "pr", "subagents"],
38
38
  rightSegments: [
39
39
  "session_name",
40
40
  "cache_hit",
@@ -59,7 +59,7 @@ export const STATUS_LINE_PRESETS: Record<StatusLinePreset, PresetDef> = {
59
59
 
60
60
  nerd: {
61
61
  // Full preset with all Nerd Font icons
62
- leftSegments: ["pi", "vim", "hostname", "model", "mode", "path", "git", "pr", "session", "subagents"],
62
+ leftSegments: ["pi", "vim", "hostname", "model", "mode", "team", "path", "git", "pr", "session", "subagents"],
63
63
  rightSegments: [
64
64
  "session_name",
65
65
  "token_in",
@@ -85,7 +85,7 @@ export const STATUS_LINE_PRESETS: Record<StatusLinePreset, PresetDef> = {
85
85
 
86
86
  ascii: {
87
87
  // No Nerd Font dependencies
88
- leftSegments: ["vim", "model", "mode", "path", "git", "pr"],
88
+ leftSegments: ["vim", "model", "mode", "team", "path", "git", "pr"],
89
89
  rightSegments: ["session_name", "token_total", "cost", "context_pct"],
90
90
  separator: "ascii",
91
91
  segmentOptions: {
@@ -4,6 +4,7 @@ export const STATUS_LINE_SEGMENT_IDS = [
4
4
  "status",
5
5
  "model",
6
6
  "mode",
7
+ "team",
7
8
  "path",
8
9
  "git",
9
10
  "pr",
@@ -38,7 +39,7 @@ export const CUSTOM_STATUS_LINE_DEFAULTS: {
38
39
  readonly left: StatusLineSegmentId[];
39
40
  readonly right: StatusLineSegmentId[];
40
41
  } = {
41
- left: ["vim", "model", "mode", "path", "git", "pr"],
42
+ left: ["vim", "model", "mode", "team", "path", "git", "pr"],
42
43
  right: ["session_name", "token_total", "cost", "context_pct"],
43
44
  };
44
45
 
@@ -534,6 +534,11 @@ const modeSegment: StatusLineSegment = {
534
534
  return { content: accentFg(ctx, "accent", content), visible: true };
535
535
  }
536
536
 
537
+ if (ctx.leadMode?.enabled) {
538
+ const content = withIcon(theme.icon.agents, "Lead");
539
+ return { content: accentFg(ctx, "accent", content), visible: true };
540
+ }
541
+
537
542
  const loop = ctx.loopMode;
538
543
  if (loop) {
539
544
  const icon = loop.state === "paused" ? theme.icon.pause || theme.icon.loop : theme.icon.loop;
@@ -563,6 +568,7 @@ const modeSegment: StatusLineSegment = {
563
568
  const goal = ctx.goalMode;
564
569
  if (goal && (goal.enabled || goal.paused)) return describeGoalMode(ctx, goal);
565
570
  if (ctx.vibeMode?.enabled) return segView([span("Vibe", accentToken(ctx, "accent"))], "agents");
571
+ if (ctx.leadMode?.enabled) return segView([span("Lead", accentToken(ctx, "accent"))], "agents");
566
572
  const loop = ctx.loopMode;
567
573
  if (loop) {
568
574
  const paused = loop.state === "paused";
@@ -581,6 +587,23 @@ const modeSegment: StatusLineSegment = {
581
587
  },
582
588
  };
583
589
 
590
+ /**
591
+ * Team breadcrumb: only rendered inside a resolved Team worktree/repository, so
592
+ * ordinary sessions pay no width. The host supplies a display-only label.
593
+ */
594
+ const teamSegment: StatusLineSegment = {
595
+ id: "team",
596
+ render(ctx) {
597
+ if (!ctx.team) return { content: "", visible: false };
598
+ const label = ctx.team.label;
599
+ return { content: theme.fg("statusLinePath", withIcon(theme.icon.agents, label)), visible: true };
600
+ },
601
+ describe(ctx) {
602
+ if (!ctx.team) return null;
603
+ return segView([span(ctx.team.label, "statusLinePath strong")], "agents");
604
+ },
605
+ };
606
+
584
607
  const pathSegment: StatusLineSegment = {
585
608
  id: "path",
586
609
  render(ctx) {
@@ -810,7 +833,9 @@ function costSummary(ctx: SegmentContext): string | undefined {
810
833
  const pricingPeriod = state.model?.cost
811
834
  ? getTimeBasedPricingPeriod(state.model.cost, ctx.now?.getTime())
812
835
  : undefined;
813
- const usingSubscription = state.model ? (ctx.session.modelRegistry?.isUsingOAuth(state.model) ?? false) : false;
836
+ const usingSubscription = state.model
837
+ ? (ctx.session.modelRegistry?.isUsingSubscription(state.model) ?? false)
838
+ : false;
814
839
  // Resolve the advisor subscription flag lazily: with no active advisor
815
840
  // it walks the whole model catalog (getAvailable → hasAuth per provider
816
841
  // → credential-file reads), and the status line re-renders at the
@@ -1069,9 +1094,10 @@ const sessionNameSegment: StatusLineSegment = {
1069
1094
  const name = sessionManager?.getSessionName() || ctx.previewTitle;
1070
1095
  if (!name) return { content: "", visible: false };
1071
1096
 
1072
- const title = sanitizeStatusText(name);
1073
- const content = ctx.isPinned ? withIcon(theme.icon.pin, title) : title;
1074
- return { content: accentFg(ctx, "accent", content), visible: true };
1097
+ const styledTitle = accentFg(ctx, "accent", sanitizeStatusText(name));
1098
+ const content =
1099
+ ctx.isPinned && theme.icon.pin ? `${theme.fg("accent", theme.icon.pin)} ${styledTitle}` : styledTitle;
1100
+ return { content, visible: true };
1075
1101
  },
1076
1102
  describe(ctx) {
1077
1103
  const name = ctx.session.sessionManager?.getSessionName() || ctx.previewTitle;
@@ -1334,6 +1360,7 @@ export const SEGMENTS: Record<StatusLineSegmentId, StatusLineSegment> = {
1334
1360
  status: statusSegment,
1335
1361
  model: modelSegment,
1336
1362
  mode: modeSegment,
1363
+ team: teamSegment,
1337
1364
  path: pathSegment,
1338
1365
  git: gitSegment,
1339
1366
  pr: prSegment,
@@ -72,7 +72,7 @@ function startupSession(data: StatusLineStartupData): StatusLineSession {
72
72
  getSessionId: () => "",
73
73
  getUsageStatistics: () => NO_USAGE,
74
74
  },
75
- modelRegistry: { isUsingOAuth: () => data.usingSubscription },
75
+ modelRegistry: { isUsingSubscription: () => data.usingSubscription },
76
76
  getContextUsage: () =>
77
77
  data.model?.contextWindow ? { tokens: 0, contextWindow: data.model.contextWindow, percent: null } : undefined,
78
78
  autoResolvedThinkingLevel: () => undefined,
@@ -98,6 +98,14 @@ export interface SegmentContext {
98
98
  vibeMode: {
99
99
  enabled: boolean;
100
100
  } | null;
101
+ /** Lead (PM) mode indicator; optional so existing context fixtures stay valid. */
102
+ leadMode?: {
103
+ enabled: boolean;
104
+ } | null;
105
+ /** Team breadcrumb (`Team / PM / repo / engineer / worktree`) when the cwd resolves into a team. */
106
+ team?: {
107
+ label: string;
108
+ } | null;
101
109
  /** Modal editing state, or null when `tui.vimMode` is off. */
102
110
  vim: {
103
111
  mode: "insert" | "normal" | "visual" | "visual-line" | "replace";
@@ -125,6 +125,19 @@ function isRawMultilineBurst(text: string): boolean {
125
125
  return false;
126
126
  }
127
127
 
128
+ /**
129
+ * Whether a classified raw burst ends with an Enter typed after the pasted
130
+ * text: a final CR when every earlier break is LF. An unmarked paste encodes
131
+ * its breaks one way (terminals send CR, automation writes LF), so a lone CR
132
+ * after LF-delimited text is the submit key a stall batched into the same
133
+ * read (#17820). It rides along with the paste like a bracketed paste's
134
+ * trailing Enter.
135
+ */
136
+ function endsWithTypedEnter(text: string): boolean {
137
+ const last = text.length - 1;
138
+ return text.charCodeAt(last) === 0x0d && text.lastIndexOf("\r", last - 1) === -1;
139
+ }
140
+
128
141
  // `resolveEscapeEnd` result for an abandoned string sequence; see there.
129
142
  const STRING_ABORTED = -3;
130
143
  const OSC5522_PREFIX = "\x1b]5522;";
@@ -855,7 +868,8 @@ export class StdinBuffer extends EventEmitter<StdinBufferEventMap> {
855
868
  }
856
869
  const content = this.#takeRawPasteCandidate();
857
870
  this.#pendingKittyPrintableCodepoint = undefined;
858
- this.emit("paste", content);
871
+ if (endsWithTypedEnter(content)) this.emit("paste", content.slice(0, -1), "\r");
872
+ else this.emit("paste", content);
859
873
  }
860
874
 
861
875
  /** Replay an ambiguous raw candidate as the original per-key data events. */
@@ -645,8 +645,13 @@ const KNOWN_TERMINALS = Object.freeze({
645
645
  // OSC 99, and OSC 66 text sizing are outside rio's supported set and keep
646
646
  // the conservative defaults.
647
647
  rio: new TerminalInfo("rio", ImageProtocol.Kitty, true, true),
648
- // Rex (TERM_PROGRAM=rex / TERM=xterm-rex): only Kitty graphics is confirmed.
649
- rex: new TerminalInfo("rex", ImageProtocol.Kitty, true, false),
648
+ // Rex (Superlogical's terminal) identifies via TERM_PROGRAM=rex, or
649
+ // TERM=xterm-rex over SSH. It renders Kitty graphics and OSC 8
650
+ // hyperlinks — a link opens on command-click, and
651
+ // Settings > Terminal > Links only decides whether an `ssh://`-style link
652
+ // that launches another app asks first — so links are on. Notifications
653
+ // keep the BEL default.
654
+ rex: new TerminalInfo("rex", ImageProtocol.Kitty, true, true),
650
655
  // Tern (Stencil's terminal, `stencil-term`) sets TERM_PROGRAM=tern and
651
656
  // implements Kitty graphics (Unicode placeholders included), OSC 8 and
652
657
  // OSC 9/99 notifications. Whether omp renders natively (Tern Surface
@@ -1500,6 +1505,10 @@ function notificationToLine(n: TerminalNotification): string {
1500
1505
  const OSC99_UNSAFE = /[\x00-\x1f\x7f\x80-\x9f]/u;
1501
1506
  const OSC99_MAX_PAYLOAD_BYTES = 2048;
1502
1507
  const OSC99_APP_NAME = "zeta";
1508
+ // Kitty matches notification ids across its whole process, not per window, so
1509
+ // a bare counter would collide between zeta sessions sharing one kitty instance
1510
+ // and turn a new notification into a silent replacement of another session's.
1511
+ const OSC99_ID_PREFIX = `zeta-${crypto.randomUUID().slice(0, 8)}`;
1503
1512
  let nextOsc99NotificationId = 1;
1504
1513
 
1505
1514
  function base64Utf8(value: string): string {
@@ -1513,7 +1522,7 @@ function sanitizeOsc99Id(id: string | undefined): string {
1513
1522
  }
1514
1523
 
1515
1524
  function osc99Id(id: string | undefined): string {
1516
- return sanitizeOsc99Id(id) || `zeta-${nextOsc99NotificationId++}`;
1525
+ return sanitizeOsc99Id(id) || `${OSC99_ID_PREFIX}-${nextOsc99NotificationId++}`;
1517
1526
  }
1518
1527
 
1519
1528
  function utf8CodePointBytes(char: string): number {
package/src/terminal.ts CHANGED
@@ -45,6 +45,13 @@ const TERMINAL_PROGRESS_CLEAR_SEQUENCE = "\x1b]9;4;0;\x07";
45
45
  const WINDOWS_TERMINAL_OSC11_POLL_MS = 30_000;
46
46
  /** How long a relayed ESC record waits for the rest of its sequence before acting as Escape (matches StdinBuffer). */
47
47
  const WIN32_RELAYED_ESCAPE_TIMEOUT_MS = 75;
48
+ /**
49
+ * How long a relayed OSC/DCS/APC string waits for its terminator. Far longer
50
+ * than a lone ESC: a TSP event split across console-host reads must not be
51
+ * released mid-string (its tail would be typed into the composer), and a stall
52
+ * of the event loop longer than 75 ms fires the timer before the queued tail is read.
53
+ */
54
+ const WIN32_RELAYED_STRING_TIMEOUT_MS = 5000;
48
55
 
49
56
  /** How long a TSP hello waits for its reply inside tmux, which answers DA1 itself. */
50
57
  const TSP_TMUX_HELLO_TIMEOUT_MS = 1000;
@@ -806,6 +813,22 @@ function isPrivateModeSupported(status: string): boolean {
806
813
  return status !== "0" && status !== "4";
807
814
  }
808
815
 
816
+ /**
817
+ * Restore the submit Enter of keystrokes the kernel buffered in cooked mode
818
+ * before raw input attached (#17820). The tty's ICRNL folds Enter into LF,
819
+ * which the editor reads as Shift+Enter, so a prompt typed or written during
820
+ * startup never submitted. The line break ending the typeahead (its ESC-free
821
+ * prefix; probe replies may follow in the same read) is the Enter that
822
+ * submits it; earlier breaks stay line breaks of the draft. CRLF (a Windows
823
+ * console line) is left alone.
824
+ */
825
+ function restoreCookedEnter(data: string): string {
826
+ const escape = data.indexOf("\x1b");
827
+ const end = escape === -1 ? data.length : escape;
828
+ if (end === 0 || data.charCodeAt(end - 1) !== 0x0a || data.charCodeAt(end - 2) === 0x0d) return data;
829
+ return `${data.slice(0, end - 1)}\r${data.slice(end)}`;
830
+ }
831
+
809
832
  /** Construction-time overrides for {@link ProcessTerminal}. */
810
833
  export interface ProcessTerminalOptions {
811
834
  /**
@@ -832,6 +855,9 @@ export interface ProcessTerminalOptions {
832
855
  */
833
856
  export class ProcessTerminal implements Terminal {
834
857
  #wasRaw = false;
858
+ // Set when raw input attaches over a cooked tty: the next read starts with
859
+ // whatever the kernel line-buffered meanwhile. See restoreCookedEnter.
860
+ #cookedTypeahead = false;
835
861
  #inputHandler?: (data: string) => void;
836
862
  #resizeHandler?: () => void;
837
863
  /** True between a `deferInput` start() and enableInput(). */
@@ -1195,6 +1221,7 @@ export class ProcessTerminal implements Terminal {
1195
1221
  this.#markTerminalDisconnected("stdin raw mode setup failed", err);
1196
1222
  return;
1197
1223
  }
1224
+ this.#cookedTypeahead = !this.#wasRaw;
1198
1225
  }
1199
1226
  process.stdin.setEncoding("utf8");
1200
1227
  process.stdin.on("end", this.#stdinEndHandler);
@@ -1402,7 +1429,7 @@ export class ProcessTerminal implements Terminal {
1402
1429
  if (decoder.hasPendingSequence) {
1403
1430
  this.#win32PendingFlushTimer = setTimeout(
1404
1431
  () => this.#releaseWin32PendingSequence(),
1405
- WIN32_RELAYED_ESCAPE_TIMEOUT_MS,
1432
+ decoder.hasPendingString ? WIN32_RELAYED_STRING_TIMEOUT_MS : WIN32_RELAYED_ESCAPE_TIMEOUT_MS,
1406
1433
  );
1407
1434
  }
1408
1435
  return;
@@ -1767,6 +1794,10 @@ export class ProcessTerminal implements Terminal {
1767
1794
 
1768
1795
  // Handler that pipes stdin data through the buffer
1769
1796
  this.#stdinDataHandler = (data: string) => {
1797
+ if (this.#cookedTypeahead && data) {
1798
+ this.#cookedTypeahead = false;
1799
+ data = restoreCookedEnter(data);
1800
+ }
1770
1801
  // Recover modes reset by the host before the user's next paste. Not
1771
1802
  // mid-paste: the host is plainly in 2004 then, and per-key reads would
1772
1803
  // turn one paste into thousands of writes (#15757).
@@ -2093,10 +2124,13 @@ export class ProcessTerminal implements Terminal {
2093
2124
  this.#safeWrite("\x1b[?9001h");
2094
2125
  this.#win32InputDecoder = new Win32InputModeDecoder();
2095
2126
  // The normalizer's expiry already spent the ESC wait; release the decoder's hold
2096
- // at once instead of starting a second window.
2127
+ // at once instead of starting a second window. A held string keeps its own
2128
+ // longer timer: releasing it here would type the rest of it as text.
2097
2129
  this.#win32PasteNormalizer = new Win32PasteMarkerNormalizer(
2098
2130
  data => this.#stdinBuffer?.process(data),
2099
- () => this.#releaseWin32PendingSequence(),
2131
+ () => {
2132
+ if (!this.#win32InputDecoder?.hasPendingString) this.#releaseWin32PendingSequence();
2133
+ },
2100
2134
  );
2101
2135
  // A WSL pty is not always relayed by a console host (tmux, VS Code
2102
2136
  // Remote-WSL, WSLg terminals). Those ignore 9001 and keep sending plain
@@ -2525,6 +2559,10 @@ export class ProcessTerminal implements Terminal {
2525
2559
  #markTerminalDisconnected(reason: string, err?: unknown): void {
2526
2560
  if (this.#dead) return;
2527
2561
  this.#dead = true;
2562
+ // The SIGHUP raised below is this instance's own disconnect, so postmortem
2563
+ // must not write a report to fd 2 afterwards: a stalled stdout leaves that
2564
+ // descriptor a full, blocking pty, and the write would hang before the exit.
2565
+ postmortem.declareTerminalDead();
2528
2566
  this.#disarmStdoutStallWatchdog();
2529
2567
  logger.warn("terminal disconnected; stopping interactive rendering", { reason, err });
2530
2568