fur-cli 2.1.1

Turn your AI chats into a durable, local-first diary. Save messages, attach notes, organize conversations, and stop losing context every time the model forgets you exist.
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
pub mod avatars;
mod commands;
mod git;
mod helpers;
mod renderer;
mod schema;
mod security;
mod utils;
use colored::Colorize;

use clap::{CommandFactory, Parser, Subcommand};
use clap_complete::{
    generate,
    shells::{Bash, Fish, Zsh},
};
use serde_json::Value;
use std::fs;
use std::io;
use std::path::Path;

use crate::commands::{
    avatar, chat, clone, conversation,
    doctor::{self, DoctorArgs},
    export::{self, ExportArgs},
    graph::{self, GraphArgs},
    id::{self, IdArgs},
    jot::{self, JotArgs},
    jump::{self, JumpArgs},
    link::{self, LinkArgs},
    message::{self, MsgArgs},
    new,
    onboard::{self, OnboardArgs},
    printed,
    rebuild::{self, RebuildArgs},
    search::{self, SearchArgs},
    status,
    sweep::{self, SweepArgs},
    timeline::{self, TimelineArgs},
    tree::{self, TreeArgs},
    xclone,
};

#[derive(Parser)]
#[command(
    name = "fur",
    version,
    about = "FUR: AI Conversation Control System",
    long_about = "FUR turns your AI conversations into a digital diary. A solution to the long-term memory problem of AI chats."
)]
struct Cli {
    #[command(subcommand)]
    command: Commands,
}

#[derive(Subcommand)]
enum Commands {
    // Hidden completions
    #[command(hide = true)]
    Completions {
        #[arg(value_parser = ["bash", "zsh", "fish"])]
        shell: String,
    },

    // Git passthrough
    Status {},
    Add {
        #[arg(trailing_var_arg = true, allow_hyphen_values = true)]
        args: Vec<String>,
    },
    Commit {
        #[arg(trailing_var_arg = true, allow_hyphen_values = true)]
        args: Vec<String>,
    },
    Push {
        #[arg(trailing_var_arg = true, allow_hyphen_values = true)]
        args: Vec<String>,
    },
    Pull {
        #[arg(trailing_var_arg = true, allow_hyphen_values = true)]
        args: Vec<String>,
    },

    #[command(about = "Security:: Encrypt the current fur diary")]
    Lock(security::lock::LockArgs),

    #[command(about = "Security:: Decrypt the current fur diary")]
    Unlock(security::unlock::UnlockArgs),

    #[command(about = "Security:: Generate a Diceware passphrase for encryption")]
    Keygen {
        #[arg(short, long, default_value_t = 6)]
        words: usize,
    },

    // Everyday
    #[command(about = "Everyday:: Start a new conversation (new convo)")]
    New {
        name: String,
    },

    #[command(about = "Everyday:: Jot something out (write short form in quotes)")]
    Jot(JotArgs),

    #[command(about = "Everyday:: Paste a full chat (write long form)")]
    Chat {
        avatar: Option<String>,
    },

    #[command(about = "Everyday:: Edit or Delete a jotted message")]
    Msg(MsgArgs),

    #[command(about = "Everyday:: Record that a conversation derives from another")]
    Link(LinkArgs),

    #[command(about = "Everyday:: Remove a conversation lineage edge")]
    Unlink(LinkArgs),

    #[command(about = "Everyday:: Show full conversation (replaces timeline --verbose)")]
    Show(TimelineArgs),

    #[command(about = "Everyday:: Print timeline of full conversation.")]
    Timeline(TimelineArgs),

    #[command(about = "Everyday:: Export full conversation as Markdown")]
    Printed {
        out: Option<String>,

        /// Include the text of long-form attachments
        #[arg(short, long)]
        verbose: bool,

        /// Include everything this conversation draws on
        #[arg(long)]
        provenance: bool,

        /// Provenance in both directions: sources and what came after
        #[arg(long, conflicts_with = "provenance")]
        full: bool,

        /// Conversation to print (id or prefix); defaults to the active one
        #[arg(long)]
        id: Option<String>,
    },

    #[command(about = "Everyday:: Search all conversations for text or markdown matches")]
    Search(SearchArgs),

    #[command(about = "Everyday:: Export conversations as canonical Markdown into chats/")]
    Export(ExportArgs),

    #[command(about = "Management:: Repair missing or moved attachments")]
    Doctor(DoctorArgs),

    #[command(about = "Management:: Import a published FUR conversation from a registry")]
    Import {
        /// Registry publication ID
        publication_id: String,

        /// Import a complete published FUR diary
        #[arg(long)]
        diary: bool,

        /// Publication registry base URL
        #[arg(long, default_value = "http://127.0.0.1:8000")]
        registry: String,
    },

