Add workspaces, conversation sessions, app-managed computers and pictures

- Rail: Add icon with stacked form modals (bot, workspace, computer),
  coordinator, recent bots with "See all bots", Workspaces section, and
  a workspace mode listing only its crew
- Workspaces: page for context, bots (per-workspace instructions and
  memory), computers (default, link, unlink), models and delete;
  conversations scoped per bot per workspace
- Sessions: conversations split into searchable, reopenable sessions
  with carry-over summaries; sessions and new-session header icons
- Computers: created and provisioned over the docker socket, home dir
  kept at DATA_DIR/computers/<id> after delete; super admins only
- Models: workspace settings win over a bot's own, then the defaults
- Pictures for bots and workspaces; bots editable from the header
- Coordinator tools: update_workspace, set_bot_workspace_instructions

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2026-10-19 08:39:33 +01:00
co-authored by Claude Opus 5.5
parent 56daf0c462
commit 0ce61cdb49
223 changed files with 8166 additions and 585 deletions
+17 -6
View File
@@ -10,6 +10,11 @@ type Params = {
* The coordinator can use every computer and give the crew access.
*/
is_coordinator?: boolean;
/**
* In a workspace the computers are the workspace's, and its default
* is where tasks run.
*/
in_workspace?: boolean;
};
/**
@@ -17,9 +22,11 @@ type Params = {
* one it's on, and how it reaches them (markdown). Without it a bot asked
* "can you see the computer?" says it can't.
*/
export default function composeComputersNote({ computers, is_coordinator }: Params) {
export default function composeComputersNote({ computers, is_coordinator, in_workspace }: Params) {
if (!computers.length) {
return `# Your computers\n\nYou have no computer, so you can't run commands, open files or browse. If the user asks for that, say so.`;
return in_workspace
? `# Your computers\n\nThis workspace has no computer, so you can't run commands, open files or browse here. If the user asks for that, say so: they can add a computer to the workspace and set it as its default.`
: `# Your computers\n\nYou have no computer, so you can't run commands, open files or browse. If the user asks for that, say so.`;
}
const listed = computers
@@ -38,10 +45,14 @@ export default function composeComputersNote({ computers, is_coordinator }: Para
${listed}
Each is a Linux sandbox of your own (a shell, files, code runners and a browser), set up for the crew. It isn't the user's desktop: you can't see their screen or their own files unless they're put on it. The user picks which one you're on; your tasks run there.${
is_coordinator
? ` As the coordinator you can use every computer the user has, and you decide which ones each crew member can use with assign_computer.`
: ""
Each is a Linux sandbox of your own (a shell, files, code runners and a browser), set up for the crew. It isn't the user's desktop: you can't see their screen or their own files unless they're put on it. ${
in_workspace
? `These are this workspace's computers. Its tasks run on the default one (the first, "you're on it"); you can switch the default with set_workspace_computer when the work needs another.`
: `The user picks which one you're on; your tasks run there.${
is_coordinator
? ` As the coordinator you can use every computer the user has, and you decide which ones each crew member can use with assign_computer.`
: ""
}`
}
- To find which computer holds something (a file, a running app, a logged-in session), use search_computers: it runs one read-only command on all of them at once.
+71
View File
@@ -0,0 +1,71 @@
import BunSQLite from "@moduletrace/bun-sqlite";
import type { BUN_SQLITE_COBBLE_BOT_SESSIONS } from "@/db/types/db";
import { AppData } from "@/src/data/app-data";
import { PreviousSessionNote, SessionSummaryPrompt } from "@/src/data/harness-prompts";
import grabBotMessages from "@/src/functions/backend/db/bots/grab-bot-messages";
import generateText from "@/src/harness/text/generate-text";
type Params = {
session_id: number | string;
bot_id: number | string;
workspace_id?: number | string | null;
signal?: AbortSignal;
};
/**
* The previous session's summary for a session's prompt (markdown), or ""
* when it doesn't carry on from one. The summary is written the first
* time it's needed and kept on that session.
*/
export default async function grabSessionCarryOver({
session_id,
bot_id,
workspace_id,
signal,
}: Params) {
const previous = (
await BunSQLite.sql<BUN_SQLITE_COBBLE_BOT_SESSIONS>({
sql: `SELECT p.* FROM bot_sessions s JOIN bot_sessions p ON p.id = s.previous_session_id
WHERE s.id = ? AND p.bot_id = s.bot_id LIMIT 1`,
values: [session_id],
})
).payload?.[0];
if (!previous?.id) return "";
if (previous.summary?.trim()) {
return `${PreviousSessionNote}\n\n${previous.summary.trim()}`;
}
const messages = await grabBotMessages({
session_id: previous.id,
limit: AppData.BotSessionSummaryMessages,
});
if (!messages.length) return "";
const transcript = messages
.map((message) => `${message.author == "user" ? "User" : "You"}: ${message.text || "(files only)"}`)
.join("\n\n");
const result = await generateText({
messages: [
{ role: "system", content: SessionSummaryPrompt },
{ role: "user", content: transcript },
],
bot_id,
workspace_id,
signal,
});
const summary = (result.text || "").trim().slice(0, AppData.BotSessionSummaryMaxChars);
if (!summary) return "";
await BunSQLite.sql({
sql: `UPDATE bot_sessions SET summary = ?, updated_at = ? WHERE id = ?`,
values: [summary, Date.now(), previous.id],
});
return `${PreviousSessionNote}\n\n${summary}`;
}
+5 -1
View File
@@ -84,7 +84,11 @@ export default async function processBotJob({
bot_id,
data: {
event: "server:bot-job-update",
data: { ...row, task_id: job.task_id || null } satisfies BotJobUpdateData,
data: {
...row,
task_id: job.task_id || null,
session_id: job.session_id || null,
} satisfies BotJobUpdateData,
},
});
} catch (error) {
+43 -10
View File
@@ -1,6 +1,11 @@
import type { BUN_SQLITE_COBBLE_BOTS } from "@/db/types/db";
import { AppData } from "@/src/data/app-data";
import { ChatReplyNote, CoordinatorReplyNote, CoordinatorSoloNote } from "@/src/data/harness-prompts";
import {
ChatReplyNote,
CoordinatorReplyNote,
CoordinatorSoloNote,
WorkspaceLearningNote,
} from "@/src/data/harness-prompts";
import grabBotMessages from "@/src/functions/backend/db/bots/grab-bot-messages";
import grabBotPrompt from "@/src/functions/backend/db/bots/grab-bot-prompt";
import grabBotComputers from "@/src/functions/backend/db/computers/grab-bot-computers";
@@ -8,6 +13,8 @@ import runTextLoop from "@/src/harness/text/run-text-loop";
import grabBotChatTools from "@/src/harness/tools/bot/grab-bot-chat-tools";
import botMessagesToHarness from "./bot-messages-to-harness";
import composeComputersNote from "./compose-computers-note";
import grabSessionCarryOver from "./grab-session-carry-over";
import jobSessionId from "@/src/functions/backend/db/bots-queue/job-session-id";
import loadAttachmentParts from "./load-attachment-parts";
import withTakeOverRefs from "./with-take-over-refs";
import type { BotJobContext, BotJobOutcome } from "./types";
@@ -17,11 +24,14 @@ type Params = BotJobContext & {
};
/**
* Answers the user in chat: the bot reads the recent conversation (and
* the files of the latest messages, `loadAttachmentParts`) and
* replies, knowing its computers (`composeComputersNote`), with its chat tools (memory, instructions, start_task, and for
* the coordinator delegate_task). Finishes silently when the last message
* is already the bot's, i.e. an earlier reply answered everything.
* Answers the user in chat: the bot reads the session's recent messages
* (and the files of the latest ones, `loadAttachmentParts`) and replies,
* knowing where it is (its workspace, if the session is in one), what
* happened in the session before (`grabSessionCarryOver`) and its
* computers (`composeComputersNote`), with its chat tools (memory,
* instructions, start_task, and for the coordinator delegate_task).
* Finishes silently when the last message is already the bot's, i.e. an
* earlier reply answered everything.
*/
export default async function runBotReply({
bot,
@@ -29,8 +39,11 @@ export default async function runBotReply({
signal,
report,
}: Params): Promise<BotJobOutcome> {
const session_id = await jobSessionId({ job });
const workspace_id = job.workspace_id || null;
const history = await grabBotMessages({
bot_id: bot.id,
session_id,
limit: AppData.BotReplyHistoryMessages,
});
@@ -38,8 +51,19 @@ export default async function runBotReply({
return { result: "", silent: true };
}
const prompt = await grabBotPrompt({ bot_id: bot.id, user_id: bot.user_id });
const computers = await grabBotComputers({ bot_id: bot.id, user_id: bot.user_id });
const prompt = await grabBotPrompt({ bot_id: bot.id, user_id: bot.user_id, workspace_id });
const computers = await grabBotComputers({ bot_id: bot.id, user_id: bot.user_id, workspace_id });
/**
* A summary that can't be written now (no model free) is left out
* rather than holding up the reply.
*/
const carry_over = await grabSessionCarryOver({
session_id,
bot_id: bot.id,
workspace_id,
signal,
}).catch(() => "");
const take_overs: string[] = [];
@@ -47,6 +71,8 @@ export default async function runBotReply({
bot,
user_id: bot.user_id,
computers,
session_id,
workspace_id,
message_id: job.message_id || undefined,
onTakeOver: ({ ref }) => take_overs.push(ref),
});
@@ -64,8 +90,14 @@ export default async function runBotReply({
const result = await runTextLoop({
system: [
prompt,
carry_over,
ChatReplyNote,
composeComputersNote({ computers, is_coordinator: bot.kind == "coordinator" }),
workspace_id ? WorkspaceLearningNote : "",
composeComputersNote({
computers,
is_coordinator: bot.kind == "coordinator",
in_workspace: Boolean(workspace_id),
}),
crew_note,
`Now: ${new Date().toUTCString()}.`,
]
@@ -78,6 +110,7 @@ export default async function runBotReply({
tools,
max_steps: AppData.BotReplyMaxToolSteps,
bot_id: bot.id,
workspace_id,
signal,
onStep: report,
});
+30 -8
View File
@@ -1,4 +1,4 @@
import { TaskRunNote } from "@/src/data/harness-prompts";
import { TaskRunNote, WorkspaceLearningNote } from "@/src/data/harness-prompts";
import grabBotComputers from "@/src/functions/backend/db/computers/grab-bot-computers";
import grabBotPrompt from "@/src/functions/backend/db/bots/grab-bot-prompt";
import runTextLoop from "@/src/harness/text/run-text-loop";
@@ -8,6 +8,8 @@ import askToTakeOverTool from "@/src/harness/tools/computer/ask-to-take-over-too
import searchComputersTool from "@/src/harness/tools/computer/search-computers-tool";
import computerRef from "@/src/utils/computer-ref";
import composeJobBrief from "./compose-job-brief";
import grabSessionCarryOver from "./grab-session-carry-over";
import jobSessionId from "@/src/functions/backend/db/bots-queue/job-session-id";
import withTakeOverRefs from "./with-take-over-refs";
import type { BotJobContext, BotJobOutcome } from "./types";
@@ -16,7 +18,8 @@ type Params = BotJobContext & {
};
/**
* Works through a task: the bot follows its brief with its full prompt,
* Works through a task in its session's workspace (if any): the bot
* follows its brief with its full prompt,
* its own tools, search_computers across all its computers and, when the
* job has a computer, that computer's tools (over MCP), until it answers. That answer is the report for the user.
* When only the user can go on (a login, a captcha), the bot asks them to
@@ -30,13 +33,27 @@ export default async function runBotTask({
signal,
report,
}: Params): Promise<BotJobOutcome> {
const workspace_id = job.workspace_id || null;
const computer = job.computer_id
? await openComputerTools({ computer_id: job.computer_id, bot_id: bot.id, signal })
? await openComputerTools({
computer_id: job.computer_id,
bot_id: bot.id,
workspace_id,
signal,
})
: null;
try {
const prompt = await grabBotPrompt({ bot_id: bot.id, user_id: bot.user_id });
const computers = await grabBotComputers({ bot_id: bot.id, user_id: bot.user_id });
const session_id = await jobSessionId({ job });
const prompt = await grabBotPrompt({ bot_id: bot.id, user_id: bot.user_id, workspace_id });
const computers = await grabBotComputers({ bot_id: bot.id, user_id: bot.user_id, workspace_id });
const carry_over = await grabSessionCarryOver({
session_id,
bot_id: bot.id,
workspace_id,
signal,
}).catch(() => "");
const take_overs: string[] = [];
/**
@@ -50,10 +67,14 @@ export default async function runBotTask({
const result = await runTextLoop({
system: [
prompt,
carry_over,
TaskRunNote,
workspace_id ? WorkspaceLearningNote : "",
computer
? `You're working on the computer "${computer.name}" (a Linux sandbox with a shell, files, code runners and a browser). Use its tools; don't ask the user to run anything. When only the user can go on (a login, a captcha, a code sent to them), ask them to take over with ask_user_to_take_over.`
: `You have no computer for this task.`,
: workspace_id
? `You have no computer for this task: this workspace has none. If the task needs one, stop and say so in the report; the user can add a computer to the workspace.`
: `You have no computer for this task.`,
computers.length > 1
? `search_computers runs a read-only command on every computer you have. When you name one in the report, write its ref, e.g. ${computerRef({ id: computers[0]!.id || 0 })}: the user can click it to switch you to that computer.`
: "",
@@ -76,10 +97,10 @@ export default async function runBotTask({
},
],
tools: [
...grabBotTools({ user_id: bot.user_id, bot_id: bot.id }),
...grabBotTools({ user_id: bot.user_id, bot_id: bot.id, workspace_id, computers }),
...(computers.length
? [
searchComputersTool({ bot_id: bot.id, computers }),
searchComputersTool({ computers, workspace_id }),
askToTakeOverTool({
computers: take_over_computers,
in_task: true,
@@ -90,6 +111,7 @@ export default async function runBotTask({
...(computer?.tools || []),
],
bot_id: bot.id,
workspace_id,
signal,
onStep: (step) =>
report({ ...step, text: step.text && computer ? computer.redact(step.text) : step.text }),