difflore-cli 0.1.0

Your AI coding agent, taught by your team's PR reviews — a local-first, open-source MCP server that turns past review comments into rules your agent follows automatically.
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
use super::{AgentsCommands, Cli, CloudCommands, Commands, StatusLane, build_cli};
use clap::Parser;

#[test]
fn fix_help_states_pr_mode_is_local_only() {
    let mut command = build_cli();
    let fix = command
        .find_subcommand_mut("fix")
        .expect("fix command should exist");
    let help = fix.render_long_help().to_string();

    assert!(help.contains("GitHub PR"));
    assert!(help.contains("working tree"));
    assert!(help.contains("never commits"));
    assert!(help.contains("pushes"));
    assert!(help.contains("posts GitHub comments"));
}

#[test]
fn public_help_keeps_curated_command_surface() {
    let help = build_cli().render_long_help().to_string();

    for visible in [
        "  init",
        "  status",
        "  import-reviews",
        "  recall",
        "  fix",
        "  ask",
        "  cloud",
        "  agents",
        "  providers",
        "  embeddings",
        "  doctor",
    ] {
        assert!(help.contains(visible), "{visible} should be visible");
    }

    for removed in [
        "  plan",
        "  plan-pr",
        "  impact",
        "  upgrade",
        "  config",
        "  hook",
        "  review-inbox",
        "  reviewer",
        "  knowledge",
        "  ingest",
        "  candidates",
        "  explore",
        "  mcp-server",
        "  memory",
        "  mcp",
        "  lsp",
        "  migrate",
        "  demo",
        "  tui",
        "  dist",
        "  daemon",
        "  rules",
        "  sync",
        "  value-check",
    ] {
        assert!(!help.contains(removed), "{removed} should not be visible");
    }
}

#[test]
fn fix_help_keeps_launch_surface_short_but_pr_switches_parse() {
    let mut command = build_cli();
    let fix = command
        .find_subcommand_mut("fix")
        .expect("fix command should exist");
    let help = fix.render_long_help().to_string();
    let option_tokens = help
        .lines()
        .filter_map(|line| line.split_whitespace().next())
        .collect::<Vec<_>>();

    assert!(help.contains("--pr"));
    for hidden in [
        "--work-branch",
        "--no-checkout",
        "--allow-dirty",
        "--no-upload-acceptance",
        "--explain-rules",
        "--report",
        "--check",
        "--agent",
        "--repo",
        "--base",
    ] {
        assert!(
            !option_tokens.contains(&hidden),
            "{hidden} should stay hidden from fix help"
        );
    }
}

#[test]
fn fix_pr_safety_switches_parse_into_fix_args() {
    let cli = Cli::try_parse_from([
        "difflore",
        "fix",
        "--pr",
        "difflore/difflore-cli#42",
        "--work-branch",
        "local-pr-42",
        "--allow-dirty",
        "--no-upload-acceptance",
    ])
    .expect("fix PR safety switches should parse");

    match cli.command.expect("subcommand") {
        Commands::Fix(args) => {
            assert_eq!(args.pr.as_deref(), Some("difflore/difflore-cli#42"));
            assert_eq!(args.work_branch.as_deref(), Some("local-pr-42"));
            assert!(!args.no_checkout);
            assert!(args.allow_dirty);
            assert!(args.no_upload_acceptance);
        }
        _ => panic!("expected fix command"),
    }
}

#[test]
fn fix_pr_work_branch_conflicts_with_no_checkout_and_preview() {
    for args in [
        [
            "difflore",
            "fix",
            "--pr",
            "difflore/difflore-cli#42",
            "--work-branch",
            "local-pr-42",
            "--no-checkout",
        ]
        .as_slice(),
        [
            "difflore",
            "fix",
            "--pr",
            "difflore/difflore-cli#42",
            "--preview",
            "--work-branch",
            "local-pr-42",
        ]
        .as_slice(),
    ] {
        assert!(
            Cli::try_parse_from(args).is_err(),
            "{args:?} should reject conflicting PR safety switches"
        );
    }
}

#[test]
fn fix_pr_safety_switches_require_pr_mode() {
    for args in [
        ["difflore", "fix", "--work-branch", "local-pr-42"].as_slice(),
        ["difflore", "fix", "--no-checkout"].as_slice(),
        ["difflore", "fix", "--allow-dirty"].as_slice(),
        ["difflore", "fix", "--no-upload-acceptance"].as_slice(),
    ] {
        assert!(
            Cli::try_parse_from(args).is_err(),
            "{args:?} should require --pr"
        );
    }
}

