Files
Codewalkers/apps/server/agent/lifecycle/factory.ts
Lukas May 28521e1c20 chore: merge main into cw/small-change-flow
Integrates main branch changes (headquarters dashboard, task retry count,
agent prompt persistence, remote sync improvements) with the initiative's
errand agent feature. Both features coexist in the merged result.

Key resolutions:
- Schema: take main's errands table (nullable projectId, no conflictFiles,
  with errandsRelations); migrate to 0035_faulty_human_fly
- Router: keep both errandProcedures and headquartersProcedures
- Errand prompt: take main's simpler version (no question-asking flow)
- Manager: take main's status check (running|idle only, no waiting_for_input)
- Tests: update to match removed conflictFiles field and undefined vs null
2026-03-06 16:48:12 +01:00

62 lines
2.0 KiB
TypeScript

/**
* Lifecycle Factory — Wire up all lifecycle components with proper dependencies.
*
* Creates and configures the complete lifecycle management system with all
* dependencies properly injected. Provides simple entry point for integration.
*/
import { FileSystemSignalManager } from './signal-manager.js';
import { DefaultRetryPolicy } from './retry-policy.js';
import { AgentErrorAnalyzer } from './error-analyzer.js';
import { DefaultCleanupStrategy } from './cleanup-strategy.js';
import { AgentLifecycleController } from './controller.js';
import type { AgentRepository } from '../../db/repositories/agent-repository.js';
import type { AccountRepository } from '../../db/repositories/account-repository.js';
import type { ProcessManager } from '../process-manager.js';
import type { CleanupManager } from '../cleanup-manager.js';
import type { EventBus } from '../../events/types.js';
export interface LifecycleFactoryOptions {
repository: AgentRepository;
processManager: ProcessManager;
cleanupManager: CleanupManager;
accountRepository?: AccountRepository;
debug?: boolean;
eventBus?: EventBus;
}
/**
* Create a fully configured AgentLifecycleController with all dependencies.
*/
export function createLifecycleController(options: LifecycleFactoryOptions): AgentLifecycleController {
const {
repository,
processManager,
cleanupManager,
accountRepository,
debug = false,
eventBus,
} = options;
// Create core components
const signalManager = new FileSystemSignalManager();
const retryPolicy = new DefaultRetryPolicy();
const errorAnalyzer = new AgentErrorAnalyzer(signalManager);
const cleanupStrategy = new DefaultCleanupStrategy(cleanupManager);
// Wire up the main controller
const lifecycleController = new AgentLifecycleController(
signalManager,
retryPolicy,
errorAnalyzer,
processManager,
repository,
cleanupManager,
cleanupStrategy,
accountRepository,
debug,
eventBus,
);
return lifecycleController;
}