Implement execution workspaces and work products

This commit is contained in:
Dotta
2026-03-13 17:12:25 -05:00
parent 9da5358bb3
commit 920bc4c70f
45 changed files with 9157 additions and 140 deletions

View File

@@ -0,0 +1,68 @@
import {
type AnyPgColumn,
index,
jsonb,
pgTable,
text,
timestamp,
uuid,
} from "drizzle-orm/pg-core";
import { companies } from "./companies.js";
import { issues } from "./issues.js";
import { projectWorkspaces } from "./project_workspaces.js";
import { projects } from "./projects.js";
export const executionWorkspaces = pgTable(
"execution_workspaces",
{
id: uuid("id").primaryKey().defaultRandom(),
companyId: uuid("company_id").notNull().references(() => companies.id),
projectId: uuid("project_id").notNull().references(() => projects.id, { onDelete: "cascade" }),
projectWorkspaceId: uuid("project_workspace_id").references(() => projectWorkspaces.id, { onDelete: "set null" }),
sourceIssueId: uuid("source_issue_id").references((): AnyPgColumn => issues.id, { onDelete: "set null" }),
mode: text("mode").notNull(),
strategyType: text("strategy_type").notNull(),
name: text("name").notNull(),
status: text("status").notNull().default("active"),
cwd: text("cwd"),
repoUrl: text("repo_url"),
baseRef: text("base_ref"),
branchName: text("branch_name"),
providerType: text("provider_type").notNull().default("local_fs"),
providerRef: text("provider_ref"),
derivedFromExecutionWorkspaceId: uuid("derived_from_execution_workspace_id")
.references((): AnyPgColumn => executionWorkspaces.id, { onDelete: "set null" }),
lastUsedAt: timestamp("last_used_at", { withTimezone: true }).notNull().defaultNow(),
openedAt: timestamp("opened_at", { withTimezone: true }).notNull().defaultNow(),
closedAt: timestamp("closed_at", { withTimezone: true }),
cleanupEligibleAt: timestamp("cleanup_eligible_at", { withTimezone: true }),
cleanupReason: text("cleanup_reason"),
metadata: jsonb("metadata").$type<Record<string, unknown>>(),
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
},
(table) => ({
companyProjectStatusIdx: index("execution_workspaces_company_project_status_idx").on(
table.companyId,
table.projectId,
table.status,
),
companyProjectWorkspaceStatusIdx: index("execution_workspaces_company_project_workspace_status_idx").on(
table.companyId,
table.projectWorkspaceId,
table.status,
),
companySourceIssueIdx: index("execution_workspaces_company_source_issue_idx").on(
table.companyId,
table.sourceIssueId,
),
companyLastUsedIdx: index("execution_workspaces_company_last_used_idx").on(
table.companyId,
table.lastUsedAt,
),
companyBranchIdx: index("execution_workspaces_company_branch_idx").on(
table.companyId,
table.branchName,
),
}),
);

View File

@@ -13,10 +13,12 @@ export { agentTaskSessions } from "./agent_task_sessions.js";
export { agentWakeupRequests } from "./agent_wakeup_requests.js";
export { projects } from "./projects.js";
export { projectWorkspaces } from "./project_workspaces.js";
export { executionWorkspaces } from "./execution_workspaces.js";
export { workspaceRuntimeServices } from "./workspace_runtime_services.js";
export { projectGoals } from "./project_goals.js";
export { goals } from "./goals.js";
export { issues } from "./issues.js";
export { issueWorkProducts } from "./issue_work_products.js";
export { labels } from "./labels.js";
export { issueLabels } from "./issue_labels.js";
export { issueApprovals } from "./issue_approvals.js";

View File

