tmux-ide 2.9.16 → 2.9.18

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 (40) hide show
  1. package/bin/cli.js +913 -367
  2. package/package.json +1 -1
  3. package/packages/core/src/terminal-fnv64-wasm.ts +8 -1
  4. package/packages/core/src/terminal-replica-hash-cache.ts +108 -1
  5. package/packages/core/src/terminal-replica.ts +14 -0
  6. package/packages/daemon/dist/command-center/discovery.js +39 -6
  7. package/packages/daemon/dist/doctor.js +101 -2
  8. package/packages/daemon/dist/lib/catalog-fleet-read.js +10 -0
  9. package/packages/daemon/dist/lib/daemon-embed.js +18 -4
  10. package/packages/daemon/dist/lib/daemon-service.js +13 -5
  11. package/packages/daemon/dist/lib/native-split-capability.js +20 -0
  12. package/packages/daemon/dist/lib/tmux-server-owner.js +2 -1
  13. package/packages/daemon/dist/lib/tmux-server-owners.js +20 -1
  14. package/packages/daemon/dist/lib/tui-binary.js +83 -17
  15. package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/Info.plist +2 -2
  16. package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/MacOS/tmux-ide-notifier +0 -0
  17. package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/Resources/AppIcon.icns +0 -0
  18. package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/Resources/Assets.car +0 -0
  19. package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/_CodeSignature/CodeResources +4 -4
  20. package/packages/daemon/dist/terminal/mirror/control-channel.js +3 -2
  21. package/packages/daemon/dist/terminal/mirror/mirror-service.js +47 -11
  22. package/packages/daemon/dist/terminal/mirror/session-channel.js +19 -4
  23. package/packages/daemon/dist/terminal/mirror/window-split-authority.js +9 -2
  24. package/packages/daemon/dist/terminal/protocol/native-split-resize.js +16 -16
  25. package/packages/daemon/dist/terminal/protocol/stock-split-resize.js +194 -0
  26. package/packages/daemon/src/command-center/discovery.ts +72 -7
  27. package/packages/daemon/src/doctor.ts +104 -2
  28. package/packages/daemon/src/lib/catalog-fleet-read.ts +40 -0
  29. package/packages/daemon/src/lib/daemon-embed.ts +31 -12
  30. package/packages/daemon/src/lib/daemon-service.ts +17 -4
  31. package/packages/daemon/src/lib/native-split-capability.ts +21 -0
  32. package/packages/daemon/src/lib/tmux-server-owner.ts +2 -0
  33. package/packages/daemon/src/lib/tmux-server-owners.ts +17 -1
  34. package/packages/daemon/src/lib/tui-binary.ts +114 -22
  35. package/packages/daemon/src/terminal/mirror/control-channel.ts +3 -2
  36. package/packages/daemon/src/terminal/mirror/mirror-service.ts +51 -12
  37. package/packages/daemon/src/terminal/mirror/session-channel.ts +23 -4
  38. package/packages/daemon/src/terminal/mirror/window-split-authority.ts +15 -4
  39. package/packages/daemon/src/terminal/protocol/native-split-resize.ts +16 -16
  40. package/packages/daemon/src/terminal/protocol/stock-split-resize.ts +268 -0
@@ -43,9 +43,19 @@ export const MIN_TUI_BINARY_BYTES = 10 * 1024 * 1024;
43
43
  /** Hard download/decompression ceilings: release binaries are currently ~70MB. */
44
44
  export const MAX_TUI_COMPRESSED_BYTES = 128 * 1024 * 1024;
45
45
  export const MAX_TUI_BINARY_BYTES = 256 * 1024 * 1024;
46
- export const TUI_DOWNLOAD_TIMEOUT_MS = 30_000;
46
+ /** Abort a request when no bytes arrive for this long; a slow transfer never trips it. */
47
+ export const TUI_DOWNLOAD_STALL_TIMEOUT_MS = 30_000;
48
+ /** One budget for the manifest, the binary, and every retry: ~145 KB/s at the size ceiling. */
49
+ export const TUI_DOWNLOAD_TOTAL_TIMEOUT_MS = 15 * 60_000;
50
+ /** Attempts per file; only transient failures are retried. */
51
+ export const TUI_DOWNLOAD_MAX_ATTEMPTS = 3;
52
+ export const TUI_DOWNLOAD_RETRY_DELAY_MS = 1_000;
47
53
 
