Skip to content

The cross-harness, self-improving memory layer for AI agents. Join our community: https://discord.com/invite/zdNChS2fBu

fix(lenses): tell diff file headers from content lines that look like them

Claudedbf6cf46c0ac
diff --git a/cli/beacon/internal/endpoint/dashboard/lenses/files-changed.lens.html b/cli/beacon/internal/endpoint/dashboard/lenses/files-changed.lens.html
index b578f94a..65dbbda9 100644
--- a/cli/beacon/internal/endpoint/dashboard/lenses/files-changed.lens.html
+++ b/cli/beacon/internal/endpoint/dashboard/lenses/files-changed.lens.html
@@ -81,13 +81,29 @@
return d && d.included && typeof d.text === "string" ? d.text : null;
}
+ // classifyDiff labels each line of a unified diff. The ---/+++ file headers only come before a
+ // file's first @@ hunk; inside a hunk, "--- x" is a removed "-- x" (a SQL or Lua comment) and
+ // "+++ x" an added "++ x", so position, not prefix, decides which a line is.
+ function classifyDiff(text) {
+ var inHunk = false;
+ return text.replace(/\n$/, "").split("\n").map(function (line) {
+ if (line.indexOf("diff ") === 0) { inHunk = false; return { line: line, cls: "hunk" }; }
+ if (line.indexOf("@@") === 0) { inHunk = true; return { line: line, cls: "hunk" }; }
+ if (!inHunk && (line.indexOf("+++ ") === 0 || line.indexOf("--- ") === 0 || line === "+++" || line === "---")) {
+ return { line: line, cls: "hunk" };
+ }
+ if (line.charAt(0) === "+") return { line: line, cls: "add" };
+ if (line.charAt(0) === "-") return { line: line, cls: "del" };
+ return { line: line, cls: "" };
+ });
+ }
+
function countLines(text) {
var added = 0, removed = 0;
if (!text) return { added: 0, removed: 0 };
- text.split("\n").forEach(function (line) {
- if (line.indexOf("+++") === 0 || line.indexOf("---") === 0) return;
- if (line.charAt(0) === "+") added += 1;
- else if (line.charAt(0) === "-") removed += 1;
+ classifyDiff(text).forEach(function (l) {
+ if (l.cls === "add") added += 1;
+ else if (l.cls === "del") removed += 1;
});
return { added: added, removed: removed };
}
@@ -172,14 +188,9 @@
function renderDiff(text) {
var pre = el("pre");
- var lines = text.replace(/\n$/, "").split("\n");
- lines.slice(0, MAX_DIFF_LINES).forEach(function (line) {
- var cls = "";
- if (line.indexOf("@@") === 0) cls = "hunk";
- else if (line.indexOf("+++") === 0 || line.indexOf("---") === 0) cls = "hunk";
- else if (line.charAt(0) === "+") cls = "add";
- else if (line.charAt(0) === "-") cls = "del";
- pre.appendChild(el("span", line === "" ? " " : line, cls));
+ var lines = classifyDiff(text);
+ lines.slice(0, MAX_DIFF_LINES).forEach(function (l) {
+ pre.appendChild(el("span", l.line === "" ? " " : l.line, l.cls));
});
if (lines.length > MAX_DIFF_LINES) {
pre.appendChild(el("span", "… " + fmt.format(lines.length - MAX_DIFF_LINES) + " more lines", "hunk"));
diff --git a/cli/beacon/internal/endpoint/dashboard/testdata/lens-e2e/fixtures/runtime.jsonl b/cli/beacon/internal/endpoint/dashboard/testdata/lens-e2e/fixtures/runtime.jsonl
index df3df65e..fe71aade 100644
--- a/cli/beacon/internal/endpoint/dashboard/testdata/lens-e2e/fixtures/runtime.jsonl
+++ b/cli/beacon/internal/endpoint/dashboard/testdata/lens-e2e/fixtures/runtime.jsonl
@@ -10,3 +10,4 @@
{"vendor": "beacon", "product": "endpoint-agent", "schema_version": "1.0", "severity": "info", "endpoint": {"os": "linux"}, "harness": {"name": "claude_code"}, "session": {"id": "rich", "working_directory": "/work/service"}, "timestamp": "2026-06-12T09:00:55Z", "event": {"id": "rich-delete", "kind": "agent_runtime", "action": "file.deleted", "category": "file"}, "message": "file.deleted", "file": {"path": "/work/service/internal/retry/jitter.go", "operation": "delete", "diff_hash": "sha256:ddd", "diff_bytes": 900}, "content": {"retention": "metadata", "included": false, "redacted": true}}
{"vendor": "beacon", "product": "endpoint-agent", "schema_version": "1.0", "severity": "info", "endpoint": {"os": "linux"}, "harness": {"name": "claude_code"}, "session": {"id": "rich", "working_directory": "/work/service"}, "timestamp": "2026-06-12T09:01:00Z", "event": {"id": "rich-denied", "kind": "agent_runtime", "action": "approval.decided", "category": "approval"}, "message": "approval.decided", "approval": {"required": true, "decision": "deny", "reason": "user denied rm"}}
{"vendor": "beacon", "product": "endpoint-agent", "schema_version": "1.0", "severity": "info", "endpoint": {"os": "linux"}, "harness": {"name": "claude_code"}, "session": {"id": "rich", "working_directory": "/work/service"}, "timestamp": "2026-06-12T09:01:10Z", "event": {"id": "rich-answer", "kind": "agent_runtime", "action": "agent.message", "category": "agent"}, "message": "agent.message", "gen_ai": {"usage": {"input_tokens": 5200, "output_tokens": 800, "cost_usd": 0.031}}, "model": "claude-sonnet-5-5"}
+{"timestamp": "2026-06-15T10:00:00Z", "vendor": "beacon", "product": "endpoint-agent", "schema_version": "1.0", "severity": "info", "endpoint": {"os": "linux"}, "harness": {"name": "claude_code"}, "session": {"id": "sqlish", "working_directory": "/w"}, "event": {"id": "sqlish-edit", "kind": "agent_runtime", "action": "file.modified", "category": "file"}, "message": "file.modified", "file": {"path": "/w/q.sql", "operation": "modify", "diff": "diff --git a/q.sql b/q.sql\n--- a/q.sql\n+++ b/q.sql\n@@ -1,3 +1,3 @@\n--- removed sql comment\n+++i;\n select 1;\n", "diff_hash": "sha256:sql", "diff_bytes": 108}, "content": {"retention": "full", "included": true}}
diff --git a/cli/beacon/internal/endpoint/dashboard/testdata/lens-e2e/tests/builtin-files-changed.spec.ts b/cli/beacon/internal/endpoint/dashboard/testdata/lens-e2e/tests/builtin-files-changed.spec.ts
index 08708552..b04d1ea4 100644
--- a/cli/beacon/internal/endpoint/dashboard/testdata/lens-e2e/tests/builtin-files-changed.spec.ts
+++ b/cli/beacon/internal/endpoint/dashboard/testdata/lens-e2e/tests/builtin-files-changed.spec.ts
@@ -35,3 +35,14 @@ test('files changed: a trace without writes says so', async ({ page }) => {
const frame = page.frameLocator('iframe.lens-frame');
await expect(frame.locator('#summary')).toHaveText('No files were changed in this trace.');
});
+
+test('files changed: diff headers are told apart from content lines that look like them', async ({ page }) => {
+ await page.goto('/session.html?id=sqlish&lens=files-changed');
+ const frame = page.frameLocator('iframe.lens-frame');
+ // "--- removed sql comment" removes "-- removed sql comment"; "+++i;" adds "++i;".
+ await expect(frame.locator('#summary')).toHaveText('1 file changed in 1 edit · +1 −1');
+ const pre = frame.locator('#detail pre');
+ await expect(pre.locator('.hunk')).toHaveCount(4); // diff --git, ---, +++, @@
+ await expect(pre.locator('.del')).toHaveText('--- removed sql comment');
+ await expect(pre.locator('.add')).toHaveText('+++i;');
+});