patchloom 0.11.0

Structured file editing library and CLI for AI agents: parser-backed JSON/YAML/TOML edits, AST-aware code operations, multi-file batching, markdown operations, and MCP server
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
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
//! Read-only `patchloom ast` subcommands (list, read, validate, search, refs, deps, map, impact, diff).

use super::common::{
    collect_source_files, display_path, filter_symbols, get_git_file_content, lang_from_str,
    parse_kind_filter, print_symbols_compact, print_symbols_human, print_symbols_json,
    resolve_lang, resolve_target_paths, setup_multi_file, setup_single_file,
};
use crate::ast::symbols::{self, SymbolDef};
use crate::cli::global::GlobalFlags;
use crate::exit;
use anyhow::Context;
use clap::Args;

#[derive(Debug, Args)]
pub struct ListArgs {
    /// File or directory to list symbols from.
    pub path: String,

    /// Filter by symbol kind (comma-separated: function,struct,enum,...).
    #[arg(long)]
    pub kind: Option<String>,

    /// Compact mode: definition names only (Cline-style, maximum token efficiency).
    #[arg(long)]
    pub compact: bool,

    /// Language hint (overrides extension detection).
    #[arg(long)]
    pub lang: Option<String>,
}

pub(super) fn run_list(args: ListArgs, global: &GlobalFlags) -> anyhow::Result<u8> {
    let cwd = global.resolve_cwd()?;
    // Match setup_multi_file / read-side commands: --contain must reject ../ escapes
    // before reading source outside the workspace (MPI 2026-07-07).
    global.check_paths_contained(&cwd, [args.path.as_str()])?;
    let target = cwd.join(&args.path);

    let kind_filter = parse_kind_filter(&args.kind);
    let lang_hint = args.lang.as_deref();
    crate::verbose!(
        "ast list: target={}, kind_filter={:?}",
        args.path,
        kind_filter
    );

    let mut any_output = false;

    if target.is_file() {
        let lang = resolve_lang(lang_hint, &target);
        crate::verbose!("ast list: detected language={lang} for {}", args.path);
        if !lang.has_grammar() {
            let msg = format!(
                "Unsupported language: {} (detected from {}). \
                 Supported: Rust, Python, TypeScript, JavaScript, Go, Java, \
                 C#, Ruby, PHP, Swift, Kotlin, C, C++, HCL, XML, Protobuf, \
                 TOML, YAML, JSON, Shell.",
                lang, args.path,
            );
            global.emit_error_json(&msg)?;
            return Ok(exit::NO_MATCHES);
        }
        let symbols = symbols::extract_symbols_from_file(&target, Some(lang));
        let filtered = filter_symbols(&symbols, &kind_filter);
        if !filtered.is_empty() {
            any_output = true;
            if global.json || global.jsonl {
                print_symbols_json(&args.path, &filtered, global)?;
            } else if args.compact {
                print_symbols_compact(&args.path, &filtered);
            } else {
                print_symbols_human(&args.path, &filtered);
            }
        }
    } else if target.is_dir() {
        let paths = collect_source_files(&target, global)?;
        let glob_matcher = crate::build_glob_matcher_from_global(global)?;
        let glob_roots = vec![target.clone()];
        crate::verbose!("ast list: scanning {} files in {}", paths.len(), args.path);

        struct ListFileResult {
            display: String,
            symbols: Vec<SymbolDef>,
        }

        let results: Vec<ListFileResult> =
            crate::par_process_files(&paths, glob_matcher.as_ref(), &glob_roots, |path| {
                let lang = resolve_lang(lang_hint, path);
                let symbols = symbols::extract_symbols_from_file(path, Some(lang));
                if symbols.is_empty() {
                    return None;
                }
                let display = display_path(path, &cwd);
                Some(ListFileResult { display, symbols })
            });

        for result in &results {
            let filtered = filter_symbols(&result.symbols, &kind_filter);
            if filtered.is_empty() {
                continue;
            }
            any_output = true;
            if global.json || global.jsonl {
                print_symbols_json(&result.display, &filtered, global)?;
            } else if args.compact {
                print_symbols_compact(&result.display, &filtered);
            } else {
                print_symbols_human(&result.display, &filtered);
            }
        }
    } else {
        anyhow::bail!("path not found: {}", args.path);
    }

    if any_output {
        Ok(exit::SUCCESS)
    } else {
        let msg = format!("no symbols found in {}", args.path);
        global.emit_error_json(&msg)?;
        Ok(exit::NO_MATCHES)
    }
}