@@ -0,0 +1,64 @@
import {
boolean,
index,
jsonb,
pgTable,
text,
timestamp,
uuid,
} from "drizzle-orm/pg-core";
import { companies } from "./companies.js";
import { executionWorkspaces } from "./execution_workspaces.js";
import { heartbeatRuns } from "./heartbeat_runs.js";
import { issues } from "./issues.js";
import { projects } from "./projects.js";
import { workspaceRuntimeServices } from "./workspace_runtime_services.js";
export const issueWorkProducts = pgTable(
"issue_work_products",
{
id: uuid("id").primaryKey().defaultRandom(),
companyId: uuid("company_id").notNull().references(() => companies.id),
projectId: uuid("project_id").references(() => projects.id, { onDelete: "set null" }),
issueId: uuid("issue_id").notNull().references(() => issues.id, { onDelete: "cascade" }),
executionWorkspaceId: uuid("execution_workspace_id")
.references(() => executionWorkspaces.id, { onDelete: "set null" }),
runtimeServiceId: uuid("runtime_service_id")
.references(() => workspaceRuntimeServices.id, { onDelete: "set null" }),
type: text("type").notNull(),
provider: text("provider").notNull(),
externalId: text("external_id"),
title: text("title").notNull(),
url: text("url"),
status: text("status").notNull(),
reviewState: text("review_state").notNull().default("none"),
isPrimary: boolean("is_primary").notNull().default(false),
healthStatus: text("health_status").notNull().default("unknown"),
summary: text("summary"),
metadata: jsonb("metadata").$type<Record<string, unknown>>(),
createdByRunId: uuid("created_by_run_id").references(() => heartbeatRuns.id, { onDelete: "set null" }),
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
},
(table) => ({
companyIssueTypeIdx: index("issue_work_products_company_issue_type_idx").on(
table.companyId,
table.issueId,
table.type,
),
companyExecutionWorkspaceTypeIdx: index("issue_work_products_company_execution_workspace_type_idx").on(
table.companyId,
table.executionWorkspaceId,
table.type,
),
companyProviderExternalIdIdx: index("issue_work_products_company_provider_external_id_idx").on(
table.companyId,
table.provider,
table.externalId,
),
companyUpdatedIdx: index("issue_work_products_company_updated_idx").on(
table.companyId,
table.updatedAt,
),
}),
);

View File

@@ -14,6 +14,8 @@ import { projects } from "./projects.js";
import { goals } from "./goals.js";
import { companies } from "./companies.js";
import { heartbeatRuns } from "./heartbeat_runs.js";
import { projectWorkspaces } from "./project_workspaces.js";
import { executionWorkspaces } from "./execution_workspaces.js";
export const issues = pgTable(
"issues",
@@ -21,6 +23,7 @@ export const issues = pgTable(
id: uuid("id").primaryKey().defaultRandom(),
companyId: uuid("company_id").notNull().references(() => companies.id),
projectId: uuid("project_id").references(() => projects.id),
projectWorkspaceId: uuid("project_workspace_id").references(() => projectWorkspaces.id, { onDelete: "set null" }),
goalId: uuid("goal_id").references(() => goals.id),
parentId: uuid("parent_id").references((): AnyPgColumn => issues.id),
title: text("title").notNull(),
@@ -40,6 +43,9 @@ export const issues = pgTable(
requestDepth: integer("request_depth").notNull().default(0),
billingCode: text("billing_code"),
assigneeAdapterOverrides: jsonb("assignee_adapter_overrides").$type<Record<string, unknown>>(),
executionWorkspaceId: uuid("execution_workspace_id")
.references((): AnyPgColumn => executionWorkspaces.id, { onDelete: "set null" }),
executionWorkspacePreference: text("execution_workspace_preference"),
executionWorkspaceSettings: jsonb("execution_workspace_settings").$type<Record<string, unknown>>(),
startedAt: timestamp("started_at", { withTimezone: true }),
completedAt: timestamp("completed_at", { withTimezone: true }),
@@ -62,6 +68,8 @@ export const issues = pgTable(
),
parentIdx: index("issues_company_parent_idx").on(table.companyId, table.parentId),
projectIdx: index("issues_company_project_idx").on(table.companyId, table.projectId),
projectWorkspaceIdx: index("issues_company_project_workspace_idx").on(table.companyId, table.projectWorkspaceId),
executionWorkspaceIdx: index("issues_company_execution_workspace_idx").on(table.companyId, table.executionWorkspaceId),
identifierIdx: uniqueIndex("issues_identifier_idx").on(table.identifier),
}),
);

