use crate::common::domain_types::AgentName;
use serde::{Deserialize, Serialize};
#[derive(Clone, Copy, Serialize, Deserialize, Debug, PartialEq, Eq)]
pub enum WorkspaceIoErrorKind {
NotFound,
PermissionDenied,
AlreadyExists,
InvalidData,
Other,
}
impl WorkspaceIoErrorKind {
#[must_use]
pub const fn from_io_error_kind(kind: std::io::ErrorKind) -> Self {
match kind {
std::io::ErrorKind::NotFound => Self::NotFound,
std::io::ErrorKind::PermissionDenied => Self::PermissionDenied,
std::io::ErrorKind::AlreadyExists => Self::AlreadyExists,
std::io::ErrorKind::InvalidData => Self::InvalidData,
_ => Self::Other,
}
}
}
#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)]
pub enum ErrorEvent {
UserInterruptRequested,
ReviewInputsNotMaterialized {
pass: u32,
},
PlanningContinuationNotSupported,
ReviewContinuationNotSupported,
FixContinuationNotSupported,
CommitContinuationNotSupported,
FixPromptMissing,
AgentChainExhausted {
role: crate::agents::AgentRole,
phase: super::PipelinePhase,
cycle: u32,
},
WorkspaceReadFailed {
path: String,
kind: WorkspaceIoErrorKind,
},
WorkspaceWriteFailed {
path: String,
kind: WorkspaceIoErrorKind,
},
WorkspaceCreateDirAllFailed {
path: String,
kind: WorkspaceIoErrorKind,
},
WorkspaceRemoveFailed {
path: String,
kind: WorkspaceIoErrorKind,
},
GitAddAllFailed { kind: WorkspaceIoErrorKind },
GitAddSpecificFailed { kind: WorkspaceIoErrorKind },
GitStatusFailed { kind: WorkspaceIoErrorKind },
AgentNotFound { agent: AgentName },
PlanningInputsNotMaterialized { iteration: u32 },
DevelopmentInputsNotMaterialized { iteration: u32 },
CommitInputsNotMaterialized { attempt: u32 },
PlanningPromptMissing { iteration: u32 },
DevelopmentPromptMissing { iteration: u32 },
ReviewPromptMissing { pass: u32 },
CommitPromptMissing { attempt: u32 },
CommitAgentNotInitialized { attempt: u32 },
ValidatedPlanningMarkdownMissing { iteration: u32 },
ValidatedDevelopmentOutcomeMissing { iteration: u32 },
ValidatedReviewOutcomeMissing { pass: u32 },
ValidatedFixOutcomeMissing { pass: u32 },
ValidatedCommitOutcomeMissing { attempt: u32 },
}
impl std::fmt::Display for ErrorEvent {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::UserInterruptRequested => {
write!(f, "User interrupt requested (SIGINT / Ctrl+C)")
}
Self::ReviewInputsNotMaterialized { pass } => {
write!(
f,
"Review inputs not materialized for pass {pass} (expected materialize_review_inputs before prepare_review_prompt)"
)
}
Self::PlanningContinuationNotSupported => {
write!(f, "Planning does not support continuation prompts")
}
Self::ReviewContinuationNotSupported => {
write!(f, "Review does not support continuation prompts")
}
Self::FixContinuationNotSupported => {
write!(f, "Fix does not support continuation prompts")
}
Self::CommitContinuationNotSupported => {
write!(
f,
"Commit message generation does not support continuation prompts"
)
}
Self::FixPromptMissing => {
write!(f, "Missing fix prompt at .agent/tmp/fix_prompt.txt")
}
Self::AgentChainExhausted { role, phase, cycle } => {
write!(
f,
"Agent chain exhausted for role {role:?} in phase {phase:?} (cycle {cycle})"
)
}
Self::WorkspaceReadFailed { path, kind } => {
write!(f, "Workspace read failed at {path} ({kind:?})")
}
Self::WorkspaceWriteFailed { path, kind } => {
write!(f, "Workspace write failed at {path} ({kind:?})")
}
Self::WorkspaceCreateDirAllFailed { path, kind } => {
write!(f, "Workspace create_dir_all failed at {path} ({kind:?})")
}
Self::WorkspaceRemoveFailed { path, kind } => {
write!(f, "Workspace remove failed at {path} ({kind:?})")
}
Self::GitAddAllFailed { kind } => {
write!(f, "git add -A (stage all changes) failed ({kind:?})")
}
Self::GitAddSpecificFailed { kind } => {
write!(
f,
"git add <files> (stage specific paths) failed ({kind:?})"
)
}
Self::GitStatusFailed { kind } => {
write!(f, "git status (pre-termination check) failed ({kind:?})")
}
Self::AgentNotFound { agent } => {
write!(f, "Agent not found: {agent}")
}
Self::PlanningInputsNotMaterialized { iteration } => {
write!(
f,
"Planning inputs not materialized for iteration {iteration} (expected materialize_planning_inputs before prepare/invoke)"
)
}
Self::DevelopmentInputsNotMaterialized { iteration } => {
write!(
f,
"Development inputs not materialized for iteration {iteration} (expected materialize_development_inputs before prepare/invoke)"
)
}
Self::CommitInputsNotMaterialized { attempt } => {
write!(
f,
"Commit inputs not materialized for attempt {attempt} (expected materialize_commit_inputs before prepare)"
)
}
Self::PlanningPromptMissing { iteration } => {
write!(
f,
"Missing planning prompt at .agent/tmp/planning_prompt.txt for iteration {iteration}"
)
}
Self::DevelopmentPromptMissing { iteration } => {
write!(
f,
"Missing development prompt at .agent/tmp/development_prompt.txt for iteration {iteration}"
)
}
Self::ReviewPromptMissing { pass } => {
write!(
f,
"Missing review prompt at .agent/tmp/review_prompt.txt for pass {pass}"
)
}
Self::CommitPromptMissing { attempt } => {
write!(
f,
"Missing commit prompt at .agent/tmp/commit_prompt.txt for attempt {attempt}"
)
}
Self::CommitAgentNotInitialized { attempt } => {
write!(
f,
"Commit agent not initialized for attempt {attempt} (expected InitializeAgentChain before invoke_commit_agent)"
)
}
Self::ValidatedPlanningMarkdownMissing { iteration } => {
write!(
f,
"Missing validated planning markdown for iteration {iteration}"
)
}
Self::ValidatedDevelopmentOutcomeMissing { iteration } => {
write!(
f,
"Missing validated development outcome for iteration {iteration}"
)
}
Self::ValidatedReviewOutcomeMissing { pass } => {
write!(f, "Missing validated review outcome for pass {pass}")
}
Self::ValidatedFixOutcomeMissing { pass } => {
write!(f, "Missing validated fix outcome for pass {pass}")
}
Self::ValidatedCommitOutcomeMissing { attempt } => {
write!(f, "Missing validated commit outcome for attempt {attempt}")
}
}
}
}
impl std::error::Error for ErrorEvent {}