tmux-ide 2.9.17 → 2.9.20

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 (26) hide show
  1. package/bin/cli.js +631 -320
  2. package/package.json +1 -1
  3. package/packages/daemon/dist/doctor.js +108 -2
  4. package/packages/daemon/dist/lib/daemon-embed.js +4 -1
  5. package/packages/daemon/dist/lib/native-split-capability.js +18 -0
  6. package/packages/daemon/dist/lib/tmux-server-owner.js +2 -1
  7. package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/Info.plist +2 -2
  8. package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/MacOS/tmux-ide-notifier +0 -0
  9. package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/Resources/Assets.car +0 -0
  10. package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/_CodeSignature/CodeResources +2 -2
  11. package/packages/daemon/dist/terminal/mirror/control-channel.js +3 -2
  12. package/packages/daemon/dist/terminal/mirror/mirror-service.js +47 -11
  13. package/packages/daemon/dist/terminal/mirror/session-channel.js +20 -4
  14. package/packages/daemon/dist/terminal/mirror/window-split-authority.js +9 -2
  15. package/packages/daemon/dist/terminal/protocol/native-split-resize.js +16 -16
  16. package/packages/daemon/dist/terminal/protocol/stock-split-resize.js +194 -0
  17. package/packages/daemon/src/doctor.ts +111 -2
  18. package/packages/daemon/src/lib/daemon-embed.ts +4 -0
  19. package/packages/daemon/src/lib/native-split-capability.ts +20 -0
  20. package/packages/daemon/src/lib/tmux-server-owner.ts +2 -0
  21. package/packages/daemon/src/terminal/mirror/control-channel.ts +3 -2
  22. package/packages/daemon/src/terminal/mirror/mirror-service.ts +51 -12
  23. package/packages/daemon/src/terminal/mirror/session-channel.ts +24 -4
  24. package/packages/daemon/src/terminal/mirror/window-split-authority.ts +16 -4
  25. package/packages/daemon/src/terminal/protocol/native-split-resize.ts +16 -16
  26. package/packages/daemon/src/terminal/protocol/stock-split-resize.ts +268 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tmux-ide",
3
- "version": "2.9.17",
3
+ "version": "2.9.20",
4
4
  "description": "The open-source workspace for coding agents: run Claude Code, Codex and other agents in tmux with live status",
5
5
  "type": "module",
6
6
  "bin": {
@@ -1,8 +1,11 @@
1
1
  import { requireSupportedTmuxVersion } from "./lib/tmux-version.js";
2
2
  import { resolveTmuxExecutable } from "./lib/tmux-client-execution.js";
3
+ import { TMUX_SOCKET_PATH_ENV } from "./lib/runtime-namespace.js";
3
4
  import { execSync, execFileSync } from "node:child_process";
4
- import { accessSync, constants, existsSync } from "node:fs";
5
- import { resolve, dirname } from "node:path";
5
+ import { accessSync, constants, existsSync, mkdtempSync, rmSync } from "node:fs";
6
+ import { tmpdir } from "node:os";
7
+ import { resolve, dirname, join } from "node:path";
8
+ import { nativeSplitCapability } from "./terminal/protocol/native-split-resize.js";
6
9
  import { fileURLToPath } from "node:url";
7
10
  import { getCurrentVersion, getUpdateStatus } from "./lib/update-check.js";
8
11
  import { installedSkillVersion } from "./lib/skill-sync.js";
@@ -149,6 +152,103 @@ function check(label, fn, { optional = false } = {}) {
149
152
  return { label, pass: false, detail: e.message, optional };
150
153
  }
151
154
  }
