vtcode 0.99.1

A Rust-based terminal coding agent with modular architecture supporting multiple LLM providers
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
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
mod modal;
mod options;
mod schema;
mod suggestions;

pub(crate) use modal::execute_request_user_input_tool;
pub(crate) use schema::normalize_request_user_input_fallback_args;

#[cfg(test)]
mod tests {
    use super::modal::build_question_items;
    use super::options::{resolve_question_options, sanitize_provided_options};
    use super::schema::{
        RequestUserInputOption, RequestUserInputQuestion, normalize_request_user_input_args,
        normalize_request_user_input_fallback_args,
    };
    use super::suggestions::generate_suggested_options;
    use serde_json::json;
    use vtcode_tui::app::{InlineListSelection, WizardModalMode};

    fn prompt_question_with_hints() -> RequestUserInputQuestion {
        RequestUserInputQuestion {
            id: "system_prompt_plan".to_string(),
            header: "Direction".to_string(),
            question: "Which area should we prioritize to improve plan mode behavior?".to_string(),
            options: None,
            focus_area: Some("system prompt".to_string()),
            analysis_hints: vec!["navigation loop".to_string(), "stream timeout".to_string()],
        }
    }

    #[test]
    fn generates_prompt_specific_suggestions() {
        let question = prompt_question_with_hints();
        let options = generate_suggested_options(&question).expect("expected generated options");

        assert!((1..=3).contains(&options.len()));
        assert!(options[0].label.contains("(Recommended)"));
        assert!(
            options
                .iter()
                .any(|option| option.label.contains("fallback") || option.label.contains("Loop"))
        );
    }

    #[test]
    fn generates_weakness_aware_prompt_options() {
        let question = RequestUserInputQuestion {
            id: "prompt_improvement".to_string(),
            header: "Direction".to_string(),
            question: "Which system prompt improvement should we prioritize?".to_string(),
            options: None,
            focus_area: Some("system_prompt".to_string()),
            analysis_hints: vec![
                "Redundancy exists between prompt variants".to_string(),
                "Missing explicit guidance for failure patterns".to_string(),
            ],
        };

        let options = generate_suggested_options(&question).expect("expected generated options");
        assert!((1..=3).contains(&options.len()));
        assert!(options.iter().any(|opt| {
            opt.label.contains("redundancy")
                || opt.label.contains("Failure pattern")
                || opt.label.contains("Prompt")
        }));
    }

    #[test]
    fn generates_planning_options_for_goal_constraints_questions() {
        let question = RequestUserInputQuestion {
            id: "constraints".to_string(),
            header: "Plan".to_string(),
            question: "Break the work into 3-7 composable steps. For each step include target file(s) and a concrete expected outcome.".to_string(),
            options: None,
            focus_area: None,
            analysis_hints: Vec::new(),
        };

        let options = generate_suggested_options(&question).expect("expected planning options");
        assert!((1..=3).contains(&options.len()));
        assert!(options[0].label.contains("(Recommended)"));
    }

