vtcode-core 0.19.1

Core library for VTCode - a Rust-based terminal coding agent
Documentation
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
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
//! Man page generation for VTCode CLI using roff-rs
//!
//! This module provides functionality to generate Unix man pages for VTCode
//! commands and subcommands using the roff-rs library.

use anyhow::{Context, Result, bail};
use roff::{Roff, bold, italic, roman};
use std::fs;
use std::path::Path;

/// Man page generator for VTCode CLI
pub struct ManPageGenerator;

impl ManPageGenerator {
    /// Get current date in YYYY-MM-DD format
    fn current_date() -> String {
        use chrono::Utc;
        Utc::now().format("%Y-%m-%d").to_string()
    }

    /// Generate man page for the main VTCode command
    pub fn generate_main_man_page() -> Result<String> {
        let current_date = Self::current_date();
        let page = Roff::new()
            .control("TH", ["VTCODE", "1", &current_date, "VTCode", "User Commands"])
            .control("SH", ["NAME"])
            .text([roman("vtcode - Advanced coding agent with Decision Ledger")])
            .control("SH", ["SYNOPSIS"])
            .text([
                bold("vtcode"),
                roman(" ["),
                bold("OPTIONS"),
                roman("] ["),
                bold("COMMAND"),
                roman("] ["),
                bold("ARGS"),
                roman("]"),
            ])
            .control("SH", ["DESCRIPTION"])
            .text([
                roman("VTCode is an advanced coding agent with single-agent architecture and Decision Ledger that provides"),
                roman(" intelligent code generation, analysis, and modification capabilities. It supports"),
                roman(" multiple LLM providers and includes tree-sitter powered code analysis for"),
                roman(" Rust, Python, JavaScript, TypeScript, Go, and Java."),
            ])
            .control("SH", ["OPTIONS"])
            .control("TP", [])
            .text([bold("-m"), roman(", "), bold("--model"), roman(" "), italic("MODEL")])
            .text([roman("Specify the LLM model to use (default: gemini-2.5-flash-preview-05-20)")])
            .control("TP", [])
            .text([bold("-p"), roman(", "), bold("--provider"), roman(" "), italic("PROVIDER")])
            .text([roman("Specify the LLM provider (gemini, openai, anthropic, deepseek)")])
            .control("TP", [])
            .text([bold("--workspace"), roman(" "), italic("PATH")])
            .text([roman("Set the workspace root directory for file operations")])
            .control("TP", [])
            .text([bold("--enable-tree-sitter")])
            .text([roman("Enable tree-sitter code analysis")])
            .control("TP", [])
            .text([bold("--performance-monitoring")])
            .text([roman("Enable performance monitoring and metrics")])
            .control("TP", [])
            .text([bold("--debug")])
            .text([roman("Enable debug output")])
            .control("TP", [])
            .text([bold("--verbose")])
            .text([roman("Enable verbose logging")])
            .control("TP", [])
            .text([bold("-h"), roman(", "), bold("--help")])
            .text([roman("Display help information")])
            .control("TP", [])
            .text([bold("-V"), roman(", "), bold("--version")])
            .text([roman("Display version information")])
            .control("SH", ["COMMANDS"])
            .control("TP", [])
            .text([bold("chat")])
            .text([roman("Start interactive AI coding assistant")])
            .control("TP", [])
            .text([bold("ask"), roman(" "), italic("PROMPT")])
            .text([roman("Single prompt mode without tools")])
            .control("TP", [])
            .text([bold("analyze")])
            .text([roman("Analyze workspace with tree-sitter integration")])
            .control("TP", [])
            .text([bold("performance")])
            .text([roman("Display performance metrics and system status")])
            .control("TP", [])
            .text([bold("benchmark")])
            .text([roman("Run SWE-bench evaluation framework")])
            .control("TP", [])
            .text([bold("create-project"), roman(" "), italic("NAME"), roman(" "), italic("FEATURES")])
            .text([roman("Create complete Rust project with features")])
            .control("TP", [])
            .text([bold("init")])
            .text([roman("Initialize project with enhanced structure")])
            .control("TP", [])
            .text([bold("man"), roman(" "), italic("COMMAND")])
            .text([roman("Generate or display man pages for commands")])
            .control("SH", ["EXAMPLES"])
            .text([roman("Start interactive chat:")])
            .text([bold("  vtcode chat")])
            .text([roman("Ask a question:")])
            .text([bold("  vtcode ask \"Explain Rust ownership\"")])
            .text([roman("Create a web project:")])
            .text([bold("  vtcode create-project myapp web,auth,db")])
            .text([roman("Generate man page:")])
            .text([bold("  vtcode man chat")])
            .control("SH", ["ENVIRONMENT"])
            .control("TP", [])
            .text([bold("GEMINI_API_KEY")])
            .text([roman("API key for Google Gemini (default provider)")])
            .control("TP", [])
            .text([bold("OPENAI_API_KEY")])
            .text([roman("API key for OpenAI GPT models")])
            .control("TP", [])
            .text([bold("ANTHROPIC_API_KEY")])
            .text([roman("API key for Anthropic Claude models")])
            .control("TP", [])
            .text([bold("DEEPSEEK_API_KEY")])
            .text([roman("API key for DeepSeek models")])
            .control("SH", ["FILES"])
            .control("TP", [])
            .text([bold("vtcode.toml")])
            .text([roman("Configuration file (current directory or ~/.vtcode/)")])
            .control("TP", [])
            .text([bold(".vtcode/")])
            .text([roman("Project cache and context directory")])
            .control("SH", ["SEE ALSO"])
            .text([roman("Full documentation: https://github.com/vinhnx/vtcode")])
            .text([roman("Related commands: cargo(1), rustc(1), git(1)")])
            .render();

        Ok(page)
    }