#[derive(Debug, Args)]
pub struct ReadArgs {
    /// File to read from.
    pub path: String,

    /// Symbol name (e.g. "run" or "Server::start").
    pub symbol: String,

    /// Number of context lines before/after the symbol.
    #[arg(long, short, default_value = "0")]
    pub context: usize,

    /// Language hint.
    #[arg(long)]
    pub lang: Option<String>,
}

pub(super) fn run_read(args: ReadArgs, global: &GlobalFlags) -> anyhow::Result<u8> {
    let (_cwd, _target, lang, source) =
        setup_single_file(&args.path, args.lang.as_deref(), global)?;
    crate::verbose!(
        "ast read: file={}, symbol={}, lang={lang}",
        args.path,
        args.symbol
    );
    let all_symbols = symbols::extract_symbols(&source, lang);
    let sym = match symbols::find_symbol(&all_symbols, &args.symbol) {
        Some(s) => s,
        None => {
            let msg = format!("symbol '{}' not found in {}", args.symbol, args.path);
            global.emit_error_json(&msg)?;
            return Ok(exit::NO_MATCHES);
        }
    };

    let lines: Vec<&str> = source.lines().collect();
    let start = sym
        .start_line
        .saturating_sub(args.context.saturating_add(1));
    let end = sym.end_line.saturating_add(args.context).min(lines.len());

    let content: String = lines[start..end].iter().map(|l| format!("{l}\n")).collect();
    if !global.emit_json(&serde_json::json!({
        "file": args.path,
        "symbol": sym.name,
        "kind": sym.kind.to_string(),
        "start_line": sym.start_line,
        "end_line": sym.end_line,
        "signature": sym.signature,
        "content": content,
    }))? {
        for (i, line) in lines[start..end].iter().enumerate() {
            let line_num = start + i + 1;
            println!("{line_num:>4} | {line}");
        }
    }

    Ok(exit::SUCCESS)
}

#[derive(Debug, Args)]
pub struct ValidateArgs {
    /// File or directory to validate.
    pub path: String,

    /// Language hint.
    #[arg(long)]
    pub lang: Option<String>,
}

pub(super) fn run_validate(args: ValidateArgs, global: &GlobalFlags) -> anyhow::Result<u8> {
    let (cwd, paths) = setup_multi_file(&args.path, global)?;
    let lang_hint = args.lang.as_deref();
    crate::verbose!("ast validate: target={}", args.path);

    let mut all_valid = true;
    crate::verbose!("ast validate: checking {} files", paths.len());

    struct ValidateFileResult {
        display: String,
        result: crate::ast::validate::ValidationResult,
    }

    let glob_matcher = crate::build_glob_matcher_from_global(global)?;
    let glob_roots = vec![cwd.join(&args.path)];
    let results: Vec<ValidateFileResult> =
        crate::par_process_files(&paths, glob_matcher.as_ref(), &glob_roots, |path| {
            let lang = resolve_lang(lang_hint, path);
            if !lang.has_grammar() {
                return None;
            }
            let result = crate::ast::validate::validate_file(path, Some(lang)).ok()?;
            let display = display_path(path, &cwd);
            Some(ValidateFileResult { display, result })
        });

    for vr in &results {
        if !vr.result.valid {
            all_valid = false;
        }
        if !global.emit_json(&serde_json::json!({
            "file": vr.display,
            "valid": vr.result.valid,
            "language": vr.result.language,
            "errors": vr.result.errors,
        }))? && !global.quiet
        {
            if !vr.result.valid {
                eprintln!("{}: INVALID ({})", vr.display, vr.result.language);
                for err in &vr.result.errors {
                    eprintln!("  line {}:{}: {}", err.line, err.column, err.text.trim());
                }
            } else {
                eprintln!("{}: OK ({})", vr.display, vr.result.language);
            }
        }
    }

    if all_valid {
        Ok(exit::SUCCESS)
    } else {
        Ok(exit::FAILURE)
    }
}

#[derive(Debug, Args)]
pub struct SearchArgs {
    /// Tree-sitter S-expression query, or a code pattern (with --pattern).
    pub query: String,

    /// File or directory to search.
    pub path: String,

    /// Treat the query as a code pattern with meta-variables ($VAR, $$$MULTI).
    #[arg(long)]
    pub pattern: bool,

    /// Language hint (required for pattern mode; detected from extension otherwise).
    #[arg(long)]
    pub lang: Option<String>,

    /// Maximum number of results.
    #[arg(long)]
    pub max_results: Option<usize>,
}

