fix(19): wire AgentManager into server tRPC context

AgentManager was never instantiated or passed to the CoordinationServer,
causing all agent-related tRPC procedures to throw "Agent manager not
available". Creates DrizzleAgentRepository, SimpleGitWorktreeManager,
and ClaudeAgentManager in startServer() and passes agentManager into
the server context deps.
This commit is contained in:
Lukas May
2026-02-04 22:03:09 +01:00
parent 049810ffae
commit 9d7002d2bd
2 changed files with 15 additions and 6 deletions

View File

@@ -21,7 +21,10 @@ import {
DrizzlePlanRepository, DrizzlePlanRepository,
DrizzleTaskRepository, DrizzleTaskRepository,
DrizzleMessageRepository, DrizzleMessageRepository,
DrizzleAgentRepository,
} from '../db/index.js'; } from '../db/index.js';
import { ClaudeAgentManager } from '../agent/index.js';
import { SimpleGitWorktreeManager } from '../git/index.js';
/** Environment variable for custom port */ /** Environment variable for custom port */
const CW_PORT_ENV = 'CW_PORT'; const CW_PORT_ENV = 'CW_PORT';
@@ -51,6 +54,11 @@ async function startServer(port?: number): Promise<void> {
const planRepository = new DrizzlePlanRepository(db); const planRepository = new DrizzlePlanRepository(db);
const taskRepository = new DrizzleTaskRepository(db); const taskRepository = new DrizzleTaskRepository(db);
const messageRepository = new DrizzleMessageRepository(db); const messageRepository = new DrizzleMessageRepository(db);
const agentRepository = new DrizzleAgentRepository(db);
// Create agent manager with worktree isolation
const worktreeManager = new SimpleGitWorktreeManager(process.cwd(), eventBus);
const agentManager = new ClaudeAgentManager(agentRepository, worktreeManager, eventBus);
// Create and start server // Create and start server
const server = new CoordinationServer( const server = new CoordinationServer(
@@ -59,6 +67,7 @@ async function startServer(port?: number): Promise<void> {
logManager, logManager,
eventBus, eventBus,
{ {
agentManager,
initiativeRepository, initiativeRepository,
phaseRepository, phaseRepository,
planRepository, planRepository,

View File

@@ -408,8 +408,8 @@ export const appRouter = router({
*/ */
listAgents: publicProcedure listAgents: publicProcedure
.query(async ({ ctx }) => { .query(async ({ ctx }) => {
if (!ctx.agentManager) return []; const agentManager = requireAgentManager(ctx);
return ctx.agentManager.list(); return agentManager.list();
}), }),
/** /**
@@ -463,9 +463,9 @@ export const appRouter = router({
getAgentQuestions: publicProcedure getAgentQuestions: publicProcedure
.input(agentIdentifierSchema) .input(agentIdentifierSchema)
.query(async ({ ctx, input }): Promise<PendingQuestions | null> => { .query(async ({ ctx, input }): Promise<PendingQuestions | null> => {
if (!ctx.agentManager) return null; const agentManager = requireAgentManager(ctx);
const agent = await resolveAgent(ctx, input); const agent = await resolveAgent(ctx, input);
return ctx.agentManager.getPendingQuestions(agent.id); return agentManager.getPendingQuestions(agent.id);
}), }),
/** /**
@@ -474,8 +474,8 @@ export const appRouter = router({
*/ */
listWaitingAgents: publicProcedure listWaitingAgents: publicProcedure
.query(async ({ ctx }) => { .query(async ({ ctx }) => {
if (!ctx.agentManager) return []; const agentManager = requireAgentManager(ctx);
const allAgents = await ctx.agentManager.list(); const allAgents = await agentManager.list();
return allAgents.filter(agent => agent.status === 'waiting_for_input'); return allAgents.filter(agent => agent.status === 'waiting_for_input');
}), }),