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
use super::*;
use std::collections::BTreeMap;
use vtcode_core::config::core::PromptCachingConfig;
use vtcode_core::config::models::Provider;
use vtcode_core::config::types::{ModelSelectionSource, ReasoningEffortLevel, UiSurfacePreference};
use vtcode_core::core::agent::snapshots::{
    DEFAULT_CHECKPOINTS_ENABLED, DEFAULT_MAX_AGE_DAYS, DEFAULT_MAX_SNAPSHOTS,
};

#[tokio::test]
async fn test_prompt_refinement_applies_to_gemini_when_flag_disabled() {
    unsafe {
        std::env::set_var("VTCODE_PROMPT_REFINER_STUB", "1");
    }

    let cfg = CoreAgentConfig {
        model: vtcode_core::config::constants::models::google::GEMINI_3_FLASH_PREVIEW.to_string(),
        api_key: "test".to_string(),
        provider: "gemini".to_string(),
        api_key_env: Provider::Gemini.default_api_key_env().to_string(),
        workspace: std::env::current_dir().unwrap(),
        verbose: false,
        theme: vtcode_core::ui::theme::DEFAULT_THEME_ID.to_string(),
        reasoning_effort: ReasoningEffortLevel::default(),
        ui_surface: UiSurfacePreference::default(),
        prompt_cache: PromptCachingConfig::default(),
        model_source: ModelSelectionSource::WorkspaceConfig,
        custom_api_keys: BTreeMap::new(),
        checkpointing_enabled: DEFAULT_CHECKPOINTS_ENABLED,
        checkpointing_storage_dir: None,
        checkpointing_max_snapshots: DEFAULT_MAX_SNAPSHOTS,
        checkpointing_max_age_days: Some(DEFAULT_MAX_AGE_DAYS),
        quiet: false,
        max_conversation_turns: 1000,
        model_behavior: None,
        openai_chatgpt_auth: None,
    };

    let mut vt = VTCodeConfig::default();
    vt.agent.refine_prompts_enabled = true;

    let raw = "make me a list of files";
    let out = refine_user_prompt_if_enabled(raw, &cfg, Some(&vt)).await;

    assert!(out.starts_with("[REFINED] "));

    unsafe {
        std::env::remove_var("VTCODE_PROMPT_REFINER_STUB");
    }
}

#[test]
fn test_should_attempt_refinement_skips_short_inputs() {
    assert!(!should_attempt_refinement("hi"));
    assert!(!should_attempt_refinement("add docs"));
    assert!(should_attempt_refinement(
        "summarize the latest commit changes"
    ));
}

#[test]
fn test_should_accept_refinement_rejects_role_play() {
    let raw = "hello";
    let refined = "Hello! How can I help you today?";
    assert!(!should_accept_refinement(raw, refined));

    let technical_raw = "describe vtcode streaming parser";
    let technical_refined =
        "Provide a detailed description of the vtcode streaming parser implementation.";
    assert!(should_accept_refinement(technical_raw, technical_refined));
}

#[test]
fn test_finalize_refined_prompt_uses_canonical_diagnostic_tools() {
    let refined = finalize_refined_prompt("debug the failing command".to_string());

    assert!(refined.contains("`unified_search`"));
    assert!(refined.contains("`unified_exec`"));
    assert!(!refined.contains("debug_agent"));
    assert!(!refined.contains("search_tools"));
}

// Vibe coding tests
#[test]
fn test_detect_vague_references() {
    let prompt = "make it blue";
    let refs = detect_vague_references(prompt);
    assert_eq!(refs.len(), 1);
    assert_eq!(refs[0].term, "it");

    let prompt2 = "fix that bug in the sidebar";
    let refs2 = detect_vague_references(prompt2);
    assert_eq!(refs2.len(), 2); // "that" and "the"
    assert!(refs2.iter().any(|r| r.term == "that"));
    assert!(refs2.iter().any(|r| r.term == "the"));

    let prompt3 = "decrease the padding by half";
    let refs3 = detect_vague_references(prompt3);
    assert_eq!(refs3.len(), 1);
    assert_eq!(refs3[0].term, "the");
}

