Milestone 2: secret check and runaway guard
Notes with a likely secret on a new line are held on the device (own short rule list, per SPEC §8); `lunesync held pointer|not-secret` resolves them. Bursts removing or rewriting a big part of the vault are saved but not shared until `lunesync held share|undo`. Incoming edits to a held note land in place with the held version kept beside it. Adds `tidy show` and SPEC §6 detail for M2. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -91,6 +91,8 @@ pub fn run(cfg: &VaultConfig, label: &str, poll: Duration, timing: Timing, log:
|
||||
let mut sync_at = Instant::now();
|
||||
let mut backoff = poll;
|
||||
let mut was_waiting = false;
|
||||
let mut was_holding = false;
|
||||
let mut announced: HashSet<String> = HashSet::new();
|
||||
loop {
|
||||
let first = rx.recv_timeout(Duration::from_millis(250));
|
||||
for ev in first.into_iter().chain(rx.try_iter()) {
|
||||
@@ -116,11 +118,39 @@ pub fn run(cfg: &VaultConfig, label: &str, poll: Duration, timing: Timing, log:
|
||||
match vault.save_changes(None, &skip) {
|
||||
Ok(Some(saved)) => {
|
||||
say(&format!("saved: {}", saved.message));
|
||||
if let Some(d) = saved.held {
|
||||
say(&format!(
|
||||
"HELD: this change removes or rewrites {} of {} notes, so it stays on this device. \
|
||||
`lunesync held share` to send it anyway, `lunesync held undo` to bring everything back",
|
||||
d.removed + d.rewritten,
|
||||
d.total
|
||||
));
|
||||
}
|
||||
sync_at = now;
|
||||
}
|
||||
Ok(None) => {}
|
||||
Err(e) => say(&format!("couldn't save changes: {e:#}")),
|
||||
}
|
||||
match vault.secret_holds() {
|
||||
Ok(notes) => {
|
||||
let mut current = HashSet::new();
|
||||
for n in notes {
|
||||
for h in n.hits {
|
||||
let key = format!("{}:{}", n.path, h.line_hash);
|
||||
if !announced.contains(&key) {
|
||||
say(&format!(
|
||||
"HELD: {} line {} has a possible {} ({}), so this note isn't shared. \
|
||||
`lunesync held` to replace it with a pointer or mark it not a secret",
|
||||
n.path, h.line, h.rule, h.hint
|
||||
));
|
||||
}
|
||||
current.insert(key);
|
||||
}
|
||||
}
|
||||
announced = current;
|
||||
}
|
||||
Err(e) => say(&format!("couldn't run the secret check: {e:#}")),
|
||||
}
|
||||
}
|
||||
|
||||
if Instant::now() >= sync_at {
|
||||
@@ -131,9 +161,13 @@ pub fn run(cfg: &VaultConfig, label: &str, poll: Duration, timing: Timing, log:
|
||||
match result {
|
||||
Ok(report) => {
|
||||
st.last_error = None;
|
||||
if !report.waiting_for_local_edits {
|
||||
if !report.waiting_for_local_edits && !report.holding {
|
||||
st.last_synced = st.last_attempt;
|
||||
}
|
||||
if report.holding && !was_holding {
|
||||
say("not sharing anything from this device while a big change is held");
|
||||
}
|
||||
was_holding = report.holding;
|
||||
if report.waiting_for_local_edits && !was_waiting {
|
||||
say("new changes are waiting until your current edits settle");
|
||||
}
|
||||
@@ -180,6 +214,9 @@ fn print_report(r: &SyncReport, say: &dyn Fn(&str)) {
|
||||
for (note, copy) in &r.kept_both {
|
||||
say(&format!("{note} was changed in two places — kept both, yours is in \"{copy}\""));
|
||||
}
|
||||
for (note, copy) in &r.set_aside {
|
||||
say(&format!("{note} changed elsewhere while held here — your held version is now \"{copy}\""));
|
||||
}
|
||||
for (old, new) in &r.case_renamed {
|
||||
say(&format!("{old} clashed with another name differing only by case — renamed to {new}"));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user