pub fn evaluate_layer1(project_root: &Path, phase: u32) -> Option<AgentResult>Expand description
Layer 1: Try to detect agent result from the native per-adapter envelope or the DEVFLOW_RESULT marker in stdout.
The monitor’s own idle-timeout side channel is consulted FIRST, ahead of
everything below including read_capture itself — see
[parse_idle_timeout_side_channel], where that ordering is a correctness
requirement rather than a preference.
Precedence: Claude rate-limit envelope (a SPECIFIC failure that must
outrank the generic is_error check — rate-limit envelopes carry
is_error: true, and classifying them Failed would kill the primary
rate-limit resume cron path) → Claude envelope is_error: true (authoritative,
overrides a success marker) → Claude stream-json JSONL event stream (the
last result event’s marker decides; a marker-less last turn defers) →
DEVFLOW_RESULT marker (portable; works for plain text and a Claude
envelope’s unwrapped result text) → Codex JSONL event stream
(turn.failed decisive; turn.completed defers) → Codex plain-text
rate-limit heuristic (least authoritative, stays last).
The Claude stream parser’s position is load-bearing in BOTH directions
(T-30-03). The two single-document detectors stay ahead of it because they
remain authoritative for the --output-format json envelope that ships
today. It goes ahead of parse_devflow_result so that an adapter-specific
stream capture is owned whole by the parser that understands its framing,
rather than letting the generic 4000-character tail scan take a bite of a
mid-line window of JSONL first.