    /// Generate man page for a specific command
    pub fn generate_command_man_page(command: &str) -> Result<String> {
        match command {
            "chat" => Self::generate_chat_man_page(),
            "ask" => Self::generate_ask_man_page(),
            "analyze" => Self::generate_analyze_man_page(),
            "performance" => Self::generate_performance_man_page(),
            "benchmark" => Self::generate_benchmark_man_page(),
            "create-project" => Self::generate_create_project_man_page(),
            "init" => Self::generate_init_man_page(),
            "man" => Self::generate_man_man_page(),
            _ => bail!("Unknown command: {}", command),
        }
    }

    /// Generate man page for the chat command
    fn generate_chat_man_page() -> Result<String> {
        let current_date = Self::current_date();
        let page = Roff::new()
            .control("TH", ["VTCODE-CHAT", "1", &current_date, "VTCode", "User Commands"])
            .control("SH", ["NAME"])
            .text([roman("vtcode-chat - Interactive AI coding assistant")])
            .control("SH", ["SYNOPSIS"])
            .text([
                bold("vtcode"),
                roman(" ["),
                bold("OPTIONS"),
                roman("] "),
                bold("chat"),
            ])
            .control("SH", ["DESCRIPTION"])
            .text([
                roman("Start an interactive AI coding assistant session."),
                roman(" The chat command provides intelligent code generation, analysis, and modification"),
                roman(" with support for multiple LLM providers and tree-sitter powered code analysis."),
            ])
            .control("SH", ["OPTIONS"])
            .text([roman("All global options are supported. See "), bold("vtcode(1)"), roman(" for details.")])
            .control("SH", ["EXAMPLES"])
            .text([roman("Start basic chat session:")])
            .text([bold("  vtcode chat")])
            .text([roman("Start with specific model:")])
            .text([bold("  vtcode --model gemini-2.5-pro chat")])
            .control("SH", ["SEE ALSO"])
            .text([bold("vtcode(1)"), roman(", "), bold("vtcode-ask(1)"), roman(", "), bold("vtcode-analyze(1)")])
            .render();

        Ok(page)
    }

