tmux-ide 2.9.21 → 2.9.22

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 (69) hide show
  1. package/bin/cli.js +5282 -3386
  2. package/package.json +1 -1
  3. package/packages/contracts/src/index.ts +1 -0
  4. package/packages/contracts/src/pane-reader.ts +121 -0
  5. package/packages/contracts/src/pane-stream.ts +18 -0
  6. package/packages/contracts/src/visual-theme-presets.ts +58 -2
  7. package/packages/daemon/dist/command-center/tmux-server-reader.js +41 -0
  8. package/packages/daemon/dist/command-center/tmux-servers.js +6 -0
  9. package/packages/daemon/dist/doctor.js +106 -43
  10. package/packages/daemon/dist/lib/cli-command.js +13 -0
  11. package/packages/daemon/dist/lib/daemon-embed.js +15 -0
  12. package/packages/daemon/dist/lib/pane-reader-files.js +226 -0
  13. package/packages/daemon/dist/lib/remote-tmux-command.js +8 -5
  14. package/packages/daemon/dist/lib/tmux-client-execution.js +73 -7
  15. package/packages/daemon/dist/lib/tmux-pane-reader.js +105 -0
  16. package/packages/daemon/dist/lib/tmux-server-features.js +38 -0
  17. package/packages/daemon/dist/lib/tmux-server-owner.js +9 -0
  18. package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/Info.plist +2 -2
  19. package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/MacOS/tmux-ide-notifier +0 -0
  20. package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/Resources/Assets.car +0 -0
  21. package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/_CodeSignature/CodeResources +2 -2
  22. package/packages/daemon/dist/open-browser.js +26 -12
  23. package/packages/daemon/dist/open-reader.js +84 -0
  24. package/packages/daemon/dist/plugins/daemon-plugins.js +2 -10
  25. package/packages/daemon/dist/restore.js +57 -40
  26. package/packages/daemon/dist/terminal/mirror/session-channel.js +4 -1
  27. package/packages/daemon/dist/terminal/pane-stream/pane-stream-websocket.js +12 -3
  28. package/packages/daemon/dist/terminal/protocol/reader-option.js +66 -0
  29. package/packages/daemon/dist/terminal/protocol/session-descriptor-discovery.js +7 -2
  30. package/packages/daemon/dist/tmux-upgrade/cli.js +106 -0
  31. package/packages/daemon/dist/tmux-upgrade/io.js +540 -0
  32. package/packages/daemon/dist/tmux-upgrade/plan.js +238 -0
  33. package/packages/daemon/dist/tmux-upgrade/run.js +199 -0
  34. package/packages/daemon/dist/tui/chrome/snapshot.js +3 -4
  35. package/packages/daemon/dist/tui/mirror/runtime/application-home-agent-navigation.js +64 -4
  36. package/packages/daemon/dist/tui/mirror/runtime/application-home-agents-owner.js +35 -5
  37. package/packages/daemon/dist/tui/mirror/runtime/application-machine-agent-navigation.js +12 -8
  38. package/packages/daemon/dist/tui/mirror/runtime/application-terminal-interaction-controller.js +125 -111
  39. package/packages/daemon/src/command-center/tmux-server-reader.ts +62 -0
  40. package/packages/daemon/src/command-center/tmux-servers.ts +6 -0
  41. package/packages/daemon/src/doctor.ts +118 -45
  42. package/packages/daemon/src/lib/cli-command.ts +16 -0
  43. package/packages/daemon/src/lib/daemon-embed.ts +17 -0
  44. package/packages/daemon/src/lib/pane-reader-files.ts +294 -0
  45. package/packages/daemon/src/lib/remote-tmux-command.ts +13 -6
  46. package/packages/daemon/src/lib/tmux-client-execution.ts +79 -7
  47. package/packages/daemon/src/lib/tmux-pane-reader.ts +144 -0
  48. package/packages/daemon/src/lib/tmux-server-features.ts +43 -0
  49. package/packages/daemon/src/lib/tmux-server-owner.ts +9 -0
  50. package/packages/daemon/src/open-browser.ts +59 -18
  51. package/packages/daemon/src/open-reader.ts +148 -0
  52. package/packages/daemon/src/plugins/daemon-plugins.ts +2 -12
  53. package/packages/daemon/src/restore.ts +80 -44
  54. package/packages/daemon/src/terminal/mirror/events.ts +2 -0
  55. package/packages/daemon/src/terminal/mirror/session-channel.ts +6 -1
  56. package/packages/daemon/src/terminal/pane-stream/pane-stream-websocket.ts +15 -2
  57. package/packages/daemon/src/terminal/protocol/reader-option.ts +77 -0
  58. package/packages/daemon/src/terminal/protocol/session-descriptor-discovery.ts +10 -1
  59. package/packages/daemon/src/tmux-upgrade/cli.ts +118 -0
  60. package/packages/daemon/src/tmux-upgrade/io.ts +596 -0
  61. package/packages/daemon/src/tmux-upgrade/plan.ts +353 -0
  62. package/packages/daemon/src/tmux-upgrade/run.ts +325 -0
  63. package/packages/daemon/src/tui/chrome/snapshot.ts +3 -4
  64. package/packages/daemon/src/tui/mirror/runtime/application-home-agent-navigation.ts +110 -10
  65. package/packages/daemon/src/tui/mirror/runtime/application-home-agents-owner.ts +58 -6
  66. package/packages/daemon/src/tui/mirror/runtime/application-machine-agent-navigation.ts +20 -9
  67. package/packages/daemon/src/tui/mirror/runtime/application-root-v2.tsx +2 -2
  68. package/packages/daemon/src/tui/mirror/runtime/application-terminal-interaction-controller.ts +149 -128
  69. package/packages/tmux-bridge/src/runner.ts +3 -1
