/**
 * @fileoverview Ralph Loop / todo tracking type definitions.
 *
 * Covers the autonomous task execution system: loop state, todo items,
 * completion confidence scoring, RALPH_STATUS block parsing, and the
 * circuit breaker for stuck-loop detection.
 *
 * Key exports:
 * - RalphLoopState / RalphLoopStatus — global loop controller state (embedded in AppState)
 * - RalphTrackerState — per-session loop tracking (cycle count, completion phrase, plan version)
 * - RalphTodoItem / RalphTodoProgress — detected todo items with priority and progress estimation
 * - RalphSessionState — composite per-session state (loop + todos), linked via sessionId
 * - CompletionConfidence — multi-signal scoring for completion detection (0-100)
 * - RalphStatusBlock — parsed RALPH_STATUS block from Claude output (status, tests, exit signal)
 * - CircuitBreakerStatus / CircuitBreakerState — stuck-loop detection state machine (CLOSED → HALF_OPEN → OPEN)
 * - Factory functions: createInitialCircuitBreakerStatus(), createInitialRalphTrackerState(), createInitialRalphSessionState()
 *
 * Cross-domain relationships:
 * - RalphLoopState is embedded in AppState.ralphLoop (app-state domain)
 * - RalphSessionState.sessionId links to SessionState.id (session domain)
 * - CircuitBreakerStatus feeds into RalphLoopHealthScore.components.circuitBreaker (respawn domain)
 *
 * Served at `GET /api/sessions/:id/ralph-state` and `GET /api/sessions/:id/ralph-status`.
 */
/**
 * Creates initial circuit breaker status.
 */
export function createInitialCircuitBreakerStatus() {
    return {
        state: 'CLOSED',
        consecutiveNoProgress: 0,
        consecutiveSameError: 0,
        consecutiveTestsFailure: 0,
        lastProgressIteration: 0,
        reason: 'Initial state',
        reasonCode: 'normal_operation',
        lastTransitionAt: Date.now(),
        lastErrorMessage: null,
    };
}
/**
 * Creates initial Ralph tracker state
 * @returns Fresh Ralph tracker state with defaults
 */
export function createInitialRalphTrackerState() {
    return {
        enabled: false, // Disabled by default, auto-enables when Ralph patterns detected
        active: false,
        completionPhrase: null,
        startedAt: null,
        cycleCount: 0,
        maxIterations: null,
        lastActivity: Date.now(),
        elapsedHours: null,
    };
}
/**
 * Creates initial Ralph session state
 * @param sessionId Session ID this state belongs to
 * @returns Fresh Ralph session state
 */
export function createInitialRalphSessionState(sessionId) {
    return {
        sessionId,
        loop: createInitialRalphTrackerState(),
        todos: [],
        lastUpdated: Date.now(),
    };
}
//# sourceMappingURL=ralph.js.map