@cotal-ai/manager 0.190.0 → 0.192.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.
Files changed (117) hide show
  1. package/README.md +9 -5
  2. package/dist/boot.d.ts.map +1 -1
  3. package/dist/boot.js +3 -0
  4. package/dist/boot.js.map +1 -1
  5. package/dist/command-dispatch.d.ts +2 -0
  6. package/dist/command-dispatch.d.ts.map +1 -1
  7. package/dist/command-dispatch.js +8 -0
  8. package/dist/command-dispatch.js.map +1 -1
  9. package/dist/commands.d.ts +4 -0
  10. package/dist/commands.d.ts.map +1 -1
  11. package/dist/commands.js +57 -20
  12. package/dist/commands.js.map +1 -1
  13. package/dist/connector-inventory.d.ts +20 -3
  14. package/dist/connector-inventory.d.ts.map +1 -1
  15. package/dist/connector-inventory.js +65 -13
  16. package/dist/connector-inventory.js.map +1 -1
  17. package/dist/harness-resolution.d.ts +14 -2
  18. package/dist/harness-resolution.d.ts.map +1 -1
  19. package/dist/harness-resolution.js +16 -2
  20. package/dist/harness-resolution.js.map +1 -1
  21. package/dist/harness-sessions-contract.d.ts +115 -0
  22. package/dist/harness-sessions-contract.d.ts.map +1 -0
  23. package/dist/harness-sessions-contract.js +53 -0
  24. package/dist/harness-sessions-contract.js.map +1 -0
  25. package/dist/harness-sessions.d.ts +116 -0
  26. package/dist/harness-sessions.d.ts.map +1 -0
  27. package/dist/harness-sessions.js +335 -0
  28. package/dist/harness-sessions.js.map +1 -0
  29. package/dist/hosted-connector-observation.d.ts +7 -0
  30. package/dist/hosted-connector-observation.d.ts.map +1 -0
  31. package/dist/hosted-connector-observation.js +13 -0
  32. package/dist/hosted-connector-observation.js.map +1 -0
  33. package/dist/index.d.ts +2 -1
  34. package/dist/index.d.ts.map +1 -1
  35. package/dist/index.js +1 -1
  36. package/dist/index.js.map +1 -1
  37. package/dist/interrupted-run-recovery.d.ts +30 -0
  38. package/dist/interrupted-run-recovery.d.ts.map +1 -0
  39. package/dist/interrupted-run-recovery.js +156 -0
  40. package/dist/interrupted-run-recovery.js.map +1 -0
  41. package/dist/interrupted-run-retry.d.ts +11 -0
  42. package/dist/interrupted-run-retry.d.ts.map +1 -0
  43. package/dist/interrupted-run-retry.js +44 -0
  44. package/dist/interrupted-run-retry.js.map +1 -0
  45. package/dist/launch.d.ts.map +1 -1
  46. package/dist/launch.js +5 -20
  47. package/dist/launch.js.map +1 -1
  48. package/dist/maintenance-contract.d.ts +57 -0
  49. package/dist/maintenance-contract.d.ts.map +1 -0
  50. package/dist/maintenance-contract.js +19 -0
  51. package/dist/maintenance-contract.js.map +1 -0
  52. package/dist/manager-config.d.ts +6 -3
  53. package/dist/manager-config.d.ts.map +1 -1
  54. package/dist/manager-config.js +6 -1
  55. package/dist/manager-config.js.map +1 -1
  56. package/dist/manager-service-contract.d.ts +15 -1
  57. package/dist/manager-service-contract.d.ts.map +1 -1
  58. package/dist/manager-service-contract.js +17 -19
  59. package/dist/manager-service-contract.js.map +1 -1
  60. package/dist/manager.d.ts +15 -12
  61. package/dist/manager.d.ts.map +1 -1
  62. package/dist/manager.js +8 -1
  63. package/dist/manager.js.map +1 -1
  64. package/dist/names-capacity.d.ts +1 -0
  65. package/dist/names-capacity.d.ts.map +1 -1
  66. package/dist/names-capacity.js +5 -3
  67. package/dist/names-capacity.js.map +1 -1
  68. package/dist/preservation.d.ts +2 -2
  69. package/dist/preservation.d.ts.map +1 -1
  70. package/dist/preservation.js +16 -5
  71. package/dist/preservation.js.map +1 -1
  72. package/dist/preserved-resume.d.ts +3 -4
  73. package/dist/preserved-resume.d.ts.map +1 -1
  74. package/dist/preserved-resume.js +21 -18
  75. package/dist/preserved-resume.js.map +1 -1
  76. package/dist/readiness-wait.d.ts.map +1 -1
  77. package/dist/readiness-wait.js +5 -1
  78. package/dist/readiness-wait.js.map +1 -1
  79. package/dist/resume.d.ts +2 -5
  80. package/dist/resume.d.ts.map +1 -1
  81. package/dist/resume.js +20 -8
  82. package/dist/resume.js.map +1 -1
  83. package/dist/run-hosting.d.ts +18 -0
  84. package/dist/run-hosting.d.ts.map +1 -1
  85. package/dist/run-hosting.js +115 -17
  86. package/dist/run-hosting.js.map +1 -1
  87. package/dist/runtime/custodial-pty.d.ts.map +1 -1
  88. package/dist/runtime/custodial-pty.js +2 -0
  89. package/dist/runtime/custodial-pty.js.map +1 -1
  90. package/dist/runtime/headless.d.ts +4 -0
  91. package/dist/runtime/headless.d.ts.map +1 -0
  92. package/dist/runtime/headless.js +62 -0
  93. package/dist/runtime/headless.js.map +1 -0
  94. package/dist/runtime/pty.d.ts.map +1 -1
  95. package/dist/runtime/pty.js +3 -0
  96. package/dist/runtime/pty.js.map +1 -1
  97. package/dist/seat-launch.d.ts +12 -0
  98. package/dist/seat-launch.d.ts.map +1 -1
  99. package/dist/seat-launch.js +36 -0
  100. package/dist/seat-launch.js.map +1 -1
  101. package/dist/seat-start.d.ts +1 -0
  102. package/dist/seat-start.d.ts.map +1 -1
  103. package/dist/seat-start.js +13 -7
  104. package/dist/seat-start.js.map +1 -1
  105. package/dist/seat-types.d.ts +9 -1
  106. package/dist/seat-types.d.ts.map +1 -1
  107. package/dist/service-adapter.d.ts.map +1 -1
  108. package/dist/service-adapter.js +2 -0
  109. package/dist/service-adapter.js.map +1 -1
  110. package/dist/status-and-models.d.ts +2 -0
  111. package/dist/status-and-models.d.ts.map +1 -1
  112. package/dist/status-and-models.js +14 -3
  113. package/dist/status-and-models.js.map +1 -1
  114. package/dist/terminal-input.d.ts.map +1 -1
  115. package/dist/terminal-input.js +8 -0
  116. package/dist/terminal-input.js.map +1 -1
  117. package/package.json +12 -12
