Versions 149 to 150
new file, 534 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+
26+
27+/** At most one push out a minute: each one clones the repo, so publishes in a burst share one. */
31+
33+ * The load guard (platform issue 46): an estimate of a loaded project's memory from its log entries, lines and claim
34+ * keys, all read from SQLite without loading. A Durable Object has 128 MB. Past the hard cap a project refuses to
35+ * load (export still reads it); past the soft cap, new work is held so the hard cap is never reached.
46+const SOFT_HELD_OPS: ReadonlySet<string> = new Set(["record", "edit", "publish", "land", "amend", "pluck", "drop"]);
47+
49+ return entries * LOAD_BYTES_PER_ENTRY + lines * LOAD_BYTES_PER_LINE + keys * LOAD_BYTES_PER_KEY + LOAD_BASE_BYTES;
51+
59+
67+
68+/** What the issues Durable Object hears when a start note naming an issue begins and ends. Each is optional. */
74+
85+ private gitSyncing: Promise<{ head: string; commits: number; answer: unknown } | null> | undefined;
86+
91+
94+ return { keep: (text: string) => this.blobs.putText(text), read: (sha: string) => this.blobs.textOf(sha) };
96+
97+ /** The project, loaded from its log on first use. A log too big for memory is refused, not loaded. */
103+ if (why) throw new Error(`${why}, too big to load in a Durable Object's memory; GET export still reads it`);
104+ this.loaded = EngineProject.open(this.ctx.storage, (sha) => this.blobs.has(sha), this.wholeFiles());
110+
116+
121+ return tables.length === 0 ? { chars: 0, entries: 0 } : new SqliteLog(this.ctx.storage).logSize();
123+
132+
139+ ? `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`
142+
143+ /** Why this project mustn't load: its estimated memory, or before its lines are counted, its log's size; else null. */
149+ ? `this project holds ${counted.lines} lines and ${this.logChars().entries} entries, an estimated ${(bytes / 1e6).toFixed(0)} MB once loaded`
153+ return chars > LOG_LOAD_MAX_CHARS ? `this project's log is ${(chars / 1e6).toFixed(1)} MB` : null;
155+
157+
161+ if (a.status === 200 && (await this.ctx.storage.get("pushError"))) await this.ctx.storage.setAlarm(Date.now());
164+
168+
169+ /** Shared's newest version, from storage alone, never loading the project. Null when there's no project. */
172+ return { version: new SqliteLog(this.ctx.storage).sharedVersion(), at: new Date().toISOString() };
174+
176+ async exportLog(from: number, limit: number): Promise<{ lines: string; next: number | null } | null> {
181+
187+
189+ * GET feed?from=&wait=<seconds, up to 25>: when nothing is new, hold the call until an entry is written or the wait
208+
209+ /** One project call: the agent key (if any), the size caps, then answer() from worker/project/http.ts. */
236+ // Readers live in storage, not the log: a refused call writes nothing, so replay never needs them.
250+ const logLength = () => (this.loaded as { logLength?: () => number } | undefined)?.logLength?.() ?? 0;
259+ // A new version of shared: push it out to Artifacts in the background. The alarm retries; the call never waits.
274+
276+ * The engine's starting answer carries hooks for the issues code (a start note naming an issue began or ended). They
277+ * go to the project's IssueProject, and never to the client. A failed hook is logged and never fails the call.
287+ const issues = this.env.ISSUES_DO.get(this.env.ISSUES_DO.idFromName(name)) as unknown as IssueHooks;
292+ console.log(JSON.stringify({ event: "issues-hook", what, project: name, error: String(e).slice(0, 200) }));
304+
305+ /** A folder's binary files count by their bytes, and a binary file says its size: the blob store knows both. */
312+ blobs ? { ...e, bytes: (e.bytes ?? 0) + blobs.reduce((n, sha) => n + this.blobs.size(sha), 0) } : e,
320+
322+
324+ * Takes in commits pushed to the project's repo with plain git: the ones above the server's last commit that
325+ * haven't been taken in yet. One run at a time; a call while a run is going gets that run's answer.
333+
334+ private async gitSyncOnce(): Promise<{ head: string; commits: number; answer: unknown } | null> {
358+ result = this.project.ingest({ author: found.author, base: found.base, commits: found.commits }, Date.now());
374+
380+
382+ * Plain-git pushes in first, so the push out builds on them; then shared out to the project's Artifacts repo, at
383+ * most once a minute, backing off on failure. Without an ARTIFACTS binding (local dev) it does nothing.
410+ // Kept for /out, and tried again with a backoff of our own (a thrown alarm is retried only six times).
422+ await this.ctx.storage.put({ pushed: result, "git:head": result.commit, pushedAt: Date.now() });
425+ if (this.project.shared().version > result.version) await this.soon(Date.now() + PUSH_EVERY_MS);
427+
445+
447+
451+
454+ const decided = await checkKey(state, this.env.KEY_HMAC_SECRET, presented, agent, Date.now(), address);
460+
477+
486+
490+
492+
499+
501+ * 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 149 150 server/src/project-object.ts --json
- JSON
- /christopher/abso-core/compare/149..150?file=server%2Fsrc%2Fproject-object.ts&format=json