@culture.dev/agents 0.16.2 → 0.17.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.
Files changed (107) hide show
  1. package/README.md +26 -3
  2. package/dist/contract-schemas/api.json +324 -1
  3. package/dist/contract-schemas/fleet.json +114 -0
  4. package/dist/contract-schemas/reachability.json +51 -0
  5. package/dist/contract-schemas/remote.json +150 -0
  6. package/dist/contract-schemas/run.json +17 -3
  7. package/dist/contract-schemas/unreadable.json +45 -0
  8. package/dist/contract-schemas/version.json +1 -1
  9. package/dist/src/contract/api.d.ts +10 -0
  10. package/dist/src/contract/api.js +18 -0
  11. package/dist/src/contract/api.js.map +1 -1
  12. package/dist/src/contract/generated/fleet.d.ts +50 -0
  13. package/dist/src/contract/generated/fleet.js +3 -0
  14. package/dist/src/contract/generated/fleet.js.map +1 -0
  15. package/dist/src/contract/generated/index.d.ts +24 -0
  16. package/dist/src/contract/generated/reachability.d.ts +20 -0
  17. package/dist/src/contract/generated/reachability.js +3 -0
  18. package/dist/src/contract/generated/reachability.js.map +1 -0
  19. package/dist/src/contract/generated/remote.d.ts +64 -0
  20. package/dist/src/contract/generated/remote.js +3 -0
  21. package/dist/src/contract/generated/remote.js.map +1 -0
  22. package/dist/src/contract/generated/run.d.ts +3 -1
  23. package/dist/src/contract/generated/unreadable.d.ts +15 -0
  24. package/dist/src/contract/generated/unreadable.js +3 -0
  25. package/dist/src/contract/generated/unreadable.js.map +1 -0
  26. package/dist/src/contract/generated/version.d.ts +1 -1
  27. package/dist/src/contract/index.d.ts +1 -1
  28. package/dist/src/contract/index.js +1 -1
  29. package/dist/src/contract/index.js.map +1 -1
  30. package/dist/src/daemon/daemon.d.ts +6 -0
  31. package/dist/src/daemon/daemon.js +2 -0
  32. package/dist/src/daemon/daemon.js.map +1 -1
  33. package/dist/src/daemon/fleet-routes.d.ts +40 -0
  34. package/dist/src/daemon/fleet-routes.js +111 -0
  35. package/dist/src/daemon/fleet-routes.js.map +1 -0
  36. package/dist/src/daemon/http.d.ts +2 -2
  37. package/dist/src/daemon/http.js +5 -4
  38. package/dist/src/daemon/http.js.map +1 -1
  39. package/dist/src/daemon/main.js +16 -1
  40. package/dist/src/daemon/main.js.map +1 -1
  41. package/dist/src/daemon/ports.d.ts +22 -4
  42. package/dist/src/daemon/routes.d.ts +6 -1
  43. package/dist/src/daemon/routes.js +34 -0
  44. package/dist/src/daemon/routes.js.map +1 -1
  45. package/dist/src/daemon/secrets.js +2 -0
  46. package/dist/src/daemon/secrets.js.map +1 -1
  47. package/dist/src/fleet/aliases.d.ts +17 -0
  48. package/dist/src/fleet/aliases.js +62 -0
  49. package/dist/src/fleet/aliases.js.map +1 -0
  50. package/dist/src/fleet/announce.d.ts +53 -0
  51. package/dist/src/fleet/announce.js +126 -0
  52. package/dist/src/fleet/announce.js.map +1 -0
  53. package/dist/src/fleet/bundle.d.ts +21 -0
  54. package/dist/src/fleet/bundle.js +88 -0
  55. package/dist/src/fleet/bundle.js.map +1 -0
  56. package/dist/src/fleet/cert.d.ts +43 -0
  57. package/dist/src/fleet/cert.js +110 -0
  58. package/dist/src/fleet/cert.js.map +1 -0
  59. package/dist/src/fleet/command.d.ts +5 -0
  60. package/dist/src/fleet/command.js +71 -0
  61. package/dist/src/fleet/command.js.map +1 -0
  62. package/dist/src/fleet/config.d.ts +36 -0
  63. package/dist/src/fleet/config.js +69 -0
  64. package/dist/src/fleet/config.js.map +1 -0
  65. package/dist/src/fleet/index.d.ts +69 -0
  66. package/dist/src/fleet/index.js +120 -0
  67. package/dist/src/fleet/index.js.map +1 -0
  68. package/dist/src/fleet/members.d.ts +47 -0
  69. package/dist/src/fleet/members.js +131 -0
  70. package/dist/src/fleet/members.js.map +1 -0
  71. package/dist/src/fleet/peers.d.ts +18 -0
  72. package/dist/src/fleet/peers.js +76 -0
  73. package/dist/src/fleet/peers.js.map +1 -0
  74. package/dist/src/fleet/remote-attach.d.ts +33 -0
  75. package/dist/src/fleet/remote-attach.js +109 -0
  76. package/dist/src/fleet/remote-attach.js.map +1 -0
  77. package/dist/src/fleet/remote.d.ts +85 -0
  78. package/dist/src/fleet/remote.js +115 -0
  79. package/dist/src/fleet/remote.js.map +1 -0
  80. package/dist/src/fleet/serve-runs.d.ts +56 -0
  81. package/dist/src/fleet/serve-runs.js +176 -0
  82. package/dist/src/fleet/serve-runs.js.map +1 -0
  83. package/dist/src/fleet/transport.d.ts +85 -0
  84. package/dist/src/fleet/transport.js +243 -0
  85. package/dist/src/fleet/transport.js.map +1 -0
  86. package/dist/src/fleet/trust.d.ts +35 -0
  87. package/dist/src/fleet/trust.js +136 -0
  88. package/dist/src/fleet/trust.js.map +1 -0
  89. package/dist/src/harness/stub/backend.js +3 -1
  90. package/dist/src/harness/stub/backend.js.map +1 -1
  91. package/dist/src/index.d.ts +1 -1
  92. package/dist/src/index.js +1 -1
  93. package/dist/src/runs/admission.d.ts +15 -0
  94. package/dist/src/runs/admission.js +24 -1
  95. package/dist/src/runs/admission.js.map +1 -1
  96. package/dist/src/runs/gateway.d.ts +1 -0
  97. package/dist/src/runs/gateway.js +4 -0
  98. package/dist/src/runs/gateway.js.map +1 -1
  99. package/dist/src/runs/keys.js +5 -3
  100. package/dist/src/runs/keys.js.map +1 -1
  101. package/dist/src/runs/service.d.ts +6 -5
  102. package/dist/src/runs/service.js +25 -14
  103. package/dist/src/runs/service.js.map +1 -1
  104. package/dist/src/runs/unreadable.d.ts +8 -0
  105. package/dist/src/runs/unreadable.js +64 -0
  106. package/dist/src/runs/unreadable.js.map +1 -0
  107. package/package.json +3 -2
