omp-superagent 0.1.13 → 0.1.15
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/DESIGN.md +8 -5
- package/THIRD_PARTY_NOTICES.md +6 -0
- package/assets/architecture-dark.svg +4 -4
- package/assets/architecture.ko-dark.svg +4 -4
- package/assets/architecture.ko.svg +4 -4
- package/assets/architecture.mmd +5 -5
- package/assets/architecture.svg +4 -4
- package/config.example.json +1 -0
- package/docs/OPERATIONS.en.md +59 -23
- package/docs/OPERATIONS.md +53 -18
- package/docs/design/execution.md +161 -43
- package/docs/design/messaging.md +45 -9
- package/docs/releases/0.1.15.md +13 -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 +6 -3
- package/scripts/prepare-worker-memory.ts +37 -0
- package/skills/head/SKILL.md +22 -47
- package/skills/head/references/routing.md +11 -12
- package/skills/head/references/supervision.md +10 -14
- package/skills/lane/SKILL.md +14 -16
- package/skills/lane/references/workflow.md +14 -27
- package/src/cli.ts +56 -56
- package/src/config/config.ts +4 -0
- package/src/contracts.ts +34 -27
- package/src/cron/cron-jobs.ts +4 -3
- package/src/cron/cron-pr-intake.ts +1 -2
- package/src/extension.ts +57 -14
- package/src/gateway/gateway-client.ts +14 -12
- package/src/group/group-runner.ts +3 -2
- package/src/group-runner-extension.ts +7 -3
- package/src/host-extension.ts +109 -2
- package/src/host-sdk-helper.ts +6 -1
- package/src/lane/decision-tool.ts +2 -3
- package/src/lane/lane-report.ts +8 -30
- package/src/lane/lane-rows.ts +1 -1
- package/src/lane/workflow.ts +44 -3
- package/src/lane-extension.ts +5 -46
- package/src/messaging/discord-context.ts +8 -6
- package/src/omp/host-protocol.ts +4 -3
- package/src/omp/host.ts +24 -7
- package/src/omp/managed-super.ts +43 -27
- package/src/omp/native-sessions.ts +12 -0
- package/src/omp/worker-memory-import.ts +410 -0
- package/src/omp/worker-memory-sdk.ts +8 -0
- package/src/operator/setup.ts +8 -13
- package/src/pr/pr-github-schema.ts +9 -0
- package/src/pr/pr-github.ts +6 -2
- package/src/pr/pr-intake-automation.ts +11 -8
- package/src/pr/pr-intake-fix.ts +2 -5
- package/src/pr/pr-intake-review.ts +7 -7
- package/src/routing/topic-history.ts +2 -2
- package/src/runtime/controller.ts +444 -408
- package/src/runtime/head-recovery.ts +7 -7
- package/src/runtime/worker-memory.ts +156 -0
- package/src/storage/deferred-routing.ts +1 -7
- package/src/storage/store.ts +441 -375
- package/src/worker/worker-host.ts +3 -2
- package/src/worker/worker-ledger.ts +20 -11
- package/src/worker/worker-memory-page.ts +83 -0
- package/src/worker/worker-memory-proofs.ts +260 -0
- package/src/worker/worker-memory-source.ts +305 -0
- package/src/worker/worker-memory-storage.ts +130 -0
- package/src/worker/worker-profile.ts +2 -0
- package/src/worker/worker-repository.ts +92 -7
- package/src/worker/worker-request.ts +1 -0
- package/src/worker/worker-service.ts +25 -8
- package/src/worker/worker-wire.ts +20 -6
|
@@ -198,10 +198,11 @@ export function headRecoveryEvidence(entries: unknown[], owner: Pick<HeadRecover
|
|
|
198
198
|
const matches = (entry: Record<string, unknown>, type: string) => entry.type === "custom" && entry.customType === type
|
|
199
199
|
&& object(entry.data).sessionId === owner.sessionId && object(entry.data).sessionFile === owner.sessionFile;
|
|
200
200
|
const receipts = slice.filter(entry => matches(entry, "rpc_prompt_result"));
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
const
|
|
204
|
-
const frame = object(
|
|
201
|
+
if (receipts.length !== 1) return null;
|
|
202
|
+
const [receipt] = receipts;
|
|
203
|
+
const receiptData = object(receipt.data);
|
|
204
|
+
const frame = object(receiptData.frame);
|
|
205
|
+
if (frame.id !== owner.requestId) return null;
|
|
205
206
|
const starts = slice.filter(entry => matches(entry, "rpc_agent_start"));
|
|
206
207
|
const latestStart = starts.at(-1);
|
|
207
208
|
const latestStartIndex = latestStart ? slice.indexOf(latestStart) : -1;
|
|
@@ -215,12 +216,12 @@ export function headRecoveryEvidence(entries: unknown[], owner: Pick<HeadRecover
|
|
|
215
216
|
const latestAssistant = assistants.at(-1);
|
|
216
217
|
const latestRunStatus = object(latestAssistant?.message).stopReason;
|
|
217
218
|
let outcome: "done" | "cancelled" | undefined;
|
|
218
|
-
const receiptData = object(receipt.data);
|
|
219
219
|
const startData = object(latestStart?.data);
|
|
220
|
+
const receiptIndex = slice.indexOf(receipt);
|
|
220
221
|
const receiptAfterStart = typeof receiptData.runOrdinal === "number" && typeof startData.runOrdinal === "number"
|
|
221
222
|
&& receiptData.hostPid === startData.hostPid
|
|
222
223
|
? receiptData.runOrdinal >= startData.runOrdinal
|
|
223
|
-
:
|
|
224
|
+
: receiptIndex > latestStartIndex;
|
|
224
225
|
if (frame.status === "aborted" && (!latestStart || receiptAfterStart)) outcome = "cancelled";
|
|
225
226
|
if (frame.status === "completed") {
|
|
226
227
|
if (frame.agentInvoked === false && !latestStart) outcome = "done";
|
|
@@ -229,7 +230,6 @@ export function headRecoveryEvidence(entries: unknown[], owner: Pick<HeadRecover
|
|
|
229
230
|
}
|
|
230
231
|
const error = object(frame.error);
|
|
231
232
|
const failedAt = typeof receipt.timestamp === "string" ? Date.parse(receipt.timestamp) : NaN;
|
|
232
|
-
const receiptIndex = slice.indexOf(receipt);
|
|
233
233
|
const sameRun = typeof receiptData.hostPid === "number" && Number.isSafeInteger(receiptData.hostPid)
|
|
234
234
|
&& receiptData.hostPid > 0 && typeof receiptData.instanceKey === "string" && receiptData.instanceKey !== ""
|
|
235
235
|
&& typeof receiptData.runOrdinal === "number" && Number.isSafeInteger(receiptData.runOrdinal) && receiptData.runOrdinal > 0
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { Type } from "@sinclair/typebox/type";
|
|
4
|
+
import { Value } from "@sinclair/typebox/value";
|
|
5
|
+
import type { Lane, StorePort } from "../contracts";
|
|
6
|
+
import type { prepareWorkerMemoryImport } from "../omp/worker-memory-import";
|
|
7
|
+
import { parseWorkerMemoryPage } from "../worker/worker-memory-page";
|
|
8
|
+
import { workerMemoryCheckoutStamp, workerMemoryRepositoryMatches } from "../worker/worker-repository";
|
|
9
|
+
import type { WorkerProbe, WorkerRegistration } from "../worker/worker-wire";
|
|
10
|
+
import { successful, type RuntimeHost } from "./native-frames";
|
|
11
|
+
|
|
12
|
+
type Destination = NonNullable<ReturnType<typeof prepareWorkerMemoryImport>>;
|
|
13
|
+
export type MemoryDestination = (headId: string, headFile: string, cwd: string) => Destination | undefined;
|
|
14
|
+
const digest = (parts: readonly unknown[]) => createHash("sha256").update(JSON.stringify(parts)).digest("hex");
|
|
15
|
+
const statusKey = (id: string) => `worker-memory:status:${id}`;
|
|
16
|
+
const changeStamp = /^[a-f0-9]{64}$/;
|
|
17
|
+
const count = Type.Integer({ minimum: 0, maximum: Number.MAX_SAFE_INTEGER });
|
|
18
|
+
const observation = { generation: count, at: count };
|
|
19
|
+
const exact = { additionalProperties: false };
|
|
20
|
+
const pendingIndex = new WeakMap<StorePort, Map<string, string>>();
|
|
21
|
+
const report = Type.Union([
|
|
22
|
+
Type.Object({ ...observation, status: Type.Literal("unavailable") }, exact),
|
|
23
|
+
Type.Object({ ...observation, status: Type.Literal("unchanged") }, exact),
|
|
24
|
+
Type.Object({ ...observation, status: Type.Literal("checked"), cursor: count, records: count,
|
|
25
|
+
inserted: count, skipped: count, rejected: count, lexical: count, indexed: count, disabled: count, pending: count, deferred: count }, exact),
|
|
26
|
+
]);
|
|
27
|
+
|
|
28
|
+
interface ScanCursor { after: number; start?: string; unchanged?: string }
|
|
29
|
+
function scanCursor(saved: string | null): ScanCursor {
|
|
30
|
+
if (!saved) return { after: 0 };
|
|
31
|
+
const cursor: ScanCursor = JSON.parse(saved);
|
|
32
|
+
if (!Number.isSafeInteger(cursor.after) || cursor.after < 0
|
|
33
|
+
|| cursor.start !== undefined && !changeStamp.test(cursor.start)
|
|
34
|
+
|| cursor.unchanged !== undefined && (!changeStamp.test(cursor.unchanged) || cursor.after !== 0))
|
|
35
|
+
throw new Error("Invalid memory scan cursor");
|
|
36
|
+
return cursor;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function workerMemoryStatus(store: StorePort, laneId: string) {
|
|
40
|
+
const raw = store.getMeta(statusKey(laneId));
|
|
41
|
+
if (!raw) return null;
|
|
42
|
+
if (raw.length <= 512) {
|
|
43
|
+
try {
|
|
44
|
+
const status: unknown = JSON.parse(raw);
|
|
45
|
+
if (Value.Check(report, status)) {
|
|
46
|
+
if (status.status === "checked" && status.pending && pendingIndex.get(store)?.get(laneId) !== raw)
|
|
47
|
+
return { ...status, pending: 0, deferred: status.deferred + status.pending };
|
|
48
|
+
return status;
|
|
49
|
+
}
|
|
50
|
+
} catch (error) { if (!(error instanceof SyntaxError)) throw error; }
|
|
51
|
+
}
|
|
52
|
+
return { status: "unavailable" } as const;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** Use the same checkout proof before redirecting a fresh worker bank and before importing it. */
|
|
56
|
+
export async function verifyMemoryCheckout(lane: Pick<Lane, "cwd" | "repoRoot" | "remote">) {
|
|
57
|
+
try {
|
|
58
|
+
if (!lane.remote || !lane.repoRoot) return;
|
|
59
|
+
const checkout = { ...lane.remote, repoRoot: lane.repoRoot, gitDir: join(lane.repoRoot, ".git") };
|
|
60
|
+
const stamp = workerMemoryCheckoutStamp(lane.cwd, checkout);
|
|
61
|
+
if (!stamp || !await workerMemoryRepositoryMatches(lane.cwd, checkout)) return;
|
|
62
|
+
return () => workerMemoryCheckoutStamp(lane.cwd, checkout) === stamp;
|
|
63
|
+
} catch (error) {
|
|
64
|
+
if (!(error instanceof Error)) throw error;
|
|
65
|
+
// Optional private storage must never prevent a normal remote launch.
|
|
66
|
+
return undefined;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** A read of the already attached owner, never an open, resume, model turn or SSH path request. */
|
|
71
|
+
export async function pullWorkerMemory(store: StorePort, lane: Pick<Lane,
|
|
72
|
+
"id" | "generation" | "cwd" | "repoRoot" | "remote" | "pid" | "sessionId" | "sessionFile">, source: {
|
|
73
|
+
connection: Pick<RuntimeHost, "request">;
|
|
74
|
+
registration: WorkerRegistration;
|
|
75
|
+
lookup(): Promise<WorkerRegistration>;
|
|
76
|
+
probe(reg: WorkerRegistration): Promise<WorkerProbe>;
|
|
77
|
+
destination(): Destination | undefined;
|
|
78
|
+
current(): boolean;
|
|
79
|
+
confirmIdleHead(): Promise<boolean>;
|
|
80
|
+
ownsStatus(): boolean;
|
|
81
|
+
canIndex(): boolean;
|
|
82
|
+
}) {
|
|
83
|
+
const remote = lane.remote;
|
|
84
|
+
if (!remote || !lane.sessionId || !lane.repoRoot || join(lane.repoRoot, remote.subdir) !== lane.cwd) return;
|
|
85
|
+
try {
|
|
86
|
+
const dest = source.destination();
|
|
87
|
+
if (!dest || !source.current()) return;
|
|
88
|
+
const validEnrollment = (reg: WorkerRegistration) => reg.destination === source.registration.destination
|
|
89
|
+
&& reg.identityFile === source.registration.identityFile && reg.description.workerId === remote.workerId
|
|
90
|
+
&& reg.description.stateDir === remote.stateDir && reg.description.repos.some(repo => repo.id === remote.repoId
|
|
91
|
+
&& source.registration.description.repos.some(saved => saved.id === repo.id && saved.cwd === repo.cwd));
|
|
92
|
+
const reg = await source.lookup();
|
|
93
|
+
if (!validEnrollment(reg) || !source.current()) return;
|
|
94
|
+
const [checkoutUnchanged, owner] = await Promise.all([verifyMemoryCheckout(lane), source.probe(reg)]);
|
|
95
|
+
if (!checkoutUnchanged?.() || !source.current()
|
|
96
|
+
|| owner.memorySyncVersion !== 1 || owner.uncertain || !owner.socket || !owner.pidAlive || !owner.ownerAlive
|
|
97
|
+
|| !owner.sessionFile || owner.pid !== lane.pid || owner.sessionId !== lane.sessionId) return;
|
|
98
|
+
const origin = digest([remote.workerId, remote.stateDir, remote.repoId, remote.revision, remote.subdir,
|
|
99
|
+
lane.id, lane.cwd, lane.sessionId, lane.sessionFile]);
|
|
100
|
+
const key = `worker-memory:cursor:${digest([dest.namespace, origin])}`;
|
|
101
|
+
const { after, start, unchanged } = scanCursor(store.getMeta(key));
|
|
102
|
+
const reply = await source.connection.request({ type: "get_worker_memory", after, ...(unchanged && { unchanged }) });
|
|
103
|
+
if (!source.current()) return;
|
|
104
|
+
const page = parseWorkerMemoryPage(successful(reply, "get_worker_memory"), after);
|
|
105
|
+
if (!validEnrollment(await source.lookup()) || !source.current()
|
|
106
|
+
|| !await source.confirmIdleHead()) return;
|
|
107
|
+
const currentDest = source.destination();
|
|
108
|
+
if (!currentDest || currentDest.namespace !== dest.namespace || !source.current() || !checkoutUnchanged()) return;
|
|
109
|
+
if (unchanged === page.stamp && !after && !page.next && !page.records.length) {
|
|
110
|
+
// Keep the last actual index readback; an empty stamp response is not another vector check.
|
|
111
|
+
const previous = workerMemoryStatus(store, lane.id);
|
|
112
|
+
if (previous?.status !== "checked" || previous.generation !== lane.generation)
|
|
113
|
+
store.tryWorkerMemoryMeta(statusKey(lane.id), JSON.stringify({ generation: lane.generation, at: Date.now(), status: "unchanged" }));
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
// Commit through the original live SDK capability. A same-path replacement
|
|
117
|
+
// or change in its native settings is not the policy that authorized the read.
|
|
118
|
+
const receiptKey = (id: string) => `worker-memory:imported:${digest([dest.receiptNamespace, id])}`;
|
|
119
|
+
const result = dest.importPage(page.records, origin, {
|
|
120
|
+
seen: id => store.getMeta(receiptKey(id)) === "1",
|
|
121
|
+
mark: ids => {
|
|
122
|
+
if (!store.tryWorkerMemoryMeta(ids.map(receiptKey), "1")) throw new Error("Memory receipts not reserved");
|
|
123
|
+
},
|
|
124
|
+
}, () => source.canIndex() && checkoutUnchanged());
|
|
125
|
+
if (result === undefined) return;
|
|
126
|
+
const first = after === 0 ? page.stamp : start;
|
|
127
|
+
const cursor: ScanCursor = { after: page.next };
|
|
128
|
+
if (first === page.stamp) {
|
|
129
|
+
if (page.next === 0) cursor.unchanged = first;
|
|
130
|
+
else cursor.start = first;
|
|
131
|
+
}
|
|
132
|
+
if (!store.tryWorkerMemoryMeta(key, JSON.stringify(cursor))) return;
|
|
133
|
+
const { confirmation, ...counts } = result;
|
|
134
|
+
const status = { generation: lane.generation, at: Date.now(), status: "checked",
|
|
135
|
+
cursor: page.next, records: page.records.length, ...counts };
|
|
136
|
+
const receipt = JSON.stringify(status);
|
|
137
|
+
store.tryWorkerMemoryMeta(statusKey(lane.id), receipt);
|
|
138
|
+
if (!confirmation) return;
|
|
139
|
+
const tasks = pendingIndex.get(store) ?? new Map<string, string>();
|
|
140
|
+
pendingIndex.set(store, tasks);
|
|
141
|
+
tasks.set(lane.id, receipt);
|
|
142
|
+
// Native indexing may finish after eviction. A later page, a different native
|
|
143
|
+
// generation, or stopped HEAD owns its own status; don't hold release to update it.
|
|
144
|
+
void confirmation.then(observed => {
|
|
145
|
+
if (observed && source.ownsStatus() && store.getMeta(statusKey(lane.id)) === receipt)
|
|
146
|
+
store.tryWorkerMemoryMeta(statusKey(lane.id), JSON.stringify({ ...status, ...observed }));
|
|
147
|
+
}).catch(() => { /* A lost readback is not confirmation of a vector. */ }).finally(() => {
|
|
148
|
+
if (tasks.get(lane.id) === receipt) tasks.delete(lane.id);
|
|
149
|
+
});
|
|
150
|
+
} catch {
|
|
151
|
+
// Neither worker error strings nor SDK diagnostics belong in logs, the ledger or a model turn.
|
|
152
|
+
if (source.current()) store.tryWorkerMemoryMeta(statusKey(lane.id), JSON.stringify({
|
|
153
|
+
generation: lane.generation, at: Date.now(), status: "unavailable",
|
|
154
|
+
}));
|
|
155
|
+
}
|
|
156
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Database } from "bun:sqlite";
|
|
2
|
-
import { deferredRecoveryCandidate, physicalRouteKey, routingConversation, type DeferredRoutingPort, type Inbound, type Lane
|
|
2
|
+
import { deferredRecoveryCandidate, physicalRouteKey, routingConversation, type DeferredRoutingPort, type Inbound, type Lane } from "../contracts";
|
|
3
3
|
|
|
4
4
|
const LEGACY_QUEUE = "intake:deferred-routing";
|
|
5
5
|
const SCHEMA = `
|
|
@@ -132,12 +132,6 @@ export class DeferredRoutingQueue implements DeferredRoutingPort {
|
|
|
132
132
|
this.db.query("DELETE FROM deferred_routing WHERE id = ?").run(id);
|
|
133
133
|
}
|
|
134
134
|
|
|
135
|
-
hasOnRoute(route: Route, exceptId: string): boolean {
|
|
136
|
-
return this.db.query(`
|
|
137
|
-
SELECT 1 FROM deferred_routing WHERE physical_route = ? AND id <> ? LIMIT 1
|
|
138
|
-
`).get(physicalRouteKey(route), exceptId) !== null;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
135
|
choices(input: Pick<Inbound, "id" | "route" | "receivedAt">, deadline: number): Iterable<DeferredChoiceRow> {
|
|
142
136
|
return this.db.query<DeferredChoiceRow, [string, number, number, string]>(`
|
|
143
137
|
SELECT id, json_extract(data, '$.text') AS text, message_id AS messageId,
|