#[test]
fn test_detect_vague_references_no_matches() {
    let prompt = "create a new function called handleSubmit";
    let refs = detect_vague_references(prompt);
    assert_eq!(refs.len(), 0); // "a" is not in VAGUE_PATTERNS, so no matches
}

#[test]
fn test_enriched_prompt_to_llm_prompt() {
    let mut enriched = EnrichedPrompt::new("make it blue".to_string());

    enriched.add_resolution(EntityResolution {
        original: "it".to_string(),
        resolved: "Sidebar".to_string(),
        file: "src/components/Sidebar.tsx".to_string(),
        line: 15,
        confidence: 0.95,
    });

    enriched.add_recent_file("src/styles/main.css".to_string());
    enriched.add_inferred_value("blue".to_string(), "#0000FF".to_string());

    let prompt = enriched.to_llm_prompt();

    assert!(prompt.contains("User request: make it blue"));
    assert!(prompt.contains("Resolved references:"));
    assert!(prompt.contains("\"it\" → Sidebar"));
    assert!(prompt.contains("src/components/Sidebar.tsx:15"));
    assert!(prompt.contains("confidence: 95%"));
    assert!(prompt.contains("Recent context:"));
    assert!(prompt.contains("src/styles/main.css"));
    assert!(prompt.contains("Inferred values:"));
    assert!(prompt.contains("\"blue\" → #0000FF"));
}

#[test]
fn test_should_enrich_prompt_disabled() {
    let vt_cfg = VTCodeConfig::default();
    // Default has vibe_coding.enabled = false

    let prompt = "make it blue";
    assert!(!should_enrich_prompt(prompt, Some(&vt_cfg)));
}

#[test]
fn test_should_enrich_prompt_enabled() {
    let mut vt_cfg = VTCodeConfig::default();
    vt_cfg.agent.vibe_coding.enabled = true;

    // Has vague reference "it"
    let prompt = "make it blue";
    assert!(should_enrich_prompt(prompt, Some(&vt_cfg)));

    // No vague references
    let prompt2 = "create a new function";
    assert!(!should_enrich_prompt(prompt2, Some(&vt_cfg)));
}

#[test]
fn test_should_enrich_prompt_too_short() {
    let mut vt_cfg = VTCodeConfig::default();
    vt_cfg.agent.vibe_coding.enabled = true;
    vt_cfg.agent.vibe_coding.min_prompt_length = 10;
    vt_cfg.agent.vibe_coding.min_prompt_words = 3;

    // Too short (2 words)
    let prompt = "make it";
    assert!(!should_enrich_prompt(prompt, Some(&vt_cfg)));

    // Long enough (3 words)
    let prompt2 = "make it blue";
    assert!(should_enrich_prompt(prompt2, Some(&vt_cfg)));
}

#[tokio::test]
async fn test_prompt_enricher_new() {
    let workspace_root = std::env::current_dir().unwrap();
    let vt_cfg = VTCodeConfig::default();

    let enricher = PromptEnricher::new(workspace_root, vt_cfg);

    // Verify components are initialized
    assert!(enricher.entity_resolver.read().await.index_is_empty());
    let state = enricher.workspace_state.read().await;
    assert_eq!(state.recent_files(10).len(), 0);
}

#[tokio::test]
async fn test_prompt_enricher_enrich_no_vague_refs() {
    let workspace_root = std::env::current_dir().unwrap();
    let mut vt_cfg = VTCodeConfig::default();
    vt_cfg.agent.vibe_coding.enabled = true;

    let enricher = PromptEnricher::new(workspace_root, vt_cfg);

    let prompt = "create a new function called handleSubmit";
    let enriched = enricher.enrich_vague_prompt(prompt).await;

    // No vague references, should return original
    assert_eq!(enriched.original, prompt);
    assert_eq!(enriched.resolutions.len(), 0);
}

