fix: Surface active architect agents in initiative activity state
Auto-spawned discuss/plan/refine agents were invisible because: 1. listInitiatives only filtered for mode='detail' agents 2. deriveInitiativeActivity returned 'idle' for zero phases before checking for active agents Broadened agent filter to all architect modes (discuss, plan, detail, refine), moved active agent check before zero-phases early return, and added 'discussing'/'refining' activity states with pulsing indicators.
This commit is contained in:
@@ -5,16 +5,23 @@
|
||||
import type { Initiative, Phase } from '../../db/schema.js';
|
||||
import type { InitiativeActivity, InitiativeActivityState } from '@codewalk-district/shared';
|
||||
|
||||
export interface ActiveDetailAgent {
|
||||
export interface ActiveArchitectAgent {
|
||||
initiativeId: string;
|
||||
mode: string;
|
||||
status: string;
|
||||
}
|
||||
|
||||
const MODE_TO_STATE: Record<string, InitiativeActivityState> = {
|
||||
discuss: 'discussing',
|
||||
plan: 'detailing',
|
||||
detail: 'detailing',
|
||||
refine: 'refining',
|
||||
};
|
||||
|
||||
export function deriveInitiativeActivity(
|
||||
initiative: Initiative,
|
||||
phases: Phase[],
|
||||
activeDetailAgents?: ActiveDetailAgent[],
|
||||
activeArchitectAgents?: ActiveArchitectAgent[],
|
||||
): InitiativeActivity {
|
||||
const phasesTotal = phases.length;
|
||||
const phasesCompleted = phases.filter(p => p.status === 'completed').length;
|
||||
@@ -26,6 +33,18 @@ export function deriveInitiativeActivity(
|
||||
if (initiative.status === 'completed') {
|
||||
return { ...base, state: 'complete' };
|
||||
}
|
||||
|
||||
// Check for active architect agents BEFORE zero-phases check
|
||||
// so auto-spawned discuss/plan/refine agents surface activity
|
||||
const activeAgent = activeArchitectAgents?.find(
|
||||
a => a.initiativeId === initiative.id
|
||||
&& (a.status === 'running' || a.status === 'waiting_for_input'),
|
||||
);
|
||||
if (activeAgent) {
|
||||
const state = MODE_TO_STATE[activeAgent.mode] ?? 'detailing';
|
||||
return { ...base, state };
|
||||
}
|
||||
|
||||
if (phasesTotal === 0) {
|
||||
return { ...base, state: 'idle' };
|
||||
}
|
||||
@@ -53,15 +72,5 @@ export function deriveInitiativeActivity(
|
||||
return { ...base, state: 'ready', activePhase: { id: approved.id, name: approved.name } };
|
||||
}
|
||||
|
||||
// Check for active detail agents (detailing trumps planning)
|
||||
const detailing = activeDetailAgents?.some(
|
||||
a => a.initiativeId === initiative.id
|
||||
&& a.mode === 'detail'
|
||||
&& (a.status === 'running' || a.status === 'waiting_for_input'),
|
||||
);
|
||||
if (detailing) {
|
||||
return { ...base, state: 'detailing' };
|
||||
}
|
||||
|
||||
return { ...base, state: 'planning' };
|
||||
}
|
||||
|
||||
@@ -98,11 +98,12 @@ export function initiativeProcedures(publicProcedure: ProcedureBuilder) {
|
||||
? await repo.findByStatus(input.status)
|
||||
: await repo.findAll();
|
||||
|
||||
// Fetch active detail agents once for all initiatives
|
||||
// Fetch active architect agents once for all initiatives
|
||||
const ARCHITECT_MODES = ['discuss', 'plan', 'detail', 'refine'];
|
||||
const allAgents = ctx.agentManager ? await ctx.agentManager.list() : [];
|
||||
const activeDetailAgents = allAgents
|
||||
const activeArchitectAgents = allAgents
|
||||
.filter(a =>
|
||||
a.mode === 'detail'
|
||||
ARCHITECT_MODES.includes(a.mode ?? '')
|
||||
&& (a.status === 'running' || a.status === 'waiting_for_input')
|
||||
&& !a.userDismissedAt,
|
||||
)
|
||||
@@ -112,13 +113,13 @@ export function initiativeProcedures(publicProcedure: ProcedureBuilder) {
|
||||
const phaseRepo = ctx.phaseRepository;
|
||||
return Promise.all(initiatives.map(async (init) => {
|
||||
const phases = await phaseRepo.findByInitiativeId(init.id);
|
||||
return { ...init, activity: deriveInitiativeActivity(init, phases, activeDetailAgents) };
|
||||
return { ...init, activity: deriveInitiativeActivity(init, phases, activeArchitectAgents) };
|
||||
}));
|
||||
}
|
||||
|
||||
return initiatives.map(init => ({
|
||||
...init,
|
||||
activity: deriveInitiativeActivity(init, [], activeDetailAgents),
|
||||
activity: deriveInitiativeActivity(init, [], activeArchitectAgents),
|
||||
}));
|
||||
}),
|
||||
|
||||
|
||||
Reference in New Issue
Block a user