From 6229bcad5b575ce8f64f701b4600bb791bbbed59 Mon Sep 17 00:00:00 2001 From: mavrick Date: Fri, 27 Nov 2026 14:02:26 -0600 Subject: [PATCH 1/7] feat(ui): Messages read like compiler messages, explain loss codes offline and undo to before a command The Messages pane groups a command's messages under its name and what it worked on, with Undo to before this while the history reaches that state. A message that reports lost data shows its severity and code, then a note on what the code means and a help line on what to do, from text built into RustGIS, so both read offline; the guide's entry is a link beside them. A Data losses filter lists only those. Each loss code now carries its meaning beside its action, tested against the guide's entry. rustgis-cli explain CODE prints both, offline. Part of #2371. --- apps/rustgis-cli/src/main.rs | 20 +++- apps/rustgis-cli/tests/integration/strict.rs | 19 ++++ crates/data/src/diagnostics.rs | 41 ++++++- crates/data/src/loss.rs | 68 ++++++++++-- crates/engine/src/lib.rs | 42 +++++++- crates/engine/src/tests.rs | 2 + crates/engine/src/tests/message_runs.rs | 35 ++++++ crates/ui-egui/src/chrome.rs | 8 ++ crates/ui-egui/src/diagnosticlog.rs | 106 +++++++++++++++---- docs/cli.md | 7 ++ docs/user-guide/index.md | 13 ++- 11 files changed, 320 insertions(+), 41 deletions(-) create mode 100644 crates/engine/src/tests/message_runs.rs diff --git a/apps/rustgis-cli/src/main.rs b/apps/rustgis-cli/src/main.rs index f5c18234bb..32c74a9330 100644 --- a/apps/rustgis-cli/src/main.rs +++ b/apps/rustgis-cli/src/main.rs @@ -3,6 +3,7 @@ //! ```text //! rustgis-cli commands # list command ids and parameters //! rustgis-cli tools # list geoprocessing tools +//! rustgis-cli explain changed.rounded # what a loss code means and what to do, offline //! rustgis-cli info data.geojson # layer summary as JSON //! rustgis-cli render data.geojson out.png [--basemap ocean] [--tiles URL] [--width 1600 --height 900] //! rustgis-cli run [--sample | --project p.rgis | --data f.geojson …] \ @@ -50,11 +51,27 @@ use serde_json::{Map, Value, json}; fn usage() -> ExitCode { eprintln!( - "usage:\n rustgis-cli commands | tools\n rustgis-cli plugins [install | uninstall | enable | disable | browse | get | prepare ] [--registry URL]\n rustgis-cli skills [add | remove | enable | disable ]\n rustgis-cli info \n rustgis-cli logo [--size N] [--canvas WxH --at X,Y (.bmp only)]\n rustgis-cli render [--basemap NAME] [--tiles URL] [--width N] [--height N] [--dpi N] [--worldview auto|default|CODE] [--worldview-detail simplified|original]\n rustgis-cli run [--sample] [--project P] [--data F]… --cmd 'id={{json}}'… [--save P] [--strict [--allow KIND|CODE]…] [--worldview auto|default|CODE] [--worldview-detail simplified|original]\n rustgis-cli ask [--sample] [--project P] [--data F]… \"request\" [--image PICTURE]… [--provider P] [--model M] [--base-url URL] [--yes] [--save P]\n rustgis-cli ask --models [--provider P]\n rustgis-cli ask --login [--another-account] [--account CLIENT_ID] | --logout\n rustgis-cli ask --accounts | --account CLIENT_ID | --remove-account CLIENT_ID\n common options: --use-saved-secrets (use the connections, passwords, keys, ChatGPT sign-in and Earthdata Login token the RustGIS app saved; reads the system keychain), --threads N (the most threads one piece of work uses, 1-1024; default: the cores, up to 16)\n rustgis-cli mcp [--sample] [--project P] [--data F]… [--yes] [--attach [PORT] [--token-file FILE] [--timeout SECONDS (5-600)]]\n rustgis-cli mcp-register [--client claude] [--name NAME] [--port PORT]" + "usage:\n rustgis-cli commands | tools\n rustgis-cli explain [CODE]\n rustgis-cli plugins [install | uninstall | enable | disable | browse | get | prepare ] [--registry URL]\n rustgis-cli skills [add | remove | enable | disable ]\n rustgis-cli info \n rustgis-cli logo [--size N] [--canvas WxH --at X,Y (.bmp only)]\n rustgis-cli render [--basemap NAME] [--tiles URL] [--width N] [--height N] [--dpi N] [--worldview auto|default|CODE] [--worldview-detail simplified|original]\n rustgis-cli run [--sample] [--project P] [--data F]… --cmd 'id={{json}}'… [--save P] [--strict [--allow KIND|CODE]…] [--worldview auto|default|CODE] [--worldview-detail simplified|original]\n rustgis-cli ask [--sample] [--project P] [--data F]… \"request\" [--image PICTURE]… [--provider P] [--model M] [--base-url URL] [--yes] [--save P]\n rustgis-cli ask --models [--provider P]\n rustgis-cli ask --login [--another-account] [--account CLIENT_ID] | --logout\n rustgis-cli ask --accounts | --account CLIENT_ID | --remove-account CLIENT_ID\n common options: --use-saved-secrets (use the connections, passwords, keys, ChatGPT sign-in and Earthdata Login token the RustGIS app saved; reads the system keychain), --threads N (the most threads one piece of work uses, 1-1024; default: the cores, up to 16)\n rustgis-cli mcp [--sample] [--project P] [--data F]… [--yes] [--attach [PORT] [--token-file FILE] [--timeout SECONDS (5-600)]]\n rustgis-cli mcp-register [--client claude] [--name NAME] [--port PORT]" ); ExitCode::from(2) } +/// `explain [CODE]`: what a loss code means and what to do about it, from the text built into +/// RustGIS, so it reads offline, as a compiler explains its error codes; with no code, every code. +fn explain(code: Option<&str>) -> Result<(), String> { + let Some(id) = code.filter(|c| !c.starts_with("--")) else { + for code in LossCode::ALL { + let spec = code.spec(); + println!("{:<28} {}", spec.id, spec.meaning); + } + return Ok(()); + }; + let code = LossCode::from_id(id).ok_or_else(|| format!("explain {id}: not a loss code (`rustgis-cli explain` lists them)"))?; + let spec = code.spec(); + println!("{}: {}\n\n{}\n\nWhat to do: {}\n\nMore: {}", spec.id, spec.kind.id(), spec.meaning, spec.action, code.doc_url()); + Ok(()) +} + /// The value after `name`. A flag that takes one is in [`VALUE_FLAGS`], which [`check_values`] /// checks before anything runs, so the value is there and isn't another option. fn opt<'a>(args: &'a [String], name: &str) -> Option<&'a str> { @@ -1048,6 +1065,7 @@ fn cli() -> ExitCode { print(&out); Ok(()) } + "explain" => explain(args.get(1).map(String::as_str)), "skills" => skills(&args), "mcp-register" => mcp_register(&args), "commands" => { diff --git a/apps/rustgis-cli/tests/integration/strict.rs b/apps/rustgis-cli/tests/integration/strict.rs index 66a624e3a6..1a723cea67 100644 --- a/apps/rustgis-cli/tests/integration/strict.rs +++ b/apps/rustgis-cli/tests/integration/strict.rs @@ -116,3 +116,22 @@ fn allow_takes_a_known_kind_or_code_and_needs_strict() { assert!(err.contains(said), "{args:?}: {err}"); } } + +#[test] +fn explain_says_what_a_code_means_and_what_to_do_offline() { + let explain = |args: &[&str]| Command::new(env!("CARGO_BIN_EXE_rustgis-cli")).arg("explain").args(args).output().unwrap(); + let out = explain(&["dropped.ring"]); + let text = String::from_utf8_lossy(&out.stdout); + assert!(out.status.success(), "{text}"); + assert!(text.starts_with("dropped.ring: dropped\n\nA polygon ring was left out."), "{text}"); + assert!(text.contains("What to do: Correct the unreadable polygon ring"), "{text}"); + assert!(text.contains("More: https://rustgis.app/user-guide/loss-codes/#dropped.ring"), "{text}"); + // Every code, one line each, starting with the code. + let all = String::from_utf8_lossy(&explain(&[]).stdout).into_owned(); + for code in ["dropped.legend", "changed.rounded", "assumed.encoding"] { + assert!(all.lines().any(|line| line.starts_with(code)), "{all}"); + } + let unknown = explain(&["dropped.everything"]); + assert!(!unknown.status.success()); + assert!(String::from_utf8_lossy(&unknown.stderr).contains("not a loss code")); +} diff --git a/crates/data/src/diagnostics.rs b/crates/data/src/diagnostics.rs index 4af2891c7d..a3cf204a76 100644 --- a/crates/data/src/diagnostics.rs +++ b/crates/data/src/diagnostics.rs @@ -45,6 +45,8 @@ pub enum Filter { Warnings, Info, Network, + /// Messages that report lost data, with a loss code. + Losses, } impl Filter { @@ -56,6 +58,7 @@ impl Filter { Self::Info => record.severity == Severity::Info, // The note that further servers' absences go unlisted belongs with the absences. Self::Network => record.network.is_some() || record.source == "Network", + Self::Losses => record.loss.is_some(), } } } @@ -98,8 +101,23 @@ pub struct Record { pub message: String, pub details: String, pub network: Option, - /// The loss the message reports, if any: the pane links to its entry in the guide. + /// The loss the message reports, if any: the pane explains it and links to its entry in the guide. pub loss: Option, + /// The command run that said it, when a command did. + pub run: Option, +} + +/// One run of a command, as the messages it said remember it: the pane groups them by it and can +/// take the project back to before it. +#[derive(Clone, Debug, PartialEq, Eq)] +pub struct Run { + /// Counts the session's runs, so the messages of one run are told from the next one's. + pub id: u64, + /// The project's state before the run ([`Session::history_position`] in the engine): Undo + /// returns to it while it is still in the history. + pub before: u64, + /// What the run worked on, as its parameters name it (a layer, a table, a file). + pub target: Option, } #[derive(Default)] @@ -207,13 +225,21 @@ impl History { details: bounded(details, MAX_DETAILS_BYTES), network: None, loss: None, + run: None, }); } /// [`History::push`] for a message already through [`redact`] (a notice the session redacted /// for its status bar): it is only bounded, so a notice isn't redacted again for each copy. /// Only a [`Redacted`], which `redact` alone makes, gets this path. - pub fn push_redacted(&self, severity: Severity, source: &str, message: &Redacted, loss: Option) { + pub fn push_redacted( + &self, + severity: Severity, + source: &str, + message: &Redacted, + loss: Option, + run: Option, + ) { self.retain(Record { id: 0, timestamp_ms: timestamp_ms(), @@ -223,6 +249,7 @@ impl History { details: String::new(), network: None, loss, + run, }); } @@ -326,6 +353,7 @@ impl Capture { details: String::new(), network: None, loss: None, + run: None, }, ); guard.absences_overflow_said = Some(id); @@ -344,6 +372,7 @@ impl Capture { details: String::new(), network: Some(Network { url, method: known_method(method), status: Some(status), duration_ms: None, kind: NetworkKind::Http }), loss: None, + run: None, }; let id = store(&mut guard, record); guard.absences_said.push((server, id)); @@ -384,6 +413,7 @@ impl Capture { details: bounded(details, MAX_DETAILS_BYTES), network: Some(network), loss: None, + run: None, }; let mut state = lock(&state); if once @@ -1828,7 +1858,7 @@ mod tests { fn text_already_redacted_is_only_bounded() { let history = History::default(); let long = "word ".repeat(1000); - history.push_redacted(Severity::Info, "Application", &Redacted::new(&long), None); + history.push_redacted(Severity::Info, "Application", &Redacted::new(&long), None, None); history.push(Severity::Info, "Application", &long, ""); let records = history.records(); assert_eq!(records[0].message, records[1].message); @@ -1841,13 +1871,14 @@ mod tests { fn a_loss_keeps_its_code_and_the_report_gives_its_guide_entry() { let history = History::default(); let code = crate::loss::LossCode::DroppedRing; - history.push_redacted(Severity::Warning, "layer.addData", &Redacted::new("1 ring left out"), Some(code)); - history.push_redacted(Severity::Info, "layer.addData", &Redacted::new("added"), None); + history.push_redacted(Severity::Warning, "layer.addData", &Redacted::new("1 ring left out"), Some(code), None); + history.push_redacted(Severity::Info, "layer.addData", &Redacted::new("added"), None, None); let records = history.records(); assert_eq!(records.iter().map(|r| r.loss).collect::>(), [Some(code), None]); let report = history.report(Filter::All); assert!(report.contains("Loss: dropped.ring (https://rustgis.app/user-guide/loss-codes/#dropped.ring)"), "{report}"); assert_eq!(report.matches("Loss: ").count(), 1, "{report}"); + assert_eq!(records.iter().filter(|r| Filter::Losses.matches(r)).count(), 1); } #[test] diff --git a/crates/data/src/loss.rs b/crates/data/src/loss.rs index 166c9635c6..62a4a050f4 100644 --- a/crates/data/src/loss.rs +++ b/crates/data/src/loss.rs @@ -35,7 +35,7 @@ impl LossKind { /// Declares the codes once, so the list of every code can't miss one. macro_rules! loss_codes { - ($($code:ident => ($id:literal, $kind:ident, $action:literal),)*) => { + ($($code:ident => ($id:literal, $kind:ident, $meaning:literal, $action:literal $(,)?),)*) => { /// The specific cause of a loss. Add causes here so producers use the same code for the /// same loss. #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] @@ -51,7 +51,7 @@ macro_rules! loss_codes { /// The registry entry that supplies the untranslated identifier and remediation. pub const fn spec(self) -> LossSpec { match self { - $(Self::$code => LossSpec { id: $id, kind: LossKind::$kind, action: $action },)* + $(Self::$code => LossSpec { id: $id, kind: LossKind::$kind, meaning: $meaning, action: $action },)* } } } @@ -59,95 +59,142 @@ macro_rules! loss_codes { } loss_codes! { - DroppedLegend => ("dropped.legend", Dropped, "Use a service with short HTTP or HTTPS addresses for its legend pictures."), - DroppedRing => ("dropped.ring", Dropped, "Correct the unreadable polygon ring in the source, or write to a format that holds holes, such as GeoPackage."), + DroppedLegend => ( + "dropped.legend", + Dropped, + "A map service offered legend pictures that RustGIS does not show, so they were left out. These are pictures with addresses that fail RustGIS's checks, are in another format, or past the limit on legends per layer.", + "Use a service with short HTTP or HTTPS addresses for its legend pictures.", + ), + DroppedRing => ( + "dropped.ring", + Dropped, + "A polygon ring was left out. Rings that could not be read, or that have no area, are skipped, and a format with no holes keeps only the outer edge of each polygon.", + "Correct the unreadable polygon ring in the source, or write to a format that holds holes, such as GeoPackage.", + ), DroppedExtraAttributes => ( "dropped.extra-attributes", Dropped, + "A row had more attribute values than the layer has fields, and the extra values were not kept.", "Add fields for the extra attribute values or remove those values from the input." ), - DroppedTime => ("dropped.time", Dropped, "Write to a date-time field to keep the time of day."), - DroppedValue => ("dropped.value", Dropped, "Correct the value or use a destination field that can hold it."), + DroppedTime => ( + "dropped.time", + Dropped, + "A date-time was written to a date field, which keeps only the day, so the time of day was lost.", + "Write to a date-time field to keep the time of day.", + ), + DroppedValue => ( + "dropped.value", + Dropped, + "A value could not be kept and was read or written as empty (null). Examples are spreadsheet error cells, text in a date or yes/no column, and a result that is not a number.", + "Correct the value or use a destination field that can hold it.", + ), DroppedCalculationResult => ( "dropped.calculation-result", Dropped, + "A calculation gave no result for some rows, so the field was left empty there. The input may have no place that can be given in longitude and latitude, or the result may be too large to hold.", "Correct the expression or check the input rows named in the notice." ), DroppedZm => ( "dropped.zm", Dropped, + "Z (height) or M (measure) values were not kept. RustGIS keeps x and y only.", "Keep the source file where heights or measures matter: RustGIS keeps x and y only." ), DroppedCrsName => ( "dropped.crs-name", Dropped, + "A coordinate system's name or definition could not be written with the data, so the file holds the coordinates without it.", "Keep the source file's coordinate system definition with the export, or export in WGS 84, which every format can name." ), DroppedFeature => ( "dropped.feature", Dropped, + "Whole features, rows or items were left out because they could not be read or are not supported.", "Correct those features in the source, or read the source in the way the notice suggests." ), DroppedGeometry => ( "dropped.geometry", Dropped, + "A feature's geometry could not be read or written. The feature was kept without its place, or the place was left out.", "Correct the geometry in the source, or give the coordinate system its coordinates are in." ), DroppedOverLimit => ( "dropped.over-limit", Dropped, + "RustGIS read only part of the data because it is past a size limit.", "Read less at once, such as by filtering or clipping the source first." ), - ChangedTruncated => ("changed.truncated", Changed, "Use a decimal field to keep the fractional part."), + ChangedTruncated => ( + "changed.truncated", + Changed, + "A number lost its fractional part because the field holds whole numbers.", + "Use a decimal field to keep the fractional part.", + ), ChangedFieldName => ( "changed.field-name", Changed, + "A field name was changed to fit the format it was written to.", "Use field names the format holds: at most 10 bytes and unique ignoring case for a Shapefile, unique ignoring case for a GeoPackage." ), ChangedCut => ( "changed.cut", Changed, + "Text was cut short to fit a format or a limit.", "Shorten the text to what the format holds (254 bytes for a Shapefile; nothing past a NUL character), or write to a format without the limit, such as GeoPackage." ), - ChangedBody => ("changed.body", Changed, "Export in the layer's own coordinate system, which keeps its body."), + ChangedBody => ( + "changed.body", + Changed, + "Longitude and latitude on a body other than the Earth were written as Earth coordinates, because the format cannot say which body they are on.", + "Export in the layer's own coordinate system, which keeps its body.", + ), ChangedEncoding => ( "changed.encoding", Changed, + "Text that is not valid in the encoding it was read with was read with a replacement character in its place.", "Put a .cpg file naming the file's own encoding beside it." ), ChangedRounded => ( "changed.rounded", Changed, + "A number or time was rounded to what the format or the field holds.", "Keep the source file where finer values matter, or write to a format that holds them (times finer than the format keeps, numbers past a dBase field's precision, or whole numbers past 2^53 in a decimal field)." ), ChangedPosition => ( "changed.position", Changed, + "Positions were moved to fit the coordinate system they were written in, for example vertices beyond 85.05 degrees north or south in Web Mercator.", "Export in a coordinate system that holds the positions, such as WGS 84." ), ApproximatedDatum => ( "approximated.datum", Approximated, + "A datum RustGIS does not shift was treated as WGS 84, so places may be a little off.", "Export in the layer's own coordinate system, or give that system with a known transformation to WGS 84." ), ApproximatedCurve => ( "approximated.curve", Approximated, + "Curves, circles or rotated boxes were drawn or written as straight segments.", "Keep the source file where exact curves matter: RustGIS draws curves as straight segments." ), AssumedNullMarker => ( "assumed.null-marker", Assumed, + "A value written as the text , which some programs write for a missing value, was read as empty (null).", "Write the value another way if the text Null is meant as text, not as an empty value." ), AssumedCrs => ( "assumed.crs", Assumed, + "The file does not say which coordinate system its coordinates are in, or says one RustGIS cannot use, so RustGIS read them as longitude and latitude (WGS 84).", "Give the coordinate system the coordinates are in (\"crs\" when adding the data, or Define Projection)." ), AssumedEncoding => ( "assumed.encoding", Assumed, + "The file does not name its text encoding, or names one RustGIS does not read, so RustGIS assumed one (UTF-8, or Latin-1 for a DXF).", "Give the file's encoding in a form RustGIS reads: a .cpg beside a Shapefile or dBASE file naming UTF-8 or its Windows code page, or a DXF saved as UTF-8." ), } @@ -172,6 +219,9 @@ impl LossCode { pub struct LossSpec { pub id: &'static str, pub kind: LossKind, + /// What happened to the data, said the same way wherever the code comes from: the app shows it + /// beside a notice, offline, and the guide's entry opens with it. + pub meaning: &'static str, pub action: &'static str, } @@ -554,6 +604,8 @@ mod tests { let entry = guide.split(&format!("\n{heading}\n")).nth(1).unwrap_or_default(); let entry = entry.split("\n### ").next().unwrap_or_default().split("\n## ").next().unwrap_or_default(); assert!(!entry.is_empty(), "docs/user-guide/loss-codes.md should have the entry\n{heading}"); + let opening = entry.trim_start().split("\n\n").next().unwrap_or_default().split_whitespace().collect::>().join(" "); + assert_eq!(opening.replace('`', ""), spec.meaning, "docs/user-guide/loss-codes.md: `{}` should open with its meaning", spec.id); let action = format!("**What to do:** {}", spec.action); assert!(entry.replace('\n', " ").contains(&action), "docs/user-guide/loss-codes.md: `{}` should say\n{action}", spec.id); assert!(code.doc_url().ends_with(&format!("/user-guide/loss-codes/#{}", spec.id))); diff --git a/crates/engine/src/lib.rs b/crates/engine/src/lib.rs index 1e3f3d3dd9..88acc1e318 100644 --- a/crates/engine/src/lib.rs +++ b/crates/engine/src/lib.rs @@ -686,6 +686,21 @@ impl RoomMade { } } +/// What a command run worked on, as its parameters name it, for the messages it says: a layer, a +/// table or an input by name, cut short. File paths are left out, as they can hold a login. +fn run_target(params: &Value) -> Option { + let name = ["layer", "table", "input", "map"].iter().find_map(|key| params.get(*key).and_then(Value::as_str))?; + let name = name.trim(); + if name.is_empty() { + return None; + } + let mut cut: String = name.chars().take(80).collect(); + if cut.len() < name.len() { + cut.push('…'); + } + Some(cut) +} + /// An undo or redo step: the project before it, the layout open then, its label, who made it, /// which state of the project it is ([`Session::dirty`]), and the identities of its feature /// allocations for memory accounting. File origins accompany changes made by the command only: @@ -1041,6 +1056,9 @@ pub struct Session { pub(crate) depth: u32, /// Only the command's registered id, never its parameters. Nested commands restore this. pub(crate) diagnostic_source: Option<&'static str>, + /// The top-level command running, as the messages it says remember it, and how many have run. + run: Option, + runs: u64, /// How many of the commands running now restore the project if they fail: a replacement is /// put aside only under one of them, as only then can it be rolled back. restorable: u32, @@ -1546,6 +1564,8 @@ impl Session { put_aside: None, depth: 0, diagnostic_source: None, + run: None, + runs: 0, restorable: 0, published_syncs: Vec::new(), actor: None, @@ -1924,6 +1944,13 @@ impl Session { // Restored on every path, including panics outside `guarded`, so a later notice is not // attributed to an aborted command. Mirrors the capture scope's restore-on-drop. let previous = std::mem::replace(&mut self.diagnostic_source, source); + // A run of its own for a top-level command: its messages are grouped by it, and the pane can + // undo back to before it. + let previous_run = outermost.then(|| { + self.runs = self.runs.wrapping_add(1); + let run = rustgis_data::diagnostics::Run { id: self.runs, before: self.state, target: run_target(params) }; + self.run.replace(run) + }); let history_deferred = std::mem::replace(&mut self.undo_memory.deferred, true); let result = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| { let notice_mark = self.notice_mark(); @@ -2010,6 +2037,9 @@ impl Session { res })); self.diagnostic_source = previous; + if let Some(run) = previous_run { + self.run = run; + } self.undo_memory.deferred = history_deferred; // Every top-level invocation consumes its key, even a refusal or panic before guarded. if outermost { @@ -3599,7 +3629,7 @@ impl Session { if severity == rustgis_data::diagnostics::Severity::Error && self.rerun_said.iter().any(|said| said == text.as_str()) { return; } - self.diagnostics.push_redacted(severity, source.unwrap_or("Application"), &text, loss); + self.diagnostics.push_redacted(severity, source.unwrap_or("Application"), &text, loss, self.run.clone()); self.notices.push(Notice { text: text.into_string(), error: severity == rustgis_data::diagnostics::Severity::Error, @@ -3679,6 +3709,16 @@ impl Session { self.redo.iter().rev().map(|step| step.2) } + /// How many Undo steps take the project back to the state `state` ([`Session::history_position`]'s + /// first part, as a message's [`Run::before`](rustgis_data::diagnostics::Run) holds it): `Some(0)` + /// when it is the current state, `None` when the history no longer reaches it. + pub fn undo_steps_to(&self, state: u64) -> Option { + if self.state == state { + return Some(0); + } + self.undo.iter().rposition(|step| step.4 == state).map(|i| self.undo.len() - i) + } + /// Identifies the current position and the history it belongs to. Editing and then undoing /// the edit returns to the same state with a different redo stack. pub fn history_position(&self) -> (u64, u64) { diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index 394233600e..067670db9d 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -31,6 +31,8 @@ mod unplaced_gp; mod unplaced_out; #[cfg(not(target_arch = "wasm32"))] +#[path = "tests/message_runs.rs"] +mod message_runs; #[path = "tests/said_not_silent.rs"] mod said_not_silent; diff --git a/crates/engine/src/tests/message_runs.rs b/crates/engine/src/tests/message_runs.rs new file mode 100644 index 0000000000..f12e722de4 --- /dev/null +++ b/crates/engine/src/tests/message_runs.rs @@ -0,0 +1,35 @@ +//! The Messages pane groups a command's messages by its run and can undo back to before it. + +use super::*; + +#[test] +fn a_commands_messages_remember_its_run_and_undo_reaches_back_to_before_it() { + let mut s = world(); + s.run("layer.addDataText", &json!({"fileName": "records.csv", "text": "n\n1\n2\n"})).unwrap(); + s.run("edit.enable", &json!({"on": true})).unwrap(); + let loss_records = |s: &Session| -> Vec { + s.diagnostics.records().into_iter().filter(|r| r.loss.is_some()).collect() + }; + s.run("edit.calculateField", &json!({"table": "records", "field": "n", "expression": "n + 1.5"})).unwrap(); + let first = loss_records(&s); + let [cut] = first.as_slice() else { panic!("one coded message: {first:?}") }; + assert_eq!(cut.source, "edit.calculateField"); + let run = cut.run.clone().expect("said by a command run"); + assert_eq!(run.target.as_deref(), Some("records")); + assert_eq!(s.undo_steps_to(run.before), Some(1), "one step back to before it"); + + s.run("edit.calculateField", &json!({"table": "records", "field": "n", "expression": "n + 0.5"})).unwrap(); + let both = loss_records(&s); + let later = both.last().and_then(|r| r.run.clone()).unwrap(); + assert_ne!(later.id, run.id, "each run is its own"); + assert_eq!(s.undo_steps_to(run.before), Some(2), "back past the later run too"); + assert_eq!(s.undo_steps_to(later.before), Some(1)); + + // Undone back to before the first run, its state is the current one. + s.run("edit.undo", &json!({})).unwrap(); + s.run("edit.undo", &json!({})).unwrap(); + assert_eq!(s.undo_steps_to(run.before), Some(0)); + // A message no command said has no run. + s.notify("said by the app", false); + assert!(s.diagnostics.records().last().is_some_and(|r| r.run.is_none())); +} diff --git a/crates/ui-egui/src/chrome.rs b/crates/ui-egui/src/chrome.rs index 35e62e2041..70d60652b2 100644 --- a/crates/ui-egui/src/chrome.rs +++ b/crates/ui-egui/src/chrome.rs @@ -337,6 +337,14 @@ pub(crate) struct HistoryJump { cancel_pressed: bool, } +impl HistoryJump { + /// `total` Undo steps from the history position `position`, as the Messages pane's Undo to + /// before this asks: a long jump has the same progress and Cancel as Undo History's. + pub(crate) fn undo(position: (u64, u64), total: usize) -> Self { + Self { command: "edit.undo", position, total, done: 0, cancel_pressed: false } + } +} + /// Advances a jump within the frame budget. Each step uses the UI's normal undo/redo cleanup. /// A step already in progress finishes before yielding. Project changes invalidate the rest. pub(crate) fn advance_history_jump(app: &mut RustGisApp, ctx: &egui::Context) { diff --git a/crates/ui-egui/src/diagnosticlog.rs b/crates/ui-egui/src/diagnosticlog.rs index 3eea4e9ffb..622a4aa0c9 100644 --- a/crates/ui-egui/src/diagnosticlog.rs +++ b/crates/ui-egui/src/diagnosticlog.rs @@ -2,6 +2,7 @@ use egui::{RichText, Ui}; use rustgis_engine::data::diagnostics::{Filter, NetworkKind, Record, Severity}; +use rustgis_engine::data::loss::LossKind; use crate::{RustGisApp, theme::Tokens}; @@ -28,6 +29,7 @@ pub(crate) fn show(app: &mut RustGisApp, ui: &mut Ui, t: &Tokens) { (Filter::Warnings, tl_raw!("Warnings")), (Filter::Info, tl_raw!("Info")), (Filter::Network, tl_raw!("Network failures")), + (Filter::Losses, tl_raw!("Data losses")), ] { let count = records.iter().filter(|r| filter.matches(r)).count(); let text = crate::i18n::fmt("{label} ({count})", &[("label", label), ("count", &count.to_string())]); @@ -57,13 +59,22 @@ pub(crate) fn show(app: &mut RustGisApp, ui: &mut Ui, t: &Tokens) { ui.separator(); egui::ScrollArea::vertical().id_salt("diagnostic_log_entries").auto_shrink([false, false]).show(ui, |ui| { egui::Frame::NONE.inner_margin(egui::Margin::symmetric(12, 8)).show(ui, |ui| { - let mut shown = false; let filter = app.ui.diagnostic_filter; - for record in records.iter().rev().filter(|r| filter.matches(r)) { - shown = true; - ui.push_id(record.id, |ui| entry(ui, record, t, &mut app.ui.open_url)); + let shown: Vec<&Record> = records.iter().rev().filter(|r| filter.matches(r)).collect(); + // The messages of one command run, newest first, under that run's heading. + for group in shown.chunk_by(|a, b| a.run.is_some() && a.run.as_ref().map(|r| r.id) == b.run.as_ref().map(|r| r.id)) { + let Some(first) = group.first() else { continue }; + ui.push_id(first.id, |ui| { + if first.run.is_some() { + run_heading(ui, app, first, t); + } + for record in group { + ui.push_id(record.id, |ui| entry(ui, record, t, first.run.is_none(), &mut app.ui.open_url)); + } + }); ui.separator(); } + let shown = !shown.is_empty(); if !shown { ui.label(tl!("No diagnostic entries match this filter.")); } @@ -72,36 +83,85 @@ pub(crate) fn show(app: &mut RustGisApp, ui: &mut Ui, t: &Tokens) { app.ui.diagnostic_snapshot = Some((generation, records)); } -/// One entry: its time, severity and source, the message, the loss code with a link to its entry -/// in the guide (set in `open_url` when clicked), and any technical details. -fn entry(ui: &mut Ui, record: &Record, t: &Tokens, open_url: &mut Option) { +/// A command run's heading over the messages it said: the command by name, what it worked on and +/// when, with Undo to before it while the history still reaches that state. +fn run_heading(ui: &mut Ui, app: &mut RustGisApp, record: &Record, t: &Tokens) { + let Some(run) = &record.run else { return }; + let name = app.session.registry.get(record.source.as_str()).map_or(record.source.as_str(), |spec| crate::i18n::t(spec.label)); + ui.horizontal_wrapped(|ui| { + ui.label(RichText::new(name).strong()); + if let Some(target) = &run.target { + ui.label(RichText::new(crate::i18n::fmt("on {target}", &[("target", target.as_str())])).color(t.text_dim)); + } + ui.label(RichText::new(time(record.timestamp_ms)).small().monospace().color(t.text_dim)); + }); + // Only a run that changed the project, whose state before is still in the history. + let steps = app.session.undo_steps_to(run.before).filter(|steps| *steps > 0); + if let Some(steps) = steps { + let hover = if steps == 1 { + tl!("Takes back this command's changes").to_string() + } else { + crate::i18n::fmt("Takes back this command's changes and the {n} after it", &[("n", &(steps - 1).to_string())]) + }; + if ui.small_button(tl!("Undo to before this")).on_hover_text(hover).clicked() { + app.ui.history_jump = Some(crate::chrome::HistoryJump::undo(app.session.history_position(), steps)); + ui.ctx().request_repaint(); + } + } +} + +/// One entry, laid out as a compiler message: its severity, and its loss code when it reports lost +/// data; the message; then what the code means (`note`) and what to do (`help`), from text built +/// into the app so they read offline, with the guide's entry for more. A message no command said +/// shows its time and source itself (`standalone`). +fn entry(ui: &mut Ui, record: &Record, t: &Tokens, standalone: bool, open_url: &mut Option) { // Literal labels, so each is found and translated with the interface's other strings. let (severity, color) = match record.severity { Severity::Error => (tl!("Error"), t.red), Severity::Warning => (tl!("Warning"), t.amber), Severity::Info => (tl!("Info"), t.accent_text), }; - // A source is a command id (kept as written) or one of the history's own words. - let source = match record.source.as_str() { - "Application" => tl!("Application"), - "Network" => tl!("Network"), - "Plugin" => tl!("Plugin"), - command => command, - }; ui.horizontal_wrapped(|ui| { - ui.label(RichText::new(time(record.timestamp_ms)).small().monospace().color(t.text_dim)); + if standalone { + ui.label(RichText::new(time(record.timestamp_ms)).small().monospace().color(t.text_dim)); + } ui.label(RichText::new(severity).small().strong().color(color)); - ui.label(RichText::new(source).small().color(t.text_dim)); + if let Some(code) = record.loss { + // The code is an identifier, never translated: scripts and the guide match on it. + ui.label(RichText::new(format!("[{}]", code.spec().id)).small().monospace().color(color)); + let kind = match code.spec().kind { + LossKind::Dropped => tl!("data left out"), + LossKind::Changed => tl!("data changed"), + LossKind::Approximated => tl!("data approximated"), + LossKind::Assumed => tl!("something assumed"), + }; + ui.label(RichText::new(kind).small().color(t.text_dim)); + } + if standalone { + // A source is a command id (kept as written) or one of the history's own words. + let source = match record.source.as_str() { + "Application" => tl!("Application"), + "Network" => tl!("Network"), + "Plugin" => tl!("Plugin"), + command => command, + }; + ui.label(RichText::new(source).small().color(t.text_dim)); + } }); ui.add(egui::Label::new(&record.message).wrap().selectable(true)); if let Some(code) = record.loss { - // The code is an identifier, never translated; its guide entry says what to do. - ui.horizontal_wrapped(|ui| { - ui.label(RichText::new(code.spec().id).small().monospace().color(t.text_dim)); - if ui.link(RichText::new(tl!("What this means")).small()).on_hover_text(code.doc_url()).clicked() { - *open_url = Some(code.doc_url()); - } - }); + let spec = code.spec(); + let line = |ui: &mut Ui, label: &str, text: &str| { + ui.horizontal_wrapped(|ui| { + ui.label(RichText::new(label).small().strong().color(t.text_dim)); + ui.add(egui::Label::new(RichText::new(text).small()).wrap()); + }); + }; + line(ui, tl!("= note:"), crate::i18n::t(spec.meaning)); + line(ui, tl!("= help:"), crate::i18n::t(spec.action)); + if ui.link(RichText::new(tl!("More in the guide")).small()).on_hover_text(code.doc_url()).clicked() { + *open_url = Some(code.doc_url()); + } } if !record.details.is_empty() || record.network.is_some() { egui::CollapsingHeader::new(tl!("Technical details")).show(ui, |ui| { diff --git a/docs/cli.md b/docs/cli.md index 5861861639..e3716e0421 100644 --- a/docs/cli.md +++ b/docs/cli.md @@ -163,6 +163,13 @@ An `--allow` that names no kind or code is refused with status 2, as is `--allow Each code has an entry in [Data loss codes](user-guide/loss-codes.md): what it means, where it is said and what to do about it. A strict run's message gives the address of each code's entry. +`rustgis-cli explain CODE` says what a code means and what to do, from the text built into +RustGIS, so it works offline; `rustgis-cli explain` lists every code: + +```sh +rustgis-cli explain changed.rounded +``` + Not every loss has a code yet: losses still reported without one don't stop a strict run. ## Asking the AI assistant diff --git a/docs/user-guide/index.md b/docs/user-guide/index.md index d65091d653..94263677a4 100644 --- a/docs/user-guide/index.md +++ b/docs/user-guide/index.md @@ -126,13 +126,20 @@ Open **View › Windows › Messages**, click the status-bar notice or **Message or search for **Messages** in Command Search (`ui.pane.diagnosticLog`). This troubleshooting history is separate from **Help › Diagnostic Monitor**, which still shows performance metrics. -Messages are collected even while the pane is closed. The newest entries appear first, with -a UTC timestamp, severity, and source (such as the command id or Network). Expand **Technical +Messages are collected even while the pane is closed. The newest entries appear first. A +command's messages sit under its name, what it worked on (a layer or table) and a UTC time; a +message no command said shows its own time and source (such as Network). + +A message that reports lost data is laid out like a compiler's: its severity and +[loss code](loss-codes.md) (`Warning [changed.truncated] data changed`), the message, then a +**note** on what the code means and a **help** line on what to do. Both are built into RustGIS, so +they read offline; **More in the guide** opens the code's entry. **Undo to before this** takes +the project back to before that command, and the changes after it, while Undo still reaches it. Expand **Technical details** for failed requests: their address, method, observed HTTP status and duration when available. Native connection failures and timeouts are identified when the transport knows them; an opaque browser failure does not claim a status or a specific DNS, CORS, or connection cause. -Use **All**, **Errors**, **Warnings**, **Info**, or **Network failures** to filter the history +Use **All**, **Errors**, **Warnings**, **Info**, **Network failures** or **Data losses** to filter the history (**Network failures** also lists the notes below about omitted absences). **Copy diagnostics** copies the filtered entries and their technical details, including folded details, as plain text: oldest entry first, with UTC Unix-millisecond timestamps, where the pane shows the newest From 429ac0d11939caf889d4ed03c272604eed0e5b1f Mon Sep 17 00:00:00 2001 From: mavrick Date: Fri, 27 Nov 2026 14:44:59 -0600 Subject: [PATCH 2/7] fix(engine): Undo to before this finds a run by the state it left, so a later edit from the same state isn't undone in its place --- apps/rustgis-cli/src/main.rs | 8 ++++-- crates/data/src/diagnostics.rs | 22 +++++++++++++++-- crates/engine/src/lib.rs | 25 +++++++++++++------ crates/engine/src/tests.rs | 2 +- crates/engine/src/tests/message_runs.rs | 33 +++++++++++++------------ crates/ui-egui/src/diagnosticlog.rs | 8 +++--- 6 files changed, 66 insertions(+), 32 deletions(-) diff --git a/apps/rustgis-cli/src/main.rs b/apps/rustgis-cli/src/main.rs index 32c74a9330..0e9043a0ff 100644 --- a/apps/rustgis-cli/src/main.rs +++ b/apps/rustgis-cli/src/main.rs @@ -59,7 +59,7 @@ fn usage() -> ExitCode { /// `explain [CODE]`: what a loss code means and what to do about it, from the text built into /// RustGIS, so it reads offline, as a compiler explains its error codes; with no code, every code. fn explain(code: Option<&str>) -> Result<(), String> { - let Some(id) = code.filter(|c| !c.starts_with("--")) else { + let Some(id) = code else { for code in LossCode::ALL { let spec = code.spec(); println!("{:<28} {}", spec.id, spec.meaning); @@ -1065,7 +1065,11 @@ fn cli() -> ExitCode { print(&out); Ok(()) } - "explain" => explain(args.get(1).map(String::as_str)), + "explain" => match args.get(1..).unwrap_or_default() { + [] => explain(None), + [code] if !code.starts_with("--") => explain(Some(code)), + _ => Err("explain takes one loss code, or none to list them all".into()), + }, "skills" => skills(&args), "mcp-register" => mcp_register(&args), "commands" => { diff --git a/crates/data/src/diagnostics.rs b/crates/data/src/diagnostics.rs index a3cf204a76..6a484dee91 100644 --- a/crates/data/src/diagnostics.rs +++ b/crates/data/src/diagnostics.rs @@ -50,6 +50,8 @@ pub enum Filter { } impl Filter { + /// Whether the pane's filter shows `record`: by severity, as a network failure, or as a message + /// that reports lost data (one with a loss code). pub fn matches(self, record: &Record) -> bool { match self { Self::All => true, @@ -113,9 +115,12 @@ pub struct Record { pub struct Run { /// Counts the session's runs, so the messages of one run are told from the next one's. pub id: u64, - /// The project's state before the run ([`Session::history_position`] in the engine): Undo - /// returns to it while it is still in the history. + /// The project's state before the run (`Session::state` in the engine). pub before: u64, + /// The state the run left the project in, once it has finished: another than `before` when it + /// changed the project. A change makes a state no other change has, so the history finds the + /// run's own step by it, even after an Undo and another edit from the same state before. + pub after: Option, /// What the run worked on, as its parameters name it (a layer, a table, a file). pub target: Option, } @@ -257,6 +262,19 @@ impl History { store(&mut lock(&self.0), record); } + /// Records the state the run `id` left the project in ([`Run::after`]) on the messages it said, + /// which are the newest ones with a run. + pub fn finish_run(&self, id: u64, after: u64) { + let mut state = lock(&self.0); + for record in state.records.iter_mut().rev() { + match &mut record.run { + Some(run) if run.id == id => run.after = Some(after), + Some(_) => break, + None => {} + } + } + } + /// Oldest first; both the count and every string in this independent snapshot are bounded. pub fn records(&self) -> Vec { lock(&self.0).records.iter().cloned().collect() diff --git a/crates/engine/src/lib.rs b/crates/engine/src/lib.rs index 88acc1e318..ee491438e3 100644 --- a/crates/engine/src/lib.rs +++ b/crates/engine/src/lib.rs @@ -694,6 +694,7 @@ fn run_target(params: &Value) -> Option { if name.is_empty() { return None; } + let name = rustgis_data::diagnostics::redact(name); let mut cut: String = name.chars().take(80).collect(); if cut.len() < name.len() { cut.push('…'); @@ -1948,7 +1949,7 @@ impl Session { // undo back to before it. let previous_run = outermost.then(|| { self.runs = self.runs.wrapping_add(1); - let run = rustgis_data::diagnostics::Run { id: self.runs, before: self.state, target: run_target(params) }; + let run = rustgis_data::diagnostics::Run { id: self.runs, before: self.state, after: None, target: run_target(params) }; self.run.replace(run) }); let history_deferred = std::mem::replace(&mut self.undo_memory.deferred, true); @@ -2038,6 +2039,9 @@ impl Session { })); self.diagnostic_source = previous; if let Some(run) = previous_run { + if let Some(ended) = &self.run { + self.diagnostics.finish_run(ended.id, self.state); + } self.run = run; } self.undo_memory.deferred = history_deferred; @@ -3709,14 +3713,19 @@ impl Session { self.redo.iter().rev().map(|step| step.2) } - /// How many Undo steps take the project back to the state `state` ([`Session::history_position`]'s - /// first part, as a message's [`Run::before`](rustgis_data::diagnostics::Run) holds it): `Some(0)` - /// when it is the current state, `None` when the history no longer reaches it. - pub fn undo_steps_to(&self, state: u64) -> Option { - if self.state == state { - return Some(0); + /// How many Undo steps take back the change that left the project in the state `after` (a + /// message's [`Run::after`](rustgis_data::diagnostics::Run)), with the changes made since: + /// `None` when the history no longer holds that change. A change makes a state no other has, + /// so an edit made after undoing it, from the same state before, isn't taken for it. + pub fn undo_steps_back_past(&self, after: u64) -> Option { + if self.undo.is_empty() { + return None; + } + if self.state == after { + return Some(1); } - self.undo.iter().rposition(|step| step.4 == state).map(|i| self.undo.len() - i) + // The step after the change keeps the state the change left. + self.undo.iter().rposition(|step| step.4 == after).map(|i| self.undo.len() - i + 1).filter(|n| *n <= self.undo.len()) } /// Identifies the current position and the history it belongs to. Editing and then undoing diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index 067670db9d..7159c6aa44 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -30,9 +30,9 @@ mod unplaced_gp; #[path = "tests/unplaced_out.rs"] mod unplaced_out; -#[cfg(not(target_arch = "wasm32"))] #[path = "tests/message_runs.rs"] mod message_runs; +#[cfg(not(target_arch = "wasm32"))] #[path = "tests/said_not_silent.rs"] mod said_not_silent; diff --git a/crates/engine/src/tests/message_runs.rs b/crates/engine/src/tests/message_runs.rs index f12e722de4..6674d3d912 100644 --- a/crates/engine/src/tests/message_runs.rs +++ b/crates/engine/src/tests/message_runs.rs @@ -3,32 +3,33 @@ use super::*; #[test] -fn a_commands_messages_remember_its_run_and_undo_reaches_back_to_before_it() { +fn a_commands_messages_remember_its_run_and_undo_reaches_back_past_it() { let mut s = world(); s.run("layer.addDataText", &json!({"fileName": "records.csv", "text": "n\n1\n2\n"})).unwrap(); s.run("edit.enable", &json!({"on": true})).unwrap(); - let loss_records = |s: &Session| -> Vec { - s.diagnostics.records().into_iter().filter(|r| r.loss.is_some()).collect() + let last_run = |s: &Session| -> rustgis_data::diagnostics::Run { + s.diagnostics.records().into_iter().rev().find(|r| r.loss.is_some()).and_then(|r| r.run).expect("a coded message from a run") }; s.run("edit.calculateField", &json!({"table": "records", "field": "n", "expression": "n + 1.5"})).unwrap(); - let first = loss_records(&s); - let [cut] = first.as_slice() else { panic!("one coded message: {first:?}") }; - assert_eq!(cut.source, "edit.calculateField"); - let run = cut.run.clone().expect("said by a command run"); - assert_eq!(run.target.as_deref(), Some("records")); - assert_eq!(s.undo_steps_to(run.before), Some(1), "one step back to before it"); + let first = last_run(&s); + assert_eq!(first.target.as_deref(), Some("records")); + let after = first.after.expect("finished"); + assert_ne!(after, first.before, "it changed the project"); + assert_eq!(s.undo_steps_back_past(after), Some(1), "one step back past it"); s.run("edit.calculateField", &json!({"table": "records", "field": "n", "expression": "n + 0.5"})).unwrap(); - let both = loss_records(&s); - let later = both.last().and_then(|r| r.run.clone()).unwrap(); - assert_ne!(later.id, run.id, "each run is its own"); - assert_eq!(s.undo_steps_to(run.before), Some(2), "back past the later run too"); - assert_eq!(s.undo_steps_to(later.before), Some(1)); + let later = last_run(&s); + assert_ne!(later.id, first.id, "each run is its own"); + assert_eq!(s.undo_steps_back_past(after), Some(2), "back past the later run too"); + assert_eq!(s.undo_steps_back_past(later.after.unwrap()), Some(1)); - // Undone back to before the first run, its state is the current one. + // Both undone, then another edit from the state before the first: the first run's change is + // gone from the history, so its message offers nothing, not the new edit. s.run("edit.undo", &json!({})).unwrap(); s.run("edit.undo", &json!({})).unwrap(); - assert_eq!(s.undo_steps_to(run.before), Some(0)); + assert_eq!(s.state(), first.before); + s.run("edit.calculateField", &json!({"table": "records", "field": "n", "expression": "n * 2"})).unwrap(); + assert_eq!(s.undo_steps_back_past(after), None); // A message no command said has no run. s.notify("said by the app", false); assert!(s.diagnostics.records().last().is_some_and(|r| r.run.is_none())); diff --git a/crates/ui-egui/src/diagnosticlog.rs b/crates/ui-egui/src/diagnosticlog.rs index 622a4aa0c9..5587f9fe86 100644 --- a/crates/ui-egui/src/diagnosticlog.rs +++ b/crates/ui-egui/src/diagnosticlog.rs @@ -95,15 +95,17 @@ fn run_heading(ui: &mut Ui, app: &mut RustGisApp, record: &Record, t: &Tokens) { } ui.label(RichText::new(time(record.timestamp_ms)).small().monospace().color(t.text_dim)); }); - // Only a run that changed the project, whose state before is still in the history. - let steps = app.session.undo_steps_to(run.before).filter(|steps| *steps > 0); + // Only a run that changed the project, whose change is still in the history. + let steps = run.after.filter(|after| *after != run.before).and_then(|after| app.session.undo_steps_back_past(after)); if let Some(steps) = steps { let hover = if steps == 1 { tl!("Takes back this command's changes").to_string() } else { crate::i18n::fmt("Takes back this command's changes and the {n} after it", &[("n", &(steps - 1).to_string())]) }; - if ui.small_button(tl!("Undo to before this")).on_hover_text(hover).clicked() { + // One history jump at a time: Undo History's own, or another message's. + let free = app.ui.history_jump.is_none(); + if ui.add_enabled(free, egui::Button::new(tl!("Undo to before this")).small()).on_hover_text(hover).clicked() { app.ui.history_jump = Some(crate::chrome::HistoryJump::undo(app.session.history_position(), steps)); ui.ctx().request_repaint(); } From d9660a77760296033438bd3f270c5929ad0e2f05 Mon Sep 17 00:00:00 2001 From: mavrick Date: Fri, 27 Nov 2026 15:32:05 -0600 Subject: [PATCH 3/7] fix(ui): Undo to before this lands only on the run's own state before; explain takes the common options; a message's code explained in a quiet inset --- apps/rustgis-cli/src/main.rs | 26 +++++++--- crates/data/src/diagnostics.rs | 2 + crates/engine/src/lib.rs | 32 +++++++------ crates/engine/src/tests/message_runs.rs | 20 ++++++-- crates/ui-egui/src/diagnosticlog.rs | 64 ++++++++++++++----------- docs/user-guide/index.md | 8 ++-- 6 files changed, 96 insertions(+), 56 deletions(-) diff --git a/apps/rustgis-cli/src/main.rs b/apps/rustgis-cli/src/main.rs index 0e9043a0ff..e96873c587 100644 --- a/apps/rustgis-cli/src/main.rs +++ b/apps/rustgis-cli/src/main.rs @@ -62,13 +62,13 @@ fn explain(code: Option<&str>) -> Result<(), String> { let Some(id) = code else { for code in LossCode::ALL { let spec = code.spec(); - println!("{:<28} {}", spec.id, spec.meaning); + out!("{:<28} {}", spec.id, spec.meaning); } return Ok(()); }; let code = LossCode::from_id(id).ok_or_else(|| format!("explain {id}: not a loss code (`rustgis-cli explain` lists them)"))?; let spec = code.spec(); - println!("{}: {}\n\n{}\n\nWhat to do: {}\n\nMore: {}", spec.id, spec.kind.id(), spec.meaning, spec.action, code.doc_url()); + out!("{}: {}\n\n{}\n\nWhat to do: {}\n\nMore: {}", spec.id, spec.kind.id(), spec.meaning, spec.action, code.doc_url()); Ok(()) } @@ -1065,11 +1065,23 @@ fn cli() -> ExitCode { print(&out); Ok(()) } - "explain" => match args.get(1..).unwrap_or_default() { - [] => explain(None), - [code] if !code.starts_with("--") => explain(Some(code)), - _ => Err("explain takes one loss code, or none to list them all".into()), - }, + "explain" => { + // The common options (`--threads 2`, `--use-saved-secrets`) are taken, and their values. + let mut words = Vec::new(); + let mut rest = args.iter().skip(1); + while let Some(arg) = rest.next() { + if VALUE_FLAGS.contains(&arg.as_str()) { + rest.next(); + } else if !arg.starts_with("--") { + words.push(arg.as_str()); + } + } + match words.as_slice() { + [] => explain(None), + [code] => explain(Some(code)), + _ => Err("explain takes one loss code, or none to list them all".into()), + } + } "skills" => skills(&args), "mcp-register" => mcp_register(&args), "commands" => { diff --git a/crates/data/src/diagnostics.rs b/crates/data/src/diagnostics.rs index 6a484dee91..10a6da5067 100644 --- a/crates/data/src/diagnostics.rs +++ b/crates/data/src/diagnostics.rs @@ -266,6 +266,8 @@ impl History { /// which are the newest ones with a run. pub fn finish_run(&self, id: u64, after: u64) { let mut state = lock(&self.0); + // A changed record: a snapshot taken before it shows the run as unfinished. + state.generation = state.generation.wrapping_add(1); for record in state.records.iter_mut().rev() { match &mut record.run { Some(run) if run.id == id => run.after = Some(after), diff --git a/crates/engine/src/lib.rs b/crates/engine/src/lib.rs index ee491438e3..9f08b108f4 100644 --- a/crates/engine/src/lib.rs +++ b/crates/engine/src/lib.rs @@ -2039,7 +2039,9 @@ impl Session { })); self.diagnostic_source = previous; if let Some(run) = previous_run { - if let Some(ended) = &self.run { + // Undo makes no step of its own: it moves back one, so "before" it isn't a step to take + // back. Redo's step is its own, and undoing it returns to before it. + if let Some(ended) = self.run.as_ref().filter(|_| id != "edit.undo") { self.diagnostics.finish_run(ended.id, self.state); } self.run = run; @@ -3713,19 +3715,21 @@ impl Session { self.redo.iter().rev().map(|step| step.2) } - /// How many Undo steps take back the change that left the project in the state `after` (a - /// message's [`Run::after`](rustgis_data::diagnostics::Run)), with the changes made since: - /// `None` when the history no longer holds that change. A change makes a state no other has, - /// so an edit made after undoing it, from the same state before, isn't taken for it. - pub fn undo_steps_back_past(&self, after: u64) -> Option { - if self.undo.is_empty() { - return None; - } - if self.state == after { - return Some(1); - } - // The step after the change keeps the state the change left. - self.undo.iter().rposition(|step| step.4 == after).map(|i| self.undo.len() - i + 1).filter(|n| *n <= self.undo.len()) + /// How many Undo steps take back the change of a run that went from the state `before` to + /// `after` (a message's [`Run`](rustgis_data::diagnostics::Run)), with the changes made since: + /// `None` when the history no longer holds that change as a step of its own. A change makes a + /// state no other has, so an edit made after undoing it, from the same state before, isn't taken + /// for it; and the step Undo lands on must be `before`, so a run whose step was merged into an + /// earlier one, or that made no step, isn't taken back past that earlier command. + pub fn undo_steps_back_past(&self, before: u64, after: u64) -> Option { + let steps = if self.state == after { + 1 + } else { + // The step after the change keeps the state the change left. + self.undo.len() - self.undo.iter().rposition(|step| step.4 == after)? + 1 + }; + let landing = self.undo.len().checked_sub(steps)?; + (self.undo.get(landing)?.4 == before).then_some(steps) } /// Identifies the current position and the history it belongs to. Editing and then undoing diff --git a/crates/engine/src/tests/message_runs.rs b/crates/engine/src/tests/message_runs.rs index 6674d3d912..24cb04440d 100644 --- a/crates/engine/src/tests/message_runs.rs +++ b/crates/engine/src/tests/message_runs.rs @@ -15,13 +15,13 @@ fn a_commands_messages_remember_its_run_and_undo_reaches_back_past_it() { assert_eq!(first.target.as_deref(), Some("records")); let after = first.after.expect("finished"); assert_ne!(after, first.before, "it changed the project"); - assert_eq!(s.undo_steps_back_past(after), Some(1), "one step back past it"); + assert_eq!(s.undo_steps_back_past(first.before, after), Some(1), "one step back past it"); s.run("edit.calculateField", &json!({"table": "records", "field": "n", "expression": "n + 0.5"})).unwrap(); let later = last_run(&s); assert_ne!(later.id, first.id, "each run is its own"); - assert_eq!(s.undo_steps_back_past(after), Some(2), "back past the later run too"); - assert_eq!(s.undo_steps_back_past(later.after.unwrap()), Some(1)); + assert_eq!(s.undo_steps_back_past(first.before, after), Some(2), "back past the later run too"); + assert_eq!(s.undo_steps_back_past(later.before, later.after.unwrap()), Some(1)); // Both undone, then another edit from the state before the first: the first run's change is // gone from the history, so its message offers nothing, not the new edit. @@ -29,7 +29,19 @@ fn a_commands_messages_remember_its_run_and_undo_reaches_back_past_it() { s.run("edit.undo", &json!({})).unwrap(); assert_eq!(s.state(), first.before); s.run("edit.calculateField", &json!({"table": "records", "field": "n", "expression": "n * 2"})).unwrap(); - assert_eq!(s.undo_steps_back_past(after), None); + assert_eq!(s.undo_steps_back_past(first.before, after), None); + // A run whose step joined an earlier one's (a held key nudging an element) has no step of its + // own: Undo would land before the earlier command, so its message offers nothing. + s.merge_undo("nudge"); + s.run("edit.calculateField", &json!({"table": "records", "field": "n", "expression": "n + 1.5"})).unwrap(); + s.merge_undo("nudge"); + s.run("edit.calculateField", &json!({"table": "records", "field": "n", "expression": "n + 2.5"})).unwrap(); + let joined = last_run(&s); + assert_eq!(s.undo_steps_back_past(joined.before, joined.after.unwrap()), None); + // An undo makes no step: a message it says offers no Undo to before it. + s.run("edit.undo", &json!({})).unwrap(); + let undone = s.diagnostics.records().into_iter().rev().find_map(|r| r.run.filter(|run| run.id > later.id)); + assert!(undone.as_ref().is_none_or(|run| run.after.is_none()), "{undone:?}"); // A message no command said has no run. s.notify("said by the app", false); assert!(s.diagnostics.records().last().is_some_and(|r| r.run.is_none())); diff --git a/crates/ui-egui/src/diagnosticlog.rs b/crates/ui-egui/src/diagnosticlog.rs index 5587f9fe86..0691f2be3f 100644 --- a/crates/ui-egui/src/diagnosticlog.rs +++ b/crates/ui-egui/src/diagnosticlog.rs @@ -93,28 +93,30 @@ fn run_heading(ui: &mut Ui, app: &mut RustGisApp, record: &Record, t: &Tokens) { if let Some(target) = &run.target { ui.label(RichText::new(crate::i18n::fmt("on {target}", &[("target", target.as_str())])).color(t.text_dim)); } - ui.label(RichText::new(time(record.timestamp_ms)).small().monospace().color(t.text_dim)); }); - // Only a run that changed the project, whose change is still in the history. - let steps = run.after.filter(|after| *after != run.before).and_then(|after| app.session.undo_steps_back_past(after)); - if let Some(steps) = steps { - let hover = if steps == 1 { - tl!("Takes back this command's changes").to_string() - } else { - crate::i18n::fmt("Takes back this command's changes and the {n} after it", &[("n", &(steps - 1).to_string())]) - }; - // One history jump at a time: Undo History's own, or another message's. - let free = app.ui.history_jump.is_none(); - if ui.add_enabled(free, egui::Button::new(tl!("Undo to before this")).small()).on_hover_text(hover).clicked() { - app.ui.history_jump = Some(crate::chrome::HistoryJump::undo(app.session.history_position(), steps)); - ui.ctx().request_repaint(); + // Only a run that changed the project, whose change is still a step of its own in the history. + let steps = run.after.filter(|after| *after != run.before).and_then(|after| app.session.undo_steps_back_past(run.before, after)); + ui.horizontal_wrapped(|ui| { + ui.label(RichText::new(time(record.timestamp_ms)).small().monospace().color(t.text_dim)); + if let Some(steps) = steps { + let hover = if steps == 1 { + tl!("Takes back this command's changes").to_string() + } else { + crate::i18n::fmt("Takes back this command's changes and the {n} after it", &[("n", &(steps - 1).to_string())]) + }; + // One history jump at a time: Undo History's own, or another message's. + let free = app.ui.history_jump.is_none(); + if ui.add_enabled(free, egui::Button::new(tl!("Undo to before this")).small()).on_hover_text(hover).clicked() { + app.ui.history_jump = Some(crate::chrome::HistoryJump::undo(app.session.history_position(), steps)); + ui.ctx().request_repaint(); + } } - } + }); } /// One entry, laid out as a compiler message: its severity, and its loss code when it reports lost -/// data; the message; then what the code means (`note`) and what to do (`help`), from text built -/// into the app so they read offline, with the guide's entry for more. A message no command said +/// data; the message; then what the code means and what to do, from text built into the app so +/// they read offline, with the guide's entry for more. A message no command said /// shows its time and source itself (`standalone`). fn entry(ui: &mut Ui, record: &Record, t: &Tokens, standalone: bool, open_url: &mut Option) { // Literal labels, so each is found and translated with the interface's other strings. @@ -153,17 +155,25 @@ fn entry(ui: &mut Ui, record: &Record, t: &Tokens, standalone: bool, open_url: & ui.add(egui::Label::new(&record.message).wrap().selectable(true)); if let Some(code) = record.loss { let spec = code.spec(); - let line = |ui: &mut Ui, label: &str, text: &str| { - ui.horizontal_wrapped(|ui| { - ui.label(RichText::new(label).small().strong().color(t.text_dim)); - ui.add(egui::Label::new(RichText::new(text).small()).wrap()); + // What the code means and what to do, in a quiet inset under the message. + egui::Frame::NONE + .fill(t.pane_header) + .stroke(egui::Stroke::new(1.0, t.border)) + .corner_radius(egui::CornerRadius::same(4)) + .inner_margin(egui::Margin::symmetric(8, 6)) + .show(ui, |ui| { + ui.set_width(ui.available_width()); + for (heading, text) in + [(tl!("What happened"), crate::i18n::t(spec.meaning)), (tl!("What to do"), crate::i18n::t(spec.action))] + { + ui.label(RichText::new(heading).small().strong().color(t.text_dim)); + ui.add(egui::Label::new(RichText::new(text).small()).wrap()); + ui.add_space(4.0); + } + if ui.link(RichText::new(tl!("More in the guide")).small()).on_hover_text(code.doc_url()).clicked() { + *open_url = Some(code.doc_url()); + } }); - }; - line(ui, tl!("= note:"), crate::i18n::t(spec.meaning)); - line(ui, tl!("= help:"), crate::i18n::t(spec.action)); - if ui.link(RichText::new(tl!("More in the guide")).small()).on_hover_text(code.doc_url()).clicked() { - *open_url = Some(code.doc_url()); - } } if !record.details.is_empty() || record.network.is_some() { egui::CollapsingHeader::new(tl!("Technical details")).show(ui, |ui| { diff --git a/docs/user-guide/index.md b/docs/user-guide/index.md index 94263677a4..94a8599a34 100644 --- a/docs/user-guide/index.md +++ b/docs/user-guide/index.md @@ -127,12 +127,12 @@ or search for **Messages** in Command Search (`ui.pane.diagnosticLog`). This tro history is separate from **Help › Diagnostic Monitor**, which still shows performance metrics. Messages are collected even while the pane is closed. The newest entries appear first. A -command's messages sit under its name, what it worked on (a layer or table) and a UTC time; a -message no command said shows its own time and source (such as Network). +command's messages sit under its name, what it worked on (a layer or table) and the UTC time of its +latest message; a message no command said shows its own time and source (such as Network). A message that reports lost data is laid out like a compiler's: its severity and -[loss code](loss-codes.md) (`Warning [changed.truncated] data changed`), the message, then a -**note** on what the code means and a **help** line on what to do. Both are built into RustGIS, so +[loss code](loss-codes.md) (`Warning [changed.truncated] data changed`), the message, then +**What happened** and **What to do** for that code. Both are built into RustGIS, so they read offline; **More in the guide** opens the code's entry. **Undo to before this** takes the project back to before that command, and the changes after it, while Undo still reaches it. Expand **Technical details** for failed requests: their address, method, observed HTTP status and duration when From 9cca791edeaa966bdcb5b45f6aa530c699c2cae5 Mon Sep 17 00:00:00 2001 From: mavrick Date: Fri, 27 Nov 2026 16:07:21 -0600 Subject: [PATCH 4/7] test(engine): look for the Undo's run after the merged runs --- crates/engine/src/tests/message_runs.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/engine/src/tests/message_runs.rs b/crates/engine/src/tests/message_runs.rs index 24cb04440d..1f4d8e9aed 100644 --- a/crates/engine/src/tests/message_runs.rs +++ b/crates/engine/src/tests/message_runs.rs @@ -40,7 +40,7 @@ fn a_commands_messages_remember_its_run_and_undo_reaches_back_past_it() { assert_eq!(s.undo_steps_back_past(joined.before, joined.after.unwrap()), None); // An undo makes no step: a message it says offers no Undo to before it. s.run("edit.undo", &json!({})).unwrap(); - let undone = s.diagnostics.records().into_iter().rev().find_map(|r| r.run.filter(|run| run.id > later.id)); + let undone = s.diagnostics.records().into_iter().rev().find_map(|r| r.run.filter(|run| run.id > joined.id)); assert!(undone.as_ref().is_none_or(|run| run.after.is_none()), "{undone:?}"); // A message no command said has no run. s.notify("said by the app", false); From 596b731936ee6e57d8824b01a08f6dbdfb11cfad Mon Sep 17 00:00:00 2001 From: mavrick Date: Fri, 27 Nov 2026 16:40:00 -0600 Subject: [PATCH 5/7] fix(ui): a run's heading names the command that started it, and a run's messages stay together around others --- crates/data/src/diagnostics.rs | 2 ++ crates/engine/src/lib.rs | 8 +++++++- crates/engine/src/tests/message_runs.rs | 5 +---- crates/ui-egui/src/diagnosticlog.rs | 25 ++++++++++++++++++++++--- 4 files changed, 32 insertions(+), 8 deletions(-) diff --git a/crates/data/src/diagnostics.rs b/crates/data/src/diagnostics.rs index 10a6da5067..0169e2a5bb 100644 --- a/crates/data/src/diagnostics.rs +++ b/crates/data/src/diagnostics.rs @@ -115,6 +115,8 @@ pub struct Record { pub struct Run { /// Counts the session's runs, so the messages of one run are told from the next one's. pub id: u64, + /// The top-level command that started the run: a message a nested step said is still the run's. + pub command: String, /// The project's state before the run (`Session::state` in the engine). pub before: u64, /// The state the run left the project in, once it has finished: another than `before` when it diff --git a/crates/engine/src/lib.rs b/crates/engine/src/lib.rs index 9f08b108f4..3325b82c8f 100644 --- a/crates/engine/src/lib.rs +++ b/crates/engine/src/lib.rs @@ -1949,7 +1949,13 @@ impl Session { // undo back to before it. let previous_run = outermost.then(|| { self.runs = self.runs.wrapping_add(1); - let run = rustgis_data::diagnostics::Run { id: self.runs, before: self.state, after: None, target: run_target(params) }; + let run = rustgis_data::diagnostics::Run { + id: self.runs, + command: id.to_string(), + before: self.state, + after: None, + target: run_target(params), + }; self.run.replace(run) }); let history_deferred = std::mem::replace(&mut self.undo_memory.deferred, true); diff --git a/crates/engine/src/tests/message_runs.rs b/crates/engine/src/tests/message_runs.rs index 1f4d8e9aed..3ea3500b94 100644 --- a/crates/engine/src/tests/message_runs.rs +++ b/crates/engine/src/tests/message_runs.rs @@ -13,6 +13,7 @@ fn a_commands_messages_remember_its_run_and_undo_reaches_back_past_it() { s.run("edit.calculateField", &json!({"table": "records", "field": "n", "expression": "n + 1.5"})).unwrap(); let first = last_run(&s); assert_eq!(first.target.as_deref(), Some("records")); + assert_eq!(first.command, "edit.calculateField"); let after = first.after.expect("finished"); assert_ne!(after, first.before, "it changed the project"); assert_eq!(s.undo_steps_back_past(first.before, after), Some(1), "one step back past it"); @@ -38,10 +39,6 @@ fn a_commands_messages_remember_its_run_and_undo_reaches_back_past_it() { s.run("edit.calculateField", &json!({"table": "records", "field": "n", "expression": "n + 2.5"})).unwrap(); let joined = last_run(&s); assert_eq!(s.undo_steps_back_past(joined.before, joined.after.unwrap()), None); - // An undo makes no step: a message it says offers no Undo to before it. - s.run("edit.undo", &json!({})).unwrap(); - let undone = s.diagnostics.records().into_iter().rev().find_map(|r| r.run.filter(|run| run.id > joined.id)); - assert!(undone.as_ref().is_none_or(|run| run.after.is_none()), "{undone:?}"); // A message no command said has no run. s.notify("said by the app", false); assert!(s.diagnostics.records().last().is_some_and(|r| r.run.is_none())); diff --git a/crates/ui-egui/src/diagnosticlog.rs b/crates/ui-egui/src/diagnosticlog.rs index 0691f2be3f..69c99e9742 100644 --- a/crates/ui-egui/src/diagnosticlog.rs +++ b/crates/ui-egui/src/diagnosticlog.rs @@ -61,8 +61,26 @@ pub(crate) fn show(app: &mut RustGisApp, ui: &mut Ui, t: &Tokens) { egui::Frame::NONE.inner_margin(egui::Margin::symmetric(12, 8)).show(ui, |ui| { let filter = app.ui.diagnostic_filter; let shown: Vec<&Record> = records.iter().rev().filter(|r| filter.matches(r)).collect(); - // The messages of one command run, newest first, under that run's heading. - for group in shown.chunk_by(|a, b| a.run.is_some() && a.run.as_ref().map(|r| r.id) == b.run.as_ref().map(|r| r.id)) { + // The messages of one command run, newest first, under that run's heading, wherever a + // message no run said (a network failure) falls among them. + let mut groups: Vec> = Vec::new(); + let mut at: std::collections::HashMap = std::collections::HashMap::new(); + for &record in &shown { + match record.run.as_ref().and_then(|run| at.get(&run.id).copied()) { + Some(i) => { + if let Some(group) = groups.get_mut(i) { + group.push(record); + } + } + None => { + if let Some(run) = &record.run { + at.insert(run.id, groups.len()); + } + groups.push(vec![record]); + } + } + } + for group in &groups { let Some(first) = group.first() else { continue }; ui.push_id(first.id, |ui| { if first.run.is_some() { @@ -87,7 +105,8 @@ pub(crate) fn show(app: &mut RustGisApp, ui: &mut Ui, t: &Tokens) { /// when, with Undo to before it while the history still reaches that state. fn run_heading(ui: &mut Ui, app: &mut RustGisApp, record: &Record, t: &Tokens) { let Some(run) = &record.run else { return }; - let name = app.session.registry.get(record.source.as_str()).map_or(record.source.as_str(), |spec| crate::i18n::t(spec.label)); + // The command that started the run, whichever step said the message. + let name = app.session.registry.get(run.command.as_str()).map_or(run.command.as_str(), |spec| crate::i18n::t(spec.label)); ui.horizontal_wrapped(|ui| { ui.label(RichText::new(name).strong()); if let Some(target) = &run.target { From d50d4ed13792ed98cdcfbb5ce78690379745fccd Mon Sep 17 00:00:00 2001 From: mavrick Date: Fri, 27 Nov 2026 17:17:32 -0600 Subject: [PATCH 6/7] fix(engine): a run's target is redacted as a message is, logins in use included --- crates/engine/src/lib.rs | 3 ++- crates/engine/src/tests/message_runs.rs | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/crates/engine/src/lib.rs b/crates/engine/src/lib.rs index 3325b82c8f..e43aa570d1 100644 --- a/crates/engine/src/lib.rs +++ b/crates/engine/src/lib.rs @@ -694,7 +694,8 @@ fn run_target(params: &Value) -> Option { if name.is_empty() { return None; } - let name = rustgis_data::diagnostics::redact(name); + // As a message is: addresses, credentials and the values of the logins in use masked. + let name = Session::redacted(name).into_string(); let mut cut: String = name.chars().take(80).collect(); if cut.len() < name.len() { cut.push('…'); diff --git a/crates/engine/src/tests/message_runs.rs b/crates/engine/src/tests/message_runs.rs index 3ea3500b94..3fe56b4abe 100644 --- a/crates/engine/src/tests/message_runs.rs +++ b/crates/engine/src/tests/message_runs.rs @@ -43,3 +43,25 @@ fn a_commands_messages_remember_its_run_and_undo_reaches_back_past_it() { s.notify("said by the app", false); assert!(s.diagnostics.records().last().is_some_and(|r| r.run.is_none())); } + +#[test] +fn a_runs_target_masks_a_login_in_use() { + let mut s = Session::new(Project::default()); + let id = s + .run( + "connection.new", + &json!({"kind": "wms", "name": "Run", "address": "https://run-target.example.invalid", "auth": "header", "keyName": "X-Key"}), + ) + .unwrap()["id"] + .as_str() + .unwrap() + .to_string(); + let secret = "RGSYNTH_run_target_key"; + s.run("connection.login", &json!({"id": id, "apiKey": secret})).unwrap(); + // A layer named with the key: the command fails, and its message keeps the run's target. + let _ = s.run("layer.zoomTo", &json!({"layer": format!("roads {secret}")})); + let run = s.diagnostics.records().into_iter().rev().find_map(|r| r.run).expect("the failure's run"); + let target = run.target.expect("a target"); + assert!(!target.contains(secret), "{target}"); + assert!(target.starts_with("roads "), "{target}"); +} From 3c906ec8b2eae95ddbf24c29e9fd06bf20f69851 Mon Sep 17 00:00:00 2001 From: mavrick Date: Fri, 27 Nov 2026 17:49:47 -0600 Subject: [PATCH 7/7] fix(engine): a run keeps the registered command's own id, never the text it was asked for --- crates/data/src/diagnostics.rs | 3 ++- crates/engine/src/lib.rs | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/crates/data/src/diagnostics.rs b/crates/data/src/diagnostics.rs index 0169e2a5bb..2dbb1d2ff8 100644 --- a/crates/data/src/diagnostics.rs +++ b/crates/data/src/diagnostics.rs @@ -123,7 +123,8 @@ pub struct Run { /// changed the project. A change makes a state no other change has, so the history finds the /// run's own step by it, even after an Undo and another edit from the same state before. pub after: Option, - /// What the run worked on, as its parameters name it (a layer, a table, a file). + /// What the run worked on, as its parameters name it (a layer, a table, an input or a map; + /// never a file path), redacted as a message is. pub target: Option, } diff --git a/crates/engine/src/lib.rs b/crates/engine/src/lib.rs index e43aa570d1..87c65010ca 100644 --- a/crates/engine/src/lib.rs +++ b/crates/engine/src/lib.rs @@ -1952,7 +1952,9 @@ impl Session { self.runs = self.runs.wrapping_add(1); let run = rustgis_data::diagnostics::Run { id: self.runs, - command: id.to_string(), + // The registered command's own id, never the text asked for: an unknown one could + // hold anything, a login included. + command: source.unwrap_or("unknown command").to_string(), before: self.state, after: None, target: run_target(params),