0.1.6: GBrain brains — refreshed after sync, clashes never make a second page
- A vault has a kind on the hub: Obsidian (as before) or GBrain. Set it with
`lunesync vault kind`, the canvas panel or the window; Lune suggests it when
it finds gbrain.yml / .gbrain-source. Every change is in the access log.
- GBrain vaults: devices that have `gbrain` (looked for beyond PATH) are asked
once whether to refresh it after sync. Lune then runs
`gbrain sync --source <name> --no-pull` in the background after notes arrive
or are saved; it never holds up syncing. A failed refresh turns the vault
amber ("GBrain not refreshed") with Retry, also on the canvas.
- Clashes in GBrain vaults: lines both sides added are kept in the one note,
incoming first. Same lines changed: the incoming version stays, this
device's waits under Notes to tidy, stored in .git/lune/tidy (never a copy
file GBrain would index). Applies to syncing, undo, held notes and
handovers. Held notes moved aside stay red until decided.
- .gbrain-source is kept per device. Obsidian vaults are unchanged.
- SPEC: M8 section and decisions recorded.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
105
cli/src/main.rs
105
cli/src/main.rs
@@ -144,6 +144,20 @@ enum Command {
|
||||
#[command(subcommand)]
|
||||
action: HubCmd,
|
||||
},
|
||||
/// GBrain vaults: refresh GBrain on this device after notes arrive, and bring it up to date again after a failure
|
||||
Gbrain {
|
||||
#[arg(long)]
|
||||
vault: Option<String>,
|
||||
/// Refresh GBrain after notes arrive on this device: on or off
|
||||
#[arg(long)]
|
||||
refresh: Option<OnOff>,
|
||||
/// The name of this vault's source in GBrain on this device (default: the vault's name)
|
||||
#[arg(long)]
|
||||
source: Option<String>,
|
||||
/// Refresh GBrain now, even if nothing new arrived
|
||||
#[arg(long)]
|
||||
retry: bool,
|
||||
},
|
||||
/// Recent history entries and which device made them
|
||||
History {
|
||||
#[arg(long)]
|
||||
@@ -196,6 +210,11 @@ enum VaultCmd {
|
||||
#[arg(long)]
|
||||
yes: bool,
|
||||
},
|
||||
/// Say what a vault is for: gbrain (Lune refreshes GBrain after notes arrive) or obsidian (the default). Needs Manage
|
||||
Kind {
|
||||
name: String,
|
||||
kind: String,
|
||||
},
|
||||
/// Stop syncing a vault with its own remote (GitHub, GitLab…): it stays on this device only, ready to upload
|
||||
Detach { name: String },
|
||||
/// Move a vault that's only on this device onto the hub (detach it from any other remote first)
|
||||
@@ -333,6 +352,41 @@ fn run_cli(cli: Cli) -> Result<()> {
|
||||
}
|
||||
Command::Vault { action: VaultCmd::New { name } } => team::vault_new(&mut config, &name)?,
|
||||
Command::Vault { action: VaultCmd::Upload { name, fresh } } => team::vault_upload(&mut config, &name, fresh)?,
|
||||
Command::Vault { action: VaultCmd::Kind { name, kind } } => {
|
||||
let kind = lune_core::config::VaultKind::parse(&kind).context("a vault's kind is gbrain or obsidian")?;
|
||||
println!("{}", lune_core::brain::set_kind(&mut config, &name, kind)?);
|
||||
if kind == lune_core::config::VaultKind::Gbrain {
|
||||
println!("Other devices learn it within a minute. Next: `lunesync gbrain --vault {name} --refresh on` to refresh GBrain here after notes arrive.");
|
||||
}
|
||||
}
|
||||
Command::Gbrain { vault, refresh, source, retry } => {
|
||||
let name = config.pick(vault.as_deref(), &cwd)?.name.clone();
|
||||
let changed = refresh.is_some() || source.is_some();
|
||||
lune_core::brain::set_device_settings(
|
||||
&mut config,
|
||||
&name,
|
||||
refresh.map(|r| matches!(r, OnOff::On)),
|
||||
source,
|
||||
)?;
|
||||
let cfg = config.find(&name).unwrap().clone();
|
||||
if changed {
|
||||
println!("Saved.");
|
||||
}
|
||||
if retry {
|
||||
if lune_core::brain::refresh_now(&cfg, None, lune_core::brain::TIMEOUT, false)? {
|
||||
println!("GBrain is up to date for {name}.");
|
||||
} else {
|
||||
println!("GBrain is already being refreshed for {name}.");
|
||||
}
|
||||
} else {
|
||||
match (cfg.gbrain_refresh, lune_core::brain::find_gbrain()) {
|
||||
(Some(true), _) => println!("{name}: refreshing GBrain after sync is on (source \"{}\"). Turn off: `lunesync gbrain --vault {name} --refresh off`", cfg.gbrain_source_name()),
|
||||
(Some(false), _) => println!("{name}: refreshing GBrain after sync is off. Turn on: `lunesync gbrain --vault {name} --refresh on`"),
|
||||
(None, Some(p)) => println!("{name}: found gbrain at {}. Turn on refreshing GBrain after sync: `lunesync gbrain --vault {name} --refresh on` (or --refresh off to stop being asked).", p.display()),
|
||||
(None, None) => println!("{name}: the gbrain command wasn't found on this device, so nothing is refreshed."),
|
||||
}
|
||||
}
|
||||
}
|
||||
Command::Vault { action: VaultCmd::Detach { name } } => team::vault_detach(&mut config, &name)?,
|
||||
Command::Invite { person, vaults } => team::invite(&config, &person, &vaults)?,
|
||||
Command::Grant { person, vault, role } => team::grant(&config, &person, &vault, &role)?,
|
||||
@@ -407,10 +461,15 @@ fn run_cli(cli: Cli) -> Result<()> {
|
||||
let v = Vault::open(cfg, &config.device_label())?;
|
||||
for k in tidy::list(&v)? {
|
||||
if !any {
|
||||
println!("Notes changed in two places (both versions kept):");
|
||||
println!("Notes changed in two places (both versions kept; a GBrain vault keeps yours on this device):");
|
||||
}
|
||||
any = true;
|
||||
println!(" {:<12} {} ← {}", v.name, k.note, k.copy);
|
||||
if k.local {
|
||||
let why = if k.held { "kept on this device (it looked like a secret)" } else { "kept on this device" };
|
||||
println!(" {:<12} {} ← your version, {why}", v.name, k.note);
|
||||
} else {
|
||||
println!(" {:<12} {} ← {}", v.name, k.note, k.copy);
|
||||
}
|
||||
}
|
||||
}
|
||||
if any {
|
||||
@@ -430,7 +489,7 @@ fn run_cli(cli: Cli) -> Result<()> {
|
||||
};
|
||||
match tidy::keep(&v, &rel, choice)? {
|
||||
Some(saved) => println!("{}.", saved.message),
|
||||
None => println!("Nothing changed."),
|
||||
None => println!("Tidied."),
|
||||
}
|
||||
share_now(&v);
|
||||
}
|
||||
@@ -456,7 +515,7 @@ fn run_cli(cli: Cli) -> Result<()> {
|
||||
);
|
||||
println!(" Send it: `lunesync held share` Bring everything back: `lunesync held undo`");
|
||||
}
|
||||
for n in v.secret_holds()? {
|
||||
for n in v.all_secret_holds()? {
|
||||
any = true;
|
||||
for h in &n.hits {
|
||||
println!("{}: {} line {} has a possible {}: {}", v.name, n.path, h.line, h.rule, h.hint);
|
||||
@@ -516,9 +575,15 @@ fn held(config: &Config, cwd: &Path, vault: Option<&str>, cmd: HeldCmd) -> Resul
|
||||
} else {
|
||||
let kept = v.undo_held()?;
|
||||
println!("Brought everything back in {}.", v.name);
|
||||
for (note, copy) in kept {
|
||||
for (note, copy) in kept.copies {
|
||||
println!(" {note} was edited elsewhere meanwhile — kept both, the other version is \"{copy}\".");
|
||||
}
|
||||
for note in kept.joined {
|
||||
println!(" {note} had lines added elsewhere meanwhile — both sets of lines are kept.");
|
||||
}
|
||||
for note in kept.to_tidy {
|
||||
println!(" {note} was edited elsewhere meanwhile — the version from this device waits under `lunesync tidy`.");
|
||||
}
|
||||
}
|
||||
share_now(&v);
|
||||
}
|
||||
@@ -526,6 +591,13 @@ fn held(config: &Config, cwd: &Path, vault: Option<&str>, cmd: HeldCmd) -> Resul
|
||||
let (cfg, rel) = locate(config, vault, cwd, &file)?;
|
||||
let v = Vault::open(cfg, &label)?;
|
||||
let _op = state::op_lock(&v.git_dir)?;
|
||||
if v.secret_holds()?.iter().all(|n| n.path != rel)
|
||||
&& let Some((entry, hits)) = tidy::held_aside_hits(&v, &rel, line)?
|
||||
{
|
||||
tidy::replace_held_aside(&v, &entry, &hits, line, &pointer)?;
|
||||
println!("Replaced {} secret{} in your held version of {rel} with \"{pointer}\"; it waits in `lunesync tidy`.", hits.len(), if hits.len() == 1 { "" } else { "s" });
|
||||
return Ok(());
|
||||
}
|
||||
let hits = held_hits(&v, &rel, line)?;
|
||||
let path = v.root.join(&rel);
|
||||
let text = std::fs::read_to_string(&path)?;
|
||||
@@ -537,6 +609,18 @@ fn held(config: &Config, cwd: &Path, vault: Option<&str>, cmd: HeldCmd) -> Resul
|
||||
let (cfg, rel) = locate(config, vault, cwd, &file)?;
|
||||
let v = Vault::open(cfg, &label)?;
|
||||
let _op = state::op_lock(&v.git_dir)?;
|
||||
if v.secret_holds()?.iter().all(|n| n.path != rel)
|
||||
&& let Some((entry, hits)) = tidy::held_aside_hits(&v, &rel, line)?
|
||||
{
|
||||
tidy::allow_held_aside(&v, &entry, &hits)?;
|
||||
if let (Some(hub), Some(id)) = (config.hub_of(cfg), cfg.hub_vault) {
|
||||
for h in &hits {
|
||||
hub.not_a_secret(id, &h.line_hash)?;
|
||||
}
|
||||
}
|
||||
println!("OK — those lines won't be held again on this device; your version waits in `lunesync tidy`.");
|
||||
return Ok(());
|
||||
}
|
||||
for h in held_hits(&v, &rel, line)? {
|
||||
secrets::allow(&v.git_dir, &h, &rel)?;
|
||||
if let (Some(hub), Some(id)) = (config.hub_of(cfg), cfg.hub_vault) {
|
||||
@@ -652,6 +736,17 @@ fn print_status(cfg: &VaultConfig, label: &str) {
|
||||
if to_tidy > 0 {
|
||||
println!(" {to_tidy} note{} to tidy — see `lunesync tidy`", if to_tidy == 1 { "" } else { "s" });
|
||||
}
|
||||
if let Some(g) = &st.gbrain {
|
||||
match g.refresh {
|
||||
_ if g.failed => println!(" GBrain not refreshed{} — fix it, then `lunesync gbrain --vault {} --retry`", g.error.as_ref().map(|e| format!(" ({e})")).unwrap_or_default(), st.name),
|
||||
Some(true) => println!(" GBrain vault · refreshed after sync (source \"{}\")", g.source),
|
||||
Some(false) => println!(" GBrain vault · refreshing after sync is off"),
|
||||
None if g.ask => println!(" GBrain vault · found gbrain here — turn on refreshing after sync: `lunesync gbrain --vault {} --refresh on`", st.name),
|
||||
None => println!(" GBrain vault · the gbrain command wasn't found on this device"),
|
||||
}
|
||||
} else if st.suggest_gbrain {
|
||||
println!(" This looks like a GBrain — mark it with `lunesync vault kind {} gbrain`", st.name);
|
||||
}
|
||||
if !st.case_clashes.is_empty() {
|
||||
println!(" Names differing only by case: {}", st.case_clashes.join(", "));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user