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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
//! The kinds of Needs You items: one registry, each kind with its group
//! and urgency rank. A feature adds a kind here, never a free
//! string; the runtime's list is derived from it.
use serde::{Deserialize, Serialize};
/// Where an item puts the work.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, schemars::JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum Group {
/// Nothing moves until the person decides.
BlockedOnYou,
/// Work is done or held; the person reviews it.
ReadyToReview,
/// A run is in progress.
Working,
/// Nothing runs and nothing waits.
Idle,
}
impl Group {
/// Every group, in the order Needs You shows them.
pub const ALL: [Self; 4] = [
Self::BlockedOnYou,
Self::ReadyToReview,
Self::Working,
Self::Idle,
];
/// Its recorded name.
#[must_use]
pub const fn as_str(self) -> &'static str {
match self {
Self::BlockedOnYou => "blocked_on_you",
Self::ReadyToReview => "ready_to_review",
Self::Working => "working",
Self::Idle => "idle",
}
}
/// As people read it.
#[must_use]
pub const fn title(self) -> &'static str {
match self {
Self::BlockedOnYou => "Blocked on you",
Self::ReadyToReview => "Ready to review",
Self::Working => "Working",
Self::Idle => "Idle",
}
}
}
/// What the evidence of finished work leaves to the person, the riskiest
/// first: read from verdicts, attestations, strength, drift and the tick
/// commits' trailers — never from what the model said.
#[derive(
Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize, schemars::JsonSchema,
)]
#[serde(rename_all = "snake_case")]
pub enum Risk {
/// Ticks the regression checks alone decided.
RegressionOnly,
/// Ticks accepted on a person's word.
Attested,
/// Verified ticks whose acceptance strength is below the target.
StrengthBelowTarget,
/// Evidence that proves an earlier wording of the spec.
Stale,
/// Changes outside the paths the task names.
ScopeOutside,
/// Attempts an external agent made.
ExternalExecutor,
}
impl Risk {
/// Every reason, the riskiest first.
pub const ALL: [Self; 6] = [
Self::RegressionOnly,
Self::Attested,
Self::StrengthBelowTarget,
Self::Stale,
Self::ScopeOutside,
Self::ExternalExecutor,
];
/// Its recorded name.
#[must_use]
pub const fn as_str(self) -> &'static str {
match self {
Self::RegressionOnly => "regression_only",
Self::Attested => "attested",
Self::StrengthBelowTarget => "strength_below_target",
Self::Stale => "stale",
Self::ScopeOutside => "scope_outside",
Self::ExternalExecutor => "external_executor",
}
}
/// The chip for `n` ticks with this reason.
#[must_use]
pub fn chip(self, n: usize) -> String {
let ticks = if n == 1 { "tick" } else { "ticks" };
match self {
Self::RegressionOnly => format!("{n} regression-only"),
Self::Attested => format!("{n} attested"),
Self::StrengthBelowTarget => format!("{n} below strength target"),
Self::Stale => format!("{n} stale"),
Self::ScopeOutside => format!("{n} {ticks} outside scope"),
Self::ExternalExecutor => format!("{n} by an agent"),
}
}
}
/// A kind of decision waiting for a person, most urgent first.
#[derive(
Debug,
Clone,
Copy,
PartialEq,
Eq,
Hash,
PartialOrd,
Ord,
Serialize,
Deserialize,
schemars::JsonSchema,
)]
#[serde(rename_all = "snake_case")]
pub enum Kind {
/// The calls waiting in a journal could not be read.
Unknown,
/// A run waits on an approval.
Approval,
/// A run's batch of calls waits for one decision.
ApprovalBatch,
/// A verified attempt is held: its tests reject what the spec allows.
Ruling,
/// A bug's reproductions wait for the person's confirmation.
BugConfirm,
/// A bug could not be reproduced.
BugCannotReproduce,
/// An *Unchanged* statement of a bug does not hold today.
BugUnchangedNotHolding,
/// A special case survived a bug's reproductions.
BugReproWeak,
/// The monitor suspects a shortcut.
Gaming,
/// Most of a feature's ticks are regression-only: one diagnosis.
Unverified,
/// Proven against an earlier wording.
Stale,
/// The spec leaves questions open.
Question,
/// Two independent test authors read a requirement differently: the
/// person says which reading is meant, or rewords it.
Ambiguous,
/// Requirements not approved on their current wording.
Review,
/// Changes requested on the spec.
Revise,
/// A step only a person can take: a `[YOU]` task, or one whose attempt
/// stopped `BLOCKED` — I did it, a hint and a new attempt, or skip.
Yours,
/// The last attempt did not pass.
Stuck,
/// An autopilot run refused calls it would have asked about: listed
/// for the person afterwards.
AutopilotDenied,
/// A bug is already fixed: keep its reproduction, or drop it.
BugAlreadySatisfied,
/// Changes a run set aside.
Aside,
/// A quick change or bug that grew: start a spec from it.
Promote,
/// Planning files a run cannot read yet.
Commit,
/// Every task done: review and hand it off.
Handoff,
}
impl Kind {
/// Every kind, the most urgent first.
pub const ALL: [Self; 23] = [
Self::Unknown,
Self::Approval,
Self::ApprovalBatch,
Self::Ruling,
Self::BugConfirm,
Self::BugCannotReproduce,
Self::BugUnchangedNotHolding,
Self::BugReproWeak,
Self::Gaming,
Self::Unverified,
Self::Stale,
Self::Question,
Self::Ambiguous,
Self::Review,
Self::Revise,
Self::Yours,
Self::Stuck,
Self::AutopilotDenied,
Self::BugAlreadySatisfied,
Self::Aside,
Self::Promote,
Self::Commit,
Self::Handoff,
];
/// Its recorded name.
#[must_use]
pub const fn as_str(self) -> &'static str {
match self {
Self::Unknown => "unknown",
Self::Approval => "approval",
Self::ApprovalBatch => "approval_batch",
Self::Ruling => "ruling",
Self::BugConfirm => "bug_confirm",
Self::BugCannotReproduce => "bug_cannot_reproduce",
Self::BugUnchangedNotHolding => "bug_unchanged_not_holding",
Self::BugReproWeak => "bug_repro_weak",
Self::Gaming => "gaming",
Self::Unverified => "unverified",
Self::Stale => "stale",
Self::Question => "question",
Self::Ambiguous => "ambiguous",
Self::Review => "review",
Self::Revise => "revise",
Self::Yours => "yours",
Self::Stuck => "stuck",
Self::AutopilotDenied => "autopilot_denied",
Self::BugAlreadySatisfied => "bug_already_satisfied",
Self::Aside => "aside",
Self::Promote => "promote",
Self::Commit => "commit",
Self::Handoff => "handoff",
}
}
/// Its group.
#[must_use]
pub const fn group(self) -> Group {
match self {
Self::Unknown
| Self::Approval
| Self::ApprovalBatch
| Self::Ruling
| Self::BugConfirm
| Self::BugCannotReproduce
| Self::BugUnchangedNotHolding
| Self::BugReproWeak
| Self::Gaming
| Self::Question
| Self::Ambiguous
| Self::Revise
| Self::Yours
| Self::Stuck
| Self::Commit => Group::BlockedOnYou,
Self::Unverified
| Self::Stale
| Self::AutopilotDenied
| Self::Review
| Self::BugAlreadySatisfied
| Self::Aside
| Self::Promote
| Self::Handoff => Group::ReadyToReview,
}
}
/// Its urgency: lower is more urgent.
#[must_use]
pub fn rank(self) -> usize {
Self::ALL
.iter()
.position(|k| *k == self)
.unwrap_or(Self::ALL.len())
}
/// The kind recorded as `name`.
#[must_use]
pub fn named(name: &str) -> Option<Self> {
Self::ALL.iter().copied().find(|k| k.as_str() == name)
}
/// Every recorded name, the most urgent first.
#[must_use]
pub fn names() -> [&'static str; 23] {
Self::ALL.map(Self::as_str)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn every_kind_has_one_name_a_group_and_its_place() {
let schema = serde_json::to_value(schemars::schema_for!(Kind)).unwrap_or_default();
let mut named: Vec<String> = schema["oneOf"]
.as_array()
.into_iter()
.flatten()
.filter_map(|v| v["const"].as_str().map(str::to_owned))
.collect();
named.sort();
let mut listed: Vec<String> = Kind::names().iter().map(|n| (*n).to_owned()).collect();
listed.sort();
assert_eq!(named, listed, "Kind::ALL is not the enum");
for (i, k) in Kind::ALL.iter().enumerate() {
assert_eq!(k.rank(), i);
assert_eq!(Kind::named(k.as_str()), Some(*k));
assert_eq!(serde_json::to_value(k).unwrap_or_default(), k.as_str());
}
// Today's kinds keep their order among themselves.
let today: Vec<&str> = Kind::names()
.into_iter()
.filter(|n| {
!n.starts_with("bug_")
&& !matches!(
*n,
"ambiguous" | "autopilot_denied" | "unverified" | "yours" | "promote"
)
})
.collect();
assert_eq!(
today,
[
"unknown",
"approval",
"approval_batch",
"ruling",
"gaming",
"stale",
"question",
"review",
"revise",
"stuck",
"aside",
"commit",
"handoff"
]
);
assert_eq!(Kind::BugAlreadySatisfied.group(), Group::ReadyToReview);
// A kind is blocking or ready, never working or idle.
assert!(
Kind::ALL
.iter()
.all(|k| matches!(k.group(), Group::BlockedOnYou | Group::ReadyToReview))
);
let mut risks = Risk::ALL.to_vec();
risks.sort();
assert_eq!(risks, Risk::ALL, "Risk::ALL is the riskiest-first order");
assert_eq!(Kind::Ambiguous.group(), Group::BlockedOnYou);
assert_eq!(Kind::AutopilotDenied.group(), Group::ReadyToReview);
// First of its group: before `stale`.
assert_eq!(Kind::Unverified.group(), Group::ReadyToReview);
assert_eq!(Kind::Unverified.rank() + 1, Kind::Stale.rank());
for k in [
Kind::BugConfirm,
Kind::BugCannotReproduce,
Kind::BugUnchangedNotHolding,
Kind::BugReproWeak,
] {
assert_eq!(k.group(), Group::BlockedOnYou, "{k:?}");
}
}
}