diff --git a/foundry/packages/backend/src/actors/repository/db/migrations.ts b/foundry/packages/backend/src/actors/repository/db/migrations.ts index 2bd8fa0..f0a2543 100644 --- a/foundry/packages/backend/src/actors/repository/db/migrations.ts +++ b/foundry/packages/backend/src/actors/repository/db/migrations.ts @@ -32,7 +32,6 @@ CREATE TABLE \`task_index\` ( --> statement-breakpoint CREATE TABLE \`tasks\` ( \`task_id\` text PRIMARY KEY NOT NULL, - \`repo_id\` text NOT NULL, \`title\` text NOT NULL, \`status\` text NOT NULL, \`repo_name\` text NOT NULL, diff --git a/foundry/packages/backend/src/actors/repository/db/schema.ts b/foundry/packages/backend/src/actors/repository/db/schema.ts index 5c6c7ee..4a07332 100644 --- a/foundry/packages/backend/src/actors/repository/db/schema.ts +++ b/foundry/packages/backend/src/actors/repository/db/schema.ts @@ -41,19 +41,3 @@ export const tasks = sqliteTable("tasks", { pullRequestJson: text("pull_request_json"), sessionsSummaryJson: text("sessions_summary_json").notNull().default("[]"), }); - -/** - * Materialized task summary projection owned by the repository coordinator. - * Task actors push updates here; organization reads fan in through repositories. - */ -export const tasks = sqliteTable("tasks", { - taskId: text("task_id").notNull().primaryKey(), - repoId: text("repo_id").notNull(), - title: text("title").notNull(), - status: text("status").notNull(), - repoName: text("repo_name").notNull(), - updatedAtMs: integer("updated_at_ms").notNull(), - branch: text("branch"), - pullRequestJson: text("pull_request_json"), - sessionsSummaryJson: text("sessions_summary_json").notNull().default("[]"), -}); diff --git a/foundry/packages/backend/src/actors/task/index.ts b/foundry/packages/backend/src/actors/task/index.ts index e961e90..64d3d80 100644 --- a/foundry/packages/backend/src/actors/task/index.ts +++ b/foundry/packages/backend/src/actors/task/index.ts @@ -57,6 +57,7 @@ interface TaskActionCommand { interface TaskSessionCommand { sessionId: string; + authSessionId?: string; } interface TaskStatusSyncCommand { diff --git a/foundry/packages/backend/src/actors/task/workflow/index.ts b/foundry/packages/backend/src/actors/task/workflow/index.ts index 2c7c02e..663f800 100644 --- a/foundry/packages/backend/src/actors/task/workflow/index.ts +++ b/foundry/packages/backend/src/actors/task/workflow/index.ts @@ -113,7 +113,7 @@ const commandHandlers: Record = { }, "task.command.workspace.mark_unread": async (loopCtx, msg) => { - await loopCtx.step("workspace-mark-unread", async () => markWorkspaceUnread(loopCtx)); + await loopCtx.step("workspace-mark-unread", async () => markWorkspaceUnread(loopCtx, msg.body?.authSessionId)); await msg.complete({ ok: true }); }, @@ -127,7 +127,7 @@ const commandHandlers: Record = { const created = await loopCtx.step({ name: "workspace-create-session", timeout: 5 * 60_000, - run: async () => createWorkspaceSession(loopCtx, msg.body?.model), + run: async () => createWorkspaceSession(loopCtx, msg.body?.model, msg.body?.authSessionId), }); await msg.complete(created); } catch (error) { @@ -140,12 +140,12 @@ const commandHandlers: Record = { const created = await loopCtx.step({ name: "workspace-create-session-for-send", timeout: 5 * 60_000, - run: async () => createWorkspaceSession(loopCtx, msg.body?.model), + run: async () => createWorkspaceSession(loopCtx, msg.body?.model, msg.body?.authSessionId), }); await loopCtx.step({ name: "workspace-send-initial-message", timeout: 5 * 60_000, - run: async () => sendWorkspaceMessage(loopCtx, created.sessionId, msg.body.text, []), + run: async () => sendWorkspaceMessage(loopCtx, created.sessionId, msg.body.text, [], msg.body?.authSessionId), }); } catch (error) { logActorWarning("task.workflow", "create_session_and_send failed", { @@ -159,7 +159,7 @@ const commandHandlers: Record = { await loopCtx.step({ name: "workspace-ensure-session", timeout: 5 * 60_000, - run: async () => ensureWorkspaceSession(loopCtx, msg.body.sessionId, msg.body?.model), + run: async () => ensureWorkspaceSession(loopCtx, msg.body.sessionId, msg.body?.model, msg.body?.authSessionId), }); await msg.complete({ ok: true }); }, @@ -170,12 +170,16 @@ const commandHandlers: Record = { }, "task.command.workspace.set_session_unread": async (loopCtx, msg) => { - await loopCtx.step("workspace-set-session-unread", async () => setWorkspaceSessionUnread(loopCtx, msg.body.sessionId, msg.body.unread)); + await loopCtx.step("workspace-set-session-unread", async () => + setWorkspaceSessionUnread(loopCtx, msg.body.sessionId, msg.body.unread, msg.body?.authSessionId), + ); await msg.complete({ ok: true }); }, "task.command.workspace.update_draft": async (loopCtx, msg) => { - await loopCtx.step("workspace-update-draft", async () => updateWorkspaceDraft(loopCtx, msg.body.sessionId, msg.body.text, msg.body.attachments)); + await loopCtx.step("workspace-update-draft", async () => + updateWorkspaceDraft(loopCtx, msg.body.sessionId, msg.body.text, msg.body.attachments, msg.body?.authSessionId), + ); await msg.complete({ ok: true }); }, @@ -189,7 +193,7 @@ const commandHandlers: Record = { await loopCtx.step({ name: "workspace-send-message", timeout: 10 * 60_000, - run: async () => sendWorkspaceMessage(loopCtx, msg.body.sessionId, msg.body.text, msg.body.attachments), + run: async () => sendWorkspaceMessage(loopCtx, msg.body.sessionId, msg.body.text, msg.body.attachments, msg.body?.authSessionId), }); await msg.complete({ ok: true }); } catch (error) { @@ -233,7 +237,7 @@ const commandHandlers: Record = { await loopCtx.step({ name: "workspace-close-session", timeout: 5 * 60_000, - run: async () => closeWorkspaceSession(loopCtx, msg.body.sessionId), + run: async () => closeWorkspaceSession(loopCtx, msg.body.sessionId, msg.body?.authSessionId), }); await msg.complete({ ok: true }); }, diff --git a/foundry/packages/backend/src/actors/task/workspace.ts b/foundry/packages/backend/src/actors/task/workspace.ts index 15f4483..81e6a97 100644 --- a/foundry/packages/backend/src/actors/task/workspace.ts +++ b/foundry/packages/backend/src/actors/task/workspace.ts @@ -1328,14 +1328,6 @@ export async function publishWorkspacePr(c: any): Promise { githubToken: auth?.githubToken ?? null, baseBranch: metadata.defaultBranch ?? undefined, }); - await c.db - .update(taskTable) - .set({ - prSubmitted: 1, - updatedAt: Date.now(), - }) - .where(eq(taskTable.id, 1)) - .run(); await broadcastTaskUpdate(c); } diff --git a/foundry/packages/shared/src/workspace.ts b/foundry/packages/shared/src/workspace.ts index 751ee0b..aa9aa99 100644 --- a/foundry/packages/shared/src/workspace.ts +++ b/foundry/packages/shared/src/workspace.ts @@ -104,15 +104,16 @@ export interface WorkspaceParsedDiffLine { export interface WorkspacePullRequestSummary { number: number; - title: string; - state: string; - url: string; - headRefName: string; - baseRefName: string; - repoFullName: string; - authorLogin: string | null; - isDraft: boolean; - updatedAtMs: number; + status: "draft" | "ready"; + title?: string; + state?: string; + url?: string; + headRefName?: string; + baseRefName?: string; + repoFullName?: string; + authorLogin?: string | null; + isDraft?: boolean; + updatedAtMs?: number; } export interface WorkspaceSandboxSummary { @@ -241,6 +242,7 @@ export interface TaskWorkspaceRenameInput { repoId: string; taskId: string; value: string; + authSessionId?: string; } export interface TaskWorkspaceSendMessageInput {