Skip to content

abso-core

Public

abso is version control for agents: the client, the engine and a server you can run on your own Cloudflare account.

Check passed

Versions 161 to 162

Compare

+70 −13 in 6 places
Lines 4–13 at 162 (were 4–11 at 161)
44// R2 copies, edge cache, probes or disk-first writer.
55
66import { DurableObject } from "cloudflare:workers";
7−import { type Answer, answer, type Readers } from "../../worker/project/http.ts";
7+import { createHash } from "node:crypto";
8+import { type Answer, answer, type Readers, readerAnswer } from "../../worker/project/http.ts";
89import type { ProjectCalls, ProjectHistory } from "../../worker/project/project-api.ts";
10+import { ProjectError } from "../../worker/project/project-error.ts";
911import { BLOB_MAX, BlobStore } from "./blobs.ts";
1012import { DiskFirstRuntime } from "./disk-first-runtime.ts";
1113import { EngineProject, SqliteLog } from "./engine-project.ts";
Lines 165–171 at 162 (were 163–168 at 161)
163165 body: unknown,
164166 how: string | undefined,
165167 revision: number,
168+ request?: { id: string; principal: string },
166169 ): Promise<Answer> {
167170 const runtime = this.diskRuntime()!;
168171 const validate = () => {
Lines 173–183 at 162 (were 170–176 at 161)
170173 throw Object.assign(Error("project authorization changed during call setup"), { code: "authority-changed" });
171174 };
172175 const progress = await this.prepareDisk(validate);
173− const known = new Set((await this.ctx.storage.get<string[]>("readers")) ?? []);
176+ const legacyReaders = (await this.ctx.storage.get<string[]>("readers")) ?? [];
177+ const storedReaders = progress?.ready
178+ ? (new SqliteWriterState(this.ctx.storage, "server-disk-v1").read("runtime", "readers") as string[] | undefined)
179+ : undefined;
180+ const known = new Set(storedReaders ?? legacyReaders);
174181 validate();
175182 let readersChanged = false;
176183 const readers: Readers = {
Lines 194–237 at 162 (were 187–211 at 161)
187194 return { status: 404, body: { error: "no such project; run init first" } };
188195 if (!progress?.ready && !(progress?.phase === "empty" && op === "init"))
189196 return { status: 503, body: { error: "project indexes are being prepared", retryAfter: 1, progress } };
197+ if (agent && op !== "reader") {
198+ const refused = readerAnswer({ status: () => undefined }, op, agent, body, readers);
199+ if (refused) return refused;
200+ }
190201 const before = new SqliteLog(this.ctx.storage).seq();
191202 const action = (calls: EngineProject) => {
192203 const result = answer(calls, op, agent, body, readers, how);
193204 if (result.status >= 500) throw Error(`project operation failed: ${JSON.stringify(result.body)}`);
205+ if (readersChanged)
206+ new SqliteWriterState(this.ctx.storage, "server-disk-v1").write("runtime", "readers", readers.list());
194207 return result;
195208 };
196209
210+ const receipt = request
211+ ? {
212+ id: `http:${createHash("sha256").update(request.principal).digest("hex")}:${request.id}`,
213+ identity: {
214+ project: name,
215+ principal: request.principal,
216+ agent: agent ?? null,
217+ operation: op,
218+ body: body ?? null,
219+ how: how ?? null,
220+ },
221+ }
222+ : undefined;
197223 const result =
198224 progress.phase === "empty"
199− ? runtime.initialize(action, validate)
225+ ? runtime.initialize(action, validate, receipt)
200226 : READ_OPS.has(op) || op.startsWith("change/")
201227 ? runtime.read(action, validate)
202− : runtime.write(action, validate);
228+ : runtime.write(action, validate, receipt);
203230 if (readersChanged) {
204231 this.authorityRevision++;
205− await this.ctx.storage.put("readers", readers.list());
206232 }
207233 const log = new SqliteLog(this.ctx.storage);
208− if (log.seq() !== before) {
234+ if (log.seq() !== before || (request && !READ_OPS.has(op))) {
209235 this.wake();
210236 await this.ctx.storage.put("name", name);
211237 await this.soon(Date.now() + 100);
Lines 371–408 at 162 (were 345–364 at 161)
345371 inFeed = false,
346372 how?: string,
347373 key?: KeyForCall,
374+ requestId?: string,
348375 ): Promise<Answer> {
349376 const revision = this.authorityRevision;
377+ let principal = "shared-token";
378+ if (
379+ requestId !== undefined &&
380+ !/^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(requestId)
381+ )
382+ return { status: 400, body: { error: "Idempotency-Key must be a UUID" } };
350383 if (key) {
351384 const decided = await this.checkAgentKey(key.presented, agent, key.address);
352385 if (!decided.ok) return { status: decided.status, body: { error: decided.error } };
353386 const allowed = keyAllows(decided.role, { write: key.write, agent, route: key.route });
354387 if (!allowed.ok) return { status: allowed.status, body: { error: allowed.error } };
355388 how = decided.as;
389+ principal = `key:${decided.id}`;
356390 }
357391 if (op === "feed" && !inFeed) return this.feed(name, body);
358392 if (this.diskRuntime()) {
359393 try {
360− return await this.diskCall(name, op, agent, body, how, revision);
394+ return await this.diskCall(
395+ name,
396+ op,
397+ agent,
398+ body,
399+ how,
400+ revision,
401+ requestId ? { id: requestId, principal } : undefined,
402+ );
361403 } catch (error) {
404+ if ((error as { code?: string })?.code === "request-reused")
405+ return { status: 409, body: { error: "Idempotency-Key was reused for a different request" } };
362406 if ((error as { code?: string })?.code === "authority-changed")
363407 return { status: 409, body: { error: "project authorization changed; retry the request", retryable: true } };
364408 throw error;
Lines 543–569 at 162 (were 499–512 at 161)
499543 if (found) await this.ctx.storage.put("git:head", found.head);
500544 return null;
501545 }
546+ // Unexpected failures leave the cursor unacknowledged for retry. Engine
547+ // refusals are recorded and acknowledged so a later fixing commit can advance.
548+ const ingest = (p: EngineProject) =>
549+ p.ingest({ author: found.author, base: found.base, commits: found.commits }, Date.now());
550+ const runtime = this.diskRuntime();
502551 let result: unknown;
503552 try {
504− result = this.useProject(
505− (p) => p.ingest({ author: found.author, base: found.base, commits: found.commits }, Date.now()),
506− true,
507− );
508− } catch (e) {
509− result = { error: e instanceof Error ? e.message : String(e) };
553+ result = runtime
554+ ? runtime.write(ingest, () => {}, {
555+ id: `git:${found.head}`,
556+ identity: {
557+ project: name,
558+ head: found.head,
559+ base: found.base,
560+ commits: found.commits.map((commit) => commit.sha),
561+ },
562+ })
563+ : this.useProject(ingest, true);
564+ } catch (error) {
565+ if (!(error instanceof ProjectError)) throw error;
566+ result = { error: error.message };
510567 }
511568 const taken = {
512569 at: new Date().toISOString(),
MCP
compare on this site's /mcp
CLI
abso diff 161 162 server/src/project-object.ts --json
JSON
/christopher/abso-core/compare/161..162?file=server%2Fsrc%2Fproject-object.ts&format=json