Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@
All notable changes to Setu. Release notes are cut from the section
matching the tag.

## 0.1.6 — 2026-10-22

### Fixed

- **Site logs are plain text.** The agent strips terminal escape sequences
(colours, cursor moves, window titles) from each journal line, so an app
that colours its logs under systemd no longer fills the Logs tab with
`ESC[32m` noise.

## 0.1.5 — 2026-10-21

Spec: `docs/specs/2026-10-21-setu-0.1.5-design.md`.
Expand Down
18 changes: 9 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ members = [
]

[workspace.package]
version = "0.1.5"
version = "0.1.6"
edition = "2021"
license = "AGPL-3.0-only"
# Never published to crates.io (single binary + private repo); also
Expand Down
79 changes: 77 additions & 2 deletions crates/agent/src/journal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,64 @@ pub fn parse_journal_json(text: &str) -> LogStream {
next = Some(c.to_string());
}
match v.get("MESSAGE") {
Some(serde_json::Value::String(s)) => lines.push(s.clone()),
Some(serde_json::Value::String(s)) => lines.push(strip_ansi(s)),
// Non-UTF-8 messages arrive as a byte array.
Some(serde_json::Value::Array(bytes)) => {
let raw: Vec<u8> = bytes
.iter()
.filter_map(|b| b.as_u64().and_then(|b| u8::try_from(b).ok()))
.collect();
lines.push(String::from_utf8_lossy(&raw).into_owned());
lines.push(strip_ansi(&String::from_utf8_lossy(&raw)));
}
_ => {}
}
}
LogStream { lines, next }
}

/// Drops terminal escape sequences (colours, cursor moves, titles) from a
/// log line. Apps colour their logs whether or not a terminal is reading,
/// and the panel shows plain text, so `ESC[32mINFO` would arrive as
/// garbage. Handles CSI (`ESC [ … final`), OSC (`ESC ] … BEL` or
/// `ESC \\`) and two-byte `ESC x` escapes; any other text is kept.
pub fn strip_ansi(line: &str) -> String {
if !line.contains('\u{1b}') {
return line.to_owned();
}
let mut out = String::with_capacity(line.len());
let mut chars = line.chars().peekable();
while let Some(c) = chars.next() {
if c != '\u{1b}' {
out.push(c);
continue;
}
match chars.next() {
// CSI: parameters and intermediates up to a final byte in @..~.
Some('[') => {
for c in chars.by_ref() {
if ('@'..='~').contains(&c) {
break;
}
}
}
// OSC: up to BEL or the string terminator ESC \.
Some(']') => {
while let Some(c) = chars.next() {
if c == '\u{7}' {
break;
}
if c == '\u{1b}' && chars.peek() == Some(&'\\') {
chars.next();
break;
}
}
}
_ => {}
}
}
out
}

/// Read up to `lines` entries after `cursor`.
/// `program` is `journalctl` in production (a fake script in tests).
pub async fn read(
Expand Down Expand Up @@ -109,4 +152,36 @@ mod tests {
assert_eq!(s.lines, ["hello", "hi"]);
assert_eq!(s.next.as_deref(), Some("c2"));
}

#[test]
fn colour_codes_are_stripped_from_messages() {
// What a tracing subscriber writes when it thinks a terminal is
// reading: dim timestamp, green level, dim target.
let coloured = "\u{1b}[2m2026-10-22T06:37:20Z\u{1b}[0m \u{1b}[32m INFO\u{1b}[0m \u{1b}[2mvyasa::host\u{1b}[0m\u{1b}[2m:\u{1b}[0m docs sync finished";
let text = format!(
"{}\n{}\n",
serde_json::json!({"__CURSOR": "c1", "MESSAGE": coloured}),
// journald hands control characters over as a byte array.
serde_json::json!({"__CURSOR": "c2", "MESSAGE": "\u{1b}[31mfail\u{1b}[0m".bytes().collect::<Vec<_>>()}),
);
let s = parse_journal_json(&text);
assert_eq!(
s.lines,
[
"2026-10-22T06:37:20Z INFO vyasa::host: docs sync finished",
"fail"
]
);
}

#[test]
fn strip_ansi_keeps_plain_text_and_drops_osc_titles() {
assert_eq!(strip_ansi("plain [text] ok"), "plain [text] ok");
assert_eq!(strip_ansi("\u{1b}]0;title\u{7}after"), "after");
assert_eq!(
strip_ansi("a\u{1b}]8;;http://x\u{1b}\\link\u{1b}]8;;\u{1b}\\b"),
"alinkb"
);
assert_eq!(strip_ansi("bold \u{1b}[1;31mred\u{1b}[0m"), "bold red");
}
}
2 changes: 1 addition & 1 deletion ui/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "setu-ui",
"private": true,
"version": "0.1.5",
"version": "0.1.6",
"type": "module",
"scripts": {
"gen:api": "tsx scripts/gen-api.ts",
Expand Down
Loading