pub(super) fn run_search(args: SearchArgs, global: &GlobalFlags) -> anyhow::Result<u8> {
    let (cwd, paths) = setup_multi_file(&args.path, global)?;
    let lang_hint = args.lang.as_deref();
    crate::verbose!(
        "ast search: query={}, pattern={}, target={}",
        args.query,
        args.pattern,
        args.path
    );

    let mut total_matches = 0usize;
    crate::verbose!("ast search: scanning {} files", paths.len());

    struct SearchFileResult {
        display: String,
        matches: Vec<crate::ast::search::SearchMatch>,
    }

    let glob_matcher = crate::build_glob_matcher_from_global(global)?;
    let glob_roots = vec![cwd.join(&args.path)];
    let file_results: Vec<SearchFileResult> =
        crate::par_process_files(&paths, glob_matcher.as_ref(), &glob_roots, |path| {
            let lang = resolve_lang(lang_hint, path);
            let query_str = if args.pattern {
                match crate::ast::search::compile_pattern_query(&args.query, lang) {
                    Ok(q) => q,
                    Err(e) => {
                        if !global.quiet {
                            eprintln!(
                                "patchloom: pattern compile error for {}: {e}",
                                path.display()
                            );
                        }
                        return None;
                    }
                }
            } else {
                args.query.clone()
            };
            let matches =
                crate::ast::search::search_file(path, &query_str, Some(lang), args.max_results)
                    .ok()?;
            if matches.is_empty() {
                return None;
            }
            let display = display_path(path, &cwd);
            Some(SearchFileResult { display, matches })
        });

    'outer: for result in &file_results {
        for m in &result.matches {
            total_matches += 1;
            if !global.emit_json(&serde_json::json!({
                "file": result.display,
                "line": m.line,
                "column": m.column,
                "text": m.text,
                "captures": m.captures,
            }))? {
                println!(
                    "{}:{}:{}: {}",
                    result.display,
                    m.line,
                    m.column,
                    m.text.lines().next().unwrap_or("")
                );
                for cap in &m.captures {
                    println!("  @{} = \"{}\"", cap.name, cap.text);
                }
            }
            if let Some(max) = args.max_results
                && total_matches >= max
            {
                break 'outer;
            }
        }
    }

    if total_matches == 0 {
        let msg = format!("no matches for pattern in {}", args.path);
        global.emit_error_json(&msg)?;
        Ok(exit::NO_MATCHES)
    } else {
        Ok(exit::SUCCESS)
    }
}

#[derive(Debug, Args)]
pub struct RefsArgs {
    /// Symbol name to find references for.
    pub symbol: String,

    /// File or directory to search.
    pub path: String,

    /// Include the definition site in results.
    #[arg(long)]
    pub include_def: bool,

    /// Language hint.
    #[arg(long)]
    pub lang: Option<String>,
}

pub(super) fn run_refs(args: RefsArgs, global: &GlobalFlags) -> anyhow::Result<u8> {
    let (cwd, paths) = setup_multi_file(&args.path, global)?;
    let lang_hint = args.lang.as_deref();
    crate::verbose!("ast refs: symbol={}, target={}", args.symbol, args.path);
    crate::verbose!("ast refs: scanning {} files", paths.len());

    let glob_matcher = crate::build_glob_matcher_from_global(global)?;
    let glob_roots = vec![cwd.join(&args.path)];
    let per_file_refs: Vec<Vec<crate::ast::refs::SymbolRef>> =
        crate::par_process_files(&paths, glob_matcher.as_ref(), &glob_roots, |path| {
            let display = display_path(path, &cwd);
            let lang = lang_hint.map(lang_from_str);
            let refs = crate::ast::refs::find_refs_in_file(path, &args.symbol, lang, &display);
            if refs.is_empty() { None } else { Some(refs) }
        });

    let mut all_refs: Vec<_> = per_file_refs.into_iter().flatten().collect();

    if !args.include_def {
        all_refs.retain(|r| r.kind != crate::ast::refs::RefKind::Definition);
    }

    if all_refs.is_empty() {
        let msg = format!("no references found for '{}' in {}", args.symbol, args.path);
        global.emit_error_json(&msg)?;
        return Ok(exit::NO_MATCHES);
    }

    if !global.emit_json(&serde_json::json!({
        "symbol": args.symbol,
        "references": all_refs,
        "count": all_refs.len(),
    }))? {
        for r in &all_refs {
            let kind_label = match r.kind {
                crate::ast::refs::RefKind::Definition => "def",
                crate::ast::refs::RefKind::Reference => "ref",
            };
            println!("{}:{}: [{}] {}", r.file, r.line, kind_label, r.context);
        }
    }

    Ok(exit::SUCCESS)
}