@@ -0,0 +1,335 @@
1
+ /**
2
+ * The manager's `harness-sessions` read and the `ncs1_` handles it issues (Manager revision 59):
3
+ * the saved sessions a harness keeps for one directory on this host, listed for the person who owns
4
+ * this Manager before any seat exists, and the seat modes its launch catalog offers. A row never
5
+ * carries the harness's session id. It carries an opaque handle that only this Manager instance
6
+ * resolves, only for the same caller, connector, directory and listing, only within 120 seconds, and
7
+ * only in a `spawn` whose `resume` names it, where it resolves to that id before anything is
8
+ * provisioned. The connector still forks the session (`--resume <id> --fork-session` for Claude), so
9
+ * the saved source is never written.
10
+ */
11
+ import { randomBytes } from "node:crypto";
12
+ import { homedir } from "node:os";
13
+ import { EpEnvelopeError, loadCotalConfig, ProjectConfigTrustError, rejectionText, SEAT_MODE_OPTION, spawnEnvAllow } from "@cotal-ai/core";
14
+ import { isCommandFailure, isTrustedProject } from "@cotal-ai/workspace";
15
+ /** The prefix every handle starts with. A legacy plain `resume` value never takes it. */
16
+ export const SESSION_HANDLE_PREFIX = "ncs1_";
17
+ /** How long a listed handle resolves. */
18
+ export const SESSION_HANDLE_TTL_MS = 120_000;
19
+ /** The most rows one reply carries, and the default page. */
20
+ export const SESSION_LIST_MAX = 32;
21
+ export const SESSION_LIST_DEFAULT = 20;
22
+ /** The most live handles, and the most live cursors, this Manager keeps at once. A listing is
23
+ * admitted only when a handle for every row it may hand out, on this page and on the pages its cursor
24
+ * serves later, fits beside those already held; one that does not is refused `resource-exhausted` and
25
+ * issues nothing. So a live handle or cursor is never dropped before its 120 seconds end, and a
26
+ * cursor's next page always fits. */
27
+ export const HANDLE_TABLE_MAX = 4096;
28
+ /** The longest store identity and record revision a connector may name. */
29
+ const NATIVE_KEY_MAX = 512;
30
+ /** The title a row shows when the connector's own title would show its id, a path or its store. */
31
+ const NEUTRAL_TITLE = "Untitled session";
32
+ const TITLE_MAX = 120;
33
+ const SEAT_MODES_MAX = 8;
34
+ const SEAT_MODE_ID = /^[a-z0-9-]{1,32}$/;
35
+ const RFC3339_UTC_MS = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/;
36
+ const SESSION_STATES = new Set(["saved", "active", "archived", "unknown"]);
37
+ const CURSOR = /^[A-Za-z0-9_-]{24,96}$/;
38
+ const sameCaller = (a, b) => a.owner === b.owner && a.actor === b.actor && a.uid === b.uid;
39
+ const token = (bytes) => randomBytes(bytes).toString("base64url");
40
+ const nativeKey = (value) => typeof value === "string" && value.length >= 1 && value.length <= NATIVE_KEY_MAX;
41
+ /** A connector's own words (a rejection or a `supported: false` reason) stay on this host: they can
42
+ * name a native path or session, and no reply carries one. */
43
+ const logLocal = (agent, what, detail) => {
44
+ console.error(`! harness-sessions ${agent}: ${what}: ${rejectionText(detail)}`);
45
+ };
46
+ /** Code points, not UTF-16 units, so a cut never splits a surrogate pair. Control characters are
47
+ * dropped: a title is shown as text. */
48
+ function displayTitle(title) {
49
+ if (typeof title !== "string")
50
+ return undefined;
51
+ const clean = [...title.replace(/\p{C}/gu, " ").replace(/\s+/g, " ").trim()];
52
+ if (clean.length === 0)
53
+ return undefined;
54
+ return clean.length > TITLE_MAX ? `${clean.slice(0, TITLE_MAX - 1).join("")}…` : clean.join("");
55
+ }
56
+ /** The handle a `resume` names, or undefined for a legacy session id. */
57
+ export function isSessionHandle(resume) {
58
+ return resume !== undefined && resume.startsWith(SESSION_HANDLE_PREFIX);
59
+ }
60
+ /** The connector's seat modes as the reply carries them: one to eight unique rows, or absent when the
61
+ * connector offers no selector. A malformed list is the connector's fault and refuses the read. */
62
+ export function connectorSeatModes(connector, resolvedBinaries) {
63
+ if (!connector.seatModes)
64
+ return undefined;
65
+ const modes = connector.seatModes({ ...(resolvedBinaries ? { resolvedBinaries } : {}) });
66
+ const ids = new Set();
67
+ const ok = Array.isArray(modes) && modes.length >= 1 && modes.length <= SEAT_MODES_MAX && modes.every((m) => {
68
+ const fresh = typeof m?.id === "string" && SEAT_MODE_ID.test(m.id) && !ids.has(m.id);
69
+ ids.add(m?.id);
70
+ return fresh && typeof m.label === "string" && [...m.label].length >= 1 && [...m.label].length <= 80;
71
+ });
72
+ if (!ok)
73
+ throw new EpEnvelopeError("internal", `${connector.name} lists seat modes this Manager cannot carry: 1 to ${SEAT_MODES_MAX} unique ids of [a-z0-9-] with a label of 1 to 80 characters`, undefined, "not-executed");
74
+ return modes.map((m) => ({ id: m.id, label: m.label }));
75
+ }
76
+ /** Why a launch cannot run its `launchOptions["seat-mode"]`, or undefined when it can. A launch that
77
+ * does not name one keeps the connector's default. A value the connector does not list is refused,
78
+ * and so is any value but the default on a runtime that does not run the seat as a local child. */
79
+ export function seatModeRefusal(connector, runtime, launchOptions, resolvedBinaries) {
80
+ if (launchOptions === undefined || !Object.hasOwn(launchOptions, SEAT_MODE_OPTION))
81
+ return undefined;
82
+ const asked = launchOptions[SEAT_MODE_OPTION];
83
+ let modes;
84
+ try {
85
+ modes = connectorSeatModes(connector, resolvedBinaries);
86
+ }
87
+ catch (e) {
88
+ return rejectionText(e);
89
+ }
90
+ if (!modes)
91
+ return `${connector.name} connector offers no seat modes (launchOptions.${SEAT_MODE_OPTION})`;
92
+ const chosen = modes.find((m) => m.id === asked);
93
+ if (!chosen)
94
+ return `${connector.name} offers seat modes ${modes.map((m) => JSON.stringify(m.id)).join(", ")} on this host, not ${JSON.stringify(asked)} (launchOptions.${SEAT_MODE_OPTION})`;
95
+ if (chosen.id !== modes[0].id && (runtime.kind !== "pty" || runtime.spawnDelegated))
96
+ return `runtime "${runtime.kind}" does not run the seat as a local child, so it cannot run seat mode ${JSON.stringify(chosen.id)} (launchOptions.${SEAT_MODE_OPTION})`;
97
+ return undefined;
98
+ }
99
+ /** The saved-session listings and the handles they issued, held in memory for this Manager process
100
+ * only: a restarted Manager knows none, so every handle it issued refuses as expired. */
101
+ export class HarnessSessions {
102
+ parts;
103
+ host;
104
+ handles = new Map();
105
+ pages = new Map();
106
+ /** The handle slots the kept cursors hold for the rows they have still to hand out. */
107
+ reserved = 0;
108
+ constructor(parts, host) {
109
+ this.parts = parts;
110
+ this.host = host;
111
+ }
112
+ now() { return (this.host.now ?? Date.now)(); }
113
+ sweep() {
114
+ const now = this.now();
115
+ for (const [k, v] of this.handles)
116
+ if (v.expiresAt <= now)
117
+ this.handles.delete(k);
118
+ for (const [k, v] of this.pages)
119
+ if (v.expiresAt <= now) {
120
+ this.pages.delete(k);
121
+ this.reserved -= v.rest.length;
122
+ }
123
+ }
124
+ /** The listing's directory, resolved as `resolve-cwd` does. A refusal names only the value the
125
+ * caller sent; the filesystem's own diagnostic stays in this host's log. */
126
+ cwdOf(agent, value) {
127
+ try {
128
+ return this.host.resolveSpawnCwd(value).cwd;
129
+ }
130
+ catch (e) {
131
+ if (!(e instanceof EpEnvelopeError) || e.code !== "failed-precondition")
132
+ throw e;
133
+ logLocal(agent, "cwd", e);
134
+ throw new EpEnvelopeError("failed-precondition", `cwd does not resolve on this host as an absolute, searchable directory: ${JSON.stringify(String(value))} (harness-sessions)`, e.details, "not-executed");
135
+ }
136
+ }
137
+ /** The owner check: the caller must be the person this Manager runs for, on a runtime that runs
138
+ * seats on this host. An installation that cannot name that person or that host serves no saved
139
+ * sessions. */
140
+ admit(caller) {
141
+ const owner = this.host.owner();
142
+ if (owner === undefined)
143
+ throw new EpEnvelopeError("unimplemented", "this Manager runs for no single signed-in owner, so it lists no saved sessions (harness-sessions)", undefined, "not-executed");
144
+ if (caller.owner !== owner)
145
+ throw new EpEnvelopeError("permission-denied", "saved sessions on this Manager are listed only for the owner it runs for (harness-sessions)", undefined, "not-executed");
146
+ const runtime = this.host.runtime();
147
+ if (runtime.spawnDelegated)
148
+ throw new EpEnvelopeError("unimplemented", `runtime "${runtime.kind}" starts seats outside this host, so this Manager lists no saved sessions (harness-sessions)`, undefined, "not-executed");
149
+ }
150
+ /** Serve one `harness-sessions` request. */
151
+ async list(args, caller) {
152
+ this.admit(caller);
153
+ this.sweep();
154
+ if (args.cursor !== undefined)
155
+ return this.nextPage(String(args.cursor), args, caller);
156
+ const cwd = this.cwdOf(String(args.agent), args.cwd);
157
+ let connector;
158
+ try {
159
+ connector = await this.parts.harnessResolution.resolveConnector(String(args.agent));
160
+ }
161
+ catch (e) {
162
+ throw new EpEnvelopeError("not-found", rejectionText(e), undefined, "not-executed");
163
+ }
164
+ const agent = connector.name;
165
+ await this.parts.connectorInventory.refreshConnectors(agent, true);
166
+ const harness = this.parts.harnessResolution.launchHarness(connector);
167
+ if ("refusal" in harness)
168
+ throw new EpEnvelopeError("failed-precondition", harness.refusal, undefined, "not-executed");
169
+ const modes = this.launchModes(connector, harness.binaries);
170
+ const limit = typeof args.limit === "number" ? args.limit : SESSION_LIST_DEFAULT;
171
+ if (!connector.sessions)
172
+ return { ...modes, sessions: { supported: false, reason: `the ${agent} connector does not list saved sessions` } };
173
+ if (!connector.supportsResume)
174
+ return { ...modes, sessions: { supported: false, reason: `${agent} seats do not fork a saved session` } };
175
+ let envAllow;
176
+ try {
177
+ envAllow = spawnEnvAllow(loadCotalConfig(this.host.workspaceRoot(), isTrustedProject));
178
+ }
179
+ catch (e) {
180
+ if (!(e instanceof ProjectConfigTrustError) && !isCommandFailure(e))
181
+ throw e;
182
+ throw new EpEnvelopeError("failed-precondition", e.message, undefined, "not-executed");
183
+ }
184
+ let listed;
185
+ try {
186
+ listed = await connector.sessions.list({ cwd, resolvedBinaries: harness.binaries, ...(envAllow ? { envAllow } : {}) });
187
+ }
188
+ catch (e) {
189
+ logLocal(agent, "listing failed", e);
190
+ throw new EpEnvelopeError("unavailable", `${agent} did not list its saved sessions; the reason is in this Manager's log (harness-sessions)`, undefined, "not-executed");
191
+ }
192
+ if (!listed.supported) {
193
+ logLocal(agent, "lists no saved sessions", listed.reason);
194
+ return { ...modes, sessions: { supported: false, reason: `${agent} lists no saved sessions for this directory on this host` } };
195
+ }
196
+ if (!nativeKey(listed.store))
197
+ throw new EpEnvelopeError("internal", `${agent} listed saved sessions without naming the store it read, so no handle can be bound to it`, undefined, "not-executed");
198
+ const rows = this.fit(agent, listed.sessions, { cwd, store: listed.store });
199
+ return { ...modes, ...this.page({ caller, connector: agent, cwd, store: listed.store, rest: rows, limit, expiresAt: 0 }) };
200
+ }
201
+ /** The seat modes this launch catalog offers, or nothing for a connector without a selector. A
202
+ * runtime that does not run seats as local children offers only the default. */
203
+ launchModes(connector, binaries) {
204
+ const modes = connectorSeatModes(connector, binaries);
205
+ if (!modes)
206
+ return {};
207
+ const runtime = this.host.runtime();
208
+ return { modes: runtime.kind === "pty" && !runtime.spawnDelegated ? modes : modes.slice(0, 1) };
209
+ }
210
+ /** The connector's rows, checked: a row with no usable id, title, revision or state is the
211
+ * connector's fault. A title is cut to 120 characters, and one that shows the session's id, the
212
+ * directory, the store or this host's home directory is replaced with a neutral title. A time that
213
+ * is not RFC 3339 UTC is left out. */
214
+ fit(agent, sessions, where) {
215
+ if (!Array.isArray(sessions))
216
+ throw new EpEnvelopeError("internal", `${agent} listed saved sessions that are not an array`, undefined, "not-executed");
217
+ const home = homedir();
218
+ return sessions.map((s) => {
219
+ const shown = displayTitle(s?.title);
220
+ if (typeof s?.id !== "string" || s.id === "" || shown === undefined || !nativeKey(s.revision) || !SESSION_STATES.has(String(s.state)))
221
+ throw new EpEnvelopeError("internal", `${agent} listed a saved session without an id, a title, a revision or a known state`, undefined, "not-executed");
222
+ const raw = String(s.title);
223
+ const leaks = [s.id, where.cwd, where.store, ...(home.length > 1 ? [home] : [])].some((secret) => raw.includes(secret) || shown.includes(secret));
224
+ return { id: s.id, title: leaks ? NEUTRAL_TITLE : shown, revision: s.revision, state: s.state, ...(typeof s.updatedAt === "string" && RFC3339_UTC_MS.test(s.updatedAt) ? { updatedAt: s.updatedAt } : {}) };
225
+ });
226
+ }
227
+ /** One page of `listing`, issuing a handle per row, and the cursor to the rest when any is left.
228
+ * `spent` is the cursor this page continues: its reserved slots pay for this page and the next. */
229
+ page(listing, spent) {
230
+ const shown = listing.rest.slice(0, listing.limit);
231
+ const rest = listing.rest.slice(listing.limit);
232
+ const freed = spent === undefined ? 0 : this.pages.get(spent)?.rest.length ?? 0;
233
+ const handlesAfter = this.handles.size + this.reserved - freed + shown.length + rest.length;
234
+ const cursorsAfter = this.pages.size - (spent === undefined ? 0 : 1) + (rest.length > 0 ? 1 : 0);
235
+ if (handlesAfter > HANDLE_TABLE_MAX || cursorsAfter > HANDLE_TABLE_MAX)
236
+ throw new EpEnvelopeError("resource-exhausted", `this Manager holds the ${HANDLE_TABLE_MAX} saved-session handles and cursors it keeps at once; each expires 120 seconds after its listing, so list again then (harness-sessions)`, undefined, "not-executed");
237
+ if (spent !== undefined) {
238
+ this.pages.delete(spent);
239
+ this.reserved -= freed;
240
+ }
241
+ const expiresAt = this.now() + SESSION_HANDLE_TTL_MS;
242
+ const items = shown.map((s) => {
243
+ const handle = `${SESSION_HANDLE_PREFIX}${token(24)}`;
244
+ this.handles.set(handle, { caller: listing.caller, connector: listing.connector, cwd: listing.cwd, store: listing.store, sessionId: s.id, revision: s.revision, snapshot: s.updatedAt ?? "", expiresAt });
245
+ return { handle, title: s.title, state: s.state, ...(s.updatedAt ? { updatedAt: s.updatedAt } : {}) };
246
+ });
247
+ if (rest.length === 0)
248
+ return { sessions: { supported: true, items } };
249
+ const cursor = token(24);
250
+ this.pages.set(cursor, { ...listing, rest, expiresAt });
251
+ this.reserved += rest.length;
252
+ return { sessions: { supported: true, items }, nextCursor: cursor };
253
+ }
254
+ /** The next page of a kept listing. The cursor, its caller and its agent are checked before any
255
+ * directory work, and a `cwd` that does not resolve, or resolves elsewhere, is `not-found` like
256
+ * any other use the cursor was not issued for. */
257
+ nextPage(cursor, args, caller) {
258
+ const kept = CURSOR.test(cursor) ? this.pages.get(cursor) : undefined;
259
+ const notFound = () => new EpEnvelopeError("not-found", "the cursor has expired or names another listing; list again without a cursor (harness-sessions)", undefined, "not-executed");
260
+ if (!kept || !sameCaller(kept.caller, caller) || kept.connector !== String(args.agent))
261
+ throw notFound();
262
+ let cwd;
263
+ try {
264
+ cwd = this.cwdOf(kept.connector, args.cwd);
265
+ }
266
+ catch (e) {
267
+ if (e instanceof EpEnvelopeError && e.code === "failed-precondition")
268
+ throw notFound();
269
+ throw e;
270
+ }
271
+ if (kept.cwd !== cwd)
272
+ throw notFound();
273
+ const limit = typeof args.limit === "number" ? args.limit : kept.limit;
274
+ return this.page({ ...kept, limit }, cursor);
275
+ }
276
+ /** Resolve a spawn's handle to the session id it stands for, before anything is provisioned. The
277
+ * handle must have been issued by this Manager process to this exact caller for this connector and
278
+ * directory, within the last 120 seconds, and the session must still be listed unchanged from the
279
+ * same native store. The request id binds it: a retry of the same request resolves it again, and
280
+ * any other request is refused. The request claims the handle before the native record is read
281
+ * again, and the claim, the handle and its expiry are checked once more after that read, so two
282
+ * requests at once never both take it and a read that ends after the 120 seconds refuses. A read
283
+ * that failed releases a claim this request made, so a later request may try again; a record that
284
+ * changed, left or moved store revokes the handle. A refusal never falls back to reading the value
285
+ * as a session id. */
286
+ async resolve(handle, opts) {
287
+ this.sweep();
288
+ const bound = this.handles.get(handle);
289
+ const stale = "resume: the saved-session handle has expired or was not issued by this Manager; list the saved sessions again (harness-sessions)";
290
+ const taken = "resume: the saved-session handle was already taken by another launch; list the saved sessions again (harness-sessions)";
291
+ if (!bound)
292
+ return { refusal: stale };
293
+ if (opts.caller === undefined || !sameCaller(bound.caller, opts.caller))
294
+ return { refusal: "resume: the saved-session handle was issued to another caller (harness-sessions)" };
295
+ if (bound.connector !== opts.connector.name)
296
+ return { refusal: `resume: the saved-session handle names a ${bound.connector} session, and this launch resolves agent "${opts.connector.name}"` };
297
+ if (bound.cwd !== opts.cwd)
298
+ return { refusal: "resume: the saved-session handle was listed for another directory than this launch's cwd" };
299
+ const requestId = opts.requestId;
300
+ if (requestId === undefined || (bound.boundTo !== undefined && bound.boundTo !== requestId))
301
+ return { refusal: taken };
302
+ const claimedNow = bound.boundTo === undefined;
303
+ bound.boundTo = requestId;
304
+ // Revalidate against the native record now, so a session removed or written since it was listed,
305
+ // or a listing from another store, is refused rather than forked as it is today.
306
+ let current;
307
+ try {
308
+ current = await opts.connector.sessions.list({ cwd: opts.cwd, ...(opts.resolvedBinaries ? { resolvedBinaries: opts.resolvedBinaries } : {}), ...(opts.envAllow ? { envAllow: opts.envAllow } : {}) });
309
+ }
310
+ catch (e) {
311
+ logLocal(opts.connector.name, "listing to check a handle failed", e);
312
+ if (claimedNow && this.handles.get(handle) === bound && bound.boundTo === requestId)
313
+ bound.boundTo = undefined;
314
+ return { refusal: `resume: ${opts.connector.name} did not list its saved sessions to check the handle; the reason is in this Manager's log (harness-sessions)` };
315
+ }
316
+ if (this.handles.get(handle) !== bound || bound.expiresAt <= this.now()) {
317
+ this.handles.delete(handle);
318
+ return { refusal: stale };
319
+ }
320
+ if (bound.boundTo !== requestId)
321
+ return { refusal: taken };
322
+ const rows = current.supported && nativeKey(current.store) && current.store === bound.store && Array.isArray(current.sessions) ? current.sessions : undefined;
323
+ if (!rows)
324
+ logLocal(opts.connector.name, "listing to check a handle", current.supported ? "it names another store, or none" : current.reason);
325
+ const row = rows?.find((s) => s?.id === bound.sessionId);
326
+ if (!row || row.revision !== bound.revision || ((typeof row.updatedAt === "string" && RFC3339_UTC_MS.test(row.updatedAt)) ? row.updatedAt : "") !== bound.snapshot) {
327
+ this.handles.delete(handle);
328
+ return { refusal: rows
329
+ ? "resume: the saved session changed or is gone since it was listed; list the saved sessions again (harness-sessions)"
330
+ : "resume: the saved session can no longer be read from the store it was listed from; list the saved sessions again (harness-sessions)" };
331
+ }
332
+ return { sessionId: bound.sessionId };
333
+ }
334
+ }
335
+ //# sourceMappingURL=harness-sessions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"harness-sessions.js","sourceRoot":"","sources":["../src/harness-sessions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,uBAAuB,EAAE,aAAa,EAAE,gBAAgB,EAAE,aAAa,EAA2E,MAAM,gBAAgB,CAAC;AACpN,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAIzE,yFAAyF;AACzF,MAAM,CAAC,MAAM,qBAAqB,GAAG,OAAO,CAAC;AAC7C,yCAAyC;AACzC,MAAM,CAAC,MA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CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,KAAK,KAAK,CAAC,SAAS,CAAC,CAAC;QACzD,IAAI,CAAC,GAAG,IAAI,GAAG,CAAC,QAAQ,KAAK,KAAK,CAAC,QAAQ,IAAI,CAAC,CAAC,OAAO,GAAG,CAAC,SAAS,KAAK,QAAQ,IAAI,cAAc,CAAC,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,KAAK,CAAC,QAAQ,EAAE,CAAC;YACnK,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;YAC5B,OAAO,EAAE,OAAO,EAAE,IAAI;oBACpB,CAAC,CAAC,oHAAoH;oBACtH,CAAC,CAAC,qIAAqI,EAAE,CAAC;QAC9I,CAAC;QACD,OAAO,EAAE,SAAS,EAAE,KAAK,CAAC,SAAS,EAAE,CAAC;IACxC,CAAC;CACF"}
@@ -0,0 +1,7 @@
1
+ import type { Manager } from "./manager.js";
2
+ /** Answer the machine daemon's explicit connector observation on its retained parent channel. */
3
+ export declare function answerConnectorQuestion(frame: {
4
+ kind?: unknown;
5
+ attemptId?: unknown;
6
+ }, manager: Pick<Manager, "hostedConnectors">): boolean;
7
+ //# sourceMappingURL=hosted-connector-observation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hosted-connector-observation.d.ts","sourceRoot":"","sources":["../src/hosted-connector-observation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAE5C,iGAAiG;AACjG,wBAAgB,uBAAuB,CAAC,KAAK,EAAE;IAAE,IAAI,CAAC,EAAE,OAAO,CAAC;IAAC,SAAS,CAAC,EAAE,OAAO,CAAA;CAAE,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,kBAAkB,CAAC,GAAG,OAAO,CAQ3I"}
@@ -0,0 +1,13 @@
1
+ /** Answer the machine daemon's explicit connector observation on its retained parent channel. */
2
+ export function answerConnectorQuestion(frame, manager) {
3
+ if (frame.kind !== "machine-connectors" || typeof frame.attemptId !== "string" || !/^[A-Za-z0-9-]{1,64}$/.test(frame.attemptId))
4
+ return false;
5
+ const base = { kind: "machine-connectors-result", attemptId: frame.attemptId };
6
+ const answer = (result) => {
7
+ if (process.connected)
8
+ process.send?.({ ...base, ...result }, () => { });
9
+ };
10
+ void manager.hostedConnectors().then(connectors => answer({ ok: true, connectors }), () => answer({ ok: false }));
11
+ return true;
12
+ }
13
+ //# sourceMappingURL=hosted-connector-observation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hosted-connector-observation.js","sourceRoot":"","sources":["../src/hosted-connector-observation.ts"],"names":[],"mappings":"AAEA,iGAAiG;AACjG,MAAM,UAAU,uBAAuB,CAAC,KAA8C,EAAE,OAA0C;IAChI,IAAI,KAAK,CAAC,IAAI,KAAK,oBAAoB,IAAI,OAAO,KAAK,CAAC,SAAS,KAAK,QAAQ,IAAI,CAAC,sBAAsB,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC;QAAE,OAAO,KAAK,CAAC;IAC9I,MAAM,IAAI,GAAG,EAAE,IAAI,EAAE,2BAA2B,EAAE,SAAS,EAAE,KAAK,CAAC,SAAS,EAAE,CAAC;IAC/E,MAAM,MAAM,GAAG,CAAC,MAAc,EAAE,EAAE;QAChC,IAAI,OAAO,CAAC,SAAS;YAAE,OAAO,CAAC,IAAI,EAAE,CAAC,EAAE,GAAG,IAAI,EAAE,GAAG,MAAM,EAAE,EAAE,GAAG,EAAE,GAA8C,CAAC,CAAC,CAAC;IACtH,CAAC,CAAC;IACF,KAAK,OAAO,CAAC,gBAAgB,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC,MAAM,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC;IAClH,OAAO,IAAI,CAAC;AACd,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import "./service-adapter.js";
2
- import "./commands.js";
2
+ export { runMachineManager } from "./commands.js";
3
+ export type { ApplicationPathRead } from "./connector-inventory.js";
3
4
  export { Manager, ManagerInstanceLeaseHeld, READINESS_TIMEOUT_MS, type ManagerOptions, type ManagerStopOptions, type ManagerServiceObservation, type ManagerServiceIdentity, type ManagerMaintenanceState, type ManagerResumeIdentity, type ManagerResumeAgent, type ManagerResumeInventory, type ManagerResumeResult, type ManagerPreserveFailure, type ManagerPreservationPlan, type ManagerPreserveOptions, type ManagerPreserveResult, } from "./manager.js";
