@prestyj/cli 5.38.0 → 5.39.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 +92 -42
- package/dist/app-sidecar/fleet-adapter.d.ts +138 -0
- package/dist/app-sidecar/fleet-adapter.js +356 -0
- package/dist/app-sidecar/fleet-adapter.js.map +1 -0
- package/dist/app-sidecar/fleet-routes.d.ts +4 -0
- package/dist/app-sidecar/fleet-routes.js +109 -0
- package/dist/app-sidecar/fleet-routes.js.map +1 -0
- package/dist/app-sidecar/goal-routes.d.ts +20 -0
- package/dist/app-sidecar/goal-routes.js +42 -1
- package/dist/app-sidecar/goal-routes.js.map +1 -1
- package/dist/app-sidecar.js +5 -0
- package/dist/app-sidecar.js.map +1 -1
- package/dist/cli/cloud.d.ts +45 -0
- package/dist/cli/cloud.js +241 -0
- package/dist/cli/cloud.js.map +1 -0
- package/dist/cli/command-routing.d.ts +3 -2
- package/dist/cli/command-routing.js +24 -3
- package/dist/cli/command-routing.js.map +1 -1
- package/dist/cli/fleet.d.ts +19 -3
- package/dist/cli/fleet.js +107 -33
- package/dist/cli/fleet.js.map +1 -1
- package/dist/cli/goals.d.ts +11 -0
- package/dist/cli/goals.js +115 -0
- package/dist/cli/goals.js.map +1 -0
- package/dist/cli/node.d.ts +18 -1
- package/dist/cli/node.js +303 -33
- package/dist/cli/node.js.map +1 -1
- package/dist/cli.js +6 -0
- package/dist/cli.js.map +1 -1
- package/dist/core/agent-session.d.ts +8 -0
- package/dist/core/agent-session.js +18 -1
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/cloud/claude.d.ts +128 -0
- package/dist/core/cloud/claude.js +836 -0
- package/dist/core/cloud/claude.js.map +1 -0
- package/dist/core/cloud/cloud-agent.d.ts +136 -0
- package/dist/core/cloud/cloud-agent.js +783 -0
- package/dist/core/cloud/cloud-agent.js.map +1 -0
- package/dist/core/cloud/codex.d.ts +154 -0
- package/dist/core/cloud/codex.js +622 -0
- package/dist/core/cloud/codex.js.map +1 -0
- package/dist/core/cloud/config.d.ts +69 -0
- package/dist/core/cloud/config.js +86 -0
- package/dist/core/cloud/config.js.map +1 -0
- package/dist/core/cloud/git.d.ts +15 -0
- package/dist/core/cloud/git.js +33 -0
- package/dist/core/cloud/git.js.map +1 -0
- package/dist/core/cloud/registry.d.ts +13 -0
- package/dist/core/cloud/registry.js +64 -0
- package/dist/core/cloud/registry.js.map +1 -0
- package/dist/core/cloud/runner.d.ts +46 -0
- package/dist/core/cloud/runner.js +99 -0
- package/dist/core/cloud/runner.js.map +1 -0
- package/dist/core/cloud/snapshot.d.ts +23 -0
- package/dist/core/cloud/snapshot.js +98 -0
- package/dist/core/cloud/snapshot.js.map +1 -0
- package/dist/core/cloud/types.d.ts +139 -0
- package/dist/core/cloud/types.js +28 -0
- package/dist/core/cloud/types.js.map +1 -0
- package/dist/core/fleet/client.d.ts +106 -6
- package/dist/core/fleet/client.js +352 -20
- package/dist/core/fleet/client.js.map +1 -1
- package/dist/core/fleet/cloud-jobs.d.ts +59 -0
- package/dist/core/fleet/cloud-jobs.js +131 -0
- package/dist/core/fleet/cloud-jobs.js.map +1 -0
- package/dist/core/fleet/discovery.d.ts +2 -0
- package/dist/core/fleet/discovery.js +3 -1
- package/dist/core/fleet/discovery.js.map +1 -1
- package/dist/core/fleet/fleet-scheduler.d.ts +4 -0
- package/dist/core/fleet/fleet-scheduler.js +11 -1
- package/dist/core/fleet/fleet-scheduler.js.map +1 -1
- package/dist/core/fleet/git.d.ts +7 -0
- package/dist/core/fleet/git.js +22 -1
- package/dist/core/fleet/git.js.map +1 -1
- package/dist/core/fleet/machines.d.ts +112 -0
- package/dist/core/fleet/machines.js +219 -0
- package/dist/core/fleet/machines.js.map +1 -0
- package/dist/core/fleet/node/agents.d.ts +2 -0
- package/dist/core/fleet/node/agents.js +195 -9
- package/dist/core/fleet/node/agents.js.map +1 -1
- package/dist/core/fleet/node/config.d.ts +37 -3
- package/dist/core/fleet/node/config.js +201 -40
- package/dist/core/fleet/node/config.js.map +1 -1
- package/dist/core/fleet/node/context.d.ts +19 -1
- package/dist/core/fleet/node/docker.d.ts +13 -5
- package/dist/core/fleet/node/docker.js +132 -66
- package/dist/core/fleet/node/docker.js.map +1 -1
- package/dist/core/fleet/node/doctor.d.ts +29 -0
- package/dist/core/fleet/node/doctor.js +202 -0
- package/dist/core/fleet/node/doctor.js.map +1 -0
- package/dist/core/fleet/node/env.d.ts +7 -0
- package/dist/core/fleet/node/env.js +51 -0
- package/dist/core/fleet/node/env.js.map +1 -0
- package/dist/core/fleet/node/gc.d.ts +46 -0
- package/dist/core/fleet/node/gc.js +140 -0
- package/dist/core/fleet/node/gc.js.map +1 -0
- package/dist/core/fleet/node/goals.d.ts +43 -0
- package/dist/core/fleet/node/goals.js +418 -0
- package/dist/core/fleet/node/goals.js.map +1 -0
- package/dist/core/fleet/node/jobs.d.ts +37 -2
- package/dist/core/fleet/node/jobs.js +236 -15
- package/dist/core/fleet/node/jobs.js.map +1 -1
- package/dist/core/fleet/node/local-client.d.ts +9 -0
- package/dist/core/fleet/node/local-client.js +29 -0
- package/dist/core/fleet/node/local-client.js.map +1 -0
- package/dist/core/fleet/node/ops-routes.d.ts +15 -0
- package/dist/core/fleet/node/ops-routes.js +84 -0
- package/dist/core/fleet/node/ops-routes.js.map +1 -0
- package/dist/core/fleet/node/pair-code-route.d.ts +14 -0
- package/dist/core/fleet/node/pair-code-route.js +76 -0
- package/dist/core/fleet/node/pair-code-route.js.map +1 -0
- package/dist/core/fleet/node/secrets.d.ts +43 -0
- package/dist/core/fleet/node/secrets.js +184 -0
- package/dist/core/fleet/node/secrets.js.map +1 -0
- package/dist/core/fleet/node/server.d.ts +22 -1
- package/dist/core/fleet/node/server.js +210 -21
- package/dist/core/fleet/node/server.js.map +1 -1
- package/dist/core/fleet/node/state.d.ts +24 -1
- package/dist/core/fleet/node/state.js +12 -3
- package/dist/core/fleet/node/state.js.map +1 -1
- package/dist/core/fleet/node/tls.d.ts +17 -0
- package/dist/core/fleet/node/tls.js +49 -0
- package/dist/core/fleet/node/tls.js.map +1 -0
- package/dist/core/fleet/node/uninstall.d.ts +27 -0
- package/dist/core/fleet/node/uninstall.js +100 -0
- package/dist/core/fleet/node/uninstall.js.map +1 -0
- package/dist/core/fleet/node/update.d.ts +28 -0
- package/dist/core/fleet/node/update.js +62 -0
- package/dist/core/fleet/node/update.js.map +1 -0
- package/dist/core/fleet/node/workspace.d.ts +4 -0
- package/dist/core/fleet/node/workspace.js +38 -9
- package/dist/core/fleet/node/workspace.js.map +1 -1
- package/dist/core/fleet/node-load.d.ts +4 -0
- package/dist/core/fleet/node-load.js +62 -0
- package/dist/core/fleet/node-load.js.map +1 -0
- package/dist/core/fleet/project-config.d.ts +10 -0
- package/dist/core/fleet/project-config.js +39 -1
- package/dist/core/fleet/project-config.js.map +1 -1
- package/dist/core/fleet/prompt-hint.d.ts +11 -0
- package/dist/core/fleet/prompt-hint.js +47 -0
- package/dist/core/fleet/prompt-hint.js.map +1 -0
- package/dist/core/fleet/propose-config.d.ts +26 -0
- package/dist/core/fleet/propose-config.js +95 -0
- package/dist/core/fleet/propose-config.js.map +1 -0
- package/dist/core/fleet/protocol.d.ts +97 -1
- package/dist/core/fleet/protocol.js +10 -1
- package/dist/core/fleet/protocol.js.map +1 -1
- package/dist/core/fleet/registry.d.ts +12 -1
- package/dist/core/fleet/registry.js +39 -7
- package/dist/core/fleet/registry.js.map +1 -1
- package/dist/core/fleet/remote-agent-nodes.d.ts +56 -8
- package/dist/core/fleet/remote-agent-nodes.js +162 -22
- package/dist/core/fleet/remote-agent-nodes.js.map +1 -1
- package/dist/core/fleet/remote-agent.d.ts +52 -1
- package/dist/core/fleet/remote-agent.js +220 -40
- package/dist/core/fleet/remote-agent.js.map +1 -1
- package/dist/core/fleet/service.d.ts +95 -3
- package/dist/core/fleet/service.js +762 -35
- package/dist/core/fleet/service.js.map +1 -1
- package/dist/core/fleet/store.js +22 -5
- package/dist/core/fleet/store.js.map +1 -1
- package/dist/core/fleet/types.d.ts +36 -1
- package/dist/core/fleet/types.js +12 -2
- package/dist/core/fleet/types.js.map +1 -1
- package/dist/core/goal-controller.d.ts +1 -0
- package/dist/core/goal-controller.js +1 -1
- package/dist/core/goal-controller.js.map +1 -1
- package/dist/core/goal-fleet.d.ts +117 -0
- package/dist/core/goal-fleet.js +441 -0
- package/dist/core/goal-fleet.js.map +1 -0
- package/dist/core/goal-headless.d.ts +45 -0
- package/dist/core/goal-headless.js +177 -0
- package/dist/core/goal-headless.js.map +1 -0
- package/dist/core/goal-remote-worker.d.ts +45 -0
- package/dist/core/goal-remote-worker.js +157 -0
- package/dist/core/goal-remote-worker.js.map +1 -0
- package/dist/core/goal-store.d.ts +36 -0
- package/dist/core/goal-store.js +69 -1
- package/dist/core/goal-store.js.map +1 -1
- package/dist/core/goal-verifier.d.ts +5 -0
- package/dist/core/goal-verifier.js +10 -0
- package/dist/core/goal-verifier.js.map +1 -1
- package/dist/core/goal-worker.d.ts +12 -0
- package/dist/core/goal-worker.js +162 -8
- package/dist/core/goal-worker.js.map +1 -1
- package/dist/core/subagent-manager.d.ts +12 -5
- package/dist/core/subagent-manager.js +15 -10
- package/dist/core/subagent-manager.js.map +1 -1
- package/dist/core/validation/backends.d.ts +34 -5
- package/dist/core/validation/backends.js +45 -5
- package/dist/core/validation/backends.js.map +1 -1
- package/dist/core/validation/cloud-backend.d.ts +77 -0
- package/dist/core/validation/cloud-backend.js +343 -0
- package/dist/core/validation/cloud-backend.js.map +1 -0
- package/dist/core/validation/config.js +9 -2
- package/dist/core/validation/config.js.map +1 -1
- package/dist/core/validation/node-backend.d.ts +2 -0
- package/dist/core/validation/node-backend.js +5 -0
- package/dist/core/validation/node-backend.js.map +1 -1
- package/dist/core/validation/scheduler.d.ts +11 -0
- package/dist/core/validation/scheduler.js +34 -7
- package/dist/core/validation/scheduler.js.map +1 -1
- package/dist/core/validation/service.d.ts +6 -0
- package/dist/core/validation/service.js +51 -13
- package/dist/core/validation/service.js.map +1 -1
- package/dist/core/validation/types.d.ts +14 -0
- package/dist/modes/acp-mode.d.ts +3 -1
- package/dist/modes/acp-mode.js +2 -1
- package/dist/modes/acp-mode.js.map +1 -1
- package/dist/system-prompt.d.ts +5 -0
- package/dist/system-prompt.js +3 -0
- package/dist/system-prompt.js.map +1 -1
- package/dist/tools/fleet.d.ts +40 -4
- package/dist/tools/fleet.js +228 -17
- package/dist/tools/fleet.js.map +1 -1
- package/dist/tools/goals.d.ts +4 -1
- package/dist/tools/goals.js +45 -5
- package/dist/tools/goals.js.map +1 -1
- package/dist/tools/index.d.ts +7 -0
- package/dist/tools/index.js +6 -1
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/steroids.d.ts +1 -1
- package/dist/tools/subagent-control.js +1 -1
- package/dist/tools/subagent-control.js.map +1 -1
- package/dist/tools/validate.js +1 -1
- package/dist/tools/validate.js.map +1 -1
- package/dist/ui/App.js +2 -0
- package/dist/ui/App.js.map +1 -1
- package/package.json +6 -4
|
@@ -1,15 +1,26 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { PinnedTlsAgent } from "./client.js";
|
|
2
|
+
import { type NodeInfo } from "./protocol.js";
|
|
2
3
|
export interface FleetNodeEntry {
|
|
3
4
|
name: string;
|
|
4
5
|
/** Base URL, e.g. http://my-pc.tailnet.ts.net:7377 */
|
|
5
6
|
url: string;
|
|
6
7
|
token: string;
|
|
7
8
|
labels?: string[];
|
|
9
|
+
/** Pinned SHA-256 of an https node's TLS certificate (X10). */
|
|
10
|
+
fingerprint?: string;
|
|
8
11
|
}
|
|
9
12
|
export declare function fleetNodesFile(): string;
|
|
10
13
|
/** Paired nodes; [] when the file is missing or unreadable. */
|
|
11
14
|
export declare function readFleetNodes(file?: string): Promise<FleetNodeEntry[]>;
|
|
15
|
+
/**
|
|
16
|
+
* Auth plus the S3 protocol/version headers. Protocol-2 nodes refuse requests
|
|
17
|
+
* without them (426), so every direct call to a node must send these.
|
|
18
|
+
*/
|
|
12
19
|
export declare function nodeHeaders(node: FleetNodeEntry): Record<string, string>;
|
|
20
|
+
/** TLS agent that pins the node's certificate (https nodes paired with a fingerprint). */
|
|
21
|
+
export declare function nodeTlsAgent(node: FleetNodeEntry): PinnedTlsAgent | undefined;
|
|
22
|
+
/** fetch for this node: global fetch, or a pinned one for TLS nodes (self-signed certs). */
|
|
23
|
+
export declare function nodeFetch(node: FleetNodeEntry): typeof fetch;
|
|
13
24
|
export declare function nodeUrl(node: FleetNodeEntry, route: string): string;
|
|
14
25
|
/** GET /v1/info; undefined when the node can't be reached or refuses. */
|
|
15
26
|
export declare function probeNode(node: FleetNodeEntry, timeoutMs?: number): Promise<NodeInfo | undefined>;
|
|
@@ -17,15 +28,52 @@ export interface ProbedNode {
|
|
|
17
28
|
node: FleetNodeEntry;
|
|
18
29
|
info?: NodeInfo;
|
|
19
30
|
}
|
|
31
|
+
/** Slots this process has reserved on `name` and not yet released. */
|
|
32
|
+
export declare function pendingAgentStarts(name: string): number;
|
|
33
|
+
/** Reserve one start slot on a node; call the returned release exactly once. */
|
|
34
|
+
export declare function reserveAgentStart(name: string): () => void;
|
|
35
|
+
/** Free slots after this process's pending starts. */
|
|
36
|
+
export declare function freeAgentSlots(probed: ProbedNode): number;
|
|
37
|
+
/**
|
|
38
|
+
* The node can't run an agent on `provider` (it reports its logins and that
|
|
39
|
+
* provider isn't one of them). Older nodes don't report them: undefined.
|
|
40
|
+
*/
|
|
41
|
+
export declare function missingProviderProblem(probed: ProbedNode, provider: string | undefined): string | undefined;
|
|
20
42
|
/** Why a probed node can't take an agent now, or undefined when it can. */
|
|
21
|
-
export declare function agentNodeProblem(probed: ProbedNode): string | undefined;
|
|
22
|
-
/**
|
|
23
|
-
export declare function
|
|
43
|
+
export declare function agentNodeProblem(probed: ProbedNode, provider?: string): string | undefined;
|
|
44
|
+
/** The node would take an agent once a slot frees (its only problem is being full). */
|
|
45
|
+
export declare function agentNodeOnlyFull(probed: ProbedNode, provider?: string): boolean;
|
|
46
|
+
/** `auto`: a node with model credentials and a free slot; most free slots first, then least loaded. */
|
|
47
|
+
export declare function pickAutoNode(probed: readonly ProbedNode[], provider?: string): ProbedNode | undefined;
|
|
48
|
+
export interface SelectAgentNodeOptions {
|
|
49
|
+
file?: string;
|
|
50
|
+
/** Provider the agent will use; nodes not signed in to it are skipped/refused. */
|
|
51
|
+
provider?: string;
|
|
52
|
+
probe?: (node: FleetNodeEntry) => Promise<NodeInfo | undefined>;
|
|
53
|
+
}
|
|
24
54
|
/**
|
|
25
55
|
* Resolve spawn_agent's `machine` ("auto" or a node name) to a node that can
|
|
26
56
|
* run an agent now. Throws a message the model can act on.
|
|
27
57
|
*/
|
|
28
|
-
export declare function selectAgentNode(machine: string, options?:
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
58
|
+
export declare function selectAgentNode(machine: string, options?: SelectAgentNodeOptions): Promise<FleetNodeEntry>;
|
|
59
|
+
export interface AcquireAgentNodeOptions extends SelectAgentNodeOptions {
|
|
60
|
+
/** Give up waiting for a free slot after this long (default 6 h). */
|
|
61
|
+
queueTimeoutMs?: number;
|
|
62
|
+
/** Re-check interval while every usable node is full (default 2 s). */
|
|
63
|
+
pollMs?: number;
|
|
64
|
+
/** Stop waiting (e.g. the agent was killed). */
|
|
65
|
+
cancelled?: () => boolean;
|
|
66
|
+
/** Told once when the start has to wait for a slot. */
|
|
67
|
+
onQueued?: (reason: string) => void;
|
|
68
|
+
}
|
|
69
|
+
export declare const DEFAULT_AGENT_QUEUE_TIMEOUT_MS: number;
|
|
70
|
+
/**
|
|
71
|
+
* Like selectAgentNode, but when the only problem is that every usable node is
|
|
72
|
+
* full, wait (re-checking every pollMs) until a slot frees instead of failing.
|
|
73
|
+
* Returns the node with a start slot reserved; release it once the node has
|
|
74
|
+
* answered the start (accepted or refused).
|
|
75
|
+
*/
|
|
76
|
+
export declare function acquireAgentNode(machine: string, options?: AcquireAgentNodeOptions): Promise<{
|
|
77
|
+
node: FleetNodeEntry;
|
|
78
|
+
release: () => void;
|
|
79
|
+
}>;
|
|
@@ -5,6 +5,8 @@
|
|
|
5
5
|
import fs from "node:fs/promises";
|
|
6
6
|
import path from "node:path";
|
|
7
7
|
import { getAppPaths } from "@prestyj/core";
|
|
8
|
+
import { controllerVersion, pinnedFetch, PinnedTlsAgent } from "./client.js";
|
|
9
|
+
import { FLEET_PROTOCOL, PROTOCOL_HEADER, VERSION_HEADER } from "./protocol.js";
|
|
8
10
|
export function fleetNodesFile() {
|
|
9
11
|
return path.join(getAppPaths().agentDir, "fleet", "nodes.json");
|
|
10
12
|
}
|
|
@@ -20,13 +22,43 @@ export async function readFleetNodes(file = fleetNodesFile()) {
|
|
|
20
22
|
const nodes = parsed?.nodes;
|
|
21
23
|
if (!Array.isArray(nodes))
|
|
22
24
|
return [];
|
|
23
|
-
return nodes
|
|
25
|
+
return nodes
|
|
26
|
+
.filter((node) => !!node &&
|
|
24
27
|
typeof node.name === "string" &&
|
|
25
28
|
typeof node.url === "string" &&
|
|
26
|
-
typeof node.token === "string")
|
|
29
|
+
typeof node.token === "string")
|
|
30
|
+
.map((node) => ({
|
|
31
|
+
...node,
|
|
32
|
+
...(typeof node.fingerprint === "string" ? { fingerprint: node.fingerprint } : {}),
|
|
33
|
+
}));
|
|
27
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* Auth plus the S3 protocol/version headers. Protocol-2 nodes refuse requests
|
|
37
|
+
* without them (426), so every direct call to a node must send these.
|
|
38
|
+
*/
|
|
28
39
|
export function nodeHeaders(node) {
|
|
29
|
-
return {
|
|
40
|
+
return {
|
|
41
|
+
authorization: `Bearer ${node.token}`,
|
|
42
|
+
[PROTOCOL_HEADER]: String(FLEET_PROTOCOL),
|
|
43
|
+
[VERSION_HEADER]: controllerVersion(),
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
const pinnedAgents = new Map();
|
|
47
|
+
/** TLS agent that pins the node's certificate (https nodes paired with a fingerprint). */
|
|
48
|
+
export function nodeTlsAgent(node) {
|
|
49
|
+
if (!node.fingerprint || !/^https:/i.test(node.url))
|
|
50
|
+
return undefined;
|
|
51
|
+
let agent = pinnedAgents.get(node.fingerprint);
|
|
52
|
+
if (!agent) {
|
|
53
|
+
agent = new PinnedTlsAgent(node.fingerprint);
|
|
54
|
+
pinnedAgents.set(node.fingerprint, agent);
|
|
55
|
+
}
|
|
56
|
+
return agent;
|
|
57
|
+
}
|
|
58
|
+
/** fetch for this node: global fetch, or a pinned one for TLS nodes (self-signed certs). */
|
|
59
|
+
export function nodeFetch(node) {
|
|
60
|
+
const agent = nodeTlsAgent(node);
|
|
61
|
+
return agent ? pinnedFetch(agent) : fetch;
|
|
30
62
|
}
|
|
31
63
|
export function nodeUrl(node, route) {
|
|
32
64
|
return `${node.url.replace(/\/+$/, "")}${route}`;
|
|
@@ -34,7 +66,7 @@ export function nodeUrl(node, route) {
|
|
|
34
66
|
/** GET /v1/info; undefined when the node can't be reached or refuses. */
|
|
35
67
|
export async function probeNode(node, timeoutMs = 4_000) {
|
|
36
68
|
try {
|
|
37
|
-
const res = await
|
|
69
|
+
const res = await nodeFetch(node)(nodeUrl(node, "/v1/info"), {
|
|
38
70
|
headers: nodeHeaders(node),
|
|
39
71
|
signal: AbortSignal.timeout(timeoutMs),
|
|
40
72
|
});
|
|
@@ -46,23 +78,79 @@ export async function probeNode(node, timeoutMs = 4_000) {
|
|
|
46
78
|
return undefined;
|
|
47
79
|
}
|
|
48
80
|
}
|
|
81
|
+
/**
|
|
82
|
+
* Starts this process has promised a node but the node hasn't counted yet
|
|
83
|
+
* (between the probe and its POST /v1/agents answer). Concurrent "auto"
|
|
84
|
+
* starts see each other here, so they spread instead of piling on one node.
|
|
85
|
+
*/
|
|
86
|
+
const pendingStarts = new Map();
|
|
87
|
+
/** Slots this process has reserved on `name` and not yet released. */
|
|
88
|
+
export function pendingAgentStarts(name) {
|
|
89
|
+
return pendingStarts.get(name) ?? 0;
|
|
90
|
+
}
|
|
91
|
+
/** Reserve one start slot on a node; call the returned release exactly once. */
|
|
92
|
+
export function reserveAgentStart(name) {
|
|
93
|
+
pendingStarts.set(name, pendingAgentStarts(name) + 1);
|
|
94
|
+
let released = false;
|
|
95
|
+
return () => {
|
|
96
|
+
if (released)
|
|
97
|
+
return;
|
|
98
|
+
released = true;
|
|
99
|
+
const left = pendingAgentStarts(name) - 1;
|
|
100
|
+
if (left > 0)
|
|
101
|
+
pendingStarts.set(name, left);
|
|
102
|
+
else
|
|
103
|
+
pendingStarts.delete(name);
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
/** Free slots after this process's pending starts. */
|
|
107
|
+
export function freeAgentSlots(probed) {
|
|
108
|
+
const { info } = probed;
|
|
109
|
+
if (!info)
|
|
110
|
+
return 0;
|
|
111
|
+
return info.slots - info.slotsUsed - pendingAgentStarts(probed.node.name);
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* The node can't run an agent on `provider` (it reports its logins and that
|
|
115
|
+
* provider isn't one of them). Older nodes don't report them: undefined.
|
|
116
|
+
*/
|
|
117
|
+
export function missingProviderProblem(probed, provider) {
|
|
118
|
+
const have = probed.info?.modelProviders;
|
|
119
|
+
if (!provider || !have || have.includes(provider))
|
|
120
|
+
return undefined;
|
|
121
|
+
return (`not signed in to ${provider} there (it has ${have.join(", ") || "no logins"}): ` +
|
|
122
|
+
`run \`ezcoder login\` on ${probed.node.name} and choose ${provider}, ` +
|
|
123
|
+
`or give the agent a model from a provider it has`);
|
|
124
|
+
}
|
|
49
125
|
/** Why a probed node can't take an agent now, or undefined when it can. */
|
|
50
|
-
export function agentNodeProblem(probed) {
|
|
126
|
+
export function agentNodeProblem(probed, provider) {
|
|
51
127
|
const { info } = probed;
|
|
52
128
|
if (!info)
|
|
53
129
|
return "unreachable";
|
|
54
130
|
if (!info.modelAuth)
|
|
55
131
|
return "no model credentials (run `ezcoder login` there, or share-auth)";
|
|
56
|
-
|
|
57
|
-
|
|
132
|
+
const missing = missingProviderProblem(probed, provider);
|
|
133
|
+
if (missing)
|
|
134
|
+
return missing;
|
|
135
|
+
if (freeAgentSlots(probed) <= 0) {
|
|
136
|
+
const pending = pendingAgentStarts(probed.node.name);
|
|
137
|
+
return `full (${info.slotsUsed}/${info.slots} slots${pending ? `, ${pending} starting` : ""})`;
|
|
138
|
+
}
|
|
58
139
|
return undefined;
|
|
59
140
|
}
|
|
60
|
-
/**
|
|
61
|
-
export function
|
|
141
|
+
/** The node would take an agent once a slot frees (its only problem is being full). */
|
|
142
|
+
export function agentNodeOnlyFull(probed, provider) {
|
|
143
|
+
return (!!probed.info &&
|
|
144
|
+
probed.info.modelAuth &&
|
|
145
|
+
!missingProviderProblem(probed, provider) &&
|
|
146
|
+
freeAgentSlots(probed) <= 0);
|
|
147
|
+
}
|
|
148
|
+
/** `auto`: a node with model credentials and a free slot; most free slots first, then least loaded. */
|
|
149
|
+
export function pickAutoNode(probed, provider) {
|
|
62
150
|
return probed
|
|
63
|
-
.filter((candidate) => agentNodeProblem(candidate) === undefined)
|
|
64
|
-
.sort((a, b) =>
|
|
65
|
-
|
|
151
|
+
.filter((candidate) => agentNodeProblem(candidate, provider) === undefined)
|
|
152
|
+
.sort((a, b) => freeAgentSlots(b) - freeAgentSlots(a) ||
|
|
153
|
+
a.info.load - b.info.load ||
|
|
66
154
|
a.node.name.localeCompare(b.node.name))[0];
|
|
67
155
|
}
|
|
68
156
|
/**
|
|
@@ -70,27 +158,79 @@ export function pickAutoNode(probed) {
|
|
|
70
158
|
* run an agent now. Throws a message the model can act on.
|
|
71
159
|
*/
|
|
72
160
|
export async function selectAgentNode(machine, options = {}) {
|
|
161
|
+
const picked = await tryReserveAgentNode(machine, options);
|
|
162
|
+
if ("error" in picked)
|
|
163
|
+
throw new Error(picked.error);
|
|
164
|
+
picked.release();
|
|
165
|
+
return picked.node;
|
|
166
|
+
}
|
|
167
|
+
async function tryReserveAgentNode(machine, options) {
|
|
73
168
|
const nodes = await readFleetNodes(options.file);
|
|
74
169
|
if (nodes.length === 0) {
|
|
75
|
-
|
|
170
|
+
return {
|
|
171
|
+
waitable: false,
|
|
172
|
+
error: "No fleet nodes are paired. Pair one with `ezcoder fleet add`, or leave machine unset to run locally.",
|
|
173
|
+
};
|
|
76
174
|
}
|
|
77
175
|
const probe = options.probe ?? ((node) => probeNode(node));
|
|
78
176
|
if (machine !== "auto") {
|
|
79
177
|
const node = nodes.find((candidate) => candidate.name === machine);
|
|
80
178
|
if (!node) {
|
|
81
|
-
|
|
179
|
+
return {
|
|
180
|
+
waitable: false,
|
|
181
|
+
error: `Unknown machine "${machine}". Paired: ${nodes.map((n) => n.name).join(", ")} (or "auto").`,
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
const probed = { node, info: await probe(node) };
|
|
185
|
+
// Decide and reserve with no await in between, so concurrent starts see it.
|
|
186
|
+
const problem = agentNodeProblem(probed, options.provider);
|
|
187
|
+
if (problem) {
|
|
188
|
+
return {
|
|
189
|
+
waitable: agentNodeOnlyFull(probed, options.provider),
|
|
190
|
+
error: `Machine "${machine}" can't run an agent now: ${problem}`,
|
|
191
|
+
};
|
|
82
192
|
}
|
|
83
|
-
|
|
84
|
-
if (problem)
|
|
85
|
-
throw new Error(`Machine "${machine}" can't run an agent now: ${problem}`);
|
|
86
|
-
return node;
|
|
193
|
+
return { node, release: reserveAgentStart(node.name) };
|
|
87
194
|
}
|
|
88
195
|
const probed = await Promise.all(nodes.map(async (node) => ({ node, info: await probe(node) })));
|
|
89
|
-
const picked = pickAutoNode(probed);
|
|
196
|
+
const picked = pickAutoNode(probed, options.provider);
|
|
90
197
|
if (!picked) {
|
|
91
|
-
const reasons = probed
|
|
92
|
-
|
|
198
|
+
const reasons = probed
|
|
199
|
+
.map((p) => `${p.node.name}: ${agentNodeProblem(p, options.provider)}`)
|
|
200
|
+
.join("; ");
|
|
201
|
+
return {
|
|
202
|
+
waitable: probed.some((p) => agentNodeOnlyFull(p, options.provider)),
|
|
203
|
+
error: `No paired machine can run an agent now (${reasons}).`,
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
return { node: picked.node, release: reserveAgentStart(picked.node.name) };
|
|
207
|
+
}
|
|
208
|
+
export const DEFAULT_AGENT_QUEUE_TIMEOUT_MS = 6 * 60 * 60_000;
|
|
209
|
+
/**
|
|
210
|
+
* Like selectAgentNode, but when the only problem is that every usable node is
|
|
211
|
+
* full, wait (re-checking every pollMs) until a slot frees instead of failing.
|
|
212
|
+
* Returns the node with a start slot reserved; release it once the node has
|
|
213
|
+
* answered the start (accepted or refused).
|
|
214
|
+
*/
|
|
215
|
+
export async function acquireAgentNode(machine, options = {}) {
|
|
216
|
+
const deadline = Date.now() + (options.queueTimeoutMs ?? DEFAULT_AGENT_QUEUE_TIMEOUT_MS);
|
|
217
|
+
let told = false;
|
|
218
|
+
for (;;) {
|
|
219
|
+
const attempt = await tryReserveAgentNode(machine, options);
|
|
220
|
+
if ("node" in attempt)
|
|
221
|
+
return attempt;
|
|
222
|
+
if (!attempt.waitable)
|
|
223
|
+
throw new Error(attempt.error);
|
|
224
|
+
if (options.cancelled?.())
|
|
225
|
+
throw new Error("Cancelled while waiting for a free slot");
|
|
226
|
+
if (Date.now() > deadline) {
|
|
227
|
+
throw new Error(`${attempt.error} Gave up after waiting for a free slot.`);
|
|
228
|
+
}
|
|
229
|
+
if (!told) {
|
|
230
|
+
told = true;
|
|
231
|
+
options.onQueued?.(attempt.error);
|
|
232
|
+
}
|
|
233
|
+
await new Promise((resolve) => setTimeout(resolve, options.pollMs ?? 2_000));
|
|
93
234
|
}
|
|
94
|
-
return picked.node;
|
|
95
235
|
}
|
|
96
236
|
//# sourceMappingURL=remote-agent-nodes.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"remote-agent-nodes.js","sourceRoot":"","sources":["../../../src/core/fleet/remote-agent-nodes.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,2EAA2E;AAC3E,8EAA8E;AAC9E,mDAAmD;AACnD,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAClC,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MAAM,CAAC;AAE9D;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,OAAe,EACf,UAAmC,EAAE;IAErC,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,OAAO,CAAC,cAAc,IAAI,8BAA8B,CAAC,CAAC;IACzF,IAAI,IAAI,GAAG,KAAK,CAAC;IACjB,SAAS,CAAC;QACR,MAAM,OAAO,GAAG,MAAM,mBAAmB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QAC5D,IAAI,MAAM,IAAI,OAAO;YAAE,OAAO,OAAO,CAAC;QACtC,IAAI,CAAC,OAAO,CAAC,QAAQ;YAAE,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QACtD,IAAI,OAAO,CAAC,SAAS,EAAE,EAAE;YAAE,MAAM,IAAI,KAAK,CAAC,yCAAyC,CAAC,CAAC;QACtF,IAAI,IAAI,CAAC,GAAG,EAAE,GAAG,QAAQ,EAAE,CAAC;YAC1B,MAAM,IAAI,KAAK,CAAC,GAAG,OAAO,CAAC,KAAK,yCAAyC,CAAC,CAAC;QAC7E,CAAC;QACD,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,IAAI,GAAG,IAAI,CAAC;YACZ,OAAO,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QACpC,CAAC;QACD,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,OAAO,CAAC,MAAM,IAAI,KAAK,CAAC,CAAC,CAAC;IAC/E,CAAC;AACH,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { EventEmitter } from "node:events";
|
|
2
2
|
import { PassThrough, Writable } from "node:stream";
|
|
3
|
-
import type
|
|
3
|
+
import { type SourceSpec } from "./protocol.js";
|
|
4
4
|
import { type FleetNodeEntry } from "./remote-agent-nodes.js";
|
|
5
5
|
export interface RemoteAgentInfo {
|
|
6
6
|
node: string;
|
|
@@ -9,6 +9,8 @@ export interface RemoteAgentInfo {
|
|
|
9
9
|
export interface RemoteWorkerSpawn {
|
|
10
10
|
/** "auto" or a paired node name. */
|
|
11
11
|
machine: string;
|
|
12
|
+
/** Provider the child runs on; machines not signed in to it aren't picked. */
|
|
13
|
+
modelProvider?: string;
|
|
12
14
|
/** Local folder the child works in; its edits come back here. */
|
|
13
15
|
cwd: string;
|
|
14
16
|
localAgentId: string;
|
|
@@ -19,6 +21,32 @@ export interface RemoteWorkerSpawn {
|
|
|
19
21
|
nodesFile?: string;
|
|
20
22
|
reconnectWindowMs?: number;
|
|
21
23
|
onRemote?: (info: RemoteAgentInfo) => void;
|
|
24
|
+
/** Every sync-back attempt's outcome (Goal workers turn a conflict into a task failure, GL3). */
|
|
25
|
+
onSync?: (event: RemoteSyncEvent) => void;
|
|
26
|
+
/**
|
|
27
|
+
* Last check of the picked node before any work is sent (Goals: S3 protocol
|
|
28
|
+
* and GL5 prerequisites on that node). Throw to refuse the start.
|
|
29
|
+
*/
|
|
30
|
+
vetNode?: (node: FleetNodeEntry) => Promise<void>;
|
|
31
|
+
/** Told once when every usable node is full and the start waits for a slot. */
|
|
32
|
+
onQueued?: (reason: string) => void;
|
|
33
|
+
/** Re-check interval while queued (default 2 s). */
|
|
34
|
+
queuePollMs?: number;
|
|
35
|
+
/** Give up waiting for a slot after this long (default 6 h). */
|
|
36
|
+
queueTimeoutMs?: number;
|
|
37
|
+
/** Longest a node's Retry-After is honoured, ms (default 60 s; tests shorten it). */
|
|
38
|
+
maxRetryAfterMs?: number;
|
|
39
|
+
}
|
|
40
|
+
export interface RemoteSyncEvent {
|
|
41
|
+
when: "turn" | "close";
|
|
42
|
+
node: string;
|
|
43
|
+
/** Present when the node's diff was fetched (applied, conflict or refused). */
|
|
44
|
+
result?: SyncResult;
|
|
45
|
+
/** Present when the sync itself failed; `kept` = the full patch was saved locally. */
|
|
46
|
+
error?: string;
|
|
47
|
+
kept?: boolean;
|
|
48
|
+
/** Full patch saved locally when `kept`. */
|
|
49
|
+
keptPath?: string;
|
|
22
50
|
}
|
|
23
51
|
export interface PreparedRemoteSource {
|
|
24
52
|
repoRoot: string;
|
|
@@ -39,9 +67,17 @@ export interface SyncResult {
|
|
|
39
67
|
applied: boolean;
|
|
40
68
|
/** Kept patch when it could not be applied cleanly. */
|
|
41
69
|
conflictPatch?: string;
|
|
70
|
+
/** Files whose hunks do not apply to the local folder (subset of `files`). */
|
|
71
|
+
conflictFiles?: string[];
|
|
72
|
+
/** Git-ignored files the agent changed that were not brought back (R9). */
|
|
73
|
+
notBroughtBack?: string[];
|
|
42
74
|
/** One line for the agent's receipt / stderr. */
|
|
43
75
|
note?: string;
|
|
44
76
|
}
|
|
77
|
+
/** Which of `files` make `patchFile` fail to apply (checked one file at a time, nothing written). */
|
|
78
|
+
export declare function conflictingFiles(repoRoot: string, patchFile: string, files: readonly string[]): Promise<string[]>;
|
|
79
|
+
/** Receipt line for git-ignored files the agent changed (R9). */
|
|
80
|
+
export declare function notBroughtBackNote(node: string, files: readonly string[]): string;
|
|
45
81
|
/**
|
|
46
82
|
* Symlinks the change from tree `from` to `to` adds or retargets that point
|
|
47
83
|
* outside the repository (absolute, `..` escapes) or into `.git`. Applying
|
|
@@ -62,6 +98,8 @@ export declare function applyRemoteDelta(options: {
|
|
|
62
98
|
keepDir: string;
|
|
63
99
|
node: string;
|
|
64
100
|
}): Promise<SyncResult>;
|
|
101
|
+
/** Retry-After (seconds or HTTP date) in ms, capped at a minute. */
|
|
102
|
+
export declare function retryAfterMs(header: string | null): number | undefined;
|
|
65
103
|
export declare class RemoteWorkerProcess extends EventEmitter {
|
|
66
104
|
private readonly spawnOptions;
|
|
67
105
|
readonly stdout: PassThrough;
|
|
@@ -90,6 +128,10 @@ export declare class RemoteWorkerProcess extends EventEmitter {
|
|
|
90
128
|
private stateDir?;
|
|
91
129
|
private killTimer?;
|
|
92
130
|
private closing?;
|
|
131
|
+
/** The node holds edits we could not fetch: don't remove its workspace. */
|
|
132
|
+
private unsynced;
|
|
133
|
+
/** Git-ignored changes already listed in a receipt (R9: each is reported once). */
|
|
134
|
+
private readonly reportedIgnored;
|
|
93
135
|
constructor(spawnOptions: RemoteWorkerSpawn);
|
|
94
136
|
kill(signal?: NodeJS.Signals | number): boolean;
|
|
95
137
|
/**
|
|
@@ -98,6 +140,12 @@ export declare class RemoteWorkerProcess extends EventEmitter {
|
|
|
98
140
|
*/
|
|
99
141
|
detach(): void;
|
|
100
142
|
private start;
|
|
143
|
+
/**
|
|
144
|
+
* Pick a node with a free slot (waiting while all are full), then create the
|
|
145
|
+
* agent there. A node that answers 429 (busy: a slot went to someone else
|
|
146
|
+
* between probe and start) sends us back to the queue after its Retry-After.
|
|
147
|
+
*/
|
|
148
|
+
private createOnFreeNode;
|
|
101
149
|
private http;
|
|
102
150
|
private connect;
|
|
103
151
|
private reconnect;
|
|
@@ -107,6 +155,9 @@ export declare class RemoteWorkerProcess extends EventEmitter {
|
|
|
107
155
|
private forwardLine;
|
|
108
156
|
/** Sync and describe the outcome; never throws (a failed sync is reported, not fatal). */
|
|
109
157
|
private syncNote;
|
|
158
|
+
private reportSync;
|
|
159
|
+
/** Ignored files changed since the last receipt, reported once each (R9). */
|
|
160
|
+
private newlyIgnored;
|
|
110
161
|
/** GET the node's diff and apply what changed since the last sync. */
|
|
111
162
|
syncBack(): Promise<SyncResult | undefined>;
|
|
112
163
|
private cleanupAndFinish;
|