View File

@@ -5,6 +5,7 @@ import {
pgTable,
text,
timestamp,
uniqueIndex,
uuid,
} from "drizzle-orm/pg-core";
import { companies } from "./companies.js";
@@ -17,9 +18,17 @@ export const projectWorkspaces = pgTable(
companyId: uuid("company_id").notNull().references(() => companies.id),
projectId: uuid("project_id").notNull().references(() => projects.id, { onDelete: "cascade" }),
name: text("name").notNull(),
sourceType: text("source_type").notNull().default("local_path"),
cwd: text("cwd"),
repoUrl: text("repo_url"),
repoRef: text("repo_ref"),
defaultRef: text("default_ref"),
visibility: text("visibility").notNull().default("default"),
setupCommand: text("setup_command"),
cleanupCommand: text("cleanup_command"),
remoteProvider: text("remote_provider"),
remoteWorkspaceRef: text("remote_workspace_ref"),
sharedWorkspaceKey: text("shared_workspace_key"),
metadata: jsonb("metadata").$type<Record<string, unknown>>(),
isPrimary: boolean("is_primary").notNull().default(false),
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
@@ -28,5 +37,9 @@ export const projectWorkspaces = pgTable(
(table) => ({
companyProjectIdx: index("project_workspaces_company_project_idx").on(table.companyId, table.projectId),
projectPrimaryIdx: index("project_workspaces_project_primary_idx").on(table.projectId, table.isPrimary),
projectSourceTypeIdx: index("project_workspaces_project_source_type_idx").on(table.projectId, table.sourceType),
companySharedKeyIdx: index("project_workspaces_company_shared_key_idx").on(table.companyId, table.sharedWorkspaceKey),
projectRemoteRefIdx: uniqueIndex("project_workspaces_project_remote_ref_idx")
.on(table.projectId, table.remoteProvider, table.remoteWorkspaceRef),
}),
);

View File

@@ -10,6 +10,7 @@ import {
import { companies } from "./companies.js";
import { projects } from "./projects.js";
import { projectWorkspaces } from "./project_workspaces.js";
import { executionWorkspaces } from "./execution_workspaces.js";
import { issues } from "./issues.js";
import { agents } from "./agents.js";
import { heartbeatRuns } from "./heartbeat_runs.js";
@@ -21,6 +22,7 @@ export const workspaceRuntimeServices = pgTable(
companyId: uuid("company_id").notNull().references(() => companies.id),
projectId: uuid("project_id").references(() => projects.id, { onDelete: "set null" }),
projectWorkspaceId: uuid("project_workspace_id").references(() => projectWorkspaces.id, { onDelete: "set null" }),
executionWorkspaceId: uuid("execution_workspace_id").references(() => executionWorkspaces.id, { onDelete: "set null" }),
issueId: uuid("issue_id").references(() => issues.id, { onDelete: "set null" }),
scopeType: text("scope_type").notNull(),
scopeId: text("scope_id"),
@@ -50,6 +52,11 @@ export const workspaceRuntimeServices = pgTable(
table.projectWorkspaceId,
table.status,
),
companyExecutionWorkspaceStatusIdx: index("workspace_runtime_services_company_execution_workspace_status_idx").on(
table.companyId,
table.executionWorkspaceId,
table.status,
),
companyProjectStatusIdx: index("workspace_runtime_services_company_project_status_idx").on(
table.companyId,
table.projectId,