feat(cli): command architecture — agents, missions, and gateway-aware prdy
All checks were successful
ci/woodpecker/push/ci Pipeline was successful
ci/woodpecker/pr/ci Pipeline was successful

DB schema:
- Extend agents table with projectId, ownerId, systemPrompt, allowedTools,
  skills, isSystem columns and indexes
- Add agentId FK to conversations table with index

Brain:
- New agents repository (findAll, findById, findByName, findByProject,
  findSystem, findAccessible, create, update, remove)
- Wire into Brain interface and createBrain factory

Gateway:
- New AgentConfigsController at /api/agents with full CRUD + ownership guards
- Consolidate /api/missions — user-scoped CRUD replaces old project-ownership
  model, add /api/missions/:id/tasks sub-routes (replaces coord mission-tasks)
- Slim coord controller to file-based endpoints only (agent tool consumption)
- Remove DB-backed methods from CoordService (now handled by Brain repos)
- Wire agentConfigId into AgentService.createSession for DB config merging
- Add agentId field to ChatSocketMessageDto and ChatMessagePayload

CLI:
- New `mosaic agent` command (--list, --new, --show, --update, --delete)
- New `mosaic mission` command (--list, --init, --plan, --update, task sub)
- New `mosaic prdy` gateway-aware wrapper (--init, --update, --project)
- Shared with-auth helper and select-dialog utility
- TUI: accept --agent and --project flags, pass agentId to socket, display
  agent name in top bar
- Gateway API client: add agents, projects, missions, mission-tasks helpers
- Add @clack/prompts dependency
- Refactor sessions commands to use with-auth helper

Types:
- Add agentId to ChatMessagePayload

Tests:
- Update resource-ownership test for user-scoped missions (NotFoundException)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-15 18:08:48 -05:00
parent 82c10a7b33
commit ae4cd490ec
28 changed files with 1747 additions and 394 deletions

View File

@@ -0,0 +1,58 @@
import { eq, or, type Db, agents } from '@mosaic/db';
export type Agent = typeof agents.$inferSelect;
export type NewAgent = typeof agents.$inferInsert;
export function createAgentsRepo(db: Db) {
return {
async findAll(): Promise<Agent[]> {
return db.select().from(agents);
},
async findById(id: string): Promise<Agent | undefined> {
const rows = await db.select().from(agents).where(eq(agents.id, id));
return rows[0];
},
async findByName(name: string): Promise<Agent | undefined> {
const rows = await db.select().from(agents).where(eq(agents.name, name));
return rows[0];
},
async findByProject(projectId: string): Promise<Agent[]> {
return db.select().from(agents).where(eq(agents.projectId, projectId));
},
async findSystem(): Promise<Agent[]> {
return db.select().from(agents).where(eq(agents.isSystem, true));
},
async findAccessible(ownerId: string): Promise<Agent[]> {
return db
.select()
.from(agents)
.where(or(eq(agents.ownerId, ownerId), eq(agents.isSystem, true)));
},
async create(data: NewAgent): Promise<Agent> {
const rows = await db.insert(agents).values(data).returning();
return rows[0]!;
},
async update(id: string, data: Partial<NewAgent>): Promise<Agent | undefined> {
const rows = await db
.update(agents)
.set({ ...data, updatedAt: new Date() })
.where(eq(agents.id, id))
.returning();
return rows[0];
},
async remove(id: string): Promise<boolean> {
const rows = await db.delete(agents).where(eq(agents.id, id)).returning();
return rows.length > 0;
},
};
}
export type AgentsRepo = ReturnType<typeof createAgentsRepo>;

View File

@@ -4,6 +4,7 @@ import { createMissionsRepo, type MissionsRepo } from './missions.js';
import { createMissionTasksRepo, type MissionTasksRepo } from './mission-tasks.js';
import { createTasksRepo, type TasksRepo } from './tasks.js';
import { createConversationsRepo, type ConversationsRepo } from './conversations.js';
import { createAgentsRepo, type AgentsRepo } from './agents.js';
export interface Brain {
projects: ProjectsRepo;
@@ -11,6 +12,7 @@ export interface Brain {
missionTasks: MissionTasksRepo;
tasks: TasksRepo;
conversations: ConversationsRepo;
agents: AgentsRepo;
}
export function createBrain(db: Db): Brain {
@@ -20,5 +22,6 @@ export function createBrain(db: Db): Brain {
missionTasks: createMissionTasksRepo(db),
tasks: createTasksRepo(db),
conversations: createConversationsRepo(db),
agents: createAgentsRepo(db),
};
}

View File

@@ -26,3 +26,9 @@ export {
type Message,
type NewMessage,
} from './conversations.js';
export {
createAgentsRepo,
type AgentsRepo,
type Agent as AgentConfig,
type NewAgent as NewAgentConfig,
} from './agents.js';