Versions 8 to 318
new file, 839 lines
1+// One project: its append-only log and blobs in the Durable Object's SQLite, the engine loaded from them, and the push
2+// out to the project's Artifacts repo after each new version of shared. Ported from the platform's ProjectObject
3+// (worker/src/index.ts), trimmed to the core path: no CI, merge queue checker, boxes, pipelines, members, visibility,
5+
35+
62+
63+/** At most one push out a minute: each one clones the repo, so publishes in a burst share one. */
71+const GIT_LIMIT_POLICY = `expanded-v2:${GIT_PACK_MAX_BYTES}:${GIT_OBJECT_MAX_BYTES}:${GIT_DECODED_MAX_BYTES}`;
72+
74+ * The load guard (platform issue 46): an estimate of a loaded project's memory from its log entries, lines and claim
75+ * keys, all read from SQLite without loading. A Durable Object has 128 MB. Past the hard cap a project refuses to
76+ * load (export still reads it); past the soft cap, new work is held so the hard cap is never reached.
87+const SOFT_HELD_OPS: ReadonlySet<string> = new Set(["record", "edit", "publish", "land", "amend", "pluck", "drop"]);
88+
90+ return entries * LOAD_BYTES_PER_ENTRY + lines * LOAD_BYTES_PER_LINE + keys * LOAD_BYTES_PER_KEY + LOAD_BASE_BYTES;
92+
100+
108+
109+/** What the issues Durable Object hears when a start note naming an issue begins and ends. Each is optional. */
115+
127+ private gitSyncing: Promise<{ head: string; commits: number; answer: unknown } | null> | undefined;
128+
138+
141+ return { keep: (text: string) => this.blobs.putText(text), read: (sha: string) => this.blobs.textOf(sha) };
143+
167+ new SqliteWriterState(this.ctx.storage, "server-disk-v1").read("runtime", "format") !== undefined
172+ if (runtime) return write ? runtime.write(operation, () => {}) : runtime.read(operation, () => {});
189+ throw Object.assign(Error("project authorization changed during call setup"), { code: "authority-changed" });
194+ ? (new SqliteWriterState(this.ctx.storage, "server-disk-v1").read("runtime", "readers") as string[] | undefined)
212+ return { status: 503, body: { error: "project indexes are being prepared", retryAfter: 1, progress } };
220+ if (result.status >= 500) throw Error(`project operation failed: ${JSON.stringify(result.body)}`);
222+ new SqliteWriterState(this.ctx.storage, "server-disk-v1").write("runtime", "readers", readers.list());
225+
245+
263+ if (result.status === 200 && op === "starting") result.body = await this.startingHooks(name, result.body);
267+
268+ /** The project, loaded from its log on first use. A log too big for memory is refused, not loaded. */
275+ if (why) throw new Error(`${why}, too big to load in a Durable Object's memory; GET export still reads it`);
276+ this.loaded = EngineProject.open(this.ctx.storage, (sha) => this.blobs.has(sha), this.wholeFiles());
282+
288+
293+ return tables.length === 0 ? { chars: 0, entries: 0 } : new SqliteLog(this.ctx.storage).logSize();
295+
304+
311+ ? `this project is near the most a project can hold (an estimated ${(bytes / 1e6).toFixed(0)} MB of ${LOAD_MAX_BYTES / 1e6} MB), so recording and publishing are held; status and reads keep working`
314+
315+ /** Why this project mustn't load: its estimated memory, or before its lines are counted, its log's size; else null. */
321+ ? `this project holds ${counted.lines} lines and ${this.logChars().entries} entries, an estimated ${(bytes / 1e6).toFixed(0)} MB once loaded`
325+ return chars > LOG_LOAD_MAX_CHARS ? `this project's log is ${(chars / 1e6).toFixed(1)} MB` : null;
327+
329+
333+ if (a.status === 200 && (await this.ctx.storage.get("pushError"))) await this.ctx.storage.setAlarm(Date.now());
336+
340+
341+ /** Shared's newest version, from storage alone, never loading the project. Null when there's no project. */
344+ return { version: new SqliteLog(this.ctx.storage).sharedVersion(), at: new Date().toISOString() };
346+
348+ async exportLog(from: number, limit: number): Promise<{ lines: string; next: number | null } | null> {
353+
359+
361+ * GET feed?from=&wait=<seconds, up to 25>: when nothing is new, hold the call until an entry is written or the wait
380+
381+ /** One project call: the agent key (if any), the size caps, then answer() from worker/project/http.ts. */
423+ return { status: 409, body: { error: "project authorization changed; retry the request", retryable: true } };
428+ return { status: 409, body: { error: "disk-first indexes exist; enable ABSO_DISK_FIRST before writing" } };
438+ // Readers live in storage, not the log: a refused call writes nothing, so replay never needs them.
452+ const logLength = () => (this.loaded as { logLength?: () => number } | undefined)?.logLength?.() ?? 0;
461+ // A new version of shared: push it out to Artifacts in the background. The alarm retries; the call never waits.
476+
478+ * The engine's starting answer carries hooks for the issues code (a start note naming an issue began or ended). They
479+ * go to the project's IssueProject, and never to the client. A failed hook is logged and never fails the call.
489+ const issues = this.env.ISSUES_DO.get(this.env.ISSUES_DO.idFromName(name)) as unknown as IssueHooks;
494+ console.log(JSON.stringify({ event: "issues-hook", what, project: name, error: String(e).slice(0, 200) }));
506+
507+ /** A folder's binary files count by their bytes, and a binary file says its size: the blob store knows both. */
514+ blobs ? { ...e, bytes: (e.bytes ?? 0) + blobs.reduce((n, sha) => n + this.blobs.size(sha), 0) } : e,
522+
524+
526+ * Takes in commits pushed to the project's repo with plain git: the ones above the server's last commit that
527+ * haven't been taken in yet. One run at a time; a call while a run is going gets that run's answer.
535+
536+ private async gitSyncOnce(): Promise<{ head: string; commits: number; answer: unknown } | null> {
550+ ? await this.ctx.storage.get<{ head: string; policy: string; kind: GitIntakeLimitError["kind"]; error: string }>(
636+
642+
644+ * Plain-git pushes in first, so the push out builds on them; then shared out to the project's Artifacts repo, at
645+ * most once a minute, backing off on failure. Without an ARTIFACTS binding (local dev) it does nothing.
704+ // Kept for /out, and tried again with a backoff of our own (a thrown alarm is retried only six times).
716+ await this.ctx.storage.put({ pushed: result, "git:head": result.commit, pushedAt: Date.now() });
719+ if (this.useProject((p) => p.shared().version) > result.version) await this.soon(Date.now() + PUSH_EVERY_MS);
721+
738+
740+
744+
747+ const decided = await checkKey(state, this.env.KEY_HMAC_SECRET, presented, agent, Date.now(), address);
753+
771+
781+
785+
787+
796+
798+ * Issues news, delivered through the engine's announce path: each item goes to the agents whose start note names
- MCP
- compare on this site's /mcp
- CLI
- abso diff 8 318 server/src/project-object.ts --json
- JSON
- /christopher/abso-core/compare/8..318?file=server%2Fsrc%2Fproject-object.ts&format=json