web: Show history details as approvals show them
CI / Check (push) Successful in 4m44s

The audit log kept a request's detail as text, so the web app's history
showed it as one preformatted block. Keep the structure instead, and
render it with the same fields, tables and coloured diffs as a pending
request. Older records' text still reads, as a text section.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit was merged in pull request #7.
This commit is contained in:
jackos1998andClaude Opus 5.5 authored and Jack O'Sullivan committed 2026-11-27 16:34:58 +00:00
1 parent 9d08b5cf8f
commit 0b2cdf4155
8 files changed
+106 -24

No files matched your search

+3 -2
View File
@@ -328,8 +328,9 @@ operation, and nothing acts on the structure besides showing it.
Each request, decision, approver, lease use and result is an event with the request's ID. The
broker writes it to the journal as a line of text and to `audit.jsonl` in its state directory as a
line of JSON. `slop-approve log [-n 50] [--json]` shows the recent events through the approve
socket, with each request's full detail. Secret operations record the file and the blob ID of the
line of JSON, keeping what approvers were shown with its structure, so the web app's history shows
it as the request did. `slop-approve log [-n 50] [--json]` shows the recent events through the
approve socket, with each request's full detail. Secret operations record the file and the blob ID of the
ciphertext they were sent, never values.
## Operations
+53 -6
View File
@@ -10,6 +10,7 @@ use std::time::SystemTime;
use anyhow::Result;
use serde::{Deserialize, Serialize};
use crate::detail::{Detail, Section};
use crate::proto::ApprovedBy;
/// One line of the audit file.
@@ -40,14 +41,14 @@ pub enum Event {
requester: String,
op: String,
summary: String,
detail: String,
detail: Shown,
/// Agent-supplied.
label: Option<String>,
},
/// What approvers are shown once preparing a request (such as building a deploy) finished.
Prepared {
id: String,
detail: String,
detail: Shown,
},
Approved {
id: String,
@@ -100,6 +101,39 @@ impl Event {
}
}
/// What approvers were shown of a request. Records from before the broker kept the structure
/// have its text.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(untagged)]
pub enum Shown {
Detail(Detail),
Text(String),
}
impl Shown {
pub fn to_text(&self) -> String {
match self {
Shown::Detail(detail) => detail.to_text(),
Shown::Text(text) => text.clone(),
}
}
/// The structure, with old records' text as one text section.
pub fn to_detail(&self) -> Detail {
match self {
Shown::Detail(detail) => detail.clone(),
Shown::Text(text) if text.is_empty() => Detail::default(),
Shown::Text(text) => Detail { fields: vec![], sections: vec![Section::text("Text", text)] },
}
}
}
impl From<Detail> for Shown {
fn from(detail: Detail) -> Shown {
Shown::Detail(detail)
}
}
/// Request IDs are long; approvers type a prefix, and logs show the same.
pub fn short(id: &str) -> &str {
&id[..id.len().min(6)]
@@ -115,7 +149,7 @@ impl fmt::Display for Event {
}
Event::Request { id, requester, summary, detail, label, .. } => {
write!(f, "{} {requester} asks: {summary}", short(id))?;
if let Some(line) = detail.lines().next() {
if let Some(line) = detail.to_text().lines().next() {
write!(f, "; {line}")?;
}
if let Some(label) = label {
@@ -125,7 +159,7 @@ impl fmt::Display for Event {
}
Event::Prepared { id, detail } => {
write!(f, "{} ready for approval", short(id))?;
if let Some(line) = detail.lines().next() {
if let Some(line) = detail.to_text().lines().next() {
write!(f, "; {line}")?;
}
Ok(())
@@ -165,7 +199,7 @@ impl Record {
let time = self.time.replace('T', " ").trim_end_matches('Z').to_owned();
let mut text = format!("{time} {}\n", self.event);
if let Event::Request { detail, .. } | Event::Prepared { detail, .. } = &self.event {
for line in detail.lines().skip(1) {
for line in detail.to_text().lines().skip(1) {
text += &format!("{:21}{line}\n", "");
}
}
@@ -248,7 +282,7 @@ mod tests {
requester: "slop-cannon".into(),
op: "ssh".into(),
summary: "ssh river".into(),
detail: "Command: a\nmore".into(),
detail: Shown::Text("Command: a\nmore".into()),
label: Some("why".into()),
},
};
@@ -258,4 +292,17 @@ mod tests {
\x20 more\n"
);
}
#[test]
fn keeps_what_approvers_saw_and_reads_old_text() {
let detail = Detail::code("Command", "uptime");
let event = Event::Prepared { id: "a".into(), detail: detail.clone().into() };
let line = serde_json::to_string(&event).unwrap();
assert_eq!(serde_json::from_str::<Event>(&line).unwrap(), event);
let old: Event = serde_json::from_str(r#"{"event":"prepared","id":"a","detail":"Command: uptime"}"#).unwrap();
let Event::Prepared { detail: old, .. } = old else { panic!("{old:?}") };
assert_eq!(old, Shown::Text("Command: uptime".into()));
assert_eq!(old.to_text(), detail.to_text());
}
}
+2 -2
View File
@@ -1,6 +1,6 @@
//! What approvers are shown of a request: fields, then tables, lists and text. Operations build
//! it; every surface renders it. The web app shows the structure, the others [`Detail::to_text`],
//! which is also what the audit log keeps and passkey confirmations fingerprint.
//! it; every surface renders it. The web app shows the structure (also in the audit history,
//! which keeps it), the others [`Detail::to_text`], which passkey confirmations fingerprint.
//!
//! The structure is the same for every operation, so surfaces don't need to know any of them.
//! All of it can carry agent-written text, which every surface makes printable when it shows it.
+3 -3
View File
@@ -195,7 +195,7 @@ async fn process(broker: &Broker, requester: &str, request: Request, io: &mut Io
requester: requester.to_owned(),
op: parsed.op.to_string(),
summary: parsed.summary.clone(),
detail: parsed.detail.to_text(),
detail: parsed.detail.clone().into(),
label: label.clone(),
});
@@ -239,7 +239,7 @@ async fn process(broker: &Broker, requester: &str, request: Request, io: &mut Io
Ok(gate) => gate,
Err(error) => return failed(error),
};
log(Event::Prepared { id: id.clone(), detail: gate.detail.to_text() });
log(Event::Prepared { id: id.clone(), detail: gate.detail.clone().into() });
let (by, approver) = match authorize(broker, &id, requester, &gate, label.clone(), io).await {
Ok(Some(approval)) => approval,
@@ -263,7 +263,7 @@ async fn process(broker: &Broker, requester: &str, request: Request, io: &mut Io
return failed(error);
}
log(Event::Prepared { id: id.clone(), detail: parsed.detail.to_text() });
log(Event::Prepared { id: id.clone(), detail: parsed.detail.clone().into() });
}
let (approved_by, approver) = match authorize(broker, &id, requester, &parsed, label, io).await {
+11 -8
View File
@@ -1,7 +1,8 @@
//! The audit log gathered by request: what was asked, who approved it and how it ended.
use std::collections::HashMap;
use crate::audit::{Event, Record};
use crate::audit::{Event, Record, Shown};
use crate::detail::Detail;
use crate::proto::ApprovedBy;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
@@ -165,8 +166,8 @@ fn summarize(id: String, records: Vec<Record>) -> History {
history
}
/// One event in a request's timeline: what happened, and any longer text to show with it.
pub fn describe(event: &Event) -> (String, Option<String>) {
/// One event in a request's timeline: what happened, and what approvers were shown with it.
pub fn describe(event: &Event) -> (String, Option<Detail>) {
match event {
Event::Unknown { peer } => (format!("Refused a connection from {peer}"), None),
Event::Invalid { error, .. } => (format!("Invalid request: {error}"), None),
@@ -175,11 +176,9 @@ pub fn describe(event: &Event) -> (String, Option<String>) {
if let Some(label) = label {
text += &format!(" (label: {label})");
}
(text, Some(detail.clone()).filter(|d| !d.is_empty()))
}
Event::Prepared { detail, .. } => {
("Prepared for approval".into(), Some(detail.clone()).filter(|d| !d.is_empty()))
(text, shown(detail))
}
Event::Prepared { detail, .. } => ("Prepared for approval".into(), shown(detail)),
Event::Approved { by, approver, step, .. } => {
let by = match (by, approver) {
(ApprovedBy::Policy, _) => "policy".to_owned(),
@@ -204,6 +203,10 @@ pub fn describe(event: &Event) -> (String, Option<String>) {
}
}
fn shown(detail: &Shown) -> Option<Detail> {
Some(detail.to_detail()).filter(|d| !d.fields.is_empty() || !d.sections.is_empty())
}
#[cfg(test)]
mod tests {
use super::*;
@@ -218,7 +221,7 @@ mod tests {
requester: "slop-cannon".into(),
op: "ssh".into(),
summary: format!("ssh {id}"),
detail: "Command: uptime".into(),
detail: Detail::code("Command", "uptime").into(),
label: None,
}
}
+32 -1
View File
@@ -67,7 +67,7 @@ fn section_titles(detail: &Detail) -> String {
detail.sections.iter().map(Section::title).collect::<Vec<_>>().join(", ")
}
fn describe(record: &Record) -> (String, Option<String>) {
fn describe(record: &Record) -> (String, Option<Detail>) {
history::describe(&record.event)
}
@@ -270,4 +270,35 @@ mod tests {
assert!(html.contains("needs-passkey"));
assert!(html.contains("Needs passkey"));
}
#[test]
fn history_shows_what_approvers_saw() {
use crate::audit::{Event, Record, Shown};
let mut detail = Detail::code("Command", "uptime");
detail.section(Section::diff("Diff", "@@ -1 +1 @@\n-b\n+a"));
let records = vec![
Record {
time: "2026-11-27T10:00:00Z".into(),
event: Event::Request {
id: "abc".into(),
requester: "slop-cannon".into(),
op: "ssh".into(),
summary: "ssh river".into(),
detail: detail.into(),
label: None,
},
},
Record {
time: "2026-11-27T10:00:01Z".into(),
event: Event::Prepared { id: "abc".into(), detail: Shown::Text("Old: text".into()) },
},
];
let (histories, _) = super::history::gather(records);
let html = request("broker", "token", "abc", None, Some(&histories[0]), 0).0;
assert!(html.contains("<dt>Command</dt><dd class=\"neutral\"><code>uptime</code></dd>"), "{html}");
assert!(html.contains("<span class=\"diff-add\">+a</span>"), "{html}");
assert!(html.contains("Details (Text)") && html.contains("<pre>Old: text</pre>"), "{html}");
}
}
+1 -1
View File
@@ -80,7 +80,7 @@
{% for record in records %}
{% let (text, detail) = self::describe(record) %}
<li>{% call time(record.time) %}{% endcall %} <span>{{ text }}</span>
{%- if let Some(detail) = detail %}<details><summary>Details</summary><pre>{{ detail }}</pre></details>{% endif %}</li>
{%- if let Some(detail) = detail %}{% call detail(detail, false) %}{% endcall %}{% endif %}</li>
{% endfor %}
</ol>
{% endmacro %}
+1 -1
View File
@@ -237,7 +237,7 @@ async fn approvers_see_the_whole_command_and_stdin_that_run() {
// So is the audit log.
let records = broker.audit.tail(10).unwrap();
let slop_broker::audit::Event::Request { detail: logged, .. } = &records[0].event else { panic!("{records:?}") };
assert_eq!(*logged, detail);
assert_eq!(logged.to_text(), detail);
// Multi-line commands are shown as text rather than a one-line field.
let mut client = Client::start(&broker, ssh(&["echo one\necho two"])).await;