    /// Generate man page for the ask command
    fn generate_ask_man_page() -> Result<String> {
        let current_date = Self::current_date();
        let page = Roff::new()
            .control("TH", ["VTCODE-ASK", "1", &current_date, "VTCode", "User Commands"])
            .control("SH", ["NAME"])
            .text([roman("vtcode-ask - Single prompt mode without tools")])
            .control("SH", ["SYNOPSIS"])
            .text([
                bold("vtcode"),
                roman(" ["),
                bold("OPTIONS"),
                roman("] "),
                bold("ask"),
                roman(" "),
                italic("PROMPT"),
            ])
            .control("SH", ["DESCRIPTION"])
            .text([
                roman("Execute a single prompt without tool usage. This is perfect for quick questions,"),
                roman(" code explanations, and simple queries that don't require file operations or"),
                roman(" complex tool interactions."),
            ])
            .control("SH", ["EXAMPLES"])
            .text([roman("Ask about Rust ownership:")])
            .text([bold("  vtcode ask \"Explain Rust ownership\"")])
            .text([roman("Get code explanation:")])
            .text([bold("  vtcode ask \"What does this regex do: \\w+@\\w+\\.\\w+\"")])
            .control("SH", ["SEE ALSO"])
            .text([bold("vtcode(1)"), roman(", "), bold("vtcode-chat(1)")])
            .render();

        Ok(page)
    }

    /// Generate man page for the analyze command
    fn generate_analyze_man_page() -> Result<String> {
        let current_date = Self::current_date();
        let page = Roff::new()
            .control(
                "TH",
                [
                    "VTCODE-ANALYZE",
                    "1",
                    &current_date,
                    "VTCode",
                    "User Commands",
                ],
            )
            .control("SH", ["NAME"])
            .text([roman(
                "vtcode-analyze - Analyze workspace with tree-sitter integration",
            )])
            .control("SH", ["SYNOPSIS"])
            .text([
                bold("vtcode"),
                roman(" ["),
                bold("OPTIONS"),
                roman("] "),
                bold("analyze"),
            ])
            .control("SH", ["DESCRIPTION"])
            .text([
                roman(
                    "Analyze the current workspace using tree-sitter integration. Provides project",
                ),
                roman(
                    " structure analysis, language detection, code complexity metrics, dependency",
                ),
                roman(" insights, and symbol extraction for supported languages."),
            ])
            .control("SH", ["SUPPORTED LANGUAGES"])
            .text([roman(
                "• Rust • Python • JavaScript • TypeScript • Go • Java",
            )])
            .control("SH", ["FEATURES"])
            .control("TP", [])
            .text([bold("Project Structure")])
            .text([roman("Directory tree and file organization analysis")])
            .control("TP", [])
            .text([bold("Language Detection")])
            .text([roman("Automatic detection of programming languages used")])
            .control("TP", [])
            .text([bold("Code Metrics")])
            .text([roman("Complexity analysis and code quality metrics")])
            .control("TP", [])
            .text([bold("Symbol Extraction")])
            .text([roman("Functions, classes, and other code symbols")])
            .control("SH", ["EXAMPLES"])
            .text([roman("Analyze current workspace:")])
            .text([bold("  vtcode analyze")])
            .control("SH", ["SEE ALSO"])
            .text([bold("vtcode(1)"), roman(", "), bold("vtcode-chat(1)")])
            .render();

        Ok(page)
    }

    /// Generate man page for the performance command
    fn generate_performance_man_page() -> Result<String> {
        let current_date = Self::current_date();
        let page = Roff::new()
            .control(
                "TH",
                [
                    "VTCODE-PERFORMANCE",
                    "1",
                    &current_date,
                    "VTCode",
                    "User Commands",
                ],
            )
            .control("SH", ["NAME"])
            .text([roman(
                "vtcode-performance - Display performance metrics and system status",
            )])
            .control("SH", ["SYNOPSIS"])
            .text([
                bold("vtcode"),
                roman(" ["),
                bold("OPTIONS"),
                roman("] "),
                bold("performance"),
            ])
            .control("SH", ["DESCRIPTION"])
            .text([
                roman("Display comprehensive performance metrics and system status information."),
                roman(" Shows token usage, API costs, response times, tool execution statistics,"),
                roman(" memory usage patterns, and agent performance metrics."),
            ])
            .control("SH", ["METRICS DISPLAYED"])
            .control("TP", [])
            .text([bold("Token Usage")])
            .text([roman("Input/output token counts and API costs")])
            .control("TP", [])
            .text([bold("Response Times")])
            .text([roman("API response latency and processing times")])
            .control("TP", [])
            .text([bold("Tool Execution")])
            .text([roman("Tool call statistics and execution times")])
            .control("TP", [])
            .text([bold("Memory Usage")])
            .text([roman("Memory consumption patterns")])
            .control("TP", [])
            .text([bold("Agent Performance")])
            .text([roman("Single-agent execution metrics")])
            .control("SH", ["EXAMPLES"])
            .text([roman("Show performance metrics:")])
            .text([bold("  vtcode performance")])
            .control("SH", ["SEE ALSO"])
            .text([bold("vtcode(1)"), roman(", "), bold("vtcode-benchmark(1)")])
            .render();

        Ok(page)
    }

