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,
DrizzleTaskRepository,
DrizzleMessageRepository,
DrizzleAgentRepository,
} from '../db/index.js';
import { ClaudeAgentManager } from '../agent/index.js';
import { SimpleGitWorktreeManager } from '../git/index.js';
/** Environment variable for custom port */
const CW_PORT_ENV = 'CW_PORT';
@@ -51,6 +54,11 @@ async function startServer(port?: number): Promise<void> {
const planRepository = new DrizzlePlanRepository(db);
const taskRepository = new DrizzleTaskRepository(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
const server = new CoordinationServer(
@@ -59,6 +67,7 @@ async function startServer(port?: number): Promise<void> {
logManager,
eventBus,
{
agentManager,
initiativeRepository,
phaseRepository,
planRepository,

View File

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