Milestone 6: canvas for health and leaving

Devices report freshness per vault every 30 s (counts only); the canvas
shows current / behind / offline, held secrets in red, and a Nudge that
reaches the device at its next check-in. Notes kept in two versions can
be compared side by side and tidied on the hub's copy. Handovers are
reviewed in the vault panel; people can be removed from the team and
restored with a one-time link.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-29 09:47:28 +07:00
parent 193cb06f85
commit 8be559817c
15 changed files with 744 additions and 57 deletions

View File

@@ -32,6 +32,19 @@ pub struct Me {
/// Vaults this device must leave (access ended).
#[serde(default)]
pub leaving: Vec<Departure>,
/// Someone asked this device to share now (Nudge).
#[serde(default)]
pub nudge: bool,
}
/// One vault's health, as a device reports it to the hub: counts only, never content.
#[derive(Debug, Serialize)]
pub struct VaultHealth {
pub vault_id: i64,
pub last_synced: Option<i64>,
pub waiting: usize,
pub held_secrets: usize,
pub holding: bool,
}
/// A vault this device has to hand over and leave (A6).
@@ -186,6 +199,11 @@ impl HubLink {
Ok(v["url"].as_str().unwrap_or_default().to_string())
}
pub fn report(&self, vaults: &[VaultHealth]) -> Result<()> {
let _: Value = self.post("/api/report", json!({ "vaults": vaults }))?;
Ok(())
}
pub fn remove(&self, person: &str, vault: &str, without_saving: bool) -> Result<usize> {
let v: Value = self.post("/api/remove", json!({"person": person, "vault": vault, "without_saving": without_saving}))?;
Ok(v["devices"].as_u64().unwrap_or(0) as usize)

View File

@@ -34,6 +34,16 @@ pub fn arrive(config: &mut Config) -> Result<Vec<String>> {
for d in &me.leaving {
said.push(leave(config, &h, d)?);
}
if me.nudge {
// Each vault's runner sees this and shares at once.
for vc in config.vaults.iter().filter(|v| v.hub_vault.is_some()) {
let dir = state::lune_dir(&vc.path.join(".git"));
if dir.exists() {
std::fs::write(dir.join("nudge"), "")?;
}
}
said.push("Someone asked this device to share now — sharing".into());
}
for hv in me.vaults {
if let Some(vc) = config.vaults.iter().find(|v| v.hub_vault == Some(hv.id)) {
@@ -72,6 +82,24 @@ pub fn arrive(config: &mut Config) -> Result<Vec<String>> {
Ok(said)
}
/// Tells the hub how each of this device's hub vaults is doing (M6 freshness).
pub fn report(config: &Config) -> Result<()> {
let Some(h) = &config.hub else { return Ok(()) };
let label = config.device_label();
let mut out = vec![];
for vc in config.vaults.iter().filter(|v| v.hub_vault.is_some()) {
let Ok(v) = Vault::open(vc, &label) else { continue };
out.push(hub::VaultHealth {
vault_id: vc.hub_vault.unwrap(),
last_synced: state::SyncState::load(&v.git_dir).last_synced,
waiting: v.waiting_files().unwrap_or(0),
held_secrets: v.secret_holds().map(|n| n.len()).unwrap_or(0),
holding: !crate::guard::load(&v.git_dir).is_empty(),
});
}
h.report(&out)
}
/// Leaves one vault: stop syncing, save, make read-only, hand over what wasn't shared, and once the
/// hub has it, delete the folder if the app created it.
pub fn leave(config: &mut Config, link: &HubLink, d: &Departure) -> Result<String> {

View File

@@ -95,11 +95,18 @@ pub fn run(cfg: &VaultConfig, label: &str, poll: Duration, timing: Timing, log:
let mut was_read_only = false;
let mut announced: HashSet<String> = HashSet::new();
let leaving = state::lune_dir(&vault.git_dir).join("leaving");
let nudge = state::lune_dir(&vault.git_dir).join("nudge");
loop {
if leaving.exists() {
say("access to this vault ended — stopped syncing it");
return Ok(());
}
if nudge.exists() {
// Nudged from the canvas: save what has settled and share right away.
let _ = std::fs::remove_file(&nudge);
rescan_at = Instant::now();
sync_at = Instant::now();
}
let first = rx.recv_timeout(Duration::from_millis(250));
for ev in first.into_iter().chain(rx.try_iter()) {
match ev {