155
+ const UNKNOWN = (command) => new RegExp(`^unknown command: ${command}$`, "mu");
156
+ /** The same reading of the server as the mirror's: the stock resize when it refuses
157
+ * the split command by name, and full only with the split capability it requires. */
158
+ function nativeCommands(probe) {
159
+ const ask = (command) => {
160
+ try {
161
+ return { output: probe([command, "-V"]) };
162
+ }
163
+ catch (error) {
164
+ const failure = error;
165
+ return { failure: String(failure.stderr ?? failure.message ?? "") };
166
+ }
167
+ };
168
+ const split = ask("tmux-ide-resize-split");
169
+ const events = ask("tmux-ide-events");
170
+ const failures = [split.failure, events.failure].filter((text) => text !== undefined);
171
+ if (failures.some((text) => /no server running|error connecting/u.test(text)))
172
+ return "no-server";
173
+ const refused = (answer, command) => answer.failure !== undefined && UNKNOWN(command).test(answer.failure);
174
+ if (refused(split, "tmux-ide-resize-split")) {
175
+ if (refused(events, "tmux-ide-events"))
176
+ return "stock";
177
+ // The journal answers: a tmux-ide tmux built before the split command.
178
+ if (events.output !== undefined)
179
+ return "older";
180
+ return "unknown";
181
+ }
182
+ if (split.output !== undefined && events.output !== undefined) {
183
+ try {
184
+ return nativeSplitCapability(split.output) ? "full" : "partial";
185
+ }
186
+ catch {
187
+ return "partial";
188
+ }
189
+ }
190
+ return failures.length === 2 ? "unknown" : "partial";
191
+ }
192
+ /** Reads the server a session would use. With none running, a throwaway private
193
+ * server shows what the resolved binary would start. */
194
+ export function tmuxFeaturesRow(probeServer, probeBinary) {
195
+ let answer = nativeCommands(probeServer);
196
+ if (answer === "no-server")
197
+ answer = nativeCommands(probeBinary);
198
+ const details = {
199
+ full: "bundled tmux: full features",
200
+ stock: "stock tmux: reduced features",
201
+ older: "older tmux-ide tmux: reduced features (restart it with tmux-ide's own tmux for every feature; that ends its sessions)",
202
+ partial: "this tmux has only some tmux-ide commands: no pane dividers",
203
+ "no-server": "could not read the tmux server's features",
204
+ unknown: "could not read the tmux server's features",
205
+ };
206
+ return {
207
+ label: "tmux features",
208
+ pass: answer === "full" || answer === "stock" || answer === "older",
209
+ detail: details[answer],
210
+ optional: true,
211
+ };
212
+ }
213
+ function runTmuxFeatureProbes(executable) {
214
+ const run = (prefix) => (args) => execFileSync(executable, [...prefix, ...args], {
215
+ encoding: "utf8",
216
+ stdio: ["ignore", "pipe", "pipe"],
217
+ timeout: 3000,
218
+ });
219
+ const socketPath = process.env[TMUX_SOCKET_PATH_ENV];
220
+ const socketName = process.env.TMUX_IDE_TMUX_SOCKET_NAME;
221
+ const server = socketPath ? ["-S", socketPath] : socketName ? ["-L", socketName] : [];
222
+ const cleanups = [];
223
+ const probeBinary = (() => {
224
+ let scratch = null;
225
+ return (args) => {
226
+ scratch ??= (() => {
227
+ const dir = mkdtempSync(join(tmpdir(), "tmi-doctor-"));
228
+ const prefix = ["-S", join(dir, "s"), "-f", "/dev/null"];
229
+ cleanups.push(() => {
230
+ try {
231
+ run(prefix)(["kill-server"]);
232
+ }
233
+ catch {
234
+ // The server is already gone.
235
+ }
236
+ rmSync(dir, { recursive: true, force: true });
237
+ });
238
+ run(prefix)(["new-session", "-d", "-s", "probe"]);
239
+ return { dir, prefix };
240
+ })();
241
+ return run(scratch.prefix)(args);
242
+ };
243
+ })();
244
+ try {
245
+ return tmuxFeaturesRow(run(server), probeBinary);
246
+ }
247
+ finally {
248
+ for (const cleanup of cleanups)
249
+ cleanup();
250
+ }
251
+ }
152
252
  export function nodeVersionRow(version) {
153
253
  const major = Number(version.split(".")[0]);
154
254
  const pass = Number.isInteger(major) && major >= 20;
@@ -190,6 +290,12 @@ export async function doctor({ json, } = {}) {
190
290
  requireSupportedTmuxVersion(version);
191
291
  return `${version} (${executable})`;
192
292
  }));
293
+ try {
294
+ checks.push(runTmuxFeatureProbes(resolveTmuxExecutable()));
295
+ }
296
+ catch {
297
+ // The tmux version row above already reports a missing executable.
298
+ }
193
299
  checks.push(nodeVersionRow(process.versions.node));
