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 293 to 318

Compare

+56 −11 in 9 places
Lines 159–166 at 318 (were 159–165 at 293)
159159
160160/** Workers' crypto.DigestStream, which the blob store hashes uploads with. */
161161async function installDigestStream(): Promise<void> {
162− const c = globalThis.crypto as unknown as { DigestStream?: unknown };
162+ // Through a cast: abso's worker compiles this file too (tool.lock.json), and its types have no globalThis.crypto.
163+ const c = (globalThis as unknown as { crypto: { DigestStream?: unknown } }).crypto;
163164 if (c.DigestStream) return;
164165 const { createHash } = await import("node:crypto");
165166 class DigestStream extends WritableStream<Uint8Array> {
Lines 190–197 at 318 (were 189–194 at 293)
189190 DatabaseSync: new (path: string) => Db;
190191 handle: (request: Request, env: unknown, ctx: unknown, issues: unknown) => Promise<Response>;
191192 ProjectObject: new (ctx: unknown, env: unknown) => object;
193+ IssueProject: new (ctx: unknown, env: unknown) => object;
194+ issuesFetch: (request: Request, env: unknown, ctx: unknown, route: unknown) => Promise<Response>;
192195};
193196let server: Promise<Server> | undefined;
194197
Lines 243–255 at 318 (were 240–246 at 293)
240243 `local projects couldn't load the server's code: ${e instanceof Error ? e.message : String(e)}`,
241244 );
242245 }
243− return { DatabaseSync: sqlite.DatabaseSync, handle: loaded.handle, ProjectObject: loaded.ProjectObject };
246+ return {
247+ DatabaseSync: sqlite.DatabaseSync,
248+ handle: loaded.handle,
249+ ProjectObject: loaded.ProjectObject,
250+ IssueProject: loaded.IssueProject,
251+ issuesFetch: loaded.issuesFetch,
252+ };
244253 })();
245254 return server;
246255}
Lines 265–274 at 318 (were 256–261 at 293)
256265 object: object | undefined;
257266 /** PRAGMA data_version when this process last used the project: it changes when another process writes. */
258267 seen: number | undefined;
268+ /** The project's issues, asks and news: issues.sqlite beside it, opened when a call first reaches them. */
269+ issues?: { db: Db; storage: ReturnType<typeof storageOver> };
270+ /** The issues object for the call under way: made again for each call, as another process may have written. */
271+ issueObject?: object;
259272}
260273
261274/** Every store file this process has open: closed when its command ends (closeLocalStores). */
Lines 284–293 at 318 (were 271–278 at 293)
271284 opened.clear();
272285}
273286
274−const PROJECT_PATH = /^\/p\/([^/]+)\//;
275−const NAME = /^[A-Za-z0-9._-]{1,100}$/;
287+/** A project's calls, and its issues, asks and news, which the open server keeps at /issues/p/<project>/. */
288+const PROJECT_PATH = /^(?:\/issues)?\/p\/([^/]+)\//;
289+/** A project's name is also its folder in the store, so it never starts with a dot ("." and ".." would leave it). */
290+const NAME = /^[A-Za-z0-9_-][A-Za-z0-9._-]{0,99}$/;
276291const json = (status: number, body: unknown) => Response.json(body, { status });
277292
278293/**
Lines 327–365 at 318 (were 312–321 at 293)
312327 return p.object;
313328 },
314329 },
315− // Issues, asks and news aren't in local projects yet: a start note's issue hooks find nothing to call.
316− ISSUES_DO: { idFromName: (n: string) => n, get: () => ({}) },
330+ ISSUES_DO: {
331+ idFromName: (n: string) => n,
332+ get: (n: string) => {
333+ const p = open.get(n);
334+ if (!p || n !== name) throw new LocalError(`no local project ${n}`);
335+ if (p.issues === undefined || !opened.has(p.issues.db)) {
336+ const db = new opening!.DatabaseSync(join(dir, name, "issues.sqlite"));
337+ opened.add(db);
338+ db.exec("PRAGMA journal_mode = WAL; PRAGMA busy_timeout = 120000; PRAGMA synchronous = NORMAL");
339+ p.issues = { db, storage: storageOver(db) };
340+ }
341+ // Its writes need no lock of their own: every call holds the project file's (see below).
342+ p.issueObject ??= new opening!.IssueProject(
343+ { id: { toString: () => n, name: n }, storage: p.issues.storage },
344+ env(name),
345+ );
346+ return p.issueObject;
347+ },
348+ },
317349 });
318− return async (input, init = {}) => {
350+ // One call at a time, as a Durable Object takes them: a call holds its project's write transaction across awaits,
351+ // and the connection can't start a second (two calls at once come from Promise.all in ci and waiting --mine).
352+ let last: Promise<unknown> = Promise.resolve();
353+ return (input, init) => {
354+ const next = last.then(
355+ () => call(input, init),
356+ () => call(input, init),
357+ );
358+ last = next.catch(() => {});
359+ return next;
360+ };
362+ async function call(input: string, init: RequestInit = {}): Promise<Response> {
319363 const s = await loadServer();
320364 opening = s;
321365 const url = new URL(input);
Lines 373–382 at 318 (were 329–335 at 293)
329373 headers.set("authorization", `Bearer ${LOCAL_TOKEN}`);
330374 const request = new Request(url, { ...init, headers });
331375 const waits: Promise<unknown>[] = [];
376+ // Every call, issues ones too, holds the project file's lock, so local writers of the project and of its
377+ // issues take one lock in one order.
332378 p.db.exec("BEGIN IMMEDIATE");
379+ p.issueObject = undefined;
333380 try {
334381 const version = (p.db.prepare("PRAGMA data_version").get() as { data_version: number }).data_version;
335382 if (p.seen !== undefined && version !== p.seen) p.object = undefined;
Lines 384–390 at 318 (were 337–343 at 293)
337384 request,
338385 env(name),
339386 { waitUntil: (w: Promise<unknown>) => waits.push(w) },
340− issuesNone,
387+ s.issuesFetch,
341388 );
342389 await Promise.allSettled(waits);
343390 // The answer is read whole before the write is kept, so a body that fails to arrive keeps nothing either.
Lines 403–407 at 318 (were 356–362 at 293)
356403 // Where the Workers runtime answers a throw with a 500, so does this.
357404 return json(500, { error: e instanceof Error ? e.message : String(e) });
358405 }
359− };
406+ }
360407}
361−
362−const issuesNone = async () => json(404, { error: "issues, asks and news aren't in local projects yet" });
MCP
compare on this site's /mcp
CLI
abso diff 293 318 client/src/local-store.ts --json
JSON
/christopher/abso-core/compare/293..318?file=client%2Fsrc%2Flocal-store.ts&format=json