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
@@ -43,13 +43,35 @@ export function createApplicationHomeAgentNavigator(options: {
43
43
  focusFirstPane: boolean,
44
44
  admission?: () => boolean,
45
45
  ) => Promise<ApplicationGenerationStartResult>;
46
- readonly selectPane: (paneId: string, source: HomeAgentNavigationSource) => void;
46
+ /**
47
+ * With `admission`, the selection is registered now and sent to the runtime
48
+ * only if `admission` resolves true. The controller drops input it holds for
49
+ * a refused pane, never delivering it to another pane; in the app the root
50
+ * routes no keys or paste while an agent is opening, so none is held.
51
+ */
52
+ readonly selectPane: (
53
+ paneId: string,
54
+ source: HomeAgentNavigationSource,
55
+ admission?: Promise<boolean>,
56
+ ) => void;
57
+ /**
58
+ * Home's roster can list an agent a moment before the attached session does.
59
+ * Resolves true once `listed()` holds, false on the bound, abort or a
60
+ * different generation (the navigator then refuses as before).
61
+ */
62
+ readonly waitForAgent?: (
63
+ generationKey: string,
64
+ listed: () => boolean,
65
+ signal: AbortSignal,
66
+ ) => Promise<boolean>;
47
67
  readonly showTerminals: (source: HomeAgentNavigationSource) => void;
48
68
  readonly setNote: (note: string | null) => void;
49
69
  }) {
50
70
  let navigationToken = 0;
51
71
  let disposed = false;
52
72
  let admissionController: AbortController | null = null;
73
+ /** The token whose wait note is on screen; cleared with the wait (#764). */
74
+ let waitingNote: number | null = null;
53
75
  const active = (token: number) => !disposed && token === navigationToken;
54
76
  const failure = (
55
77
  token: number,
@@ -60,12 +82,20 @@ export function createApplicationHomeAgentNavigator(options: {
60
82
  options.setNote(note);
61
83
  return { opened: false, failure: reason };
62
84
  };
63
- const admit = (
85
+ const listed = (
86
+ current: HomeAgentNavigationGeneration | null,
87
+ target: HomeAgentNavigationTarget,
88
+ ): boolean =>
89
+ !!target.paneId &&
90
+ !!current?.agents.some(
91
+ (agent) => agent.id === target.agentId && agent.paneId === target.paneId,
92
+ );
93
+ /** Every admission check; null admits. Notes are set only for a refusal. */
94
+ const refusal = (
64
95
  token: number,
65
96
  target: HomeAgentNavigationTarget,
66
- source: HomeAgentNavigationSource,
67
97
  expectedGeneration?: string,
68
- ): HomeAgentNavigationResult => {
98
+ ): HomeAgentNavigationResult | null => {
69
99
  if (!active(token)) return { opened: false, failure: "superseded" };
70
100
  if (!options.isCurrentTarget(target))
71
101
  return failure(
@@ -87,18 +117,63 @@ export function createApplicationHomeAgentNavigator(options: {
87
117
  "The session changed while opening that agent. Return Home and retry.",
88
118
  );
89
119
  }
90
- if (
91
- !target.paneId ||
92
- !current.agents.some((agent) => agent.id === target.agentId && agent.paneId === target.paneId)
93
- )
120
+ if (!listed(current, target))
94
121
  return failure(
95
122
  token,
96
123
  "pane-removed",
97
124
  "That exact agent terminal is no longer available. Return Home and select another agent.",
98
125
  );
126
+ return null;
127
+ };
128
+ const admit = (
129
+ token: number,
130
+ target: HomeAgentNavigationTarget,
131
+ source: HomeAgentNavigationSource,
132
+ expectedGeneration?: string,
133
+ ): HomeAgentNavigationResult => {
134
+ const refused = refusal(token, target, expectedGeneration);
135
+ if (refused) return refused;
99
136
  // Synchronous on the warm path: selection precedes surface visibility and
100
137
  // the next input event. The existing terminal owner remains the only input path.
101
- options.selectPane(target.paneId, source);
138
+ options.selectPane(target.paneId!, source);
139
+ options.showTerminals(source);
140
+ options.setNote(null);
141
+ return { opened: true };
142
+ };
143
+ /**
144
+ * The warm path when Home lists an agent the attached session doesn't yet
145
+ * (#764): register the selection now, wait (bounded) for the session to list
146
+ * exactly this agent on this pane, then run every admission check again.
147
+ * The selection reaches the runtime only if this admits. The root ignores
148
+ * keys and paste while an agent is opening, so input typed during the wait
149
+ * is dropped; the note says why nothing happens yet.
150
+ */
151
+ const admitWhenListed = async (
152
+ token: number,
153
+ target: HomeAgentNavigationTarget,
154
+ source: HomeAgentNavigationSource,
155
+ generationKey: string,
156
+ waitForAgent: NonNullable<typeof options.waitForAgent>,
157
+ signal: AbortSignal,
158
+ ): Promise<HomeAgentNavigationResult> => {
159
+ let settle!: (admitted: boolean) => void;
160
+ const admission = new Promise<boolean>((resolve) => {
161
+ settle = resolve;
162
+ });
163
+ options.selectPane(target.paneId!, source, admission);
164
+ // The cold path's "Opening agent in …" note, for the warm wait.
165
+ options.setNote(`Waiting for agent in ${target.sessionName}…`);
166
+ waitingNote = token;
167
+ try {
168
+ await waitForAgent(generationKey, () => listed(options.currentGeneration(), target), signal);
169
+ } catch {
170
+ // A failed wait is a refusal below, never an admission.
171
+ }
172
+ if (waitingNote === token) waitingNote = null;
173
+ // A refusal replaces the note; an admission clears it below.
174
+ const refused = refusal(token, target, generationKey);
175
+ settle(refused === null);
176
+ if (refused) return refused;
102
177
  options.showTerminals(source);
103
178
  options.setNote(null);
104
179
  return { opened: true };
@@ -112,6 +187,8 @@ export function createApplicationHomeAgentNavigator(options: {
112
187
  admissionController?.abort();
113
188
  const controller = new AbortController();
114
189
  admissionController = controller;
190
+ // This navigation sets its own note.
191
+ waitingNote = null;
115
192
  const token = ++navigationToken;
116
193
  try {
117
194
  if (!target.paneId)
@@ -122,8 +199,27 @@ export function createApplicationHomeAgentNavigator(options: {
122
199
  "stale-target",
123
200
  "That agent changed or disappeared. Select it again on Home.",
124
201
  );
125
- if (options.currentGeneration()?.sessionName === target.sessionName)
202
+ const attached = options.currentGeneration();
203
+ if (attached?.sessionName === target.sessionName) {
204
+ if (
205
+ options.waitForAgent &&
206
+ attached.daemonInstanceId === target.daemonInstanceId &&
207
+ attached.liveSessionId === target.liveSessionId &&
208
+ !listed(attached, target)
209
+ ) {
210
+ // The same session, just not listing this agent yet: possibly a
211
+ // moment behind Home. Refused as before if the wait ends without it.
212
+ return admitWhenListed(
213
+ token,
214
+ target,
215
+ source,
216
+ attached.generationKey,
217
+ options.waitForAgent,
218
+ controller.signal,
219
+ );
220
+ }
126
221
  return admit(token, target, source);
222
+ }
127
223
  options.setNote(`Opening agent in ${target.sessionName}…`);
128
224
  // Never briefly focus the first pane of the newly opened session.
129
225
  const opened = await options.startGeneration(target.sessionName, false, source, false, () =>
@@ -164,6 +260,10 @@ export function createApplicationHomeAgentNavigator(options: {
164
260
  cancel() {
165
261
  navigationToken += 1;
166
262
  admissionController?.abort();
263
+ if (waitingNote !== null) {
264
+ waitingNote = null;
265
+ options.setNote(null);
266
+ }
167
267
  },
168
268
  dispose() {
169
269
  disposed = true;
@@ -53,12 +53,43 @@ export function waitForHomeAgentSemantic(
53
53
  generation: () => OpenTuiGenerationHostSnapshot | null,
54
54
  expectedKey: string,
55
55
  signal: AbortSignal,
56
+ ): Promise<boolean> {
57
+ const client = generation()?.client;
58
+ return waitForHomeAgentGeneration(
59
+ generation,
60
+ expectedKey,
61
+ () => Boolean(client?.getSnapshot().semantic),
62
+ signal,
63
+ );
64
+ }
65
+
66
+ /**
67
+ * Waits, bounded, until the attached generation `expectedKey` lists an agent
68
+ * (`listed`), or until the generation changes, the bound passes or `signal`
69
+ * aborts (#764: Home can list an agent before the attached session does).
70
+ */
71
+ export function waitForHomeAgentListed(
72
+ generation: () => OpenTuiGenerationHostSnapshot | null,
73
+ expectedKey: string,
74
+ listed: () => boolean,
75
+ signal: AbortSignal,
76
+ ): Promise<boolean> {
77
+ return waitForHomeAgentGeneration(generation, expectedKey, listed, signal);
78
+ }
79
+
80
+ /** The bound both waits share: the cold path's own 5 s. */
81
+ export const HOME_AGENT_WAIT_MS = 5_000;
82
+
83
+ function waitForHomeAgentGeneration(
84
+ generation: () => OpenTuiGenerationHostSnapshot | null,
85
+ expectedKey: string,
86
+ satisfied: () => boolean,
87
+ signal: AbortSignal,
56
88
  ): Promise<boolean> {
57
89
  const client = generation()?.client;
58
90
  if (!client || signal.aborted) return Promise.resolve(false);
59
91
  const ready = () =>
60
- applicationGenerationNavigationKey(generation()) !== expectedKey ||
61
- Boolean(client.getSnapshot().semantic);
92
+ applicationGenerationNavigationKey(generation()) !== expectedKey || satisfied();
62
93
  // A changed generation is settled, not admitted: the navigator revalidates it.
63
94
  if (ready()) return Promise.resolve(true);
64
95
  return new Promise((resolve) => {
@@ -76,7 +107,7 @@ export function waitForHomeAgentSemantic(
76
107
  const check = () => {
77
108
  if (ready()) finish(true);
78
109
  };
79
- const timeout = setTimeout(() => finish(false), 5_000);
110
+ const timeout = setTimeout(() => finish(false), HOME_AGENT_WAIT_MS);
80
111
  signal.addEventListener("abort", abort, { once: true });
81
112
  // subscribe may synchronously deliver its current projection.
82
113
  for (const scope of ["semantic", "lifecycle"] as const) {
@@ -90,6 +121,19 @@ export function waitForHomeAgentSemantic(
90
121
  });
91
122
  }
92
123
 
124
+ /**
125
+ * While an agent opens, it owns the keyboard: other keys are ignored and Esc
126
+ * cancels the open (#764: the warm wait can last 5 s). True when it owns `name`.
127
+ */
128
+ export function agentOpeningOwnsKey(
129
+ name: string,
130
+ opener: { opening(): boolean; cancel(): void },
131
+ ): boolean {
132
+ if (!opener.opening()) return false;
133
+ if (name === "escape") opener.cancel();
134
+ return true;
135
+ }
136
+
93
137
  /** Resident feature composition: observation, selection, and navigation have separate owners. */
94
138
  export function createApplicationHomeAgentsOwner(options: {
95
139
  readonly catalog: Accessor<ApplicationHomeCatalogSnapshot>;
@@ -98,7 +142,7 @@ export function createApplicationHomeAgentsOwner(options: {
98
142
  readonly generation: () => OpenTuiGenerationHostSnapshot | null;
99
143
  readonly sessionName: () => string | null;
100
144
  readonly startGeneration: ReturnType<typeof createApplicationGenerationStarter>;
101
- readonly selectPane: (paneId: string) => void;
145
+ readonly selectPane: (paneId: string, admission?: Promise<boolean>) => void;
102
146
  readonly showTerminals: (source: "keyboard" | "mouse") => void;
103
147
  readonly restoreHome?: (source: "keyboard" | "mouse") => Promise<void> | void;
104
148
  readonly setNote: (note: string | null) => void;
@@ -138,10 +182,13 @@ export function createApplicationHomeAgentsOwner(options: {
138
182
  };
139
183
  },
140
184
  waitForGeneration: (key, signal) => waitForHomeAgentSemantic(options.generation, key, signal),
185
+ waitForAgent: (key, listed, signal) =>
186
+ waitForHomeAgentListed(options.generation, key, listed, signal),
141
187
  startGeneration: options.startGeneration,
142
188
  // The existing pane input router is source-neutral. Session/surface intents
143
189
  // above retain keyboard vs pointer provenance without inventing a second router.
144
- selectPane: (paneId) => options.selectPane(paneId),
190
+ selectPane: (paneId, _source, admission) =>
191
+ admission ? options.selectPane(paneId, admission) : options.selectPane(paneId),
145
192
  showTerminals: options.showTerminals,
146
193
  setNote: options.setNote,
147
194
  });
@@ -202,7 +249,12 @@ export function createApplicationHomeAgentsOwner(options: {
202
249
  observer.dispose();
203
250
  selection.dispose();
204
251
  });
205
- return { presentation, opening, cancel };
252
+ return {
253
+ presentation,
254
+ opening,
255
+ cancel,
256
+ ownsKey: (name: string) => agentOpeningOwnsKey(name, { opening, cancel }),
257
+ };
206
258
  }
207
259
 
208
260
  /** Compose Home navigation with competing chrome intents; physical input stays in the root. */
@@ -5,7 +5,11 @@ import {
5
5
  type HomeAgentNavigationTarget,
6
6
  } from "./application-home-agent-navigation.ts";
7
7
  import { applicationGenerationNavigationKey } from "./application-generation-starter.ts";
8
- import { waitForHomeAgentSemantic } from "./application-home-agents-owner.ts";
8
+ import {
9
+ agentOpeningOwnsKey,
10
+ waitForHomeAgentListed,
11
+ waitForHomeAgentSemantic,
12
+ } from "./application-home-agents-owner.ts";
9
13
  import type { OpenTuiGenerationHostSnapshot } from "./open-tui-generation-host.ts";
10
14
 
11
15
  type HomeNavigatorOptions = Parameters<typeof createApplicationHomeAgentNavigator>[0];
@@ -19,7 +23,8 @@ export function createApplicationMachineAgentNavigator(options: {
19
23
  readonly generation: () => OpenTuiGenerationHostSnapshot | null;
20
24
  readonly sessionName: () => string | null;
21
25
  readonly startGeneration: HomeNavigatorOptions["startGeneration"];
22
- readonly selectPane: HomeNavigatorOptions["selectPane"];
26
+ /** The interaction controller's selectPane: `admission` must reach it (#764). */
27
+ readonly selectPane: (paneId: string, admission?: Promise<boolean>) => void;
23
28
  readonly showTerminals: HomeNavigatorOptions["showTerminals"];
24
29
  readonly setNote: HomeNavigatorOptions["setNote"];
25
30
  }) {
@@ -27,6 +32,11 @@ export function createApplicationMachineAgentNavigator(options: {
27
32
  let disposed = false;
28
33
  let opening = false;
29
34
  let request = 0;
35
+ const cancel = () => {
36
+ request++;
37
+ opening = false;
38
+ current?.cancel();
39
+ };
30
40
  return {
31
41
  open(
32
42
  machineId: string,
@@ -48,7 +58,7 @@ export function createApplicationMachineAgentNavigator(options: {
48
58
  ) {
49
59
  // Reserve before the next key; the terminal controller waits for a fresh
50
60
  // coherent runtime and remains the only owner of physical input.
51
- options.selectPane(target.paneId!, source);
61
+ options.selectPane(target.paneId!);
52
62
  options.showTerminals(source);
53
63
  options.setNote(null);
54
64
  opening = false;
@@ -72,6 +82,8 @@ export function createApplicationMachineAgentNavigator(options: {
72
82
  };
73
83
  },
74
84
  waitForGeneration: (key, signal) => waitForHomeAgentSemantic(generation, key, signal),
85
+ waitForAgent: (key, listed, signal) =>
86
+ waitForHomeAgentListed(generation, key, listed, signal),
75
87
  startGeneration: (session, prepared, origin, focus, admission) =>
76
88
  options.startGeneration(
77
89
  session,
@@ -81,7 +93,8 @@ export function createApplicationMachineAgentNavigator(options: {
81
93
  () =>
82
94
  selected() && options.isCurrentTarget(machineId, target) && (admission?.() ?? true),
83
95
  ),
84
- selectPane: options.selectPane,
96
+ selectPane: (paneId, _source, admission) =>
97
+ admission ? options.selectPane(paneId, admission) : options.selectPane(paneId),
85
98
  showTerminals: options.showTerminals,
86
99
  setNote: options.setNote,
87
100
  });
@@ -90,11 +103,9 @@ export function createApplicationMachineAgentNavigator(options: {
90
103
  });
91
104
  },
92
105
  opening: () => opening,
93
- cancel() {
94
- request++;
95
- opening = false;
96
- current?.cancel();
97
- },
106
+ cancel,
107
+ /** Esc cancels an open in progress; other keys are ignored meanwhile. */
108
+ ownsKey: (name: string) => agentOpeningOwnsKey(name, { opening: () => opening, cancel }),
98
109
  dispose() {
99
110
  disposed = true;
100
111
  request++;
@@ -367,7 +367,7 @@ export async function startApplicationRoot(options: StartApplicationRootOptions
367
367
  generation,
368
368
  sessionName: () => sessionOwner?.sessionName() ?? null,
369
369
  startGeneration,
370
- selectPane: (paneId, source) => interaction.selectPane(paneId, source),
370
+ selectPane: interaction.selectPane,
371
371
  showTerminals: () => setSurface("terminals"),
372
372
  setNote: setTransientNote,
373
373
  });
@@ -484,7 +484,7 @@ export async function startApplicationRoot(options: StartApplicationRootOptions
484
484
  else paletteCommands.setOpen(chromeAction === "palette-open", "keyboard");
485
485
  return;
486
486
  }
487
- if (homeAgents?.opening() || machineAgentNavigator?.opening()) return;
487
+ if (homeAgents?.ownsKey(name) || machineAgentNavigator?.ownsKey(name)) return;
488
488
  if (
489
489
  activeSurface() === "terminals" &&
490
490
  shell().semantic === null &&