    /// Generate man page for the benchmark command
    fn generate_benchmark_man_page() -> Result<String> {
        let current_date = Self::current_date();
        let page = Roff::new()
            .control(
                "TH",
                [
                    "VTCODE-BENCHMARK",
                    "1",
                    &current_date,
                    "VTCode",
                    "User Commands",
                ],
            )
            .control("SH", ["NAME"])
            .text([roman(
                "vtcode-benchmark - Run SWE-bench evaluation framework",
            )])
            .control("SH", ["SYNOPSIS"])
            .text([
                bold("vtcode"),
                roman(" ["),
                bold("OPTIONS"),
                roman("] "),
                bold("benchmark"),
            ])
            .control("SH", ["DESCRIPTION"])
            .text([
                roman(
                    "Run automated performance testing against the SWE-bench evaluation framework.",
                ),
                roman(" Provides comparative analysis across different models, benchmark scoring,"),
                roman(" and optimization insights for coding tasks."),
            ])
            .control("SH", ["FEATURES"])
            .control("TP", [])
            .text([bold("Automated Testing")])
            .text([roman("Run standardized coding tasks and challenges")])
            .control("TP", [])
            .text([bold("Comparative Analysis")])
            .text([roman("Compare performance across different models")])
            .control("TP", [])
            .text([bold("Benchmark Scoring")])
            .text([roman("Quantitative performance metrics and scores")])
            .control("TP", [])
            .text([bold("Optimization Insights")])
            .text([roman("Recommendations for performance improvements")])
            .control("SH", ["EXAMPLES"])
            .text([roman("Run benchmark suite:")])
            .text([bold("  vtcode benchmark")])
            .control("SH", ["SEE ALSO"])
            .text([
                bold("vtcode(1)"),
                roman(", "),
                bold("vtcode-performance(1)"),
            ])
            .render();

        Ok(page)
    }

    /// Generate man page for the create-project command
    fn generate_create_project_man_page() -> Result<String> {
        let current_date = Self::current_date();
        let page = Roff::new()
            .control(
                "TH",
                [
                    "VTCODE-CREATE-PROJECT",
                    "1",
                    &current_date,
                    "VTCode",
                    "User Commands",
                ],
            )
            .control("SH", ["NAME"])
            .text([roman(
                "vtcode-create-project - Create complete Rust project with features",
            )])
            .control("SH", ["SYNOPSIS"])
            .text([
                bold("vtcode"),
                roman(" ["),
                bold("OPTIONS"),
                roman("] "),
                bold("create-project"),
                roman(" "),
                italic("NAME"),
                roman(" "),
                italic("FEATURES"),
            ])
            .control("SH", ["DESCRIPTION"])
            .text([
                roman("Create a complete Rust project with advanced features and integrations."),
                roman(" Supports web frameworks, database integration, authentication systems,"),
                roman(" testing setup, and tree-sitter integration."),
            ])
            .control("SH", ["AVAILABLE FEATURES"])
            .text([roman("• web - Web framework (Axum, Rocket, Warp)")])
            .text([roman("• auth - Authentication system")])
            .text([roman("• db - Database integration")])
            .text([roman("• test - Testing setup")])
            .text([roman("• tree-sitter - Code analysis integration")])
            .control("SH", ["EXAMPLES"])
            .text([roman("Create web app with auth and database:")])
            .text([bold("  vtcode create-project myapp web,auth,db")])
            .text([roman("Create basic project:")])
            .text([bold("  vtcode create-project simple_app")])
            .control("SH", ["SEE ALSO"])
            .text([bold("vtcode(1)"), roman(", "), bold("vtcode-init(1)")])
            .render();

        Ok(page)
    }

