Milestone 7: the app normal people install (macOS)

A Tauri menu-bar app runs the same sync engine as `lunesync run`. It
connects from the website with no code typed (lune://join and
lune://pair links), shows status in the menu bar, and lets a person
resolve held secrets, held big changes and kept-both notes side by
side. Uninstall shares and hands over first, then removes only what
Lune created.

Releases are signed on the hub that holds the key (`lunehub release
keygen/publish`); other hubs `release import` them. Apps verify the
signature and the signed version. Clients older than the previous
release are asked to update and keep saving locally.

A device can now be on several hubs at once (own and workplace), each
with its own key; the CLI takes --team when it matters. The supervisor
and status summary moved into core, shared by the CLI and the app.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-29 11:47:35 +07:00
parent 8be559817c
commit 6cb85004fb
59 changed files with 6871 additions and 210 deletions

View File

@@ -1,6 +1,6 @@
[package]
name = "lunesync"
version = "0.1.0"
version.workspace = true
edition = "2024"
[dependencies]

View File

@@ -7,20 +7,20 @@ use clap::{Parser, Subcommand, ValueEnum};
use lune_core::config::{Config, VaultConfig};
use lune_core::guard;
use lune_core::secrets;
use lune_core::runner::{self, Timing};
use lune_core::state::{self, SyncState};
use lune_core::tidy::{self, Keep};
use lune_core::vault::{self, Added, Vault};
use lune_core::remote;
use std::collections::HashSet;
use std::path::{Path, PathBuf};
use std::time::{Duration, Instant};
#[derive(Parser)]
#[command(name = "lunesync", version, about = "Keeps every copy of your vaults in sync.")]
struct Cli {
#[command(subcommand)]
command: Command,
/// Which team's hub, when this device is on more than one (part of its address, e.g. its host name)
#[arg(long, global = true)]
team: Option<String>,
}
#[derive(Subcommand)]
@@ -280,6 +280,7 @@ fn run_cli(cli: Cli) -> Result<()> {
let mut config = Config::load()?;
config.use_hub_credentials();
let cwd = std::env::current_dir()?;
team::choose(cli.team);
match cli.command {
Command::Device { action: None } => println!("This device is \"{}\".", config.device_label()),
Command::Device { action: Some(DeviceCmd::Name { label }) } => {
@@ -287,7 +288,7 @@ fn run_cli(cli: Cli) -> Result<()> {
if label.is_empty() {
bail!("the label can't be empty");
}
if let Some(h) = &config.hub {
for h in &config.hubs {
h.set_label(&label)?;
}
config.device_name = Some(label.clone());
@@ -346,7 +347,7 @@ fn run_cli(cli: Cli) -> Result<()> {
println!("No vaults yet. Add one with `lunesync add <name> <folder> --remote <url>`.");
}
println!("Device: {}", config.device_label());
if let Some(h) = &config.hub {
for h in &config.hubs {
match h.me() {
Ok(me) => println!("Hub: {} as {}{}", h.url, me.person, if me.owner { " (team owner)" } else { "" }),
Err(e) => println!("Hub: {} — can't reach it right now ({e})", h.url),
@@ -506,7 +507,7 @@ fn held(config: &Config, cwd: &Path, vault: Option<&str>, cmd: HeldCmd) -> Resul
let _op = state::op_lock(&v.git_dir)?;
for h in held_hits(&v, &rel, line)? {
secrets::allow(&v.git_dir, &h, &rel)?;
if let (Some(hub), Some(id)) = (&config.hub, cfg.hub_vault) {
if let (Some(hub), Some(id)) = (config.hub_of(cfg), cfg.hub_vault) {
hub.not_a_secret(id, &h.line_hash)?;
}
println!("OK — line {} of {rel} won't be held again on this device.", h.line);
@@ -569,59 +570,11 @@ fn log_line(vault: &str, msg: &str) {
/// Syncs every vault, picks up vaults added meanwhile, and checks the hub for new memberships.
fn run() -> Result<()> {
let mut started: HashSet<PathBuf> = HashSet::new();
let mut hub_check = Instant::now();
let mut hub_said = String::new();
loop {
let mut config = Config::load()?;
config.use_hub_credentials();
if config.vaults.is_empty() && config.hub.is_none() {
bail!("no vaults yet — add one with `lunesync add <name> <folder> --remote <url>` or join a hub");
}
if config.hub.is_some() && Instant::now() >= hub_check {
hub_check = Instant::now() + Duration::from_secs(30);
match team::arrive(&mut config) {
Ok(msgs) => {
hub_said.clear();
msgs.iter().for_each(|m| log_line("hub", m));
if let Err(e) = lune_core::membership::report(&config) {
log_line("hub", &format!("couldn't report health: {e:#}"));
}
}
Err(e) => {
let msg = format!("can't check the hub: {e:#}");
if msg != hub_said {
log_line("hub", &msg);
hub_said = msg;
}
}
}
}
// A vault that left (access ended) can come back later at the same place.
started.retain(|p| config.vaults.iter().any(|v| &v.path == p));
for cfg in &config.vaults {
if !started.insert(cfg.path.clone()) {
continue;
}
let (cfg, label, poll) = (cfg.clone(), config.device_label(), config.poll_interval());
std::thread::spawn(move || {
loop {
match runner::run(&cfg, &label, poll, Timing::default(), &log_line) {
Ok(()) => return,
Err(e) if format!("{e}").contains("already being synced") => {
log_line(&cfg.name, &format!("{e:#}"));
return;
}
Err(e) => {
log_line(&cfg.name, &format!("stopped: {e:#} — retrying in 30 s"));
std::thread::sleep(Duration::from_secs(30));
}
}
}
});
}
std::thread::sleep(Duration::from_secs(2));
let config = Config::load()?;
if config.vaults.is_empty() && config.hubs.is_empty() {
bail!("no vaults yet — add one with `lunesync add <name> <folder> --remote <url>` or join a hub");
}
lune_core::supervisor::supervise(log_line)
}
/// After a one-off command, try to share right away; the runner picks it up otherwise.
@@ -645,48 +598,32 @@ fn share_now(v: &Vault) {
fn print_status(cfg: &VaultConfig, label: &str) {
println!("\n{} — {}", cfg.name, cfg.path.display());
let v = match Vault::open(cfg, label) {
Ok(v) => v,
Err(e) => {
println!(" Can't open: {e:#}");
return;
}
};
let st = SyncState::load(&v.git_dir);
let read_only = v.role().is_some_and(|r| !lune_core::hub::can_edit(&r));
let waiting = v.waiting_files().unwrap_or(0);
let changes = format!("{waiting} change{}", if waiting == 1 { "" } else { "s" });
let headline = match &st.last_error {
None if read_only && waiting > 0 => format!("Up to date · {changes} kept here, not shared (you have read access)"),
None if read_only => "Up to date (read access)".to_string(),
Some(e) if e.starts_with("offline") => format!("Offline · waiting to sync · {changes}"),
Some(e) => format!("Can't sync: {e}{}", if waiting > 0 { format!(" · {changes} waiting") } else { String::new() }),
None if waiting > 0 => format!("Waiting to sync · {changes}"),
None if st.last_synced.is_some() => format!("Synced {}", ago(st.last_synced.unwrap())),
None => "Not synced yet".to_string(),
};
println!(" {headline}");
let st = lune_core::status::of(cfg, label);
match st.last_synced {
Some(t) if st.headline == "Synced" => println!(" Synced {}", ago(t)),
_ => println!(" {}", st.headline),
}
if let Some(t) = st.last_synced {
println!(" Last sync: {} ({})", Local.timestamp_opt(t, 0).unwrap().format("%Y-%m-%d %H:%M:%S"), ago(t));
}
for h in guard::load(&v.git_dir) {
for h in &st.held {
println!(" Holding back a big change: \"{}\" — nothing from here is shared until you decide (`lunesync held`)", h.message);
}
let secret_notes = v.secret_holds().map(|l| l.len()).unwrap_or(0);
let secret_notes = st.secrets.len();
if secret_notes > 0 {
println!(
" {secret_notes} note{} not shared: looks like a secret (`lunesync held`)",
if secret_notes == 1 { "" } else { "s" }
);
}
let to_tidy = tidy::list(&v).map(|l| l.len()).unwrap_or(0);
let to_tidy = st.tidy.len();
if to_tidy > 0 {
println!(" {to_tidy} note{} to tidy — see `lunesync tidy`", if to_tidy == 1 { "" } else { "s" });
}
if !st.case_clashes.is_empty() {
println!(" Names differing only by case: {}", st.case_clashes.join(", "));
}
if !state::is_running(&v.git_dir) {
if !st.running && !st.headline.starts_with("Can't open") {
println!(" Not running — start `lunesync run` or `lunesync service install`");
}
}

View File

@@ -9,12 +9,20 @@ use lune_core::state;
use lune_core::vault::Vault;
use std::path::PathBuf;
static TEAM: std::sync::OnceLock<Option<String>> = std::sync::OnceLock::new();
/// The `--team` choice for this command.
pub fn choose(team: Option<String>) {
let _ = TEAM.set(team);
}
/// The hub this command talks to: the one `--team` names, or the only one.
pub fn link(config: &Config) -> Result<&HubLink> {
config.hub.as_ref().context("this device isn't on a hub yet — `lunesync join <invite link>` or `lunesync login`")
config.pick_hub(TEAM.get().cloned().flatten().as_deref())
}
fn connect(config: &mut Config, url: String, w: hub::Welcome, label: &str, vaults_dir: Option<PathBuf>) -> Result<()> {
config.hub = Some(HubLink { url, device_id: w.device_id, key: w.key });
config.hubs.push(HubLink { url, device_id: w.device_id, key: w.key });
config.device_name = Some(label.to_string());
if vaults_dir.is_some() {
config.vaults_dir = vaults_dir;
@@ -30,16 +38,17 @@ fn connect(config: &mut Config, url: String, w: hub::Welcome, label: &str, vault
}
pub fn join(config: &mut Config, invite: &str, label: &str, vaults_dir: Option<PathBuf>) -> Result<()> {
if let Some(h) = &config.hub {
bail!("this device is already on the hub at {}", h.url);
let url = invite.split("/join/").next().unwrap_or_default().trim_end_matches('/');
if config.hub(url).is_some() {
bail!("this device is already on the hub at {url}");
}
let (url, w) = hub::join(invite, label)?;
connect(config, url, w, label, vaults_dir)
}
pub fn login(config: &mut Config, url: &str, code: &str, label: &str, vaults_dir: Option<PathBuf>) -> Result<()> {
if let Some(h) = &config.hub {
bail!("this device is already on the hub at {}", h.url);
if config.hub(url.trim_end_matches('/')).is_some() {
bail!("this device is already on the hub at {url}");
}
let w = hub::login(url, code, label)?;
connect(config, url.trim_end_matches('/').to_string(), w, label, vaults_dir)
@@ -94,6 +103,7 @@ pub fn vault_upload(config: &mut Config, name: &str, fresh: bool) -> Result<()>
let vc = config.vaults.iter_mut().find(|x| x.path == cfg.path).unwrap();
vc.remote = hv.git_url.clone();
vc.hub_vault = Some(hv.id);
vc.hub_url = Some(h.url.clone());
config.save()?;
println!("{} now syncs through the hub{}.", cfg.name, if fresh { ", starting fresh" } else { ", history included" });
println!("Other devices with this vault: `lunesync pair` here, then `lunesync login …` there — it moves over on its own.");