1use std::ffi::OsString;
8use std::path::PathBuf;
9
10pub mod local;
11
12#[derive(Debug, Clone)]
13pub struct StageOrder {
14 pub run_id: String,
15 pub stage: String,
16 pub attempt: u32,
20 pub execution: StageExecution,
21 pub worktree: PathBuf,
22 pub branch: String,
23 pub output_path: PathBuf,
24}
25
26#[derive(Debug, Clone)]
27pub enum StageExecution {
28 Agent(AgentLaunch),
29 Exec(ExecLaunch),
30}
31
32#[derive(Debug, Clone)]
33pub struct AgentLaunch {
34 pub argv: Vec<String>,
35 pub environment: Vec<(OsString, OsString)>,
36 pub worker: WorkerCredentials,
40}
41
42#[derive(Debug, Clone)]
43pub struct ExecLaunch {
44 pub argv: Vec<String>,
45 pub worker: Option<WorkerCredentials>,
46 pub environment: Vec<(OsString, OsString)>,
49}
50
51#[derive(Debug, Clone, PartialEq, Eq)]
52pub struct WorkerCredentials {
53 pub socket: PathBuf,
54 pub token: String,
55 pub scope: WorkerScope,
58}
59
60#[derive(Debug, Clone, PartialEq, Eq)]
62pub enum WorkerScope {
63 Stage { stage: String, attempt: u32 },
71 PanelReviewer {
77 stage: String,
78 stage_index: usize,
79 attempt: u32,
80 reviewer_index: usize,
81 },
82}
83
84#[derive(Debug, Clone, Copy, PartialEq, Eq)]
85pub struct ProcessIdentity {
86 pub pid: u32,
87 pub start_time: Option<i64>,
88 pub process_group_id: u32,
89}
90
91#[derive(Debug, Clone, Copy, PartialEq, Eq)]
92pub struct ExecutionEvidence {
93 pub exit_code: Option<i32>,
94 pub started_at_ms: i64,
95 pub finished_at_ms: i64,
96 pub process: Option<ProcessIdentity>,
97 pub output_capture_complete: bool,
98 pub stragglers_killed: bool,
99}
100
101#[derive(Debug, Clone)]
102pub struct AgentProcessCheckpoint {
103 pub run_id: String,
104 pub stage: String,
105 pub attempt: u32,
106 pub branch: String,
107 pub worktree: PathBuf,
108 pub process: ProcessIdentity,
109 pub worker: WorkerCredentials,
110 pub started_at_ms: i64,
111}
112
113#[derive(Debug, Clone)]
114pub struct ExecProcessCheckpoint {
115 pub run_id: String,
116 pub stage: String,
117 pub attempt: u32,
118 pub process: ProcessIdentity,
119 pub started_at_ms: i64,
120}
121
122pub trait StageHooks {
124 type Error;
125
126 fn cancellation_requested(&self, run_id: &str) -> bool;
127
128 fn record_agent_process(&self, checkpoint: &AgentProcessCheckpoint) -> Result<(), Self::Error>;
129
130 fn record_exec_process(&self, checkpoint: &ExecProcessCheckpoint) -> Result<(), Self::Error>;
131}
132
133#[derive(Debug)]
134pub enum RunnerError<E> {
135 Execution(String),
136 Hook(E),
137}
138
139impl<E: std::fmt::Display> std::fmt::Display for RunnerError<E> {
140 fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
141 match self {
142 Self::Execution(message) => formatter.write_str(message),
143 Self::Hook(error) => error.fmt(formatter),
144 }
145 }
146}
147
148#[derive(Debug)]
149pub struct ExecutionFailure<E> {
150 pub evidence: ExecutionEvidence,
151 pub error: RunnerError<E>,
152}