    #[test]
    fn generates_distinct_options_for_outcome_steps_and_verification_questions() {
        let outcome_question = RequestUserInputQuestion {
            id: "q1".to_string(),
            header: "Q1".to_string(),
            question: "What user-visible outcome should this change deliver, and what constraints or non-goals must be respected?".to_string(),
            options: None,
            focus_area: Some("system_prompt".to_string()),
            analysis_hints: vec![
                "Redundancy exists between prompt variants".to_string(),
                "Missing explicit guidance for failure patterns".to_string(),
            ],
        };
        let steps_question = RequestUserInputQuestion {
            id: "q2".to_string(),
            header: "Q2".to_string(),
            question: "Break the work into 3-7 composable steps. For each step include target file(s) and a concrete expected outcome.".to_string(),
            options: None,
            focus_area: Some("system_prompt".to_string()),
            analysis_hints: vec![
                "Redundancy exists between prompt variants".to_string(),
                "Missing explicit guidance for failure patterns".to_string(),
            ],
        };
        let verification_question = RequestUserInputQuestion {
            id: "q3".to_string(),
            header: "Q3".to_string(),
            question: "For each step, what exact command or manual check proves it is complete?"
                .to_string(),
            options: None,
            focus_area: Some("system_prompt".to_string()),
            analysis_hints: vec![
                "Redundancy exists between prompt variants".to_string(),
                "Missing explicit guidance for failure patterns".to_string(),
            ],
        };

        let outcome = generate_suggested_options(&outcome_question).expect("outcome options");
        let steps = generate_suggested_options(&steps_question).expect("step options");
        let verification =
            generate_suggested_options(&verification_question).expect("verification options");

        let outcome_labels = outcome
            .iter()
            .map(|opt| opt.label.clone())
            .collect::<Vec<_>>();
        let step_labels = steps
            .iter()
            .map(|opt| opt.label.clone())
            .collect::<Vec<_>>();
        let verification_labels = verification
            .iter()
            .map(|opt| opt.label.clone())
            .collect::<Vec<_>>();

        assert_ne!(outcome_labels, step_labels);
        assert_ne!(step_labels, verification_labels);
        assert_ne!(outcome_labels, verification_labels);

        assert!(outcome[0].label.contains("Recommended"));
        assert!(steps[0].label.contains("Recommended"));
        assert!(verification[0].label.contains("Recommended"));
    }

    #[test]
    fn provided_duplicate_options_are_regenerated_per_question() {
        let duplicate_options = vec![
            RequestUserInputOption {
                label: "Minimal implementation slice (Recommended)".to_string(),
                description: "Ship only the smallest possible scope.".to_string(),
            },
            RequestUserInputOption {
                label: "Balanced implementation".to_string(),
                description: "Ship medium scope with moderate risk.".to_string(),
            },
            RequestUserInputOption {
                label: "Comprehensive implementation".to_string(),
                description: "Ship full scope with deeper validation.".to_string(),
            },
        ];

        let questions = vec![
            RequestUserInputQuestion {
                id: "goal".to_string(),
                header: "Goal".to_string(),
                question: "What user-visible outcome should this change deliver, and what constraints or non-goals must be respected?".to_string(),
                options: Some(duplicate_options.clone()),
                focus_area: None,
                analysis_hints: Vec::new(),
            },
            RequestUserInputQuestion {
                id: "constraints".to_string(),
                header: "Plan".to_string(),
                question: "Break the work into 3-7 composable steps. For each step include target file(s) and a concrete expected outcome.".to_string(),
                options: Some(duplicate_options.clone()),
                focus_area: None,
                analysis_hints: Vec::new(),
            },
            RequestUserInputQuestion {
                id: "verification".to_string(),
                header: "Verification".to_string(),
                question: "For each step, what exact command or manual check proves it is complete?"
                    .to_string(),
                options: Some(duplicate_options),
                focus_area: None,
                analysis_hints: Vec::new(),
            },
        ];

        let resolved = resolve_question_options(&questions);
        assert_eq!(resolved.len(), 3);

        let goal_labels = resolved[0]
            .as_ref()
            .expect("goal options should resolve")
            .iter()
            .map(|option| option.label.clone())
            .collect::<Vec<_>>();
        let step_labels = resolved[1]
            .as_ref()
            .expect("step options should resolve")
            .iter()
            .map(|option| option.label.clone())
            .collect::<Vec<_>>();
        let verification_labels = resolved[2]
            .as_ref()
            .expect("verification options should resolve")
            .iter()
            .map(|option| option.label.clone())
            .collect::<Vec<_>>();

        assert_ne!(goal_labels, step_labels);
        assert_ne!(step_labels, verification_labels);
        assert_ne!(goal_labels, verification_labels);
    }