#[derive(Debug, Args)]
pub struct DepsArgs {
    /// File or directory to analyze.
    pub path: String,

    /// Show reverse dependencies (what imports this file).
    #[arg(long)]
    pub reverse: bool,

    /// Language hint.
    #[arg(long)]
    pub lang: Option<String>,
}

pub(super) fn run_deps(args: DepsArgs, global: &GlobalFlags) -> anyhow::Result<u8> {
    let cwd = global.resolve_cwd()?;
    global.check_paths_contained(&cwd, [args.path.as_str()])?;
    let target = cwd.join(&args.path);
    let lang_hint = args.lang.as_deref().map(lang_from_str);
    crate::verbose!("ast deps: target={}, reverse={}", args.path, args.reverse);

    let paths = resolve_target_paths(&target, &args.path, global)?;
    crate::verbose!("ast deps: scanning {} files", paths.len());

    let mut any_output = false;

    if args.reverse {
        // For reverse deps, scan all files and find which ones import
        // anything matching the target file's module path
        let target_name = target
            .file_stem()
            .and_then(|s| s.to_str())
            .unwrap_or_default();

        // Scan from the project root (cwd), not just the target's parent
        // directory, to find importers anywhere in the project.
        let all_files = collect_source_files(&cwd, global)?;

        for path in &all_files {
            let imports = crate::ast::deps::extract_imports_from_file(path, lang_hint);
            // Use segment-boundary matching to avoid substring false positives.
            // Split import paths on common separators (::, /, .) and check if
            // any segment exactly equals the target file stem.
            let matching: Vec<_> = imports
                .iter()
                .filter(|i| {
                    i.path
                        .split(['/', '.'])
                        .flat_map(|seg| seg.split("::"))
                        .any(|seg| seg == target_name)
                })
                .collect();
            if matching.is_empty() {
                continue;
            }
            any_output = true;
            let display = display_path(path, &cwd);

            if global.json || global.jsonl {
                for imp in &matching {
                    global.emit_json(&serde_json::json!({
                        "file": display,
                        "imports": imp.path,
                        "line": imp.line,
                        "raw": imp.raw,
                    }))?;
                }
            } else {
                for imp in &matching {
                    println!("{}:{}: {}", display, imp.line, imp.raw);
                }
            }
        }
    } else {
        struct DepsFileResult {
            display: String,
            imports: Vec<crate::ast::deps::Import>,
        }

        let glob_matcher = crate::build_glob_matcher_from_global(global)?;
        let glob_roots = vec![cwd.join(&args.path)];
        let results: Vec<DepsFileResult> =
            crate::par_process_files(&paths, glob_matcher.as_ref(), &glob_roots, |path| {
                let imports = crate::ast::deps::extract_imports_from_file(path, lang_hint);
                if imports.is_empty() {
                    return None;
                }
                let display = display_path(path, &cwd);
                Some(DepsFileResult { display, imports })
            });

        for result in &results {
            any_output = true;
            if !global.emit_json(&serde_json::json!({
                "file": result.display,
                "imports": result.imports,
            }))? {
                println!("{}", result.display);
                println!("  imports:");
                for imp in &result.imports {
                    println!("    {}", imp.path);
                }
                println!();
            }
        }
    }

    if any_output {
        Ok(exit::SUCCESS)
    } else {
        let msg = format!("no imports found in {}", args.path);
        global.emit_error_json(&msg)?;
        Ok(exit::NO_MATCHES)
    }
}

#[derive(Debug, Args)]
pub struct MapArgs {
    /// Directory to map.
    pub path: String,

    /// Maximum approximate token count for output.
    #[arg(long, default_value = "1024")]
    pub max_tokens: usize,

    /// Boost symbols from these files (comma-separated paths).
    #[arg(long, value_delimiter = ',')]
    pub focus: Vec<String>,

    /// Boost these symbol names (comma-separated).
    #[arg(long, value_delimiter = ',')]
    pub boost: Vec<String>,
}

