@startuml
package "core:transitions" {
  data class WorkflowGraph {
    + id: String
    + stages: Map
    + transitions: Set
    + start: StageId
  }

  data class StageConfig {
    + requiredCapabilities
    + tokenBudget
    + generationConfig
    + allowedTools
    + produces
  }

  data class TransitionEdge {
    + id: TransitionId
    + from: StageId
    + to: StageId
    + condition: TransitionCondition
  }

  fun interface TransitionCondition {
    + evaluate(EvaluationContext): Boolean
  }

  interface TransitionResolver {
    + resolve(WorkflowGraph, EvaluationContext): TransitionDecision
  }

  class DefaultTransitionResolver

  sealed interface TransitionDecision {
    data class Move
    data object Stay
    data class Blocked
    data object NoMatch
  }

  data class EvaluationContext {
    + sessionId
    + currentStage
    + artifacts
    + variables
  }

  fun interface TransitionConditionEvaluator
  fun interface PromptResolver

  interface StageExecutor
  interface StageExecutionEventMapper

  data class StageExecutionRequest
  sealed interface StageExecutionResult {
    data class Success
    data class Failure
  }

  DefaultTransitionResolver ..|> TransitionResolver
  DefaultTransitionResolver --> TransitionConditionEvaluator
  DefaultTransitionResolver --> TransitionOrdering

  WorkflowGraph *-- StageConfig
  WorkflowGraph *-- TransitionEdge
  TransitionEdge *-- TransitionCondition

  TransitionResolver --> TransitionDecision
  TransitionResolver --> EvaluationContext

  StageExecutionEventMapper --> StageExecutionRequest
  StageExecutionEventMapper --> StageExecutionResult
  StageExecutionEventMapper --> EventPayload

  package "conditions" {
    class AlwaysTrue
    class VariableEquals
    class ArtifactPresent
    class ArtifactAbsent
    class ArtifactValidated
    class AllOf
    class AnyOf
    class Not
  }

  AlwaysTrue ..|> TransitionCondition
  VariableEquals ..|> TransitionCondition
  ArtifactPresent ..|> TransitionCondition
  AllOf ..|> TransitionCondition

  package "cycle detection" {
    class CycleExtractor
    class CycleDfs
    class DeterministicAdjacencyBuilder
    object CycleCanonicalizer
    data class DetectedCycle
  }

  package "cycle policy" {
    sealed interface CyclePolicy {
      data class Retry
      data class Refinement
      data class Approval
    }
    data class CycleSignature
    data class CyclePolicyBinding
    class CyclePolicyResolver
    class PolicyValidation
  }
}

@enduml