    #[command(about = "Everyday:: Publish a canonical conversation to a registry")]
    Publish {
        /// Conversation ID or unique short hash; defaults to the active conversation
        conversation: Option<String>,

        /// Publish a FUR project diary. With no value, uses the current project;
        /// pass a path such as `fur publish --diary atom` after `fur scan`.
        #[arg(
            long,
            conflicts_with = "conversation",
            num_args = 0..=1,
            default_missing_value = "."
        )]
        diary: Option<String>,

        /// Publication registry base URL
        #[arg(long, default_value = "http://127.0.0.1:8000")]
        registry: String,
    },

    #[command(about = "Management:: Rebuild .fur/ from the documents in chats/")]
    Rebuild(RebuildArgs),

    #[command(about = "Management:: Set which avatar is you, and pick faces")]
    Onboard(OnboardArgs),

    // Management
    #[command(about = "Management:: See or create new conversation avatars/personas")]
    Avatar {
        #[command(subcommand)]
        action: Option<AvatarAction>,
        #[arg(long)]
        view: bool,
        /// Avatar to describe (used with --name / --role / --kind / --clear-role)
        name: Option<String>,
        /// Human-readable name, e.g. "Pedro Quispe"
        #[arg(long = "name")]
        display_name: Option<String>,
        /// Functional role, e.g. "Analista Económico"
        #[arg(long)]
        role: Option<String>,
        /// human or ai
        #[arg(long, value_parser = ["human", "ai"])]
        kind: Option<String>,
        /// Remove the role
        #[arg(long)]
        clear_role: bool,
    },

    #[command(about = "Setup:: Show or set who this machine writes as")]
    Id(IdArgs),

    #[command(about = "Management:: Clone a conversation safely (deep copy)")]
    Clone {
        /// Optional: conversation ID or prefix
        #[arg(short, long, default_value = "")]
        id: String,

        /// Optional: custom title for the new conversation
        #[arg(short, long)]
        title: Option<String>,
    },

    #[command(about = "Management:: Deep clone a conversation into another .fur project", visible_aliases = ["xc"])]
    Xclone {
        /// Path to the target project (folder containing .fur/)
        #[arg(long)]
        to: String,

        /// Conversation ID or prefix (defaults to active thread)
        #[arg(short, long, default_value = "")]
        id: String,

        /// Optional custom title for the cloned conversation
        #[arg(short, long)]
        title: Option<String>,
    },

    #[command(
        about = "Management:: See or jump to any of your conversations",
        visible_alias = "conversation"
    )]
    Convo(conversation::ThreadArgs),

    #[command(about = "Management:: Tree of full conversation")]
    Tree(TreeArgs),

    #[command(about = "Management:: Export conversation lineage as JSON")]
    Graph(GraphArgs),

    #[command(about = "Management:: Scan for FUR projects beneath the current directory")]
    Scan {
        /// Maximum recursion depth
        #[arg(long, default_value_t = 5)]
        depth: usize,

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

        /// Suppress warnings
        #[arg(long)]
        silent: bool,
    },

    #[command(
        about = "Management:: Global search of all your FUR projects (starting from your home directory)"
    )]
    Gsearch(SweepArgs),

    // Experimental
    #[command(about = "Under development:: Jump to specific chat within convo")]
    Jump(JumpArgs),
}

#[derive(Subcommand)]
enum AvatarAction {
    New,
}

enum GitCmd {
    Status,
    Add(Vec<String>),
    Commit(Vec<String>),
    Push(Vec<String>),
    Pull(Vec<String>),
}

fn dispatch_git(cmd: GitCmd) {
    match cmd {
        GitCmd::Status => {
            let args = status::StatusArgs {
                conversation_override: None,
            };
            status::run_status(args);
            if let Some(repo) = utils::git::find_git_root() {
                git::status::run_git_status(&repo);
            }
        }
        GitCmd::Add(args) => git::passthrough::passthrough("add", &args),
        GitCmd::Commit(args) => git::passthrough::passthrough("commit", &args),
        GitCmd::Push(args) => git::passthrough::passthrough("push", &args),
        GitCmd::Pull(args) => git::passthrough::passthrough("pull", &args),
    }
}

