package com.correx.core.kernel.orchestration.subagent

import com.correx.core.events.types.SessionId
import com.correx.core.events.types.StageId
import com.correx.core.kernel.orchestration.OrchestrationConfig
import com.correx.core.sessions.Session
import com.correx.core.transitions.execution.StageExecutionResult
import com.correx.core.transitions.graph.WorkflowGraph

/**
 * Runs the stage in the parent session by delegating to the orchestrator's existing
 * stage-execution function. No new isolation; reuses journal + CAS + validation.
 */
class InSessionSubagentRunner(
    private val executeStage: suspend (
        SessionId, StageId, WorkflowGraph, Session, OrchestrationConfig,
    ) -> StageExecutionResult,
) : SubagentRunner {
    override suspend fun run(request: SubagentRunRequest): SubagentRunResult =
        SubagentRunResult(
            executeStage(
                request.sessionId, request.stageId, request.graph, request.session, request.config,
            ),
        )
}
