refactor(06-03): migrate Batch 5 secondary routes and wire router index

- features/routes/list.ts: Add facadeFactory parameter, use facade.detectOrphanedFeatures
- projects/routes/overview.ts: Add facadeFactory parameter, use facade.getRunningAgents/getStatusForProject
- features/index.ts: Pass facadeFactory to list handler
- projects/index.ts: Pass facadeFactory to overview handler
- auto-mode/index.ts: Accept facadeFactory parameter and wire to all route handlers
- All routes maintain backward compatibility with autoModeService fallback
This commit is contained in:
Shirone
2026-01-30 21:46:05 +01:00
committed by gsxdsm
parent 7bc1f68699
commit 7fd3d61a59
5 changed files with 97 additions and 23 deletions

View File

@@ -5,6 +5,7 @@
import { Router } from 'express';
import type { FeatureLoader } from '../../services/feature-loader.js';
import type { AutoModeService } from '../../services/auto-mode-service.js';
import type { AutoModeServiceFacade } from '../../services/auto-mode/index.js';
import type { SettingsService } from '../../services/settings-service.js';
import type { NotificationService } from '../../services/notification-service.js';
import { createOverviewHandler } from './routes/overview.js';
@@ -13,14 +14,21 @@ export function createProjectsRoutes(
featureLoader: FeatureLoader,
autoModeService: AutoModeService,
settingsService: SettingsService,
notificationService: NotificationService
notificationService: NotificationService,
facadeFactory?: (projectPath: string) => AutoModeServiceFacade
): Router {
const router = Router();
// GET /overview - Get aggregate status for all projects
router.get(
'/overview',
createOverviewHandler(featureLoader, autoModeService, settingsService, notificationService)
createOverviewHandler(
featureLoader,
autoModeService,
settingsService,
notificationService,
facadeFactory
)
);
return router;

View File

@@ -10,6 +10,11 @@
import type { Request, Response } from 'express';
import type { FeatureLoader } from '../../../services/feature-loader.js';
import type { AutoModeService } from '../../../services/auto-mode-service.js';
import type {
AutoModeServiceFacade,
RunningAgentInfo,
ProjectAutoModeStatus,
} from '../../../services/auto-mode/index.js';
import type { SettingsService } from '../../../services/settings-service.js';
import type { NotificationService } from '../../../services/notification-service.js';
import type {
@@ -149,7 +154,8 @@ export function createOverviewHandler(
featureLoader: FeatureLoader,
autoModeService: AutoModeService,
settingsService: SettingsService,
notificationService: NotificationService
notificationService: NotificationService,
facadeFactory?: (projectPath: string) => AutoModeServiceFacade
) {
return async (_req: Request, res: Response): Promise<void> => {
try {
@@ -158,7 +164,15 @@ export function createOverviewHandler(
const projectRefs: ProjectRef[] = settings.projects || [];
// Get all running agents once to count live running features per project
const allRunningAgents = await autoModeService.getRunningAgents();
// Use facade if available, otherwise fall back to autoModeService
let allRunningAgents: RunningAgentInfo[];
if (facadeFactory && projectRefs.length > 0) {
// For running agents, we can use any project's facade since it's a global query
const facade = facadeFactory(projectRefs[0].path);
allRunningAgents = await facade.getRunningAgents();
} else {
allRunningAgents = await autoModeService.getRunningAgents();
}
// Collect project statuses in parallel
const projectStatusPromises = projectRefs.map(async (projectRef): Promise<ProjectStatus> => {
@@ -169,7 +183,13 @@ export function createOverviewHandler(
const totalFeatures = features.length;
// Get auto-mode status for this project (main worktree, branchName = null)
const autoModeStatus = autoModeService.getStatusForProject(projectRef.path, null);
let autoModeStatus: ProjectAutoModeStatus;
if (facadeFactory) {
const facade = facadeFactory(projectRef.path);
autoModeStatus = facade.getStatusForProject(null);
} else {
autoModeStatus = autoModeService.getStatusForProject(projectRef.path, null);
}
const isAutoModeRunning = autoModeStatus.isAutoLoopRunning;
// Count live running features for this project (across all branches)