Open-source AI coworkers that each get a computer of their own: a browser, files and tools, with every action decided before it happens and recorded after. Bring any AG-UI agent.
Let a person set standing instructions that every coworker follows (#335)
Nick Launchesb8243012864e
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 255e23d0..dc2a0ad5 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -8,6 +8,22 @@ Newest first. `Unreleased` is what is on `main` and not yet tagged.## Unreleased+### A person can set standing instructions that every coworker follows++Settings now has a box for standing instructions: one piece of text per person, saved once and+spliced into every built-in coworker's prompt, in every channel, on every run, including the runs a+routine starts overnight. It is the place for what is true of every task rather than of any one of+them, such as how somebody wants to be written to or what their company is and is not to be called.+A coworker's role still decides what it does; these decide how it does it, and the prompt says so,+so an instruction cannot quietly redefine what a coworker is for.++Instructions belong to the person who wrote them. Nobody, administrators included, can read or set+somebody else's, and they are deleted with the account. A coworker running at a remote AG-UI+endpoint is not sent them, since this deployment does not compose that prompt. Nothing is added to+any prompt until somebody writes something, so a deployment where nobody uses this behaves exactly+as before.++This adds migration `0026_user_instructions`, which creates one table.### The trail says who a coworker was opened toMaking a coworker public admits every signed-in person to it, and being admitted to a coworker isdiff --git a/app/src/components/settings/standing-instructions.tsx b/app/src/components/settings/standing-instructions.tsxnew file mode 100644index 00000000..c4ea2c32--- /dev/null+++ b/app/src/components/settings/standing-instructions.tsx@@ -0,0 +1,115 @@+import { useMutation, useQuery } from "@tanstack/react-query";+import { useEffect, useState } from "react";+import { PageSection } from "@/components/layout/page-shell";+import { Button } from "@/components/ui/button";+import { Textarea } from "@/components/ui/textarea";+import { saveInstructionsMutationOptions } from "@/lib/settings/mutations";+import {+ INSTRUCTIONS_LIMIT,+ instructionsQueryOptions,+} from "@/lib/settings/queries";+import { queryClient } from "@/query-client";++/**+ * One box, applied to every coworker in every channel.+ *+ * WHAT IT IS FOR, said on the screen rather than left to be guessed. A coworker's role and this are+ * both durable instructions and a person meeting them for the first time has no reason to know which+ * belongs where, so the description draws the line the prompt draws: the role says what a coworker+ * is for, this says how the person wants things done. Without that sentence the obvious mistake is+ * to write a job description here and get it applied to every coworker at once.+ */+export function StandingInstructions() {+ const stored = useQuery(instructionsQueryOptions());+ const save = useMutation(saveInstructionsMutationOptions(queryClient));++ const [draft, setDraft] = useState<string | null>(null);+ const [problem, setProblem] = useState<string | null>(null);+ const [saved, setSaved] = useState(false);++ /*+ * The box holds the stored text until somebody types, and their typing after that.+ *+ * Null is "has not been edited", which is not the same as "is empty": seeding the state with ""+ * and then filling it in when the read lands would overwrite whatever they had already started+ * typing into a box that was ready before the network was.+ */+ useEffect(() => {+ if (stored.data !== undefined && draft === null) setDraft(stored.data);+ }, [stored.data, draft]);++ const text = draft ?? stored.data ?? "";+ const over = text.trim().length > INSTRUCTIONS_LIMIT;+ const unchanged = stored.data !== undefined && text === stored.data;++ const submit = () => {+ setProblem(null);+ setSaved(false);+ save.mutate(text, {+ onError: (thrown: Error) => setProblem(thrown.message),+ /* The server trims, so the box settles to what was actually stored rather than what was sent. */+ onSuccess: (asStored) => {+ setDraft(asStored);+ setSaved(true);+ },+ });+ };++ return (+ <PageSection+ description="Applies to every coworker in every channel. Your role text on a coworker says what it does; this says how you want things done, for example writing style or how to describe your company."+ title="Standing instructions"+ >+ {stored.isPending ? null : stored.error ? (+ <p className="mt-4 text-destructive text-sm" role="alert">+ {stored.error.message}+ </p>+ ) : (+ <div className="mt-4 flex flex-col gap-2">+ <Textarea+ aria-label="Standing instructions"+ className="min-h-40"+ disabled={save.isPending}+ onChange={(event) => {+ setDraft(event.target.value);+ setSaved(false);+ }}+ placeholder="We are two people, not a team. Write in British English, and never call our product a platform."+ value={text}+ />+ <div className="flex flex-row items-center justify-between gap-4">+ <p+ className={+ over+ ? "text-destructive text-xs"+ : "text-muted-foreground text-xs"+ }+ >+ {text.trim().length} of {INSTRUCTIONS_LIMIT} characters+ </p>+ <div className="flex flex-row items-center gap-3">+ {/*+ * One line, and only the news. A save that worked says so until the next keystroke; a+ * refusal shows the server's own sentence, which names what was wrong with it.+ */}+ {problem ? (+ <span className="text-destructive text-xs" role="alert">+ {problem}+ </span>+ ) : saved ? (+ <span className="text-muted-foreground text-xs">Saved</span>+ ) : null}+ <Button+ disabled={save.isPending || over || unchanged}+ onClick={submit}+ size="sm"+ >+ Save+ </Button>+ </div>+ </div>+ </div>+ )}+ </PageSection>+ );+}diff --git a/app/src/lib/settings/mutations.ts b/app/src/lib/settings/mutations.tsnew file mode 100644index 00000000..0febef9c--- /dev/null+++ b/app/src/lib/settings/mutations.ts@@ -0,0 +1,24 @@+import { mutationOptions, type QueryClient } from "@tanstack/react-query";+import { client } from "@/lib/client";+import { settingsKeys } from "./queries";++/**+ * Save, or clear by saving nothing.+ *+ * A PUT of the whole text rather than a patch, because there is one field and its new value is the+ * whole of what changed. What comes back is what was stored — the server trims — so the cache is+ * seeded from the reply rather than from what was sent, and a box that had trailing whitespace in it+ * settles to what the database actually holds.+ */+export function saveInstructionsMutationOptions(queryClient: QueryClient) {+ return mutationOptions({+ mutationFn: (instructions: string): Promise<string> =>+ client("/api/settings/instructions", "instructions", {+ method: "PUT",+ body: { instructions },+ fallback: "Your standing instructions could not be saved",+ }),+ onSuccess: (saved) =>+ queryClient.setQueryData(settingsKeys.instructions(), saved),+ });+}diff --git a/app/src/lib/settings/queries.ts b/app/src/lib/settings/queries.tsnew file mode 100644index 00000000..e6bf1a75--- /dev/null+++ b/app/src/lib/settings/queries.ts@@ -0,0 +1,28 @@+import { queryOptions } from "@tanstack/react-query";+import { client } from "@/lib/client";++/**+ * How much one person may say, in characters.+ *+ * The server owns this rule and refuses past it; this copy exists so the box can count down rather+ * than let somebody write four paragraphs and find out on save. A drift between the two therefore+ * shows up as a refusal with the server's own sentence on it, which is the safe direction for a+ * duplicated number to fail in.+ */+export const INSTRUCTIONS_LIMIT = 4000;++export const settingsKeys = {+ all: ["settings"] as const,+ instructions: () => [...settingsKeys.all, "instructions"] as const,+};++/** "" means this person has written none. There is no separate absent state to draw. */+export function instructionsQueryOptions() {+ return queryOptions({+ queryKey: settingsKeys.instructions(),+ queryFn: async (): Promise<string> =>+ client("/api/settings/instructions", "instructions", {+ fallback: "Could not load your standing instructions",+ }),+ });+}diff --git a/app/src/routes/_authed/settings/index.tsx b/app/src/routes/_authed/settings/index.tsxindex 2fba05d2..46d0a549 100644--- a/app/src/routes/_authed/settings/index.tsx+++ b/app/src/routes/_authed/settings/index.tsx@@ -5,6 +5,7 @@ import {PageSection,PageShell,} from "@/components/layout/page-shell";+import { StandingInstructions } from "@/components/settings/standing-instructions";import { useTheme } from "@/components/theme-provider";import {Item,@@ -56,6 +57,11 @@ function RouteComponent() {</Item></PageRows></PageSection>+ {/*+ * Above the shortcuts and below the appearance switch, because it is the only thing on this+ * screen that changes what a coworker says rather than what this browser looks like.+ */}+ <StandingInstructions />{/** Drawn from the same registry the listeners match against, so this list is what the keys* actually do rather than what somebody remembered they did. Read-only on purpose: thesediff --git a/server/drizzle/0027_user_instructions.sql b/server/drizzle/0027_user_instructions.sqlnew file mode 100644index 00000000..1aef72bb--- /dev/null+++ b/server/drizzle/0027_user_instructions.sql@@ -0,0 +1,8 @@+CREATE TABLE "user_instructions" (+ "user_id" text PRIMARY KEY NOT NULL,+ "instructions" text NOT NULL,+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,+ "updated_at" timestamp with time zone DEFAULT now() NOT NULL+);+--> statement-breakpoint+ALTER TABLE "user_instructions" ADD CONSTRAINT "user_instructions_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;\ No newline at end of filediff --git a/server/drizzle/meta/0027_snapshot.json b/server/drizzle/meta/0027_snapshot.jsonnew file mode 100644index 00000000..c48f319e--- /dev/null+++ b/server/drizzle/meta/0027_snapshot.json@@ -0,0 +1,3101 @@+{+ "id": "c98643b6-c5da-420f-82b7-ea9b94eb0b06",+ "prevId": "fb3704b5-21f5-4d73-a80d-88fad27b6b85",+ "version": "7",+ "dialect": "postgresql",+ "tables": {+ "public.accounts": {+ "name": "accounts",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true+ },+ "account_id": {+ "name": "account_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "provider_id": {+ "name": "provider_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "issuer": {+ "name": "issuer",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "user_id": {+ "name": "user_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "access_token": {+ "name": "access_token",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "refresh_token": {+ "name": "refresh_token",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "id_token": {+ "name": "id_token",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "access_token_expires_at": {+ "name": "access_token_expires_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": false+ },+ "refresh_token_expires_at": {+ "name": "refresh_token_expires_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": false+ },+ "scope": {+ "name": "scope",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "password": {+ "name": "password",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "created_at": {+ "name": "created_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {+ "accounts_provider_account_idx": {+ "name": "accounts_provider_account_idx",+ "columns": [+ {+ "expression": "provider_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "account_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": true,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "accounts_user_id_users_id_fk": {+ "name": "accounts_user_id_users_id_fk",+ "tableFrom": "accounts",+ "tableTo": "users",+ "columnsFrom": [+ "user_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.agents": {+ "name": "agents",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true+ },+ "name": {+ "name": "name",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "type": {+ "name": "type",+ "type": "agent_type",+ "typeSchema": "public",+ "primaryKey": false,+ "notNull": true+ },+ "configuration": {+ "name": "configuration",+ "type": "jsonb",+ "primaryKey": false,+ "notNull": true+ },+ "package_id": {+ "name": "package_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": false+ },+ "override": {+ "name": "override",+ "type": "jsonb",+ "primaryKey": false,+ "notNull": false+ },+ "created_at": {+ "name": "created_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {},+ "foreignKeys": {+ "agents_package_id_deployment_packages_id_fk": {+ "name": "agents_package_id_deployment_packages_id_fk",+ "tableFrom": "agents",+ "tableTo": "deployment_packages",+ "columnsFrom": [+ "package_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "set null",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.audit_events": {+ "name": "audit_events",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "uuid",+ "primaryKey": true,+ "notNull": true,+ "default": "gen_random_uuid()"+ },+ "actor_user_id": {+ "name": "actor_user_id",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "event_type": {+ "name": "event_type",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "target_type": {+ "name": "target_type",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "target_id": {+ "name": "target_id",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "payload": {+ "name": "payload",+ "type": "jsonb",+ "primaryKey": false,+ "notNull": true+ },+ "created_at": {+ "name": "created_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {+ "audit_events_created_at_idx": {+ "name": "audit_events_created_at_idx",+ "columns": [+ {+ "expression": "created_at",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "audit_events_type_time_idx": {+ "name": "audit_events_type_time_idx",+ "columns": [+ {+ "expression": "event_type",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "created_at",+ "isExpression": false,+ "asc": false,+ "nulls": "last"+ },+ {+ "expression": "id",+ "isExpression": false,+ "asc": false,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "audit_events_actor_time_idx": {+ "name": "audit_events_actor_time_idx",+ "columns": [+ {+ "expression": "actor_user_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "created_at",+ "isExpression": false,+ "asc": false,+ "nulls": "last"+ },+ {+ "expression": "id",+ "isExpression": false,+ "asc": false,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "audit_events_target_time_idx": {+ "name": "audit_events_target_time_idx",+ "columns": [+ {+ "expression": "target_type",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "target_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "created_at",+ "isExpression": false,+ "asc": false,+ "nulls": "last"+ },+ {+ "expression": "id",+ "isExpression": false,+ "asc": false,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {},+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.channel_agents": {+ "name": "channel_agents",+ "schema": "",+ "columns": {+ "channel_id": {+ "name": "channel_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "agent_id": {+ "name": "agent_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "created_at": {+ "name": "created_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {},+ "foreignKeys": {+ "channel_agents_channel_id_channels_id_fk": {+ "name": "channel_agents_channel_id_channels_id_fk",+ "tableFrom": "channel_agents",+ "tableTo": "channels",+ "columnsFrom": [+ "channel_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "channel_agents_agent_id_agents_id_fk": {+ "name": "channel_agents_agent_id_agents_id_fk",+ "tableFrom": "channel_agents",+ "tableTo": "agents",+ "columnsFrom": [+ "agent_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {+ "channel_agents_channel_id_agent_id_pk": {+ "name": "channel_agents_channel_id_agent_id_pk",+ "columns": [+ "channel_id",+ "agent_id"+ ]+ }+ },+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.channel_memberships": {+ "name": "channel_memberships",+ "schema": "",+ "columns": {+ "channel_id": {+ "name": "channel_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "user_id": {+ "name": "user_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "pinned_at": {+ "name": "pinned_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": false+ },+ "last_read_at": {+ "name": "last_read_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": false+ },+ "created_at": {+ "name": "created_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {},+ "foreignKeys": {+ "channel_memberships_channel_id_channels_id_fk": {+ "name": "channel_memberships_channel_id_channels_id_fk",+ "tableFrom": "channel_memberships",+ "tableTo": "channels",+ "columnsFrom": [+ "channel_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "channel_memberships_user_id_users_id_fk": {+ "name": "channel_memberships_user_id_users_id_fk",+ "tableFrom": "channel_memberships",+ "tableTo": "users",+ "columnsFrom": [+ "user_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {+ "channel_memberships_channel_id_user_id_pk": {+ "name": "channel_memberships_channel_id_user_id_pk",+ "columns": [+ "channel_id",+ "user_id"+ ]+ }+ },+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.channels": {+ "name": "channels",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true+ },+ "name": {+ "name": "name",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "description": {+ "name": "description",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "suggested_prompts": {+ "name": "suggested_prompts",+ "type": "text[]",+ "primaryKey": false,+ "notNull": true,+ "default": "'{}'"+ },+ "allowed_groups": {+ "name": "allowed_groups",+ "type": "text[]",+ "primaryKey": false,+ "notNull": true,+ "default": "'{}'"+ },+ "package_id": {+ "name": "package_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": false+ },+ "override": {+ "name": "override",+ "type": "jsonb",+ "primaryKey": false,+ "notNull": false+ },+ "summary": {+ "name": "summary",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "summary_at": {+ "name": "summary_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": false+ },+ "last_message": {+ "name": "last_message",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "last_message_at": {+ "name": "last_message_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": false+ },+ "last_message_agent_id": {+ "name": "last_message_agent_id",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "deleted_at": {+ "name": "deleted_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": false+ },+ "created_at": {+ "name": "created_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {+ "channels_recent_activity_idx": {+ "name": "channels_recent_activity_idx",+ "columns": [+ {+ "expression": "COALESCE(\"last_message_at\", \"created_at\") DESC",+ "asc": true,+ "isExpression": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "channels_awaiting_summary_idx": {+ "name": "channels_awaiting_summary_idx",+ "columns": [+ {+ "expression": "id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "where": "\"channels\".\"summary\" is null and \"channels\".\"deleted_at\" is null",+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "channels_package_id_deployment_packages_id_fk": {+ "name": "channels_package_id_deployment_packages_id_fk",+ "tableFrom": "channels",+ "tableTo": "deployment_packages",+ "columnsFrom": [+ "package_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "set null",+ "onUpdate": "no action"+ },+ "channels_last_message_agent_id_agents_id_fk": {+ "name": "channels_last_message_agent_id_agents_id_fk",+ "tableFrom": "channels",+ "tableTo": "agents",+ "columnsFrom": [+ "last_message_agent_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "set null",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.credentials": {+ "name": "credentials",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "uuid",+ "primaryKey": true,+ "notNull": true,+ "default": "gen_random_uuid()"+ },+ "kind": {+ "name": "kind",+ "type": "credential_kind",+ "typeSchema": "public",+ "primaryKey": false,+ "notNull": true+ },+ "provider": {+ "name": "provider",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "encrypted_value": {+ "name": "encrypted_value",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "key_id": {+ "name": "key_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "metadata": {+ "name": "metadata",+ "type": "jsonb",+ "primaryKey": false,+ "notNull": true+ },+ "revoked_at": {+ "name": "revoked_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": false+ },+ "created_at": {+ "name": "created_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {+ "credentials_active_key_idx": {+ "name": "credentials_active_key_idx",+ "columns": [+ {+ "expression": "kind",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "provider",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "key_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": true,+ "where": "\"credentials\".\"revoked_at\" IS NULL",+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {},+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.deployment_packages": {+ "name": "deployment_packages",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "uuid",+ "primaryKey": true,+ "notNull": true,+ "default": "gen_random_uuid()"+ },+ "tenant_id": {+ "name": "tenant_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "source_path": {+ "name": "source_path",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "checksum": {+ "name": "checksum",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "loaded_at": {+ "name": "loaded_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {},+ "foreignKeys": {},+ "compositePrimaryKeys": {},+ "uniqueConstraints": {+ "deployment_packages_tenant_id_unique": {+ "name": "deployment_packages_tenant_id_unique",+ "nullsNotDistinct": false,+ "columns": [+ "tenant_id"+ ]+ }+ },+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.intelligence_channel_mappings": {+ "name": "intelligence_channel_mappings",+ "schema": "",+ "columns": {+ "user_id": {+ "name": "user_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "channel_id": {+ "name": "channel_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "thread_id": {+ "name": "thread_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "created_at": {+ "name": "created_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {+ "intelligence_channel_mappings_thread_idx": {+ "name": "intelligence_channel_mappings_thread_idx",+ "columns": [+ {+ "expression": "thread_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": true,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "intelligence_channel_mappings_user_id_users_id_fk": {+ "name": "intelligence_channel_mappings_user_id_users_id_fk",+ "tableFrom": "intelligence_channel_mappings",+ "tableTo": "users",+ "columnsFrom": [+ "user_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "intelligence_channel_mappings_channel_id_channels_id_fk": {+ "name": "intelligence_channel_mappings_channel_id_channels_id_fk",+ "tableFrom": "intelligence_channel_mappings",+ "tableTo": "channels",+ "columnsFrom": [+ "channel_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {+ "intelligence_channel_mappings_user_id_channel_id_pk": {+ "name": "intelligence_channel_mappings_user_id_channel_id_pk",+ "columns": [+ "user_id",+ "channel_id"+ ]+ }+ },+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.revoked_access": {+ "name": "revoked_access",+ "schema": "",+ "columns": {+ "email": {+ "name": "email",+ "type": "text",+ "primaryKey": true,+ "notNull": true+ },+ "revoked_at": {+ "name": "revoked_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ },+ "revoked_by": {+ "name": "revoked_by",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ }+ },+ "indexes": {},+ "foreignKeys": {},+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.sessions": {+ "name": "sessions",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true+ },+ "user_id": {+ "name": "user_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "token": {+ "name": "token",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "expires_at": {+ "name": "expires_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true+ },+ "ip_address": {+ "name": "ip_address",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "user_agent": {+ "name": "user_agent",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "created_at": {+ "name": "created_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {},+ "foreignKeys": {+ "sessions_user_id_users_id_fk": {+ "name": "sessions_user_id_users_id_fk",+ "tableFrom": "sessions",+ "tableTo": "users",+ "columnsFrom": [+ "user_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {+ "sessions_token_unique": {+ "name": "sessions_token_unique",+ "nullsNotDistinct": false,+ "columns": [+ "token"+ ]+ }+ },+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.sso_providers": {+ "name": "sso_providers",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true+ },+ "issuer": {+ "name": "issuer",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "oidc_config": {+ "name": "oidc_config",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "saml_config": {+ "name": "saml_config",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "user_id": {+ "name": "user_id",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "provider_id": {+ "name": "provider_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "organization_id": {+ "name": "organization_id",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "domain": {+ "name": "domain",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ }+ },+ "indexes": {},+ "foreignKeys": {+ "sso_providers_user_id_users_id_fk": {+ "name": "sso_providers_user_id_users_id_fk",+ "tableFrom": "sso_providers",+ "tableTo": "users",+ "columnsFrom": [+ "user_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "set null",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {+ "sso_providers_provider_id_unique": {+ "name": "sso_providers_provider_id_unique",+ "nullsNotDistinct": false,+ "columns": [+ "provider_id"+ ]+ }+ },+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.user_instructions": {+ "name": "user_instructions",+ "schema": "",+ "columns": {+ "user_id": {+ "name": "user_id",+ "type": "text",+ "primaryKey": true,+ "notNull": true+ },+ "instructions": {+ "name": "instructions",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "created_at": {+ "name": "created_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {},+ "foreignKeys": {+ "user_instructions_user_id_users_id_fk": {+ "name": "user_instructions_user_id_users_id_fk",+ "tableFrom": "user_instructions",+ "tableTo": "users",+ "columnsFrom": [+ "user_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.user_roles": {+ "name": "user_roles",+ "schema": "",+ "columns": {+ "user_id": {+ "name": "user_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "role": {+ "name": "role",+ "type": "role",+ "typeSchema": "public",+ "primaryKey": false,+ "notNull": true+ },+ "created_at": {+ "name": "created_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {},+ "foreignKeys": {+ "user_roles_user_id_users_id_fk": {+ "name": "user_roles_user_id_users_id_fk",+ "tableFrom": "user_roles",+ "tableTo": "users",+ "columnsFrom": [+ "user_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {+ "user_roles_user_id_role_pk": {+ "name": "user_roles_user_id_role_pk",+ "columns": [+ "user_id",+ "role"+ ]+ }+ },+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.users": {+ "name": "users",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true+ },+ "email": {+ "name": "email",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "name": {+ "name": "name",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "image": {+ "name": "image",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "email_verified": {+ "name": "email_verified",+ "type": "boolean",+ "primaryKey": false,+ "notNull": true,+ "default": false+ },+ "groups": {+ "name": "groups",+ "type": "text[]",+ "primaryKey": false,+ "notNull": true,+ "default": "'{}'"+ },+ "onboarding_step": {+ "name": "onboarding_step",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "default": 0+ },+ "onboarding_completed_at": {+ "name": "onboarding_completed_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": false+ },+ "created_at": {+ "name": "created_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {},+ "foreignKeys": {},+ "compositePrimaryKeys": {},+ "uniqueConstraints": {+ "users_email_unique": {+ "name": "users_email_unique",+ "nullsNotDistinct": false,+ "columns": [+ "email"+ ]+ }+ },+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.verifications": {+ "name": "verifications",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true+ },+ "identifier": {+ "name": "identifier",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "value": {+ "name": "value",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "expires_at": {+ "name": "expires_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true+ },+ "created_at": {+ "name": "created_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {},+ "foreignKeys": {},+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.action_policy": {+ "name": "action_policy",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true+ },+ "mode": {+ "name": "mode",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "deny": {+ "name": "deny",+ "type": "text[]",+ "primaryKey": false,+ "notNull": true+ },+ "allow": {+ "name": "allow",+ "type": "text[]",+ "primaryKey": false,+ "notNull": true+ },+ "updated_by": {+ "name": "updated_by",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "updated_at": {+ "name": "updated_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {},+ "foreignKeys": {},+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.computer_page_frame": {+ "name": "computer_page_frame",+ "schema": "",+ "columns": {+ "computer_id": {+ "name": "computer_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "tool_call_id": {+ "name": "tool_call_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "url": {+ "name": "url",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "title": {+ "name": "title",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "frame": {+ "name": "frame",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "captured_at": {+ "name": "captured_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {+ "computer_page_frame_captured_idx": {+ "name": "computer_page_frame_captured_idx",+ "columns": [+ {+ "expression": "captured_at",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {},+ "compositePrimaryKeys": {+ "computer_page_frame_computer_id_tool_call_id_pk": {+ "name": "computer_page_frame_computer_id_tool_call_id_pk",+ "columns": [+ "computer_id",+ "tool_call_id"+ ]+ }+ },+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.computer_snapshot": {+ "name": "computer_snapshot",+ "schema": "",+ "columns": {+ "computer_id": {+ "name": "computer_id",+ "type": "text",+ "primaryKey": true,+ "notNull": true+ },+ "snapshot_id": {+ "name": "snapshot_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true+ },+ "url": {+ "name": "url",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "elements": {+ "name": "elements",+ "type": "jsonb",+ "primaryKey": false,+ "notNull": true+ },+ "taken_at": {+ "name": "taken_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ },+ "session": {+ "name": "session",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ }+ },+ "indexes": {},+ "foreignKeys": {},+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.agent_preferences": {+ "name": "agent_preferences",+ "schema": "",+ "columns": {+ "user_id": {+ "name": "user_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "agent_id": {+ "name": "agent_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "hidden_at": {+ "name": "hidden_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": false+ }+ },+ "indexes": {},+ "foreignKeys": {+ "agent_preferences_user_id_users_id_fk": {+ "name": "agent_preferences_user_id_users_id_fk",+ "tableFrom": "agent_preferences",+ "tableTo": "users",+ "columnsFrom": [+ "user_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "agent_preferences_agent_id_agents_id_fk": {+ "name": "agent_preferences_agent_id_agents_id_fk",+ "tableFrom": "agent_preferences",+ "tableTo": "agents",+ "columnsFrom": [+ "agent_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {+ "agent_preferences_user_id_agent_id_pk": {+ "name": "agent_preferences_user_id_agent_id_pk",+ "columns": [+ "user_id",+ "agent_id"+ ]+ }+ },+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.agent_profiles": {+ "name": "agent_profiles",+ "schema": "",+ "columns": {+ "agent_id": {+ "name": "agent_id",+ "type": "text",+ "primaryKey": true,+ "notNull": true+ },+ "owner_user_id": {+ "name": "owner_user_id",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "title": {+ "name": "title",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "role_description": {+ "name": "role_description",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "avatar_seed": {+ "name": "avatar_seed",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "visibility": {+ "name": "visibility",+ "type": "agent_visibility",+ "typeSchema": "public",+ "primaryKey": false,+ "notNull": true+ },+ "callback_token_hash": {+ "name": "callback_token_hash",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "callback_token_issued_at": {+ "name": "callback_token_issued_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": false+ },+ "deleted_at": {+ "name": "deleted_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": false+ },+ "created_at": {+ "name": "created_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {+ "agent_profiles_visibility_deleted_idx": {+ "name": "agent_profiles_visibility_deleted_idx",+ "columns": [+ {+ "expression": "visibility",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "deleted_at",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "agent_profiles_agent_id_agents_id_fk": {+ "name": "agent_profiles_agent_id_agents_id_fk",+ "tableFrom": "agent_profiles",+ "tableTo": "agents",+ "columnsFrom": [+ "agent_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "agent_profiles_owner_user_id_users_id_fk": {+ "name": "agent_profiles_owner_user_id_users_id_fk",+ "tableFrom": "agent_profiles",+ "tableTo": "users",+ "columnsFrom": [+ "owner_user_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "set null",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.routine_runs": {+ "name": "routine_runs",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true+ },+ "routine_id": {+ "name": "routine_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "started_at": {+ "name": "started_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ },+ "finished_at": {+ "name": "finished_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": false+ },+ "status": {+ "name": "status",+ "type": "routine_run_status",+ "typeSchema": "public",+ "primaryKey": false,+ "notNull": false+ },+ "error": {+ "name": "error",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ }+ },+ "indexes": {+ "routine_runs_by_routine_idx": {+ "name": "routine_runs_by_routine_idx",+ "columns": [+ {+ "expression": "routine_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "started_at",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "routine_runs_routine_id_routines_id_fk": {+ "name": "routine_runs_routine_id_routines_id_fk",+ "tableFrom": "routine_runs",+ "tableTo": "routines",+ "columnsFrom": [+ "routine_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.routines": {+ "name": "routines",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true+ },+ "owner_user_id": {+ "name": "owner_user_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "agent_id": {+ "name": "agent_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "channel_id": {+ "name": "channel_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "instruction": {+ "name": "instruction",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "cron": {+ "name": "cron",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "timezone": {+ "name": "timezone",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "'UTC'"+ },+ "enabled": {+ "name": "enabled",+ "type": "boolean",+ "primaryKey": false,+ "notNull": true,+ "default": true+ },+ "next_run_at": {+ "name": "next_run_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true+ },+ "last_run_at": {+ "name": "last_run_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": false+ },+ "created_at": {+ "name": "created_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {+ "routines_due_idx": {+ "name": "routines_due_idx",+ "columns": [+ {+ "expression": "enabled",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "next_run_at",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "routines_by_owner_idx": {+ "name": "routines_by_owner_idx",+ "columns": [+ {+ "expression": "owner_user_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "enabled",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "routines_owner_user_id_users_id_fk": {+ "name": "routines_owner_user_id_users_id_fk",+ "tableFrom": "routines",+ "tableTo": "users",+ "columnsFrom": [+ "owner_user_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "routines_agent_id_agents_id_fk": {+ "name": "routines_agent_id_agents_id_fk",+ "tableFrom": "routines",+ "tableTo": "agents",+ "columnsFrom": [+ "agent_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.component_exclusions": {+ "name": "component_exclusions",+ "schema": "",+ "columns": {+ "component_name": {+ "name": "component_name",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "agent_id": {+ "name": "agent_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "withheld_by": {+ "name": "withheld_by",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "created_at": {+ "name": "created_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {},+ "foreignKeys": {+ "component_exclusions_component_name_components_name_fk": {+ "name": "component_exclusions_component_name_components_name_fk",+ "tableFrom": "component_exclusions",+ "tableTo": "components",+ "columnsFrom": [+ "component_name"+ ],+ "columnsTo": [+ "name"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "component_exclusions_agent_id_agents_id_fk": {+ "name": "component_exclusions_agent_id_agents_id_fk",+ "tableFrom": "component_exclusions",+ "tableTo": "agents",+ "columnsFrom": [+ "agent_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {+ "component_exclusions_component_name_agent_id_pk": {+ "name": "component_exclusions_component_name_agent_id_pk",+ "columns": [+ "component_name",+ "agent_id"+ ]+ }+ },+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.component_functions": {+ "name": "component_functions",+ "schema": "",+ "columns": {+ "component_name": {+ "name": "component_name",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "function_name": {+ "name": "function_name",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "granted_by": {+ "name": "granted_by",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "created_at": {+ "name": "created_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {},+ "foreignKeys": {+ "component_functions_component_name_components_name_fk": {+ "name": "component_functions_component_name_components_name_fk",+ "tableFrom": "component_functions",+ "tableTo": "components",+ "columnsFrom": [+ "component_name"+ ],+ "columnsTo": [+ "name"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {+ "component_functions_component_name_function_name_pk": {+ "name": "component_functions_component_name_function_name_pk",+ "columns": [+ "component_name",+ "function_name"+ ]+ }+ },+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.components": {+ "name": "components",+ "schema": "",+ "columns": {+ "name": {+ "name": "name",+ "type": "text",+ "primaryKey": true,+ "notNull": true+ },+ "title": {+ "name": "title",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "kind": {+ "name": "kind",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "draft_description": {+ "name": "draft_description",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "published_description": {+ "name": "published_description",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "published": {+ "name": "published",+ "type": "boolean",+ "primaryKey": false,+ "notNull": true,+ "default": false+ },+ "published_at": {+ "name": "published_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": false+ },+ "updated_by": {+ "name": "updated_by",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "created_at": {+ "name": "created_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {},+ "foreignKeys": {},+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.mcp_servers": {+ "name": "mcp_servers",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true+ },+ "title": {+ "name": "title",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "vendor": {+ "name": "vendor",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "url": {+ "name": "url",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "provenance": {+ "name": "provenance",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "'first-party'"+ },+ "credential_id": {+ "name": "credential_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": false+ },+ "tools_refreshed_at": {+ "name": "tools_refreshed_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": false+ },+ "last_error": {+ "name": "last_error",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "added_by": {+ "name": "added_by",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "created_at": {+ "name": "created_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {},+ "foreignKeys": {+ "mcp_servers_credential_id_credentials_id_fk": {+ "name": "mcp_servers_credential_id_credentials_id_fk",+ "tableFrom": "mcp_servers",+ "tableTo": "credentials",+ "columnsFrom": [+ "credential_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "restrict",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.mcp_tools": {+ "name": "mcp_tools",+ "schema": "",+ "columns": {+ "server_id": {+ "name": "server_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "name": {+ "name": "name",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "description": {+ "name": "description",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "''"+ },+ "input_schema": {+ "name": "input_schema",+ "type": "jsonb",+ "primaryKey": false,+ "notNull": true,+ "default": "'{}'::jsonb"+ },+ "created_at": {+ "name": "created_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {},+ "foreignKeys": {+ "mcp_tools_server_id_mcp_servers_id_fk": {+ "name": "mcp_tools_server_id_mcp_servers_id_fk",+ "tableFrom": "mcp_tools",+ "tableTo": "mcp_servers",+ "columnsFrom": [+ "server_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {+ "mcp_tools_server_id_name_pk": {+ "name": "mcp_tools_server_id_name_pk",+ "columns": [+ "server_id",+ "name"+ ]+ }+ },+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.mcp_user_credentials": {+ "name": "mcp_user_credentials",+ "schema": "",+ "columns": {+ "server_id": {+ "name": "server_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "user_id": {+ "name": "user_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "credential_id": {+ "name": "credential_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": true+ },+ "scope": {+ "name": "scope",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "connected_at": {+ "name": "connected_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {+ "mcp_user_credentials_user_idx": {+ "name": "mcp_user_credentials_user_idx",+ "columns": [+ {+ "expression": "user_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "mcp_user_credentials_server_id_mcp_servers_id_fk": {+ "name": "mcp_user_credentials_server_id_mcp_servers_id_fk",+ "tableFrom": "mcp_user_credentials",+ "tableTo": "mcp_servers",+ "columnsFrom": [+ "server_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "mcp_user_credentials_user_id_users_id_fk": {+ "name": "mcp_user_credentials_user_id_users_id_fk",+ "tableFrom": "mcp_user_credentials",+ "tableTo": "users",+ "columnsFrom": [+ "user_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "mcp_user_credentials_credential_id_credentials_id_fk": {+ "name": "mcp_user_credentials_credential_id_credentials_id_fk",+ "tableFrom": "mcp_user_credentials",+ "tableTo": "credentials",+ "columnsFrom": [+ "credential_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {+ "mcp_user_credentials_server_id_user_id_pk": {+ "name": "mcp_user_credentials_server_id_user_id_pk",+ "columns": [+ "server_id",+ "user_id"+ ]+ }+ },+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.plugin_grants": {+ "name": "plugin_grants",+ "schema": "",+ "columns": {+ "kind": {+ "name": "kind",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "ref": {+ "name": "ref",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "agent_id": {+ "name": "agent_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "granted_by": {+ "name": "granted_by",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "created_at": {+ "name": "created_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {+ "plugin_grants_agent_idx": {+ "name": "plugin_grants_agent_idx",+ "columns": [+ {+ "expression": "agent_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "plugin_grants_agent_id_agents_id_fk": {+ "name": "plugin_grants_agent_id_agents_id_fk",+ "tableFrom": "plugin_grants",+ "tableTo": "agents",+ "columnsFrom": [+ "agent_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {+ "plugin_grants_kind_ref_agent_id_pk": {+ "name": "plugin_grants_kind_ref_agent_id_pk",+ "columns": [+ "kind",+ "ref",+ "agent_id"+ ]+ }+ },+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.sandboxed_components": {+ "name": "sandboxed_components",+ "schema": "",+ "columns": {+ "name": {+ "name": "name",+ "type": "text",+ "primaryKey": true,+ "notNull": true+ },+ "title": {+ "name": "title",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "draft_description": {+ "name": "draft_description",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "''"+ },+ "draft_html": {+ "name": "draft_html",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "''"+ },+ "draft_css": {+ "name": "draft_css",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "''"+ },+ "draft_js_functions": {+ "name": "draft_js_functions",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "''"+ },+ "draft_argument_schema": {+ "name": "draft_argument_schema",+ "type": "jsonb",+ "primaryKey": false,+ "notNull": true,+ "default": "'{}'::jsonb"+ },+ "published_description": {+ "name": "published_description",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "published_html": {+ "name": "published_html",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "published_css": {+ "name": "published_css",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "published_js_functions": {+ "name": "published_js_functions",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "published_argument_schema": {+ "name": "published_argument_schema",+ "type": "jsonb",+ "primaryKey": false,+ "notNull": false+ },+ "sample_arguments": {+ "name": "sample_arguments",+ "type": "jsonb",+ "primaryKey": false,+ "notNull": true,+ "default": "'{}'::jsonb"+ },+ "revision": {+ "name": "revision",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "default": 0+ },+ "published": {+ "name": "published",+ "type": "boolean",+ "primaryKey": false,+ "notNull": true,+ "default": false+ },+ "published_at": {+ "name": "published_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": false+ },+ "authored_by": {+ "name": "authored_by",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "created_at": {+ "name": "created_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {},+ "foreignKeys": {},+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.skill_tools": {+ "name": "skill_tools",+ "schema": "",+ "columns": {+ "skill_id": {+ "name": "skill_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "ref": {+ "name": "ref",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "declared_by": {+ "name": "declared_by",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "created_at": {+ "name": "created_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {+ "skill_tools_ref_idx": {+ "name": "skill_tools_ref_idx",+ "columns": [+ {+ "expression": "ref",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "skill_tools_skill_id_skills_id_fk": {+ "name": "skill_tools_skill_id_skills_id_fk",+ "tableFrom": "skill_tools",+ "tableTo": "skills",+ "columnsFrom": [+ "skill_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {+ "skill_tools_skill_id_ref_pk": {+ "name": "skill_tools_skill_id_ref_pk",+ "columns": [+ "skill_id",+ "ref"+ ]+ }+ },+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.skills": {+ "name": "skills",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true+ },+ "owner_user_id": {+ "name": "owner_user_id",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "slug": {+ "name": "slug",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "title": {+ "name": "title",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "summary": {+ "name": "summary",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "instructions": {+ "name": "instructions",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "origin": {+ "name": "origin",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "'yours'"+ },+ "installed_by": {+ "name": "installed_by",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "created_at": {+ "name": "created_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {+ "skills_slug_key": {+ "name": "skills_slug_key",+ "columns": [+ {+ "expression": "slug",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": true,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "skills_owner_idx": {+ "name": "skills_owner_idx",+ "columns": [+ {+ "expression": "owner_user_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "skills_owner_user_id_users_id_fk": {+ "name": "skills_owner_user_id_users_id_fk",+ "tableFrom": "skills",+ "tableTo": "users",+ "columnsFrom": [+ "owner_user_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.work_items": {+ "name": "work_items",+ "schema": "",+ "columns": {+ "kind": {+ "name": "kind",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "key": {+ "name": "key",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "run_at": {+ "name": "run_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ },+ "claimed_by": {+ "name": "claimed_by",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "lease_until": {+ "name": "lease_until",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": false+ },+ "attempts": {+ "name": "attempts",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "default": 0+ },+ "finished_at": {+ "name": "finished_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": false+ },+ "last_error": {+ "name": "last_error",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "payload": {+ "name": "payload",+ "type": "jsonb",+ "primaryKey": false,+ "notNull": true,+ "default": "'{}'::jsonb"+ },+ "created_at": {+ "name": "created_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {+ "work_items_claimable_idx": {+ "name": "work_items_claimable_idx",+ "columns": [+ {+ "expression": "kind",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "run_at",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {},+ "compositePrimaryKeys": {+ "work_items_kind_key_pk": {+ "name": "work_items_kind_key_pk",+ "columns": [+ "kind",+ "key"+ ]+ }+ },+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ }+ },+ "enums": {+ "public.agent_type": {+ "name": "agent_type",+ "schema": "public",+ "values": [+ "built_in",+ "remote_ag_ui"+ ]+ },+ "public.credential_kind": {+ "name": "credential_kind",+ "schema": "public",+ "values": [+ "model",+ "connector",+ "agent",+ "mcp",+ "mcp_oauth_client",+ "mcp_user_token"+ ]+ },+ "public.role": {+ "name": "role",+ "schema": "public",+ "values": [+ "admin",+ "user"+ ]+ },+ "public.agent_visibility": {+ "name": "agent_visibility",+ "schema": "public",+ "values": [+ "public",+ "private"+ ]+ },+ "public.routine_run_status": {+ "name": "routine_run_status",+ "schema": "public",+ "values": [+ "succeeded",+ "failed",+ "skipped"+ ]+ }+ },+ "schemas": {},+ "sequences": {},+ "roles": {},+ "policies": {},+ "views": {},+ "_meta": {+ "columns": {},+ "schemas": {},+ "tables": {}+ }+}\ No newline at end of filediff --git a/server/drizzle/meta/_journal.json b/server/drizzle/meta/_journal.jsonindex 3c1aa00f..49201434 100644--- a/server/drizzle/meta/_journal.json+++ b/server/drizzle/meta/_journal.json@@ -190,6 +190,13 @@"when": 1788271863590,"tag": "0026_channel_summary","breakpoints": true+ },+ {+ "idx": 27,+ "version": "7",+ "when": 1788543624826,+ "tag": "0027_user_instructions",+ "breakpoints": true}]-}\ No newline at end of file+}diff --git a/server/src/app.ts b/server/src/app.tsindex ff81b178..356d07d9 100644--- a/server/src/app.ts+++ b/server/src/app.ts@@ -46,6 +46,11 @@ import type { RoutineRunner } from "./routines/runner";import type { IntentRouter } from "./routing/classify";import { createRoutingRoutes } from "./routing/routes";import type { PackageStatusReader } from "./tenant-package";+import {+ INSTRUCTIONS_LIMIT,+ InstructionsTooLongError,+ type UserInstructionsStore,+} from "./user-instructions";/*** One row for something an administrator did to somebody's access.@@ -202,6 +207,17 @@ export function createApp(* nothing can finish.*/onboardingStore?: OnboardingStore,+ /**+ * One person's standing instructions, which every built-in coworker they run is told.+ *+ * Appended last, like everything above it: these are positional, so inserting one anywhere else+ * silently shifts every existing call site's arguments by one.+ *+ * Absent leaves the routes answering 503 rather than "you have written none". The difference+ * matters on exactly this screen: a person who cannot be told what they saved would otherwise be+ * shown an empty box, and the obvious thing to do with an empty box is fill it in again.+ */+ userInstructions?: UserInstructionsStore,) {const app = new Hono<{ Variables: AppVariables }>();@@ -344,6 +360,89 @@ export function createApp(onboarding: await onboardingStore.status(context.var.actor.id),});});+ /*+ * A person's own standing instructions, read and written by the person they belong to.+ *+ * `requireUser` and never `requireAdmin`, and scoped to `context.var.actor.id` rather than to+ * anything in the path or the body. There is deliberately no route here for reading somebody+ * else's or writing on their behalf: these instructions go into a prompt that then speaks as that+ * person's coworker, so a way to set them for another account would be a way to put words in+ * somebody's mouth in every channel they work in. An administrator has no business here either,+ * for the same reason.+ */+ app.get("/api/settings/instructions", requireUser, async (context) => {+ if (!userInstructions) {+ return context.json(+ { error: "Standing instructions are not available." },+ 503,+ );+ }++ return context.json({+ // "" is what having written none looks like to a text box, and the store's null is what it+ // looks like to a database. The translation happens once, here.+ instructions: (await userInstructions.read(context.var.actor.id)) ?? "",+ });+ });+ app.put("/api/settings/instructions", requireUser, async (context) => {+ if (!userInstructions) {+ return context.json(+ { error: "Standing instructions are not available." },+ 503,+ );+ }++ const body = (await context.req.json().catch(() => undefined)) as+ | { instructions?: unknown }+ | undefined;++ if (typeof body?.instructions !== "string") {+ return context.json({ error: "Send the instructions to save." }, 400);+ }++ /*+ * The cap is the store's rule, so the store is what enforces it and this catches the refusal+ * rather than checking the length again. A second copy of `> 4000` here is a second place for+ * the number to be changed in only one of them.+ */+ let saved: string;+ try {+ saved = await userInstructions.write(+ context.var.actor.id,+ body.instructions,+ );+ } catch (error) {+ if (error instanceof InstructionsTooLongError) {+ return context.json({ error: error.message }, 400);+ }+ throw error;+ }++ /*+ * The trail records that they changed and how long they now are, NEVER what they say.+ *+ * The audit table is append-only and read by administrators, and this is a person's own note+ * about how they want to be spoken to. Recording the text would put it somewhere they cannot+ * edit it and somebody else can read it, which is not what a preferences screen promises. The+ * length is enough to answer the question a trail is for: when did this change, and to what+ * extent.+ */+ if (auditStore) {+ await recordAuditEvent(auditStore, {+ eventType: "configuration.changed",+ targetType: "user_instructions",+ targetId: context.var.actor.id,+ actorUserId: context.var.actor.id,+ payload: {+ change: saved === "" ? "instructions_cleared" : "instructions_saved",+ characters: saved.length,+ limit: INSTRUCTIONS_LIMIT,+ },+ });+ }++ return context.json({ instructions: saved });+ });app.get("/api/admin/status", requireUser, (context) => {const denied = requireAdmin(context);return denied ?? context.json({ status: "ok" });diff --git a/server/src/copilot.ts b/server/src/copilot.tsindex e850efb7..fb68b0e2 100644--- a/server/src/copilot.ts+++ b/server/src/copilot.ts@@ -185,6 +185,42 @@ function isHttpUrl(value: string) {}}+/**+ * What the person asking has said they want, in every channel, from every coworker.+ *+ * The OpenBot equivalent of a CLAUDE.md, and the third instruction carrier beside the two that+ * already existed. A role is the coworker's and reads the same to everybody who talks to it; a skill+ * is pulled in for one task. This is the person's, and it is true of every task they ever ask for —+ * how they want to be written to, what their company is called, what it is not to be called.+ *+ * THE PRECEDENCE SENTENCE IS PART OF THE BLOCK, not decoration. Two standing instructions in one+ * prompt is a conflict waiting to be resolved by whichever the model read last, and the answer is+ * not symmetric: a person may say how they want things done, and must not be able to say what a+ * coworker is for. Without the sentence, "always answer in one line" quietly overrides a role that+ * exists to produce a filing with its sources in it.+ *+ * BUILT-IN COWORKERS ONLY. A remote AG-UI bot runs its own loop at somebody else's endpoint, and+ * everything this deployment sends it is a standing system message rather than a prompt it composes+ * — see `remoteAgentWithStandingRole`. Adding a third message there is a real change with its own+ * questions (whether an endpoint that ignores the role would honour this, and whether one+ * deployment's person may address another's server with their own prose), and it is deliberately not+ * made here.+ *+ * Null for anything blank, so the caller has one thing to test rather than an empty paragraph to+ * detect.+ */+export function standingInstructionsGuidance(+ instructions: string | null | undefined,+): string | null {+ const trimmed = instructions?.trim() ?? "";+ if (trimmed.length === 0) return null;++ return [+ `The person you are working with has standing instructions that apply in every channel and every task, alongside your role: ${trimmed}`,+ "Where the two conflict, the role decides what you do and these decide how you do it.",+ ].join("\n\n");+}+export function builtInAgentConfiguration(agent: RegisteredBuiltInAgent,model: RuntimeModel,@@ -214,6 +250,11 @@ export function builtInAgentConfiguration(* and browsed to it. See `grantedToolGuidance`.*/connectedVendors: readonly string[] = [],+ /**+ * The standing instructions of the person this run belongs to. Absent means they have written+ * none, which is most people on most days and costs the prompt nothing.+ */+ standingInstructions?: string | null,): BuiltInAgentConfiguration {if (!apiKey) {return {@@ -227,17 +268,25 @@ export function builtInAgentConfiguration(};}+ const standing = standingInstructionsGuidance(standingInstructions);+return {model: `${model.provider}/${model.defaultModel}`,/*- * The package's role, then what this Bot actually holds, then the computer.+ * The package's role, then the person's own standing instructions, then what this Bot actually+ * holds, then the computer.** The grants go BEFORE the computer prose on purpose. That prose is long and emphatic about the* browser and mentions connectors nowhere, so a Bot that read it last reached for the browser* even when it held a tool for the exact system being asked about.+ *+ * The person's instructions go straight after the role and before all of it, because they are+ * the other half of the same question — who you are and who you are working for — and because+ * their precedence sentence only means anything next to the role it defers to.*/prompt: [agent.systemPrompt,+ ...(standing ? [standing] : []),/** Unconditional, unlike the two below it.*@@ -307,8 +356,25 @@ export async function buildAgents(agentFetch?: AgentFetch,/** How a run gets its tool for handing work on. Absent means no Bot is offered one. */handoff?: HandoffForRun,+ /**+ * What the person asking has told every coworker they run. Absent means this deployment does not+ * carry standing instructions, which is what every deployment did before they existed.+ */+ loadInstructions?: LoadInstructions,): Promise<Record<string, AbstractAgent>> {const vendors = await loadVendors().catch(() => [] as readonly string[]);+ /*+ * Read once per build and only when somebody will be told it, like the vendors above and the model+ * key below: it is a fact about the person, not about a coworker, and asking per Bot would be the+ * same row fetched once for each of them. Skipped entirely when nothing built-in is being built,+ * because the remote path does not carry this at all.+ *+ * Failure is silence. A coworker that could not be told loses a paragraph; one that refused to+ * start would lose the conversation, and a preferences row is not worth a run.+ */+ const instructions = agents.some((agent) => agent.type === "built_in")+ ? await loadInstructions?.().catch(() => null)+ : null;return Object.fromEntries(await Promise.all(agents.map(async (agent) => [@@ -325,12 +391,22 @@ export async function buildAgents(selection,agentFetch,handoff,+ instructions ?? null,),]),),);}+/**+ * The standing instructions of whoever this run belongs to, resolved when a run needs them.+ *+ * A closure rather than a string passed down, for the same reason `LoadToolsForBot` is one: it is a+ * per-person fact that a person can change between two runs, and a value captured at boot would+ * serve everybody the first person's preferences. Null means they have written none.+ */+export type LoadInstructions = () => Promise<string | null>;+async function buildAgent(agent: RegisteredAgent,model: RuntimeModel,@@ -343,6 +419,8 @@ async function buildAgent(selection?: ToolSelection,agentFetch?: AgentFetch,handoff?: HandoffForRun,+ /** Already resolved by {@link buildAgents}, so one roster costs one read. */+ standingInstructions: string | null = null,): Promise<AbstractAgent> {if (agent.type === "unavailable") {return new UnavailableAgent(agent);@@ -402,6 +480,12 @@ async function buildAgent(* Making this work is a feature rather than a fix: the callback would have to carry a run* assertion the endpoint cannot forge, and execute a hop on its behalf. Worth doing; not done* here, and worth knowing it is missing rather than assuming it is not.+ *+ * AND THE PERSON'S STANDING INSTRUCTIONS ARE NOT SENT HERE EITHER. `standingInstructions` is+ * built-in only, deliberately: a remote Bot composes its own prompt at somebody else's endpoint,+ * so this deployment would be sending one person's prose to a server it does not run, with no+ * way to know whether it is read or how it ranks against the role. See+ * `standingInstructionsGuidance`.*/return remoteAgentWithStandingRole(agent,@@ -428,6 +512,7 @@ async function buildAgent(tools,computerGuidance,connectedVendors,+ standingInstructions,),);@@ -866,6 +951,13 @@ export async function resolveRuntimeAgents(* theirs to see at all; what narrows is what gets built.*/onlyBotId?: string,+ /**+ * The standing instructions of the person this build is for.+ *+ * Appended after `onlyBotId` rather than beside the other per-person collaborators, because these+ * are positional and moving one shifts every existing call site by one.+ */+ loadInstructions?: LoadInstructions,): Promise<Record<string, AbstractAgent>> {const all = await loadAgents();if (all.length === 0) {@@ -896,6 +988,7 @@ export async function resolveRuntimeAgents(selection,agentFetch,handoff,+ loadInstructions,);}@@ -966,6 +1059,14 @@ export function createRequestAgents(* roster that person can see, so a Bot must never be able to address one they cannot.*/handoffForActor?: (actorId: string) => HandoffForRun,+ /**+ * What this person has told every coworker they run, resolved for whoever is asking.+ *+ * Per actor, and through `identifyActor` rather than anything in the request body, for the same+ * reason the grants are: this text goes into a prompt that then speaks as that person's coworker,+ * so which person it belongs to has to be decided by the session and never by the caller.+ */+ loadInstructionsForActor?: (actorId: string) => LoadInstructions,) {return async ({ request }: { request: Request }) => {const actor = await identifyActor(request);@@ -981,6 +1082,9 @@ export function createRequestAgents(selectionForActor?.(actor.id),agentFetch,handoffForActor?.(actor.id),+ // Every Bot this person can see, so no `onlyBotId` here; the instructions follow it.+ undefined,+ loadInstructionsForActor?.(actor.id),);};}@@ -1100,6 +1204,14 @@ export function mountCopilotRuntime(* awaited in the lock path and a failure in it never touches whether the lock was taken.*/onRunBusy?: (input: { threadId: string; busy: boolean }) => void,+ /**+ * What the person asking has told every built-in coworker they run, resolved per person.+ *+ * Given to both the request path and `agentFor` below, so a hop delivered to a Bot at three in the+ * morning carries the same standing instructions the Bot in front of the person does. A seam wired+ * into only one of them would be the drift `agentFor` exists to prevent.+ */+ loadInstructionsForActor?: (actorId: string) => LoadInstructions,) {const { intelligence } = config.runtime;@@ -1142,6 +1254,7 @@ export function mountCopilotRuntime(// see is still absent; what this skips is constructing the other Bots and asking the database// what each of them was granted, on every delivery and again on every retry.input.botId,+ loadInstructionsForActor?.(actor.id),);return agents[input.botId] ?? null;};@@ -1210,6 +1323,7 @@ export function mountCopilotRuntime(selectionForActor,agentFetch,handoffForActor,+ loadInstructionsForActor,) as never,});diff --git a/server/src/db/schema/core.ts b/server/src/db/schema/core.tsindex 42875503..e2bcdf80 100644--- a/server/src/db/schema/core.ts+++ b/server/src/db/schema/core.ts@@ -159,6 +159,33 @@ export const userRoles = pgTable((table) => [primaryKey({ columns: [table.userId, table.role] })],);+/**+ * One person's standing instructions, applied to every built-in coworker they run.+ *+ * The person-shaped half of a durable instruction. The other two carriers are both about the work+ * rather than about the person: a coworker's role belongs to the coworker and is the same for+ * everybody who talks to it, and a skill is invoked for one task. Neither can say "always write to+ * me in British English" or "we are a two-person company, never call us a team", which is a fact+ * about the person and true in every channel.+ *+ * The user id IS the primary key rather than a column beside a surrogate one. There is exactly one+ * of these per person, and a table that allowed two would make "what are this person's standing+ * instructions" depend on which row a query happened to order first.+ *+ * Empty is absence, not a row: the store deletes on an empty save rather than storing "". A row+ * holding an empty string would be a person with standing instructions that say nothing, which the+ * prompt seam then has to recognise and skip anyway — so there is one representation of "none", and+ * it is having no row.+ */+export const userInstructions = pgTable("user_instructions", {+ userId: text("user_id")+ .primaryKey()+ .references(() => users.id, { onDelete: "cascade" }),+ instructions: text("instructions").notNull(),+ createdAt: createdAt(),+ updatedAt: updatedAt(),+});+/*** An enterprise identity provider this deployment has been told about.*diff --git a/server/src/index.ts b/server/src/index.tsindex de6f95d7..667f05bd 100644--- a/server/src/index.ts+++ b/server/src/index.ts@@ -83,6 +83,7 @@ import {loadTenantPackage,synchronizeTenantPackage,} from "./tenant-package";+import { createUserInstructionsStore } from "./user-instructions";import { repeatAfterEach } from "./work/loop";import {createWorkQueue,@@ -513,6 +514,20 @@ const resolveRuntimeModelApiKey = () =>const loadToolsForActor = (actorId: string) => (botId: string) =>grantedTools({ store: pluginStore, botId, actorId });+/** One person's standing instructions, for both the /api/settings routes and every run they start. */+const userInstructionsStore = createUserInstructionsStore(database);++/*+ * What this person has told every built-in coworker they run.+ *+ * Per actor and read per build, for the reason every other per-person fact here is: somebody who+ * edits their instructions and sends a message expects the message to land on the new ones, and a+ * value captured at boot would serve the whole deployment whatever the first person to sign in had+ * written.+ */+const loadInstructionsForActor = (actorId: string) => () =>+ userInstructionsStore.read(actorId);+/** What the deployment tells a remote Bot about the run it is starting.*@@ -667,6 +682,9 @@ const buildAgentFor = async ({// full so a Bot this owner cannot see is still absent, but the other Bots are neither built nor// asked what they hold.agentId,+ // The owner's own standing instructions. A routine is their work done while they are asleep, so+ // it is written the way they asked for it to be written, exactly as their chat turn would be.+ loadInstructionsForActor(actor.id),);const agent = agents[agentId];if (!agent) {@@ -824,6 +842,8 @@ const copilotRuntime = mountCopilotRuntime((input) => {void channelStore.signalBusy(input.threadId, input.busy).catch(() => {});},+ // What this person has told every coworker of theirs, in every channel. See user-instructions.ts.+ loadInstructionsForActor,);/**@@ -1111,6 +1131,9 @@ const app = createApp(routineStore,// Where each person is in first-run onboarding, read by /api/me and written by the wizard.createOnboardingStore(database),+ // The same store every run reads through `loadInstructionsForActor`, so the screen a person edits+ // and the prompt their coworker is built from can never be two different pieces of text.+ userInstructionsStore,);/**diff --git a/server/src/user-instructions.ts b/server/src/user-instructions.tsnew file mode 100644index 00000000..759f5da6--- /dev/null+++ b/server/src/user-instructions.ts@@ -0,0 +1,107 @@+import { eq } from "drizzle-orm";+import type { Database } from "./db/client";+import { userInstructions } from "./db/schema";++/**+ * One person's standing instructions: the thing every coworker they run is told, in every channel.+ *+ * WHAT THIS IS FOR. Until now the only durable instruction carriers were per coworker or per task. A+ * role belongs to the coworker and reads the same to everybody who talks to it; a skill is pulled in+ * for one job and then gone. Neither can hold "we are two people, never call us a team" or "write in+ * British English", which is a fact about the person rather than about the work, and which somebody+ * otherwise retypes into every conversation until they stop bothering and simply accept worse+ * answers.+ *+ * WHAT IT IS NOT. It is not a grant and it changes nothing about what a coworker may call. It is+ * prose appended to a prompt, so the worst a bad one can do is make an answer worse — which is why+ * every failure to read it is silent at the seam that uses it, and why the cap below is generous+ * rather than careful.+ */+export type UserInstructionsStore = {+ /** Null when this person has written none. Never an empty string: see {@link INSTRUCTIONS_LIMIT}. */+ read: (userId: string) => Promise<string | null>;+ /**+ * Save, or clear. Returns what was stored, which is the trimmed text, or "" when the row is gone.+ *+ * Returned rather than assumed by the caller, because the trim is this module's decision and a+ * screen that echoed back what it sent would show trailing whitespace the database does not have.+ */+ write: (userId: string, text: string) => Promise<string>;+};++/**+ * How much one person may say, in characters.+ *+ * A ceiling on a prompt rather than a validation rule with a reason behind it: every built-in+ * coworker carries this on every run, so it is paid for on every turn of every conversation, and+ * there is no upper bound anybody would notice being missing. Four thousand is several paragraphs,+ * comfortably more than the "how we talk about ourselves" note this is for, and small enough beside+ * a context window that a person cannot quietly make every run expensive.+ */+export const INSTRUCTIONS_LIMIT = 4000;++/**+ * Somebody sent more than the cap.+ *+ * A named class rather than a boolean return, because the route has to answer 400 with a sentence+ * and every other outcome here is a success. Thrown by the store rather than only checked at the+ * route so the cap has ONE home: a second caller — a routine, an import, whatever arrives next —+ * cannot write past it by not knowing the rule existed.+ */+export class InstructionsTooLongError extends Error {+ constructor() {+ super(+ `Standing instructions are at most ${INSTRUCTIONS_LIMIT} characters.`,+ );+ this.name = "InstructionsTooLongError";+ }+}++export function createUserInstructionsStore(+ database: Database,+): UserInstructionsStore {+ return {+ async read(userId) {+ const [row] = await database+ .select({ instructions: userInstructions.instructions })+ .from(userInstructions)+ .where(eq(userInstructions.userId, userId))+ .limit(1);++ return row?.instructions ?? null;+ },++ async write(userId, text) {+ const instructions = text.trim();++ if (instructions.length > INSTRUCTIONS_LIMIT) {+ throw new InstructionsTooLongError();+ }++ /*+ * Emptying the box is deleting the row, not storing "".+ *+ * The two would read identically to a person and differently to everything else: the prompt+ * seam would have to know that an empty string means no block, the store would answer "" where+ * it had promised null, and "has this person written any" would stop being a row count. One+ * representation of none, and it is absence.+ */+ if (instructions.length === 0) {+ await database+ .delete(userInstructions)+ .where(eq(userInstructions.userId, userId));+ return "";+ }++ await database+ .insert(userInstructions)+ .values({ userId, instructions })+ .onConflictDoUpdate({+ target: userInstructions.userId,+ set: { instructions, updatedAt: new Date() },+ });++ return instructions;+ },+ };+}diff --git a/server/tests/copilot.test.ts b/server/tests/copilot.test.tsindex 5733e367..61f37e69 100644--- a/server/tests/copilot.test.ts+++ b/server/tests/copilot.test.ts@@ -806,6 +806,212 @@ describe("where a Bot says its answer came from", () => {});});+/**+ * The person's own standing instructions, and where they land in a prompt.+ *+ * The third instruction carrier. A role is the coworker's and reads the same to everybody; a skill+ * is pulled in for one task. This is the person's, and it is true of every task they ask for, which+ * is why the only interesting properties are about placement and precedence rather than about+ * content: WHERE it sits relative to the role, that it is absent when nobody has written any, that+ * it never reaches a Bot at somebody else's endpoint, and that failing to read it costs a paragraph+ * rather than a run.+ */+describe("a person's standing instructions", () => {+ const assistant = {+ id: "general-assistant",+ name: "General Assistant",+ type: "built_in" as const,+ systemPrompt: "Be helpful.",+ };+ const model = { provider: "openai" as const, defaultModel: "gpt-5.6-terra" };++ const promptWith = (instructions: string | null) =>+ builtInAgentConfiguration(+ assistant,+ model,+ "openai-secret",+ [],+ undefined,+ [],+ instructions,+ ).prompt as string;++ test("carries the block, its precedence sentence, and the person's own words", () => {+ const prompt = promptWith("Write in British English.");++ expect(prompt).toContain(+ "The person you are working with has standing instructions that apply in every channel and every task, alongside your role: Write in British English.",+ );+ /*+ * The precedence sentence is part of the block rather than decoration. Two standing instructions+ * in one prompt is a conflict resolved by whichever the model read last, and the resolution is+ * not symmetric: "always answer in one line" must not quietly override a role that exists to+ * produce a filing with its sources in it.+ */+ expect(prompt).toContain(+ "Where the two conflict, the role decides what you do and these decide how you do it.",+ );+ });++ test("sits after the role and before everything the deployment adds", () => {+ const prompt = builtInAgentConfiguration(+ assistant,+ model,+ "openai-secret",+ [{ name: "mcp__google-drive__search_files" }] as never[],+ "Computer guidance.",+ [],+ "Write in British English.",+ ).prompt as string;++ // The role, then who it is working for, then what it holds, then its hands. Asserted as+ // positions rather than as presence, because the order is the part that was decided.+ expect(prompt.indexOf("Be helpful.")).toBeLessThan(+ prompt.indexOf("standing instructions that apply in every channel"),+ );+ expect(+ prompt.indexOf("standing instructions that apply in every channel"),+ ).toBeLessThan(prompt.indexOf("google-drive"));+ expect(prompt.indexOf("google-drive")).toBeLessThan(+ prompt.indexOf("Computer guidance."),+ );+ });++ test.each([[null], [undefined], [""], [" \n "]])(+ "adds nothing at all when there are none: %j",+ (instructions) => {+ const prompt = promptWith(instructions as string | null);++ expect(prompt).not.toContain("standing instructions");+ // Byte for byte what a deployment had before any of this existed, which is what most people+ // on most days get.+ expect(prompt).toBe(`Be helpful.\n\n${PROVENANCE_GUIDANCE}`);+ },+ );++ test("is read once for a whole roster, and only when somebody built-in will be told it", async () => {+ let reads = 0;+ const loadInstructions = async () => {+ reads += 1;+ return "Write in British English.";+ };++ await buildAgents(+ [+ assistant,+ { ...assistant, id: "second-assistant", name: "Second Assistant" },+ ],+ model,+ "openai-secret",+ undefined,+ undefined,+ undefined,+ undefined,+ undefined,+ undefined,+ undefined,+ undefined,+ loadInstructions,+ );+ // One person, one row: asking per Bot would be the same read once for each of them.+ expect(reads).toBe(1);++ await buildAgents(+ [+ {+ id: "risk",+ name: "Risk",+ type: "remote_ag_ui",+ endpoint: "http://risk.internal/ag-ui",+ },+ ],+ model,+ "openai-secret",+ undefined,+ undefined,+ undefined,+ undefined,+ undefined,+ undefined,+ undefined,+ undefined,+ loadInstructions,+ );+ /*+ * Not read at all for a roster with nothing built-in. A remote Bot composes its own prompt at+ * somebody else's endpoint, so this deployment has nowhere to put the text and no reason to pay+ * for reading it.+ */+ expect(reads).toBe(1);+ });++ test("never reaches a Bot at somebody else's endpoint", () => {+ const content = standingRoleMessage({+ id: "risk",+ name: "Risk",+ title: "Risk & Compliance",+ roleDescription: "Investigate policies and controls.",+ }).content;++ expect(content).not.toContain("standing instructions that apply");+ });++ test("costs a paragraph rather than a run when it cannot be read", async () => {+ const agents = await buildAgents(+ [assistant],+ model,+ "openai-secret",+ undefined,+ undefined,+ undefined,+ undefined,+ undefined,+ undefined,+ undefined,+ undefined,+ async () => {+ throw new Error("The database is unreachable.");+ },+ );++ // The Bot is still built and still answers. A preferences row is not worth a conversation.+ expect(agents["general-assistant"]).toBeInstanceOf(BuiltInAgent);+ });++ test("is resolved for whoever the request turned out to be", async () => {+ const asked: string[] = [];+ const factory = createRequestAgents(+ async () => ({ id: "user-7", role: "user" as const }),+ async () => [assistant],+ model,+ async () => "openai-secret",+ undefined,+ undefined,+ undefined,+ undefined,+ undefined,+ undefined,+ undefined,+ undefined,+ (actorId) => async () => {+ asked.push(actorId);+ return "Write in British English.";+ },+ );++ await factory({+ request: new Request("http://openbot.test/api/copilotkit"),+ });++ /*+ * The actor from `identifyActor`, never anything in the request body. This text goes into a+ * prompt that then speaks as that person's coworker in every channel they work in, so which+ * person it belongs to is the session's answer and nobody else's.+ */+ expect(asked).toEqual(["user-7"]);+ });+});+/*** The dangling tool call, refused before it reaches the model provider.*diff --git a/server/tests/schema.test.ts b/server/tests/schema.test.tsindex 1a3104e9..1f9665fd 100644--- a/server/tests/schema.test.ts+++ b/server/tests/schema.test.ts@@ -18,6 +18,7 @@ import {intelligenceChannelMappings,mcpUserCredentials,sessions,+ userInstructions,userRoles,users,verifications,@@ -39,6 +40,7 @@ describe("OpenBot database schema", () => {credentials,auditEvents,intelligenceChannelMappings,+ userInstructions,].map(getTableName),).toEqual(["users",@@ -53,6 +55,7 @@ describe("OpenBot database schema", () => {"credentials","audit_events","intelligence_channel_mappings",+ "user_instructions",]);});@@ -108,6 +111,62 @@ describe("OpenBot database schema", () => {]);});+ test("gives one person one set of standing instructions, and makes that the key", () => {+ const config = getTableConfig(userInstructions);++ /*+ * The user id IS the primary key, not a column beside a surrogate one.+ *+ * "What has this person asked every coworker to do" must have exactly one answer, because the+ * answer goes into a prompt. With an id and no unique constraint two rows are legal, and then+ * which of them speaks for the person depends on whichever the query happened to order first.+ */+ expect(+ config.columns.map((column) => ({+ name: column.name,+ sqlType: column.getSQLType(),+ notNull: column.notNull,+ primary: column.primary,+ })),+ ).toEqual([+ { name: "user_id", sqlType: "text", notNull: true, primary: true },+ { name: "instructions", sqlType: "text", notNull: true, primary: false },+ {+ name: "created_at",+ sqlType: "timestamp with time zone",+ notNull: true,+ primary: false,+ },+ {+ name: "updated_at",+ sqlType: "timestamp with time zone",+ notNull: true,+ primary: false,+ },+ ]);++ /*+ * Cascade, because this is one person's own prose about themselves. A deleted account must not+ * leave behind a paragraph that would be read into somebody's prompt if the id were ever reused.+ */+ expect(+ config.foreignKeys.map((foreignKey) => {+ const reference = foreignKey.reference();+ return {+ sourceColumns: reference.columns.map((column) => column.name),+ targetTable: getTableName(reference.foreignTable),+ onDelete: foreignKey.onDelete,+ };+ }),+ ).toEqual([+ {+ sourceColumns: ["user_id"],+ targetTable: "users",+ onDelete: "cascade",+ },+ ]);+ });+test("follows the person and the server when either goes away", () => {const config = getTableConfig(mcpUserCredentials);const cascading = config.foreignKeys.filter(diff --git a/server/tests/settings-instructions-routes.test.ts b/server/tests/settings-instructions-routes.test.tsnew file mode 100644index 00000000..b3a45ca9--- /dev/null+++ b/server/tests/settings-instructions-routes.test.ts@@ -0,0 +1,317 @@+import { describe, expect, test } from "bun:test";+import { createApp } from "../src/app";+import type { AuditStore } from "../src/audit";+import { loadConfig } from "../src/config";+import {+ INSTRUCTIONS_LIMIT,+ InstructionsTooLongError,+ type UserInstructionsStore,+} from "../src/user-instructions";+import { testEnvironment } from "./support/environment";++const MEMBER = {+ id: "member-1",+ email: "[email protected]",+ name: "A Member",+ image: null,+};++const OTHER = {+ id: "member-2",+ email: "[email protected]",+ name: "Another Member",+ image: null,+};++/**+ * A person's own standing instructions, over HTTP.+ *+ * The rules worth pinning are the ones a screen cannot check for itself: that the text is scoped to+ * whoever the session says is asking rather than to anything in the request, that the cap is refused+ * rather than truncated, and that the trail records the change without recording the prose.+ */+function appWith(+ store?: UserInstructionsStore,+ options: { as?: typeof MEMBER; auditStore?: AuditStore } = {},+) {+ return createApp(+ loadConfig(testEnvironment()),+ {+ handler: () => new Response(null, { status: 204 }),+ api: { getSession: async () => ({ user: options.as ?? MEMBER }) },+ } as never,+ { rolesForUser: async () => ["user"] },+ /*+ * Positions 4-12 are the other stores, 13 is auditStore, 14-24 are more stores, and `store` is+ * 25, userInstructions, the signature's last. Every parameter from 4 on is optional, so a wrong+ * count is a silent type-check pass: see people-routes.test.ts, which learned this the hard way.+ */+ ...(Array.from({ length: 9 }) as never[]),+ options.auditStore as never,+ ...(Array.from({ length: 11 }) as never[]),+ store as never,+ );+}++/** One text per person, in memory, with the same trim, cap and clear rules the real store has. */+function memoryStore(initial: Record<string, string> = {}) {+ const state: Record<string, string> = { ...initial };+ const store: UserInstructionsStore = {+ read: async (userId) => state[userId] ?? null,+ write: async (userId, text) => {+ const instructions = text.trim();+ if (instructions.length > INSTRUCTIONS_LIMIT) {+ throw new InstructionsTooLongError();+ }+ if (instructions.length === 0) {+ delete state[userId];+ return "";+ }+ state[userId] = instructions;+ return instructions;+ },+ };+ return { store, state };+}++function memoryAudit() {+ const rows: Parameters<AuditStore["insert"]>[0][] = [];+ return {+ rows,+ store: {+ insert: async (event) => {+ rows.push(event);+ },+ } satisfies AuditStore,+ };+}++describe("standing instruction routes", () => {+ test("answers with an empty string when this person has written none", async () => {+ const { store } = memoryStore();+ const app = appWith(store);++ const response = await app.request(+ "http://openbot.local/api/settings/instructions",+ );++ expect(response.status).toBe(200);+ await expect(response.json()).resolves.toEqual({ instructions: "" });+ });++ test("saves, trims, and answers with what was stored", async () => {+ const { store, state } = memoryStore();+ const app = appWith(store);++ const response = await app.request(+ "http://openbot.local/api/settings/instructions",+ {+ method: "PUT",+ headers: { "content-type": "application/json" },+ body: JSON.stringify({ instructions: " Write in British English. " }),+ },+ );++ expect(response.status).toBe(200);+ await expect(response.json()).resolves.toEqual({+ instructions: "Write in British English.",+ });+ expect(state[MEMBER.id]).toBe("Write in British English.");+ });++ test("a later read returns what a save stored", async () => {+ const { store } = memoryStore();+ const app = appWith(store);++ await app.request("http://openbot.local/api/settings/instructions", {+ method: "PUT",+ headers: { "content-type": "application/json" },+ body: JSON.stringify({ instructions: "Never say we are a team." }),+ });++ const response = await app.request(+ "http://openbot.local/api/settings/instructions",+ );++ await expect(response.json()).resolves.toEqual({+ instructions: "Never say we are a team.",+ });+ });++ test("an empty save clears them", async () => {+ const { store, state } = memoryStore({+ [MEMBER.id]: "Write in British English.",+ });+ const app = appWith(store);++ const response = await app.request(+ "http://openbot.local/api/settings/instructions",+ {+ method: "PUT",+ headers: { "content-type": "application/json" },+ body: JSON.stringify({ instructions: " " }),+ },+ );++ expect(response.status).toBe(200);+ await expect(response.json()).resolves.toEqual({ instructions: "" });+ expect(state[MEMBER.id]).toBeUndefined();+ });++ test("refuses more than the cap, and stores nothing when it does", async () => {+ const { store, state } = memoryStore({+ [MEMBER.id]: "Write in British English.",+ });+ const app = appWith(store);++ const response = await app.request(+ "http://openbot.local/api/settings/instructions",+ {+ method: "PUT",+ headers: { "content-type": "application/json" },+ body: JSON.stringify({+ instructions: "x".repeat(INSTRUCTIONS_LIMIT + 1),+ }),+ },+ );++ expect(response.status).toBe(400);+ // The sentence names the limit, because "too long" without a number is not something anybody can+ // act on while looking at a box they cannot count.+ const body = (await response.json()) as { error: string };+ expect(body.error).toContain(String(INSTRUCTIONS_LIMIT));+ expect(state[MEMBER.id]).toBe("Write in British English.");+ });++ test.each([[{}], [{ instructions: null }], [{ instructions: 42 }]])(+ "refuses a body it does not understand: %j",+ async (body) => {+ const { store, state } = memoryStore();+ const app = appWith(store);++ const response = await app.request(+ "http://openbot.local/api/settings/instructions",+ {+ method: "PUT",+ headers: { "content-type": "application/json" },+ body: JSON.stringify(body),+ },+ );++ expect(response.status).toBe(400);+ expect(state).toEqual({});+ },+ );++ /*+ * The scoping test, and the reason this endpoint has no user id anywhere in it.+ *+ * This text is read into a prompt that then speaks as that person's coworker in every channel they+ * work in. A route that took the person from the path or the body would be a way to put words in+ * somebody else's mouth, so the only source is the session.+ */+ test("two people never see each other's instructions", async () => {+ const { store, state } = memoryStore();++ await appWith(store, { as: MEMBER }).request(+ "http://openbot.local/api/settings/instructions",+ {+ method: "PUT",+ headers: { "content-type": "application/json" },+ body: JSON.stringify({ instructions: "Write in British English." }),+ },+ );+ await appWith(store, { as: OTHER }).request(+ "http://openbot.local/api/settings/instructions",+ {+ method: "PUT",+ headers: { "content-type": "application/json" },+ body: JSON.stringify({ instructions: "Answer in one paragraph." }),+ },+ );++ await expect(+ appWith(store, { as: MEMBER })+ .request("http://openbot.local/api/settings/instructions")+ .then((response) => response.json()),+ ).resolves.toEqual({ instructions: "Write in British English." });+ await expect(+ appWith(store, { as: OTHER })+ .request("http://openbot.local/api/settings/instructions")+ .then((response) => response.json()),+ ).resolves.toEqual({ instructions: "Answer in one paragraph." });+ expect(state).toEqual({+ [MEMBER.id]: "Write in British English.",+ [OTHER.id]: "Answer in one paragraph.",+ });+ });++ test("records that they changed, and never what they say", async () => {+ const { store } = memoryStore();+ const audit = memoryAudit();+ const app = appWith(store, { auditStore: audit.store });++ await app.request("http://openbot.local/api/settings/instructions", {+ method: "PUT",+ headers: { "content-type": "application/json" },+ body: JSON.stringify({ instructions: "Write in British English." }),+ });++ expect(audit.rows).toEqual([+ {+ eventType: "configuration.changed",+ targetType: "user_instructions",+ targetId: MEMBER.id,+ actorUserId: MEMBER.id,+ payload: {+ change: "instructions_saved",+ characters: "Write in British English.".length,+ limit: INSTRUCTIONS_LIMIT,+ },+ },+ ]);+ expect(JSON.stringify(audit.rows)).not.toContain("British");+ });++ test("records a clearing as a clearing", async () => {+ const { store } = memoryStore({ [MEMBER.id]: "Write in British English." });+ const audit = memoryAudit();+ const app = appWith(store, { auditStore: audit.store });++ await app.request("http://openbot.local/api/settings/instructions", {+ method: "PUT",+ headers: { "content-type": "application/json" },+ body: JSON.stringify({ instructions: "" }),+ });++ expect(audit.rows[0]?.payload).toEqual({+ change: "instructions_cleared",+ characters: 0,+ limit: INSTRUCTIONS_LIMIT,+ });+ });++ /*+ * 503, not an empty string. "You have written none" and "this deployment cannot tell you" are+ * different answers, and the wrong one on this screen shows somebody an empty box, which invites+ * them to type it all in again over the top of something that is still there.+ */+ test("answers 503 rather than pretending when there is no store", async () => {+ const app = appWith(undefined);++ await expect(+ app+ .request("http://openbot.local/api/settings/instructions")+ .then((response) => response.status),+ ).resolves.toBe(503);+ await expect(+ app+ .request("http://openbot.local/api/settings/instructions", {+ method: "PUT",+ headers: { "content-type": "application/json" },+ body: JSON.stringify({ instructions: "Write in British English." }),+ })+ .then((response) => response.status),+ ).resolves.toBe(503);+ });+});diff --git a/server/tests/user-instructions.integration.test.ts b/server/tests/user-instructions.integration.test.tsnew file mode 100644index 00000000..3d3bab87--- /dev/null+++ b/server/tests/user-instructions.integration.test.ts@@ -0,0 +1,150 @@+import { afterAll, afterEach, describe, expect, test } from "bun:test";+import { randomUUID } from "node:crypto";+import { eq } from "drizzle-orm";+import { createDatabase } from "../src/db/client";+import { userInstructions, users } from "../src/db/schema";+import {+ createUserInstructionsStore,+ INSTRUCTIONS_LIMIT,+ InstructionsTooLongError,+} from "../src/user-instructions";+import { TEST_POOL } from "./support/database";++const databaseUrl =+ process.env.DATABASE_URL ??+ "postgres://openbot:openbot@localhost:5432/openbot";+const database = createDatabase(databaseUrl, TEST_POOL);+const store = createUserInstructionsStore(database);++const createdUserIds: string[] = [];++async function person() {+ const id = `user-instructions-${randomUUID()}`;+ await database.insert(users).values({ id, email: `${id}@openbot.test` });+ createdUserIds.push(id);+ return id;+}++afterEach(async () => {+ for (const userId of createdUserIds.splice(0)) {+ await database.delete(users).where(eq(users.id, userId));+ }+});++afterAll(async () => {+ await database.$client.close();+});++describe("one person's standing instructions", () => {+ test("reads as nothing before anybody has written any", async () => {+ await expect(store.read(await person())).resolves.toBeNull();+ });++ test("saves, replaces, and reads back what was stored", async () => {+ const userId = await person();++ await expect(+ store.write(userId, "Write in British English."),+ ).resolves.toBe("Write in British English.");+ await expect(store.read(userId)).resolves.toBe("Write in British English.");++ // The second save REPLACES rather than appends: the box holds one text, and a save says what it+ // now is. There is no gesture in the UI for removing half of what you wrote if it merged.+ await expect(store.write(userId, "Never say we are a team.")).resolves.toBe(+ "Never say we are a team.",+ );+ await expect(store.read(userId)).resolves.toBe("Never say we are a team.");++ // One row, not two. See the primary key on the table.+ const rows = await database+ .select()+ .from(userInstructions)+ .where(eq(userInstructions.userId, userId));+ expect(rows.length).toBe(1);+ });++ test("trims what it is given, so the stored text is what the model will read", async () => {+ const userId = await person();++ await expect(+ store.write(userId, " \n Write in British English. \n "),+ ).resolves.toBe("Write in British English.");+ await expect(store.read(userId)).resolves.toBe("Write in British English.");+ });++ test("clears by saving nothing, and leaves no empty row behind", async () => {+ const userId = await person();+ await store.write(userId, "Write in British English.");++ await expect(store.write(userId, " ")).resolves.toBe("");++ /*+ * Absence, not an empty string. The two would read the same to a person and differently to+ * everything else: the prompt seam would have to learn that "" means no block, and "has this+ * person written any" would stop being a row count.+ */+ await expect(store.read(userId)).resolves.toBeNull();+ expect(+ await database+ .select()+ .from(userInstructions)+ .where(eq(userInstructions.userId, userId)),+ ).toEqual([]);+ });++ test("clearing what was never written is not an error", async () => {+ const userId = await person();++ await expect(store.write(userId, "")).resolves.toBe("");+ await expect(store.read(userId)).resolves.toBeNull();+ });++ test("refuses more than the cap, and stores nothing when it does", async () => {+ const userId = await person();+ await store.write(userId, "Write in British English.");++ await expect(+ store.write(userId, "x".repeat(INSTRUCTIONS_LIMIT + 1)),+ ).rejects.toBeInstanceOf(InstructionsTooLongError);++ // The refusal is a refusal, not a partial write: what was there is still there.+ await expect(store.read(userId)).resolves.toBe("Write in British English.");+ });++ test("accepts exactly the cap, measured after the trim", async () => {+ const userId = await person();+ const atTheLimit = "x".repeat(INSTRUCTIONS_LIMIT);++ // The whitespace is not part of what is stored, so it must not be part of what is counted: a+ // trailing newline from a textarea is not somebody exceeding a limit.+ await expect(store.write(userId, ` ${atTheLimit}\n`)).resolves.toBe(+ atTheLimit,+ );+ await expect(store.read(userId)).resolves.toBe(atTheLimit);+ });++ test("keeps two people's instructions apart", async () => {+ const one = await person();+ const other = await person();++ await store.write(one, "Write in British English.");+ await store.write(other, "Answer in one paragraph.");++ await expect(store.read(one)).resolves.toBe("Write in British English.");+ await expect(store.read(other)).resolves.toBe("Answer in one paragraph.");+ });++ test("goes when the person goes", async () => {+ const userId = await person();+ await store.write(userId, "Write in British English.");++ await database.delete(users).where(eq(users.id, userId));++ expect(+ await database+ .select()+ .from(userInstructions)+ .where(eq(userInstructions.userId, userId)),+ ).toEqual([]);+ });+});