send-to-paseo 2.4.2 → 2.5.0
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/settings.tsx +2 -0
- package/index.server.ts +3 -1
- package/package.json +2 -2
- package/server/daemon.ts +46 -6
- package/server/follow-up.ts +34 -9
- package/server/resolve.ts +8 -4
- package/server/shared-daemon.ts +110 -36
- package/shared/contracts.ts +7 -1
package/client/settings.tsx
CHANGED
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
addAdditionalMachine,
|
|
15
15
|
clearRecentSends,
|
|
16
16
|
DEFAULT_PORT,
|
|
17
|
+
PLUGIN_VERSION,
|
|
17
18
|
enablePrivateAccess,
|
|
18
19
|
externalBridgeUrlProblem,
|
|
19
20
|
getConnectionCode,
|
|
@@ -1186,6 +1187,7 @@ export function SendToPaseoSettings({ theme, host, layout, navigation }: PluginS
|
|
|
1186
1187
|
</>
|
|
1187
1188
|
) : null}
|
|
1188
1189
|
|
|
1190
|
+
<Text selectable style={styles.muted}>Send to Paseo {PLUGIN_VERSION}</Text>
|
|
1189
1191
|
</ScrollView>
|
|
1190
1192
|
);
|
|
1191
1193
|
}
|
package/index.server.ts
CHANGED
|
@@ -17,7 +17,7 @@ import {
|
|
|
17
17
|
updateConfig,
|
|
18
18
|
} from "./shared/contracts";
|
|
19
19
|
import { getBridgeStatus, restartBridge, runBridge } from "./server/bridge";
|
|
20
|
-
import { closeDaemon } from "./server/daemon";
|
|
20
|
+
import { closeDaemon, warmDaemon } from "./server/daemon";
|
|
21
21
|
import { dependencySnapshot } from "./server/deps";
|
|
22
22
|
import {
|
|
23
23
|
listAgentProfiles,
|
|
@@ -179,6 +179,8 @@ export default function contribute(server: PluginServerContext) {
|
|
|
179
179
|
});
|
|
180
180
|
|
|
181
181
|
const stopBridge = runBridge();
|
|
182
|
+
// Connect now, not on the first popover: the click path never pays for a daemon connect (warm-daemon-connection).
|
|
183
|
+
warmDaemon();
|
|
182
184
|
// The held daemon connection closes after the bridge has stopped serving requests.
|
|
183
185
|
return async () => { removeTools(); await stopBridge(); await closeDaemon(); };
|
|
184
186
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "send-to-paseo",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.
|
|
4
|
+
"version": "2.5.0",
|
|
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,7 +35,7 @@
|
|
|
35
35
|
},
|
|
36
36
|
"scripts": {
|
|
37
37
|
"typecheck": "tsc --noEmit",
|
|
38
|
-
"test": "node check-deps.mjs && node --test client/hosts.test.mjs server/main-agent.test.mjs server/follow-up.test.mjs server/daemon-connection.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",
|
|
39
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"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
package/server/daemon.ts
CHANGED
|
@@ -26,7 +26,10 @@ import { sharedDaemon } from "./shared-daemon";
|
|
|
26
26
|
|
|
27
27
|
const CONNECT_TIMEOUT_MS = 10_000;
|
|
28
28
|
const STATUS_TIMEOUT_MS = 2_000;
|
|
29
|
-
/**
|
|
29
|
+
/**
|
|
30
|
+
* An optional Follow Up call gives up after this long. The popover's lookups never spend it on a
|
|
31
|
+
* connect (they run only on a connected client, warm-daemon-connection), so it covers the RPC alone.
|
|
32
|
+
*/
|
|
30
33
|
const FOLLOW_UP_TIMEOUT_MS = 2_000;
|
|
31
34
|
const STATUS_TTL_MS = 15_000;
|
|
32
35
|
|
|
@@ -45,6 +48,7 @@ interface DaemonClient {
|
|
|
45
48
|
connect(): Promise<void>;
|
|
46
49
|
close(): Promise<void>;
|
|
47
50
|
invokePluginRpc(plugin: string, method: string, input: unknown): Promise<unknown>;
|
|
51
|
+
getConnectionState?(): { status: string };
|
|
48
52
|
}
|
|
49
53
|
|
|
50
54
|
interface ClientModule {
|
|
@@ -194,21 +198,57 @@ async function openDaemon(): Promise<DaemonClient> {
|
|
|
194
198
|
}
|
|
195
199
|
}
|
|
196
200
|
|
|
197
|
-
const shared = sharedDaemon(openDaemon);
|
|
201
|
+
const shared = sharedDaemon(openDaemon, { keepWarm: true });
|
|
202
|
+
|
|
203
|
+
/** Opens the held connection in the background. The plugin calls it at start so no popover pays for the connect. */
|
|
204
|
+
export function warmDaemon(): void {
|
|
205
|
+
shared.warm();
|
|
206
|
+
}
|
|
198
207
|
|
|
199
208
|
/** Closes the held connection. The plugin's teardown runs it after the bridge stops. */
|
|
200
209
|
export function closeDaemon(): Promise<void> {
|
|
201
210
|
return shared.close();
|
|
202
211
|
}
|
|
203
212
|
|
|
204
|
-
/**
|
|
205
|
-
|
|
213
|
+
/**
|
|
214
|
+
* Thrown when Follow-up could not be asked: no connected client yet, the call outran its budget, or
|
|
215
|
+
* the socket went away. That is "couldn't check", never "Follow-up has nothing" (AGENTS.md,
|
|
216
|
+
* optional-lookup-never-silent). Follow-up's own answers, absence included, are thrown as they are.
|
|
217
|
+
*/
|
|
218
|
+
export class FollowUpUnreachableError extends Error {
|
|
219
|
+
readonly code = "follow_up_unreachable";
|
|
220
|
+
}
|
|
221
|
+
export const isFollowUpUnreachable = (error: unknown): boolean =>
|
|
222
|
+
(error as { code?: unknown } | null)?.code === "follow_up_unreachable";
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Optional companion RPCs always target this daemon, never a browser-selected host. With
|
|
226
|
+
* `ifConnected` (the popover's lookups) the call never waits on a connect: no connected client
|
|
227
|
+
* means unreachable at once, and the background warm-up is already reconnecting.
|
|
228
|
+
*/
|
|
229
|
+
export async function callFollowUp(method: "follow.pr-owner" | "follow.pr-workspaces" | "follow.browser-exchange", input: unknown, options: { ifConnected?: boolean } = {}): Promise<unknown> {
|
|
206
230
|
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
231
|
+
let reached = false;
|
|
207
232
|
try {
|
|
208
233
|
return await Promise.race([
|
|
209
|
-
shared.run((client) =>
|
|
210
|
-
|
|
234
|
+
shared.run(async (client) => {
|
|
235
|
+
reached = true;
|
|
236
|
+
try {
|
|
237
|
+
return await invokeFollowUp((plugin, m, i) => client.invokePluginRpc(plugin, m, i), method, input);
|
|
238
|
+
} catch (error) {
|
|
239
|
+
// The socket went away under the call: the question never got its answer.
|
|
240
|
+
const status = client.getConnectionState?.().status;
|
|
241
|
+
if (status !== undefined && status !== "connected") throw new FollowUpUnreachableError(error instanceof Error ? error.message : String(error));
|
|
242
|
+
throw error;
|
|
243
|
+
}
|
|
244
|
+
}, { ifConnected: options.ifConnected === true }),
|
|
245
|
+
new Promise<never>((_, reject) => { timer = setTimeout(() => reject(new FollowUpUnreachableError("Optional Follow Up request timed out.")), FOLLOW_UP_TIMEOUT_MS); timer.unref?.(); }),
|
|
211
246
|
]);
|
|
247
|
+
} catch (error) {
|
|
248
|
+
if (isFollowUpUnreachable(error)) throw error;
|
|
249
|
+
// Never reached a connected client (not connected, failed open, backoff): couldn't check.
|
|
250
|
+
if (!reached) throw new FollowUpUnreachableError(error instanceof Error ? error.message : String(error));
|
|
251
|
+
throw error;
|
|
212
252
|
} finally { if (timer) clearTimeout(timer); }
|
|
213
253
|
}
|
|
214
254
|
|
package/server/follow-up.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import { callFollowUp } from "./daemon";
|
|
2
|
+
import { callFollowUp, isFollowUpUnreachable } from "./daemon";
|
|
3
3
|
import type { ListedAgent } from "./main-agent";
|
|
4
|
-
import { buildAgentDeepLink, buildAgentWebLink, type FollowUpView } from "../shared/contracts";
|
|
4
|
+
import { buildAgentDeepLink, buildAgentWebLink, type Candidate, type FollowUpView } from "../shared/contracts";
|
|
5
5
|
|
|
6
6
|
const ownerReply = z.object({ owner: z.object({ workspaceId: z.string().min(1).max(200), agentId: z.string().min(1).max(200) }).nullable() });
|
|
7
7
|
export type PrOwner = NonNullable<z.infer<typeof ownerReply>["owner"]>;
|
|
@@ -21,15 +21,20 @@ const workspacesReply = z.object({
|
|
|
21
21
|
workspaces: z.array(z.object({ workspaceId: text(200).min(1), agentId: text(200).min(1), title: text(200), agentStatus: text(40), group: text(20), state: text(200) })).max(3),
|
|
22
22
|
});
|
|
23
23
|
export type PrWorkspaces = Omit<z.infer<typeof workspacesReply>, "tracked">;
|
|
24
|
+
/** Follow-up could not be asked in time (not connected, budget spent, socket gone). Not "none". */
|
|
25
|
+
export const FOLLOW_UP_UNKNOWN = "unknown" as const;
|
|
24
26
|
/**
|
|
25
|
-
* Follow-up's owners of a PR
|
|
26
|
-
* broken, or the repository outside the scope it tracks
|
|
27
|
+
* Follow-up's owners of a PR; null when there is nothing to show (Follow-up absent, older than this RPC,
|
|
28
|
+
* broken, or the repository outside the scope it tracks and therefore advertises to the browser); or
|
|
29
|
+
* `"unknown"` when it could not be asked. Unknown must never read as none (optional-lookup-never-silent).
|
|
30
|
+
* Never waits on a daemon connect: the popover's click path does not pay for one (warm-daemon-connection).
|
|
27
31
|
*/
|
|
28
|
-
export async function lookupPrWorkspaces(owner: string, repo: string, number: number): Promise<PrWorkspaces | null> {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
32
|
+
export async function lookupPrWorkspaces(owner: string, repo: string, number: number): Promise<PrWorkspaces | null | typeof FOLLOW_UP_UNKNOWN> {
|
|
33
|
+
let raw: unknown;
|
|
34
|
+
try { raw = await callFollowUp("follow.pr-workspaces", { repo: `${owner}/${repo}`, number }, { ifConnected: true }); }
|
|
35
|
+
catch (error) { return isFollowUpUnreachable(error) ? FOLLOW_UP_UNKNOWN : null; }
|
|
36
|
+
const reply = workspacesReply.safeParse(raw);
|
|
37
|
+
return reply.success && reply.data.tracked ? { workspaces: reply.data.workspaces, more: reply.data.more } : null;
|
|
33
38
|
}
|
|
34
39
|
/** Adds this machine's open links and Paseo's own workspace names. Without a server id no link can be built, so nothing is shown. */
|
|
35
40
|
export function followUpView(found: PrWorkspaces | null, serverId: string | null, names: ReadonlyMap<string, string>): FollowUpView | undefined {
|
|
@@ -39,3 +44,23 @@ export function followUpView(found: PrWorkspaces | null, serverId: string | null
|
|
|
39
44
|
workspaces: found.workspaces.map(w => ({ ...w, title: names.get(w.workspaceId) || w.title || w.workspaceId, deepLink: buildAgentDeepLink({ serverId, agentId: w.agentId }), webUrl: buildAgentWebLink({ serverId, agentId: w.agentId }) })),
|
|
40
45
|
};
|
|
41
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* The resolve answer's Follow-up fields. When the workspaces lookup is unknown it says so
|
|
49
|
+
* (`followUpUnreachable`), and still offers the registered owner from `follow.pr-owner` when that
|
|
50
|
+
* owner's agent is one of this PR's candidates, with the same open links as `followUpView`.
|
|
51
|
+
*/
|
|
52
|
+
export function followUpAnswer(
|
|
53
|
+
found: PrWorkspaces | null | typeof FOLLOW_UP_UNKNOWN,
|
|
54
|
+
owner: PrOwner | null,
|
|
55
|
+
candidates: readonly Candidate[],
|
|
56
|
+
serverId: string | null,
|
|
57
|
+
names: ReadonlyMap<string, string>,
|
|
58
|
+
): { followUp?: FollowUpView; followUpUnreachable?: true } {
|
|
59
|
+
if (found !== FOLLOW_UP_UNKNOWN) { const view = followUpView(found, serverId, names); return view ? { followUp: view } : {}; }
|
|
60
|
+
const registered = owner ? candidates.find(c => c.kind === "existing" && c.workspaceId === owner.workspaceId && c.followUpAgent?.agentId === owner.agentId) : undefined;
|
|
61
|
+
const agent = registered?.kind === "existing" ? registered.followUpAgent : undefined;
|
|
62
|
+
const fallback = owner && agent
|
|
63
|
+
? followUpView({ more: 0, workspaces: [{ workspaceId: owner.workspaceId, agentId: owner.agentId, title: "", agentStatus: agent.status, group: "", state: "" }] }, serverId, names)
|
|
64
|
+
: undefined;
|
|
65
|
+
return { followUpUnreachable: true, ...(fallback ? { followUp: fallback } : {}) };
|
|
66
|
+
}
|
package/server/resolve.ts
CHANGED
|
@@ -14,7 +14,7 @@ import {
|
|
|
14
14
|
type StackPrState,
|
|
15
15
|
} from "../shared/contracts";
|
|
16
16
|
import { requireServerId, withPaseo } from "./daemon";
|
|
17
|
-
import {
|
|
17
|
+
import { followUpAnswer, lookupPrOwner, lookupPrWorkspaces, registeredAgent, type PrOwner } from "./follow-up";
|
|
18
18
|
import {
|
|
19
19
|
ANCESTRY_STACK_DISTANCE,
|
|
20
20
|
UNKNOWN_STACK_DISTANCE,
|
|
@@ -979,7 +979,8 @@ export async function handleResolve(request: ResolveRequest): Promise<ResolveRes
|
|
|
979
979
|
// starts this work before the popover opens).
|
|
980
980
|
const workspacesPromise = paseo.workspaces.list();
|
|
981
981
|
const ownerPromise = lookupPrOwner(ref.owner, ref.repo, ref.number);
|
|
982
|
-
// Asked for only by an extension with Follow-up browser access on
|
|
982
|
+
// Asked for only by an extension with Follow-up browser access on. Absent is "no section"; not
|
|
983
|
+
// reached in time is `followUpUnreachable`, never "no section" (optional-lookup-never-silent).
|
|
983
984
|
const followUpPromise = request.followUp === true
|
|
984
985
|
? Promise.all([lookupPrWorkspaces(ref.owner, ref.repo, ref.number), requireServerId().catch(() => null)])
|
|
985
986
|
: Promise.resolve([null, null] as const);
|
|
@@ -1041,9 +1042,12 @@ export async function handleResolve(request: ResolveRequest): Promise<ResolveRes
|
|
|
1041
1042
|
? undefined
|
|
1042
1043
|
: await resolveDefaultMode(paseo, effectiveProvider, { profile, catalog });
|
|
1043
1044
|
const [ownersFound, serverId] = await followUpPromise;
|
|
1044
|
-
|
|
1045
|
+
// Unknown (Follow-up not asked in time) is said, never dropped into "no section".
|
|
1046
|
+
const followUp = request.followUp === true
|
|
1047
|
+
? followUpAnswer(ownersFound, owner, candidates, serverId, new Map(allWorkspaces.entries.map(w => [w.id, typeof w.name === "string" ? w.name : ""])))
|
|
1048
|
+
: {};
|
|
1045
1049
|
return {
|
|
1046
|
-
...
|
|
1050
|
+
...followUp,
|
|
1047
1051
|
pr,
|
|
1048
1052
|
project,
|
|
1049
1053
|
candidates,
|
package/server/shared-daemon.ts
CHANGED
|
@@ -8,6 +8,14 @@
|
|
|
8
8
|
* off, and calls inside that window fail fast with the same error. A connection
|
|
9
9
|
* older than `maxMs` is replaced once its in-flight calls finish. `close()` is
|
|
10
10
|
* the plugin's teardown: nothing opens afterwards, so the subprocess can exit.
|
|
11
|
+
*
|
|
12
|
+
* With `keepWarm` the connection is also kept open between requests
|
|
13
|
+
* (warm-daemon-connection, AGENTS.md), so the popover's click path never pays
|
|
14
|
+
* for a connect: `warm()` opens it at plugin start, a drop or a failed open
|
|
15
|
+
* reconnects in the background on the same backoff, and an aged connection
|
|
16
|
+
* keeps serving until its replacement is connected. `run(work, { ifConnected:
|
|
17
|
+
* true })` never waits on a connect: with no connected client it starts one and
|
|
18
|
+
* fails at once with `code: "not_connected"`.
|
|
11
19
|
*/
|
|
12
20
|
|
|
13
21
|
export interface Closable {
|
|
@@ -20,8 +28,15 @@ type StatusSource = {
|
|
|
20
28
|
subscribeConnectionStatus?(listener: (state: ConnectionStatus) => void): () => void;
|
|
21
29
|
};
|
|
22
30
|
|
|
31
|
+
export interface RunOptions {
|
|
32
|
+
/** Fail at once (`code: "not_connected"`) instead of waiting for a connect. */
|
|
33
|
+
ifConnected?: boolean;
|
|
34
|
+
}
|
|
35
|
+
|
|
23
36
|
export interface SharedDaemon<C extends Closable> {
|
|
24
|
-
run<T>(work: (client: C) => Promise<T
|
|
37
|
+
run<T>(work: (client: C) => Promise<T>, options?: RunOptions): Promise<T>;
|
|
38
|
+
/** Opens the connection in the background if none is open or opening. Never throws. */
|
|
39
|
+
warm(): void;
|
|
25
40
|
close(): Promise<void>;
|
|
26
41
|
}
|
|
27
42
|
|
|
@@ -29,71 +44,129 @@ export const SHARED_CLIENT_MAX_MS = 30 * 60_000;
|
|
|
29
44
|
export const OPEN_BACKOFF_MS = 1_000;
|
|
30
45
|
export const OPEN_BACKOFF_MAX_MS = 30_000;
|
|
31
46
|
|
|
47
|
+
export class NotConnectedError extends Error {
|
|
48
|
+
readonly code = "not_connected";
|
|
49
|
+
constructor() { super("The Paseo daemon connection is not open yet."); }
|
|
50
|
+
}
|
|
51
|
+
|
|
32
52
|
export function sharedDaemon<C extends Closable>(
|
|
33
53
|
open: () => Promise<C>,
|
|
34
|
-
options: { maxMs?: number; now?: () => number; backoffMs?: number; backoffMaxMs?: number; stopping?: () => Error } = {},
|
|
54
|
+
options: { maxMs?: number; now?: () => number; backoffMs?: number; backoffMaxMs?: number; stopping?: () => Error; keepWarm?: boolean } = {},
|
|
35
55
|
): SharedDaemon<C> {
|
|
36
56
|
const maxMs = options.maxMs ?? SHARED_CLIENT_MAX_MS;
|
|
37
57
|
const now = options.now ?? Date.now;
|
|
38
58
|
const backoffMs = options.backoffMs ?? OPEN_BACKOFF_MS;
|
|
39
59
|
const backoffMaxMs = options.backoffMaxMs ?? OPEN_BACKOFF_MAX_MS;
|
|
40
60
|
const stopping = options.stopping ?? (() => new Error("Send to Paseo is stopping."));
|
|
41
|
-
|
|
61
|
+
const keepWarm = options.keepWarm === true;
|
|
62
|
+
type Entry = { client: Promise<C>; ready: C | null; opened: number; users: number; retired: boolean; unsubscribe?: () => void };
|
|
42
63
|
let current: Entry | null = null;
|
|
64
|
+
/** The replacement for an aged `current`, opening while `current` keeps serving. */
|
|
65
|
+
let next: Entry | null = null;
|
|
43
66
|
let stopped = false;
|
|
44
67
|
let failures = 0;
|
|
45
68
|
let retryAt = 0;
|
|
46
69
|
let lastError: unknown = null;
|
|
70
|
+
// A one-shot, unref'd timer for the background reconnect, cleared in close(): it never keeps
|
|
71
|
+
// the subprocess alive and never outlives teardown (AGENTS.md forbids live timers here).
|
|
72
|
+
let retryTimer: ReturnType<typeof setTimeout> | null = null;
|
|
47
73
|
const all = new Set<Entry>();
|
|
48
74
|
|
|
75
|
+
const live = (client: C) => {
|
|
76
|
+
const status = (client as unknown as StatusSource).getConnectionState?.().status;
|
|
77
|
+
return status === undefined || status === "connected";
|
|
78
|
+
};
|
|
49
79
|
const shut = async (entry: Entry) => {
|
|
50
80
|
all.delete(entry);
|
|
51
81
|
if (current === entry) current = null;
|
|
82
|
+
if (next === entry) next = null;
|
|
52
83
|
entry.unsubscribe?.();
|
|
53
84
|
const client = await entry.client.catch(() => null);
|
|
54
85
|
if (client) await client.close().catch(() => undefined);
|
|
55
86
|
};
|
|
87
|
+
const scheduleWarm = () => {
|
|
88
|
+
if (!keepWarm || stopped || retryTimer) return;
|
|
89
|
+
retryTimer = setTimeout(() => { retryTimer = null; warm(); }, Math.max(0, retryAt - now()));
|
|
90
|
+
retryTimer.unref?.();
|
|
91
|
+
};
|
|
56
92
|
const retire = (entry: Entry) => {
|
|
93
|
+
if (entry.retired) return;
|
|
57
94
|
entry.retired = true;
|
|
58
95
|
if (current === entry) current = null;
|
|
96
|
+
if (next === entry) next = null;
|
|
59
97
|
if (entry.users === 0) void shut(entry);
|
|
98
|
+
if (!current && !next) scheduleWarm();
|
|
60
99
|
};
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
100
|
+
|
|
101
|
+
const start = (): Entry => {
|
|
102
|
+
const entry = { opened: now(), users: 0, retired: false, ready: null } as Entry;
|
|
103
|
+
entry.client = open().then(
|
|
104
|
+
(client) => {
|
|
105
|
+
failures = 0;
|
|
106
|
+
if (stopped) {
|
|
107
|
+
void client.close().catch(() => undefined);
|
|
108
|
+
throw stopping();
|
|
109
|
+
}
|
|
110
|
+
entry.ready = client;
|
|
111
|
+
entry.unsubscribe = (client as unknown as StatusSource).subscribeConnectionStatus?.((state) => {
|
|
112
|
+
if (state.status === "disconnected" || state.status === "disposed") retire(entry);
|
|
113
|
+
});
|
|
114
|
+
if (next === entry) {
|
|
115
|
+
// The replacement is connected: it takes over, and the aged one closes once idle.
|
|
116
|
+
next = null;
|
|
117
|
+
const aged = current;
|
|
118
|
+
current = entry;
|
|
119
|
+
if (aged) retire(aged);
|
|
120
|
+
}
|
|
121
|
+
return client;
|
|
122
|
+
},
|
|
123
|
+
(error: unknown) => {
|
|
124
|
+
failures++;
|
|
125
|
+
lastError = error;
|
|
126
|
+
retryAt = now() + Math.min(backoffMs * 2 ** (failures - 1), backoffMaxMs);
|
|
127
|
+
all.delete(entry);
|
|
128
|
+
if (current === entry) current = null;
|
|
129
|
+
if (next === entry) next = null;
|
|
130
|
+
if (!current) scheduleWarm();
|
|
131
|
+
throw error;
|
|
132
|
+
},
|
|
133
|
+
);
|
|
134
|
+
// A background open's failure is recorded above; nobody else awaits it.
|
|
135
|
+
entry.client.catch(() => undefined);
|
|
136
|
+
all.add(entry);
|
|
137
|
+
return entry;
|
|
64
138
|
};
|
|
65
139
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
if (current && now() - current.opened >= maxMs)
|
|
140
|
+
/** The entry a call should use now, opening or rotating as needed. Null inside the open backoff. */
|
|
141
|
+
const select = (): Entry | null => {
|
|
142
|
+
if (current && now() - current.opened >= maxMs) {
|
|
143
|
+
if (keepWarm && current.ready && live(current.ready)) {
|
|
144
|
+
// Rotate without a gap: keep serving on the aged connection until the new one is up.
|
|
145
|
+
if (!next && !(failures > 0 && now() < retryAt)) next = start();
|
|
146
|
+
} else {
|
|
147
|
+
retire(current);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
69
150
|
if (!current) {
|
|
70
|
-
if (failures > 0 && now() < retryAt)
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
retryAt = now() + Math.min(backoffMs * 2 ** (failures - 1), backoffMaxMs);
|
|
88
|
-
all.delete(entry);
|
|
89
|
-
if (current === entry) current = null;
|
|
90
|
-
throw error;
|
|
91
|
-
},
|
|
92
|
-
);
|
|
93
|
-
current = entry;
|
|
94
|
-
all.add(entry);
|
|
151
|
+
if (failures > 0 && now() < retryAt) return null;
|
|
152
|
+
current = start();
|
|
153
|
+
}
|
|
154
|
+
return current;
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
function warm(): void {
|
|
158
|
+
if (stopped) return;
|
|
159
|
+
try { select(); } catch { /* recorded by start() */ }
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
const run = async <T>(work: (client: C) => Promise<T>, runOptions: RunOptions = {}): Promise<T> => {
|
|
163
|
+
if (stopped) throw stopping();
|
|
164
|
+
const entry = select();
|
|
165
|
+
if (!entry) {
|
|
166
|
+
if (runOptions.ifConnected) throw new NotConnectedError();
|
|
167
|
+
throw lastError instanceof Error ? lastError : new Error(String(lastError));
|
|
95
168
|
}
|
|
96
|
-
|
|
169
|
+
if (runOptions.ifConnected && !(entry.ready && live(entry.ready))) throw new NotConnectedError();
|
|
97
170
|
entry.users++;
|
|
98
171
|
try {
|
|
99
172
|
const client = await entry.client;
|
|
@@ -111,7 +184,8 @@ export function sharedDaemon<C extends Closable>(
|
|
|
111
184
|
|
|
112
185
|
const close = async () => {
|
|
113
186
|
stopped = true;
|
|
187
|
+
if (retryTimer) { clearTimeout(retryTimer); retryTimer = null; }
|
|
114
188
|
await Promise.allSettled([...all].map((entry) => shut(entry)));
|
|
115
189
|
};
|
|
116
|
-
return { run, close };
|
|
190
|
+
return { run, warm, close };
|
|
117
191
|
}
|
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.
|
|
12
|
+
export const PLUGIN_VERSION = "2.5.0";
|
|
13
13
|
/** Bumped only for an incompatible bridge API; the paths stay `/v1`. */
|
|
14
14
|
export const CONTRACT_VERSION = 1;
|
|
15
15
|
|
|
@@ -365,6 +365,12 @@ export interface LocalResolveResponse {
|
|
|
365
365
|
* advertises to the browser). Absent otherwise; never an error.
|
|
366
366
|
*/
|
|
367
367
|
followUp?: FollowUpView;
|
|
368
|
+
/**
|
|
369
|
+
* Additive. Present (true) when the request asked for the Follow-up view and Follow-up could not
|
|
370
|
+
* be asked in time: "couldn't check", which is not "none". `followUp`, when also present, then
|
|
371
|
+
* holds only the registered owner from `follow.pr-owner`.
|
|
372
|
+
*/
|
|
373
|
+
followUpUnreachable?: true;
|
|
368
374
|
}
|
|
369
375
|
|
|
370
376
|
/** One workspace that owns the PR, as the popover shows it. Titles, ids, status and one line: nothing else. */
|