@@ -1,13 +1,18 @@
1
1
  import { retainsAgentControl } from "./application-retained-agent.js";
2
2
  import { createApplicationHomeAgentNavigator, } from "./application-home-agent-navigation.js";
3
3
  import { applicationGenerationNavigationKey } from "./application-generation-starter.js";
4
- import { waitForHomeAgentSemantic } from "./application-home-agents-owner.js";
4
+ import { agentOpeningOwnsKey, waitForHomeAgentListed, waitForHomeAgentSemantic, } from "./application-home-agents-owner.js";
5
5
  /** Machine identity fences the existing exact-agent admission owner. No independent input path. */
6
6
  export function createApplicationMachineAgentNavigator(options) {
7
7
  let current = null;
8
8
  let disposed = false;
9
9
  let opening = false;
10
10
  let request = 0;
11
+ const cancel = () => {
12
+ request++;
13
+ opening = false;
14
+ current?.cancel();
15
+ };
11
16
  return {
12
17
  open(machineId, target, source = "mouse") {
13
18
  current?.dispose();
@@ -23,7 +28,7 @@ export function createApplicationMachineAgentNavigator(options) {
23
28
  retainsAgentControl(generation(), target)) {
24
29
  // Reserve before the next key; the terminal controller waits for a fresh
25
30
  // coherent runtime and remains the only owner of physical input.
26
- options.selectPane(target.paneId, source);
31
+ options.selectPane(target.paneId);
27
32
  options.showTerminals(source);
28
33
  options.setNote(null);
29
34
  opening = false;
@@ -47,8 +52,9 @@ export function createApplicationMachineAgentNavigator(options) {
47
52
  };
48
53
  },
49
54
  waitForGeneration: (key, signal) => waitForHomeAgentSemantic(generation, key, signal),
55
+ waitForAgent: (key, listed, signal) => waitForHomeAgentListed(generation, key, listed, signal),
50
56
  startGeneration: (session, prepared, origin, focus, admission) => options.startGeneration(session, prepared, origin, focus, () => selected() && options.isCurrentTarget(machineId, target) && (admission?.() ?? true)),
51
- selectPane: options.selectPane,
57
+ selectPane: (paneId, _source, admission) => admission ? options.selectPane(paneId, admission) : options.selectPane(paneId),
52
58
  showTerminals: options.showTerminals,
53
59
  setNote: options.setNote,
54
60
  });
@@ -58,11 +64,9 @@ export function createApplicationMachineAgentNavigator(options) {
58
64
  });
59
65
  },
60
66
  opening: () => opening,