fn main() {
    let cli = Cli::parse();

    // Locked archives, and copied archives with no .fur/ index.
    let exempt = matches!(
        cli.command,
        Commands::Unlock(_) | Commands::Keygen { .. } | Commands::Completions { .. }
    );
    if !commands::rebuild::preflight(exempt) {
        return;
    }

    let skip_schema_migration = std::env::var_os("FUR_SKIP_SCHEMA_MIGRATION").is_some();

    if !skip_schema_migration && schema::detect_old_schema() {
        println!("{}", "⚠ Older FUR schema detected.".bright_yellow().bold());

        if schema::ask_yes_no("Run metadata migration now?") {
            schema::run_backfill_meta();
        } else {
            println!("Skipping migration.\n");
        }
    }

    match cli.command {
        Commands::Completions { shell } => {
            let mut cmd = Cli::command();

            match shell.as_str() {
                "bash" => generate(Bash, &mut cmd, "fur", &mut io::stdout()),
                "zsh" => generate(Zsh, &mut cmd, "fur", &mut io::stdout()),
                "fish" => generate(Fish, &mut cmd, "fur", &mut io::stdout()),
                _ => eprintln!("Unsupported shell: {}", shell),
            }
        }

        Commands::Lock(args) => security::lock::run_lock(args),
        Commands::Unlock(args) => security::unlock::run_unlock(args),
        Commands::Keygen { words } => {
            let (pass, entropy) = security::crypto::generate_password(words);

            println!("\nGenerated passphrase:\n{}\n", pass);

            println!("Entropy ≈ {:.1} bits\n", entropy);

            if entropy < 70.0 {
                println!("⚠ Warning: low entropy passphrase (recommended ≥ 6 words)");
            }
        }
        Commands::Status {} => dispatch_git(GitCmd::Status),
        Commands::Add { args } => dispatch_git(GitCmd::Add(args)),
        Commands::Commit { args } => dispatch_git(GitCmd::Commit(args)),
        Commands::Push { args } => dispatch_git(GitCmd::Push(args)),
        Commands::Pull { args } => dispatch_git(GitCmd::Pull(args)),

        Commands::New { name } => new::run_new(name),

        Commands::Jot(a) => jot::run_jot(a),

        Commands::Chat { avatar } => chat::run_chat(avatar),

        Commands::Msg(a) => message::run_msg(a),

        Commands::Link(a) => link::run_link(a),

        Commands::Unlink(a) => link::run_unlink(a),

        Commands::Timeline(a) => timeline::run_timeline(a),

        Commands::Show(a) => {
            let mut a = a;
            a.verbose = true; // force verbose mode
            timeline::run_timeline(a);
        }

        Commands::Printed {
            out,
            verbose,
            provenance,
            full,
            id,
        } => {
            let scope = if full {
                Some(commands::provenance::Scope::Full)
            } else if provenance {
                Some(commands::provenance::Scope::Ancestors)
            } else {
                None
            };
            printed::run_printed(out, verbose, scope, id)
        }

        Commands::Doctor(args) => doctor::run_doctor(args),

        Commands::Import {
            publication_id,
            diary,
            registry,
        } => commands::registry::run_import(&publication_id, diary, &registry),

        Commands::Publish {
            conversation,
            diary,
            registry,
        } => commands::publish::run_publish(
            conversation.as_deref(),
            diary.as_deref(),
            &registry,
        ),

        Commands::Rebuild(args) => rebuild::run_rebuild(args),

        Commands::Onboard(args) => onboard::run_onboard(args),

        Commands::Avatar {
            action,
            name,
            display_name,
            role,
            kind,
            clear_role,
            ..
        } => match action {
            Some(AvatarAction::New) => avatar::run_avatar_onboarding(),
            None => match name {
                // `fur avatar <handle> --name/--role/--kind …` describes an
                // avatar; bare `fur avatar` keeps listing them.
                Some(target)
                    if display_name.is_some() || role.is_some() || kind.is_some() || clear_role =>
                {
                    avatar::run_avatar_meta(
                        &target,
                        display_name.as_deref(),
                        role.as_deref(),
                        kind.as_deref(),
                        clear_role,
                    )
                }
                _ => avatar::run_avatar_view(),
            },
        },

        Commands::Id(a) => id::run_id(a),

        Commands::Convo(a) => conversation::run_conversation(a),
        Commands::Xclone { to, id, title } => {
            // If no id given, fall back to active thread
            let tid_to_clone = if id.is_empty() {
                let index_path = Path::new(".fur").join("index.json");
                let index: Value = serde_json::from_str(&fs::read_to_string(&index_path).unwrap())
                    .expect("❌ Failed to read index.json");
                index["active_thread"]
                    .as_str()
                    .expect("❌ No active thread set")
                    .to_string()
            } else {
                id
            };

            xclone::run_xclone(&to, &tid_to_clone, title);
        }

        Commands::Tree(a) => tree::run_tree(a),

        Commands::Graph(a) => graph::run_graph(a),
        Commands::Search(a) => search::run_search(a),
        Commands::Export(a) => export::run_export(a),

        Commands::Scan {
            depth,
            json,
            silent,
        } => {
            sweep::run_sweep(sweep::SweepArgs {
                dir: Some(".".to_string()),
                depth,
                json,
                silent,
            });
        }

        Commands::Gsearch(a) => sweep::run_sweep(a),

        Commands::Clone { id, title } => {
            if id.is_empty() {
                clone::run_clone_from_active(title);
            } else {
                clone::run_clone(&id, title);
            }
        }

        Commands::Jump(a) => {
            if let Err(e) = jump::run_jump(a) {
                eprintln!("Error: {}", e);
            }
        }
    }
}