tmux-ide 2.9.21 → 2.9.23
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.
- package/bin/cli.js +6235 -8473
- package/package.json +3 -3
- package/packages/contracts/src/index.ts +2 -0
- package/packages/contracts/src/pane-reader.ts +121 -0
- package/packages/contracts/src/pane-stream.ts +18 -0
- package/packages/contracts/src/visual-theme-presets.ts +58 -2
- package/packages/contracts/src/websocket-heartbeat.ts +41 -0
- package/packages/daemon/dist/command-center/automation.js +1 -1
- package/packages/daemon/dist/command-center/daemon-fleet-facts-observer.js +37 -5
- package/packages/daemon/dist/command-center/discovery.js +28 -2
- package/packages/daemon/dist/command-center/server.js +8 -2
- package/packages/daemon/dist/command-center/tmux-server-reader.js +41 -0
- package/packages/daemon/dist/command-center/tmux-servers.js +7 -1
- package/packages/daemon/dist/doctor.js +147 -43
- package/packages/daemon/dist/lib/bounded-tmux-read.js +34 -12
- package/packages/daemon/dist/lib/cli-command.js +13 -0
- package/packages/daemon/dist/lib/daemon-embed.js +126 -55
- package/packages/daemon/dist/lib/daemon-stop-progress.js +58 -0
- package/packages/daemon/dist/lib/embedded-daemon-lifecycle.js +11 -0
- package/packages/daemon/dist/lib/embedded-tmux-server-owners.js +88 -12
- package/packages/daemon/dist/lib/headless-daemon.js +177 -10
- package/packages/daemon/dist/lib/log.js +18 -1
- package/packages/daemon/dist/lib/pane-reader-files.js +226 -0
- package/packages/daemon/dist/lib/remote-tmux-command.js +8 -5
- package/packages/daemon/dist/lib/tmux-client-execution.js +73 -7
- package/packages/daemon/dist/lib/tmux-external-interaction-observer.js +140 -19
- package/packages/daemon/dist/lib/tmux-native-browser.js +4 -2
- package/packages/daemon/dist/lib/tmux-pane-reader.js +107 -0
- package/packages/daemon/dist/lib/tmux-server-agent-admission.js +6 -1
- package/packages/daemon/dist/lib/tmux-server-features.js +38 -0
- package/packages/daemon/dist/lib/tmux-server-owner-teardown.js +33 -0
- package/packages/daemon/dist/lib/tmux-server-owner.js +38 -37
- package/packages/daemon/dist/lib/tmux-server-owners.js +310 -20
- package/packages/daemon/dist/lib/tmux-server-registration.js +128 -9
- package/packages/daemon/dist/lib/unix-socket-authority.js +58 -3
- package/packages/daemon/dist/lib/workspace-pane-creation.js +10 -1
- package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/Info.plist +2 -2
- package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/MacOS/tmux-ide-notifier +0 -0
- package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/Resources/Assets.car +0 -0
- package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/_CodeSignature/CodeResources +2 -2
- package/packages/daemon/dist/open-browser.js +26 -12
- package/packages/daemon/dist/open-reader.js +84 -0
- package/packages/daemon/dist/plugins/cli.js +1 -2
- package/packages/daemon/dist/plugins/daemon-plugins.js +2 -10
- package/packages/daemon/dist/restore.js +57 -40
- package/packages/daemon/dist/server/pane-stream-upgrade.js +5 -1
- package/packages/daemon/dist/server/websocket-heartbeat.js +103 -0
- package/packages/daemon/dist/terminal/attachments/native-runtime.js +32 -14
- package/packages/daemon/dist/terminal/mirror/layout-content-rows.js +11 -0
- package/packages/daemon/dist/terminal/mirror/mirror-service.js +61 -3
- package/packages/daemon/dist/terminal/mirror/session-channel.js +13 -12
- package/packages/daemon/dist/terminal/pane-stream/pane-stream-websocket.js +123 -25
- package/packages/daemon/dist/terminal/pane-stream/runtime.js +3 -2
- package/packages/daemon/dist/terminal/protocol/reader-option.js +66 -0
- package/packages/daemon/dist/terminal/protocol/session-descriptor-discovery.js +30 -2
- package/packages/daemon/dist/terminal/protocol/stock-split-resize.js +4 -1
- package/packages/daemon/dist/terminal/session-runtime/registry.js +17 -0
- package/packages/daemon/dist/terminal/session-runtime/terminal-replica-interpreter.js +81 -3
- package/packages/daemon/dist/terminal/session-runtime/terminal-replica-owner.js +60 -3
- package/packages/daemon/dist/tmux-upgrade/cli.js +106 -0
- package/packages/daemon/dist/tmux-upgrade/io.js +540 -0
- package/packages/daemon/dist/tmux-upgrade/plan.js +238 -0
- package/packages/daemon/dist/tmux-upgrade/run.js +199 -0
- package/packages/daemon/dist/tui/chrome/snapshot.js +3 -4
- package/packages/daemon/dist/tui/mirror/runtime/application-home-agent-navigation.js +64 -4
- package/packages/daemon/dist/tui/mirror/runtime/application-home-agents-owner.js +35 -5
- package/packages/daemon/dist/tui/mirror/runtime/application-machine-agent-navigation.js +12 -8
- package/packages/daemon/dist/tui/mirror/runtime/application-terminal-interaction-controller.js +125 -111
- package/packages/daemon/src/command-center/automation.ts +1 -1
- package/packages/daemon/src/command-center/daemon-fleet-facts-observer.ts +49 -8
- package/packages/daemon/src/command-center/discovery.ts +35 -2
- package/packages/daemon/src/command-center/server.ts +22 -8
- package/packages/daemon/src/command-center/tmux-server-reader.ts +62 -0
- package/packages/daemon/src/command-center/tmux-servers.ts +7 -1
- package/packages/daemon/src/doctor.ts +164 -45
- package/packages/daemon/src/lib/bounded-tmux-read.ts +29 -9
- package/packages/daemon/src/lib/cli-command.ts +16 -0
- package/packages/daemon/src/lib/daemon-embed.ts +176 -64
- package/packages/daemon/src/lib/daemon-stop-progress.ts +78 -0
- package/packages/daemon/src/lib/embedded-daemon-lifecycle.ts +12 -0
- package/packages/daemon/src/lib/embedded-tmux-server-owners.ts +115 -11
- package/packages/daemon/src/lib/headless-daemon.ts +205 -12
- package/packages/daemon/src/lib/log.ts +18 -1
- package/packages/daemon/src/lib/pane-reader-files.ts +294 -0
- package/packages/daemon/src/lib/remote-tmux-command.ts +13 -6
- package/packages/daemon/src/lib/tmux-client-execution.ts +79 -7
- package/packages/daemon/src/lib/tmux-external-interaction-observer.ts +163 -25
- package/packages/daemon/src/lib/tmux-native-browser.ts +4 -3
- package/packages/daemon/src/lib/tmux-pane-reader.ts +145 -0
- package/packages/daemon/src/lib/tmux-server-agent-admission.ts +6 -1
- package/packages/daemon/src/lib/tmux-server-features.ts +43 -0
- package/packages/daemon/src/lib/tmux-server-owner-teardown.ts +54 -0
- package/packages/daemon/src/lib/tmux-server-owner.ts +41 -35
- package/packages/daemon/src/lib/tmux-server-owners.ts +427 -22
- package/packages/daemon/src/lib/tmux-server-registration.ts +155 -7
- package/packages/daemon/src/lib/unix-socket-authority.ts +72 -3
- package/packages/daemon/src/lib/workspace-pane-creation.ts +11 -1
- package/packages/daemon/src/open-browser.ts +59 -18
- package/packages/daemon/src/open-reader.ts +148 -0
- package/packages/daemon/src/plugins/cli.ts +1 -2
- package/packages/daemon/src/plugins/daemon-plugins.ts +2 -12
- package/packages/daemon/src/restore.ts +80 -44
- package/packages/daemon/src/server/pane-stream-upgrade.ts +6 -0
- package/packages/daemon/src/server/websocket-heartbeat.ts +135 -0
- package/packages/daemon/src/terminal/attachments/native-runtime.ts +58 -14
- package/packages/daemon/src/terminal/mirror/events.ts +2 -0
- package/packages/daemon/src/terminal/mirror/layout-content-rows.ts +11 -0
- package/packages/daemon/src/terminal/mirror/mirror-service.ts +61 -2
- package/packages/daemon/src/terminal/mirror/session-channel.ts +15 -14
- package/packages/daemon/src/terminal/pane-stream/pane-stream-websocket.ts +140 -23
- package/packages/daemon/src/terminal/pane-stream/runtime.ts +4 -2
- package/packages/daemon/src/terminal/protocol/reader-option.ts +77 -0
- package/packages/daemon/src/terminal/protocol/session-descriptor-discovery.ts +41 -1
- package/packages/daemon/src/terminal/protocol/stock-split-resize.ts +6 -1
- package/packages/daemon/src/terminal/session-runtime/registry.ts +23 -0
- package/packages/daemon/src/terminal/session-runtime/runtime-observability.ts +2 -0
- package/packages/daemon/src/terminal/session-runtime/terminal-replica-interpreter.ts +100 -3
- package/packages/daemon/src/terminal/session-runtime/terminal-replica-owner.ts +60 -3
- package/packages/daemon/src/tmux-upgrade/cli.ts +118 -0
- package/packages/daemon/src/tmux-upgrade/io.ts +596 -0
- package/packages/daemon/src/tmux-upgrade/plan.ts +353 -0
- package/packages/daemon/src/tmux-upgrade/run.ts +325 -0
- package/packages/daemon/src/tui/chrome/snapshot.ts +3 -4
- package/packages/daemon/src/tui/mirror/runtime/application-home-agent-navigation.ts +110 -10
- package/packages/daemon/src/tui/mirror/runtime/application-home-agents-owner.ts +58 -6
- package/packages/daemon/src/tui/mirror/runtime/application-machine-agent-navigation.ts +20 -9
- package/packages/daemon/src/tui/mirror/runtime/application-root-v2.tsx +2 -2
- package/packages/daemon/src/tui/mirror/runtime/application-terminal-interaction-controller.ts +149 -128
- package/packages/daemon-client/src/direct-application-shell-transport.ts +21 -3
- package/packages/daemon-client/src/workspace-event-supervisor.ts +63 -2
- package/packages/tmux-bridge/src/runner.ts +3 -1
|
@@ -23,6 +23,20 @@ import {
|
|
|
23
23
|
|
|
24
24
|
const HOOK_MARKER = "tmux-ide-interaction-v3";
|
|
25
25
|
const OWNED_HOOK_MARKER = "tmux-ide-interaction-v";
|
|
26
|
+
/** The retention name of one observer: the marker plus its daemon id. */
|
|
27
|
+
const OWNER_NAME =
|
|
28
|
+
/tmux-ide-interaction-v3-[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/u;
|
|
29
|
+
const OWNER_RECORD = /^retention-owner pid=([1-9][0-9]{0,9})$/u;
|
|
30
|
+
/** Observers of THIS process that are installed and not yet disposed. */
|
|
31
|
+
const liveLocalObservers = new Set<string>();
|
|
32
|
+
function processIsAlive(pid: number): boolean {
|
|
33
|
+
try {
|
|
34
|
+
process.kill(pid, 0);
|
|
35
|
+
return true;
|
|
36
|
+
} catch (error) {
|
|
37
|
+
return (error as NodeJS.ErrnoException).code !== "ESRCH";
|
|
38
|
+
}
|
|
39
|
+
}
|
|
26
40
|
const FIELD_SEPARATOR = "|tmux-ide-input-field-v1|";
|
|
27
41
|
const EVENT_SEPARATOR = "|tmux-ide-input-event-v1|";
|
|
28
42
|
export interface ExternalTmuxInteractionGap {
|
|
@@ -55,7 +69,10 @@ export interface HookHealthcheckSchedule {
|
|
|
55
69
|
|
|
56
70
|
export const DEFAULT_HOOK_HEALTHCHECK_SCHEDULE: HookHealthcheckSchedule = Object.freeze({
|
|
57
71
|
baseMs: 1_000,
|
|
58
|
-
|
|
72
|
+
// A healthy idle server is checked 12 times an hour, not 120. Since daemons
|
|
73
|
+
// no longer remove each other's hooks, only a user action (a config reload,
|
|
74
|
+
// `set-hook -gu`) can take them away; that is then noticed within 5 minutes.
|
|
75
|
+
maxMs: 300_000,
|
|
59
76
|
});
|
|
60
77
|
|
|
61
78
|
export type HookHealthcheckOutcome = "healthy" | "repaired" | "failed";
|
|
@@ -162,18 +179,66 @@ function defaultWaiter(
|
|
|
162
179
|
): ExternalTmuxInteractionObserverIo["waitForSignal"] {
|
|
163
180
|
const prefix = socketArguments(authority);
|
|
164
181
|
return (channel, signal) =>
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
182
|
+
waitForBlockingTmuxClient(
|
|
183
|
+
authority.executablePath,
|
|
184
|
+
[...prefix, ...tmuxInteractionWaitCommand(bufferName, channel)],
|
|
185
|
+
signal,
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
export const BLOCKING_CLIENT_KILL_GRACE_MS = 250;
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Run a tmux client that blocks until signalled (`wait-for`). It has no
|
|
193
|
+
* deadline by design, so cancellation must not depend on the client's
|
|
194
|
+
* cooperation: TERM on abort, KILL after a grace, and settle when the process
|
|
195
|
+
* exits. Observer disposal awaits this, and with it every daemon stop (#839).
|
|
196
|
+
*/
|
|
197
|
+
export function waitForBlockingTmuxClient(
|
|
198
|
+
executable: string,
|
|
199
|
+
args: readonly string[],
|
|
200
|
+
signal: AbortSignal,
|
|
201
|
+
killGraceMs: number = BLOCKING_CLIENT_KILL_GRACE_MS,
|
|
202
|
+
): Promise<void> {
|
|
203
|
+
if (signal.aborted) return Promise.resolve();
|
|
204
|
+
return new Promise<void>((resolve, reject) => {
|
|
205
|
+
let settled = false;
|
|
206
|
+
let failure: Error | null = null;
|
|
207
|
+
let escalation: ReturnType<typeof setTimeout> | null = null;
|
|
208
|
+
const child = execFile(
|
|
209
|
+
executable,
|
|
210
|
+
[...args],
|
|
211
|
+
{ encoding: "utf8", windowsHide: true },
|
|
212
|
+
(error) => {
|
|
213
|
+
failure ??= error;
|
|
214
|
+
},
|
|
215
|
+
);
|
|
216
|
+
const settle = (): void => {
|
|
217
|
+
if (settled) return;
|
|
218
|
+
settled = true;
|
|
219
|
+
if (escalation) clearTimeout(escalation);
|
|
220
|
+
signal.removeEventListener("abort", cancel);
|
|
221
|
+
if (!failure || signal.aborted) resolve();
|
|
222
|
+
else reject(failure);
|
|
223
|
+
};
|
|
224
|
+
const cancel = (): void => {
|
|
225
|
+
if (escalation) return;
|
|
226
|
+
child.kill("SIGTERM");
|
|
227
|
+
escalation = setTimeout(() => child.kill("SIGKILL"), killGraceMs);
|
|
228
|
+
};
|
|
229
|
+
signal.addEventListener("abort", cancel, { once: true });
|
|
230
|
+
child.once("error", (error) => {
|
|
231
|
+
failure ??= error;
|
|
232
|
+
settle();
|
|
176
233
|
});
|
|
234
|
+
// "exit", not "close": a lingering holder of the pipes must not keep the
|
|
235
|
+
// waiter, and so the stop, pending after the client itself is gone.
|
|
236
|
+
child.once("exit", (code, exitSignal) => {
|
|
237
|
+
if (code !== 0 && !failure)
|
|
238
|
+
failure = new Error(`tmux wait client ended with ${exitSignal ?? `code ${String(code)}`}`);
|
|
239
|
+
settle();
|
|
240
|
+
});
|
|
241
|
+
});
|
|
177
242
|
}
|
|
178
243
|
|
|
179
244
|
function abortableDelay(milliseconds: number, signal: AbortSignal): Promise<void> {
|
|
@@ -265,17 +330,19 @@ export function parseTmuxInputHookRecords(raw: string): readonly TmuxInputHookRe
|
|
|
265
330
|
return records;
|
|
266
331
|
}
|
|
267
332
|
|
|
268
|
-
|
|
333
|
+
/** Every tmux-ide hook of this array, with the observer it belongs to (null: a legacy hook). */
|
|
334
|
+
function ownedHooks(
|
|
269
335
|
output: string,
|
|
270
336
|
hookName: "after-send-keys" | "after-capture-pane",
|
|
271
|
-
): readonly number[] {
|
|
337
|
+
): readonly { readonly index: number; readonly owner: string | null }[] {
|
|
272
338
|
const row = new RegExp(`^${hookName}\\[([0-9]+)\\]\\s+(.+)$`, "u");
|
|
273
|
-
const
|
|
339
|
+
const hooks: { index: number; owner: string | null }[] = [];
|
|
274
340
|
for (const line of output.split("\n")) {
|
|
275
341
|
const match = row.exec(line);
|
|
276
|
-
if (match && match[2]!.includes(OWNED_HOOK_MARKER))
|
|
342
|
+
if (match && match[2]!.includes(OWNED_HOOK_MARKER))
|
|
343
|
+
hooks.push({ index: Number(match[1]!), owner: OWNER_NAME.exec(match[2]!)?.[0] ?? null });
|
|
277
344
|
}
|
|
278
|
-
return
|
|
345
|
+
return hooks;
|
|
279
346
|
}
|
|
280
347
|
|
|
281
348
|
/**
|
|
@@ -311,6 +378,7 @@ export class TmuxExternalInteractionObserver {
|
|
|
311
378
|
#diagnostics: ExternalTmuxObserverDiagnostics | null;
|
|
312
379
|
#diagnosticActiveOperations = 0;
|
|
313
380
|
readonly #authenticatedInternalReads: AuthenticatedInternalReadVerifier;
|
|
381
|
+
readonly #ownerProcess: { readonly pid: number; readonly isAlive: (pid: number) => boolean };
|
|
314
382
|
|
|
315
383
|
constructor(options: {
|
|
316
384
|
daemonInstanceId: string;
|
|
@@ -334,7 +402,10 @@ export class TmuxExternalInteractionObserver {
|
|
|
334
402
|
onGap?: (gap: ExternalTmuxInteractionGap) => void;
|
|
335
403
|
/** Health-check cadence bounds. Tests inject small values; production uses the default. */
|
|
336
404
|
healthcheck?: Partial<HookHealthcheckSchedule>;
|
|
405
|
+
/** This daemon's process and the liveness test for another's. Tests inject both. */
|
|
406
|
+
ownerProcess?: { readonly pid: number; readonly isAlive: (pid: number) => boolean };
|
|
337
407
|
}) {
|
|
408
|
+
this.#ownerProcess = options.ownerProcess ?? { pid: process.pid, isAlive: processIsAlive };
|
|
338
409
|
this.#daemonInstanceId = options.daemonInstanceId;
|
|
339
410
|
this.#healthcheckSchedule = Object.freeze({
|
|
340
411
|
baseMs: options.healthcheck?.baseMs ?? DEFAULT_HOOK_HEALTHCHECK_SCHEDULE.baseMs,
|
|
@@ -401,6 +472,7 @@ export class TmuxExternalInteractionObserver {
|
|
|
401
472
|
});
|
|
402
473
|
if (!isTmuxServerUnavailable(error)) {
|
|
403
474
|
this.#active = false;
|
|
475
|
+
liveLocalObservers.delete(this.#bufferName);
|
|
404
476
|
throw error;
|
|
405
477
|
}
|
|
406
478
|
// A configless first run legitimately has no tmux server yet. Keep the
|
|
@@ -414,6 +486,7 @@ export class TmuxExternalInteractionObserver {
|
|
|
414
486
|
await this.#removeOwnedHooks();
|
|
415
487
|
await this.#deleteRetention();
|
|
416
488
|
});
|
|
489
|
+
liveLocalObservers.delete(this.#bufferName);
|
|
417
490
|
throw new Error("tmux external interaction observer was disposed during startup");
|
|
418
491
|
}
|
|
419
492
|
this.#loop = this.#run();
|
|
@@ -471,6 +544,8 @@ export class TmuxExternalInteractionObserver {
|
|
|
471
544
|
}
|
|
472
545
|
|
|
473
546
|
async dispose(): Promise<void> {
|
|
547
|
+
// From here on another observer of this process may clear what this one leaves.
|
|
548
|
+
liveLocalObservers.delete(this.#bufferName);
|
|
474
549
|
if (!this.#active && !this.#loop && !this.#starting && !this.#installed) return;
|
|
475
550
|
const starting = this.#starting;
|
|
476
551
|
this.#active = false;
|
|
@@ -491,12 +566,24 @@ export class TmuxExternalInteractionObserver {
|
|
|
491
566
|
}
|
|
492
567
|
|
|
493
568
|
async #install(signal?: AbortSignal): Promise<void> {
|
|
494
|
-
await this.#
|
|
495
|
-
await this.#
|
|
569
|
+
const others = await this.#liveOtherObservers(signal);
|
|
570
|
+
await this.#removeOwnedHooks(signal, others);
|
|
571
|
+
await this.#deleteOwnedBuffers(signal, others);
|
|
496
572
|
signal?.throwIfAborted();
|
|
497
|
-
|
|
498
|
-
//
|
|
499
|
-
|
|
573
|
+
liveLocalObservers.add(this.#bufferName);
|
|
574
|
+
// The small named buffer indexes retention options for crash cleanup and
|
|
575
|
+
// names the owning process: another daemon on this server leaves these
|
|
576
|
+
// hooks alone while that process lives, and clears them once it is gone.
|
|
577
|
+
// Event data lives only in bounded options, never in this buffer.
|
|
578
|
+
await this.#io.runTmux(
|
|
579
|
+
[
|
|
580
|
+
"set-buffer",
|
|
581
|
+
"-b",
|
|
582
|
+
this.#bufferName,
|
|
583
|
+
`retention-owner pid=${String(this.#ownerProcess.pid)}`,
|
|
584
|
+
],
|
|
585
|
+
signal,
|
|
586
|
+
);
|
|
500
587
|
const hook = (
|
|
501
588
|
operationKind: ExternalTmuxInteraction["operationKind"],
|
|
502
589
|
markerOption: string,
|
|
@@ -765,7 +852,51 @@ export class TmuxExternalInteractionObserver {
|
|
|
765
852
|
});
|
|
766
853
|
}
|
|
767
854
|
|
|
768
|
-
|
|
855
|
+
/**
|
|
856
|
+
* The other observers on this tmux server whose owner is alive: another
|
|
857
|
+
* daemon process, or another owner generation of this one. Their hooks,
|
|
858
|
+
* buffers and options are not ours to remove. Null when the server would
|
|
859
|
+
* not say; then nothing foreign is touched at all.
|
|
860
|
+
*/
|
|
861
|
+
async #liveOtherObservers(signal?: AbortSignal): Promise<ReadonlySet<string> | null> {
|
|
862
|
+
let output: string;
|
|
863
|
+
try {
|
|
864
|
+
output = await this.#io.runTmux(["list-buffers", "-F", "#{buffer_name}"], signal);
|
|
865
|
+
} catch {
|
|
866
|
+
return null;
|
|
867
|
+
}
|
|
868
|
+
const live = new Set<string>();
|
|
869
|
+
for (const name of output.split("\n")) {
|
|
870
|
+
if (name === this.#bufferName || OWNER_NAME.exec(name)?.[0] !== name) continue;
|
|
871
|
+
let record: string;
|
|
872
|
+
try {
|
|
873
|
+
record = (await this.#io.runTmux(["show-buffer", "-b", name], signal)).trim();
|
|
874
|
+
} catch {
|
|
875
|
+
continue;
|
|
876
|
+
}
|
|
877
|
+
const pid = Number(OWNER_RECORD.exec(record)?.[1]);
|
|
878
|
+
// A marker without a pid was written by an older daemon; as before, it is cleared.
|
|
879
|
+
if (!Number.isSafeInteger(pid)) continue;
|
|
880
|
+
if (
|
|
881
|
+
pid === this.#ownerProcess.pid
|
|
882
|
+
? liveLocalObservers.has(name)
|
|
883
|
+
: this.#ownerProcess.isAlive(pid)
|
|
884
|
+
)
|
|
885
|
+
live.add(name);
|
|
886
|
+
}
|
|
887
|
+
return live;
|
|
888
|
+
}
|
|
889
|
+
|
|
890
|
+
/**
|
|
891
|
+
* Remove this observer's hooks, and those nobody alive owns (a crashed
|
|
892
|
+
* daemon's, legacy ones). Never another live observer's: two daemons on one
|
|
893
|
+
* tmux server would otherwise keep taking each other's hooks away.
|
|
894
|
+
*/
|
|
895
|
+
async #removeOwnedHooks(
|
|
896
|
+
signal?: AbortSignal,
|
|
897
|
+
others?: ReadonlySet<string> | null,
|
|
898
|
+
): Promise<void> {
|
|
899
|
+
const live = others === undefined ? await this.#liveOtherObservers(signal) : others;
|
|
769
900
|
for (const hookName of ["after-send-keys", "after-capture-pane"] as const) {
|
|
770
901
|
let output: string;
|
|
771
902
|
try {
|
|
@@ -773,7 +904,9 @@ export class TmuxExternalInteractionObserver {
|
|
|
773
904
|
} catch {
|
|
774
905
|
continue;
|
|
775
906
|
}
|
|
776
|
-
for (const index of
|
|
907
|
+
for (const { index, owner } of ownedHooks(output, hookName)) {
|
|
908
|
+
if (owner !== this.#bufferName && (live === null || (owner !== null && live.has(owner))))
|
|
909
|
+
continue;
|
|
777
910
|
try {
|
|
778
911
|
await this.#io.runTmux(["set-hook", "-gu", `${hookName}[${index}]`], signal);
|
|
779
912
|
} catch {
|
|
@@ -848,7 +981,11 @@ export class TmuxExternalInteractionObserver {
|
|
|
848
981
|
await this.#deleteBuffer(this.#bufferName);
|
|
849
982
|
}
|
|
850
983
|
|
|
851
|
-
async #deleteOwnedBuffers(
|
|
984
|
+
async #deleteOwnedBuffers(
|
|
985
|
+
signal: AbortSignal | undefined,
|
|
986
|
+
live: ReadonlySet<string> | null,
|
|
987
|
+
): Promise<void> {
|
|
988
|
+
if (live === null) return;
|
|
852
989
|
let output: string;
|
|
853
990
|
try {
|
|
854
991
|
output = await this.#io.runTmux(["list-buffers", "-F", "#{buffer_name}"], signal);
|
|
@@ -857,6 +994,7 @@ export class TmuxExternalInteractionObserver {
|
|
|
857
994
|
}
|
|
858
995
|
for (const name of output.split("\n")) {
|
|
859
996
|
if (!name.startsWith(OWNED_HOOK_MARKER) || name === this.#bufferName) continue;
|
|
997
|
+
if (live.has(name)) continue;
|
|
860
998
|
if (/^[A-Za-z0-9._-]{1,256}$/u.test(name)) {
|
|
861
999
|
await this.#deleteOption(tmuxInteractionOption(name), signal);
|
|
862
1000
|
await this.#deleteOption(`${tmuxInteractionOption(name)}-drain`, signal);
|
|
@@ -64,8 +64,9 @@ export function createNativeBrowserResolver(options: {
|
|
|
64
64
|
);
|
|
65
65
|
if (matches.length !== 1) throw new NativeBrowserUnavailable();
|
|
66
66
|
const pane = { ...matches[0]! };
|
|
67
|
-
|
|
68
|
-
|
|
67
|
+
// A stock tmux server has no pane birth id; it reads empty there, both times.
|
|
68
|
+
const paneBirth = pane.nativePaneBirthId ?? "";
|
|
69
|
+
if (!/^%[0-9]+$/u.test(pane.runtimePaneId)) throw new NativeBrowserUnavailable();
|
|
69
70
|
const observe = async () => {
|
|
70
71
|
const raw = await options.run(
|
|
71
72
|
[
|
|
@@ -80,7 +81,7 @@ export function createNativeBrowserResolver(options: {
|
|
|
80
81
|
assertCurrent();
|
|
81
82
|
if (raw.length > 8192) throw new NativeBrowserUnavailable();
|
|
82
83
|
const [semantic, birth, endpoint] = raw.trimEnd().split("\t").map(decodeTmuxArgument);
|
|
83
|
-
if (semantic !== target.semanticPaneId || birth !==
|
|
84
|
+
if (semantic !== target.semanticPaneId || birth !== paneBirth)
|
|
84
85
|
throw new NativeBrowserUnavailable();
|
|
85
86
|
const parsed = NativeBrowserEndpointSchema.parse(JSON.parse(endpoint ?? "null"));
|
|
86
87
|
if (parsed.pane !== pane.runtimePaneId) throw new NativeBrowserUnavailable();
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { basename, dirname } from "node:path";
|
|
2
|
+
import {
|
|
3
|
+
PaneReaderAssetRequestSchemaZ,
|
|
4
|
+
PaneReaderAssetResponseSchemaZ,
|
|
5
|
+
PaneReaderRequestSchemaZ,
|
|
6
|
+
PaneReaderResponseSchemaZ,
|
|
7
|
+
type PaneEditorContextTarget,
|
|
8
|
+
type PaneReaderAssetResponse,
|
|
9
|
+
type PaneReaderResponse,
|
|
10
|
+
} from "@tmux-ide/contracts";
|
|
11
|
+
import type { LiveSessionSummary } from "../command-center/discovery.ts";
|
|
12
|
+
import type { WorkspaceTerminalInventoryRuntime } from "../terminal/attachments/native-runtime.ts";
|
|
13
|
+
import type { WorkspaceRegistry } from "./workspace-registry.ts";
|
|
14
|
+
import { decodeTmuxArgument } from "../terminal/protocol/session-descriptor-discovery.ts";
|
|
15
|
+
import { readerOption, type ReaderOption } from "../terminal/protocol/reader-option.ts";
|
|
16
|
+
import { readReaderAssetPage, readReaderPage } from "./pane-reader-files.ts";
|
|
17
|
+
|
|
18
|
+
/** Any identity, liveness or option failure. Carries no path or detail. */
|
|
19
|
+
export class PaneReaderUnavailable extends Error {
|
|
20
|
+
constructor() {
|
|
21
|
+
super("The reader pane is unavailable");
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface PaneReaderResolver {
|
|
26
|
+
read(input: unknown, cancellation: AbortSignal): Promise<PaneReaderResponse>;
|
|
27
|
+
asset(input: unknown, cancellation: AbortSignal): Promise<PaneReaderAssetResponse>;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Serves only the file named by the target pane's `@tmux_ide_reader` option,
|
|
32
|
+
* for a pane whose identity is proven again before and after the read, and
|
|
33
|
+
* whose reader process is alive.
|
|
34
|
+
*/
|
|
35
|
+
export function createPaneReaderResolver(options: {
|
|
36
|
+
generation: string;
|
|
37
|
+
assertOpen(): void;
|
|
38
|
+
registry: Pick<WorkspaceRegistry, "get">;
|
|
39
|
+
catalog(): Promise<LiveSessionSummary[]>;
|
|
40
|
+
inventory: Pick<WorkspaceTerminalInventoryRuntime, "discoverTerminalInventory">;
|
|
41
|
+
run(args: readonly string[], signal: AbortSignal): Promise<string>;
|
|
42
|
+
alive?: (pid: number) => boolean;
|
|
43
|
+
}): PaneReaderResolver {
|
|
44
|
+
let readers = 0;
|
|
45
|
+
const withReader = async <T>(
|
|
46
|
+
target: PaneEditorContextTarget,
|
|
47
|
+
cancellation: AbortSignal,
|
|
48
|
+
work: (reader: ReaderOption) => T,
|
|
49
|
+
): Promise<T> => {
|
|
50
|
+
const signal = AbortSignal.any([cancellation, AbortSignal.timeout(2500)]);
|
|
51
|
+
const workspace = options.registry.get(target.workspaceName);
|
|
52
|
+
const assertCurrent = () => {
|
|
53
|
+
options.assertOpen();
|
|
54
|
+
signal.throwIfAborted();
|
|
55
|
+
if (
|
|
56
|
+
target.generation !== options.generation ||
|
|
57
|
+
!workspace ||
|
|
58
|
+
options.registry.get(target.workspaceName) !== workspace
|
|
59
|
+
)
|
|
60
|
+
throw new PaneReaderUnavailable();
|
|
61
|
+
};
|
|
62
|
+
assertCurrent();
|
|
63
|
+
if (readers >= 8) throw new PaneReaderUnavailable();
|
|
64
|
+
readers++;
|
|
65
|
+
try {
|
|
66
|
+
const sessions = await options.catalog();
|
|
67
|
+
assertCurrent();
|
|
68
|
+
const matching = sessions.filter((s) => s.liveSessionId === target.liveSessionId);
|
|
69
|
+
if (matching.length !== 1 || matching[0]!.sessionName !== workspace!.sessionName)
|
|
70
|
+
throw new PaneReaderUnavailable();
|
|
71
|
+
const snapshot = await options.inventory.discoverTerminalInventory(signal);
|
|
72
|
+
assertCurrent();
|
|
73
|
+
if (
|
|
74
|
+
snapshot.catalog.invalidRuntimeProof ||
|
|
75
|
+
snapshot.catalog.duplicateSemanticStamp ||
|
|
76
|
+
snapshot.catalog.duplicateRuntimePaneBinding
|
|
77
|
+
)
|
|
78
|
+
throw new PaneReaderUnavailable();
|
|
79
|
+
const matches = snapshot.panes.filter(
|
|
80
|
+
(p) =>
|
|
81
|
+
p.workspaceName === target.workspaceName &&
|
|
82
|
+
p.semanticPaneId === target.semanticPaneId &&
|
|
83
|
+
p.sessionName === workspace!.sessionName,
|
|
84
|
+
);
|
|
85
|
+
if (matches.length !== 1) throw new PaneReaderUnavailable();
|
|
86
|
+
const pane = { ...matches[0]! };
|
|
87
|
+
// A stock tmux server has no pane birth id; it reads empty there, both times.
|
|
88
|
+
const paneBirth = pane.nativePaneBirthId ?? "";
|
|
89
|
+
if (!/^%[0-9]+$/u.test(pane.runtimePaneId)) throw new PaneReaderUnavailable();
|
|
90
|
+
const observe = async (): Promise<ReaderOption> => {
|
|
91
|
+
const raw = await options.run(
|
|
92
|
+
[
|
|
93
|
+
"display-message",
|
|
94
|
+
"-p",
|
|
95
|
+
"-t",
|
|
96
|
+
pane.runtimePaneId,
|
|
97
|
+
"#{qa:@tmux_ide_pane_id}\t#{qa:pane_birth_id}\t#{pane_pid}\t#{qa:@tmux_ide_reader}",
|
|
98
|
+
],
|
|
99
|
+
signal,
|
|
100
|
+
);
|
|
101
|
+
assertCurrent();
|
|
102
|
+
if (raw.length > 16_384) throw new PaneReaderUnavailable();
|
|
103
|
+
const [semantic, birth, panePid, option] = raw
|
|
104
|
+
.trimEnd()
|
|
105
|
+
.split("\t")
|
|
106
|
+
.map(decodeTmuxArgument);
|
|
107
|
+
if (semantic !== target.semanticPaneId || birth !== paneBirth)
|
|
108
|
+
throw new PaneReaderUnavailable();
|
|
109
|
+
const reader = readerOption(option ?? "", panePid ?? "", options.alive);
|
|
110
|
+
if (!reader) throw new PaneReaderUnavailable();
|
|
111
|
+
return reader;
|
|
112
|
+
};
|
|
113
|
+
const reader = await observe();
|
|
114
|
+
const result = work(reader);
|
|
115
|
+
const current = await observe();
|
|
116
|
+
if (current.path !== reader.path || current.pid !== reader.pid)
|
|
117
|
+
throw new PaneReaderUnavailable();
|
|
118
|
+
return result;
|
|
119
|
+
} finally {
|
|
120
|
+
readers--;
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
return {
|
|
124
|
+
read: async (input, cancellation) => {
|
|
125
|
+
const request = PaneReaderRequestSchemaZ.parse(input);
|
|
126
|
+
return withReader(request.target, cancellation, (reader) =>
|
|
127
|
+
PaneReaderResponseSchemaZ.parse({
|
|
128
|
+
version: 1,
|
|
129
|
+
name: reader.name,
|
|
130
|
+
folder: basename(dirname(reader.path)),
|
|
131
|
+
...readReaderPage(reader.path, request.have, request.page),
|
|
132
|
+
}),
|
|
133
|
+
);
|
|
134
|
+
},
|
|
135
|
+
asset: async (input, cancellation) => {
|
|
136
|
+
const request = PaneReaderAssetRequestSchemaZ.parse(input);
|
|
137
|
+
return withReader(request.target, cancellation, (reader) =>
|
|
138
|
+
PaneReaderAssetResponseSchemaZ.parse({
|
|
139
|
+
version: 1,
|
|
140
|
+
...readReaderAssetPage(reader.path, request.src, request.page),
|
|
141
|
+
}),
|
|
142
|
+
);
|
|
143
|
+
},
|
|
144
|
+
};
|
|
145
|
+
}
|
|
@@ -42,12 +42,17 @@ export async function captureAgentAdmission(
|
|
|
42
42
|
id !== session.id ||
|
|
43
43
|
!/^@\d+$/.test(window!) ||
|
|
44
44
|
!/^%\d+$/.test(pane!) ||
|
|
45
|
-
!/^[1-9]\d
|
|
45
|
+
!/^(?:[1-9]\d*)?$/.test(birth!)
|
|
46
46
|
)
|
|
47
47
|
throw new Error("Agent native identity is unavailable");
|
|
48
48
|
return { window: window!, pane: pane!, birth: birth!, stamp: stamp! };
|
|
49
49
|
});
|
|
50
50
|
if (rows.length > 512) throw new Error("Agent inventory exceeds admission bounds");
|
|
51
|
+
// A stock tmux server has no pane birth id: every row reads empty. Its pane
|
|
52
|
+
// ids are never reused while it runs, and each command already checks the
|
|
53
|
+
// session id and creation time, so the pane and window ids fence the lifetime.
|
|
54
|
+
if (rows.some((row) => row.birth === "") && rows.some((row) => row.birth !== ""))
|
|
55
|
+
throw new Error("Agent native identity is unavailable");
|
|
51
56
|
return rows;
|
|
52
57
|
};
|
|
53
58
|
const initial = await scan();
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { nativeSplitCapability } from "../terminal/protocol/native-split-resize.ts";
|
|
2
|
+
|
|
3
|
+
/** Runs one tmux command against a server and returns its stdout; throws with stderr. */
|
|
4
|
+
export type TmuxProbe = (args: readonly string[]) => string;
|
|
5
|
+
const UNKNOWN = (command: string) => new RegExp(`^unknown command: ${command}$`, "mu");
|
|
6
|
+
|
|
7
|
+
export type NativeAnswer = "full" | "stock" | "older" | "partial" | "no-server" | "unknown";
|
|
8
|
+
/** The same reading of the server as the mirror's: the stock resize when it refuses
|
|
9
|
+
* the split command by name, and full only with the split capability it requires. */
|
|
10
|
+
export function nativeCommands(probe: TmuxProbe): NativeAnswer {
|
|
11
|
+
const ask = (command: string) => {
|
|
12
|
+
try {
|
|
13
|
+
return { output: probe([command, "-V"]) };
|
|
14
|
+
} catch (error) {
|
|
15
|
+
const failure = error as { stderr?: unknown; message?: string };
|
|
16
|
+
return { failure: String(failure.stderr ?? failure.message ?? "") };
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
const split = ask("tmux-ide-resize-split");
|
|
20
|
+
const events = ask("tmux-ide-events");
|
|
21
|
+
const failures = [split.failure, events.failure].filter((text) => text !== undefined);
|
|
22
|
+
if (failures.some((text) => /no server running|error connecting/u.test(text!)))
|
|
23
|
+
return "no-server";
|
|
24
|
+
const refused = (answer: { failure?: string }, command: string) =>
|
|
25
|
+
answer.failure !== undefined && UNKNOWN(command).test(answer.failure);
|
|
26
|
+
if (refused(split, "tmux-ide-resize-split")) {
|
|
27
|
+
if (refused(events, "tmux-ide-events")) return "stock";
|
|
28
|
+
// The journal answers: a tmux-ide tmux built before the split command.
|
|
29
|
+
if (events.output !== undefined) return "older";
|
|
30
|
+
return "unknown";
|
|
31
|
+
}
|
|
32
|
+
if (split.output !== undefined && events.output !== undefined) {
|
|
33
|
+
try {
|
|
34
|
+
return nativeSplitCapability(split.output) ? "full" : "partial";
|
|
35
|
+
} catch {
|
|
36
|
+
return "partial";
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return failures.length === 2 ? "unknown" : "partial";
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** The answers a live server can give (doctor also reports "no-server"). */
|
|
43
|
+
export type ServerFeatures = Exclude<NativeAnswer, "no-server">;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import {
|
|
2
|
+
paneStreamCloseForRetirement,
|
|
3
|
+
type PaneStreamShutdownClose,
|
|
4
|
+
} from "../terminal/pane-stream/pane-stream-websocket.ts";
|
|
5
|
+
import type { TrackTeardownStep } from "./daemon-stop-progress.ts";
|
|
6
|
+
import type { TmuxServerOwnerRetirement } from "./tmux-server-owners.ts";
|
|
7
|
+
|
|
8
|
+
export type NativeOwnerTeardownStep = readonly [name: string, close: () => unknown];
|
|
9
|
+
|
|
10
|
+
export interface NativeOwnerTeardownParts {
|
|
11
|
+
readonly serverId: string;
|
|
12
|
+
readonly paneStreams: { dispose(close?: PaneStreamShutdownClose): Promise<void> };
|
|
13
|
+
/** Synchronous: from here on the owner refuses new work. */
|
|
14
|
+
readonly markRetired: () => void;
|
|
15
|
+
/**
|
|
16
|
+
* Synchronous prelude (abort credentials, start observation disposal), then
|
|
17
|
+
* the ordered steps. `streamsClosed` is the stream shutdown already under way.
|
|
18
|
+
*/
|
|
19
|
+
readonly begin: (streamsClosed: Promise<void>) => readonly NativeOwnerTeardownStep[];
|
|
20
|
+
readonly track?: TrackTeardownStep;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* One tmux server owner's teardown. The pane streams hear first, and hear why:
|
|
25
|
+
* a retired owner under a live daemon means "reconnect now", not "the daemon
|
|
26
|
+
* is shutting down" (#840). Every later step runs even if an earlier one
|
|
27
|
+
* fails; the failures are reported together. Idempotent.
|
|
28
|
+
*/
|
|
29
|
+
export function createNativeOwnerTeardown(
|
|
30
|
+
parts: NativeOwnerTeardownParts,
|
|
31
|
+
): (retirement?: TmuxServerOwnerRetirement) => Promise<void> {
|
|
32
|
+
let teardown: Promise<void> | null = null;
|
|
33
|
+
return (retirement) => {
|
|
34
|
+
if (teardown) return teardown;
|
|
35
|
+
parts.markRetired();
|
|
36
|
+
const streamsClosed = parts.paneStreams.dispose(paneStreamCloseForRetirement(retirement));
|
|
37
|
+
streamsClosed.catch(() => undefined);
|
|
38
|
+
const steps = parts.begin(streamsClosed);
|
|
39
|
+
const track: TrackTeardownStep = parts.track ?? (async (_step, work) => await work());
|
|
40
|
+
teardown = (async () => {
|
|
41
|
+
const failures: unknown[] = [];
|
|
42
|
+
for (const [step, close] of steps) {
|
|
43
|
+
try {
|
|
44
|
+
await track(`owner:${parts.serverId}:${step}`, close);
|
|
45
|
+
} catch (error) {
|
|
46
|
+
failures.push(error);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if (failures.length)
|
|
50
|
+
throw new AggregateError(failures, "Tmux server owner retirement failed");
|
|
51
|
+
})();
|
|
52
|
+
return teardown;
|
|
53
|
+
};
|
|
54
|
+
}
|