4
5
  export { parseResumeControlArgs, parseResumeCommitArgs, parseResumeFinalizeArgs, MAX_RESUME_CONTROL_BYTES, MAX_RESUME_COMMIT_BYTES, type ResumeControlArgs, } from "./resume.js";
5
6
  export { SPAWN_INPUT_KEYS, type ManagerStaticReconciliationSweep } from "./manager-service-contract.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;AAC9B,OAAO,eAAe,CAAC;AAEvB,OAAO,EACL,OAAO,EACP,wBAAwB,EACxB,oBAAoB,EACpB,KAAK,cAAc,EACnB,KAAK,kBAAkB,EACvB,KAAK,yBAAyB,EAC9B,KAAK,sBAAsB,EAC3B,KAAK,uBAAuB,EAC5B,KAAK,qBAAqB,EAC1B,KAAK,kBAAkB,EACvB,KAAK,sBAAsB,EAC3B,KAAK,mBAAmB,EACxB,KAAK,sBAAsB,EAC3B,KAAK,uBAAuB,EAC5B,KAAK,sBAAsB,EAC3B,KAAK,qBAAqB,GAC3B,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,sBAAsB,EACtB,qBAAqB,EACrB,uBAAuB,EACvB,wBAAwB,EACxB,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,qBAAqB,EAC1B,KAAK,kBAAkB,EACvB,KAAK,sBAAsB,EAC3B,KAAK,mBAAmB,EACxB,KAAK,sBAAsB,EAC3B,KAAK,uBAAuB,EAC5B,KAAK,sBAAsB,EAC3B,KAAK,qBAAqB,GAC3B,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,sBAAsB,EACtB,qBAAqB,EACrB,uBAAuB,EACvB,wBAAwB,EACxB,uBAAuB,EACvB,KAAK,iBAAiB,GACvB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,gBAAgB,EAAE,KAAK,gCAAgC,EAAE,MAAM,+BAA+B,CAAC;AACxG,OAAO,EAAE,4BAA4B,EAAE,uBAAuB,EAAE,MAAM,+BAA+B,CAAC;AACtG,YAAY,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AACtF,OAAO,EAAE,oBAAoB,EAAE,yBAAyB,EAAE,8BAA8B,EAAE,MAAM,aAAa,CAAC;AAC9G,YAAY,EAAE,aAAa,EAAE,iBAAiB,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACxG,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,UAAU,EAAE,KAAK,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACtE,OAAO,KAAK,mBAAmB,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EAAE,8BAA8B,EAAE,MAAM,sBAAsB,CAAC;AACtE,YAAY,EAAE,0BAA0B,EAAE,MAAM,uBAAuB,CAAC;AACxE,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AACxE,YAAY,EAAE,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC"}
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import "./service-adapter.js"; // self-registers native service metadata and guarded lifecycle hooks
2
- import "./commands.js"; // self-registers the control-plane commands on import
2
+ export { runMachineManager } from "./commands.js"; // also registers the control-plane commands
3
3
  export { Manager, ManagerInstanceLeaseHeld, READINESS_TIMEOUT_MS, } from "./manager.js";