#[tokio::test]
async fn test_prompt_enricher_enrich_with_vague_refs() {
    let workspace_root = std::env::current_dir().unwrap();
    let mut vt_cfg = VTCodeConfig::default();
    vt_cfg.agent.vibe_coding.enabled = true;
    vt_cfg.agent.vibe_coding.enable_entity_resolution = true;
    vt_cfg.agent.vibe_coding.track_workspace_state = true;

    let enricher = PromptEnricher::new(workspace_root, vt_cfg);

    // Add a recent file to workspace state
    {
        let mut state = enricher.workspace_state.write().await;
        state.record_file_access(
            &PathBuf::from("src/test.rs"),
            vtcode_core::context::workspace_state::ActivityType::Edit,
        );
    }

    let prompt = "make it blue";
    let enriched = enricher.enrich_vague_prompt(prompt).await;

    // Should detect "it" as vague reference
    assert_eq!(enriched.original, prompt);
    // Should have recent file added
    assert_eq!(enriched.recent_files.len(), 1);
    assert_eq!(enriched.recent_files[0], "src/test.rs");
}

#[tokio::test]
async fn test_prompt_enricher_to_llm_prompt_format() {
    let workspace_root = std::env::current_dir().unwrap();
    let mut vt_cfg = VTCodeConfig::default();
    vt_cfg.agent.vibe_coding.enabled = true;
    vt_cfg.agent.vibe_coding.track_workspace_state = true;

    let enricher = PromptEnricher::new(workspace_root, vt_cfg);

    // Add a recent file
    {
        let mut state = enricher.workspace_state.write().await;
        state.record_file_access(
            &PathBuf::from("src/components/Sidebar.tsx"),
            vtcode_core::context::workspace_state::ActivityType::Edit,
        );
    }

    let prompt = "update this component";
    let enriched = enricher.enrich_vague_prompt(prompt).await;
    let llm_prompt = enriched.to_llm_prompt();

    // Verify format
    assert!(llm_prompt.contains("User request:"));
    assert!(llm_prompt.contains("update this component"));
    assert!(llm_prompt.contains("Recent context:"));
    assert!(llm_prompt.contains("src/components/Sidebar.tsx"));
}

// Phase 3 Integration Tests
#[tokio::test]
async fn test_refine_and_enrich_prompt_disabled() {
    let workspace_root = std::env::current_dir().unwrap();
    let cfg = CoreAgentConfig {
        model: "test-model".to_string(),
        api_key: "test-key".to_string(),
        provider: "test".to_string(),
        api_key_env: "TEST_API_KEY".to_string(),
        workspace: workspace_root,
        verbose: false,
        theme: vtcode_core::ui::theme::DEFAULT_THEME_ID.to_string(),
        reasoning_effort: ReasoningEffortLevel::default(),
        ui_surface: UiSurfacePreference::default(),
        prompt_cache: PromptCachingConfig::default(),
        model_source: ModelSelectionSource::WorkspaceConfig,
        custom_api_keys: BTreeMap::new(),
        checkpointing_enabled: DEFAULT_CHECKPOINTS_ENABLED,
        checkpointing_storage_dir: None,
        checkpointing_max_snapshots: DEFAULT_MAX_SNAPSHOTS,
        checkpointing_max_age_days: Some(DEFAULT_MAX_AGE_DAYS),
        quiet: false,
        max_conversation_turns: 1000,
        model_behavior: None,
        openai_chatgpt_auth: None,
    };

    let vt_cfg = VTCodeConfig::default(); // vibe_coding disabled by default

    let prompt = "make it blue";
    let result = refine_and_enrich_prompt(prompt, &cfg, Some(&vt_cfg)).await;

    // Should return original since vibe coding is disabled
    assert_eq!(result, prompt);
}