pub(super) fn run_map(args: MapArgs, global: &GlobalFlags) -> anyhow::Result<u8> {
    let cwd = global.resolve_cwd()?;
    global.check_paths_contained(&cwd, [args.path.as_str()])?;
    let target = cwd.join(&args.path);
    crate::verbose!(
        "ast map: target={}, max_tokens={}",
        args.path,
        args.max_tokens
    );

    if !target.is_dir() {
        anyhow::bail!("path must be a directory: {}", args.path);
    }

    let paths = collect_source_files(&target, global)?;
    crate::verbose!("ast map: collected {} source files", paths.len());
    let file_pairs: Vec<(std::path::PathBuf, String)> = paths
        .iter()
        .map(|p| {
            let display = display_path(p, &cwd);
            (p.clone(), display)
        })
        .collect();

    let opts = crate::ast::map::MapOptions {
        max_tokens: args.max_tokens,
        focus: &args.focus,
        boost: &args.boost,
    };

    let entries = crate::ast::map::generate_map(&file_pairs, &opts);

    if entries.is_empty() {
        let msg = format!("no symbols found in {}", args.path);
        global.emit_error_json(&msg)?;
        return Ok(exit::NO_MATCHES);
    }

    if !global.emit_json_items(&entries)? {
        print!("{}", crate::ast::map::render_tree(&entries));
    }

    Ok(exit::SUCCESS)
}

#[derive(Debug, Args)]
pub struct ImpactArgs {
    /// Symbol name to analyze.
    pub symbol: String,

    /// Directory to scan for references.
    pub path: String,

    /// Maximum traversal depth (1 = direct refs only).
    #[arg(long, default_value = "3")]
    pub depth: usize,

    /// Language hint.
    #[arg(long)]
    pub lang: Option<String>,
}

pub(super) fn run_impact(args: ImpactArgs, global: &GlobalFlags) -> anyhow::Result<u8> {
    let (cwd, paths) = setup_multi_file(&args.path, global)?;
    crate::verbose!("ast impact: symbol={}, depth={}", args.symbol, args.depth);
    crate::verbose!("ast impact: scanning {} files", paths.len());

    let file_pairs: Vec<(std::path::PathBuf, String)> = paths
        .iter()
        .map(|p| {
            let display = display_path(p, &cwd);
            (p.clone(), display)
        })
        .collect();

    let nodes = crate::ast::impact::compute_impact(&args.symbol, &file_pairs, args.depth);

    if nodes.is_empty() {
        global.emit_error_json(&format!("no references found for '{}'", args.symbol))?;
        return Ok(exit::NO_MATCHES);
    }

    if !global.emit_json(&serde_json::json!({
        "symbol": args.symbol,
        "depth": args.depth,
        "impact": nodes,
        "direct_count": nodes.len(),
    }))? {
        print!(
            "{}",
            crate::ast::impact::render_impact_tree(&args.symbol, &nodes, 0)
        );
    }

    Ok(exit::SUCCESS)
}

#[derive(Debug, Args)]
pub struct DiffArgs {
    /// File to diff.
    pub path: String,

    /// Git ref for the "old" version (default: HEAD).
    #[arg(long, default_value = "HEAD")]
    pub from: String,

    /// Git ref for the "new" version (default: working tree).
    #[arg(long)]
    pub to: Option<String>,

    /// Language hint.
    #[arg(long)]
    pub lang: Option<String>,
}

pub(super) fn run_diff(args: DiffArgs, global: &GlobalFlags) -> anyhow::Result<u8> {
    let cwd = global.resolve_cwd()?;
    global.check_paths_contained(&cwd, [args.path.as_str()])?;
    let target = cwd.join(&args.path);
    let lang = resolve_lang(args.lang.as_deref(), &target);
    crate::verbose!(
        "ast diff: file={}, from={}, lang={lang}",
        args.path,
        args.from
    );

    // Get old version from git
    let old_source = get_git_file_content(&cwd, &args.path, &args.from)?;

    // Get new version
    let new_source = if let Some(ref to_ref) = args.to {
        get_git_file_content(&cwd, &args.path, to_ref)?
    } else {
        std::fs::read_to_string(&target).with_context(|| format!("reading {}", args.path))?
    };

    let changes = crate::ast::diff::structural_diff(&old_source, &new_source, lang);

    if changes.is_empty() {
        global.emit_error_json("no structural changes")?;
        return Ok(exit::NO_MATCHES);
    }

    if !global.emit_json(&serde_json::json!({
        "file": args.path,
        "from": args.from,
        "to": args.to.as_deref().unwrap_or("working tree"),
        "changes": changes,
    }))? {
        print!("{}", crate::ast::diff::render_changes(&args.path, &changes));
    }

    Ok(exit::SUCCESS)
}