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
use clap::{Parser, Subcommand};

use super::args::{
    FixCliArgs, ImportReviewsCliArgs, InitCliArgs, RecallCliArgs, StatusLane, SyncCliArgs,
};

#[derive(Parser)]
#[command(name = "difflore")]
#[command(bin_name = "difflore")]
#[command(about = "AI review memory for local coding agents")]
#[command(next_line_help = true)]
#[command(
    long_about = "DiffLore turns your team's past PR review judgment into memory \
your local AI agents can recall before they code. The core loop is: \
`difflore init`, `difflore import-reviews`, `difflore cloud sync`, \
then `difflore recall --diff` or `difflore fix --preview`."
)]
pub(crate) struct Cli {
    /// Bare `difflore` shows local memory status and the next command.
    #[command(subcommand)]
    pub(crate) command: Option<Commands>,

    /// Disable interactive prompts (skips the first-run wizard on a TTY).
    #[arg(long, global = true)]
    pub(crate) no_interactive: bool,
}

#[derive(Subcommand)]
pub(crate) enum Commands {
    /// See DiffLore work on a bundled sample — no setup, no repo, nothing written.
    #[command(
        long_about = "Run a zero-config demo with bundled PR-review rules and a sample edit. \
It shows the memories that would fire, where they came from, and the next command to run. \
Nothing leaves your laptop and nothing is written to disk."
    )]
    Try,

    /// Run first-time setup for this repo.
    Init(InitCliArgs),

    /// Show local memory status and the next command.
    Status {
        /// Output as JSON.
        #[arg(long)]
        json: bool,

        /// Filter readiness output to a release stage.
        #[arg(long, value_enum, default_value_t = StatusLane::All, hide = true)]
        lane: StatusLane,
    },

    /// Import past GitHub PR review comments as review memory evidence.
    #[command(
        next_line_help = false,
        long_about = "Import past GitHub PR review comments into local review memory. \
Use `--dry-run` to preview first, then run `difflore recall --diff` to see what agents will remember."
    )]
    ImportReviews(ImportReviewsCliArgs),

    /// Preview which team memories an agent would see for an intent or current diff.
    Recall(RecallCliArgs),

    /// Suggest local patches using remembered team review judgment.
    #[command(
        next_line_help = false,
        long_about = "Suggest safe local patches for the current diff or a GitHub PR. \
Start with `difflore fix --preview`; accepted changes only touch the working tree. \
DiffLore never commits, pushes, opens PRs, or posts GitHub comments."
    )]
    Fix(FixCliArgs),

    /// Ask the team's review memory a natural-language question.
    Ask {
        /// The question to ask.
        query: String,

        /// File path for scoping (optional; drives file-pattern recall).
        #[arg(long, value_name = "PATH")]
        file: Option<String>,

        /// Output as JSON.
        #[arg(long)]
        json: bool,
    },

    /// Manage cloud login, sync, and team impact.
    Cloud {
        #[command(subcommand)]
        command: CloudCommands,
    },

    /// Browse and install shareable starter rule packs.
    Packs {
        #[command(subcommand)]
        command: PacksCommands,
    },

    /// Wire and inspect local AI agent integrations.
    Agents {
        #[command(subcommand)]
        command: AgentsCommands,
    },

    /// Choose the local AI backend DiffLore uses for fixes.
    Providers {
        #[command(subcommand)]
        command: ProviderCommands,
    },

    /// Configure optional semantic search for higher-quality recall.
    Embeddings {
        #[command(subcommand)]
        command: EmbeddingsCommands,
    },

    /// Measure recall quality (self-recall @1/@5/MRR) on your corpus, fast and repeatable.
    #[command(
        hide = true,
        long_about = "Measure recall quality on the local corpus. Deterministic and offline; \
nothing is written to your real indexes."
    )]
    Eval {
        /// Number of rules to sample (1..=200).
        #[arg(long, value_name = "N")]
        samples: Option<usize>,

        /// Output as JSON.
        #[arg(long)]
        json: bool,
    },

    /// Replay a recorded review's decision trail — every issue traced to its memory evidence.
    #[command(
        hide = true,
        long_about = "Replay one recorded review decision trail from DiffLore Cloud. \
Pass `--json` for the raw document."
    )]
    Trajectory {
        /// The review id (UUID) to replay. Shown after a review runs.
        #[arg(value_name = "REVIEW_ID")]
        review_id: String,

        /// Output the raw trajectory document as JSON.
        #[arg(long)]
        json: bool,
    },

    /// Show readiness and blockers; pass `--report` for a full diagnostic file.
    Doctor {
        /// Write the report to a file instead of stdout.
        #[arg(long)]
        report: bool,

        /// Auto-repair the safe subset of detected problems.
        #[arg(long)]
        fix: bool,

        /// Preview retrying uploads that stopped after a login/auth outage.
        #[arg(long, hide = true)]
        drain_abandoned: bool,

        /// Only include uploads whose last attempt is older than this duration.
        /// Accepts `30d`, `7d`, `24h`, `1h`, `30m`.
        #[arg(long, value_name = "DURATION", default_value = "30d", hide = true)]
        older_than: String,

        /// Apply the retry queue changes instead of previewing them.
        #[arg(long, default_value_t = false, hide = true)]
        no_dry_run: bool,

        /// JSON output for the retry summary. Has no effect outside
        /// `--drain-abandoned`.
        #[arg(long, hide = true)]
        json: bool,
    },

    /// Internal MCP stdio transport used by installed agents.
    #[command(name = "mcp-server", hide = true)]
    McpServer,

    /// Local skill-store maintenance utilities.
    #[command(hide = true)]
    Skills {
        #[command(subcommand)]
        command: SkillsCommands,
    },

    /// Verify plugin distribution manifests (maintainer-only release guardrail).
    #[command(hide = true)]
    Dist {
        #[command(subcommand)]
        command: DistCommands,
    },
}

