M1.7: crash-recovery journal and restore dialog
Dirty buffers are written atomically to <data_dir>/recovery/<project-id>/ about 1 s after the last edit (at most 2 s while typing), from pump_vfs, never per keystroke. Entries are removed on save, close (also force), forced project close/open and recovery.discard. project.open emits recoveryAvailable; recovery.list/restore/discard; restored buffers are dirty and keep line ending and BOM. Corrupt entries are moved aside and reported as warning notifications. UI: restore dialog in ui/src/components/recovery (Restore all, Restore selected, Discard, time, changed-on-disk hint), catalog keys and runtime allow-list. Tests: crash/restore with CRLF + BOM, corrupt entries, removal paths, property test of random edits, headless control-channel test, Vitest for the dialog. Docs: architecture, parity, gaps, ROADMAP. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
6d976ed03e
commit
0b40eb90f8
27 changed files with 2222 additions and 27 deletions
|
|
@ -12,6 +12,7 @@ use serde_json::{Value, json};
|
|||
|
||||
use super::params::parse;
|
||||
use crate::buffers::{BufferId, LineEndingName};
|
||||
use crate::journal;
|
||||
use crate::workspace::path_string;
|
||||
use crate::{Command, CommandSpec, EngineError, Event, Outcome, State};
|
||||
|
||||
|
|
@ -163,6 +164,7 @@ impl Command for Edit {
|
|||
.map_err(|e| EngineError::invalid_params(command, e.to_string()))?;
|
||||
open.version = open.version.saturating_add(1);
|
||||
let (version, dirty) = (open.version, open.dirty());
|
||||
journal::mark_edited(state, p.id, std::time::Instant::now());
|
||||
state.emit(Event::BufferChanged { id: p.id, version });
|
||||
if dirty != was_dirty {
|
||||
state.emit(Event::DirtyChanged { id: p.id, dirty });
|
||||
|
|
@ -212,6 +214,7 @@ impl Command for Close {
|
|||
if open.dirty() && !p.force {
|
||||
return Err(EngineError::UnsavedChanges(path_string(&open.path)));
|
||||
}
|
||||
journal::forget(state, p.id);
|
||||
state.buffers.remove(p.id);
|
||||
state.emit(Event::BufferClosed { id: p.id });
|
||||
Ok(Outcome::value(Value::Null))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue