send-to-paseo 2.6.0 → 2.6.1-beta.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/client/display.tsx +12 -17
- package/client/navigation.ts +7 -0
- package/client/settings-feed/index.ts +79 -0
- package/client/settings.tsx +2 -1
- package/index.server.ts +9 -3
- package/package.json +4 -3
- package/server/bridge.ts +5 -1
- package/server/daemon-endpoint.ts +143 -0
- package/server/daemon.ts +61 -39
- package/server/follow-up-id.ts +12 -24
- package/server/send.ts +13 -2
- package/server/settings-feed/index.ts +48 -0
- package/server/shared-daemon.ts +25 -1
- package/shared/contracts.ts +4 -1
- package/shared/display.ts +7 -0
package/client/display.tsx
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import { watchSettings } from "./settings-feed/index";
|
|
1
2
|
import type { PluginClientContext, PluginSurfaceProps } from "@getpaseo/plugin/client";
|
|
2
3
|
import { useSettings } from "@getpaseo/plugin/client";
|
|
3
4
|
import { SettingsAction, SettingsCard, SettingsSection, SettingsSwitch } from "@getpaseo/plugin/client/ui";
|
|
4
5
|
import { useEffect } from "react";
|
|
5
6
|
import { ActivityIndicator, ScrollView, Text, View } from "react-native";
|
|
6
|
-
import { displayPreferences, displayRpc } from "../shared/display";
|
|
7
|
+
import { displayFeed, displayPreferences, displayRpc } from "../shared/display";
|
|
7
8
|
import { sidebarVisibility } from "./sidebar-visibility";
|
|
8
9
|
|
|
9
10
|
const listeners = new Set<(visible: boolean) => void>();
|
|
@@ -45,7 +46,7 @@ function DisplaySettings({ theme }: PluginSurfaceProps) {
|
|
|
45
46
|
);
|
|
46
47
|
}
|
|
47
48
|
|
|
48
|
-
/**
|
|
49
|
+
/** Push settings across clients; older hosts fall back to one read a minute. */
|
|
49
50
|
export function contributeDisplay(client: PluginClientContext, item: { title: string; register: () => (() => void) | void }) {
|
|
50
51
|
const sidebar = sidebarVisibility(item.register);
|
|
51
52
|
// Paseo 0.10.1 memoizes sidebar route resolution when an installation mounts.
|
|
@@ -64,29 +65,23 @@ export function contributeDisplay(client: PluginClientContext, item: { title: st
|
|
|
64
65
|
onSelect({ openSettings }) { openSettings("display"); },
|
|
65
66
|
});
|
|
66
67
|
let disposed = false;
|
|
67
|
-
let pending = false;
|
|
68
68
|
let generation = 0;
|
|
69
69
|
const update = (visible: boolean) => { generation += 1; sidebar.set(visible); };
|
|
70
70
|
listeners.add(update);
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
if (!disposed && generation === currentGeneration && result.status === "ready") {
|
|
71
|
+
const feed = watchSettings({
|
|
72
|
+
client, contract: displayFeed,
|
|
73
|
+
revision: () => generation,
|
|
74
|
+
read: () => client.rpc(displayRpc.read, {}),
|
|
75
|
+
apply: result => {
|
|
76
|
+
if (!disposed && result.status === "ready") {
|
|
78
77
|
const parsed = displayPreferences.schema.safeParse(result.values);
|
|
79
78
|
if (parsed.success) sidebar.set(parsed.data.showSidebar);
|
|
80
79
|
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
} finally { pending = false; }
|
|
84
|
-
};
|
|
85
|
-
void refresh();
|
|
86
|
-
const timer = setInterval(() => void refresh(), 5000);
|
|
80
|
+
},
|
|
81
|
+
});
|
|
87
82
|
return () => {
|
|
88
83
|
disposed = true;
|
|
89
|
-
|
|
84
|
+
feed.stop();
|
|
90
85
|
listeners.delete(update);
|
|
91
86
|
sidebar.dispose();
|
|
92
87
|
removeSurface();
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { PluginSurfaceProps } from "@getpaseo/plugin/client";
|
|
2
|
+
|
|
3
|
+
/** Open a recent send on its own host. */
|
|
4
|
+
export function openSettingsAgent(navigation: PluginSurfaceProps["navigation"], serverId: string, agentId: string): void {
|
|
5
|
+
const target = navigation as (NonNullable<PluginSurfaceProps["navigation"]> & { supportsFocusHost?: boolean }) | undefined;
|
|
6
|
+
target?.openAgent({ agentId, serverId, ...(target.supportsFocusHost === true ? { focusHost: true } : {}) });
|
|
7
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// Vendored from paseo-plugin-kit v0.4.0-beta.0 (settings-feed-client/index.ts). Do not edit; change the kit and run `paseo-kit vendor settings-feed-client <dir>`.
|
|
2
|
+
/** Push settings on current hosts; read once a minute while a feed is unavailable. */
|
|
3
|
+
type Handle = (() => void) & { ready?: Promise<unknown> };
|
|
4
|
+
type Clock = Pick<typeof globalThis, "setTimeout" | "clearTimeout" | "setInterval" | "clearInterval">;
|
|
5
|
+
type Timer = ReturnType<typeof setTimeout>;
|
|
6
|
+
|
|
7
|
+
export function watchSettings<Document>(o: {
|
|
8
|
+
client: unknown;
|
|
9
|
+
contract: unknown;
|
|
10
|
+
read(): Promise<Document>;
|
|
11
|
+
apply(document: Document): void;
|
|
12
|
+
/** Changes from this client's settings screen invalidate an older RPC read. */
|
|
13
|
+
revision?: () => number;
|
|
14
|
+
clock?: Clock;
|
|
15
|
+
}): { stop(): void } {
|
|
16
|
+
const clock = o.clock ?? globalThis;
|
|
17
|
+
const client = o.client as { subscribe?: (contract: unknown, input: object, event: (document: Document) => void, options: { onClosed(): void }) => Handle };
|
|
18
|
+
let stopped = false, pending = false, live = true, attempt = 0, generation = 0, eventRevision = 0;
|
|
19
|
+
let poll: Timer | undefined, retry: Timer | undefined, steady: Timer | undefined, handle: Handle | undefined;
|
|
20
|
+
const read = async () => {
|
|
21
|
+
if (stopped || pending) return;
|
|
22
|
+
pending = true;
|
|
23
|
+
const current = eventRevision, revision = o.revision?.();
|
|
24
|
+
try {
|
|
25
|
+
const document = await o.read();
|
|
26
|
+
if (!stopped && current === eventRevision && revision === o.revision?.()) o.apply(document);
|
|
27
|
+
} catch { /* Keep the last valid setting through a disconnect. */ }
|
|
28
|
+
finally { pending = false; }
|
|
29
|
+
};
|
|
30
|
+
const stopPoll = () => { if (poll !== undefined) clock.clearInterval(poll); poll = undefined; };
|
|
31
|
+
const startPoll = () => {
|
|
32
|
+
if (poll !== undefined || stopped) return;
|
|
33
|
+
void read();
|
|
34
|
+
poll = clock.setInterval(() => void read(), 60_000);
|
|
35
|
+
};
|
|
36
|
+
const clearSteady = () => { if (steady !== undefined) clock.clearTimeout(steady); steady = undefined; };
|
|
37
|
+
const release = (h: Handle | undefined) => { try { h?.(); } catch { /* Already closed. */ } };
|
|
38
|
+
const start = () => {
|
|
39
|
+
retry = undefined;
|
|
40
|
+
if (stopped) return;
|
|
41
|
+
const mine = ++generation;
|
|
42
|
+
const closed = () => {
|
|
43
|
+
if (stopped || mine !== generation) return;
|
|
44
|
+
generation++; clearSteady();
|
|
45
|
+
const old = handle; handle = undefined; release(old);
|
|
46
|
+
const wasLive = live; live = false;
|
|
47
|
+
const delay = attempt < 15 ? 1_000 : Math.min(30_000, 1_000 * 2 ** Math.min(5, attempt - 14));
|
|
48
|
+
attempt++;
|
|
49
|
+
retry = clock.setTimeout(start, delay);
|
|
50
|
+
if (wasLive) startPoll();
|
|
51
|
+
};
|
|
52
|
+
try {
|
|
53
|
+
const h = client.subscribe!.call(o.client, o.contract, {}, document => {
|
|
54
|
+
if (!stopped && mine === generation) { eventRevision++; o.apply(document); }
|
|
55
|
+
}, { onClosed: closed });
|
|
56
|
+
if (stopped || mine !== generation) { release(h); return; }
|
|
57
|
+
handle = h;
|
|
58
|
+
Promise.resolve(h.ready).then(() => {
|
|
59
|
+
if (stopped || mine !== generation) return;
|
|
60
|
+
clearSteady();
|
|
61
|
+
// Acknowledgement followed by immediate closure must not restart RPC polling every second.
|
|
62
|
+
steady = clock.setTimeout(() => {
|
|
63
|
+
steady = undefined;
|
|
64
|
+
if (stopped || mine !== generation) return;
|
|
65
|
+
live = true; attempt = 0; stopPoll();
|
|
66
|
+
}, 30_000);
|
|
67
|
+
}, closed);
|
|
68
|
+
} catch { closed(); }
|
|
69
|
+
};
|
|
70
|
+
if (typeof client?.subscribe === "function") start();
|
|
71
|
+
else startPoll();
|
|
72
|
+
return { stop() {
|
|
73
|
+
if (stopped) return;
|
|
74
|
+
stopped = true; generation++;
|
|
75
|
+
stopPoll(); clearSteady();
|
|
76
|
+
if (retry !== undefined) clock.clearTimeout(retry);
|
|
77
|
+
release(handle); handle = undefined;
|
|
78
|
+
} };
|
|
79
|
+
}
|
package/client/settings.tsx
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { openSettingsAgent } from "./navigation";
|
|
1
2
|
import type { PluginTheme } from "@getpaseo/plugin";
|
|
2
3
|
import {
|
|
3
4
|
getPaseoClient,
|
|
@@ -763,7 +764,7 @@ export function SendToPaseoSettings({ theme, host, layout, navigation }: PluginS
|
|
|
763
764
|
onCopyToken={() => void onCopy()}
|
|
764
765
|
detailsOpen={showConnectionDetails}
|
|
765
766
|
onToggleDetails={() => setShowConnectionDetails(!showConnectionDetails)}
|
|
766
|
-
onOpenAgent={navigation === undefined ? null : (agentId) => navigation
|
|
767
|
+
onOpenAgent={navigation === undefined ? null : (agentId) => openSettingsAgent(navigation, host.id, agentId)}
|
|
767
768
|
onClear={() => void clearRecent({ serverId: host.id }).then(invalidate)}
|
|
768
769
|
/>
|
|
769
770
|
)}
|
package/index.server.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { registerSettingsFeed } from "./server/settings-feed/index";
|
|
1
2
|
import { contributeAgentTools } from "./server/native-tools";
|
|
2
|
-
import { displayPreferences } from "./shared/display";
|
|
3
|
+
import { displayFeed, displayPreferences } from "./shared/display";
|
|
3
4
|
import type { PluginServerContext } from "@getpaseo/plugin/server";
|
|
4
5
|
import {
|
|
5
6
|
addAdditionalMachine,
|
|
@@ -37,7 +38,7 @@ import { requireServerTarget } from "./server/target";
|
|
|
37
38
|
|
|
38
39
|
export default function contribute(server: PluginServerContext) {
|
|
39
40
|
const removeTools = contributeAgentTools(server);
|
|
40
|
-
server.registerSettings(displayPreferences);
|
|
41
|
+
const stopDisplayFeed = registerSettingsFeed(server, displayFeed, server.registerSettings(displayPreferences));
|
|
41
42
|
server.handle(getStatus, async ({ serverId }, { paseo }) => {
|
|
42
43
|
await requireServerTarget(serverId);
|
|
43
44
|
const current = await settings.read();
|
|
@@ -182,5 +183,10 @@ export default function contribute(server: PluginServerContext) {
|
|
|
182
183
|
// Connect now, not on the first popover: the click path never pays for a daemon connect (warm-daemon-connection).
|
|
183
184
|
warmDaemon();
|
|
184
185
|
// The held daemon connection closes after the bridge has stopped serving requests.
|
|
185
|
-
return async () => {
|
|
186
|
+
return async () => {
|
|
187
|
+
stopDisplayFeed();
|
|
188
|
+
removeTools();
|
|
189
|
+
await stopBridge();
|
|
190
|
+
await closeDaemon();
|
|
191
|
+
};
|
|
186
192
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "send-to-paseo",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.6.
|
|
4
|
+
"version": "2.6.1-beta.1",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "Local HTTP bridge that dispatches PR work to the right Paseo workspace and agent.",
|
|
7
7
|
"repository": {
|
|
@@ -35,8 +35,8 @@
|
|
|
35
35
|
},
|
|
36
36
|
"scripts": {
|
|
37
37
|
"typecheck": "tsc --noEmit",
|
|
38
|
-
"test": "node check-deps.mjs && node --test client/hosts.test.mjs client/settings.test.mjs server/main-agent.test.mjs server/follow-up.test.mjs server/daemon-connection.test.mjs",
|
|
39
|
-
"verify": "npm run typecheck && npm test && node --test --experimental-strip-types agent-tools.test.mjs shared/chat.test.mjs && node --test native-tools.test.mjs"
|
|
38
|
+
"test": "node check-deps.mjs && node --test client/hosts.test.mjs client/settings.test.mjs server/main-agent.test.mjs server/follow-up.test.mjs server/daemon-connection.test.mjs server/daemon-endpoint.test.mjs",
|
|
39
|
+
"verify": "npm run typecheck && npm test && node --test --experimental-strip-types agent-tools.test.mjs shared/chat.test.mjs && node --test native-tools.test.mjs && node --test display-feed.test.mjs && paseo-kit vendor --check settings-feed-client client/settings-feed && paseo-kit vendor --check settings-feed-server server/settings-feed"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@getpaseo/client": "0.14.0",
|
|
@@ -46,6 +46,7 @@
|
|
|
46
46
|
"@types/node": "^22.10.2",
|
|
47
47
|
"@types/react": "~19.2.0",
|
|
48
48
|
"esbuild": "^0.28.2",
|
|
49
|
+
"paseo-plugin-kit": "github:tomgrin10/paseo-plugin-kit#v0.4.0-beta.0",
|
|
49
50
|
"react": "19.1.0",
|
|
50
51
|
"react-native": "0.81.5",
|
|
51
52
|
"typescript": "^5.9.3",
|
package/server/bridge.ts
CHANGED
|
@@ -335,7 +335,11 @@ async function ping(authenticated: boolean): Promise<PingResponse> {
|
|
|
335
335
|
} catch (error) {
|
|
336
336
|
// Ping reports status; it does not fail. An unreachable daemon already
|
|
337
337
|
// shows up in `daemon.reachable`.
|
|
338
|
-
|
|
338
|
+
// A connection that did not open is logged once, with its cause, by the
|
|
339
|
+
// shared daemon connection; logging it again here on every ping is noise.
|
|
340
|
+
if (!(error instanceof BridgeError && error.code === "daemon_unreachable")) {
|
|
341
|
+
console.error("[send-to-paseo] could not list providers for ping", String(error));
|
|
342
|
+
}
|
|
339
343
|
}
|
|
340
344
|
}
|
|
341
345
|
return {
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { request as httpRequest } from "node:http";
|
|
2
|
+
import { request as httpsRequest } from "node:https";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Where the plugin's daemon connection goes, for every way Paseo can listen
|
|
6
|
+
* (daemon-connection-reaches-every-listener, AGENTS.md).
|
|
7
|
+
*
|
|
8
|
+
* `daemon.listen` takes the same forms Paseo's own `parseListenString` does: a
|
|
9
|
+
* socket path (`/…`, `~/…`, `unix://…`), a Windows pipe (`\\.\pipe\…`,
|
|
10
|
+
* `pipe://…`), a bare port, `host:port`, `[v6]:port`, and a comma list whose
|
|
11
|
+
* first entry is the main listener. Both halves of the connection, the
|
|
12
|
+
* WebSocket (`webSocketFactory`) and the HTTP status read (`daemonHttpGet`),
|
|
13
|
+
* are built from this one value, so a form either works for both or neither.
|
|
14
|
+
*
|
|
15
|
+
* Before this the plugin built `ws://${listen}/ws`, which a socket path turned
|
|
16
|
+
* into `ws:///…/paseo.sock/ws` (host "…", not a socket) and a listener list
|
|
17
|
+
* into a URL with a comma in its host, and it opened that with Node's built-in
|
|
18
|
+
* WebSocket, which cannot reach a socket at all (`ws+unix://` is refused with
|
|
19
|
+
* "expected a ws: or wss: url"). Paseo itself worked; the plugin never
|
|
20
|
+
* connected, and the failure was not logged.
|
|
21
|
+
*/
|
|
22
|
+
export interface DaemonEndpoint {
|
|
23
|
+
/** What the WebSocket opens: `ws://host:port/ws`, or `ws+unix://<path>:/ws` for a socket. */
|
|
24
|
+
url: string;
|
|
25
|
+
/** The socket or pipe path, or null for TCP. */
|
|
26
|
+
socketPath: string | null;
|
|
27
|
+
/** Origin of the plain HTTP endpoints for TCP (`http://host:port`); unused for a socket. */
|
|
28
|
+
httpOrigin: string;
|
|
29
|
+
/** Safe to log: no credentials, no query. */
|
|
30
|
+
address: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export const DEFAULT_LISTEN = "127.0.0.1:6767";
|
|
34
|
+
|
|
35
|
+
const bracket = (host: string) => (host.includes(":") && !host.startsWith("[") ? `[${host}]` : host);
|
|
36
|
+
|
|
37
|
+
/** The socket or pipe a listen value names, or null for TCP. Same rules as Paseo's `parseSocketTarget`. */
|
|
38
|
+
function socketTarget(listen: string, home: string): { path: string; pipe: boolean } | null {
|
|
39
|
+
if (listen.startsWith("\\\\.\\pipe\\")) return { path: listen, pipe: true };
|
|
40
|
+
if (listen.startsWith("pipe://")) return { path: listen.slice("pipe://".length), pipe: true };
|
|
41
|
+
const path = listen.startsWith("unix://") ? listen.slice("unix://".length) : listen.startsWith("/") || listen.startsWith("~") ? listen : null;
|
|
42
|
+
return path === null ? null : { path: path.replace(/^~(?=[/\\]|$)/, home), pipe: false };
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function socketEndpoint(path: string, pipe: boolean): DaemonEndpoint {
|
|
46
|
+
// Paseo's CLI addresses a pipe as ws://localhost/ws plus the path; a UNIX socket needs ws+unix.
|
|
47
|
+
return { url: pipe ? "ws://localhost/ws" : `ws+unix://${path}:/ws`, socketPath: path, httpOrigin: "http://localhost", address: path };
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** The endpoint for a `daemon.listen` value (undefined or blank is Paseo's default). */
|
|
51
|
+
export function endpointFromListen(listen: string | undefined, home: string): DaemonEndpoint {
|
|
52
|
+
const raw = listen?.trim() || DEFAULT_LISTEN;
|
|
53
|
+
const socket = socketTarget(raw, home);
|
|
54
|
+
if (socket) return socketEndpoint(socket.path, socket.pipe);
|
|
55
|
+
// Several listeners: the first is the main one (Paseo's getMainListenAddress); the rest are extra TCP addresses.
|
|
56
|
+
const main = raw.split(",", 1)[0]!.trim();
|
|
57
|
+
let hostPort: string;
|
|
58
|
+
if (/^\d+$/.test(main)) hostPort = `127.0.0.1:${main}`;
|
|
59
|
+
else {
|
|
60
|
+
const colon = main.lastIndexOf(":");
|
|
61
|
+
if (colon < 0) throw new Error(`Paseo's daemon.listen is not an address the plugin understands: ${main}`);
|
|
62
|
+
const host = main.slice(0, colon).replace(/^\[(.*)\]$/, "$1") || "127.0.0.1";
|
|
63
|
+
hostPort = `${bracket(host)}:${main.slice(colon + 1)}`;
|
|
64
|
+
}
|
|
65
|
+
return { url: `ws://${hostPort}/ws`, socketPath: null, httpOrigin: `http://${hostPort}`, address: hostPort };
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** Strips credentials, query and fragment from a URL for a log line or an error. */
|
|
69
|
+
export function safeAddress(url: string): string {
|
|
70
|
+
return url.replace(/\/\/[^/@]*@/, "//").replace(/[?#].*$/, "");
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* The endpoint for a `PASEO_DAEMON_URL` override: `ws://`/`wss://` as given, or a
|
|
75
|
+
* `ws+unix://<path>:/ws` socket address (what Paseo's CLI uses).
|
|
76
|
+
*/
|
|
77
|
+
export function endpointFromUrl(url: string): DaemonEndpoint {
|
|
78
|
+
if (url.startsWith("ws+unix://")) {
|
|
79
|
+
const path = url.slice("ws+unix://".length).replace(/:\/ws$/, "");
|
|
80
|
+
return socketEndpoint(path, false);
|
|
81
|
+
}
|
|
82
|
+
let httpOrigin = "http://127.0.0.1:6767";
|
|
83
|
+
try {
|
|
84
|
+
const parsed = new URL(url);
|
|
85
|
+
httpOrigin = `${parsed.protocol === "wss:" ? "https:" : "http:"}//${parsed.host}`;
|
|
86
|
+
} catch {
|
|
87
|
+
// An invalid override fails at connect, with the client's own reason in the log.
|
|
88
|
+
}
|
|
89
|
+
return { url, socketPath: null, httpOrigin, address: safeAddress(url) };
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** The endpoint the plugin connects to: `PASEO_DAEMON_URL` when set, else `daemon.listen`. */
|
|
93
|
+
export function resolveEndpoint(listen: string | undefined, env: Record<string, string | undefined>, home: string): DaemonEndpoint {
|
|
94
|
+
const override = env.PASEO_DAEMON_URL;
|
|
95
|
+
return override ? endpointFromUrl(override) : endpointFromListen(listen, home);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
type WsConstructor = new (address: string, protocols: string[] | undefined, options: Record<string, unknown>) => unknown;
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* The WebSocket the daemon client opens: the `ws` package (the one Paseo's own
|
|
102
|
+
* client and CLI use), given the socket path for a socket or pipe. Node's
|
|
103
|
+
* built-in WebSocket, the client's default, cannot reach a socket.
|
|
104
|
+
*/
|
|
105
|
+
export function webSocketFactory(WebSocket: WsConstructor, endpoint: DaemonEndpoint) {
|
|
106
|
+
return (url: string, options?: { headers?: Record<string, string>; protocols?: string[] }) =>
|
|
107
|
+
new WebSocket(url, options?.protocols, {
|
|
108
|
+
headers: options?.headers,
|
|
109
|
+
...(endpoint.socketPath ? { socketPath: endpoint.socketPath } : {}),
|
|
110
|
+
maxPayload: 100 * 1024 * 1024,
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** A failed connect as one log line: where, and the client's own reason. */
|
|
115
|
+
export function describeConnectFailure(endpoint: DaemonEndpoint, error: unknown): string {
|
|
116
|
+
const reason = String(error instanceof Error ? error.message : error ?? "")
|
|
117
|
+
.replace(/\s+/g, " ")
|
|
118
|
+
.trim()
|
|
119
|
+
.slice(0, 300);
|
|
120
|
+
return `can't connect to Paseo at ${endpoint.address}: ${reason || "unknown error"}`;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** GET a plain HTTP endpoint of the daemon (`/api/status`, `/api/health`) over the same endpoint. */
|
|
124
|
+
export function daemonHttpGet(endpoint: DaemonEndpoint, path: string, timeoutMs: number): Promise<{ status: number; body: string }> {
|
|
125
|
+
return new Promise((resolve, reject) => {
|
|
126
|
+
const origin = new URL(endpoint.httpOrigin);
|
|
127
|
+
const request = origin.protocol === "https:" ? httpsRequest : httpRequest;
|
|
128
|
+
const req = request(
|
|
129
|
+
endpoint.socketPath
|
|
130
|
+
? { socketPath: endpoint.socketPath, path, method: "GET", headers: { host: "localhost" } }
|
|
131
|
+
: { protocol: origin.protocol, hostname: origin.hostname.replace(/^\[(.*)\]$/, "$1"), port: origin.port || undefined, path, method: "GET" },
|
|
132
|
+
(res) => {
|
|
133
|
+
const chunks: Buffer[] = [];
|
|
134
|
+
res.on("data", (chunk: Buffer) => chunks.push(chunk));
|
|
135
|
+
res.on("end", () => resolve({ status: res.statusCode ?? 0, body: Buffer.concat(chunks).toString("utf8") }));
|
|
136
|
+
res.on("error", reject);
|
|
137
|
+
},
|
|
138
|
+
);
|
|
139
|
+
req.setTimeout(timeoutMs, () => req.destroy(new Error(`timed out after ${timeoutMs} ms`)));
|
|
140
|
+
req.on("error", reject);
|
|
141
|
+
req.end();
|
|
142
|
+
});
|
|
143
|
+
}
|
package/server/daemon.ts
CHANGED
|
@@ -8,6 +8,7 @@ import { resolveDaemonPassword } from "./daemon-password";
|
|
|
8
8
|
import { settings } from "./settings";
|
|
9
9
|
import { invokeFollowUp } from "./follow-up-id";
|
|
10
10
|
import { sharedDaemon } from "./shared-daemon";
|
|
11
|
+
import { daemonHttpGet, describeConnectFailure, resolveEndpoint, webSocketFactory, type DaemonEndpoint } from "./daemon-endpoint";
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
14
|
* The plugin's one held daemon connection (one-held-daemon-connection, AGENTS.md).
|
|
@@ -33,18 +34,11 @@ const STATUS_TIMEOUT_MS = 2_000;
|
|
|
33
34
|
const FOLLOW_UP_TIMEOUT_MS = 2_000;
|
|
34
35
|
const STATUS_TTL_MS = 15_000;
|
|
35
36
|
|
|
36
|
-
function timeoutSignal(ms: number): AbortSignal {
|
|
37
|
-
return (
|
|
38
|
-
AbortSignal as typeof AbortSignal & {
|
|
39
|
-
timeout(milliseconds: number): AbortSignal;
|
|
40
|
-
}
|
|
41
|
-
).timeout(ms);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
37
|
type PaseoApi = PluginHandlerContext["paseo"];
|
|
45
38
|
|
|
46
39
|
/** The subset of Paseo's DaemonClient this plugin uses. */
|
|
47
40
|
interface DaemonClient {
|
|
41
|
+
sendMessage?: AgentMessageSender;
|
|
48
42
|
connect(): Promise<void>;
|
|
49
43
|
close(): Promise<void>;
|
|
50
44
|
invokePluginRpc(plugin: string, method: string, input: unknown): Promise<unknown>;
|
|
@@ -61,10 +55,13 @@ interface ClientModule {
|
|
|
61
55
|
connectTimeoutMs: number;
|
|
62
56
|
suppressSendErrors: boolean;
|
|
63
57
|
password?: string;
|
|
58
|
+
webSocketFactory?: ReturnType<typeof webSocketFactory>;
|
|
64
59
|
}) => DaemonClient;
|
|
65
60
|
}
|
|
66
61
|
|
|
67
62
|
let clientModule: ClientModule | null = null;
|
|
63
|
+
/** The `ws` package Paseo's client ships with, or null when this host has none (the client then keeps its default). */
|
|
64
|
+
let wsModule: (new (...args: any[]) => unknown) | null | undefined;
|
|
68
65
|
|
|
69
66
|
/**
|
|
70
67
|
* Borrows Paseo's own SDK and daemon client from the host at runtime.
|
|
@@ -88,6 +85,22 @@ function loadClientModule(): ClientModule {
|
|
|
88
85
|
const { createPaseoApi } = load(sdk) as Pick<ClientModule, "createPaseoApi">;
|
|
89
86
|
const { DaemonClient } = load(internal) as Pick<ClientModule, "DaemonClient">;
|
|
90
87
|
clientModule = { createPaseoApi, DaemonClient };
|
|
88
|
+
// Resolved beside Paseo's own client, so the plugin still adds no dependency
|
|
89
|
+
// (daemon-connection-reaches-every-listener): Node's built-in WebSocket, the
|
|
90
|
+
// client's default, cannot open a UNIX socket or a pipe.
|
|
91
|
+
// Paseo's plugin runner (process.argv[1]) is the reliable base: inside the plugin
|
|
92
|
+
// process the compiled module's own `require.resolve` does not find the host's
|
|
93
|
+
// client (2026-12-02 harness: the socket still failed with "expected a ws: or wss: url").
|
|
94
|
+
wsModule = null;
|
|
95
|
+
for (const base of [() => createRequire(process.argv[1] ?? join(process.cwd(), "noop.cjs")).resolve(internal), () => load.resolve(internal)]) {
|
|
96
|
+
try {
|
|
97
|
+
const ws = createRequire(base())("ws") as { WebSocket?: new (...args: any[]) => unknown };
|
|
98
|
+
wsModule = ws.WebSocket ?? (ws as unknown as new (...args: any[]) => unknown);
|
|
99
|
+
break;
|
|
100
|
+
} catch {
|
|
101
|
+
// Try the next base; none means the client keeps its default WebSocket.
|
|
102
|
+
}
|
|
103
|
+
}
|
|
91
104
|
} catch (error) {
|
|
92
105
|
throw new BridgeError(
|
|
93
106
|
"daemon_unreachable",
|
|
@@ -99,29 +112,27 @@ function loadClientModule(): ClientModule {
|
|
|
99
112
|
return clientModule;
|
|
100
113
|
}
|
|
101
114
|
|
|
102
|
-
let
|
|
115
|
+
let cachedEndpoint: DaemonEndpoint | null = null;
|
|
103
116
|
|
|
104
|
-
/**
|
|
105
|
-
|
|
106
|
-
|
|
117
|
+
/**
|
|
118
|
+
* Where the daemon is, from `PASEO_DAEMON_URL` or `daemon.listen` in config (Paseo's default when
|
|
119
|
+
* neither says). One value for the WebSocket and the HTTP status read
|
|
120
|
+
* (daemon-connection-reaches-every-listener, AGENTS.md).
|
|
121
|
+
*/
|
|
122
|
+
async function resolveDaemonEndpoint(): Promise<DaemonEndpoint> {
|
|
123
|
+
if (cachedEndpoint !== null) return cachedEndpoint;
|
|
107
124
|
const home = process.env.PASEO_HOME ?? join(homedir(), ".paseo");
|
|
108
125
|
let listen: string | undefined;
|
|
109
126
|
try {
|
|
110
127
|
const raw = JSON.parse(await readFile(join(home, "config.json"), "utf8")) as {
|
|
111
|
-
daemon?: { listen?:
|
|
128
|
+
daemon?: { listen?: unknown };
|
|
112
129
|
};
|
|
113
|
-
listen = raw.daemon
|
|
130
|
+
if (typeof raw.daemon?.listen === "string") listen = raw.daemon.listen;
|
|
114
131
|
} catch {
|
|
115
132
|
// Fall through to the documented default.
|
|
116
133
|
}
|
|
117
|
-
|
|
118
|
-
return
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
async function resolveUrl(): Promise<string> {
|
|
122
|
-
const fromEnv = process.env.PASEO_DAEMON_URL;
|
|
123
|
-
if (fromEnv !== undefined && fromEnv !== "") return fromEnv;
|
|
124
|
-
return `ws://${await resolveListen()}/ws`;
|
|
134
|
+
cachedEndpoint = resolveEndpoint(listen, process.env, homedir());
|
|
135
|
+
return cachedEndpoint;
|
|
125
136
|
}
|
|
126
137
|
|
|
127
138
|
/**
|
|
@@ -164,8 +175,9 @@ async function resolvePassword(): Promise<string | undefined> {
|
|
|
164
175
|
async function openDaemon(): Promise<DaemonClient> {
|
|
165
176
|
const { DaemonClient } = loadClientModule();
|
|
166
177
|
const password = await resolvePassword();
|
|
178
|
+
const endpoint = await resolveDaemonEndpoint();
|
|
167
179
|
const client = new DaemonClient({
|
|
168
|
-
url:
|
|
180
|
+
url: endpoint.url,
|
|
169
181
|
clientId: "send-to-paseo",
|
|
170
182
|
clientType: "cli",
|
|
171
183
|
reconnect: { enabled: false },
|
|
@@ -174,13 +186,15 @@ async function openDaemon(): Promise<DaemonClient> {
|
|
|
174
186
|
// Omitted rather than passed as "" when there is none, so a daemon without
|
|
175
187
|
// auth is unaffected.
|
|
176
188
|
...(password === undefined ? {} : { password }),
|
|
189
|
+
...(wsModule ? { webSocketFactory: webSocketFactory(wsModule, endpoint) } : {}),
|
|
177
190
|
});
|
|
178
191
|
try {
|
|
179
192
|
await client.connect();
|
|
180
193
|
return client;
|
|
181
194
|
} catch (error) {
|
|
182
195
|
await client.close().catch(() => undefined);
|
|
183
|
-
|
|
196
|
+
let detail = describeConnectFailure(endpoint, error);
|
|
197
|
+
if (endpoint.socketPath && !wsModule) detail += " (the ws package was not found beside Paseo's client, and Node's own WebSocket cannot open a socket)";
|
|
184
198
|
// A daemon that wants a password is REACHABLE and refusing, which is a
|
|
185
199
|
// different fix from "start Paseo". The hint has to say which.
|
|
186
200
|
if (/password/i.test(detail)) {
|
|
@@ -198,7 +212,16 @@ async function openDaemon(): Promise<DaemonClient> {
|
|
|
198
212
|
}
|
|
199
213
|
}
|
|
200
214
|
|
|
201
|
-
|
|
215
|
+
/**
|
|
216
|
+
* A failed open as one log line, the real cause included (the hint carries the
|
|
217
|
+
* client's own reason). sharedDaemon logs it once per cause.
|
|
218
|
+
*/
|
|
219
|
+
function connectFailureLine(error: unknown): string {
|
|
220
|
+
if (error instanceof BridgeError) return `[send-to-paseo] ${error.message}${error.hint ? ` ${error.hint}` : ""}`;
|
|
221
|
+
return `[send-to-paseo] ${error instanceof Error ? error.message : String(error)}`;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
const shared = sharedDaemon(openDaemon, { keepWarm: true, describeFailure: connectFailureLine });
|
|
202
225
|
|
|
203
226
|
/** Opens the held connection in the background. The plugin calls it at start so no popover pays for the connect. */
|
|
204
227
|
export function warmDaemon(): void {
|
|
@@ -252,13 +275,16 @@ export async function callFollowUp(method: "follow.pr-owner" | "follow.pr-worksp
|
|
|
252
275
|
} finally { if (timer) clearTimeout(timer); }
|
|
253
276
|
}
|
|
254
277
|
|
|
255
|
-
/**
|
|
256
|
-
export
|
|
278
|
+
/** The low-level client preserves receipts that the high-level SDK currently discards. */
|
|
279
|
+
export type AgentMessageSender = (agentId: string, text: string, options: { activeTurnBehavior: "steer" }) => Promise<unknown>;
|
|
280
|
+
|
|
281
|
+
/** Runs work in a scoped SDK view, preserving access to the held connection's receipt. */
|
|
282
|
+
export async function withPaseo<T>(work: (paseo: PaseoApi, sendMessage?: AgentMessageSender) => Promise<T>): Promise<T> {
|
|
257
283
|
const { createPaseoApi } = loadClientModule();
|
|
258
284
|
return shared.run(async (client) => {
|
|
259
285
|
const paseo = createPaseoApi(client);
|
|
260
286
|
try {
|
|
261
|
-
return await work(paseo);
|
|
287
|
+
return await work(paseo, typeof client.sendMessage === "function" ? client.sendMessage.bind(client) : undefined);
|
|
262
288
|
} finally {
|
|
263
289
|
// Releases this request's handles and listeners, never the socket.
|
|
264
290
|
await paseo.dispose().catch(() => undefined);
|
|
@@ -316,14 +342,12 @@ export async function readDaemonStatus(): Promise<DaemonStatus> {
|
|
|
316
342
|
if (statusCache !== null && Date.now() - statusCache.at < STATUS_TTL_MS) {
|
|
317
343
|
return statusCache.status;
|
|
318
344
|
}
|
|
319
|
-
const
|
|
345
|
+
const endpoint = await resolveDaemonEndpoint();
|
|
320
346
|
let status: DaemonStatus = { reachable: false, version: null, serverId: null };
|
|
321
347
|
try {
|
|
322
|
-
const response = await
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
if (response.ok) {
|
|
326
|
-
const body = (await response.json()) as { version?: unknown; serverId?: unknown };
|
|
348
|
+
const response = await daemonHttpGet(endpoint, "/api/status", STATUS_TIMEOUT_MS);
|
|
349
|
+
if (response.status >= 200 && response.status < 300) {
|
|
350
|
+
const body = JSON.parse(response.body) as { version?: unknown; serverId?: unknown };
|
|
327
351
|
status = {
|
|
328
352
|
reachable: true,
|
|
329
353
|
version: typeof body.version === "string" ? body.version : null,
|
|
@@ -332,11 +356,9 @@ export async function readDaemonStatus(): Promise<DaemonStatus> {
|
|
|
332
356
|
} else if (response.status === 401 || response.status === 403) {
|
|
333
357
|
// It answered. It just would not tell us. Liveness comes from the
|
|
334
358
|
// unauthenticated endpoint, and the id from disk.
|
|
335
|
-
const health = await
|
|
336
|
-
signal: timeoutSignal(STATUS_TIMEOUT_MS),
|
|
337
|
-
}).catch(() => null);
|
|
359
|
+
const health = await daemonHttpGet(endpoint, "/api/health", STATUS_TIMEOUT_MS).catch(() => null);
|
|
338
360
|
status = {
|
|
339
|
-
reachable: health
|
|
361
|
+
reachable: health !== null && health.status >= 200 && health.status < 300,
|
|
340
362
|
version: null,
|
|
341
363
|
serverId: await readServerIdFile(),
|
|
342
364
|
};
|
|
@@ -371,5 +393,5 @@ export async function requireServerId(): Promise<string> {
|
|
|
371
393
|
|
|
372
394
|
export function clearDaemonCaches(): void {
|
|
373
395
|
statusCache = null;
|
|
374
|
-
|
|
396
|
+
cachedEndpoint = null;
|
|
375
397
|
}
|
package/server/follow-up-id.ts
CHANGED
|
@@ -1,33 +1,21 @@
|
|
|
1
|
-
/**
|
|
2
|
-
|
|
3
|
-
* still runs as `follow-through`. Callers try the new id first and fall back only when that plugin isn't there.
|
|
4
|
-
*/
|
|
5
|
-
export const FOLLOW_UP_PLUGIN_IDS = ["follow-up", "follow-through"] as const;
|
|
1
|
+
/** Follow-up 2.x's plugin id. */
|
|
2
|
+
const FOLLOW_UP_PLUGIN_ID = "follow-up";
|
|
6
3
|
|
|
7
4
|
/** Paseo's answer when no plugin runs under the id (0.15: "Plugin is not available: <id>"). */
|
|
8
5
|
const absent = (error: unknown) => /plugin (?:is )?not (?:available|installed|configured)|unknown plugin/i.test(error instanceof Error ? error.message : String(error));
|
|
9
6
|
|
|
10
|
-
|
|
11
|
-
* The browser bridge polls every few seconds, and the daemon logs every absent-plugin answer at error level, so an id
|
|
12
|
-
* is never re-probed per call. The id that answered goes first next time and is only abandoned when it comes back
|
|
13
|
-
* absent (2.0 moved to a new id mid-process, or a rollback). When neither id is installed, that fact is cached for
|
|
14
|
-
* `ABSENT_TTL_MS` so a host without Follow-up isn't probed on every poll either.
|
|
15
|
-
*/
|
|
7
|
+
// Browser polls must not repeatedly probe a missing optional plugin.
|
|
16
8
|
const ABSENT_TTL_MS = 30_000;
|
|
17
|
-
let
|
|
18
|
-
let
|
|
19
|
-
let neitherError: unknown;
|
|
9
|
+
let absentUntil = 0;
|
|
10
|
+
let absentError: unknown;
|
|
20
11
|
|
|
21
|
-
/** Calls
|
|
12
|
+
/** Calls Follow-up once; RPC errors and timeouts are propagated without caching them as absence. */
|
|
22
13
|
export async function invokeFollowUp(invoke: (pluginId: string, method: string, input: unknown) => Promise<unknown>, method: string, input: unknown, now: () => number = Date.now): Promise<unknown> {
|
|
23
|
-
if (
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
14
|
+
if (now() < absentUntil) throw absentError;
|
|
15
|
+
try {
|
|
16
|
+
return await invoke(FOLLOW_UP_PLUGIN_ID, method, input);
|
|
17
|
+
} catch (error) {
|
|
18
|
+
if (absent(error)) { absentError = error; absentUntil = now() + ABSENT_TTL_MS; }
|
|
19
|
+
throw error;
|
|
29
20
|
}
|
|
30
|
-
remembered = undefined;
|
|
31
|
-
neitherError = last; neitherUntil = now() + ABSENT_TTL_MS;
|
|
32
|
-
throw last;
|
|
33
21
|
}
|
package/server/send.ts
CHANGED
|
@@ -210,7 +210,7 @@ export async function handleSend(request: SendRequest): Promise<SendResponse> {
|
|
|
210
210
|
const prompt = normalizePrompt(request.prompt);
|
|
211
211
|
const dryRun = isDryRun();
|
|
212
212
|
|
|
213
|
-
return withPaseo(async (paseo) => {
|
|
213
|
+
return withPaseo(async (paseo, sendMessage) => {
|
|
214
214
|
// All four are read-only and independent. On a cold send, `gh` and the
|
|
215
215
|
// daemon status are the slow inputs; starting them together avoids paying
|
|
216
216
|
// their latency in series after the already-prefetched resolve.
|
|
@@ -334,6 +334,7 @@ export async function handleSend(request: SendRequest): Promise<SendResponse> {
|
|
|
334
334
|
let recordedProvider: string;
|
|
335
335
|
let recordedModeId: string | null;
|
|
336
336
|
let agentCreated = true;
|
|
337
|
+
let delivery: Pick<SendResponse, "deliveryStatus" | "guidance"> = {};
|
|
337
338
|
let dispatch: "new" | "main" = "new";
|
|
338
339
|
|
|
339
340
|
if (mainAgent !== null) {
|
|
@@ -348,12 +349,21 @@ export async function handleSend(request: SendRequest): Promise<SendResponse> {
|
|
|
348
349
|
// The public 0.9 SDK forwards this supported daemon option but omits
|
|
349
350
|
// it from PaseoAgentSendOptions. Steering preserves a running main
|
|
350
351
|
// agent's current turn instead of implicitly interrupting it.
|
|
351
|
-
|
|
352
|
+
const receipt: unknown = sendMessage
|
|
353
|
+
? await sendMessage(mainAgent.id, composedPrompt, { activeTurnBehavior: "steer" })
|
|
354
|
+
: await paseo.agents.ref(mainAgent).send(
|
|
352
355
|
composedPrompt,
|
|
353
356
|
{ activeTurnBehavior: "steer" } as Parameters<
|
|
354
357
|
ReturnType<PaseoApi["agents"]["ref"]>["send"]
|
|
355
358
|
>[1] & { activeTurnBehavior: "steer" },
|
|
356
359
|
);
|
|
360
|
+
if (receipt && typeof receipt === "object") {
|
|
361
|
+
const value = receipt as { deliveryStatus?: unknown; guidance?: unknown };
|
|
362
|
+
delivery = {
|
|
363
|
+
...(value.deliveryStatus === "queued" ? { deliveryStatus: "queued" as const } : {}),
|
|
364
|
+
...(typeof value.guidance === "string" ? { guidance: value.guidance } : {}),
|
|
365
|
+
};
|
|
366
|
+
}
|
|
357
367
|
} catch (error) {
|
|
358
368
|
throw new BridgeError(
|
|
359
369
|
"agent_create_failed",
|
|
@@ -444,6 +454,7 @@ export async function handleSend(request: SendRequest): Promise<SendResponse> {
|
|
|
444
454
|
deepLink,
|
|
445
455
|
title: responseTitle,
|
|
446
456
|
agentCreated,
|
|
457
|
+
...delivery,
|
|
447
458
|
dispatch,
|
|
448
459
|
dryRun,
|
|
449
460
|
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// Vendored from paseo-plugin-kit v0.4.0-beta.0 (settings-feed-server/index.ts). Do not edit; change the kit and run `paseo-kit vendor settings-feed-server <dir>`.
|
|
2
|
+
/** Bridge the host's settings notifications to plugin subscriptions, without a polling timer. */
|
|
3
|
+
type Push = (document: unknown) => Promise<void>;
|
|
4
|
+
type Context = { push: Push; signal: AbortSignal };
|
|
5
|
+
export function registerSettingsFeed(
|
|
6
|
+
server: unknown,
|
|
7
|
+
contract: unknown,
|
|
8
|
+
settings: { read(): Promise<unknown>; subscribe?: unknown },
|
|
9
|
+
): () => void {
|
|
10
|
+
const host = server as { handle(contract: unknown, handler: (input: unknown, context: Context) => void): void };
|
|
11
|
+
const subscribe = settings.subscribe;
|
|
12
|
+
if (typeof subscribe !== "function") return () => {};
|
|
13
|
+
let stopped = false, revision = 0;
|
|
14
|
+
const subscribers = new Map<Push, () => void>();
|
|
15
|
+
const send = (push: Push, document: unknown) => {
|
|
16
|
+
if (stopped || !subscribers.has(push)) return;
|
|
17
|
+
void Promise.resolve().then(() => {
|
|
18
|
+
if (!stopped && subscribers.has(push)) return push(document);
|
|
19
|
+
}).catch(() => { subscribers.get(push)?.(); });
|
|
20
|
+
};
|
|
21
|
+
let off: () => void;
|
|
22
|
+
try {
|
|
23
|
+
off = subscribe.call(settings, (document: unknown) => {
|
|
24
|
+
revision++;
|
|
25
|
+
for (const push of subscribers.keys()) send(push, document);
|
|
26
|
+
}) as (() => void);
|
|
27
|
+
} catch { return () => {}; }
|
|
28
|
+
try {
|
|
29
|
+
host.handle(contract, (_input, context) => {
|
|
30
|
+
if (stopped || context.signal.aborted) return;
|
|
31
|
+
if (typeof context.push !== "function") throw new Error("Settings feeds require plugin subscriptions.");
|
|
32
|
+
const remove = () => { subscribers.delete(context.push); context.signal.removeEventListener("abort", remove); };
|
|
33
|
+
subscribers.set(context.push, remove);
|
|
34
|
+
context.signal.addEventListener("abort", remove, { once: true });
|
|
35
|
+
const current = revision;
|
|
36
|
+
void settings.read().then(document => {
|
|
37
|
+
if (revision === current) send(context.push, document);
|
|
38
|
+
}).catch(remove);
|
|
39
|
+
});
|
|
40
|
+
} catch {
|
|
41
|
+
off(); return () => {};
|
|
42
|
+
}
|
|
43
|
+
return () => {
|
|
44
|
+
if (stopped) return;
|
|
45
|
+
stopped = true; off();
|
|
46
|
+
for (const remove of [...subscribers.values()]) remove();
|
|
47
|
+
};
|
|
48
|
+
}
|
package/server/shared-daemon.ts
CHANGED
|
@@ -16,6 +16,11 @@
|
|
|
16
16
|
* keeps serving until its replacement is connected. `run(work, { ifConnected:
|
|
17
17
|
* true })` never waits on a connect: with no connected client it starts one and
|
|
18
18
|
* fails at once with `code: "not_connected"`.
|
|
19
|
+
*
|
|
20
|
+
* A failed open logs its real cause once (`describeFailure`, through `log`):
|
|
21
|
+
* the background reconnect retries on its backoff for as long as the daemon is
|
|
22
|
+
* unreachable, and every retry with the same cause stays quiet until a
|
|
23
|
+
* connection opens or the cause changes. Callers see only "unreachable".
|
|
19
24
|
*/
|
|
20
25
|
|
|
21
26
|
export interface Closable {
|
|
@@ -51,7 +56,17 @@ export class NotConnectedError extends Error {
|
|
|
51
56
|
|
|
52
57
|
export function sharedDaemon<C extends Closable>(
|
|
53
58
|
open: () => Promise<C>,
|
|
54
|
-
options: {
|
|
59
|
+
options: {
|
|
60
|
+
maxMs?: number;
|
|
61
|
+
now?: () => number;
|
|
62
|
+
backoffMs?: number;
|
|
63
|
+
backoffMaxMs?: number;
|
|
64
|
+
stopping?: () => Error;
|
|
65
|
+
keepWarm?: boolean;
|
|
66
|
+
/** One log line for a failed open, with its real cause. No secrets. */
|
|
67
|
+
describeFailure?: (error: unknown) => string;
|
|
68
|
+
log?: (line: string) => void;
|
|
69
|
+
} = {},
|
|
55
70
|
): SharedDaemon<C> {
|
|
56
71
|
const maxMs = options.maxMs ?? SHARED_CLIENT_MAX_MS;
|
|
57
72
|
const now = options.now ?? Date.now;
|
|
@@ -59,6 +74,10 @@ export function sharedDaemon<C extends Closable>(
|
|
|
59
74
|
const backoffMaxMs = options.backoffMaxMs ?? OPEN_BACKOFF_MAX_MS;
|
|
60
75
|
const stopping = options.stopping ?? (() => new Error("Send to Paseo is stopping."));
|
|
61
76
|
const keepWarm = options.keepWarm === true;
|
|
77
|
+
const describeFailure = options.describeFailure ?? ((error: unknown) => (error instanceof Error ? error.message : String(error)));
|
|
78
|
+
const log = options.log ?? ((line: string) => console.error(line));
|
|
79
|
+
/** The last failure line logged; cleared when a connection opens, so the next outage is logged again. */
|
|
80
|
+
let logged: string | null = null;
|
|
62
81
|
type Entry = { client: Promise<C>; ready: C | null; opened: number; users: number; retired: boolean; unsubscribe?: () => void };
|
|
63
82
|
let current: Entry | null = null;
|
|
64
83
|
/** The replacement for an aged `current`, opening while `current` keeps serving. */
|
|
@@ -103,6 +122,7 @@ export function sharedDaemon<C extends Closable>(
|
|
|
103
122
|
entry.client = open().then(
|
|
104
123
|
(client) => {
|
|
105
124
|
failures = 0;
|
|
125
|
+
logged = null;
|
|
106
126
|
if (stopped) {
|
|
107
127
|
void client.close().catch(() => undefined);
|
|
108
128
|
throw stopping();
|
|
@@ -123,6 +143,10 @@ export function sharedDaemon<C extends Closable>(
|
|
|
123
143
|
(error: unknown) => {
|
|
124
144
|
failures++;
|
|
125
145
|
lastError = error;
|
|
146
|
+
if (!stopped) {
|
|
147
|
+
const line = describeFailure(error);
|
|
148
|
+
if (line !== logged) { logged = line; log(line); }
|
|
149
|
+
}
|
|
126
150
|
retryAt = now() + Math.min(backoffMs * 2 ** (failures - 1), backoffMaxMs);
|
|
127
151
|
all.delete(entry);
|
|
128
152
|
if (current === entry) current = null;
|
package/shared/contracts.ts
CHANGED
|
@@ -9,7 +9,7 @@ import { z } from "zod";
|
|
|
9
9
|
|
|
10
10
|
/** Advertised in `GET /v1/ping`. Keep in step with `package.json`. */
|
|
11
11
|
export const PLUGIN_NAME = "send-to-paseo";
|
|
12
|
-
export const PLUGIN_VERSION = "2.6.
|
|
12
|
+
export const PLUGIN_VERSION = "2.6.1-beta.1";
|
|
13
13
|
/** Bumped only for an incompatible bridge API; the paths stay `/v1`. */
|
|
14
14
|
export const CONTRACT_VERSION = 1;
|
|
15
15
|
|
|
@@ -423,6 +423,9 @@ export interface ResolveResponse extends LocalResolveResponse {
|
|
|
423
423
|
|
|
424
424
|
export interface SendResponse {
|
|
425
425
|
ok: true;
|
|
426
|
+
/** Additive daemon receipt; absent on older hosts. */
|
|
427
|
+
deliveryStatus?: "queued";
|
|
428
|
+
guidance?: string;
|
|
426
429
|
agentId: string;
|
|
427
430
|
workspaceId: string;
|
|
428
431
|
workspaceCreated: boolean;
|
package/shared/display.ts
CHANGED
|
@@ -9,3 +9,10 @@ export const displayPreferences = defineSettings({
|
|
|
9
9
|
});
|
|
10
10
|
|
|
11
11
|
export const displayRpc = settingsRpc(displayPreferences.id);
|
|
12
|
+
|
|
13
|
+
/** Plain contract keeps clients on older SDKs compatible. */
|
|
14
|
+
export const displayFeed = {
|
|
15
|
+
name: "send-to-paseo.display-feed",
|
|
16
|
+
input: z.object({}),
|
|
17
|
+
event: z.object({ status: z.string(), revision: z.string().optional(), values: z.unknown().optional(), error: z.string().optional() }),
|
|
18
|
+
};
|