@@ -0,0 +1,76 @@
1
+ /**
2
+ * The local address list a core announces itself to (docs/d2/part-two-design.md, Decision 3):
3
+ * `${XDG_CONFIG_HOME:-$HOME/.config}/culture-agents/fleet/peers.json`, beside the trust list, as a
4
+ * JSON array of `"<ip>:<port>"` or `"[<ipv6>]:<port>"` strings. It is configuration, not membership:
5
+ * an address with no live core behind it is never listed, and a core is listed only under the name
6
+ * its key holds in the trust list. It is local and untracked, and it is the only place a core keeps
7
+ * an address. IP addresses only: nothing here resolves a name, so no name can redirect a call.
8
+ * A missing file announces to nobody; the core still hears the peers that announce to it.
9
+ */
10
+ import { join } from "node:path";
11
+ import { FleetConfigError, parseAddress } from "./config.js";
12
+ import { readTrustText, resolveTrustPath } from "./trust.js";
13
+ /** The most peers one core announces to; each costs one TLS handshake per interval. */
14
+ export const MAX_PEERS = 64;
15
+ export function resolvePeersPath(env = process.env) {
16
+ return join(resolveTrustPath(env), "..", "peers.json");
17
+ }
18
+ /** Parse the text of an address list. Throws `FleetConfigError` on anything but a valid list. */
19
+ export function parsePeers(text, path) {
20
+ let raw;
21
+ try {
22
+ raw = JSON.parse(text);
23
+ }
24
+ catch {
25
+ throw new FleetConfigError(`${path} is not valid JSON`);
26
+ }
27
+ if (!Array.isArray(raw))
28
+ throw new FleetConfigError(`${path} must hold a JSON array of "<ip>:<port>" strings`);
29
+ if (raw.length > MAX_PEERS)
30
+ throw new FleetConfigError(`${path} lists ${raw.length} addresses; at most ${MAX_PEERS}`);
31
+ const seen = new Set();
32
+ const out = [];
33
+ raw.forEach((value, i) => {
34
+ if (typeof value !== "string")
35
+ throw new FleetConfigError(`entry ${i} in ${path} must be a string`);
36
+ const address = parseAddress(value, `entry ${i} in ${path}`, 1);
37
+ const id = `${address.host} ${address.port}`;
38
+ if (!seen.has(id))
39
+ out.push(address);
40
+ seen.add(id);
41
+ });
42
+ return out;
43
+ }
44
+ /** The address list in `path`; empty when the file does not exist. Read with the trust file's cap. */
45
+ export function loadPeers(path) {
46
+ let text;
47
+ try {
48
+ text = readTrustText(path);
49
+ }
50
+ catch (e) {
51
+ throw new FleetConfigError(e.message);
52
+ }
53
+ return text === null ? [] : parsePeers(text, path);
54
+ }
55
+ /**
56
+ * The address list read again on every call, so the operator can change it without a restart. A
57
+ * list that turns invalid announces to nobody until it is fixed; `onError` says why, once per change.
58
+ */
59
+ export function peersSource(path, onError) {
60
+ let lastError = null;
61
+ return () => {
62
+ try {
63
+ const peers = loadPeers(path);
64
+ lastError = null;
65
+ return peers;
66
+ }
67
+ catch (e) {
68
+ const message = e.message;
69
+ if (message !== lastError)
70
+ onError(`fleet address list refused, announcing to nobody until it is fixed: ${message}`);
71
+ lastError = message;
72
+ return [];
73
+ }
74
+ };
75
+ }
76
+ //# sourceMappingURL=peers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"peers.js","sourceRoot":"","sources":["../../../src/fleet/peers.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAO7D,uFAAuF;AACvF,MAAM,CAAC,MAAM,SAAS,GAAG,EAAE,CAAC;AAI5B,MAAM,UAAU,gBAAgB,CAAC,MAAW,OAAO,CAAC,GAAG;IACrD,OAAO,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,EAAE,IAAI,EAAE,YAAY,CAAC,CAAC;AACzD,CAAC;AAED,iGAAiG;AACjG,MAAM,UAAU,UAAU,CAAC,IAAY,EAAE,IAAY;IACnD,IAAI,GAAY,CAAC;IACjB,IAAI,CAAC;QACH,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACzB,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,IAAI,gBAAgB,CAAC,GAAG,IAAI,oBAAoB,CAAC,CAAC;IAC1D,CAAC;IACD,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC;QAAE,MAAM,IAAI,gBAAgB,CAAC,GAAG,IAAI,kDAAkD,CAAC,CAAC;IAC/G,IAAI,GAAG,CAAC,MAAM,GAAG,SAAS;QAAE,MAAM,IAAI,gBAAgB,CAAC,GAAG,IAAI,UAAU,GAAG,CAAC,MAAM,uBAAuB,S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AAS,CAAC,IAAI,CAAC,CAAC;YAC9B,SAAS,GAAG,IAAI,CAAC;YACjB,OAAO,KAAK,CAAC;QACf,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,MAAM,OAAO,GAAI,CAAW,CAAC,OAAO,CAAC;YACrC,IAAI,OAAO,KAAK,SAAS;gBAAE,OAAO,CAAC,uEAAuE,OAAO,EAAE,CAAC,CAAC;YACrH,SAAS,GAAG,OAAO,CAAC;YACpB,OAAO,EAAE,CAAC;QACZ,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,33 @@
1
+ /**
2
+ * `fleet.runs.attach` on the calling core: the events of a run on another member, as an SSE stream
3
+ * on the control socket, read from the member one page at a time (`GET /v1/fleet/runs/{id}/events`).
4
+ * Each page is one call with its own timeout and a byte cap, so no read from the network is
5
+ * unbounded and no call can hang; a stream to the operator stays open as long as the run is active.
6
+ *
7
+ * - The first page is read before the response starts, so a refusal (`not_found`, `denied`,
8
+ * `unavailable`, ...) is an ordinary JSON error.
9
+ * - Events go out in cursor order, each once; a duplicate is skipped, and a gap or an event of
10
+ * another run ends the stream (the client attaches again from its last cursor and gets the rest).
11
+ * - The stream closes after the terminal `run.state` event, or at once when the run is already
12
+ * terminal with nothing after `after`. When the member stops answering mid-stream, the stream
13
+ * ends; the CLI reconnects with its last cursor, and a reconnect that fails is `unavailable`.
14
+ */
15
+ import type { ServerResponse } from "node:http";
16
+ import type { Remote } from "./remote.js";
17
+ /** Events asked for per page: an event's text is at most 100 000 characters, so a page stays under the cap. */
18
+ export declare const ATTACH_PAGE = 10;
19
+ /** The most one page's response may hold. */
20
+ export declare const MAX_PAGE_BYTES: number;
21
+ /** How long to wait before asking again when the member had nothing new. */
22
+ export declare const ATTACH_POLL_MS = 250;
23
+ export interface RemoteAttach {
24
+ remote: Remote;
25
+ node: string;
26
+ runId: string;
27
+ after: number;
28
+ res: ServerResponse;
29
+ keepaliveMs: number;
30
+ shutdown: AbortSignal;
31
+ pollMs?: number;
32
+ }
33
+ export declare function streamRemoteAttach(a: RemoteAttach, log?: (line: string) => void): Promise<void>;
@@ -0,0 +1,109 @@
1
+ import { isTerminal, validate } from "../contract/index.js";
2
+ import { sseFrame } from "../daemon/http.js";
3
+ import { SENSITIVITY_HEADER } from "./bundle.js";
4
+ /** Events asked for per page: an event's text is at most 100 000 characters, so a page stays under the cap. */
5
+ export const ATTACH_PAGE = 10;
6
+ /** The most one page's response may hold. */
7
+ export const MAX_PAGE_BYTES = 8 * 1024 * 1024;
8
+ /** How long to wait before asking again when the member had nothing new. */
9
+ export const ATTACH_POLL_MS = 250;
10
+ const page = (a, after) => a.remote.request(a.node, {
11
+ method: "GET",
12
+ path: `/v1/fleet/runs/${encodeURIComponent(a.runId)}/events?after=${after}&limit=${ATTACH_PAGE}`,
13
+ status: 200,
14
+ schema: "event#event_page",
15
+ maxBytes: MAX_PAGE_BYTES,
16
+ });
17
+ const terminalEvent = (e) => e.kind === "run.state" && isTerminal(e.data.to);
18
+ /** Sleep `ms`, or less when `signal` aborts. True when the stream goes on (the signal did not abort). */
19
+ function pause(ms, signal) {
20
+ return new Promise((resolve) => {
21
+ const timer = setTimeout(done, ms);
22
+ function done() {
23
+ clearTimeout(timer);
24
+ signal.removeEventListener("abort", done);
25
+ resolve(!signal.aborted);
26
+ }
27
+ signal.addEventListener("abort", done, { once: true });
28
+ });
29
+ }
30
+ /** Write the page's new events; returns the new cursor and whether the stream is over. */
31
+ function writePage(a, p, cursor, log) {
32
+ let at = cursor;
33
+ for (const event of p.events) {
34
+ if (event.cursor <= at)
35
+ continue; // already sent
36
+ if (event.cursor !== at + 1 || event.run_id !== a.runId || !validate("event", event).ok) {
37
+ log(`culture-agents core: ending the stream of remote run ${a.runId}: ${a.node} sent event ${event.cursor} after ${at}, or an event that is not this run's`);
38
+ return { cursor: at, over: true };
39
+ }
40
+ a.res.write(sseFrame(event.cursor, event.kind, event));
41
+ at = event.cursor;
42
+ if (terminalEvent(event))
43
+ return { cursor: at, over: true };
44
+ }
45
+ return { cursor: at, over: false };
46
+ }
47
+ /** Whether the run is terminal with nothing after `after`: then the stream closes at once. */
48
+ async function finishedAt(a, first) {
49
+ if (first.events.length > 0 || first.last_cursor > a.after)
50
+ return false;
51
+ const run = (await a.remote.request(a.node, { method: "GET", path: `/v1/fleet/runs/${encodeURIComponent(a.runId)}`, status: 200, schema: "remote" }));
52
+ return run.terminal;
53
+ }
54
+ /**
55
+ * Write `first`, then each next page, until the stream is over: a terminal event, a bad page, an
56
+ * abort or a failed call. Each step schedules the next from its own callback, so no promise chain
57
+ * grows however long the run streams. Resolves with the last cursor written.
58
+ */
59
+ function follow(a, first, signal, log) {
60
+ return new Promise((resolve) => {
61
+ let cursor = a.after;
62
+ const end = (e) => {
63
+ if (e !== undefined)
64
+ log(`culture-agents core: the stream of remote run ${a.runId} ended after cursor ${cursor}: ${e instanceof Error ? e.message : "an unknown error"}`);
65
+ resolve(cursor);
66
+ };
67
+ const step = (current) => {
68
+ const written = writePage(a, current, cursor, log);
69
+ cursor = written.cursor;
70
+ if (written.over || signal.aborted)
71
+ return end();
72
+ const wait = current.more ? Promise.resolve(true) : pause(a.pollMs ?? ATTACH_POLL_MS, signal);
73
+ wait
74
+ .then((goOn) => (goOn ? page(a, cursor) : null))
75
+ .then((next) => (next === null ? end() : step(next)))
76
+ .catch(end);
77
+ };
78
+ try {
79
+ step(first);
80
+ }
81
+ catch (e) {
82
+ end(e);
83
+ }
84
+ });
85
+ }
86
+ export async function streamRemoteAttach(a, log = (l) => process.stderr.write(`${l}\n`)) {
87
+ const first = await page(a, a.after); // refusals happen here, before the stream starts
88
+ const done = await finishedAt(a, first);
89
+ const abort = new AbortController();
90
+ const stop = () => abort.abort();
91
+ a.res.once("close", stop);
92
+ a.shutdown.addEventListener("abort", stop, { once: true });
93
+ // The member's events as it stored them, unredacted (t26): the response says so.
94
+ a.res.writeHead(200, { "Content-Type": "text/event-stream; charset=utf-8", "Cache-Control": "no-cache", Connection: "keep-alive", [SENSITIVITY_HEADER]: "unredacted" });
95
+ a.res.flushHeaders();
96
+ const keepalive = setInterval(() => a.res.write(": keepalive\n\n"), a.keepaliveMs);
97
+ try {
98
+ if (!done)
99
+ await follow(a, first, abort.signal, log);
100
+ }
101
+ finally {
102
+ clearInterval(keepalive);
103
+ a.res.off("close", stop);
104
+ a.shutdown.removeEventListener("abort", stop);
105
+ if (!a.res.writableEnded)
106
+ a.res.end();
107
+ }
108
+ }
109
+ //# sourceMappingURL=remote-attach.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"remote-attach.js","sourceRoot":"","sources":["../../../src/fleet/remote-attach.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAiE,MAAM,sBAAsB,CAAC;AAC3H,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE7C,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEjD,+GAA+G;AAC/G,MAAM,CAAC,MAAM,WAAW,GAAG,EAAE,CAAC;AAC9B,6CAA6C;AAC7C,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC;AAC9C,4EAA4E;AAC5E,MAAM,CAAC,MAAM,cAAc,GAAG,GAAG,CAAC;AAalC,MAAM,IAAI,GAAG,CAAC,CAAe,EAAE,KAAa,EAAsB,EAAE,CAClE,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,EAAE;IACvB,MAAM,EAAE,KAAK;IACb,IAAI,EAAE,kBAAkB,kBAAkB,CAAC,CAAC,CAAC,KAAK,CAAC,iBAAiB,KAAK,UAAU,WAAW,EAAE;IAChG,MAAM,EAAE,GAAG;IACX,MAAM,EAAE,kBAAkB;IAC1B,QAAQ,EAAE,cAAc;CACzB,CAAuB,CAAC;AAE3B,MAAM,aAAa,GAAG,CAAC,CAAW,EAAW,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,WAAW,IAAI,UA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AAC,GAAG,CAAC,aAAa;YAAE,CAAC,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC;IACxC,CAAC;AACH,CAAC"}
@@ -0,0 +1,85 @@
1
+ /**
2
+ * Remote control calls on the calling core (contract 3.2): one call to another fleet member over the
3
+ * fleet transport, on behalf of the local operator's request on the control socket. The caller
4
+ * chooses the member (the node of the agent id or run id); nothing schedules.
5
+ *
6
+ * A call goes only to a member that is listed now (it announced itself within the silence, under the
7
+ * name the trust list gives its key) and only to an address of the local address list whose last
8
+ * reply was authenticated as that member's key; the transport checks that key again on the call
9
+ * (`expectNode`), so neither a name nor a stale address can reach another host. Then:
10
+ *
11
+ * - Version rule between cores (contract/README.md, "Calls between cores"): the member's announced
12
+ * MAJOR must equal this core's (else `incompatible_version`), and its MINOR must have the route
13
+ * (else `unsupported`, `placement`). The call carries this core's `Agents-Api-Version`.
14
+ * - Every call has one timeout (5 s) and a cap on what it reads. A member that does not answer, or
15
+ * answers more than the cap, is `unavailable`: never a hang, and nothing is stored on this core.
16
+ * - The member's answer is checked against the contract: the expected shape is returned, a typed
17
+ * error is relayed as that error (naming the member), anything else is `internal`.
18
+ */
19
+ import type { KeyObject } from "node:crypto";
20
+ import { type SchemaName } from "../contract/index.js";
21
+ import { ControlError } from "../daemon/errors.js";
22
+ import type { Members } from "./members.js";
23
+ import type { PeerAddress } from "./peers.js";
24
+ import { type FleetCallOptions, type FleetResponse } from "./transport.js";
25
+ import type { TrustList } from "./trust.js";
26
+ /** The MINOR that added remote runs: a member that announced less does not serve them. */
27
+ export declare const REMOTE_RUNS_SINCE = "3.2";
28
+ type Call = (o: FleetCallOptions) => Promise<FleetResponse>;
29
+ export interface RemoteOptions {
30
+ key: KeyObject;
31
+ /** This core's trust list, read again for each call. */
32
+ trust: () => TrustList;
33
+ members: Members;
34
+ /** The address whose last reply was authenticated as `node` (announce.ts). */
35
+ addressOf: (node: string) => PeerAddress | undefined;
36
+ /** The API version this core speaks. Default: this build's; tests use an older MINOR. */
37
+ apiVersion?: string;
38
+ timeoutMs?: number;
39
+ /** The transport call (tests inject one). */
40
+ call?: Call;
41
+ }
42
+ export interface RemoteRequest {
43
+ method: "GET" | "POST";
44
+ path: string;
45
+ body?: unknown;
46
+ /** The success status and the shape its body must have. */
47
+ status: number;
48
+ schema: SchemaName;
49
+ /** Default: the transport's 1 MiB. */
50
+ maxBytes?: number;
51
+ /** The MINOR the member must have announced (default: REMOTE_RUNS_SINCE), and what needs it, for the refusal. */
52
+ since?: string;
53
+ what?: string;
54
+ /** Default: the remote options' timeout (5 s). */
55
+ timeoutMs?: number;
56
+ }
57
+ /** A GET whose success body is bytes, not JSON (a run's bundle, 3.3); a refusal is still a typed JSON error. */
58
+ export interface RemoteBytesRequest {
59
+ path: string;
60
+ maxBytes: number;
61
+ timeoutMs: number;
62
+ since: string;
63
+ what: string;
64
+ /** Whether a 200 body is what was asked for. */
65
+ accept: (body: Buffer) => boolean;
66
+ }
67
+ export interface Remote {
68
+ /** This core's API version, as it sends it. */
69
+ readonly apiVersion: string;
70
+ /** One call to member `node`: the checked success body, or a `ControlError`. */
71
+ request(node: string, r: RemoteRequest): Promise<unknown>;
72
+ /** One GET to member `node` whose success body is bytes: those bytes, or a `ControlError`. */
73
+ fetchBytes(node: string, r: RemoteBytesRequest): Promise<Buffer>;
74
+ }
75
+ /**
76
+ * The member does not answer this caller: not in the member list (but trusted), or a call to it that
77
+ * failed. It is a `unavailable` error for every route that needs the member, and the one thing the
78
+ * unreachable view (contract 3.3, `fleet.runs.view`) reads. It is never stored.
79
+ */
80
+ export declare class Unreached extends ControlError {
81
+ readonly reason: "not_listed" | "no_answer";
82
+ constructor(reason: "not_listed" | "no_answer", message: string);
83
+ }
84
+ export declare function createRemote(o: RemoteOptions): Remote;
85
+ export {};
@@ -0,0 +1,115 @@
1
+ import { API_VERSION_HEADER, apiVersion, isPeerCompatible, servesSince, validate } from "../contract/index.js";
2
+ import { ControlError, unavailable, unsupported } from "../daemon/errors.js";
3
+ import { FLEET_TIMEOUT_MS, FleetCallError, MAX_RESPONSE_BYTES, fleetCall } from "./transport.js";
4
+ /** The MINOR that added remote runs: a member that announced less does not serve them. */
5
+ export const REMOTE_RUNS_SINCE = "3.2";
6
+ /**
7
+ * The member does not answer this caller: not in the member list (but trusted), or a call to it that
8
+ * failed. It is a `unavailable` error for every route that needs the member, and the one thing the
9
+ * unreachable view (contract 3.3, `fleet.runs.view`) reads. It is never stored.
10
+ */
11
+ export class Unreached extends ControlError {
12
+ reason;
13
+ constructor(reason, message) {
14
+ super("unavailable", message.slice(0, 500));
15
+ this.reason = reason;
16
+ this.name = "Unreached";
17
+ }
18
+ }
19
+ function parsed(body) {
20
+ try {
21
+ return JSON.parse(body.toString("utf8"));
22
+ }
23
+ catch {
24
+ return undefined;
25
+ }
26
+ }
27
+ /** The member's typed error, relayed with the member named in its message. */
28
+ function relayed(node, error) {
29
+ const { code, message, retryable, ...extras } = error;
30
+ return new ControlError(code, `${node}: ${message}`.slice(0, 2000), { ...extras, retryable });
31
+ }
32
+ /**
33
+ * A failed call to `node`. A member that answered more than `cap` bytes, or with a key its trust entry
34
+ * does not hold, did answer: a typed `unavailable` saying so. Anything else (a timeout, a closed or
35
+ * refused connection) is a member that did not answer, which the unreachable view reads.
36
+ */
37
+ function callFailure(node, e, cap) {
38
+ const message = e instanceof Error ? e.message : "an unknown error";
39
+ if (e instanceof FleetCallError && e.code === "ETOOLARGE")
40
+ return unavailable(`${node} answered more than ${cap} bytes; nothing of the answer was kept.`);
41
+ if (e instanceof FleetCallError && e.code === "EUNTRUSTED")
42
+ return unavailable(`${node} answered with a key its entry in this core's trust list does not hold: ${message}`.slice(0, 2000));
43
+ return new Unreached("no_answer", `${node} did not answer: ${message}`.slice(0, 2000));
44
+ }
45
+ /** The member's typed error relayed, or `internal` for an answer outside the contract. */
46
+ function refusal(node, res) {
47
+ const error = validate("error", parsed(res.body));
48
+ if (error.ok)
49
+ return relayed(node, error.value.error);
50
+ return new ControlError("internal", `${node} answered HTTP ${res.status} with a body that does not match the contract.`);
51
+ }
52
+ export function createRemote(o) {
53
+ const own = o.apiVersion ?? apiVersion;
54
+ const call = o.call ?? fleetCall;
55
+ /** The member's address once the version rule allows the call. */
56
+ function target(node, since, what) {
57
+ const member = o.members.view().members.find((m) => m.node === node);
58
+ if (!member) {
59
+ const text = `${node} is not a listed fleet member: it has not announced itself to this core within the silence limit, or its key is not in this core's trust list.`;
60
+ // A trusted member that is not listed is silent; a name the trust list lacks is not a member at all.
61
+ throw o.trust().some((t) => t.node === node) ? new Unreached("not_listed", text) : unavailable(text);
62
+ }
63
+ if (!isPeerCompatible(own, member.api_version)) {
64
+ throw new ControlError("incompatible_version", `${node} speaks API ${member.api_version} and this core ${own}; cores call each other only within one MAJOR version.`, {
65
+ client_api_version: own,
66
+ server_api_version: member.api_version,
67
+ });
68
+ }
69
+ if (!servesSince(member.api_version, since))
70
+ throw unsupported("placement", `${node} speaks API ${member.api_version}; ${what} need API ${since} or later on that member. Upgrade it.`);
71
+ const address = o.addressOf(node);
72
+ if (!address)
73
+ throw new Unreached("no_answer", `No address in this core's fleet address list (peers.json) has answered as ${node}; add its address there.`);
74
+ return address;
75
+ }
76
+ async function send(node, r) {
77
+ const address = target(node, r.since ?? REMOTE_RUNS_SINCE, r.what ?? "runs on another member");
78
+ try {
79
+ return await call({
80
+ key: o.key,
81
+ trust: o.trust(),
82
+ host: address.host,
83
+ port: address.port,
84
+ method: r.method,
85
+ path: r.path,
86
+ ...(r.body !== undefined && { body: JSON.stringify(r.body) }),
87
+ expectNode: node,
88
+ headers: { [API_VERSION_HEADER]: own },
89
+ timeoutMs: r.timeoutMs ?? o.timeoutMs ?? FLEET_TIMEOUT_MS,
90
+ maxResponseBytes: r.maxBytes ?? MAX_RESPONSE_BYTES,
91
+ });
92
+ }
93
+ catch (e) {
94
+ throw callFailure(node, e, r.maxBytes ?? MAX_RESPONSE_BYTES);
95
+ }
96
+ }
97
+ return {
98
+ apiVersion: own,
99
+ async request(node, r) {
100
+ const res = await send(node, r);
101
+ const body = parsed(res.body);
102
+ if (res.status === r.status && validate(r.schema, body).ok)
103
+ return body;
104
+ throw refusal(node, res);
105
+ },
106
+ async fetchBytes(node, r) {
107
+ const { path, maxBytes, timeoutMs, since, what } = r;
108
+ const res = await send(node, { method: "GET", path, status: 200, schema: "error", maxBytes, timeoutMs, since, what });
109
+ if (res.status === 200 && r.accept(res.body))
110
+ return res.body;
111
+ throw refusal(node, res);
112
+ },
113
+ };
114
+ }
115
+ //# sourceMappingURL=remote.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"remote.js","sourceRoot":"","sources":["../../../src/fleet/remote.ts"],"names":[],"mappings":"AAoBA,OAAO,EAAE,kBAAkB,EAAE,UAAU,EAAE,gBAAgB,EAAE,WAAW,EAAE,QAAQ,EAAmC,MAAM,sBAAsB,CAAC;AAChJ,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAG7E,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,kBAAkB,EAAE,SAAS,EAA6C,MAAM,gBAAgB,CAAC;AAG5I,0FAA0F;AAC1F,MAAM,CAAC,MAAM,iBAAiB,GAAG,KAAK,CAAC;AAsDvC;;;;GAIG;AACH,MAAM,OAAO,SAAU,SAAQ,YAAY;IAE9B;IADX,YACW,MAAkC,EAC3C,OAAe;QAEf,KAAK,CAAC,aAAa,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC;QAHnC,WAAM,GAAN,MAAM,CAA4B;QAI3C,IAAI,CAAC,IAAI,GAAG,WAAW,CAAC;IAC1B,CAAC;CACF;AAED,SAAS,MAAM,CAAC,IAAY;IAC1B,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC;IAC3C,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;A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AAI,kBAAkB,CAAC,CAAC;QAC/D,CAAC;IACH,CAAC;IAED,OAAO;QACL,UAAU,EAAE,GAAG;QACf,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;YACnB,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;YAChC,MAAM,IAAI,GAAG,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;YAC9B,IAAI,GAAG,CAAC,MAAM,KAAK,CAAC,CAAC,MAAM,IAAI,QAAQ,CAAC,CAAC,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,EAAE;gBAAE,OAAO,IAAI,CAAC;YACxE,MAAM,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;QAC3B,CAAC;QACD,KAAK,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC;YACtB,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,CAAC,CAAC;YACrD,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;YACtH,IAAI,GAAG,CAAC,MAAM,KAAK,GAAG,IAAI,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC;gBAAE,OAAO,GAAG,CAAC,IAAI,CAAC;YAC9D,MAAM,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;QAC3B,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Remote runs on the executing core (docs/d2/part-two-design.md, Decisions 4 and 5; contract 3.2):
3
+ * the routes the fleet transport serves an authenticated member besides version, announce and the
4
+ * member list. Each request comes from a member the transport authenticated against the trust list
5
+ * before any request byte was read (transport.ts); `member` is that member's trust-list entry.
6
+ *
7
+ * - `POST /v1/fleet/runs`: a submit. The repository is an alias this host defines (aliases.ts),
8
+ * resolved to an allow-listed path; the allow-list applies to that path unchanged. A named
9
+ * `base_commit` the aliased checkout lacks is refused `invalid`, and nothing is fetched; without
10
+ * one the run starts from this host's HEAD at acceptance, which the response returns. The deadline
11
+ * arrives as a duration and becomes an absolute time on this core's clock (spec c42). The run's
12
+ * submitter is the member, `{ kind: "member", node }`, never a request field.
13
+ * - `GET /v1/fleet/runs/{id}`, `GET .../events`, `POST .../steer`, `POST .../cancel`: only on a run
14
+ * that this member submitted (`denied` otherwise). The local operator keeps full control of every
15
+ * run through the control socket; nothing here widens what a member may do.
16
+ * - `GET /v1/fleet/runs/{id}/result` and `GET .../bundle` (3.3, bundle.ts): the outcome of a finished
17
+ * run this member submitted, and its branch as a git bundle holding only that run's ref. Events,
18
+ * result and bundle cross unredacted; events and bundle carry the sensitivity header.
19
+ * - `GET /v1/fleet/aliases`: this host's aliases and what the allow-list permits on each, no path.
20
+ *
21
+ * Every one of these routes requires the `Agents-Api-Version` header and serves a caller of the same
22
+ * MAJOR whatever its MINOR (contract/README.md, "Calls between cores"). Bodies are capped (1 MiB).
23
+ */
24
+ import type { IncomingMessage, ServerResponse } from "node:http";
25
+ import { type EventPage, type RemoteRun, type Run } from "../contract/index.js";
26
+ import { type AllowlistState } from "../daemon/allowlist.js";
27
+ import type { RunService } from "../daemon/ports.js";
28
+ import { type AliasState } from "./aliases.js";
29
+ import type { TrustEntry } from "./trust.js";
30
+ /** The most events one page over the fleet transport carries (the caller asks for fewer). */
31
+ export declare const MAX_MEMBER_PAGE = 50;
32
+ export interface RunsDeps {
33
+ service: RunService;
34
+ allowlist: () => AllowlistState;
35
+ aliases: () => AliasState;
36
+ /** This core's node name. */
37
+ node: string;
38
+ /** The API version this core reports (api.json; tests inject an older MINOR). */
39
+ apiVersion: string;
40
+ now: () => Date;
41
+ /** Whether `repo` holds commit `sha`. Default: `git cat-file -e`. */
42
+ hasCommit?: (repo: string, sha: string) => Promise<boolean>;
43
+ }
44
+ /** Same MAJOR, any MINOR. Required on the remote-run routes; checked when present on the 3.1 routes (announce, members). */
45
+ export declare function checkPeerVersion(req: IncomingMessage, own: string, required?: boolean): void;
46
+ /** The run as another member sees it: no repository path. */
47
+ export declare function remoteView(run: Run): RemoteRun;
48
+ /** The most one events page may hold, well under the caller's `MAX_PAGE_BYTES` read cap. */
49
+ export declare const PAGE_BUDGET_BYTES: number;
50
+ /**
51
+ * `page` cut to the first events that fit `PAGE_BUDGET_BYTES`, with `more` set when any were left
52
+ * out. At least one event stays: one event's text is at most 100 000 characters, far under it.
53
+ */
54
+ export declare function fitPage(page: EventPage): EventPage;
55
+ /** Serve one remote-run route; false when `method path` is not one (the caller answers `not_found`). The version is checked first. */
56
+ export declare function serveRuns(d: RunsDeps, member: TrustEntry, req: IncomingMessage, res: ServerResponse, url: URL): Promise<boolean>;