61
- cancel() {
62
- request++;
63
- opening = false;
64
- current?.cancel();
65
- },
67
+ cancel,
68
+ /** Esc cancels an open in progress; other keys are ignored meanwhile. */
69
+ ownsKey: (name) => agentOpeningOwnsKey(name, { opening: () => opening, cancel }),
66
70
  dispose() {
67
71
  disposed = true;
68
72
  request++;
@@ -525,88 +525,110 @@ export function createApplicationTerminalInteractionController(options) {
525
525
  return;
526
526
  finishLinkSelection(snapshot.current !== null && paneForWindow(snapshot.current) === pending.paneId);
527
527
  };
528
- const paneInput = new TerminalPaneInputRouter({
529
- select: async (paneId) => {
530
- finishLinkSelection(false);
531
- const initial = options.generation();
532
- const selectionControl = controlIdentity(initial);
533
- const selectionVersion = paneInput.selectionVersion;
534
- const selectionCurrent = () => paneInput.selectionVersion === selectionVersion &&
535
- sameControl(selectionControl, controlIdentity(selectionGeneration));
536
- const panePresent = () => selectionLayout.windows.some((window) => window.panes.some((pane) => pane.pane === paneId));
537
- if (initial?.status === "rebinding") {
538
- // Reserve the optimistic target now, but send its FIRST mutation only
539
- // after this same control connection has a coherent terminal runtime.
540
- const ready = await selectionWaiter.wait(() => {
541
- if (!selectionCurrent())
542
- return false;
543
- const active = selectionGeneration;
544
- if (active?.status !== "live" || observedLayoutEpoch !== active.rendererEpoch)
545
- return "pending";
546
- return panePresent();
547
- });
548
- if (!ready || !selectionCurrent())
528
+ // The one way a pane selection reaches the runtime (#764: also used once an
529
+ // admitted agent selection settles).
530
+ const selectInRuntime = async (paneId) => {
531
+ finishLinkSelection(false);
532
+ const initial = options.generation();
533
+ const selectionControl = controlIdentity(initial);
534
+ const selectionVersion = paneInput.selectionVersion;
535
+ const selectionCurrent = () => paneInput.selectionVersion === selectionVersion &&
536
+ sameControl(selectionControl, controlIdentity(selectionGeneration));
537
+ const panePresent = () => selectionLayout.windows.some((window) => window.panes.some((pane) => pane.pane === paneId));
538
+ if (initial?.status === "rebinding") {
539
+ // Reserve the optimistic target now, but send its FIRST mutation only
540
+ // after this same control connection has a coherent terminal runtime.
541
+ const ready = await selectionWaiter.wait(() => {
542
+ if (!selectionCurrent())
549
543
  return false;
550
- }
551
- const expected = liveSelectionTarget();
552
- let dispatchedRendererEpoch;
553
- const selecting = pendingWindowSwitch;
554
- const operationId = selecting?.traceId;
555
- const selectionFailure = { current: null };
556
- const receipt = expected
557
- ? await selectTerminalPane(expected, () => {
558
- if (!selectionControl)
559
- return liveSelectionTarget();
560
- return sameControl(selectionControl, controlIdentity(options.generation()))
561
- ? expected
562
- : null;
563
- }, paneId, operationId, (failure) => {
564
- selectionFailure.current = failure;
565
- }, windowLinkForPane(options.layout(), paneId) ?? undefined, () => {
566
- dispatchedRendererEpoch = options.generation()?.rendererEpoch;
567
- })
568
- : null;
569
- if (receipt === null &&
570
- selectionFailure.current?.reason === "topology-changed" &&
571
- selectionCurrent()) {
572
- // The daemon may have selected the pane before retiring its stream.
573
- // Observe the replacement runtime; never resubmit an uncertain command
574
- // or manufacture an operation receipt. Input still waits on this promise.
575
- const confirmed = await selectionWaiter.wait(() => {
576
- if (!selectionCurrent())
577
- return false;
578
- const active = selectionGeneration;
579
- if (active?.status !== "live" ||
580
- active.rendererEpoch === dispatchedRendererEpoch ||
581
- observedLayoutEpoch !== active.rendererEpoch)
582
- return "pending";
583
- if (!panePresent())
584
- return false;
585
- const current = selectionLayout.current;
586
- const activePanes = current?.panes.filter((pane) => pane.active) ?? [];
587
- if (!current?.currentWindow || activePanes.length !== 1)
588
- return "pending";
589
- return activePanes[0]?.pane === paneId ? true : "pending";
590
- });
591
- if (selecting && pendingWindowSwitch === selecting)
592
- pendingWindowSwitch = null;
593
- return confirmed && selectionCurrent();
594
- }
595
- if (selecting && pendingWindowSwitch === selecting) {
596
- const receiptAtMicros = options.detailedWindowSwitchTiming ? diagnosticNowMicros() : null;
597
- if (selecting.timing)
598
- selecting.timing.receiptAtMicros = receiptAtMicros;
599
- selecting.selectionApplied =
600
- receipt?.applied === true &&
601
- receipt.operationId === selecting.traceId &&
602
- receipt.semanticPaneId === selecting.paneId;
603
- diagnose("window-switch-receipt", {
544
+ const active = selectionGeneration;
545
+ if (active?.status !== "live" || observedLayoutEpoch !== active.rendererEpoch)
546
+ return "pending";
547
+ return panePresent();
548
+ });
549
+ if (!ready || !selectionCurrent())
550
+ return false;
551
+ }
552
+ const expected = liveSelectionTarget();
553
+ let dispatchedRendererEpoch;
554
+ const selecting = pendingWindowSwitch;
555
+ const operationId = selecting?.traceId;
556
+ const selectionFailure = { current: null };
557
+ const receipt = expected
558
+ ? await selectTerminalPane(expected, () => {
559
+ if (!selectionControl)
560
+ return liveSelectionTarget();
561
+ return sameControl(selectionControl, controlIdentity(options.generation()))
562
+ ? expected
563
+ : null;
564
+ }, paneId, operationId, (failure) => {
565
+ selectionFailure.current = failure;
566
+ }, windowLinkForPane(options.layout(), paneId) ?? undefined, () => {
567
+ dispatchedRendererEpoch = options.generation()?.rendererEpoch;
568
+ })
569
+ : null;
570
+ if (receipt === null &&
571
+ selectionFailure.current?.reason === "topology-changed" &&
572
+ selectionCurrent()) {
573
+ // The daemon may have selected the pane before retiring its stream.
574
+ // Observe the replacement runtime; never resubmit an uncertain command
575
+ // or manufacture an operation receipt. Input still waits on this promise.
576
+ const confirmed = await selectionWaiter.wait(() => {
577
+ if (!selectionCurrent())
578
+ return false;
579
+ const active = selectionGeneration;
580
+ if (active?.status !== "live" ||
581
+ active.rendererEpoch === dispatchedRendererEpoch ||
582
+ observedLayoutEpoch !== active.rendererEpoch)
583
+ return "pending";
584
+ if (!panePresent())
585
+ return false;
586
+ const current = selectionLayout.current;
587
+ const activePanes = current?.panes.filter((pane) => pane.active) ?? [];
588
+ if (!current?.currentWindow || activePanes.length !== 1)
589
+ return "pending";
590
+ return activePanes[0]?.pane === paneId ? true : "pending";
591
+ });
592
+ if (selecting && pendingWindowSwitch === selecting)
593
+ pendingWindowSwitch = null;
594
+ return confirmed && selectionCurrent();
595
+ }
596
+ if (selecting && pendingWindowSwitch === selecting) {
597
+ const receiptAtMicros = options.detailedWindowSwitchTiming ? diagnosticNowMicros() : null;
598
+ if (selecting.timing)
599
+ selecting.timing.receiptAtMicros = receiptAtMicros;
600
+ selecting.selectionApplied =
601
+ receipt?.applied === true &&
602
+ receipt.operationId === selecting.traceId &&
603
+ receipt.semanticPaneId === selecting.paneId;
604
+ diagnose("window-switch-receipt", {
605
+ traceId: selecting.traceId,
606
+ target: selecting.target,
607
+ paneId: selecting.paneId,
608
+ operationId: receipt?.operationId ?? null,
609
+ selected: receipt !== null,
610
+ applied: receipt?.applied === true,
611
+ daemonGeneration: selecting.daemonGeneration,
612
+ clientGeneration: selecting.clientGeneration,
613
+ rendererEpoch: selecting.rendererEpoch,
614
+ sourceEpoch: selecting.sourceEpoch,
615
+ generation: selecting.generation,
616
+ incarnation: selecting.incarnation,
617
+ revision: selecting.revision,
618
+ stateHash: selecting.stateHash,
619
+ cols: selecting.cols,
620
+ rows: selecting.rows,
621
+ failureStage: selectionFailure.current?.stage ?? (expected ? null : "pre-dispatch"),
622
+ failureReason: selectionFailure.current?.reason ?? (expected ? null : "generation-replaced"),
623
+ failureBackendReason: selectionFailure.current?.backendReason ?? null,
624
+ durationMicros: receiptAtMicros === null ? null : receiptAtMicros - selecting.startedAtMicros,
625
+ ...(receiptAtMicros === null ? {} : { phaseAtMicros: receiptAtMicros }),
626
+ });
627
+ if (!selecting.selectionApplied) {
628
+ diagnoseCritical(`window-switch:${selecting.traceId}:failed`, "window-switch-failed", {
604
629
  traceId: selecting.traceId,
605
630
  target: selecting.target,
606
631
  paneId: selecting.paneId,
607
- operationId: receipt?.operationId ?? null,
608
- selected: receipt !== null,
609
- applied: receipt?.applied === true,
610
632
  daemonGeneration: selecting.daemonGeneration,
611
633
  clientGeneration: selecting.clientGeneration,
612
634
  rendererEpoch: selecting.rendererEpoch,
@@ -617,40 +639,21 @@ export function createApplicationTerminalInteractionController(options) {
617
639
  stateHash: selecting.stateHash,
618
640
  cols: selecting.cols,
619
641
  rows: selecting.rows,
620
- failureStage: selectionFailure.current?.stage ?? (expected ? null : "pre-dispatch"),
621
- failureReason: selectionFailure.current?.reason ?? (expected ? null : "generation-replaced"),
622
- failureBackendReason: selectionFailure.current?.backendReason ?? null,
642
+ stage: selectionFailure.current?.stage ?? (expected ? "receipt" : "pre-dispatch"),
643
+ reason: selectionFailure.current?.reason ??
644
+ (expected ? "receipt-invalid" : "generation-replaced"),
645
+ backendReason: selectionFailure.current?.backendReason ?? null,
623
646
  durationMicros: receiptAtMicros === null ? null : receiptAtMicros - selecting.startedAtMicros,
624
- ...(receiptAtMicros === null ? {} : { phaseAtMicros: receiptAtMicros }),
625
647
  });
626
- if (!selecting.selectionApplied) {
627
- diagnoseCritical(`window-switch:${selecting.traceId}:failed`, "window-switch-failed", {
628
- traceId: selecting.traceId,
629
- target: selecting.target,
630
- paneId: selecting.paneId,
631
- daemonGeneration: selecting.daemonGeneration,
632
- clientGeneration: selecting.clientGeneration,
633
- rendererEpoch: selecting.rendererEpoch,
634
- sourceEpoch: selecting.sourceEpoch,
635
- generation: selecting.generation,
636
- incarnation: selecting.incarnation,
637
- revision: selecting.revision,
638
- stateHash: selecting.stateHash,
639
- cols: selecting.cols,
640
- rows: selecting.rows,
641
- stage: selectionFailure.current?.stage ?? (expected ? "receipt" : "pre-dispatch"),
642
- reason: selectionFailure.current?.reason ??
643
- (expected ? "receipt-invalid" : "generation-replaced"),
644
- backendReason: selectionFailure.current?.backendReason ?? null,
645
- durationMicros: receiptAtMicros === null ? null : receiptAtMicros - selecting.startedAtMicros,
646
- });
647
- pendingWindowSwitch = null;
648
- return false;
649
- }
650
- maybeRequestWindowSwitchFrame();
648
+ pendingWindowSwitch = null;
649
+ return false;
651
650
  }
652
- return receipt !== null;
653
- },
651
+ maybeRequestWindowSwitchFrame();
652
+ }
653
+ return receipt !== null;
654
+ };
655
+ const paneInput = new TerminalPaneInputRouter({
656
+ select: (paneId) => selectInRuntime(paneId),
654
657
  send: async (paneId, routed) => {
655
658
  const { input, parserOrigin } = routed;
656
659
  const selectionVersion = paneInput.selectionVersion;
@@ -913,9 +916,20 @@ export function createApplicationTerminalInteractionController(options) {
913
916
  maybeRequestWindowSwitchFrame();
914
917
  maybeRequestPaneResizeFrame();
915
918
  },
916
- selectPane: (paneId) => {
919
+ selectPane: (paneId, admission) => {
917
920
  finishLinkSelection(false);
918
- paneInput.selectPane(paneId);
921
+ if (admission)
922
+ // Ordered now; selected only once admitted, otherwise held input drops.
923
+ paneInput.selectPane(paneId, {
924
+ presentOptimistically: false,
925
+ selection: () => {
926
+ // A later selection supersedes this one: never select it after all.
927
+ const version = paneInput.selectionVersion;
928
+ return admission.then((admitted) => admitted && paneInput.selectionVersion === version ? selectInRuntime(paneId) : false);
929
+ },
930
+ });
931
+ else
932
+ paneInput.selectPane(paneId);
919
933
  selectionWaiter.reconcile();
920
934
  },
921
935
  async unlinkWindowLink(target) {
@@ -0,0 +1,62 @@
1
+ import type { Context, Hono } from "hono";
2
+ import { z } from "zod";
3
+ import {
4
+ PaneReaderAssetRequestSchemaZ,
5
+ PaneReaderRequestSchemaZ,
6
+ TmuxServerScopeSchemaZ,
7
+ } from "@tmux-ide/contracts";
8
+ import { TmuxServerScopeError, type TmuxServerOwners } from "../lib/tmux-server-owners.ts";
9
+ import type { NativeTmuxServerOwner } from "../lib/tmux-server-owner.ts";
10
+
11
+ /**
12
+ * The native Markdown reader's routes (card #756). Mount only below the
13
+ * owner-authenticated, no-store scoped router. Responses never carry a path,
14
+ * a file-system error or validation detail.
15
+ */
16
+ export function mountTmuxServerReaderRoutes(
17
+ app: Hono,
18
+ options: {
19
+ readonly scopedPath: string;
20
+ readonly owners: TmuxServerOwners<NativeTmuxServerOwner>;
21
+ readonly readBody: (request: Request) => Promise<unknown>;
22
+ },
23
+ ): void {
24
+ const handle =
25
+ (schema: z.ZodType<{ target: { generation: string } }>, kind: "read" | "asset") =>
26
+ async (c: Context) => {
27
+ const scope = TmuxServerScopeSchemaZ.safeParse({
28
+ serverId: c.req.param("serverId"),
29
+ generation: c.req.param("generation"),
30
+ });
31
+ if (!scope.success) return c.json({ error: { code: "invalid-request" } }, 400);
32
+ let request: { target: { generation: string } };
33
+ try {
34
+ request = schema.parse(await options.readBody(c.req.raw));
35
+ } catch {
36
+ return c.json({ error: { code: "invalid-request" } }, 400);
37
+ }
38
+ if (request.target.generation !== scope.data.generation)
39
+ return c.json({ error: { code: "stale-generation" } }, 409);
40
+ try {
41
+ c.req.raw.signal.throwIfAborted();
42
+ const response: unknown = await options.owners.withOwner(
43
+ scope.data,
44
+ (owner): Promise<unknown> =>
45
+ kind === "read"
46
+ ? owner.paneReader.read(request, c.req.raw.signal)
47
+ : owner.paneReader.asset(request, c.req.raw.signal),
48
+ );
49
+ c.req.raw.signal.throwIfAborted();
50
+ return c.json(response);
51
+ } catch (error) {
52
+ if (error instanceof TmuxServerScopeError)
53
+ return c.json(
54
+ { error: { code: "scope-unavailable" } },
55
+ error.code === "not-found" ? 404 : 409,
56
+ );
57
+ return c.json({ error: { code: "reader-unavailable" } }, 503);
58
+ }
59
+ };
60
+ app.post(`${options.scopedPath}/reader`, handle(PaneReaderRequestSchemaZ, "read"));
61
+ app.post(`${options.scopedPath}/reader/asset`, handle(PaneReaderAssetRequestSchemaZ, "asset"));
62
+ }
@@ -5,6 +5,7 @@ import { WindowSplitLayoutUnavailable } from "../terminal/mirror/window-split-au
5
5
  import { streamTmuxInteractions } from "./tmux-server-interaction-events.ts";
6
6
  import { mountTmuxServerNativeBackingRoute } from "./tmux-server-native-backing.ts";
7
7
  import { mountTmuxServerEditorContextRoute } from "./tmux-server-editor-context.ts";
8
+ import { mountTmuxServerReaderRoutes } from "./tmux-server-reader.ts";
8
9
  import { Hono, type Context } from "hono";
9
10
  import { streamSSE } from "hono/streaming";
10
11
  import { projectApplicationShellResource } from "./resources/application-shell.ts";
@@ -157,6 +158,11 @@ export function mountTmuxServerRoutes(app: Hono, options: TmuxServerRoutesOption
157
158
  owners: options.owners,
158
159
  readBody: (request) => boundedJson(request, 8 * 1024),
159
160
  });
161
+ mountTmuxServerReaderRoutes(app, {
162
+ scopedPath: scoped,
163
+ owners: options.owners,
164
+ readBody: (request) => boundedJson(request, 8 * 1024),
165
+ });
160
166
  app.post(
161
167
  `${scoped}/native-browser`,
162
168
  route(async (c) => {
@@ -2,10 +2,13 @@ import { requireSupportedTmuxVersion } from "./lib/tmux-version.ts";
2
2
  import { resolveTmuxExecutable } from "./lib/tmux-client-execution.ts";
3
3
  import { TMUX_SOCKET_PATH_ENV } from "./lib/runtime-namespace.ts";
4
4
  import { execSync, execFileSync } from "node:child_process";
5
- import { accessSync, constants, existsSync, mkdtempSync, rmSync } from "node:fs";
5
+ import { accessSync, constants, existsSync, mkdtempSync, realpathSync, rmSync } from "node:fs";
6
6
  import { tmpdir } from "node:os";
7
- import { resolve, dirname, join } from "node:path";
8
- import { nativeSplitCapability } from "./terminal/protocol/native-split-resize.ts";
7
+ import { delimiter, resolve, dirname, join } from "node:path";
8
+ import { resolveBundledTmux } from "./lib/bundled-tmux.ts";
9
+ import { readSnapshot } from "./tui/chrome/snapshot.ts";
10
+ import { isListableSession } from "./tui/team/sessions.ts";
11
+ import { nativeCommands, type NativeAnswer, type TmuxProbe } from "./lib/tmux-server-features.ts";
9
12
  import { fileURLToPath } from "node:url";
10
13
  import { getCurrentVersion, getUpdateStatus } from "./lib/update-check.ts";
11
14
  import { installedSkillVersion } from "./lib/skill-sync.ts";
@@ -179,54 +182,20 @@ function check(
179
182
  }
180
183
  }
181
184
 
182
- type TmuxProbe = (args: readonly string[]) => string;
183
- const UNKNOWN = (command: string) => new RegExp(`^unknown command: ${command}$`, "mu");
184
-
185
- type NativeAnswer = "full" | "stock" | "older" | "partial" | "no-server" | "unknown";
186
- /** The same reading of the server as the mirror's: the stock resize when it refuses
187
- * the split command by name, and full only with the split capability it requires. */
188
- function nativeCommands(probe: TmuxProbe): NativeAnswer {
189
- const ask = (command: string) => {
190
- try {
191
- return { output: probe([command, "-V"]) };
192
- } catch (error) {
193
- const failure = error as { stderr?: unknown; message?: string };
194
- return { failure: String(failure.stderr ?? failure.message ?? "") };
195
- }
196
- };
197
- const split = ask("tmux-ide-resize-split");
198
- const events = ask("tmux-ide-events");
199
- const failures = [split.failure, events.failure].filter((text) => text !== undefined);
200
- if (failures.some((text) => /no server running|error connecting/u.test(text!)))
201
- return "no-server";
202
- const refused = (answer: { failure?: string }, command: string) =>
203
- answer.failure !== undefined && UNKNOWN(command).test(answer.failure);
204
- if (refused(split, "tmux-ide-resize-split")) {
205
- if (refused(events, "tmux-ide-events")) return "stock";
206
- // The journal answers: a tmux-ide tmux built before the split command.
207
- if (events.output !== undefined) return "older";
208
- return "unknown";
209
- }
210
- if (split.output !== undefined && events.output !== undefined) {
211
- try {
212
- return nativeSplitCapability(split.output) ? "full" : "partial";
213
- } catch {
214
- return "partial";
215
- }
216
- }
217
- return failures.length === 2 ? "unknown" : "partial";
218
- }
219
-
220
185
  /** Reads the server a session would use. With none running, a throwaway private
221
186
  * server shows what the resolved binary would start. */
222
187
  export function tmuxFeaturesRow(probeServer: TmuxProbe, probeBinary: TmuxProbe): CheckResult {
223
188
  let answer = nativeCommands(probeServer);
224
- if (answer === "no-server") answer = nativeCommands(probeBinary);
189
+ const running = answer !== "no-server";
190
+ if (!running) answer = nativeCommands(probeBinary);
191
+ // Only a running server can be moved; the command restarts it and restores its sessions.
192
+ const upgrade = running
193
+ ? "; run `tmux-ide servers upgrade` to move it to tmux-ide's own tmux"
194
+ : "";
225
195
  const details: Record<NativeAnswer, string> = {
226
196
  full: "bundled tmux: full features",
227
- stock: "stock tmux: reduced features",
228
- older:
229
- "older tmux-ide tmux: reduced features (restart it with tmux-ide's own tmux for every feature; that ends its sessions)",
197
+ stock: `stock tmux: reduced features${upgrade}`,
198
+ older: `older tmux-ide tmux: reduced features${upgrade}`,
230
199
  partial: "this tmux has only some tmux-ide commands: no pane dividers",
231
200
  "no-server": "could not read the tmux server's features",
232
201
  unknown: "could not read the tmux server's features",
@@ -239,6 +208,108 @@ export function tmuxFeaturesRow(probeServer: TmuxProbe, probeBinary: TmuxProbe):
239
208
  };
240
209
  }
241
210
 
211
+ /**
212
+ * PURE — what a plain `tmux` typed in a shell runs. Informational: when it is
213
+ * not tmux-ide's own tmux and it starts the server, features drop (#766).
214
+ */
215
+ export function plainTmuxRow(pathTmux: string | null, bundled: string | null): CheckResult {
216
+ const label = "plain `tmux` in your shell";
217
+ if (!pathTmux)
218
+ return {
219
+ label,
220
+ pass: true,
221
+ detail: "not on PATH (tmux-ide uses its own tmux)",
222
+ optional: true,
223
+ };
224
+ if (bundled && pathTmux === bundled)
225
+ return { label, pass: true, detail: `tmux-ide's own tmux (${pathTmux})`, optional: true };
226
+ return {
227
+ label,
228
+ pass: true,
229
+ detail: `${pathTmux}; if it starts the server, features drop (see docs: tmux upgrade)`,
230
+ optional: true,
231
+ };
232
+ }
233
+
234
+ const DAY_MS = 24 * 60 * 60 * 1000;
235
+
236
+ /**
237
+ * PURE — is the crash snapshot fresh enough to restore from? It fails when it
238
+ * is missing a live session, or is over a day old while sessions run. Only the
239
+ * chrome updater writes it, and that runs only while a session is adopted.
240
+ */
241
+ export function snapshotRow(
242
+ snapshot: { savedAt: string; sessions: readonly { name: string }[] } | null,
243
+ liveSessions: readonly string[] | null,
244
+ nowMs: number,
245
+ ): CheckResult {
246
+ const label = "crash snapshot (restore)";
247
+ const hint =
248
+ "Only the chrome updater writes it, while a session is adopted: `tmux-ide adopt --all` starts it";
249
+ if (!snapshot) {
250
+ return liveSessions?.length
251
+ ? { label, pass: false, detail: `none yet. ${hint}`, optional: true }
252
+ : { label, pass: true, detail: "none yet (no sessions running)", optional: true };
253
+ }
254
+ const ageMs = nowMs - Date.parse(snapshot.savedAt);
255
+ const age =
256
+ ageMs >= DAY_MS
257
+ ? `${Math.floor(ageMs / DAY_MS)} days old`
258
+ : `${Math.max(0, Math.round(ageMs / 60_000))} min old`;
259
+ const saved = new Set(snapshot.sessions.map((session) => session.name));
260
+ const missing = (liveSessions ?? []).filter((name) => !saved.has(name));
261
+ if (missing.length)
262
+ return {
263
+ label,
264
+ pass: false,
265
+ detail: `${age}; misses ${missing.length} running session${missing.length === 1 ? "" : "s"} (${missing.slice(0, 5).join(", ")}${missing.length > 5 ? ", …" : ""}). ${hint}`,
266
+ optional: true,
267
+ };
268
+ return { label, pass: true, detail: `${age}, covers every running session`, optional: true };
269
+ }
270
+
271
+ function firstOnPath(name: string): string | null {
272
+ for (const directory of (process.env.PATH ?? "").split(delimiter)) {
273
+ if (!directory) continue;
274
+ const candidate = join(directory, name);
275
+ try {
276
+ accessSync(candidate, constants.X_OK);
277
+ return realpathSync(candidate);
278
+ } catch {
279
+ // Try the next PATH entry.
280
+ }
281
+ }
282
+ return null;
283
+ }
284
+
285
+ function safeBundledTmux(): string | null {
286
+ try {
287
+ const bundled = resolveBundledTmux();
288
+ return bundled ? realpathSync(bundled) : null;
289
+ } catch {
290
+ return null;
291
+ }
292
+ }
293
+
294
+ /** The sessions the snapshot should hold, on the server doctor reads; null when unreadable. */
295
+ function liveListableSessions(): string[] | null {
296
+ try {
297
+ const socketPath = process.env[TMUX_SOCKET_PATH_ENV];
298
+ const socketName = process.env.TMUX_IDE_TMUX_SOCKET_NAME;
299
+ const server = socketPath ? ["-S", socketPath] : socketName ? ["-L", socketName] : [];
300
+ return execFileSync(
301
+ resolveTmuxExecutable(),
302
+ [...server, "list-sessions", "-F", "#{session_name}"],
303
+ { encoding: "utf8", stdio: ["ignore", "pipe", "pipe"], timeout: 3000 },
304
+ )
305
+ .split("\n")
306
+ .filter((name) => name && isListableSession(name));
307
+ } catch (error) {
308
+ const text = String((error as { stderr?: unknown }).stderr ?? "");
309
+ return /no server running|error connecting/u.test(text) ? [] : null;
310
+ }
311
+ }
312
+
242
313
  function runTmuxFeatureProbes(executable: string): CheckResult {
243
314
  const run =
244
315
  (prefix: readonly string[]): TmuxProbe =>
@@ -335,6 +406,8 @@ export async function doctor({
335
406
  } catch {
336
407
  // The tmux version row above already reports a missing executable.
337
408
  }
409
+ checks.push(plainTmuxRow(firstOnPath("tmux"), safeBundledTmux()));
410
+ checks.push(snapshotRow(readSnapshot(), liveListableSessions(), Date.now()));
338
411
 
339
412
  checks.push(nodeVersionRow(process.versions.node));
340
413
 
@@ -0,0 +1,16 @@
1
+ import { basename, dirname, extname, join } from "node:path";
2
+ import { fileURLToPath } from "node:url";
3
+
4
+ /**
5
+ * The argv prefix that runs this tmux-ide's CLI: the bundled `bin/cli.js`,
6
+ * or `bin/cli.ts` under the runtime's loader flags when run from source.
7
+ * `here` must sit two directories below `packages/daemon/src`'s parent.
8
+ */
9
+ export function resolveCliCommand(
10
+ here: string = fileURLToPath(import.meta.url),
11
+ runtime: { execPath: string; execArgv: readonly string[] } = process,
12
+ ): string[] {
13
+ if (basename(here) === "cli.js") return [runtime.execPath, here];
14
+ const cli = join(dirname(here), "..", "..", "..", "..", "bin", `cli${extname(here)}`);
15
+ return [runtime.execPath, ...runtime.execArgv, cli];
16
+ }
@@ -1,3 +1,4 @@
1
+ import { createPaneReaderResolver } from "./tmux-pane-reader.ts";
1
2
  import { createNativeBrowserResolver } from "./tmux-native-browser.ts";
2
3
  import { createNativeSurfaceContextResolver } from "./native-surface-context.ts";
3
4
  import { NativeSurfaceProviderRegistry } from "../terminal/graphics/native-surface-provider.ts";
@@ -1996,6 +1997,22 @@ async function startEmbeddedDaemonGeneration(
1996
1997
  throw new Error("Default native browser owner is unavailable");
1997
1998
  },
1998
1999
  }),
2000
+ paneReader: createPaneReaderResolver({
2001
+ generation: instanceId,
2002
+ run: fleetFactsTmuxRunner,
2003
+ registry: workspaceRegistry,
2004
+ catalog: createNativeTmuxServerCatalog(workspaceRegistry, fleetFactsTmuxRunner),
2005
+ inventory: terminalInventoryRuntime,
2006
+ assertOpen: () => {
2007
+ if (
2008
+ defaultEditorContextRetired ||
2009
+ serverOwners?.defaultRetired ||
2010
+ !initialNativeServerIdentity ||
2011
+ terminalInventoryRuntime?.lifecycleState() !== "ready"
2012
+ )
2013
+ throw new Error("Default reader owner is unavailable");
2014
+ },
2015
+ }),
1999
2016
  catalog: createNativeTmuxServerCatalog(workspaceRegistry, fleetFactsTmuxRunner),
2000
2017
  readWindowSplitLayout: async (workspaceName, input) => {
2001
2018
  const target = WindowLinkTargetSchemaZ.parse(input);