mirror of
https://github.com/AutoMaker-Org/automaker.git
synced 2026-02-03 08:53:36 +00:00
refactor(06-02): migrate Batch 1 query-only routes to facade pattern
- status.ts: Add facadeFactory parameter for per-project status - context-exists.ts: Add facadeFactory parameter for context checks - running-agents/index.ts: Add facade parameter for getRunningAgents All routes maintain backward compatibility by accepting both autoModeService (legacy) and facade/facadeFactory (new).
This commit is contained in:
@@ -4,9 +4,17 @@
|
|||||||
|
|
||||||
import type { Request, Response } from 'express';
|
import type { Request, Response } from 'express';
|
||||||
import type { AutoModeService } from '../../../services/auto-mode-service.js';
|
import type { AutoModeService } from '../../../services/auto-mode-service.js';
|
||||||
|
import type { AutoModeServiceFacade } from '../../../services/auto-mode/index.js';
|
||||||
import { getErrorMessage, logError } from '../common.js';
|
import { getErrorMessage, logError } from '../common.js';
|
||||||
|
|
||||||
export function createContextExistsHandler(autoModeService: AutoModeService) {
|
/**
|
||||||
|
* Create context exists handler with transition compatibility.
|
||||||
|
* Accepts either autoModeService (legacy) or facadeFactory (new).
|
||||||
|
*/
|
||||||
|
export function createContextExistsHandler(
|
||||||
|
autoModeService: AutoModeService,
|
||||||
|
facadeFactory?: (projectPath: string) => AutoModeServiceFacade
|
||||||
|
) {
|
||||||
return async (req: Request, res: Response): Promise<void> => {
|
return async (req: Request, res: Response): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
const { projectPath, featureId } = req.body as {
|
const { projectPath, featureId } = req.body as {
|
||||||
@@ -22,6 +30,15 @@ export function createContextExistsHandler(autoModeService: AutoModeService) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Use facade if factory is provided, otherwise fall back to autoModeService
|
||||||
|
if (facadeFactory) {
|
||||||
|
const facade = facadeFactory(projectPath);
|
||||||
|
const exists = await facade.contextExists(featureId);
|
||||||
|
res.json({ success: true, exists });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Legacy path: use autoModeService directly
|
||||||
const exists = await autoModeService.contextExists(projectPath, featureId);
|
const exists = await autoModeService.contextExists(projectPath, featureId);
|
||||||
res.json({ success: true, exists });
|
res.json({ success: true, exists });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@@ -7,9 +7,18 @@
|
|||||||
|
|
||||||
import type { Request, Response } from 'express';
|
import type { Request, Response } from 'express';
|
||||||
import type { AutoModeService } from '../../../services/auto-mode-service.js';
|
import type { AutoModeService } from '../../../services/auto-mode-service.js';
|
||||||
|
import type { AutoModeServiceFacade } from '../../../services/auto-mode/index.js';
|
||||||
import { getErrorMessage, logError } from '../common.js';
|
import { getErrorMessage, logError } from '../common.js';
|
||||||
|
|
||||||
export function createStatusHandler(autoModeService: AutoModeService) {
|
/**
|
||||||
|
* Create status handler with transition compatibility.
|
||||||
|
* Accepts either autoModeService (legacy) or facade (new).
|
||||||
|
* When facade is provided, creates a per-project facade for the request.
|
||||||
|
*/
|
||||||
|
export function createStatusHandler(
|
||||||
|
autoModeService: AutoModeService,
|
||||||
|
facadeFactory?: (projectPath: string) => AutoModeServiceFacade
|
||||||
|
) {
|
||||||
return async (req: Request, res: Response): Promise<void> => {
|
return async (req: Request, res: Response): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
const { projectPath, branchName } = req.body as {
|
const { projectPath, branchName } = req.body as {
|
||||||
@@ -21,6 +30,25 @@ export function createStatusHandler(autoModeService: AutoModeService) {
|
|||||||
if (projectPath) {
|
if (projectPath) {
|
||||||
// Normalize branchName: undefined becomes null
|
// Normalize branchName: undefined becomes null
|
||||||
const normalizedBranchName = branchName ?? null;
|
const normalizedBranchName = branchName ?? null;
|
||||||
|
|
||||||
|
// Use facade if factory is provided, otherwise fall back to autoModeService
|
||||||
|
if (facadeFactory) {
|
||||||
|
const facade = facadeFactory(projectPath);
|
||||||
|
const projectStatus = facade.getStatusForProject(normalizedBranchName);
|
||||||
|
res.json({
|
||||||
|
success: true,
|
||||||
|
isRunning: projectStatus.runningCount > 0,
|
||||||
|
isAutoLoopRunning: projectStatus.isAutoLoopRunning,
|
||||||
|
runningFeatures: projectStatus.runningFeatures,
|
||||||
|
runningCount: projectStatus.runningCount,
|
||||||
|
maxConcurrency: projectStatus.maxConcurrency,
|
||||||
|
projectPath,
|
||||||
|
branchName: normalizedBranchName,
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Legacy path: use autoModeService directly
|
||||||
const projectStatus = autoModeService.getStatusForProject(
|
const projectStatus = autoModeService.getStatusForProject(
|
||||||
projectPath,
|
projectPath,
|
||||||
normalizedBranchName
|
normalizedBranchName
|
||||||
@@ -39,6 +67,7 @@ export function createStatusHandler(autoModeService: AutoModeService) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Fall back to global status for backward compatibility
|
// Fall back to global status for backward compatibility
|
||||||
|
// Global status uses autoModeService (facade is per-project)
|
||||||
const status = autoModeService.getStatus();
|
const status = autoModeService.getStatus();
|
||||||
const activeProjects = autoModeService.getActiveAutoLoopProjects();
|
const activeProjects = autoModeService.getActiveAutoLoopProjects();
|
||||||
const activeWorktrees = autoModeService.getActiveAutoLoopWorktrees();
|
const activeWorktrees = autoModeService.getActiveAutoLoopWorktrees();
|
||||||
|
|||||||
@@ -4,15 +4,29 @@
|
|||||||
|
|
||||||
import type { Request, Response } from 'express';
|
import type { Request, Response } from 'express';
|
||||||
import type { AutoModeService } from '../../../services/auto-mode-service.js';
|
import type { AutoModeService } from '../../../services/auto-mode-service.js';
|
||||||
|
import type { AutoModeServiceFacade } from '../../../services/auto-mode/index.js';
|
||||||
import { getBacklogPlanStatus, getRunningDetails } from '../../backlog-plan/common.js';
|
import { getBacklogPlanStatus, getRunningDetails } from '../../backlog-plan/common.js';
|
||||||
import { getAllRunningGenerations } from '../../app-spec/common.js';
|
import { getAllRunningGenerations } from '../../app-spec/common.js';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import { getErrorMessage, logError } from '../common.js';
|
import { getErrorMessage, logError } from '../common.js';
|
||||||
|
|
||||||
export function createIndexHandler(autoModeService: AutoModeService) {
|
/**
|
||||||
|
* Create index handler with transition compatibility.
|
||||||
|
* Accepts either autoModeService (legacy) or facade (new).
|
||||||
|
* Note: getRunningAgents is global (not per-project), so facade is created
|
||||||
|
* with an empty path for global queries.
|
||||||
|
*/
|
||||||
|
export function createIndexHandler(
|
||||||
|
autoModeService: AutoModeService,
|
||||||
|
facade?: AutoModeServiceFacade
|
||||||
|
) {
|
||||||
return async (_req: Request, res: Response): Promise<void> => {
|
return async (_req: Request, res: Response): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
const runningAgents = [...(await autoModeService.getRunningAgents())];
|
// Use facade if provided, otherwise fall back to autoModeService
|
||||||
|
const runningAgents = facade
|
||||||
|
? [...(await facade.getRunningAgents())]
|
||||||
|
: [...(await autoModeService.getRunningAgents())];
|
||||||
|
|
||||||
const backlogPlanStatus = getBacklogPlanStatus();
|
const backlogPlanStatus = getBacklogPlanStatus();
|
||||||
const backlogPlanDetails = getRunningDetails();
|
const backlogPlanDetails = getRunningDetails();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user