#[test]
fn agents_command_parses_public_install_and_status_surface() {
    let install = Cli::try_parse_from(["difflore", "agents", "install", "--dry-run"])
        .expect("agents install should parse");
    assert!(matches!(
        install.command,
        Some(Commands::Agents {
            command: AgentsCommands::Install { dry_run: true }
        })
    ));

    let status = Cli::try_parse_from(["difflore", "agents", "status", "--json"])
        .expect("agents status should parse");
    assert!(matches!(
        status.command,
        Some(Commands::Agents {
            command: AgentsCommands::Status { json: true }
        })
    ));

    let uninstall = Cli::try_parse_from(["difflore", "agents", "uninstall", "--dry-run"])
        .expect("agents uninstall should parse");
    assert!(matches!(
        uninstall.command,
        Some(Commands::Agents {
            command: AgentsCommands::Uninstall { dry_run: true }
        })
    ));

    let uninstall_default = Cli::try_parse_from(["difflore", "agents", "uninstall"])
        .expect("agents uninstall without flag should parse");
    assert!(matches!(
        uninstall_default.command,
        Some(Commands::Agents {
            command: AgentsCommands::Uninstall { dry_run: false }
        })
    ));

    let update = Cli::try_parse_from(["difflore", "agents", "update", "--dry-run", "--force"])
        .expect("agents update should parse");
    assert!(matches!(
        update.command,
        Some(Commands::Agents {
            command: AgentsCommands::Update {
                dry_run: true,
                force: true
            }
        })
    ));

    let update_default = Cli::try_parse_from(["difflore", "agents", "update"])
        .expect("agents update without flags should parse");
    assert!(matches!(
        update_default.command,
        Some(Commands::Agents {
            command: AgentsCommands::Update {
                dry_run: false,
                force: false
            }
        })
    ));
}

#[test]
fn status_replaces_value_check_and_cloud_owns_sync() {
    let status =
        Cli::try_parse_from(["difflore", "status", "--json"]).expect("status should parse");
    assert!(matches!(
        status.command,
        Some(Commands::Status {
            json: true,
            lane: StatusLane::All,
        })
    ));

    let beta_status = Cli::try_parse_from(["difflore", "status", "--lane", "local-beta", "--json"])
        .expect("status local beta lane should parse");
    assert!(matches!(
        beta_status.command,
        Some(Commands::Status {
            json: true,
            lane: StatusLane::LocalBeta,
        })
    ));

    let ga_status = Cli::try_parse_from(["difflore", "status", "--lane", "production-ga"])
        .expect("status production GA lane should parse");
    assert!(matches!(
        ga_status.command,
        Some(Commands::Status {
            json: false,
            lane: StatusLane::ProductionGa,
        })
    ));

    assert!(
        Cli::try_parse_from(["difflore", "value-check"]).is_err(),
        "legacy value-check command should not parse"
    );

    let sync = Cli::try_parse_from(["difflore", "cloud", "sync", "--dry-run"])
        .expect("cloud sync should parse");
    assert!(matches!(
        sync.command,
        Some(Commands::Cloud {
            command: CloudCommands::Sync(super::SyncCliArgs { dry_run: true, .. })
        })
    ));

    let team =
        Cli::try_parse_from(["difflore", "cloud", "team", "--json"]).expect("team should parse");
    assert!(matches!(
        team.command,
        Some(Commands::Cloud {
            command: CloudCommands::Team { json: true }
        })
    ));

    let publish =
        Cli::try_parse_from(["difflore", "cloud", "publish", "--rule", "rule-1", "--json"])
            .expect("cloud publish should parse");
    assert!(matches!(
        publish.command,
        Some(Commands::Cloud {
            command: CloudCommands::Publish { rule, json: true, .. }
        }) if rule == "rule-1"
    ));

    let unpublish = Cli::try_parse_from([
        "difflore",
        "cloud",
        "unpublish",
        "--rule",
        "rule-1",
        "--json",
    ])
    .expect("cloud unpublish should parse");
    assert!(matches!(
        unpublish.command,
        Some(Commands::Cloud {
            command: CloudCommands::Unpublish { rule, json: true, .. }
        }) if rule == "rule-1"
    ));

    assert!(
        Cli::try_parse_from(["difflore", "sync"]).is_err(),
        "top-level sync should not parse"
    );
}

#[test]
fn removed_top_level_commands_do_not_parse() {
    for removed in [
        "plan",
        "plan-pr",
        "impact",
        "upgrade",
        "config",
        "hook",
        "review-inbox",
        "reviewer",
        "knowledge",
        "ingest",
        "candidates",
        "explore",
        "memory",
        "mcp",
        "lsp",
        "migrate",
        "demo",
        "tui",
        "dist",
        "daemon",
        "rules",
    ] {
        assert!(
            Cli::try_parse_from(["difflore", removed]).is_err(),
            "{removed} should not parse"
        );
    }
}

#[test]
fn hidden_mcp_server_transport_parses_but_stays_out_of_help() {
    let help = build_cli().render_long_help().to_string();
    assert!(!help.contains("  mcp-server"));
    assert!(!help.contains("  eval"));
    assert!(!help.contains("  trajectory"));
    assert!(!help.contains("  skills"));

    let parsed = Cli::try_parse_from(["difflore", "mcp-server"])
        .expect("hidden MCP transport should parse for installed agents");
    assert!(matches!(parsed.command, Some(Commands::McpServer)));

    assert!(Cli::try_parse_from(["difflore", "eval"]).is_ok());
    assert!(Cli::try_parse_from(["difflore", "trajectory", "review-id"]).is_ok());
    assert!(Cli::try_parse_from(["difflore", "skills", "sweep"]).is_ok());
}