    /// Generate man page for the init command
    fn generate_init_man_page() -> Result<String> {
        let current_date = Self::current_date();
        let page = Roff::new()
            .control(
                "TH",
                ["VTCODE-INIT", "1", &current_date, "VTCode", "User Commands"],
            )
            .control("SH", ["NAME"])
            .text([roman(
                "vtcode-init - Initialize project with enhanced structure",
            )])
            .control("SH", ["SYNOPSIS"])
            .text([
                bold("vtcode"),
                roman(" ["),
                bold("OPTIONS"),
                roman("] "),
                bold("init"),
            ])
            .control("SH", ["DESCRIPTION"])
            .text([
                roman("Initialize a project with enhanced dot-folder structure for VTCode."),
                roman(" Creates project directory structure, config files, cache directories,"),
                roman(" embeddings storage, and tree-sitter parser setup."),
            ])
            .control("SH", ["DIRECTORY STRUCTURE"])
            .text([roman(
                "• .vtcode/ - Main project cache and context directory",
            )])
            .text([roman("• .vtcode/config/ - Configuration files")])
            .text([roman("• .vtcode/cache/ - File and analysis cache")])
            .text([roman("• .vtcode/embeddings/ - Code embeddings storage")])
            .text([roman("• .vtcode/parsers/ - Tree-sitter parsers")])
            .text([roman("• .vtcode/context/ - Agent context stores")])
            .control("SH", ["EXAMPLES"])
            .text([roman("Initialize current directory:")])
            .text([bold("  vtcode init")])
            .control("SH", ["SEE ALSO"])
            .text([
                bold("vtcode(1)"),
                roman(", "),
                bold("vtcode-create-project(1)"),
            ])
            .render();

        Ok(page)
    }

    /// Generate man page for the man command itself
    fn generate_man_man_page() -> Result<String> {
        let current_date = Self::current_date();
        let page = Roff::new()
            .control("TH", ["VTCODE-MAN", "1", &current_date, "VTCode", "User Commands"])
            .control("SH", ["NAME"])
            .text([roman("vtcode-man - Generate or display man pages for VTCode commands")])
            .control("SH", ["SYNOPSIS"])
            .text([
                bold("vtcode"),
                roman(" ["),
                bold("OPTIONS"),
                roman("] "),
                bold("man"),
                roman(" ["),
                italic("COMMAND"),
                roman("] ["),
                bold("--output"),
                roman(" "),
                italic("FILE"),
                roman("]"),
            ])
            .control("SH", ["DESCRIPTION"])
            .text([
                roman("Generate or display Unix man pages for VTCode commands. Man pages provide"),
                roman(" detailed documentation for all VTCode functionality including usage examples,"),
                roman(" option descriptions, and feature explanations."),
            ])
            .control("SH", ["OPTIONS"])
            .control("TP", [])
            .text([bold("--output"), roman(" "), italic("FILE")])
            .text([roman("Write man page to specified file instead of displaying")])
            .control("SH", ["AVAILABLE COMMANDS"])
            .text([roman("• chat - Interactive AI coding assistant")])
            .text([roman("• ask - Single prompt mode")])
            .text([roman("• analyze - Workspace analysis")])
            .text([roman("• performance - Performance metrics")])
            .text([roman("• benchmark - SWE-bench evaluation")])
            .text([roman("• create-project - Project creation")])
            .text([roman("• init - Project initialization")])
            .text([roman("• man - Man page generation (this command)")])
            .control("SH", ["EXAMPLES"])
            .text([roman("Display main VTCode man page:")])
            .text([bold("  vtcode man")])
            .text([roman("Display chat command man page:")])
            .text([bold("  vtcode man chat")])
            .text([roman("Save man page to file:")])
            .text([bold("  vtcode man chat --output chat.1")])
            .control("SH", ["SEE ALSO"])
            .text([bold("vtcode(1)"), roman(", "), bold("man(1)")])
            .render();

        Ok(page)
    }

    /// Save man page to file
    pub fn save_man_page(content: &str, filename: &Path) -> Result<()> {
        fs::write(filename, content)
            .with_context(|| format!("Failed to write man page to {}", filename.display()))?;
        Ok(())
    }

    /// Get list of available commands for man page generation
    pub fn available_commands() -> Vec<&'static str> {
        vec![
            "chat",
            "ask",
            "analyze",
            "performance",
            "benchmark",
            "create-project",
            "init",
            "man",
        ]
    }
}