From dfaa51076b4751172dfd0dc0a81b3e2e89493eaa Mon Sep 17 00:00:00 2001 From: Lukas May Date: Fri, 30 Jan 2026 19:58:35 +0100 Subject: [PATCH] feat(04-01): add agents table to database schema - Define agents table with id, name (unique), taskId, sessionId, worktreeId, status - Status enum: idle, running, waiting_for_input, stopped, crashed - Foreign key to tasks with onDelete: 'set null' (agent may outlive task) - Add agentsRelations linking to tasks - Export Agent and NewAgent types --- src/db/schema.ts | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/db/schema.ts b/src/db/schema.ts index 5b24960..c0b13d9 100644 --- a/src/db/schema.ts +++ b/src/db/schema.ts @@ -168,3 +168,32 @@ export const taskDependenciesRelations = relations(taskDependencies, ({ one }) = export type TaskDependency = InferSelectModel; export type NewTaskDependency = InferInsertModel; + +// ============================================================================ +// AGENTS +// ============================================================================ + +export const agents = sqliteTable('agents', { + id: text('id').primaryKey(), + name: text('name').notNull().unique(), // Human-readable name (e.g., 'gastown', 'chinatown') + taskId: text('task_id').references(() => tasks.id, { onDelete: 'set null' }), // Task may be deleted + sessionId: text('session_id'), // Claude CLI session ID for resumption (null until first run completes) + worktreeId: text('worktree_id').notNull(), // WorktreeManager worktree ID + status: text('status', { + enum: ['idle', 'running', 'waiting_for_input', 'stopped', 'crashed'], + }) + .notNull() + .default('idle'), + createdAt: integer('created_at', { mode: 'timestamp' }).notNull(), + updatedAt: integer('updated_at', { mode: 'timestamp' }).notNull(), +}); + +export const agentsRelations = relations(agents, ({ one }) => ({ + task: one(tasks, { + fields: [agents.taskId], + references: [tasks.id], + }), +})); + +export type Agent = InferSelectModel; +export type NewAgent = InferInsertModel;