194
300
  checks.push(check("256-color terminal", () => {
195
301
  const term = process.env.TERM ?? "";
@@ -10,7 +10,7 @@ import { createNativeBrowserResolver } from "./tmux-native-browser.js";
10
10
  import { createNativeSurfaceContextResolver } from "./native-surface-context.js";
11
11
  import { NativeSurfaceProviderRegistry } from "../terminal/graphics/native-surface-provider.js";
12
12
  import { TmuxServerVersionSchemaZ } from "@tmux-ide/contracts";
13
- import { createNativeSplitCapabilityProbe, createNativeSplitReadiness, } from "./native-split-capability.js";
13
+ import { createNativeSplitCapabilityProbe, createNativeSplitReadiness, createStockSplitProbe, } from "./native-split-capability.js";
14
14
  import { executeCanonicalSplitMutation } from "./canonical-split-mutation.js";
15
15
  import { createGuardedNativeSplitResize } from "./guarded-native-split-resize.js";
16
16
  import { WindowLinkTargetSchemaZ } from "@tmux-ide/contracts";
@@ -1112,6 +1112,9 @@ async function startEmbeddedDaemonGeneration(opts) {
1112
1112
  observation: () => observationSelector ?? null,
1113
1113
  runPinnedTmux: nativeGenerationTmuxRunner,
1114
1114
  }),
1115
+ splitLayoutStock: createStockSplitProbe({
1116
+ runPinnedTmux: nativeGenerationTmuxRunner,
1117
+ }),
1115
1118
  createOwnedViewerAdapter: () => ownedViewerFactory?.(),
1116
1119
  nativeServerIdentity: initialNativeServerIdentity,
1117
1120
  executable: tmuxAuthority.executablePath,
@@ -80,3 +80,21 @@ export function createNativeSplitReadiness(options) {
80
80
  pending = null;
81
81
  }));
82
82
  }
83
+ /** True only when the selected server refuses `tmux-ide-resize-split` by name: a
84
+ * stock tmux, or a tmux-ide tmux built before that command, which may still have
85
+ * the journal. A timeout, a lost server or any other failure says nothing, so it
86
+ * stays false. */
87
+ export function createStockSplitProbe(options) {
88
+ const command = "tmux-ide-resize-split";
89
+ return async () => {
90
+ try {
91
+ await options.runPinnedTmux([command, "-V"]);
92
+ return false;
93
+ }
94
+ catch (error) {
95
+ const failure = error;
96
+ const text = String(failure?.cause?.stderr ?? failure?.stderr ?? "");
97
+ return new RegExp(`^unknown command: ${command}$`, "mu").test(text);
98
+ }
99
+ };
100
+ }
@@ -1,7 +1,7 @@
1
1
  import { createNativeBrowserResolver } from "./tmux-native-browser.js";
2
2
  import { createNativeSurfaceContextResolver } from "./native-surface-context.js";
3
3
  import { shellEscape } from "./shell.js";
4
- import { createNativeSplitCapabilityProbe, createNativeSplitReadiness, } from "./native-split-capability.js";
4
+ import { createNativeSplitCapabilityProbe, createNativeSplitReadiness, createStockSplitProbe, } from "./native-split-capability.js";
5
5
  import { executeCanonicalSplitMutation } from "./canonical-split-mutation.js";
6
6
  import { createGuardedNativeSplitResize } from "./guarded-native-split-resize.js";
7
7
  import { execFileSync } from "node:child_process";
@@ -287,6 +287,7 @@ export async function createNativeTmuxServerOwner(options) {
287
287
  observation: () => observationSelector ?? null,
288
288
  runPinnedTmux: generationRun,
289
289
  }),
