The open-source app everyone uses to manage agents at work
TypeScript acpxagent-orchestrationagent-skillsagentic-aiai-agentsai-engineeringai-governanceai-toolsautonomous-agentsclaudeclaude-codeclaude-skillscodexhermesllmmcpmulti-agentopenclawproject-managementworkflow-automation
feat(routines): add workspace-aware routine runs
dotta909e8cd4c8c4
diff --git a/cli/src/__tests__/routines.test.ts b/cli/src/__tests__/routines.test.tsnew file mode 100644index 0000000000..e24a2b5bba--- /dev/null+++ b/cli/src/__tests__/routines.test.ts@@ -0,0 +1,249 @@+import { randomUUID } from "node:crypto";+import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";+import os from "node:os";+import path from "node:path";+import { afterAll, afterEach, beforeAll, describe, expect, it } from "vitest";+import { eq } from "drizzle-orm";+import {+ agents,+ companies,+ createDb,+ projects,+ routines,+} from "@paperclipai/db";+import {+ getEmbeddedPostgresTestSupport,+ startEmbeddedPostgresTestDatabase,+} from "./helpers/embedded-postgres.js";+import { disableAllRoutinesInConfig } from "../commands/routines.js";++const embeddedPostgresSupport = await getEmbeddedPostgresTestSupport();+const describeEmbeddedPostgres = embeddedPostgresSupport.supported ? describe : describe.skip;++if (!embeddedPostgresSupport.supported) {+ console.warn(+ `Skipping embedded Postgres routines CLI tests on this host: ${embeddedPostgresSupport.reason ?? "unsupported environment"}`,+ );+}++function writeTestConfig(configPath: string, tempRoot: string, connectionString: string) {+ const config = {+ $meta: {+ version: 1,+ updatedAt: new Date().toISOString(),+ source: "doctor" as const,+ },+ database: {+ mode: "postgres" as const,+ connectionString,+ embeddedPostgresDataDir: path.join(tempRoot, "embedded-db"),+ embeddedPostgresPort: 54329,+ backup: {+ enabled: false,+ intervalMinutes: 60,+ retentionDays: 30,+ dir: path.join(tempRoot, "backups"),+ },+ },+ logging: {+ mode: "file" as const,+ logDir: path.join(tempRoot, "logs"),+ },+ server: {+ deploymentMode: "local_trusted" as const,+ exposure: "private" as const,+ host: "127.0.0.1",+ port: 3100,+ allowedHostnames: [],+ serveUi: false,+ },+ auth: {+ baseUrlMode: "auto" as const,+ disableSignUp: false,+ },+ storage: {+ provider: "local_disk" as const,+ localDisk: {+ baseDir: path.join(tempRoot, "storage"),+ },+ s3: {+ bucket: "paperclip",+ region: "us-east-1",+ prefix: "",+ forcePathStyle: false,+ },+ },+ secrets: {+ provider: "local_encrypted" as const,+ strictMode: false,+ localEncrypted: {+ keyFilePath: path.join(tempRoot, "secrets", "master.key"),+ },+ },+ };++ mkdirSync(path.dirname(configPath), { recursive: true });+ writeFileSync(configPath, `${JSON.stringify(config, null, 2)}\n`, "utf8");+}++describeEmbeddedPostgres("disableAllRoutinesInConfig", () => {+ let db!: ReturnType<typeof createDb>;+ let tempDb: Awaited<ReturnType<typeof startEmbeddedPostgresTestDatabase>> | null = null;+ let tempRoot = "";+ let configPath = "";++ beforeAll(async () => {+ tempDb = await startEmbeddedPostgresTestDatabase("paperclip-routines-cli-db-");+ db = createDb(tempDb.connectionString);+ tempRoot = mkdtempSync(path.join(os.tmpdir(), "paperclip-routines-cli-config-"));+ configPath = path.join(tempRoot, "config.json");+ writeTestConfig(configPath, tempRoot, tempDb.connectionString);+ }, 20_000);++ afterEach(async () => {+ await db.delete(routines);+ await db.delete(projects);+ await db.delete(agents);+ await db.delete(companies);+ });++ afterAll(async () => {+ await tempDb?.cleanup();+ if (tempRoot) {+ rmSync(tempRoot, { recursive: true, force: true });+ }+ });++ it("pauses only non-archived routines for the selected company", async () => {+ const companyId = randomUUID();+ const otherCompanyId = randomUUID();+ const projectId = randomUUID();+ const otherProjectId = randomUUID();+ const agentId = randomUUID();+ const otherAgentId = randomUUID();+ const activeRoutineId = randomUUID();+ const pausedRoutineId = randomUUID();+ const archivedRoutineId = randomUUID();+ const otherCompanyRoutineId = randomUUID();++ await db.insert(companies).values([+ {+ id: companyId,+ name: "Paperclip",+ issuePrefix: `T${companyId.replace(/-/g, "").slice(0, 6).toUpperCase()}`,+ requireBoardApprovalForNewAgents: false,+ },+ {+ id: otherCompanyId,+ name: "Other company",+ issuePrefix: `T${otherCompanyId.replace(/-/g, "").slice(0, 6).toUpperCase()}`,+ requireBoardApprovalForNewAgents: false,+ },+ ]);++ await db.insert(agents).values([+ {+ id: agentId,+ companyId,+ name: "Coder",+ adapterType: "process",+ adapterConfig: {},+ runtimeConfig: {},+ permissions: {},+ },+ {+ id: otherAgentId,+ companyId: otherCompanyId,+ name: "Other coder",+ adapterType: "process",+ adapterConfig: {},+ runtimeConfig: {},+ permissions: {},+ },+ ]);++ await db.insert(projects).values([+ {+ id: projectId,+ companyId,+ name: "Project",+ status: "in_progress",+ },+ {+ id: otherProjectId,+ companyId: otherCompanyId,+ name: "Other project",+ status: "in_progress",+ },+ ]);++ await db.insert(routines).values([+ {+ id: activeRoutineId,+ companyId,+ projectId,+ assigneeAgentId: agentId,+ title: "Active routine",+ status: "active",+ },+ {+ id: pausedRoutineId,+ companyId,+ projectId,+ assigneeAgentId: agentId,+ title: "Paused routine",+ status: "paused",+ },+ {+ id: archivedRoutineId,+ companyId,+ projectId,+ assigneeAgentId: agentId,+ title: "Archived routine",+ status: "archived",+ },+ {+ id: otherCompanyRoutineId,+ companyId: otherCompanyId,+ projectId: otherProjectId,+ assigneeAgentId: otherAgentId,+ title: "Other company routine",+ status: "active",+ },+ ]);++ const result = await disableAllRoutinesInConfig({+ config: configPath,+ companyId,+ });++ expect(result).toMatchObject({+ companyId,+ totalRoutines: 3,+ pausedCount: 1,+ alreadyPausedCount: 1,+ archivedCount: 1,+ });++ const companyRoutines = await db+ .select({+ id: routines.id,+ status: routines.status,+ })+ .from(routines)+ .where(eq(routines.companyId, companyId));+ const statusById = new Map(companyRoutines.map((routine) => [routine.id, routine.status]));++ expect(statusById.get(activeRoutineId)).toBe("paused");+ expect(statusById.get(pausedRoutineId)).toBe("paused");+ expect(statusById.get(archivedRoutineId)).toBe("archived");++ const otherCompanyRoutine = await db+ .select({+ status: routines.status,+ })+ .from(routines)+ .where(eq(routines.id, otherCompanyRoutineId));+ expect(otherCompanyRoutine[0]?.status).toBe("active");+ });+});diff --git a/cli/src/commands/routines.ts b/cli/src/commands/routines.tsnew file mode 100644index 0000000000..348f7b00ff--- /dev/null+++ b/cli/src/commands/routines.ts@@ -0,0 +1,348 @@+import fs from "node:fs";+import net from "node:net";+import path from "node:path";+import { Command } from "commander";+import pc from "picocolors";+import {+ applyPendingMigrations,+ createDb,+ createEmbeddedPostgresLogBuffer,+ ensurePostgresDatabase,+ formatEmbeddedPostgresError,+ routines,+} from "@paperclipai/db";+import { eq, inArray } from "drizzle-orm";+import { loadPaperclipEnvFile } from "../config/env.js";+import { readConfig, resolveConfigPath } from "../config/store.js";++type RoutinesDisableAllOptions = {+ config?: string;+ dataDir?: string;+ companyId?: string;+ json?: boolean;+};++type DisableAllRoutinesResult = {+ companyId: string;+ totalRoutines: number;+ pausedCount: number;+ alreadyPausedCount: number;+ archivedCount: number;+};++type EmbeddedPostgresInstance = {+ initialise(): Promise<void>;+ start(): Promise<void>;+ stop(): Promise<void>;+};++type EmbeddedPostgresCtor = new (opts: {+ databaseDir: string;+ user: string;+ password: string;+ port: number;+ persistent: boolean;+ initdbFlags?: string[];+ onLog?: (message: unknown) => void;+ onError?: (message: unknown) => void;+}) => EmbeddedPostgresInstance;++type EmbeddedPostgresHandle = {+ port: number;+ startedByThisProcess: boolean;+ stop: () => Promise<void>;+};++type ClosableDb = ReturnType<typeof createDb> & {+ $client?: {+ end?: (options?: { timeout?: number }) => Promise<void>;+ };+};++function nonEmpty(value: string | null | undefined): string | null {+ return typeof value === "string" && value.trim().length > 0 ? value.trim() : null;+}++async function isPortAvailable(port: number): Promise<boolean> {+ return await new Promise<boolean>((resolve) => {+ const server = net.createServer();+ server.unref();+ server.once("error", () => resolve(false));+ server.listen(port, "127.0.0.1", () => {+ server.close(() => resolve(true));+ });+ });+}++async function findAvailablePort(preferredPort: number): Promise<number> {+ let port = Math.max(1, Math.trunc(preferredPort));+ while (!(await isPortAvailable(port))) {+ port += 1;+ }+ return port;+}++function readPidFilePort(postmasterPidFile: string): number | null {+ if (!fs.existsSync(postmasterPidFile)) return null;+ try {+ const lines = fs.readFileSync(postmasterPidFile, "utf8").split("\n");+ const port = Number(lines[3]?.trim());+ return Number.isInteger(port) && port > 0 ? port : null;+ } catch {+ return null;+ }+}++function readRunningPostmasterPid(postmasterPidFile: string): number | null {+ if (!fs.existsSync(postmasterPidFile)) return null;+ try {+ const pid = Number(fs.readFileSync(postmasterPidFile, "utf8").split("\n")[0]?.trim());+ if (!Number.isInteger(pid) || pid <= 0) return null;+ process.kill(pid, 0);+ return pid;+ } catch {+ return null;+ }+}++async function ensureEmbeddedPostgres(dataDir: string, preferredPort: number): Promise<EmbeddedPostgresHandle> {+ const moduleName = "embedded-postgres";+ let EmbeddedPostgres: EmbeddedPostgresCtor;+ try {+ const mod = await import(moduleName);+ EmbeddedPostgres = mod.default as EmbeddedPostgresCtor;+ } catch {+ throw new Error(+ "Embedded PostgreSQL support requires dependency `embedded-postgres`. Reinstall dependencies and try again.",+ );+ }++ const postmasterPidFile = path.resolve(dataDir, "postmaster.pid");+ const runningPid = readRunningPostmasterPid(postmasterPidFile);+ if (runningPid) {+ return {+ port: readPidFilePort(postmasterPidFile) ?? preferredPort,+ startedByThisProcess: false,+ stop: async () => {},+ };+ }++ const port = await findAvailablePort(preferredPort);+ const logBuffer = createEmbeddedPostgresLogBuffer();+ const instance = new EmbeddedPostgres({+ databaseDir: dataDir,+ user: "paperclip",+ password: "paperclip",+ port,+ persistent: true,+ initdbFlags: ["--encoding=UTF8", "--locale=C", "--lc-messages=C"],+ onLog: logBuffer.append,+ onError: logBuffer.append,+ });++ if (!fs.existsSync(path.resolve(dataDir, "PG_VERSION"))) {+ try {+ await instance.initialise();+ } catch (error) {+ throw formatEmbeddedPostgresError(error, {+ fallbackMessage: `Failed to initialize embedded PostgreSQL cluster in ${dataDir} on port ${port}`,+ recentLogs: logBuffer.getRecentLogs(),+ });+ }+ }++ if (fs.existsSync(postmasterPidFile)) {+ fs.rmSync(postmasterPidFile, { force: true });+ }++ try {+ await instance.start();+ } catch (error) {+ throw formatEmbeddedPostgresError(error, {+ fallbackMessage: `Failed to start embedded PostgreSQL on port ${port}`,+ recentLogs: logBuffer.getRecentLogs(),+ });+ }++ return {+ port,+ startedByThisProcess: true,+ stop: async () => {+ await instance.stop();+ },+ };+}++async function closeDb(db: ClosableDb): Promise<void> {+ await db.$client?.end?.({ timeout: 5 }).catch(() => undefined);+}++async function openConfiguredDb(configPath: string): Promise<{+ db: ClosableDb;+ stop: () => Promise<void>;+}> {+ const config = readConfig(configPath);+ if (!config) {+ throw new Error(`Config not found at ${configPath}.`);+ }++ let embeddedHandle: EmbeddedPostgresHandle | null = null;+ try {+ if (config.database.mode === "embedded-postgres") {+ embeddedHandle = await ensureEmbeddedPostgres(+ config.database.embeddedPostgresDataDir,+ config.database.embeddedPostgresPort,+ );+ const adminConnectionString = `postgres://paperclip:[email protected]:${embeddedHandle.port}/postgres`;+ await ensurePostgresDatabase(adminConnectionString, "paperclip");+ const connectionString = `postgres://paperclip:[email protected]:${embeddedHandle.port}/paperclip`;+ await applyPendingMigrations(connectionString);+ return {+ db: createDb(connectionString) as ClosableDb,+ stop: async () => {+ await closeDb(createDb(connectionString) as ClosableDb);+ },+ };+ }++ const connectionString = nonEmpty(config.database.connectionString);+ if (!connectionString) {+ throw new Error(`Config at ${configPath} does not define a database connection string.`);+ }++ await applyPendingMigrations(connectionString);+ const db = createDb(connectionString) as ClosableDb;+ return {+ db,+ stop: async () => {+ await closeDb(db);+ },+ };+ } catch (error) {+ if (embeddedHandle?.startedByThisProcess) {+ await embeddedHandle.stop().catch(() => undefined);+ }+ throw error;+ }+}++export async function disableAllRoutinesInConfig(+ options: Pick<RoutinesDisableAllOptions, "config" | "companyId">,+): Promise<DisableAllRoutinesResult> {+ const configPath = resolveConfigPath(options.config);+ loadPaperclipEnvFile(configPath);+ const companyId =+ nonEmpty(options.companyId)+ ?? nonEmpty(process.env.PAPERCLIP_COMPANY_ID)+ ?? null;+ if (!companyId) {+ throw new Error("Company ID is required. Pass --company-id or set PAPERCLIP_COMPANY_ID.");+ }++ const config = readConfig(configPath);+ if (!config) {+ throw new Error(`Config not found at ${configPath}.`);+ }++ let embeddedHandle: EmbeddedPostgresHandle | null = null;+ let db: ClosableDb | null = null;+ try {+ if (config.database.mode === "embedded-postgres") {+ embeddedHandle = await ensureEmbeddedPostgres(+ config.database.embeddedPostgresDataDir,+ config.database.embeddedPostgresPort,+ );+ const adminConnectionString = `postgres://paperclip:[email protected]:${embeddedHandle.port}/postgres`;+ await ensurePostgresDatabase(adminConnectionString, "paperclip");+ const connectionString = `postgres://paperclip:[email protected]:${embeddedHandle.port}/paperclip`;+ await applyPendingMigrations(connectionString);+ db = createDb(connectionString) as ClosableDb;+ } else {+ const connectionString = nonEmpty(config.database.connectionString);+ if (!connectionString) {+ throw new Error(`Config at ${configPath} does not define a database connection string.`);+ }+ await applyPendingMigrations(connectionString);+ db = createDb(connectionString) as ClosableDb;+ }++ const existing = await db+ .select({+ id: routines.id,+ status: routines.status,+ })+ .from(routines)+ .where(eq(routines.companyId, companyId));++ const alreadyPausedCount = existing.filter((routine) => routine.status === "paused").length;+ const archivedCount = existing.filter((routine) => routine.status === "archived").length;+ const idsToPause = existing+ .filter((routine) => routine.status !== "paused" && routine.status !== "archived")+ .map((routine) => routine.id);++ if (idsToPause.length > 0) {+ await db+ .update(routines)+ .set({+ status: "paused",+ updatedAt: new Date(),+ })+ .where(inArray(routines.id, idsToPause));+ }++ return {+ companyId,+ totalRoutines: existing.length,+ pausedCount: idsToPause.length,+ alreadyPausedCount,+ archivedCount,+ };+ } finally {+ if (db) {+ await closeDb(db);+ }+ if (embeddedHandle?.startedByThisProcess) {+ await embeddedHandle.stop().catch(() => undefined);+ }+ }+}++export async function disableAllRoutinesCommand(options: RoutinesDisableAllOptions): Promise<void> {+ const result = await disableAllRoutinesInConfig(options);++ if (options.json) {+ console.log(JSON.stringify(result, null, 2));+ return;+ }++ if (result.totalRoutines === 0) {+ console.log(pc.dim(`No routines found for company ${result.companyId}.`));+ return;+ }++ console.log(+ `Paused ${result.pausedCount} routine(s) for company ${result.companyId} ` ++ `(${result.alreadyPausedCount} already paused, ${result.archivedCount} archived).`,+ );+}++export function registerRoutineCommands(program: Command): void {+ const routinesCommand = program.command("routines").description("Local routine maintenance commands");++ routinesCommand+ .command("disable-all")+ .description("Pause all non-archived routines in the configured local instance for one company")+ .option("-c, --config <path>", "Path to config file")+ .option("-d, --data-dir <path>", "Paperclip data directory root (isolates state from ~/.paperclip)")+ .option("-C, --company-id <id>", "Company ID")+ .option("--json", "Output raw JSON")+ .action(async (opts: RoutinesDisableAllOptions) => {+ try {+ await disableAllRoutinesCommand(opts);+ } catch (error) {+ const message = error instanceof Error ? error.message : String(error);+ console.error(pc.red(message));+ process.exit(1);+ }+ });+}diff --git a/cli/src/index.ts b/cli/src/index.tsindex adec4cb1ec..1173945961 100644--- a/cli/src/index.ts+++ b/cli/src/index.ts@@ -15,6 +15,7 @@ import { registerAgentCommands } from "./commands/client/agent.js";import { registerApprovalCommands } from "./commands/client/approval.js";import { registerActivityCommands } from "./commands/client/activity.js";import { registerDashboardCommands } from "./commands/client/dashboard.js";+import { registerRoutineCommands } from "./commands/routines.js";import { registerFeedbackCommands } from "./commands/client/feedback.js";import { applyDataDirOverride, type DataDirOptionLike } from "./config/data-dir.js";import { loadPaperclipEnvFile } from "./config/env.js";@@ -141,6 +142,7 @@ registerAgentCommands(program);registerApprovalCommands(program);registerActivityCommands(program);registerDashboardCommands(program);+registerRoutineCommands(program);registerFeedbackCommands(program);registerWorktreeCommands(program);registerPluginCommands(program);diff --git a/packages/db/package.json b/packages/db/package.jsonindex e879d3de20..5a5b0d51d2 100644--- a/packages/db/package.json+++ b/packages/db/package.json@@ -35,11 +35,12 @@"dist"],"scripts": {- "build": "tsc && cp -r src/migrations dist/migrations",+ "check:migrations": "tsx src/check-migration-numbering.ts",+ "build": "pnpm run check:migrations && tsc && cp -r src/migrations dist/migrations","clean": "rm -rf dist",- "typecheck": "tsc --noEmit",- "generate": "tsc -p tsconfig.json && drizzle-kit generate",- "migrate": "tsx src/migrate.ts",+ "typecheck": "pnpm run check:migrations && tsc --noEmit",+ "generate": "pnpm run check:migrations && tsc -p tsconfig.json && drizzle-kit generate",+ "migrate": "pnpm run check:migrations && tsx src/migrate.ts","seed": "tsx src/seed.ts"},"dependencies": {diff --git a/packages/db/src/check-migration-numbering.ts b/packages/db/src/check-migration-numbering.tsnew file mode 100644index 0000000000..f1799d4ef1--- /dev/null+++ b/packages/db/src/check-migration-numbering.ts@@ -0,0 +1,89 @@+import { readdir, readFile } from "node:fs/promises";+import { fileURLToPath } from "node:url";++const migrationsDir = fileURLToPath(new URL("./migrations", import.meta.url));+const journalPath = fileURLToPath(new URL("./migrations/meta/_journal.json", import.meta.url));++type JournalFile = {+ entries?: Array<{+ idx?: number;+ tag?: string;+ }>;+};++function migrationNumber(value: string): string | null {+ const match = value.match(/^(\d{4})_/);+ return match ? match[1] : null;+}++function ensureNoDuplicates(values: string[], label: string) {+ const seen = new Map<string, string>();++ for (const value of values) {+ const number = migrationNumber(value);+ if (!number) {+ throw new Error(`${label} entry does not start with a 4-digit migration number: ${value}`);+ }+ const existing = seen.get(number);+ if (existing) {+ throw new Error(`Duplicate migration number ${number} in ${label}: ${existing}, ${value}`);+ }+ seen.set(number, value);+ }+}++function ensureStrictlyOrdered(values: string[], label: string) {+ const sorted = [...values].sort();+ for (let index = 0; index < values.length; index += 1) {+ if (values[index] !== sorted[index]) {+ throw new Error(+ `${label} are out of order at position ${index}: expected ${sorted[index]}, found ${values[index]}`,+ );+ }+ }+}++function ensureJournalMatchesFiles(migrationFiles: string[], journalTags: string[]) {+ const journalFiles = journalTags.map((tag) => `${tag}.sql`);++ if (journalFiles.length !== migrationFiles.length) {+ throw new Error(+ `Migration journal/file count mismatch: journal has ${journalFiles.length}, files have ${migrationFiles.length}`,+ );+ }++ for (let index = 0; index < migrationFiles.length; index += 1) {+ const migrationFile = migrationFiles[index];+ const journalFile = journalFiles[index];+ if (migrationFile !== journalFile) {+ throw new Error(+ `Migration journal/file order mismatch at position ${index}: journal has ${journalFile}, files have ${migrationFile}`,+ );+ }+ }+}++async function main() {+ const migrationFiles = (await readdir(migrationsDir))+ .filter((entry) => entry.endsWith(".sql"))+ .sort();++ ensureNoDuplicates(migrationFiles, "migration files");+ ensureStrictlyOrdered(migrationFiles, "migration files");++ const rawJournal = await readFile(journalPath, "utf8");+ const journal = JSON.parse(rawJournal) as JournalFile;+ const journalTags = (journal.entries ?? [])+ .map((entry, index) => {+ if (typeof entry.tag !== "string" || entry.tag.length === 0) {+ throw new Error(`Migration journal entry ${index} is missing a tag`);+ }+ return entry.tag;+ });++ ensureNoDuplicates(journalTags, "migration journal");+ ensureStrictlyOrdered(journalTags, "migration journal");+ ensureJournalMatchesFiles(migrationFiles, journalTags);+}++await main();diff --git a/packages/db/src/client.test.ts b/packages/db/src/client.test.tsindex 6dc5c83fa4..64b1caf1f7 100644--- a/packages/db/src/client.test.ts+++ b/packages/db/src/client.test.ts@@ -305,6 +305,99 @@ describeEmbeddedPostgres("applyPendingMigrations", () => {const finalState = await inspectMigrations(connectionString);expect(finalState.status).toBe("upToDate");++ const verifySql = postgres(connectionString, { max: 1, onnotice: () => {} });+ try {+ const constraints = await verifySql.unsafe<{ conname: string }[]>(+ `+ SELECT conname+ FROM pg_constraint+ WHERE conname IN (+ 'feedback_exports_company_id_companies_id_fk',+ 'feedback_exports_feedback_vote_id_feedback_votes_id_fk',+ 'feedback_exports_issue_id_issues_id_fk',+ 'feedback_votes_company_id_companies_id_fk',+ 'feedback_votes_issue_id_issues_id_fk'+ )+ ORDER BY conname+ `,+ );+ expect(constraints.map((row) => row.conname)).toEqual([+ "feedback_exports_company_id_companies_id_fk",+ "feedback_exports_feedback_vote_id_feedback_votes_id_fk",+ "feedback_exports_issue_id_issues_id_fk",+ "feedback_votes_company_id_companies_id_fk",+ "feedback_votes_issue_id_issues_id_fk",+ ]);+ } finally {+ await verifySql.end();+ }+ },+ 20_000,+ );++ it(+ "replays migration 0048 safely when routines.variables already exists",+ async () => {+ const connectionString = await createTempDatabase();++ await applyPendingMigrations(connectionString);++ const sql = postgres(connectionString, { max: 1, onnotice: () => {} });+ try {+ const flashyMarrowHash = await migrationHash("0048_flashy_marrow.sql");++ await sql.unsafe(+ `DELETE FROM "drizzle"."__drizzle_migrations" WHERE hash = '${flashyMarrowHash}'`,+ );++ const columns = await sql.unsafe<{ column_name: string }[]>(+ `+ SELECT column_name+ FROM information_schema.columns+ WHERE table_schema = 'public'+ AND table_name = 'routines'+ AND column_name = 'variables'+ `,+ );+ expect(columns).toHaveLength(1);+ } finally {+ await sql.end();+ }++ const pendingState = await inspectMigrations(connectionString);+ expect(pendingState).toMatchObject({+ status: "needsMigrations",+ pendingMigrations: ["0048_flashy_marrow.sql"],+ reason: "pending-migrations",+ });++ await applyPendingMigrations(connectionString);++ const finalState = await inspectMigrations(connectionString);+ expect(finalState.status).toBe("upToDate");++ const verifySql = postgres(connectionString, { max: 1, onnotice: () => {} });+ try {+ const columns = await verifySql.unsafe<{ column_name: string; is_nullable: string; data_type: string }[]>(+ `+ SELECT column_name, is_nullable, data_type+ FROM information_schema.columns+ WHERE table_schema = 'public'+ AND table_name = 'routines'+ AND column_name = 'variables'+ `,+ );+ expect(columns).toEqual([+ expect.objectContaining({+ column_name: "variables",+ is_nullable: "NO",+ data_type: "jsonb",+ }),+ ]);+ } finally {+ await verifySql.end();+ }},20_000,);diff --git a/packages/db/src/migrations/0048_flashy_marrow.sql b/packages/db/src/migrations/0048_flashy_marrow.sqlnew file mode 100644index 0000000000..be81d8a35e--- /dev/null+++ b/packages/db/src/migrations/0048_flashy_marrow.sql@@ -0,0 +1 @@+ALTER TABLE "routines" ADD COLUMN IF NOT EXISTS "variables" jsonb DEFAULT '[]'::jsonb NOT NULL;diff --git a/packages/db/src/migrations/meta/0048_snapshot.json b/packages/db/src/migrations/meta/0048_snapshot.jsonnew file mode 100644index 0000000000..4b699f933e--- /dev/null+++ b/packages/db/src/migrations/meta/0048_snapshot.json@@ -0,0 +1,12546 @@+{+ "id": "685fdfd9-6d11-440d-b468-fac28279fa46",+ "prevId": "a0553dd4-5278-406f-bef7-b06597f92cf2",+ "version": "7",+ "dialect": "postgresql",+ "tables": {+ "public.activity_log": {+ "name": "activity_log",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "uuid",+ "primaryKey": true,+ "notNull": true,+ "default": "gen_random_uuid()"+ },+ "company_id": {+ "name": "company_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": true+ },+ "actor_type": {+ "name": "actor_type",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "'system'"+ },+ "actor_id": {+ "name": "actor_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "action": {+ "name": "action",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "entity_type": {+ "name": "entity_type",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "entity_id": {+ "name": "entity_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "agent_id": {+ "name": "agent_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": false+ },+ "run_id": {+ "name": "run_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": false+ },+ "details": {+ "name": "details",+ "type": "jsonb",+ "primaryKey": false,+ "notNull": false+ },+ "created_at": {+ "name": "created_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {+ "activity_log_company_created_idx": {+ "name": "activity_log_company_created_idx",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "created_at",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "activity_log_run_id_idx": {+ "name": "activity_log_run_id_idx",+ "columns": [+ {+ "expression": "run_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "activity_log_entity_type_id_idx": {+ "name": "activity_log_entity_type_id_idx",+ "columns": [+ {+ "expression": "entity_type",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "entity_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "activity_log_company_id_companies_id_fk": {+ "name": "activity_log_company_id_companies_id_fk",+ "tableFrom": "activity_log",+ "tableTo": "companies",+ "columnsFrom": [+ "company_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ },+ "activity_log_agent_id_agents_id_fk": {+ "name": "activity_log_agent_id_agents_id_fk",+ "tableFrom": "activity_log",+ "tableTo": "agents",+ "columnsFrom": [+ "agent_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ },+ "activity_log_run_id_heartbeat_runs_id_fk": {+ "name": "activity_log_run_id_heartbeat_runs_id_fk",+ "tableFrom": "activity_log",+ "tableTo": "heartbeat_runs",+ "columnsFrom": [+ "run_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.agent_api_keys": {+ "name": "agent_api_keys",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "uuid",+ "primaryKey": true,+ "notNull": true,+ "default": "gen_random_uuid()"+ },+ "agent_id": {+ "name": "agent_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": true+ },+ "company_id": {+ "name": "company_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": true+ },+ "name": {+ "name": "name",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "key_hash": {+ "name": "key_hash",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "last_used_at": {+ "name": "last_used_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": false+ },+ "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()"+ }+ },+ "indexes": {+ "agent_api_keys_key_hash_idx": {+ "name": "agent_api_keys_key_hash_idx",+ "columns": [+ {+ "expression": "key_hash",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "agent_api_keys_company_agent_idx": {+ "name": "agent_api_keys_company_agent_idx",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "agent_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "agent_api_keys_agent_id_agents_id_fk": {+ "name": "agent_api_keys_agent_id_agents_id_fk",+ "tableFrom": "agent_api_keys",+ "tableTo": "agents",+ "columnsFrom": [+ "agent_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ },+ "agent_api_keys_company_id_companies_id_fk": {+ "name": "agent_api_keys_company_id_companies_id_fk",+ "tableFrom": "agent_api_keys",+ "tableTo": "companies",+ "columnsFrom": [+ "company_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.agent_config_revisions": {+ "name": "agent_config_revisions",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "uuid",+ "primaryKey": true,+ "notNull": true,+ "default": "gen_random_uuid()"+ },+ "company_id": {+ "name": "company_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": true+ },+ "agent_id": {+ "name": "agent_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": true+ },+ "created_by_agent_id": {+ "name": "created_by_agent_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": false+ },+ "created_by_user_id": {+ "name": "created_by_user_id",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "source": {+ "name": "source",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "'patch'"+ },+ "rolled_back_from_revision_id": {+ "name": "rolled_back_from_revision_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": false+ },+ "changed_keys": {+ "name": "changed_keys",+ "type": "jsonb",+ "primaryKey": false,+ "notNull": true,+ "default": "'[]'::jsonb"+ },+ "before_config": {+ "name": "before_config",+ "type": "jsonb",+ "primaryKey": false,+ "notNull": true+ },+ "after_config": {+ "name": "after_config",+ "type": "jsonb",+ "primaryKey": false,+ "notNull": true+ },+ "created_at": {+ "name": "created_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {+ "agent_config_revisions_company_agent_created_idx": {+ "name": "agent_config_revisions_company_agent_created_idx",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "agent_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "created_at",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "agent_config_revisions_agent_created_idx": {+ "name": "agent_config_revisions_agent_created_idx",+ "columns": [+ {+ "expression": "agent_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "created_at",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "agent_config_revisions_company_id_companies_id_fk": {+ "name": "agent_config_revisions_company_id_companies_id_fk",+ "tableFrom": "agent_config_revisions",+ "tableTo": "companies",+ "columnsFrom": [+ "company_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ },+ "agent_config_revisions_agent_id_agents_id_fk": {+ "name": "agent_config_revisions_agent_id_agents_id_fk",+ "tableFrom": "agent_config_revisions",+ "tableTo": "agents",+ "columnsFrom": [+ "agent_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "agent_config_revisions_created_by_agent_id_agents_id_fk": {+ "name": "agent_config_revisions_created_by_agent_id_agents_id_fk",+ "tableFrom": "agent_config_revisions",+ "tableTo": "agents",+ "columnsFrom": [+ "created_by_agent_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "set null",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.agent_runtime_state": {+ "name": "agent_runtime_state",+ "schema": "",+ "columns": {+ "agent_id": {+ "name": "agent_id",+ "type": "uuid",+ "primaryKey": true,+ "notNull": true+ },+ "company_id": {+ "name": "company_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": true+ },+ "adapter_type": {+ "name": "adapter_type",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "session_id": {+ "name": "session_id",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "state_json": {+ "name": "state_json",+ "type": "jsonb",+ "primaryKey": false,+ "notNull": true,+ "default": "'{}'::jsonb"+ },+ "last_run_id": {+ "name": "last_run_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": false+ },+ "last_run_status": {+ "name": "last_run_status",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "total_input_tokens": {+ "name": "total_input_tokens",+ "type": "bigint",+ "primaryKey": false,+ "notNull": true,+ "default": 0+ },+ "total_output_tokens": {+ "name": "total_output_tokens",+ "type": "bigint",+ "primaryKey": false,+ "notNull": true,+ "default": 0+ },+ "total_cached_input_tokens": {+ "name": "total_cached_input_tokens",+ "type": "bigint",+ "primaryKey": false,+ "notNull": true,+ "default": 0+ },+ "total_cost_cents": {+ "name": "total_cost_cents",+ "type": "bigint",+ "primaryKey": false,+ "notNull": true,+ "default": 0+ },+ "last_error": {+ "name": "last_error",+ "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": {+ "agent_runtime_state_company_agent_idx": {+ "name": "agent_runtime_state_company_agent_idx",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "agent_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "agent_runtime_state_company_updated_idx": {+ "name": "agent_runtime_state_company_updated_idx",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "updated_at",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "agent_runtime_state_agent_id_agents_id_fk": {+ "name": "agent_runtime_state_agent_id_agents_id_fk",+ "tableFrom": "agent_runtime_state",+ "tableTo": "agents",+ "columnsFrom": [+ "agent_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ },+ "agent_runtime_state_company_id_companies_id_fk": {+ "name": "agent_runtime_state_company_id_companies_id_fk",+ "tableFrom": "agent_runtime_state",+ "tableTo": "companies",+ "columnsFrom": [+ "company_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.agent_task_sessions": {+ "name": "agent_task_sessions",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "uuid",+ "primaryKey": true,+ "notNull": true,+ "default": "gen_random_uuid()"+ },+ "company_id": {+ "name": "company_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": true+ },+ "agent_id": {+ "name": "agent_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": true+ },+ "adapter_type": {+ "name": "adapter_type",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "task_key": {+ "name": "task_key",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "session_params_json": {+ "name": "session_params_json",+ "type": "jsonb",+ "primaryKey": false,+ "notNull": false+ },+ "session_display_id": {+ "name": "session_display_id",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "last_run_id": {+ "name": "last_run_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": false+ },+ "last_error": {+ "name": "last_error",+ "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": {+ "agent_task_sessions_company_agent_adapter_task_uniq": {+ "name": "agent_task_sessions_company_agent_adapter_task_uniq",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "agent_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "adapter_type",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "task_key",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": true,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "agent_task_sessions_company_agent_updated_idx": {+ "name": "agent_task_sessions_company_agent_updated_idx",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "agent_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "updated_at",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "agent_task_sessions_company_task_updated_idx": {+ "name": "agent_task_sessions_company_task_updated_idx",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "task_key",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "updated_at",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "agent_task_sessions_company_id_companies_id_fk": {+ "name": "agent_task_sessions_company_id_companies_id_fk",+ "tableFrom": "agent_task_sessions",+ "tableTo": "companies",+ "columnsFrom": [+ "company_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ },+ "agent_task_sessions_agent_id_agents_id_fk": {+ "name": "agent_task_sessions_agent_id_agents_id_fk",+ "tableFrom": "agent_task_sessions",+ "tableTo": "agents",+ "columnsFrom": [+ "agent_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ },+ "agent_task_sessions_last_run_id_heartbeat_runs_id_fk": {+ "name": "agent_task_sessions_last_run_id_heartbeat_runs_id_fk",+ "tableFrom": "agent_task_sessions",+ "tableTo": "heartbeat_runs",+ "columnsFrom": [+ "last_run_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.agent_wakeup_requests": {+ "name": "agent_wakeup_requests",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "uuid",+ "primaryKey": true,+ "notNull": true,+ "default": "gen_random_uuid()"+ },+ "company_id": {+ "name": "company_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": true+ },+ "agent_id": {+ "name": "agent_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": true+ },+ "source": {+ "name": "source",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "trigger_detail": {+ "name": "trigger_detail",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "reason": {+ "name": "reason",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "payload": {+ "name": "payload",+ "type": "jsonb",+ "primaryKey": false,+ "notNull": false+ },+ "status": {+ "name": "status",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "'queued'"+ },+ "coalesced_count": {+ "name": "coalesced_count",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "default": 0+ },+ "requested_by_actor_type": {+ "name": "requested_by_actor_type",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "requested_by_actor_id": {+ "name": "requested_by_actor_id",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "idempotency_key": {+ "name": "idempotency_key",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "run_id": {+ "name": "run_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": false+ },+ "requested_at": {+ "name": "requested_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ },+ "claimed_at": {+ "name": "claimed_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": false+ },+ "finished_at": {+ "name": "finished_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": false+ },+ "error": {+ "name": "error",+ "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": {+ "agent_wakeup_requests_company_agent_status_idx": {+ "name": "agent_wakeup_requests_company_agent_status_idx",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "agent_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "status",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "agent_wakeup_requests_company_requested_idx": {+ "name": "agent_wakeup_requests_company_requested_idx",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "requested_at",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "agent_wakeup_requests_agent_requested_idx": {+ "name": "agent_wakeup_requests_agent_requested_idx",+ "columns": [+ {+ "expression": "agent_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "requested_at",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "agent_wakeup_requests_company_id_companies_id_fk": {+ "name": "agent_wakeup_requests_company_id_companies_id_fk",+ "tableFrom": "agent_wakeup_requests",+ "tableTo": "companies",+ "columnsFrom": [+ "company_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ },+ "agent_wakeup_requests_agent_id_agents_id_fk": {+ "name": "agent_wakeup_requests_agent_id_agents_id_fk",+ "tableFrom": "agent_wakeup_requests",+ "tableTo": "agents",+ "columnsFrom": [+ "agent_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.agents": {+ "name": "agents",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "uuid",+ "primaryKey": true,+ "notNull": true,+ "default": "gen_random_uuid()"+ },+ "company_id": {+ "name": "company_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": true+ },+ "name": {+ "name": "name",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "role": {+ "name": "role",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "'general'"+ },+ "title": {+ "name": "title",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "icon": {+ "name": "icon",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "status": {+ "name": "status",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "'idle'"+ },+ "reports_to": {+ "name": "reports_to",+ "type": "uuid",+ "primaryKey": false,+ "notNull": false+ },+ "capabilities": {+ "name": "capabilities",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "adapter_type": {+ "name": "adapter_type",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "'process'"+ },+ "adapter_config": {+ "name": "adapter_config",+ "type": "jsonb",+ "primaryKey": false,+ "notNull": true,+ "default": "'{}'::jsonb"+ },+ "runtime_config": {+ "name": "runtime_config",+ "type": "jsonb",+ "primaryKey": false,+ "notNull": true,+ "default": "'{}'::jsonb"+ },+ "budget_monthly_cents": {+ "name": "budget_monthly_cents",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "default": 0+ },+ "spent_monthly_cents": {+ "name": "spent_monthly_cents",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "default": 0+ },+ "pause_reason": {+ "name": "pause_reason",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "paused_at": {+ "name": "paused_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": false+ },+ "permissions": {+ "name": "permissions",+ "type": "jsonb",+ "primaryKey": false,+ "notNull": true,+ "default": "'{}'::jsonb"+ },+ "last_heartbeat_at": {+ "name": "last_heartbeat_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": false+ },+ "metadata": {+ "name": "metadata",+ "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": {+ "agents_company_status_idx": {+ "name": "agents_company_status_idx",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "status",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "agents_company_reports_to_idx": {+ "name": "agents_company_reports_to_idx",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "reports_to",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "agents_company_id_companies_id_fk": {+ "name": "agents_company_id_companies_id_fk",+ "tableFrom": "agents",+ "tableTo": "companies",+ "columnsFrom": [+ "company_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ },+ "agents_reports_to_agents_id_fk": {+ "name": "agents_reports_to_agents_id_fk",+ "tableFrom": "agents",+ "tableTo": "agents",+ "columnsFrom": [+ "reports_to"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.approval_comments": {+ "name": "approval_comments",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "uuid",+ "primaryKey": true,+ "notNull": true,+ "default": "gen_random_uuid()"+ },+ "company_id": {+ "name": "company_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": true+ },+ "approval_id": {+ "name": "approval_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": true+ },+ "author_agent_id": {+ "name": "author_agent_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": false+ },+ "author_user_id": {+ "name": "author_user_id",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "body": {+ "name": "body",+ "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": {+ "approval_comments_company_idx": {+ "name": "approval_comments_company_idx",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "approval_comments_approval_idx": {+ "name": "approval_comments_approval_idx",+ "columns": [+ {+ "expression": "approval_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "approval_comments_approval_created_idx": {+ "name": "approval_comments_approval_created_idx",+ "columns": [+ {+ "expression": "approval_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "created_at",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "approval_comments_company_id_companies_id_fk": {+ "name": "approval_comments_company_id_companies_id_fk",+ "tableFrom": "approval_comments",+ "tableTo": "companies",+ "columnsFrom": [+ "company_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ },+ "approval_comments_approval_id_approvals_id_fk": {+ "name": "approval_comments_approval_id_approvals_id_fk",+ "tableFrom": "approval_comments",+ "tableTo": "approvals",+ "columnsFrom": [+ "approval_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ },+ "approval_comments_author_agent_id_agents_id_fk": {+ "name": "approval_comments_author_agent_id_agents_id_fk",+ "tableFrom": "approval_comments",+ "tableTo": "agents",+ "columnsFrom": [+ "author_agent_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.approvals": {+ "name": "approvals",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "uuid",+ "primaryKey": true,+ "notNull": true,+ "default": "gen_random_uuid()"+ },+ "company_id": {+ "name": "company_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": true+ },+ "type": {+ "name": "type",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "requested_by_agent_id": {+ "name": "requested_by_agent_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": false+ },+ "requested_by_user_id": {+ "name": "requested_by_user_id",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "status": {+ "name": "status",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "'pending'"+ },+ "payload": {+ "name": "payload",+ "type": "jsonb",+ "primaryKey": false,+ "notNull": true+ },+ "decision_note": {+ "name": "decision_note",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "decided_by_user_id": {+ "name": "decided_by_user_id",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "decided_at": {+ "name": "decided_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": {+ "approvals_company_status_type_idx": {+ "name": "approvals_company_status_type_idx",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "status",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "type",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "approvals_company_id_companies_id_fk": {+ "name": "approvals_company_id_companies_id_fk",+ "tableFrom": "approvals",+ "tableTo": "companies",+ "columnsFrom": [+ "company_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ },+ "approvals_requested_by_agent_id_agents_id_fk": {+ "name": "approvals_requested_by_agent_id_agents_id_fk",+ "tableFrom": "approvals",+ "tableTo": "agents",+ "columnsFrom": [+ "requested_by_agent_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.assets": {+ "name": "assets",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "uuid",+ "primaryKey": true,+ "notNull": true,+ "default": "gen_random_uuid()"+ },+ "company_id": {+ "name": "company_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": true+ },+ "provider": {+ "name": "provider",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "object_key": {+ "name": "object_key",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "content_type": {+ "name": "content_type",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "byte_size": {+ "name": "byte_size",+ "type": "integer",+ "primaryKey": false,+ "notNull": true+ },+ "sha256": {+ "name": "sha256",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "original_filename": {+ "name": "original_filename",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "created_by_agent_id": {+ "name": "created_by_agent_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": false+ },+ "created_by_user_id": {+ "name": "created_by_user_id",+ "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": {+ "assets_company_created_idx": {+ "name": "assets_company_created_idx",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "created_at",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "assets_company_provider_idx": {+ "name": "assets_company_provider_idx",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "provider",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "assets_company_object_key_uq": {+ "name": "assets_company_object_key_uq",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "object_key",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": true,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "assets_company_id_companies_id_fk": {+ "name": "assets_company_id_companies_id_fk",+ "tableFrom": "assets",+ "tableTo": "companies",+ "columnsFrom": [+ "company_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ },+ "assets_created_by_agent_id_agents_id_fk": {+ "name": "assets_created_by_agent_id_agents_id_fk",+ "tableFrom": "assets",+ "tableTo": "agents",+ "columnsFrom": [+ "created_by_agent_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.account": {+ "name": "account",+ "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+ },+ "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+ },+ "updated_at": {+ "name": "updated_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true+ }+ },+ "indexes": {},+ "foreignKeys": {+ "account_user_id_user_id_fk": {+ "name": "account_user_id_user_id_fk",+ "tableFrom": "account",+ "tableTo": "user",+ "columnsFrom": [+ "user_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.session": {+ "name": "session",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true+ },+ "expires_at": {+ "name": "expires_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true+ },+ "token": {+ "name": "token",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "created_at": {+ "name": "created_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true+ },+ "updated_at": {+ "name": "updated_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+ },+ "user_id": {+ "name": "user_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ }+ },+ "indexes": {},+ "foreignKeys": {+ "session_user_id_user_id_fk": {+ "name": "session_user_id_user_id_fk",+ "tableFrom": "session",+ "tableTo": "user",+ "columnsFrom": [+ "user_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.user": {+ "name": "user",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true+ },+ "name": {+ "name": "name",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "email": {+ "name": "email",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "email_verified": {+ "name": "email_verified",+ "type": "boolean",+ "primaryKey": false,+ "notNull": true,+ "default": false+ },+ "image": {+ "name": "image",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "created_at": {+ "name": "created_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true+ },+ "updated_at": {+ "name": "updated_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true+ }+ },+ "indexes": {},+ "foreignKeys": {},+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.verification": {+ "name": "verification",+ "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": false+ },+ "updated_at": {+ "name": "updated_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": false+ }+ },+ "indexes": {},+ "foreignKeys": {},+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.board_api_keys": {+ "name": "board_api_keys",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "uuid",+ "primaryKey": true,+ "notNull": true,+ "default": "gen_random_uuid()"+ },+ "user_id": {+ "name": "user_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "name": {+ "name": "name",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "key_hash": {+ "name": "key_hash",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "last_used_at": {+ "name": "last_used_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": false+ },+ "revoked_at": {+ "name": "revoked_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": false+ },+ "expires_at": {+ "name": "expires_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": {+ "board_api_keys_key_hash_idx": {+ "name": "board_api_keys_key_hash_idx",+ "columns": [+ {+ "expression": "key_hash",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": true,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "board_api_keys_user_idx": {+ "name": "board_api_keys_user_idx",+ "columns": [+ {+ "expression": "user_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "board_api_keys_user_id_user_id_fk": {+ "name": "board_api_keys_user_id_user_id_fk",+ "tableFrom": "board_api_keys",+ "tableTo": "user",+ "columnsFrom": [+ "user_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.budget_incidents": {+ "name": "budget_incidents",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "uuid",+ "primaryKey": true,+ "notNull": true,+ "default": "gen_random_uuid()"+ },+ "company_id": {+ "name": "company_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": true+ },+ "policy_id": {+ "name": "policy_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": true+ },+ "scope_type": {+ "name": "scope_type",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "scope_id": {+ "name": "scope_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": true+ },+ "metric": {+ "name": "metric",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "window_kind": {+ "name": "window_kind",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "window_start": {+ "name": "window_start",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true+ },+ "window_end": {+ "name": "window_end",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true+ },+ "threshold_type": {+ "name": "threshold_type",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "amount_limit": {+ "name": "amount_limit",+ "type": "integer",+ "primaryKey": false,+ "notNull": true+ },+ "amount_observed": {+ "name": "amount_observed",+ "type": "integer",+ "primaryKey": false,+ "notNull": true+ },+ "status": {+ "name": "status",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "'open'"+ },+ "approval_id": {+ "name": "approval_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": false+ },+ "resolved_at": {+ "name": "resolved_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": {+ "budget_incidents_company_status_idx": {+ "name": "budget_incidents_company_status_idx",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "status",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "budget_incidents_company_scope_idx": {+ "name": "budget_incidents_company_scope_idx",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "scope_type",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "scope_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "status",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "budget_incidents_policy_window_threshold_idx": {+ "name": "budget_incidents_policy_window_threshold_idx",+ "columns": [+ {+ "expression": "policy_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "window_start",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "threshold_type",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": true,+ "where": "\"budget_incidents\".\"status\" <> 'dismissed'",+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "budget_incidents_company_id_companies_id_fk": {+ "name": "budget_incidents_company_id_companies_id_fk",+ "tableFrom": "budget_incidents",+ "tableTo": "companies",+ "columnsFrom": [+ "company_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ },+ "budget_incidents_policy_id_budget_policies_id_fk": {+ "name": "budget_incidents_policy_id_budget_policies_id_fk",+ "tableFrom": "budget_incidents",+ "tableTo": "budget_policies",+ "columnsFrom": [+ "policy_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ },+ "budget_incidents_approval_id_approvals_id_fk": {+ "name": "budget_incidents_approval_id_approvals_id_fk",+ "tableFrom": "budget_incidents",+ "tableTo": "approvals",+ "columnsFrom": [+ "approval_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.budget_policies": {+ "name": "budget_policies",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "uuid",+ "primaryKey": true,+ "notNull": true,+ "default": "gen_random_uuid()"+ },+ "company_id": {+ "name": "company_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": true+ },+ "scope_type": {+ "name": "scope_type",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "scope_id": {+ "name": "scope_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": true+ },+ "metric": {+ "name": "metric",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "'billed_cents'"+ },+ "window_kind": {+ "name": "window_kind",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "amount": {+ "name": "amount",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "default": 0+ },+ "warn_percent": {+ "name": "warn_percent",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "default": 80+ },+ "hard_stop_enabled": {+ "name": "hard_stop_enabled",+ "type": "boolean",+ "primaryKey": false,+ "notNull": true,+ "default": true+ },+ "notify_enabled": {+ "name": "notify_enabled",+ "type": "boolean",+ "primaryKey": false,+ "notNull": true,+ "default": true+ },+ "is_active": {+ "name": "is_active",+ "type": "boolean",+ "primaryKey": false,+ "notNull": true,+ "default": true+ },+ "created_by_user_id": {+ "name": "created_by_user_id",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "updated_by_user_id": {+ "name": "updated_by_user_id",+ "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": {+ "budget_policies_company_scope_active_idx": {+ "name": "budget_policies_company_scope_active_idx",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "scope_type",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "scope_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "is_active",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "budget_policies_company_window_idx": {+ "name": "budget_policies_company_window_idx",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "window_kind",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "metric",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "budget_policies_company_scope_metric_unique_idx": {+ "name": "budget_policies_company_scope_metric_unique_idx",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "scope_type",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "scope_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "metric",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "window_kind",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": true,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "budget_policies_company_id_companies_id_fk": {+ "name": "budget_policies_company_id_companies_id_fk",+ "tableFrom": "budget_policies",+ "tableTo": "companies",+ "columnsFrom": [+ "company_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.cli_auth_challenges": {+ "name": "cli_auth_challenges",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "uuid",+ "primaryKey": true,+ "notNull": true,+ "default": "gen_random_uuid()"+ },+ "secret_hash": {+ "name": "secret_hash",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "command": {+ "name": "command",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "client_name": {+ "name": "client_name",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "requested_access": {+ "name": "requested_access",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "'board'"+ },+ "requested_company_id": {+ "name": "requested_company_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": false+ },+ "pending_key_hash": {+ "name": "pending_key_hash",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "pending_key_name": {+ "name": "pending_key_name",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "approved_by_user_id": {+ "name": "approved_by_user_id",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "board_api_key_id": {+ "name": "board_api_key_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": false+ },+ "approved_at": {+ "name": "approved_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": false+ },+ "cancelled_at": {+ "name": "cancelled_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": false+ },+ "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": {+ "cli_auth_challenges_secret_hash_idx": {+ "name": "cli_auth_challenges_secret_hash_idx",+ "columns": [+ {+ "expression": "secret_hash",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "cli_auth_challenges_approved_by_idx": {+ "name": "cli_auth_challenges_approved_by_idx",+ "columns": [+ {+ "expression": "approved_by_user_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "cli_auth_challenges_requested_company_idx": {+ "name": "cli_auth_challenges_requested_company_idx",+ "columns": [+ {+ "expression": "requested_company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "cli_auth_challenges_requested_company_id_companies_id_fk": {+ "name": "cli_auth_challenges_requested_company_id_companies_id_fk",+ "tableFrom": "cli_auth_challenges",+ "tableTo": "companies",+ "columnsFrom": [+ "requested_company_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "set null",+ "onUpdate": "no action"+ },+ "cli_auth_challenges_approved_by_user_id_user_id_fk": {+ "name": "cli_auth_challenges_approved_by_user_id_user_id_fk",+ "tableFrom": "cli_auth_challenges",+ "tableTo": "user",+ "columnsFrom": [+ "approved_by_user_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "set null",+ "onUpdate": "no action"+ },+ "cli_auth_challenges_board_api_key_id_board_api_keys_id_fk": {+ "name": "cli_auth_challenges_board_api_key_id_board_api_keys_id_fk",+ "tableFrom": "cli_auth_challenges",+ "tableTo": "board_api_keys",+ "columnsFrom": [+ "board_api_key_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "set null",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.companies": {+ "name": "companies",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "uuid",+ "primaryKey": true,+ "notNull": true,+ "default": "gen_random_uuid()"+ },+ "name": {+ "name": "name",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "description": {+ "name": "description",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "status": {+ "name": "status",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "'active'"+ },+ "pause_reason": {+ "name": "pause_reason",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "paused_at": {+ "name": "paused_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": false+ },+ "issue_prefix": {+ "name": "issue_prefix",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "'PAP'"+ },+ "issue_counter": {+ "name": "issue_counter",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "default": 0+ },+ "budget_monthly_cents": {+ "name": "budget_monthly_cents",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "default": 0+ },+ "spent_monthly_cents": {+ "name": "spent_monthly_cents",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "default": 0+ },+ "require_board_approval_for_new_agents": {+ "name": "require_board_approval_for_new_agents",+ "type": "boolean",+ "primaryKey": false,+ "notNull": true,+ "default": true+ },+ "feedback_data_sharing_enabled": {+ "name": "feedback_data_sharing_enabled",+ "type": "boolean",+ "primaryKey": false,+ "notNull": true,+ "default": false+ },+ "feedback_data_sharing_consent_at": {+ "name": "feedback_data_sharing_consent_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": false+ },+ "feedback_data_sharing_consent_by_user_id": {+ "name": "feedback_data_sharing_consent_by_user_id",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "feedback_data_sharing_terms_version": {+ "name": "feedback_data_sharing_terms_version",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "brand_color": {+ "name": "brand_color",+ "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": {+ "companies_issue_prefix_idx": {+ "name": "companies_issue_prefix_idx",+ "columns": [+ {+ "expression": "issue_prefix",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": true,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {},+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.company_logos": {+ "name": "company_logos",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "uuid",+ "primaryKey": true,+ "notNull": true,+ "default": "gen_random_uuid()"+ },+ "company_id": {+ "name": "company_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": true+ },+ "asset_id": {+ "name": "asset_id",+ "type": "uuid",+ "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": {+ "company_logos_company_uq": {+ "name": "company_logos_company_uq",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": true,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "company_logos_asset_uq": {+ "name": "company_logos_asset_uq",+ "columns": [+ {+ "expression": "asset_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": true,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "company_logos_company_id_companies_id_fk": {+ "name": "company_logos_company_id_companies_id_fk",+ "tableFrom": "company_logos",+ "tableTo": "companies",+ "columnsFrom": [+ "company_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "company_logos_asset_id_assets_id_fk": {+ "name": "company_logos_asset_id_assets_id_fk",+ "tableFrom": "company_logos",+ "tableTo": "assets",+ "columnsFrom": [+ "asset_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.company_memberships": {+ "name": "company_memberships",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "uuid",+ "primaryKey": true,+ "notNull": true,+ "default": "gen_random_uuid()"+ },+ "company_id": {+ "name": "company_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": true+ },+ "principal_type": {+ "name": "principal_type",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "principal_id": {+ "name": "principal_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "status": {+ "name": "status",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "'active'"+ },+ "membership_role": {+ "name": "membership_role",+ "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": {+ "company_memberships_company_principal_unique_idx": {+ "name": "company_memberships_company_principal_unique_idx",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "principal_type",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "principal_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": true,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "company_memberships_principal_status_idx": {+ "name": "company_memberships_principal_status_idx",+ "columns": [+ {+ "expression": "principal_type",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "principal_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "status",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "company_memberships_company_status_idx": {+ "name": "company_memberships_company_status_idx",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "status",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "company_memberships_company_id_companies_id_fk": {+ "name": "company_memberships_company_id_companies_id_fk",+ "tableFrom": "company_memberships",+ "tableTo": "companies",+ "columnsFrom": [+ "company_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.company_secret_versions": {+ "name": "company_secret_versions",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "uuid",+ "primaryKey": true,+ "notNull": true,+ "default": "gen_random_uuid()"+ },+ "secret_id": {+ "name": "secret_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": true+ },+ "version": {+ "name": "version",+ "type": "integer",+ "primaryKey": false,+ "notNull": true+ },+ "material": {+ "name": "material",+ "type": "jsonb",+ "primaryKey": false,+ "notNull": true+ },+ "value_sha256": {+ "name": "value_sha256",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "created_by_agent_id": {+ "name": "created_by_agent_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": false+ },+ "created_by_user_id": {+ "name": "created_by_user_id",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "created_at": {+ "name": "created_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ },+ "revoked_at": {+ "name": "revoked_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": false+ }+ },+ "indexes": {+ "company_secret_versions_secret_idx": {+ "name": "company_secret_versions_secret_idx",+ "columns": [+ {+ "expression": "secret_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "created_at",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "company_secret_versions_value_sha256_idx": {+ "name": "company_secret_versions_value_sha256_idx",+ "columns": [+ {+ "expression": "value_sha256",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "company_secret_versions_secret_version_uq": {+ "name": "company_secret_versions_secret_version_uq",+ "columns": [+ {+ "expression": "secret_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "version",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": true,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "company_secret_versions_secret_id_company_secrets_id_fk": {+ "name": "company_secret_versions_secret_id_company_secrets_id_fk",+ "tableFrom": "company_secret_versions",+ "tableTo": "company_secrets",+ "columnsFrom": [+ "secret_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "company_secret_versions_created_by_agent_id_agents_id_fk": {+ "name": "company_secret_versions_created_by_agent_id_agents_id_fk",+ "tableFrom": "company_secret_versions",+ "tableTo": "agents",+ "columnsFrom": [+ "created_by_agent_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "set null",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.company_secrets": {+ "name": "company_secrets",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "uuid",+ "primaryKey": true,+ "notNull": true,+ "default": "gen_random_uuid()"+ },+ "company_id": {+ "name": "company_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": true+ },+ "name": {+ "name": "name",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "provider": {+ "name": "provider",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "'local_encrypted'"+ },+ "external_ref": {+ "name": "external_ref",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "latest_version": {+ "name": "latest_version",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "default": 1+ },+ "description": {+ "name": "description",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "created_by_agent_id": {+ "name": "created_by_agent_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": false+ },+ "created_by_user_id": {+ "name": "created_by_user_id",+ "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": {+ "company_secrets_company_idx": {+ "name": "company_secrets_company_idx",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "company_secrets_company_provider_idx": {+ "name": "company_secrets_company_provider_idx",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "provider",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "company_secrets_company_name_uq": {+ "name": "company_secrets_company_name_uq",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "name",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": true,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "company_secrets_company_id_companies_id_fk": {+ "name": "company_secrets_company_id_companies_id_fk",+ "tableFrom": "company_secrets",+ "tableTo": "companies",+ "columnsFrom": [+ "company_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ },+ "company_secrets_created_by_agent_id_agents_id_fk": {+ "name": "company_secrets_created_by_agent_id_agents_id_fk",+ "tableFrom": "company_secrets",+ "tableTo": "agents",+ "columnsFrom": [+ "created_by_agent_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "set null",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.company_skills": {+ "name": "company_skills",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "uuid",+ "primaryKey": true,+ "notNull": true,+ "default": "gen_random_uuid()"+ },+ "company_id": {+ "name": "company_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": true+ },+ "key": {+ "name": "key",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "slug": {+ "name": "slug",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "name": {+ "name": "name",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "description": {+ "name": "description",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "markdown": {+ "name": "markdown",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "source_type": {+ "name": "source_type",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "'local_path'"+ },+ "source_locator": {+ "name": "source_locator",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "source_ref": {+ "name": "source_ref",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "trust_level": {+ "name": "trust_level",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "'markdown_only'"+ },+ "compatibility": {+ "name": "compatibility",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "'compatible'"+ },+ "file_inventory": {+ "name": "file_inventory",+ "type": "jsonb",+ "primaryKey": false,+ "notNull": true,+ "default": "'[]'::jsonb"+ },+ "metadata": {+ "name": "metadata",+ "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": {+ "company_skills_company_key_idx": {+ "name": "company_skills_company_key_idx",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "key",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": true,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "company_skills_company_name_idx": {+ "name": "company_skills_company_name_idx",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "name",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "company_skills_company_id_companies_id_fk": {+ "name": "company_skills_company_id_companies_id_fk",+ "tableFrom": "company_skills",+ "tableTo": "companies",+ "columnsFrom": [+ "company_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.cost_events": {+ "name": "cost_events",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "uuid",+ "primaryKey": true,+ "notNull": true,+ "default": "gen_random_uuid()"+ },+ "company_id": {+ "name": "company_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": true+ },+ "agent_id": {+ "name": "agent_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": true+ },+ "issue_id": {+ "name": "issue_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": false+ },+ "project_id": {+ "name": "project_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": false+ },+ "goal_id": {+ "name": "goal_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": false+ },+ "heartbeat_run_id": {+ "name": "heartbeat_run_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": false+ },+ "billing_code": {+ "name": "billing_code",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "provider": {+ "name": "provider",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "biller": {+ "name": "biller",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "'unknown'"+ },+ "billing_type": {+ "name": "billing_type",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "'unknown'"+ },+ "model": {+ "name": "model",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "input_tokens": {+ "name": "input_tokens",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "default": 0+ },+ "cached_input_tokens": {+ "name": "cached_input_tokens",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "default": 0+ },+ "output_tokens": {+ "name": "output_tokens",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "default": 0+ },+ "cost_cents": {+ "name": "cost_cents",+ "type": "integer",+ "primaryKey": false,+ "notNull": true+ },+ "occurred_at": {+ "name": "occurred_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()"+ }+ },+ "indexes": {+ "cost_events_company_occurred_idx": {+ "name": "cost_events_company_occurred_idx",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "occurred_at",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "cost_events_company_agent_occurred_idx": {+ "name": "cost_events_company_agent_occurred_idx",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "agent_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "occurred_at",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "cost_events_company_provider_occurred_idx": {+ "name": "cost_events_company_provider_occurred_idx",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "provider",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "occurred_at",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "cost_events_company_biller_occurred_idx": {+ "name": "cost_events_company_biller_occurred_idx",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "biller",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "occurred_at",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "cost_events_company_heartbeat_run_idx": {+ "name": "cost_events_company_heartbeat_run_idx",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "heartbeat_run_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "cost_events_company_id_companies_id_fk": {+ "name": "cost_events_company_id_companies_id_fk",+ "tableFrom": "cost_events",+ "tableTo": "companies",+ "columnsFrom": [+ "company_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ },+ "cost_events_agent_id_agents_id_fk": {+ "name": "cost_events_agent_id_agents_id_fk",+ "tableFrom": "cost_events",+ "tableTo": "agents",+ "columnsFrom": [+ "agent_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ },+ "cost_events_issue_id_issues_id_fk": {+ "name": "cost_events_issue_id_issues_id_fk",+ "tableFrom": "cost_events",+ "tableTo": "issues",+ "columnsFrom": [+ "issue_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ },+ "cost_events_project_id_projects_id_fk": {+ "name": "cost_events_project_id_projects_id_fk",+ "tableFrom": "cost_events",+ "tableTo": "projects",+ "columnsFrom": [+ "project_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ },+ "cost_events_goal_id_goals_id_fk": {+ "name": "cost_events_goal_id_goals_id_fk",+ "tableFrom": "cost_events",+ "tableTo": "goals",+ "columnsFrom": [+ "goal_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ },+ "cost_events_heartbeat_run_id_heartbeat_runs_id_fk": {+ "name": "cost_events_heartbeat_run_id_heartbeat_runs_id_fk",+ "tableFrom": "cost_events",+ "tableTo": "heartbeat_runs",+ "columnsFrom": [+ "heartbeat_run_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.document_revisions": {+ "name": "document_revisions",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "uuid",+ "primaryKey": true,+ "notNull": true,+ "default": "gen_random_uuid()"+ },+ "company_id": {+ "name": "company_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": true+ },+ "document_id": {+ "name": "document_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": true+ },+ "revision_number": {+ "name": "revision_number",+ "type": "integer",+ "primaryKey": false,+ "notNull": true+ },+ "title": {+ "name": "title",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "format": {+ "name": "format",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "'markdown'"+ },+ "body": {+ "name": "body",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "change_summary": {+ "name": "change_summary",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "created_by_agent_id": {+ "name": "created_by_agent_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": false+ },+ "created_by_user_id": {+ "name": "created_by_user_id",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "created_by_run_id": {+ "name": "created_by_run_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": false+ },+ "created_at": {+ "name": "created_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {+ "document_revisions_document_revision_uq": {+ "name": "document_revisions_document_revision_uq",+ "columns": [+ {+ "expression": "document_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "revision_number",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": true,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "document_revisions_company_document_created_idx": {+ "name": "document_revisions_company_document_created_idx",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "document_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "created_at",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "document_revisions_company_id_companies_id_fk": {+ "name": "document_revisions_company_id_companies_id_fk",+ "tableFrom": "document_revisions",+ "tableTo": "companies",+ "columnsFrom": [+ "company_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ },+ "document_revisions_document_id_documents_id_fk": {+ "name": "document_revisions_document_id_documents_id_fk",+ "tableFrom": "document_revisions",+ "tableTo": "documents",+ "columnsFrom": [+ "document_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "document_revisions_created_by_agent_id_agents_id_fk": {+ "name": "document_revisions_created_by_agent_id_agents_id_fk",+ "tableFrom": "document_revisions",+ "tableTo": "agents",+ "columnsFrom": [+ "created_by_agent_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "set null",+ "onUpdate": "no action"+ },+ "document_revisions_created_by_run_id_heartbeat_runs_id_fk": {+ "name": "document_revisions_created_by_run_id_heartbeat_runs_id_fk",+ "tableFrom": "document_revisions",+ "tableTo": "heartbeat_runs",+ "columnsFrom": [+ "created_by_run_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "set null",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.documents": {+ "name": "documents",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "uuid",+ "primaryKey": true,+ "notNull": true,+ "default": "gen_random_uuid()"+ },+ "company_id": {+ "name": "company_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": true+ },+ "title": {+ "name": "title",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "format": {+ "name": "format",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "'markdown'"+ },+ "latest_body": {+ "name": "latest_body",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "latest_revision_id": {+ "name": "latest_revision_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": false+ },+ "latest_revision_number": {+ "name": "latest_revision_number",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "default": 1+ },+ "created_by_agent_id": {+ "name": "created_by_agent_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": false+ },+ "created_by_user_id": {+ "name": "created_by_user_id",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "updated_by_agent_id": {+ "name": "updated_by_agent_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": false+ },+ "updated_by_user_id": {+ "name": "updated_by_user_id",+ "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": {+ "documents_company_updated_idx": {+ "name": "documents_company_updated_idx",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "updated_at",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "documents_company_created_idx": {+ "name": "documents_company_created_idx",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "created_at",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "documents_company_id_companies_id_fk": {+ "name": "documents_company_id_companies_id_fk",+ "tableFrom": "documents",+ "tableTo": "companies",+ "columnsFrom": [+ "company_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ },+ "documents_created_by_agent_id_agents_id_fk": {+ "name": "documents_created_by_agent_id_agents_id_fk",+ "tableFrom": "documents",+ "tableTo": "agents",+ "columnsFrom": [+ "created_by_agent_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "set null",+ "onUpdate": "no action"+ },+ "documents_updated_by_agent_id_agents_id_fk": {+ "name": "documents_updated_by_agent_id_agents_id_fk",+ "tableFrom": "documents",+ "tableTo": "agents",+ "columnsFrom": [+ "updated_by_agent_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "set null",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.execution_workspaces": {+ "name": "execution_workspaces",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "uuid",+ "primaryKey": true,+ "notNull": true,+ "default": "gen_random_uuid()"+ },+ "company_id": {+ "name": "company_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": true+ },+ "project_id": {+ "name": "project_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": true+ },+ "project_workspace_id": {+ "name": "project_workspace_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": false+ },+ "source_issue_id": {+ "name": "source_issue_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": false+ },+ "mode": {+ "name": "mode",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "strategy_type": {+ "name": "strategy_type",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "name": {+ "name": "name",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "status": {+ "name": "status",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "'active'"+ },+ "cwd": {+ "name": "cwd",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "repo_url": {+ "name": "repo_url",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "base_ref": {+ "name": "base_ref",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "branch_name": {+ "name": "branch_name",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "provider_type": {+ "name": "provider_type",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "'local_fs'"+ },+ "provider_ref": {+ "name": "provider_ref",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "derived_from_execution_workspace_id": {+ "name": "derived_from_execution_workspace_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": false+ },+ "last_used_at": {+ "name": "last_used_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ },+ "opened_at": {+ "name": "opened_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ },+ "closed_at": {+ "name": "closed_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": false+ },+ "cleanup_eligible_at": {+ "name": "cleanup_eligible_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": false+ },+ "cleanup_reason": {+ "name": "cleanup_reason",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "metadata": {+ "name": "metadata",+ "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": {+ "execution_workspaces_company_project_status_idx": {+ "name": "execution_workspaces_company_project_status_idx",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "project_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "status",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "execution_workspaces_company_project_workspace_status_idx": {+ "name": "execution_workspaces_company_project_workspace_status_idx",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "project_workspace_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "status",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "execution_workspaces_company_source_issue_idx": {+ "name": "execution_workspaces_company_source_issue_idx",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "source_issue_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "execution_workspaces_company_last_used_idx": {+ "name": "execution_workspaces_company_last_used_idx",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "last_used_at",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "execution_workspaces_company_branch_idx": {+ "name": "execution_workspaces_company_branch_idx",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "branch_name",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "execution_workspaces_company_id_companies_id_fk": {+ "name": "execution_workspaces_company_id_companies_id_fk",+ "tableFrom": "execution_workspaces",+ "tableTo": "companies",+ "columnsFrom": [+ "company_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ },+ "execution_workspaces_project_id_projects_id_fk": {+ "name": "execution_workspaces_project_id_projects_id_fk",+ "tableFrom": "execution_workspaces",+ "tableTo": "projects",+ "columnsFrom": [+ "project_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "execution_workspaces_project_workspace_id_project_workspaces_id_fk": {+ "name": "execution_workspaces_project_workspace_id_project_workspaces_id_fk",+ "tableFrom": "execution_workspaces",+ "tableTo": "project_workspaces",+ "columnsFrom": [+ "project_workspace_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "set null",+ "onUpdate": "no action"+ },+ "execution_workspaces_source_issue_id_issues_id_fk": {+ "name": "execution_workspaces_source_issue_id_issues_id_fk",+ "tableFrom": "execution_workspaces",+ "tableTo": "issues",+ "columnsFrom": [+ "source_issue_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "set null",+ "onUpdate": "no action"+ },+ "execution_workspaces_derived_from_execution_workspace_id_execution_workspaces_id_fk": {+ "name": "execution_workspaces_derived_from_execution_workspace_id_execution_workspaces_id_fk",+ "tableFrom": "execution_workspaces",+ "tableTo": "execution_workspaces",+ "columnsFrom": [+ "derived_from_execution_workspace_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "set null",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.feedback_exports": {+ "name": "feedback_exports",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "uuid",+ "primaryKey": true,+ "notNull": true,+ "default": "gen_random_uuid()"+ },+ "company_id": {+ "name": "company_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": true+ },+ "feedback_vote_id": {+ "name": "feedback_vote_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": true+ },+ "issue_id": {+ "name": "issue_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": true+ },+ "project_id": {+ "name": "project_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": false+ },+ "author_user_id": {+ "name": "author_user_id",+ "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": true+ },+ "vote": {+ "name": "vote",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "status": {+ "name": "status",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "'local_only'"+ },+ "destination": {+ "name": "destination",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "export_id": {+ "name": "export_id",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "consent_version": {+ "name": "consent_version",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "schema_version": {+ "name": "schema_version",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "'paperclip-feedback-envelope-v2'"+ },+ "bundle_version": {+ "name": "bundle_version",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "'paperclip-feedback-bundle-v2'"+ },+ "payload_version": {+ "name": "payload_version",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "'paperclip-feedback-v1'"+ },+ "payload_digest": {+ "name": "payload_digest",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "payload_snapshot": {+ "name": "payload_snapshot",+ "type": "jsonb",+ "primaryKey": false,+ "notNull": false+ },+ "target_summary": {+ "name": "target_summary",+ "type": "jsonb",+ "primaryKey": false,+ "notNull": true+ },+ "redaction_summary": {+ "name": "redaction_summary",+ "type": "jsonb",+ "primaryKey": false,+ "notNull": false+ },+ "attempt_count": {+ "name": "attempt_count",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "default": 0+ },+ "last_attempted_at": {+ "name": "last_attempted_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": false+ },+ "exported_at": {+ "name": "exported_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": false+ },+ "failure_reason": {+ "name": "failure_reason",+ "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": {+ "feedback_exports_feedback_vote_idx": {+ "name": "feedback_exports_feedback_vote_idx",+ "columns": [+ {+ "expression": "feedback_vote_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": true,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "feedback_exports_company_created_idx": {+ "name": "feedback_exports_company_created_idx",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "created_at",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "feedback_exports_company_status_idx": {+ "name": "feedback_exports_company_status_idx",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "status",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "created_at",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "feedback_exports_company_issue_idx": {+ "name": "feedback_exports_company_issue_idx",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "issue_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "created_at",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "feedback_exports_company_project_idx": {+ "name": "feedback_exports_company_project_idx",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "project_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "created_at",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "feedback_exports_company_author_idx": {+ "name": "feedback_exports_company_author_idx",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "author_user_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "created_at",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "feedback_exports_company_id_companies_id_fk": {+ "name": "feedback_exports_company_id_companies_id_fk",+ "tableFrom": "feedback_exports",+ "tableTo": "companies",+ "columnsFrom": [+ "company_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ },+ "feedback_exports_feedback_vote_id_feedback_votes_id_fk": {+ "name": "feedback_exports_feedback_vote_id_feedback_votes_id_fk",+ "tableFrom": "feedback_exports",+ "tableTo": "feedback_votes",+ "columnsFrom": [+ "feedback_vote_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "feedback_exports_issue_id_issues_id_fk": {+ "name": "feedback_exports_issue_id_issues_id_fk",+ "tableFrom": "feedback_exports",+ "tableTo": "issues",+ "columnsFrom": [+ "issue_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "feedback_exports_project_id_projects_id_fk": {+ "name": "feedback_exports_project_id_projects_id_fk",+ "tableFrom": "feedback_exports",+ "tableTo": "projects",+ "columnsFrom": [+ "project_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "set null",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.feedback_votes": {+ "name": "feedback_votes",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "uuid",+ "primaryKey": true,+ "notNull": true,+ "default": "gen_random_uuid()"+ },+ "company_id": {+ "name": "company_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": true+ },+ "issue_id": {+ "name": "issue_id",+ "type": "uuid",+ "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": true+ },+ "author_user_id": {+ "name": "author_user_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "vote": {+ "name": "vote",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "reason": {+ "name": "reason",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "shared_with_labs": {+ "name": "shared_with_labs",+ "type": "boolean",+ "primaryKey": false,+ "notNull": true,+ "default": false+ },+ "shared_at": {+ "name": "shared_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": false+ },+ "consent_version": {+ "name": "consent_version",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "redaction_summary": {+ "name": "redaction_summary",+ "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": {+ "feedback_votes_company_issue_idx": {+ "name": "feedback_votes_company_issue_idx",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "issue_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "feedback_votes_issue_target_idx": {+ "name": "feedback_votes_issue_target_idx",+ "columns": [+ {+ "expression": "issue_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "target_type",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "target_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "feedback_votes_author_idx": {+ "name": "feedback_votes_author_idx",+ "columns": [+ {+ "expression": "author_user_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "created_at",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "feedback_votes_company_target_author_idx": {+ "name": "feedback_votes_company_target_author_idx",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "target_type",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "target_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "author_user_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": true,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "feedback_votes_company_id_companies_id_fk": {+ "name": "feedback_votes_company_id_companies_id_fk",+ "tableFrom": "feedback_votes",+ "tableTo": "companies",+ "columnsFrom": [+ "company_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ },+ "feedback_votes_issue_id_issues_id_fk": {+ "name": "feedback_votes_issue_id_issues_id_fk",+ "tableFrom": "feedback_votes",+ "tableTo": "issues",+ "columnsFrom": [+ "issue_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.finance_events": {+ "name": "finance_events",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "uuid",+ "primaryKey": true,+ "notNull": true,+ "default": "gen_random_uuid()"+ },+ "company_id": {+ "name": "company_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": true+ },+ "agent_id": {+ "name": "agent_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": false+ },+ "issue_id": {+ "name": "issue_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": false+ },+ "project_id": {+ "name": "project_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": false+ },+ "goal_id": {+ "name": "goal_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": false+ },+ "heartbeat_run_id": {+ "name": "heartbeat_run_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": false+ },+ "cost_event_id": {+ "name": "cost_event_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": false+ },+ "billing_code": {+ "name": "billing_code",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "description": {+ "name": "description",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "event_kind": {+ "name": "event_kind",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "direction": {+ "name": "direction",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "'debit'"+ },+ "biller": {+ "name": "biller",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "provider": {+ "name": "provider",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "execution_adapter_type": {+ "name": "execution_adapter_type",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "pricing_tier": {+ "name": "pricing_tier",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "region": {+ "name": "region",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "model": {+ "name": "model",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "quantity": {+ "name": "quantity",+ "type": "integer",+ "primaryKey": false,+ "notNull": false+ },+ "unit": {+ "name": "unit",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "amount_cents": {+ "name": "amount_cents",+ "type": "integer",+ "primaryKey": false,+ "notNull": true+ },+ "currency": {+ "name": "currency",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "'USD'"+ },+ "estimated": {+ "name": "estimated",+ "type": "boolean",+ "primaryKey": false,+ "notNull": true,+ "default": false+ },+ "external_invoice_id": {+ "name": "external_invoice_id",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "metadata_json": {+ "name": "metadata_json",+ "type": "jsonb",+ "primaryKey": false,+ "notNull": false+ },+ "occurred_at": {+ "name": "occurred_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()"+ }+ },+ "indexes": {+ "finance_events_company_occurred_idx": {+ "name": "finance_events_company_occurred_idx",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "occurred_at",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "finance_events_company_biller_occurred_idx": {+ "name": "finance_events_company_biller_occurred_idx",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "biller",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "occurred_at",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "finance_events_company_kind_occurred_idx": {+ "name": "finance_events_company_kind_occurred_idx",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "event_kind",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "occurred_at",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "finance_events_company_direction_occurred_idx": {+ "name": "finance_events_company_direction_occurred_idx",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "direction",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "occurred_at",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "finance_events_company_heartbeat_run_idx": {+ "name": "finance_events_company_heartbeat_run_idx",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "heartbeat_run_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "finance_events_company_cost_event_idx": {+ "name": "finance_events_company_cost_event_idx",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "cost_event_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "finance_events_company_id_companies_id_fk": {+ "name": "finance_events_company_id_companies_id_fk",+ "tableFrom": "finance_events",+ "tableTo": "companies",+ "columnsFrom": [+ "company_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ },+ "finance_events_agent_id_agents_id_fk": {+ "name": "finance_events_agent_id_agents_id_fk",+ "tableFrom": "finance_events",+ "tableTo": "agents",+ "columnsFrom": [+ "agent_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ },+ "finance_events_issue_id_issues_id_fk": {+ "name": "finance_events_issue_id_issues_id_fk",+ "tableFrom": "finance_events",+ "tableTo": "issues",+ "columnsFrom": [+ "issue_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ },+ "finance_events_project_id_projects_id_fk": {+ "name": "finance_events_project_id_projects_id_fk",+ "tableFrom": "finance_events",+ "tableTo": "projects",+ "columnsFrom": [+ "project_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ },+ "finance_events_goal_id_goals_id_fk": {+ "name": "finance_events_goal_id_goals_id_fk",+ "tableFrom": "finance_events",+ "tableTo": "goals",+ "columnsFrom": [+ "goal_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ },+ "finance_events_heartbeat_run_id_heartbeat_runs_id_fk": {+ "name": "finance_events_heartbeat_run_id_heartbeat_runs_id_fk",+ "tableFrom": "finance_events",+ "tableTo": "heartbeat_runs",+ "columnsFrom": [+ "heartbeat_run_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ },+ "finance_events_cost_event_id_cost_events_id_fk": {+ "name": "finance_events_cost_event_id_cost_events_id_fk",+ "tableFrom": "finance_events",+ "tableTo": "cost_events",+ "columnsFrom": [+ "cost_event_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.goals": {+ "name": "goals",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "uuid",+ "primaryKey": true,+ "notNull": true,+ "default": "gen_random_uuid()"+ },+ "company_id": {+ "name": "company_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": true+ },+ "title": {+ "name": "title",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "description": {+ "name": "description",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "level": {+ "name": "level",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "'task'"+ },+ "status": {+ "name": "status",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "'planned'"+ },+ "parent_id": {+ "name": "parent_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": false+ },+ "owner_agent_id": {+ "name": "owner_agent_id",+ "type": "uuid",+ "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": {+ "goals_company_idx": {+ "name": "goals_company_idx",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "goals_company_id_companies_id_fk": {+ "name": "goals_company_id_companies_id_fk",+ "tableFrom": "goals",+ "tableTo": "companies",+ "columnsFrom": [+ "company_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ },+ "goals_parent_id_goals_id_fk": {+ "name": "goals_parent_id_goals_id_fk",+ "tableFrom": "goals",+ "tableTo": "goals",+ "columnsFrom": [+ "parent_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ },+ "goals_owner_agent_id_agents_id_fk": {+ "name": "goals_owner_agent_id_agents_id_fk",+ "tableFrom": "goals",+ "tableTo": "agents",+ "columnsFrom": [+ "owner_agent_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.heartbeat_run_events": {+ "name": "heartbeat_run_events",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "bigserial",+ "primaryKey": true,+ "notNull": true+ },+ "company_id": {+ "name": "company_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": true+ },+ "run_id": {+ "name": "run_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": true+ },+ "agent_id": {+ "name": "agent_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": true+ },+ "seq": {+ "name": "seq",+ "type": "integer",+ "primaryKey": false,+ "notNull": true+ },+ "event_type": {+ "name": "event_type",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "stream": {+ "name": "stream",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "level": {+ "name": "level",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "color": {+ "name": "color",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "message": {+ "name": "message",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "payload": {+ "name": "payload",+ "type": "jsonb",+ "primaryKey": false,+ "notNull": false+ },+ "created_at": {+ "name": "created_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {+ "heartbeat_run_events_run_seq_idx": {+ "name": "heartbeat_run_events_run_seq_idx",+ "columns": [+ {+ "expression": "run_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "seq",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "heartbeat_run_events_company_run_idx": {+ "name": "heartbeat_run_events_company_run_idx",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "run_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "heartbeat_run_events_company_created_idx": {+ "name": "heartbeat_run_events_company_created_idx",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "created_at",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "heartbeat_run_events_company_id_companies_id_fk": {+ "name": "heartbeat_run_events_company_id_companies_id_fk",+ "tableFrom": "heartbeat_run_events",+ "tableTo": "companies",+ "columnsFrom": [+ "company_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ },+ "heartbeat_run_events_run_id_heartbeat_runs_id_fk": {+ "name": "heartbeat_run_events_run_id_heartbeat_runs_id_fk",+ "tableFrom": "heartbeat_run_events",+ "tableTo": "heartbeat_runs",+ "columnsFrom": [+ "run_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ },+ "heartbeat_run_events_agent_id_agents_id_fk": {+ "name": "heartbeat_run_events_agent_id_agents_id_fk",+ "tableFrom": "heartbeat_run_events",+ "tableTo": "agents",+ "columnsFrom": [+ "agent_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.heartbeat_runs": {+ "name": "heartbeat_runs",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "uuid",+ "primaryKey": true,+ "notNull": true,+ "default": "gen_random_uuid()"+ },+ "company_id": {+ "name": "company_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": true+ },+ "agent_id": {+ "name": "agent_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": true+ },+ "invocation_source": {+ "name": "invocation_source",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "'on_demand'"+ },+ "trigger_detail": {+ "name": "trigger_detail",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "status": {+ "name": "status",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "'queued'"+ },+ "started_at": {+ "name": "started_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": false+ },+ "finished_at": {+ "name": "finished_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": false+ },+ "error": {+ "name": "error",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "wakeup_request_id": {+ "name": "wakeup_request_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": false+ },+ "exit_code": {+ "name": "exit_code",+ "type": "integer",+ "primaryKey": false,+ "notNull": false+ },+ "signal": {+ "name": "signal",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "usage_json": {+ "name": "usage_json",+ "type": "jsonb",+ "primaryKey": false,+ "notNull": false+ },+ "result_json": {+ "name": "result_json",+ "type": "jsonb",+ "primaryKey": false,+ "notNull": false+ },+ "session_id_before": {+ "name": "session_id_before",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "session_id_after": {+ "name": "session_id_after",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "log_store": {+ "name": "log_store",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "log_ref": {+ "name": "log_ref",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "log_bytes": {+ "name": "log_bytes",+ "type": "bigint",+ "primaryKey": false,+ "notNull": false+ },+ "log_sha256": {+ "name": "log_sha256",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "log_compressed": {+ "name": "log_compressed",+ "type": "boolean",+ "primaryKey": false,+ "notNull": true,+ "default": false+ },+ "stdout_excerpt": {+ "name": "stdout_excerpt",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "stderr_excerpt": {+ "name": "stderr_excerpt",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "error_code": {+ "name": "error_code",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "external_run_id": {+ "name": "external_run_id",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "process_pid": {+ "name": "process_pid",+ "type": "integer",+ "primaryKey": false,+ "notNull": false+ },+ "process_started_at": {+ "name": "process_started_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": false+ },+ "retry_of_run_id": {+ "name": "retry_of_run_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": false+ },+ "process_loss_retry_count": {+ "name": "process_loss_retry_count",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "default": 0+ },+ "context_snapshot": {+ "name": "context_snapshot",+ "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": {+ "heartbeat_runs_company_agent_started_idx": {+ "name": "heartbeat_runs_company_agent_started_idx",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "agent_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "started_at",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "heartbeat_runs_company_id_companies_id_fk": {+ "name": "heartbeat_runs_company_id_companies_id_fk",+ "tableFrom": "heartbeat_runs",+ "tableTo": "companies",+ "columnsFrom": [+ "company_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ },+ "heartbeat_runs_agent_id_agents_id_fk": {+ "name": "heartbeat_runs_agent_id_agents_id_fk",+ "tableFrom": "heartbeat_runs",+ "tableTo": "agents",+ "columnsFrom": [+ "agent_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ },+ "heartbeat_runs_wakeup_request_id_agent_wakeup_requests_id_fk": {+ "name": "heartbeat_runs_wakeup_request_id_agent_wakeup_requests_id_fk",+ "tableFrom": "heartbeat_runs",+ "tableTo": "agent_wakeup_requests",+ "columnsFrom": [+ "wakeup_request_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ },+ "heartbeat_runs_retry_of_run_id_heartbeat_runs_id_fk": {+ "name": "heartbeat_runs_retry_of_run_id_heartbeat_runs_id_fk",+ "tableFrom": "heartbeat_runs",+ "tableTo": "heartbeat_runs",+ "columnsFrom": [+ "retry_of_run_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "set null",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.instance_settings": {+ "name": "instance_settings",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "uuid",+ "primaryKey": true,+ "notNull": true,+ "default": "gen_random_uuid()"+ },+ "singleton_key": {+ "name": "singleton_key",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "'default'"+ },+ "general": {+ "name": "general",+ "type": "jsonb",+ "primaryKey": false,+ "notNull": true,+ "default": "'{}'::jsonb"+ },+ "experimental": {+ "name": "experimental",+ "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": {+ "instance_settings_singleton_key_idx": {+ "name": "instance_settings_singleton_key_idx",+ "columns": [+ {+ "expression": "singleton_key",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": true,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {},+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.instance_user_roles": {+ "name": "instance_user_roles",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "uuid",+ "primaryKey": true,+ "notNull": true,+ "default": "gen_random_uuid()"+ },+ "user_id": {+ "name": "user_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "role": {+ "name": "role",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "'instance_admin'"+ },+ "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": {+ "instance_user_roles_user_role_unique_idx": {+ "name": "instance_user_roles_user_role_unique_idx",+ "columns": [+ {+ "expression": "user_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "role",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": true,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "instance_user_roles_role_idx": {+ "name": "instance_user_roles_role_idx",+ "columns": [+ {+ "expression": "role",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {},+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.invites": {+ "name": "invites",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "uuid",+ "primaryKey": true,+ "notNull": true,+ "default": "gen_random_uuid()"+ },+ "company_id": {+ "name": "company_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": false+ },+ "invite_type": {+ "name": "invite_type",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "'company_join'"+ },+ "token_hash": {+ "name": "token_hash",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "allowed_join_types": {+ "name": "allowed_join_types",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "'both'"+ },+ "defaults_payload": {+ "name": "defaults_payload",+ "type": "jsonb",+ "primaryKey": false,+ "notNull": false+ },+ "expires_at": {+ "name": "expires_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true+ },+ "invited_by_user_id": {+ "name": "invited_by_user_id",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "revoked_at": {+ "name": "revoked_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": false+ },+ "accepted_at": {+ "name": "accepted_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": {+ "invites_token_hash_unique_idx": {+ "name": "invites_token_hash_unique_idx",+ "columns": [+ {+ "expression": "token_hash",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": true,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "invites_company_invite_state_idx": {+ "name": "invites_company_invite_state_idx",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "invite_type",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "revoked_at",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "expires_at",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "invites_company_id_companies_id_fk": {+ "name": "invites_company_id_companies_id_fk",+ "tableFrom": "invites",+ "tableTo": "companies",+ "columnsFrom": [+ "company_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.issue_approvals": {+ "name": "issue_approvals",+ "schema": "",+ "columns": {+ "company_id": {+ "name": "company_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": true+ },+ "issue_id": {+ "name": "issue_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": true+ },+ "approval_id": {+ "name": "approval_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": true+ },+ "linked_by_agent_id": {+ "name": "linked_by_agent_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": false+ },+ "linked_by_user_id": {+ "name": "linked_by_user_id",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "created_at": {+ "name": "created_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {+ "issue_approvals_issue_idx": {+ "name": "issue_approvals_issue_idx",+ "columns": [+ {+ "expression": "issue_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "issue_approvals_approval_idx": {+ "name": "issue_approvals_approval_idx",+ "columns": [+ {+ "expression": "approval_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "issue_approvals_company_idx": {+ "name": "issue_approvals_company_idx",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "issue_approvals_company_id_companies_id_fk": {+ "name": "issue_approvals_company_id_companies_id_fk",+ "tableFrom": "issue_approvals",+ "tableTo": "companies",+ "columnsFrom": [+ "company_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ },+ "issue_approvals_issue_id_issues_id_fk": {+ "name": "issue_approvals_issue_id_issues_id_fk",+ "tableFrom": "issue_approvals",+ "tableTo": "issues",+ "columnsFrom": [+ "issue_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "issue_approvals_approval_id_approvals_id_fk": {+ "name": "issue_approvals_approval_id_approvals_id_fk",+ "tableFrom": "issue_approvals",+ "tableTo": "approvals",+ "columnsFrom": [+ "approval_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "issue_approvals_linked_by_agent_id_agents_id_fk": {+ "name": "issue_approvals_linked_by_agent_id_agents_id_fk",+ "tableFrom": "issue_approvals",+ "tableTo": "agents",+ "columnsFrom": [+ "linked_by_agent_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "set null",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {+ "issue_approvals_pk": {+ "name": "issue_approvals_pk",+ "columns": [+ "issue_id",+ "approval_id"+ ]+ }+ },+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.issue_attachments": {+ "name": "issue_attachments",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "uuid",+ "primaryKey": true,+ "notNull": true,+ "default": "gen_random_uuid()"+ },+ "company_id": {+ "name": "company_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": true+ },+ "issue_id": {+ "name": "issue_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": true+ },+ "asset_id": {+ "name": "asset_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": true+ },+ "issue_comment_id": {+ "name": "issue_comment_id",+ "type": "uuid",+ "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": {+ "issue_attachments_company_issue_idx": {+ "name": "issue_attachments_company_issue_idx",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "issue_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "issue_attachments_issue_comment_idx": {+ "name": "issue_attachments_issue_comment_idx",+ "columns": [+ {+ "expression": "issue_comment_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "issue_attachments_asset_uq": {+ "name": "issue_attachments_asset_uq",+ "columns": [+ {+ "expression": "asset_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": true,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "issue_attachments_company_id_companies_id_fk": {+ "name": "issue_attachments_company_id_companies_id_fk",+ "tableFrom": "issue_attachments",+ "tableTo": "companies",+ "columnsFrom": [+ "company_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ },+ "issue_attachments_issue_id_issues_id_fk": {+ "name": "issue_attachments_issue_id_issues_id_fk",+ "tableFrom": "issue_attachments",+ "tableTo": "issues",+ "columnsFrom": [+ "issue_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "issue_attachments_asset_id_assets_id_fk": {+ "name": "issue_attachments_asset_id_assets_id_fk",+ "tableFrom": "issue_attachments",+ "tableTo": "assets",+ "columnsFrom": [+ "asset_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "issue_attachments_issue_comment_id_issue_comments_id_fk": {+ "name": "issue_attachments_issue_comment_id_issue_comments_id_fk",+ "tableFrom": "issue_attachments",+ "tableTo": "issue_comments",+ "columnsFrom": [+ "issue_comment_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "set null",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.issue_comments": {+ "name": "issue_comments",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "uuid",+ "primaryKey": true,+ "notNull": true,+ "default": "gen_random_uuid()"+ },+ "company_id": {+ "name": "company_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": true+ },+ "issue_id": {+ "name": "issue_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": true+ },+ "author_agent_id": {+ "name": "author_agent_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": false+ },+ "author_user_id": {+ "name": "author_user_id",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "created_by_run_id": {+ "name": "created_by_run_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": false+ },+ "body": {+ "name": "body",+ "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": {+ "issue_comments_issue_idx": {+ "name": "issue_comments_issue_idx",+ "columns": [+ {+ "expression": "issue_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "issue_comments_company_idx": {+ "name": "issue_comments_company_idx",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "issue_comments_company_issue_created_at_idx": {+ "name": "issue_comments_company_issue_created_at_idx",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "issue_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "created_at",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "issue_comments_company_author_issue_created_at_idx": {+ "name": "issue_comments_company_author_issue_created_at_idx",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "author_user_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "issue_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "created_at",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "issue_comments_company_id_companies_id_fk": {+ "name": "issue_comments_company_id_companies_id_fk",+ "tableFrom": "issue_comments",+ "tableTo": "companies",+ "columnsFrom": [+ "company_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ },+ "issue_comments_issue_id_issues_id_fk": {+ "name": "issue_comments_issue_id_issues_id_fk",+ "tableFrom": "issue_comments",+ "tableTo": "issues",+ "columnsFrom": [+ "issue_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ },+ "issue_comments_author_agent_id_agents_id_fk": {+ "name": "issue_comments_author_agent_id_agents_id_fk",+ "tableFrom": "issue_comments",+ "tableTo": "agents",+ "columnsFrom": [+ "author_agent_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ },+ "issue_comments_created_by_run_id_heartbeat_runs_id_fk": {+ "name": "issue_comments_created_by_run_id_heartbeat_runs_id_fk",+ "tableFrom": "issue_comments",+ "tableTo": "heartbeat_runs",+ "columnsFrom": [+ "created_by_run_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "set null",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.issue_documents": {+ "name": "issue_documents",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "uuid",+ "primaryKey": true,+ "notNull": true,+ "default": "gen_random_uuid()"+ },+ "company_id": {+ "name": "company_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": true+ },+ "issue_id": {+ "name": "issue_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": true+ },+ "document_id": {+ "name": "document_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": true+ },+ "key": {+ "name": "key",+ "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": {+ "issue_documents_company_issue_key_uq": {+ "name": "issue_documents_company_issue_key_uq",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "issue_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "key",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": true,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "issue_documents_document_uq": {+ "name": "issue_documents_document_uq",+ "columns": [+ {+ "expression": "document_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": true,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "issue_documents_company_issue_updated_idx": {+ "name": "issue_documents_company_issue_updated_idx",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "issue_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "updated_at",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "issue_documents_company_id_companies_id_fk": {+ "name": "issue_documents_company_id_companies_id_fk",+ "tableFrom": "issue_documents",+ "tableTo": "companies",+ "columnsFrom": [+ "company_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ },+ "issue_documents_issue_id_issues_id_fk": {+ "name": "issue_documents_issue_id_issues_id_fk",+ "tableFrom": "issue_documents",+ "tableTo": "issues",+ "columnsFrom": [+ "issue_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "issue_documents_document_id_documents_id_fk": {+ "name": "issue_documents_document_id_documents_id_fk",+ "tableFrom": "issue_documents",+ "tableTo": "documents",+ "columnsFrom": [+ "document_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.issue_inbox_archives": {+ "name": "issue_inbox_archives",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "uuid",+ "primaryKey": true,+ "notNull": true,+ "default": "gen_random_uuid()"+ },+ "company_id": {+ "name": "company_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": true+ },+ "issue_id": {+ "name": "issue_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": true+ },+ "user_id": {+ "name": "user_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "archived_at": {+ "name": "archived_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ },+ "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": {+ "issue_inbox_archives_company_issue_idx": {+ "name": "issue_inbox_archives_company_issue_idx",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "issue_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "issue_inbox_archives_company_user_idx": {+ "name": "issue_inbox_archives_company_user_idx",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "user_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "issue_inbox_archives_company_issue_user_idx": {+ "name": "issue_inbox_archives_company_issue_user_idx",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "issue_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "user_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": true,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "issue_inbox_archives_company_id_companies_id_fk": {+ "name": "issue_inbox_archives_company_id_companies_id_fk",+ "tableFrom": "issue_inbox_archives",+ "tableTo": "companies",+ "columnsFrom": [+ "company_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ },+ "issue_inbox_archives_issue_id_issues_id_fk": {+ "name": "issue_inbox_archives_issue_id_issues_id_fk",+ "tableFrom": "issue_inbox_archives",+ "tableTo": "issues",+ "columnsFrom": [+ "issue_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.issue_labels": {+ "name": "issue_labels",+ "schema": "",+ "columns": {+ "issue_id": {+ "name": "issue_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": true+ },+ "label_id": {+ "name": "label_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": true+ },+ "company_id": {+ "name": "company_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": true+ },+ "created_at": {+ "name": "created_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {+ "issue_labels_issue_idx": {+ "name": "issue_labels_issue_idx",+ "columns": [+ {+ "expression": "issue_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "issue_labels_label_idx": {+ "name": "issue_labels_label_idx",+ "columns": [+ {+ "expression": "label_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "issue_labels_company_idx": {+ "name": "issue_labels_company_idx",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "issue_labels_issue_id_issues_id_fk": {+ "name": "issue_labels_issue_id_issues_id_fk",+ "tableFrom": "issue_labels",+ "tableTo": "issues",+ "columnsFrom": [+ "issue_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "issue_labels_label_id_labels_id_fk": {+ "name": "issue_labels_label_id_labels_id_fk",+ "tableFrom": "issue_labels",+ "tableTo": "labels",+ "columnsFrom": [+ "label_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "issue_labels_company_id_companies_id_fk": {+ "name": "issue_labels_company_id_companies_id_fk",+ "tableFrom": "issue_labels",+ "tableTo": "companies",+ "columnsFrom": [+ "company_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {+ "issue_labels_pk": {+ "name": "issue_labels_pk",+ "columns": [+ "issue_id",+ "label_id"+ ]+ }+ },+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.issue_read_states": {+ "name": "issue_read_states",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "uuid",+ "primaryKey": true,+ "notNull": true,+ "default": "gen_random_uuid()"+ },+ "company_id": {+ "name": "company_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": true+ },+ "issue_id": {+ "name": "issue_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": true+ },+ "user_id": {+ "name": "user_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "last_read_at": {+ "name": "last_read_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ },+ "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": {+ "issue_read_states_company_issue_idx": {+ "name": "issue_read_states_company_issue_idx",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "issue_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "issue_read_states_company_user_idx": {+ "name": "issue_read_states_company_user_idx",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "user_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "issue_read_states_company_issue_user_idx": {+ "name": "issue_read_states_company_issue_user_idx",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "issue_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "user_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": true,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "issue_read_states_company_id_companies_id_fk": {+ "name": "issue_read_states_company_id_companies_id_fk",+ "tableFrom": "issue_read_states",+ "tableTo": "companies",+ "columnsFrom": [+ "company_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ },+ "issue_read_states_issue_id_issues_id_fk": {+ "name": "issue_read_states_issue_id_issues_id_fk",+ "tableFrom": "issue_read_states",+ "tableTo": "issues",+ "columnsFrom": [+ "issue_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.issue_work_products": {+ "name": "issue_work_products",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "uuid",+ "primaryKey": true,+ "notNull": true,+ "default": "gen_random_uuid()"+ },+ "company_id": {+ "name": "company_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": true+ },+ "project_id": {+ "name": "project_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": false+ },+ "issue_id": {+ "name": "issue_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": true+ },+ "execution_workspace_id": {+ "name": "execution_workspace_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": false+ },+ "runtime_service_id": {+ "name": "runtime_service_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": false+ },+ "type": {+ "name": "type",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "provider": {+ "name": "provider",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "external_id": {+ "name": "external_id",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "title": {+ "name": "title",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "url": {+ "name": "url",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "status": {+ "name": "status",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "review_state": {+ "name": "review_state",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "'none'"+ },+ "is_primary": {+ "name": "is_primary",+ "type": "boolean",+ "primaryKey": false,+ "notNull": true,+ "default": false+ },+ "health_status": {+ "name": "health_status",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "'unknown'"+ },+ "summary": {+ "name": "summary",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "metadata": {+ "name": "metadata",+ "type": "jsonb",+ "primaryKey": false,+ "notNull": false+ },+ "created_by_run_id": {+ "name": "created_by_run_id",+ "type": "uuid",+ "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": {+ "issue_work_products_company_issue_type_idx": {+ "name": "issue_work_products_company_issue_type_idx",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "issue_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "type",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "issue_work_products_company_execution_workspace_type_idx": {+ "name": "issue_work_products_company_execution_workspace_type_idx",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "execution_workspace_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "type",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "issue_work_products_company_provider_external_id_idx": {+ "name": "issue_work_products_company_provider_external_id_idx",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "provider",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "external_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "issue_work_products_company_updated_idx": {+ "name": "issue_work_products_company_updated_idx",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "updated_at",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "issue_work_products_company_id_companies_id_fk": {+ "name": "issue_work_products_company_id_companies_id_fk",+ "tableFrom": "issue_work_products",+ "tableTo": "companies",+ "columnsFrom": [+ "company_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ },+ "issue_work_products_project_id_projects_id_fk": {+ "name": "issue_work_products_project_id_projects_id_fk",+ "tableFrom": "issue_work_products",+ "tableTo": "projects",+ "columnsFrom": [+ "project_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "set null",+ "onUpdate": "no action"+ },+ "issue_work_products_issue_id_issues_id_fk": {+ "name": "issue_work_products_issue_id_issues_id_fk",+ "tableFrom": "issue_work_products",+ "tableTo": "issues",+ "columnsFrom": [+ "issue_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "issue_work_products_execution_workspace_id_execution_workspaces_id_fk": {+ "name": "issue_work_products_execution_workspace_id_execution_workspaces_id_fk",+ "tableFrom": "issue_work_products",+ "tableTo": "execution_workspaces",+ "columnsFrom": [+ "execution_workspace_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "set null",+ "onUpdate": "no action"+ },+ "issue_work_products_runtime_service_id_workspace_runtime_services_id_fk": {+ "name": "issue_work_products_runtime_service_id_workspace_runtime_services_id_fk",+ "tableFrom": "issue_work_products",+ "tableTo": "workspace_runtime_services",+ "columnsFrom": [+ "runtime_service_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "set null",+ "onUpdate": "no action"+ },+ "issue_work_products_created_by_run_id_heartbeat_runs_id_fk": {+ "name": "issue_work_products_created_by_run_id_heartbeat_runs_id_fk",+ "tableFrom": "issue_work_products",+ "tableTo": "heartbeat_runs",+ "columnsFrom": [+ "created_by_run_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "set null",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.issues": {+ "name": "issues",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "uuid",+ "primaryKey": true,+ "notNull": true,+ "default": "gen_random_uuid()"+ },+ "company_id": {+ "name": "company_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": true+ },+ "project_id": {+ "name": "project_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": false+ },+ "project_workspace_id": {+ "name": "project_workspace_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": false+ },+ "goal_id": {+ "name": "goal_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": false+ },+ "parent_id": {+ "name": "parent_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": false+ },+ "title": {+ "name": "title",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "description": {+ "name": "description",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "status": {+ "name": "status",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "'backlog'"+ },+ "priority": {+ "name": "priority",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "'medium'"+ },+ "assignee_agent_id": {+ "name": "assignee_agent_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": false+ },+ "assignee_user_id": {+ "name": "assignee_user_id",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "checkout_run_id": {+ "name": "checkout_run_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": false+ },+ "execution_run_id": {+ "name": "execution_run_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": false+ },+ "execution_agent_name_key": {+ "name": "execution_agent_name_key",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "execution_locked_at": {+ "name": "execution_locked_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": false+ },+ "created_by_agent_id": {+ "name": "created_by_agent_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": false+ },+ "created_by_user_id": {+ "name": "created_by_user_id",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "issue_number": {+ "name": "issue_number",+ "type": "integer",+ "primaryKey": false,+ "notNull": false+ },+ "identifier": {+ "name": "identifier",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "origin_kind": {+ "name": "origin_kind",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "'manual'"+ },+ "origin_id": {+ "name": "origin_id",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "origin_run_id": {+ "name": "origin_run_id",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "request_depth": {+ "name": "request_depth",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "default": 0+ },+ "billing_code": {+ "name": "billing_code",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "assignee_adapter_overrides": {+ "name": "assignee_adapter_overrides",+ "type": "jsonb",+ "primaryKey": false,+ "notNull": false+ },+ "execution_workspace_id": {+ "name": "execution_workspace_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": false+ },+ "execution_workspace_preference": {+ "name": "execution_workspace_preference",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "execution_workspace_settings": {+ "name": "execution_workspace_settings",+ "type": "jsonb",+ "primaryKey": false,+ "notNull": false+ },+ "started_at": {+ "name": "started_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": false+ },+ "completed_at": {+ "name": "completed_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": false+ },+ "cancelled_at": {+ "name": "cancelled_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": false+ },+ "hidden_at": {+ "name": "hidden_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": {+ "issues_company_status_idx": {+ "name": "issues_company_status_idx",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "status",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "issues_company_assignee_status_idx": {+ "name": "issues_company_assignee_status_idx",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "assignee_agent_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "status",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "issues_company_assignee_user_status_idx": {+ "name": "issues_company_assignee_user_status_idx",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "assignee_user_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "status",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "issues_company_parent_idx": {+ "name": "issues_company_parent_idx",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "parent_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "issues_company_project_idx": {+ "name": "issues_company_project_idx",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "project_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "issues_company_origin_idx": {+ "name": "issues_company_origin_idx",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "origin_kind",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "origin_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "issues_company_project_workspace_idx": {+ "name": "issues_company_project_workspace_idx",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "project_workspace_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "issues_company_execution_workspace_idx": {+ "name": "issues_company_execution_workspace_idx",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "execution_workspace_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "issues_identifier_idx": {+ "name": "issues_identifier_idx",+ "columns": [+ {+ "expression": "identifier",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": true,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "issues_open_routine_execution_uq": {+ "name": "issues_open_routine_execution_uq",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "origin_kind",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "origin_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": true,+ "where": "\"issues\".\"origin_kind\" = 'routine_execution'\n and \"issues\".\"origin_id\" is not null\n and \"issues\".\"hidden_at\" is null\n and \"issues\".\"execution_run_id\" is not null\n and \"issues\".\"status\" in ('backlog', 'todo', 'in_progress', 'in_review', 'blocked')",+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "issues_company_id_companies_id_fk": {+ "name": "issues_company_id_companies_id_fk",+ "tableFrom": "issues",+ "tableTo": "companies",+ "columnsFrom": [+ "company_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ },+ "issues_project_id_projects_id_fk": {+ "name": "issues_project_id_projects_id_fk",+ "tableFrom": "issues",+ "tableTo": "projects",+ "columnsFrom": [+ "project_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ },+ "issues_project_workspace_id_project_workspaces_id_fk": {+ "name": "issues_project_workspace_id_project_workspaces_id_fk",+ "tableFrom": "issues",+ "tableTo": "project_workspaces",+ "columnsFrom": [+ "project_workspace_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "set null",+ "onUpdate": "no action"+ },+ "issues_goal_id_goals_id_fk": {+ "name": "issues_goal_id_goals_id_fk",+ "tableFrom": "issues",+ "tableTo": "goals",+ "columnsFrom": [+ "goal_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ },+ "issues_parent_id_issues_id_fk": {+ "name": "issues_parent_id_issues_id_fk",+ "tableFrom": "issues",+ "tableTo": "issues",+ "columnsFrom": [+ "parent_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ },+ "issues_assignee_agent_id_agents_id_fk": {+ "name": "issues_assignee_agent_id_agents_id_fk",+ "tableFrom": "issues",+ "tableTo": "agents",+ "columnsFrom": [+ "assignee_agent_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ },+ "issues_checkout_run_id_heartbeat_runs_id_fk": {+ "name": "issues_checkout_run_id_heartbeat_runs_id_fk",+ "tableFrom": "issues",+ "tableTo": "heartbeat_runs",+ "columnsFrom": [+ "checkout_run_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "set null",+ "onUpdate": "no action"+ },+ "issues_execution_run_id_heartbeat_runs_id_fk": {+ "name": "issues_execution_run_id_heartbeat_runs_id_fk",+ "tableFrom": "issues",+ "tableTo": "heartbeat_runs",+ "columnsFrom": [+ "execution_run_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "set null",+ "onUpdate": "no action"+ },+ "issues_created_by_agent_id_agents_id_fk": {+ "name": "issues_created_by_agent_id_agents_id_fk",+ "tableFrom": "issues",+ "tableTo": "agents",+ "columnsFrom": [+ "created_by_agent_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ },+ "issues_execution_workspace_id_execution_workspaces_id_fk": {+ "name": "issues_execution_workspace_id_execution_workspaces_id_fk",+ "tableFrom": "issues",+ "tableTo": "execution_workspaces",+ "columnsFrom": [+ "execution_workspace_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "set null",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.join_requests": {+ "name": "join_requests",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "uuid",+ "primaryKey": true,+ "notNull": true,+ "default": "gen_random_uuid()"+ },+ "invite_id": {+ "name": "invite_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": true+ },+ "company_id": {+ "name": "company_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": true+ },+ "request_type": {+ "name": "request_type",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "status": {+ "name": "status",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "'pending_approval'"+ },+ "request_ip": {+ "name": "request_ip",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "requesting_user_id": {+ "name": "requesting_user_id",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "request_email_snapshot": {+ "name": "request_email_snapshot",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "agent_name": {+ "name": "agent_name",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "adapter_type": {+ "name": "adapter_type",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "capabilities": {+ "name": "capabilities",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "agent_defaults_payload": {+ "name": "agent_defaults_payload",+ "type": "jsonb",+ "primaryKey": false,+ "notNull": false+ },+ "claim_secret_hash": {+ "name": "claim_secret_hash",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "claim_secret_expires_at": {+ "name": "claim_secret_expires_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": false+ },+ "claim_secret_consumed_at": {+ "name": "claim_secret_consumed_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": false+ },+ "created_agent_id": {+ "name": "created_agent_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": false+ },+ "approved_by_user_id": {+ "name": "approved_by_user_id",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "approved_at": {+ "name": "approved_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": false+ },+ "rejected_by_user_id": {+ "name": "rejected_by_user_id",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "rejected_at": {+ "name": "rejected_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": {+ "join_requests_invite_unique_idx": {+ "name": "join_requests_invite_unique_idx",+ "columns": [+ {+ "expression": "invite_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": true,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "join_requests_company_status_type_created_idx": {+ "name": "join_requests_company_status_type_created_idx",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "status",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "request_type",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "created_at",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "join_requests_invite_id_invites_id_fk": {+ "name": "join_requests_invite_id_invites_id_fk",+ "tableFrom": "join_requests",+ "tableTo": "invites",+ "columnsFrom": [+ "invite_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ },+ "join_requests_company_id_companies_id_fk": {+ "name": "join_requests_company_id_companies_id_fk",+ "tableFrom": "join_requests",+ "tableTo": "companies",+ "columnsFrom": [+ "company_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ },+ "join_requests_created_agent_id_agents_id_fk": {+ "name": "join_requests_created_agent_id_agents_id_fk",+ "tableFrom": "join_requests",+ "tableTo": "agents",+ "columnsFrom": [+ "created_agent_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.labels": {+ "name": "labels",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "uuid",+ "primaryKey": true,+ "notNull": true,+ "default": "gen_random_uuid()"+ },+ "company_id": {+ "name": "company_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": true+ },+ "name": {+ "name": "name",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "color": {+ "name": "color",+ "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": {+ "labels_company_idx": {+ "name": "labels_company_idx",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "labels_company_name_idx": {+ "name": "labels_company_name_idx",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "name",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": true,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "labels_company_id_companies_id_fk": {+ "name": "labels_company_id_companies_id_fk",+ "tableFrom": "labels",+ "tableTo": "companies",+ "columnsFrom": [+ "company_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.plugin_company_settings": {+ "name": "plugin_company_settings",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "uuid",+ "primaryKey": true,+ "notNull": true,+ "default": "gen_random_uuid()"+ },+ "company_id": {+ "name": "company_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": true+ },+ "plugin_id": {+ "name": "plugin_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": true+ },+ "enabled": {+ "name": "enabled",+ "type": "boolean",+ "primaryKey": false,+ "notNull": true,+ "default": true+ },+ "settings_json": {+ "name": "settings_json",+ "type": "jsonb",+ "primaryKey": false,+ "notNull": true,+ "default": "'{}'::jsonb"+ },+ "last_error": {+ "name": "last_error",+ "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_company_settings_company_idx": {+ "name": "plugin_company_settings_company_idx",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "plugin_company_settings_plugin_idx": {+ "name": "plugin_company_settings_plugin_idx",+ "columns": [+ {+ "expression": "plugin_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "plugin_company_settings_company_plugin_uq": {+ "name": "plugin_company_settings_company_plugin_uq",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "plugin_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": true,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "plugin_company_settings_company_id_companies_id_fk": {+ "name": "plugin_company_settings_company_id_companies_id_fk",+ "tableFrom": "plugin_company_settings",+ "tableTo": "companies",+ "columnsFrom": [+ "company_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "plugin_company_settings_plugin_id_plugins_id_fk": {+ "name": "plugin_company_settings_plugin_id_plugins_id_fk",+ "tableFrom": "plugin_company_settings",+ "tableTo": "plugins",+ "columnsFrom": [+ "plugin_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.plugin_config": {+ "name": "plugin_config",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "uuid",+ "primaryKey": true,+ "notNull": true,+ "default": "gen_random_uuid()"+ },+ "plugin_id": {+ "name": "plugin_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": true+ },+ "config_json": {+ "name": "config_json",+ "type": "jsonb",+ "primaryKey": false,+ "notNull": true,+ "default": "'{}'::jsonb"+ },+ "last_error": {+ "name": "last_error",+ "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_config_plugin_id_idx": {+ "name": "plugin_config_plugin_id_idx",+ "columns": [+ {+ "expression": "plugin_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": true,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "plugin_config_plugin_id_plugins_id_fk": {+ "name": "plugin_config_plugin_id_plugins_id_fk",+ "tableFrom": "plugin_config",+ "tableTo": "plugins",+ "columnsFrom": [+ "plugin_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.plugin_entities": {+ "name": "plugin_entities",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "uuid",+ "primaryKey": true,+ "notNull": true,+ "default": "gen_random_uuid()"+ },+ "plugin_id": {+ "name": "plugin_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": true+ },+ "entity_type": {+ "name": "entity_type",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "scope_kind": {+ "name": "scope_kind",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "scope_id": {+ "name": "scope_id",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "external_id": {+ "name": "external_id",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "title": {+ "name": "title",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "status": {+ "name": "status",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "data": {+ "name": "data",+ "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": {+ "plugin_entities_plugin_idx": {+ "name": "plugin_entities_plugin_idx",+ "columns": [+ {+ "expression": "plugin_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "plugin_entities_type_idx": {+ "name": "plugin_entities_type_idx",+ "columns": [+ {+ "expression": "entity_type",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "plugin_entities_scope_idx": {+ "name": "plugin_entities_scope_idx",+ "columns": [+ {+ "expression": "scope_kind",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "scope_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "plugin_entities_external_idx": {+ "name": "plugin_entities_external_idx",+ "columns": [+ {+ "expression": "plugin_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "entity_type",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "external_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": true,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "plugin_entities_plugin_id_plugins_id_fk": {+ "name": "plugin_entities_plugin_id_plugins_id_fk",+ "tableFrom": "plugin_entities",+ "tableTo": "plugins",+ "columnsFrom": [+ "plugin_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.plugin_job_runs": {+ "name": "plugin_job_runs",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "uuid",+ "primaryKey": true,+ "notNull": true,+ "default": "gen_random_uuid()"+ },+ "job_id": {+ "name": "job_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": true+ },+ "plugin_id": {+ "name": "plugin_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": true+ },+ "trigger": {+ "name": "trigger",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "status": {+ "name": "status",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "'pending'"+ },+ "duration_ms": {+ "name": "duration_ms",+ "type": "integer",+ "primaryKey": false,+ "notNull": false+ },+ "error": {+ "name": "error",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "logs": {+ "name": "logs",+ "type": "jsonb",+ "primaryKey": false,+ "notNull": true,+ "default": "'[]'::jsonb"+ },+ "started_at": {+ "name": "started_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": false+ },+ "finished_at": {+ "name": "finished_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": {+ "plugin_job_runs_job_idx": {+ "name": "plugin_job_runs_job_idx",+ "columns": [+ {+ "expression": "job_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "plugin_job_runs_plugin_idx": {+ "name": "plugin_job_runs_plugin_idx",+ "columns": [+ {+ "expression": "plugin_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "plugin_job_runs_status_idx": {+ "name": "plugin_job_runs_status_idx",+ "columns": [+ {+ "expression": "status",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "plugin_job_runs_job_id_plugin_jobs_id_fk": {+ "name": "plugin_job_runs_job_id_plugin_jobs_id_fk",+ "tableFrom": "plugin_job_runs",+ "tableTo": "plugin_jobs",+ "columnsFrom": [+ "job_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "plugin_job_runs_plugin_id_plugins_id_fk": {+ "name": "plugin_job_runs_plugin_id_plugins_id_fk",+ "tableFrom": "plugin_job_runs",+ "tableTo": "plugins",+ "columnsFrom": [+ "plugin_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.plugin_jobs": {+ "name": "plugin_jobs",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "uuid",+ "primaryKey": true,+ "notNull": true,+ "default": "gen_random_uuid()"+ },+ "plugin_id": {+ "name": "plugin_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": true+ },+ "job_key": {+ "name": "job_key",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "schedule": {+ "name": "schedule",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "status": {+ "name": "status",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "'active'"+ },+ "last_run_at": {+ "name": "last_run_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": false+ },+ "next_run_at": {+ "name": "next_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": {+ "plugin_jobs_plugin_idx": {+ "name": "plugin_jobs_plugin_idx",+ "columns": [+ {+ "expression": "plugin_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "plugin_jobs_next_run_idx": {+ "name": "plugin_jobs_next_run_idx",+ "columns": [+ {+ "expression": "next_run_at",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "plugin_jobs_unique_idx": {+ "name": "plugin_jobs_unique_idx",+ "columns": [+ {+ "expression": "plugin_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "job_key",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": true,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "plugin_jobs_plugin_id_plugins_id_fk": {+ "name": "plugin_jobs_plugin_id_plugins_id_fk",+ "tableFrom": "plugin_jobs",+ "tableTo": "plugins",+ "columnsFrom": [+ "plugin_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.plugin_logs": {+ "name": "plugin_logs",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "uuid",+ "primaryKey": true,+ "notNull": true,+ "default": "gen_random_uuid()"+ },+ "plugin_id": {+ "name": "plugin_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": true+ },+ "level": {+ "name": "level",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "'info'"+ },+ "message": {+ "name": "message",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "meta": {+ "name": "meta",+ "type": "jsonb",+ "primaryKey": false,+ "notNull": false+ },+ "created_at": {+ "name": "created_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {+ "plugin_logs_plugin_time_idx": {+ "name": "plugin_logs_plugin_time_idx",+ "columns": [+ {+ "expression": "plugin_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "created_at",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "plugin_logs_level_idx": {+ "name": "plugin_logs_level_idx",+ "columns": [+ {+ "expression": "level",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "plugin_logs_plugin_id_plugins_id_fk": {+ "name": "plugin_logs_plugin_id_plugins_id_fk",+ "tableFrom": "plugin_logs",+ "tableTo": "plugins",+ "columnsFrom": [+ "plugin_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.plugin_state": {+ "name": "plugin_state",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "uuid",+ "primaryKey": true,+ "notNull": true,+ "default": "gen_random_uuid()"+ },+ "plugin_id": {+ "name": "plugin_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": true+ },+ "scope_kind": {+ "name": "scope_kind",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "scope_id": {+ "name": "scope_id",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "namespace": {+ "name": "namespace",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "'default'"+ },+ "state_key": {+ "name": "state_key",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "value_json": {+ "name": "value_json",+ "type": "jsonb",+ "primaryKey": false,+ "notNull": true+ },+ "updated_at": {+ "name": "updated_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {+ "plugin_state_plugin_scope_idx": {+ "name": "plugin_state_plugin_scope_idx",+ "columns": [+ {+ "expression": "plugin_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "scope_kind",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "plugin_state_plugin_id_plugins_id_fk": {+ "name": "plugin_state_plugin_id_plugins_id_fk",+ "tableFrom": "plugin_state",+ "tableTo": "plugins",+ "columnsFrom": [+ "plugin_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {+ "plugin_state_unique_entry_idx": {+ "name": "plugin_state_unique_entry_idx",+ "nullsNotDistinct": true,+ "columns": [+ "plugin_id",+ "scope_kind",+ "scope_id",+ "namespace",+ "state_key"+ ]+ }+ },+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.plugin_webhook_deliveries": {+ "name": "plugin_webhook_deliveries",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "uuid",+ "primaryKey": true,+ "notNull": true,+ "default": "gen_random_uuid()"+ },+ "plugin_id": {+ "name": "plugin_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": true+ },+ "webhook_key": {+ "name": "webhook_key",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "external_id": {+ "name": "external_id",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "status": {+ "name": "status",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "'pending'"+ },+ "duration_ms": {+ "name": "duration_ms",+ "type": "integer",+ "primaryKey": false,+ "notNull": false+ },+ "error": {+ "name": "error",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "payload": {+ "name": "payload",+ "type": "jsonb",+ "primaryKey": false,+ "notNull": true+ },+ "headers": {+ "name": "headers",+ "type": "jsonb",+ "primaryKey": false,+ "notNull": true,+ "default": "'{}'::jsonb"+ },+ "started_at": {+ "name": "started_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": false+ },+ "finished_at": {+ "name": "finished_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": {+ "plugin_webhook_deliveries_plugin_idx": {+ "name": "plugin_webhook_deliveries_plugin_idx",+ "columns": [+ {+ "expression": "plugin_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "plugin_webhook_deliveries_status_idx": {+ "name": "plugin_webhook_deliveries_status_idx",+ "columns": [+ {+ "expression": "status",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "plugin_webhook_deliveries_key_idx": {+ "name": "plugin_webhook_deliveries_key_idx",+ "columns": [+ {+ "expression": "webhook_key",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "plugin_webhook_deliveries_plugin_id_plugins_id_fk": {+ "name": "plugin_webhook_deliveries_plugin_id_plugins_id_fk",+ "tableFrom": "plugin_webhook_deliveries",+ "tableTo": "plugins",+ "columnsFrom": [+ "plugin_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.plugins": {+ "name": "plugins",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "uuid",+ "primaryKey": true,+ "notNull": true,+ "default": "gen_random_uuid()"+ },+ "plugin_key": {+ "name": "plugin_key",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "package_name": {+ "name": "package_name",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "version": {+ "name": "version",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "api_version": {+ "name": "api_version",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "default": 1+ },+ "categories": {+ "name": "categories",+ "type": "jsonb",+ "primaryKey": false,+ "notNull": true,+ "default": "'[]'::jsonb"+ },+ "manifest_json": {+ "name": "manifest_json",+ "type": "jsonb",+ "primaryKey": false,+ "notNull": true+ },+ "status": {+ "name": "status",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "'installed'"+ },+ "install_order": {+ "name": "install_order",+ "type": "integer",+ "primaryKey": false,+ "notNull": false+ },+ "package_path": {+ "name": "package_path",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "last_error": {+ "name": "last_error",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "installed_at": {+ "name": "installed_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": {+ "plugins_plugin_key_idx": {+ "name": "plugins_plugin_key_idx",+ "columns": [+ {+ "expression": "plugin_key",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": true,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "plugins_status_idx": {+ "name": "plugins_status_idx",+ "columns": [+ {+ "expression": "status",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {},+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.principal_permission_grants": {+ "name": "principal_permission_grants",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "uuid",+ "primaryKey": true,+ "notNull": true,+ "default": "gen_random_uuid()"+ },+ "company_id": {+ "name": "company_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": true+ },+ "principal_type": {+ "name": "principal_type",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "principal_id": {+ "name": "principal_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "permission_key": {+ "name": "permission_key",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "scope": {+ "name": "scope",+ "type": "jsonb",+ "primaryKey": false,+ "notNull": false+ },+ "granted_by_user_id": {+ "name": "granted_by_user_id",+ "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": {+ "principal_permission_grants_unique_idx": {+ "name": "principal_permission_grants_unique_idx",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "principal_type",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "principal_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "permission_key",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": true,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "principal_permission_grants_company_permission_idx": {+ "name": "principal_permission_grants_company_permission_idx",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "permission_key",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "principal_permission_grants_company_id_companies_id_fk": {+ "name": "principal_permission_grants_company_id_companies_id_fk",+ "tableFrom": "principal_permission_grants",+ "tableTo": "companies",+ "columnsFrom": [+ "company_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.project_goals": {+ "name": "project_goals",+ "schema": "",+ "columns": {+ "project_id": {+ "name": "project_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": true+ },+ "goal_id": {+ "name": "goal_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": true+ },+ "company_id": {+ "name": "company_id",+ "type": "uuid",+ "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": {+ "project_goals_project_idx": {+ "name": "project_goals_project_idx",+ "columns": [+ {+ "expression": "project_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "project_goals_goal_idx": {+ "name": "project_goals_goal_idx",+ "columns": [+ {+ "expression": "goal_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "project_goals_company_idx": {+ "name": "project_goals_company_idx",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "project_goals_project_id_projects_id_fk": {+ "name": "project_goals_project_id_projects_id_fk",+ "tableFrom": "project_goals",+ "tableTo": "projects",+ "columnsFrom": [+ "project_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "project_goals_goal_id_goals_id_fk": {+ "name": "project_goals_goal_id_goals_id_fk",+ "tableFrom": "project_goals",+ "tableTo": "goals",+ "columnsFrom": [+ "goal_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "project_goals_company_id_companies_id_fk": {+ "name": "project_goals_company_id_companies_id_fk",+ "tableFrom": "project_goals",+ "tableTo": "companies",+ "columnsFrom": [+ "company_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {+ "project_goals_project_id_goal_id_pk": {+ "name": "project_goals_project_id_goal_id_pk",+ "columns": [+ "project_id",+ "goal_id"+ ]+ }+ },+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.project_workspaces": {+ "name": "project_workspaces",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "uuid",+ "primaryKey": true,+ "notNull": true,+ "default": "gen_random_uuid()"+ },+ "company_id": {+ "name": "company_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": true+ },+ "project_id": {+ "name": "project_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": true+ },+ "name": {+ "name": "name",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "source_type": {+ "name": "source_type",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "'local_path'"+ },+ "cwd": {+ "name": "cwd",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "repo_url": {+ "name": "repo_url",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "repo_ref": {+ "name": "repo_ref",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "default_ref": {+ "name": "default_ref",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "visibility": {+ "name": "visibility",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "'default'"+ },+ "setup_command": {+ "name": "setup_command",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "cleanup_command": {+ "name": "cleanup_command",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "remote_provider": {+ "name": "remote_provider",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "remote_workspace_ref": {+ "name": "remote_workspace_ref",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "shared_workspace_key": {+ "name": "shared_workspace_key",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "metadata": {+ "name": "metadata",+ "type": "jsonb",+ "primaryKey": false,+ "notNull": false+ },+ "is_primary": {+ "name": "is_primary",+ "type": "boolean",+ "primaryKey": false,+ "notNull": true,+ "default": 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": {+ "project_workspaces_company_project_idx": {+ "name": "project_workspaces_company_project_idx",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "project_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "project_workspaces_project_primary_idx": {+ "name": "project_workspaces_project_primary_idx",+ "columns": [+ {+ "expression": "project_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "is_primary",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "project_workspaces_project_source_type_idx": {+ "name": "project_workspaces_project_source_type_idx",+ "columns": [+ {+ "expression": "project_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "source_type",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "project_workspaces_company_shared_key_idx": {+ "name": "project_workspaces_company_shared_key_idx",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "shared_workspace_key",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "project_workspaces_project_remote_ref_idx": {+ "name": "project_workspaces_project_remote_ref_idx",+ "columns": [+ {+ "expression": "project_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "remote_provider",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "remote_workspace_ref",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": true,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "project_workspaces_company_id_companies_id_fk": {+ "name": "project_workspaces_company_id_companies_id_fk",+ "tableFrom": "project_workspaces",+ "tableTo": "companies",+ "columnsFrom": [+ "company_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ },+ "project_workspaces_project_id_projects_id_fk": {+ "name": "project_workspaces_project_id_projects_id_fk",+ "tableFrom": "project_workspaces",+ "tableTo": "projects",+ "columnsFrom": [+ "project_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.projects": {+ "name": "projects",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "uuid",+ "primaryKey": true,+ "notNull": true,+ "default": "gen_random_uuid()"+ },+ "company_id": {+ "name": "company_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": true+ },+ "goal_id": {+ "name": "goal_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": false+ },+ "name": {+ "name": "name",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "description": {+ "name": "description",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "status": {+ "name": "status",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "'backlog'"+ },+ "lead_agent_id": {+ "name": "lead_agent_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": false+ },+ "target_date": {+ "name": "target_date",+ "type": "date",+ "primaryKey": false,+ "notNull": false+ },+ "color": {+ "name": "color",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "pause_reason": {+ "name": "pause_reason",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "paused_at": {+ "name": "paused_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": false+ },+ "execution_workspace_policy": {+ "name": "execution_workspace_policy",+ "type": "jsonb",+ "primaryKey": false,+ "notNull": false+ },+ "archived_at": {+ "name": "archived_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": {+ "projects_company_idx": {+ "name": "projects_company_idx",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "projects_company_id_companies_id_fk": {+ "name": "projects_company_id_companies_id_fk",+ "tableFrom": "projects",+ "tableTo": "companies",+ "columnsFrom": [+ "company_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ },+ "projects_goal_id_goals_id_fk": {+ "name": "projects_goal_id_goals_id_fk",+ "tableFrom": "projects",+ "tableTo": "goals",+ "columnsFrom": [+ "goal_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ },+ "projects_lead_agent_id_agents_id_fk": {+ "name": "projects_lead_agent_id_agents_id_fk",+ "tableFrom": "projects",+ "tableTo": "agents",+ "columnsFrom": [+ "lead_agent_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.routine_runs": {+ "name": "routine_runs",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "uuid",+ "primaryKey": true,+ "notNull": true,+ "default": "gen_random_uuid()"+ },+ "company_id": {+ "name": "company_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": true+ },+ "routine_id": {+ "name": "routine_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": true+ },+ "trigger_id": {+ "name": "trigger_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": false+ },+ "source": {+ "name": "source",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "status": {+ "name": "status",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "'received'"+ },+ "triggered_at": {+ "name": "triggered_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ },+ "idempotency_key": {+ "name": "idempotency_key",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "trigger_payload": {+ "name": "trigger_payload",+ "type": "jsonb",+ "primaryKey": false,+ "notNull": false+ },+ "linked_issue_id": {+ "name": "linked_issue_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": false+ },+ "coalesced_into_run_id": {+ "name": "coalesced_into_run_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": false+ },+ "failure_reason": {+ "name": "failure_reason",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "completed_at": {+ "name": "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": {+ "routine_runs_company_routine_idx": {+ "name": "routine_runs_company_routine_idx",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "routine_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "created_at",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "routine_runs_trigger_idx": {+ "name": "routine_runs_trigger_idx",+ "columns": [+ {+ "expression": "trigger_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "created_at",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "routine_runs_linked_issue_idx": {+ "name": "routine_runs_linked_issue_idx",+ "columns": [+ {+ "expression": "linked_issue_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "routine_runs_trigger_idempotency_idx": {+ "name": "routine_runs_trigger_idempotency_idx",+ "columns": [+ {+ "expression": "trigger_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "idempotency_key",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "routine_runs_company_id_companies_id_fk": {+ "name": "routine_runs_company_id_companies_id_fk",+ "tableFrom": "routine_runs",+ "tableTo": "companies",+ "columnsFrom": [+ "company_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "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"+ },+ "routine_runs_trigger_id_routine_triggers_id_fk": {+ "name": "routine_runs_trigger_id_routine_triggers_id_fk",+ "tableFrom": "routine_runs",+ "tableTo": "routine_triggers",+ "columnsFrom": [+ "trigger_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "set null",+ "onUpdate": "no action"+ },+ "routine_runs_linked_issue_id_issues_id_fk": {+ "name": "routine_runs_linked_issue_id_issues_id_fk",+ "tableFrom": "routine_runs",+ "tableTo": "issues",+ "columnsFrom": [+ "linked_issue_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "set null",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.routine_triggers": {+ "name": "routine_triggers",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "uuid",+ "primaryKey": true,+ "notNull": true,+ "default": "gen_random_uuid()"+ },+ "company_id": {+ "name": "company_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": true+ },+ "routine_id": {+ "name": "routine_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": true+ },+ "kind": {+ "name": "kind",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "label": {+ "name": "label",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "enabled": {+ "name": "enabled",+ "type": "boolean",+ "primaryKey": false,+ "notNull": true,+ "default": true+ },+ "cron_expression": {+ "name": "cron_expression",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "timezone": {+ "name": "timezone",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "next_run_at": {+ "name": "next_run_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": false+ },+ "last_fired_at": {+ "name": "last_fired_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": false+ },+ "public_id": {+ "name": "public_id",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "secret_id": {+ "name": "secret_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": false+ },+ "signing_mode": {+ "name": "signing_mode",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "replay_window_sec": {+ "name": "replay_window_sec",+ "type": "integer",+ "primaryKey": false,+ "notNull": false+ },+ "last_rotated_at": {+ "name": "last_rotated_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": false+ },+ "last_result": {+ "name": "last_result",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "created_by_agent_id": {+ "name": "created_by_agent_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": false+ },+ "created_by_user_id": {+ "name": "created_by_user_id",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "updated_by_agent_id": {+ "name": "updated_by_agent_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": false+ },+ "updated_by_user_id": {+ "name": "updated_by_user_id",+ "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": {+ "routine_triggers_company_routine_idx": {+ "name": "routine_triggers_company_routine_idx",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "routine_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "routine_triggers_company_kind_idx": {+ "name": "routine_triggers_company_kind_idx",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "kind",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "routine_triggers_next_run_idx": {+ "name": "routine_triggers_next_run_idx",+ "columns": [+ {+ "expression": "next_run_at",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "routine_triggers_public_id_idx": {+ "name": "routine_triggers_public_id_idx",+ "columns": [+ {+ "expression": "public_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "routine_triggers_public_id_uq": {+ "name": "routine_triggers_public_id_uq",+ "columns": [+ {+ "expression": "public_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": true,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "routine_triggers_company_id_companies_id_fk": {+ "name": "routine_triggers_company_id_companies_id_fk",+ "tableFrom": "routine_triggers",+ "tableTo": "companies",+ "columnsFrom": [+ "company_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "routine_triggers_routine_id_routines_id_fk": {+ "name": "routine_triggers_routine_id_routines_id_fk",+ "tableFrom": "routine_triggers",+ "tableTo": "routines",+ "columnsFrom": [+ "routine_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "routine_triggers_secret_id_company_secrets_id_fk": {+ "name": "routine_triggers_secret_id_company_secrets_id_fk",+ "tableFrom": "routine_triggers",+ "tableTo": "company_secrets",+ "columnsFrom": [+ "secret_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "set null",+ "onUpdate": "no action"+ },+ "routine_triggers_created_by_agent_id_agents_id_fk": {+ "name": "routine_triggers_created_by_agent_id_agents_id_fk",+ "tableFrom": "routine_triggers",+ "tableTo": "agents",+ "columnsFrom": [+ "created_by_agent_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "set null",+ "onUpdate": "no action"+ },+ "routine_triggers_updated_by_agent_id_agents_id_fk": {+ "name": "routine_triggers_updated_by_agent_id_agents_id_fk",+ "tableFrom": "routine_triggers",+ "tableTo": "agents",+ "columnsFrom": [+ "updated_by_agent_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "set null",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.routines": {+ "name": "routines",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "uuid",+ "primaryKey": true,+ "notNull": true,+ "default": "gen_random_uuid()"+ },+ "company_id": {+ "name": "company_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": true+ },+ "project_id": {+ "name": "project_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": true+ },+ "goal_id": {+ "name": "goal_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": false+ },+ "parent_issue_id": {+ "name": "parent_issue_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": false+ },+ "title": {+ "name": "title",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "description": {+ "name": "description",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "assignee_agent_id": {+ "name": "assignee_agent_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": true+ },+ "priority": {+ "name": "priority",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "'medium'"+ },+ "status": {+ "name": "status",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "'active'"+ },+ "concurrency_policy": {+ "name": "concurrency_policy",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "'coalesce_if_active'"+ },+ "catch_up_policy": {+ "name": "catch_up_policy",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "'skip_missed'"+ },+ "variables": {+ "name": "variables",+ "type": "jsonb",+ "primaryKey": false,+ "notNull": true,+ "default": "'[]'::jsonb"+ },+ "created_by_agent_id": {+ "name": "created_by_agent_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": false+ },+ "created_by_user_id": {+ "name": "created_by_user_id",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "updated_by_agent_id": {+ "name": "updated_by_agent_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": false+ },+ "updated_by_user_id": {+ "name": "updated_by_user_id",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "last_triggered_at": {+ "name": "last_triggered_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": false+ },+ "last_enqueued_at": {+ "name": "last_enqueued_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_company_status_idx": {+ "name": "routines_company_status_idx",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "status",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "routines_company_assignee_idx": {+ "name": "routines_company_assignee_idx",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "assignee_agent_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "routines_company_project_idx": {+ "name": "routines_company_project_idx",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "project_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "routines_company_id_companies_id_fk": {+ "name": "routines_company_id_companies_id_fk",+ "tableFrom": "routines",+ "tableTo": "companies",+ "columnsFrom": [+ "company_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "routines_project_id_projects_id_fk": {+ "name": "routines_project_id_projects_id_fk",+ "tableFrom": "routines",+ "tableTo": "projects",+ "columnsFrom": [+ "project_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "routines_goal_id_goals_id_fk": {+ "name": "routines_goal_id_goals_id_fk",+ "tableFrom": "routines",+ "tableTo": "goals",+ "columnsFrom": [+ "goal_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "set null",+ "onUpdate": "no action"+ },+ "routines_parent_issue_id_issues_id_fk": {+ "name": "routines_parent_issue_id_issues_id_fk",+ "tableFrom": "routines",+ "tableTo": "issues",+ "columnsFrom": [+ "parent_issue_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "set null",+ "onUpdate": "no action"+ },+ "routines_assignee_agent_id_agents_id_fk": {+ "name": "routines_assignee_agent_id_agents_id_fk",+ "tableFrom": "routines",+ "tableTo": "agents",+ "columnsFrom": [+ "assignee_agent_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ },+ "routines_created_by_agent_id_agents_id_fk": {+ "name": "routines_created_by_agent_id_agents_id_fk",+ "tableFrom": "routines",+ "tableTo": "agents",+ "columnsFrom": [+ "created_by_agent_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "set null",+ "onUpdate": "no action"+ },+ "routines_updated_by_agent_id_agents_id_fk": {+ "name": "routines_updated_by_agent_id_agents_id_fk",+ "tableFrom": "routines",+ "tableTo": "agents",+ "columnsFrom": [+ "updated_by_agent_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "set null",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.workspace_operations": {+ "name": "workspace_operations",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "uuid",+ "primaryKey": true,+ "notNull": true,+ "default": "gen_random_uuid()"+ },+ "company_id": {+ "name": "company_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": true+ },+ "execution_workspace_id": {+ "name": "execution_workspace_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": false+ },+ "heartbeat_run_id": {+ "name": "heartbeat_run_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": false+ },+ "phase": {+ "name": "phase",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "command": {+ "name": "command",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "cwd": {+ "name": "cwd",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "status": {+ "name": "status",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "'running'"+ },+ "exit_code": {+ "name": "exit_code",+ "type": "integer",+ "primaryKey": false,+ "notNull": false+ },+ "log_store": {+ "name": "log_store",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "log_ref": {+ "name": "log_ref",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "log_bytes": {+ "name": "log_bytes",+ "type": "bigint",+ "primaryKey": false,+ "notNull": false+ },+ "log_sha256": {+ "name": "log_sha256",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "log_compressed": {+ "name": "log_compressed",+ "type": "boolean",+ "primaryKey": false,+ "notNull": true,+ "default": false+ },+ "stdout_excerpt": {+ "name": "stdout_excerpt",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "stderr_excerpt": {+ "name": "stderr_excerpt",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "metadata": {+ "name": "metadata",+ "type": "jsonb",+ "primaryKey": false,+ "notNull": false+ },+ "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+ },+ "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": {+ "workspace_operations_company_run_started_idx": {+ "name": "workspace_operations_company_run_started_idx",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "heartbeat_run_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "started_at",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "workspace_operations_company_workspace_started_idx": {+ "name": "workspace_operations_company_workspace_started_idx",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "execution_workspace_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "started_at",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "workspace_operations_company_id_companies_id_fk": {+ "name": "workspace_operations_company_id_companies_id_fk",+ "tableFrom": "workspace_operations",+ "tableTo": "companies",+ "columnsFrom": [+ "company_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ },+ "workspace_operations_execution_workspace_id_execution_workspaces_id_fk": {+ "name": "workspace_operations_execution_workspace_id_execution_workspaces_id_fk",+ "tableFrom": "workspace_operations",+ "tableTo": "execution_workspaces",+ "columnsFrom": [+ "execution_workspace_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "set null",+ "onUpdate": "no action"+ },+ "workspace_operations_heartbeat_run_id_heartbeat_runs_id_fk": {+ "name": "workspace_operations_heartbeat_run_id_heartbeat_runs_id_fk",+ "tableFrom": "workspace_operations",+ "tableTo": "heartbeat_runs",+ "columnsFrom": [+ "heartbeat_run_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "set null",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.workspace_runtime_services": {+ "name": "workspace_runtime_services",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "uuid",+ "primaryKey": true,+ "notNull": true+ },+ "company_id": {+ "name": "company_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": true+ },+ "project_id": {+ "name": "project_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": false+ },+ "project_workspace_id": {+ "name": "project_workspace_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": false+ },+ "execution_workspace_id": {+ "name": "execution_workspace_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": false+ },+ "issue_id": {+ "name": "issue_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": false+ },+ "scope_type": {+ "name": "scope_type",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "scope_id": {+ "name": "scope_id",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "service_name": {+ "name": "service_name",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "status": {+ "name": "status",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "lifecycle": {+ "name": "lifecycle",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "reuse_key": {+ "name": "reuse_key",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "command": {+ "name": "command",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "cwd": {+ "name": "cwd",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "port": {+ "name": "port",+ "type": "integer",+ "primaryKey": false,+ "notNull": false+ },+ "url": {+ "name": "url",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "provider": {+ "name": "provider",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "provider_ref": {+ "name": "provider_ref",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "owner_agent_id": {+ "name": "owner_agent_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": false+ },+ "started_by_run_id": {+ "name": "started_by_run_id",+ "type": "uuid",+ "primaryKey": false,+ "notNull": false+ },+ "last_used_at": {+ "name": "last_used_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ },+ "started_at": {+ "name": "started_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ },+ "stopped_at": {+ "name": "stopped_at",+ "type": "timestamp with time zone",+ "primaryKey": false,+ "notNull": false+ },+ "stop_policy": {+ "name": "stop_policy",+ "type": "jsonb",+ "primaryKey": false,+ "notNull": false+ },+ "health_status": {+ "name": "health_status",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "'unknown'"+ },+ "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": {+ "workspace_runtime_services_company_workspace_status_idx": {+ "name": "workspace_runtime_services_company_workspace_status_idx",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "project_workspace_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "status",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "workspace_runtime_services_company_execution_workspace_status_idx": {+ "name": "workspace_runtime_services_company_execution_workspace_status_idx",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "execution_workspace_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "status",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "workspace_runtime_services_company_project_status_idx": {+ "name": "workspace_runtime_services_company_project_status_idx",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "project_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "status",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "workspace_runtime_services_run_idx": {+ "name": "workspace_runtime_services_run_idx",+ "columns": [+ {+ "expression": "started_by_run_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "workspace_runtime_services_company_updated_idx": {+ "name": "workspace_runtime_services_company_updated_idx",+ "columns": [+ {+ "expression": "company_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "updated_at",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {+ "workspace_runtime_services_company_id_companies_id_fk": {+ "name": "workspace_runtime_services_company_id_companies_id_fk",+ "tableFrom": "workspace_runtime_services",+ "tableTo": "companies",+ "columnsFrom": [+ "company_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ },+ "workspace_runtime_services_project_id_projects_id_fk": {+ "name": "workspace_runtime_services_project_id_projects_id_fk",+ "tableFrom": "workspace_runtime_services",+ "tableTo": "projects",+ "columnsFrom": [+ "project_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "set null",+ "onUpdate": "no action"+ },+ "workspace_runtime_services_project_workspace_id_project_workspaces_id_fk": {+ "name": "workspace_runtime_services_project_workspace_id_project_workspaces_id_fk",+ "tableFrom": "workspace_runtime_services",+ "tableTo": "project_workspaces",+ "columnsFrom": [+ "project_workspace_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "set null",+ "onUpdate": "no action"+ },+ "workspace_runtime_services_execution_workspace_id_execution_workspaces_id_fk": {+ "name": "workspace_runtime_services_execution_workspace_id_execution_workspaces_id_fk",+ "tableFrom": "workspace_runtime_services",+ "tableTo": "execution_workspaces",+ "columnsFrom": [+ "execution_workspace_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "set null",+ "onUpdate": "no action"+ },+ "workspace_runtime_services_issue_id_issues_id_fk": {+ "name": "workspace_runtime_services_issue_id_issues_id_fk",+ "tableFrom": "workspace_runtime_services",+ "tableTo": "issues",+ "columnsFrom": [+ "issue_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "set null",+ "onUpdate": "no action"+ },+ "workspace_runtime_services_owner_agent_id_agents_id_fk": {+ "name": "workspace_runtime_services_owner_agent_id_agents_id_fk",+ "tableFrom": "workspace_runtime_services",+ "tableTo": "agents",+ "columnsFrom": [+ "owner_agent_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "set null",+ "onUpdate": "no action"+ },+ "workspace_runtime_services_started_by_run_id_heartbeat_runs_id_fk": {+ "name": "workspace_runtime_services_started_by_run_id_heartbeat_runs_id_fk",+ "tableFrom": "workspace_runtime_services",+ "tableTo": "heartbeat_runs",+ "columnsFrom": [+ "started_by_run_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "set null",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ }+ },+ "enums": {},+ "schemas": {},+ "sequences": {},+ "roles": {},+ "policies": {},+ "views": {},+ "_meta": {+ "columns": {},+ "schemas": {},+ "tables": {}+ }+}\ No newline at end of filediff --git a/packages/db/src/migrations/meta/_journal.json b/packages/db/src/migrations/meta/_journal.jsonindex cca7597bf6..ccc22bf136 100644--- a/packages/db/src/migrations/meta/_journal.json+++ b/packages/db/src/migrations/meta/_journal.json@@ -337,6 +337,13 @@"when": 1775137972687,"tag": "0047_overjoyed_groot","breakpoints": true+ },+ {+ "idx": 48,+ "version": "7",+ "when": 1775145655557,+ "tag": "0048_flashy_marrow",+ "breakpoints": true}]}\ No newline at end of filediff --git a/packages/db/src/schema/routines.ts b/packages/db/src/schema/routines.tsindex a6713f4bff..77bb1b0dbf 100644--- a/packages/db/src/schema/routines.ts+++ b/packages/db/src/schema/routines.ts@@ -15,6 +15,7 @@ import { companySecrets } from "./company_secrets.js";import { issues } from "./issues.js";import { projects } from "./projects.js";import { goals } from "./goals.js";+import type { RoutineVariable } from "@paperclipai/shared";export const routines = pgTable("routines",@@ -31,6 +32,7 @@ export const routines = pgTable(status: text("status").notNull().default("active"),concurrencyPolicy: text("concurrency_policy").notNull().default("coalesce_if_active"),catchUpPolicy: text("catch_up_policy").notNull().default("skip_missed"),+ variables: jsonb("variables").$type<RoutineVariable[]>().notNull().default([]),createdByAgentId: uuid("created_by_agent_id").references(() => agents.id, { onDelete: "set null" }),createdByUserId: text("created_by_user_id"),updatedByAgentId: uuid("updated_by_agent_id").references(() => agents.id, { onDelete: "set null" }),diff --git a/packages/shared/src/constants.ts b/packages/shared/src/constants.tsindex e385aca540..1e82a5ce77 100644--- a/packages/shared/src/constants.ts+++ b/packages/shared/src/constants.ts@@ -166,6 +166,9 @@ export type RoutineTriggerKind = (typeof ROUTINE_TRIGGER_KINDS)[number];export const ROUTINE_TRIGGER_SIGNING_MODES = ["bearer", "hmac_sha256"] as const;export type RoutineTriggerSigningMode = (typeof ROUTINE_TRIGGER_SIGNING_MODES)[number];+export const ROUTINE_VARIABLE_TYPES = ["text", "textarea", "number", "boolean", "select"] as const;+export type RoutineVariableType = (typeof ROUTINE_VARIABLE_TYPES)[number];+export const ROUTINE_RUN_STATUSES = ["received","coalesced",diff --git a/packages/shared/src/index.ts b/packages/shared/src/index.tsindex 325ccbdb20..0f936bc2cb 100644--- a/packages/shared/src/index.ts+++ b/packages/shared/src/index.ts@@ -21,6 +21,7 @@ export {ROUTINE_CATCH_UP_POLICIES,ROUTINE_TRIGGER_KINDS,ROUTINE_TRIGGER_SIGNING_MODES,+ ROUTINE_VARIABLE_TYPES,ROUTINE_RUN_STATUSES,ROUTINE_RUN_SOURCES,PAUSE_REASONS,@@ -88,6 +89,7 @@ export {type RoutineCatchUpPolicy,type RoutineTriggerKind,type RoutineTriggerSigningMode,+ type RoutineVariableType,type RoutineRunStatus,type RoutineRunSource,type PauseReason,@@ -255,6 +257,8 @@ export type {FinanceSummary,FinanceByBiller,FinanceByKind,+ AgentWakeupResponse,+ AgentWakeupSkipped,HeartbeatRun,HeartbeatRunEvent,AgentRuntimeState,@@ -304,6 +308,8 @@ export type {CompanySecret,SecretProviderDescriptor,Routine,+ RoutineVariable,+ RoutineVariableDefaultValue,RoutineTrigger,RoutineRun,RoutineTriggerSecretMaterial,@@ -473,6 +479,7 @@ export {updateRoutineSchema,createRoutineTriggerSchema,updateRoutineTriggerSchema,+ routineVariableSchema,runRoutineSchema,rotateRoutineTriggerSecretSchema,type CreateSecret,@@ -597,6 +604,14 @@ export {type ParsedProjectMention,} from "./project-mentions.js";+export {+ extractRoutineVariableNames,+ interpolateRoutineTemplate,+ isValidRoutineVariableName,+ stringifyRoutineVariableValue,+ syncRoutineVariablesWithTemplate,+} from "./routine-variables.js";+export {paperclipConfigSchema,configMetaSchema,diff --git a/packages/shared/src/routine-variables.test.ts b/packages/shared/src/routine-variables.test.tsnew file mode 100644index 0000000000..a3832d87c9--- /dev/null+++ b/packages/shared/src/routine-variables.test.ts@@ -0,0 +1,34 @@+import { describe, expect, it } from "vitest";+import {+ extractRoutineVariableNames,+ interpolateRoutineTemplate,+ syncRoutineVariablesWithTemplate,+} from "./routine-variables.js";++describe("routine variable helpers", () => {+ it("extracts placeholder names in first-appearance order", () => {+ expect(+ extractRoutineVariableNames("Review {{repo}} and {{priority}} for {{repo}}"),+ ).toEqual(["repo", "priority"]);+ });++ it("preserves existing metadata when syncing variables from a template", () => {+ expect(+ syncRoutineVariablesWithTemplate("Review {{repo}} and {{priority}}", [+ { name: "repo", label: "Repository", type: "text", defaultValue: "paperclip", required: true, options: [] },+ ]),+ ).toEqual([+ { name: "repo", label: "Repository", type: "text", defaultValue: "paperclip", required: true, options: [] },+ { name: "priority", label: null, type: "text", defaultValue: null, required: true, options: [] },+ ]);+ });++ it("interpolates provided variable values into the routine template", () => {+ expect(+ interpolateRoutineTemplate("Review {{repo}} for {{priority}}", {+ repo: "paperclip",+ priority: "high",+ }),+ ).toBe("Review paperclip for high");+ });+});diff --git a/packages/shared/src/routine-variables.ts b/packages/shared/src/routine-variables.tsnew file mode 100644index 0000000000..73df368d0b--- /dev/null+++ b/packages/shared/src/routine-variables.ts@@ -0,0 +1,62 @@+import type { RoutineVariable } from "./types/routine.js";++const ROUTINE_VARIABLE_MATCHER = /\{\{\s*([A-Za-z][A-Za-z0-9_]*)\s*\}\}/g;++export function isValidRoutineVariableName(name: string): boolean {+ return /^[A-Za-z][A-Za-z0-9_]*$/.test(name);+}++export function extractRoutineVariableNames(template: string | null | undefined): string[] {+ if (!template) return [];+ const found = new Set<string>();+ for (const match of template.matchAll(ROUTINE_VARIABLE_MATCHER)) {+ const name = match[1];+ if (name && !found.has(name)) {+ found.add(name);+ }+ }+ return [...found];+}++function defaultRoutineVariable(name: string): RoutineVariable {+ return {+ name,+ label: null,+ type: "text",+ defaultValue: null,+ required: true,+ options: [],+ };+}++export function syncRoutineVariablesWithTemplate(+ template: string | null | undefined,+ existing: RoutineVariable[] | null | undefined,+): RoutineVariable[] {+ const names = extractRoutineVariableNames(template);+ const existingByName = new Map((existing ?? []).map((variable) => [variable.name, variable]));+ return names.map((name) => existingByName.get(name) ?? defaultRoutineVariable(name));+}++export function stringifyRoutineVariableValue(value: unknown): string {+ if (typeof value === "string") return value;+ if (typeof value === "number" || typeof value === "boolean") return String(value);+ if (value == null) return "";+ try {+ return JSON.stringify(value);+ } catch {+ return String(value);+ }+}++export function interpolateRoutineTemplate(+ template: string | null | undefined,+ values: Record<string, unknown> | null | undefined,+): string | null {+ if (template == null) return null;+ if (!values || Object.keys(values).length === 0) return template;+ return template.replace(ROUTINE_VARIABLE_MATCHER, (match, rawName: string) => {+ if (!(rawName in values)) return match;+ return stringifyRoutineVariableValue(values[rawName]);+ });+}diff --git a/packages/shared/src/types/company-portability.ts b/packages/shared/src/types/company-portability.tsindex 2649e03ae8..d3f3c5c3ec 100644--- a/packages/shared/src/types/company-portability.ts+++ b/packages/shared/src/types/company-portability.ts@@ -57,6 +57,8 @@ export interface CompanyPortabilityProjectManifestEntry {metadata: Record<string, unknown> | null;}+import type { RoutineVariable } from "./routine.js";+export interface CompanyPortabilityProjectWorkspaceManifestEntry {key: string;name: string;@@ -84,6 +86,7 @@ export interface CompanyPortabilityIssueRoutineTriggerManifestEntry {export interface CompanyPortabilityIssueRoutineManifestEntry {concurrencyPolicy: string | null;catchUpPolicy: string | null;+ variables?: RoutineVariable[] | null;triggers: CompanyPortabilityIssueRoutineTriggerManifestEntry[];}diff --git a/packages/shared/src/types/heartbeat.ts b/packages/shared/src/types/heartbeat.tsindex c399b6da8e..5e8dd21709 100644--- a/packages/shared/src/types/heartbeat.ts+++ b/packages/shared/src/types/heartbeat.ts@@ -42,6 +42,18 @@ export interface HeartbeatRun {updatedAt: Date;}+export interface AgentWakeupSkipped {+ status: "skipped";+ reason: string;+ message: string | null;+ issueId: string | null;+ executionRunId: string | null;+ executionAgentId: string | null;+ executionAgentName: string | null;+}++export type AgentWakeupResponse = HeartbeatRun | AgentWakeupSkipped;+export interface HeartbeatRunEvent {id: number;companyId: string;diff --git a/packages/shared/src/types/index.ts b/packages/shared/src/types/index.tsindex d76b37a8f7..7c5d18cb21 100644--- a/packages/shared/src/types/index.ts+++ b/packages/shared/src/types/index.ts@@ -130,6 +130,8 @@ export type {} from "./secrets.js";export type {Routine,+ RoutineVariable,+ RoutineVariableDefaultValue,RoutineTrigger,RoutineRun,RoutineTriggerSecretMaterial,@@ -141,6 +143,8 @@ export type {export type { CostEvent, CostSummary, CostByAgent, CostByProviderModel, CostByBiller, CostByAgentModel, CostWindowSpendRow, CostByProject } from "./cost.js";export type { FinanceEvent, FinanceSummary, FinanceByBiller, FinanceByKind } from "./finance.js";export type {+ AgentWakeupResponse,+ AgentWakeupSkipped,HeartbeatRun,HeartbeatRunEvent,AgentRuntimeState,diff --git a/packages/shared/src/types/routine.ts b/packages/shared/src/types/routine.tsindex 3244f243df..774961f267 100644--- a/packages/shared/src/types/routine.ts+++ b/packages/shared/src/types/routine.ts@@ -1,4 +1,4 @@-import type { IssueOriginKind } from "../constants.js";+import type { IssueOriginKind, RoutineVariableType } from "../constants.js";export interface RoutineProjectSummary {id: string;@@ -25,6 +25,17 @@ export interface RoutineIssueSummary {updatedAt: Date;}+export type RoutineVariableDefaultValue = string | number | boolean | null;++export interface RoutineVariable {+ name: string;+ label: string | null;+ type: RoutineVariableType;+ defaultValue: RoutineVariableDefaultValue;+ required: boolean;+ options: string[];+}+export interface Routine {id: string;companyId: string;@@ -38,6 +49,7 @@ export interface Routine {status: string;concurrencyPolicy: string;catchUpPolicy: string;+ variables: RoutineVariable[];createdByAgentId: string | null;createdByUserId: string | null;updatedByAgentId: string | null;diff --git a/packages/shared/src/validators/company-portability.ts b/packages/shared/src/validators/company-portability.tsindex 8a3a4545fc..97004b350d 100644--- a/packages/shared/src/validators/company-portability.ts+++ b/packages/shared/src/validators/company-portability.ts@@ -1,4 +1,5 @@import { z } from "zod";+import { routineVariableSchema } from "./routine.js";export const portabilityIncludeSchema = z.object({@@ -123,6 +124,7 @@ export const portabilityIssueRoutineTriggerManifestEntrySchema = z.object({export const portabilityIssueRoutineManifestEntrySchema = z.object({concurrencyPolicy: z.string().nullable(),catchUpPolicy: z.string().nullable(),+ variables: z.array(routineVariableSchema).nullable().optional(),triggers: z.array(portabilityIssueRoutineTriggerManifestEntrySchema).default([]),});diff --git a/packages/shared/src/validators/index.ts b/packages/shared/src/validators/index.tsindex 696567b7f3..20c26ddb9d 100644--- a/packages/shared/src/validators/index.ts+++ b/packages/shared/src/validators/index.ts@@ -214,6 +214,7 @@ export {updateRoutineSchema,createRoutineTriggerSchema,updateRoutineTriggerSchema,+ routineVariableSchema,runRoutineSchema,rotateRoutineTriggerSecretSchema,type CreateRoutine,diff --git a/packages/shared/src/validators/routine.ts b/packages/shared/src/validators/routine.tsindex 966756ab6b..0bce7722ae 100644--- a/packages/shared/src/validators/routine.ts+++ b/packages/shared/src/validators/routine.ts@@ -5,7 +5,44 @@ import {ROUTINE_CONCURRENCY_POLICIES,ROUTINE_STATUSES,ROUTINE_TRIGGER_SIGNING_MODES,+ ROUTINE_VARIABLE_TYPES,} from "../constants.js";+import { issueExecutionWorkspaceSettingsSchema } from "./issue.js";++const routineVariableValueSchema = z.union([z.string(), z.number().finite(), z.boolean()]);++export const routineVariableSchema = z.object({+ name: z.string().trim().regex(/^[A-Za-z][A-Za-z0-9_]*$/),+ label: z.string().trim().max(120).optional().nullable(),+ type: z.enum(ROUTINE_VARIABLE_TYPES).optional().default("text"),+ defaultValue: routineVariableValueSchema.optional().nullable(),+ required: z.boolean().optional().default(true),+ options: z.array(z.string().trim().min(1).max(120)).max(50).optional().default([]),+}).superRefine((value, ctx) => {+ if (value.type === "select" && value.options.length === 0) {+ ctx.addIssue({+ code: z.ZodIssueCode.custom,+ path: ["options"],+ message: "Select variables require at least one option",+ });+ }+ if (value.type !== "select" && value.options.length > 0) {+ ctx.addIssue({+ code: z.ZodIssueCode.custom,+ path: ["options"],+ message: "Only select variables can define options",+ });+ }+ if (value.type === "select" && value.defaultValue != null) {+ if (typeof value.defaultValue !== "string" || !value.options.includes(value.defaultValue)) {+ ctx.addIssue({+ code: z.ZodIssueCode.custom,+ path: ["defaultValue"],+ message: "Select variable defaults must match one of the allowed options",+ });+ }+ }+});export const createRoutineSchema = z.object({projectId: z.string().uuid(),@@ -18,6 +55,7 @@ export const createRoutineSchema = z.object({status: z.enum(ROUTINE_STATUSES).optional().default("active"),concurrencyPolicy: z.enum(ROUTINE_CONCURRENCY_POLICIES).optional().default("coalesce_if_active"),catchUpPolicy: z.enum(ROUTINE_CATCH_UP_POLICIES).optional().default("skip_missed"),+ variables: z.array(routineVariableSchema).optional().default([]),});export type CreateRoutine = z.infer<typeof createRoutineSchema>;@@ -62,8 +100,19 @@ export type UpdateRoutineTrigger = z.infer<typeof updateRoutineTriggerSchema>;export const runRoutineSchema = z.object({triggerId: z.string().uuid().optional().nullable(),payload: z.record(z.unknown()).optional().nullable(),+ variables: z.record(routineVariableValueSchema).optional().nullable(),idempotencyKey: z.string().trim().max(255).optional().nullable(),source: z.enum(["manual", "api"]).optional().default("manual"),+ executionWorkspaceId: z.string().uuid().optional().nullable(),+ executionWorkspacePreference: z.enum([+ "inherit",+ "shared_workspace",+ "isolated_workspace",+ "operator_branch",+ "reuse_existing",+ "agent_default",+ ]).optional().nullable(),+ executionWorkspaceSettings: issueExecutionWorkspaceSettingsSchema.optional().nullable(),});export type RunRoutine = z.infer<typeof runRoutineSchema>;diff --git a/scripts/provision-worktree.sh b/scripts/provision-worktree.shindex 19b0831ef5..09cfc36b4e 100644--- a/scripts/provision-worktree.sh+++ b/scripts/provision-worktree.sh@@ -31,20 +31,41 @@ source_env_path="$(dirname "$source_config_path")/.env"mkdir -p "$paperclip_dir"-run_isolated_worktree_init() {+run_paperclipai_command() {+ local command_args=("$@")if command -v pnpm >/dev/null 2>&1 && pnpm paperclipai --help >/dev/null 2>&1; then- pnpm paperclipai worktree init --force --seed-mode minimal --name "$worktree_name" --from-config "$source_config_path"+ pnpm paperclipai "${command_args[@]}"+ return 0+ fi++ local base_cli_tsx_path="$base_cwd/cli/node_modules/tsx/dist/cli.mjs"+ local base_cli_entry_path="$base_cwd/cli/src/index.ts"+ if command -v node >/dev/null 2>&1 && [[ -f "$base_cli_tsx_path" ]] && [[ -f "$base_cli_entry_path" ]]; then+ node "$base_cli_tsx_path" "$base_cli_entry_path" "${command_args[@]}"return 0fiif command -v paperclipai >/dev/null 2>&1; then- paperclipai worktree init --force --seed-mode minimal --name "$worktree_name" --from-config "$source_config_path"+ paperclipai "${command_args[@]}"return 0fireturn 1}+run_isolated_worktree_init() {+ run_paperclipai_command \+ worktree \+ init \+ --force \+ --seed-mode \+ minimal \+ --name \+ "$worktree_name" \+ --from-config \+ "$source_config_path"+}+write_fallback_worktree_config() {WORKTREE_NAME="$worktree_name" \BASE_CWD="$base_cwd" \@@ -300,6 +321,20 @@ if ! run_isolated_worktree_init; thenwrite_fallback_worktree_configfi+disable_seeded_routines() {+ local company_id="${PAPERCLIP_COMPANY_ID:-}"+ if [[ -z "$company_id" ]]; then+ echo "PAPERCLIP_COMPANY_ID not set; skipping routine disable post-step." >&2+ return 0+ fi++ if ! run_paperclipai_command routines disable-all --config "$worktree_config_path" --company-id "$company_id"; then+ echo "paperclipai CLI not available in this workspace; skipping routine disable post-step." >&2+ fi+}++disable_seeded_routines+while IFS= read -r relative_path; do[[ -n "$relative_path" ]] || continuesource_path="$base_cwd/$relative_path"diff --git a/server/src/__tests__/issues-service.test.ts b/server/src/__tests__/issues-service.test.tsindex f6bcddd582..08802fb05e 100644--- a/server/src/__tests__/issues-service.test.ts+++ b/server/src/__tests__/issues-service.test.ts@@ -1,4 +1,5 @@import { randomUUID } from "node:crypto";+import { eq } from "drizzle-orm";import { afterAll, afterEach, beforeAll, describe, expect, it } from "vitest";import {activityLog,@@ -428,6 +429,160 @@ describeEmbeddedPostgres("issueService.list participantAgentId", () => {resurfacedIssueId,]));});++ it("resurfaces archived issue when status/updatedAt changes after archiving", async () => {+ const companyId = randomUUID();+ const userId = "user-1";+ const otherUserId = "user-2";++ await db.insert(companies).values({+ id: companyId,+ name: "Paperclip",+ issuePrefix: `T${companyId.replace(/-/g, "").slice(0, 6).toUpperCase()}`,+ requireBoardApprovalForNewAgents: false,+ });++ const issueId = randomUUID();++ await db.insert(issues).values({+ id: issueId,+ companyId,+ title: "Issue with old comment then status change",+ status: "todo",+ priority: "medium",+ createdByUserId: userId,+ createdAt: new Date("2026-03-26T10:00:00.000Z"),+ updatedAt: new Date("2026-03-26T10:00:00.000Z"),+ });++ // Old external comment before archiving+ await db.insert(issueComments).values({+ companyId,+ issueId,+ authorUserId: otherUserId,+ body: "Old comment before archive",+ createdAt: new Date("2026-03-26T11:00:00.000Z"),+ updatedAt: new Date("2026-03-26T11:00:00.000Z"),+ });++ // Archive after seeing the comment+ await svc.archiveInbox(+ companyId,+ issueId,+ userId,+ new Date("2026-03-26T12:00:00.000Z"),+ );++ // Verify it's archived+ const afterArchive = await svc.list(companyId, {+ touchedByUserId: userId,+ inboxArchivedByUserId: userId,+ });+ expect(afterArchive.map((i) => i.id)).not.toContain(issueId);++ // Status/work update changes updatedAt (no new comment)+ await db+ .update(issues)+ .set({+ status: "in_progress",+ updatedAt: new Date("2026-03-26T13:00:00.000Z"),+ })+ .where(eq(issues.id, issueId));++ // Should resurface because updatedAt > archivedAt+ const afterUpdate = await svc.list(companyId, {+ touchedByUserId: userId,+ inboxArchivedByUserId: userId,+ });+ expect(afterUpdate.map((i) => i.id)).toContain(issueId);+ });++ it("sorts and exposes last activity from comments and non-local issue activity logs", async () => {+ const companyId = randomUUID();+ const olderIssueId = randomUUID();+ const commentIssueId = randomUUID();+ const activityIssueId = randomUUID();++ await db.insert(companies).values({+ id: companyId,+ name: "Paperclip",+ issuePrefix: `T${companyId.replace(/-/g, "").slice(0, 6).toUpperCase()}`,+ requireBoardApprovalForNewAgents: false,+ });++ await db.insert(issues).values([+ {+ id: olderIssueId,+ companyId,+ title: "Older issue",+ status: "todo",+ priority: "medium",+ updatedAt: new Date("2026-03-26T10:00:00.000Z"),+ },+ {+ id: commentIssueId,+ companyId,+ title: "Comment activity issue",+ status: "todo",+ priority: "medium",+ updatedAt: new Date("2026-03-26T10:00:00.000Z"),+ },+ {+ id: activityIssueId,+ companyId,+ title: "Logged activity issue",+ status: "todo",+ priority: "medium",+ updatedAt: new Date("2026-03-26T10:00:00.000Z"),+ },+ ]);++ await db.insert(issueComments).values({+ companyId,+ issueId: commentIssueId,+ body: "New comment without touching issue.updatedAt",+ createdAt: new Date("2026-03-26T11:00:00.000Z"),+ updatedAt: new Date("2026-03-26T11:00:00.000Z"),+ });++ await db.insert(activityLog).values([+ {+ companyId,+ actorType: "system",+ actorId: "system",+ action: "issue.document_updated",+ entityType: "issue",+ entityId: activityIssueId,+ createdAt: new Date("2026-03-26T12:00:00.000Z"),+ },+ {+ companyId,+ actorType: "user",+ actorId: "user-1",+ action: "issue.read_marked",+ entityType: "issue",+ entityId: olderIssueId,+ createdAt: new Date("2026-03-26T13:00:00.000Z"),+ },+ ]);++ const result = await svc.list(companyId, {});++ expect(result.map((issue) => issue.id)).toEqual([+ activityIssueId,+ commentIssueId,+ olderIssueId,+ ]);+ expect(result.find((issue) => issue.id === activityIssueId)?.lastActivityAt?.toISOString()).toBe(+ "2026-03-26T12:00:00.000Z",+ );+ expect(result.find((issue) => issue.id === commentIssueId)?.lastActivityAt?.toISOString()).toBe(+ "2026-03-26T11:00:00.000Z",+ );+ expect(result.find((issue) => issue.id === olderIssueId)?.lastActivityAt?.toISOString()).toBe(+ "2026-03-26T10:00:00.000Z",+ );+ });});describeEmbeddedPostgres("issueService.create workspace inheritance", () => {diff --git a/server/src/__tests__/routines-e2e.test.ts b/server/src/__tests__/routines-e2e.test.tsindex ab5fd778ea..d4d61eef5e 100644--- a/server/src/__tests__/routines-e2e.test.ts+++ b/server/src/__tests__/routines-e2e.test.ts@@ -10,11 +10,13 @@ import {companies,companyMemberships,createDb,+ executionWorkspaces,heartbeatRunEvents,heartbeatRuns,instanceSettings,issues,principalPermissionGrants,+ projectWorkspaces,projects,routineRuns,routines,@@ -102,6 +104,8 @@ describeEmbeddedPostgres("routine routes end-to-end", () => {await db.delete(heartbeatRuns);await db.delete(agentWakeupRequests);await db.delete(issues);+ await db.delete(executionWorkspaces);+ await db.delete(projectWorkspaces);await db.delete(principalPermissionGrants);await db.delete(companyMemberships);await db.delete(routines);@@ -272,4 +276,136 @@ describeEmbeddedPostgres("routine routes end-to-end", () => {]),);});++ it("runs routines with variable inputs and interpolates the execution issue description", async () => {+ const { companyId, agentId, projectId, userId } = await seedFixture();+ const app = await createApp({+ type: "board",+ userId,+ source: "session",+ isInstanceAdmin: false,+ companyIds: [companyId],+ });++ const createRes = await request(app)+ .post(`/api/companies/${companyId}/routines`)+ .send({+ projectId,+ title: "Repository triage",+ description: "Review {{repo}} for {{priority}} bugs",+ assigneeAgentId: agentId,+ variables: [+ { name: "repo", type: "text", required: true },+ { name: "priority", type: "select", required: true, defaultValue: "high", options: ["high", "low"] },+ ],+ });++ expect(createRes.status).toBe(201);++ const runRes = await request(app)+ .post(`/api/routines/${createRes.body.id}/run`)+ .send({+ source: "manual",+ variables: { repo: "paperclip" },+ });++ expect(runRes.status).toBe(202);+ expect(runRes.body.triggerPayload).toEqual({+ variables: {+ repo: "paperclip",+ priority: "high",+ },+ });++ const [issue] = await db+ .select({ description: issues.description })+ .from(issues)+ .where(eq(issues.id, runRes.body.linkedIssueId));++ expect(issue?.description).toBe("Review paperclip for high bugs");+ });++ it("persists execution workspace selections from manual routine runs", async () => {+ const { companyId, agentId, projectId, userId } = await seedFixture();+ const projectWorkspaceId = randomUUID();+ const executionWorkspaceId = randomUUID();+ const app = await createApp({+ type: "board",+ userId,+ source: "session",+ isInstanceAdmin: false,+ companyIds: [companyId],+ });++ await db.insert(projectWorkspaces).values({+ id: projectWorkspaceId,+ companyId,+ projectId,+ name: "Primary workspace",+ isPrimary: true,+ sharedWorkspaceKey: "routine-primary",+ });+ await db.insert(executionWorkspaces).values({+ id: executionWorkspaceId,+ companyId,+ projectId,+ projectWorkspaceId,+ mode: "isolated_workspace",+ strategyType: "git_worktree",+ name: "Routine worktree",+ status: "active",+ providerType: "git_worktree",+ });+ await db+ .update(projects)+ .set({+ executionWorkspacePolicy: {+ enabled: true,+ defaultMode: "shared_workspace",+ defaultProjectWorkspaceId: projectWorkspaceId,+ },+ })+ .where(eq(projects.id, projectId));+ await db.insert(instanceSettings).values({+ experimental: { enableIsolatedWorkspaces: true },+ });++ const createRes = await request(app)+ .post(`/api/companies/${companyId}/routines`)+ .send({+ projectId,+ title: "Workspace-aware routine",+ assigneeAgentId: agentId,+ });++ expect(createRes.status).toBe(201);++ const runRes = await request(app)+ .post(`/api/routines/${createRes.body.id}/run`)+ .send({+ source: "manual",+ executionWorkspaceId,+ executionWorkspacePreference: "reuse_existing",+ executionWorkspaceSettings: { mode: "isolated_workspace" },+ });++ expect(runRes.status).toBe(202);++ const [issue] = await db+ .select({+ projectWorkspaceId: issues.projectWorkspaceId,+ executionWorkspaceId: issues.executionWorkspaceId,+ executionWorkspacePreference: issues.executionWorkspacePreference,+ executionWorkspaceSettings: issues.executionWorkspaceSettings,+ })+ .from(issues)+ .where(eq(issues.id, runRes.body.linkedIssueId));++ expect(issue).toEqual({+ projectWorkspaceId,+ executionWorkspaceId,+ executionWorkspacePreference: "reuse_existing",+ executionWorkspaceSettings: { mode: "isolated_workspace" },+ });+ });});diff --git a/server/src/__tests__/routines-service.test.ts b/server/src/__tests__/routines-service.test.tsindex d6aad0f2fb..9f1f7ae906 100644--- a/server/src/__tests__/routines-service.test.ts+++ b/server/src/__tests__/routines-service.test.ts@@ -8,8 +8,11 @@ import {companySecrets,companySecretVersions,createDb,+ executionWorkspaces,heartbeatRuns,+ instanceSettings,issues,+ projectWorkspaces,projects,routineRuns,routines,@@ -20,6 +23,7 @@ import {startEmbeddedPostgresTestDatabase,} from "./helpers/embedded-postgres.js";import { issueService } from "../services/issues.ts";+import { instanceSettingsService } from "../services/instance-settings.ts";import { routineService } from "../services/routines.ts";const embeddedPostgresSupport = await getEmbeddedPostgresTestSupport();@@ -49,9 +53,12 @@ describeEmbeddedPostgres("routine service live-execution coalescing", () => {await db.delete(companySecrets);await db.delete(heartbeatRuns);await db.delete(issues);+ await db.delete(executionWorkspaces);+ await db.delete(projectWorkspaces);await db.delete(projects);await db.delete(agents);await db.delete(companies);+ await db.delete(instanceSettings);});afterAll(async () => {@@ -317,6 +324,148 @@ describeEmbeddedPostgres("routine service live-execution coalescing", () => {expect(routineIssues[0]?.id).toBe(previousIssue.id);});+ it("interpolates routine variables into the execution issue and stores resolved values", async () => {+ const { companyId, agentId, projectId, svc } = await seedFixture();+ const variableRoutine = await svc.create(+ companyId,+ {+ projectId,+ goalId: null,+ parentIssueId: null,+ title: "repo triage",+ description: "Review {{repo}} for {{priority}} bugs",+ assigneeAgentId: agentId,+ priority: "medium",+ status: "active",+ concurrencyPolicy: "coalesce_if_active",+ catchUpPolicy: "skip_missed",+ variables: [+ { name: "repo", label: null, type: "text", defaultValue: null, required: true, options: [] },+ { name: "priority", label: null, type: "select", defaultValue: "high", required: true, options: ["high", "low"] },+ ],+ },+ {},+ );++ const run = await svc.runRoutine(variableRoutine.id, {+ source: "manual",+ variables: { repo: "paperclip" },+ });++ const storedIssue = await db+ .select({ description: issues.description })+ .from(issues)+ .where(eq(issues.id, run.linkedIssueId!))+ .then((rows) => rows[0] ?? null);+ const storedRun = await db+ .select({ triggerPayload: routineRuns.triggerPayload })+ .from(routineRuns)+ .where(eq(routineRuns.id, run.id))+ .then((rows) => rows[0] ?? null);++ expect(storedIssue?.description).toBe("Review paperclip for high bugs");+ expect(storedRun?.triggerPayload).toEqual({+ variables: {+ repo: "paperclip",+ priority: "high",+ },+ });+ });++ it("attaches the selected execution workspace to manually triggered routine issues", async () => {+ const { companyId, projectId, routine, svc } = await seedFixture();+ const projectWorkspaceId = randomUUID();+ const executionWorkspaceId = randomUUID();++ await instanceSettingsService(db).updateExperimental({ enableIsolatedWorkspaces: true });+ await db+ .update(projects)+ .set({+ executionWorkspacePolicy: {+ enabled: true,+ defaultMode: "shared_workspace",+ defaultProjectWorkspaceId: projectWorkspaceId,+ },+ })+ .where(eq(projects.id, projectId));+ await db.insert(projectWorkspaces).values({+ id: projectWorkspaceId,+ companyId,+ projectId,+ name: "Primary workspace",+ isPrimary: true,+ sharedWorkspaceKey: "routine-primary",+ });+ await db.insert(executionWorkspaces).values({+ id: executionWorkspaceId,+ companyId,+ projectId,+ projectWorkspaceId,+ mode: "isolated_workspace",+ strategyType: "git_worktree",+ name: "Routine worktree",+ status: "active",+ providerType: "git_worktree",+ });++ const run = await svc.runRoutine(routine.id, {+ source: "manual",+ executionWorkspaceId,+ executionWorkspacePreference: "reuse_existing",+ executionWorkspaceSettings: { mode: "isolated_workspace" },+ });++ const storedIssue = await db+ .select({+ projectWorkspaceId: issues.projectWorkspaceId,+ executionWorkspaceId: issues.executionWorkspaceId,+ executionWorkspacePreference: issues.executionWorkspacePreference,+ executionWorkspaceSettings: issues.executionWorkspaceSettings,+ })+ .from(issues)+ .where(eq(issues.id, run.linkedIssueId!))+ .then((rows) => rows[0] ?? null);++ expect(storedIssue).toEqual({+ projectWorkspaceId,+ executionWorkspaceId,+ executionWorkspacePreference: "reuse_existing",+ executionWorkspaceSettings: { mode: "isolated_workspace" },+ });+ });++ it("blocks schedule triggers when required variables do not have defaults", async () => {+ const { companyId, agentId, projectId, svc } = await seedFixture();+ const variableRoutine = await svc.create(+ companyId,+ {+ projectId,+ goalId: null,+ parentIssueId: null,+ title: "repo triage",+ description: "Review {{repo}}",+ assigneeAgentId: agentId,+ priority: "medium",+ status: "active",+ concurrencyPolicy: "coalesce_if_active",+ catchUpPolicy: "skip_missed",+ variables: [+ { name: "repo", label: null, type: "text", defaultValue: null, required: true, options: [] },+ ],+ },+ {},+ );++ await expect(+ svc.createTrigger(variableRoutine.id, {+ kind: "schedule",+ label: "daily",+ cronExpression: "0 10 * * *",+ timezone: "UTC",+ }, {}),+ ).rejects.toThrow(/require defaults for required variables/i);+ });+it("serializes concurrent dispatches until the first execution issue is linked to a queued run", async () => {const { routine, svc } = await seedFixture({wakeup: async (wakeupAgentId, wakeupOpts) => {diff --git a/server/src/services/company-portability.ts b/server/src/services/company-portability.tsindex 0818b431f8..c73d9eaa95 100644--- a/server/src/services/company-portability.ts+++ b/server/src/services/company-portability.ts@@ -27,6 +27,7 @@ import type {CompanyPortabilitySidebarOrder,CompanyPortabilitySkillManifestEntry,CompanySkill,+ RoutineVariable,} from "@paperclipai/shared";import {ISSUE_PRIORITIES,@@ -523,7 +524,7 @@ const ADAPTER_DEFAULT_RULES_BY_TYPE: Record<string, Array<{ path: string[]; valuclaude_local: [{ path: ["timeoutSec"], value: 0 },{ path: ["graceSec"], value: 15 },- { path: ["maxTurnsPerRun"], value: 300 },+ { path: ["maxTurnsPerRun"], value: 1000 },],openclaw_gateway: [{ path: ["timeoutSec"], value: 120 },@@ -568,6 +569,29 @@ function normalizeRoutineTriggerExtension(value: unknown): CompanyPortabilityIss};}+function normalizeRoutineVariableExtension(value: unknown): RoutineVariable | null {+ if (!isPlainRecord(value)) return null;+ const name = asString(value.name);+ if (!name) return null;+ const type = asString(value.type) ?? "text";+ if (!["text", "textarea", "number", "boolean", "select"].includes(type)) return null;+ const options = Array.isArray(value.options)+ ? value.options.map((entry) => asString(entry)).filter((entry): entry is string => Boolean(entry))+ : [];+ const defaultValue =+ typeof value.defaultValue === "string" || typeof value.defaultValue === "number" || typeof value.defaultValue === "boolean"+ ? value.defaultValue+ : null;+ return {+ name,+ label: asString(value.label),+ type: type as RoutineVariable["type"],+ defaultValue,+ required: asBoolean(value.required) ?? true,+ options,+ };+}+function normalizeRoutineExtension(value: unknown): CompanyPortabilityIssueRoutineManifestEntry | null {if (!isPlainRecord(value)) return null;const triggers = Array.isArray(value.triggers)@@ -575,9 +599,15 @@ function normalizeRoutineExtension(value: unknown): CompanyPortabilityIssueRouti.map((entry) => normalizeRoutineTriggerExtension(entry)).filter((entry): entry is CompanyPortabilityIssueRoutineTriggerManifestEntry => entry !== null): [];+ const variables = Array.isArray(value.variables)+ ? value.variables+ .map((entry) => normalizeRoutineVariableExtension(entry))+ .filter((entry): entry is RoutineVariable => entry !== null)+ : null;const routine = {concurrencyPolicy: asString(value.concurrencyPolicy),catchUpPolicy: asString(value.catchUpPolicy),+ variables,triggers,};return stripEmptyValues(routine) ? routine : null;@@ -587,6 +617,7 @@ function buildRoutineManifestFromLiveRoutine(routine: RoutineLike): CompanyPortareturn {concurrencyPolicy: routine.concurrencyPolicy,catchUpPolicy: routine.catchUpPolicy,+ variables: routine.variables,triggers: routine.triggers.map((trigger) => ({kind: trigger.kind,label: trigger.label ?? null,@@ -1086,11 +1117,13 @@ function resolvePortableRoutineDefinition(? {concurrencyPolicy: issue.routine.concurrencyPolicy,catchUpPolicy: issue.routine.catchUpPolicy,+ variables: issue.routine.variables ?? null,triggers: [...issue.routine.triggers],}: {concurrencyPolicy: null,catchUpPolicy: null,+ variables: null,triggers: [] as CompanyPortabilityIssueRoutineTriggerManifestEntry[],};@@ -3204,6 +3237,7 @@ export function companyPortabilityService(db: Db, storage?: StorageService) {priority: routine.priority !== "medium" ? routine.priority : undefined,concurrencyPolicy: routine.concurrencyPolicy !== "coalesce_if_active" ? routine.concurrencyPolicy : undefined,catchUpPolicy: routine.catchUpPolicy !== "skip_missed" ? routine.catchUpPolicy : undefined,+ variables: (routine.variables ?? []).length > 0 ? routine.variables : undefined,triggers: routine.triggers.map((trigger) => stripEmptyValues({kind: trigger.kind,label: trigger.label ?? null,@@ -4173,6 +4207,7 @@ export function companyPortabilityService(db: Db, storage?: StorageService) {const routineDefinition = resolvedRoutine.routine ?? {concurrencyPolicy: null,catchUpPolicy: null,+ variables: null,triggers: [],};const createdRoutine = await routines.create(targetCompany.id, {@@ -4196,6 +4231,7 @@ export function companyPortabilityService(db: Db, storage?: StorageService) {routineDefinition.catchUpPolicy && ROUTINE_CATCH_UP_POLICIES.includes(routineDefinition.catchUpPolicy as any)? routineDefinition.catchUpPolicy as typeof ROUTINE_CATCH_UP_POLICIES[number]: "skip_missed",+ variables: routineDefinition.variables ?? [],}, {agentId: null,userId: actorUserId ?? null,diff --git a/server/src/services/issues.ts b/server/src/services/issues.tsindex dc62bdc675..832c4e1761 100644--- a/server/src/services/issues.ts+++ b/server/src/services/issues.ts@@ -99,6 +99,11 @@ type IssueUserCommentStats = {myLastCommentAt: Date | null;lastExternalCommentAt: Date | null;};+type IssueLastActivityStat = {+ issueId: string;+ latestCommentAt: Date | null;+ latestLogAt: Date | null;+};type IssueUserContextInput = {createdByUserId: string | null;assigneeUserId: string | null;@@ -262,8 +267,8 @@ function issueLastActivityAtExpr(companyId: string, userId: string) {const lastExternalCommentAt = lastExternalCommentAtExpr(companyId, userId);const myLastTouchAt = myLastTouchAtExpr(companyId, userId);return sql<Date>`- COALESCE(- ${lastExternalCommentAt},+ GREATEST(+ COALESCE(${lastExternalCommentAt}, to_timestamp(0)),CASEWHEN ${issues.updatedAt} > COALESCE(${myLastTouchAt}, to_timestamp(0))THEN ${issues.updatedAt}@@ -273,6 +278,52 @@ function issueLastActivityAtExpr(companyId: string, userId: string) {`;}+const ISSUE_LOCAL_INBOX_ACTIVITY_ACTIONS = [+ "issue.read_marked",+ "issue.read_unmarked",+ "issue.inbox_archived",+ "issue.inbox_unarchived",+] as const;++function issueLatestCommentAtExpr(companyId: string) {+ return sql<Date | null>`+ (+ SELECT MAX(${issueComments.createdAt})+ FROM ${issueComments}+ WHERE ${issueComments.issueId} = ${issues.id}+ AND ${issueComments.companyId} = ${companyId}+ )+ `;+}++function issueLatestLogAtExpr(companyId: string) {+ return sql<Date | null>`+ (+ SELECT MAX(${activityLog.createdAt})+ FROM ${activityLog}+ WHERE ${activityLog.companyId} = ${companyId}+ AND ${activityLog.entityType} = 'issue'+ AND ${activityLog.entityId} = ${issues.id}::text+ AND ${activityLog.action} NOT IN (${sql.join(+ ISSUE_LOCAL_INBOX_ACTIVITY_ACTIONS.map((action) => sql`${action}`),+ sql`, `,+ )})+ )+ `;+}++function issueCanonicalLastActivityAtExpr(companyId: string) {+ const latestCommentAt = issueLatestCommentAtExpr(companyId);+ const latestLogAt = issueLatestLogAtExpr(companyId);+ return sql<Date>`+ GREATEST(+ ${issues.updatedAt},+ COALESCE(${latestCommentAt}, to_timestamp(0)),+ COALESCE(${latestLogAt}, to_timestamp(0))+ )+ `;+}+function unreadForUserCondition(companyId: string, userId: string) {const touchedCondition = touchedByUserCondition(companyId, userId);const myLastTouchAt = myLastTouchAtExpr(companyId, userId);@@ -383,6 +434,19 @@ export function deriveIssueUserContext(};}+function latestIssueActivityAt(...values: Array<Date | string | null | undefined>): Date | null {+ const normalized = values+ .map((value) => {+ if (!value) return null;+ if (value instanceof Date) return Number.isNaN(value.getTime()) ? null : value;+ const parsed = new Date(value);+ return Number.isNaN(parsed.getTime()) ? null : parsed;+ })+ .filter((value): value is Date => value instanceof Date)+ .sort((a, b) => b.getTime() - a.getTime());+ return normalized[0] ?? null;+}+async function labelMapForIssues(dbOrTx: any, issueIds: string[]): Promise<Map<string, IssueLabelRow[]>> {const map = new Map<string, IssueLabelRow[]>();if (issueIds.length === 0) return map;@@ -749,66 +813,158 @@ export function issueService(db: Db) {ELSE 6END`;+ const canonicalLastActivityAt = issueCanonicalLastActivityAtExpr(companyId);const rows = await db.select().from(issues).where(and(...conditions))- .orderBy(hasSearch ? asc(searchOrder) : asc(priorityOrder), asc(priorityOrder), desc(issues.updatedAt));+ .orderBy(+ hasSearch ? asc(searchOrder) : asc(priorityOrder),+ asc(priorityOrder),+ desc(canonicalLastActivityAt),+ desc(issues.updatedAt),+ );const withLabels = await withIssueLabels(db, rows);const runMap = await activeRunMapForIssues(db, withLabels);const withRuns = withActiveRuns(withLabels, runMap);- if (!contextUserId || withRuns.length === 0) {+ if (withRuns.length === 0) {return withRuns;}const issueIds = withRuns.map((row) => row.id);- const statsRows = await db- .select({- issueId: issueComments.issueId,- myLastCommentAt: sql<Date | null>`- MAX(CASE WHEN ${issueComments.authorUserId} = ${contextUserId} THEN ${issueComments.createdAt} END)- `,- lastExternalCommentAt: sql<Date | null>`- MAX(- CASE- WHEN ${issueComments.authorUserId} IS NULL OR ${issueComments.authorUserId} <> ${contextUserId}- THEN ${issueComments.createdAt}- END+ const [statsRows, readRows, lastActivityRows] = await Promise.all([+ contextUserId+ ? db+ .select({+ issueId: issueComments.issueId,+ myLastCommentAt: sql<Date | null>`+ MAX(CASE WHEN ${issueComments.authorUserId} = ${contextUserId} THEN ${issueComments.createdAt} END)+ `,+ lastExternalCommentAt: sql<Date | null>`+ MAX(+ CASE+ WHEN ${issueComments.authorUserId} IS NULL OR ${issueComments.authorUserId} <> ${contextUserId}+ THEN ${issueComments.createdAt}+ END+ )+ `,+ })+ .from(issueComments)+ .where(+ and(+ eq(issueComments.companyId, companyId),+ inArray(issueComments.issueId, issueIds),+ ),)- `,- })- .from(issueComments)- .where(- and(- eq(issueComments.companyId, companyId),- inArray(issueComments.issueId, issueIds),- ),- )- .groupBy(issueComments.issueId);- const readRows = await db- .select({- issueId: issueReadStates.issueId,- myLastReadAt: issueReadStates.lastReadAt,- })- .from(issueReadStates)- .where(- and(- eq(issueReadStates.companyId, companyId),- eq(issueReadStates.userId, contextUserId),- inArray(issueReadStates.issueId, issueIds),- ),- );+ .groupBy(issueComments.issueId)+ : Promise.resolve([]),+ contextUserId+ ? db+ .select({+ issueId: issueReadStates.issueId,+ myLastReadAt: issueReadStates.lastReadAt,+ })+ .from(issueReadStates)+ .where(+ and(+ eq(issueReadStates.companyId, companyId),+ eq(issueReadStates.userId, contextUserId),+ inArray(issueReadStates.issueId, issueIds),+ ),+ )+ : Promise.resolve([]),+ Promise.all([+ db+ .select({+ issueId: issueComments.issueId,+ latestCommentAt: sql<Date | null>`MAX(${issueComments.createdAt})`,+ })+ .from(issueComments)+ .where(+ and(+ eq(issueComments.companyId, companyId),+ inArray(issueComments.issueId, issueIds),+ ),+ )+ .groupBy(issueComments.issueId),+ db+ .select({+ issueId: activityLog.entityId,+ latestLogAt: sql<Date | null>`MAX(${activityLog.createdAt})`,+ })+ .from(activityLog)+ .where(+ and(+ eq(activityLog.companyId, companyId),+ eq(activityLog.entityType, "issue"),+ inArray(activityLog.entityId, issueIds),+ sql`${activityLog.action} NOT IN (${sql.join(+ ISSUE_LOCAL_INBOX_ACTIVITY_ACTIONS.map((action) => sql`${action}`),+ sql`, `,+ )})`,+ ),+ )+ .groupBy(activityLog.entityId),+ ]).then(([commentRows, logRows]) => {+ const byIssueId = new Map<string, IssueLastActivityStat>();+ for (const row of commentRows) {+ byIssueId.set(row.issueId, {+ issueId: row.issueId,+ latestCommentAt: row.latestCommentAt,+ latestLogAt: null,+ });+ }+ for (const row of logRows) {+ const existing = byIssueId.get(row.issueId);+ if (existing) existing.latestLogAt = row.latestLogAt;+ else {+ byIssueId.set(row.issueId, {+ issueId: row.issueId,+ latestCommentAt: null,+ latestLogAt: row.latestLogAt,+ });+ }+ }+ return [...byIssueId.values()];+ }),+ ]);const statsByIssueId = new Map(statsRows.map((row) => [row.issueId, row]));+ const lastActivityByIssueId = new Map(lastActivityRows.map((row) => [row.issueId, row]));++ if (!contextUserId) {+ return withRuns.map((row) => {+ const activity = lastActivityByIssueId.get(row.id);+ const lastActivityAt = latestIssueActivityAt(+ row.updatedAt,+ activity?.latestCommentAt ?? null,+ activity?.latestLogAt ?? null,+ ) ?? row.updatedAt;+ return {+ ...row,+ lastActivityAt,+ };+ });+ }+const readByIssueId = new Map(readRows.map((row) => [row.issueId, row.myLastReadAt]));- return withRuns.map((row) => ({- ...row,- ...deriveIssueUserContext(row, contextUserId, {- myLastCommentAt: statsByIssueId.get(row.id)?.myLastCommentAt ?? null,- myLastReadAt: readByIssueId.get(row.id) ?? null,- lastExternalCommentAt: statsByIssueId.get(row.id)?.lastExternalCommentAt ?? null,- }),- }));+ return withRuns.map((row) => {+ const activity = lastActivityByIssueId.get(row.id);+ const lastActivityAt = latestIssueActivityAt(+ row.updatedAt,+ activity?.latestCommentAt ?? null,+ activity?.latestLogAt ?? null,+ ) ?? row.updatedAt;+ return {+ ...row,+ lastActivityAt,+ ...deriveIssueUserContext(row, contextUserId, {+ myLastCommentAt: statsByIssueId.get(row.id)?.myLastCommentAt ?? null,+ myLastReadAt: readByIssueId.get(row.id) ?? null,+ lastExternalCommentAt: statsByIssueId.get(row.id)?.lastExternalCommentAt ?? null,+ }),+ };+ });},countUnreadTouchedByUser: async (companyId: string, userId: string, status?: string) => {diff --git a/server/src/services/routines.ts b/server/src/services/routines.tsindex f6fdb26f48..6367a29b16 100644--- a/server/src/services/routines.ts+++ b/server/src/services/routines.ts@@ -21,10 +21,16 @@ import type {RoutineRunSummary,RoutineTrigger,RoutineTriggerSecretMaterial,+ RoutineVariable,RunRoutine,UpdateRoutine,UpdateRoutineTrigger,} from "@paperclipai/shared";+import {+ interpolateRoutineTemplate,+ stringifyRoutineVariableValue,+ syncRoutineVariablesWithTemplate,+} from "@paperclipai/shared";import { conflict, forbidden, notFound, unauthorized, unprocessable } from "../errors.js";import { logger } from "../middleware/logger.js";import { issueService } from "./issues.js";@@ -138,6 +144,145 @@ function normalizeWebhookTimestampMs(rawTimestamp: string) {return parsed > 1e12 ? parsed : parsed * 1000;}+function isPlainRecord(value: unknown): value is Record<string, unknown> {+ return typeof value === "object" && value !== null && !Array.isArray(value);+}++function parseBooleanVariableValue(name: string, raw: unknown) {+ if (typeof raw === "boolean") return raw;+ if (typeof raw === "number" && (raw === 0 || raw === 1)) return raw === 1;+ if (typeof raw === "string") {+ const normalized = raw.trim().toLowerCase();+ if (["true", "1", "yes", "y", "on"].includes(normalized)) return true;+ if (["false", "0", "no", "n", "off"].includes(normalized)) return false;+ }+ throw unprocessable(`Variable "${name}" must be a boolean`);+}++function parseNumberVariableValue(name: string, raw: unknown) {+ if (typeof raw === "number" && Number.isFinite(raw)) return raw;+ if (typeof raw === "string" && raw.trim().length > 0) {+ const parsed = Number(raw);+ if (Number.isFinite(parsed)) return parsed;+ }+ throw unprocessable(`Variable "${name}" must be a number`);+}++function normalizeRoutineVariableValue(variable: RoutineVariable, raw: unknown): string | number | boolean | null {+ if (raw == null) return null;+ if (variable.type === "boolean") return parseBooleanVariableValue(variable.name, raw);+ if (variable.type === "number") return parseNumberVariableValue(variable.name, raw);++ const normalized = stringifyRoutineVariableValue(raw);+ if (variable.type === "select") {+ if (!variable.options.includes(normalized)) {+ throw unprocessable(`Variable "${variable.name}" must match one of: ${variable.options.join(", ")}`);+ }+ }+ return normalized;+}++function isMissingRoutineVariableValue(value: string | number | boolean | null) {+ return value == null || (typeof value === "string" && value.trim().length === 0);+}++function assertRoutineVariableDefinitions(variables: RoutineVariable[]) {+ for (const variable of variables) {+ if (variable.defaultValue != null) {+ normalizeRoutineVariableValue(variable, variable.defaultValue);+ }+ if (variable.type === "select" && variable.options.length === 0) {+ throw unprocessable(`Variable "${variable.name}" must define at least one option`);+ }+ }+}++function sanitizeRoutineVariableInputs(+ variables: Array<Partial<RoutineVariable> & Pick<RoutineVariable, "name">> | null | undefined,+): RoutineVariable[] {+ return (variables ?? []).map((variable) => ({+ name: variable.name,+ label: variable.label ?? null,+ type: variable.type ?? "text",+ defaultValue: variable.defaultValue ?? null,+ required: variable.required ?? true,+ options: variable.options ?? [],+ }));+}++function assertScheduleCompatibleVariables(variables: RoutineVariable[]) {+ const missingDefaults = variables+ .filter((variable) => variable.required)+ .filter((variable) => isMissingRoutineVariableValue(normalizeRoutineVariableValue(variable, variable.defaultValue)))+ .map((variable) => variable.name);+ if (missingDefaults.length > 0) {+ throw unprocessable(+ `Scheduled routines require defaults for required variables: ${missingDefaults.join(", ")}`,+ );+ }+}++function collectProvidedRoutineVariables(+ source: "schedule" | "manual" | "api" | "webhook",+ payload: Record<string, unknown> | null | undefined,+ variables: Record<string, unknown> | null | undefined,+) {+ const nestedVariables = isPlainRecord(payload) && isPlainRecord(payload.variables) ? payload.variables : {};+ const provided = {+ ...(source === "webhook" && payload ? payload : {}),+ ...nestedVariables,+ ...(variables ?? {}),+ };+ delete provided.variables;+ return provided;+}++function resolveRoutineVariableValues(+ variables: RoutineVariable[],+ input: {+ source: "schedule" | "manual" | "api" | "webhook";+ payload?: Record<string, unknown> | null;+ variables?: Record<string, unknown> | null;+ },+) {+ if (variables.length === 0) return {} as Record<string, string | number | boolean>;+ const provided = collectProvidedRoutineVariables(input.source, input.payload, input.variables);+ const resolved: Record<string, string | number | boolean> = {};+ const missing: string[] = [];++ for (const variable of variables) {+ const candidate = provided[variable.name] !== undefined ? provided[variable.name] : variable.defaultValue;+ const normalized = normalizeRoutineVariableValue(variable, candidate);+ if (normalized == null || (typeof normalized === "string" && normalized.trim().length === 0)) {+ if (variable.required) missing.push(variable.name);+ continue;+ }+ resolved[variable.name] = normalized;+ }++ if (missing.length > 0) {+ throw unprocessable(`Missing routine variables: ${missing.join(", ")}`);+ }++ return resolved;+}++function mergeRoutineRunPayload(+ payload: Record<string, unknown> | null | undefined,+ variables: Record<string, string | number | boolean>,+) {+ if (Object.keys(variables).length === 0) return payload ?? null;+ if (!payload) return { variables };+ const existingVariables = isPlainRecord(payload.variables) ? payload.variables : {};+ return {+ ...payload,+ variables: {+ ...existingVariables,+ ...variables,+ },+ };+}+export function routineService(db: Db, deps: { heartbeat?: IssueAssignmentWakeupDeps } = {}) {const issueSvc = issueService(db);const secretsSvc = secretService(db);@@ -515,8 +660,15 @@ export function routineService(db: Db, deps: { heartbeat?: IssueAssignmentWakeuptrigger: typeof routineTriggers.$inferSelect | null;source: "schedule" | "manual" | "api" | "webhook";payload?: Record<string, unknown> | null;+ variables?: Record<string, unknown> | null;idempotencyKey?: string | null;+ executionWorkspaceId?: string | null;+ executionWorkspacePreference?: string | null;+ executionWorkspaceSettings?: Record<string, unknown> | null;}) {+ const resolvedVariables = resolveRoutineVariableValues(input.routine.variables ?? [], input);+ const description = interpolateRoutineTemplate(input.routine.description, resolvedVariables);+ const triggerPayload = mergeRoutineRunPayload(input.payload, resolvedVariables);const run = await db.transaction(async (tx) => {const txDb = tx as unknown as Db;await tx.execute(@@ -553,7 +705,7 @@ export function routineService(db: Db, deps: { heartbeat?: IssueAssignmentWakeupstatus: "received",triggeredAt,idempotencyKey: input.idempotencyKey ?? null,- triggerPayload: input.payload ?? null,+ triggerPayload,}).returning();@@ -589,13 +741,16 @@ export function routineService(db: Db, deps: { heartbeat?: IssueAssignmentWakeupgoalId: input.routine.goalId,parentId: input.routine.parentIssueId,title: input.routine.title,- description: input.routine.description,+ description,status: "todo",priority: input.routine.priority,assigneeAgentId: input.routine.assigneeAgentId,originKind: "routine_execution",originId: input.routine.id,originRunId: createdRun.id,+ executionWorkspaceId: input.executionWorkspaceId ?? null,+ executionWorkspacePreference: input.executionWorkspacePreference ?? null,+ executionWorkspaceSettings: input.executionWorkspaceSettings ?? null,});} catch (error) {const isOpenExecutionConflict =@@ -824,6 +979,11 @@ export function routineService(db: Db, deps: { heartbeat?: IssueAssignmentWakeupawait assertAssignableAgent(companyId, input.assigneeAgentId);if (input.goalId) await assertGoal(companyId, input.goalId);if (input.parentIssueId) await assertParentIssue(companyId, input.parentIssueId);+ const variables = syncRoutineVariablesWithTemplate(+ input.description,+ sanitizeRoutineVariableInputs(input.variables),+ );+ assertRoutineVariableDefinitions(variables);const [created] = await db.insert(routines).values({@@ -838,6 +998,7 @@ export function routineService(db: Db, deps: { heartbeat?: IssueAssignmentWakeupstatus: input.status,concurrencyPolicy: input.concurrencyPolicy,catchUpPolicy: input.catchUpPolicy,+ variables,createdByAgentId: actor.agentId ?? null,createdByUserId: actor.userId ?? null,updatedByAgentId: actor.agentId ?? null,@@ -852,10 +1013,31 @@ export function routineService(db: Db, deps: { heartbeat?: IssueAssignmentWakeupif (!existing) return null;const nextProjectId = patch.projectId ?? existing.projectId;const nextAssigneeAgentId = patch.assigneeAgentId ?? existing.assigneeAgentId;+ const nextDescription = patch.description === undefined ? existing.description : patch.description;+ const nextVariables = syncRoutineVariablesWithTemplate(+ nextDescription,+ patch.variables === undefined ? existing.variables : sanitizeRoutineVariableInputs(patch.variables),+ );if (patch.projectId) await assertProject(existing.companyId, nextProjectId);if (patch.assigneeAgentId) await assertAssignableAgent(existing.companyId, nextAssigneeAgentId);if (patch.goalId) await assertGoal(existing.companyId, patch.goalId);if (patch.parentIssueId) await assertParentIssue(existing.companyId, patch.parentIssueId);+ assertRoutineVariableDefinitions(nextVariables);+ const enabledScheduleTriggers = await db+ .select({ id: routineTriggers.id })+ .from(routineTriggers)+ .where(+ and(+ eq(routineTriggers.routineId, existing.id),+ eq(routineTriggers.kind, "schedule"),+ eq(routineTriggers.enabled, true),+ ),+ )+ .limit(1)+ .then((rows) => rows.length > 0);+ if (enabledScheduleTriggers) {+ assertScheduleCompatibleVariables(nextVariables);+ }const [updated] = await db.update(routines).set({@@ -863,12 +1045,13 @@ export function routineService(db: Db, deps: { heartbeat?: IssueAssignmentWakeupgoalId: patch.goalId === undefined ? existing.goalId : patch.goalId,parentIssueId: patch.parentIssueId === undefined ? existing.parentIssueId : patch.parentIssueId,title: patch.title ?? existing.title,- description: patch.description === undefined ? existing.description : patch.description,+ description: nextDescription,assigneeAgentId: nextAssigneeAgentId,priority: patch.priority ?? existing.priority,status: patch.status ?? existing.status,concurrencyPolicy: patch.concurrencyPolicy ?? existing.concurrencyPolicy,catchUpPolicy: patch.catchUpPolicy ?? existing.catchUpPolicy,+ variables: nextVariables,updatedByAgentId: actor.agentId ?? null,updatedByUserId: actor.userId ?? null,updatedAt: new Date(),@@ -892,6 +1075,7 @@ export function routineService(db: Db, deps: { heartbeat?: IssueAssignmentWakeuplet nextRunAt: Date | null = null;if (input.kind === "schedule") {+ assertScheduleCompatibleVariables(routine.variables ?? []);const timeZone = input.timezone || "UTC";assertTimeZone(timeZone);const error = validateCron(input.cronExpression);@@ -947,6 +1131,8 @@ export function routineService(db: Db, deps: { heartbeat?: IssueAssignmentWakeuplet timezone = existing.timezone;if (existing.kind === "schedule") {+ const routine = await getRoutineById(existing.routineId);+ if (!routine) throw notFound("Routine not found");if (patch.cronExpression !== undefined) {if (patch.cronExpression == null) throw unprocessable("Scheduled triggers require cronExpression");const error = validateCron(patch.cronExpression);@@ -961,6 +1147,9 @@ export function routineService(db: Db, deps: { heartbeat?: IssueAssignmentWakeupif (cronExpression && timezone) {nextRunAt = nextCronTickInTimeZone(cronExpression, timezone, new Date());}+ if ((patch.enabled ?? existing.enabled) === true) {+ assertScheduleCompatibleVariables(routine.variables ?? []);+ }}const [updated] = await db@@ -1034,7 +1223,12 @@ export function routineService(db: Db, deps: { heartbeat?: IssueAssignmentWakeuptrigger,source: input.source,payload: input.payload as Record<string, unknown> | null | undefined,+ variables: input.variables as Record<string, unknown> | null | undefined,idempotencyKey: input.idempotencyKey,+ executionWorkspaceId: input.executionWorkspaceId ?? null,+ executionWorkspacePreference: input.executionWorkspacePreference ?? null,+ executionWorkspaceSettings:+ (input.executionWorkspaceSettings as Record<string, unknown> | null | undefined) ?? null,});},@@ -1097,6 +1291,9 @@ export function routineService(db: Db, deps: { heartbeat?: IssueAssignmentWakeuptrigger,source: "webhook",payload: input.payload,+ variables: isPlainRecord(input.payload) && isPlainRecord(input.payload.variables)+ ? input.payload.variables+ : null,idempotencyKey: input.idempotencyKey,});},diff --git a/ui/src/components/IssueWorkspaceCard.tsx b/ui/src/components/IssueWorkspaceCard.tsxindex 73ecf9eb9a..6637c9c309 100644--- a/ui/src/components/IssueWorkspaceCard.tsx+++ b/ui/src/components/IssueWorkspaceCard.tsx@@ -26,7 +26,12 @@ function issueModeForExistingWorkspace(mode: string | null | undefined) {return "shared_workspace";}-function shouldPresentExistingWorkspaceSelection(issue: Issue) {+function shouldPresentExistingWorkspaceSelection(issue: {+ executionWorkspaceId: string | null;+ executionWorkspacePreference: string | null;+ executionWorkspaceSettings: Issue["executionWorkspaceSettings"];+ currentExecutionWorkspace?: ExecutionWorkspace | null;+}) {const persistedMode =issue.currentExecutionWorkspace?.mode?? issue.executionWorkspaceSettings?.mode@@ -156,19 +161,44 @@ function statusBadge(status: string) {/* -------------------------------------------------------------------------- */interface IssueWorkspaceCardProps {- issue: Issue;+ issue: Omit<+ Pick<+ Issue,+ | "companyId"+ | "projectId"+ | "projectWorkspaceId"+ | "executionWorkspaceId"+ | "executionWorkspacePreference"+ | "executionWorkspaceSettings"+ >,+ "companyId"+ > & {+ companyId: string | null;+ currentExecutionWorkspace?: ExecutionWorkspace | null;+ };project: { id: string; executionWorkspacePolicy?: { enabled?: boolean; defaultMode?: string | null; defaultProjectWorkspaceId?: string | null } | null; workspaces?: Array<{ id: string; isPrimary: boolean }> } | null;onUpdate: (data: Record<string, unknown>) => void;+ initialEditing?: boolean;+ livePreview?: boolean;+ onDraftChange?: (data: Record<string, unknown>, meta: { canSave: boolean }) => void;}-export function IssueWorkspaceCard({ issue, project, onUpdate }: IssueWorkspaceCardProps) {+export function IssueWorkspaceCard({+ issue,+ project,+ onUpdate,+ initialEditing = false,+ livePreview = false,+ onDraftChange,+}: IssueWorkspaceCardProps) {const { selectedCompanyId } = useCompany();const companyId = issue.companyId ?? selectedCompanyId;- const [editing, setEditing] = useState(false);+ const [editing, setEditing] = useState(initialEditing);const { data: experimentalSettings } = useQuery({queryKey: queryKeys.instance.experimentalSettings,queryFn: () => instanceSettingsApi.getExperimental(),+ retry: false,});const policyEnabled = experimentalSettings?.enableIsolatedWorkspaces === true@@ -209,13 +239,16 @@ export function IssueWorkspaceCard({ issue, project, onUpdate }: IssueWorkspaceC?? workspace?? null;- const currentSelection = shouldPresentExistingWorkspaceSelection(issue)+ const configuredSelection = shouldPresentExistingWorkspaceSelection(issue)? "reuse_existing": (issue.executionWorkspacePreference?? issue.executionWorkspaceSettings?.mode?? defaultExecutionWorkspaceModeForProject(project));+ const currentSelection = configuredSelection === "operator_branch" || configuredSelection === "agent_default"+ ? "shared_workspace"+ : configuredSelection;const [draftSelection, setDraftSelection] = useState(currentSelection);const [draftExecutionWorkspaceId, setDraftExecutionWorkspaceId] = useState(issue.executionWorkspaceId ?? "");@@ -245,24 +278,33 @@ export function IssueWorkspaceCard({ issue, project, onUpdate }: IssueWorkspaceCconst canSaveWorkspaceConfig = draftSelection !== "reuse_existing" || draftExecutionWorkspaceId.length > 0;+ const buildWorkspaceDraftUpdate = useCallback(() => ({+ executionWorkspacePreference: draftSelection,+ executionWorkspaceId: draftSelection === "reuse_existing" ? draftExecutionWorkspaceId || null : null,+ executionWorkspaceSettings: {+ mode:+ draftSelection === "reuse_existing"+ ? issueModeForExistingWorkspace(configuredReusableWorkspace?.mode)+ : draftSelection,+ },+ }), [+ configuredReusableWorkspace?.mode,+ draftExecutionWorkspaceId,+ draftSelection,+ ]);++ useEffect(() => {+ if (!onDraftChange) return;+ onDraftChange(buildWorkspaceDraftUpdate(), { canSave: canSaveWorkspaceConfig });+ }, [buildWorkspaceDraftUpdate, canSaveWorkspaceConfig, onDraftChange]);+const handleSave = useCallback(() => {if (!canSaveWorkspaceConfig) return;- onUpdate({- executionWorkspacePreference: draftSelection,- executionWorkspaceId: draftSelection === "reuse_existing" ? draftExecutionWorkspaceId || null : null,- executionWorkspaceSettings: {- mode:- draftSelection === "reuse_existing"- ? issueModeForExistingWorkspace(configuredReusableWorkspace?.mode)- : draftSelection,- },- });+ onUpdate(buildWorkspaceDraftUpdate());setEditing(false);}, [+ buildWorkspaceDraftUpdate,canSaveWorkspaceConfig,- configuredReusableWorkspace?.mode,- draftExecutionWorkspaceId,- draftSelection,onUpdate,]);@@ -274,6 +316,8 @@ export function IssueWorkspaceCard({ issue, project, onUpdate }: IssueWorkspaceCif (!policyEnabled || !project) return null;+ const showEditingControls = livePreview || editing;+return (<div className="rounded-lg border border-border p-3 space-y-2">{/* Header row */}@@ -286,7 +330,7 @@ export function IssueWorkspaceCard({ issue, project, onUpdate }: IssueWorkspaceC{workspace ? statusBadge(workspace.status) : statusBadge("idle")}</div><div className="flex items-center gap-1">- {editing ? (+ {!livePreview && editing ? (<><Buttonvariant="ghost"@@ -305,7 +349,7 @@ export function IssueWorkspaceCard({ issue, project, onUpdate }: IssueWorkspaceCSave</Button></>- ) : (+ ) : !livePreview ? (<Buttonvariant="ghost"size="sm"@@ -314,12 +358,12 @@ export function IssueWorkspaceCard({ issue, project, onUpdate }: IssueWorkspaceC><Pencil className="h-3 w-3 mr-1" />Edit</Button>- )}+ ) : null}</div></div>{/* Read-only info */}- {!editing && (+ {!showEditingControls && (<div className="space-y-1.5 text-xs">{workspace?.branchName && (<div className="flex items-center gap-1.5">@@ -377,7 +421,7 @@ export function IssueWorkspaceCard({ issue, project, onUpdate }: IssueWorkspaceC)}{/* Editing controls */}- {editing && (+ {showEditingControls && (<div className="space-y-2 pt-1"><selectclassName="w-full rounded border border-border bg-transparent px-2 py-1.5 text-xs outline-none"diff --git a/ui/src/components/IssuesQuicklook.tsx b/ui/src/components/IssuesQuicklook.tsxnew file mode 100644index 0000000000..c4e02e49b5--- /dev/null+++ b/ui/src/components/IssuesQuicklook.tsx@@ -0,0 +1,55 @@+import { useState } from "react";+import type { Issue } from "@paperclipai/shared";+import { Link } from "@/lib/router";+import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";+import { StatusIcon } from "./StatusIcon";+import { createIssueDetailPath } from "../lib/issueDetailBreadcrumb";+import { timeAgo } from "../lib/timeAgo";++interface IssuesQuicklookProps {+ issue: Issue;+ children: React.ReactNode;+}++export function IssuesQuicklook({ issue, children }: IssuesQuicklookProps) {+ const [open, setOpen] = useState(false);++ return (+ <Popover open={open} onOpenChange={setOpen}>+ <PopoverTrigger+ asChild+ onMouseEnter={() => setOpen(true)}+ onMouseLeave={() => setOpen(false)}+ >+ {children}+ </PopoverTrigger>+ <PopoverContent+ className="w-64 p-3"+ side="top"+ align="start"+ onMouseEnter={() => setOpen(true)}+ onMouseLeave={() => setOpen(false)}+ onOpenAutoFocus={(e) => e.preventDefault()}+ >+ <div className="space-y-2">+ <div className="flex items-start gap-2">+ <StatusIcon status={issue.status} className="mt-0.5 shrink-0" />+ <Link+ to={createIssueDetailPath(issue.identifier ?? issue.id)}+ className="text-sm font-medium leading-snug hover:underline line-clamp-2"+ >+ {issue.title}+ </Link>+ </div>+ <div className="flex items-center gap-2 text-xs text-muted-foreground">+ <span className="font-mono">{issue.identifier ?? issue.id.slice(0, 8)}</span>+ <span>·</span>+ <span>{issue.status.replace(/_/g, " ")}</span>+ <span>·</span>+ <span>{timeAgo(new Date(issue.updatedAt))}</span>+ </div>+ </div>+ </PopoverContent>+ </Popover>+ );+}diff --git a/ui/src/components/NewIssueDialog.tsx b/ui/src/components/NewIssueDialog.tsxindex 559a205555..2881a7dcea 100644--- a/ui/src/components/NewIssueDialog.tsx+++ b/ui/src/components/NewIssueDialog.tsx@@ -340,6 +340,7 @@ export function NewIssueDialog() {queryKey: queryKeys.instance.experimentalSettings,queryFn: () => instanceSettingsApi.getExperimental(),enabled: newIssueOpen,+ retry: false,});const currentUserId = session?.user?.id ?? session?.session?.userId ?? null;const activeProjects = useMemo(diff --git a/ui/src/components/ProjectProperties.tsx b/ui/src/components/ProjectProperties.tsxindex 0e0ea33ebe..6574091ccd 100644--- a/ui/src/components/ProjectProperties.tsx+++ b/ui/src/components/ProjectProperties.tsx@@ -242,6 +242,7 @@ export function ProjectProperties({ project, onUpdate, onFieldUpdate, getFieldSaconst { data: experimentalSettings } = useQuery({queryKey: queryKeys.instance.experimentalSettings,queryFn: () => instanceSettingsApi.getExperimental(),+ retry: false,});const linkedGoalIds = project.goalIds.length > 0diff --git a/ui/src/components/RoutineRunVariablesDialog.tsx b/ui/src/components/RoutineRunVariablesDialog.tsxnew file mode 100644index 0000000000..5521c73832--- /dev/null+++ b/ui/src/components/RoutineRunVariablesDialog.tsx@@ -0,0 +1,323 @@+import { useCallback, useEffect, useMemo, useState } from "react";+import type { IssueExecutionWorkspaceSettings, Project, RoutineVariable } from "@paperclipai/shared";+import { useQuery } from "@tanstack/react-query";+import { instanceSettingsApi } from "../api/instanceSettings";+import { queryKeys } from "../lib/queryKeys";+import { IssueWorkspaceCard } from "./IssueWorkspaceCard";+import { Button } from "@/components/ui/button";+import {+ Dialog,+ DialogContent,+ DialogDescription,+ DialogFooter,+ DialogHeader,+ DialogTitle,+} from "@/components/ui/dialog";+import { Input } from "@/components/ui/input";+import { Label } from "@/components/ui/label";+import {+ Select,+ SelectContent,+ SelectItem,+ SelectTrigger,+ SelectValue,+} from "@/components/ui/select";+import { Textarea } from "@/components/ui/textarea";++function buildInitialValues(variables: RoutineVariable[]) {+ return Object.fromEntries(variables.map((variable) => [variable.name, variable.defaultValue ?? ""]));+}++function defaultProjectWorkspaceIdForProject(project: Project | null | undefined) {+ if (!project) return null;+ return project.executionWorkspacePolicy?.defaultProjectWorkspaceId+ ?? project.workspaces?.find((workspace) => workspace.isPrimary)?.id+ ?? project.workspaces?.[0]?.id+ ?? null;+}++function defaultExecutionWorkspaceModeForProject(project: Project | null | undefined) {+ const defaultMode = project?.executionWorkspacePolicy?.enabled ? project.executionWorkspacePolicy.defaultMode : null;+ if (+ defaultMode === "isolated_workspace" ||+ defaultMode === "operator_branch" ||+ defaultMode === "adapter_default"+ ) {+ return defaultMode === "adapter_default" ? "agent_default" : defaultMode;+ }+ return "shared_workspace";+}++function buildInitialWorkspaceConfig(project: Project | null | undefined) {+ const defaultMode = defaultExecutionWorkspaceModeForProject(project);+ return {+ executionWorkspaceId: null as string | null,+ executionWorkspacePreference: defaultMode,+ executionWorkspaceSettings: { mode: defaultMode } as IssueExecutionWorkspaceSettings,+ projectWorkspaceId: defaultProjectWorkspaceIdForProject(project),+ };+}++function workspaceConfigEquals(+ a: ReturnType<typeof buildInitialWorkspaceConfig>,+ b: ReturnType<typeof buildInitialWorkspaceConfig>,+) {+ return a.executionWorkspaceId === b.executionWorkspaceId+ && a.executionWorkspacePreference === b.executionWorkspacePreference+ && a.projectWorkspaceId === b.projectWorkspaceId+ && JSON.stringify(a.executionWorkspaceSettings ?? null) === JSON.stringify(b.executionWorkspaceSettings ?? null);+}++function applyWorkspaceDraft(+ current: ReturnType<typeof buildInitialWorkspaceConfig>,+ data: Record<string, unknown>,+) {+ const next = {+ ...current,+ executionWorkspaceId: (data.executionWorkspaceId as string | null | undefined) ?? null,+ executionWorkspacePreference:+ (data.executionWorkspacePreference as string | null | undefined)+ ?? current.executionWorkspacePreference,+ executionWorkspaceSettings:+ (data.executionWorkspaceSettings as IssueExecutionWorkspaceSettings | null | undefined)+ ?? current.executionWorkspaceSettings,+ };+ return workspaceConfigEquals(current, next) ? current : next;+}++function isMissingRequiredValue(value: unknown) {+ return value == null || (typeof value === "string" && value.trim().length === 0);+}++function supportsRoutineRunWorkspaceSelection(+ project: Project | null | undefined,+ isolatedWorkspacesEnabled: boolean,+) {+ return isolatedWorkspacesEnabled && Boolean(project?.executionWorkspacePolicy?.enabled);+}++export function routineRunNeedsConfiguration(input: {+ variables: RoutineVariable[];+ project: Project | null | undefined;+ isolatedWorkspacesEnabled: boolean;+}) {+ return input.variables.length > 0+ || supportsRoutineRunWorkspaceSelection(input.project, input.isolatedWorkspacesEnabled);+}++export interface RoutineRunDialogSubmitData {+ variables?: Record<string, string | number | boolean>;+ executionWorkspaceId?: string | null;+ executionWorkspacePreference?: string | null;+ executionWorkspaceSettings?: IssueExecutionWorkspaceSettings | null;+}++export function RoutineRunVariablesDialog({+ open,+ onOpenChange,+ companyId,+ project,+ variables,+ isPending,+ onSubmit,+}: {+ open: boolean;+ onOpenChange: (open: boolean) => void;+ companyId: string | null | undefined;+ project: Project | null | undefined;+ variables: RoutineVariable[];+ isPending: boolean;+ onSubmit: (data: RoutineRunDialogSubmitData) => void;+}) {+ const [values, setValues] = useState<Record<string, unknown>>({});+ const [workspaceConfig, setWorkspaceConfig] = useState(() => buildInitialWorkspaceConfig(project));+ const [workspaceConfigValid, setWorkspaceConfigValid] = useState(true);++ const { data: experimentalSettings } = useQuery({+ queryKey: queryKeys.instance.experimentalSettings,+ queryFn: () => instanceSettingsApi.getExperimental(),+ retry: false,+ });++ const workspaceSelectionEnabled = supportsRoutineRunWorkspaceSelection(+ project,+ experimentalSettings?.enableIsolatedWorkspaces === true,+ );++ useEffect(() => {+ if (!open) return;+ setValues(buildInitialValues(variables));+ setWorkspaceConfig(buildInitialWorkspaceConfig(project));+ setWorkspaceConfigValid(true);+ }, [open, project, variables]);++ const missingRequired = useMemo(+ () =>+ variables+ .filter((variable) => variable.required)+ .filter((variable) => isMissingRequiredValue(values[variable.name]))+ .map((variable) => variable.label || variable.name),+ [values, variables],+ );++ const workspaceIssue = useMemo(() => ({+ companyId: companyId ?? null,+ projectId: project?.id ?? null,+ projectWorkspaceId: workspaceConfig.projectWorkspaceId,+ executionWorkspaceId: workspaceConfig.executionWorkspaceId,+ executionWorkspacePreference: workspaceConfig.executionWorkspacePreference,+ executionWorkspaceSettings: workspaceConfig.executionWorkspaceSettings,+ currentExecutionWorkspace: null,+ }), [+ companyId,+ project?.id,+ workspaceConfig.executionWorkspaceId,+ workspaceConfig.executionWorkspacePreference,+ workspaceConfig.executionWorkspaceSettings,+ workspaceConfig.projectWorkspaceId,+ ]);++ const canSubmit = missingRequired.length === 0 && (!workspaceSelectionEnabled || workspaceConfigValid);++ const handleWorkspaceUpdate = useCallback((data: Record<string, unknown>) => {+ setWorkspaceConfig((current) => applyWorkspaceDraft(current, data));+ }, []);++ const handleWorkspaceDraftChange = useCallback((+ data: Record<string, unknown>,+ meta: { canSave: boolean },+ ) => {+ setWorkspaceConfig((current) => applyWorkspaceDraft(current, data));+ setWorkspaceConfigValid((current) => (current === meta.canSave ? current : meta.canSave));+ }, []);++ return (+ <Dialog open={open} onOpenChange={(next) => !isPending && onOpenChange(next)}>+ <DialogContent className="max-w-xl">+ <DialogHeader>+ <DialogTitle>Run routine</DialogTitle>+ <DialogDescription>+ Fill in the routine variables before starting the execution issue.+ </DialogDescription>+ </DialogHeader>++ <div className="space-y-4">+ {variables.map((variable) => (+ <div key={variable.name} className="space-y-1.5">+ <Label className="text-xs">+ {variable.label || variable.name}+ {variable.required ? " *" : ""}+ </Label>+ {variable.type === "textarea" ? (+ <Textarea+ rows={4}+ value={typeof values[variable.name] === "string" ? values[variable.name] as string : ""}+ onChange={(event) => setValues((current) => ({ ...current, [variable.name]: event.target.value }))}+ />+ ) : variable.type === "boolean" ? (+ <Select+ value={values[variable.name] === true ? "true" : values[variable.name] === false ? "false" : "__unset__"}+ onValueChange={(next) => setValues((current) => ({+ ...current,+ [variable.name]: next === "__unset__" ? "" : next === "true",+ }))}+ >+ <SelectTrigger>+ <SelectValue />+ </SelectTrigger>+ <SelectContent>+ <SelectItem value="__unset__">No value</SelectItem>+ <SelectItem value="true">True</SelectItem>+ <SelectItem value="false">False</SelectItem>+ </SelectContent>+ </Select>+ ) : variable.type === "select" ? (+ <Select+ value={typeof values[variable.name] === "string" && values[variable.name] ? values[variable.name] as string : "__unset__"}+ onValueChange={(next) => setValues((current) => ({+ ...current,+ [variable.name]: next === "__unset__" ? "" : next,+ }))}+ >+ <SelectTrigger>+ <SelectValue placeholder="Choose a value" />+ </SelectTrigger>+ <SelectContent>+ <SelectItem value="__unset__">No value</SelectItem>+ {variable.options.map((option) => (+ <SelectItem key={option} value={option}>{option}</SelectItem>+ ))}+ </SelectContent>+ </Select>+ ) : (+ <Input+ type={variable.type === "number" ? "number" : "text"}+ value={values[variable.name] == null ? "" : String(values[variable.name])}+ onChange={(event) => setValues((current) => ({ ...current, [variable.name]: event.target.value }))}+ />+ )}+ </div>+ ))}++ {workspaceSelectionEnabled && project && companyId ? (+ <IssueWorkspaceCard+ key={`${open ? "open" : "closed"}:${project.id}`}+ issue={workspaceIssue}+ project={project}+ initialEditing+ livePreview+ onUpdate={handleWorkspaceUpdate}+ onDraftChange={handleWorkspaceDraftChange}+ />+ ) : null}+ </div>++ <DialogFooter showCloseButton={false}>+ {missingRequired.length > 0 ? (+ <p className="mr-auto text-xs text-amber-600">+ Missing: {missingRequired.join(", ")}+ </p>+ ) : workspaceSelectionEnabled && !workspaceConfigValid ? (+ <p className="mr-auto text-xs text-amber-600">+ Choose an existing workspace before running.+ </p>+ ) : (+ <span className="mr-auto" />+ )}+ <Button variant="ghost" onClick={() => onOpenChange(false)} disabled={isPending}>+ Cancel+ </Button>+ <Button+ onClick={() => {+ const nextVariables: Record<string, string | number | boolean> = {};+ for (const variable of variables) {+ const rawValue = values[variable.name];+ if (isMissingRequiredValue(rawValue)) continue;+ if (variable.type === "number") {+ nextVariables[variable.name] = Number(rawValue);+ } else if (variable.type === "boolean") {+ nextVariables[variable.name] = rawValue === true;+ } else {+ nextVariables[variable.name] = String(rawValue);+ }+ }+ onSubmit({+ variables: nextVariables,+ ...(workspaceSelectionEnabled+ ? {+ executionWorkspaceId: workspaceConfig.executionWorkspaceId,+ executionWorkspacePreference: workspaceConfig.executionWorkspacePreference,+ executionWorkspaceSettings: workspaceConfig.executionWorkspaceSettings,+ }+ : {}),+ });+ }}+ disabled={isPending || !canSubmit}+ >+ {isPending ? "Running..." : "Run routine"}+ </Button>+ </DialogFooter>+ </DialogContent>+ </Dialog>+ );+}diff --git a/ui/src/components/RoutineVariablesEditor.tsx b/ui/src/components/RoutineVariablesEditor.tsxnew file mode 100644index 0000000000..565589b8b4--- /dev/null+++ b/ui/src/components/RoutineVariablesEditor.tsx@@ -0,0 +1,232 @@+import { useEffect, useMemo, useState } from "react";+import { ChevronDown, ChevronRight } from "lucide-react";+import { syncRoutineVariablesWithTemplate, type RoutineVariable } from "@paperclipai/shared";+import { Badge } from "@/components/ui/badge";+import { Collapsible, CollapsibleContent, CollapsibleTrigger } from "@/components/ui/collapsible";+import { Input } from "@/components/ui/input";+import { Label } from "@/components/ui/label";+import {+ Select,+ SelectContent,+ SelectItem,+ SelectTrigger,+ SelectValue,+} from "@/components/ui/select";+import { Textarea } from "@/components/ui/textarea";++const variableTypes: RoutineVariable["type"][] = ["text", "textarea", "number", "boolean", "select"];++function serializeVariables(value: RoutineVariable[]) {+ return JSON.stringify(value);+}++function parseSelectOptions(value: string) {+ return value+ .split(",")+ .map((entry) => entry.trim())+ .filter(Boolean);+}++function updateVariableList(+ variables: RoutineVariable[],+ name: string,+ mutate: (variable: RoutineVariable) => RoutineVariable,+) {+ return variables.map((variable) => (variable.name === name ? mutate(variable) : variable));+}++export function RoutineVariablesEditor({+ description,+ value,+ onChange,+}: {+ description: string;+ value: RoutineVariable[];+ onChange: (value: RoutineVariable[]) => void;+}) {+ const [open, setOpen] = useState(true);+ const syncedVariables = useMemo(+ () => syncRoutineVariablesWithTemplate(description, value),+ [description, value],+ );+ const syncedSignature = serializeVariables(syncedVariables);+ const currentSignature = serializeVariables(value);++ useEffect(() => {+ if (syncedSignature !== currentSignature) {+ onChange(syncedVariables);+ }+ }, [currentSignature, onChange, syncedSignature, syncedVariables]);++ if (syncedVariables.length === 0) {+ return null;+ }++ return (+ <Collapsible open={open} onOpenChange={setOpen}>+ <CollapsibleTrigger className="flex w-full items-center justify-between rounded-lg border border-border/70 px-3 py-2 text-left">+ <div>+ <p className="text-sm font-medium">Variables</p>+ <p className="text-xs text-muted-foreground">+ Detected from `{"{{name}}"}` placeholders in the routine instructions.+ </p>+ </div>+ {open ? <ChevronDown className="h-4 w-4 text-muted-foreground" /> : <ChevronRight className="h-4 w-4 text-muted-foreground" />}+ </CollapsibleTrigger>+ <CollapsibleContent className="space-y-3 pt-3">+ {syncedVariables.map((variable) => (+ <div key={variable.name} className="rounded-lg border border-border/70 p-4">+ <div className="mb-3 flex flex-wrap items-center gap-2">+ <Badge variant="outline" className="font-mono text-xs">+ {`{{${variable.name}}}`}+ </Badge>+ <span className="text-xs text-muted-foreground">+ Prompt the user for this value before each manual run.+ </span>+ </div>++ <div className="grid gap-3 md:grid-cols-2">+ <div className="space-y-1.5">+ <Label className="text-xs">Label</Label>+ <Input+ value={variable.label ?? ""}+ onChange={(event) => onChange(updateVariableList(syncedVariables, variable.name, (current) => ({+ ...current,+ label: event.target.value || null,+ })))}+ placeholder={variable.name.replaceAll("_", " ")}+ />+ </div>++ <div className="space-y-1.5">+ <Label className="text-xs">Type</Label>+ <Select+ value={variable.type}+ onValueChange={(type) => onChange(updateVariableList(syncedVariables, variable.name, (current) => ({+ ...current,+ type: type as RoutineVariable["type"],+ defaultValue: type === "boolean" ? null : current.defaultValue,+ options: type === "select" ? current.options : [],+ })))}+ >+ <SelectTrigger>+ <SelectValue />+ </SelectTrigger>+ <SelectContent>+ {variableTypes.map((type) => (+ <SelectItem key={type} value={type}>{type}</SelectItem>+ ))}+ </SelectContent>+ </Select>+ </div>++ <div className="space-y-1.5 md:col-span-2">+ <div className="flex items-center justify-between gap-3">+ <Label className="text-xs">Default value</Label>+ <label className="flex items-center gap-2 text-xs text-muted-foreground">+ <input+ type="checkbox"+ checked={variable.required}+ onChange={(event) => onChange(updateVariableList(syncedVariables, variable.name, (current) => ({+ ...current,+ required: event.target.checked,+ })))}+ />+ Required+ </label>+ </div>++ {variable.type === "textarea" ? (+ <Textarea+ rows={3}+ value={variable.defaultValue == null ? "" : String(variable.defaultValue)}+ onChange={(event) => onChange(updateVariableList(syncedVariables, variable.name, (current) => ({+ ...current,+ defaultValue: event.target.value || null,+ })))}+ />+ ) : variable.type === "boolean" ? (+ <Select+ value={variable.defaultValue === true ? "true" : variable.defaultValue === false ? "false" : "__unset__"}+ onValueChange={(next) => onChange(updateVariableList(syncedVariables, variable.name, (current) => ({+ ...current,+ defaultValue: next === "__unset__" ? null : next === "true",+ })))}+ >+ <SelectTrigger>+ <SelectValue />+ </SelectTrigger>+ <SelectContent>+ <SelectItem value="__unset__">No default</SelectItem>+ <SelectItem value="true">True</SelectItem>+ <SelectItem value="false">False</SelectItem>+ </SelectContent>+ </Select>+ ) : variable.type === "select" ? (+ <div className="grid gap-3 md:grid-cols-2">+ <div className="space-y-1.5">+ <Label className="text-xs">Options</Label>+ <Input+ value={variable.options.join(", ")}+ onChange={(event) => {+ const options = parseSelectOptions(event.target.value);+ onChange(updateVariableList(syncedVariables, variable.name, (current) => ({+ ...current,+ options,+ defaultValue:+ typeof current.defaultValue === "string" && options.includes(current.defaultValue)+ ? current.defaultValue+ : null,+ })));+ }}+ placeholder="high, medium, low"+ />+ </div>+ <div className="space-y-1.5">+ <Label className="text-xs">Default option</Label>+ <Select+ value={typeof variable.defaultValue === "string" ? variable.defaultValue : "__unset__"}+ onValueChange={(next) => onChange(updateVariableList(syncedVariables, variable.name, (current) => ({+ ...current,+ defaultValue: next === "__unset__" ? null : next,+ })))}+ >+ <SelectTrigger>+ <SelectValue placeholder="No default" />+ </SelectTrigger>+ <SelectContent>+ <SelectItem value="__unset__">No default</SelectItem>+ {variable.options.map((option) => (+ <SelectItem key={option} value={option}>{option}</SelectItem>+ ))}+ </SelectContent>+ </Select>+ </div>+ </div>+ ) : (+ <Input+ type={variable.type === "number" ? "number" : "text"}+ value={variable.defaultValue == null ? "" : String(variable.defaultValue)}+ onChange={(event) => onChange(updateVariableList(syncedVariables, variable.name, (current) => ({+ ...current,+ defaultValue: event.target.value || null,+ })))}+ placeholder={variable.type === "number" ? "42" : "Default value"}+ />+ )}+ </div>+ </div>+ </div>+ ))}+ </CollapsibleContent>+ </Collapsible>+ );+}++export function RoutineVariablesHint() {+ return (+ <div className="rounded-lg border border-dashed border-border/70 px-3 py-2 text-xs text-muted-foreground">+ Use `{"{{variable_name}}"}` placeholders in the instructions to prompt for inputs when the routine runs.+ </div>+ );+}diff --git a/ui/src/lib/project-workspaces-tab.ts b/ui/src/lib/project-workspaces-tab.tsindex df0d9bb35d..f4e5c5c376 100644--- a/ui/src/lib/project-workspaces-tab.ts+++ b/ui/src/lib/project-workspaces-tab.ts@@ -78,35 +78,37 @@ export function buildProjectWorkspaceSummaries(input: {})) continue;const existing = summaries.get(`execution:${executionWorkspace.id}`);- const nextIssues = [...(existing?.issues ?? []), issue].sort(- (a, b) => new Date(b.updatedAt).getTime() - new Date(a.updatedAt).getTime(),- );+ const nextIssues = existing?.issues ?? [];+ nextIssues.push(issue);- summaries.set(`execution:${executionWorkspace.id}`, {- key: `execution:${executionWorkspace.id}`,- kind: "execution_workspace",- workspaceId: executionWorkspace.id,- workspaceName: executionWorkspace.name,- cwd: executionWorkspace.cwd ?? null,- branchName: executionWorkspace.branchName ?? executionWorkspace.baseRef ?? null,- lastUpdatedAt: maxDate(- existing?.lastUpdatedAt,- executionWorkspace.lastUsedAt,- executionWorkspace.updatedAt,- issue.updatedAt,- ),- projectWorkspaceId: executionWorkspace.projectWorkspaceId ?? issue.projectWorkspaceId ?? null,- executionWorkspaceId: executionWorkspace.id,- executionWorkspaceStatus: executionWorkspace.status,- serviceCount: executionWorkspace.runtimeServices?.length ?? 0,- runningServiceCount: executionWorkspace.runtimeServices?.filter((service) => service.status === "running").length ?? 0,- primaryServiceUrl: executionWorkspace.runtimeServices?.find((service) => service.url)?.url ?? null,- hasRuntimeConfig: Boolean(- executionWorkspace.config?.workspaceRuntime- ?? projectWorkspacesById.get(executionWorkspace.projectWorkspaceId ?? issue.projectWorkspaceId ?? "")?.runtimeConfig?.workspaceRuntime,- ),- issues: nextIssues,- });+ if (!existing) {+ summaries.set(`execution:${executionWorkspace.id}`, {+ key: `execution:${executionWorkspace.id}`,+ kind: "execution_workspace",+ workspaceId: executionWorkspace.id,+ workspaceName: executionWorkspace.name,+ cwd: executionWorkspace.cwd ?? null,+ branchName: executionWorkspace.branchName ?? executionWorkspace.baseRef ?? null,+ lastUpdatedAt: maxDate(+ executionWorkspace.lastUsedAt,+ executionWorkspace.updatedAt,+ issue.updatedAt,+ ),+ projectWorkspaceId: executionWorkspace.projectWorkspaceId ?? issue.projectWorkspaceId ?? null,+ executionWorkspaceId: executionWorkspace.id,+ executionWorkspaceStatus: executionWorkspace.status,+ serviceCount: executionWorkspace.runtimeServices?.length ?? 0,+ runningServiceCount: executionWorkspace.runtimeServices?.filter((service) => service.status === "running").length ?? 0,+ primaryServiceUrl: executionWorkspace.runtimeServices?.find((service) => service.url)?.url ?? null,+ hasRuntimeConfig: Boolean(+ executionWorkspace.config?.workspaceRuntime+ ?? projectWorkspacesById.get(executionWorkspace.projectWorkspaceId ?? issue.projectWorkspaceId ?? "")?.runtimeConfig?.workspaceRuntime,+ ),+ issues: nextIssues,+ });+ } else {+ existing.lastUpdatedAt = maxDate(existing.lastUpdatedAt, issue.updatedAt);+ }continue;}@@ -115,27 +117,30 @@ export function buildProjectWorkspaceSummaries(input: {if (!projectWorkspace) continue;const existing = summaries.get(`project:${projectWorkspace.id}`);- const nextIssues = [...(existing?.issues ?? []), issue].sort(- (a, b) => new Date(b.updatedAt).getTime() - new Date(a.updatedAt).getTime(),- );+ const nextIssues = existing?.issues ?? [];+ nextIssues.push(issue);- summaries.set(`project:${projectWorkspace.id}`, {- key: `project:${projectWorkspace.id}`,- kind: "project_workspace",- workspaceId: projectWorkspace.id,- workspaceName: projectWorkspace.name,- cwd: projectWorkspace.cwd ?? null,- branchName: projectWorkspace.repoRef ?? projectWorkspace.defaultRef ?? null,- lastUpdatedAt: maxDate(existing?.lastUpdatedAt, projectWorkspace.updatedAt, issue.updatedAt),- projectWorkspaceId: projectWorkspace.id,- executionWorkspaceId: null,- executionWorkspaceStatus: null,- serviceCount: projectWorkspace.runtimeServices?.length ?? 0,- runningServiceCount: projectWorkspace.runtimeServices?.filter((service) => service.status === "running").length ?? 0,- primaryServiceUrl: projectWorkspace.runtimeServices?.find((service) => service.url)?.url ?? null,- hasRuntimeConfig: Boolean(projectWorkspace.runtimeConfig?.workspaceRuntime),- issues: nextIssues,- });+ if (!existing) {+ summaries.set(`project:${projectWorkspace.id}`, {+ key: `project:${projectWorkspace.id}`,+ kind: "project_workspace",+ workspaceId: projectWorkspace.id,+ workspaceName: projectWorkspace.name,+ cwd: projectWorkspace.cwd ?? null,+ branchName: projectWorkspace.repoRef ?? projectWorkspace.defaultRef ?? null,+ lastUpdatedAt: maxDate(projectWorkspace.updatedAt, issue.updatedAt),+ projectWorkspaceId: projectWorkspace.id,+ executionWorkspaceId: null,+ executionWorkspaceStatus: null,+ serviceCount: projectWorkspace.runtimeServices?.length ?? 0,+ runningServiceCount: projectWorkspace.runtimeServices?.filter((service) => service.status === "running").length ?? 0,+ primaryServiceUrl: projectWorkspace.runtimeServices?.find((service) => service.url)?.url ?? null,+ hasRuntimeConfig: Boolean(projectWorkspace.runtimeConfig?.workspaceRuntime),+ issues: nextIssues,+ });+ } else {+ existing.lastUpdatedAt = maxDate(existing.lastUpdatedAt, issue.updatedAt);+ }}for (const projectWorkspace of input.project.workspaces) {@@ -165,8 +170,17 @@ export function buildProjectWorkspaceSummaries(input: {});}- return [...summaries.values()].sort((a, b) => {+ const result = [...summaries.values()];+ // Sort issues within each summary once (instead of on every insertion)+ const issueTime = (issue: Issue) => new Date(issue.updatedAt).getTime();+ for (const summary of result) {+ if (summary.issues.length > 1) {+ summary.issues.sort((a, b) => issueTime(b) - issueTime(a));+ }+ }+ result.sort((a, b) => {const diff = b.lastUpdatedAt.getTime() - a.lastUpdatedAt.getTime();return diff !== 0 ? diff : a.workspaceName.localeCompare(b.workspaceName);});+ return result;}diff --git a/ui/src/pages/ProjectDetail.tsx b/ui/src/pages/ProjectDetail.tsxindex cc7c26b54d..994759c128 100644--- a/ui/src/pages/ProjectDetail.tsx+++ b/ui/src/pages/ProjectDetail.tsx@@ -31,7 +31,8 @@ import { Button } from "@/components/ui/button";import { Tabs } from "@/components/ui/tabs";import { PluginLauncherOutlet } from "@/plugins/launchers";import { PluginSlotMount, PluginSlotOutlet, usePluginSlots } from "@/plugins/slots";-import { Clock3, Copy, GitBranch, Loader2 } from "lucide-react";+import { Copy, FolderOpen, GitBranch, Loader2, Play, Square } from "lucide-react";+import { IssuesQuicklook } from "../components/IssuesQuicklook";/* ── Top-level tab types ── */@@ -256,152 +257,144 @@ function ProjectWorkspacesContent({const cleanupFailedSummaries = summaries.filter((summary) => summary.executionWorkspaceStatus === "cleanup_failed");const renderSummaryRow = (summary: ReturnType<typeof buildProjectWorkspaceSummaries>[number]) => {- const visibleIssues = summary.issues.slice(0, 3);+ const visibleIssues = summary.issues.slice(0, 5);const hiddenIssueCount = Math.max(summary.issues.length - visibleIssues.length, 0);const workspaceHref =summary.kind === "project_workspace"? projectWorkspaceUrl({ id: projectRef, urlKey: projectRef }, summary.workspaceId): `/execution-workspaces/${summary.workspaceId}`;+ const hasRunningServices = summary.runningServiceCount > 0;++ const truncatePath = (path: string) => {+ const parts = path.split("/").filter(Boolean);+ if (parts.length <= 3) return path;+ return `…/${parts.slice(-2).join("/")}`;+ };return (<divkey={summary.key}className="border-b border-border px-4 py-3 last:border-b-0">- <div className="grid gap-4 md:grid-cols-[minmax(0,18rem)_minmax(0,1fr)_auto] md:items-start">- <div className="min-w-0">- <Link- to={workspaceHref}- className="block truncate text-sm font-medium hover:underline"- >- {summary.workspaceName}- </Link>-- <div className="mt-1 flex flex-wrap items-center gap-3 text-xs text-muted-foreground">- <span className="inline-flex items-center gap-1">- <GitBranch className="h-3.5 w-3.5" />- <span className="font-mono">{summary.branchName ?? "No branch info"}</span>+ {/* Header row: name + actions */}+ <div className="flex items-center gap-3">+ <Link+ to={workspaceHref}+ className="min-w-0 shrink truncate text-sm font-medium hover:underline"+ >+ {summary.workspaceName}+ </Link>++ <div className="flex shrink-0 items-center gap-2 text-xs text-muted-foreground">+ {summary.serviceCount > 0 ? (+ <span className={`inline-flex items-center gap-1 ${hasRunningServices ? "text-emerald-500" : ""}`}>+ <span className={`inline-block h-1.5 w-1.5 rounded-full ${hasRunningServices ? "bg-emerald-500" : "bg-muted-foreground/40"}`} />+ {summary.runningServiceCount}/{summary.serviceCount}</span>- <span className="rounded-full border border-border px-2 py-0.5 text-[11px]">- {summary.runningServiceCount}/{summary.serviceCount} services running- </span>- {summary.executionWorkspaceStatus ? (- <span className="rounded-full border border-border px-2 py-0.5 text-[11px]">- {summary.executionWorkspaceStatus}- </span>- ) : null}- </div>- {summary.primaryServiceUrl ? (- <a- href={summary.primaryServiceUrl}- target="_blank"- rel="noreferrer"- className="mt-2 inline-flex items-center gap-1 text-xs text-muted-foreground hover:underline"- >- {summary.primaryServiceUrl}- </a>) : null}-- {summary.cwd ? (- <div className="mt-2 flex min-w-0 items-start gap-2 text-xs text-muted-foreground">- <span className="min-w-0 truncate font-mono leading-tight" title={summary.cwd}>- {summary.cwd}- </span>- <CopyText text={summary.cwd} className="shrink-0" copiedLabel="Path copied">- <Copy className="h-3.5 w-3.5" />- </CopyText>- </div>+ {summary.executionWorkspaceStatus && summary.executionWorkspaceStatus !== "active" ? (+ <span className="text-[11px] text-muted-foreground">{summary.executionWorkspaceStatus}</span>) : null}</div>- <div className="min-w-0">- <div className="mb-2 text-[11px] font-medium uppercase tracking-[0.18em] text-muted-foreground">- Issues ({summary.issues.length})- </div>- <div className="flex flex-wrap gap-2">- {visibleIssues.map((issue) => (- <Link- key={issue.id}- to={`/issues/${issue.identifier ?? issue.id}`}- className="inline-flex max-w-full items-center gap-2 rounded-md border border-border bg-background px-2.5 py-1.5 text-left text-xs leading-none transition-colors hover:bg-accent"- >- <span className="shrink-0 font-mono text-[11px] text-muted-foreground">- {issue.identifier ?? issue.id.slice(0, 8)}- </span>- <span className="truncate leading-tight">{issue.title}</span>- </Link>- ))}- {hiddenIssueCount > 0 ? (- <span className="inline-flex items-center rounded-md border border-dashed border-border px-2.5 py-1.5 text-xs text-muted-foreground">- ... and {hiddenIssueCount} more- </span>- ) : null}- </div>- </div>-- <div className="flex shrink-0 flex-col items-start gap-2 md:items-end">- <Link- to={workspaceHref}- className="text-xs font-medium text-foreground hover:underline"- >- {summary.kind === "project_workspace" ? "Configure workspace" : "View workspace"}- </Link>- <div className="flex flex-wrap gap-2">- <Button- variant="outline"- size="sm"- disabled={- controlWorkspaceRuntime.isPending- || !summary.hasRuntimeConfig- || runtimeActionKey !== null && runtimeActionKey !== `${summary.key}:start`- }- onClick={() =>- controlWorkspaceRuntime.mutate({- key: summary.key,- kind: summary.kind,- workspaceId: summary.workspaceId,- action: "start",- })- }- >- {runtimeActionKey === `${summary.key}:start` ? <Loader2 className="mr-2 h-3.5 w-3.5 animate-spin" /> : null}- Start- </Button>+ <div className="ml-auto flex shrink-0 items-center gap-2">+ <span className="text-xs text-muted-foreground">{timeAgo(summary.lastUpdatedAt)}</span>+ {summary.hasRuntimeConfig ? (<Button- variant="outline"+ variant="ghost"size="sm"- disabled={controlWorkspaceRuntime.isPending || summary.serviceCount === 0}+ className="h-7 gap-1.5 px-2 text-xs"+ disabled={controlWorkspaceRuntime.isPending}onClick={() =>controlWorkspaceRuntime.mutate({key: summary.key,kind: summary.kind,workspaceId: summary.workspaceId,- action: "stop",+ action: hasRunningServices ? "stop" : "start",})}>- Stop+ {runtimeActionKey === `${summary.key}:start` || runtimeActionKey === `${summary.key}:stop` ? (+ <Loader2 className="h-3 w-3 animate-spin" />+ ) : hasRunningServices ? (+ <Square className="h-3 w-3" />+ ) : (+ <Play className="h-3 w-3" />+ )}+ {hasRunningServices ? "Stop" : "Start"}</Button>- </div>+ ) : null}{summary.kind === "execution_workspace" && summary.executionWorkspaceId && summary.executionWorkspaceStatus ? (<Button- variant="outline"+ variant="ghost"size="sm"+ className="h-7 px-2 text-xs text-muted-foreground"onClick={() => setClosingWorkspace({id: summary.executionWorkspaceId!,name: summary.workspaceName,status: summary.executionWorkspaceStatus!,})}>- {summary.executionWorkspaceStatus === "cleanup_failed" ? "Retry close" : "Close workspace"}+ {summary.executionWorkspaceStatus === "cleanup_failed" ? "Retry close" : "Close"}</Button>) : null}- <div className="inline-flex items-center gap-1 text-xs text-muted-foreground">- <Clock3 className="h-3.5 w-3.5" />- {timeAgo(summary.lastUpdatedAt)}- </div></div></div>++ {/* Metadata lines: branch, folder */}+ <div className="mt-1.5 space-y-0.5 text-xs text-muted-foreground">+ {summary.branchName ? (+ <div className="flex items-center gap-1.5">+ <GitBranch className="h-3 w-3 shrink-0" />+ <span className="font-mono">{summary.branchName}</span>+ </div>+ ) : null}+ {summary.cwd ? (+ <div className="flex items-center gap-1.5">+ <FolderOpen className="h-3 w-3 shrink-0" />+ <span className="truncate font-mono" title={summary.cwd}>+ {truncatePath(summary.cwd)}+ </span>+ <CopyText text={summary.cwd} className="shrink-0" copiedLabel="Path copied">+ <Copy className="h-3 w-3" />+ </CopyText>+ </div>+ ) : null}+ {summary.primaryServiceUrl ? (+ <div className="flex items-center gap-1.5">+ <a+ href={summary.primaryServiceUrl}+ target="_blank"+ rel="noreferrer"+ className="font-mono hover:text-foreground hover:underline"+ >+ {summary.primaryServiceUrl}+ </a>+ </div>+ ) : null}+ </div>++ {/* Issues */}+ {summary.issues.length > 0 ? (+ <div className="mt-2 flex flex-wrap items-center gap-x-2 gap-y-1 text-xs text-muted-foreground">+ <span className="font-medium text-muted-foreground/70">Issues</span>+ {visibleIssues.map((issue) => (+ <IssuesQuicklook key={issue.id} issue={issue}>+ <Link+ to={`/issues/${issue.identifier ?? issue.id}`}+ className="font-mono hover:text-foreground hover:underline"+ >+ {issue.identifier ?? issue.id.slice(0, 8)}+ </Link>+ </IssuesQuicklook>+ ))}+ {hiddenIssueCount > 0 ? (+ <Link to={workspaceHref} className="hover:text-foreground hover:underline">+ +{hiddenIssueCount} more+ </Link>+ ) : null}+ </div>+ ) : null}</div>);};@@ -488,6 +481,7 @@ export function ProjectDetail() {const experimentalSettingsQuery = useQuery({queryKey: queryKeys.instance.experimentalSettings,queryFn: () => instanceSettingsApi.getExperimental(),+ retry: false,});const {slots: pluginDetailSlots,diff --git a/ui/src/pages/RoutineDetail.tsx b/ui/src/pages/RoutineDetail.tsxindex 387e31f738..55dc32f4b2 100644--- a/ui/src/pages/RoutineDetail.tsx+++ b/ui/src/pages/RoutineDetail.tsx@@ -17,6 +17,7 @@ import {} from "lucide-react";import { routinesApi, type RoutineTriggerResponse, type RotateRoutineTriggerResponse } from "../api/routines";import { heartbeatsApi } from "../api/heartbeats";+import { instanceSettingsApi } from "../api/instanceSettings";import { LiveRunWidget } from "../components/LiveRunWidget";import { agentsApi } from "../api/agents";import { projectsApi } from "../api/projects";@@ -31,6 +32,12 @@ import { PageSkeleton } from "../components/PageSkeleton";import { AgentIcon } from "../components/AgentIconPicker";import { InlineEntitySelector, type InlineEntityOption } from "../components/InlineEntitySelector";import { MarkdownEditor, type MarkdownEditorRef } from "../components/MarkdownEditor";+import {+ RoutineRunVariablesDialog,+ routineRunNeedsConfiguration,+ type RoutineRunDialogSubmitData,+} from "../components/RoutineRunVariablesDialog";+import { RoutineVariablesEditor, RoutineVariablesHint } from "../components/RoutineVariablesEditor";import { ScheduleEditor, describeSchedule } from "../components/ScheduleEditor";import { RunButton } from "../components/AgentActionButtons";import { getRecentAssigneeIds, sortAgentsByRecency, trackRecentAssignee } from "../lib/recent-assignees";@@ -48,7 +55,7 @@ import {} from "@/components/ui/select";import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";import { Badge } from "@/components/ui/badge";-import type { RoutineTrigger } from "@paperclipai/shared";+import type { RoutineTrigger, RoutineVariable } from "@paperclipai/shared";const concurrencyPolicies = ["coalesce_if_active", "always_enqueue", "skip_if_active"];const catchUpPolicies = ["skip_missed", "enqueue_missed_with_cap"];@@ -216,7 +223,7 @@ function TriggerEditor({onClick={() => onSave(trigger.id, buildRoutineTriggerPatch(trigger, draft, getLocalTimezone()))}><Save className="mr-1.5 h-3.5 w-3.5" />- Save+ Save trigger</Button><Buttonvariant="ghost"@@ -247,13 +254,23 @@ export function RoutineDetail() {const projectSelectorRef = useRef<HTMLButtonElement | null>(null);const [secretMessage, setSecretMessage] = useState<SecretMessage | null>(null);const [advancedOpen, setAdvancedOpen] = useState(false);+ const [runVariablesOpen, setRunVariablesOpen] = useState(false);const [newTrigger, setNewTrigger] = useState({kind: "schedule",cronExpression: "0 10 * * *",signingMode: "bearer",replayWindowSec: "300",});- const [editDraft, setEditDraft] = useState({+ const [editDraft, setEditDraft] = useState<{+ title: string;+ description: string;+ projectId: string;+ assigneeAgentId: string;+ priority: string;+ concurrencyPolicy: string;+ catchUpPolicy: string;+ variables: RoutineVariable[];+ }>({title: "",description: "",projectId: "",@@ -261,6 +278,7 @@ export function RoutineDetail() {priority: "medium",concurrencyPolicy: "coalesce_if_active",catchUpPolicy: "skip_missed",+ variables: [],});const activeTab = useMemo(() => getRoutineTabFromSearch(location.search), [location.search]);@@ -309,6 +327,11 @@ export function RoutineDetail() {queryFn: () => projectsApi.list(selectedCompanyId!),enabled: !!selectedCompanyId,});+ const { data: experimentalSettings } = useQuery({+ queryKey: queryKeys.instance.experimentalSettings,+ queryFn: () => instanceSettingsApi.getExperimental(),+ retry: false,+ });const routineDefaults = useMemo(() =>@@ -321,6 +344,7 @@ export function RoutineDetail() {priority: routine.priority,concurrencyPolicy: routine.concurrencyPolicy,catchUpPolicy: routine.catchUpPolicy,+ variables: routine.variables,}: null,[routine],@@ -334,7 +358,8 @@ export function RoutineDetail() {editDraft.assigneeAgentId !== routineDefaults.assigneeAgentId ||editDraft.priority !== routineDefaults.priority ||editDraft.concurrencyPolicy !== routineDefaults.concurrencyPolicy ||- editDraft.catchUpPolicy !== routineDefaults.catchUpPolicy+ editDraft.catchUpPolicy !== routineDefaults.catchUpPolicy ||+ JSON.stringify(editDraft.variables) !== JSON.stringify(routineDefaults.variables));}, [editDraft, routineDefaults]);@@ -409,9 +434,20 @@ export function RoutineDetail() {});const runRoutine = useMutation({- mutationFn: () => routinesApi.run(routineId!),+ mutationFn: (data?: RoutineRunDialogSubmitData) =>+ routinesApi.run(routineId!, {+ ...(data?.variables && Object.keys(data.variables).length > 0 ? { variables: data.variables } : {}),+ ...(data?.executionWorkspaceId !== undefined ? { executionWorkspaceId: data.executionWorkspaceId } : {}),+ ...(data?.executionWorkspacePreference !== undefined+ ? { executionWorkspacePreference: data.executionWorkspacePreference }+ : {}),+ ...(data?.executionWorkspaceSettings !== undefined+ ? { executionWorkspaceSettings: data.executionWorkspaceSettings }+ : {}),+ }),onSuccess: async () => {pushToast({ title: "Routine run started", tone: "success" });+ setRunVariablesOpen(false);setActiveTab("runs");await Promise.all([queryClient.invalidateQueries({ queryKey: queryKeys.routines.detail(routineId!) }),@@ -476,6 +512,12 @@ export function RoutineDetail() {webhookUrl: result.secretMaterial.webhookUrl,webhookSecret: result.secretMaterial.webhookSecret,});+ } else {+ pushToast({+ title: "Trigger added",+ body: "The routine schedule was saved.",+ tone: "success",+ });}await Promise.all([queryClient.invalidateQueries({ queryKey: queryKeys.routines.detail(routineId!) }),@@ -495,6 +537,11 @@ export function RoutineDetail() {const updateTrigger = useMutation({mutationFn: ({ id, patch }: { id: string; patch: Record<string, unknown> }) => routinesApi.updateTrigger(id, patch),onSuccess: async () => {+ pushToast({+ title: "Trigger saved",+ body: "The routine cadence update was saved.",+ tone: "success",+ });await Promise.all([queryClient.invalidateQueries({ queryKey: queryKeys.routines.detail(routineId!) }),queryClient.invalidateQueries({ queryKey: queryKeys.routines.list(selectedCompanyId!) }),@@ -513,6 +560,10 @@ export function RoutineDetail() {const deleteTrigger = useMutation({mutationFn: (id: string) => routinesApi.deleteTrigger(id),onSuccess: async () => {+ pushToast({+ title: "Trigger deleted",+ tone: "success",+ });await Promise.all([queryClient.invalidateQueries({ queryKey: queryKeys.routines.detail(routineId!) }),queryClient.invalidateQueries({ queryKey: queryKeys.routines.list(selectedCompanyId!) }),@@ -600,6 +651,12 @@ export function RoutineDetail() {}const automationEnabled = routine.status === "active";+ const selectedProject = projects?.find((project) => project.id === routine.projectId) ?? null;+ const needsRunConfiguration = routineRunNeedsConfiguration({+ variables: routine.variables ?? [],+ project: selectedProject,+ isolatedWorkspacesEnabled: experimentalSettings?.enableIsolatedWorkspaces === true,+ });const automationToggleDisabled = updateRoutineStatus.isPending || routine.status === "archived";const automationLabel = routine.status === "archived" ? "Archived" : automationEnabled ? "Active" : "Paused";const automationLabelClassName = routine.status === "archived"@@ -643,7 +700,16 @@ export function RoutineDetail() {}}/><div className="flex shrink-0 items-center gap-3 pt-1">- <RunButton onClick={() => runRoutine.mutate()} disabled={runRoutine.isPending} />+ <RunButton+ onClick={() => {+ if (needsRunConfiguration) {+ setRunVariablesOpen(true);+ return;+ }+ runRoutine.mutate({});+ }}+ disabled={runRoutine.isPending}+ /><buttontype="button"role="switch"@@ -797,6 +863,12 @@ export function RoutineDetail() {}}}/>+ <RoutineVariablesHint />+ <RoutineVariablesEditor+ description={editDraft.description}+ value={editDraft.variables}+ onChange={(variables) => setEditDraft((current) => ({ ...current, variables }))}+ />{/* Advanced delivery settings */}<Collapsible open={advancedOpen} onOpenChange={setAdvancedOpen}>@@ -1016,6 +1088,16 @@ export function RoutineDetail() {)}</TabsContent></Tabs>++ <RoutineRunVariablesDialog+ open={runVariablesOpen}+ onOpenChange={setRunVariablesOpen}+ companyId={routine.companyId}+ project={selectedProject}+ variables={routine.variables ?? []}+ isPending={runRoutine.isPending}+ onSubmit={(data) => runRoutine.mutate(data)}+ /></div>);}diff --git a/ui/src/pages/Routines.tsx b/ui/src/pages/Routines.tsxindex 5d8adf911a..fc856d7254 100644--- a/ui/src/pages/Routines.tsx+++ b/ui/src/pages/Routines.tsx@@ -3,6 +3,7 @@ import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";import { useNavigate } from "@/lib/router";import { ChevronDown, ChevronRight, MoreHorizontal, Play, Plus, Repeat } from "lucide-react";import { routinesApi } from "../api/routines";+import { instanceSettingsApi } from "../api/instanceSettings";import { agentsApi } from "../api/agents";import { projectsApi } from "../api/projects";import { useCompany } from "../context/CompanyContext";@@ -15,6 +16,12 @@ import { PageSkeleton } from "../components/PageSkeleton";import { AgentIcon } from "../components/AgentIconPicker";import { InlineEntitySelector, type InlineEntityOption } from "../components/InlineEntitySelector";import { MarkdownEditor, type MarkdownEditorRef } from "../components/MarkdownEditor";+import {+ RoutineRunVariablesDialog,+ routineRunNeedsConfiguration,+ type RoutineRunDialogSubmitData,+} from "../components/RoutineRunVariablesDialog";+import { RoutineVariablesEditor, RoutineVariablesHint } from "../components/RoutineVariablesEditor";import { Button } from "@/components/ui/button";import { Card, CardContent } from "@/components/ui/card";import { Collapsible, CollapsibleContent, CollapsibleTrigger } from "@/components/ui/collapsible";@@ -33,6 +40,7 @@ import {SelectTrigger,SelectValue,} from "@/components/ui/select";+import type { RoutineListItem, RoutineVariable } from "@paperclipai/shared";const concurrencyPolicies = ["coalesce_if_active", "always_enqueue", "skip_if_active"];const catchUpPolicies = ["skip_missed", "enqueue_missed_with_cap"];@@ -74,9 +82,19 @@ export function Routines() {const projectSelectorRef = useRef<HTMLButtonElement | null>(null);const [runningRoutineId, setRunningRoutineId] = useState<string | null>(null);const [statusMutationRoutineId, setStatusMutationRoutineId] = useState<string | null>(null);+ const [runDialogRoutine, setRunDialogRoutine] = useState<RoutineListItem | null>(null);const [composerOpen, setComposerOpen] = useState(false);const [advancedOpen, setAdvancedOpen] = useState(false);- const [draft, setDraft] = useState({+ const [draft, setDraft] = useState<{+ title: string;+ description: string;+ projectId: string;+ assigneeAgentId: string;+ priority: string;+ concurrencyPolicy: string;+ catchUpPolicy: string;+ variables: RoutineVariable[];+ }>({title: "",description: "",projectId: "",@@ -84,6 +102,7 @@ export function Routines() {priority: "medium",concurrencyPolicy: "coalesce_if_active",catchUpPolicy: "skip_missed",+ variables: [],});useEffect(() => {@@ -105,6 +124,11 @@ export function Routines() {queryFn: () => projectsApi.list(selectedCompanyId!),enabled: !!selectedCompanyId,});+ const { data: experimentalSettings } = useQuery({+ queryKey: queryKeys.instance.experimentalSettings,+ queryFn: () => instanceSettingsApi.getExperimental(),+ retry: false,+ });useEffect(() => {autoResizeTextarea(titleInputRef.current);@@ -125,6 +149,7 @@ export function Routines() {priority: "medium",concurrencyPolicy: "coalesce_if_active",catchUpPolicy: "skip_missed",+ variables: [],});setComposerOpen(false);setAdvancedOpen(false);@@ -162,11 +187,21 @@ export function Routines() {});const runRoutine = useMutation({- mutationFn: (id: string) => routinesApi.run(id),- onMutate: (id) => {+ mutationFn: ({ id, data }: { id: string; data?: RoutineRunDialogSubmitData }) => routinesApi.run(id, {+ ...(data?.variables && Object.keys(data.variables).length > 0 ? { variables: data.variables } : {}),+ ...(data?.executionWorkspaceId !== undefined ? { executionWorkspaceId: data.executionWorkspaceId } : {}),+ ...(data?.executionWorkspacePreference !== undefined+ ? { executionWorkspacePreference: data.executionWorkspacePreference }+ : {}),+ ...(data?.executionWorkspaceSettings !== undefined+ ? { executionWorkspaceSettings: data.executionWorkspaceSettings }+ : {}),+ }),+ onMutate: ({ id }) => {setRunningRoutineId(id);},- onSuccess: async (_, id) => {+ onSuccess: async (_, { id }) => {+ setRunDialogRoutine(null);await Promise.all([queryClient.invalidateQueries({ queryKey: queryKeys.routines.list(selectedCompanyId!) }),queryClient.invalidateQueries({ queryKey: queryKeys.routines.detail(id) }),@@ -214,9 +249,24 @@ export function Routines() {() => new Map((projects ?? []).map((project) => [project.id, project])),[projects],);+ const runDialogProject = runDialogRoutine?.projectId ? projectById.get(runDialogRoutine.projectId) ?? null : null;const currentAssignee = draft.assigneeAgentId ? agentById.get(draft.assigneeAgentId) ?? null : null;const currentProject = draft.projectId ? projectById.get(draft.projectId) ?? null : null;+ function handleRunNow(routine: RoutineListItem) {+ const project = routine.projectId ? projectById.get(routine.projectId) ?? null : null;+ const needsConfiguration = routineRunNeedsConfiguration({+ variables: routine.variables ?? [],+ project,+ isolatedWorkspacesEnabled: experimentalSettings?.enableIsolatedWorkspaces === true,+ });+ if (needsConfiguration) {+ setRunDialogRoutine(routine);+ return;+ }+ runRoutine.mutate({ id: routine.id, data: {} });+ }+if (!selectedCompanyId) {return <EmptyState icon={Repeat} message="Select a company to view routines." />;}@@ -414,6 +464,14 @@ export function Routines() {}}}/>+ <div className="mt-3 space-y-3">+ <RoutineVariablesHint />+ <RoutineVariablesEditor+ description={draft.description}+ value={draft.variables}+ onChange={(variables) => setDraft((current) => ({ ...current, variables }))}+ />+ </div></div><div className="border-t border-border/60 px-5 py-3">@@ -623,7 +681,7 @@ export function Routines() {</DropdownMenuItem><DropdownMenuItemdisabled={runningRoutineId === routine.id || isArchived}- onClick={() => runRoutine.mutate(routine.id)}+ onClick={() => handleRunNow(routine)}>{runningRoutineId === routine.id ? "Running..." : "Run now"}</DropdownMenuItem>@@ -661,6 +719,21 @@ export function Routines() {</div>)}</div>++ <RoutineRunVariablesDialog+ open={runDialogRoutine !== null}+ onOpenChange={(next) => {+ if (!next) setRunDialogRoutine(null);+ }}+ companyId={selectedCompanyId}+ project={runDialogProject}+ variables={runDialogRoutine?.variables ?? []}+ isPending={runRoutine.isPending}+ onSubmit={(data) => {+ if (!runDialogRoutine) return;+ runRoutine.mutate({ id: runDialogRoutine.id, data });+ }}+ /></div>);}