    #[test]
    fn valid_provided_options_are_preserved() {
        let provided_options = vec![
            RequestUserInputOption {
                label: "Outcome KPI (Recommended)".to_string(),
                description: "Define one measurable user-visible result.".to_string(),
            },
            RequestUserInputOption {
                label: "Constraint checklist".to_string(),
                description: "Lock boundaries before implementation.".to_string(),
            },
            RequestUserInputOption {
                label: "MVP boundary".to_string(),
                description: "Limit scope to the smallest deliverable.".to_string(),
            },
        ];

        let questions = vec![RequestUserInputQuestion {
            id: "goal".to_string(),
            header: "Goal".to_string(),
            question: "What user-visible outcome should this change deliver, and what constraints or non-goals must be respected?".to_string(),
            options: Some(provided_options.clone()),
            focus_area: None,
            analysis_hints: Vec::new(),
        }];

        let resolved = resolve_question_options(&questions);
        let resolved_options = resolved[0]
            .as_ref()
            .expect("provided options should be preserved");

        assert_eq!(resolved_options.len(), provided_options.len());
        for (resolved_option, provided_option) in resolved_options.iter().zip(provided_options) {
            assert_eq!(resolved_option.label, provided_option.label);
            assert_eq!(resolved_option.description, provided_option.description);
        }
    }

    #[test]
    fn id_keyword_does_not_override_question_text_intent() {
        let question = RequestUserInputQuestion {
            id: "constraints".to_string(),
            header: "Plan".to_string(),
            question: "For each step, what exact command or manual check proves it is complete?"
                .to_string(),
            options: None,
            focus_area: None,
            analysis_hints: Vec::new(),
        };

        let options = generate_suggested_options(&question).expect("verification options");
        let labels = options
            .iter()
            .map(|option| option.label.to_lowercase())
            .collect::<Vec<_>>();

        assert!(
            labels
                .iter()
                .any(|label| label.contains("command-based proof"))
        );
        assert!(
            !labels
                .iter()
                .any(|label| label.contains("dependency-first slices"))
        );
    }

    #[test]
    fn option_questions_add_explicit_custom_note_choice() {
        let question = RequestUserInputQuestion {
            id: "scope".to_string(),
            header: "Scope".to_string(),
            question: "Pick direction".to_string(),
            options: Some(vec![
                RequestUserInputOption {
                    label: "Option A".to_string(),
                    description: "A".to_string(),
                },
                RequestUserInputOption {
                    label: "Option B".to_string(),
                    description: "B".to_string(),
                },
            ]),
            focus_area: None,
            analysis_hints: Vec::new(),
        };

        let items = build_question_items(&question);
        assert_eq!(items.len(), 3);
        assert!(items[2].title.contains("Custom note"));

        let selection = items[2]
            .selection
            .clone()
            .expect("expected selection for other choice");
        match selection {
            InlineListSelection::RequestUserInputAnswer {
                selected, other, ..
            } => {
                assert!(selected.is_empty());
                assert_eq!(other, Some(String::new()));
            }
            _ => panic!("expected request_user_input selection"),
        }
    }

    #[test]
    fn falls_back_to_generic_options_when_no_suggestions_apply() {
        let question = RequestUserInputQuestion {
            id: "env".to_string(),
            header: "Env".to_string(),
            question: "What environment are you using?".to_string(),
            options: None,
            focus_area: None,
            analysis_hints: Vec::new(),
        };

        let items = build_question_items(&question);
        assert_eq!(items.len(), 4);
        assert!(items[0].title.contains("(Recommended)"));
        assert!(items[3].title.contains("Custom note"));
    }

    #[test]
    fn structured_payload_normalizes_to_multi_step_mode() {
        let args = json!({
            "questions": [
                {
                    "id": "scope",
                    "header": "Scope",
                    "question": "Which direction should we take?",
                    "options": [
                        {"label": "Minimal (Recommended)", "description": "Smallest viable slice"},
                        {"label": "Full", "description": "Complete implementation"}
                    ]
                }
            ]
        });

        let normalized = normalize_request_user_input_args(&args).expect("normalize structured");
        assert_eq!(normalized.args.questions.len(), 1);
        assert_eq!(normalized.wizard_mode, WizardModalMode::MultiStep);
        assert_eq!(normalized.current_step, 0);
        assert_eq!(normalized.title_override, None);
        assert_eq!(normalized.freeform_label.as_deref(), Some("Custom note"));
        assert_eq!(
            normalized.freeform_placeholder.as_deref(),
            Some("Type your response...")
        );
    }