#[derive(Subcommand)]
pub(crate) enum SkillsCommands {
    /// Preview cleanup for stale local memory records.
    Sweep {
        /// Apply the cleanup. Without this flag, prints a preview only.
        #[arg(long, default_value_t = false)]
        no_dry_run: bool,
        /// Confidence multiplier applied during cleanup.
        #[arg(long, default_value_t = 0.5)]
        decay_factor: f32,
        /// Ignore records newer than this many days.
        #[arg(long, default_value_t = 14)]
        days: u32,
        /// Also quarantine unguided review records.
        #[arg(long, default_value_t = false)]
        quarantine_unguided: bool,
    },

    /// Preview repair for old accepted-fix attribution records.
    #[command(name = "backfill-attribution")]
    BackfillAttribution {
        /// Apply the repair. Without this flag, prints a preview only.
        #[arg(long, default_value_t = false)]
        no_dry_run: bool,
    },
}

#[derive(Subcommand)]
pub(crate) enum DistCommands {
    /// Check plugin/marketplace manifests against the CLI version and bundle.
    Verify {
        /// Output as JSON.
        #[arg(long)]
        json: bool,
    },
}

#[derive(Subcommand)]
pub(crate) enum PacksCommands {
    /// List packs in the registry (or installed packs with --installed).
    List {
        /// Registry base URL or file:// path (defaults to the first-party registry).
        #[arg(long, value_name = "URL")]
        registry: Option<String>,
        /// List locally-installed packs instead of the registry catalog.
        #[arg(long)]
        installed: bool,
        /// Output as JSON.
        #[arg(long)]
        json: bool,
    },
    /// Show a pack's manifest (rules, provenance, target globs, license).
    Show {
        /// Pack id, optionally `<id>@<version>`.
        #[arg(value_name = "PACK_ID")]
        pack_id: String,
        #[arg(long, value_name = "URL")]
        registry: Option<String>,
        #[arg(long)]
        json: bool,
    },
    /// Install a pack's rules as suggestion-only starter memory.
    Install {
        /// Pack id, optionally `<id>@<version>`.
        #[arg(value_name = "PACK_ID")]
        pack_id: String,
        #[arg(long, value_name = "URL")]
        registry: Option<String>,
        /// Preview the rows that would be written without writing.
        #[arg(long)]
        dry_run: bool,
        /// Skip confirmation prompts.
        #[arg(long)]
        yes: bool,
        #[arg(long)]
        json: bool,
    },
    /// List locally-installed packs (alias for `packs list --installed`).
    Installed {
        #[arg(long)]
        json: bool,
    },
    /// Remove all rules installed from a pack.
    Uninstall {
        /// Pack id to remove.
        #[arg(value_name = "PACK_ID")]
        pack_id: String,
        #[arg(long)]
        yes: bool,
        #[arg(long)]
        json: bool,
    },
    /// Validate a local pack directory's pack.json and print PR instructions.
    Publish {
        /// Path to the pack.json manifest to validate.
        #[arg(value_name = "PATH")]
        path: String,
        #[arg(long, value_name = "URL")]
        registry: Option<String>,
        #[arg(long)]
        json: bool,
    },
}

#[derive(Subcommand)]
pub(crate) enum CloudCommands {
    /// Show current cloud login, plan, and team info.
    Status {
        /// Output as JSON.
        #[arg(long)]
        json: bool,
    },