48
54
  const MAX_CHECKSUM_MANIFEST_BYTES = 4 * 1024;
55
+ /** A second installer says why it is quiet once the wait is longer than a lock handover. */
56
+ const TUI_DOWNLOAD_LOCK_NOTICE_MS = 2_000;
57
+ /** Lets a lock waiter outlast the holder's verify and install after its download budget. */
58
+ const TUI_DOWNLOAD_LOCK_MARGIN_MS = 5_000;
49
59
 
50
60
  const SUPPORTED: Record<string, TuiPlatformTag> = {
51
61
  "darwin-arm64": "darwin-arm64",
@@ -162,9 +172,19 @@ interface DownloadLimits {
162
172
  readonly minBinaryBytes: number;
163
173
  readonly maxCompressedBytes: number;
164
174
  readonly maxBinaryBytes: number;
165
- readonly timeoutMs: number;
166
175
  }
167
176
 
177
+ interface DownloadPolicy {
178
+ readonly stallTimeoutMs: number;
179
+ readonly deadline: number;
180
+ readonly totalTimeoutMs: number;
181
+ readonly maxAttempts: number;
182
+ readonly retryDelayMs: number;
183
+ }
184
+
185
+ /** A failure a retry cannot fix: the release asset is missing or breaks a hard limit. */
186
+ class PermanentDownloadError extends Error {}
187
+
168
188
  type FetchLike = (input: string | URL | Request, init?: RequestInit) => Promise<Response>;
169
189
 
170
190
  function checksumPath(path: string): string {
@@ -269,36 +289,61 @@ function purgeCachedBinary(path: string): void {
269
289
  }
270
290
  }
271
291
 
292
+ function isTransientHttpStatus(status: number): boolean {
293
+ return status === 408 || status === 429 || status >= 500;
294
+ }
295
+
272
296
  async function readBoundedResponse(
273
297
  fetchImpl: FetchLike,
274
298
  url: string,
275
299
  maxBytes: number,
276
- timeoutMs: number,
300
+ policy: DownloadPolicy,
277
301
  ): Promise<Buffer> {
278
302
  const controller = new AbortController();
279
- const timer = setTimeout(() => controller.abort(), timeoutMs);
303
+ let total = 0;
304
+ let timeoutMessage: string | null = null;
305
+ const abortWith = (message: () => string) => () => {
306
+ timeoutMessage = message();
307
+ controller.abort();
308
+ };
309
+ const overallTimer = setTimeout(
310
+ abortWith(() => `download did not finish within ${policy.totalTimeoutMs}ms`),
311
+ Math.max(0, policy.deadline - Date.now()),
312
+ );
313
+ const onStall = abortWith(
314
+ () => `download stalled: no data for ${policy.stallTimeoutMs}ms after ${total} bytes`,
315
+ );
316
+ let stallTimer = setTimeout(onStall, policy.stallTimeoutMs);
317
+ const markProgress = () => {
318
+ clearTimeout(stallTimer);
319
+ stallTimer = setTimeout(onStall, policy.stallTimeoutMs);
320
+ };
280
321
  try {
281
322
  const response = await fetchImpl(url, { signal: controller.signal });
282
323
  if (!response.ok) {
283
- throw new Error(`HTTP ${response.status} ${response.statusText}`);
324
+ const message = `HTTP ${response.status} ${response.statusText}`;
325
+ if (isTransientHttpStatus(response.status)) throw new Error(message);
326
+ throw new PermanentDownloadError(message);
284
327
  }
328
+ markProgress();
285
329
  const declaredLength = Number(response.headers.get("content-length"));
286
330
  if (Number.isFinite(declaredLength) && declaredLength > maxBytes) {
287
- throw new Error(`declared size ${declaredLength} exceeds ${maxBytes} bytes`);
331
+ throw new PermanentDownloadError(`declared size ${declaredLength} exceeds ${maxBytes} bytes`);
288
332
  }
289
333
  if (!response.body) throw new Error("response has no body");
290
334
 
291
335
  const chunks: Buffer[] = [];
292
- let total = 0;
293
336
  const reader = response.body.getReader();
294
337
  try {
295
338
  while (true) {
296
339
  const { done, value } = await reader.read();
297
340
  if (done) break;
341
+ if (value.byteLength === 0) continue;
342
+ markProgress();
298
343
  total += value.byteLength;
299
344
  if (total > maxBytes) {
300
345
  await reader.cancel();
301
- throw new Error(`download exceeds ${maxBytes} bytes`);
346
+ throw new PermanentDownloadError(`download exceeds ${maxBytes} bytes`);
302
347
  }
303
348
  chunks.push(Buffer.from(value));
304
349
  }
@@ -307,12 +352,39 @@ async function readBoundedResponse(
307
352
  }
308
353
  return Buffer.concat(chunks, total);
309
354
  } catch (error) {
310
- if (controller.signal.aborted) {
311
- throw new Error(`download timed out after ${timeoutMs}ms`, { cause: error });
312
- }
355
+ if (timeoutMessage) throw new Error(timeoutMessage, { cause: error });
313
356
  throw error;
314
357
  } finally {
315
- clearTimeout(timer);
358
+ clearTimeout(overallTimer);
359
+ clearTimeout(stallTimer);
360
+ // Releases the connection of any response whose body was not fully read.
361
+ controller.abort();
362
+ }
363
+ }
364
+
365
+ async function readWithRetries(
366
+ fetchImpl: FetchLike,
367
+ url: string,
368
+ maxBytes: number,
369
+ policy: DownloadPolicy,
370
+ log: (msg: string) => void,
371
+ ): Promise<Buffer> {
372
+ for (let attempt = 1; ; attempt++) {
373
+ try {
374
+ return await readBoundedResponse(fetchImpl, url, maxBytes, policy);
375
+ } catch (error) {
376
+ const delayMs = policy.retryDelayMs * attempt;
377
+ if (
378
+ error instanceof PermanentDownloadError ||
379
+ attempt >= policy.maxAttempts ||
380
+ Date.now() + delayMs >= policy.deadline
381
+ ) {
382
+ throw error;
383
+ }
384
+ const message = error instanceof Error ? error.message : String(error);
385
+ log(`download attempt ${attempt}/${policy.maxAttempts} failed (${message}); retrying`);
386
+ await new Promise((resolve) => setTimeout(resolve, delayMs));
387
+ }
316
388
  }
317
389
  }
318
390
 
@@ -333,8 +405,11 @@ export async function downloadTuiBinary(
333
405
  home?: string;
334
406
  tag?: TuiPlatformTag | null;
335
407
  fetch?: FetchLike;
336
- timeoutMs?: number;
337
- limits?: Partial<Omit<DownloadLimits, "timeoutMs">>;
408
+ stallTimeoutMs?: number;
409
+ totalTimeoutMs?: number;
410
+ maxAttempts?: number;
411
+ retryDelayMs?: number;
412
+ limits?: Partial<DownloadLimits>;
338
413
  } = {},
339
414
  ): Promise<{ path: string; bytes: number }> {
340
415
  if (resolveRuntimeNamespace().development)
@@ -356,13 +431,17 @@ export async function downloadTuiBinary(
356
431
  minBinaryBytes: opts.limits?.minBinaryBytes ?? MIN_TUI_BINARY_BYTES,
357
432
  maxCompressedBytes: opts.limits?.maxCompressedBytes ?? MAX_TUI_COMPRESSED_BYTES,
358
433
  maxBinaryBytes: opts.limits?.maxBinaryBytes ?? MAX_TUI_BINARY_BYTES,
359
- timeoutMs: opts.timeoutMs ?? TUI_DOWNLOAD_TIMEOUT_MS,
360
434
  };
435
+ const totalTimeoutMs = opts.totalTimeoutMs ?? TUI_DOWNLOAD_TOTAL_TIMEOUT_MS;
361
436
  mkdirSync(dirname(dest), { recursive: true });
437
+ const lockNotice = setTimeout(
438
+ () => log("waiting for another tmux-ide download of this version to finish"),
439
+ TUI_DOWNLOAD_LOCK_NOTICE_MS,
440
+ );
362
441
  const releaseLock = await acquirePrivateOperationLock(
363
442
  downloadLockPath(dest),
364
- limits.timeoutMs * 2 + 5_000,
365
- );
443
+ totalTimeoutMs + TUI_DOWNLOAD_LOCK_MARGIN_MS,
444
+ ).finally(() => clearTimeout(lockNotice));
366
445
  const suffix = `${process.pid}.${randomUUID()}.tmp`;
367
446
  const binaryTmp = `${dest}.${suffix}`;
368
447
  const checksumTmp = `${checksumPath(dest)}.${suffix}`;
@@ -372,22 +451,35 @@ export async function downloadTuiBinary(
372
451
  purgeCachedBinary(dest);
373
452
 
374
453
  const fetchImpl = opts.fetch ?? globalThis.fetch;
454
+ // Starts after the lock so the budget matches what a lock waiter allows for.
455
+ const policy: DownloadPolicy = {
456
+ stallTimeoutMs: opts.stallTimeoutMs ?? TUI_DOWNLOAD_STALL_TIMEOUT_MS,
457
+ deadline: Date.now() + totalTimeoutMs,
458
+ totalTimeoutMs,
459
+ maxAttempts: opts.maxAttempts ?? TUI_DOWNLOAD_MAX_ATTEMPTS,
460
+ retryDelayMs: opts.retryDelayMs ?? TUI_DOWNLOAD_RETRY_DELAY_MS,
461
+ };
375
462
  log(`downloading checksum manifest ${checksumUrl}`);
376
463
  let manifestBytes: Buffer;
377
464
  let gz: Buffer;
378
465
  try {
379
- manifestBytes = await readBoundedResponse(
466
+ manifestBytes = await readWithRetries(
380
467
  fetchImpl,
381
468
  checksumUrl,
382
469
  MAX_CHECKSUM_MANIFEST_BYTES,
383
- limits.timeoutMs,
470
+ policy,
471
+ log,
384
472
  );
385
- gz = await readBoundedResponse(fetchImpl, url, limits.maxCompressedBytes, limits.timeoutMs);
473
+ log(`downloading ${url}`);
474
+ gz = await readWithRetries(fetchImpl, url, limits.maxCompressedBytes, policy, log);
386
475
  } catch (error) {
387
476
  const message = error instanceof Error ? error.message : String(error);
477
+ const hint =
478
+ error instanceof PermanentDownloadError
479
+ ? "Check that the release published both exact-version assets."
480
+ : "Check your network connection, then retry with `tmux-ide update --tui-binary`, or run the installer again if tmux-ide is not installed yet.";
388
481
  throw new Error(
389
- `could not download the TUI binary and checksum for v${version} (${message}). ` +
390
- `Check that the release published both exact-version assets.`,
482
+ `could not download the TUI binary and checksum for v${version} (${message}). ${hint}`,
391
483
  { cause: error },
392
484
  );
393
485
  }
@@ -805,7 +805,8 @@ export class ControlChannelCore {
805
805
  }
806
806
  if (event.kind === "error" && sink.index !== sink.state.resultIndex)
807
807
  this.discardedErrors += 1;
808
- if (event.kind === "error" && sink.index === 0) {
808
+ if (event.kind === "error") {
809
+ // tmux drops the failed command's remaining group, so those replies never come.
809
810
  while (this.pending[0]?.kind === "command-list" && this.pending[0].state === sink.state)
810
811
  this.pending.shift();
811
812
  if (!sink.state.settled) {
@@ -813,7 +814,7 @@ export class ControlChannelCore {
813
814
  sink.state.onReply({
814
815
  ok: false,
815
816
  lines:
816
- sink.state.budget || sink.state.resultIndex === 0
817
+ sink.index > 0 || sink.state.budget || sink.state.resultIndex === 0
817
818
  ? sink.state.lines
818
819
  : sink.state.leadingErrorLines,
819
820
  });
@@ -1,3 +1,4 @@
1
+ import { randomUUID } from "node:crypto";
1
2
  import { setTimeout as waitForPublication } from "node:timers/promises";
2
3
  import {
3
4
  WindowSplitResizeTargetSchemaZ,
@@ -10,6 +11,7 @@ import type {
10
11
  GuardedNativeSplitResizeResult,
11
12
  } from "../../lib/guarded-native-split-resize.ts";
12
13
  import { WindowSplitAuthority, WindowSplitLayoutUnavailable } from "./window-split-authority.ts";
14
+ import { resizeStockSplit, type StockSplitResizeResult } from "../protocol/stock-split-resize.ts";
13
15
  import { SharedWindowIndex } from "./shared-window-index.ts";
14
16
  import { RegisteredWindowGuard, type RegisteredWindowReader } from "./registered-window-guard.ts";
15
17
  import type { OwnedViewerAdapter } from "./owned-viewer-adapter.ts";
@@ -66,6 +68,8 @@ export interface MirrorServiceOptions {
66
68
  splitLayoutPrepare?: () => Promise<boolean>;
67
69
  /** Positively probe this native epoch before issuing handles; absent denies. */
68
70
  splitLayoutCapability?: (epoch: string) => boolean | Promise<boolean>;
71
+ /** True only when the server positively lacks the native commands: a stock tmux. */
72
+ splitLayoutStock?: () => Promise<boolean>;
69
73
  onSharedWindowConflict?: (session: string, conflicted: boolean) => void;
70
74
  createOwnedViewerAdapter?: (session: string) => OwnedViewerAdapter | undefined;
71
75
  nativeServerIdentity?: import("../../lib/tmux-server-generation-runner.ts").NativeTmuxServerIdentity;
@@ -167,6 +171,8 @@ export interface MirrorSessionRetention {
167
171
 
168
172
  interface ChannelEntry {
169
173
  splitAuthority?: WindowSplitAuthority;
174
+ /** Set once this channel's split authority serves a stock tmux server. */
175
+ stockSplitEpoch?: string;
170
176
  channel: SessionChannel;
171
177
  started: Promise<void>;
172
178
  refs: number;
@@ -418,9 +424,17 @@ export class MirrorService {
418
424
  } catch {
419
425
  /* Unavailable owner. */
420
426
  }
421
- if (!ready || this.disposed || entry.retired || this.channels.get(session) !== entry)
427
+ if (!ready) {
428
+ // Anything but a positive "no such command" stays a refusal.
429
+ const stock = await this.#stockSplitServer();
430
+ if (!stock || this.disposed || entry.retired || this.channels.get(session) !== entry)
431
+ throw new WindowSplitLayoutUnavailable();
432
+ return this.#readStockSplitLayout(entry, target);
433
+ }
434
+ if (this.disposed || entry.retired || this.channels.get(session) !== entry)
422
435
  throw new WindowSplitLayoutUnavailable();
423
436
  }
437
+ if (entry.stockSplitEpoch) throw new WindowSplitLayoutUnavailable();
424
438
  const epoch = this.opts.splitLayoutEpoch?.();
425
439
  let supported = false;
426
440
  try {
@@ -443,6 +457,25 @@ export class MirrorService {
443
457
  return entry.splitAuthority.read(target);
444
458
  }
445
459
 
460
+ async #stockSplitServer(): Promise<boolean> {
461
+ try {
462
+ return (await this.opts.splitLayoutStock?.()) === true;
463
+ } catch {
464
+ return false;
465
+ }
466
+ }
467
+
468
+ #readStockSplitLayout(entry: ChannelEntry, target: WindowLinkTarget): WindowSplitLayoutResource {
469
+ if (entry.splitAuthority && !entry.stockSplitEpoch) throw new WindowSplitLayoutUnavailable();
470
+ const epoch = (entry.stockSplitEpoch ??= randomUUID());
471
+ entry.splitAuthority ??= new WindowSplitAuthority({
472
+ describe: (window) => entry.channel.describeSplitLayout(window, true),
473
+ serverEpoch: () => epoch,
474
+ stock: true,
475
+ });
476
+ return entry.splitAuthority.read(target);
477
+ }
478
+
446
479
  /** Resolve only issued handles, then revalidate immediately at native dispatch. */
447
480
  async resizeWindowSplit(
448
481
  session: string,
@@ -451,7 +484,7 @@ export class MirrorService {
451
484
  authorizeBeforeEffect: () => void,
452
485
  runNative: ReturnType<typeof createGuardedNativeSplitResize>,
453
486
  ): Promise<
454
- GuardedNativeSplitResizeResult & {
487
+ (GuardedNativeSplitResizeResult | StockSplitResizeResult) & {
455
488
  successor?: { resource: WindowSplitLayoutResource; splitId: string } | null;
456
489
  }
457
490
  > {
@@ -467,16 +500,22 @@ export class MirrorService {
467
500
  await entry!.started;
468
501
  const resolved = current().resolve(captured);
469
502
  const successor = current().prepareSuccessor(captured);
470
- const result = await runNative(resolved.request, {
471
- operationId,
472
- serverEpoch: resolved.serverEpoch,
473
- session: resolved.session,
474
- anchor: resolved.anchor,
475
- authorizeBeforeEffect: () => {
476
- current().resolve(captured);
477
- authorizeBeforeEffect();
478
- },
479
- });
503
+ const authorize = () => {
504
+ current().resolve(captured);
505
+ authorizeBeforeEffect();
506
+ };
507
+ const result = entry!.stockSplitEpoch
508
+ ? await resizeStockSplit(resolved.request, resolved.session.created, authorize, {
509
+ readOptions: (windowId) => entry!.channel.stockSplitOptions(windowId),
510
+ send: (command) => entry!.channel.stockSplitCommand(command),
511
+ })
512
+ : await runNative(resolved.request, {
513
+ operationId,
514
+ serverEpoch: resolved.serverEpoch,
515
+ session: resolved.session,
516
+ anchor: resolved.anchor,
517
+ authorizeBeforeEffect: authorize,
518
+ });
480
519
  if (result.status !== "applied") return result;
481
520
  // Native success is retained even if canonical publication is late or diverges.
482
521
  // This grace period observes only; it never retries a native mutation.
@@ -1,3 +1,4 @@
1
+ import { STOCK_SPLIT_OPTIONS_FORMAT } from "../protocol/stock-split-resize.ts";
1
2
  import { layoutContentRows } from "./layout-content-rows.ts";
2
3
  import {
3
4
  decodeNativeAtomicSnapshot,
@@ -440,6 +441,8 @@ export interface NativeSplitLayoutSnapshot {
440
441
  readonly runtimeWindowId: string;
441
442
  readonly semanticWindowId: string;
442
443
  readonly rawLayout: string;
444
+ /** Set on a stock server, where it decides how small tmux lets a pane get. */
445
+ readonly paneBorderStatus?: string;
443
446
  readonly panes: readonly {
444
447
  readonly runtimePaneId: string;
445
448
  readonly semanticPaneId: string;
@@ -964,7 +967,7 @@ export class SessionChannel {
964
967
  }
965
968
 
966
969
  /** Exact native ancestry, never reconstructed from published pane rectangles. */
967
- describeSplitLayout(target: WindowLinkTarget): NativeSplitLayoutSnapshot {
970
+ describeSplitLayout(target: WindowLinkTarget, stock = false): NativeSplitLayoutSnapshot {
968
971
  const authority = this.windowLinkAuthority;
969
972
  const identity = this.attachedIdentity;
970
973
  const generation = this.attachedServerGeneration;
@@ -999,8 +1002,7 @@ export class SessionChannel {
999
1002
  pane.descriptor?.runtimeSessionId !== identity.runtimeSessionId ||
1000
1003
  pane.descriptor?.windowId !== resolved.runtimeWindowId ||
1001
1004
  this.panesBySemantic.get(pane.semanticId) !== pane ||
1002
- !birth ||
1003
- !/^[1-9]\d*$/u.test(birth) ||
1005
+ (!stock && (!birth || !/^[1-9]\d*$/u.test(birth))) ||
1004
1006
  !layout.leaves.some(
1005
1007
  (visible) =>
1006
1008
  visible.id === leaf.id &&
@@ -1014,7 +1016,7 @@ export class SessionChannel {
1014
1016
  return Object.freeze({
1015
1017
  runtimePaneId: pane.runtimeId,
1016
1018
  semanticPaneId: pane.semanticId,
1017
- nativePaneBirthId: birth,
1019
+ nativePaneBirthId: stock ? "" : birth!,
1018
1020
  });
1019
1021
  });
1020
1022
  return Object.freeze({
@@ -1024,10 +1026,27 @@ export class SessionChannel {
1024
1026
  runtimeWindowId: resolved.runtimeWindowId,
1025
1027
  semanticWindowId: window.semanticId,
1026
1028
  rawLayout: layout.rawLayout,
1029
+ ...(stock ? { paneBorderStatus: window.paneBorderStatus } : {}),
1027
1030
  panes: Object.freeze(panes),
1028
1031
  });
1029
1032
  }
1030
1033
 
1034
+ stockSplitOptions(windowId: string): Promise<string[]> {
1035
+ return this.io.request(`display-message -p -t ${windowId} "${STOCK_SPLIT_OPTIONS_FORMAT}"`);
1036
+ }
1037
+
1038
+ /** One guarded resize on this control connection, for a stock tmux server. */
1039
+ stockSplitCommand(command: string): Promise<string[]> {
1040
+ return new Promise((resolve, reject) => {
1041
+ const onReply = (reply: ControlReply) =>
1042
+ reply.ok ? resolve(reply.lines) : reject(new Error("Stock split command failed"));
1043
+ const limits = { maxBytes: 16 * 1024, maxLines: 4 };
1044
+ if (this.io.commandListBoundedInline)
1045
+ this.io.commandListBoundedInline(command, 3, 2, limits, onReply);
1046
+ else this.io.commandListInline(command, 3, 2, onReply);
1047
+ });
1048
+ }
1049
+
1031
1050
  async executeWindowLinkAction(request: {
1032
1051
  action: "select" | "unlink";
1033
1052
  target?: WindowLinkTarget;
@@ -12,6 +12,7 @@ import {
12
12
  import { supportsNativeSessionGuard } from "../../lib/native-operation-command.ts";
13
13
  import type { NativeSplitResizeRequest } from "../protocol/native-split-resize.ts";
14
14
  import { parseLayoutTree, type LayoutTreeNode } from "../protocol/layout-parse.ts";
15
+ import { stockSplitMovable } from "../protocol/stock-split-resize.ts";
15
16
  import {
16
17
  SplitLayoutPublicationPending,
17
18
  type NativeSplitLayoutSnapshot,
@@ -44,6 +45,8 @@ export class WindowSplitAuthority {
44
45
  private readonly options: {
45
46
  describe(window: WindowLinkTarget): NativeSplitLayoutSnapshot;
46
47
  serverEpoch(): string | null;
48
+ /** A stock server has no pane birth ids, and some splits have no resize target. */
49
+ stock?: boolean;
47
50
  },
48
51
  ) {}
49
52
 
@@ -69,9 +72,10 @@ export class WindowSplitAuthority {
69
72
  if (
70
73
  !/^%(0|[1-9][0-9]{0,9})$/u.test(pane.runtimePaneId) ||
71
74
  Number(pane.runtimePaneId.slice(1)) > 0xffffffff ||
72
- !NativeJournalUint64SchemaZ.refine((birth) => birth !== "0").safeParse(
73
- pane.nativePaneBirthId,
74
- ).success
75
+ (!this.options.stock &&
76
+ !NativeJournalUint64SchemaZ.refine((birth) => birth !== "0").safeParse(
77
+ pane.nativePaneBirthId,
78
+ ).success)
75
79
  )
76
80
  throw new WindowSplitLayoutUnavailable();
77
81
  });
@@ -98,7 +102,14 @@ export class WindowSplitAuthority {
98
102
  }
99
103
  node.children.forEach((child, index) => {
100
104
  const childPath = [...path, index];
101
- if (index < node.children.length - 1) {
105
+ if (
106
+ index < node.children.length - 1 &&
107
+ (!this.options.stock ||
108
+ stockSplitMovable(tree, childPath, node.axis, {
109
+ borderStatus: snapshot.paneBorderStatus ?? "off",
110
+ scrollbar: 0,
111
+ }))
112
+ ) {
102
113
  const splitId = randomUUID();
103
114
  paths.set(splitId, childPath);
104
115
  splits.push({
@@ -32,7 +32,7 @@ function json(text: string, limit: number): unknown {
32
32
  throw new Error("Bounded native response required");
33
33
  return JSON.parse(text);
34
34
  }
35
- function capability(text: string): boolean {
35
+ export function nativeSplitCapability(text: string): boolean {
36
36
  const value = json(text, 1024);
37
37
  return (
38
38
  object(value, [
@@ -54,13 +54,13 @@ function capability(text: string): boolean {
54
54
  /** Read-only, uncached probe; the caller pins and bounds the selected server. */
55
55
  export async function supportsNativeSplitResize(runTmux: NativeSplitRunner): Promise<boolean> {
56
56
  try {
57
- return capability(await runTmux(["tmux-ide-resize-split", "-V"]));
57
+ return nativeSplitCapability(await runTmux(["tmux-ide-resize-split", "-V"]));
58
58
  } catch {
59
59
  return false;
60
60
  }
61
61
  }
62
62
 
63
- function validTree(tree: LayoutTreeNode): boolean {
63
+ export function validSplitTree(tree: LayoutTreeNode): boolean {
64
64
  let budget = 5;
65
65
  const visit = (node: LayoutTreeNode): boolean => {
66
66
  if (node.left + node.width > 4096 || node.top + node.height > 4096) return false;
@@ -74,7 +74,7 @@ function validTree(tree: LayoutTreeNode): boolean {
74
74
  };
75
75
  return visit(tree);
76
76
  }
77
- function locate(tree: LayoutTreeNode, path: readonly number[]) {
77
+ export function locateSplit(tree: LayoutTreeNode, path: readonly number[]) {
78
78
  let node = tree;
79
79
  let parent: Extract<LayoutTreeNode, { kind: "split" }> | undefined;
80
80
  for (const index of path) {
@@ -84,7 +84,7 @@ function locate(tree: LayoutTreeNode, path: readonly number[]) {
84
84
  }
85
85
  return parent && path.at(-1)! < parent.children.length - 1 ? { parent, node } : null;
86
86
  }
87
- function edge(node: LayoutTreeNode, axis: "cols" | "rows") {
87
+ export function splitEdge(node: LayoutTreeNode, axis: "cols" | "rows") {
88
88
  return axis === "cols" ? node.left + node.width : node.top + node.height;
89
89
  }
90
90
  function sameRect(a: LayoutTreeNode, b: LayoutTreeNode) {
@@ -93,7 +93,7 @@ function sameRect(a: LayoutTreeNode, b: LayoutTreeNode) {
93
93
  /** Only geometry inside the exact parent may change, along the requested axis.
94
94
  * Native redistribution can affect multiple siblings. This verifies convergence,
95
95
  * not exclusive causation or authentication of the returned layout. */
96
- function preservesTree(
96
+ export function preservesSplitTree(
97
97
  before: LayoutTreeNode,
98
98
  after: LayoutTreeNode,
99
99
  affected: LayoutTreeNode,
@@ -116,7 +116,7 @@ function preservesTree(
116
116
  before.axis === after.axis &&
117
117
  before.children.length === after.children.length &&
118
118
  before.children.every((child, index) =>
119
- preservesTree(child, after.children[index]!, affected, axis, inside),
119
+ preservesSplitTree(child, after.children[index]!, affected, axis, inside),
120
120
  )
121
121
  );
122
122
  }
@@ -151,8 +151,8 @@ export async function resizeNativeSplit(
151
151
  )
152
152
  return { status: "refused", reason: "invalid-request" };
153
153
  const tree = parseLayoutTree(request.expectedLayout);
154
- if (!tree || !validTree(tree)) return { status: "refused", reason: "invalid-request" };
155
- const selected = locate(tree, request.path);
154
+ if (!tree || !validSplitTree(tree)) return { status: "refused", reason: "invalid-request" };
155
+ const selected = locateSplit(tree, request.path);
156
156
  if (!selected || selected.parent.axis !== request.axis)
157
157
  return { status: "refused", reason: "invalid-request" };
158
158
  before = tree;
@@ -162,7 +162,7 @@ export async function resizeNativeSplit(
162
162
  return { status: "refused", reason: "invalid-request" };
163
163
  }
164
164
  try {
165
- if (!capability(await runTmux(["tmux-ide-resize-split", "-V"])))
165
+ if (!nativeSplitCapability(await runTmux(["tmux-ide-resize-split", "-V"])))
166
166
  return { status: "refused", reason: "unsupported" };
167
167
  } catch {
168
168
  return { status: "refused", reason: "unsupported" };
@@ -200,15 +200,15 @@ export async function resizeNativeSplit(
200
200
  )
201
201
  return { status: "uncertain", reason: "invalid-receipt" };
202
202
  const after = parseLayoutTree(receipt.layout);
203
- const original = locate(before, captured.path)!;
204
- const actual = after && locate(after, captured.path);
205
- const previous = edge(original.node, captured.axis);
203
+ const original = locateSplit(before, captured.path)!;
204
+ const actual = after && locateSplit(after, captured.path);
205
+ const previous = splitEdge(original.node, captured.axis);
206
206
  if (
207
207
  !after ||
208
- !validTree(after) ||
208
+ !validSplitTree(after) ||
209
209
  !actual ||
210
- !preservesTree(before, after, original.parent, captured.axis) ||
211
- receipt.boundary !== edge(actual.node, captured.axis) ||
210
+ !preservesSplitTree(before, after, original.parent, captured.axis) ||
211
+ receipt.boundary !== splitEdge(actual.node, captured.axis) ||
212
212
  receipt.boundary < Math.min(previous, captured.boundary) ||
213
213
  receipt.boundary > Math.max(previous, captured.boundary)
214
214
  )