290
+ splitLayoutStock: createStockSplitProbe({ runPinnedTmux: generationRun }),
290
291
  createOwnedViewerAdapter: createOwnedViewerAdapterFactory({
291
292
  environmentId: options.environmentId,
292
293
  serverScope: { serverId: options.serverId, generation },
@@ -21,9 +21,9 @@
21
21
  <key>CFBundlePackageType</key>
22
22
  <string>APPL</string>
23
23
  <key>CFBundleShortVersionString</key>
24
- <string>2.9.17</string>
24
+ <string>2.9.20</string>
25
25
  <key>CFBundleVersion</key>
26
- <string>2.9.17</string>
26
+ <string>2.9.20</string>
27
27
  <key>LSMinimumSystemVersion</key>
28
28
  <string>11.0</string>
29
29
  <key>LSUIElement</key>
@@ -10,7 +10,7 @@
10
10
  </data>
11
11
  <key>Resources/Assets.car</key>
12
12
  <data>
13
- YZSYPnzkfPLVemp3jiRDnR5WhhQ=
13
+ i7NYcRFn5KWT9s02gBWS2lV7Llc=
14
14
  </data>
15
15
  </dict>
16
16
  <key>files2</key>
@@ -26,7 +26,7 @@
26
26
  <dict>
27
27
  <key>hash2</key>
28
28
  <data>
29
- zV9+zCqfvUhHrz90MuHUjqBvx93oA7g6BxgO8hDUlN8=
29
+ AITW218ObXrpylURnyD4C2ud6DjNc/w8unCYkbG/UDY=
30
30
  </data>
31
31
  </dict>
32
32
  </dict>
@@ -533,14 +533,15 @@ export class ControlChannelCore {
533
533
  }
534
534
  if (event.kind === "error" && sink.index !== sink.state.resultIndex)
535
535
  this.discardedErrors += 1;
536
- if (event.kind === "error" && sink.index === 0) {
536
+ if (event.kind === "error") {
537
+ // tmux drops the failed command's remaining group, so those replies never come.
537
538
  while (this.pending[0]?.kind === "command-list" && this.pending[0].state === sink.state)
538
539
  this.pending.shift();
539
540
  if (!sink.state.settled) {
540
541
  sink.state.settled = true;
541
542
  sink.state.onReply({
542
543
  ok: false,
543
- lines: sink.state.budget || sink.state.resultIndex === 0
544
+ lines: sink.index > 0 || sink.state.budget || sink.state.resultIndex === 0
544
545
  ? sink.state.lines
545
546
  : sink.state.leadingErrorLines,
546
547
  });
@@ -1,6 +1,8 @@
1
+ import { randomUUID } from "node:crypto";
1
2
  import { setTimeout as waitForPublication } from "node:timers/promises";
2
3
  import { WindowSplitResizeTargetSchemaZ, } from "@tmux-ide/contracts";
3
4
  import { WindowSplitAuthority, WindowSplitLayoutUnavailable } from "./window-split-authority.js";
5
+ import { resizeStockSplit } from "../protocol/stock-split-resize.js";
4
6
  import { SharedWindowIndex } from "./shared-window-index.js";
5
7
  import { RegisteredWindowGuard } from "./registered-window-guard.js";
6
8
  import { accessSync, constants, realpathSync, statSync } from "node:fs";
@@ -237,9 +239,18 @@ export class MirrorService {
237
239
  catch {
238
240
  /* Unavailable owner. */
239
241
  }
240
- if (!ready || this.disposed || entry.retired || this.channels.get(session) !== entry)
242
+ if (!ready) {
243
+ // Anything but a positive "no such command" stays a refusal.
244
+ const stock = await this.#stockSplitServer();
245
+ if (!stock || this.disposed || entry.retired || this.channels.get(session) !== entry)
246
+ throw new WindowSplitLayoutUnavailable();
247
+ return this.#readStockSplitLayout(entry, target);
248
+ }
249
+ if (this.disposed || entry.retired || this.channels.get(session) !== entry)
241
250
  throw new WindowSplitLayoutUnavailable();
242
251
  }
252
+ if (entry.stockSplitEpoch)
253
+ throw new WindowSplitLayoutUnavailable();
243
254
  const epoch = this.opts.splitLayoutEpoch?.();
244
255
  let supported = false;
245
256
  try {
@@ -260,6 +271,25 @@ export class MirrorService {
260
271
  });
261
272
  return entry.splitAuthority.read(target);
262
273
  }
274
+ async #stockSplitServer() {
275
+ try {
276
+ return (await this.opts.splitLayoutStock?.()) === true;
277
+ }
278
+ catch {
279
+ return false;
280
+ }
281
+ }
282
+ #readStockSplitLayout(entry, target) {
283
+ if (entry.splitAuthority && !entry.stockSplitEpoch)
284
+ throw new WindowSplitLayoutUnavailable();
285
+ const epoch = (entry.stockSplitEpoch ??= randomUUID());
286
+ entry.splitAuthority ??= new WindowSplitAuthority({
287
+ describe: (window) => entry.channel.describeSplitLayout(window, true),
288
+ serverEpoch: () => epoch,
289
+ stock: true,
290
+ });
291
+ return entry.splitAuthority.read(target);
292
+ }
263
293
  /** Resolve only issued handles, then revalidate immediately at native dispatch. */
264
294
  async resizeWindowSplit(session, target, operationId, authorizeBeforeEffect, runNative) {
265
295
  const captured = WindowSplitResizeTargetSchemaZ.parse(target);
@@ -275,16 +305,22 @@ export class MirrorService {
275
305
  await entry.started;
276
306
  const resolved = current().resolve(captured);
277
307
  const successor = current().prepareSuccessor(captured);
278
- const result = await runNative(resolved.request, {
279
- operationId,
280
- serverEpoch: resolved.serverEpoch,
281
- session: resolved.session,
282
- anchor: resolved.anchor,
283
- authorizeBeforeEffect: () => {
284
- current().resolve(captured);
285
- authorizeBeforeEffect();
286
- },
287
- });
308
+ const authorize = () => {
309
+ current().resolve(captured);
310
+ authorizeBeforeEffect();
311
+ };
312
+ const result = entry.stockSplitEpoch
313
+ ? await resizeStockSplit(resolved.request, resolved.session.created, authorize, {
314
+ readOptions: (windowId) => entry.channel.stockSplitOptions(windowId),
315
+ send: (command) => entry.channel.stockSplitCommand(command),
316
+ })
317
+ : await runNative(resolved.request, {
318
+ operationId,
319
+ serverEpoch: resolved.serverEpoch,
320
+ session: resolved.session,
321
+ anchor: resolved.anchor,
322
+ authorizeBeforeEffect: authorize,
323
+ });
288
324
  if (result.status !== "applied")
289
325
  return result;
290
326
  // Native success is retained even if canonical publication is late or diverges.
@@ -1,3 +1,4 @@
1
+ import { STOCK_SPLIT_OPTIONS_FORMAT } from "../protocol/stock-split-resize.js";
1
2
  import { layoutContentRows } from "./layout-content-rows.js";
2
3
  import { decodeNativeAtomicSnapshot, decodeNativeAtomicDualSnapshot, nativeAtomicDualSnapshotPlan, nativeAtomicSnapshotPlan, } from "./native-atomic-snapshot.js";
3
4
  import { boundedTmuxInteractionAppendCommand } from "../../lib/tmux-interaction-retention.js";
@@ -557,7 +558,7 @@ export class SessionChannel {
557
558
  };
558
559
  }
559
560
  /** Exact native ancestry, never reconstructed from published pane rectangles. */
560
- describeSplitLayout(target) {
561
+ describeSplitLayout(target, stock = false) {
561
562
  const authority = this.windowLinkAuthority;
562
563
  const identity = this.attachedIdentity;
563
564
  const generation = this.attachedServerGeneration;
@@ -587,8 +588,8 @@ export class SessionChannel {
587
588
  pane.descriptor?.runtimeSessionId !== identity.runtimeSessionId ||
588
589
  pane.descriptor?.windowId !== resolved.runtimeWindowId ||
589
590
  this.panesBySemantic.get(pane.semanticId) !== pane ||
590
- !birth ||
591
- !/^[1-9]\d*$/u.test(birth) ||
591
+ // A stock server has no birth ids; a server that has them must give valid ones.
592
+ ((!stock || birth) && (!birth || !/^[1-9]\d*$/u.test(birth))) ||
592
593
  !layout.leaves.some((visible) => visible.id === leaf.id &&
593
594
  visible.left === leaf.left &&
594
595
  visible.top === leaf.top &&
@@ -598,7 +599,7 @@ export class SessionChannel {
598
599
  return Object.freeze({
599
600
  runtimePaneId: pane.runtimeId,
600
601
  semanticPaneId: pane.semanticId,
601
- nativePaneBirthId: birth,
602
+ nativePaneBirthId: birth || "",
602
603
  });
603
604
  });
604
605
  return Object.freeze({
@@ -608,9 +609,24 @@ export class SessionChannel {
608
609
  runtimeWindowId: resolved.runtimeWindowId,
609
610
  semanticWindowId: window.semanticId,
610
611
  rawLayout: layout.rawLayout,
612
+ ...(stock ? { paneBorderStatus: window.paneBorderStatus } : {}),
611
613
  panes: Object.freeze(panes),
612
614
  });
613
615
  }
616
+ stockSplitOptions(windowId) {
617
+ return this.io.request(`display-message -p -t ${windowId} "${STOCK_SPLIT_OPTIONS_FORMAT}"`);
618
+ }
619
+ /** One guarded resize on this control connection, for a stock tmux server. */
620
+ stockSplitCommand(command) {
621
+ return new Promise((resolve, reject) => {
622
+ const onReply = (reply) => reply.ok ? resolve(reply.lines) : reject(new Error("Stock split command failed"));
623
+ const limits = { maxBytes: 16 * 1024, maxLines: 4 };
624
+ if (this.io.commandListBoundedInline)
625
+ this.io.commandListBoundedInline(command, 3, 2, limits, onReply);
626
+ else
627
+ this.io.commandListInline(command, 3, 2, onReply);
628
+ });
629
+ }
614
630
  async executeWindowLinkAction(request) {
615
631
  const authority = this.windowLinkAuthority;
616
632
  if (!authority || this.disposed)
@@ -3,6 +3,7 @@ import { z } from "zod";
3
3
  import { NativeJournalUint64SchemaZ, WindowLinkTargetSchemaZ, WindowSplitLayoutResourceSchemaZ, WindowSplitResizeTargetSchemaZ, } from "@tmux-ide/contracts";
4
4
  import { supportsNativeSessionGuard } from "../../lib/native-operation-command.js";
5
5
  import { parseLayoutTree } from "../protocol/layout-parse.js";
6
+ import { stockSplitMovable } from "../protocol/stock-split-resize.js";
6
7
  import { SplitLayoutPublicationPending, } from "./session-channel.js";
7
8
  const MAX_RETAINED_WINDOWS = 32;
8
9
  export class WindowSplitLayoutUnavailable extends Error {
@@ -43,7 +44,8 @@ export class WindowSplitAuthority {
43
44
  snapshot.panes.forEach((pane) => {
44
45
  if (!/^%(0|[1-9][0-9]{0,9})$/u.test(pane.runtimePaneId) ||
45
46
  Number(pane.runtimePaneId.slice(1)) > 0xffffffff ||
46
- !NativeJournalUint64SchemaZ.refine((birth) => birth !== "0").safeParse(pane.nativePaneBirthId).success)
47
+ (!(this.options.stock && pane.nativePaneBirthId === "") &&
48
+ !NativeJournalUint64SchemaZ.refine((birth) => birth !== "0").safeParse(pane.nativePaneBirthId).success))
47
49
  throw new WindowSplitLayoutUnavailable();
48
50
  });
49
51
  const mapping = new Map(snapshot.panes.map((pane) => [pane.runtimePaneId, pane]));
@@ -71,7 +73,12 @@ export class WindowSplitAuthority {
71
73
  }
72
74
  node.children.forEach((child, index) => {
73
75
  const childPath = [...path, index];
74
- if (index < node.children.length - 1) {
76
+ if (index < node.children.length - 1 &&
77
+ (!this.options.stock ||
78
+ stockSplitMovable(tree, childPath, node.axis, {
79
+ borderStatus: snapshot.paneBorderStatus ?? "off",
80
+ scrollbar: 0,
81
+ }))) {
75
82
  const splitId = randomUUID();
76
83
  paths.set(splitId, childPath);
77
84
  splits.push({
@@ -11,7 +11,7 @@ function json(text, limit) {
11
11
  throw new Error("Bounded native response required");
12
12
  return JSON.parse(text);
13
13
  }
14
- function capability(text) {
14
+ export function nativeSplitCapability(text) {
15
15
  const value = json(text, 1024);
16
16
  return (object(value, [
17
17
  "schemaVersion",
@@ -31,13 +31,13 @@ function capability(text) {
31
31
  /** Read-only, uncached probe; the caller pins and bounds the selected server. */
32
32
  export async function supportsNativeSplitResize(runTmux) {
33
33
  try {
34
- return capability(await runTmux(["tmux-ide-resize-split", "-V"]));
34
+ return nativeSplitCapability(await runTmux(["tmux-ide-resize-split", "-V"]));
35
35
  }
36
36
  catch {
37
37
  return false;
38
38
  }
39
39
  }
40
- function validTree(tree) {
40
+ export function validSplitTree(tree) {
41
41
  let budget = 5;
42
42
  const visit = (node) => {
43
43
  if (node.left + node.width > 4096 || node.top + node.height > 4096)
@@ -55,7 +55,7 @@ function validTree(tree) {
55
55
  };
56
56
  return visit(tree);
57
57
  }
58
- function locate(tree, path) {
58
+ export function locateSplit(tree, path) {
59
59
  let node = tree;
60
60
  let parent;
61
61
  for (const index of path) {
@@ -66,7 +66,7 @@ function locate(tree, path) {
66
66
  }
67
67
  return parent && path.at(-1) < parent.children.length - 1 ? { parent, node } : null;
68
68
  }
69
- function edge(node, axis) {
69
+ export function splitEdge(node, axis) {
70
70
  return axis === "cols" ? node.left + node.width : node.top + node.height;
71
71
  }
72
72
  function sameRect(a, b) {
@@ -75,7 +75,7 @@ function sameRect(a, b) {
75
75
  /** Only geometry inside the exact parent may change, along the requested axis.
76
76
  * Native redistribution can affect multiple siblings. This verifies convergence,
77
77
  * not exclusive causation or authentication of the returned layout. */
78
- function preservesTree(before, after, affected, axis, inside = false) {
78
+ export function preservesSplitTree(before, after, affected, axis, inside = false) {
79
79
  const begins = before === affected;
80
80
  if (before.kind !== after.kind || ((!inside || begins) && !sameRect(before, after)))
81
81
  return false;
@@ -90,7 +90,7 @@ function preservesTree(before, after, affected, axis, inside = false) {
90
90
  return (after.kind === "split" &&
91
91
  before.axis === after.axis &&
92
92
  before.children.length === after.children.length &&
93
- before.children.every((child, index) => preservesTree(child, after.children[index], affected, axis, inside)));
93
+ before.children.every((child, index) => preservesSplitTree(child, after.children[index], affected, axis, inside)));
94
94
  }
95
95
  /** Internal foundation only; no route or native capability is enabled here.
96
96
  * Capability is checked on every invocation, never cached across generations.
@@ -117,9 +117,9 @@ export async function resizeNativeSplit(request, runTmux) {
117
117
  request.boundary > 4096)
118
118
  return { status: "refused", reason: "invalid-request" };
119
119
  const tree = parseLayoutTree(request.expectedLayout);
120
- if (!tree || !validTree(tree))
120
+ if (!tree || !validSplitTree(tree))
121
121
  return { status: "refused", reason: "invalid-request" };
122
- const selected = locate(tree, request.path);
122
+ const selected = locateSplit(tree, request.path);
123
123
  if (!selected || selected.parent.axis !== request.axis)
124
124
  return { status: "refused", reason: "invalid-request" };
125
125
  before = tree;
@@ -130,7 +130,7 @@ export async function resizeNativeSplit(request, runTmux) {
130
130
  return { status: "refused", reason: "invalid-request" };
131
131
  }
132
132
  try {
133
- if (!capability(await runTmux(["tmux-ide-resize-split", "-V"])))
133
+ if (!nativeSplitCapability(await runTmux(["tmux-ide-resize-split", "-V"])))
134
134
  return { status: "refused", reason: "unsupported" };
135
135
  }
136
136
  catch {
@@ -168,14 +168,14 @@ export async function resizeNativeSplit(request, runTmux) {
168
168
  receipt.boundary > 4096)
169
169
  return { status: "uncertain", reason: "invalid-receipt" };
170
170
  const after = parseLayoutTree(receipt.layout);
171
- const original = locate(before, captured.path);
172
- const actual = after && locate(after, captured.path);
173
- const previous = edge(original.node, captured.axis);
171
+ const original = locateSplit(before, captured.path);
172
+ const actual = after && locateSplit(after, captured.path);
173
+ const previous = splitEdge(original.node, captured.axis);
174
174
  if (!after ||
175
- !validTree(after) ||
175
+ !validSplitTree(after) ||
176
176
  !actual ||
177
- !preservesTree(before, after, original.parent, captured.axis) ||
178
- receipt.boundary !== edge(actual.node, captured.axis) ||
177
+ !preservesSplitTree(before, after, original.parent, captured.axis) ||
178
+ receipt.boundary !== splitEdge(actual.node, captured.axis) ||
179
179
  receipt.boundary < Math.min(previous, captured.boundary) ||
180
180
  receipt.boundary > Math.max(previous, captured.boundary))
181
181
  return { status: "uncertain", reason: "invalid-receipt" };