    /// Log in to cloud (browser OAuth, GitHub CLI, or pre-issued token via flag/env/stdin).
    #[command(next_line_help = false, long_about = concat!(
        "Log in to DiffLore Cloud.\n",
        "\n",
        "Browser login is the default for interactive use:\n",
        "\n",
        "  difflore cloud login\n",
        "  difflore cloud login --browser\n",
        "  difflore cloud login --github\n",
        "\n",
        "For headless environments, pass a token with `--token`, stdin, or ",
        "`DIFFLORE_CLOUD_TOKEN`.",
    ))]
    Login {
        /// Bearer token. Prefer stdin or `DIFFLORE_CLOUD_TOKEN` to keep it out of shell history.
        #[arg(long)]
        token: Option<String>,

        /// Force the browser OAuth flow even from local non-TTY shells; prints the auth URL.
        #[arg(long, conflicts_with_all = ["token", "github"])]
        browser: bool,

        /// Exchange the local GitHub CLI auth token for a DiffLore Cloud token.
        #[arg(long, conflicts_with = "token")]
        github: bool,
    },

    /// Sync governed team review memory with cloud.
    Sync(SyncCliArgs),

    /// Show the current team workspace and its readiness checks.
    Team {
        /// Output as JSON.
        #[arg(long)]
        json: bool,
    },

    /// Publish a local rule to the current cloud team.
    Publish {
        /// Local or cloud rule id to publish.
        #[arg(long, value_name = "RULE_ID")]
        rule: String,

        /// Team id. Defaults to the current cloud team.
        #[arg(long, value_name = "TEAM_ID")]
        team_id: Option<String>,

        /// Team enforcement policy.
        #[arg(long, default_value = "recommended", value_parser = ["recommended", "required"])]
        enforcement: String,

        /// Output as JSON.
        #[arg(long)]
        json: bool,
    },

    /// Remove a published rule from the current cloud team.
    Unpublish {
        /// Local or cloud rule id to unpublish.
        #[arg(long, value_name = "RULE_ID")]
        rule: String,

        /// Team id. Defaults to the current cloud team.
        #[arg(long, value_name = "TEAM_ID")]
        team_id: Option<String>,

        /// Output as JSON.
        #[arg(long)]
        json: bool,
    },

    /// Show cloud team impact proof.
    Impact {
        /// Output as JSON.
        #[arg(long)]
        json: bool,
    },

    /// Clear the stored cloud token on this device.
    Logout,
}

#[derive(Subcommand)]
pub(crate) enum AgentsCommands {
    /// Install DiffLore into every detected local agent.
    Install {
        /// Preview what would change without touching disk.
        #[arg(long)]
        dry_run: bool,
    },

    /// Remove DiffLore from every agent it was installed into.
    #[command(
        long_about = "Undo `difflore agents install`: remove the DiffLore MCP entry and \
DiffLore hook groups from each agent it was wired into (preserving every other entry), \
then delete the canonical install record. Pass `--dry-run` to preview first."
    )]
    Uninstall {
        /// Preview what would be removed without touching disk.
        #[arg(long)]
        dry_run: bool,
    },

    /// Show per-agent detection and install state.
    Status {
        /// Output as JSON.
        #[arg(long)]
        json: bool,
    },

    /// Re-render DiffLore blocks that are unchanged since DiffLore wrote them.
    #[command(
        long_about = "Safely upgrade DiffLore's config/hook blocks to the current shape. \
Blocks that are byte-identical to what DiffLore last wrote are re-rendered in place; \
blocks you (or another tool) hand-edited are left untouched unless you pass `--force`. \
Pass `--dry-run` to preview the plan first."
    )]
    Update {
        /// Preview what would change without touching disk.
        #[arg(long)]
        dry_run: bool,

        /// Overwrite blocks that were locally edited since DiffLore wrote them.
        #[arg(long)]
        force: bool,
    },
}

#[derive(Subcommand)]
pub(crate) enum ProviderCommands {
    /// List configured AI backends.
    List {
        /// Output as JSON.
        #[arg(long)]
        json: bool,
    },

    /// Interactive AI backend picker (Claude / Codex / Gemini / OpenCode CLI).
    Setup,

    /// Add a local AI CLI backend.
    Add {
        /// Agent CLI to use: `claude`, `codex`, `gemini`, or `opencode`.
        #[arg(long, value_name = "TOOL")]
        tool: String,

        /// Optional model override. Defaults to the agent CLI's own default.
        #[arg(long)]
        model: Option<String>,
    },

    /// Remove an AI backend by ID.
    Remove {
        /// Provider ID to remove.
        id: String,
        /// Skip the confirmation prompt.
        #[arg(long)]
        yes: bool,
    },

    /// Set active AI backend.
    SetActive {
        /// Provider ID.
        id: String,
    },
}

#[derive(Subcommand)]
pub(crate) enum EmbeddingsCommands {
    /// Show the active search mode.
    Status {
        /// Output as JSON.
        #[arg(long)]
        json: bool,
    },

    /// Configure a BYOK semantic embedding provider (OpenAI-compatible).
    Setup {
        /// Base URL of the OpenAI-compatible embedding endpoint.
        #[arg(long, value_name = "URL")]
        provider_url: Option<String>,

        /// Embedding model name.
        #[arg(long, value_name = "MODEL")]
        model: Option<String>,

        /// Output vector dimensionality.
        #[arg(long, value_name = "N")]
        dim: Option<usize>,

        /// API key. Prefer the `DIFFLORE_EMBEDDING_KEY` env var or piped stdin.
        #[arg(long, value_name = "KEY")]
        key: Option<String>,

        /// Configure a keyless local provider (no API key required).
        #[arg(long, conflicts_with = "key")]
        no_key: bool,
    },

    /// Turn off semantic search and use fast local keyword matching.
    Disable,

    /// Rebuild the local semantic search index for this repo.
    Rebuild {
        /// Output as JSON.
        #[arg(long)]
        json: bool,
    },
}