#[tokio::test]
async fn test_refine_and_enrich_prompt_enabled() {
    let workspace_root = std::env::current_dir().unwrap();
    let cfg = CoreAgentConfig {
        model: "test-model".to_string(),
        api_key: "test-key".to_string(),
        provider: "test".to_string(),
        api_key_env: "TEST_API_KEY".to_string(),
        workspace: workspace_root,
        verbose: false,
        theme: vtcode_core::ui::theme::DEFAULT_THEME_ID.to_string(),
        reasoning_effort: ReasoningEffortLevel::default(),
        ui_surface: UiSurfacePreference::default(),
        prompt_cache: PromptCachingConfig::default(),
        model_source: ModelSelectionSource::WorkspaceConfig,
        custom_api_keys: BTreeMap::new(),
        checkpointing_enabled: DEFAULT_CHECKPOINTS_ENABLED,
        checkpointing_storage_dir: None,
        checkpointing_max_snapshots: DEFAULT_MAX_SNAPSHOTS,
        checkpointing_max_age_days: Some(DEFAULT_MAX_AGE_DAYS),
        quiet: false,
        max_conversation_turns: 1000,
        model_behavior: None,
        openai_chatgpt_auth: None,
    };

    let mut vt_cfg = VTCodeConfig::default();
    vt_cfg.agent.vibe_coding.enabled = true;

    let prompt = "make it blue";
    let result = refine_and_enrich_prompt(prompt, &cfg, Some(&vt_cfg)).await;

    // Should be enriched with context
    assert!(result.contains("User request:"));
    assert!(result.contains("make it blue"));
}

#[tokio::test]
async fn test_refine_and_enrich_prompt_no_vague_refs() {
    let workspace_root = std::env::current_dir().unwrap();
    let cfg = CoreAgentConfig {
        model: "test-model".to_string(),
        api_key: "test-key".to_string(),
        provider: "test".to_string(),
        api_key_env: "TEST_API_KEY".to_string(),
        workspace: workspace_root,
        verbose: false,
        theme: vtcode_core::ui::theme::DEFAULT_THEME_ID.to_string(),
        reasoning_effort: ReasoningEffortLevel::default(),
        ui_surface: UiSurfacePreference::default(),
        prompt_cache: PromptCachingConfig::default(),
        model_source: ModelSelectionSource::WorkspaceConfig,
        custom_api_keys: BTreeMap::new(),
        checkpointing_enabled: DEFAULT_CHECKPOINTS_ENABLED,
        checkpointing_storage_dir: None,
        checkpointing_max_snapshots: DEFAULT_MAX_SNAPSHOTS,
        checkpointing_max_age_days: Some(DEFAULT_MAX_AGE_DAYS),
        quiet: false,
        max_conversation_turns: 1000,
        model_behavior: None,
        openai_chatgpt_auth: None,
    };

    let mut vt_cfg = VTCodeConfig::default();
    vt_cfg.agent.vibe_coding.enabled = true;

    // Prompt with no vague references
    let prompt = "create a new function called handleSubmit";
    let result = refine_and_enrich_prompt(prompt, &cfg, Some(&vt_cfg)).await;

    // Should return original since no vague references detected
    assert_eq!(result, prompt);
}

