5.2 KiB
phase, plan, type, wave, depends_on, files_modified, autonomous
| phase | plan | type | wave | depends_on | files_modified | autonomous | ||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 05-task-dispatch | 01 | execute | 1 |
|
true |
Purpose: AGENT-06 requires agents to surface questions to users. When an agent pauses on AskUserQuestion, the question needs to persist in the database so users can query pending messages and respond later. Output: messages table, MessageRepository port/adapter with full CRUD and tests.
<execution_context>
@/.claude/get-shit-done/workflows/execute-plan.md
@/.claude/get-shit-done/templates/summary.md
</execution_context>
@src/db/schema.ts @src/db/repositories/task-repository.ts @src/db/repositories/drizzle/task.ts @src/db/repositories/drizzle/agent.ts @src/events/types.ts
Task 1: Add messages table to schema src/db/schema.ts Add messages table after agents table. Schema: - id: text primary key - senderType: text enum ['agent', 'user'] NOT NULL (who sent the message) - senderId: text nullable (agent ID if senderType='agent', null for user) - recipientType: text enum ['agent', 'user'] NOT NULL (who receives the message) - recipientId: text nullable (agent ID if recipientType='agent', null for user) - type: text enum ['question', 'info', 'error', 'response'] NOT NULL default 'info' - content: text NOT NULL (the message text) - requiresResponse: integer boolean NOT NULL default 0 (1 = expects reply, 0 = notification only) - status: text enum ['pending', 'read', 'responded'] NOT NULL default 'pending' - parentMessageId: text nullable foreign key to messages.id (links response to original question) - createdAt: integer timestamp NOT NULL - updatedAt: integer timestamp NOT NULLSender/recipient foreign keys reference agents.id with SET NULL on delete (messages persist).
Add relations:
- sender agent (optional)
- recipient agent (optional)
- parent message (for threading responses)
- child messages (replies to this message)
Export Message and NewMessage types.
Follow existing patterns: use sqliteTable, relations, InferSelectModel/InferInsertModel. npm run build passes, no TypeScript errors messages table in schema with types exported
Task 2: Create MessageRepository port and adapter src/db/repositories/message-repository.ts, src/db/repositories/drizzle/message.ts, src/db/repositories/drizzle/message.test.ts, src/db/repositories/index.ts, src/db/repositories/drizzle/index.ts Create MessageRepository following TaskRepository pattern exactly:-
Port interface (message-repository.ts):
- CreateMessageData type (omit id, createdAt, updatedAt)
- UpdateMessageData type (partial of create data)
- MessageRepository interface with:
- create(data: CreateMessageData): Promise
- findById(id: string): Promise<Message | null>
- findBySender(type: 'agent'|'user', id?: string): Promise<Message[]>
- findByRecipient(type: 'agent'|'user', id?: string): Promise<Message[]>
- findPendingForUser(): Promise<Message[]> (recipientType='user', status='pending')
- findRequiringResponse(): Promise<Message[]> (requiresResponse=true, status='pending')
- findReplies(parentMessageId: string): Promise<Message[]>
- update(id: string, data: UpdateMessageData): Promise
- delete(id: string): Promise
-
Drizzle adapter (drizzle/message.ts):
- DrizzleMessageRepository class implementing port
- Use nanoid for id generation
- Fetch after insert to get schema defaults
- Order by createdAt DESC for lists
-
Tests (drizzle/message.test.ts):
- Use createTestDatabase helper
- Test create with agent→user message (question)
- Test create with agent→user message (notification, requiresResponse=false)
- Test findBySender and findByRecipient
- Test findPendingForUser returns only user-targeted pending messages
- Test findRequiringResponse returns only messages needing response
- Test message threading (parentMessageId linking)
- Test update status flow: pending → read → responded
-
Re-export from index files (same pattern as AgentRepository) npm test -- src/db/repositories/drizzle/message.test.ts passes MessageRepository port/adapter with passing tests
<success_criteria>
- messages table added to schema with proper types
- MessageRepository port interface defined
- DrizzleMessageRepository adapter implemented
- All tests pass
- Exports wired up in index files </success_criteria>