#[test]
fn public_oss_copy_does_not_reintroduce_cloud_fix_positioning() {
    let surfaces = [
        ("README.md", include_str!("../../../../README.md")),
        (
            "commands/cloud/mod.rs",
            include_str!("../commands/cloud/mod.rs"),
        ),
        (
            "commands/doctor/report/env_probes.rs",
            include_str!("../commands/doctor/report/env_probes.rs"),
        ),
        (
            "difflore-tui/widgets/status_bar.rs",
            include_str!("../../../../crates/difflore-tui/src/widgets/status_bar.rs"),
        ),
        (
            "difflore-tui/modals/fix_runs_low.rs",
            include_str!("../../../../crates/difflore-tui/src/modals/fix_runs_low.rs"),
        ),
    ];
    let forbidden = [
        "hosted auto fix",
        "managed inference",
        "cloud auto fix",
        "auto-fix",
        "auto fix quota",
        "fix-run quota",
        "fix runs",
        "cloud team trial",
        "difflore[bot]",
        "difflore does not run fix locally",
    ];

    for (name, text) in surfaces {
        let lower = text.to_ascii_lowercase();
        for phrase in forbidden {
            assert!(
                !lower.contains(phrase),
                "{name} reintroduced forbidden cloud-fix positioning phrase `{phrase}`"
            );
        }
    }
}

#[test]
fn fix_strict_requires_ci_mode() {
    let mut command = build_cli();
    let fix = command
        .find_subcommand_mut("fix")
        .expect("fix command should exist");
    let help = fix.render_long_help().to_string();
    assert!(help.contains("Requires `--ci`"));

    assert!(
        Cli::try_parse_from(["difflore", "fix", "--strict"]).is_err(),
        "--strict without --ci should fail at parse time"
    );
    assert!(
        Cli::try_parse_from(["difflore", "fix", "--ci", "--strict"]).is_ok(),
        "--strict should be valid with --ci"
    );
    assert!(
        Cli::try_parse_from(["difflore", "fix", "--check", "--strict"]).is_err(),
        "--check alias should not parse"
    );
}

#[test]
fn import_reviews_help_promotes_cli_only_value_path() {
    let mut command = build_cli();
    let import_reviews = command
        .find_subcommand_mut("import-reviews")
        .expect("import-reviews command should exist");
    let help = import_reviews.render_long_help().to_string();

    assert!(help.contains("past GitHub PR review comments"));
    assert!(help.contains("--dry-run"));
    assert!(help.contains("difflore recall --diff"));
    assert!(help.contains("--upload"));
    assert!(!help.contains("difflore candidates"));
    assert!(!help.contains("--local-candidates"));
    assert!(!help.contains("--max-candidates"));
}

#[test]
fn import_reviews_rejects_candidate_budget_flag() {
    assert!(
        Cli::try_parse_from(["difflore", "import-reviews", "--max-candidates", "12"]).is_err(),
        "--max-candidates should not parse"
    );
    assert!(
        Cli::try_parse_from(["difflore", "import-reviews", "--local-candidates"]).is_err(),
        "--local-candidates should not parse"
    );
}

#[test]
fn recall_rejects_eval_escape_hatches() {
    assert!(
        Cli::try_parse_from(["difflore", "recall", "--via", "mcp", "--json"]).is_err(),
        "--via should not parse"
    );
    assert!(
        Cli::try_parse_from(["difflore", "recall", "--copy-agent-context"]).is_err(),
        "--copy-agent-context should not parse"
    );
}

#[test]
fn import_reviews_parses_target_pr_numbers() {
    let cli = Cli::try_parse_from([
        "difflore",
        "import-reviews",
        "--pr",
        "13629",
        "--pr",
        "45397",
        "--json",
    ])
    .expect("import-reviews should parse targeted PR import");

    match cli.command.expect("subcommand") {
        Commands::ImportReviews(args) => {
            assert_eq!(args.pr_numbers, vec![13629, 45397]);
            assert!(args.json);
        }
        _ => panic!("expected import-reviews command"),
    }
}

#[test]
fn import_reviews_parses_exclude_prs_csv() {
    let cli = Cli::try_parse_from(["difflore", "import-reviews", "--exclude-prs", "42,1337,42"])
        .expect("import-reviews should parse --exclude-prs CSV");

    match cli.command.expect("subcommand") {
        Commands::ImportReviews(args) => {
            // clap splits on commas; dedup happens later when the Vec is
            // collected into a set during validation.
            assert_eq!(args.exclude_prs, vec![42, 1337, 42]);
        }
        _ => panic!("expected import-reviews command"),
    }
}

#[test]
fn import_reviews_exclude_prs_defaults_to_empty() {
    let cli = Cli::try_parse_from(["difflore", "import-reviews"])
        .expect("import-reviews should parse with no exclusions");

    match cli.command.expect("subcommand") {
        Commands::ImportReviews(args) => {
            assert!(args.exclude_prs.is_empty());
        }
        _ => panic!("expected import-reviews command"),
    }
}