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:
@@ -204,6 +204,11 @@ pub fn secret_pointer(vault: String, path: String, pointer: String) -> Answer<()
|
||||
return Err("say where to get it, e.g. \"search prod-deploy in Secrets Manager\"".into());
|
||||
}
|
||||
with_vault(&vault, |_, v| {
|
||||
if v.secret_holds()?.iter().all(|n| n.path != path)
|
||||
&& let Some((entry, hits)) = tidy::held_aside_hits(v, &path, None)?
|
||||
{
|
||||
return tidy::replace_held_aside(v, &entry, &hits, None, pointer.trim());
|
||||
}
|
||||
let hits = held_hits(v, &path)?;
|
||||
let file = v.root.join(&path);
|
||||
let text = std::fs::read_to_string(&file)?;
|
||||
@@ -216,6 +221,17 @@ pub fn secret_pointer(vault: String, path: String, pointer: String) -> Answer<()
|
||||
pub fn not_a_secret(vault: String, path: String) -> Answer<()> {
|
||||
with_vault(&vault, |config, v| {
|
||||
let cfg = config.find(&vault).unwrap();
|
||||
if v.secret_holds()?.iter().all(|n| n.path != path)
|
||||
&& let Some((entry, hits)) = tidy::held_aside_hits(v, &path, None)?
|
||||
{
|
||||
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)?;
|
||||
}
|
||||
}
|
||||
return Ok(());
|
||||
}
|
||||
for h in held_hits(v, &path)? {
|
||||
secrets::allow(&v.git_dir, &h, &path)?;
|
||||
if let (Some(hub), Some(id)) = (config.hub_of(cfg), cfg.hub_vault) {
|
||||
@@ -247,10 +263,11 @@ pub fn compare(vault: String, copy: String) -> Answer<Comparison> {
|
||||
let cfg = config.find(&vault).ok_or(format!("no vault named {vault}"))?;
|
||||
let v = Vault::open(cfg, &config.device_label()).map_err(plain)?;
|
||||
let k = tidy::list(&v).map_err(plain)?.into_iter().find(|k| k.copy == copy).ok_or("that was tidied already")?;
|
||||
let (note_bytes, copy_bytes) = tidy::versions(&v, &k).map_err(plain)?;
|
||||
Ok(Comparison {
|
||||
note_text: as_text(std::fs::read(v.root.join(&k.note)).ok()),
|
||||
copy_text: as_text(std::fs::read(v.root.join(&k.copy)).ok()),
|
||||
copy_is_mine: k.label.eq_ignore_ascii_case(&v.label),
|
||||
note_text: as_text(note_bytes),
|
||||
copy_text: as_text(Some(copy_bytes)),
|
||||
copy_is_mine: k.is_mine(&v),
|
||||
note: k.note,
|
||||
copy: k.copy,
|
||||
label: k.label,
|
||||
@@ -262,7 +279,7 @@ pub fn compare(vault: String, copy: String) -> Answer<Comparison> {
|
||||
pub fn tidy(vault: String, copy: String, keep: String) -> Answer<()> {
|
||||
with_vault(&vault, |_, v| {
|
||||
let k = tidy::list(v)?.into_iter().find(|k| k.copy == copy).ok_or_else(|| anyhow::anyhow!("that was tidied already"))?;
|
||||
let copy_is_mine = k.label.eq_ignore_ascii_case(&v.label);
|
||||
let copy_is_mine = k.is_mine(v);
|
||||
let choice = match (keep.as_str(), copy_is_mine) {
|
||||
("both", _) => Keep::Both,
|
||||
("copy", true) | ("note", false) => Keep::Mine,
|
||||
@@ -272,6 +289,46 @@ pub fn tidy(vault: String, copy: String, keep: String) -> Answer<()> {
|
||||
})
|
||||
}
|
||||
|
||||
/// Marks a vault as a GBrain (or back to Obsidian) on its team's hub; every device follows.
|
||||
#[tauri::command(async)]
|
||||
pub fn set_vault_kind(vault: String, kind: String) -> Answer<String> {
|
||||
let kind = lune_core::config::VaultKind::parse(&kind).ok_or("a vault is a GBrain or an Obsidian vault")?;
|
||||
let mut config = Config::load().map_err(plain)?;
|
||||
config.use_hub_credentials();
|
||||
lune_core::brain::set_kind(&mut config, &vault, kind).map_err(plain)
|
||||
}
|
||||
|
||||
/// This Mac's answer to "Refresh GBrain after sync", and its GBrain source name.
|
||||
#[tauri::command(async)]
|
||||
pub fn gbrain_settings(vault: String, refresh: Option<bool>, source: Option<String>) -> Answer<()> {
|
||||
let mut config = Config::load().map_err(plain)?;
|
||||
lune_core::brain::set_device_settings(&mut config, &vault, refresh, source).map_err(plain)?;
|
||||
if refresh == Some(true) {
|
||||
// Bring GBrain up to date once now, so turning it on is visibly working.
|
||||
if let Some(cfg) = config.find(&vault) {
|
||||
lune_core::brain::request(cfg);
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Tries refreshing GBrain again after "GBrain not refreshed".
|
||||
#[tauri::command(async)]
|
||||
pub fn gbrain_retry(vault: String) -> Answer<()> {
|
||||
let config = Config::load().map_err(plain)?;
|
||||
let cfg = config.find(&vault).ok_or(format!("no vault named {vault}"))?;
|
||||
lune_core::brain::request(cfg);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// "Not now" on the suggestion to mark a vault as a GBrain.
|
||||
#[tauri::command(async)]
|
||||
pub fn dismiss_gbrain_hint(vault: String) -> Answer<()> {
|
||||
let config = Config::load().map_err(plain)?;
|
||||
let cfg = config.find(&vault).ok_or(format!("no vault named {vault}"))?;
|
||||
lune_core::brain::dismiss_suggestion(&cfg.path.join(".git")).map_err(plain)
|
||||
}
|
||||
|
||||
/// Leaves a team on this Mac. `forget` drops a hub that can't be reached (its folders stay).
|
||||
#[tauri::command(async)]
|
||||
pub fn leave_team(team: String, forget: bool) -> Answer<String> {
|
||||
|
||||
@@ -359,6 +359,10 @@ fn main() {
|
||||
commands::tidy,
|
||||
commands::open_canvas,
|
||||
commands::leave_team,
|
||||
commands::set_vault_kind,
|
||||
commands::gbrain_settings,
|
||||
commands::gbrain_retry,
|
||||
commands::dismiss_gbrain_hint,
|
||||
commands::open_folder,
|
||||
commands::restart,
|
||||
])
|
||||
|
||||
Reference in New Issue
Block a user