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,238 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PURE — the plan for moving a tmux server onto tmux-ide's own tmux (#766):
|
|
3
|
+
* snapshot coverage, the agent and program lists, the text shown before the
|
|
4
|
+
* question, and the confirmation rule. The io lives in ./run.ts.
|
|
5
|
+
*/
|
|
6
|
+
import { paneResumeCommand } from "../restore.js";
|
|
7
|
+
import { parseAuthority } from "../tui/detect/classify.js";
|
|
8
|
+
import { isListableSession } from "../tui/team/sessions.js";
|
|
9
|
+
import { UPDATER_SESSION } from "../lib/chrome-front-door.js";
|
|
10
|
+
/** `list-panes -a` lines: `session \t window_index \t pane_index`. */
|
|
11
|
+
export const COVERAGE_PANE_FORMAT = "#{session_name}\t#{window_index}\t#{pane_index}";
|
|
12
|
+
function parseListing(listing) {
|
|
13
|
+
const sessions = new Map();
|
|
14
|
+
const notRestored = new Set();
|
|
15
|
+
for (const line of listing) {
|
|
16
|
+
if (!line)
|
|
17
|
+
continue;
|
|
18
|
+
const [session = "", window = "", pane = ""] = line.split("\t");
|
|
19
|
+
if (!session)
|
|
20
|
+
continue;
|
|
21
|
+
if (!isListableSession(session)) {
|
|
22
|
+
if (session !== UPDATER_SESSION)
|
|
23
|
+
notRestored.add(session);
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
let windows = sessions.get(session);
|
|
27
|
+
if (!windows)
|
|
28
|
+
sessions.set(session, (windows = new Map()));
|
|
29
|
+
const panes = windows.get(Number(window)) ?? [];
|
|
30
|
+
panes.push(Number(pane));
|
|
31
|
+
windows.set(Number(window), panes);
|
|
32
|
+
}
|
|
33
|
+
return { sessions, notRestored: [...notRestored].sort() };
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Does the snapshot hold every listable session, window and pane the live
|
|
37
|
+
* server lists, with a layout per window and a folder per pane? Nothing may be
|
|
38
|
+
* killed unless this is ok against a listing taken after the file was read back.
|
|
39
|
+
*/
|
|
40
|
+
export function coverage(snapshot, listing) {
|
|
41
|
+
const live = parseListing(listing);
|
|
42
|
+
const problems = [];
|
|
43
|
+
if (live.sessions.size === 0 && live.notRestored.length === 0)
|
|
44
|
+
problems.push("the server lists no sessions");
|
|
45
|
+
const saved = new Map(snapshot.sessions.map((session) => [session.name, session]));
|
|
46
|
+
for (const [name, windows] of live.sessions) {
|
|
47
|
+
const session = saved.get(name);
|
|
48
|
+
if (!session) {
|
|
49
|
+
problems.push(`session ${name} is not in the snapshot`);
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
const savedWindows = new Map(session.windows.map((window) => [window.index, window]));
|
|
53
|
+
for (const [index, panes] of windows) {
|
|
54
|
+
const window = savedWindows.get(index);
|
|
55
|
+
if (!window) {
|
|
56
|
+
problems.push(`window ${name}:${index} is not in the snapshot`);
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
if (window.panes.length !== panes.length)
|
|
60
|
+
problems.push(`window ${name}:${index} has ${panes.length} panes, the snapshot has ${window.panes.length}`);
|
|
61
|
+
}
|
|
62
|
+
for (const window of session.windows)
|
|
63
|
+
if (!windows.has(window.index))
|
|
64
|
+
problems.push(`window ${name}:${window.index} closed after the snapshot`);
|
|
65
|
+
}
|
|
66
|
+
for (const session of snapshot.sessions) {
|
|
67
|
+
if (!live.sessions.has(session.name)) {
|
|
68
|
+
problems.push(`session ${session.name} ended after the snapshot`);
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
for (const window of session.windows) {
|
|
72
|
+
if (!window.layout)
|
|
73
|
+
problems.push(`window ${session.name}:${window.index} has no layout in the snapshot`);
|
|
74
|
+
for (const pane of window.panes)
|
|
75
|
+
if (!pane.cwd)
|
|
76
|
+
problems.push(`pane ${session.name}:${window.index}.${pane.index} has no folder in the snapshot`);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return { ok: problems.length === 0, problems, notRestored: live.notRestored };
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* After restore: the same sessions, with the same pane count per window in
|
|
83
|
+
* order. Window indexes may differ (base-index), so they are not compared.
|
|
84
|
+
*/
|
|
85
|
+
export function sameShape(snapshot, listing) {
|
|
86
|
+
const live = parseListing(listing).sessions;
|
|
87
|
+
const problems = [];
|
|
88
|
+
for (const session of snapshot.sessions) {
|
|
89
|
+
const windows = live.get(session.name);
|
|
90
|
+
if (!windows) {
|
|
91
|
+
problems.push(`session ${session.name} did not come back`);
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
const got = [...windows.entries()].sort(([a], [b]) => a - b).map(([, panes]) => panes.length);
|
|
95
|
+
const want = session.windows.map((window) => window.panes.length);
|
|
96
|
+
if (got.join("+") !== want.join("+"))
|
|
97
|
+
problems.push(`session ${session.name} came back with ${got.join("+")} panes, the snapshot has ${want.join("+")}`);
|
|
98
|
+
}
|
|
99
|
+
return problems;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* An `idle` or `done` report older than this reads as `unknown`: the agent may
|
|
103
|
+
* have started a turn its hooks never reported. (`working` and `blocked` go
|
|
104
|
+
* stale after 10 minutes, in classify.ts.)
|
|
105
|
+
*/
|
|
106
|
+
export const IDLE_STALE_SECONDS = 60 * 60;
|
|
107
|
+
/** PURE: the agent's turn state from its `@agent_state` report, conservatively. */
|
|
108
|
+
export function agentTurnState(raw, nowSec) {
|
|
109
|
+
const state = parseAuthority(raw ?? undefined, nowSec);
|
|
110
|
+
if (!state)
|
|
111
|
+
return "unknown";
|
|
112
|
+
if (state === "idle" || state === "done") {
|
|
113
|
+
const epoch = Number(raw.slice(raw.lastIndexOf(":") + 1));
|
|
114
|
+
if (nowSec - epoch > IDLE_STALE_SECONDS)
|
|
115
|
+
return "unknown";
|
|
116
|
+
}
|
|
117
|
+
return state;
|
|
118
|
+
}
|
|
119
|
+
export function buildUpgradePlan(input) {
|
|
120
|
+
const agents = [];
|
|
121
|
+
const programs = [];
|
|
122
|
+
let paneCount = 0;
|
|
123
|
+
const sessions = input.snapshot.sessions.map((session) => {
|
|
124
|
+
let panes = 0;
|
|
125
|
+
for (const window of session.windows)
|
|
126
|
+
for (const pane of window.panes) {
|
|
127
|
+
panes++;
|
|
128
|
+
const target = `${session.name}:${window.index}.${pane.index}`;
|
|
129
|
+
if (pane.agent) {
|
|
130
|
+
agents.push({
|
|
131
|
+
target,
|
|
132
|
+
agent: pane.agent,
|
|
133
|
+
cwd: pane.cwd,
|
|
134
|
+
state: agentTurnState(pane.agentState, input.nowSec),
|
|
135
|
+
resumes: paneResumeCommand(pane, { resumeAgents: input.resumeAgents }) !== null,
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
else if (pane.command && target !== input.selfPane)
|
|
139
|
+
programs.push({ target, command: pane.command });
|
|
140
|
+
}
|
|
141
|
+
paneCount += panes;
|
|
142
|
+
return { name: session.name, windows: session.windows.length, panes };
|
|
143
|
+
});
|
|
144
|
+
return {
|
|
145
|
+
server: input.server,
|
|
146
|
+
bundled: input.bundled,
|
|
147
|
+
snapshotPath: input.snapshotPath,
|
|
148
|
+
savedAt: input.snapshot.savedAt,
|
|
149
|
+
sessions,
|
|
150
|
+
paneCount,
|
|
151
|
+
agents,
|
|
152
|
+
midTurn: agents.filter((agent) => agent.target !== input.selfPane && !["idle", "done"].includes(agent.state)).length,
|
|
153
|
+
programs,
|
|
154
|
+
ending: (input.ending ?? []).filter((pane) => pane.agent || pane.command),
|
|
155
|
+
notRestored: input.notRestored,
|
|
156
|
+
resumeAgents: input.resumeAgents,
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
const plural = (count, word) => `${count} ${word}${count === 1 ? "" : "s"}`;
|
|
160
|
+
const FEATURE_NAMES = {
|
|
161
|
+
full: "tmux-ide's tmux",
|
|
162
|
+
stock: "stock tmux",
|
|
163
|
+
older: "an older tmux-ide tmux",
|
|
164
|
+
partial: "a tmux with only some tmux-ide commands",
|
|
165
|
+
unknown: "tmux",
|
|
166
|
+
};
|
|
167
|
+
/** The text shown before the question. Its first line names the machine and the server. */
|
|
168
|
+
export function renderPlan(plan) {
|
|
169
|
+
const { server } = plan;
|
|
170
|
+
const lines = [
|
|
171
|
+
`This ends ${plural(plan.sessions.length, "session")} and ${plural(plan.agents.length, "agent")} on ${server.host} (${server.socketPath}).`,
|
|
172
|
+
`The server runs ${FEATURE_NAMES[server.features]} ${server.version}${server.executable ? ` (${server.executable})` : ""}.`,
|
|
173
|
+
`tmux-ide's own tmux (${plan.bundled.version}) has every feature. Moving restarts the server.`,
|
|
174
|
+
"",
|
|
175
|
+
"These sessions close and come back:",
|
|
176
|
+
...plan.sessions.map((session) => ` ${session.name} ${plural(session.windows, "window")}, ${plural(session.panes, "pane")}`),
|
|
177
|
+
"",
|
|
178
|
+
"Comes back: windows, split layouts, each pane's folder, pane titles.",
|
|
179
|
+
"Does not come back: running programs, scrollback, shell variables,",
|
|
180
|
+
"aliases you set by hand, background jobs. Save open files first.",
|
|
181
|
+
];
|
|
182
|
+
if (plan.programs.length) {
|
|
183
|
+
lines.push("", "These programs stop (tmux-ide can't tell whether one is an agent):");
|
|
184
|
+
for (const program of plan.programs)
|
|
185
|
+
lines.push(` ${program.target} ${program.command}`);
|
|
186
|
+
}
|
|
187
|
+
if (plan.agents.length) {
|
|
188
|
+
lines.push("", `Agents (${plan.agents.length}):`);
|
|
189
|
+
for (const agent of plan.agents) {
|
|
190
|
+
const outcome = agent.resumes
|
|
191
|
+
? "resumes its conversation"
|
|
192
|
+
: plan.resumeAgents
|
|
193
|
+
? "ends; no saved conversation id"
|
|
194
|
+
: "ends (--no-resume-agents)";
|
|
195
|
+
lines.push(` ${agent.target} ${agent.agent} ${agent.state} ${agent.cwd} ${outcome}`);
|
|
196
|
+
}
|
|
197
|
+
if (plan.midTurn)
|
|
198
|
+
lines.push(plan.midTurn === 1
|
|
199
|
+
? "1 agent is mid-turn. Its current turn will be lost."
|
|
200
|
+
: `${plan.midTurn} agents may be mid-turn. Their current turns will be lost.`);
|
|
201
|
+
}
|
|
202
|
+
if (plan.notRestored.length)
|
|
203
|
+
lines.push("", `Also ends, not restored: ${plan.notRestored.join(", ")}`);
|
|
204
|
+
for (const pane of plan.ending)
|
|
205
|
+
lines.push(` ${pane.target} ${pane.agent ?? pane.command} ${pane.cwd} ends and does not come back`);
|
|
206
|
+
lines.push("", `Snapshot saved: ${plan.snapshotPath}`);
|
|
207
|
+
return lines.join("\n");
|
|
208
|
+
}
|
|
209
|
+
export function atRisk(plan) {
|
|
210
|
+
return { midTurn: plan.midTurn, programs: plan.programs.length, ending: plan.ending.length };
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* The default answer is always No. `--yes` alone never ends an agent that may
|
|
214
|
+
* be mid-turn, a program that may be an agent, or anything that won't come back.
|
|
215
|
+
*/
|
|
216
|
+
export function confirmation(input) {
|
|
217
|
+
if (input.dryRun || (input.json && !input.yes))
|
|
218
|
+
return { kind: "preview" };
|
|
219
|
+
if (!input.yes)
|
|
220
|
+
return { kind: "ask" };
|
|
221
|
+
const { midTurn, programs, ending } = input.risk;
|
|
222
|
+
if ((midTurn > 0 || programs > 0 || ending > 0) && !input.endRunningAgents) {
|
|
223
|
+
const parts = [
|
|
224
|
+
...(midTurn ? [`${plural(midTurn, "agent")} may be mid-turn`] : []),
|
|
225
|
+
...(programs
|
|
226
|
+
? [`${plural(programs, "program")} may be ${programs === 1 ? "an agent" : "agents"}`]
|
|
227
|
+
: []),
|
|
228
|
+
...(ending
|
|
229
|
+
? [`${plural(ending, "pane")} in sessions that are not restored run something`]
|
|
230
|
+
: []),
|
|
231
|
+
];
|
|
232
|
+
return {
|
|
233
|
+
kind: "refuse",
|
|
234
|
+
reason: `${parts.join("; ")}. Pass --yes --end-running-agents to end them, or wait until they are idle. Nothing was stopped.`,
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
return { kind: "proceed" };
|
|
238
|
+
}
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The steps of `tmux-ide servers upgrade` (#766), over an injectable io so the
|
|
3
|
+
* order and every refusal are unit-tested. Nothing is killed until a snapshot
|
|
4
|
+
* written to its own file, read back and parsed, covers a fresh listing of the
|
|
5
|
+
* server, and the user (or `--yes`, with `--end-running-agents` when an agent
|
|
6
|
+
* is mid-turn) agreed. Real io: ./io.ts.
|
|
7
|
+
*
|
|
8
|
+
* The kill and the restore always run in a detached worker, so the step that
|
|
9
|
+
* ends the server never depends on the invoking terminal, ssh connection or
|
|
10
|
+
* shell staying alive. The foreground waits for the worker's result file.
|
|
11
|
+
*/
|
|
12
|
+
import { IdeError } from "../lib/errors.js";
|
|
13
|
+
import { atRisk, buildUpgradePlan, confirmation, coverage, renderPlan, sameShape, } from "./plan.js";
|
|
14
|
+
/** The line that rebuilds the sessions by hand from a pinned snapshot. */
|
|
15
|
+
export const retryCommand = (snapshotPath, resumeAgents) => `tmux-ide restore --from ${snapshotPath}${resumeAgents ? " --resume-agents" : ""}`;
|
|
16
|
+
const nothingChanged = (message, code) => new IdeError(`${message} Nothing was stopped.`, { code, exitCode: 1 });
|
|
17
|
+
/** Snapshot, write, read back, and prove coverage against a fresh listing. */
|
|
18
|
+
function pinnedSnapshot(io, client, socket) {
|
|
19
|
+
const snapshot = io.collect(client, socket);
|
|
20
|
+
let path;
|
|
21
|
+
try {
|
|
22
|
+
path = io.saveSnapshot(snapshot);
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
throw nothingChanged(`The snapshot could not be written: ${error.message}.`, "SNAPSHOT_WRITE");
|
|
26
|
+
}
|
|
27
|
+
const saved = io.loadSnapshot(path);
|
|
28
|
+
if (!saved)
|
|
29
|
+
throw nothingChanged(`The snapshot at ${path} could not be read back.`, "SNAPSHOT_READ");
|
|
30
|
+
const covered = coverage(saved, io.listPanes(client, socket));
|
|
31
|
+
if (!covered.ok)
|
|
32
|
+
throw nothingChanged(`The snapshot does not cover the server: ${covered.problems.join("; ")}.`, "SNAPSHOT_COVERAGE");
|
|
33
|
+
return { snapshot: saved, path, notRestored: covered.notRestored };
|
|
34
|
+
}
|
|
35
|
+
export async function upgradeServer(io, options) {
|
|
36
|
+
const configured = io.configuredBinary();
|
|
37
|
+
const bundled = io.bundled();
|
|
38
|
+
if (!bundled)
|
|
39
|
+
throw nothingChanged("No bundled tmux found for this machine. Reinstall tmux-ide.", "NO_BUNDLED_TMUX");
|
|
40
|
+
if (configured && configured !== bundled.executable)
|
|
41
|
+
throw nothingChanged(`TMUX_IDE_TMUX_BIN names ${configured}, not tmux-ide's own tmux. Unset it first.`, "TMUX_BIN_OVERRIDE");
|
|
42
|
+
const client = bundled.executable;
|
|
43
|
+
const facts = io.identify(client);
|
|
44
|
+
if (!facts)
|
|
45
|
+
throw new IdeError("No tmux server is running here.", { code: "NO_SERVER", exitCode: 1 });
|
|
46
|
+
const server = {
|
|
47
|
+
...facts,
|
|
48
|
+
host: io.host(),
|
|
49
|
+
features: io.features(client, facts.socketPath),
|
|
50
|
+
};
|
|
51
|
+
if (server.features === "full")
|
|
52
|
+
return {
|
|
53
|
+
status: "already-full",
|
|
54
|
+
message: `${server.host} (${server.socketPath}) already runs tmux-ide's own tmux.`,
|
|
55
|
+
};
|
|
56
|
+
const scratch = io.scratchFeatures(client);
|
|
57
|
+
if (scratch !== "full")
|
|
58
|
+
throw nothingChanged(`A scratch server from the bundled tmux reports "${scratch}", not full features.`, "BUNDLE_NOT_FULL");
|
|
59
|
+
for (let attempt = 0;; attempt++) {
|
|
60
|
+
const pinned = pinnedSnapshot(io, client, server.socketPath);
|
|
61
|
+
const plan = buildUpgradePlan({
|
|
62
|
+
server,
|
|
63
|
+
bundled,
|
|
64
|
+
snapshot: pinned.snapshot,
|
|
65
|
+
snapshotPath: pinned.path,
|
|
66
|
+
notRestored: pinned.notRestored,
|
|
67
|
+
ending: io.endingPanes(client, server.socketPath),
|
|
68
|
+
selfPane: io.ownPane(client, server.socketPath),
|
|
69
|
+
resumeAgents: options.resumeAgents,
|
|
70
|
+
nowSec: io.nowSec(),
|
|
71
|
+
});
|
|
72
|
+
const decision = confirmation({ ...options, risk: atRisk(plan) });
|
|
73
|
+
if (decision.kind === "preview")
|
|
74
|
+
return { status: "preview", message: renderPlan(plan), plan };
|
|
75
|
+
if (decision.kind === "refuse") {
|
|
76
|
+
if (!options.json)
|
|
77
|
+
io.print(renderPlan(plan));
|
|
78
|
+
return { status: "refused", message: decision.reason, plan };
|
|
79
|
+
}
|
|
80
|
+
if (decision.kind === "ask") {
|
|
81
|
+
io.print(renderPlan(plan));
|
|
82
|
+
if (!(await io.confirm("Restart the server and restore? [y/N] ")))
|
|
83
|
+
return { status: "declined", message: "Nothing was stopped.", plan };
|
|
84
|
+
}
|
|
85
|
+
// The server may have changed while the question was open.
|
|
86
|
+
if (!coverage(pinned.snapshot, io.listPanes(client, server.socketPath)).ok) {
|
|
87
|
+
if (attempt >= 2)
|
|
88
|
+
throw nothingChanged("The server keeps changing; try again in a moment.", "SERVER_CHANGING");
|
|
89
|
+
io.print("The server changed since the snapshot. Taking a new one.");
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
const work = {
|
|
93
|
+
server,
|
|
94
|
+
client,
|
|
95
|
+
snapshotPath: pinned.path,
|
|
96
|
+
resumeAgents: options.resumeAgents,
|
|
97
|
+
};
|
|
98
|
+
// Before anything is ended, in every mode: where the snapshot is and how to use it.
|
|
99
|
+
io.print(`Snapshot saved: ${pinned.path}\nIf the sessions do not come back, run: ${retryCommand(pinned.path, options.resumeAgents)}`);
|
|
100
|
+
const inside = io.insideTarget(client, server.socketPath);
|
|
101
|
+
const worker = io.startWorker(work);
|
|
102
|
+
io.print(`The restart runs in the background. Log: ${worker.log}`);
|
|
103
|
+
if (inside)
|
|
104
|
+
return {
|
|
105
|
+
status: "handed-off",
|
|
106
|
+
message: `This terminal runs inside that server and closes in a moment. Reopen tmux-ide or run \`tmux attach\` in a few seconds. Log: ${worker.log}`,
|
|
107
|
+
plan,
|
|
108
|
+
};
|
|
109
|
+
const result = await io.waitForWorker(worker);
|
|
110
|
+
if (!result)
|
|
111
|
+
return {
|
|
112
|
+
status: "failed",
|
|
113
|
+
message: `The background restart did not report back. Read ${worker.log}. If the sessions are missing, run: ${retryCommand(pinned.path, options.resumeAgents)}`,
|
|
114
|
+
plan,
|
|
115
|
+
};
|
|
116
|
+
return { ...result, plan };
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
/** The detached worker's entry: confirm it is still the same server, then finish. */
|
|
120
|
+
export async function finishUpgrade(io, work) {
|
|
121
|
+
const facts = io.identify(work.client);
|
|
122
|
+
if (!facts || facts.pid !== work.server.pid || facts.startTime !== work.server.startTime)
|
|
123
|
+
return {
|
|
124
|
+
status: "failed",
|
|
125
|
+
message: "The server changed since the prompt. Nothing was stopped.",
|
|
126
|
+
};
|
|
127
|
+
const snapshot = io.loadSnapshot(work.snapshotPath);
|
|
128
|
+
if (!snapshot || !coverage(snapshot, io.listPanes(work.client, work.server.socketPath)).ok)
|
|
129
|
+
return {
|
|
130
|
+
status: "failed",
|
|
131
|
+
message: "The snapshot no longer covers the server. Nothing was stopped.",
|
|
132
|
+
};
|
|
133
|
+
return stopAndRestore(io, work, snapshot);
|
|
134
|
+
}
|
|
135
|
+
async function stopAndRestore(io, work, snapshot) {
|
|
136
|
+
const { server, client, snapshotPath, resumeAgents } = work;
|
|
137
|
+
const retry = `Snapshot: ${snapshotPath}. Retry with: ${retryCommand(snapshotPath, resumeAgents)}`;
|
|
138
|
+
try {
|
|
139
|
+
io.kill(client, server);
|
|
140
|
+
}
|
|
141
|
+
catch (error) {
|
|
142
|
+
return {
|
|
143
|
+
status: "failed",
|
|
144
|
+
message: `The kill failed (${error.message}); the server is still running. ${retry}`,
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
if (!io.serverGone(client, server.socketPath)) {
|
|
148
|
+
// Something answers on the socket. The same server: it did not end. Another
|
|
149
|
+
// server (someone started one in the gap): rebuild into it; live names are skipped.
|
|
150
|
+
const now = io.identify(client);
|
|
151
|
+
if (!now || (now.pid === server.pid && now.startTime === server.startTime))
|
|
152
|
+
return {
|
|
153
|
+
status: "failed",
|
|
154
|
+
message: `The server is still running after the kill. ${retry}`,
|
|
155
|
+
};
|
|
156
|
+
io.print(`Another server (pid ${now.pid}) now answers on the socket; restoring into it.`);
|
|
157
|
+
}
|
|
158
|
+
const input = { socket: server.socketPath, snapshotPath, resumeAgents };
|
|
159
|
+
let outcome;
|
|
160
|
+
try {
|
|
161
|
+
outcome = await io.restore({ ...input, client });
|
|
162
|
+
}
|
|
163
|
+
catch (error) {
|
|
164
|
+
if (!server.executable)
|
|
165
|
+
return {
|
|
166
|
+
status: "failed",
|
|
167
|
+
message: `tmux-ide's tmux could not start a server (${error.message}). ${retry}`,
|
|
168
|
+
};
|
|
169
|
+
try {
|
|
170
|
+
outcome = await io.restore({ ...input, client: server.executable });
|
|
171
|
+
}
|
|
172
|
+
catch (fallback) {
|
|
173
|
+
return {
|
|
174
|
+
status: "failed",
|
|
175
|
+
message: `Neither tmux could start a server (${fallback.message}). ${retry}`,
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
return {
|
|
179
|
+
status: "failed",
|
|
180
|
+
message: `tmux-ide's tmux could not start a server (${error.message}); your sessions were restored on ${server.executable} instead. ${retry}`,
|
|
181
|
+
...outcome,
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
const features = io.features(client, server.socketPath);
|
|
185
|
+
const shape = sameShape(snapshot, io.listPanes(client, server.socketPath));
|
|
186
|
+
const problems = [
|
|
187
|
+
...outcome.failed.map((name) => `session ${name} failed to rebuild`),
|
|
188
|
+
...shape.filter((line) => !outcome.failed.some((name) => line.includes(` ${name} `))),
|
|
189
|
+
...(features === "full" ? [] : [`the new server reports "${features}", not full features`]),
|
|
190
|
+
];
|
|
191
|
+
if (problems.length)
|
|
192
|
+
return { status: "failed", message: `${problems.join("; ")}. ${retry}`, ...outcome };
|
|
193
|
+
io.print(`Restored ${outcome.restored.length} sessions. tmux features: bundled tmux: full features.`);
|
|
194
|
+
return {
|
|
195
|
+
status: "upgraded",
|
|
196
|
+
message: `${server.host} (${server.socketPath}) now runs tmux-ide's own tmux.`,
|
|
197
|
+
...outcome,
|
|
198
|
+
};
|
|
199
|
+
}
|
|
@@ -84,7 +84,7 @@ function isBareShell(cmd) {
|
|
|
84
84
|
* BOTH the agent and the restore command; a bare shell records neither; any
|
|
85
85
|
* other foreground process records its `pane_current_command` as the command.
|
|
86
86
|
*/
|
|
87
|
-
function resolvePaneCommand(cmd, pid, hint, table) {
|
|
87
|
+
export function resolvePaneCommand(cmd, pid, hint, table) {
|
|
88
88
|
const { manifest } = resolveAgentCommand(cmd, pid, table, { hint: hint || undefined });
|
|
89
89
|
if (manifest && manifest.id !== "shell") {
|
|
90
90
|
return { agent: manifest.id, command: manifest.id };
|
|
@@ -239,9 +239,8 @@ export function writeSnapshot(snapshot) {
|
|
|
239
239
|
// a failed write just means a staler snapshot — never fatal
|
|
240
240
|
}
|
|
241
241
|
}
|
|
242
|
-
/** Read + validate
|
|
243
|
-
export function readSnapshot() {
|
|
244
|
-
const path = snapshotPath();
|
|
242
|
+
/** Read + validate a snapshot file (default: the updater's). Returns null when missing or malformed. */
|
|
243
|
+
export function readSnapshot(path = snapshotPath()) {
|
|
245
244
|
try {
|
|
246
245
|
if (!existsSync(path))
|
|
247
246
|
return null;
|
|
@@ -3,6 +3,8 @@ export function createApplicationHomeAgentNavigator(options) {
|
|
|
3
3
|
let navigationToken = 0;
|
|
4
4
|
let disposed = false;
|
|
5
5
|
let admissionController = null;
|
|
6
|
+
/** The token whose wait note is on screen; cleared with the wait (#764). */
|
|
7
|
+
let waitingNote = null;
|
|
6
8
|
const active = (token) => !disposed && token === navigationToken;
|
|
7
9
|
const failure = (token, reason, note) => {
|
|
8
10
|
if (!active(token))
|
|
@@ -10,7 +12,10 @@ export function createApplicationHomeAgentNavigator(options) {
|
|
|
10
12
|
options.setNote(note);
|
|
11
13
|
return { opened: false, failure: reason };
|
|
12
14
|
};
|
|
13
|
-
const
|
|
15
|
+
const listed = (current, target) => !!target.paneId &&
|
|
16
|
+
!!current?.agents.some((agent) => agent.id === target.agentId && agent.paneId === target.paneId);
|
|
17
|
+
/** Every admission check; null admits. Notes are set only for a refusal. */
|
|
18
|
+
const refusal = (token, target, expectedGeneration) => {
|
|
14
19
|
if (!active(token))
|
|
15
20
|
return { opened: false, failure: "superseded" };
|
|
16
21
|
if (!options.isCurrentTarget(target))
|
|
@@ -23,9 +28,14 @@ export function createApplicationHomeAgentNavigator(options) {
|
|
|
23
28
|
current.liveSessionId !== target.liveSessionId) {
|
|
24
29
|
return failure(token, "generation-changed", "The session changed while opening that agent. Return Home and retry.");
|
|
25
30
|
}
|
|
26
|
-
if (!target
|
|
27
|
-
!current.agents.some((agent) => agent.id === target.agentId && agent.paneId === target.paneId))
|
|
31
|
+
if (!listed(current, target))
|
|
28
32
|
return failure(token, "pane-removed", "That exact agent terminal is no longer available. Return Home and select another agent.");
|
|
33
|
+
return null;
|
|
34
|
+
};
|
|
35
|
+
const admit = (token, target, source, expectedGeneration) => {
|
|
36
|
+
const refused = refusal(token, target, expectedGeneration);
|
|
37
|
+
if (refused)
|
|
38
|
+
return refused;
|
|
29
39
|
// Synchronous on the warm path: selection precedes surface visibility and
|
|
30
40
|
// the next input event. The existing terminal owner remains the only input path.
|
|
31
41
|
options.selectPane(target.paneId, source);
|
|
@@ -33,6 +43,40 @@ export function createApplicationHomeAgentNavigator(options) {
|
|
|
33
43
|
options.setNote(null);
|
|
34
44
|
return { opened: true };
|
|
35
45
|
};
|
|
46
|
+
/**
|
|
47
|
+
* The warm path when Home lists an agent the attached session doesn't yet
|
|
48
|
+
* (#764): register the selection now, wait (bounded) for the session to list
|
|
49
|
+
* exactly this agent on this pane, then run every admission check again.
|
|
50
|
+
* The selection reaches the runtime only if this admits. The root ignores
|
|
51
|
+
* keys and paste while an agent is opening, so input typed during the wait
|
|
52
|
+
* is dropped; the note says why nothing happens yet.
|
|
53
|
+
*/
|
|
54
|
+
const admitWhenListed = async (token, target, source, generationKey, waitForAgent, signal) => {
|
|
55
|
+
let settle;
|
|
56
|
+
const admission = new Promise((resolve) => {
|
|
57
|
+
settle = resolve;
|
|
58
|
+
});
|
|
59
|
+
options.selectPane(target.paneId, source, admission);
|
|
60
|
+
// The cold path's "Opening agent in …" note, for the warm wait.
|
|
61
|
+
options.setNote(`Waiting for agent in ${target.sessionName}…`);
|
|
62
|
+
waitingNote = token;
|
|
63
|
+
try {
|
|
64
|
+
await waitForAgent(generationKey, () => listed(options.currentGeneration(), target), signal);
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
// A failed wait is a refusal below, never an admission.
|
|
68
|
+
}
|
|
69
|
+
if (waitingNote === token)
|
|
70
|
+
waitingNote = null;
|
|
71
|
+
// A refusal replaces the note; an admission clears it below.
|
|
72
|
+
const refused = refusal(token, target, generationKey);
|
|
73
|
+
settle(refused === null);
|
|
74
|
+
if (refused)
|
|
75
|
+
return refused;
|
|
76
|
+
options.showTerminals(source);
|
|
77
|
+
options.setNote(null);
|
|
78
|
+
return { opened: true };
|
|
79
|
+
};
|
|
36
80
|
return {
|
|
37
81
|
async open(target, source = "mouse") {
|
|
38
82
|
if (disposed)
|
|
@@ -40,14 +84,26 @@ export function createApplicationHomeAgentNavigator(options) {
|
|
|
40
84
|
admissionController?.abort();
|
|
41
85
|
const controller = new AbortController();
|
|
42
86
|
admissionController = controller;
|
|
87
|
+
// This navigation sets its own note.
|
|
88
|
+
waitingNote = null;
|
|
43
89
|
const token = ++navigationToken;
|
|
44
90
|
try {
|
|
45
91
|
if (!target.paneId)
|
|
46
92
|
return failure(token, "unavailable", "This agent has no available terminal to open.");
|
|
47
93
|
if (!options.isCurrentTarget(target))
|
|
48
94
|
return failure(token, "stale-target", "That agent changed or disappeared. Select it again on Home.");
|
|
49
|
-
|
|
95
|
+
const attached = options.currentGeneration();
|
|
96
|
+
if (attached?.sessionName === target.sessionName) {
|
|
97
|
+
if (options.waitForAgent &&
|
|
98
|
+
attached.daemonInstanceId === target.daemonInstanceId &&
|
|
99
|
+
attached.liveSessionId === target.liveSessionId &&
|
|
100
|
+
!listed(attached, target)) {
|
|
101
|
+
// The same session, just not listing this agent yet: possibly a
|
|
102
|
+
// moment behind Home. Refused as before if the wait ends without it.
|
|
103
|
+
return admitWhenListed(token, target, source, attached.generationKey, options.waitForAgent, controller.signal);
|
|
104
|
+
}
|
|
50
105
|
return admit(token, target, source);
|
|
106
|
+
}
|
|
51
107
|
options.setNote(`Opening agent in ${target.sessionName}…`);
|
|
52
108
|
// Never briefly focus the first pane of the newly opened session.
|
|
53
109
|
const opened = await options.startGeneration(target.sessionName, false, source, false, () => active(token));
|
|
@@ -76,6 +132,10 @@ export function createApplicationHomeAgentNavigator(options) {
|
|
|
76
132
|
cancel() {
|
|
77
133
|
navigationToken += 1;
|
|
78
134
|
admissionController?.abort();
|
|
135
|
+
if (waitingNote !== null) {
|
|
136
|
+
waitingNote = null;
|
|
137
|
+
options.setNote(null);
|
|
138
|
+
}
|
|
79
139
|
},
|
|
80
140
|
dispose() {
|
|
81
141
|
disposed = true;
|
|
@@ -10,11 +10,24 @@ import { createApplicationPaneRenameOwner } from "./application-pane-rename-owne
|
|
|
10
10
|
import { applicationPaletteCommands, applicationPaletteCommandSource, } from "./application-palette-input.js";
|
|
11
11
|
/** Observe the existing client, never open a second shell or poll for readiness. */
|
|
12
12
|
export function waitForHomeAgentSemantic(generation, expectedKey, signal) {
|
|
13
|
+
const client = generation()?.client;
|
|
14
|
+
return waitForHomeAgentGeneration(generation, expectedKey, () => Boolean(client?.getSnapshot().semantic), signal);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Waits, bounded, until the attached generation `expectedKey` lists an agent
|
|
18
|
+
* (`listed`), or until the generation changes, the bound passes or `signal`
|
|
19
|
+
* aborts (#764: Home can list an agent before the attached session does).
|
|
20
|
+
*/
|
|
21
|
+
export function waitForHomeAgentListed(generation, expectedKey, listed, signal) {
|
|
22
|
+
return waitForHomeAgentGeneration(generation, expectedKey, listed, signal);
|
|
23
|
+
}
|
|
24
|
+
/** The bound both waits share: the cold path's own 5 s. */
|
|
25
|
+
export const HOME_AGENT_WAIT_MS = 5_000;
|
|
26
|
+
function waitForHomeAgentGeneration(generation, expectedKey, satisfied, signal) {
|
|
13
27
|
const client = generation()?.client;
|
|
14
28
|
if (!client || signal.aborted)
|
|
15
29
|
return Promise.resolve(false);
|
|
16
|
-
const ready = () => applicationGenerationNavigationKey(generation()) !== expectedKey ||
|
|
17
|
-
Boolean(client.getSnapshot().semantic);
|
|
30
|
+
const ready = () => applicationGenerationNavigationKey(generation()) !== expectedKey || satisfied();
|
|
18
31
|
// A changed generation is settled, not admitted: the navigator revalidates it.
|
|
19
32
|
if (ready())
|
|
20
33
|
return Promise.resolve(true);
|
|
@@ -36,7 +49,7 @@ export function waitForHomeAgentSemantic(generation, expectedKey, signal) {
|
|
|
36
49
|
if (ready())
|
|
37
50
|
finish(true);
|
|
38
51
|
};
|
|
39
|
-
const timeout = setTimeout(() => finish(false),
|
|
52
|
+
const timeout = setTimeout(() => finish(false), HOME_AGENT_WAIT_MS);
|
|
40
53
|
signal.addEventListener("abort", abort, { once: true });
|
|
41
54
|
// subscribe may synchronously deliver its current projection.
|
|
42
55
|
for (const scope of ["semantic", "lifecycle"]) {
|
|
@@ -54,6 +67,17 @@ export function waitForHomeAgentSemantic(generation, expectedKey, signal) {
|
|
|
54
67
|
check();
|
|
55
68
|
});
|
|
56
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* While an agent opens, it owns the keyboard: other keys are ignored and Esc
|
|
72
|
+
* cancels the open (#764: the warm wait can last 5 s). True when it owns `name`.
|
|
73
|
+
*/
|
|
74
|
+
export function agentOpeningOwnsKey(name, opener) {
|
|
75
|
+
if (!opener.opening())
|
|
76
|
+
return false;
|
|
77
|
+
if (name === "escape")
|
|
78
|
+
opener.cancel();
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
57
81
|
/** Resident feature composition: observation, selection, and navigation have separate owners. */
|
|
58
82
|
export function createApplicationHomeAgentsOwner(options) {
|
|
59
83
|
const observer = options.observer ?? createApplicationHomeAgentObserver();
|
|
@@ -86,10 +110,11 @@ export function createApplicationHomeAgentsOwner(options) {
|
|
|
86
110
|
};
|
|
87
111
|
},
|
|
88
112
|
waitForGeneration: (key, signal) => waitForHomeAgentSemantic(options.generation, key, signal),
|
|
113
|
+
waitForAgent: (key, listed, signal) => waitForHomeAgentListed(options.generation, key, listed, signal),
|
|
89
114
|
startGeneration: options.startGeneration,
|
|
90
115
|
// The existing pane input router is source-neutral. Session/surface intents
|
|
91
116
|
// above retain keyboard vs pointer provenance without inventing a second router.
|
|
92
|
-
selectPane: (paneId) => options.selectPane(paneId),
|
|
117
|
+
selectPane: (paneId, _source, admission) => admission ? options.selectPane(paneId, admission) : options.selectPane(paneId),
|
|
93
118
|
showTerminals: options.showTerminals,
|
|
94
119
|
setNote: options.setNote,
|
|
95
120
|
});
|
|
@@ -149,7 +174,12 @@ export function createApplicationHomeAgentsOwner(options) {
|
|
|
149
174
|
observer.dispose();
|
|
150
175
|
selection.dispose();
|
|
151
176
|
});
|
|
152
|
-
return {
|
|
177
|
+
return {
|
|
178
|
+
presentation,
|
|
179
|
+
opening,
|
|
180
|
+
cancel,
|
|
181
|
+
ownsKey: (name) => agentOpeningOwnsKey(name, { opening, cancel }),
|
|
182
|
+
};
|
|
153
183
|
}
|
|
154
184
|
/** Compose Home navigation with competing chrome intents; physical input stays in the root. */
|
|
155
185
|
export function createApplicationHomeNavigationOwner(options) {
|