1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
//! Auth-shaped step-failure classification (DESIGN §8.3 detection, §15 M6 Z8): a
//! pure predicate over the already-derived step facts (§5.1 #10/#13 — framing
//! Failed + the response/error text) deciding whether a failed step *looks* like a
//! credential / authorization problem, so the Login affordance surfaces one click
//! away (beside the failed step and in the Login pane). Shell paints; this is
//! covered logic — the steps view-model reads [`classify`] into its Login flag.
//!
//! **The affordance names its row (bl-8e34).** An auth-shaped failure is only
//! half an answer: `bz --login` takes a provider row, and brazen's error line
//! carries none (`provider_detail` is null on the borrowed-credential decline
//! that motivated this). So the classification is a three-state [`AuthFailure`],
//! not a flag — no failure / a failure with no derivable row / a failure **on
//! this row** — and [`row_of_model`] is where the row comes from: the failing
//! step's own `request.json` model id, matched against the roles the agent's
//! governing config declares (§9.4's `roles:` grammar, read through
//! [`crate::fork::roles_at`]). Both halves are already-on-disk facts, so nothing
//! is stored and no new read is invented; the routing is a join, not a lookup
//! table.
use crateerror_text;
use crateRoleModel;
/// Case-insensitive substrings that mark an **auth-shaped** failure — the
/// credential / auth / 401 / 403 / permission-denied class (§8.3). Matched against
/// the raw error event line ([`error_text`]), so both an HTTP status code and its
/// reason phrase catch. Deliberately narrow so a transport reset or a 500 never
/// fires this: bare `auth` is **excluded** (it hits `author`); the tokens are the
/// full `authenticat` / `authoriz` / `authoris` stems, and every other marker
/// names a genuinely auth-related concept.
const AUTH_MARKERS: & = &;
/// Does `error_line` (a raw JSONL error event) look auth-shaped? Pure,
/// case-insensitive substring match against [`AUTH_MARKERS`].
/// A step's auth-shaped-failure state and where its remedy points (§8.3).
/// Three states because three exist: the affordance is offered or it is not,
/// and when it is offered the row it should run is derivable or it is not.
/// Absent data is a value, never a branch — [`Unrouted`](Self::Unrouted) is the
/// honest middle, not an error.
/// Classify a step's settled `response.json` (§8.3): its framing is Failed (an
/// error event settled the last segment) **and** that error text matches
/// [`looks_auth`]. [`error_text`] returning `Some` already means framing Failed
/// (they share the last-segment traversal), so one call answers both facts —
/// the single source the steps view-model reads for its Login flag.
///
/// Bytes in, no row out: routing needs the governing config, which is a git
/// read this pure classifier does not do. The caller upgrades
/// [`Unrouted`](AuthFailure::Unrouted) through [`row_of_model`] — so the git
/// call is paid once per agent, and only when some step is actually failing.
/// The provider row that serves `model`, per the roles a governing config
/// declares (`providers.yaml` `roles:`, read through [`crate::fork::roles_at`]).
///
/// The join is on the model id because that is the fact the failing step
/// records: `request.json` carries the model, never the row. A model no role
/// binds yields `None`, and so does one bound under **two different rows** —
/// naming either would be a guess, and a guessed row sends the operator through
/// a browser sign-in for a credential that was never the problem.
/// The **latest** step's auth-shaped-failure state (§11 center): the
/// conversation-view detection that banners Login inline. Reads off an
/// already-built steps view-model ([`crate::steps_view::StepsView`] — the one
/// owner of the per-step Login flag), so the banner, the Steps tab, and the
/// Login pane all derive from the same classification. It takes the view, not
/// the disk: the shell declares one standing `Query::Steps` that this banner
/// and the Steps tab share (REMOTE §9.7, bl-13f9), and a predicate that re-read
/// the whole steps tree per frame was the chat pane's frame-time cost.