pi-better-server 0.1.3 → 0.2.1
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/README.md +14 -8
- package/package.json +1 -1
- package/scripts/bench-localhost.ts +279 -0
- package/src/handshake.ts +1 -1
- package/src/remote/target.ts +3 -2
- package/src/remote-client/connection-progress.ts +64 -10
- package/src/remote-client/extension.ts +29 -17
- package/src/remote-client/menu.ts +8 -3
- package/src/remote-client/remote-progress.ts +10 -1
- package/src/remote-client/session-browser.ts +4 -2
- package/src/remote-client/session.ts +2 -1
- package/src/remote-client/transfer-command.ts +5 -2
package/README.md
CHANGED
|
@@ -108,14 +108,16 @@ A client that skips `hello` is still served.
|
|
|
108
108
|
|
|
109
109
|
The native client provides an experimental VS Code Remote-style workflow:
|
|
110
110
|
start ordinary local Pi **1.2.0** with this package loaded at startup, then run
|
|
111
|
-
`/remote connect r5
|
|
111
|
+
`/remote connect r5`, or `/remote connect localhost` for the daemon on this machine.
|
|
112
|
+
The terminal keeps Pi's native local UI while the daemon owns
|
|
112
113
|
the model, tools, workspace and session state. Your local conversation stays separate
|
|
113
114
|
unless you explicitly choose to move or copy it after connecting.
|
|
114
115
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
116
|
+
`localhost` skips SSH. It talks to the local daemon socket, starting that daemon
|
|
117
|
+
through the installed runtime when one is registered. A remote host installs or stages
|
|
118
|
+
the matching server build, verifies readiness and compatibility, and then opens the SSH
|
|
119
|
+
tunnel. A registered runtime keeps its agent and server directories. A new host uses
|
|
120
|
+
`~/.pi/agent` and `~/.pi/agent/server`. See [automatic server updates](#automatic-server-updates)
|
|
119
121
|
for busy sessions, older daemons and manual launcher overrides.
|
|
120
122
|
|
|
121
123
|
### Connect and disconnect
|
|
@@ -131,6 +133,7 @@ connecting.
|
|
|
131
133
|
/remote list
|
|
132
134
|
/remote connect
|
|
133
135
|
/remote connect r5
|
|
136
|
+
/remote connect localhost
|
|
134
137
|
/remote r5
|
|
135
138
|
/remote r5 --cwd /home/user/workspaces/project
|
|
136
139
|
/remote r5 --session <id-or-unique-prefix>
|
|
@@ -148,9 +151,12 @@ and press Enter to confirm a connection. `/remote connect` opens a host picker;
|
|
|
148
151
|
actions only. Host suggestions appear only after `connect`, with a complete
|
|
149
152
|
`connect <host>` completion value. `/remote r5` remains a supported shorthand.
|
|
150
153
|
|
|
151
|
-
While connecting, a native spinner shows
|
|
152
|
-
|
|
153
|
-
|
|
154
|
+
While connecting, a native spinner names each stage and shows how long that stage
|
|
155
|
+
and the whole attempt have taken. Finished stages stay on screen with their duration.
|
|
156
|
+
Once SSH succeeds, the screen says Connected. Later stages are remote progress, not
|
|
157
|
+
another connection attempt: finding the remote server, starting or checking the Pi
|
|
158
|
+
server, opening the tunnel, and contacting the daemon. Local stages stay under Connecting,
|
|
159
|
+
because there is no SSH step. Escape cancels that attempt and returns to the local UI. It does not stop any
|
|
154
160
|
remote sessions or shared SSH connection. Connection failures retain their original
|
|
155
161
|
error message; the spinner does not imply that an unreachable host is available.
|
|
156
162
|
|
package/package.json
CHANGED
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Benchmark for the pi-better-server localhost connection path.
|
|
3
|
+
*
|
|
4
|
+
* Run with plain node (Node >= 22.18 strips the types itself):
|
|
5
|
+
*
|
|
6
|
+
* node scripts/bench-localhost.ts
|
|
7
|
+
*
|
|
8
|
+
* Spawns real daemon child processes (src/cli.ts) against a private agent dir
|
|
9
|
+
* with the scripted fake provider, then measures: cold start, connect+hello,
|
|
10
|
+
* RPC latencies, prompt roundtrip, replay catch-up, and the re-attach path.
|
|
11
|
+
*/
|
|
12
|
+
import { connect } from "node:net";
|
|
13
|
+
import { join } from "node:path";
|
|
14
|
+
import { performance } from "node:perf_hooks";
|
|
15
|
+
import { DaemonClient } from "../src/client.ts";
|
|
16
|
+
import { makeEnv, spawnDaemon, type Env } from "../test/helpers.ts";
|
|
17
|
+
|
|
18
|
+
// Iteration counts. Kept small so the whole run stays well under a minute.
|
|
19
|
+
const COLD_STARTS = 3;
|
|
20
|
+
const CONNECTS = 10;
|
|
21
|
+
const RPC_CALLS = 10;
|
|
22
|
+
const CREATE_SESSIONS = 4;
|
|
23
|
+
const PROMPTS = 5;
|
|
24
|
+
const REPLAY_TURNS = 12; // prompts run to accumulate events for the replay measurement
|
|
25
|
+
const REPLAY_RUNS = 5; // fresh connections replaying the accumulated history
|
|
26
|
+
const ATTACHES = 5;
|
|
27
|
+
|
|
28
|
+
const now = (): number => performance.now();
|
|
29
|
+
|
|
30
|
+
function stats(samples: number[]): { min: number; median: number; max: number } {
|
|
31
|
+
const sorted = [...samples].sort((a, b) => a - b);
|
|
32
|
+
const mid = Math.floor(sorted.length / 2);
|
|
33
|
+
const median = sorted.length % 2 === 0 ? (sorted[mid - 1] + sorted[mid]) / 2 : sorted[mid];
|
|
34
|
+
return { min: sorted[0], median, max: sorted[sorted.length - 1] };
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
interface Row {
|
|
38
|
+
name: string;
|
|
39
|
+
n: number;
|
|
40
|
+
min: number;
|
|
41
|
+
median: number;
|
|
42
|
+
max: number;
|
|
43
|
+
note?: string;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const rows: Row[] = [];
|
|
47
|
+
function record(name: string, samples: number[], note?: string): void {
|
|
48
|
+
const s = stats(samples);
|
|
49
|
+
rows.push({ name, n: samples.length, ...s, note });
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function printTable(): void {
|
|
53
|
+
const headers = ["benchmark", "n", "min (ms)", "median (ms)", "max (ms)", "notes"];
|
|
54
|
+
const cells = rows.map((r) => [r.name, String(r.n), r.min.toFixed(1), r.median.toFixed(1), r.max.toFixed(1), r.note ?? ""]);
|
|
55
|
+
const widths = headers.map((h, i) => Math.max(h.length, ...cells.map((c) => c[i].length)));
|
|
56
|
+
const line = (parts: string[]): string => parts.map((p, i) => p.padEnd(widths[i])).join(" ").trimEnd();
|
|
57
|
+
console.log("");
|
|
58
|
+
console.log(line(headers));
|
|
59
|
+
console.log(widths.map((w) => "-".repeat(w)).join(" "));
|
|
60
|
+
for (const c of cells) console.log(line(c));
|
|
61
|
+
console.log("");
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** Connect, say hello (no optional capabilities), and time the whole thing. */
|
|
65
|
+
async function timedConnect(socketPath: string): Promise<{ client: DaemonClient; ms: number }> {
|
|
66
|
+
const t0 = now();
|
|
67
|
+
const client = await DaemonClient.connect(socketPath, { hello: { capabilities: [] } });
|
|
68
|
+
return { client, ms: now() - t0 };
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** Time one RPC through `client.call` (throws on failure). */
|
|
72
|
+
async function timedCall(client: DaemonClient, command: Record<string, unknown>): Promise<{ response: any; ms: number }> {
|
|
73
|
+
const t0 = now();
|
|
74
|
+
const response = await client.call(command);
|
|
75
|
+
return { response, ms: now() - t0 };
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** Resolve once `match` has been true for a pushed event, with a hard timeout. */
|
|
79
|
+
function waitForEvent(events: Array<{ message: any; at: number }>, what: string, match: (message: any) => boolean, timeoutMs = 20_000): Promise<{ message: any; at: number }> {
|
|
80
|
+
const deadline = now() + timeoutMs;
|
|
81
|
+
return new Promise((resolve, reject) => {
|
|
82
|
+
const poll = (): void => {
|
|
83
|
+
const hit = events.find((e) => match(e.message));
|
|
84
|
+
if (hit) return resolve(hit);
|
|
85
|
+
if (now() > deadline) return reject(new Error(`Timed out waiting for ${what}`));
|
|
86
|
+
setTimeout(poll, 5);
|
|
87
|
+
};
|
|
88
|
+
poll();
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const daemons: Array<{ kill: (signal?: string) => void }> = [];
|
|
93
|
+
function cleanup(): void {
|
|
94
|
+
for (const child of daemons) {
|
|
95
|
+
try {
|
|
96
|
+
child.kill("SIGKILL");
|
|
97
|
+
} catch {
|
|
98
|
+
// already gone
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
process.on("exit", cleanup);
|
|
103
|
+
// makeEnv registers an exit handler that removes the temp roots.
|
|
104
|
+
|
|
105
|
+
async function main(): Promise<void> {
|
|
106
|
+
console.log("bench-localhost: measuring pi-better-server over a local unix socket");
|
|
107
|
+
|
|
108
|
+
// ---- 1. Daemon cold start: spawn -> "listening on" -> socket accepts a connection ----
|
|
109
|
+
const coldStarts: number[] = [];
|
|
110
|
+
let env: Env | undefined;
|
|
111
|
+
let daemon: (typeof daemons)[number] | undefined;
|
|
112
|
+
let socketPath = "";
|
|
113
|
+
for (let i = 0; i < COLD_STARTS; i++) {
|
|
114
|
+
const e = makeEnv();
|
|
115
|
+
const t0 = now();
|
|
116
|
+
const started = await spawnDaemon(e);
|
|
117
|
+
// The stderr marker precedes the socket being connectable by a hair; probe a real connection.
|
|
118
|
+
await new Promise<void>((resolve, reject) => {
|
|
119
|
+
const probe = connect(join(e.serverDir, "pi-server.sock"));
|
|
120
|
+
probe.once("connect", () => {
|
|
121
|
+
probe.end();
|
|
122
|
+
resolve();
|
|
123
|
+
});
|
|
124
|
+
probe.once("error", reject);
|
|
125
|
+
});
|
|
126
|
+
coldStarts.push(now() - t0);
|
|
127
|
+
daemons.push(started.child);
|
|
128
|
+
if (i === COLD_STARTS - 1) {
|
|
129
|
+
// Keep the last daemon for the rest of the benchmark.
|
|
130
|
+
env = e;
|
|
131
|
+
daemon = started.child;
|
|
132
|
+
socketPath = started.socketPath;
|
|
133
|
+
} else {
|
|
134
|
+
started.child.kill("SIGKILL");
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
record("daemon cold start (spawn -> socket accepts)", coldStarts);
|
|
138
|
+
if (!env || !daemon) throw new Error("no daemon survived cold-start measurement");
|
|
139
|
+
|
|
140
|
+
// ---- 2. Client connect + hello handshake ----
|
|
141
|
+
const connects: number[] = [];
|
|
142
|
+
for (let i = 0; i < CONNECTS; i++) {
|
|
143
|
+
const { client, ms } = await timedConnect(socketPath);
|
|
144
|
+
connects.push(ms);
|
|
145
|
+
client.close();
|
|
146
|
+
}
|
|
147
|
+
record("client connect + hello", connects);
|
|
148
|
+
|
|
149
|
+
// One long-lived client for the RPC and prompt measurements.
|
|
150
|
+
const { client } = await timedConnect(socketPath);
|
|
151
|
+
|
|
152
|
+
// ---- 3a. list_sessions ----
|
|
153
|
+
const listSessions: number[] = [];
|
|
154
|
+
for (let i = 0; i < RPC_CALLS; i++) listSessions.push((await timedCall(client, { type: "list_sessions" })).ms);
|
|
155
|
+
record("rpc list_sessions", listSessions);
|
|
156
|
+
|
|
157
|
+
// ---- 3b. create_session (keeps one for the prompt tests, closes the rest later) ----
|
|
158
|
+
const createSessions: number[] = [];
|
|
159
|
+
const createdIds: string[] = [];
|
|
160
|
+
for (let i = 0; i < CREATE_SESSIONS; i++) {
|
|
161
|
+
const { response, ms } = await timedCall(client, { type: "create_session", cwd: env.cwd, model: { provider: "fake", modelId: "fake-1" } });
|
|
162
|
+
createSessions.push(ms);
|
|
163
|
+
createdIds.push(response.sessionId);
|
|
164
|
+
}
|
|
165
|
+
record("rpc create_session", createSessions);
|
|
166
|
+
const sessionId = createdIds[0];
|
|
167
|
+
const spareIds = createdIds.slice(1);
|
|
168
|
+
|
|
169
|
+
// ---- 3c. open_session on an already-created session ----
|
|
170
|
+
const openSessions: number[] = [];
|
|
171
|
+
for (let i = 0; i < RPC_CALLS; i++) openSessions.push((await timedCall(client, { type: "open_session", sessionId })).ms);
|
|
172
|
+
record("rpc open_session", openSessions);
|
|
173
|
+
|
|
174
|
+
// ---- 3d. client_snapshot ----
|
|
175
|
+
const snapshots: number[] = [];
|
|
176
|
+
for (let i = 0; i < RPC_CALLS; i++) snapshots.push((await timedCall(client, { type: "client_snapshot", sessionId })).ms);
|
|
177
|
+
record("rpc client_snapshot", snapshots);
|
|
178
|
+
|
|
179
|
+
// ---- 3e. subscribe ----
|
|
180
|
+
const subscribes: number[] = [];
|
|
181
|
+
for (let i = 0; i < RPC_CALLS; i++) subscribes.push((await timedCall(client, { type: "subscribe", sessionId })).ms);
|
|
182
|
+
record("rpc subscribe", subscribes);
|
|
183
|
+
|
|
184
|
+
// ---- 3f. rename_session ----
|
|
185
|
+
const renames: number[] = [];
|
|
186
|
+
for (let i = 0; i < RPC_CALLS; i++) renames.push((await timedCall(client, { type: "rename_session", sessionId, name: `bench-${i}` })).ms);
|
|
187
|
+
record("rpc rename_session", renames);
|
|
188
|
+
|
|
189
|
+
// ---- 3g. close_session (close the spare sessions created above) ----
|
|
190
|
+
const closes: number[] = [];
|
|
191
|
+
for (const id of spareIds) closes.push((await timedCall(client, { type: "close_session", sessionId: id })).ms);
|
|
192
|
+
record("rpc close_session", closes);
|
|
193
|
+
|
|
194
|
+
// ---- 4. Prompt roundtrip with the fake provider ----
|
|
195
|
+
// The creator connection is auto-subscribed, so events stream to it.
|
|
196
|
+
const events: Array<{ message: any; at: number }> = [];
|
|
197
|
+
client.onEvent((message) => events.push({ message, at: now() }));
|
|
198
|
+
const firstEvent: number[] = [];
|
|
199
|
+
const toAgentEnd: number[] = [];
|
|
200
|
+
const toSettled: number[] = [];
|
|
201
|
+
let settledSeen = false;
|
|
202
|
+
// Match only events pushed after `startIdx` in the shared log.
|
|
203
|
+
const after = (startIdx: number, predicate: (m: any) => boolean) => (m: any): boolean => {
|
|
204
|
+
const idx = events.findIndex((e) => e.message === m);
|
|
205
|
+
return idx >= startIdx && predicate(m);
|
|
206
|
+
};
|
|
207
|
+
for (let i = 0; i < PROMPTS; i++) {
|
|
208
|
+
const baseline = events.length;
|
|
209
|
+
const t0 = now();
|
|
210
|
+
await client.call({ type: "prompt", sessionId, message: `bench prompt ${i}` });
|
|
211
|
+
const first = await waitForEvent(events, "first streamed event", after(baseline, (m) => m.sessionId === sessionId));
|
|
212
|
+
firstEvent.push(first.at - t0);
|
|
213
|
+
const end = await waitForEvent(events, "agent_end", after(baseline, (m) => m.sessionId === sessionId && m.event?.type === "agent_end"));
|
|
214
|
+
toAgentEnd.push(end.at - t0);
|
|
215
|
+
try {
|
|
216
|
+
const settled = await waitForEvent(events, "agent_settled", after(baseline, (m) => m.sessionId === sessionId && m.event?.type === "agent_settled"), 3_000);
|
|
217
|
+
toSettled.push(settled.at - t0);
|
|
218
|
+
settledSeen = true;
|
|
219
|
+
} catch {
|
|
220
|
+
// This Pi build does not emit agent_settled to subscribers; agent_end is the terminal event.
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
record("prompt -> first streamed event", firstEvent);
|
|
224
|
+
record("prompt -> agent_end", toAgentEnd);
|
|
225
|
+
if (settledSeen) record("prompt -> agent_settled", toSettled);
|
|
226
|
+
else console.log("note: daemon emitted no agent_settled event; agent_end is the measured terminal event");
|
|
227
|
+
|
|
228
|
+
// ---- 5. Replay: accumulate history, then subscribe from seq 0 on fresh connections ----
|
|
229
|
+
for (let i = 0; i < REPLAY_TURNS; i++) {
|
|
230
|
+
const baseline = events.length;
|
|
231
|
+
await client.call({ type: "prompt", sessionId, message: `replay filler ${i}` });
|
|
232
|
+
await waitForEvent(events, "agent_end", after(baseline, (m) => m.sessionId === sessionId && m.event?.type === "agent_end"));
|
|
233
|
+
}
|
|
234
|
+
const replays: number[] = [];
|
|
235
|
+
let replayCount = 0;
|
|
236
|
+
let replayed = 0;
|
|
237
|
+
for (let run = 0; run < REPLAY_RUNS; run++) {
|
|
238
|
+
const replayClient = (await timedConnect(socketPath)).client;
|
|
239
|
+
const replayEvents: Array<{ message: any; at: number }> = [];
|
|
240
|
+
replayClient.onEvent((message) => replayEvents.push({ message, at: now() }));
|
|
241
|
+
const tReplay0 = now();
|
|
242
|
+
const sub = await replayClient.call({ type: "subscribe", sessionId, sinceSeq: 0 });
|
|
243
|
+
const lastSeq = (sub.data as { lastSeq: number }).lastSeq;
|
|
244
|
+
replayed = (sub.data as { replayed: number }).replayed;
|
|
245
|
+
await waitForEvent(replayEvents, `replay catch-up to seq ${lastSeq}`, (m) => m.sessionId === sessionId && typeof m.seq === "number" && m.seq >= lastSeq);
|
|
246
|
+
replays.push(now() - tReplay0);
|
|
247
|
+
replayCount = replayEvents.filter((m) => m.message.sessionId === sessionId && typeof m.message.seq === "number" && m.message.seq <= lastSeq).length;
|
|
248
|
+
replayClient.close();
|
|
249
|
+
}
|
|
250
|
+
const replayMedian = stats(replays).median;
|
|
251
|
+
const perSec = replayMedian > 0 ? (replayCount / replayMedian) * 1000 : 0;
|
|
252
|
+
record("replay subscribe(sinceSeq 0) -> caught up", replays, `${replayCount} events (replayed ${replayed}), ${perSec.toFixed(0)} events/s at median`);
|
|
253
|
+
|
|
254
|
+
// ---- 6. Re-attach: open_session + client_snapshot + subscribe on the existing session ----
|
|
255
|
+
const attaches: number[] = [];
|
|
256
|
+
for (let i = 0; i < ATTACHES; i++) {
|
|
257
|
+
const attachClient = (await timedConnect(socketPath)).client;
|
|
258
|
+
const t0 = now();
|
|
259
|
+
await attachClient.call({ type: "open_session", sessionId });
|
|
260
|
+
await attachClient.call({ type: "client_snapshot", sessionId });
|
|
261
|
+
await attachClient.call({ type: "subscribe", sessionId, sinceSeq: 0 });
|
|
262
|
+
attaches.push(now() - t0);
|
|
263
|
+
attachClient.close();
|
|
264
|
+
}
|
|
265
|
+
record("re-attach (open + snapshot + subscribe)", attaches, "per fresh connection, connect+hello excluded");
|
|
266
|
+
|
|
267
|
+
// ---- Cleanup ----
|
|
268
|
+
await client.call({ type: "close_session", sessionId }).catch(() => undefined);
|
|
269
|
+
client.close();
|
|
270
|
+
daemon.kill("SIGKILL");
|
|
271
|
+
|
|
272
|
+
printTable();
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
main().catch((error) => {
|
|
276
|
+
console.error("bench failed:", error);
|
|
277
|
+
cleanup();
|
|
278
|
+
process.exit(1);
|
|
279
|
+
});
|
package/src/handshake.ts
CHANGED
|
@@ -4,7 +4,7 @@ import type { ServerBuild } from "./startup/managed-types.ts";
|
|
|
4
4
|
import { PROTOCOL_VERSION, type HelloCommand, type HelloData } from "./protocol.ts";
|
|
5
5
|
|
|
6
6
|
/** Kept equal to package.json `version`; a test pins that. */
|
|
7
|
-
export const SERVER_VERSION = "0.1
|
|
7
|
+
export const SERVER_VERSION = "0.2.1";
|
|
8
8
|
|
|
9
9
|
export const SERVER_EXTENSION_VERSIONS: Readonly<Record<string, string>> = { "pi-better-server": SERVER_VERSION };
|
|
10
10
|
|
package/src/remote/target.ts
CHANGED
|
@@ -121,6 +121,7 @@ export async function resolveTarget(options: TargetOptions): Promise<Target> {
|
|
|
121
121
|
const ensureServer = options.ensureServer !== false && (options.agent ?? process.env.PI_SERVER_AGENT ?? "pi") === "pi";
|
|
122
122
|
if (!options.host) {
|
|
123
123
|
let socketPath = options.socket;
|
|
124
|
+
const requestedDir = options.remoteDir ? absolutePath(options.remoteDir, "--remote-dir") : undefined;
|
|
124
125
|
let serverDir: string | undefined;
|
|
125
126
|
const candidate = ensureServer && !options.socket ? discoverLocalRuntime() : undefined;
|
|
126
127
|
if (candidate) {
|
|
@@ -133,7 +134,7 @@ export async function resolveTarget(options: TargetOptions): Promise<Target> {
|
|
|
133
134
|
checkAbort();
|
|
134
135
|
if (discovery.exitCode !== 0) throw new Error(`Runtime discovery: ${discovery.stderr.trim() || "launcher failed"}. ${INSTALL_GUIDANCE}`);
|
|
135
136
|
const runtime = parseRuntime(discovery.stdout);
|
|
136
|
-
serverDir = process.env.PI_SERVER_DIR || runtime.defaultServerDir;
|
|
137
|
+
serverDir = requestedDir ?? (process.env.PI_SERVER_DIR || runtime.defaultServerDir);
|
|
137
138
|
progress("server");
|
|
138
139
|
const result = await runner.runOnce({
|
|
139
140
|
shell: false, argv: [runtime.launcher, ...ensureArgs(serverDir)],
|
|
@@ -144,7 +145,7 @@ export async function resolveTarget(options: TargetOptions): Promise<Target> {
|
|
|
144
145
|
socketPath = parseReadiness(result.stdout, serverDir).socketPath;
|
|
145
146
|
}
|
|
146
147
|
if (socketPath === undefined) {
|
|
147
|
-
serverDir = defaultServerDir();
|
|
148
|
+
serverDir = requestedDir ?? defaultServerDir();
|
|
148
149
|
socketPath = socketPathFor(serverDir);
|
|
149
150
|
}
|
|
150
151
|
return {
|
|
@@ -4,10 +4,24 @@ import { CancellableLoader, truncateToWidth } from "@earendil-works/pi-tui";
|
|
|
4
4
|
export interface ConnectionProgress {
|
|
5
5
|
signal: AbortSignal;
|
|
6
6
|
stage(message: string): void;
|
|
7
|
+
/** SSH is up. Later stages are work on the remote, not the connection itself. */
|
|
8
|
+
sshConnected(): void;
|
|
7
9
|
}
|
|
8
10
|
|
|
9
11
|
type Outcome<T> = { kind: "connected"; value: T } | { kind: "failed"; error: unknown } | { kind: "cancelled" };
|
|
10
12
|
|
|
13
|
+
interface StageRecord {
|
|
14
|
+
message: string;
|
|
15
|
+
startedAt: number;
|
|
16
|
+
durationMs?: number;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** Compact durations: one decimal under ten seconds, whole seconds after that. */
|
|
20
|
+
export function formatStageDuration(ms: number): string {
|
|
21
|
+
const seconds = Math.max(0, ms) / 1000;
|
|
22
|
+
return seconds < 10 ? `${seconds.toFixed(1)}s` : `${Math.round(seconds)}s`;
|
|
23
|
+
}
|
|
24
|
+
|
|
11
25
|
/** Owns the loading screen only; late resources from a cancelled attempt are disposed. */
|
|
12
26
|
export async function withConnectionProgress<T>(
|
|
13
27
|
ui: Pick<ExtensionUIContext, "custom">,
|
|
@@ -20,43 +34,83 @@ export async function withConnectionProgress<T>(
|
|
|
20
34
|
try {
|
|
21
35
|
outcome = await ui.custom<Outcome<T>>((tui, theme, _keys, done) => {
|
|
22
36
|
const controller = new AbortController();
|
|
37
|
+
const startedAt = Date.now();
|
|
38
|
+
const stages: StageRecord[] = [];
|
|
23
39
|
const loader = new CancellableLoader(tui, text => theme.fg("accent", text), text => theme.fg("muted", text), `Connecting to ${host}: preparing...`);
|
|
24
40
|
let finished = false;
|
|
25
41
|
let abandoned = false;
|
|
42
|
+
let sshReady = false;
|
|
43
|
+
const prefix = () => sshReady ? "Remote" : `Connecting to ${host}`;
|
|
44
|
+
const paint = (message: string, started = Date.now()) => {
|
|
45
|
+
loader.setMessage(`${prefix()}: ${message} · ${formatStageDuration(Date.now() - started)}`);
|
|
46
|
+
};
|
|
47
|
+
// Elapsed labels tick even when the current stage produces no new messages.
|
|
48
|
+
const ticker = setInterval(() => {
|
|
49
|
+
if (finished) return;
|
|
50
|
+
const current = stages.at(-1);
|
|
51
|
+
if (current) paint(current.message, current.startedAt);
|
|
52
|
+
tui.requestRender();
|
|
53
|
+
}, 500);
|
|
54
|
+
const stage = (message: string) => {
|
|
55
|
+
if (finished) return;
|
|
56
|
+
const current = stages.at(-1);
|
|
57
|
+
if (current?.message === message) return;
|
|
58
|
+
if (current) current.durationMs = Date.now() - current.startedAt;
|
|
59
|
+
stages.push({ message, startedAt: Date.now() });
|
|
60
|
+
if (!finished) loader.setMessage(`${prefix()}: ${message}`);
|
|
61
|
+
tui.requestRender();
|
|
62
|
+
};
|
|
63
|
+
const sshConnected = () => {
|
|
64
|
+
if (finished || sshReady) return;
|
|
65
|
+
sshReady = true;
|
|
66
|
+
const current = stages.at(-1);
|
|
67
|
+
if (current) loader.setMessage(`${prefix()}: ${current.message}`);
|
|
68
|
+
tui.requestRender();
|
|
69
|
+
};
|
|
70
|
+
const stop = () => {
|
|
71
|
+
clearInterval(ticker);
|
|
72
|
+
loader.stop();
|
|
73
|
+
};
|
|
26
74
|
abandon = () => {
|
|
27
75
|
if (finished) return;
|
|
28
76
|
finished = true;
|
|
29
77
|
abandoned = true;
|
|
30
78
|
controller.abort();
|
|
31
|
-
|
|
79
|
+
stop();
|
|
32
80
|
};
|
|
33
81
|
loader.onAbort = () => { if (!finished) { abandon!(); done({ kind: "cancelled" }); } };
|
|
34
82
|
void Promise.resolve().then(() => {
|
|
35
83
|
controller.signal.throwIfAborted();
|
|
36
|
-
return connect({
|
|
37
|
-
signal: controller.signal,
|
|
38
|
-
stage: message => { if (!finished) loader.setMessage(`Connecting to ${host}: ${message}`); },
|
|
39
|
-
});
|
|
84
|
+
return connect({ signal: controller.signal, stage, sshConnected });
|
|
40
85
|
}).then(value => {
|
|
41
86
|
if (abandoned) { void Promise.resolve().then(() => disposeLate(value)).catch(() => undefined); return; }
|
|
42
87
|
finished = true;
|
|
43
|
-
|
|
88
|
+
stop();
|
|
44
89
|
done({ kind: "connected", value });
|
|
45
90
|
}, error => {
|
|
46
91
|
if (abandoned) return;
|
|
47
92
|
finished = true;
|
|
48
|
-
|
|
93
|
+
stop();
|
|
49
94
|
done({ kind: "failed", error });
|
|
50
95
|
});
|
|
51
96
|
return {
|
|
52
|
-
render: width =>
|
|
97
|
+
render: width => {
|
|
98
|
+
if (width <= 0) return [];
|
|
99
|
+
const fit = (text: string) => truncateToWidth(text, width, "...");
|
|
100
|
+
const now = Date.now();
|
|
101
|
+
const history = stages.slice(0, -1).map(doneStage =>
|
|
102
|
+
theme.fg("muted", fit(` ✓ ${doneStage.message} ${formatStageDuration(doneStage.durationMs ?? now - doneStage.startedAt)}`)));
|
|
103
|
+
const connected = sshReady ? [theme.fg("accent", fit(`Connected to ${host}`))] : [];
|
|
104
|
+
const elapsed = theme.fg("dim", fit(`Esc cancel · ${formatStageDuration(now - startedAt)}`));
|
|
105
|
+
return [...history, ...connected, ...loader.render(width), elapsed];
|
|
106
|
+
},
|
|
53
107
|
handleInput: data => loader.handleInput(data),
|
|
54
108
|
invalidate: () => loader.invalidate(),
|
|
55
|
-
dispose: () => { abandon?.(); loader.dispose(); },
|
|
109
|
+
dispose: () => { clearInterval(ticker); abandon?.(); loader.dispose(); },
|
|
56
110
|
};
|
|
57
111
|
});
|
|
58
112
|
} catch (error) { abandon?.(); throw error; }
|
|
59
113
|
if (!outcome) { abandon?.(); return undefined; }
|
|
60
114
|
if (outcome.kind === "failed") throw outcome.error;
|
|
61
115
|
return outcome.kind === "connected" ? outcome.value : undefined;
|
|
62
|
-
}
|
|
116
|
+
}
|
|
@@ -8,7 +8,7 @@ import { resolveSession } from "../remote/sessions.ts";
|
|
|
8
8
|
import { getPi12Bridge, installPi12Bridge, type Pi12Bridge } from "./pi-1.2-bridge.ts";
|
|
9
9
|
import { planPackageSync, readLocalPackageCatalog, type PackageCatalog } from "./packages.ts";
|
|
10
10
|
import { RemoteClientSession } from "./session.ts";
|
|
11
|
-
import { availableRemoteHosts, chooseRemoteHost, remoteArgumentCompletions, showRemoteHostList } from "./menu.ts";
|
|
11
|
+
import { availableRemoteHosts, chooseRemoteHost, LOCAL_HOST, remoteArgumentCompletions, showRemoteHostList } from "./menu.ts";
|
|
12
12
|
import { rememberedServerDir, rememberRemoteHost } from "./profiles.ts";
|
|
13
13
|
import { browseRemoteSessions } from "./session-browser.ts";
|
|
14
14
|
import { withConnectionProgress } from "./connection-progress.ts";
|
|
@@ -19,7 +19,10 @@ import { browseRemoteFolders } from "./folder-browser.ts";
|
|
|
19
19
|
import { showRemoteProgress } from "./remote-progress.ts";
|
|
20
20
|
import { NATIVE_RECONNECT_CAPABILITIES, openUpgradeTransport } from "./upgrade-transport.ts";
|
|
21
21
|
|
|
22
|
-
const USAGE = "/remote connect <ssh-alias> [--cwd <remote-path>] [--session <id>] [--remote-dir <server-dir>]";
|
|
22
|
+
const USAGE = "/remote connect <ssh-alias|localhost> [--cwd <remote-path>] [--session <id>] [--remote-dir <server-dir>]";
|
|
23
|
+
/** `localhost` names the daemon on this machine: a plain Unix socket, no SSH setup. */
|
|
24
|
+
export { LOCAL_HOST };
|
|
25
|
+
export const isLocalHost = (host: string): boolean => host === LOCAL_HOST;
|
|
23
26
|
const UPGRADE_STAGES: Record<string, string> = {
|
|
24
27
|
artifact: "preparing matching server...", probe: "checking remote platform...", "node-download": "preparing private Node runtime...",
|
|
25
28
|
verifying: "verifying installed server...", "verification-upload": "sending server verification data...",
|
|
@@ -35,7 +38,8 @@ export function parseRemoteArgs(text: string) {
|
|
|
35
38
|
cwd: { type: "string" }, session: { type: "string" }, "remote-dir": { type: "string" },
|
|
36
39
|
} });
|
|
37
40
|
if (positionals.length !== 1) throw new Error(`Usage: ${USAGE}`);
|
|
38
|
-
|
|
41
|
+
const host = positionals[0] === "local" ? LOCAL_HOST : positionals[0]!;
|
|
42
|
+
return { host, cwd: values.cwd, sessionId: values.session, remoteDir: values["remote-dir"] };
|
|
39
43
|
}
|
|
40
44
|
|
|
41
45
|
type RemoteOptions = ReturnType<typeof parseRemoteArgs>;
|
|
@@ -183,15 +187,22 @@ export async function connectHost(options: RemoteOptions, local: LocalFrontend):
|
|
|
183
187
|
let remoteDir = options.remoteDir ?? await rememberedServerDir(options.host);
|
|
184
188
|
const controlPathRoot = join(process.env.PI_REMOTE_TMP ?? "/tmp", `pi-native-${process.getuid?.() ?? process.pid}`);
|
|
185
189
|
let deferredUpgrade: string | undefined;
|
|
186
|
-
const setup = await withConnectionProgress(ui, options.host, async ({ signal, stage }) => {
|
|
190
|
+
const setup = await withConnectionProgress(ui, options.host, async ({ signal, stage, sshConnected }) => {
|
|
187
191
|
let pendingTarget: Target | undefined;
|
|
188
192
|
let pendingClient: DaemonClient | undefined;
|
|
189
193
|
try {
|
|
190
|
-
|
|
194
|
+
const localConnect = isLocalHost(options.host);
|
|
195
|
+
stage(localConnect ? "finding local server..." : "establishing SSH...");
|
|
191
196
|
pendingTarget = await local.dependencies.resolveTarget({
|
|
192
|
-
host: options.host, agent: "pi", controlPathRoot, signal, managedRuntime: true,
|
|
197
|
+
host: localConnect ? undefined : options.host, agent: "pi", controlPathRoot, signal, managedRuntime: true,
|
|
193
198
|
...(remoteDir ? { remoteDir } : {}),
|
|
194
|
-
onProgress: phase =>
|
|
199
|
+
onProgress: phase => {
|
|
200
|
+
// The ssh phase is the connection. Everything after it is work on the remote.
|
|
201
|
+
if (!localConnect && phase !== "ssh") sshConnected();
|
|
202
|
+
stage(localConnect
|
|
203
|
+
? { directory: "finding local server...", server: "starting or checking Pi server...", ssh: "finding local server...", forward: "connecting to local socket..." }[phase]
|
|
204
|
+
: { ssh: "establishing SSH...", directory: "finding remote server...", server: "starting or checking Pi server...", forward: "opening SSH tunnel..." }[phase]);
|
|
205
|
+
},
|
|
195
206
|
onUpgradeProgress: (phase, detail) => {
|
|
196
207
|
if (phase === "deferred") deferredUpgrade = detail;
|
|
197
208
|
stage(UPGRADE_STAGES[phase] ?? "checking matching server...");
|
|
@@ -199,7 +210,12 @@ export async function connectHost(options: RemoteOptions, local: LocalFrontend):
|
|
|
199
210
|
});
|
|
200
211
|
signal.throwIfAborted();
|
|
201
212
|
stage("contacting Pi server...");
|
|
202
|
-
|
|
213
|
+
try {
|
|
214
|
+
pendingClient = await DaemonClient.connect(pendingTarget.socketPath, { signal, hello: { capabilities: [...NATIVE_RECONNECT_CAPABILITIES] } });
|
|
215
|
+
} catch (error) {
|
|
216
|
+
if (!localConnect) throw error;
|
|
217
|
+
throw new Error(`Could not reach the local Pi server at ${pendingTarget.socketPath}: ${error instanceof Error ? error.message : String(error)}. Start it with the pi-better-server CLI or install the native runtime, then retry /remote connect localhost.`);
|
|
218
|
+
}
|
|
203
219
|
signal.throwIfAborted();
|
|
204
220
|
stage("checking server compatibility...");
|
|
205
221
|
const capabilities = pendingClient.server?.capabilities ?? [];
|
|
@@ -225,7 +241,6 @@ export async function connectHost(options: RemoteOptions, local: LocalFrontend):
|
|
|
225
241
|
: `Server update staged. The current daemon cannot perform a verified automatic handoff and was left running. ${deferredUpgrade}`, safe ? "info" : "warning");
|
|
226
242
|
}
|
|
227
243
|
let connection = client;
|
|
228
|
-
ui.setStatus("pi-remote", `SSH: ${options.host} (sessions)`);
|
|
229
244
|
if (!await syncPackages(connection, local, undefined, { scope: "global", host: options.host, onNotice: message => notices.push(message) })) return;
|
|
230
245
|
let choice: Exclude<RemoteSessionChoice, { action: "transfer" }> | undefined;
|
|
231
246
|
for (;;) {
|
|
@@ -249,17 +264,15 @@ export async function connectHost(options: RemoteOptions, local: LocalFrontend):
|
|
|
249
264
|
if (selectedChoice.action === "create") sessionId = (await connection.call({ type: "create_session", cwd })).sessionId as string;
|
|
250
265
|
await connection.call({ type: "open_session", sessionId });
|
|
251
266
|
return RemoteClientSession.connect(connection, sessionId, {
|
|
252
|
-
reconnectAfterUpgrade: (notice, signal) => openUpgradeTransport(
|
|
253
|
-
|
|
254
|
-
|
|
267
|
+
reconnectAfterUpgrade: (notice, signal) => openUpgradeTransport(isLocalHost(options.host)
|
|
268
|
+
? { agent: "pi", managedRuntime: true, ...(remoteDir ? { remoteDir } : {}) }
|
|
269
|
+
: { host: options.host, agent: "pi", controlPathRoot, managedRuntime: true, ...(remoteDir ? { remoteDir } : {}) },
|
|
270
|
+
local.dependencies, signal, notice.buildId),
|
|
255
271
|
onReconnected: replacement => {
|
|
256
272
|
connection = replacement;
|
|
257
273
|
void closeInitialTransport().catch(error => ui.notify(`Remote tunnel cleanup: ${String(error)}`, "warning"));
|
|
258
274
|
},
|
|
259
|
-
onUpgradeStatus: phase => ui.setStatus("pi-remote", phase === "ready"
|
|
260
|
-
? `SSH: ${options.host}` : `SSH: ${options.host} (${phase === "restarting" ? "server restarting" : "reconnecting"})`),
|
|
261
275
|
onDisconnect: () => {
|
|
262
|
-
ui.setStatus("pi-remote", `SSH: ${options.host} (disconnected)`);
|
|
263
276
|
ui.notify(`Disconnected from ${options.host}. Remote work has not been aborted. Use /remote disconnect to return locally, then reconnect.`, "warning");
|
|
264
277
|
},
|
|
265
278
|
localCommandCompletions: (prefix) => argumentCompletions(prefix, true),
|
|
@@ -294,11 +307,10 @@ export async function connectHost(options: RemoteOptions, local: LocalFrontend):
|
|
|
294
307
|
await bridge.attach(remote);
|
|
295
308
|
endBrowse = undefined;
|
|
296
309
|
attached = true;
|
|
297
|
-
ui.setStatus("pi-remote", `SSH: ${options.host}`);
|
|
298
310
|
ui.notify(`Attached to ${options.host}:${cwd}. /remote opens the server's sessions; /remote disconnect returns locally.`, "info");
|
|
299
311
|
} finally {
|
|
300
312
|
try { endBrowse?.(); }
|
|
301
|
-
finally { if (!attached)
|
|
313
|
+
finally { if (!attached) await closeInitialTransport(); }
|
|
302
314
|
}
|
|
303
315
|
}
|
|
304
316
|
|
|
@@ -6,6 +6,8 @@ import { sshHostAliases } from "./ssh-hosts.ts";
|
|
|
6
6
|
|
|
7
7
|
type MenuUi = Pick<ExtensionUIContext, "select" | "input">;
|
|
8
8
|
const OTHER_HOST = "Connect to another SSH host...";
|
|
9
|
+
const LOCAL_HOST_LABEL = "Connect to localhost (this machine, no SSH)";
|
|
10
|
+
export const LOCAL_HOST = "localhost";
|
|
9
11
|
|
|
10
12
|
export async function savedRemoteHosts(agentDir = getAgentDir()): Promise<string[]> {
|
|
11
13
|
let files;
|
|
@@ -36,8 +38,9 @@ export async function showRemoteHostList(ui: Pick<ExtensionUIContext, "select" |
|
|
|
36
38
|
|
|
37
39
|
export async function chooseRemoteHost(ui: MenuUi, hosts: readonly string[]): Promise<string | undefined> {
|
|
38
40
|
const labels = hosts.map((host) => `Connect to ${host}`);
|
|
39
|
-
const choice = await ui.select("Remote", [...labels, OTHER_HOST]);
|
|
41
|
+
const choice = await ui.select("Remote", [LOCAL_HOST_LABEL, ...labels, OTHER_HOST]);
|
|
40
42
|
if (choice === undefined) return undefined;
|
|
43
|
+
if (choice === LOCAL_HOST_LABEL) return LOCAL_HOST;
|
|
41
44
|
const index = labels.indexOf(choice);
|
|
42
45
|
if (index !== -1) return hosts[index];
|
|
43
46
|
if (choice !== OTHER_HOST) throw new Error("Unknown remote menu choice");
|
|
@@ -52,8 +55,10 @@ export function remoteArgumentCompletions(prefix: string, connected = false, hos
|
|
|
52
55
|
if (/^(connect|pull)(?:\s|$)/.test(input)) {
|
|
53
56
|
const action = input.split(/\s+/, 1)[0]!;
|
|
54
57
|
const hostPrefix = input.slice(action.length).trimStart();
|
|
55
|
-
const
|
|
56
|
-
|
|
58
|
+
const candidates = action === "connect" ? [LOCAL_HOST, ...hosts.filter((host) => host !== LOCAL_HOST)] : [...hosts];
|
|
59
|
+
const matches = candidates.filter((host) => host.toLowerCase().startsWith(hostPrefix))
|
|
60
|
+
.map((host) => ({ value: `${action} ${host}`, label: host,
|
|
61
|
+
description: host === LOCAL_HOST ? "Connect to the daemon on this machine" : `${action === "connect" ? "Connect to" : "Pull session from"} ${host}` }));
|
|
57
62
|
return matches.length ? matches : null;
|
|
58
63
|
}
|
|
59
64
|
const values = connected ? ["connect", "list", "sessions", "pull", "disconnect"] : ["connect", "list", "pull"];
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ExtensionUIContext } from "@earendil-works/pi-coding-agent";
|
|
2
2
|
import { CancellableLoader, truncateToWidth } from "@earendil-works/pi-tui";
|
|
3
|
+
import { formatStageDuration } from "./connection-progress.ts";
|
|
3
4
|
|
|
4
5
|
type Outcome<T> = { value: T } | { error: unknown } | undefined;
|
|
5
6
|
|
|
@@ -14,11 +15,19 @@ export async function showRemoteProgress<T>(
|
|
|
14
15
|
const cancellable = options.cancellable !== false;
|
|
15
16
|
const result = await ui.custom<Outcome<T>>((tui, theme, _keys, done) => {
|
|
16
17
|
let disposed = false;
|
|
18
|
+
const startedAt = Date.now();
|
|
17
19
|
const safeMessage = `${host}: ${message}`.replace(/[\x00-\x1f\x7f-\x9f]/g, " ");
|
|
18
20
|
const loader = new CancellableLoader(tui, text => theme.fg("accent", text), text => theme.fg("muted", text), safeMessage);
|
|
21
|
+
// Keep the wait visibly alive: the elapsed label ticks even when nothing else changes.
|
|
22
|
+
const ticker = setInterval(() => {
|
|
23
|
+
if (disposed) return;
|
|
24
|
+
loader.setMessage(`${safeMessage} · ${formatStageDuration(Date.now() - startedAt)}`);
|
|
25
|
+
tui.requestRender();
|
|
26
|
+
}, 500);
|
|
19
27
|
const finish = (value: Outcome<T>) => {
|
|
20
28
|
if (disposed) return;
|
|
21
29
|
disposed = true;
|
|
30
|
+
clearInterval(ticker);
|
|
22
31
|
loader.stop();
|
|
23
32
|
done(value);
|
|
24
33
|
};
|
|
@@ -31,7 +40,7 @@ export async function showRemoteProgress<T>(
|
|
|
31
40
|
render: width => width > 0 ? [...loader.render(width), theme.fg("dim", truncateToWidth(cancellable ? "Esc cancel" : "Waiting for the remote operation to finish", width, ""))] : [],
|
|
32
41
|
handleInput: data => { if (cancellable) loader.handleInput(data); },
|
|
33
42
|
invalidate: () => loader.invalidate(),
|
|
34
|
-
dispose: () => { disposed = true; loader.dispose(); },
|
|
43
|
+
dispose: () => { disposed = true; clearInterval(ticker); loader.dispose(); },
|
|
35
44
|
};
|
|
36
45
|
});
|
|
37
46
|
if (result && "error" in result) throw result.error;
|
|
@@ -115,7 +115,8 @@ export class RemoteSessionBrowser implements Component {
|
|
|
115
115
|
if (previous && visibleWidth(`${previous} ${command}`) <= width) legend[legend.length - 1] = `${previous} ${command}`;
|
|
116
116
|
else legend.push(fit(command));
|
|
117
117
|
}
|
|
118
|
-
|
|
118
|
+
const hostLabel = this.host === "localhost" ? "Local daemon" : `Remote: ${singleLine(this.host)}`;
|
|
119
|
+
let header = [theme.bold(fit(hostLabel)),
|
|
119
120
|
...(this.options.cwd ? [theme.fg("muted", fit(`Folder: ${singleLine(this.options.cwd)}`))] : [])];
|
|
120
121
|
let details = selected ? [
|
|
121
122
|
...wrapTextWithAnsi(singleLine(selected.name || "Untitled session"), width).slice(0, 2).map(line => theme.fg("accent", line)),
|
|
@@ -134,7 +135,8 @@ export class RemoteSessionBrowser implements Component {
|
|
|
134
135
|
if (fixed() + minimumBody + scrollRoom > budget) notices = [];
|
|
135
136
|
while (header.length && fixed() + minimumBody + scrollRoom > budget) header.pop();
|
|
136
137
|
const available = Math.max(0, budget - fixed());
|
|
137
|
-
|
|
138
|
+
// Use the height the terminal offers; only very short windows shed rows.
|
|
139
|
+
const unreservedHeight = available;
|
|
138
140
|
const entryCount = rows.length + (unreservedHeight >= 4 ? new Set(rows.map(session => session.cwd)).size : 0);
|
|
139
141
|
const bodyHeight = Math.max(0, unreservedHeight - (entryCount > unreservedHeight && available > 1 ? 1 : 0));
|
|
140
142
|
const grouped = bodyHeight >= 4;
|
|
@@ -1156,6 +1156,8 @@ export class RemoteClientSession {
|
|
|
1156
1156
|
}
|
|
1157
1157
|
}
|
|
1158
1158
|
private present(request: SessionEvent): void {
|
|
1159
|
+
// Preserve status events on the wire, but never write them to the local footer.
|
|
1160
|
+
if (request.method === "setStatus") return;
|
|
1159
1161
|
if (["select", "confirm", "input", "editor"].includes(request.method)) {
|
|
1160
1162
|
this.dialogs.set(request.id, request);
|
|
1161
1163
|
this.presentDialogs();
|
|
@@ -1165,7 +1167,6 @@ export class RemoteClientSession {
|
|
|
1165
1167
|
const ui = this.uiContext;
|
|
1166
1168
|
switch (request.method) {
|
|
1167
1169
|
case "notify": ui.notify(request.message, request.notifyType); break;
|
|
1168
|
-
case "setStatus": ui.setStatus(request.statusKey, request.statusText); break;
|
|
1169
1170
|
case "setWidget":
|
|
1170
1171
|
if (request.widgetLines !== undefined && (!Array.isArray(request.widgetLines) || !request.widgetLines.every((line: unknown) => typeof line === "string"))) {
|
|
1171
1172
|
throw new Error("Remote custom widget components are not supported; only text lines are supported");
|
|
@@ -84,14 +84,17 @@ export async function runRemoteTransfer(args: RemoteTransferArgs, frontend: Tran
|
|
|
84
84
|
let client: DaemonClient | undefined;
|
|
85
85
|
let operationFailed = false;
|
|
86
86
|
try {
|
|
87
|
-
const setup = await withConnectionProgress(ui, host, async ({ signal, stage }) => {
|
|
87
|
+
const setup = await withConnectionProgress(ui, host, async ({ signal, stage, sshConnected }) => {
|
|
88
88
|
let pendingTarget: Target | undefined;
|
|
89
89
|
let pendingClient: DaemonClient | undefined;
|
|
90
90
|
try {
|
|
91
91
|
stage("establishing SSH...");
|
|
92
92
|
pendingTarget = await (frontend.resolveTarget ?? resolveTarget)({
|
|
93
93
|
host, agent: "pi", signal, ...(remoteDir ? { remoteDir } : {}),
|
|
94
|
-
onProgress: phase =>
|
|
94
|
+
onProgress: phase => {
|
|
95
|
+
if (phase !== "ssh") sshConnected();
|
|
96
|
+
stage({ ssh: "establishing SSH...", directory: "finding remote server...", server: "starting or checking Pi server...", forward: "opening SSH tunnel..." }[phase]);
|
|
97
|
+
},
|
|
95
98
|
});
|
|
96
99
|
signal.throwIfAborted();
|
|
97
100
|
stage("contacting Pi server...");
|