M1.3: engine workspace, file and buffer commands, event stream
State holds the open project (VFS project, watcher, watched directories)
and versioned buffers. New commands: project.open/close/children,
file.open/save/saveAll, buffer.get/edit/close. buffer.edit takes UTF-16
change sets based on a version and fails with the new stale_version code;
closing dirty buffers or projects without force fails with
unsaved_changes. Commands queue events (projectOpened, treeChanged,
bufferChanged, dirtyChanged, fileChangedOnDisk, ...) that the engine
returns in Outcome.events; Engine::pump_vfs maps changes on disk to
events and reloads clean buffers. project.children watches listed
directories, capped at 256 native / 32 polling, least recently listed
dropped first.
Control channel: events.subscribe streams {"event": ...} lines, with
bounded per-subscriber queues (lutra_control::Subscribers) and method docs
in methods.rs. testkit's EngineBackend and the desktop Host implement the
new Backend::subscribe. Verified with 14 engine integration tests, a TCP
events test and the running app over the control channel.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
a63ab4ac45
commit
f1976c7d67
30 changed files with 2235 additions and 46 deletions
|
|
@ -22,6 +22,21 @@ pub enum EngineError {
|
|||
/// What is wrong with the params.
|
||||
message: String,
|
||||
},
|
||||
/// An edit was based on an older version of the buffer than the engine
|
||||
/// holds. The caller resynchronises (`buffer.get`) and retries.
|
||||
#[error("buffer {id} is at version {current}, the edit was based on version {base}")]
|
||||
StaleVersion {
|
||||
/// The buffer id.
|
||||
id: u64,
|
||||
/// The version the caller based its edit on.
|
||||
base: u64,
|
||||
/// The engine's current version.
|
||||
current: u64,
|
||||
},
|
||||
/// The action would discard unsaved changes; repeat it with `force` to
|
||||
/// discard them.
|
||||
#[error("{0} has unsaved changes")]
|
||||
UnsavedChanges(String),
|
||||
/// The command ran and failed, e.g. a file could not be read.
|
||||
#[error("{0}")]
|
||||
Failed(String),
|
||||
|
|
@ -38,11 +53,21 @@ impl EngineError {
|
|||
Self::UnknownCommand(_) => "unknown_command",
|
||||
Self::Disabled(_) => "disabled",
|
||||
Self::InvalidParams { .. } => "invalid_params",
|
||||
Self::StaleVersion { .. } => "stale_version",
|
||||
Self::UnsavedChanges(_) => "unsaved_changes",
|
||||
Self::Failed(_) => "failed",
|
||||
Self::Internal(_) => "internal",
|
||||
}
|
||||
}
|
||||
|
||||
/// Shorthand for [`EngineError::InvalidParams`].
|
||||
pub fn invalid_params(command: &str, message: impl Into<String>) -> Self {
|
||||
Self::InvalidParams {
|
||||
command: command.to_string(),
|
||||
message: message.into(),
|
||||
}
|
||||
}
|
||||
|
||||
/// The error as a `{ code, message }` payload for IPC and the control
|
||||
/// channel.
|
||||
pub fn payload(&self) -> ErrorPayload {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue