Add bot types with a permission matrix, and workspace admin bots

A bot's powers came from bots.kind alone, so only the coordinator could
hand work to other bots. bot_types now works like user_types: a row with
no workspace holds everywhere (the coordinator), one with a workspace
only there (a workspace admin), and no row is a worker. bots.kind stays
the legacy marker of the one coordinator for who sees it.

The matrices in src/dict/bot-types-dict.ts say what each type may do,
whom it may direct and who grants it, read by one generic interpreter
(rbac/type-assignment.ts) that userTypeAssignment now wraps too. Every
run reads its powers once (grabBotRunPowers) and the chat tools, task
runs and task tools gate on them instead of kind; a run's powers are its
type's and its user's together.

In the workspace it leads, an admin hands tasks to the workers there
(results relayed back to it), sets their instructions, adds tasks to
their lists and keeps the workspace's context when its user may. Super
admins and admins grant it from the workspace's settings or the chat
header's menu, and the coordinator with set_bot_type. Admins are marked
with a filled green shield beside their name across the workspace, kept
live by pushBotUpdated's admin_workspace_ids.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2026-10-25 09:04:14 +01:00
co-authored by Claude Opus 5.5
parent 4161863587
commit ea62dd11f0
65 changed files with 1970 additions and 239 deletions
+28 -8
View File
@@ -9,8 +9,12 @@ import {
CoordinatorSoloNote,
TasksNote,
TaskReminderNote,
workspaceAdminNote,
WorkspaceLearningNote,
} from "@/src/data/harness-prompts";
import grabBotRunPowers from "@/src/functions/backend/db/bot-types/grab-bot-run-powers";
import workspaceAdminsNote from "./workspace-admins-note";
import type { WorkspaceAdminTools } from "@/src/harness/tools/bot/grab-workspace-admin-tools";
import { grabReplyMaxToolSteps } from "@/src/functions/backend/db/app-settings/grab-run-limits";
import grabBotMessages from "@/src/functions/backend/db/bots/grab-bot-messages";
import grabBotPrompt from "@/src/functions/backend/db/bots/grab-bot-prompt";
@@ -158,8 +162,16 @@ export default async function runBotReply({
onAttach: ({ media_id }) => attachments.push(media_id),
});
/**
* What the bot's types let it do here, and what it leads when it's this
* workspace's admin.
*/
const powers = await grabBotRunPowers({ bot_id: bot.id, workspace_id });
let led: WorkspaceAdminTools | null = null;
const tools = await grabBotChatTools({
bot,
powers,
user_id,
computers,
session_id,
@@ -168,6 +180,9 @@ export default async function runBotReply({
message_id: job.message_id || undefined,
onTakeOver: ({ ref }) => take_overs.push(ref),
onPropose: ({ ref }) => proposals.push(ref),
onWorkspaceAdmin: (admin) => {
led = admin;
},
});
/**
@@ -193,14 +208,19 @@ export default async function runBotReply({
});
/**
* delegate_task is only there while the coordinator has workers.
* delegate_task is only there while the coordinator, or a workspace's
* admin, has bots to hand work to. Anyone else in a workspace with an
* admin is told who leads it.
*/
const crew_note =
bot.kind != "coordinator"
? ""
: tools.some((tool) => tool.name == "delegate_task")
? coordinatorReplyNote({ bot_id: bot.id })
: CoordinatorSoloNote;
const can_delegate = tools.some((tool) => tool.name == "delegate_task");
const lead = led as WorkspaceAdminTools | null;
const crew_note = powers.is_coordinator
? can_delegate
? coordinatorReplyNote({ bot_id: bot.id })
: CoordinatorSoloNote
: lead?.workspace && can_delegate
? workspaceAdminNote({ workspace_name: lead.workspace.name || "this workspace", members: lead.members })
: await workspaceAdminsNote({ bot_id: bot.id, workspace_id });
try {
const result = await runTextLoop({
@@ -216,7 +236,7 @@ export default async function runBotReply({
workspace_id ? WorkspaceLearningNote : "",
composeComputersNote({
computers,
is_coordinator: bot.kind == "coordinator",
is_coordinator: powers.is_coordinator,
in_workspace: Boolean(workspace_id),
}),
crew_note,