pi-better-server 0.1.0 → 0.1.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 +27 -18
- package/package.json +1 -1
- package/src/cli.ts +0 -0
- package/src/handshake.ts +2 -2
- package/src/remote-cli.ts +0 -0
- package/src/remote-client/extension.ts +48 -20
- package/src/remote-client/host.ts +8 -5
- package/src/remote-client/packages.ts +20 -6
- package/src/remote-client/pi-1.2-bridge.ts +60 -0
- package/src/remote-client/session-browser.ts +5 -2
package/README.md
CHANGED
|
@@ -154,8 +154,10 @@ Escape cancels that attempt and returns to the local UI. It does not stop any
|
|
|
154
154
|
remote sessions or shared SSH connection. Connection failures retain their original
|
|
155
155
|
error message; the spinner does not imply that an unreachable host is available.
|
|
156
156
|
|
|
157
|
-
Connecting opens the server's session landing page
|
|
158
|
-
session has history.
|
|
157
|
+
Connecting opens the server's session landing page after extension synchronization,
|
|
158
|
+
including when the local session has history. The browser takes over a clean native
|
|
159
|
+
screen; leaving it or cancelling setup restores the local view and history.
|
|
160
|
+
Selecting an explicit `--session` attaches directly after the same extension check.
|
|
159
161
|
The landing page has **Active sessions** and **Closed sessions** tabs, with sessions
|
|
160
162
|
grouped by their full working folder. Move and Copy remain explicit actions when
|
|
161
163
|
a local conversation is available; connecting alone never authorizes a transfer.
|
|
@@ -342,24 +344,31 @@ before executing again.
|
|
|
342
344
|
|
|
343
345
|
### Package synchronization
|
|
344
346
|
|
|
345
|
-
|
|
346
|
-
configured, installed npm/git package catalog
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
`skills`, `prompts`, `themes`
|
|
350
|
-
and
|
|
347
|
+
Immediately after connecting, before the session browser opens, the client reads
|
|
348
|
+
the locally configured, installed npm/git package catalog and compares it with the
|
|
349
|
+
remote host's global catalog. It resolves npm packages to their installed exact
|
|
350
|
+
versions and git packages to full installed commit pins. The confirmation previews
|
|
351
|
+
additions and replacements, including `extensions`, `skills`, `prompts`, `themes`
|
|
352
|
+
filters and `autoload`. Declining skips synchronization and continues to the
|
|
353
|
+
browser with the installed remote catalog. Remote-only packages are retained.
|
|
351
354
|
|
|
352
355
|
Only approved package declarations are synchronized. Credentials, settings outside
|
|
353
|
-
those declarations and local extension/resource sources are not copied
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
Busy work is not aborted
|
|
356
|
+
those declarations and local extension/resource sources are not copied. Unsupported
|
|
357
|
+
local resources are summarized once, with repeated selectors collapsed rather
|
|
358
|
+
than printed as dozens of identical warnings. The approved target is the remote
|
|
359
|
+
host's global package configuration, not a workspace chosen later in the browser.
|
|
360
|
+
Trusted project declarations remain untouched and can still override global
|
|
361
|
+
packages in that workspace; manage those declarations on the remote host.
|
|
362
|
+
|
|
363
|
+
Host-level sync requires `global-package-sync-v1`. Older daemons keep their existing
|
|
364
|
+
sessions and extensions; the client reports that updates are deferred and still
|
|
365
|
+
opens the browser. Busy work is not aborted and sessions are never closed just to
|
|
366
|
+
update packages. New daemons require idle sessions and refuse concurrent runtime
|
|
367
|
+
loading or maintenance. Approved updates automatically refresh hosted runtimes and
|
|
368
|
+
connected clients. Installation stops on the first failure; earlier successful
|
|
369
|
+
installs are not rolled back, so idle runtimes are refreshed after a partial install.
|
|
370
|
+
Explicit legacy and busy refusals defer the update; other installation failures
|
|
371
|
+
remain errors rather than being reported as success.
|
|
363
372
|
|
|
364
373
|
### Verification status
|
|
365
374
|
|
package/package.json
CHANGED
package/src/cli.ts
CHANGED
|
File without changes
|
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.1.1";
|
|
8
8
|
|
|
9
9
|
export const SERVER_EXTENSION_VERSIONS: Readonly<Record<string, string>> = { "pi-better-server": SERVER_VERSION };
|
|
10
10
|
|
|
@@ -14,7 +14,7 @@ export function serverHello(identity: HelloIdentity = {}): HelloData {
|
|
|
14
14
|
const build = identity.build ?? readOwnBuild();
|
|
15
15
|
return { protocolVersion: PROTOCOL_VERSION, piVersion: PI_VERSION, extensionVersions: { ...SERVER_EXTENSION_VERSIONS },
|
|
16
16
|
...(build ? { build } : {}), ...(identity.instanceId ? { instanceId: identity.instanceId } : {}),
|
|
17
|
-
capabilities: ["native-client-v1", "package-sync-v1", "session-browser-v1", "folder-browser-v1", "session-transfer-v1", "compressed-bundle-v1", "remote-reload-v1",
|
|
17
|
+
capabilities: ["native-client-v1", "package-sync-v1", "global-package-sync-v1", "session-browser-v1", "folder-browser-v1", "session-transfer-v1", "compressed-bundle-v1", "remote-reload-v1",
|
|
18
18
|
...(identity.safeUpgrade && build && identity.instanceId ? ["safe-upgrade-v1"] : [])] };
|
|
19
19
|
}
|
|
20
20
|
|
package/src/remote-cli.ts
CHANGED
|
File without changes
|
|
@@ -132,7 +132,7 @@ export async function chooseConnectionTransfer(ui: Pick<ExtensionUIContext, "sel
|
|
|
132
132
|
}
|
|
133
133
|
|
|
134
134
|
/** The browser's creation context is not a constraint on existing sessions. */
|
|
135
|
-
export async function chooseRemoteSession(client: DaemonClient, ui: ExtensionUIContext, host: string, options: { cwd?: string; sessionId?: string; allowTransfer?: boolean }): Promise<RemoteSessionChoice | undefined> {
|
|
135
|
+
export async function chooseRemoteSession(client: DaemonClient, ui: ExtensionUIContext, host: string, options: { cwd?: string; sessionId?: string; allowTransfer?: boolean; notice?: string }): Promise<RemoteSessionChoice | undefined> {
|
|
136
136
|
if (options.sessionId) {
|
|
137
137
|
const sessionId = options.sessionId;
|
|
138
138
|
const result = await showRemoteProgress(ui, host, "Finding remote session...", () => resolveSession(client, sessionId));
|
|
@@ -150,11 +150,10 @@ export async function chooseRemoteSession(client: DaemonClient, ui: ExtensionUIC
|
|
|
150
150
|
creationCwd = root;
|
|
151
151
|
}
|
|
152
152
|
const choice = await browseRemoteSessions(ui, client, host, {
|
|
153
|
-
cwd: creationCwd, allowTransfer: options.allowTransfer,
|
|
153
|
+
cwd: creationCwd, allowTransfer: options.allowTransfer, notice: options.notice,
|
|
154
154
|
selectFolder: initialPath => {
|
|
155
155
|
if (client.server && !client.server.capabilities?.includes("folder-browser-v1")) {
|
|
156
|
-
|
|
157
|
-
return Promise.resolve(undefined);
|
|
156
|
+
return Promise.reject(new Error("Update pi-better-server on the remote host to browse or create folders. Existing sessions are still available."));
|
|
158
157
|
}
|
|
159
158
|
return browseRemoteFolders(ui, client, host, initialPath);
|
|
160
159
|
},
|
|
@@ -165,11 +164,12 @@ export async function chooseRemoteSession(client: DaemonClient, ui: ExtensionUIC
|
|
|
165
164
|
return choice.action === "create" ? { action: "create", cwd } : { action: "transfer", copy: choice.copy, cwd };
|
|
166
165
|
}
|
|
167
166
|
|
|
168
|
-
async function connectHost(options: RemoteOptions, local: LocalFrontend): Promise<void> {
|
|
167
|
+
export async function connectHost(options: RemoteOptions, local: LocalFrontend): Promise<void> {
|
|
169
168
|
const { ui, bridge } = local;
|
|
170
169
|
let target: Target | undefined;
|
|
171
170
|
let client: DaemonClient | undefined;
|
|
172
171
|
let attached = false;
|
|
172
|
+
let endBrowse: (() => void) | undefined;
|
|
173
173
|
const closeInitialTransport = async () => {
|
|
174
174
|
const initialClient = client;
|
|
175
175
|
const initialTarget = target;
|
|
@@ -214,36 +214,34 @@ async function connectHost(options: RemoteOptions, local: LocalFrontend): Promis
|
|
|
214
214
|
target = setup.target;
|
|
215
215
|
client = setup.client;
|
|
216
216
|
remoteDir = target.serverDir ?? remoteDir;
|
|
217
|
+
endBrowse = bridge.beginBrowse();
|
|
217
218
|
await rememberRemoteHost(options.host, remoteDir).catch((error) => ui.notify(`Could not remember remote host: ${error instanceof Error ? error.message : String(error)}`, "warning"));
|
|
219
|
+
const notices: string[] = [];
|
|
218
220
|
if (deferredUpgrade) {
|
|
221
|
+
notices.push("Server update deferred; the current daemon and its sessions were left running.");
|
|
219
222
|
const safe = client.server?.capabilities?.includes("safe-upgrade-v1");
|
|
220
223
|
ui.notify(safe ? `Server update staged; activation is deferred. ${deferredUpgrade}`
|
|
221
224
|
: `Server update staged. The current daemon cannot perform a verified automatic handoff and was left running. ${deferredUpgrade}`, safe ? "info" : "warning");
|
|
222
225
|
}
|
|
223
226
|
let connection = client;
|
|
224
227
|
ui.setStatus("pi-remote", `SSH: ${options.host} (sessions)`);
|
|
228
|
+
if (!await syncPackages(connection, local, undefined, { scope: "global", host: options.host, onNotice: message => notices.push(message) })) return;
|
|
225
229
|
let choice: Exclude<RemoteSessionChoice, { action: "transfer" }> | undefined;
|
|
226
|
-
let transferred = false;
|
|
227
230
|
for (;;) {
|
|
228
|
-
const selected = await chooseRemoteSession(connection, ui, options.host, { ...options, allowTransfer: !!local.localSession });
|
|
231
|
+
const selected = await chooseRemoteSession(connection, ui, options.host, { ...options, allowTransfer: !!local.localSession, notice: notices.join(" ") });
|
|
229
232
|
if (!selected || selected.action !== "transfer") { choice = selected; break; }
|
|
230
233
|
const transferChoice = await chooseConnectionTransfer(ui, selected.copy);
|
|
231
234
|
if (!transferChoice || transferChoice === "browse") continue;
|
|
232
235
|
const result = await runRemoteTransfer({
|
|
233
236
|
direction: "push", host: options.host, remoteDir,
|
|
234
237
|
copy: transferChoice.copy, includeWorkspace: transferChoice.includeWorkspace, cwd: selected.cwd,
|
|
235
|
-
}, { ui, cwd: local.cwd, localSession: local.localSession, resolveTarget: local.dependencies.resolveTarget
|
|
236
|
-
beforeTransfer: async (client, destination) => {
|
|
237
|
-
if (!await syncPackages(client, local, destination)) throw new Error("Remote extension check cancelled; no transfer was started.");
|
|
238
|
-
} });
|
|
238
|
+
}, { ui, cwd: local.cwd, localSession: local.localSession, resolveTarget: local.dependencies.resolveTarget });
|
|
239
239
|
if (!result) continue;
|
|
240
240
|
choice = { action: "attach", cwd: result.cwd, sessionId: result.sessionId };
|
|
241
|
-
transferred = true;
|
|
242
241
|
break;
|
|
243
242
|
}
|
|
244
243
|
if (!choice) return;
|
|
245
244
|
let cwd = choice.cwd;
|
|
246
|
-
if (!transferred && !await syncPackages(connection, local, cwd)) return;
|
|
247
245
|
let sessionId = choice.action === "attach" ? choice.sessionId : "";
|
|
248
246
|
const selectedChoice = choice;
|
|
249
247
|
const opened = await showRemoteProgress(ui, options.host, choice.action === "create" ? "Starting remote session..." : "Opening remote session...", async (): Promise<RemoteClientSession> => {
|
|
@@ -293,11 +291,13 @@ async function connectHost(options: RemoteOptions, local: LocalFrontend): Promis
|
|
|
293
291
|
const dispose = remote.dispose.bind(remote);
|
|
294
292
|
remote.dispose = () => { dispose(); void closeInitialTransport().catch(() => undefined); };
|
|
295
293
|
await bridge.attach(remote);
|
|
294
|
+
endBrowse = undefined;
|
|
296
295
|
attached = true;
|
|
297
296
|
ui.setStatus("pi-remote", `SSH: ${options.host}`);
|
|
298
297
|
ui.notify(`Attached to ${options.host}:${cwd}. /remote opens the server's sessions; /remote disconnect returns locally.`, "info");
|
|
299
298
|
} finally {
|
|
300
|
-
|
|
299
|
+
try { endBrowse?.(); }
|
|
300
|
+
finally { if (!attached) { await closeInitialTransport(); ui.setStatus("pi-remote", undefined); } }
|
|
301
301
|
}
|
|
302
302
|
}
|
|
303
303
|
|
|
@@ -340,15 +340,33 @@ export async function pullAttachedSession(
|
|
|
340
340
|
return result;
|
|
341
341
|
}
|
|
342
342
|
|
|
343
|
-
export async function syncPackages(
|
|
343
|
+
export async function syncPackages(
|
|
344
|
+
client: DaemonClient, local: Pick<LocalFrontend, "cwd" | "ui">, cwd?: string,
|
|
345
|
+
options: { scope?: "global"; host?: string; onNotice?: (message: string) => void } = {},
|
|
346
|
+
): Promise<boolean> {
|
|
344
347
|
const { ui } = local;
|
|
345
|
-
const
|
|
348
|
+
const notice = (message: string) => {
|
|
349
|
+
if (options.onNotice) options.onNotice(message);
|
|
350
|
+
else ui.notify(message, "warning");
|
|
351
|
+
};
|
|
352
|
+
const host = options.host ?? "Remote";
|
|
353
|
+
const global = options.scope === "global";
|
|
354
|
+
if (global && client.server && !client.server.capabilities?.includes("global-package-sync-v1")) {
|
|
355
|
+
notice("Extension sync deferred: this daemon does not support safe host-level updates. Existing sessions were left running; continuing with installed extensions.");
|
|
356
|
+
return true;
|
|
357
|
+
}
|
|
358
|
+
const target = global ? { scope: "global" } : { cwd };
|
|
359
|
+
const catalogs = await showRemoteProgress(ui, host, global ? "Checking remote extensions..." : "Checking workspace extensions...", async () => ({
|
|
346
360
|
localCatalog: await readLocalPackageCatalog(undefined, local.cwd),
|
|
347
|
-
remote: (await client.call({ type: "client_packages",
|
|
361
|
+
remote: (await client.call({ type: "client_packages", ...target })).data as PackageCatalog,
|
|
348
362
|
}));
|
|
349
363
|
if (!catalogs) return false;
|
|
350
364
|
const { localCatalog, remote } = catalogs.value;
|
|
351
|
-
|
|
365
|
+
const unsupported = [...new Set(localCatalog.unsupported)];
|
|
366
|
+
if (unsupported.length) {
|
|
367
|
+
const visible = unsupported.slice(0, 3).map(value => value.replace(/[\x00-\x1f\x7f-\x9f]/g, " ").slice(0, 100));
|
|
368
|
+
notice(`Local-only resources are not synced: ${visible.join(", ")}${unsupported.length > visible.length ? ` (+${unsupported.length - visible.length} more)` : ""}.`);
|
|
369
|
+
}
|
|
352
370
|
const plan = planPackageSync(localCatalog.packages, remote.packages);
|
|
353
371
|
const changes = [...plan.install];
|
|
354
372
|
for (const conflict of plan.conflicts ?? []) {
|
|
@@ -359,9 +377,19 @@ export async function syncPackages(client: DaemonClient, local: Pick<LocalFronte
|
|
|
359
377
|
...plan.install.map((entry) => `Install: ${JSON.stringify(entry)}`),
|
|
360
378
|
...(plan.conflicts ?? []).map((entry) => `Replace: ${JSON.stringify(entry.remote)}\nWith: ${JSON.stringify(entry.local)}`),
|
|
361
379
|
].join("\n\n");
|
|
362
|
-
const
|
|
380
|
+
const targetLabel = global ? "Target: remote host global extensions" : `Target workspace: ${cwd}`;
|
|
381
|
+
const approved = await ui.confirm("Sync remote extensions?", `${targetLabel}\n\n${preview}\n\nOnly these package declarations are synced. Credentials, provider settings, and local extension source are not copied. Remote-only packages are kept. Trusted project overrides must be managed on the remote host.`);
|
|
363
382
|
if (!approved) return true;
|
|
364
|
-
|
|
383
|
+
try {
|
|
384
|
+
await showRemoteProgress(ui, host, "Installing approved remote extensions...", () => client.call({ type: "client_packages_install", ...target, packages: changes }), { cancellable: false });
|
|
385
|
+
} catch (error) {
|
|
386
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
387
|
+
const deferred = /^Close remote daemon sessions before updating extensions[;.]/.test(message)
|
|
388
|
+
|| /^Wait for remote (?:model|work|dialogs|activity observation)\b/.test(message)
|
|
389
|
+
|| /^Remote session (?:operations are already|maintenance is) in progress(?:[;. ]|$)/.test(message);
|
|
390
|
+
if (!deferred) throw error;
|
|
391
|
+
notice("Extension update deferred by the remote daemon. No sessions were closed; continuing with installed extensions. Retry when remote work is idle or after migrating the legacy daemon.");
|
|
392
|
+
}
|
|
365
393
|
return true;
|
|
366
394
|
}
|
|
367
395
|
|
|
@@ -103,15 +103,18 @@ export class NativeClientHost {
|
|
|
103
103
|
}
|
|
104
104
|
return { root, workspaces: workspaces.sort((a, b) => a.name.localeCompare(b.name)) };
|
|
105
105
|
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
106
|
+
if (command.scope !== undefined && command.scope !== "global") throw new Error("Unknown package scope");
|
|
107
|
+
const global = command.scope === "global";
|
|
108
|
+
const cwd = global ? undefined : command.cwd === undefined ? process.cwd() : command.cwd;
|
|
109
|
+
if (!global && (typeof cwd !== "string" || !isAbsolute(cwd) || !(await stat(cwd)).isDirectory())) throw new Error("cwd must be an existing absolute remote workspace directory");
|
|
110
|
+
const catalog = () => readLocalPackageCatalog(getAgentDir(), cwd as string | undefined, { scope: global ? "global" : "workspace" });
|
|
111
|
+
if (command.type === "client_packages") return catalog();
|
|
109
112
|
if (command.type !== "client_packages_install") throw new Error("Unknown native client host command");
|
|
110
113
|
if (!Array.isArray(command.packages)) throw new Error("packages must be an array of pinned Pi package specifications");
|
|
111
114
|
return this.registry.maintenance.withIdleSessions("packages", async (live, maintenance) => {
|
|
112
115
|
let installError: unknown;
|
|
113
116
|
try {
|
|
114
|
-
await installPackageCatalog(command.packages as PackageSpec[], { agentDir: getAgentDir(), cwd });
|
|
117
|
+
await installPackageCatalog(command.packages as PackageSpec[], { agentDir: getAgentDir(), ...(global ? {} : { cwd: cwd as string }) });
|
|
115
118
|
} catch (error) { installError = error; }
|
|
116
119
|
// Pi mutates process-wide provider registrations, so reload serially under a
|
|
117
120
|
// fresh global idle check, including providers registered by preceding reloads.
|
|
@@ -121,7 +124,7 @@ export class NativeClientHost {
|
|
|
121
124
|
throw reloadError;
|
|
122
125
|
}
|
|
123
126
|
if (installError) throw installError;
|
|
124
|
-
return
|
|
127
|
+
return catalog();
|
|
125
128
|
});
|
|
126
129
|
}
|
|
127
130
|
}
|
|
@@ -145,15 +145,25 @@ function identity(value: unknown): string | undefined {
|
|
|
145
145
|
|
|
146
146
|
function unsupportedLabel(value: unknown): string {
|
|
147
147
|
const source = typeof value === "string" ? value : value && typeof value === "object" ? (value as PackageSpec).source : undefined;
|
|
148
|
-
if (typeof source !== "string" || /[\
|
|
149
|
-
if (/^(?:\.\.?\/|\/|~\/)/.test(source)) return source;
|
|
148
|
+
if (typeof source !== "string" || /[\p{C}]/u.test(source)) return "[unsupported package source]";
|
|
149
|
+
if (/^(?:\.\.?\/|\/|~\/)/.test(source) && /^[\p{L}\p{M}\p{N}._~@/ -]+$/u.test(source)) return source;
|
|
150
150
|
try { parse(source); return source; } catch { return "[unsupported package source]"; }
|
|
151
151
|
}
|
|
152
152
|
|
|
153
|
-
function
|
|
153
|
+
function resourceLabel(value: unknown): string {
|
|
154
|
+
// Resource paths and selectors are not package declarations or installable sources.
|
|
155
|
+
if (typeof value === "string" && /^[\p{L}\p{M}\p{N}._~@/ !+*?\[\]{},()-]+$/u.test(value)) {
|
|
156
|
+
if (/^[!+-]|[\*?]/.test(value)) return "[local resource selectors]";
|
|
157
|
+
return value;
|
|
158
|
+
}
|
|
159
|
+
return unsupportedLabel(value);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function readPackageSettings(agentDir: string, cwd: string, scope: "global" | "workspace" = "workspace") {
|
|
154
163
|
const manager = SettingsManager.create(cwd, agentDir, { projectTrusted: false });
|
|
155
164
|
const errors = manager.drainErrors();
|
|
156
165
|
if (errors.length) throw new Error("Cannot read Pi package settings", { cause: errors[0]!.error });
|
|
166
|
+
if (scope === "global") return { global: manager.getGlobalSettings(), project: {} };
|
|
157
167
|
const trusted = new ProjectTrustStore(agentDir).get(cwd) ?? (manager.getDefaultProjectTrust() === "always");
|
|
158
168
|
if (trusted) manager.setProjectTrusted(true);
|
|
159
169
|
if (manager.drainErrors().length) throw new Error("Cannot read trusted project package settings");
|
|
@@ -163,17 +173,20 @@ function readPackageSettings(agentDir: string, cwd: string) {
|
|
|
163
173
|
/** Reads only package declarations, never auth, environment, or resource contents.
|
|
164
174
|
* Session-only trust overrides are not discoverable here. A host with resolved
|
|
165
175
|
* session state should prefer its own pinned PackageSpec[] over rediscovery.
|
|
176
|
+
* Global scope skips project settings and trust entirely; workspace is the default.
|
|
166
177
|
*/
|
|
167
|
-
export async function readLocalPackageCatalog(
|
|
178
|
+
export async function readLocalPackageCatalog(
|
|
179
|
+
agentDir = getAgentDir(), cwd = process.cwd(), options: { scope?: "global" | "workspace" } = {},
|
|
180
|
+
): Promise<PackageCatalog> {
|
|
168
181
|
agentDir = resolve(agentDir);
|
|
169
182
|
cwd = resolve(cwd);
|
|
170
|
-
const { global, project } = readPackageSettings(agentDir, cwd);
|
|
183
|
+
const { global, project } = readPackageSettings(agentDir, cwd, options.scope);
|
|
171
184
|
const selected = new Map<string, { value: unknown; base: string; layered: boolean }>();
|
|
172
185
|
const catalog: PackageCatalog = { packages: [], unsupported: [] };
|
|
173
186
|
for (const [settings, base] of [[global, agentDir], [project, join(cwd, ".pi")]] as const) {
|
|
174
187
|
for (const key of resources) {
|
|
175
188
|
const paths = settings[key];
|
|
176
|
-
if (Array.isArray(paths)) for (const path of paths) catalog.unsupported.push(
|
|
189
|
+
if (Array.isArray(paths)) for (const path of paths) catalog.unsupported.push(resourceLabel(path));
|
|
177
190
|
}
|
|
178
191
|
for (const value of entries(settings as Record<string, unknown>)) {
|
|
179
192
|
const key = identity(value);
|
|
@@ -206,6 +219,7 @@ export async function readLocalPackageCatalog(agentDir = getAgentDir(), cwd = pr
|
|
|
206
219
|
catalog.unsupported.push(unsupportedLabel(value));
|
|
207
220
|
}
|
|
208
221
|
}
|
|
222
|
+
catalog.unsupported = [...new Set(catalog.unsupported)];
|
|
209
223
|
return catalog;
|
|
210
224
|
}
|
|
211
225
|
|
|
@@ -14,6 +14,10 @@ import { InteractiveMode, VERSION } from "@earendil-works/pi-coding-agent";
|
|
|
14
14
|
* New/fork/tree/clone/resume/import are intentionally unavailable remotely.
|
|
15
15
|
*/
|
|
16
16
|
export interface Pi12Bridge {
|
|
17
|
+
/** Screen-only scope. Call after connecting, before sync/browser; clean up in finally.
|
|
18
|
+
* Idempotent cleanup restores local mounts; attach also ends the scope itself.
|
|
19
|
+
*/
|
|
20
|
+
beginBrowse(): () => void;
|
|
17
21
|
attach(remoteSession: unknown): Promise<void>;
|
|
18
22
|
disconnect(): Promise<void>;
|
|
19
23
|
readonly mode?: unknown;
|
|
@@ -139,6 +143,7 @@ class Controller implements Pi12Bridge {
|
|
|
139
143
|
private local: { manager: Native; cwd: string; agentDir: string } | undefined;
|
|
140
144
|
private changing = false;
|
|
141
145
|
private guarded = false;
|
|
146
|
+
private endBrowse: (() => void) | undefined;
|
|
142
147
|
private readonly restores: (() => void)[] = [];
|
|
143
148
|
|
|
144
149
|
readonly mode: Native;
|
|
@@ -166,6 +171,54 @@ class Controller implements Pi12Bridge {
|
|
|
166
171
|
methods(object(this.mode.programStatus, "InteractiveMode.programStatus"), ["reset"], "programStatus");
|
|
167
172
|
}
|
|
168
173
|
|
|
174
|
+
private checkScreen(): void {
|
|
175
|
+
const ui = object(this.mode.ui, "InteractiveMode.ui");
|
|
176
|
+
methods(ui, ["clear", "addChild", "requestRender"], "InteractiveMode.ui");
|
|
177
|
+
if (!Array.isArray(ui.children)) throw failure("InteractiveMode.ui.children is missing.");
|
|
178
|
+
methods(object(this.mode.editorContainer, "InteractiveMode.editorContainer"), ["render"], "editorContainer");
|
|
179
|
+
const header = object(this.mode.headerContainer, "InteractiveMode.headerContainer");
|
|
180
|
+
methods(header, ["render"], "headerContainer");
|
|
181
|
+
writable(header, "render");
|
|
182
|
+
if (ui.mode === "fullscreen") {
|
|
183
|
+
methods(ui, ["setLayoutRoot"], "InteractiveMode.ui");
|
|
184
|
+
object(this.mode.fullscreenLayoutRoot, "InteractiveMode.fullscreenLayoutRoot");
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
beginBrowse(): () => void {
|
|
189
|
+
if (this.changing || this.remote || this.local || this.endBrowse) {
|
|
190
|
+
throw failure("cannot begin browsing during another browse or session replacement.");
|
|
191
|
+
}
|
|
192
|
+
if (!this.mode.isInitialized) throw failure("the interactive UI has not finished starting.");
|
|
193
|
+
this.checkScreen();
|
|
194
|
+
const ui = this.mode.ui as Native;
|
|
195
|
+
const roots = [...ui.children];
|
|
196
|
+
const layoutRoot = this.mode.fullscreenLayoutRoot;
|
|
197
|
+
let active = true;
|
|
198
|
+
const cleanup = () => {
|
|
199
|
+
if (!active) return;
|
|
200
|
+
active = false;
|
|
201
|
+
this.endBrowse = undefined;
|
|
202
|
+
ui.clear();
|
|
203
|
+
for (const root of roots) ui.addChild(root);
|
|
204
|
+
if (ui.mode === "fullscreen") ui.setLayoutRoot(layoutRoot);
|
|
205
|
+
ui.requestRender(true);
|
|
206
|
+
};
|
|
207
|
+
this.endBrowse = cleanup;
|
|
208
|
+
try {
|
|
209
|
+
// Native custom/select/input screens all use this container. Unmount the
|
|
210
|
+
// surrounding local view, not its children or its still-live runtime.
|
|
211
|
+
ui.clear();
|
|
212
|
+
ui.addChild(this.mode.editorContainer);
|
|
213
|
+
if (ui.mode === "fullscreen") ui.setLayoutRoot(this.mode.editorContainer);
|
|
214
|
+
ui.requestRender(true);
|
|
215
|
+
} catch (error) {
|
|
216
|
+
cleanup();
|
|
217
|
+
throw error;
|
|
218
|
+
}
|
|
219
|
+
return cleanup;
|
|
220
|
+
}
|
|
221
|
+
|
|
169
222
|
private warning(operation: string): { cancelled: true } {
|
|
170
223
|
const guidance = operation === "/settings"
|
|
171
224
|
? "Use /model or /thinking for supported remote controls. Disconnect /remote to change local settings."
|
|
@@ -186,6 +239,9 @@ class Controller implements Pi12Bridge {
|
|
|
186
239
|
private guard(): void {
|
|
187
240
|
if (this.guarded) return;
|
|
188
241
|
this.guarded = true;
|
|
242
|
+
// Native renderCurrentSessionState clears chat/resources, but retains the
|
|
243
|
+
// startup header. Hide its rendering only for the remote attachment.
|
|
244
|
+
this.replace(this.mode.headerContainer, "render", () => []);
|
|
189
245
|
for (const [name, command] of Object.entries(blockedUi)) {
|
|
190
246
|
this.replace(this.mode, name, () => this.warning(command));
|
|
191
247
|
}
|
|
@@ -367,6 +423,7 @@ class Controller implements Pi12Bridge {
|
|
|
367
423
|
if (this.remote === remoteSession) return;
|
|
368
424
|
if (this.remote || this.local) throw failure("disconnect the current remote session before attaching another.");
|
|
369
425
|
this.checkHost();
|
|
426
|
+
this.checkScreen();
|
|
370
427
|
if (!this.mode.isInitialized) throw failure("the interactive UI has not finished starting.");
|
|
371
428
|
const remote = object(remoteSession, "RemoteSession");
|
|
372
429
|
const local = object(this.host.session, "local session");
|
|
@@ -391,6 +448,7 @@ class Controller implements Pi12Bridge {
|
|
|
391
448
|
}
|
|
392
449
|
}
|
|
393
450
|
if (local.isBashRunning) throw failure("wait for the local ! command to finish before connecting.");
|
|
451
|
+
this.endBrowse?.();
|
|
394
452
|
this.local = { manager: local.sessionManager, cwd: this.host.cwd, agentDir: this.host.services.agentDir };
|
|
395
453
|
this.changing = true;
|
|
396
454
|
this.guard();
|
|
@@ -408,6 +466,7 @@ class Controller implements Pi12Bridge {
|
|
|
408
466
|
this.host.apply({ session: this.remoteView(remote), services: this.host.services, diagnostics: [], modelFallbackMessage: undefined });
|
|
409
467
|
this.state.managers.set(remote.sessionManager, this);
|
|
410
468
|
await this.host.finishSessionReplacement();
|
|
469
|
+
this.mode.ui.requestRender(true);
|
|
411
470
|
} catch (error) {
|
|
412
471
|
// Teardown can fail before its final dispose (for example during UI
|
|
413
472
|
// cleanup). Never leave that outgoing executor live during recovery.
|
|
@@ -465,6 +524,7 @@ class Controller implements Pi12Bridge {
|
|
|
465
524
|
try {
|
|
466
525
|
await this.host.finishSessionReplacement();
|
|
467
526
|
this.local = undefined;
|
|
527
|
+
this.mode.ui.requestRender(true);
|
|
468
528
|
} catch (error) {
|
|
469
529
|
this.guard();
|
|
470
530
|
await this.host.teardownCurrent("resume");
|
|
@@ -11,6 +11,7 @@ export type RemoteSessionBrowserIntent = RemoteSessionBrowserResult | { action:
|
|
|
11
11
|
interface BrowserOptions {
|
|
12
12
|
cwd?: string;
|
|
13
13
|
loading?: string;
|
|
14
|
+
notice?: string;
|
|
14
15
|
allowTransfer?: boolean;
|
|
15
16
|
selectFolder?: (initialPath: string) => Promise<string | undefined>;
|
|
16
17
|
}
|
|
@@ -121,14 +122,16 @@ export class RemoteSessionBrowser implements Component {
|
|
|
121
122
|
...wrapTextWithAnsi(`cwd: ${singleLine(selected.cwd)}`, width).slice(0, 2).map(line => theme.fg("muted", line)),
|
|
122
123
|
theme.fg("dim", fit(`ID: ${singleLine(selected.sessionId).slice(0, 8)}`)),
|
|
123
124
|
] : [];
|
|
125
|
+
let notices = this.options.notice ? wrapTextWithAnsi(singleLine(this.options.notice), width).slice(0, budget < 14 ? 1 : 2).map(line => theme.fg("warning", line)) : [];
|
|
124
126
|
const errors = this.state.error ? wrapTextWithAnsi(singleLine(this.state.error), width).slice(0, budget < 14 ? 1 : 2).map(line => theme.fg("error", line)) : [];
|
|
125
127
|
let spacious = width >= 48 && budget >= 16;
|
|
126
128
|
const gaps = () => spacious ? 3 + (details.length ? 1 : 0) : 0;
|
|
127
129
|
const minimumBody = Math.min(3, Math.max(1, rows.length));
|
|
128
|
-
const fixed = () => header.length + tabLines.length + errors.length + details.length + legend.length + gaps();
|
|
130
|
+
const fixed = () => header.length + tabLines.length + notices.length + errors.length + details.length + legend.length + gaps();
|
|
129
131
|
const scrollRoom = rows.length > minimumBody ? 1 : 0;
|
|
130
132
|
if (fixed() + minimumBody + scrollRoom > budget) details = [];
|
|
131
133
|
if (fixed() + minimumBody + scrollRoom > budget) spacious = false;
|
|
134
|
+
if (fixed() + minimumBody + scrollRoom > budget) notices = [];
|
|
132
135
|
while (header.length && fixed() + minimumBody + scrollRoom > budget) header.pop();
|
|
133
136
|
const available = Math.max(0, budget - fixed());
|
|
134
137
|
const unreservedHeight = Math.min(10, available);
|
|
@@ -168,7 +171,7 @@ export class RemoteSessionBrowser implements Component {
|
|
|
168
171
|
}
|
|
169
172
|
const scrolling = entries.length > bodyHeight && bodyHeight > 0 && available > 1 ? [theme.fg("dim", fit(`(${selectedIndex + 1}/${rows.length})`))] : [];
|
|
170
173
|
const gap = spacious ? [""] : [];
|
|
171
|
-
return [...header, ...gap, ...tabLines, ...gap, ...errors, ...body, ...scrolling,
|
|
174
|
+
return [...header, ...gap, ...tabLines, ...gap, ...notices, ...errors, ...body, ...scrolling,
|
|
172
175
|
...(details.length ? [...gap, ...details] : []), ...gap, ...legend.map(line => theme.fg("dim", line))].slice(0, budget).map(line => fit(line));
|
|
173
176
|
}
|
|
174
177
|
|