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
// Roadmap type definitions: structs, enums, constants, serde helpers
//
// Included by roadmap.rs — shares parent scope, no `use` imports needed.
/// Roadmap YAML schema version
pub const ROADMAP_VERSION: &str = "1.0";
/// Main roadmap structure
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct Roadmap {
/// Schema version
pub roadmap_version: String,
/// GitHub integration enabled
#[serde(
default = "default_github_enabled",
deserialize_with = "deserialize_bool_lenient"
)]
pub github_enabled: bool,
/// GitHub repository (owner/repo)
pub github_repo: Option<String>,
/// List of roadmap items (tickets)
#[serde(default)]
pub roadmap: Vec<RoadmapItem>,
}
fn default_github_enabled() -> bool {
true
}
/// Lenient boolean deserializer: accepts both native YAML booleans and quoted strings "true"/"false"
fn deserialize_bool_lenient<'de, D>(deserializer: D) -> Result<bool, D::Error>
where
D: serde::Deserializer<'de>,
{
use serde::de;
struct BoolVisitor;
impl<'de> de::Visitor<'de> for BoolVisitor {
type Value = bool;
fn expecting(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
f.write_str("a boolean or string \"true\"/\"false\"")
}
fn visit_bool<E: de::Error>(self, v: bool) -> Result<bool, E> {
Ok(v)
}
fn visit_str<E: de::Error>(self, v: &str) -> Result<bool, E> {
match v {
"true" => Ok(true),
"false" => Ok(false),
_ => Err(E::custom(format!("expected true/false, got '{}'", v))),
}
}
}
deserializer.deserialize_any(BoolVisitor)
}
fn default_timestamp() -> String {
"1970-01-01T00:00:00Z".to_string()
}
impl Default for Roadmap {
fn default() -> Self {
Self {
roadmap_version: ROADMAP_VERSION.to_string(),
github_enabled: true,
github_repo: None,
roadmap: Vec::new(),
}
}
}
/// Individual roadmap item (ticket/issue)
///
/// Note: Extra fields in YAML (like description, implementation, references)
/// are silently ignored to support backward compatibility with older roadmap formats.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct RoadmapItem {
/// Unique ID (e.g., "GH-8", "PERF-001", "EPIC-001")
pub id: String,
/// GitHub issue number (null if YAML-only)
pub github_issue: Option<u64>,
/// Item type (task, epic, bug, etc.)
#[serde(default = "default_item_type")]
pub item_type: ItemType,
/// Title
pub title: String,
/// Current status
pub status: ItemStatus,
/// Priority level
#[serde(default)]
pub priority: Priority,
/// Assigned to (GitHub username with @)
pub assigned_to: Option<String>,
/// Created timestamp (ISO 8601)
#[serde(default = "default_timestamp")]
pub created: String,
/// Last updated timestamp (ISO 8601)
#[serde(default = "default_timestamp")]
pub updated: String,
/// Path to specification file
pub spec: Option<PathBuf>,
/// Acceptance criteria (checklist)
#[serde(default)]
pub acceptance_criteria: Vec<String>,
/// Phases (for multi-phase work)
#[serde(default, deserialize_with = "deserialize_phases")]
pub phases: Vec<Phase>,
/// Subtasks (for epic items)
#[serde(default)]
pub subtasks: Vec<Subtask>,
/// Estimated effort (human-readable)
pub estimated_effort: Option<String>,
/// Labels/tags
#[serde(default)]
pub labels: Vec<String>,
/// Additional notes/documentation (markdown)
#[serde(default)]
pub notes: Option<String>,
}
fn default_item_type() -> ItemType {
ItemType::Task
}
/// Item type enumeration
#[derive(Debug, Clone, Copy, Serialize, PartialEq, Eq)]
#[serde(rename_all = "lowercase")]
pub enum ItemType {
Task,
Epic,
Bug,
Feature,
Enhancement,
Documentation,
Refactor,
}
impl ItemType {
/// Every accepted spelling, in the order the error message lists them.
pub const VALID_VALUES: &'static [&'static str] = &[
"task",
"epic",
"bug",
"feature",
"enhancement",
"documentation",
"refactor",
];
/// Parse an `item_type`, strictly.
///
/// Unlike `status`, this is exact-lowercase with no aliases and no
/// separator folding — `Bug` is an error, by design, and
/// `test_item_type_and_priority_are_strict_lowercase` pins that. The only
/// thing added over serde's derived impl is the typo hint: #628 asked for
/// the `did you mean` suggestion that `status` has, because a wrong
/// `item_type` was the *first* of three fix-and-rerun cycles on a
/// 1300-entry roadmap and serde's stock message offers no candidate.
pub fn from_string(s: &str) -> Result<Self, String> {
match s {
"task" => Ok(Self::Task),
"epic" => Ok(Self::Epic),
"bug" => Ok(Self::Bug),
"feature" => Ok(Self::Feature),
"enhancement" => Ok(Self::Enhancement),
"documentation" => Ok(Self::Documentation),
"refactor" => Ok(Self::Refactor),
_ => Err(format!(
"unknown item_type '{}'{}\n\nValid values: {}\n\
(exact lowercase; unlike 'status', no aliases and no case folding)",
s,
suggest_from(s, Self::VALID_VALUES),
Self::VALID_VALUES.join(", ")
)),
}
}
}
impl<'de> serde::Deserialize<'de> for ItemType {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
let s = String::deserialize(deserializer)?;
ItemType::from_string(&s).map_err(serde::de::Error::custom)
}
}
/// Nearest-match hint, or nothing when no candidate is close enough.
///
/// The cutoff keeps the message honest: pointing `verification` at `refactor`
/// would be noise, and #628 praised the status hint precisely because it was
/// right. Comparing against the input lowercased means a case error (`Bug`)
/// still gets pointed at `bug`, which is the most common way to hit this.
fn suggest_from(input: &str, candidates: &[&str]) -> String {
let normalized = input.to_lowercase();
candidates
.iter()
.map(|c| (levenshtein_distance(&normalized, c), *c))
// Bound by the SHORTER of the two words. Scaling the cutoff by the
// candidate alone let the long candidates swallow unrelated inputs
// (`defect` is 4 edits from `refactor`, within `refactor`'s budget of
// 4, so it was confidently suggested; `question` reached
// `documentation` at 7 edits) while the short ones rejected near
// misses. Comparing against the input too keeps the hint honest in
// both directions.
.filter(|(distance, candidate)| {
*distance <= normalized.len().min(candidate.len()).div_ceil(2)
})
.min()
.map(|(_, candidate)| format!(" (did you mean '{}'?)", candidate))
.unwrap_or_default()
}
/// Priority enumeration
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Default)]
#[serde(rename_all = "lowercase")]
pub enum Priority {
Low,
#[default]
Medium,
High,
Critical,
}
/// Phase within a roadmap item
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct Phase {
/// Phase name
pub name: String,
/// Phase status
pub status: ItemStatus,
/// Estimated effort
pub estimated_effort: Option<String>,
/// Completion percentage (0-100)
#[serde(default)]
pub completion: u8,
}
/// Subtask within an epic
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct Subtask {
/// Subtask ID
pub id: String,
/// GitHub issue number (if synced)
pub github_issue: Option<u64>,
/// Subtask title
pub title: String,
/// Subtask status
pub status: ItemStatus,
/// Completion percentage (0-100)
#[serde(default)]
pub completion: u8,
}
/// Custom deserializer for phases that provides helpful error messages (issue #130)
fn deserialize_phases<'de, D>(deserializer: D) -> Result<Vec<Phase>, D::Error>
where
D: serde::Deserializer<'de>,
{
use serde::de::{self, SeqAccess, Visitor};
use std::fmt;
struct PhasesVisitor;
impl<'de> Visitor<'de> for PhasesVisitor {
type Value = Vec<Phase>;
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
formatter.write_str("a sequence of Phase structs")
}
fn visit_seq<A>(self, mut seq: A) -> Result<Self::Value, A::Error>
where
A: SeqAccess<'de>,
{
let mut phases = Vec::new();
let mut index = 0;
while let Some(value) = seq.next_element::<serde_yaml_ng::Value>()? {
match value {
serde_yaml_ng::Value::String(s) => {
return Err(de::Error::custom(format!(
"phases[{}]: invalid type. \
Phases must be structs with 'name' and 'status' fields.\n\n\
Example:\n \
phases:\n \
- name: \"{}\"\n \
status: planned\n\n\
Found string: \"{}\"",
index, s, s
)));
}
serde_yaml_ng::Value::Mapping(_) => {
let phase: Phase =
serde_yaml_ng::from_value(value).map_err(de::Error::custom)?;
phases.push(phase);
}
_ => {
return Err(de::Error::custom(format!(
"phases[{}]: expected a Phase struct, found {:?}",
index, value
)));
}
}
index += 1;
}
Ok(phases)
}
}
deserializer.deserialize_seq(PhasesVisitor)
}