4
4
  export { parseResumeControlArgs, parseResumeCommitArgs, parseResumeFinalizeArgs, MAX_RESUME_CONTROL_BYTES, MAX_RESUME_COMMIT_BYTES, } from "./resume.js";
5
5
  export { SPAWN_INPUT_KEYS } from "./manager-service-contract.js";
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC,CAAC,qEAAqE;AACpG,OAAO,eAAe,CAAC,CAAC,sDAAsD;AAE9E,OAAO,EACL,OAAO,EACP,wBAAwB,EACxB,oBAAoB,GAcrB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,sBAAsB,EACtB,qBAAqB,EACrB,uBAAuB,EACvB,wBAAwB,EACxB,uBAAuB,GAExB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,gBAAgB,EAAyC,MAAM,+BAA+B,CAAC;AACxG,OAAO,EAAE,4BAA4B,EAAE,uBAAuB,EAAE,MAAM,+BAA+B,CAAC;AAEtG,OAAO,EAAE,oBAAoB,EAAE,yBAAyB,EAAE,8BAA8B,EAAE,MAAM,aAAa,CAAC;AAE9G,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,UAAU,EAA0B,MAAM,kBAAkB,CAAC;AACtE,OAAO,KAAK,mBAAmB,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EAAE,8BAA8B,EAAE,MAAM,sBAAsB,CAAC;AAEtE,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC,CAAC,qEAAqE;AACpG,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC,CAAC,4CAA4C;AAG/F,OAAO,EACL,OAAO,EACP,wBAAwB,EACxB,oBAAoB,GAcrB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,sBAAsB,EACtB,qBAAqB,EACrB,uBAAuB,EACvB,wBAAwB,EACxB,uBAAuB,GAExB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,gBAAgB,EAAyC,MAAM,+BAA+B,CAAC;AACxG,OAAO,EAAE,4BAA4B,EAAE,uBAAuB,EAAE,MAAM,+BAA+B,CAAC;AAEtG,OAAO,EAAE,oBAAoB,EAAE,yBAAyB,EAAE,8BAA8B,EAAE,MAAM,aAAa,CAAC;AAE9G,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,UAAU,EAA0B,MAAM,kBAAkB,CAAC;AACtE,OAAO,KAAK,mBAAmB,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EAAE,8BAA8B,EAAE,MAAM,sBAAsB,CAAC;AAEtE,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC"}
@@ -0,0 +1,30 @@
1
+ export interface InterruptedRunRecovery {
2
+ readonly runId: string;
3
+ readonly timeout: string;
4
+ readonly holder: string;
5
+ readonly epoch: number;
6
+ readonly fencingToken: number;
7
+ readonly until: number;
8
+ }
9
+ /** A row the file held that was not a note. The caller logs it rather than dropping it silently. */
10
+ export interface InterruptedRunRecoveryRead {
11
+ readonly notes: InterruptedRunRecovery[];
12
+ readonly dropped: number;
13
+ /** The file existed and could not be read as a note list. */
14
+ readonly corrupt: boolean;
15
+ }
16
+ /** The space directory that holds this manager's note of released runs it is still retrying. */
17
+ export declare function interruptedRunRecoveryDir(root: string, space: string): string;
18
+ export declare function readInterruptedRunRecovery(dir: string): InterruptedRunRecoveryRead;
19
+ export declare function writeInterruptedRunRecovery(dir: string, rows: readonly InterruptedRunRecovery[]): void;
20
+ export declare const interruptedRunRecoveryStore: {
21
+ write: typeof writeInterruptedRunRecovery;
22
+ };
23
+ /** Read the note, change it, and write it back while holding the directory lock. A second process
24
+ * waits for the same lock, so the two updates cannot drop each other's rows. */
25
+ export declare function updateInterruptedRunRecovery(dir: string, change: (read: InterruptedRunRecoveryRead) => readonly InterruptedRunRecovery[]): Promise<InterruptedRunRecoveryRead>;
26
+ /** The HTTP status a refusal carries. A rate-limit error can name it without a response body. */
27
+ export declare function recoveryHttpStatus(error: unknown): number | undefined;
28
+ /** How long a rate-limit refusal asked this retry to wait, in seconds, when it named a wait. */
29
+ export declare function recoveryRetryAfterSeconds(error: unknown): number | undefined;
30
+ //# sourceMappingURL=interrupted-run-recovery.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interrupted-run-recovery.d.ts","sourceRoot":"","sources":["../src/interrupted-run-recovery.ts"],"names":[],"mappings":"AAWA,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACxB;AAED,oGAAoG;AACpG,MAAM,WAAW,0BAA0B;IACzC,QAAQ,CAAC,KAAK,EAAE,sBAAsB,EAAE,CAAC;IACzC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,6DAA6D;IAC7D,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;CAC3B;AAED,gGAAgG;AAChG,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAE7E;AAMD,wBAAgB,0BAA0B,CAAC,GAAG,EAAE,MAAM,GAAG,0BAA0B,CAiBlF;AAaD,wBAAgB,2BAA2B,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,sBAAsB,EAAE,GAAG,IAAI,CAetG;AAED,eAAO,MAAM,2BAA2B;;CAEvC,CAAC;AAEF;iFACiF;AACjF,wBAAsB,4BAA4B,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,IAAI,EAAE,0BAA0B,KAAK,SAAS,sBAAsB,EAAE,GAAG,OAAO,CAAC,0BAA0B,CAAC,CAUpL;AAiCD,iGAAiG;AACjG,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAMrE;AAED,gGAAgG;AAChG,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAI5E"}
@@ -0,0 +1,156 @@
1
+ /**
2
+ * The local note of released runs one manager is still retrying. The next boot of that same manager
3
+ * reads it and continues those retries. The note is this process's own bookkeeping, not a run record.
4
+ * It lives under the space's own directory, so another space on the same root never reads it.
5
+ */
6
+ import { createPrivateRecord, mkSecretDir } from "@cotal-ai/core";
7
+ import { closeSync, constants, existsSync, openSync, readFileSync, renameSync, statSync, unlinkSync, writeFileSync } from "node:fs";
8
+ import { join } from "node:path";
9
+ import { setTimeout as delay } from "node:timers/promises";
10
+ import { spaceSegment } from "@cotal-ai/workspace";
11
+ /** The space directory that holds this manager's note of released runs it is still retrying. */
12
+ export function interruptedRunRecoveryDir(root, space) {
13
+ return join(root, ".cotal", spaceSegment(space));
14
+ }
15
+ function interruptedRunRecoveryPath(dir) {
16
+ return join(dir, "interrupted-run-recovery.json");
17
+ }
18
+ export function readInterruptedRunRecovery(dir) {
19
+ const path = interruptedRunRecoveryPath(dir);
20
+ if (!existsSync(path))
21
+ return { notes: [], dropped: 0, corrupt: false };
22
+ try {
23
+ const raw = JSON.parse(readFileSync(path, "utf8"));
24
+ if (!Array.isArray(raw))
25
+ return { notes: [], dropped: 0, corrupt: true };
26
+ const notes = [];
27
+ let dropped = 0;
28
+ for (const row of raw) {
29
+ const note = interruptedRunRecoveryRow(row);
30
+ if (note === undefined)
31
+ dropped += 1;
32
+ else
33
+ notes.push(note);
34
+ }
35
+ return { notes, dropped, corrupt: false };
36
+ }
37
+ catch {
38
+ return { notes: [], dropped: 0, corrupt: true };
39
+ }
40
+ }
41
+ function interruptedRunRecoveryRow(row) {
42
+ if (row === null || typeof row !== "object")
43
+ return undefined;
44
+ const note = row;
45
+ if (typeof note.runId !== "string" || typeof note.timeout !== "string" || typeof note.holder !== "string")
46
+ return undefined;
47
+ if (![note.epoch, note.fencingToken, note.until].every((value) => typeof value === "number" && Number.isSafeInteger(value) && value >= 0))
48
+ return undefined;
49
+ return {
50
+ runId: note.runId, timeout: note.timeout, holder: note.holder,
51
+ epoch: note.epoch, fencingToken: note.fencingToken, until: note.until,
52
+ };
53
+ }
54
+ export function writeInterruptedRunRecovery(dir, rows) {
55
+ const path = interruptedRunRecoveryPath(dir);
56
+ if (rows.length === 0) {
57
+ try {
58
+ unlinkSync(path);
59
+ }
60
+ catch { /* already gone */ }
61
+ return;
62
+ }
63
+ mkSecretDir(dir);
64
+ const tmp = `${path}.${process.pid}.${Date.now()}.tmp`;
65
+ try {
66
+ createPrivateRecord(tmp, `${JSON.stringify(rows)}\n`);
67
+ renameSync(tmp, path);
68
+ }
69
+ catch (error) {
70
+ try {
71
+ unlinkSync(tmp);
72
+ }
73
+ catch { /* the temp was not created */ }
74
+ throw error;
75
+ }
76
+ }
77
+ export const interruptedRunRecoveryStore = {
78
+ write: writeInterruptedRunRecovery,
79
+ };
80
+ /** Read the note, change it, and write it back while holding the directory lock. A second process
81
+ * waits for the same lock, so the two updates cannot drop each other's rows. */
82
+ export async function updateInterruptedRunRecovery(dir, change) {
83
+ mkSecretDir(dir);
84
+ const release = await lockInterruptedRunRecovery(dir);
85
+ try {
86
+ const read = readInterruptedRunRecovery(dir);
87
+ interruptedRunRecoveryStore.write(dir, change(read));
88
+ return read;
89
+ }
90
+ finally {
91
+ release();
92
+ }
93
+ }
94
+ /** An exclusive create, so a second process waits. The file names its holder, and a release deletes
95
+ * it only while that name is still there. A file left by a dead holder is replaced after a few
96
+ * seconds, which is long enough for the rewrite itself. */
97
+ async function lockInterruptedRunRecovery(dir) {
98
+ const path = join(dir, "interrupted-run-recovery.lock");
99
+ const token = `${process.pid}.${Date.now()}.${Math.random().toString(16).slice(2)}`;
100
+ const deadline = Date.now() + 5_000;
101
+ for (;;) {
102
+ try {
103
+ const fd = openSync(path, constants.O_CREAT | constants.O_EXCL | constants.O_RDWR, 0o600);
104
+ try {
105
+ writeFileSync(fd, token);
106
+ }
107
+ catch (error) {
108
+ closeSync(fd);
109
+ try {
110
+ unlinkSync(path);
111
+ }
112
+ catch { /* the create is this attempt's to undo */ }
113
+ throw error;
114
+ }
115
+ closeSync(fd);
116
+ return () => {
117
+ try {
118
+ if (readFileSync(path, "utf8") === token)
119
+ unlinkSync(path);
120
+ }
121
+ catch { /* already released */ }
122
+ };
123
+ }
124
+ catch (error) {
125
+ if (error.code !== "EEXIST")
126
+ throw error;
127
+ try {
128
+ if (Date.now() - statSync(path).mtimeMs > 5_000)
129
+ unlinkSync(path);
130
+ }
131
+ catch { /* the holder released it between the check and the removal */ }
132
+ if (Date.now() >= deadline)
133
+ throw error;
134
+ await delay(20);
135
+ }
136
+ }
137
+ }
138
+ /** The HTTP status a refusal carries. A rate-limit error can name it without a response body. */
139
+ export function recoveryHttpStatus(error) {
140
+ if (error === null || typeof error !== "object")
141
+ return undefined;
142
+ const status = error.status;
143
+ if (typeof status !== "number" || !Number.isInteger(status))
144
+ return undefined;
145
+ if (!("body" in error) && status !== 429)
146
+ return undefined;
147
+ return status;
148
+ }
149
+ /** How long a rate-limit refusal asked this retry to wait, in seconds, when it named a wait. */
150
+ export function recoveryRetryAfterSeconds(error) {
151
+ if (recoveryHttpStatus(error) !== 429)
152
+ return undefined;
153
+ const seconds = error.retryAfterSeconds;
154
+ return typeof seconds === "number" && Number.isSafeInteger(seconds) && seconds > 0 ? seconds : undefined;
155
+ }
156
+ //# sourceMappingURL=interrupted-run-recovery.js.map