Keep every bot's computer work in its own workspace folder
Computers now mount only /home/gem/workspace from DATA_DIR/computers/<id>, so only the workspace persists and goes into the data archive. An older computer's whole home is moved aside to <id>-home-<ts> (kept, never archived) and its container recreated once by sync-computers. Each run works in bots/<bot>/users/<user> (also its cwd and HOME), with bots/<bot> for work every user shares and workspaces/<id> shared by a workspace's bots; the coordinator reaches the whole workspace. Computer tools are gated by withComputerDirs: bash and code start there, file tool paths and file: URLs outside the run's folders are refused, and so is sudo. search_computers, import_file and script tools start there too. The files browser shows members only the bots' folders they reach, their own user folder in each and their workspaces', with names on the id folders. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -1,23 +1,26 @@
|
||||
import bunext from "@moduletrace/bunext";
|
||||
import BunSQLite from "@moduletrace/bun-sqlite";
|
||||
import type { BUN_SQLITE_COBBLE_CONTAINERS } from "@/db/types/db";
|
||||
import migrateComputerLayout from "@/src/functions/backend/db/computers/migrate-computer-layout";
|
||||
import refreshComputerContainer from "@/src/functions/backend/db/computers/refresh-computer-container";
|
||||
|
||||
type Row = Pick<
|
||||
BUN_SQLITE_COBBLE_CONTAINERS,
|
||||
"id" | "docker_id" | "status" | "ip_address"
|
||||
"id" | "docker_id" | "status" | "ip_address" | "metadata"
|
||||
> & { computer_id: number };
|
||||
|
||||
/**
|
||||
* Reads every computer container's state from docker and records it
|
||||
* (`refreshComputerContainer`), telling owners about changes. Containers
|
||||
* still being set up, or that failed, are left alone.
|
||||
* still being set up, or that failed, are left alone. A container that
|
||||
* still mounts its computer's whole home is recreated with only the
|
||||
* workspace (`migrateComputerLayout`, once per computer).
|
||||
*/
|
||||
export default async function syncComputers() {
|
||||
const rows =
|
||||
(
|
||||
await BunSQLite.sql<Row>({
|
||||
sql: `SELECT co.id, co.docker_id, co.status, co.ip_address, c.id AS computer_id
|
||||
sql: `SELECT co.id, co.docker_id, co.status, co.ip_address, co.metadata, c.id AS computer_id
|
||||
FROM containers co JOIN computers c ON c.container_id = co.id
|
||||
WHERE co.docker_id IS NOT NULL AND co.status NOT IN ('creating', 'failed')`,
|
||||
})
|
||||
@@ -25,7 +28,9 @@ export default async function syncComputers() {
|
||||
|
||||
let changed = 0;
|
||||
|
||||
for (const { computer_id, ...container } of rows) {
|
||||
for (const { computer_id, metadata, ...container } of rows) {
|
||||
if (await migrateComputerLayout({ computer_id, metadata })) continue;
|
||||
|
||||
const refreshed = await refreshComputerContainer({
|
||||
computer_id,
|
||||
container,
|
||||
|
||||
Reference in New Issue
Block a user