Share one crew across the install, keep user memory per user

Bots, workspaces and computers now belong to the install. Users reach
workers only through bot_users (assigned by a super admin or admin) and
workspace_users; the coordinator and main computer are one per install,
and only the super admin sees the coordinator. Conversations are per
user (bot_sessions.user_id), jobs run for the session's user, and live
updates go only to who should see them.

A bot's core memory is now general knowledge shared by every user it
works for; what it learns about a user lives in bot_user_memories.

One-off scripts move existing installs over: move-bot-memory-to-owners
(run first), then share-crew.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2026-10-19 11:37:14 +01:00
co-authored by Claude Opus 5.5
parent 4dd34ed251
commit e45d54d30b
133 changed files with 1854 additions and 436 deletions
+27 -11
View File
@@ -1,27 +1,38 @@
import { z } from "zod";
import { AppData } from "@/src/data/app-data";
import updateBotMemory from "@/src/functions/backend/db/bots/update-bot-memory";
import updateBotUserMemory from "@/src/functions/backend/db/bots/update-bot-user-memory";
import updateWorkspaceBot from "@/src/functions/backend/db/workspaces/update-workspace-bot";
import type { HarnessTool } from "../../types";
type Params = {
/**
* The user the run is for: `user` memory is theirs alone.
*/
user_id: number | string;
bot_id: number | string;
/**
* The workspace the run is in: then the bot rewrites its memory for
* the workspace unless it picks `core`.
* the workspace unless it picks another scope.
*/
workspace_id?: number | string | null;
};
type Args = {
memory: string;
scope?: "workspace" | "core";
scope?: "user" | "workspace" | "core";
};
const UserScopeNote = `what you remember about this user, under "# Memory about the user": their preferences, facts about them and their work, decisions they made. Only runs for this user see it.`;
const CoreScopeNote = `scope "core" is your core memory, under "# Memory", shared with every user you work for: only general knowledge about your job that holds for anyone, never anything about a particular user.`;
const ReplaceNote = `Anything you leave out is forgotten, so include the parts that still matter.`;
/**
* Lets a bot rewrite its own memory: its core memory (under `# Memory`),
* or in a workspace (by default) its memory for that workspace.
* Lets a bot rewrite one of its memories: about the user it works for
* (the default outside a workspace), for the workspace (the default in
* one), or its core memory, shared by every user.
*/
export default function updateMemoryTool({
user_id,
@@ -33,19 +44,24 @@ export default function updateMemoryTool({
return {
name: "update_memory",
description: workspace_id
? `Replace a memory with this full text (markdown). scope "workspace" (the default) is your memory for this workspace, under "# Memory in ..."; "core" is your core memory, under "# Memory", in every workspace and your own chat. Keep what you must always remember: the user's preferences, facts about their work, decisions made. Anything you leave out is forgotten, so include the parts that still matter.`
: `Replace your memory with this full text (markdown). It's in your prompt under "# Memory" on every run. Keep what you must always remember: the user's preferences, facts about their work, decisions made. Anything you leave out is forgotten, so include the parts that still matter.`,
? `Replace a memory with this full text (markdown). scope "workspace" (the default) is your memory for this workspace, under "# Memory in ...": what holds for the work here. scope "user" is ${UserScopeNote} ${CoreScopeNote} ${ReplaceNote}`
: `Replace a memory with this full text (markdown). scope "user" (the default) is ${UserScopeNote} ${CoreScopeNote} ${ReplaceNote}`,
schema: workspace_id
? z.object({ memory, scope: z.enum(["workspace", "core"]).default("workspace") })
: z.object({ memory }),
? z.object({ memory, scope: z.enum(["workspace", "user", "core"]).default("workspace") })
: z.object({ memory, scope: z.enum(["user", "core"]).default("user") }),
run: async ({ args }) => {
if (workspace_id && args.scope != "core") {
if (args.scope == "core") {
await updateBotMemory({ user_id, bot_id, memory: args.memory });
return `Core memory saved.`;
}
if (workspace_id && args.scope == "workspace") {
await updateWorkspaceBot({ user_id, workspace_id, bot_id, memory: args.memory });
return `Memory for this workspace saved.`;
}
await updateBotMemory({ user_id, bot_id, memory: args.memory });
return `Core memory saved.`;
await updateBotUserMemory({ user_id, bot_id, memory: args.memory });
return `Memory about the user saved.`;
},
};
}