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
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { basename, isAbsolute } from "node:path";
|
|
2
|
+
import { hasControlCharacter } from "@tmux-ide/contracts";
|
|
3
|
+
const MARKDOWN = /\.(?:md|markdown)$/iu;
|
|
4
|
+
export function isMarkdownPath(path) {
|
|
5
|
+
const name = basename(path);
|
|
6
|
+
return MARKDOWN.test(name) && !/^\.(?:md|markdown)$/iu.test(name);
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Parse `@tmux_ide_reader`: `{"version":1,"pid":N,"path":"/abs/notes.md"}`.
|
|
10
|
+
* A reader exists only while the process that set the option is alive, and
|
|
11
|
+
* only on the pane whose own process it is: `panePid` is that pane's
|
|
12
|
+
* `#{pane_pid}`. The CLI starts `tmux-ide show` with tmux's direct exec (no
|
|
13
|
+
* shell), so the pane's process is the reader itself and records exactly that
|
|
14
|
+
* pid. Equality rather than "a descendant of" needs no process-tree walk.
|
|
15
|
+
*
|
|
16
|
+
* What the tie rules out: an option left behind by a reader that has exited,
|
|
17
|
+
* and a later process that happens to reuse its pid. What it does not: the
|
|
18
|
+
* option is not proof that `tmux-ide show` set it. In a shell pane the shell
|
|
19
|
+
* is the pane's process, so the shell can set an option naming its own pid,
|
|
20
|
+
* and any process that can talk to the tmux server can read another pane's
|
|
21
|
+
* pid and set that pane's option. Both are the same user, who can already
|
|
22
|
+
* read the file; the reader grants no access they do not have.
|
|
23
|
+
*/
|
|
24
|
+
export function readerOption(value, panePid, alive = processAlive) {
|
|
25
|
+
if (!value || value.length > 8192)
|
|
26
|
+
return null;
|
|
27
|
+
let parsed;
|
|
28
|
+
try {
|
|
29
|
+
parsed = JSON.parse(value);
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed))
|
|
35
|
+
return null;
|
|
36
|
+
const record = parsed;
|
|
37
|
+
if (Object.keys(record).sort().join(",") !== "path,pid,version")
|
|
38
|
+
return null;
|
|
39
|
+
const { version, pid, path } = record;
|
|
40
|
+
if (version !== 1 || typeof pid !== "number" || !Number.isSafeInteger(pid) || pid <= 0)
|
|
41
|
+
return null;
|
|
42
|
+
if (!/^[1-9][0-9]*$/u.test(panePid) || String(pid) !== panePid)
|
|
43
|
+
return null;
|
|
44
|
+
if (typeof path !== "string" ||
|
|
45
|
+
path.length > 4096 ||
|
|
46
|
+
!isAbsolute(path) ||
|
|
47
|
+
hasControlCharacter(path) ||
|
|
48
|
+
!isMarkdownPath(path))
|
|
49
|
+
return null;
|
|
50
|
+
const name = basename(path);
|
|
51
|
+
if (name.length > 255)
|
|
52
|
+
return null;
|
|
53
|
+
if (!alive(pid))
|
|
54
|
+
return null;
|
|
55
|
+
return { name, path, pid };
|
|
56
|
+
}
|
|
57
|
+
function processAlive(pid) {
|
|
58
|
+
try {
|
|
59
|
+
process.kill(pid, 0);
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
// Including EPERM: a pid now owned by another user is not our reader.
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { browserIcon } from "./browser-icon.js";
|
|
2
|
+
import { readerOption } from "./reader-option.js";
|
|
2
3
|
/**
|
|
3
4
|
* `qa` asks tmux to escape each value as a command argument. In particular,
|
|
4
5
|
* embedded tabs/newlines/backslashes become escapes, leaving our record tabs
|
|
@@ -29,7 +30,33 @@ export const SESSION_PANE_DESCRIPTOR_FORMAT = [
|
|
|
29
30
|
"#{pane_birth_id}",
|
|
30
31
|
"#{qa:@tmux_ide_name_source}",
|
|
31
32
|
"#{qa:@tmux_ide_browser_icon}",
|
|
33
|
+
"#{qa:@tmux_ide_reader}",
|
|
34
|
+
// The reader option belongs to the pane only when its own process set it.
|
|
35
|
+
"#{pane_pid}",
|
|
32
36
|
].join("\t");
|
|
37
|
+
/**
|
|
38
|
+
* Descriptor fields the program in a pane changes whenever it likes: its
|
|
39
|
+
* command name, the window name tmux derives from it, and its title.
|
|
40
|
+
*/
|
|
41
|
+
const VOLATILE_DESCRIPTOR_FIELDS = new Set([
|
|
42
|
+
4, // pane_current_command
|
|
43
|
+
7, // window_name
|
|
44
|
+
9, // pane_title
|
|
45
|
+
]);
|
|
46
|
+
/**
|
|
47
|
+
* Whether two `list-panes` replies in SESSION_PANE_DESCRIPTOR_FORMAT describe
|
|
48
|
+
* the same panes. A busy pane changes its command and title between any two
|
|
49
|
+
* reads, which is not a pane set that is still changing: those fields are
|
|
50
|
+
* display text, read again on the next refresh (#730).
|
|
51
|
+
*/
|
|
52
|
+
export function sameSessionPaneInventory(before, after) {
|
|
53
|
+
const stable = (line) => line
|
|
54
|
+
.split("\t")
|
|
55
|
+
.map((field, index) => (VOLATILE_DESCRIPTOR_FIELDS.has(index) ? "" : field))
|
|
56
|
+
.join("\t");
|
|
57
|
+
return (before.length === after.length &&
|
|
58
|
+
before.every((line, index) => line === after[index] || stable(line) === stable(after[index])));
|
|
59
|
+
}
|
|
33
60
|
/** Decode the escapes emitted by tmux's `qa` format modifier. */
|
|
34
61
|
export function decodeTmuxArgument(value) {
|
|
35
62
|
const encoded = value.length >= 2 &&
|
|
@@ -102,9 +129,9 @@ export function parseSessionPaneDescriptorReply(lines) {
|
|
|
102
129
|
continue;
|
|
103
130
|
}
|
|
104
131
|
const encoded = utf8Line.split("\t");
|
|
105
|
-
if (encoded.length
|
|
132
|
+
if (encoded.length < 21 || encoded.length > 25)
|
|
106
133
|
continue;
|
|
107
|
-
const [runtimePaneId = "", semanticPaneId = "", role = "", type = "", currentCommand = "", cwd = "", windowIndexRaw = "", windowName = "", windowId = "", title = "", runtimeSessionId = "", paneIndexRaw = "", name = "", missionStamp = "", paneActiveRaw = "", windowActiveRaw = "", semanticWindowId = "", sessionName = "", windowPaneCountRaw = "", sessionWindowCountRaw = "", nativePaneBirthId = "", nameSource = "", browserIconRaw = "",] = encoded.map(decodeTmuxArgument);
|
|
134
|
+
const [runtimePaneId = "", semanticPaneId = "", role = "", type = "", currentCommand = "", cwd = "", windowIndexRaw = "", windowName = "", windowId = "", title = "", runtimeSessionId = "", paneIndexRaw = "", name = "", missionStamp = "", paneActiveRaw = "", windowActiveRaw = "", semanticWindowId = "", sessionName = "", windowPaneCountRaw = "", sessionWindowCountRaw = "", nativePaneBirthId = "", nameSource = "", browserIconRaw = "", readerRaw = "", panePidRaw = "",] = encoded.map(decodeTmuxArgument);
|
|
108
135
|
if (!/^%(?:0|[1-9][0-9]*)$/u.test(runtimePaneId) || runtimePaneId.length > 32)
|
|
109
136
|
continue;
|
|
110
137
|
if (!/^\$(?:0|[1-9][0-9]*)$/u.test(runtimeSessionId) || runtimeSessionId.length > 32)
|
|
@@ -142,6 +169,7 @@ export function parseSessionPaneDescriptorReply(lines) {
|
|
|
142
169
|
}
|
|
143
170
|
descriptors.push({
|
|
144
171
|
browserIcon: browserIcon(browserIconRaw),
|
|
172
|
+
reader: readerOption(readerRaw, panePidRaw),
|
|
145
173
|
sessionName,
|
|
146
174
|
runtimePaneId,
|
|
147
175
|
runtimeSessionId,
|
|
@@ -119,7 +119,10 @@ export function stockSplitCommand(request, sessionCreated, plan, panes, options,
|
|
|
119
119
|
export const STOCK_SPLIT_OPTIONS_FORMAT = "#{pane-border-status}\t#{pane-scrollbars}\t#{pane-scrollbars-style}";
|
|
120
120
|
export function parseStockSplitOptions(line) {
|
|
121
121
|
const [borderStatus, scrollbars, style] = (line ?? "").split("\t");
|
|
122
|
-
|
|
122
|
+
// The raw value stays: the guarded command compares it with the option. A
|
|
123
|
+
// floating value leaves tiled panes without a status line, like "off".
|
|
124
|
+
if (!/^(off|top|bottom|top-floating|bottom-floating)$/u.test(borderStatus ?? "") ||
|
|
125
|
+
!/^[a-z]+$/u.test(scrollbars ?? ""))
|
|
123
126
|
return null;
|
|
124
127
|
const field = (name) => Number(new RegExp(`\\b${name}=(\\d+)`, "u").exec(style ?? "")?.[1] ?? 0);
|
|
125
128
|
return {
|
|
@@ -71,6 +71,15 @@ export class SessionRuntimeRegistry {
|
|
|
71
71
|
#scheduler;
|
|
72
72
|
#observability;
|
|
73
73
|
#createTraceCorrelator;
|
|
74
|
+
#onInventoryRecovered;
|
|
75
|
+
#announceInventory(session) {
|
|
76
|
+
try {
|
|
77
|
+
this.#onInventoryRecovered?.(session);
|
|
78
|
+
}
|
|
79
|
+
catch {
|
|
80
|
+
// A publication failure never changes qualification.
|
|
81
|
+
}
|
|
82
|
+
}
|
|
74
83
|
#sessions = new Map();
|
|
75
84
|
#listenerDisposal = null;
|
|
76
85
|
#proofPrewarmOwnership = new Map();
|
|
@@ -85,6 +94,7 @@ export class SessionRuntimeRegistry {
|
|
|
85
94
|
this.#observability = options.observability ?? DISABLED_SESSION_RUNTIME_OBSERVABILITY;
|
|
86
95
|
this.#createTraceCorrelator =
|
|
87
96
|
options.createTraceCorrelator ?? ((scheduler) => new RuntimeTraceCorrelator(scheduler));
|
|
97
|
+
this.#onInventoryRecovered = options.onInventoryRecovered ?? null;
|
|
88
98
|
const diagnosticMirrorOptions = {
|
|
89
99
|
onInputAccepted: (session, action, acceptedAtMicros, ok) => {
|
|
90
100
|
for (const traceId of action.traceIds ?? []) {
|
|
@@ -174,6 +184,10 @@ export class SessionRuntimeRegistry {
|
|
|
174
184
|
options.mirror?.onSharedWindowConflict?.(session, conflict);
|
|
175
185
|
if (conflict)
|
|
176
186
|
this.#sessions.get(session)?.invalidateSharedWindowAuthority();
|
|
187
|
+
// A cleared conflict is the trigger an idle client needs: nobody else
|
|
188
|
+
// may read the inventory, and the client's re-read re-qualifies it.
|
|
189
|
+
else if (!this.#mirror.hasSharedWindowConflict(session))
|
|
190
|
+
this.#announceInventory(session);
|
|
177
191
|
},
|
|
178
192
|
onNativeClientActivity: (session) => {
|
|
179
193
|
options.mirror?.onNativeClientActivity?.(session);
|
|
@@ -253,7 +267,10 @@ export class SessionRuntimeRegistry {
|
|
|
253
267
|
}
|
|
254
268
|
signal?.throwIfAborted();
|
|
255
269
|
await abortable(this.#mirror.verifyRegisteredWindows(), signal);
|
|
270
|
+
const wasQualified = runtime.trustedInventoryQualified();
|
|
256
271
|
runtime.qualifyTrustedInventory(runtimeSessionId);
|
|
272
|
+
if (!wasQualified && runtime.trustedInventoryQualified())
|
|
273
|
+
this.#announceInventory(session);
|
|
257
274
|
}
|
|
258
275
|
finally {
|
|
259
276
|
this.#releaseProofPrewarmRuntime(runtime);
|
|
@@ -10,6 +10,31 @@ import { KITTY_PLACEMENT_OSC, KittyApcScanner, KittyImageStore, } from "../graph
|
|
|
10
10
|
// Bound parser work per turn without changing byte-stream semantics. This is a
|
|
11
11
|
// batch bound, not a producer queue cap: upstream pressure must preserve bytes.
|
|
12
12
|
const MAX_INGEST_BATCH_BYTES = 256 * 1024;
|
|
13
|
+
/**
|
|
14
|
+
* Under a flood, publish at most one commit per display interval (daemon perf
|
|
15
|
+
* F1). Each commit projects, diffs and hashes the replica; committing after
|
|
16
|
+
* every parsed chunk kept the daemon off tmux's control pipe, so tmux itself
|
|
17
|
+
* ran about 4× slower while a pane was viewed. Rows that scroll through
|
|
18
|
+
* history between two commits are never projected or hashed. A write with no
|
|
19
|
+
* output queued behind it (a keystroke echo, the end of a burst) still
|
|
20
|
+
* commits at once.
|
|
21
|
+
*/
|
|
22
|
+
export const COALESCED_COMMIT_INTERVAL_MS = 16;
|
|
23
|
+
/**
|
|
24
|
+
* A flood commit costs far more than the display interval (about 35 ms with a
|
|
25
|
+
* full 2,000-row history), so an interval counted from the commit's start
|
|
26
|
+
* alone never skips anything: the next chunk always arrives "late". After a
|
|
27
|
+
* commit the interpreter therefore also reads queued output for this many
|
|
28
|
+
* times the commit's own cost before it commits again, so at most one part in
|
|
29
|
+
* (1 + factor) of a flood goes to commits (half, at 1).
|
|
30
|
+
*/
|
|
31
|
+
export const COALESCED_COMMIT_REST_FACTOR = 1;
|
|
32
|
+
/**
|
|
33
|
+
* Upper bound of that rest. A skipped frame can still wait longer when the
|
|
34
|
+
* queued write behind it opens a synchronized update: then it is published
|
|
35
|
+
* with that update, at its end or by the 250 ms sync recovery.
|
|
36
|
+
*/
|
|
37
|
+
export const COALESCED_COMMIT_MAX_REST_MS = 100;
|
|
13
38
|
/** Daemon-owned, sans-I/O VT interpreter with one FIFO for bytes and geometry. */
|
|
14
39
|
export class TerminalReplicaInterpreter {
|
|
15
40
|
#nativeSeedBackingCandidate;
|
|
@@ -38,6 +63,11 @@ export class TerminalReplicaInterpreter {
|
|
|
38
63
|
#needsSeed = true;
|
|
39
64
|
#closed = false;
|
|
40
65
|
#walkCount = 0;
|
|
66
|
+
#lastCommitAtMs = Number.NEGATIVE_INFINITY;
|
|
67
|
+
#lastCommitEndMs = Number.NEGATIVE_INFINITY;
|
|
68
|
+
#lastCommitCostMs = 0;
|
|
69
|
+
// A coalesced write skipped its commit and counts on a queued write to publish.
|
|
70
|
+
#coalescedCommitOwed = false;
|
|
41
71
|
#pendingWrites = null;
|
|
42
72
|
#widgetGate = false;
|
|
43
73
|
// kitty graphics: images outlive reseeds; the scanner owns split APCs.
|
|
@@ -349,7 +379,7 @@ export class TerminalReplicaInterpreter {
|
|
|
349
379
|
this.#backend.dispose();
|
|
350
380
|
this.#emit(update);
|
|
351
381
|
}
|
|
352
|
-
async #write(data, continuedTrace) {
|
|
382
|
+
async #write(data, continuedTrace, hasBacklog = () => false) {
|
|
353
383
|
if (this.#closed || this.#nativeReseedRequested)
|
|
354
384
|
return;
|
|
355
385
|
// This optional id is only a controlled next-output probe. It is not a
|
|
@@ -370,8 +400,17 @@ export class TerminalReplicaInterpreter {
|
|
|
370
400
|
// see. Skipping it matters: every parser write settles on a later timer
|
|
371
401
|
// turn, so a frame split into dozens of %output chunks would otherwise
|
|
372
402
|
// serialize dozens of turns and fall behind a 30 fps image stream.
|
|
373
|
-
if (scanned.forward.byteLength === 0)
|
|
403
|
+
if (scanned.forward.byteLength === 0) {
|
|
404
|
+
// The queued write a coalesced commit was counting on turned out to be
|
|
405
|
+
// all image payload, and nothing else is queued: publish what it skipped.
|
|
406
|
+
// Not inside a synchronized update: its end, or the sync recovery,
|
|
407
|
+
// publishes the owed commit with the whole frame.
|
|
408
|
+
if (this.#coalescedCommitOwed && !hasBacklog() && !this.#backend.modes().synchronizedOutput) {
|
|
409
|
+
this.#commit(false, this.#pendingWriteDirty ?? undefined, trace);
|
|
410
|
+
this.#publishGraphics();
|
|
411
|
+
}
|
|
374
412
|
return;
|
|
413
|
+
}
|
|
375
414
|
// Scanning can prepend an escape retained from the previous chunk. Bound
|
|
376
415
|
// the actual parser calls too, and union damage across every fragment.
|
|
377
416
|
for (let offset = 0; offset < scanned.forward.length; offset += MAX_INGEST_BATCH_BYTES) {
|
|
@@ -408,6 +447,18 @@ export class TerminalReplicaInterpreter {
|
|
|
408
447
|
this.#commit(false, undefined, trace);
|
|
409
448
|
}
|
|
410
449
|
else {
|
|
450
|
+
// Coalesce under a flood: more output is already queued, the last commit
|
|
451
|
+
// is recent, and nobody is timing this write. The dirty range stays in
|
|
452
|
+
// #pendingWriteDirty and the next commit (the queued write's, or any
|
|
453
|
+
// control operation's) merges it, so nothing is dropped. The bootstrap
|
|
454
|
+
// seed is never held: before it no commit has run, so one is always due.
|
|
455
|
+
if (trace === null &&
|
|
456
|
+
this.#causalCell === null &&
|
|
457
|
+
hasBacklog() &&
|
|
458
|
+
!this.#coalescedCommitIsDue()) {
|
|
459
|
+
this.#coalescedCommitOwed = true;
|
|
460
|
+
return;
|
|
461
|
+
}
|
|
411
462
|
this.#commit(false, this.#backend.dirtyRange(), trace);
|
|
412
463
|
}
|
|
413
464
|
this.#publishGraphics();
|
|
@@ -444,7 +495,26 @@ export class TerminalReplicaInterpreter {
|
|
|
444
495
|
this.#syncRecovery.cancel();
|
|
445
496
|
this.#syncRecovery = null;
|
|
446
497
|
}
|
|
498
|
+
/** True once a queued flood may publish again: see the two constants above. */
|
|
499
|
+
#coalescedCommitIsDue() {
|
|
500
|
+
const now = this.#scheduler.nowMs();
|
|
501
|
+
if (now - this.#lastCommitAtMs < COALESCED_COMMIT_INTERVAL_MS)
|
|
502
|
+
return false;
|
|
503
|
+
const rest = Math.min(COALESCED_COMMIT_MAX_REST_MS, COALESCED_COMMIT_REST_FACTOR * this.#lastCommitCostMs);
|
|
504
|
+
return now - this.#lastCommitEndMs >= rest;
|
|
505
|
+
}
|
|
447
506
|
#commit(forceSeed, dirty, trace = null) {
|
|
507
|
+
this.#lastCommitAtMs = this.#scheduler.nowMs();
|
|
508
|
+
this.#coalescedCommitOwed = false;
|
|
509
|
+
try {
|
|
510
|
+
this.#commitNow(forceSeed, dirty, trace);
|
|
511
|
+
}
|
|
512
|
+
finally {
|
|
513
|
+
this.#lastCommitEndMs = this.#scheduler.nowMs();
|
|
514
|
+
this.#lastCommitCostMs = this.#lastCommitEndMs - this.#lastCommitAtMs;
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
#commitNow(forceSeed, dirty, trace) {
|
|
448
518
|
if (this.#backend.requiresNativeReseed()) {
|
|
449
519
|
if (!this.#nativeReseedRequested) {
|
|
450
520
|
this.#nativeReseedRequested = true;
|
|
@@ -710,7 +780,15 @@ export class TerminalReplicaInterpreter {
|
|
|
710
780
|
group.entries.splice(0, completed.length);
|
|
711
781
|
group.bytes -= length;
|
|
712
782
|
try {
|
|
713
|
-
|
|
783
|
+
// Backlog: bytes still in this group, or a newer untraced group
|
|
784
|
+
// already waiting behind it (a group that has not run yet always
|
|
785
|
+
// holds an entry). A traced group is a boundary: its commit must
|
|
786
|
+
// not carry these external bytes. Checked after parsing, when it
|
|
787
|
+
// is current.
|
|
788
|
+
await this.#write(data, group.trace, () => group.entries.length > 0 ||
|
|
789
|
+
(this.#pendingWrites !== null &&
|
|
790
|
+
this.#pendingWrites !== group &&
|
|
791
|
+
this.#pendingWrites.trace === null));
|
|
714
792
|
}
|
|
715
793
|
catch (error) {
|
|
716
794
|
for (const entry of completed)
|
|
@@ -5,6 +5,11 @@ import { projectNativeGridRow } from "../mirror/native-grid-projection.js";
|
|
|
5
5
|
import { TerminalReplicaInterpreter, } from "./terminal-replica-interpreter.js";
|
|
6
6
|
import { SYSTEM_SESSION_RUNTIME_SCHEDULER, } from "./runtime-scheduler.js";
|
|
7
7
|
import { DISABLED_SESSION_RUNTIME_OBSERVABILITY } from "./runtime-observability.js";
|
|
8
|
+
/**
|
|
9
|
+
* How long a pane may have no listener before it is parked (perf F2). Long
|
|
10
|
+
* enough that switching away and back stays warm.
|
|
11
|
+
*/
|
|
12
|
+
export const PARK_AFTER_MS = 10_000;
|
|
8
13
|
/** One parser/replica owner for one semantic pane inside one SessionRuntime. */
|
|
9
14
|
export class SessionRuntimeTerminalReplicaOwner {
|
|
10
15
|
generation;
|
|
@@ -21,6 +26,11 @@ export class SessionRuntimeTerminalReplicaOwner {
|
|
|
21
26
|
#start;
|
|
22
27
|
#upstream = null;
|
|
23
28
|
#disposed = false;
|
|
29
|
+
#parkTimer = null;
|
|
30
|
+
#parked = false;
|
|
31
|
+
// From the park until the next reseed lands, the replica is older than tmux.
|
|
32
|
+
// Native backing and history anchors must not pair it with current tmux state.
|
|
33
|
+
#stale = false;
|
|
24
34
|
#historyAnchors = new HistoryAnchorOwner();
|
|
25
35
|
#cols = 80;
|
|
26
36
|
#rows = 24;
|
|
@@ -142,12 +152,12 @@ export class SessionRuntimeTerminalReplicaOwner {
|
|
|
142
152
|
this.#interpreter.failCausalCell(reason, traceId);
|
|
143
153
|
}
|
|
144
154
|
captureHistoryAnchor(proof, historyIndex) {
|
|
145
|
-
if (this.#disposed || this.#reseed || this.#waitingForGeometryCapture)
|
|
155
|
+
if (this.#disposed || this.#stale || this.#reseed || this.#waitingForGeometryCapture)
|
|
146
156
|
return { status: "unavailable" };
|
|
147
157
|
return this.#historyAnchors.capture(proof, historyIndex);
|
|
148
158
|
}
|
|
149
159
|
resolveHistoryAnchor(proof, token) {
|
|
150
|
-
if (this.#disposed || this.#reseed || this.#waitingForGeometryCapture)
|
|
160
|
+
if (this.#disposed || this.#stale || this.#reseed || this.#waitingForGeometryCapture)
|
|
151
161
|
return { status: "unavailable" };
|
|
152
162
|
return this.#historyAnchors.resolve(proof, token);
|
|
153
163
|
}
|
|
@@ -183,7 +193,7 @@ export class SessionRuntimeTerminalReplicaOwner {
|
|
|
183
193
|
if (!upstream?.captureNativeBacking)
|
|
184
194
|
return { status: "unsupported" };
|
|
185
195
|
const initial = this.#interpreter.currentSeed();
|
|
186
|
-
if (!initial || this.#reseed || this.#waitingForGeometryCapture)
|
|
196
|
+
if (!initial || this.#stale || this.#reseed || this.#waitingForGeometryCapture)
|
|
187
197
|
return { status: "changed" };
|
|
188
198
|
const epoch = this.#subscriptionEpoch;
|
|
189
199
|
const captured = await upstream.captureNativeBacking();
|
|
@@ -195,6 +205,7 @@ export class SessionRuntimeTerminalReplicaOwner {
|
|
|
195
205
|
return (!this.#disposed &&
|
|
196
206
|
this.#upstream === upstream &&
|
|
197
207
|
this.#subscriptionEpoch === epoch &&
|
|
208
|
+
!this.#stale &&
|
|
198
209
|
!this.#reseed &&
|
|
199
210
|
!this.#waitingForGeometryCapture &&
|
|
200
211
|
captured.isCurrent() &&
|
|
@@ -250,6 +261,8 @@ export class SessionRuntimeTerminalReplicaOwner {
|
|
|
250
261
|
catch {
|
|
251
262
|
// Bootstrap delivery has the same client-isolation rule as live frames.
|
|
252
263
|
}
|
|
264
|
+
// The last frame is out; now ask for the reseed that makes it current.
|
|
265
|
+
this.#unpark();
|
|
253
266
|
}
|
|
254
267
|
catch (error) {
|
|
255
268
|
this.#listeners.delete(listener);
|
|
@@ -264,9 +277,47 @@ export class SessionRuntimeTerminalReplicaOwner {
|
|
|
264
277
|
return;
|
|
265
278
|
closed = true;
|
|
266
279
|
this.#listeners.delete(listener);
|
|
280
|
+
if (this.#listeners.size === 0)
|
|
281
|
+
this.#schedulePark();
|
|
267
282
|
},
|
|
268
283
|
};
|
|
269
284
|
}
|
|
285
|
+
/**
|
|
286
|
+
* Park this pane PARK_AFTER_MS after its last listener leaves (perf F2).
|
|
287
|
+
* The owner is the pane's only channel subscriber, so freezing it pauses the
|
|
288
|
+
* pane's output to the daemon's control client (the channel's all-frozen
|
|
289
|
+
* path). tmux keeps running the pane; nothing here is parsed or hashed. The
|
|
290
|
+
* last committed seed stays, so the next listener sees it at once, and
|
|
291
|
+
* thawing runs the channel's requested-pause recovery, which reseeds.
|
|
292
|
+
* Until that reseed lands the replica is stale: history anchors and native
|
|
293
|
+
* backing answer as they do during any reseed, and the reseed's reset then
|
|
294
|
+
* drops every anchor taken before the park.
|
|
295
|
+
*/
|
|
296
|
+
#schedulePark() {
|
|
297
|
+
if (this.#disposed || this.#parked)
|
|
298
|
+
return;
|
|
299
|
+
this.#parkTimer?.cancel();
|
|
300
|
+
this.#parkTimer = this.#scheduler.timer(() => {
|
|
301
|
+
this.#parkTimer = null;
|
|
302
|
+
if (this.#disposed || this.#parked || this.#listeners.size > 0 || !this.#upstream)
|
|
303
|
+
return;
|
|
304
|
+
this.#parked = true;
|
|
305
|
+
this.#stale = true;
|
|
306
|
+
this.#upstream.freeze();
|
|
307
|
+
}, PARK_AFTER_MS);
|
|
308
|
+
}
|
|
309
|
+
#unpark() {
|
|
310
|
+
this.#parkTimer?.cancel();
|
|
311
|
+
this.#parkTimer = null;
|
|
312
|
+
if (!this.#parked)
|
|
313
|
+
return;
|
|
314
|
+
this.#parked = false;
|
|
315
|
+
this.#upstream?.thaw();
|
|
316
|
+
}
|
|
317
|
+
/** True while the pane is parked (tests and qualification). */
|
|
318
|
+
get parked() {
|
|
319
|
+
return this.#parked;
|
|
320
|
+
}
|
|
270
321
|
/** Kitty graphics side channel: current state now (if any), then every change. */
|
|
271
322
|
subscribeGraphics(listener) {
|
|
272
323
|
const current = this.#interpreter.currentGraphics();
|
|
@@ -301,6 +352,8 @@ export class SessionRuntimeTerminalReplicaOwner {
|
|
|
301
352
|
this.#historyAnchors.invalidate();
|
|
302
353
|
this.#historyTimer?.cancel();
|
|
303
354
|
this.#historyTimer = null;
|
|
355
|
+
this.#parkTimer?.cancel();
|
|
356
|
+
this.#parkTimer = null;
|
|
304
357
|
this.#subscriptionEpoch += 1;
|
|
305
358
|
await this.#interpreter.enqueue({ type: "close", reason });
|
|
306
359
|
await this.#start.catch(() => undefined);
|
|
@@ -335,6 +388,7 @@ export class SessionRuntimeTerminalReplicaOwner {
|
|
|
335
388
|
// Output received during the probe makes its count incomparable with
|
|
336
389
|
// the newer parser state. The dirty flag schedules another check.
|
|
337
390
|
this.#historyDirty ||
|
|
391
|
+
this.#stale ||
|
|
338
392
|
this.#reseed ||
|
|
339
393
|
this.#waitingForGeometryCapture ||
|
|
340
394
|
size === null)
|
|
@@ -398,6 +452,9 @@ export class SessionRuntimeTerminalReplicaOwner {
|
|
|
398
452
|
this.#waitingForGeometryCapture = false;
|
|
399
453
|
const reseed = this.#reseed;
|
|
400
454
|
this.#reseed = null;
|
|
455
|
+
// A completed capture after the park makes the replica current again.
|
|
456
|
+
if (reseed && !this.#parked)
|
|
457
|
+
this.#stale = false;
|
|
401
458
|
const lease = reseed ? this.#qualifyReseed(reseed, event.x, event.y) : null;
|
|
402
459
|
this.#supervise(reseed && lease
|
|
403
460
|
? this.#interpreter.enqueue({
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `tmux-ide servers upgrade` (#766): flags, the `--ssh` hand-off, the detached
|
|
3
|
+
* worker's `--continue`, and the exit code. The steps are in ./run.ts.
|
|
4
|
+
*/
|
|
5
|
+
import { spawnSync } from "node:child_process";
|
|
6
|
+
import { readFileSync } from "node:fs";
|
|
7
|
+
import { dirname, join } from "node:path";
|
|
8
|
+
import { SavedMachineSchema } from "@tmux-ide/contracts";
|
|
9
|
+
import { IdeError } from "../lib/errors.js";
|
|
10
|
+
import { remoteTmuxIdeArgsCommand } from "../lib/remote-tmux-command.js";
|
|
11
|
+
import { createUpgradeIo, parseWorkerState, writeWorkerResult } from "./io.js";
|
|
12
|
+
import { finishUpgrade, retryCommand, upgradeServer, } from "./run.js";
|
|
13
|
+
/** The flags a remote run gets: the same choices, never the local socket defaults. */
|
|
14
|
+
export function forwardedUpgradeArgs(options) {
|
|
15
|
+
const args = [];
|
|
16
|
+
if (options.yes)
|
|
17
|
+
args.push("--yes");
|
|
18
|
+
if (options.endRunningAgents)
|
|
19
|
+
args.push("--end-running-agents");
|
|
20
|
+
if (!options.resumeAgents)
|
|
21
|
+
args.push("--no-resume-agents");
|
|
22
|
+
if (options.dryRun)
|
|
23
|
+
args.push("--dry-run");
|
|
24
|
+
if (options.json)
|
|
25
|
+
args.push("--json");
|
|
26
|
+
if (options.socketPath)
|
|
27
|
+
args.push("--socket-path", options.socketPath);
|
|
28
|
+
if (options.socketName)
|
|
29
|
+
args.push("--socket-name", options.socketName);
|
|
30
|
+
return args;
|
|
31
|
+
}
|
|
32
|
+
const EXIT = {
|
|
33
|
+
"already-full": 0,
|
|
34
|
+
preview: 0,
|
|
35
|
+
declined: 0,
|
|
36
|
+
"handed-off": 0,
|
|
37
|
+
upgraded: 0,
|
|
38
|
+
refused: 1,
|
|
39
|
+
failed: 1,
|
|
40
|
+
};
|
|
41
|
+
function report(result, json) {
|
|
42
|
+
if (json) {
|
|
43
|
+
process.stdout.write(`${JSON.stringify(result)}\n`);
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
// The plan was already printed before the question; print it here only for a preview.
|
|
47
|
+
console.log(result.status === "preview"
|
|
48
|
+
? `${result.message}\n\nDry run: nothing was stopped.`
|
|
49
|
+
: result.message);
|
|
50
|
+
}
|
|
51
|
+
export async function runUpgradeCli(options) {
|
|
52
|
+
if (options.socketPath && options.socketName)
|
|
53
|
+
throw new IdeError("Pass --socket-path or --socket-name, not both.", {
|
|
54
|
+
code: "USAGE",
|
|
55
|
+
exitCode: 2,
|
|
56
|
+
});
|
|
57
|
+
if (options.ssh !== undefined) {
|
|
58
|
+
SavedMachineSchema.shape.sshTarget.parse(options.ssh);
|
|
59
|
+
// The remote runs the same command against its own server, bundle and
|
|
60
|
+
// hostname; its prompt answers here through the terminal.
|
|
61
|
+
const child = spawnSync("ssh", [
|
|
62
|
+
...(options.json ? ["-T"] : ["-t"]),
|
|
63
|
+
"--",
|
|
64
|
+
options.ssh,
|
|
65
|
+
remoteTmuxIdeArgsCommand(["servers", "upgrade", ...forwardedUpgradeArgs(options)]),
|
|
66
|
+
], { stdio: "inherit" });
|
|
67
|
+
if (child.error)
|
|
68
|
+
throw new IdeError("Could not start ssh.", { code: "SSH", exitCode: 1 });
|
|
69
|
+
if (child.status !== 0)
|
|
70
|
+
process.exitCode = child.status ?? 1;
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
if (options.continueFrom !== undefined) {
|
|
74
|
+
const work = parseWorkerState(readFileSync(options.continueFrom, "utf8"));
|
|
75
|
+
const io = createUpgradeIo({
|
|
76
|
+
target: { socketPath: work.server.socketPath },
|
|
77
|
+
cliEntry: options.cliEntry,
|
|
78
|
+
json: false,
|
|
79
|
+
});
|
|
80
|
+
// Nothing the foreground's terminal does may stop the worker mid-restore.
|
|
81
|
+
for (const signal of ["SIGHUP", "SIGINT", "SIGPIPE"])
|
|
82
|
+
process.on(signal, () => { });
|
|
83
|
+
let result;
|
|
84
|
+
try {
|
|
85
|
+
result = await finishUpgrade(io, work);
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
result = {
|
|
89
|
+
status: "failed",
|
|
90
|
+
message: `${error.message} If the sessions are missing, run: ${retryCommand(work.snapshotPath, work.resumeAgents)}`,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
console.log(`${new Date().toISOString()} ${result.status}: ${result.message}`);
|
|
94
|
+
writeWorkerResult(join(dirname(options.continueFrom), "result.json"), result);
|
|
95
|
+
process.exitCode = EXIT[result.status];
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
const io = createUpgradeIo({
|
|
99
|
+
target: { socketPath: options.socketPath, socketName: options.socketName },
|
|
100
|
+
cliEntry: options.cliEntry,
|
|
101
|
+
json: options.json,
|
|
102
|
+
});
|
|
103
|
+
const result = await upgradeServer(io, options);
|
|
104
|
+
report(result, options.json);
|
|
105
|
+
process.exitCode = EXIT[result.status];
|
|
106
|
+
}
|