// Phase 4: End-to-End Value Inference Tests
#[tokio::test]
async fn test_value_inference_decrease_by_half_milestone() {
    use std::path::PathBuf;

    let workspace_root = std::env::current_dir().unwrap();
    let _cfg = CoreAgentConfig {
        model: "test-model".to_string(),
        api_key: "test-key".to_string(),
        provider: "test".to_string(),
        api_key_env: "TEST_API_KEY".to_string(),
        workspace: workspace_root.clone(),
        verbose: false,
        theme: vtcode_core::ui::theme::DEFAULT_THEME_ID.to_string(),
        reasoning_effort: ReasoningEffortLevel::default(),
        ui_surface: UiSurfacePreference::default(),
        prompt_cache: PromptCachingConfig::default(),
        model_source: ModelSelectionSource::WorkspaceConfig,
        custom_api_keys: BTreeMap::new(),
        checkpointing_enabled: DEFAULT_CHECKPOINTS_ENABLED,
        checkpointing_storage_dir: None,
        checkpointing_max_snapshots: DEFAULT_MAX_SNAPSHOTS,
        checkpointing_max_age_days: Some(DEFAULT_MAX_AGE_DAYS),
        quiet: false,
        max_conversation_turns: 1000,
        model_behavior: None,
        openai_chatgpt_auth: None,
    };

    let mut vt_cfg = VTCodeConfig::default();
    vt_cfg.agent.vibe_coding.enabled = true;
    vt_cfg.agent.vibe_coding.enable_relative_value_inference = true;
    vt_cfg.agent.vibe_coding.track_workspace_state = true;

    // Create enricher to set up workspace state
    let enricher = PromptEnricher::new(workspace_root.clone(), vt_cfg.clone());

    // Simulate recent file edit with padding value
    enricher
        .record_workspace_change_for_test(
            PathBuf::from("src/styles.css"),
            Some("  padding: 32px;".to_string()),
            "  padding: 32px;".to_string(),
        )
        .await;

    // Test "decrease the padding by half"
    let prompt = "decrease the padding by half";
    let enriched = enricher.enrich_vague_prompt(prompt).await;

    // Should detect "the" as vague reference and infer value
    assert!(enriched.original.contains("padding"));
    assert!(!enriched.inferred_values.is_empty());

    // Should calculate half of 32 = 16
    let (_expr, value) = &enriched.inferred_values[0];
    assert!(value.contains("16"));
}

#[tokio::test]
async fn test_value_inference_multiple_patterns() {
    use std::path::PathBuf;

    let workspace_root = std::env::current_dir().unwrap();
    let _cfg = CoreAgentConfig {
        model: "test-model".to_string(),
        api_key: "test-key".to_string(),
        provider: "test".to_string(),
        api_key_env: "TEST_API_KEY".to_string(),
        workspace: workspace_root.clone(),
        verbose: false,
        theme: vtcode_core::ui::theme::DEFAULT_THEME_ID.to_string(),
        reasoning_effort: ReasoningEffortLevel::default(),
        ui_surface: UiSurfacePreference::default(),
        prompt_cache: PromptCachingConfig::default(),
        model_source: ModelSelectionSource::WorkspaceConfig,
        custom_api_keys: BTreeMap::new(),
        checkpointing_enabled: DEFAULT_CHECKPOINTS_ENABLED,
        checkpointing_storage_dir: None,
        checkpointing_max_snapshots: DEFAULT_MAX_SNAPSHOTS,
        checkpointing_max_age_days: Some(DEFAULT_MAX_AGE_DAYS),
        quiet: false,
        max_conversation_turns: 1000,
        model_behavior: None,
        openai_chatgpt_auth: None,
    };

    let mut vt_cfg = VTCodeConfig::default();
    vt_cfg.agent.vibe_coding.enabled = true;
    vt_cfg.agent.vibe_coding.enable_relative_value_inference = true;

    let enricher = PromptEnricher::new(workspace_root.clone(), vt_cfg.clone());

    // Test with JSON config value
    enricher
        .record_workspace_change_for_test(
            PathBuf::from("config.json"),
            None,
            r#"  "timeout": 5000,"#.to_string(),
        )
        .await;

    let prompt = "double the timeout";
    let enriched = enricher.enrich_vague_prompt(prompt).await;

    if !enriched.inferred_values.is_empty() {
        let (_, value) = &enriched.inferred_values[0];
        // Should calculate 5000 * 2 = 10000
        assert!(value.contains("10000"));
    }
}