omp-superagent 0.1.15 → 0.1.17
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/docs/OPERATIONS.en.md +62 -4
- package/docs/OPERATIONS.md +44 -3
- package/docs/design/execution.md +55 -2
- package/docs/design/messaging.md +27 -7
- package/docs/releases/0.1.16.md +9 -0
- package/docs/releases/0.1.17.md +10 -0
- package/gateway/bin/omp-gateway-darwin-arm64 +0 -0
- package/gateway/bin/omp-gateway-darwin-x64 +0 -0
- package/gateway/bin/omp-gateway-linux-arm64 +0 -0
- package/gateway/bin/omp-gateway-linux-x64 +0 -0
- package/host-owner/bin/omp-host-owner-darwin-arm64 +0 -0
- package/host-owner/bin/omp-host-owner-darwin-x64 +0 -0
- package/host-owner/bin/omp-host-owner-linux-arm64 +0 -0
- package/host-owner/bin/omp-host-owner-linux-x64 +0 -0
- package/package.json +1 -1
- package/skills/head/SKILL.md +7 -0
- package/skills/head/references/routing.md +24 -4
- package/src/config/config.ts +10 -0
- package/src/contracts.ts +7 -4
- package/src/extension.ts +12 -10
- package/src/gateway/gateway-client.ts +10 -3
- package/src/messaging/discord-work-thread.ts +36 -0
- package/src/runtime/controller.ts +335 -78
- package/src/runtime/head-superstack.ts +83 -0
- package/src/runtime/result-attachments.ts +3 -1
- package/src/storage/store.ts +51 -12
- package/src/worker/worker-checkout.ts +38 -4
- package/src/worker/worker-host.ts +114 -24
- package/src/worker/worker-ledger.ts +28 -9
- package/src/worker/worker-repository.ts +13 -0
- package/src/worker/worker-service.ts +74 -17
- package/src/worker/worker-wire.ts +3 -1
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
2
|
import { lstatSync, type Stats } from "node:fs";
|
|
3
|
-
import { dirname } from "node:path";
|
|
3
|
+
import { dirname, join } from "node:path";
|
|
4
4
|
import { fileURLToPath } from "node:url";
|
|
5
5
|
import { startHost } from "../omp/host";
|
|
6
|
-
import { boundWorkspace, enrolledRepo, privateWorkerDirectory, reserveCheckout } from "./worker-checkout";
|
|
7
|
-
import { absentWorkerHost, attestWorkerHost, inspectWorkerHost, readWorkerFiles,
|
|
6
|
+
import { boundWorkspace, enrolledRepo, privateWorkerDirectory, reserveCheckout, workerCheckoutIdentity } from "./worker-checkout";
|
|
7
|
+
import { absentWorkerHost, attestWorkerHost, inspectWorkerHost, prepareWorkerJournalDirectory, readWorkerFiles,
|
|
8
8
|
WORKER_ATTEMPT_ENV, WORKER_SESSION_ENV, workerPaths } from "./worker-host";
|
|
9
|
-
import { WorkerLedger, type WorkerReceipt } from "./worker-ledger";
|
|
9
|
+
import { WorkerLedger, type WorkerJournalDirectory, type WorkerReceipt } from "./worker-ledger";
|
|
10
10
|
import { WORKER_MEMORY_WIRE_ENV } from "./worker-memory-storage";
|
|
11
11
|
import { assertWorkerGitStartup, requireWorkerStartupFlags, workerLaunchProfile, workerManagedUlwPath } from "./worker-profile";
|
|
12
12
|
import { parseWorkerPolicy, parseWorkerRequest, WorkerRefusal } from "./worker-request";
|
|
@@ -25,6 +25,7 @@ type AttachPermit = {
|
|
|
25
25
|
readonly pid: number; readonly ownerPid: number;
|
|
26
26
|
readonly socket: { readonly dev: string; readonly ino: string };
|
|
27
27
|
readonly journal: { readonly dev: string; readonly ino: string };
|
|
28
|
+
readonly journalDirectory?: WorkerJournalDirectory;
|
|
28
29
|
};
|
|
29
30
|
type WorkerReply = { readonly ok: true; readonly value: unknown } | { readonly ok: false; readonly error: string };
|
|
30
31
|
type WorkerPreparation = { readonly kind: "reply"; readonly reply: WorkerReply } | ({ readonly kind: "attach" } & AttachPermit);
|
|
@@ -52,9 +53,19 @@ async function describeWorker(policy: WorkerPolicy, workspace?: Workspace): Prom
|
|
|
52
53
|
const platform = process.platform;
|
|
53
54
|
if (platform !== "linux" && platform !== "darwin") throw new WorkerRefusal("Unsupported worker platform");
|
|
54
55
|
const { workerId, stateDir, repos, capacity } = policy;
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
56
|
+
if (workspace) {
|
|
57
|
+
const repo = findRepo(policy, workspace.repoId);
|
|
58
|
+
const gitDir = await enrolledRepo(policy, repo);
|
|
59
|
+
await boundWorkspace(repo, workspace);
|
|
60
|
+
if (lstatSync(join(stateDir, "worker.sqlite"), { throwIfNoEntry: false })) {
|
|
61
|
+
const service = new WorkerService(policy);
|
|
62
|
+
try { await service.reap({ repoId: repo.id, repoRoot: repo.cwd, gitDir }); }
|
|
63
|
+
finally { service.close(); }
|
|
64
|
+
}
|
|
65
|
+
} else {
|
|
66
|
+
// Enrollment-wide inventory still validates all its registered checkouts.
|
|
67
|
+
for (const repo of repos) await enrolledRepo(policy, repo);
|
|
68
|
+
}
|
|
58
69
|
return { workerId, platform, stateDir, repos, capacity, active: WorkerLedger.count(policy) };
|
|
59
70
|
}
|
|
60
71
|
|
|
@@ -82,13 +93,15 @@ class WorkerService {
|
|
|
82
93
|
return current;
|
|
83
94
|
}
|
|
84
95
|
|
|
85
|
-
async
|
|
96
|
+
async reap(scope?: Pick<WorkerReceipt, "repoId" | "repoRoot" | "gitDir">): Promise<void> {
|
|
86
97
|
for (const receipt of this.#ledger.active()) {
|
|
98
|
+
if (scope && (scope.repoId !== receipt.repoId || scope.repoRoot !== receipt.repoRoot || scope.gitDir !== receipt.gitDir)) continue;
|
|
87
99
|
if (!this.#policy.repos.some(repo => repo.id === receipt.repoId && repo.cwd === receipt.repoRoot)) continue;
|
|
88
100
|
try { await inspectWorkerHost(this.#ledger, workerPaths(this.#policy, receipt.laneId), receipt, false); }
|
|
89
101
|
catch (error) {
|
|
90
102
|
if (!(error instanceof Error)) throw error;
|
|
91
|
-
//
|
|
103
|
+
// A refused inspection does not free an unverified reservation.
|
|
104
|
+
// Checkout-only retirement may already have committed before refusal.
|
|
92
105
|
}
|
|
93
106
|
}
|
|
94
107
|
}
|
|
@@ -104,9 +117,30 @@ class WorkerService {
|
|
|
104
117
|
return { ...probe, uncertain: true, pid: null, sessionId: null };
|
|
105
118
|
const absent = !probe.uncertain && !probe.socket && !probe.pidAlive && !probe.ownerAlive && probe.pid === null;
|
|
106
119
|
const sealed = absent && this.#ledger.confirmRelease(ref, lane.repo.cwd, { observed, reconcile });
|
|
120
|
+
let reopenActive: number | undefined;
|
|
121
|
+
const released = this.#receipt(lane);
|
|
122
|
+
// Released with an exact readable session is also valid after an attempt
|
|
123
|
+
// that reached no Host. It does not manufacture an exitGeneration for it.
|
|
124
|
+
if (sealed && released?.phase === "released" && released.attempt === observed?.attempt
|
|
125
|
+
&& probe.sessionId && released.sessionId === probe.sessionId
|
|
126
|
+
&& released.checkoutIdentity) {
|
|
127
|
+
try {
|
|
128
|
+
if (await enrolledRepo(this.#policy, lane.repo) === released.gitDir) {
|
|
129
|
+
await boundWorkspace(lane.repo, ref, { gitDir: released.gitDir, checkoutIdentity: released.checkoutIdentity });
|
|
130
|
+
const current = this.#receipt(lane);
|
|
131
|
+
const active = this.#ledger.active().length;
|
|
132
|
+
if (current?.attempt === released.attempt && current.phase === "released" && active < this.#policy.capacity)
|
|
133
|
+
reopenActive = active;
|
|
134
|
+
}
|
|
135
|
+
} catch (error) {
|
|
136
|
+
if (!(error instanceof WorkerRefusal)) throw error;
|
|
137
|
+
// Exit is independent of checkout readiness; keep its proof intact.
|
|
138
|
+
}
|
|
139
|
+
}
|
|
107
140
|
const memoryLaunch = process.env[WORKER_MEMORY_WIRE_ENV] === "1" && absent && !probe.sessionFile && !sealed;
|
|
108
141
|
return { ...probe, ...(sealed && { sealedGeneration: ref.generation }),
|
|
109
142
|
...(sealed && exitGeneration === ref.generation && { exitGeneration }),
|
|
143
|
+
...(reopenActive !== undefined && { reopenActive }),
|
|
110
144
|
...(memoryLaunch && { memoryLaunchVersion: 1 }),
|
|
111
145
|
...(!probe.uncertain && probe.socket && observed?.generation === ref.generation
|
|
112
146
|
&& observed.privateMemoryPrepared && observed.memory?.proof && { memoryPreparedVersion: 1 }),
|
|
@@ -128,15 +162,17 @@ class WorkerService {
|
|
|
128
162
|
return { pid: probe.pid };
|
|
129
163
|
throw new WorkerRefusal("Worker lane generation has no verified live Host; it cannot reopen");
|
|
130
164
|
}
|
|
131
|
-
await this
|
|
165
|
+
await this.reap();
|
|
132
166
|
const previous = this.#receipt(lane);
|
|
167
|
+
if (previous?.phase === "checkout-released")
|
|
168
|
+
throw new WorkerRefusal("Worker checkout was released, but the original journal remains unverified and cannot reopen");
|
|
133
169
|
if (observed?.attempt !== previous?.attempt || (previous && previous.phase !== "released"))
|
|
134
170
|
throw new WorkerRefusal("Worker lane has a resident or uncertain launch");
|
|
135
171
|
if (previous && ref.generation <= previous.generation)
|
|
136
172
|
throw new WorkerRefusal("Worker does not reopen a previous lane generation");
|
|
137
173
|
const gitDir = await enrolledRepo(this.#policy, lane.repo);
|
|
138
174
|
if (previous && previous.gitDir !== gitDir) throw new WorkerRefusal("Worker checkout metadata directory changed");
|
|
139
|
-
const initial = await readWorkerFiles(lane.paths);
|
|
175
|
+
const initial = await readWorkerFiles(lane.paths, previous?.journalDirectory);
|
|
140
176
|
if (absentWorkerHost(initial, previous).uncertain) throw new WorkerRefusal("Worker lane has an unverified socket or journal");
|
|
141
177
|
if (launch.memorySync && process.env[WORKER_MEMORY_WIRE_ENV] !== "1")
|
|
142
178
|
throw new WorkerRefusal("Worker memory is not supported by this transport");
|
|
@@ -145,23 +181,43 @@ class WorkerService {
|
|
|
145
181
|
const memoryKey = previous?.memory?.key ?? (launch.memorySync ? crypto.randomUUID() : undefined);
|
|
146
182
|
// Commit admission before reserving the checkout, publishing any session
|
|
147
183
|
// artifacts, or starting the stock OMP process.
|
|
148
|
-
|
|
184
|
+
let reservation = this.#ledger.reserve(ref, { repoRoot: lane.repo.cwd, gitDir, launchDigest,
|
|
149
185
|
...(previous?.memory && { memory: previous.memory }) }, previous);
|
|
186
|
+
const continuation = previous?.phase === "released" && previous.sessionId && previous.checkoutIdentity
|
|
187
|
+
? { gitDir, checkoutIdentity: previous.checkoutIdentity } : undefined;
|
|
188
|
+
const selected = join(lane.repo.cwd, ref.subdir);
|
|
150
189
|
let cwd: string;
|
|
151
190
|
let target: ReturnType<typeof workerLaunchProfile>;
|
|
152
191
|
let managedUlwPath: string;
|
|
153
192
|
try {
|
|
154
193
|
reserveCheckout(reservation);
|
|
155
|
-
|
|
194
|
+
const checkoutIdentity = workerCheckoutIdentity(lane.repo.cwd, gitDir, selected);
|
|
195
|
+
if (previous?.checkoutIdentity && previous.checkoutIdentity !== checkoutIdentity)
|
|
196
|
+
throw new WorkerRefusal("Worker continuation no longer matches the original checkout directories");
|
|
197
|
+
cwd = await boundWorkspace(lane.repo, ref, continuation);
|
|
156
198
|
await assertWorkerGitStartup(lane.repo);
|
|
157
199
|
target = workerLaunchProfile(this.#policy, cwd);
|
|
158
200
|
managedUlwPath = await workerManagedUlwPath(this.#policy.repos);
|
|
159
201
|
await requireWorkerStartupFlags(target.executable, this.#policy.stateDir, target.env);
|
|
160
|
-
if (absentWorkerHost(await readWorkerFiles(lane.paths), reservation).uncertain)
|
|
202
|
+
if (absentWorkerHost(await readWorkerFiles(lane.paths, reservation.journalDirectory), reservation).uncertain)
|
|
161
203
|
throw new WorkerRefusal("Worker socket or journal changed before launch");
|
|
162
204
|
privateWorkerDirectory(dirname(lane.paths.socketPath), true);
|
|
163
205
|
privateWorkerDirectory(dirname(dirname(lane.paths.sessionFile)), true);
|
|
164
|
-
|
|
206
|
+
// Authorize stock-created modes only after establishing custody of a
|
|
207
|
+
// new private namespace, before either SDK preparation or OMP opens it.
|
|
208
|
+
const directory = prepareWorkerJournalDirectory(lane.paths, reservation.journalDirectory);
|
|
209
|
+
if (continuation) {
|
|
210
|
+
await assertWorkerGitStartup(lane.repo);
|
|
211
|
+
await boundWorkspace(lane.repo, ref, continuation);
|
|
212
|
+
}
|
|
213
|
+
const pin = checkoutIdentity && workerCheckoutIdentity(lane.repo.cwd, gitDir, cwd) === checkoutIdentity ? checkoutIdentity : null;
|
|
214
|
+
if (previous?.checkoutIdentity && pin !== previous.checkoutIdentity)
|
|
215
|
+
throw new WorkerRefusal("Worker checkout directories changed before launch");
|
|
216
|
+
if ((pin && pin !== reservation.checkoutIdentity) || (directory && !reservation.journalDirectory)) {
|
|
217
|
+
const prepared = { ...reservation, ...(pin && { checkoutIdentity: pin }), ...(directory && { journalDirectory: directory }) };
|
|
218
|
+
if (!this.#ledger.transition(reservation, prepared)) throw new WorkerRefusal("Worker launch reservation is no longer current");
|
|
219
|
+
reservation = prepared;
|
|
220
|
+
}
|
|
165
221
|
} catch (error) {
|
|
166
222
|
this.#ledger.retire(reservation);
|
|
167
223
|
throw error;
|
|
@@ -209,7 +265,7 @@ class WorkerService {
|
|
|
209
265
|
if (receipt?.attempt !== observed.attempt || receipt.phase !== "live" ||
|
|
210
266
|
!probe.socket || !probe.pidAlive || !probe.ownerAlive)
|
|
211
267
|
throw new WorkerRefusal("Worker lane does not have an attachable native Host");
|
|
212
|
-
const files = await readWorkerFiles(lane.paths);
|
|
268
|
+
const files = await readWorkerFiles(lane.paths, receipt.journalDirectory);
|
|
213
269
|
if (!files.session) throw new WorkerRefusal("No owned worker socket/journal/checkout");
|
|
214
270
|
const { pid, ownerPid, sessionId, sessionFile, ...identity } = await attestWorkerHost(lane.paths, files, receipt);
|
|
215
271
|
const { socketPath } = lane.paths;
|
|
@@ -219,7 +275,8 @@ class WorkerService {
|
|
|
219
275
|
if (current?.phase !== "live" || current.generation !== ref.generation || current.attempt !== receipt.attempt)
|
|
220
276
|
throw new WorkerRefusal("Worker lane changed before attach");
|
|
221
277
|
return { generation: receipt.generation, workerAttempt: receipt.attempt,
|
|
222
|
-
socketPath, sessionFile, sessionId, pid, ownerPid, socket, journal
|
|
278
|
+
socketPath, sessionFile, sessionId, pid, ownerPid, socket, journal,
|
|
279
|
+
...(receipt.journalDirectory && { journalDirectory: receipt.journalDirectory }) };
|
|
223
280
|
}
|
|
224
281
|
}
|
|
225
282
|
|
|
@@ -39,6 +39,8 @@ export interface WorkerProbe {
|
|
|
39
39
|
readonly sealedGeneration?: number;
|
|
40
40
|
/** Exact generation whose persisted native exit the worker verified. */
|
|
41
41
|
readonly exitGeneration?: number;
|
|
42
|
+
/** An exact exited session can reopen in its original checkout; reported occupancy is read-only. */
|
|
43
|
+
readonly reopenActive?: number;
|
|
42
44
|
/** The wire accepts opt-in on a fresh, absent, unsealed worker lane. */
|
|
43
45
|
readonly memoryLaunchVersion?: 1;
|
|
44
46
|
/** Private storage was prepared for this attempt; readiness can be checked after native init. */
|
|
@@ -62,7 +64,7 @@ export const WorkerDescriptionSchema = Type.Object({
|
|
|
62
64
|
const probe = Type.Object({
|
|
63
65
|
socket: Type.Boolean(), sessionFile: Type.Boolean(), pidAlive: Type.Boolean(), ownerAlive: Type.Boolean(),
|
|
64
66
|
uncertain: Type.Boolean(), pid: Type.Union([positive, Type.Null()]), sessionId: Type.Union([text, Type.Null()]),
|
|
65
|
-
sealedGeneration: Type.Optional(positive), exitGeneration: Type.Optional(positive),
|
|
67
|
+
sealedGeneration: Type.Optional(positive), exitGeneration: Type.Optional(positive), reopenActive: Type.Optional(natural),
|
|
66
68
|
memoryLaunchVersion: Type.Optional(Type.Literal(1)), memoryPreparedVersion: Type.Optional(Type.Literal(1)),
|
|
67
69
|
memorySyncVersion: Type.Optional(Type.Literal(1)),
|
|
68
70
|
});
|