    #[test]
    fn legacy_payload_is_rejected() {
        let legacy_args = json!({
            "question": "Choose one",
            "tabs": [
                {
                    "id": "scope",
                    "title": "Scope",
                    "items": [
                        {"id": "minimal", "title": "Minimal scope"},
                        {"id": "full", "title": "Full scope"}
                    ]
                }
            ]
        });
        let result = normalize_request_user_input_args(&legacy_args);
        assert!(result.is_err());
    }

    #[test]
    fn fallback_normalizes_legacy_tabbed_payload() {
        let legacy_args = json!({
            "question": "Choose one",
            "tabs": [
                {
                    "id": "scope",
                    "title": "Scope",
                    "items": [
                        {"id": "minimal", "title": "Minimal scope"},
                        {"id": "full", "title": "Full scope"}
                    ]
                }
            ]
        });

        let normalized = normalize_request_user_input_fallback_args(&legacy_args)
            .expect("fallback should normalize legacy shape");
        assert_eq!(normalized["questions"][0]["id"], "scope");
        assert_eq!(normalized["questions"][0]["header"], "Scope");
        assert_eq!(normalized["questions"][0]["question"], "Choose one");
        assert_eq!(
            normalized["questions"][0]["options"]
                .as_array()
                .map(|options| options.len()),
            Some(2)
        );
    }

    #[test]
    fn fallback_normalizes_single_question_shorthand() {
        let args = json!({
            "question": "Which direction should we take?",
            "header": "Scope",
            "options": ["Minimal", "Full", "Minimal"]
        });

        let normalized = normalize_request_user_input_fallback_args(&args)
            .expect("fallback should normalize shorthand");
        assert_eq!(normalized["questions"][0]["id"], "question_1");
        assert_eq!(normalized["questions"][0]["header"], "Scope");
        assert_eq!(
            normalized["questions"][0]["question"],
            "Which direction should we take?"
        );
        assert_eq!(
            normalized["questions"][0]["options"]
                .as_array()
                .map(|options| options.len()),
            Some(2)
        );
    }

    #[test]
    fn normalize_rejects_non_snake_case_ids() {
        let args = json!({
            "questions": [
                {
                    "id": "GoalQuestion",
                    "header": "Goal",
                    "question": "What outcome matters most?"
                }
            ]
        });

        let result = normalize_request_user_input_args(&args);
        assert!(result.is_err());
    }

    #[test]
    fn normalize_rejects_headers_over_twelve_chars() {
        let args = json!({
            "questions": [
                {
                    "id": "goal",
                    "header": "HeaderTooLong",
                    "question": "What outcome matters most?"
                }
            ]
        });

        let result = normalize_request_user_input_args(&args);
        assert!(result.is_err());
    }

    #[test]
    fn sanitize_provided_options_drops_other_and_duplicates() {
        let options = vec![
            RequestUserInputOption {
                label: "A (Recommended)".to_string(),
                description: "Choice A".to_string(),
            },
            RequestUserInputOption {
                label: "Other".to_string(),
                description: "Custom response".to_string(),
            },
            RequestUserInputOption {
                label: "A".to_string(),
                description: "Duplicate A".to_string(),
            },
            RequestUserInputOption {
                label: "B".to_string(),
                description: "Choice B".to_string(),
            },
        ];

        let sanitized = sanitize_provided_options(&options);
        let labels = sanitized
            .iter()
            .map(|option| option.label.as_str())
            .collect::<Vec<_>>();
        assert_eq!(labels, vec!["A (Recommended)", "B"]);
    }
}