Add workspaces, computers, bot memory and the bots queue

- Schema: workspaces (+ workspace_bots, workspace_computers), containers,
  computers, bot_computers, bots.memory, workspaces.system_prompt, and
  bots_queue as a bun-sqlite isQueue table
- Main computer (and its container record) ensured with the coordinator on
  signup, seed and /admin/bots; the coordinator's access to it is locked
- Effective computer access: direct grants plus workspace computers
- Full bot prompt: core instructions, workspace prompts, then memory;
  bots can rewrite their memory and system prompt
- Queue helpers on the native BunSQLite.queue API, plus a handler that
  heartbeats, serializes per computer, recovers after restarts, reports
  lost jobs, supports cancelling and pushes outcomes over the WebSocket
- Enable SQLite foreign keys at startup so schema cascades fire
- Prune finished jobs daily

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2026-10-18 18:33:54 +01:00
co-authored by Claude Opus 5.5
parent 694c83346f
commit d49f524fe8
72 changed files with 2961 additions and 31 deletions
+7
View File
@@ -1,5 +1,6 @@
import bunext from "@moduletrace/bunext";
import cronHeartbeat from "./heartbeat";
import pruneBotsQueue from "./prune-bots-queue";
import registerCronJob from "./register-cron-job";
export default function cron() {
@@ -15,4 +16,10 @@ export default function cron() {
task: cronHeartbeat,
run_on_start: true,
});
registerCronJob({
title: "prune-bots-queue",
schedule: "@daily",
task: pruneBotsQueue,
});
}
+23
View File
@@ -0,0 +1,23 @@
import bunext from "@moduletrace/bunext";
import BunSQLite from "@moduletrace/bun-sqlite";
import { AppData } from "@/src/data/app-data";
/**
* Deletes finished jobs (completed, failed or cancelled) older than
* `AppData.BotQueueRetentionDays`. Their messages stay in the conversation.
*/
export default async function pruneBotsQueue() {
const cutoff =
Date.now() - AppData.BotQueueRetentionDays * 24 * 60 * 60 * 1000;
const res = await BunSQLite.sql({
sql: `DELETE FROM bots_queue WHERE status IN ('completed', 'failed') AND finished_at IS NOT NULL AND finished_at < ? RETURNING id`,
values: [cutoff],
});
bunext.bunextLog.info(
`Cron: pruned ${res.payload?.length || 0} finished bot job(s)`,
);
return res;
}